Guest User

Untitled

a guest
Jul 20th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1. switch ($type) {
  2. case '1':
  3. $size = ($_REQUEST['size']);
  4. if (preg_match('/^(0|b[1-9]|[1-9][0-9]{1,6})(.[0-9]{1,2}+)?$/', $size)) {
  5. $optValue = $size;
  6. $optName = $categories[$type - 1][1];
  7. break;
  8. } else {
  9. header("location: ../views/productAdd.php");
  10. return;
  11. }
  12. case '2':
  13. $bWeight = ($_REQUEST['bWeight']);
  14. if (preg_match('/^(0|b[1-9]|[1-9][0-9]{1,6})(.[0-9]{1,2}+)?$/', $bWeight)) {
  15. $optValue = $bWeight;
  16. $optName = $categories[$type - 1][1];
  17. break;
  18. } else {
  19. header("location: ../views/productAdd.php");
  20. return;
  21. }
  22. case '3':
  23. $tempH = ($_REQUEST['fHeight']);
  24. $tempW = ($_REQUEST['fWidth']);
  25. $tempL = ($_REQUEST['fLenght']);
  26. if (preg_match('/^(0|b[1-9]|[1-9][0-9]{1,6})(.[0-9]{1,2}+)?$/', $tempH)) {
  27. $fHeight = $tempH;
  28. }
  29. if (preg_match('/^(0|b[1-9]|[1-9][0-9]{1,6})(.[0-9]{1,2}+)?$/', $tempW)) {
  30. $fWidth = $tempW;
  31. }
  32. if (preg_match('/^(0|b[1-9]|[1-9][0-9]{1,6})(.[0-9]{1,2}+)?$/', $tempL)) {
  33. $fLenght = $tempL;
  34. }
  35.  
  36. if (!isset($fHeight, $fWidth, $fLenght)) {
  37. header("location: ../views/productAdd.php");
  38. return;
  39. }
  40.  
  41. $optValue = $fHeight . 'x' . $fWidth . 'x' . $fLenght;
  42. $optName = $categories[$type - 1][1];
  43. break;
  44. }
  45.  
  46. class Type
  47. {
  48. public $type;
  49.  
  50. function __construct($type)
  51. {
  52. $this->temp = $type;
  53. }
  54.  
  55. function fetchType()
  56. {
  57. include "../config/categories.php";
  58. $val = ($_REQUEST[$categories[$this->temp - 1][3]]);
  59. if (preg_match('/^(0|b[1-9]|[1-9][0-9]{1,6})(.[0-9]{1,2}+)?$/', $val)) {
  60. return $val;
  61. }
  62. }
  63. }
  64.  
  65. define('VALID_DIMENSION_PATTERN', '/^(0|b[1-9]|[1-9][0-9]{1,6})(.[0-9]{1,2}+)?$/')
  66.  
  67. if (preg_match(VALID_DIMENSION_PATTERN, $bWeight)) {
  68.  
  69. function valid_dimension($dimension) {
  70. return preg_match(VALID_DIMENSION_PATTERN, $dimension)
  71. }
  72.  
  73. if (valid_dimension($bWeight)) {
  74.  
  75. function valid_dimensions(...$dimensions) {
  76. foreach($dimensions as $dimension) {
  77. if (!preg_match(VALID_DIMENSION_PATTERN, $dimension))
  78. return FALSE;
  79. }
  80. return TRUE;
  81. }
  82.  
  83. if (valid_dimensions($tempH, $tempW, $tempL)) {
Add Comment
Please, Sign In to add comment