FormValidator.class.php 24 KB

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