';
$renderer->setElementTemplate($button_element_template_simple, 'submit_in_actions');
//Display a gray div in the buttons + makes the button available when scrolling
$button_element_template_in_bottom = '
';
}
/**
* Adds a text field to the form.
* A trim-filter is attached to the field.
* @param string $label The label for the form-element
* @param string $name The element name
* @param boolean $required (optional) Is the form-element required (default=true)
* @param array $attributes (optional) List of attributes for the form-element
*/
public function add_textfield($name, $label, $required = true, $attributes = array())
{
$this->addElement('text', $name, $label, $attributes);
$this->applyFilter($name, 'trim');
if ($required) {
$this->addRule($name, get_lang('ThisFieldIsRequired'), 'required');
}
}
/**
* date_range_picker element creates 2 hidden fields
* elementName + "_start" elementName "_end"
* @param string $name
* @param string $label
* @param bool $required
* @param array $attributes
*/
public function addDateRangePicker($name, $label, $required = true, $attributes = array())
{
$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 $value
*/
function add_hidden($name, $value)
{
$this->addElement('hidden', $name, $value);
}
public function add_textarea($name, $label, $attributes = array())
{
$this->addElement('textarea', $name, $label, $attributes);
}
public function add_button($name, $label, $attributes = array())
{
$this->addElement('button', $name, $label, $attributes);
}
public function add_checkbox($name, $label, $trailer = '', $attributes = array())
{
$this->addElement('checkbox', $name, $label, $trailer, $attributes);
}
public function add_radio($name, $label, $options = '')
{
$group = array();
foreach ($options as $key => $value) {
$group[] = $this->createElement('radio', null, null, $value, $key);
}
$this->addGroup($group, $name, $label);
}
public function add_select($name, $label, $options = '', $attributes = array())
{
$this->addElement('select', $name, $label, $options, $attributes);
}
public function add_label($label, $text)
{
$this->addElement('label', $label, $text);
}
public function add_header($text)
{
$this->addElement('header', $text);
}
public function add_file($name, $label, $attributes = array())
{
$this->addElement('file', $name, $label, $attributes);
}
public function add_html($snippet)
{
$this->addElement('html', $snippet);
}
/**
* Adds a HTML-editor to the form to fill in a title.
* A trim-filter is attached to the field.
* A HTML-filter is attached to the field (cleans HTML)
* A rule is attached to check for unwanted HTML
* @param string $name
* @param string $label The label for the form-element
* @param boolean $required (optional) Is the form-element required (default=true)
* @param boolean $full_page (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 add_html_editor($name, $label, $required = true, $full_page = false, $config = null)
{
$this->addElement('html_editor', $name, $label, 'rows="15" cols="80"', $config);
$this->applyFilter($name, 'trim');
if ($required) {
$this->addRule($name, get_lang('ThisFieldIsRequired'), 'required');
}
/** @var HTML_QuickForm_html_editor $element */
$element = $this->getElement($name);
if ($element->editor) {
$element->editor->processConfig($config);
}
}
/**
* Adds a date picker element to the form
* A rule is added to check if the date is a valid one
* @param string $label The label for the form-element
* @param string $name The element name
*/
public function add_datepicker($name, $label)
{
$this->addElement('datepicker', $name, $label, array('form_name' => $this->getAttribute('name')));
$this->_elements[$this->_elementIndex[$name]]->setLocalOption('minYear', 1900); // TODO: Now - 9 years
$this->addRule($name, get_lang('InvalidDate'), 'date');
}
/**
* Adds a date picker date element to the form
* A rule is added to check if the date is a valid one
* @param string $label The label for the form-element
* @param string $name The element name
* @deprecated
*/
public function add_datepickerdate($name, $label)
{
$this->addElement('datepickerdate', $name, $label, array('form_name' => $this->getAttribute('name')));
$this->_elements[$this->_elementIndex[$name]]->setLocalOption('minYear', 1900); // TODO: Now - 9 years
$this->addRule($name, get_lang('InvalidDate'), 'date');
}
/**
* Adds a timewindow element to the form.
* 2 datepicker elements are added and a rule to check if the first date is
* before the second one.
* @param string $label The label for the form-element
* @param string $name The element name
* @deprecated
*/
public function add_timewindow($name_1, $name_2, $label_1, $label_2)
{
$this->add_datepicker($name_1, $label_1);
$this->add_datepicker($name_2, $label_2);
$this->addRule(array($name_1, $name_2), get_lang('StartDateShouldBeBeforeEndDate'), 'date_compare', 'lte');
}
/**
* Adds a progress bar to the form.
*
* Once the user submits the form, a progress bar (animated gif) is
* displayed. The progress bar will disappear once the page has been
* reloaded.
*
* @param int $delay (optional) The number of seconds between the moment the user
* @param string $label (optional) Custom label to be shown
* submits the form and the start of the progress bar.
*/
public function add_progress_bar($delay = 2, $label = '')
{
if (empty($label)) {
$label = get_lang('PleaseStandBy');
}
$this->with_progress_bar = true;
$this->updateAttributes("onsubmit=\"javascript: myUpload.start('dynamic_div','" . api_get_path(WEB_IMG_PATH) . "progress_bar.gif','" . $label . "','" . $this->getAttribute('id') . "')\"");
$this->addElement('html', '');
}
/**
* Uses new functions (php 5.2) for displaying real upload progress.
* @param string $upload_id The value of the field UPLOAD_IDENTIFIER, the second parameter (XXX) of the $form->addElement('file', XXX) sentence
* @param string $element_after The first element of the form (to place at first UPLOAD_IDENTIFIER)
* @param int $delay (optional) The frequency of the xajax call
* @param bool $wait_after_upload (optional)
*/
public function add_real_progress_bar($upload_id, $element_after, $delay = 2, $wait_after_upload = false)
{
if (!function_exists('uploadprogress_get_info')) {
$this->add_progress_bar($delay);
return;
}
if (!class_exists('xajax')) {
require_once api_get_path(LIBRARY_PATH) . 'xajax/xajax.inc.php';
}
$xajax_upload = new xajax(api_get_path(WEB_LIBRARY_PATH).'upload.xajax.php');
$xajax_upload->registerFunction('updateProgress');
// IMPORTANT : must be the first element of the form
$el = $this->insertElementBefore(FormValidator::createElement('html', ''), $element_after);
$this->addElement('html', ' ');
// Add div-element where the progress bar is to be displayed
$this->addElement('html', '
' . get_lang('UploadFile') . '
');
if ($wait_after_upload) {
$this->addElement('html', '
' . get_lang('SlideshowConversion') . '
');
}
// Get the xajax code
$this->addElement('html', $xajax_upload->getJavascript(api_get_path(WEB_LIBRARY_PATH).'xajax'));
// Get the upload code
$this->addElement('html', '');
if (!$wait_after_upload) {
$wait_after_upload = 0;
}
// Add the upload event
$this->updateAttributes("onsubmit=\"javascript: myUpload.startRealUpload('dynamic_div','" . $upload_id . "','" . $this->getAttribute('id') . "'," . $wait_after_upload . ")\"");
}
/**
* 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->return_form();
}
/**
* 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 , Ghent University, august 2006
*/
public function return_form()
{
$error = false;
$addDateLibraries = false;
$dateElementTypes = array('date_range_picker', 'date_time_picker', 'date_picker', 'datepicker', 'datetimepicker');
/** @var HTML_QuickForm_element $element */
foreach ($this->_elements as $element) {
if (in_array($element->getType(), $dateElementTypes)) {
$addDateLibraries = true;
}
if (!is_null(parent::getElementError($element->getName()))) {
$error = true;
break;
}
}
$return_value = '';
$js = null;
if ($addDateLibraries) {
/*
$js = api_get_js('jquery-ui/jquery-ui-i18n.min.js');
$js .= '';
$js .= '';
$js .= '';
$js .= '';
$js .= '';
$isocode = api_get_language_isocode();
if ($isocode != 'en') {
$js .= '';
$js .= '';
}*/
}
if ($error) {
$return_value = Display::return_message(get_lang('FormHasErrorsPleaseComplete'), 'warning');
}
$return_value .= $js;
$return_value .= parent::toHtml();
// Add div-element which is to hold the progress bar
if (isset($this->with_progress_bar) && $this->with_progress_bar) {
$return_value .= '';
}
return $return_value;
}
/**
* @param string $name
* @param string $label
* @param array $values
* @param array $attributes
*/
public function addDoubleMultipleSelect($name, $label, $values, $attributes = array())
{
$group = $this->addElement('advmultiselect', $name, $label, $values, $attributes);
$group->setElementTemplate('
{javascript}