Browse Source

Pretend to fix $TorrentID = 0 error

pjc 5 years ago
parent
commit
ba5eb8c155
2 changed files with 625 additions and 570 deletions
  1. 264
    277
      classes/validate.class.php
  2. 361
    293
      sections/upload/upload_handle.php

+ 264
- 277
classes/validate.class.php View File

1
-<?
1
+<?php
2
 /*-- TODO ---------------------------//
2
 /*-- TODO ---------------------------//
3
 Writeup how to use the VALIDATE class, add in support for form id checks
3
 Writeup how to use the VALIDATE class, add in support for form id checks
4
 Complete the number and date validation
4
 Complete the number and date validation
5
 Remove the GenerateJS stuff
5
 Remove the GenerateJS stuff
6
 //-----------------------------------*/
6
 //-----------------------------------*/
7
 
7
 
8
-class VALIDATE {
9
-  var $Fields = [];
10
-
11
-  function SetFields($FieldName, $Required, $FieldType, $ErrorMessage, $Options = []) {
12
-    $this->Fields[$FieldName]['Type'] = strtolower($FieldType);
13
-    $this->Fields[$FieldName]['Required'] = $Required;
14
-    $this->Fields[$FieldName]['ErrorMessage'] = $ErrorMessage;
15
-    if (!empty($Options['maxlength'])) {
16
-      $this->Fields[$FieldName]['MaxLength'] = $Options['maxlength'];
17
-    }
18
-    if (!empty($Options['minlength'])) {
19
-      $this->Fields[$FieldName]['MinLength'] = $Options['minlength'];
20
-    }
21
-    if (!empty($Options['comparefield'])) {
22
-      $this->Fields[$FieldName]['CompareField'] = $Options['comparefield'];
23
-    }
24
-    if (!empty($Options['allowperiod'])) {
25
-      $this->Fields[$FieldName]['AllowPeriod'] = $Options['allowperiod'];
26
-    }
27
-    if (!empty($Options['allowcomma'])) {
28
-      $this->Fields[$FieldName]['AllowComma'] = $Options['allowcomma'];
29
-    }
30
-    if (!empty($Options['inarray'])) {
31
-      $this->Fields[$FieldName]['InArray'] = $Options['inarray'];
32
-    }
33
-    if (!empty($Options['regex'])) {
34
-      $this->Fields[$FieldName]['Regex'] = $Options['regex'];
35
-    }
36
-  }
37
-
38
-  function ValidateForm($ValidateArray) {
39
-    reset($this->Fields);
40
-    foreach ($this->Fields as $FieldKey => $Field) {
41
-      $ValidateVar = $ValidateArray[$FieldKey];
42
-
43
-      if ($ValidateVar != '' || !empty($Field['Required']) || $Field['Type'] == 'date') {
44
-        if ($Field['Type'] == 'string') {
45
-          if (isset($Field['MaxLength'])) {
46
-            $MaxLength = $Field['MaxLength'];
47
-          } else {
48
-            $MaxLength = 255;
49
-          }
50
-          if (isset($Field['MinLength'])) {
51
-            $MinLength = $Field['MinLength'];
52
-          } else {
53
-            $MinLength = 1;
54
-          }
55
-
56
-          if (strlen($ValidateVar) > $MaxLength) {
57
-            return $Field['ErrorMessage'];
58
-          } elseif (strlen($ValidateVar) < $MinLength) {
59
-            return $Field['ErrorMessage'];
60
-          }
61
-
62
-        } elseif ($Field['Type'] == 'number') {
63
-          if (isset($Field['MaxLength'])) {
64
-            $MaxLength = $Field['MaxLength'];
65
-          } else {
66
-            $MaxLength = '';
67
-          }
68
-          if (isset($Field['MinLength'])) {
69
-            $MinLength = $Field['MinLength'];
70
-          } else {
71
-            $MinLength = 0;
72
-          }
73
-
74
-          $Match = '0-9';
75
-          if (isset($Field['AllowPeriod'])) {
76
-            $Match .= '.';
77
-          }
78
-          if (isset($Field['AllowComma'])) {
79
-            $Match .= ',';
80
-          }
81
-
82
-          if (preg_match('/[^'.$Match.']/', $ValidateVar) || strlen($ValidateVar) < 1) {
83
-            return $Field['ErrorMessage'];
84
-          } elseif ($MaxLength != '' && $ValidateVar > $MaxLength) {
85
-            return $Field['ErrorMessage'].'!!';
86
-          } elseif ($ValidateVar < $MinLength) {
87
-            return $Field['ErrorMessage']."$MinLength";
88
-          }
89
-
90
-        } elseif ($Field['Type'] == 'email') {
91
-          if (isset($Field['MaxLength'])) {
92
-            $MaxLength = $Field['MaxLength'];
93
-          } else {
94
-            $MaxLength = 255;
95
-          }
96
-          if (isset($Field['MinLength'])) {
97
-            $MinLength = $Field['MinLength'];
98
-          } else {
99
-            $MinLength = 6;
100
-          }
101
-
102
-          if (!preg_match("/^".EMAIL_REGEX."$/i", $ValidateVar)) {
103
-            return $Field['ErrorMessage'];
104
-          } elseif (strlen($ValidateVar) > $MaxLength) {
105
-            return $Field['ErrorMessage'];
106
-          } elseif (strlen($ValidateVar) < $MinLength) {
107
-            return $Field['ErrorMessage'];
108
-          }
109
-
110
-        } elseif ($Field['Type'] == 'link') {
111
-          if (isset($Field['MaxLength'])) {
112
-            $MaxLength = $Field['MaxLength'];
113
-          } else {
114
-            $MaxLength = 255;
115
-          }
116
-          if (isset($Field['MinLength'])) {
117
-            $MinLength = $Field['MinLength'];
118
-          } else {
119
-            $MinLength = 10;
120
-          }
121
-
122
-          if (!preg_match('/^'.URL_REGEX.'$/i', $ValidateVar)) {
123
-            return $Field['ErrorMessage'];
124
-          } elseif (strlen($ValidateVar) > $MaxLength) {
125
-            return $Field['ErrorMessage'];
126
-          } elseif (strlen($ValidateVar) < $MinLength) {
127
-            return $Field['ErrorMessage'];
128
-          }
129
-
130
-        } elseif ($Field['Type'] == 'username') {
131
-          if (isset($Field['MaxLength'])) {
132
-            $MaxLength = $Field['MaxLength'];
133
-          } else {
134
-            $MaxLength = 20;
135
-          }
136
-          if (isset($Field['MinLength'])) {
137
-            $MinLength = $Field['MinLength'];
138
-          } else {
139
-            $MinLength = 1;
140
-          }
141
-
142
-          if (!preg_match(USERNAME_REGEX, $ValidateVar)) {
143
-            return $Field['ErrorMessage'];
144
-          } elseif (strlen($ValidateVar) > $MaxLength) {
145
-            return $Field['ErrorMessage'];
146
-          } elseif (strlen($ValidateVar) < $MinLength) {
147
-            return $Field['ErrorMessage'];
148
-          }
149
-
150
-        } elseif ($Field['Type'] == 'checkbox') {
151
-          if (!isset($ValidateArray[$FieldKey])) {
152
-            return $Field['ErrorMessage'];
153
-          }
154
-
155
-        } elseif ($Field['Type'] == 'compare') {
156
-          if ($ValidateArray[$Field['CompareField']] != $ValidateVar) {
157
-            return $Field['ErrorMessage'];
158
-          }
159
-
160
-        } elseif ($Field['Type'] == 'inarray') {
161
-          if (array_search($ValidateVar, $Field['InArray']) === false) {
162
-            return $Field['ErrorMessage'];
163
-          }
164
-
165
-        } elseif ($Field['Type'] == 'regex') {
166
-          if (!preg_match($Field['Regex'], $ValidateVar)) {
167
-            return $Field['ErrorMessage'];
168
-          }
169
-        }
170
-      }
171
-    } // while
172
-  } // function
173
-
174
-  function GenerateJS($FormID) {
175
-    $ReturnJS = "<script type=\"text/javascript\" language=\"javascript\">\r\n";
176
-    $ReturnJS .= "function formVal() {\r\n";
177
-    $ReturnJS .= "  clearErrors('$FormID');\r\n";
178
-
179
-    reset($this->Fields);
180
-    foreach ($this->Fields as $FieldKey => $Field) {
181
-      if ($Field['Type'] == 'string') {
182
-        $ValItem = '  if ($(\'#'.$FieldKey.'\').raw().value == ""';
183
-        if (!empty($Field['MaxLength'])) {
184
-          $ValItem .= ' || $(\'#'.$FieldKey.'\').raw().value.length > '.$Field['MaxLength'];
185
-        } else {
186
-          $ValItem .= ' || $(\'#'.$FieldKey.'\').raw().value.length > 255';
187
-        }
188
-        if (!empty($Field['MinLength'])) {
189
-          $ValItem .= ' || $(\'#'.$FieldKey.'\').raw().value.length < '.$Field['MinLength'];
8
+class VALIDATE
9
+{
10
+    public $Fields = [];
11
+
12
+    public function SetFields($FieldName, $Required, $FieldType, $ErrorMessage, $Options = [])
13
+    {
14
+        $this->Fields[$FieldName]['Type'] = strtolower($FieldType);
15
+        $this->Fields[$FieldName]['Required'] = $Required;
16
+        $this->Fields[$FieldName]['ErrorMessage'] = $ErrorMessage;
17
+        if (!empty($Options['maxlength'])) {
18
+            $this->Fields[$FieldName]['MaxLength'] = $Options['maxlength'];
190
         }
19
         }
191
-        $ValItem .= ') { return showError(\''.$FieldKey.'\',\''.$Field['ErrorMessage'].'\'); }'."\r\n";
192
-
193
-      } elseif ($Field['Type'] == 'number') {
194
-        $Match = '0-9';
195
-        if (!empty($Field['AllowPeriod'])) {
196
-          $Match .= '.';
197
-        }
198
-        if (!empty($Field['AllowComma'])) {
199
-          $Match .= ',';
200
-        }
201
-
202
-        $ValItem = '  if ($(\'#'.$FieldKey.'\').raw().value.match(/[^'.$Match.']/) || $(\'#'.$FieldKey.'\').raw().value.length < 1';
203
-        if (!empty($Field['MaxLength'])) {
204
-          $ValItem .= ' || $(\'#'.$FieldKey.'\').raw().value/1 > '.$Field['MaxLength'];
205
-        }
206
-        if (!empty($Field['MinLength'])) {
207
-          $ValItem .= ' || $(\'#'.$FieldKey.'\').raw().value/1 < '.$Field['MinLength'];
20
+        if (!empty($Options['minlength'])) {
21
+            $this->Fields[$FieldName]['MinLength'] = $Options['minlength'];
208
         }
22
         }
209
-        $ValItem .= ') { return showError(\''.$FieldKey.'\',\''.$Field['ErrorMessage'].'\'); }'."\r\n";
210
-
211
-      } elseif ($Field['Type'] == 'email') {
212
-        $ValItem = '  if (!validEmail($(\'#'.$FieldKey.'\').raw().value)';
213
-        if (!empty($Field['MaxLength'])) {
214
-          $ValItem .= ' || $(\'#'.$FieldKey.'\').raw().value.length > '.$Field['MaxLength'];
215
-        } else {
216
-          $ValItem .= ' || $(\'#'.$FieldKey.'\').raw().value.length > 255';
217
-        }
218
-        if (!empty($Field['MinLength'])) {
219
-          $ValItem .= ' || $(\'#'.$FieldKey.'\').raw().value.length < '.$Field['MinLength'];
220
-        } else {
221
-          $ValItem .= ' || $(\'#'.$FieldKey.'\').raw().value.length < 6';
23
+        if (!empty($Options['comparefield'])) {
24
+            $this->Fields[$FieldName]['CompareField'] = $Options['comparefield'];
222
         }
25
         }
223
-        $ValItem .= ') { return showError(\''.$FieldKey.'\',\''.$Field['ErrorMessage'].'\'); }'."\r\n";
224
-
225
-      } elseif ($Field['Type'] == 'link') {
226
-        $ValItem = '  if (!validLink($(\'#'.$FieldKey.'\').raw().value)';
227
-        if (!empty($Field['MaxLength'])) {
228
-          $ValItem .= ' || $(\'#'.$FieldKey.'\').raw().value.length > '.$Field['MaxLength'];
229
-        } else {
230
-          $ValItem .= ' || $(\'#'.$FieldKey.'\').raw().value.length > 255';
26
+        if (!empty($Options['allowperiod'])) {
27
+            $this->Fields[$FieldName]['AllowPeriod'] = $Options['allowperiod'];
231
         }
28
         }
232
-        if (!empty($Field['MinLength'])) {
233
-          $ValItem .= ' || $(\'#'.$FieldKey.'\').raw().value.length < '.$Field['MinLength'];
234
-        } else {
235
-          $ValItem .= ' || $(\'#'.$FieldKey.'\').raw().value.length < 10';
236
-        }
237
-        $ValItem .= ') { return showError(\''.$FieldKey.'\',\''.$Field['ErrorMessage'].'\'); }'."\r\n";
238
-
239
-      } elseif ($Field['Type'] == 'username') {
240
-        $ValItem = '  if ($(\'#'.$FieldKey.'\').raw().value.match(/[^a-zA-Z0-9_\-]/)';
241
-        if (!empty($Field['MaxLength'])) {
242
-          $ValItem .= ' || $(\'#'.$FieldKey.'\').raw().value.length > '.$Field['MaxLength'];
29
+        if (!empty($Options['allowcomma'])) {
30
+            $this->Fields[$FieldName]['AllowComma'] = $Options['allowcomma'];
243
         }
31
         }
244
-        if (!empty($Field['MinLength'])) {
245
-          $ValItem .= ' || $(\'#'.$FieldKey.'\').raw().value.length < '.$Field['MinLength'];
32
+        if (!empty($Options['inarray'])) {
33
+            $this->Fields[$FieldName]['InArray'] = $Options['inarray'];
246
         }
34
         }
247
-        $ValItem .= ') { return showError(\''.$FieldKey.'\',\''.$Field['ErrorMessage'].'\'); }'."\r\n";
248
-
249
-      } elseif ($Field['Type'] == 'regex') {
250
-        $ValItem = '  if (!$(\'#'.$FieldKey.'\').raw().value.match('.$Field['Regex'].')) { return showError(\''.$FieldKey.'\',\''.$Field['ErrorMessage'].'\'); }'."\r\n";
251
-
252
-      } elseif ($Field['Type'] == 'date') {
253
-        $DisplayError = $FieldKey.'month';
254
-        if (isset($Field['MinLength']) && $Field['MinLength'] == 3) {
255
-          $Day = '$(\'#'.$FieldKey.'day\').raw().value';
256
-          $DisplayError .= ",{$FieldKey}day";
257
-        } else {
258
-          $Day = '1';
35
+        if (!empty($Options['regex'])) {
36
+            $this->Fields[$FieldName]['Regex'] = $Options['regex'];
259
         }
37
         }
260
-        $DisplayError .= ",{$FieldKey}year";
261
-        $ValItemHold = '  if (!validDate($(\'#'.$FieldKey.'month\').raw().value+\'/\'+'.$Day.'+\'/\'+$(\'#'.$FieldKey.'year\').raw().value)) { return showError(\''.$DisplayError.'\',\''.$Field['ErrorMessage'].'\'); }'."\r\n";
38
+    }
262
 
39
 
263
-        if (empty($Field['Required'])) {
264
-          $ValItem = '  if ($(\'#'.$FieldKey.'month\').raw().value != ""';
265
-          if (isset($Field['MinLength']) && $Field['MinLength'] == 3) {
266
-            $ValItem .= ' || $(\'#'.$FieldKey.'day\').raw().value != ""';
40
+    public function ValidateForm($ValidateArray)
41
+    {
42
+        reset($this->Fields);
43
+        foreach ($this->Fields as $FieldKey => $Field) {
44
+            $ValidateVar = $ValidateArray[$FieldKey];
45
+
46
+            if ($ValidateVar !== '' || !empty($Field['Required']) || $Field['Type'] === 'date') {
47
+                if ($Field['Type'] === 'string') {
48
+                    if (isset($Field['MaxLength'])) {
49
+                        $MaxLength = $Field['MaxLength'];
50
+                    } else {
51
+                        $MaxLength = 255;
52
+                    }
53
+                    if (isset($Field['MinLength'])) {
54
+                        $MinLength = $Field['MinLength'];
55
+                    } else {
56
+                        $MinLength = 1;
57
+                    }
58
+
59
+                    if (strlen($ValidateVar) > $MaxLength) {
60
+                        return $Field['ErrorMessage'];
61
+                    } elseif (strlen($ValidateVar) < $MinLength) {
62
+                        return $Field['ErrorMessage'];
63
+                    }
64
+                } elseif ($Field['Type'] === 'number') {
65
+                    if (isset($Field['MaxLength'])) {
66
+                        $MaxLength = $Field['MaxLength'];
67
+                    } else {
68
+                        $MaxLength = '';
69
+                    }
70
+                    if (isset($Field['MinLength'])) {
71
+                        $MinLength = $Field['MinLength'];
72
+                    } else {
73
+                        $MinLength = 0;
74
+                    }
75
+
76
+                    $Match = '0-9';
77
+                    if (isset($Field['AllowPeriod'])) {
78
+                        $Match .= '.';
79
+                    }
80
+                    if (isset($Field['AllowComma'])) {
81
+                        $Match .= ',';
82
+                    }
83
+
84
+                    if (preg_match('/[^'.$Match.']/', $ValidateVar) || strlen($ValidateVar) < 1) {
85
+                        return $Field['ErrorMessage'];
86
+                    } elseif ($MaxLength !== '' && $ValidateVar > $MaxLength) {
87
+                        return $Field['ErrorMessage'].'!!';
88
+                    } elseif ($ValidateVar < $MinLength) {
89
+                        return $Field['ErrorMessage']."$MinLength";
90
+                    }
91
+                } elseif ($Field['Type'] === 'email') {
92
+                    if (isset($Field['MaxLength'])) {
93
+                        $MaxLength = $Field['MaxLength'];
94
+                    } else {
95
+                        $MaxLength = 255;
96
+                    }
97
+                    if (isset($Field['MinLength'])) {
98
+                        $MinLength = $Field['MinLength'];
99
+                    } else {
100
+                        $MinLength = 6;
101
+                    }
102
+
103
+                    if (!preg_match("/^".EMAIL_REGEX."$/i", $ValidateVar)) {
104
+                        return $Field['ErrorMessage'];
105
+                    } elseif (strlen($ValidateVar) > $MaxLength) {
106
+                        return $Field['ErrorMessage'];
107
+                    } elseif (strlen($ValidateVar) < $MinLength) {
108
+                        return $Field['ErrorMessage'];
109
+                    }
110
+                } elseif ($Field['Type'] === 'link') {
111
+                    if (isset($Field['MaxLength'])) {
112
+                        $MaxLength = $Field['MaxLength'];
113
+                    } else {
114
+                        $MaxLength = 255;
115
+                    }
116
+                    if (isset($Field['MinLength'])) {
117
+                        $MinLength = $Field['MinLength'];
118
+                    } else {
119
+                        $MinLength = 10;
120
+                    }
121
+
122
+                    if (!preg_match('/^'.URL_REGEX.'$/i', $ValidateVar)) {
123
+                        return $Field['ErrorMessage'];
124
+                    } elseif (strlen($ValidateVar) > $MaxLength) {
125
+                        return $Field['ErrorMessage'];
126
+                    } elseif (strlen($ValidateVar) < $MinLength) {
127
+                        return $Field['ErrorMessage'];
128
+                    }
129
+                } elseif ($Field['Type'] === 'username') {
130
+                    if (isset($Field['MaxLength'])) {
131
+                        $MaxLength = $Field['MaxLength'];
132
+                    } else {
133
+                        $MaxLength = 20;
134
+                    }
135
+                    if (isset($Field['MinLength'])) {
136
+                        $MinLength = $Field['MinLength'];
137
+                    } else {
138
+                        $MinLength = 1;
139
+                    }
140
+
141
+                    if (!preg_match(USERNAME_REGEX, $ValidateVar)) {
142
+                        return $Field['ErrorMessage'];
143
+                    } elseif (strlen($ValidateVar) > $MaxLength) {
144
+                        return $Field['ErrorMessage'];
145
+                    } elseif (strlen($ValidateVar) < $MinLength) {
146
+                        return $Field['ErrorMessage'];
147
+                    }
148
+                } elseif ($Field['Type'] === 'checkbox') {
149
+                    if (!isset($ValidateArray[$FieldKey])) {
150
+                        return $Field['ErrorMessage'];
151
+                    }
152
+                } elseif ($Field['Type'] === 'compare') {
153
+                    if ($ValidateArray[$Field['CompareField']] !== $ValidateVar) {
154
+                        return $Field['ErrorMessage'];
155
+                    }
156
+                } elseif ($Field['Type'] === 'inarray') {
157
+                    if (array_search($ValidateVar, $Field['InArray']) === false) {
158
+                        return $Field['ErrorMessage'];
159
+                    }
160
+                } elseif ($Field['Type'] === 'regex') {
161
+                    if (!preg_match($Field['Regex'], $ValidateVar)) {
162
+                        return $Field['ErrorMessage'];
163
+                    }
164
+                }
165
+            }
166
+        } // while
167
+    } // function
168
+
169
+  public function GenerateJS($FormID)
170
+  {
171
+      $ReturnJS = "<script type=\"text/javascript\" language=\"javascript\">\r\n";
172
+      $ReturnJS .= "function formVal() {\r\n";
173
+      $ReturnJS .= "  clearErrors('$FormID');\r\n";
174
+
175
+      reset($this->Fields);
176
+      foreach ($this->Fields as $FieldKey => $Field) {
177
+          if ($Field['Type'] === 'string') {
178
+              $ValItem = '  if ($(\'#'.$FieldKey.'\').raw().value === ""';
179
+              if (!empty($Field['MaxLength'])) {
180
+                  $ValItem .= ' || $(\'#'.$FieldKey.'\').raw().value.length > '.$Field['MaxLength'];
181
+              } else {
182
+                  $ValItem .= ' || $(\'#'.$FieldKey.'\').raw().value.length > 255';
183
+              }
184
+              if (!empty($Field['MinLength'])) {
185
+                  $ValItem .= ' || $(\'#'.$FieldKey.'\').raw().value.length < '.$Field['MinLength'];
186
+              }
187
+              $ValItem .= ') { return showError(\''.$FieldKey.'\',\''.$Field['ErrorMessage'].'\'); }'."\r\n";
188
+          } elseif ($Field['Type'] === 'number') {
189
+              $Match = '0-9';
190
+              if (!empty($Field['AllowPeriod'])) {
191
+                  $Match .= '.';
192
+              }
193
+              if (!empty($Field['AllowComma'])) {
194
+                  $Match .= ',';
195
+              }
196
+
197
+              $ValItem = '  if ($(\'#'.$FieldKey.'\').raw().value.match(/[^'.$Match.']/) || $(\'#'.$FieldKey.'\').raw().value.length < 1';
198
+              if (!empty($Field['MaxLength'])) {
199
+                  $ValItem .= ' || $(\'#'.$FieldKey.'\').raw().value/1 > '.$Field['MaxLength'];
200
+              }
201
+              if (!empty($Field['MinLength'])) {
202
+                  $ValItem .= ' || $(\'#'.$FieldKey.'\').raw().value/1 < '.$Field['MinLength'];
203
+              }
204
+              $ValItem .= ') { return showError(\''.$FieldKey.'\',\''.$Field['ErrorMessage'].'\'); }'."\r\n";
205
+          } elseif ($Field['Type'] === 'email') {
206
+              $ValItem = '  if (!validEmail($(\'#'.$FieldKey.'\').raw().value)';
207
+              if (!empty($Field['MaxLength'])) {
208
+                  $ValItem .= ' || $(\'#'.$FieldKey.'\').raw().value.length > '.$Field['MaxLength'];
209
+              } else {
210
+                  $ValItem .= ' || $(\'#'.$FieldKey.'\').raw().value.length > 255';
211
+              }
212
+              if (!empty($Field['MinLength'])) {
213
+                  $ValItem .= ' || $(\'#'.$FieldKey.'\').raw().value.length < '.$Field['MinLength'];
214
+              } else {
215
+                  $ValItem .= ' || $(\'#'.$FieldKey.'\').raw().value.length < 6';
216
+              }
217
+              $ValItem .= ') { return showError(\''.$FieldKey.'\',\''.$Field['ErrorMessage'].'\'); }'."\r\n";
218
+          } elseif ($Field['Type'] === 'link') {
219
+              $ValItem = '  if (!validLink($(\'#'.$FieldKey.'\').raw().value)';
220
+              if (!empty($Field['MaxLength'])) {
221
+                  $ValItem .= ' || $(\'#'.$FieldKey.'\').raw().value.length > '.$Field['MaxLength'];
222
+              } else {
223
+                  $ValItem .= ' || $(\'#'.$FieldKey.'\').raw().value.length > 255';
224
+              }
225
+              if (!empty($Field['MinLength'])) {
226
+                  $ValItem .= ' || $(\'#'.$FieldKey.'\').raw().value.length < '.$Field['MinLength'];
227
+              } else {
228
+                  $ValItem .= ' || $(\'#'.$FieldKey.'\').raw().value.length < 10';
229
+              }
230
+              $ValItem .= ') { return showError(\''.$FieldKey.'\',\''.$Field['ErrorMessage'].'\'); }'."\r\n";
231
+          } elseif ($Field['Type'] === 'username') {
232
+              $ValItem = '  if ($(\'#'.$FieldKey.'\').raw().value.match(/[^a-zA-Z0-9_\-]/)';
233
+              if (!empty($Field['MaxLength'])) {
234
+                  $ValItem .= ' || $(\'#'.$FieldKey.'\').raw().value.length > '.$Field['MaxLength'];
235
+              }
236
+              if (!empty($Field['MinLength'])) {
237
+                  $ValItem .= ' || $(\'#'.$FieldKey.'\').raw().value.length < '.$Field['MinLength'];
238
+              }
239
+              $ValItem .= ') { return showError(\''.$FieldKey.'\',\''.$Field['ErrorMessage'].'\'); }'."\r\n";
240
+          } elseif ($Field['Type'] === 'regex') {
241
+              $ValItem = '  if (!$(\'#'.$FieldKey.'\').raw().value.match('.$Field['Regex'].')) { return showError(\''.$FieldKey.'\',\''.$Field['ErrorMessage'].'\'); }'."\r\n";
242
+          } elseif ($Field['Type'] === 'date') {
243
+              $DisplayError = $FieldKey.'month';
244
+              if (isset($Field['MinLength']) && $Field['MinLength'] === 3) {
245
+                  $Day = '$(\'#'.$FieldKey.'day\').raw().value';
246
+                  $DisplayError .= ",{$FieldKey}day";
247
+              } else {
248
+                  $Day = '1';
249
+              }
250
+              $DisplayError .= ",{$FieldKey}year";
251
+              $ValItemHold = '  if (!validDate($(\'#'.$FieldKey.'month\').raw().value+\'/\'+'.$Day.'+\'/\'+$(\'#'.$FieldKey.'year\').raw().value)) { return showError(\''.$DisplayError.'\',\''.$Field['ErrorMessage'].'\'); }'."\r\n";
252
+
253
+              if (empty($Field['Required'])) {
254
+                  $ValItem = '  if ($(\'#'.$FieldKey.'month\').raw().value !== ""';
255
+                  if (isset($Field['MinLength']) && $Field['MinLength'] === 3) {
256
+                      $ValItem .= ' || $(\'#'.$FieldKey.'day\').raw().value !== ""';
257
+                  }
258
+                  $ValItem .= ' || $(\'#'.$FieldKey.'year\').raw().value !== "") {'."\r\n";
259
+                  $ValItem .= $ValItemHold;
260
+                  $ValItem .= " }\r\n";
261
+              } else {
262
+                  $ValItem .= $ValItemHold;
263
+              }
264
+          } elseif ($Field['Type'] === 'checkbox') {
265
+              $ValItem = '  if (!$(\'#'.$FieldKey.'\').checked) { return showError(\''.$FieldKey.'\',\''.$Field['ErrorMessage'].'\'); }'."\r\n";
266
+          } elseif ($Field['Type'] === 'compare') {
267
+              $ValItem = '  if ($(\'#'.$FieldKey.'\').raw().value!==$(\'#'.$Field['CompareField'].'\').raw().value) { return showError(\''.$FieldKey.','.$Field['CompareField'].'\',\''.$Field['ErrorMessage'].'\'); }'."\r\n";
267
           }
268
           }
268
-          $ValItem .= ' || $(\'#'.$FieldKey.'year\').raw().value != "") {'."\r\n";
269
-          $ValItem .= $ValItemHold;
270
-          $ValItem .= " }\r\n";
271
-        } else {
272
-          $ValItem .= $ValItemHold;
273
-        }
274
-
275
-      } elseif ($Field['Type'] == 'checkbox') {
276
-        $ValItem = '  if (!$(\'#'.$FieldKey.'\').checked) { return showError(\''.$FieldKey.'\',\''.$Field['ErrorMessage'].'\'); }'."\r\n";
277
 
269
 
278
-      } elseif ($Field['Type'] == 'compare') {
279
-        $ValItem = '  if ($(\'#'.$FieldKey.'\').raw().value!=$(\'#'.$Field['CompareField'].'\').raw().value) { return showError(\''.$FieldKey.','.$Field['CompareField'].'\',\''.$Field['ErrorMessage'].'\'); }'."\r\n";
280
-      }
281
-
282
-      if (empty($Field['Required']) && $Field['Type'] != 'date') {
283
-        $ReturnJS .= '  if ($(\'#'.$FieldKey.'\').raw().value!="") {'."\r\n ";
284
-        $ReturnJS .= $ValItem;
285
-        $ReturnJS .= "  }\r\n";
286
-      } else {
287
-        $ReturnJS .= $ValItem;
270
+          if (empty($Field['Required']) && $Field['Type'] !== 'date') {
271
+              $ReturnJS .= '  if ($(\'#'.$FieldKey.'\').raw().value!=="") {'."\r\n ";
272
+              $ReturnJS .= $ValItem;
273
+              $ReturnJS .= "  }\r\n";
274
+          } else {
275
+              $ReturnJS .= $ValItem;
276
+          }
277
+          $ValItem = '';
288
       }
278
       }
289
-      $ValItem = '';
290
-    }
291
 
279
 
292
-    $ReturnJS .= "}\r\n";
293
-    $ReturnJS .= "</script>\r\n";
294
-    return $ReturnJS;
280
+      $ReturnJS .= "}\r\n";
281
+      $ReturnJS .= "</script>\r\n";
282
+      return $ReturnJS;
295
   }
283
   }
296
 }
284
 }
297
-?>

+ 361
- 293
sections/upload/upload_handle.php
File diff suppressed because it is too large
View File


Loading…
Cancel
Save