FormValidator.class.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. require_once api_get_path(LIBRARY_PATH).'pear/HTML/QuickForm.php';
  4. require_once api_get_path(LIBRARY_PATH).'pear/HTML/QuickForm/advmultiselect.php';
  5. /**
  6. * Filter
  7. */
  8. define('NO_HTML', 1);
  9. define('STUDENT_HTML', 2);
  10. define('TEACHER_HTML', 3);
  11. define('STUDENT_HTML_FULLPAGE', 4);
  12. define('TEACHER_HTML_FULLPAGE', 5);
  13. /**
  14. * Objects of this class can be used to create/manipulate/validate user input.
  15. */
  16. class FormValidator extends HTML_QuickForm
  17. {
  18. /**
  19. * Create a form validator based on an array of form data:
  20. *
  21. * array(
  22. * 'name' => 'zombie_report_parameters', //optional
  23. * 'method' => 'GET', //optional
  24. * 'items' => array(
  25. * array(
  26. * 'name' => 'ceiling',
  27. * 'label' => 'Ceiling', //optional
  28. * 'type' => 'date',
  29. * 'default' => date() //optional
  30. * ),
  31. * array(
  32. * 'name' => 'active_only',
  33. * 'label' => 'ActiveOnly',
  34. * 'type' => 'checkbox',
  35. * 'default' => true
  36. * ),
  37. * array(
  38. * 'name' => 'submit_button',
  39. * 'type' => 'style_submit_button',
  40. * 'value' => get_lang('Search'),
  41. * 'attributes' => array('class' => 'search')
  42. * )
  43. * )
  44. * );
  45. *
  46. * @param array form_data
  47. * @return FormValidator
  48. */
  49. static function create($form_data)
  50. {
  51. if (empty($form_data)) {
  52. return null;
  53. }
  54. $form_name = isset($form_data['name']) ? $form_data['name'] : 'form';
  55. $form_method = isset($form_data['method']) ? $form_data['method'] : 'POST';
  56. $form_action = isset($form_data['action']) ? $form_data['action'] : '';
  57. $form_target = isset($form_data['target']) ? $form_data['target'] : '';
  58. $form_attributes = isset($form_data['attributes']) ? $form_data['attributes'] : null;
  59. $form_track_submit = isset($form_data['track_submit']) ? $form_data['track_submit'] : true;
  60. $result = new FormValidator($form_name, $form_method, $form_action, $form_target, $form_attributes, $form_track_submit);
  61. $defaults = array();
  62. foreach ($form_data['items'] as $item) {
  63. $name = $item['name'];
  64. $type = isset($item['type']) ? $item['type'] : 'text';
  65. $label = isset($item['label']) ? $item['label'] : '';
  66. if ($type == 'wysiwyg') {
  67. $element = $result->add_html_editor($name, $label);
  68. } else {
  69. $element = $result->addElement($type, $name, $label);
  70. }
  71. if (isset($item['attributes'])) {
  72. $attributes = $item['attributes'];
  73. $element->setAttributes($attributes);
  74. }
  75. if (isset($item['value'])) {
  76. $value = $item['value'];
  77. $element->setValue($value);
  78. }
  79. if (isset($item['default'])) {
  80. $defaults[$name] = $item['default'];
  81. }
  82. if (isset($item['rules'])) {
  83. $rules = $item['rules'];
  84. foreach ($rules as $rule) {
  85. $message = $rule['message'];
  86. $type = $rule['type'];
  87. $format = isset($rule['format']) ? $rule['format'] : null;
  88. $validation = isset($rule['validation']) ? $rule['validation'] : 'server';
  89. $force = isset($rule['force']) ? $rule['force'] : false;
  90. $result->addRule($name, $message, $type, $format, $validation, $reset, $force);
  91. }
  92. }
  93. }
  94. $result->setDefaults($defaults);
  95. return $result;
  96. }
  97. var $with_progress_bar = false;
  98. /**
  99. * Constructor
  100. * @param string $form_name Name of the form
  101. * @param string $method (optional Method ('post' (default) or 'get')
  102. * @param string $action (optional Action (default is $PHP_SELF)
  103. * @param string $target (optional Form's target defaults to '_self'
  104. * @param mixed $attributes (optional) Extra attributes for <form> tag
  105. * @param bool $track_submit (optional) Whether to track if the form was
  106. * submitted by adding a special hidden field (default = true)
  107. */
  108. function __construct($form_name, $method = 'post', $action = '', $target = '', $attributes = null, $track_submit = true)
  109. {
  110. // Default form class.
  111. if (is_array($attributes) && !isset($attributes['class']) || empty($attributes)) {
  112. $attributes['class'] = 'form-horizontal';
  113. }
  114. parent::__construct($form_name, $method, $action, $target, $attributes, $track_submit);
  115. // Load some custom elements and rules
  116. $dir = api_get_path(LIBRARY_PATH) . 'formvalidator/';
  117. $this->registerElementType('html_editor', $dir . 'Element/html_editor.php', 'HTML_QuickForm_html_editor');
  118. $this->registerElementType('datetimepicker', $dir . 'Element/DateTimePicker.php', 'DateTimePicker');
  119. $this->registerElementType('datepicker', $dir . 'Element/datepicker.php', 'HTML_QuickForm_datepicker');
  120. $this->registerElementType('datepickerdate', $dir . 'Element/datepickerdate.php', 'HTML_QuickForm_datepickerdate');
  121. $this->registerElementType('receivers', $dir . 'Element/receivers.php', 'HTML_QuickForm_receivers');
  122. $this->registerElementType('select_language', $dir . 'Element/select_language.php', 'HTML_QuickForm_Select_Language');
  123. $this->registerElementType('select_ajax', $dir . 'Element/select_ajax.php', 'HTML_QuickForm_Select_Ajax');
  124. $this->registerElementType('select_theme', $dir . 'Element/select_theme.php', 'HTML_QuickForm_Select_Theme');
  125. $this->registerElementType('style_submit_button', $dir . 'Element/style_submit_button.php', 'HTML_QuickForm_stylesubmitbutton');
  126. $this->registerElementType('style_reset_button', $dir . 'Element/style_reset_button.php', 'HTML_QuickForm_styleresetbutton');
  127. $this->registerElementType('button', $dir . 'Element/style_submit_button.php', 'HTML_QuickForm_stylesubmitbutton');
  128. $this->registerElementType('captcha', 'HTML/QuickForm/CAPTCHA.php', 'HTML_QuickForm_CAPTCHA');
  129. $this->registerElementType('CAPTCHA_Image', 'HTML/QuickForm/CAPTCHA/Image.php', 'HTML_QuickForm_CAPTCHA_Image');
  130. $this->registerRule('date', null, 'HTML_QuickForm_Rule_Date', $dir . 'Rule/Date.php');
  131. $this->registerRule('date_compare', null, 'HTML_QuickForm_Rule_DateCompare', $dir . 'Rule/DateCompare.php');
  132. $this->registerRule('html', null, 'HTML_QuickForm_Rule_HTML', $dir . 'Rule/HTML.php');
  133. $this->registerRule('username_available', null, 'HTML_QuickForm_Rule_UsernameAvailable', $dir . 'Rule/UsernameAvailable.php');
  134. $this->registerRule('username', null, 'HTML_QuickForm_Rule_Username', $dir . 'Rule/Username.php');
  135. $this->registerRule('filetype', null, 'HTML_QuickForm_Rule_Filetype', $dir . 'Rule/Filetype.php');
  136. $this->registerRule('multiple_required', 'required', 'HTML_QuickForm_Rule_MultipleRequired', $dir . 'Rule/MultipleRequired.php');
  137. $this->registerRule('url', null, 'HTML_QuickForm_Rule_Url', $dir . 'Rule/Url.php');
  138. $this->registerRule('compare_fields', null, 'HTML_QuickForm_Compare_Fields', $dir . 'Rule/CompareFields.php');
  139. $this->registerRule('CAPTCHA', 'rule', 'HTML_QuickForm_Rule_CAPTCHA', 'HTML/QuickForm/Rule/CAPTCHA.php');
  140. // Modify the default templates
  141. $renderer = & $this->defaultRenderer();
  142. //Form template
  143. $form_template = '<form{attributes}>
  144. <fieldset>
  145. {content}
  146. <div class="clear"></div>
  147. </fieldset>
  148. {hidden}
  149. </form>';
  150. $renderer->setFormTemplate($form_template);
  151. //Element template
  152. if (isset($attributes['class']) && $attributes['class'] == 'well form-inline') {
  153. $element_template = ' {label} {element} ';
  154. $renderer->setElementTemplate($element_template);
  155. } elseif (isset($attributes['class']) && $attributes['class'] == 'form-search') {
  156. $element_template = ' {label} {element} ';
  157. $renderer->setElementTemplate($element_template);
  158. } else {
  159. $element_template = '
  160. <div class="control-group {error_class}">
  161. <label class="control-label">
  162. <!-- BEGIN required --><span class="form_required">*</span><!-- END required -->
  163. {label}
  164. </label>
  165. <div class="controls">
  166. {element}
  167. <!-- BEGIN label_3 -->
  168. {label_3}
  169. <!-- END label_3 -->
  170. <!-- BEGIN label_2 -->
  171. <p class="help-block">{label_2}</p>
  172. <!-- END label_2 -->
  173. <!-- BEGIN error -->
  174. <span class="help-inline">{error}</span>
  175. <!-- END error -->
  176. </div>
  177. </div>';
  178. $renderer->setElementTemplate($element_template);
  179. //Display a gray div in the buttons
  180. $button_element_template_simple = '<div class="form-actions">{label} {element}</div>';
  181. $renderer->setElementTemplate($button_element_template_simple, 'submit_in_actions');
  182. //Display a gray div in the buttons + makes the button available when scrolling
  183. $button_element_template_in_bottom = '<div class="form-actions bottom_actions">{label} {element}</div>';
  184. $renderer->setElementTemplate($button_element_template_in_bottom, 'submit_fixed_in_bottom');
  185. //When you want to group buttons use something like this
  186. /* $group = array();
  187. $group[] = $form->createElement('button', 'mark_all', get_lang('MarkAll'));
  188. $group[] = $form->createElement('button', 'unmark_all', get_lang('UnmarkAll'));
  189. $form->addGroup($group, 'buttons_in_action');
  190. */
  191. $renderer->setElementTemplate($button_element_template_simple, 'buttons_in_action');
  192. $button_element_template_simple_right = '<div class="form-actions"> <div class="pull-right">{label} {element}</div></div>';
  193. $renderer->setElementTemplate($button_element_template_simple_right, 'buttons_in_action_right');
  194. /*
  195. $renderer->setElementTemplate($button_element_template, 'submit_button');
  196. $renderer->setElementTemplate($button_element_template, 'submit');
  197. $renderer->setElementTemplate($button_element_template, 'button');
  198. *
  199. */
  200. }
  201. //Set Header template
  202. $renderer->setHeaderTemplate('<legend>{header}</legend>');
  203. //Set required field template
  204. HTML_QuickForm::setRequiredNote('<span class="form_required">*</span> <small>' . get_lang('ThisFieldIsRequired') . '</small>');
  205. $required_note_template = <<<EOT
  206. <div class="control-group">
  207. <div class="controls">{requiredNote}</div>
  208. </div>
  209. EOT;
  210. $renderer->setRequiredNoteTemplate($required_note_template);
  211. }
  212. /**
  213. * Adds a text field to the form.
  214. * A trim-filter is attached to the field.
  215. * @param string $label The label for the form-element
  216. * @param string $name The element name
  217. * @param boolean $required (optional) Is the form-element required (default=true)
  218. * @param array $attributes (optional) List of attributes for the form-element
  219. */
  220. function add_textfield($name, $label, $required = true, $attributes = array())
  221. {
  222. $this->addElement('text', $name, $label, $attributes);
  223. $this->applyFilter($name, 'trim');
  224. if ($required) {
  225. $this->addRule($name, get_lang('ThisFieldIsRequired'), 'required');
  226. }
  227. }
  228. function add_hidden($name, $value)
  229. {
  230. $this->addElement('hidden', $name, $value);
  231. }
  232. function add_textarea($name, $label, $attributes = array())
  233. {
  234. $this->addElement('textarea', $name, $label, $attributes);
  235. }
  236. function add_button($name, $label, $attributes = array())
  237. {
  238. $this->addElement('button', $name, $label, $attributes);
  239. }
  240. function add_checkbox($name, $label, $trailer = '', $attributes = array())
  241. {
  242. $this->addElement('checkbox', $name, $label, $trailer, $attributes);
  243. }
  244. function add_radio($name, $label, $options = '')
  245. {
  246. $group = array();
  247. foreach ($options as $key => $value) {
  248. $group[] = $this->createElement('radio', null, null, $value, $key);
  249. }
  250. $this->addGroup($group, $name, $label);
  251. }
  252. function add_select($name, $label, $options = '', $attributes = array())
  253. {
  254. $this->addElement('select', $name, $label, $options, $attributes);
  255. }
  256. function add_label($label, $text)
  257. {
  258. $this->addElement('label', $label, $text);
  259. }
  260. function add_header($text)
  261. {
  262. $this->addElement('header', $text);
  263. }
  264. function add_file($name, $label, $attributes = array())
  265. {
  266. $this->addElement('file', $name, $label, $attributes);
  267. }
  268. function add_html($snippet)
  269. {
  270. $this->addElement('html', $snippet);
  271. }
  272. /**
  273. * Adds a HTML-editor to the form to fill in a title.
  274. * A trim-filter is attached to the field.
  275. * A HTML-filter is attached to the field (cleans HTML)
  276. * A rule is attached to check for unwanted HTML
  277. * @param string $label The label for the form-element
  278. * @param string $name The element name
  279. * @param boolean $required (optional) Is the form-element required (default=true)
  280. * @param boolean $full_page (optional) When it is true, the editor loads completed html code for a full page.
  281. * @param array $editor_config (optional) Configuration settings for the online editor.
  282. */
  283. function add_html_editor($name, $label, $required = true, $full_page = false, $config = null)
  284. {
  285. $this->addElement('html_editor', $name, $label, 'rows="15" cols="80"', $config);
  286. $this->applyFilter($name, 'trim');
  287. $html_type = STUDENT_HTML;
  288. if (!empty($_SESSION['status'])) {
  289. $html_type = $_SESSION['status'] == COURSEMANAGER ? TEACHER_HTML : STUDENT_HTML;
  290. }
  291. if (is_array($config)) {
  292. if (isset($config['FullPage'])) {
  293. $full_page = is_bool($config['FullPage']) ? $config['FullPage'] : ($config['FullPage'] === 'true');
  294. } else {
  295. $config['FullPage'] = $full_page;
  296. }
  297. } else {
  298. $config = array('FullPage' => (bool) $full_page);
  299. }
  300. if ($full_page) {
  301. $html_type = isset($_SESSION['status']) && $_SESSION['status'] == COURSEMANAGER ? TEACHER_HTML_FULLPAGE : STUDENT_HTML_FULLPAGE;
  302. //First *filter* the HTML (markup, indenting, ...)
  303. //$this->applyFilter($name,'html_filter_teacher_fullpage');
  304. } else {
  305. //First *filter* the HTML (markup, indenting, ...)
  306. //$this->applyFilter($name,'html_filter_teacher');
  307. }
  308. if ($required) {
  309. $this->addRule($name, get_lang('ThisFieldIsRequired'), 'required');
  310. }
  311. if ($full_page) {
  312. $el = $this->getElement($name);
  313. $el->fullPage = true;
  314. }
  315. // Add rule to check not-allowed HTML
  316. //$this->addRule($name, get_lang('SomeHTMLNotAllowed'), 'html', $html_type);
  317. }
  318. /**
  319. * Adds a datepicker element to the form
  320. * A rule is added to check if the date is a valid one
  321. * @param string $label The label for the form-element
  322. * @param string $name The element name
  323. */
  324. function add_datepicker($name, $label)
  325. {
  326. $this->addElement('datepicker', $name, $label, array('form_name' => $this->getAttribute('name')));
  327. $this->_elements[$this->_elementIndex[$name]]->setLocalOption('minYear', 1900); // TODO: Now - 9 years
  328. $this->addRule($name, get_lang('InvalidDate'), 'date');
  329. }
  330. /**
  331. * Adds a datepickerdate element to the form
  332. * A rule is added to check if the date is a valid one
  333. * @param string $label The label for the form-element
  334. * @param string $name The element name
  335. */
  336. function add_datepickerdate($name, $label)
  337. {
  338. $this->addElement('datepickerdate', $name, $label, array('form_name' => $this->getAttribute('name')));
  339. $this->_elements[$this->_elementIndex[$name]]->setLocalOption('minYear', 1900); // TODO: Now - 9 years
  340. $this->addRule($name, get_lang('InvalidDate'), 'date');
  341. }
  342. /**
  343. * Adds a timewindow element to the form.
  344. * 2 datepicker elements are added and a rule to check if the first date is
  345. * before the second one.
  346. * @param string $label The label for the form-element
  347. * @param string $name The element name
  348. */
  349. function add_timewindow($name_1, $name_2, $label_1, $label_2)
  350. {
  351. $this->add_datepicker($name_1, $label_1);
  352. $this->add_datepicker($name_2, $label_2);
  353. $this->addRule(array($name_1, $name_2), get_lang('StartDateShouldBeBeforeEndDate'), 'date_compare', 'lte');
  354. }
  355. /**
  356. * Adds a button to the form to add resources.
  357. */
  358. function add_resource_button()
  359. {
  360. $group = array();
  361. $group[] = $this->createElement('static', 'add_resource_img', null, '<img src="' . api_get_path(WEB_IMG_PATH) . 'attachment.gif" alt="' . get_lang('Attachment') . '"/>');
  362. $group[] = $this->createElement('submit', 'add_resource', get_lang('Attachment'), 'class="link_alike"');
  363. $this->addGroup($group);
  364. }
  365. /**
  366. * Adds a progress bar to the form.
  367. *
  368. * Once the user submits the form, a progress bar (animated gif) is
  369. * displayed. The progress bar will disappear once the page has been
  370. * reloaded.
  371. *
  372. * @param int $delay (optional) The number of seconds between the moment the user
  373. * @param string $label (optional) Custom label to be shown
  374. * submits the form and the start of the progress bar.
  375. */
  376. function add_progress_bar($delay = 2, $label = '')
  377. {
  378. if (empty($label)) {
  379. $label = get_lang('PleaseStandBy');
  380. }
  381. $this->with_progress_bar = true;
  382. $this->updateAttributes("onsubmit=\"javascript: myUpload.start('dynamic_div','" . api_get_path(WEB_IMG_PATH) . "progress_bar.gif','" . $label . "','" . $this->getAttribute('id') . "')\"");
  383. $this->addElement('html', '<script language="javascript" src="' . api_get_path(WEB_LIBRARY_PATH) . 'javascript/upload.js" type="text/javascript"></script>');
  384. $this->addElement('html', '<script type="text/javascript">var myUpload = new upload(' . (abs(intval($delay)) * 1000) . ');</script>');
  385. }
  386. /**
  387. * Uses new functions (php 5.2) for displaying real upload progress.
  388. * @param string $upload_id The value of the field UPLOAD_IDENTIFIER, the second parameter (XXX) of the $form->addElement('file', XXX) sentence
  389. * @param string $element_after The first element of the form (to place at first UPLOAD_IDENTIFIER)
  390. * @param int $delay (optional) The frequency of the xajax call
  391. * @param bool $wait_after_upload (optional)
  392. */
  393. function add_real_progress_bar($upload_id, $element_after, $delay = 2, $wait_after_upload = false)
  394. {
  395. if (!function_exists('uploadprogress_get_info')) {
  396. $this->add_progress_bar($delay);
  397. return;
  398. }
  399. if (!class_exists('xajax')) {
  400. require_once api_get_path(LIBRARY_PATH) . 'xajax/xajax.inc.php';
  401. }
  402. $xajax_upload = new xajax(api_get_path(WEB_LIBRARY_PATH) . 'upload.xajax.php');
  403. $xajax_upload->registerFunction('updateProgress');
  404. // IMPORTANT : must be the first element of the form
  405. $el = $this->insertElementBefore(FormValidator::createElement('html', '<input type="hidden" name="UPLOAD_IDENTIFIER" value="' . $upload_id . '" />'), $element_after);
  406. $this->addElement('html', '<br />');
  407. // Add div-element where the progress bar is to be displayed
  408. $this->addElement('html', '
  409. <div id="dynamic_div_container" style="display:none">
  410. <div id="dynamic_div_label">' . get_lang('UploadFile') . '</div>
  411. <div id="dynamic_div_frame" style="width:214px; height:12px; border:1px solid grey; background-image:url(' . api_get_path(WEB_IMG_PATH) . 'real_upload_frame.gif);">
  412. <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>
  413. </div>
  414. </div>');
  415. if ($wait_after_upload) {
  416. $this->addElement('html', '
  417. <div id="dynamic_div_waiter_container" style="display:none">
  418. <div id="dynamic_div_waiter_label">
  419. ' . get_lang('SlideshowConversion') . '
  420. </div>
  421. <div id="dynamic_div_waiter_frame">
  422. <img src="' . api_get_path(WEB_IMG_PATH) . 'real_upload_frame.gif" />
  423. </div>
  424. </div>
  425. ');
  426. }
  427. // Get the xajax code
  428. $this->addElement('html', $xajax_upload->getJavascript(api_get_path(WEB_LIBRARY_PATH) . 'xajax'));
  429. // Get the upload code
  430. $this->addElement('html', '<script language="javascript" src="' . api_get_path(WEB_LIBRARY_PATH) . 'javascript/upload.js" type="text/javascript"></script>');
  431. $this->addElement('html', '<script type="text/javascript">var myUpload = new upload(' . (abs(intval($delay)) * 1000) . ');</script>');
  432. if (!$wait_after_upload) {
  433. $wait_after_upload = 0;
  434. }
  435. // Add the upload event
  436. $this->updateAttributes("onsubmit=\"javascript: myUpload.startRealUpload('dynamic_div','" . $upload_id . "','" . $this->getAttribute('id') . "'," . $wait_after_upload . ")\"");
  437. }
  438. /**
  439. * This function has been created for avoiding changes directly within QuickForm class.
  440. * When we use it, the element is threated as 'required' to be dealt during validation.
  441. * @param array $element The array of elements
  442. * @param string $message The message displayed
  443. */
  444. function add_multiple_required_rule($elements, $message)
  445. {
  446. $this->_required[] = $elements[0];
  447. $this->addRule($elements, $message, 'multiple_required');
  448. }
  449. /**
  450. * Displays the form.
  451. * If an element in the form didn't validate, an error message is showed
  452. * asking the user to complete the form.
  453. */
  454. function display()
  455. {
  456. echo $this->return_form();
  457. }
  458. /**
  459. * Returns the HTML code of the form.
  460. * If an element in the form didn't validate, an error message is showed
  461. * asking the user to complete the form.
  462. *
  463. * @return string $return_value HTML code of the form
  464. *
  465. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, august 2006
  466. */
  467. function return_form()
  468. {
  469. $error = false;
  470. foreach ($this->_elements as $element) {
  471. if (!is_null(parent::getElementError($element->getName()))) {
  472. $error = true;
  473. break;
  474. }
  475. }
  476. $return_value = '';
  477. if ($error) {
  478. $return_value = Display::return_message(get_lang('FormHasErrorsPleaseComplete'), 'warning');
  479. }
  480. $return_value .= parent::toHtml();
  481. // Add div-element which is to hold the progress bar
  482. if (isset($this->with_progress_bar) && $this->with_progress_bar) {
  483. $return_value .= '<div id="dynamic_div" style="display:block; margin-left:40%; margin-top:10px; height:50px;"></div>';
  484. }
  485. return $return_value;
  486. }
  487. }
  488. /**
  489. * Cleans HTML text
  490. * @param string $html HTML to clean
  491. * @param int $mode (optional)
  492. * @return string The cleaned HTML
  493. */
  494. function html_filter($html, $mode = NO_HTML)
  495. {
  496. require_once api_get_path(LIBRARY_PATH) . 'formvalidator/Rule/HTML.php';
  497. $allowed_tags = HTML_QuickForm_Rule_HTML::get_allowed_tags($mode);
  498. $cleaned_html = kses($html, $allowed_tags);
  499. return $cleaned_html;
  500. }
  501. function html_filter_teacher($html)
  502. {
  503. return html_filter($html, TEACHER_HTML);
  504. }
  505. function html_filter_student($html)
  506. {
  507. return html_filter($html, STUDENT_HTML);
  508. }
  509. function html_filter_teacher_fullpage($html)
  510. {
  511. return html_filter($html, TEACHER_HTML_FULLPAGE);
  512. }
  513. function html_filter_student_fullpage($html)
  514. {
  515. return html_filter($html, STUDENT_HTML_FULLPAGE);
  516. }