|
1
|
|
|
<?php |
|
2
|
|
|
/* For licensing terms, see /license.txt */ |
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* Class FormValidator |
|
6
|
|
|
* create/manipulate/validate user input. |
|
7
|
|
|
*/ |
|
8
|
|
|
class FormValidator extends HTML_QuickForm |
|
9
|
|
|
{ |
|
10
|
|
|
const LAYOUT_HORIZONTAL = 'horizontal'; |
|
11
|
|
|
const LAYOUT_INLINE = 'inline'; |
|
12
|
|
|
const LAYOUT_BOX = 'box'; |
|
13
|
|
|
const LAYOUT_BOX_NO_LABEL = 'box-no-label'; |
|
14
|
|
|
|
|
15
|
|
|
public $with_progress_bar = false; |
|
16
|
|
|
private $layout; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Constructor |
|
20
|
|
|
* @param string $name Name of the form |
|
21
|
|
|
* @param string $method (optional Method ('post' (default) or 'get') |
|
22
|
|
|
* @param string $action (optional Action (default is $PHP_SELF) |
|
23
|
|
|
* @param string $target (optional Form's target defaults to '_self' |
|
24
|
|
|
* @param mixed $attributes (optional) Extra attributes for <form> tag |
|
25
|
|
|
* @param string $layout |
|
26
|
|
|
* @param bool $trackSubmit (optional) Whether to track if the form was |
|
27
|
|
|
* submitted by adding a special hidden field (default = true) |
|
28
|
|
|
*/ |
|
29
|
|
|
public function __construct( |
|
30
|
|
|
$name, |
|
31
|
|
|
$method = 'post', |
|
32
|
|
|
$action = '', |
|
33
|
|
|
$target = '', |
|
34
|
|
|
$attributes = array(), |
|
35
|
|
|
$layout = self::LAYOUT_HORIZONTAL, |
|
36
|
|
|
$trackSubmit = true |
|
37
|
|
|
) { |
|
38
|
|
|
// Default form class. |
|
39
|
|
|
if (is_array($attributes) && !isset($attributes['class']) || empty($attributes)) { |
|
40
|
|
|
$attributes['class'] = 'form-horizontal'; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
if (isset($attributes['class']) && strpos($attributes['class'], 'form-search') !== false) { |
|
44
|
|
|
$layout = 'inline'; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
$this->setLayout($layout); |
|
48
|
|
|
|
|
49
|
|
|
switch ($layout) { |
|
50
|
|
|
case self::LAYOUT_HORIZONTAL: |
|
51
|
|
|
$attributes['class'] = 'form-horizontal'; |
|
52
|
|
|
break; |
|
53
|
|
|
case self::LAYOUT_INLINE: |
|
54
|
|
|
case self::LAYOUT_BOX: |
|
55
|
|
|
$attributes['class'] = 'form-inline'; |
|
56
|
|
|
break; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
parent::__construct($name, $method, $action, $target, $attributes, $trackSubmit); |
|
60
|
|
|
|
|
61
|
|
|
// Modify the default templates |
|
62
|
|
|
$renderer = & $this->defaultRenderer(); |
|
63
|
|
|
|
|
64
|
|
|
// Form template |
|
65
|
|
|
$formTemplate = $this->getFormTemplate(); |
|
66
|
|
|
$renderer->setFormTemplate($formTemplate); |
|
67
|
|
|
|
|
68
|
|
|
// Element template |
|
69
|
|
|
if (isset($attributes['class']) && $attributes['class'] == 'form-inline') { |
|
70
|
|
|
$elementTemplate = ' {label} {element} '; |
|
71
|
|
|
$renderer->setElementTemplate($elementTemplate); |
|
72
|
|
|
} elseif (isset($attributes['class']) && $attributes['class'] == 'form-search') { |
|
73
|
|
|
$elementTemplate = ' {label} {element} '; |
|
74
|
|
|
$renderer->setElementTemplate($elementTemplate); |
|
75
|
|
|
} else { |
|
76
|
|
|
$renderer->setElementTemplate($this->getDefaultElementTemplate()); |
|
77
|
|
|
|
|
78
|
|
|
// Display a gray div in the buttons |
|
79
|
|
|
$templateSimple = '<div class="form-actions">{label} {element}</div>'; |
|
80
|
|
|
$renderer->setElementTemplate($templateSimple, 'submit_in_actions'); |
|
81
|
|
|
|
|
82
|
|
|
//Display a gray div in the buttons + makes the button available when scrolling |
|
83
|
|
|
$templateBottom = '<div class="form-actions bottom_actions bg-form">{label} {element}</div>'; |
|
84
|
|
|
$renderer->setElementTemplate($templateBottom, 'submit_fixed_in_bottom'); |
|
85
|
|
|
|
|
86
|
|
|
//When you want to group buttons use something like this |
|
87
|
|
|
/* $group = array(); |
|
88
|
|
|
$group[] = $form->createElement('button', 'mark_all', get_lang('MarkAll')); |
|
89
|
|
|
$group[] = $form->createElement('button', 'unmark_all', get_lang('UnmarkAll')); |
|
90
|
|
|
$form->addGroup($group, 'buttons_in_action'); |
|
91
|
|
|
*/ |
|
92
|
|
|
$renderer->setElementTemplate($templateSimple, 'buttons_in_action'); |
|
93
|
|
|
|
|
94
|
|
|
$templateSimpleRight = '<div class="form-actions"> <div class="pull-right">{label} {element}</div></div>'; |
|
95
|
|
|
$renderer->setElementTemplate($templateSimpleRight, 'buttons_in_action_right'); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
//Set Header template |
|
99
|
|
|
$renderer->setHeaderTemplate('<legend>{header}</legend>'); |
|
100
|
|
|
|
|
101
|
|
|
//Set required field template |
|
102
|
|
|
$this->setRequiredNote('<span class="form_required">*</span> <small>' . get_lang('ThisFieldIsRequired') . '</small>'); |
|
103
|
|
|
$noteTemplate = <<<EOT |
|
104
|
|
|
<div class="form-group"> |
|
105
|
|
|
<div class="col-sm-offset-2 col-sm-10">{requiredNote}</div> |
|
106
|
|
|
</div> |
|
107
|
|
|
EOT; |
|
108
|
|
|
$renderer->setRequiredNoteTemplate($noteTemplate); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* @return string |
|
113
|
|
|
*/ |
|
114
|
|
|
public function getFormTemplate() |
|
115
|
|
|
{ |
|
116
|
|
|
return '<form{attributes}> |
|
117
|
|
|
<fieldset> |
|
118
|
|
|
{content} |
|
119
|
|
|
</fieldset> |
|
120
|
|
|
{hidden} |
|
121
|
|
|
</form>'; |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* @return string |
|
126
|
|
|
*/ |
|
127
|
|
|
public function getDefaultElementTemplate() |
|
128
|
|
|
{ |
|
129
|
|
|
return ' |
|
130
|
|
|
<div class="form-group {error_class}"> |
|
131
|
|
|
<label {label-for} class="col-sm-2 control-label" > |
|
132
|
|
|
<!-- BEGIN required --><span class="form_required">*</span><!-- END required --> |
|
133
|
|
|
{label} |
|
134
|
|
|
</label> |
|
135
|
|
|
<div class="col-sm-8"> |
|
136
|
|
|
{icon} |
|
137
|
|
|
{element} |
|
138
|
|
|
|
|
139
|
|
|
<!-- BEGIN label_2 --> |
|
140
|
|
|
<p class="help-block">{label_2}</p> |
|
141
|
|
|
<!-- END label_2 --> |
|
142
|
|
|
|
|
143
|
|
|
<!-- BEGIN error --> |
|
144
|
|
|
<span class="help-inline">{error}</span> |
|
145
|
|
|
<!-- END error --> |
|
146
|
|
|
</div> |
|
147
|
|
|
<div class="col-sm-2"> |
|
148
|
|
|
<!-- BEGIN label_3 --> |
|
149
|
|
|
{label_3} |
|
150
|
|
|
<!-- END label_3 --> |
|
151
|
|
|
</div> |
|
152
|
|
|
</div>'; |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
/** |
|
156
|
|
|
* @return string |
|
157
|
|
|
*/ |
|
158
|
|
|
public function getLayout() |
|
159
|
|
|
{ |
|
160
|
|
|
return $this->layout; |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
/** |
|
164
|
|
|
* @param string $layout |
|
165
|
|
|
*/ |
|
166
|
|
|
public function setLayout($layout) |
|
167
|
|
|
{ |
|
168
|
|
|
$this->layout = $layout; |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
/** |
|
172
|
|
|
* Adds a text field to the form. |
|
173
|
|
|
* A trim-filter is attached to the field. |
|
174
|
|
|
* @param string $label The label for the form-element |
|
175
|
|
|
* @param string $name The element name |
|
176
|
|
|
* @param bool $required (optional) Is the form-element required (default=true) |
|
177
|
|
|
* @param array $attributes (optional) List of attributes for the form-element |
|
178
|
|
|
*/ |
|
179
|
|
|
public function addText($name, $label, $required = true, $attributes = array()) |
|
180
|
|
|
{ |
|
181
|
|
|
$this->addElement('text', $name, $label, $attributes); |
|
182
|
|
|
$this->applyFilter($name, 'trim'); |
|
183
|
|
|
if ($required) { |
|
184
|
|
|
$this->addRule($name, get_lang('ThisFieldIsRequired'), 'required'); |
|
185
|
|
|
} |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
/** |
|
189
|
|
|
* The "date_range_picker" element creates 2 hidden fields |
|
190
|
|
|
* "elementName" + "_start" and "elementName" + "_end" |
|
191
|
|
|
* For example if the name is "range", you will have 2 new fields |
|
192
|
|
|
* when executing $form->getSubmitValues() |
|
193
|
|
|
* "range_start" and "range_end" |
|
194
|
|
|
* |
|
195
|
|
|
* @param string $name |
|
196
|
|
|
* @param string $label |
|
197
|
|
|
* @param bool $required |
|
198
|
|
|
* @param array $attributes |
|
199
|
|
|
*/ |
|
200
|
|
View Code Duplication |
public function addDateRangePicker($name, $label, $required = true, $attributes = array()) |
|
201
|
|
|
{ |
|
202
|
|
|
$this->addElement('date_range_picker', $name, $label, $attributes); |
|
203
|
|
|
$this->addElement('hidden', $name.'_start'); |
|
204
|
|
|
$this->addElement('hidden', $name.'_end'); |
|
205
|
|
|
|
|
206
|
|
|
if ($required) { |
|
207
|
|
|
$this->addRule($name, get_lang('ThisFieldIsRequired'), 'required'); |
|
208
|
|
|
} |
|
209
|
|
|
} |
|
210
|
|
|
|
|
211
|
|
|
/** |
|
212
|
|
|
* @param string $name |
|
213
|
|
|
* @param string $label |
|
214
|
|
|
* @param array $attributes |
|
215
|
|
|
* |
|
216
|
|
|
* @return mixed |
|
217
|
|
|
*/ |
|
218
|
|
|
public function addDatePicker($name, $label, $attributes = []) |
|
219
|
|
|
{ |
|
220
|
|
|
return $this->addElement('DatePicker', $name, $label, $attributes); |
|
221
|
|
|
} |
|
222
|
|
|
|
|
223
|
|
|
/** |
|
224
|
|
|
* @param string $name |
|
225
|
|
|
* @param string $label |
|
226
|
|
|
* @param array $attributes |
|
227
|
|
|
* |
|
228
|
|
|
* @return mixed |
|
229
|
|
|
*/ |
|
230
|
|
|
public function addDateTimePicker($name, $label, $attributes = []) |
|
231
|
|
|
{ |
|
232
|
|
|
return $this->addElement('DateTimePicker', $name, $label, $attributes); |
|
233
|
|
|
} |
|
234
|
|
|
|
|
235
|
|
|
/** |
|
236
|
|
|
* @param string $name |
|
237
|
|
|
* @param string $value |
|
238
|
|
|
*/ |
|
239
|
|
|
public function addHidden($name, $value) |
|
240
|
|
|
{ |
|
241
|
|
|
$this->addElement('hidden', $name, $value); |
|
242
|
|
|
} |
|
243
|
|
|
|
|
244
|
|
|
/** |
|
245
|
|
|
* @param string $name |
|
246
|
|
|
* @param string $label |
|
247
|
|
|
* @param array $attributes |
|
248
|
|
|
* |
|
249
|
|
|
* @return HTML_QuickForm_textarea |
|
250
|
|
|
*/ |
|
251
|
|
|
public function addTextarea($name, $label, $attributes = array()) |
|
252
|
|
|
{ |
|
253
|
|
|
return $this->addElement('textarea', $name, $label, $attributes); |
|
254
|
|
|
} |
|
255
|
|
|
|
|
256
|
|
|
/** |
|
257
|
|
|
* @param string $name |
|
258
|
|
|
* @param string $label |
|
259
|
|
|
* @param string $icon font-awesome |
|
260
|
|
|
* @param string $style default|primary|success|info|warning|danger|link |
|
261
|
|
|
* @param string $size large|default|small|extra-small |
|
262
|
|
|
* @param string $class Example plus is transformed to icon fa fa-plus |
|
263
|
|
|
* @param array $attributes |
|
264
|
|
|
* |
|
265
|
|
|
* @return HTML_QuickForm_button |
|
266
|
|
|
*/ |
|
267
|
|
|
public function addButton( |
|
268
|
|
|
$name, |
|
269
|
|
|
$label, |
|
270
|
|
|
$icon = 'check', |
|
271
|
|
|
$style = 'default', |
|
272
|
|
|
$size = 'default', |
|
273
|
|
|
$class = null, |
|
274
|
|
|
$attributes = array(), |
|
275
|
|
|
$createElement = false |
|
276
|
|
|
) { |
|
277
|
|
|
if ($createElement) { |
|
278
|
|
|
return $this->createElement( |
|
279
|
|
|
'button', |
|
280
|
|
|
$name, |
|
281
|
|
|
$label, |
|
282
|
|
|
$icon, |
|
283
|
|
|
$style, |
|
284
|
|
|
$size, |
|
285
|
|
|
$class, |
|
286
|
|
|
$attributes |
|
287
|
|
|
); |
|
288
|
|
|
} |
|
289
|
|
|
|
|
290
|
|
|
return $this->addElement( |
|
291
|
|
|
'button', |
|
292
|
|
|
$name, |
|
293
|
|
|
$label, |
|
294
|
|
|
$icon, |
|
295
|
|
|
$style, |
|
296
|
|
|
$size, |
|
297
|
|
|
$class, |
|
298
|
|
|
$attributes |
|
299
|
|
|
); |
|
300
|
|
|
} |
|
301
|
|
|
|
|
302
|
|
|
/** |
|
303
|
|
|
* Returns a button with the primary color and a check mark |
|
304
|
|
|
* @param string $label Text appearing on the button |
|
305
|
|
|
* @param string $name Element name (for form treatment purposes) |
|
306
|
|
|
* @param bool $createElement Whether to use the create or add method |
|
307
|
|
|
* |
|
308
|
|
|
* @return HTML_QuickForm_button |
|
309
|
|
|
*/ |
|
310
|
|
|
public function addButtonSave($label, $name = 'submit', $createElement = false) |
|
311
|
|
|
{ |
|
312
|
|
|
return $this->addButton( |
|
313
|
|
|
$name, |
|
314
|
|
|
$label, |
|
315
|
|
|
'check', |
|
316
|
|
|
'primary', |
|
317
|
|
|
null, |
|
318
|
|
|
null, |
|
319
|
|
|
array(), |
|
320
|
|
|
$createElement |
|
321
|
|
|
); |
|
322
|
|
|
} |
|
323
|
|
|
|
|
324
|
|
|
/** |
|
325
|
|
|
* Returns a cancel button |
|
326
|
|
|
* @param string $label Text appearing on the button |
|
327
|
|
|
* @param string $name Element name (for form treatment purposes) |
|
328
|
|
|
* @param bool $createElement Whether to use the create or add method |
|
329
|
|
|
* |
|
330
|
|
|
* @return HTML_QuickForm_button |
|
331
|
|
|
*/ |
|
332
|
|
|
public function addButtonCancel($label, $name = 'submit', $createElement = false) |
|
333
|
|
|
{ |
|
334
|
|
|
return $this->addButton( |
|
335
|
|
|
$name, |
|
336
|
|
|
$label, |
|
337
|
|
|
'times', |
|
338
|
|
|
'danger', |
|
339
|
|
|
null, |
|
340
|
|
|
null, |
|
341
|
|
|
array(), |
|
342
|
|
|
$createElement |
|
343
|
|
|
); |
|
344
|
|
|
} |
|
345
|
|
|
|
|
346
|
|
|
/** |
|
347
|
|
|
* Returns a button with the primary color and a "plus" icon |
|
348
|
|
|
* @param string $label Text appearing on the button |
|
349
|
|
|
* @param string $name Element name (for form treatment purposes) |
|
350
|
|
|
* @param bool $createElement Whether to use the create or add method |
|
351
|
|
|
* @param array $attributes Additional attributes |
|
352
|
|
|
* |
|
353
|
|
|
* @return HTML_QuickForm_button |
|
354
|
|
|
*/ |
|
355
|
|
|
public function addButtonCreate($label, $name = 'submit', $createElement = false, $attributes = array()) |
|
356
|
|
|
{ |
|
357
|
|
|
return $this->addButton( |
|
358
|
|
|
$name, |
|
359
|
|
|
$label, |
|
360
|
|
|
'plus', |
|
361
|
|
|
'primary', |
|
362
|
|
|
null, |
|
363
|
|
|
null, |
|
364
|
|
|
$attributes, |
|
365
|
|
|
$createElement |
|
366
|
|
|
); |
|
367
|
|
|
} |
|
368
|
|
|
|
|
369
|
|
|
/** |
|
370
|
|
|
* Returns a button with the primary color and a pencil icon |
|
371
|
|
|
* @param string $label Text appearing on the button |
|
372
|
|
|
* @param string $name Element name (for form treatment purposes) |
|
373
|
|
|
* @param bool $createElement Whether to use the create or add method |
|
374
|
|
|
* @return HTML_QuickForm_button |
|
375
|
|
|
*/ |
|
376
|
|
|
public function addButtonUpdate($label, $name = 'submit', $createElement = false) |
|
377
|
|
|
{ |
|
378
|
|
|
return $this->addButton( |
|
379
|
|
|
$name, |
|
380
|
|
|
$label, |
|
381
|
|
|
'pencil', |
|
382
|
|
|
'primary', |
|
383
|
|
|
null, |
|
384
|
|
|
null, |
|
385
|
|
|
array(), |
|
386
|
|
|
$createElement |
|
387
|
|
|
); |
|
388
|
|
|
} |
|
389
|
|
|
|
|
390
|
|
|
/** |
|
391
|
|
|
* Returns a button with the danger color and a trash icon |
|
392
|
|
|
* @param string $label Text appearing on the button |
|
393
|
|
|
* @param string $name Element name (for form treatment purposes) |
|
394
|
|
|
* @param bool $createElement Whether to use the create or add method |
|
395
|
|
|
* |
|
396
|
|
|
* @return HTML_QuickForm_button |
|
397
|
|
|
*/ |
|
398
|
|
|
public function addButtonDelete($label, $name = 'submit', $createElement = false) |
|
399
|
|
|
{ |
|
400
|
|
|
return $this->addButton( |
|
401
|
|
|
$name, |
|
402
|
|
|
$label, |
|
403
|
|
|
'trash', |
|
404
|
|
|
'danger', |
|
405
|
|
|
null, |
|
406
|
|
|
null, |
|
407
|
|
|
array(), |
|
408
|
|
|
$createElement |
|
409
|
|
|
); |
|
410
|
|
|
} |
|
411
|
|
|
|
|
412
|
|
|
/** |
|
413
|
|
|
* Returns a button with the primary color and a paper-plane icon |
|
414
|
|
|
* @param string $label Text appearing on the button |
|
415
|
|
|
* @param string $name Element name (for form treatment purposes) |
|
416
|
|
|
* @param bool $createElement Whether to use the create or add method |
|
417
|
|
|
* |
|
418
|
|
|
* @return HTML_QuickForm_button |
|
419
|
|
|
*/ |
|
420
|
|
|
public function addButtonSend($label, $name = 'submit', $createElement = false, $attributes = array()) |
|
421
|
|
|
{ |
|
422
|
|
|
return $this->addButton( |
|
423
|
|
|
$name, |
|
424
|
|
|
$label, |
|
425
|
|
|
'paper-plane', |
|
426
|
|
|
'primary', |
|
427
|
|
|
null, |
|
428
|
|
|
null, |
|
429
|
|
|
$attributes, |
|
430
|
|
|
$createElement |
|
431
|
|
|
); |
|
432
|
|
|
} |
|
433
|
|
|
|
|
434
|
|
|
/** |
|
435
|
|
|
* Returns a button with the default (grey?) color and a magnifier icon |
|
436
|
|
|
* @param string $label Text appearing on the button |
|
437
|
|
|
* @param string $name Element name (for form treatment purposes) |
|
438
|
|
|
* |
|
439
|
|
|
* @return HTML_QuickForm_button |
|
440
|
|
|
*/ |
|
441
|
|
|
public function addButtonSearch($label = null, $name = 'submit') |
|
442
|
|
|
{ |
|
443
|
|
|
if (empty($label)) { |
|
444
|
|
|
$label = get_lang('Search'); |
|
445
|
|
|
} |
|
446
|
|
|
|
|
447
|
|
|
return $this->addButton($name, $label, 'search', 'default'); |
|
448
|
|
|
} |
|
449
|
|
|
|
|
450
|
|
|
/** |
|
451
|
|
|
* Returns a button with the primary color and a right-pointing arrow icon |
|
452
|
|
|
* @param string $label Text appearing on the button |
|
453
|
|
|
* @param string $name Element name (for form treatment purposes) |
|
454
|
|
|
* @param array $attributes Additional attributes |
|
455
|
|
|
* @return HTML_QuickForm_button |
|
456
|
|
|
*/ |
|
457
|
|
|
public function addButtonNext($label, $name = 'submit', $attributes = array()) |
|
458
|
|
|
{ |
|
459
|
|
|
return $this->addButton($name, $label, 'arrow-right', 'primary', null, null, $attributes); |
|
460
|
|
|
} |
|
461
|
|
|
|
|
462
|
|
|
/** |
|
463
|
|
|
* Returns a button with the primary color and a check mark icon |
|
464
|
|
|
* @param string $label Text appearing on the button |
|
465
|
|
|
* @param string $name Element name (for form treatment purposes) |
|
466
|
|
|
* @param bool $createElement Whether to use the create or add method |
|
467
|
|
|
* @return HTML_QuickForm_button |
|
468
|
|
|
*/ |
|
469
|
|
|
public function addButtonImport($label, $name = 'submit', $createElement = false) |
|
470
|
|
|
{ |
|
471
|
|
|
return $this->addButton( |
|
472
|
|
|
$name, |
|
473
|
|
|
$label, |
|
474
|
|
|
'check', |
|
475
|
|
|
'primary', |
|
476
|
|
|
null, |
|
477
|
|
|
null, |
|
478
|
|
|
array(), |
|
479
|
|
|
$createElement |
|
480
|
|
|
); |
|
481
|
|
|
} |
|
482
|
|
|
|
|
483
|
|
|
/** |
|
484
|
|
|
* Returns a button with the primary color and a check-mark icon |
|
485
|
|
|
* @param string $label Text appearing on the button |
|
486
|
|
|
* @param string $name Element name (for form treatment purposes) |
|
487
|
|
|
* @param bool $createElement Whether to use the create or add method |
|
488
|
|
|
* @return HTML_QuickForm_button |
|
489
|
|
|
*/ |
|
490
|
|
|
public function addButtonExport($label, $name = 'submit', $createElement = false) |
|
491
|
|
|
{ |
|
492
|
|
|
return $this->addButton( |
|
493
|
|
|
$name, |
|
494
|
|
|
$label, |
|
495
|
|
|
'check', |
|
496
|
|
|
'primary', |
|
497
|
|
|
null, |
|
498
|
|
|
null, |
|
499
|
|
|
array(), |
|
500
|
|
|
$createElement |
|
501
|
|
|
); |
|
502
|
|
|
} |
|
503
|
|
|
|
|
504
|
|
|
/** |
|
505
|
|
|
* Shortcut to filter button |
|
506
|
|
|
* @param string $label Text appearing on the button |
|
507
|
|
|
* @param string $name Element name (for form treatment purposes) |
|
508
|
|
|
* @param bool $createElement Whether to use the create or add method |
|
509
|
|
|
* @return HTML_QuickForm_button |
|
510
|
|
|
*/ |
|
511
|
|
|
public function addButtonFilter($label, $name = 'submit', $createElement = false) |
|
512
|
|
|
{ |
|
513
|
|
|
return $this->addButton( |
|
514
|
|
|
$name, |
|
515
|
|
|
$label, |
|
516
|
|
|
'filter', |
|
517
|
|
|
'primary', |
|
518
|
|
|
null, |
|
519
|
|
|
null, |
|
520
|
|
|
array(), |
|
521
|
|
|
$createElement |
|
522
|
|
|
); |
|
523
|
|
|
} |
|
524
|
|
|
|
|
525
|
|
|
/** |
|
526
|
|
|
* Shortcut to reset button |
|
527
|
|
|
* @param string $label Text appearing on the button |
|
528
|
|
|
* @param string $name Element name (for form treatment purposes) |
|
529
|
|
|
* @param bool $createElement Whether to use the create or add method |
|
530
|
|
|
* @return HTML_QuickForm_button |
|
531
|
|
|
*/ |
|
532
|
|
|
public function addButtonReset($label, $name = 'reset', $createElement = false) |
|
533
|
|
|
{ |
|
534
|
|
|
$icon = 'eraser'; |
|
535
|
|
|
$style = 'default'; |
|
536
|
|
|
$size = 'default'; |
|
537
|
|
|
$class = null; |
|
538
|
|
|
$attributes = array(); |
|
539
|
|
|
|
|
540
|
|
|
if ($createElement) { |
|
541
|
|
|
return $this->createElement( |
|
542
|
|
|
'reset', |
|
543
|
|
|
$name, |
|
544
|
|
|
$label, |
|
545
|
|
|
$icon, |
|
546
|
|
|
$style, |
|
547
|
|
|
$size, |
|
548
|
|
|
$class, |
|
549
|
|
|
$attributes |
|
550
|
|
|
); |
|
551
|
|
|
} |
|
552
|
|
|
|
|
553
|
|
|
return $this->addElement( |
|
554
|
|
|
'reset', |
|
555
|
|
|
$name, |
|
556
|
|
|
$label, |
|
557
|
|
|
$icon, |
|
558
|
|
|
$style, |
|
559
|
|
|
$size, |
|
560
|
|
|
$class, |
|
561
|
|
|
$attributes |
|
562
|
|
|
); |
|
563
|
|
|
} |
|
564
|
|
|
|
|
565
|
|
|
/** |
|
566
|
|
|
* Returns a button with the primary color and an upload icon |
|
567
|
|
|
* @param string $label Text appearing on the button |
|
568
|
|
|
* @param string $name Element name (for form treatment purposes) |
|
569
|
|
|
* @param bool $createElement Whether to use the create or add method |
|
570
|
|
|
* |
|
571
|
|
|
* @return HTML_QuickForm_button |
|
572
|
|
|
*/ |
|
573
|
|
|
public function addButtonUpload($label, $name = 'submit', $createElement = false) |
|
574
|
|
|
{ |
|
575
|
|
|
return $this->addButton( |
|
576
|
|
|
$name, |
|
577
|
|
|
$label, |
|
578
|
|
|
'upload', |
|
579
|
|
|
'primary', |
|
580
|
|
|
null, |
|
581
|
|
|
null, |
|
582
|
|
|
array(), |
|
583
|
|
|
$createElement |
|
584
|
|
|
); |
|
585
|
|
|
} |
|
586
|
|
|
|
|
587
|
|
|
/** |
|
588
|
|
|
* Returns a button with the primary color and a download icon |
|
589
|
|
|
* @param string $label Text appearing on the button |
|
590
|
|
|
* @param string $name Element name (for form treatment purposes) |
|
591
|
|
|
* @param bool $createElement Whether to use the create or add method |
|
592
|
|
|
* |
|
593
|
|
|
* @return HTML_QuickForm_button |
|
594
|
|
|
*/ |
|
595
|
|
|
public function addButtonDownload($label, $name = 'submit', $createElement = false) |
|
596
|
|
|
{ |
|
597
|
|
|
return $this->addButton( |
|
598
|
|
|
$name, |
|
599
|
|
|
$label, |
|
600
|
|
|
'download', |
|
601
|
|
|
'primary', |
|
602
|
|
|
null, |
|
603
|
|
|
null, |
|
604
|
|
|
array(), |
|
605
|
|
|
$createElement |
|
606
|
|
|
); |
|
607
|
|
|
} |
|
608
|
|
|
|
|
609
|
|
|
/** |
|
610
|
|
|
* Returns a button with the primary color and a magnifier icon |
|
611
|
|
|
* @param string $label Text appearing on the button |
|
612
|
|
|
* @param string $name Element name (for form treatment purposes) |
|
613
|
|
|
* @param bool $createElement Whether to use the create or add method |
|
614
|
|
|
* |
|
615
|
|
|
* @return HTML_QuickForm_button |
|
616
|
|
|
*/ |
|
617
|
|
View Code Duplication |
public function addButtonPreview($label, $name = 'submit', $createElement = false) |
|
618
|
|
|
{ |
|
619
|
|
|
return $this->addButton( |
|
620
|
|
|
$name, |
|
621
|
|
|
$label, |
|
622
|
|
|
'search', |
|
623
|
|
|
'primary', |
|
624
|
|
|
null, |
|
625
|
|
|
null, |
|
626
|
|
|
array(), |
|
627
|
|
|
$createElement |
|
628
|
|
|
); |
|
629
|
|
|
} |
|
630
|
|
|
|
|
631
|
|
|
/** |
|
632
|
|
|
* Returns a button with the primary color and a copy (double sheet) icon |
|
633
|
|
|
* @param string $label Text appearing on the button |
|
634
|
|
|
* @param string $name Element name (for form treatment purposes) |
|
635
|
|
|
* @param bool $createElement Whether to use the create or add method |
|
636
|
|
|
* |
|
637
|
|
|
* @return HTML_QuickForm_button |
|
638
|
|
|
*/ |
|
639
|
|
View Code Duplication |
public function addButtonCopy($label, $name = 'submit', $createElement = false) |
|
640
|
|
|
{ |
|
641
|
|
|
return $this->addButton( |
|
642
|
|
|
$name, |
|
643
|
|
|
$label, |
|
644
|
|
|
'copy', |
|
645
|
|
|
'primary', |
|
646
|
|
|
null, |
|
647
|
|
|
null, |
|
648
|
|
|
array(), |
|
649
|
|
|
$createElement |
|
650
|
|
|
); |
|
651
|
|
|
} |
|
652
|
|
|
|
|
653
|
|
|
/** |
|
654
|
|
|
* @param string $name |
|
655
|
|
|
* @param string $label |
|
656
|
|
|
* @param string $text |
|
657
|
|
|
* @param array $attributes |
|
658
|
|
|
* |
|
659
|
|
|
* @return HTML_QuickForm_checkbox |
|
660
|
|
|
*/ |
|
661
|
|
|
public function addCheckBox($name, $label, $text = '', $attributes = array()) |
|
662
|
|
|
{ |
|
663
|
|
|
return $this->addElement('checkbox', $name, $label, $text, $attributes); |
|
664
|
|
|
} |
|
665
|
|
|
|
|
666
|
|
|
/** |
|
667
|
|
|
* @param string $name |
|
668
|
|
|
* @param string $label |
|
669
|
|
|
* @param array $options |
|
670
|
|
|
* @param array $attributes |
|
671
|
|
|
* |
|
672
|
|
|
* @return HTML_QuickForm_group |
|
673
|
|
|
*/ |
|
674
|
|
View Code Duplication |
public function addCheckBoxGroup($name, $label, $options = array(), $attributes = array()) |
|
675
|
|
|
{ |
|
676
|
|
|
$group = array(); |
|
677
|
|
|
foreach ($options as $value => $text) { |
|
678
|
|
|
$attributes['value'] = $value; |
|
679
|
|
|
$group[] = $this->createElement('checkbox', $value, null, $text, $attributes); |
|
680
|
|
|
} |
|
681
|
|
|
|
|
682
|
|
|
return $this->addGroup($group, $name, $label); |
|
683
|
|
|
} |
|
684
|
|
|
|
|
685
|
|
|
/** |
|
686
|
|
|
* @param string $name |
|
687
|
|
|
* @param string $label |
|
688
|
|
|
* @param array $options |
|
689
|
|
|
* @param array $attributes |
|
690
|
|
|
* |
|
691
|
|
|
* @return HTML_QuickForm_radio |
|
692
|
|
|
*/ |
|
693
|
|
View Code Duplication |
public function addRadio($name, $label, $options = array(), $attributes = array()) |
|
694
|
|
|
{ |
|
695
|
|
|
$group = array(); |
|
696
|
|
|
foreach ($options as $key => $value) { |
|
697
|
|
|
$group[] = $this->createElement('radio', null, null, $value, $key, $attributes); |
|
698
|
|
|
} |
|
699
|
|
|
|
|
700
|
|
|
return $this->addGroup($group, $name, $label); |
|
701
|
|
|
} |
|
702
|
|
|
|
|
703
|
|
|
/** |
|
704
|
|
|
* @param string $name |
|
705
|
|
|
* @param string $label |
|
706
|
|
|
* @param array $options |
|
707
|
|
|
* @param array $attributes |
|
708
|
|
|
* |
|
709
|
|
|
* @return HTML_QuickForm_select |
|
710
|
|
|
*/ |
|
711
|
|
|
public function addSelect($name, $label, $options = array(), $attributes = array()) |
|
712
|
|
|
{ |
|
713
|
|
|
return $this->addElement('select', $name, $label, $options, $attributes); |
|
714
|
|
|
} |
|
715
|
|
|
|
|
716
|
|
|
/** |
|
717
|
|
|
* @param $name |
|
718
|
|
|
* @param $label |
|
719
|
|
|
* @param $collection |
|
720
|
|
|
* @param array $attributes |
|
721
|
|
|
* @param bool $addNoneOption |
|
722
|
|
|
* @param string $textCallable set a function getStringValue() by default __toString() |
|
723
|
|
|
* |
|
724
|
|
|
* @return HTML_QuickForm_element |
|
725
|
|
|
*/ |
|
726
|
|
|
public function addSelectFromCollection( |
|
727
|
|
|
$name, |
|
728
|
|
|
$label, |
|
729
|
|
|
$collection, |
|
730
|
|
|
$attributes = array(), |
|
731
|
|
|
$addNoneOption = false, |
|
732
|
|
|
$textCallable = '' |
|
733
|
|
|
) { |
|
734
|
|
|
$options = []; |
|
735
|
|
|
|
|
736
|
|
|
if ($addNoneOption) { |
|
737
|
|
|
$options[0] = get_lang('None'); |
|
738
|
|
|
} |
|
739
|
|
|
|
|
740
|
|
|
if (!empty($collection)) { |
|
741
|
|
|
foreach ($collection as $item) { |
|
742
|
|
|
$text = $item; |
|
743
|
|
|
if (!empty($textCallable)) { |
|
744
|
|
|
$text = $item->$textCallable(); |
|
745
|
|
|
} |
|
746
|
|
|
$options[$item->getId()] = $text; |
|
747
|
|
|
} |
|
748
|
|
|
} |
|
749
|
|
|
return $this->addElement('select', $name, $label, $options, $attributes); |
|
750
|
|
|
} |
|
751
|
|
|
|
|
752
|
|
|
/** |
|
753
|
|
|
* @param string $label |
|
754
|
|
|
* @param string $text |
|
755
|
|
|
* |
|
756
|
|
|
* @return HTML_QuickForm_label |
|
757
|
|
|
*/ |
|
758
|
|
|
public function addLabel($label, $text) |
|
759
|
|
|
{ |
|
760
|
|
|
return $this->addElement('label', $label, $text); |
|
761
|
|
|
} |
|
762
|
|
|
|
|
763
|
|
|
/** |
|
764
|
|
|
* @param string $text |
|
765
|
|
|
*/ |
|
766
|
|
|
public function addHeader($text) |
|
767
|
|
|
{ |
|
768
|
|
|
$this->addElement('header', $text); |
|
769
|
|
|
} |
|
770
|
|
|
|
|
771
|
|
|
/** |
|
772
|
|
|
* @param string $name |
|
773
|
|
|
* @param string $label |
|
774
|
|
|
* @param array $attributes |
|
775
|
|
|
*/ |
|
776
|
|
|
public function addFile($name, $label, $attributes = array()) |
|
777
|
|
|
{ |
|
778
|
|
|
$this->addElement('file', $name, $label, $attributes); |
|
779
|
|
|
} |
|
780
|
|
|
|
|
781
|
|
|
/** |
|
782
|
|
|
* @param string $snippet |
|
783
|
|
|
*/ |
|
784
|
|
|
public function addHtml($snippet) |
|
785
|
|
|
{ |
|
786
|
|
|
$this->addElement('html', $snippet); |
|
787
|
|
|
} |
|
788
|
|
|
|
|
789
|
|
|
/** |
|
790
|
|
|
* Adds a HTML-editor to the form |
|
791
|
|
|
* @param string $name |
|
792
|
|
|
* @param string $label The label for the form-element |
|
793
|
|
|
* @param bool $required (optional) Is the form-element required (default=true) |
|
794
|
|
|
* @param bool $fullPage (optional) When it is true, the editor loads completed html code for a full page. |
|
795
|
|
|
* @param array $config (optional) Configuration settings for the online editor. |
|
796
|
|
|
* @param bool $style |
|
797
|
|
|
*/ |
|
798
|
|
|
public function addHtmlEditor($name, $label, $required = true, $fullPage = false, $config = array(), $style = false) |
|
799
|
|
|
{ |
|
800
|
|
|
$config['rows'] = isset($config['rows']) ? $config['rows'] : 15; |
|
801
|
|
|
$config['cols'] = isset($config['cols']) ? $config['cols'] : 80; |
|
802
|
|
|
$this->addElement('html_editor', $name, $label, $config, $style); |
|
803
|
|
|
$this->applyFilter($name, 'trim'); |
|
804
|
|
|
if ($required) { |
|
805
|
|
|
$this->addRule($name, get_lang('ThisFieldIsRequired'), 'required'); |
|
806
|
|
|
} |
|
807
|
|
|
|
|
808
|
|
|
/** @var HtmlEditor $element */ |
|
809
|
|
|
$element = $this->getElement($name); |
|
810
|
|
|
if ($style) { |
|
811
|
|
|
$config['style'] = true; |
|
812
|
|
|
} |
|
813
|
|
|
if ($fullPage) { |
|
814
|
|
|
$config['fullPage'] = true; |
|
815
|
|
|
} |
|
816
|
|
|
|
|
817
|
|
|
if ($element->editor) { |
|
818
|
|
|
$element->editor->processConfig($config); |
|
819
|
|
|
} |
|
820
|
|
|
} |
|
821
|
|
|
|
|
822
|
|
|
/** |
|
823
|
|
|
* @param string $name |
|
824
|
|
|
* @param string $label |
|
825
|
|
|
* |
|
826
|
|
|
* @return mixed |
|
827
|
|
|
*/ |
|
828
|
|
|
public function addButtonAdvancedSettings($name, $label = '') |
|
829
|
|
|
{ |
|
830
|
|
|
$label = !empty($label) ? $label : get_lang('AdvancedParameters'); |
|
831
|
|
|
|
|
832
|
|
|
return $this->addElement('advanced_settings', $name, $label); |
|
833
|
|
|
} |
|
834
|
|
|
|
|
835
|
|
|
/** |
|
836
|
|
|
* Adds a progress bar to the form. |
|
837
|
|
|
* |
|
838
|
|
|
* Once the user submits the form, a progress bar (animated gif) is |
|
839
|
|
|
* displayed. The progress bar will disappear once the page has been |
|
840
|
|
|
* reloaded. |
|
841
|
|
|
* |
|
842
|
|
|
* @param int $delay (optional) The number of seconds between the moment the user |
|
843
|
|
|
* @param string $label (optional) Custom label to be shown |
|
844
|
|
|
* |
|
845
|
|
|
* submits the form and the start of the progress bar. |
|
846
|
|
|
* @deprecated ? |
|
847
|
|
|
*/ |
|
848
|
|
|
public function add_progress_bar($delay = 2, $label = '') |
|
849
|
|
|
{ |
|
850
|
|
|
if (empty($label)) { |
|
851
|
|
|
$label = get_lang('PleaseStandBy'); |
|
852
|
|
|
} |
|
853
|
|
|
$this->with_progress_bar = true; |
|
854
|
|
|
$this->updateAttributes("onsubmit=\"javascript: myUpload.start('dynamic_div','".Display::returnIconPath('progress_bar.gif')."','" . $label . "','" . $this->getAttribute('id') . "')\""); |
|
855
|
|
|
$this->addElement('html', '<script language="javascript" src="' . api_get_path(WEB_LIBRARY_PATH) . 'javascript/upload.js" type="text/javascript"></script>'); |
|
856
|
|
|
$this->addElement('html', '<script type="text/javascript">var myUpload = new upload(' . (abs(intval($delay)) * 1000) . ');</script>'); |
|
857
|
|
|
} |
|
858
|
|
|
|
|
859
|
|
|
/** |
|
860
|
|
|
* Uses new functions (php 5.2) for displaying real upload progress. |
|
861
|
|
|
* @param string $upload_id The value of the field UPLOAD_IDENTIFIER, the second parameter (XXX) of the $form->addElement('file', XXX) sentence |
|
862
|
|
|
* @param string $element_after The first element of the form (to place at first UPLOAD_IDENTIFIER) |
|
863
|
|
|
* @param int $delay (optional) The frequency of the xajax call |
|
864
|
|
|
* @param bool $wait_after_upload (optional) |
|
865
|
|
|
*/ |
|
866
|
|
|
public function add_real_progress_bar($upload_id, $element_after, $delay = 2, $wait_after_upload = false) |
|
867
|
|
|
{ |
|
868
|
|
|
if (!function_exists('uploadprogress_get_info')) { |
|
869
|
|
|
$this->add_progress_bar($delay); |
|
|
|
|
|
|
870
|
|
|
return; |
|
871
|
|
|
} |
|
872
|
|
|
|
|
873
|
|
|
$xajax_upload = new xajax(api_get_path(WEB_LIBRARY_PATH) . 'upload.xajax.php'); |
|
874
|
|
|
|
|
875
|
|
|
$xajax_upload->registerFunction('updateProgress'); |
|
876
|
|
|
|
|
877
|
|
|
|
|
878
|
|
|
// IMPORTANT : must be the first element of the form |
|
879
|
|
|
$el = $this->insertElementBefore(FormValidator::createElement('html', '<input type="hidden" name="UPLOAD_IDENTIFIER" value="' . $upload_id . '" />'), $element_after); |
|
880
|
|
|
|
|
881
|
|
|
$this->addElement('html', '<br />'); |
|
882
|
|
|
|
|
883
|
|
|
// Add div-element where the progress bar is to be displayed |
|
884
|
|
|
$this->addElement('html', ' |
|
885
|
|
|
<div id="dynamic_div_container" style="display:none"> |
|
886
|
|
|
<div id="dynamic_div_label">' . get_lang('UploadFile') . '</div> |
|
887
|
|
|
<div id="dynamic_div_frame" style="width:214px; height:12px; border:1px solid grey; background-image:url(' . Display::returnIconPath('real_upload_frame.gif').');"> |
|
888
|
|
|
<div id="dynamic_div_filled" style="width:0%;height:100%;background-image:url(' . api_get_path(WEB_IMG_PATH) . 'real_upload_step.gif);background-repeat:repeat-x;background-position:center;"></div> |
|
889
|
|
|
</div> |
|
890
|
|
|
</div>' |
|
891
|
|
|
); |
|
892
|
|
|
|
|
893
|
|
|
if ($wait_after_upload) { |
|
894
|
|
|
$this->addElement('html', ' |
|
895
|
|
|
<div id="dynamic_div_waiter_container" style="display:none"> |
|
896
|
|
|
<div id="dynamic_div_waiter_label"> |
|
897
|
|
|
' . get_lang('SlideshowConversion') . ' |
|
898
|
|
|
</div> |
|
899
|
|
|
<div id="dynamic_div_waiter_frame"> |
|
900
|
|
|
'.Display::return_icon('real_upload_frame.gif').' |
|
901
|
|
|
</div> |
|
902
|
|
|
</div> |
|
903
|
|
|
'); |
|
904
|
|
|
} |
|
905
|
|
|
|
|
906
|
|
|
// Get the xajax code |
|
907
|
|
|
$this->addElement('html', $xajax_upload->getJavascript(api_get_path(WEB_LIBRARY_PATH) . 'xajax')); |
|
908
|
|
|
|
|
909
|
|
|
// Get the upload code |
|
910
|
|
|
$this->addElement('html', '<script language="javascript" src="' . api_get_path(WEB_LIBRARY_PATH) . 'javascript/upload.js" type="text/javascript"></script>'); |
|
911
|
|
|
$this->addElement('html', '<script type="text/javascript">var myUpload = new upload(' . (abs(intval($delay)) * 1000) . ');</script>'); |
|
912
|
|
|
|
|
913
|
|
|
if (!$wait_after_upload) { |
|
914
|
|
|
$wait_after_upload = 0; |
|
915
|
|
|
} |
|
916
|
|
|
|
|
917
|
|
|
// Add the upload event |
|
918
|
|
|
$this->updateAttributes("onsubmit=\"javascript: myUpload.startRealUpload('dynamic_div','" . $upload_id . "','" . $this->getAttribute('id') . "'," . $wait_after_upload . ")\""); |
|
919
|
|
|
} |
|
920
|
|
|
|
|
921
|
|
|
/** |
|
922
|
|
|
* This function has been created for avoiding changes directly within QuickForm class. |
|
923
|
|
|
* When we use it, the element is threated as 'required' to be dealt during validation. |
|
924
|
|
|
* @param array $element The array of elements |
|
|
|
|
|
|
925
|
|
|
* @param string $message The message displayed |
|
926
|
|
|
*/ |
|
927
|
|
|
public function add_multiple_required_rule($elements, $message) |
|
928
|
|
|
{ |
|
929
|
|
|
$this->_required[] = $elements[0]; |
|
930
|
|
|
$this->addRule($elements, $message, 'multiple_required'); |
|
931
|
|
|
} |
|
932
|
|
|
|
|
933
|
|
|
/** |
|
934
|
|
|
* Displays the form. |
|
935
|
|
|
* If an element in the form didn't validate, an error message is showed |
|
936
|
|
|
* asking the user to complete the form. |
|
937
|
|
|
*/ |
|
938
|
|
|
public function display() |
|
939
|
|
|
{ |
|
940
|
|
|
echo $this->returnForm(); |
|
941
|
|
|
} |
|
942
|
|
|
|
|
943
|
|
|
/** |
|
944
|
|
|
* Returns the HTML code of the form. |
|
945
|
|
|
* @return string $return_value HTML code of the form |
|
946
|
|
|
*/ |
|
947
|
|
|
public function returnForm() |
|
948
|
|
|
{ |
|
949
|
|
|
$error = false; |
|
950
|
|
|
/** @var HTML_QuickForm_element $element */ |
|
951
|
|
|
foreach ($this->_elements as $element) { |
|
952
|
|
|
if (!is_null(parent::getElementError($element->getName()))) { |
|
|
|
|
|
|
953
|
|
|
$error = true; |
|
954
|
|
|
break; |
|
955
|
|
|
} |
|
956
|
|
|
} |
|
957
|
|
|
|
|
958
|
|
|
$returnValue = ''; |
|
959
|
|
|
$js = null; |
|
960
|
|
|
|
|
961
|
|
|
if ($error) { |
|
962
|
|
|
$returnValue = Display::return_message( |
|
963
|
|
|
get_lang('FormHasErrorsPleaseComplete'), |
|
964
|
|
|
'warning' |
|
965
|
|
|
); |
|
966
|
|
|
} |
|
967
|
|
|
|
|
968
|
|
|
$returnValue .= $js; |
|
969
|
|
|
$returnValue .= parent::toHtml(); |
|
|
|
|
|
|
970
|
|
|
// Add div-element which is to hold the progress bar |
|
971
|
|
|
if (isset($this->with_progress_bar) && $this->with_progress_bar) { |
|
972
|
|
|
$returnValue .= '<div id="dynamic_div" style="display:block; margin-left:40%; margin-top:10px; height:50px;"></div>'; |
|
973
|
|
|
} |
|
974
|
|
|
|
|
975
|
|
|
return $returnValue; |
|
976
|
|
|
} |
|
977
|
|
|
|
|
978
|
|
|
/** |
|
979
|
|
|
* Returns the HTML code of the form. |
|
980
|
|
|
* If an element in the form didn't validate, an error message is showed |
|
981
|
|
|
* asking the user to complete the form. |
|
982
|
|
|
* |
|
983
|
|
|
* @return string $return_value HTML code of the form |
|
984
|
|
|
* |
|
985
|
|
|
* @author Patrick Cool <[email protected]>, Ghent University, august 2006 |
|
986
|
|
|
* @author Julio Montoya |
|
987
|
|
|
* @deprecated use returnForm() |
|
988
|
|
|
*/ |
|
989
|
|
|
public function return_form() |
|
990
|
|
|
{ |
|
991
|
|
|
return $this->returnForm(); |
|
992
|
|
|
} |
|
993
|
|
|
|
|
994
|
|
|
/** |
|
995
|
|
|
* Create a form validator based on an array of form data: |
|
996
|
|
|
* |
|
997
|
|
|
* array( |
|
998
|
|
|
* 'name' => 'zombie_report_parameters', //optional |
|
999
|
|
|
* 'method' => 'GET', //optional |
|
1000
|
|
|
* 'items' => array( |
|
1001
|
|
|
* array( |
|
1002
|
|
|
* 'name' => 'ceiling', |
|
1003
|
|
|
* 'label' => 'Ceiling', //optional |
|
1004
|
|
|
* 'type' => 'date', |
|
1005
|
|
|
* 'default' => date() //optional |
|
1006
|
|
|
* ), |
|
1007
|
|
|
* array( |
|
1008
|
|
|
* 'name' => 'active_only', |
|
1009
|
|
|
* 'label' => 'ActiveOnly', |
|
1010
|
|
|
* 'type' => 'checkbox', |
|
1011
|
|
|
* 'default' => true |
|
1012
|
|
|
* ), |
|
1013
|
|
|
* array( |
|
1014
|
|
|
* 'name' => 'submit_button', |
|
1015
|
|
|
* 'type' => 'style_submit_button', |
|
1016
|
|
|
* 'value' => get_lang('Search'), |
|
1017
|
|
|
* 'attributes' => array('class' => 'search') |
|
1018
|
|
|
* ) |
|
1019
|
|
|
* ) |
|
1020
|
|
|
* ); |
|
1021
|
|
|
* |
|
1022
|
|
|
* @param array $form_data |
|
1023
|
|
|
* @deprecated use normal FormValidator construct |
|
1024
|
|
|
* |
|
1025
|
|
|
* @return FormValidator |
|
1026
|
|
|
*/ |
|
1027
|
|
|
public static function create($form_data) |
|
1028
|
|
|
{ |
|
1029
|
|
|
if (empty($form_data)) { |
|
1030
|
|
|
return null; |
|
1031
|
|
|
} |
|
1032
|
|
|
$form_name = isset($form_data['name']) ? $form_data['name'] : 'form'; |
|
1033
|
|
|
$form_method = isset($form_data['method']) ? $form_data['method'] : 'POST'; |
|
1034
|
|
|
$form_action = isset($form_data['action']) ? $form_data['action'] : ''; |
|
1035
|
|
|
$form_target = isset($form_data['target']) ? $form_data['target'] : ''; |
|
1036
|
|
|
$form_attributes = isset($form_data['attributes']) ? $form_data['attributes'] : null; |
|
1037
|
|
|
$form_track_submit = isset($form_data['track_submit']) ? $form_data['track_submit'] : true; |
|
1038
|
|
|
$reset = null; |
|
1039
|
|
|
$result = new FormValidator($form_name, $form_method, $form_action, $form_target, $form_attributes, $form_track_submit); |
|
1040
|
|
|
|
|
1041
|
|
|
$defaults = array(); |
|
1042
|
|
|
foreach ($form_data['items'] as $item) { |
|
1043
|
|
|
$name = $item['name']; |
|
1044
|
|
|
$type = isset($item['type']) ? $item['type'] : 'text'; |
|
1045
|
|
|
$label = isset($item['label']) ? $item['label'] : ''; |
|
1046
|
|
|
if ($type == 'wysiwyg') { |
|
1047
|
|
|
$element = $result->addHtmlEditor($name, $label); |
|
|
|
|
|
|
1048
|
|
|
} else { |
|
1049
|
|
|
$element = $result->addElement($type, $name, $label); |
|
1050
|
|
|
} |
|
1051
|
|
|
if (isset($item['attributes'])) { |
|
1052
|
|
|
$attributes = $item['attributes']; |
|
1053
|
|
|
$element->setAttributes($attributes); |
|
1054
|
|
|
} |
|
1055
|
|
|
if (isset($item['value'])) { |
|
1056
|
|
|
$value = $item['value']; |
|
1057
|
|
|
$element->setValue($value); |
|
1058
|
|
|
} |
|
1059
|
|
|
if (isset($item['default'])) { |
|
1060
|
|
|
$defaults[$name] = $item['default']; |
|
1061
|
|
|
} |
|
1062
|
|
|
if (isset($item['rules'])) { |
|
1063
|
|
|
$rules = $item['rules']; |
|
1064
|
|
|
foreach ($rules as $rule) { |
|
1065
|
|
|
$message = $rule['message']; |
|
1066
|
|
|
$type = $rule['type']; |
|
1067
|
|
|
$format = isset($rule['format']) ? $rule['format'] : null; |
|
1068
|
|
|
$validation = isset($rule['validation']) ? $rule['validation'] : 'server'; |
|
1069
|
|
|
$force = isset($rule['force']) ? $rule['force'] : false; |
|
1070
|
|
|
$result->addRule($name, $message, $type, $format, $validation, $reset, $force); |
|
1071
|
|
|
} |
|
1072
|
|
|
} |
|
1073
|
|
|
} |
|
1074
|
|
|
$result->setDefaults($defaults); |
|
1075
|
|
|
|
|
1076
|
|
|
return $result; |
|
1077
|
|
|
} |
|
1078
|
|
|
|
|
1079
|
|
|
/** |
|
1080
|
|
|
* @return HTML_QuickForm_Renderer_Default |
|
1081
|
|
|
*/ |
|
1082
|
|
|
public static function getDefaultRenderer() |
|
1083
|
|
|
{ |
|
1084
|
|
|
return |
|
1085
|
|
|
isset($GLOBALS['_HTML_QuickForm_default_renderer']) ? |
|
1086
|
|
|
$GLOBALS['_HTML_QuickForm_default_renderer'] : null; |
|
1087
|
|
|
} |
|
1088
|
|
|
|
|
1089
|
|
|
/** |
|
1090
|
|
|
* Adds a input of type url to the form. |
|
1091
|
|
|
* @param type $name The label for the form-element |
|
1092
|
|
|
* @param type $label The element name |
|
1093
|
|
|
* @param type $required Optional. Is the form-element required (default=true) |
|
1094
|
|
|
* @param type $attributes Optional. List of attributes for the form-element |
|
1095
|
|
|
*/ |
|
1096
|
|
View Code Duplication |
public function addUrl($name, $label, $required = true, $attributes = array()) |
|
1097
|
|
|
{ |
|
1098
|
|
|
$this->addElement('url', $name, $label, $attributes); |
|
1099
|
|
|
$this->applyFilter($name, 'trim'); |
|
1100
|
|
|
$this->addRule($name, get_lang('InsertAValidUrl'), 'url'); |
|
1101
|
|
|
|
|
1102
|
|
|
if ($required) { |
|
1103
|
|
|
$this->addRule($name, get_lang('ThisFieldIsRequired'), 'required'); |
|
1104
|
|
|
} |
|
1105
|
|
|
} |
|
1106
|
|
|
|
|
1107
|
|
|
/** |
|
1108
|
|
|
* Adds a text field for letters to the form. |
|
1109
|
|
|
* A trim-filter is attached to the field. |
|
1110
|
|
|
* @param string $name The element name |
|
1111
|
|
|
* @param string $label The label for the form-element |
|
1112
|
|
|
* @param bool $required Optional. Is the form-element required (default=true) |
|
1113
|
|
|
* @param array $attributes Optional. List of attributes for the form-element |
|
1114
|
|
|
*/ |
|
1115
|
|
View Code Duplication |
public function addTextLettersOnly( |
|
1116
|
|
|
$name, |
|
1117
|
|
|
$label, |
|
1118
|
|
|
$required = false, |
|
1119
|
|
|
$attributes = [] |
|
1120
|
|
|
) { |
|
1121
|
|
|
$attributes = array_merge( |
|
1122
|
|
|
$attributes, |
|
1123
|
|
|
[ |
|
1124
|
|
|
'pattern' => '[a-zA-ZñÑ]+', |
|
1125
|
|
|
'title' => get_lang('OnlyLetters') |
|
1126
|
|
|
] |
|
1127
|
|
|
); |
|
1128
|
|
|
|
|
1129
|
|
|
$this->addElement( |
|
1130
|
|
|
'text', |
|
1131
|
|
|
$name, |
|
1132
|
|
|
[ |
|
1133
|
|
|
$label, |
|
1134
|
|
|
get_lang('OnlyLetters') |
|
1135
|
|
|
], |
|
1136
|
|
|
$attributes |
|
1137
|
|
|
); |
|
1138
|
|
|
|
|
1139
|
|
|
$this->applyFilter($name, 'trim'); |
|
1140
|
|
|
|
|
1141
|
|
|
if ($required) { |
|
1142
|
|
|
$this->addRule($name, get_lang('ThisFieldIsRequired'), 'required'); |
|
1143
|
|
|
} |
|
1144
|
|
|
|
|
1145
|
|
|
$this->addRule( |
|
1146
|
|
|
$name, |
|
1147
|
|
|
get_lang('OnlyLetters'), |
|
1148
|
|
|
'regex', |
|
1149
|
|
|
'/^[a-zA-ZñÑ]+$/' |
|
1150
|
|
|
); |
|
1151
|
|
|
} |
|
1152
|
|
|
|
|
1153
|
|
|
/** |
|
1154
|
|
|
* Adds a text field for alphanumeric characters to the form. |
|
1155
|
|
|
* A trim-filter is attached to the field. |
|
1156
|
|
|
* @param string $name The element name |
|
1157
|
|
|
* @param string $label The label for the form-element |
|
1158
|
|
|
* @param bool $required Optional. Is the form-element required (default=true) |
|
1159
|
|
|
* @param array $attributes Optional. List of attributes for the form-element |
|
1160
|
|
|
*/ |
|
1161
|
|
View Code Duplication |
public function addTextAlphanumeric( |
|
1162
|
|
|
$name, |
|
1163
|
|
|
$label, |
|
1164
|
|
|
$required = false, |
|
1165
|
|
|
$attributes = [] |
|
1166
|
|
|
) { |
|
1167
|
|
|
$attributes = array_merge( |
|
1168
|
|
|
$attributes, |
|
1169
|
|
|
[ |
|
1170
|
|
|
'pattern' => '[a-zA-Z0-9ñÑ]+', |
|
1171
|
|
|
'title' => get_lang('OnlyLettersAndNumbers') |
|
1172
|
|
|
] |
|
1173
|
|
|
); |
|
1174
|
|
|
|
|
1175
|
|
|
$this->addElement( |
|
1176
|
|
|
'text', |
|
1177
|
|
|
$name, |
|
1178
|
|
|
[ |
|
1179
|
|
|
$label, |
|
1180
|
|
|
get_lang('OnlyLettersAndNumbers') |
|
1181
|
|
|
], |
|
1182
|
|
|
$attributes |
|
1183
|
|
|
); |
|
1184
|
|
|
|
|
1185
|
|
|
$this->applyFilter($name, 'trim'); |
|
1186
|
|
|
|
|
1187
|
|
|
if ($required) { |
|
1188
|
|
|
$this->addRule($name, get_lang('ThisFieldIsRequired'), 'required'); |
|
1189
|
|
|
} |
|
1190
|
|
|
|
|
1191
|
|
|
$this->addRule( |
|
1192
|
|
|
$name, |
|
1193
|
|
|
get_lang('OnlyLettersAndNumbers'), |
|
1194
|
|
|
'regex', |
|
1195
|
|
|
'/^[a-zA-Z0-9ÑÑ]+$/' |
|
1196
|
|
|
); |
|
1197
|
|
|
} |
|
1198
|
|
|
|
|
1199
|
|
|
/** |
|
1200
|
|
|
* Adds a text field for letters and spaces to the form. |
|
1201
|
|
|
* A trim-filter is attached to the field. |
|
1202
|
|
|
* @param string $name The element name |
|
1203
|
|
|
* @param string $label The label for the form-element |
|
1204
|
|
|
* @param bool $required Optional. Is the form-element required (default=true) |
|
1205
|
|
|
* @param array $attributes Optional. List of attributes for the form-element |
|
1206
|
|
|
*/ |
|
1207
|
|
View Code Duplication |
public function addTextLettersAndSpaces( |
|
1208
|
|
|
$name, |
|
1209
|
|
|
$label, |
|
1210
|
|
|
$required = false, |
|
1211
|
|
|
$attributes = [] |
|
1212
|
|
|
) { |
|
1213
|
|
|
$attributes = array_merge( |
|
1214
|
|
|
$attributes, |
|
1215
|
|
|
[ |
|
1216
|
|
|
'pattern' => '[a-zA-ZñÑ\s]+', |
|
1217
|
|
|
'title' => get_lang('OnlyLettersAndSpaces') |
|
1218
|
|
|
] |
|
1219
|
|
|
); |
|
1220
|
|
|
|
|
1221
|
|
|
$this->addElement( |
|
1222
|
|
|
'text', |
|
1223
|
|
|
$name, |
|
1224
|
|
|
[ |
|
1225
|
|
|
$label, |
|
1226
|
|
|
get_lang('OnlyLettersAndSpaces') |
|
1227
|
|
|
], |
|
1228
|
|
|
$attributes |
|
1229
|
|
|
); |
|
1230
|
|
|
|
|
1231
|
|
|
$this->applyFilter($name, 'trim'); |
|
1232
|
|
|
|
|
1233
|
|
|
if ($required) { |
|
1234
|
|
|
$this->addRule($name, get_lang('ThisFieldIsRequired'), 'required'); |
|
1235
|
|
|
} |
|
1236
|
|
|
|
|
1237
|
|
|
$this->addRule( |
|
1238
|
|
|
$name, |
|
1239
|
|
|
get_lang('OnlyLettersAndSpaces'), |
|
1240
|
|
|
'regex', |
|
1241
|
|
|
'/^[a-zA-ZñÑ\s]+$/' |
|
1242
|
|
|
); |
|
1243
|
|
|
} |
|
1244
|
|
|
|
|
1245
|
|
|
/** |
|
1246
|
|
|
* Adds a text field for alphanumeric and spaces characters to the form. |
|
1247
|
|
|
* A trim-filter is attached to the field. |
|
1248
|
|
|
* @param string $name The element name |
|
1249
|
|
|
* @param string $label The label for the form-element |
|
1250
|
|
|
* @param bool $required Optional. Is the form-element required (default=true) |
|
1251
|
|
|
* @param array $attributes Optional. List of attributes for the form-element |
|
1252
|
|
|
*/ |
|
1253
|
|
View Code Duplication |
public function addTextAlphanumericAndSpaces( |
|
1254
|
|
|
$name, |
|
1255
|
|
|
$label, |
|
1256
|
|
|
$required = false, |
|
1257
|
|
|
$attributes = [] |
|
1258
|
|
|
) { |
|
1259
|
|
|
$attributes = array_merge( |
|
1260
|
|
|
$attributes, |
|
1261
|
|
|
[ |
|
1262
|
|
|
'pattern' => '[a-zA-Z0-9ñÑ\s]+', |
|
1263
|
|
|
'title' => get_lang('OnlyLettersAndNumbersAndSpaces') |
|
1264
|
|
|
] |
|
1265
|
|
|
); |
|
1266
|
|
|
|
|
1267
|
|
|
$this->addElement( |
|
1268
|
|
|
'text', |
|
1269
|
|
|
$name, |
|
1270
|
|
|
[ |
|
1271
|
|
|
$label, |
|
1272
|
|
|
get_lang('OnlyLettersAndNumbersAndSpaces') |
|
1273
|
|
|
], |
|
1274
|
|
|
$attributes |
|
1275
|
|
|
); |
|
1276
|
|
|
|
|
1277
|
|
|
$this->applyFilter($name, 'trim'); |
|
1278
|
|
|
|
|
1279
|
|
|
if ($required) { |
|
1280
|
|
|
$this->addRule($name, get_lang('ThisFieldIsRequired'), 'required'); |
|
1281
|
|
|
} |
|
1282
|
|
|
|
|
1283
|
|
|
$this->addRule( |
|
1284
|
|
|
$name, |
|
1285
|
|
|
get_lang('OnlyLettersAndNumbersAndSpaces'), |
|
1286
|
|
|
'regex', |
|
1287
|
|
|
'/^[a-zA-Z0-9ñÑ\s]+$/' |
|
1288
|
|
|
); |
|
1289
|
|
|
} |
|
1290
|
|
|
|
|
1291
|
|
|
/** |
|
1292
|
|
|
* @param string $url |
|
1293
|
|
|
*/ |
|
1294
|
|
|
public function addMultipleUpload($url) |
|
1295
|
|
|
{ |
|
1296
|
|
|
$inputName = 'input_file_upload'; |
|
1297
|
|
|
$this->addMultipleUploadJavascript($url, $inputName); |
|
1298
|
|
|
|
|
1299
|
|
|
$this->addHtml(' |
|
1300
|
|
|
<div class="description-upload">'.get_lang('ClickToSelectOrDragAndDropMultipleFilesOnTheUploadField').'</div> |
|
1301
|
|
|
<span class="btn btn-success fileinput-button"> |
|
1302
|
|
|
<i class="glyphicon glyphicon-plus"></i> |
|
1303
|
|
|
<span>'.get_lang('AddFiles').'</span> |
|
1304
|
|
|
<!-- The file input field used as target for the file upload widget --> |
|
1305
|
|
|
<input id="'.$inputName.'" type="file" name="files[]" multiple> |
|
1306
|
|
|
</span> |
|
1307
|
|
|
<br /> |
|
1308
|
|
|
<br /> |
|
1309
|
|
|
<div id="dropzone"> |
|
1310
|
|
|
<div class="button-load"> |
|
1311
|
|
|
'.get_lang('UploadFiles').' |
|
1312
|
|
|
</div> |
|
1313
|
|
|
</div> |
|
1314
|
|
|
|
|
1315
|
|
|
<br /> |
|
1316
|
|
|
<!-- The global progress bar --> |
|
1317
|
|
|
<div id="progress" class="progress"> |
|
1318
|
|
|
<div class="progress-bar progress-bar-success"></div> |
|
1319
|
|
|
</div> |
|
1320
|
|
|
<div id="files" class="files"></div> |
|
1321
|
|
|
'); |
|
1322
|
|
|
} |
|
1323
|
|
|
|
|
1324
|
|
|
/** |
|
1325
|
|
|
* |
|
1326
|
|
|
* @param string $url page that will handle the upload |
|
1327
|
|
|
* @param string $inputName |
|
1328
|
|
|
*/ |
|
1329
|
|
|
private function addMultipleUploadJavascript($url, $inputName) |
|
1330
|
|
|
{ |
|
1331
|
|
|
$this->addHtml(" |
|
1332
|
|
|
<script> |
|
1333
|
|
|
$(function () { |
|
1334
|
|
|
'use strict'; |
|
1335
|
|
|
|
|
1336
|
|
|
$('#".$this->getAttribute('id')."').submit(function(){ |
|
1337
|
|
|
return false; |
|
1338
|
|
|
}); |
|
1339
|
|
|
|
|
1340
|
|
|
$('#dropzone').on('click', function() { |
|
1341
|
|
|
$('#".$inputName."').click(); |
|
1342
|
|
|
}); |
|
1343
|
|
|
|
|
1344
|
|
|
var url = '".$url."'; |
|
1345
|
|
|
var uploadButton = $('<button/>') |
|
1346
|
|
|
.addClass('btn btn-primary') |
|
1347
|
|
|
.prop('disabled', true) |
|
1348
|
|
|
.text('".get_lang('Loading')."') |
|
1349
|
|
|
.on('click', function () { |
|
1350
|
|
|
var \$this = $(this), |
|
1351
|
|
|
data = \$this.data(); |
|
1352
|
|
|
|
|
1353
|
|
|
\$this |
|
1354
|
|
|
.off('click') |
|
1355
|
|
|
.text('".get_lang('Cancel')."') |
|
1356
|
|
|
.on('click', function () { |
|
1357
|
|
|
\$this.remove(); |
|
1358
|
|
|
data.abort(); |
|
1359
|
|
|
}); |
|
1360
|
|
|
data.submit().always(function () { |
|
1361
|
|
|
\$this.remove(); |
|
1362
|
|
|
}); |
|
1363
|
|
|
}); |
|
1364
|
|
|
|
|
1365
|
|
|
$('#".$inputName."').fileupload({ |
|
1366
|
|
|
url: url, |
|
1367
|
|
|
dataType: 'json', |
|
1368
|
|
|
autoUpload: true, |
|
1369
|
|
|
// Enable image resizing, except for Android and Opera, |
|
1370
|
|
|
// which actually support image resizing, but fail to |
|
1371
|
|
|
// send Blob objects via XHR requests: |
|
1372
|
|
|
disableImageResize: /Android(?!.*Chrome)|Opera/.test(window.navigator.userAgent), |
|
1373
|
|
|
previewMaxWidth: 100, |
|
1374
|
|
|
previewMaxHeight: 100, |
|
1375
|
|
|
previewCrop: true, |
|
1376
|
|
|
dropzone: $('#dropzone') |
|
1377
|
|
|
}).on('fileuploadadd', function (e, data) { |
|
1378
|
|
|
data.context = $('<div/>').appendTo('#files'); |
|
1379
|
|
|
$.each(data.files, function (index, file) { |
|
1380
|
|
|
var node = $('<p/>').append($('<span/>').text(file.name)); |
|
1381
|
|
|
/*if (!index) { |
|
1382
|
|
|
node |
|
1383
|
|
|
.append('<br>') |
|
1384
|
|
|
.append(uploadButton.clone(true).data(data)); |
|
1385
|
|
|
}*/ |
|
1386
|
|
|
node.appendTo(data.context); |
|
1387
|
|
|
} |
|
1388
|
|
|
); |
|
1389
|
|
|
}).on('fileuploadprocessalways', function (e, data) { |
|
1390
|
|
|
var index = data.index, |
|
1391
|
|
|
file = data.files[index], |
|
1392
|
|
|
node = $(data.context.children()[index]); |
|
1393
|
|
|
if (file.preview) { |
|
1394
|
|
|
node |
|
1395
|
|
|
.prepend('<br>') |
|
1396
|
|
|
.prepend(file.preview); |
|
1397
|
|
|
} |
|
1398
|
|
|
if (file.error) { |
|
1399
|
|
|
node |
|
1400
|
|
|
.append('<br>') |
|
1401
|
|
|
.append($('<span class=\"text-danger\"/>').text(file.error)); |
|
1402
|
|
|
} |
|
1403
|
|
|
if (index + 1 === data.files.length) { |
|
1404
|
|
|
data.context.find('button') |
|
1405
|
|
|
.text('Upload') |
|
1406
|
|
|
.prop('disabled', !!data.files.error); |
|
1407
|
|
|
} |
|
1408
|
|
|
}).on('fileuploadprogressall', function (e, data) { |
|
1409
|
|
|
var progress = parseInt(data.loaded / data.total * 100, 10); |
|
1410
|
|
|
$('#progress .progress-bar').css( |
|
1411
|
|
|
'width', |
|
1412
|
|
|
progress + '%' |
|
1413
|
|
|
); |
|
1414
|
|
|
}).on('fileuploaddone', function (e, data) { |
|
1415
|
|
|
|
|
1416
|
|
|
$.each(data.result.files, function (index, file) { |
|
1417
|
|
|
if (file.url) { |
|
1418
|
|
|
var link = $('<a>') |
|
1419
|
|
|
.attr('target', '_blank') |
|
1420
|
|
|
.prop('href', file.url); |
|
1421
|
|
|
|
|
1422
|
|
|
$(data.context.children()[index]).wrap(link); |
|
1423
|
|
|
} else if (file.error) { |
|
1424
|
|
|
var error = $('<span class=\"text-danger\"/>').text(file.error); |
|
1425
|
|
|
$(data.context.children()[index]) |
|
1426
|
|
|
.append('<br>') |
|
1427
|
|
|
.append(error); |
|
1428
|
|
|
} |
|
1429
|
|
|
}); |
|
1430
|
|
|
}).on('fileuploadfail', function (e, data) { |
|
1431
|
|
|
$.each(data.files, function (index) { |
|
1432
|
|
|
var error = $('<span class=\"text-danger\"/>').text('".get_lang('Failed')."'); |
|
1433
|
|
|
$(data.context.children()[index]) |
|
1434
|
|
|
.append('<br>') |
|
1435
|
|
|
.append(error); |
|
1436
|
|
|
}); |
|
1437
|
|
|
}).prop('disabled', !$.support.fileInput) |
|
1438
|
|
|
.parent().addClass($.support.fileInput ? undefined : 'disabled'); |
|
1439
|
|
|
|
|
1440
|
|
|
$('.fileinput-button').hide(); |
|
1441
|
|
|
|
|
1442
|
|
|
}); |
|
1443
|
|
|
</script>" |
|
1444
|
|
|
); |
|
1445
|
|
|
} |
|
1446
|
|
|
} |
|
1447
|
|
|
|
|
1448
|
|
|
/** |
|
1449
|
|
|
* Cleans HTML text filter |
|
1450
|
|
|
* @param string $html HTML to clean |
|
1451
|
|
|
* @param int $mode (optional) |
|
1452
|
|
|
* @return string The cleaned HTML |
|
1453
|
|
|
*/ |
|
1454
|
|
|
function html_filter($html, $mode = NO_HTML) |
|
1455
|
|
|
{ |
|
1456
|
|
|
$allowed_tags = HTML_QuickForm_Rule_HTML::get_allowed_tags($mode); |
|
1457
|
|
|
$cleaned_html = kses($html, $allowed_tags); |
|
1458
|
|
|
return $cleaned_html; |
|
1459
|
|
|
} |
|
1460
|
|
|
|
|
1461
|
|
|
function html_filter_teacher($html) |
|
1462
|
|
|
{ |
|
1463
|
|
|
return html_filter($html, TEACHER_HTML); |
|
1464
|
|
|
} |
|
1465
|
|
|
|
|
1466
|
|
|
function html_filter_student($html) |
|
1467
|
|
|
{ |
|
1468
|
|
|
return html_filter($html, STUDENT_HTML); |
|
1469
|
|
|
} |
|
1470
|
|
|
|
|
1471
|
|
|
function html_filter_teacher_fullpage($html) |
|
1472
|
|
|
{ |
|
1473
|
|
|
return html_filter($html, TEACHER_HTML_FULLPAGE); |
|
1474
|
|
|
} |
|
1475
|
|
|
|
|
1476
|
|
|
function html_filter_student_fullpage($html) |
|
1477
|
|
|
{ |
|
1478
|
|
|
return html_filter($html, STUDENT_HTML_FULLPAGE); |
|
1479
|
|
|
} |
|
1480
|
|
|
|
|
1481
|
|
|
/** |
|
1482
|
|
|
* Cleans mobile phone number text |
|
1483
|
|
|
* @param string $mobilePhoneNumber Mobile phone number to clean |
|
1484
|
|
|
* @return string The cleaned mobile phone number |
|
1485
|
|
|
*/ |
|
1486
|
|
|
function mobile_phone_number_filter($mobilePhoneNumber) |
|
1487
|
|
|
{ |
|
1488
|
|
|
$mobilePhoneNumber = str_replace(array('+', '(', ')'), '', $mobilePhoneNumber); |
|
1489
|
|
|
|
|
1490
|
|
|
return ltrim($mobilePhoneNumber, '0'); |
|
1491
|
|
|
} |
|
1492
|
|
|
|
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.