123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851 |
- <?php
- /* For licensing terms, see /license.txt */
- /**
- * Class FormValidator
- * create/manipulate/validate user input.
- */
- class FormValidator extends HTML_QuickForm
- {
- const LAYOUT_HORIZONTAL = 'horizontal';
- const LAYOUT_INLINE = 'inline';
- const LAYOUT_BOX = 'box';
- const LAYOUT_BOX_NO_LABEL = 'box-no-label';
- public $with_progress_bar = false;
- private $layout;
- /**
- * Constructor.
- *
- * @param string $name Name of the form
- * @param string $method (optional) Method ('post' (default) or 'get')
- * @param string $action (optional) Action (default is $PHP_SELF)
- * @param string $target (optional) Form's target defaults to '_self'
- * @param mixed $attributes (optional) Extra attributes for <form> tag
- * @param string $layout
- * @param bool $trackSubmit (optional) Whether to track if the form was
- * submitted by adding a special hidden field (default = true)
- */
- public function __construct(
- $name,
- $method = 'post',
- $action = '',
- $target = '',
- $attributes = [],
- $layout = self::LAYOUT_HORIZONTAL,
- $trackSubmit = true
- ) {
- // Default form class.
- if (is_array($attributes) && !isset($attributes['class']) || empty($attributes)) {
- $attributes['class'] = 'form-horizontal';
- }
- if (isset($attributes['class']) && strpos($attributes['class'], 'form-search') !== false) {
- $layout = 'inline';
- }
- $this->setLayout($layout);
- switch ($layout) {
- case self::LAYOUT_HORIZONTAL:
- $attributes['class'] = 'form-horizontal';
- break;
- case self::LAYOUT_INLINE:
- case self::LAYOUT_BOX:
- $attributes['class'] = 'form-inline';
- break;
- }
- parent::__construct($name, $method, $action, $target, $attributes, $trackSubmit);
- // Modify the default templates
- $renderer = &$this->defaultRenderer();
- // Form template
- $formTemplate = $this->getFormTemplate();
- $renderer->setFormTemplate($formTemplate);
- // Element template
- if (isset($attributes['class']) && $attributes['class'] == 'form-inline') {
- $elementTemplate = ' {label} {element} ';
- $renderer->setElementTemplate($elementTemplate);
- } elseif (isset($attributes['class']) && $attributes['class'] == 'form-search') {
- $elementTemplate = ' {label} {element} ';
- $renderer->setElementTemplate($elementTemplate);
- } else {
- $renderer->setElementTemplate($this->getDefaultElementTemplate());
- // Display a gray div in the buttons
- $templateSimple = '<div class="form-actions">{label} {element}</div>';
- $renderer->setElementTemplate($templateSimple, 'submit_in_actions');
- //Display a gray div in the buttons + makes the button available when scrolling
- $templateBottom = '<div class="form-actions bottom_actions bg-form">{label} {element}</div>';
- $renderer->setElementTemplate($templateBottom, 'submit_fixed_in_bottom');
- //When you want to group buttons use something like this
- /* $group = array();
- $group[] = $form->createElement('button', 'mark_all', get_lang('MarkAll'));
- $group[] = $form->createElement('button', 'unmark_all', get_lang('UnmarkAll'));
- $form->addGroup($group, 'buttons_in_action');
- */
- $renderer->setElementTemplate($templateSimple, 'buttons_in_action');
- $templateSimpleRight = '<div class="form-actions"> <div class="pull-right">{label} {element}</div></div>';
- $renderer->setElementTemplate($templateSimpleRight, 'buttons_in_action_right');
- }
- //Set Header template
- $renderer->setHeaderTemplate('<legend>{header}</legend>');
- //Set required field template
- $this->setRequiredNote(
- '<span class="form_required">*</span> <small>'.get_lang('ThisFieldIsRequired').'</small>'
- );
- $noteTemplate = <<<EOT
- <div class="form-group">
- <div class="col-sm-offset-2 col-sm-10">{requiredNote}</div>
- </div>
- EOT;
- $renderer->setRequiredNoteTemplate($noteTemplate);
- }
- /**
- * @return string
- */
- public function getFormTemplate()
- {
- return '<form{attributes}>
- <fieldset>
- {content}
- </fieldset>
- {hidden}
- </form>';
- }
- /**
- * @todo this function should be added in the element class
- *
- * @return string
- */
- public function getDefaultElementTemplate()
- {
- return '
- <div class="form-group {error_class}">
- <label {label-for} class="col-sm-2 control-label {extra_label_class}" >
- <!-- BEGIN required --><span class="form_required">*</span><!-- END required -->
- {label}
- </label>
- <div class="col-sm-8">
- {icon}
- {element}
- <!-- BEGIN label_2 -->
- <p class="help-block">{label_2}</p>
- <!-- END label_2 -->
- <!-- BEGIN error -->
- <span class="help-inline help-block">{error}</span>
- <!-- END error -->
- </div>
- <div class="col-sm-2">
- <!-- BEGIN label_3 -->
- {label_3}
- <!-- END label_3 -->
- </div>
- </div>';
- }
- /**
- * @return string
- */
- public function getLayout()
- {
- return $this->layout;
- }
- /**
- * @param string $layout
- */
- public function setLayout($layout)
- {
- $this->layout = $layout;
- }
- /**
- * Adds a text field to the form.
- * A trim-filter is attached to the field.
- *
- * @param string|array $label The label for the form-element
- * @param string $name The element name
- * @param bool $required (optional) Is the form-element required (default=true)
- * @param array $attributes (optional) List of attributes for the form-element
- *
- * @return HTML_QuickForm_text
- */
- public function addText($name, $label, $required = true, $attributes = [], $createElement = false)
- {
- if ($createElement) {
- $element = $this->createElement('text', $name, $label, $attributes);
- } else {
- $element = $this->addElement('text', $name, $label, $attributes);
- }
- $this->applyFilter($name, 'trim');
- if ($required) {
- $this->addRule($name, get_lang('ThisFieldIsRequired'), 'required');
- }
- return $element;
- }
- /**
- * Add hidden course params.
- */
- public function addCourseHiddenParams()
- {
- $this->addHidden('cidReq', api_get_course_id());
- $this->addHidden('id_session', api_get_session_id());
- }
- /**
- * The "date_range_picker" element creates 2 hidden fields
- * "elementName" + "_start" and "elementName" + "_end"
- * For example if the name is "range", you will have 2 new fields
- * when executing $form->getSubmitValues()
- * "range_start" and "range_end".
- *
- * @param string $name
- * @param string $label
- * @param bool $required
- * @param array $attributes
- */
- public function addDateRangePicker($name, $label, $required = true, $attributes = [])
- {
- $this->addElement('date_range_picker', $name, $label, $attributes);
- $this->addElement('hidden', $name.'_start');
- $this->addElement('hidden', $name.'_end');
- if ($required) {
- $this->addRule($name, get_lang('ThisFieldIsRequired'), 'required');
- }
- }
- /**
- * @param string $name
- * @param string $label
- * @param array $attributes
- *
- * @return mixed
- */
- public function addDatePicker($name, $label, $attributes = [])
- {
- return $this->addElement('DatePicker', $name, $label, $attributes);
- }
- /**
- * @param string $name
- * @param string $label
- * @param array $attributes
- *
- * @return mixed
- */
- public function addSelectLanguage($name, $label, $options = [], $attributes = [])
- {
- return $this->addElement('SelectLanguage', $name, $label, $options, $attributes);
- }
- /**
- * @param string $name
- * @param string $label
- * @param array $options
- * @param array $attributes
- *
- * @throws
- */
- public function addSelectAjax($name, $label, $options = [], $attributes = [])
- {
- if (!isset($attributes['url'])) {
- throw new \Exception('select_ajax needs an URL');
- }
- $this->addElement(
- 'select_ajax',
- $name,
- $label,
- $options,
- $attributes
- );
- }
- /**
- * @param string $name
- * @param string|array $label
- * @param array $attributes
- *
- * @return DateTimePicker
- */
- public function addDateTimePicker($name, $label, $attributes = [])
- {
- return $this->addElement('DateTimePicker', $name, $label, $attributes);
- }
- /**
- * @param string $name
- * @param string|array $label
- * @param array $attributes
- *
- * @return DateTimeRangePicker
- */
- public function addDateTimeRangePicker($name, $label, $attributes = [])
- {
- return $this->addElement('DateTimeRangePicker', $name, $label, $attributes);
- }
- /**
- * @param string $name
- * @param string $value
- * @param array $attributes
- */
- public function addHidden($name, $value, $attributes = [])
- {
- $this->addElement('hidden', $name, $value, $attributes);
- }
- /**
- * @param string $name
- * @param string|array $label
- * @param array $attributes
- * @param bool $required
- *
- * @return HTML_QuickForm_textarea
- */
- public function addTextarea($name, $label, $attributes = [], $required = false)
- {
- $element = $this->addElement('textarea', $name, $label, $attributes);
- if ($required) {
- $this->addRule($name, get_lang('ThisFieldIsRequired'), 'required');
- }
- return $element;
- }
- /**
- * @param string $name
- * @param string $label
- * @param string $icon font-awesome
- * @param string $style default|primary|success|info|warning|danger|link
- * @param string $size large|default|small|extra-small
- * @param string $class Example plus is transformed to icon fa fa-plus
- * @param array $attributes
- * @param bool $createElement
- *
- * @return HTML_QuickForm_button
- */
- public function addButton(
- $name,
- $label,
- $icon = 'check',
- $style = 'default',
- $size = 'default',
- $class = null,
- $attributes = [],
- $createElement = false
- ) {
- if ($createElement) {
- return $this->createElement(
- 'button',
- $name,
- $label,
- $icon,
- $style,
- $size,
- $class,
- $attributes
- );
- }
- return $this->addElement(
- 'button',
- $name,
- $label,
- $icon,
- $style,
- $size,
- $class,
- $attributes
- );
- }
- /**
- * Returns a button with the primary color and a check mark.
- *
- * @param string $label Text appearing on the button
- * @param string $name Element name (for form treatment purposes)
- * @param bool $createElement Whether to use the create or add method
- *
- * @return HTML_QuickForm_button
- */
- public function addButtonSave($label, $name = 'submit', $createElement = false)
- {
- return $this->addButton(
- $name,
- $label,
- 'check',
- 'primary',
- null,
- null,
- [],
- $createElement
- );
- }
- /**
- * Returns a cancel button.
- *
- * @param string $label Text appearing on the button
- * @param string $name Element name (for form treatment purposes)
- * @param bool $createElement Whether to use the create or add method
- *
- * @return HTML_QuickForm_button
- */
- public function addButtonCancel($label, $name = 'submit', $createElement = false)
- {
- return $this->addButton(
- $name,
- $label,
- 'times',
- 'danger',
- null,
- null,
- [],
- $createElement
- );
- }
- /**
- * Returns a button with the primary color and a "plus" icon.
- *
- * @param string $label Text appearing on the button
- * @param string $name Element name (for form treatment purposes)
- * @param bool $createElement Whether to use the create or add method
- * @param array $attributes Additional attributes
- *
- * @return HTML_QuickForm_button
- */
- public function addButtonCreate($label, $name = 'submit', $createElement = false, $attributes = [])
- {
- return $this->addButton(
- $name,
- $label,
- 'plus',
- 'primary',
- null,
- null,
- $attributes,
- $createElement
- );
- }
- /**
- * Returns a button with the primary color and a pencil icon.
- *
- * @param string $label Text appearing on the button
- * @param string $name Element name (for form treatment purposes)
- * @param bool $createElement Whether to use the create or add method
- *
- * @return HTML_QuickForm_button
- */
- public function addButtonUpdate($label, $name = 'submit', $createElement = false)
- {
- return $this->addButton(
- $name,
- $label,
- 'pencil',
- 'primary',
- null,
- null,
- [],
- $createElement
- );
- }
- /**
- * Returns a button with the danger color and a trash icon.
- *
- * @param string $label Text appearing on the button
- * @param string $name Element name (for form treatment purposes)
- * @param bool $createElement Whether to use the create or add method
- *
- * @return HTML_QuickForm_button
- */
- public function addButtonDelete($label, $name = 'submit', $createElement = false)
- {
- return $this->addButton(
- $name,
- $label,
- 'trash',
- 'danger',
- null,
- null,
- [],
- $createElement
- );
- }
- /**
- * Returns a move style button.
- *
- * @param string $label Text appearing on the button
- * @param string $name Element name (for form treatment purposes)
- * @param bool $createElement Whether to use the create or add method
- *
- * @return HTML_QuickForm_button
- */
- public function addButtonMove($label, $name = 'submit', $createElement = false)
- {
- return $this->addButton(
- $name,
- $label,
- 'arrow-circle-right',
- 'primary',
- null,
- null,
- [],
- $createElement
- );
- }
- /**
- * Returns a button with the primary color and a paper-plane icon.
- *
- * @param string $label Text appearing on the button
- * @param string $name Element name (for form treatment purposes)
- * @param bool $createElement Whether to use the create or add method
- * @param array $attributes
- *
- * @return HTML_QuickForm_button
- */
- public function addButtonSend($label, $name = 'submit', $createElement = false, $attributes = [])
- {
- return $this->addButton(
- $name,
- $label,
- 'paper-plane',
- 'primary',
- null,
- null,
- $attributes,
- $createElement
- );
- }
- /**
- * Returns a button with the default (grey?) color and a magnifier icon.
- *
- * @param string $label Text appearing on the button
- * @param string $name Element name (for form treatment purposes)
- *
- * @return HTML_QuickForm_button
- */
- public function addButtonSearch($label = null, $name = 'submit')
- {
- if (empty($label)) {
- $label = get_lang('Search');
- }
- return $this->addButton($name, $label, 'search', 'default');
- }
- /**
- * Returns a button with the primary color and a right-pointing arrow icon.
- *
- * @param string $label Text appearing on the button
- * @param string $name Element name (for form treatment purposes)
- * @param array $attributes Additional attributes
- *
- * @return HTML_QuickForm_button
- */
- public function addButtonNext($label, $name = 'submit', $attributes = [])
- {
- return $this->addButton(
- $name,
- $label,
- 'arrow-right',
- 'primary',
- null,
- null,
- $attributes
- );
- }
- /**
- * Returns a button with the primary color and a check mark icon.
- *
- * @param string $label Text appearing on the button
- * @param string $name Element name (for form treatment purposes)
- * @param bool $createElement Whether to use the create or add method
- *
- * @return HTML_QuickForm_button
- */
- public function addButtonImport($label, $name = 'submit', $createElement = false)
- {
- return $this->addButton(
- $name,
- $label,
- 'check',
- 'primary',
- null,
- null,
- [],
- $createElement
- );
- }
- /**
- * Returns a button with the primary color and a check-mark icon.
- *
- * @param string $label Text appearing on the button
- * @param string $name Element name (for form treatment purposes)
- * @param bool $createElement Whether to use the create or add method
- *
- * @return HTML_QuickForm_button
- */
- public function addButtonExport($label, $name = 'submit', $createElement = false)
- {
- return $this->addButton(
- $name,
- $label,
- 'check',
- 'primary',
- null,
- null,
- [],
- $createElement
- );
- }
- /**
- * Shortcut to filter button.
- *
- * @param string $label Text appearing on the button
- * @param string $name Element name (for form treatment purposes)
- * @param bool $createElement Whether to use the create or add method
- *
- * @return HTML_QuickForm_button
- */
- public function addButtonFilter($label, $name = 'submit', $createElement = false)
- {
- return $this->addButton(
- $name,
- $label,
- 'filter',
- 'primary',
- null,
- null,
- [],
- $createElement
- );
- }
- /**
- * Shortcut to reset button.
- *
- * @param string $label Text appearing on the button
- * @param string $name Element name (for form treatment purposes)
- * @param bool $createElement Whether to use the create or add method
- *
- * @return HTML_QuickForm_button
- */
- public function addButtonReset($label, $name = 'reset', $createElement = false)
- {
- $icon = 'eraser';
- $style = 'default';
- $size = 'default';
- $class = null;
- $attributes = [];
- if ($createElement) {
- return $this->createElement(
- 'reset',
- $name,
- $label,
- $icon,
- $style,
- $size,
- $class,
- $attributes
- );
- }
- return $this->addElement(
- 'reset',
- $name,
- $label,
- $icon,
- $style,
- $size,
- $class,
- $attributes
- );
- }
- /**
- * Returns a button with the primary color and an upload icon.
- *
- * @param string $label Text appearing on the button
- * @param string $name Element name (for form treatment purposes)
- * @param bool $createElement Whether to use the create or add method
- *
- * @return HTML_QuickForm_button
- */
- public function addButtonUpload($label, $name = 'submit', $createElement = false)
- {
- return $this->addButton(
- $name,
- $label,
- 'upload',
- 'primary',
- null,
- null,
- [],
- $createElement
- );
- }
- /**
- * Returns a button with the primary color and a download icon.
- *
- * @param string $label Text appearing on the button
- * @param string $name Element name (for form treatment purposes)
- * @param bool $createElement Whether to use the create or add method
- *
- * @return HTML_QuickForm_button
- */
- public function addButtonDownload($label, $name = 'submit', $createElement = false)
- {
- return $this->addButton(
- $name,
- $label,
- 'download',
- 'primary',
- null,
- null,
- [],
- $createElement
- );
- }
- /**
- * Returns a button with the primary color and a magnifier icon.
- *
- * @param string $label Text appearing on the button
- * @param string $name Element name (for form treatment purposes)
- * @param bool $createElement Whether to use the create or add method
- *
- * @return HTML_QuickForm_button
- */
- public function addButtonPreview($label, $name = 'submit', $createElement = false)
- {
- return $this->addButton(
- $name,
- $label,
- 'search',
- 'primary',
- null,
- null,
- [],
- $createElement
- );
- }
- /**
- * Returns a button with the primary color and a copy (double sheet) icon.
- *
- * @param string $label Text appearing on the button
- * @param string $name Element name (for form treatment purposes)
- * @param bool $createElement Whether to use the create or add method
- *
- * @return HTML_QuickForm_button
- */
- public function addButtonCopy($label, $name = 'submit', $createElement = false)
- {
- return $this->addButton(
- $name,
- $label,
- 'copy',
- 'primary',
- null,
- null,
- [],
- $createElement
- );
- }
- /**
- * @param string $name
- * @param string $label
- * @param string $text
- * @param array $attributes
- *
- * @return HTML_QuickForm_checkbox
- */
- public function addCheckBox($name, $label, $text = '', $attributes = [])
- {
- return $this->addElement('checkbox', $name, $label, $text, $attributes);
- }
- /**
- * @param string $name
- * @param string $label
- * @param array $options
- * @param array $attributes
- *
- * @return HTML_QuickForm_group
- */
- public function addCheckBoxGroup($name, $label, $options = [], $attributes = [])
- {
- $group = [];
- foreach ($options as $value => $text) {
- $attributes['value'] = $value;
- $group[] = $this->createElement(
- 'checkbox',
- $value,
- null,
- $text,
- $attributes
- );
- }
- return $this->addGroup($group, $name, $label);
- }
- /**
- * @param string $name
- * @param string $label
- * @param array $options
- * @param array $attributes
- *
- * @return HTML_QuickForm_group
- */
- public function addRadio($name, $label, $options = [], $attributes = [])
- {
- $group = [];
- foreach ($options as $key => $value) {
- $group[] = $this->createElement('radio', null, null, $value, $key, $attributes);
- }
- return $this->addGroup($group, $name, $label);
- }
- /**
- * @param string $name
- * @param string $label
- * @param array $options
- * @param array $attributes
- *
- * @return HTML_QuickForm_select
- */
- public function addSelect($name, $label, $options = [], $attributes = [])
- {
- return $this->addElement('select', $name, $label, $options, $attributes);
- }
- /**
- * @param $name
- * @param $label
- * @param $collection
- * @param array $attributes
- * @param bool $addNoneOption
- * @param string $textCallable set a function getStringValue() by default __toString()
- *
- * @return HTML_QuickForm_element
- */
- public function addSelectFromCollection(
- $name,
- $label,
- $collection,
- $attributes = [],
- $addNoneOption = false,
- $textCallable = ''
- ) {
- $options = [];
- if ($addNoneOption) {
- $options[0] = get_lang('None');
- }
- if (!empty($collection)) {
- foreach ($collection as $item) {
- $text = $item;
- if (!empty($textCallable)) {
- $text = $item->$textCallable();
- }
- $options[$item->getId()] = $text;
- }
- }
- return $this->addElement('select', $name, $label, $options, $attributes);
- }
- /**
- * @param string $label
- * @param string $text
- * @param bool $createElement
- *
- * @return HTML_QuickForm_Element
- */
- public function addLabel($label, $text, $createElement = false)
- {
- if ($createElement) {
- return $this->createElement(
- 'label',
- $label,
- $text
- );
- }
- return $this->addElement('label', $label, $text);
- }
- /**
- * @param string $text
- */
- public function addHeader($text)
- {
- if (!empty($text)) {
- $this->addElement('header', $text);
- }
- }
- /**
- * @param string $name
- * @param string $label
- * @param array $attributes
- *
- * @throws Exception if the file doesn't have an id
- *
- * @return HTML_QuickForm_file
- */
- public function addFile($name, $label, $attributes = [])
- {
- $element = $this->addElement('file', $name, $label, $attributes);
- if (isset($attributes['crop_image'])) {
- $id = $element->getAttribute('id');
- if (empty($id)) {
- throw new Exception('If you use the crop functionality the element must have an id');
- }
- $this->addHtml(
- '
- <div class="form-group" id="'.$id.'-form-group" style="display: none;">
- <div class="col-sm-offset-2 col-sm-8">
- <div id="'.$id.'_crop_image" class="cropCanvas thumbnail">
- <img id="'.$id.'_preview_image">
- </div>
- <button class="btn btn-primary" type="button" name="cropButton" id="'.$id.'_crop_button">
- <em class="fa fa-crop"></em> '.get_lang('CropYourPicture').'
- </button>
- </div>
- </div>'
- );
- $this->addHidden($id.'_crop_result', '');
- $this->addHidden($id.'_crop_image_base_64', '');
- }
- return $element;
- }
- /**
- * @param string $snippet
- */
- public function addHtml($snippet)
- {
- $this->addElement('html', $snippet);
- }
- /**
- * Draws a panel of options see the course_info/infocours.php page.
- *
- * @param string $name internal name
- * @param string $title visible title
- * @param array $groupList list of group or elements
- */
- public function addPanelOption($name, $title, $groupList)
- {
- $this->addHtml('<div class="panel panel-default">');
- $this->addHtml(
- '
- <div class="panel-heading" role="tab" id="heading-'.$name.'-settings">
- <h4 class="panel-title">
- <a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion"
- href="#collapse-'.$name.'-settings" aria-expanded="false" aria-controls="collapse-'.$name.'-settings">
- '
- );
- $this->addHtml($title);
- $this->addHtml('</a></h4></div>');
- $this->addHtml('<div id="collapse-'.$name.'-settings" class="panel-collapse collapse" role="tabpanel"
- aria-labelledby="heading-'.$name.'-settings">
- <div class="panel-body">
- ');
- foreach ($groupList as $groupName => $group) {
- // Add group array
- if (!empty($groupName) && is_array($group)) {
- $this->addGroup($group, '', $groupName);
- }
- // Add element
- if ($group instanceof HTML_QuickForm_element) {
- $this->addElement($group);
- }
- }
- $this->addHtml('</div></div>');
- $this->addHtml('</div>');
- }
- /**
- * Adds a HTML-editor to the form.
- *
- * @param string $name
- * @param string|array $label The label for the form-element
- * @param bool $required (optional) Is the form-element required (default=true)
- * @param bool $fullPage (optional) When it is true, the editor loads completed html code for a full page
- * @param array $config (optional) Configuration settings for the online editor
- */
- public function addHtmlEditor(
- $name,
- $label,
- $required = true,
- $fullPage = false,
- $config = []
- ) {
- $attributes = [];
- $attributes['rows'] = isset($config['rows']) ? $config['rows'] : 15;
- $attributes['cols'] = isset($config['cols']) ? $config['cols'] : 80;
- $attributes['cols-size'] = isset($config['cols-size']) ? $config['cols-size'] : [];
- $attributes['class'] = isset($config['class']) ? $config['class'] : [];
- $this->addElement('html_editor', $name, $label, $attributes, $config);
- $this->applyFilter($name, 'trim');
- if ($required) {
- $this->addRule($name, get_lang('ThisFieldIsRequired'), 'required');
- }
- /** @var HtmlEditor $element */
- $element = $this->getElement($name);
- $config['style'] = isset($config['style']) ? $config['style'] : false;
- if ($fullPage) {
- $config['fullPage'] = true;
- // Adds editor_content.css in ckEditor
- $config['style'] = true;
- }
- if ($element->editor) {
- $element->editor->processConfig($config);
- }
- }
- /**
- * Adds a Google Maps Geolocalization field to the form.
- *
- * @param $name
- * @param $label
- * @param bool $hideGeoLocalizationDetails
- */
- public function addGeoLocationMapField($name, $label, $dataValue, $hideGeoLocalizationDetails = false)
- {
- $gMapsPlugin = GoogleMapsPlugin::create();
- $geolocalization = $gMapsPlugin->get('enable_api') === 'true';
- if ($geolocalization && $gMapsPlugin->javascriptIncluded === false) {
- $gmapsApiKey = $gMapsPlugin->get('api_key');
- $url = '//maps.googleapis.com/maps/api/js?key='.$gmapsApiKey;
- $this->addHtml('<script type="text/javascript" src="'.$url.'" ></script>');
- $gMapsPlugin->javascriptIncluded = true;
- }
- $this->addElement(
- 'text',
- $name,
- $label,
- ['id' => $name]
- );
- $this->addHidden(
- $name.'_coordinates',
- '',
- ['id' => $name.'_coordinates']
- );
- $this->applyFilter($name, 'stripslashes');
- $this->applyFilter($name, 'trim');
- $this->addHtml(Extrafield::getLocalizationJavascript($name, $dataValue));
- if ($hideGeoLocalizationDetails) {
- $this->addHtml('<div style="display:none">');
- }
- $this->addHtml(
- Extrafield::getLocalizationInput($name, $label)
- );
- if ($hideGeoLocalizationDetails) {
- $this->addHtml('</div>');
- }
- }
- /**
- * @param string $name
- * @param string $label
- *
- * @return mixed
- */
- public function addButtonAdvancedSettings($name, $label = '')
- {
- $label = !empty($label) ? $label : get_lang('AdvancedParameters');
- return $this->addElement('advanced_settings', $name, $label);
- }
- /**
- * Adds a progress loading image to the form.
- */
- public function addProgress($delay = 2, $label = '')
- {
- if (empty($label)) {
- $label = get_lang('PleaseStandBy');
- }
- $this->with_progress_bar = true;
- $id = $this->getAttribute('id');
- $this->updateAttributes("onsubmit=\"javascript: addProgress('".$id."')\"");
- $this->addHtml('<script language="javascript" src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/upload.js" type="text/javascript"></script>');
- }
- /**
- * This function has been created for avoiding changes directly within QuickForm class.
- * When we use it, the element is threated as 'required' to be dealt during validation.
- *
- * @param array $elements The array of elements
- * @param string $message The message displayed
- */
- public function add_multiple_required_rule($elements, $message)
- {
- $this->_required[] = $elements[0];
- $this->addRule($elements, $message, 'multiple_required');
- }
- /**
- * Displays the form.
- * If an element in the form didn't validate, an error message is showed
- * asking the user to complete the form.
- */
- public function display()
- {
- echo $this->returnForm();
- }
- /**
- * Returns the HTML code of the form.
- *
- * @return string $return_value HTML code of the form
- */
- public function returnForm()
- {
- $returnValue = '';
- /** @var HTML_QuickForm_element $element */
- foreach ($this->_elements as $element) {
- $elementError = parent::getElementError($element->getName());
- if (!is_null($elementError)) {
- $returnValue .= Display::return_message($elementError, 'warning').'<br />';
- break;
- }
- }
- $returnValue .= parent::toHtml();
- // Add div-element which is to hold the progress bar
- $id = $this->getAttribute('id');
- if (isset($this->with_progress_bar) && $this->with_progress_bar) {
- // Deprecated
- // $icon = Display::return_icon('progress_bar.gif');
- // @todo improve UI
- $returnValue .= '<br />
- <div id="loading_div_'.$id.'" class="loading_div" style="display:none;margin-left:40%; margin-top:10px; height:50px;">
- <div class="wobblebar-loader"></div>
- </div>
- ';
- }
- return $returnValue;
- }
- /**
- * Returns the HTML code of the form.
- * If an element in the form didn't validate, an error message is showed
- * asking the user to complete the form.
- *
- * @return string $return_value HTML code of the form
- *
- * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, august 2006
- * @author Julio Montoya
- *
- * @deprecated use returnForm()
- */
- public function return_form()
- {
- return $this->returnForm();
- }
- /**
- * @return HTML_QuickForm_Renderer_Default
- */
- public static function getDefaultRenderer()
- {
- return
- isset($GLOBALS['_HTML_QuickForm_default_renderer']) ?
- $GLOBALS['_HTML_QuickForm_default_renderer'] : null;
- }
- /**
- * Adds a input of type url to the form.
- *
- * @param string $name The label for the form-element
- * @param string $label The element name
- * @param bool $required Optional. Is the form-element required (default=true)
- * @param array $attributes Optional. List of attributes for the form-element
- */
- public function addUrl($name, $label, $required = true, $attributes = [])
- {
- $this->addElement('url', $name, $label, $attributes);
- $this->applyFilter($name, 'trim');
- $this->addRule($name, get_lang('InsertAValidUrl'), 'url');
- if ($required) {
- $this->addRule($name, get_lang('ThisFieldIsRequired'), 'required');
- }
- }
- /**
- * Adds a text field for letters to the form.
- * A trim-filter is attached to the field.
- *
- * @param string $name The element name
- * @param string $label The label for the form-element
- * @param bool $required Optional. Is the form-element required (default=true)
- * @param array $attributes Optional. List of attributes for the form-element
- */
- public function addTextLettersOnly(
- $name,
- $label,
- $required = false,
- $attributes = []
- ) {
- $attributes = array_merge(
- $attributes,
- [
- 'pattern' => '[a-zA-ZñÑ]+',
- 'title' => get_lang('OnlyLetters'),
- ]
- );
- $this->addElement(
- 'text',
- $name,
- [
- $label,
- get_lang('OnlyLetters'),
- ],
- $attributes
- );
- $this->applyFilter($name, 'trim');
- if ($required) {
- $this->addRule($name, get_lang('ThisFieldIsRequired'), 'required');
- }
- $this->addRule(
- $name,
- get_lang('OnlyLetters'),
- 'regex',
- '/^[a-zA-ZñÑ]+$/'
- );
- }
- /**
- * Adds a text field for alphanumeric characters to the form.
- * A trim-filter is attached to the field.
- *
- * @param string $name The element name
- * @param string $label The label for the form-element
- * @param bool $required Optional. Is the form-element required (default=true)
- * @param array $attributes Optional. List of attributes for the form-element
- */
- public function addTextAlphanumeric(
- $name,
- $label,
- $required = false,
- $attributes = []
- ) {
- $attributes = array_merge(
- $attributes,
- [
- 'pattern' => '[a-zA-Z0-9ñÑ]+',
- 'title' => get_lang('OnlyLettersAndNumbers'),
- ]
- );
- $this->addElement(
- 'text',
- $name,
- [
- $label,
- get_lang('OnlyLettersAndNumbers'),
- ],
- $attributes
- );
- $this->applyFilter($name, 'trim');
- if ($required) {
- $this->addRule($name, get_lang('ThisFieldIsRequired'), 'required');
- }
- $this->addRule(
- $name,
- get_lang('OnlyLettersAndNumbers'),
- 'regex',
- '/^[a-zA-Z0-9ÑÑ]+$/'
- );
- }
- /**
- * @param string $name
- * @param $label
- * @param bool $required
- * @param array $attributes
- * @param bool $allowNegative
- * @param int $minValue
- * @param null $maxValue
- */
- public function addFloat(
- $name,
- $label,
- $required = false,
- $attributes = [],
- $allowNegative = false,
- $minValue = null,
- $maxValue = null
- ) {
- $this->addElement(
- 'FloatNumber',
- $name,
- $label,
- $attributes
- );
- $this->applyFilter($name, 'trim');
- if ($required) {
- $this->addRule($name, get_lang('ThisFieldIsRequired'), 'required');
- }
- // Rule allows "," and "."
- /*$this->addRule(
- $name,
- get_lang('OnlyNumbers'),
- 'regex',
- '/(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)|(^-?\d\d*\,\d*$)|(^-?\,\d\d*$)/'
- );*/
- if ($allowNegative == false) {
- $this->addRule(
- $name,
- get_lang('NegativeValue'),
- 'compare',
- '>=',
- 'server',
- false,
- false,
- 0
- );
- }
- if (!is_null($minValue)) {
- $this->addRule(
- $name,
- get_lang('UnderMin'),
- 'compare',
- '>=',
- 'server',
- false,
- false,
- $minValue
- );
- }
- if (!is_null($maxValue)) {
- $this->addRule(
- $name,
- get_lang('OverMax'),
- 'compare',
- '<=',
- 'server',
- false,
- false,
- $maxValue
- );
- }
- }
- /**
- * Adds a text field for letters and spaces to the form.
- * A trim-filter is attached to the field.
- *
- * @param string $name The element name
- * @param string $label The label for the form-element
- * @param bool $required Optional. Is the form-element required (default=true)
- * @param array $attributes Optional. List of attributes for the form-element
- */
- public function addTextLettersAndSpaces(
- $name,
- $label,
- $required = false,
- $attributes = []
- ) {
- $attributes = array_merge(
- $attributes,
- [
- 'pattern' => '[a-zA-ZñÑ\s]+',
- 'title' => get_lang('OnlyLettersAndSpaces'),
- ]
- );
- $this->addElement(
- 'text',
- $name,
- [
- $label,
- get_lang('OnlyLettersAndSpaces'),
- ],
- $attributes
- );
- $this->applyFilter($name, 'trim');
- if ($required) {
- $this->addRule($name, get_lang('ThisFieldIsRequired'), 'required');
- }
- $this->addRule(
- $name,
- get_lang('OnlyLettersAndSpaces'),
- 'regex',
- '/^[a-zA-ZñÑ\s]+$/'
- );
- }
- /**
- * Adds a text field for alphanumeric and spaces characters to the form.
- * A trim-filter is attached to the field.
- *
- * @param string $name The element name
- * @param string $label The label for the form-element
- * @param bool $required Optional. Is the form-element required (default=true)
- * @param array $attributes Optional. List of attributes for the form-element
- */
- public function addTextAlphanumericAndSpaces(
- $name,
- $label,
- $required = false,
- $attributes = []
- ) {
- $attributes = array_merge(
- $attributes,
- [
- 'pattern' => '[a-zA-Z0-9ñÑ\s]+',
- 'title' => get_lang('OnlyLettersAndNumbersAndSpaces'),
- ]
- );
- $this->addElement(
- 'text',
- $name,
- [
- $label,
- get_lang('OnlyLettersAndNumbersAndSpaces'),
- ],
- $attributes
- );
- $this->applyFilter($name, 'trim');
- if ($required) {
- $this->addRule($name, get_lang('ThisFieldIsRequired'), 'required');
- }
- $this->addRule(
- $name,
- get_lang('OnlyLettersAndNumbersAndSpaces'),
- 'regex',
- '/^[a-zA-Z0-9ñÑ\s]+$/'
- );
- }
- /**
- * @param string $url
- * @param string $urlToRedirect after upload redirect to this page
- */
- public function addMultipleUpload($url, $urlToRedirect = '')
- {
- $inputName = 'input_file_upload';
- $this->addMultipleUploadJavascript($url, $inputName, $urlToRedirect);
- $this->addHtml('
- <div class="description-upload">
- '.get_lang('ClickToSelectOrDragAndDropMultipleFilesOnTheUploadField').'
- </div>
- <span class="btn btn-success fileinput-button">
- <i class="glyphicon glyphicon-plus"></i>
- <span>'.get_lang('AddFiles').'</span>
- <!-- The file input field used as target for the file upload widget -->
- <input id="'.$inputName.'" type="file" name="files[]" multiple>
- </span>
- <div id="dropzone">
- <div class="button-load">
- '.get_lang('UploadFiles').'
- </div>
- </div>
- <br />
- <!-- The global progress bar -->
- <div id="progress" class="progress">
- <div class="progress-bar progress-bar-success"></div>
- </div>
- <div id="files" class="files"></div>
- ');
- }
- /**
- * @param string $elementName
- * @param string $groupName if element is inside a group
- *
- * @throws Exception
- */
- public function addPasswordRule($elementName, $groupName = '')
- {
- // Constant defined in old config/profile.conf.php
- if (CHECK_PASS_EASY_TO_FIND === true) {
- $message = get_lang('PassTooEasy').': '.api_generate_password();
- if (!empty($groupName)) {
- $groupObj = $this->getElement($groupName);
- if ($groupObj instanceof HTML_QuickForm_group) {
- $elementName = $groupObj->getElementName($elementName);
- if ($elementName === false) {
- throw new Exception("The $groupName doesn't have the element $elementName");
- }
- $this->_rules[$elementName][] = [
- 'type' => 'callback',
- 'format' => 'api_check_password',
- 'message' => $message,
- 'validation' => '',
- 'reset' => false,
- 'group' => $groupName,
- ];
- }
- } else {
- $this->addRule(
- $elementName,
- $message,
- 'callback',
- 'api_check_password'
- );
- }
- }
- }
- /**
- * Add an element with user ID and avatar to the form.
- * It needs a Chamilo\UserBundle\Entity\User as value. The exported value is the Chamilo\UserBundle\Entity\User ID.
- *
- * @see \UserAvatar
- *
- * @param string $name
- * @param string $label
- * @param string $imageSize Optional. Small, medium or large image
- * @param string $subtitle Optional. The subtitle for the field
- *
- * @return \UserAvatar
- */
- public function addUserAvatar($name, $label, $imageSize = 'small', $subtitle = '')
- {
- return $this->addElement('UserAvatar', $name, $label, ['image_size' => $imageSize, 'sub_title' => $subtitle]);
- }
- /**
- * @param array $typeList
- */
- public function addEmailTemplate($typeList)
- {
- $mailManager = new MailTemplateManager();
- foreach ($typeList as $type) {
- $list = $mailManager->get_all(
- ['where' => ['type = ? AND url_id = ?' => [$type, api_get_current_access_url_id()]]]
- );
- $options = [get_lang('Select')];
- $name = $type;
- $defaultId = '';
- foreach ($list as $item) {
- $options[$item['id']] = $item['name'];
- $name = $item['name'];
- if (empty($defaultId)) {
- $defaultId = $item['default_template'] == 1 ? $item['id'] : '';
- }
- }
- $url = api_get_path(WEB_AJAX_PATH).'mail.ajax.php?a=select_option';
- $typeNoDots = 'email_template_option_'.str_replace('.tpl', '', $type);
- $this->addSelect(
- 'email_template_option['.$type.']',
- $name,
- $options,
- ['id' => $typeNoDots]
- );
- $templateNoDots = 'email_template_'.str_replace('.tpl', '', $type);
- $templateNoDotsBlock = 'email_template_block_'.str_replace('.tpl', '', $type);
- $this->addHtml('<div id="'.$templateNoDotsBlock.'" style="display:none">');
- $this->addTextarea(
- $templateNoDots,
- get_lang('Preview'),
- ['disabled' => 'disabled ', 'id' => $templateNoDots, 'rows' => '5']
- );
- $this->addHtml('</div>');
- $this->addHtml("<script>
- $(function() {
- var defaultValue = '$defaultId';
- $('#$typeNoDots').val(defaultValue);
- $('#$typeNoDots').selectpicker('render');
- if (defaultValue != '') {
- var selected = $('#$typeNoDots option:selected').val();
- $.ajax({
- url: '$url' + '&id=' + selected+ '&template_name=$type',
- success: function (data) {
- $('#$templateNoDots').html(data);
- $('#$templateNoDotsBlock').show();
- return;
- },
- });
- }
-
- $('#$typeNoDots').on('change', function(){
- var selected = $('#$typeNoDots option:selected').val();
- $.ajax({
- url: '$url' + '&id=' + selected,
- success: function (data) {
- $('#$templateNoDots').html(data);
- $('#$templateNoDotsBlock').show();
- return;
- },
- });
- });
- });
- </script>");
- }
- }
- /**
- * @param string $url page that will handle the upload
- * @param string $inputName
- * @param string $urlToRedirect
- */
- private function addMultipleUploadJavascript($url, $inputName, $urlToRedirect = '')
- {
- $redirectCondition = '';
- if (!empty($urlToRedirect)) {
- $redirectCondition = "window.location.replace('$urlToRedirect'); ";
- }
- $icon = Display::return_icon('file_txt.gif');
- $this->addHtml("
- <script>
- $(function () {
- 'use strict';
- $('#".$this->getAttribute('id')."').submit(function() {
- return false;
- });
- $('#dropzone').on('click', function() {
- $('#".$inputName."').click();
- });
- var url = '".$url."';
- var uploadButton = $('<button/>')
- .addClass('btn btn-primary')
- .prop('disabled', true)
- .text('".addslashes(get_lang('Loading'))."')
- .on('click', function () {
- var \$this = $(this),
- data = \$this.data();
- \$this
- .off('click')
- .text('".addslashes(get_lang('Cancel'))."')
- .on('click', function () {
- \$this.remove();
- data.abort();
- });
- data.submit().always(function () {
- \$this.remove();
- });
- });
-
- $('#".$inputName."').fileupload({
- url: url,
- dataType: 'json',
- // Enable image resizing, except for Android and Opera,
- // which actually support image resizing, but fail to
- // send Blob objects via XHR requests:
- disableImageResize: /Android(?!.*Chrome)|Opera/.test(window.navigator.userAgent),
- previewMaxWidth: 300,
- previewMaxHeight: 169,
- previewCrop: true,
- dropzone: $('#dropzone'),
- }).on('fileuploadadd', function (e, data) {
- data.context = $('<div class=\"row\" />').appendTo('#files');
- $.each(data.files, function (index, file) {
- var node = $('<div class=\"col-sm-5 file_name\">').text(file.name);
- node.appendTo(data.context);
- });
- }).on('fileuploadprocessalways', function (e, data) {
- var index = data.index,
- file = data.files[index],
- node = $(data.context.children()[index]);
- if (file.preview) {
- data.context.prepend($('<div class=\"col-sm-4\">').html(file.preview));
- } else {
- data.context.prepend($('<div class=\"col-sm-4\">').html('".$icon."'));
- }
- if (index + 1 === data.files.length) {
- data.context.find('button')
- .text('Upload')
- .prop('disabled', !!data.files.error);
- }
- }).on('fileuploadprogressall', function (e, data) {
- var progress = parseInt(data.loaded / data.total * 100, 10);
- $('#progress .progress-bar').css(
- 'width',
- progress + '%'
- );
- }).on('fileuploaddone', function (e, data) {
- $.each(data.result.files, function (index, file) {
- if (file.error) {
- var link = $('<div>')
- .attr({class : 'panel-image'}) ;
- $(data.context.children()[index]).parent().wrap(link);
- // Update file name with new one from Chamilo
- $(data.context.children()[index]).parent().find('.file_name').html(file.name);
- var message = $('<div class=\"col-sm-3\">').html(
- $('<span class=\"message-image-danger\"/>').text(file.error)
- );
- $(data.context.children()[index]).parent().append(message);
- return;
- }
- if (file.url) {
- var link = $('<a>')
- .attr({target: '_blank', class : 'panel-image'})
- .prop('href', file.url);
- $(data.context.children()[index]).parent().wrap(link);
- }
- // Update file name with new one from Chamilo
- $(data.context.children()[index]).parent().find('.file_name').html(file.name);
- var message = $('<div class=\"col-sm-3\">').html(
- $('<span class=\"message-image-success\"/>').text('".addslashes(get_lang('UplUploadSucceeded'))."')
- );
- $(data.context.children()[index]).parent().append(message);
- });
- $('#dropzone').removeClass('hover');
- ".$redirectCondition."
- }).on('fileuploadfail', function (e, data) {
- $.each(data.files, function (index) {
- var failedMessage = '".addslashes(get_lang('UplUploadFailed'))."';
- var error = $('<div class=\"col-sm-3\">').html(
- $('<span class=\"alert alert-danger\"/>').text(failedMessage)
- );
- $(data.context.children()[index]).parent().append(error);
- });
- $('#dropzone').removeClass('hover');
- }).prop('disabled', !$.support.fileInput).parent().addClass($.support.fileInput ? undefined : 'disabled');
-
- $('#dropzone').on('dragover', function (e) {
- // dragleave callback implementation
- $('#dropzone').addClass('hover');
- });
-
- $('#dropzone').on('dragleave', function (e) {
- $('#dropzone').removeClass('hover');
- });
- $('.fileinput-button').hide();
- });
- </script>");
- }
- }
- /**
- * Cleans HTML text filter.
- *
- * @param string $html HTML to clean
- * @param int $mode (optional)
- *
- * @return string The cleaned HTML
- */
- function html_filter($html, $mode = NO_HTML)
- {
- $allowed_tags = HTML_QuickForm_Rule_HTML::get_allowed_tags($mode);
- $cleaned_html = kses($html, $allowed_tags);
- return $cleaned_html;
- }
- function html_filter_teacher($html)
- {
- return html_filter($html, TEACHER_HTML);
- }
- function html_filter_student($html)
- {
- return html_filter($html, STUDENT_HTML);
- }
- function html_filter_teacher_fullpage($html)
- {
- return html_filter($html, TEACHER_HTML_FULLPAGE);
- }
- function html_filter_student_fullpage($html)
- {
- return html_filter($html, STUDENT_HTML_FULLPAGE);
- }
- /**
- * Cleans mobile phone number text.
- *
- * @param string $mobilePhoneNumber Mobile phone number to clean
- *
- * @return string The cleaned mobile phone number
- */
- function mobile_phone_number_filter($mobilePhoneNumber)
- {
- $mobilePhoneNumber = str_replace(['+', '(', ')'], '', $mobilePhoneNumber);
- return ltrim($mobilePhoneNumber, '0');
- }
|