FormValidator.class.php 24 KB

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