Format code, rename add_file to addFile function

1.10.x
Julio Montoya 11 years ago
parent 0664d66b9f
commit 085bafcf49
  1. 2
      main/course_description/upload_file_form.class.php
  2. 2
      main/glossary/upload_file_form.class.php
  3. 4
      main/inc/lib/blog.lib.php
  4. 299
      main/inc/lib/formvalidator/FormValidator.class.php
  5. 2
      main/link/upload_file_form.class.php
  6. 2
      main/notebook/upload_file_form.class.php
  7. 2
      main/social/message_for_group_form.inc.php

@ -36,7 +36,7 @@ class UploadFileForm extends \FormValidator
$this->addHeader($form_name);
$label = get_lang('File');
$this->add_file('file', $label);
$this->addFile('file', $label);
$this->addRule('file', get_lang('ThisFieldIsRequired'), 'required');
//$this->add_checkbox('replace', '', get_lang('ReplaceExistingEntries'));

@ -46,7 +46,7 @@ class UploadFileForm extends \FormValidator
$this->addHidden(Request::PARAM_SEC_TOKEN, Access::instance()->get_token());
$label = get_lang('ImportCSVFileLocation');
$this->add_file('file', $label);
$this->addFile('file', $label);
$this->addRule('file', get_lang('ThisFieldIsRequired'), 'required');
$this->addCheckBox('deleteall', '', get_lang('DeleteAllGlossaryTerms'));
$this->addButton('save', get_lang('Save'));

@ -1124,7 +1124,7 @@ class Blog
$config['ToolbarSet'] = 'Project';
}
$form->addHtmlEditor('full_text', get_lang('Content'), false, false, $config);
$form->add_file('user_upload', get_lang('AddAnAttachment'));
$form->addFile('user_upload', get_lang('AddAnAttachment'));
$form->addTextarea('post_file_comment', get_lang('FileComment'));
$form->addHidden('new_post_submit', 'true');
$form->addButton('save', get_lang('Save'));
@ -2226,7 +2226,7 @@ class Blog
$config['ToolbarSet'] = 'ProjectCommentStudent';
}
$form->addHtmlEditor('comment', get_lang('Comment'), false, false, $config);
$form->add_file('user_upload', get_lang('AddAnAttachment'));
$form->addFile('user_upload', get_lang('AddAnAttachment'));
$form->addTextarea('post_file_comment', get_lang('FileComment'));

@ -7,129 +7,35 @@
class FormValidator extends HTML_QuickForm
{
public $with_progress_bar = false;
/**
* Create a form validator based on an array of form data:
*
* array(
* 'name' => 'zombie_report_parameters', //optional
* 'method' => 'GET', //optional
* 'items' => array(
* array(
* 'name' => 'ceiling',
* 'label' => 'Ceiling', //optional
* 'type' => 'date',
* 'default' => date() //optional
* ),
* array(
* 'name' => 'active_only',
* 'label' => 'ActiveOnly',
* 'type' => 'checkbox',
* 'default' => true
* ),
* array(
* 'name' => 'submit_button',
* 'type' => 'style_submit_button',
* 'value' => get_lang('Search'),
* 'attributes' => array('class' => 'search')
* )
* )
* );
*
* @param array $form_data
*
* @return FormValidator
*/
public static function create($form_data)
{
if (empty($form_data)) {
return null;
}
$form_name = isset($form_data['name']) ? $form_data['name'] : 'form';
$form_method = isset($form_data['method']) ? $form_data['method'] : 'POST';
$form_action = isset($form_data['action']) ? $form_data['action'] : '';
$form_target = isset($form_data['target']) ? $form_data['target'] : '';
$form_attributes = isset($form_data['attributes']) ? $form_data['attributes'] : null;
$form_track_submit = isset($form_data['track_submit']) ? $form_data['track_submit'] : true;
$reset = null;
$result = new FormValidator($form_name, $form_method, $form_action, $form_target, $form_attributes, $form_track_submit);
$defaults = array();
foreach ($form_data['items'] as $item) {
$name = $item['name'];
$type = isset($item['type']) ? $item['type'] : 'text';
$label = isset($item['label']) ? $item['label'] : '';
if ($type == 'wysiwyg') {
$element = $result->addHtmlEditor($name, $label);
} else {
$element = $result->addElement($type, $name, $label);
}
if (isset($item['attributes'])) {
$attributes = $item['attributes'];
$element->setAttributes($attributes);
}
if (isset($item['value'])) {
$value = $item['value'];
$element->setValue($value);
}
if (isset($item['default'])) {
$defaults[$name] = $item['default'];
}
if (isset($item['rules'])) {
$rules = $item['rules'];
foreach ($rules as $rule) {
$message = $rule['message'];
$type = $rule['type'];
$format = isset($rule['format']) ? $rule['format'] : null;
$validation = isset($rule['validation']) ? $rule['validation'] : 'server';
$force = isset($rule['force']) ? $rule['force'] : false;
$result->addRule($name, $message, $type, $format, $validation, $reset, $force);
}
}
}
$result->setDefaults($defaults);
return $result;
}
/**
* Constructor
* @param string $form_name Name of the form
* @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 bool $track_submit (optional) Whether to track if the form was
* @param bool $trackSubmit (optional) Whether to track if the form was
* submitted by adding a special hidden field (default = true)
*/
public function __construct($form_name, $method = 'post', $action = '', $target = '', $attributes = null, $track_submit = true)
{
public function __construct(
$name,
$method = 'post',
$action = '',
$target = '',
$attributes = null,
$trackSubmit = true
) {
// Default form class.
if (is_array($attributes) && !isset($attributes['class']) || empty($attributes)) {
$attributes['class'] = 'form-horizontal';
}
parent::__construct($form_name, $method, $action, $target, $attributes, $track_submit);
parent::__construct($name, $method, $action, $target, $attributes, $trackSubmit);
// Load some custom elements and rules
$dir = api_get_path(LIBRARY_PATH) . 'formvalidator/';
$this->registerElementType('html_editor', $dir . 'Element/html_editor.php', 'HTML_QuickForm_html_editor');
$this->registerElementType('date_range_picker', $dir . 'Element/DateRangePicker.php', 'DateRangePicker');
$this->registerElementType('date_time_picker', $dir . 'Element/DateTimePicker.php', 'DateTimePicker');
$this->registerElementType('date_picker', $dir . 'Element/DatePicker.php', 'DatePicker');
$this->registerElementType('datepicker', $dir . 'Element/datepicker_old.php', 'HTML_QuickForm_datepicker');
$this->registerElementType('datepickerdate', $dir . 'Element/datepickerdate.php', 'HTML_QuickForm_datepickerdate');
$this->registerElementType('receivers', $dir . 'Element/receivers.php', 'HTML_QuickForm_receivers');
$this->registerElementType('select_language', $dir . 'Element/select_language.php', 'HTML_QuickForm_Select_Language');
$this->registerElementType('select_ajax', $dir . 'Element/select_ajax.php', 'HTML_QuickForm_Select_Ajax');
$this->registerElementType('select_theme', $dir . 'Element/select_theme.php', 'HTML_QuickForm_Select_Theme');
$this->registerElementType('style_submit_button', $dir . 'Element/style_submit_button.php', 'HTML_QuickForm_stylesubmitbutton');
$this->registerElementType('style_reset_button', $dir . 'Element/style_reset_button.php', 'HTML_QuickForm_styleresetbutton');
$this->registerElementType('button', $dir . 'Element/style_submit_button.php', 'HTML_QuickForm_stylesubmitbutton');
$this->registerElementType('captcha', 'HTML/QuickForm/CAPTCHA.php', 'HTML_QuickForm_CAPTCHA');
$this->registerElementType('CAPTCHA_Image', 'HTML/QuickForm/CAPTCHA/Image.php', 'HTML_QuickForm_CAPTCHA_Image');
$this->registerElementType('number', $dir . 'Element/Number.php', 'Number');
$this->registerRule('date', null, 'HTML_QuickForm_Rule_Date', $dir . 'Rule/Date.php');
$this->registerRule('datetime', null, 'DateTimeRule', $dir . 'Rule/DateTimeRule.php');
$this->registerRule('date_compare', null, 'HTML_QuickForm_Rule_DateCompare', $dir . 'Rule/DateCompare.php');
@ -152,21 +58,21 @@ class FormValidator extends HTML_QuickForm
// Element template
if (isset($attributes['class']) && $attributes['class'] == 'well form-inline') {
$element_template = ' {label} {element} ';
$renderer->setElementTemplate($element_template);
$elementTemplate = ' {label} {element} ';
$renderer->setElementTemplate($elementTemplate);
} elseif (isset($attributes['class']) && $attributes['class'] == 'form-search') {
$element_template = ' {label} {element} ';
$renderer->setElementTemplate($element_template);
$elementTemplate = ' {label} {element} ';
$renderer->setElementTemplate($elementTemplate);
} else {
$renderer->setElementTemplate($this->getElementTemplate());
//Display a gray div in the buttons
$button_element_template_simple = '<div class="form-actions">{label} {element}</div>';
$renderer->setElementTemplate($button_element_template_simple, 'submit_in_actions');
// 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
$button_element_template_in_bottom = '<div class="form-actions bottom_actions bg-form">{label} {element}</div>';
$renderer->setElementTemplate($button_element_template_in_bottom, 'submit_fixed_in_bottom');
$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();
@ -174,17 +80,10 @@ class FormValidator extends HTML_QuickForm
$group[] = $form->createElement('button', 'unmark_all', get_lang('UnmarkAll'));
$form->addGroup($group, 'buttons_in_action');
*/
$renderer->setElementTemplate($button_element_template_simple, 'buttons_in_action');
$renderer->setElementTemplate($templateSimple, 'buttons_in_action');
$button_element_template_simple_right = '<div class="form-actions"> <div class="pull-right">{label} {element}</div></div>';
$renderer->setElementTemplate($button_element_template_simple_right, 'buttons_in_action_right');
/*
$renderer->setElementTemplate($button_element_template, 'submit_button');
$renderer->setElementTemplate($button_element_template, 'submit');
$renderer->setElementTemplate($button_element_template, 'button');
*
*/
$templateSimpleRight = '<div class="form-actions"> <div class="pull-right">{label} {element}</div></div>';
$renderer->setElementTemplate($templateSimpleRight, 'buttons_in_action_right');
}
//Set Header template
@ -192,12 +91,12 @@ class FormValidator extends HTML_QuickForm
//Set required field template
HTML_QuickForm::setRequiredNote('<span class="form_required">*</span> <small>' . get_lang('ThisFieldIsRequired') . '</small>');
$required_note_template = <<<EOT
$noteTemplate = <<<EOT
<div class="control-group">
<div class="controls">{requiredNote}</div>
</div>
EOT;
$renderer->setRequiredNoteTemplate($required_note_template);
$renderer->setRequiredNoteTemplate($noteTemplate);
}
/**
@ -246,10 +145,10 @@ EOT;
/**
* 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
* @param string $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
*/
public function addText($name, $label, $required = true, $attributes = array())
{
@ -308,8 +207,7 @@ EOT;
* @param string $name
* @param string $label
* @param string $icon font-awesome
* @param string $class
* For example plus is transformed to icon fa fa-plus
* @param string $class Example plus is transformed to icon fa fa-plus
* @param array $attributes
*
* @return HTML_QuickForm_button
@ -424,16 +322,12 @@ EOT;
}
/**
* 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
* Adds a HTML-editor to the form
* @param string $name
* @param string $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 string $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 = array())
{
@ -458,11 +352,11 @@ EOT;
/**
* Adds a datepicker 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
* @param string $label The label for the form-element
* @param string $name The element name
* @deprecated
*/
function add_datepicker($name, $label)
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
@ -472,8 +366,8 @@ EOT;
/**
* 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
* @param string $label The label for the form-element
* @param string $name The element name
* @deprecated
*/
public function add_datepickerdate($name, $label)
@ -487,8 +381,8 @@ EOT;
* 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
* @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)
@ -506,8 +400,8 @@ EOT;
* 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
* @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 = '')
@ -639,28 +533,29 @@ EOT;
$js = null;
if ($addDateLibraries) {
$js .= '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/daterange/moment.min.js" type="text/javascript"></script>';
$js .= '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/datetimepicker/jquery-ui-timepicker-addon.js" type="text/javascript"></script>';
$js .= '<link href="'.api_get_path(WEB_LIBRARY_PATH).'javascript/datetimepicker/jquery-ui-timepicker-addon.css" rel="stylesheet" type="text/css" />';
$js .= '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/daterange/daterangepicker.js" type="text/javascript"></script>';
$js .= '<link href="'.api_get_path(WEB_LIBRARY_PATH).'javascript/daterange/daterangepicker-bs2.css" rel="stylesheet" type="text/css" />';
$js .= '<script src="' . api_get_path(WEB_LIBRARY_PATH) . 'javascript/daterange/moment.min.js" type="text/javascript"></script>';
$js .= '<script src="' . api_get_path(WEB_LIBRARY_PATH) . 'javascript/datetimepicker/jquery-ui-timepicker-addon.js" type="text/javascript"></script>';
$js .= '<link href="' . api_get_path(WEB_LIBRARY_PATH) . 'javascript/datetimepicker/jquery-ui-timepicker-addon.css" rel="stylesheet" type="text/css" />';
$js .= '<script src="' . api_get_path(WEB_LIBRARY_PATH) . 'javascript/daterange/daterangepicker.js" type="text/javascript"></script>';
$js .= '<link href="' . api_get_path(WEB_LIBRARY_PATH) . 'javascript/daterange/daterangepicker-bs2.css" rel="stylesheet" type="text/css" />';
$isoCode = api_get_language_isocode();
if ($isoCode != 'en') {
$js .= api_get_js('jquery-ui/jquery-ui-i18n.min.js');
$js .= '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/datetimepicker/i18n/jquery-ui-timepicker-'.$isoCode.'.js" type="text/javascript"></script>';
$js .= '<script src="' . api_get_path(WEB_LIBRARY_PATH) . 'javascript/datetimepicker/i18n/jquery-ui-timepicker-' . $isoCode . '.js" type="text/javascript"></script>';
$js .= '<script>
$(function(){
moment.lang("'.$isoCode.'");
$.datepicker.setDefaults($.datepicker.regional["'.$isoCode.'"]);
moment.lang("' . $isoCode . '");
$.datepicker.setDefaults($.datepicker.regional["' . $isoCode . '"]);
});
</script>';
}
}
if ($error) {
$return_value = Display::return_message(get_lang('FormHasErrorsPleaseComplete'), 'warning');
$return_value = Display::return_message(get_lang('FormHasErrorsPleaseComplete'),
'warning');
}
$return_value .= $js;
@ -669,12 +564,98 @@ EOT;
if (isset($this->with_progress_bar) && $this->with_progress_bar) {
$return_value .= '<div id="dynamic_div" style="display:block; margin-left:40%; margin-top:10px; height:50px;"></div>';
}
return $return_value;
}
/**
* Create a form validator based on an array of form data:
*
* array(
* 'name' => 'zombie_report_parameters', //optional
* 'method' => 'GET', //optional
* 'items' => array(
* array(
* 'name' => 'ceiling',
* 'label' => 'Ceiling', //optional
* 'type' => 'date',
* 'default' => date() //optional
* ),
* array(
* 'name' => 'active_only',
* 'label' => 'ActiveOnly',
* 'type' => 'checkbox',
* 'default' => true
* ),
* array(
* 'name' => 'submit_button',
* 'type' => 'style_submit_button',
* 'value' => get_lang('Search'),
* 'attributes' => array('class' => 'search')
* )
* )
* );
*
* @param array $form_data
* @deprecated use normal FormValidator construct
*
* @return FormValidator
*/
public static function create($form_data)
{
if (empty($form_data)) {
return null;
}
$form_name = isset($form_data['name']) ? $form_data['name'] : 'form';
$form_method = isset($form_data['method']) ? $form_data['method'] : 'POST';
$form_action = isset($form_data['action']) ? $form_data['action'] : '';
$form_target = isset($form_data['target']) ? $form_data['target'] : '';
$form_attributes = isset($form_data['attributes']) ? $form_data['attributes'] : null;
$form_track_submit = isset($form_data['track_submit']) ? $form_data['track_submit'] : true;
$reset = null;
$result = new FormValidator($form_name, $form_method, $form_action, $form_target, $form_attributes, $form_track_submit);
$defaults = array();
foreach ($form_data['items'] as $item) {
$name = $item['name'];
$type = isset($item['type']) ? $item['type'] : 'text';
$label = isset($item['label']) ? $item['label'] : '';
if ($type == 'wysiwyg') {
$element = $result->addHtmlEditor($name, $label);
} else {
$element = $result->addElement($type, $name, $label);
}
if (isset($item['attributes'])) {
$attributes = $item['attributes'];
$element->setAttributes($attributes);
}
if (isset($item['value'])) {
$value = $item['value'];
$element->setValue($value);
}
if (isset($item['default'])) {
$defaults[$name] = $item['default'];
}
if (isset($item['rules'])) {
$rules = $item['rules'];
foreach ($rules as $rule) {
$message = $rule['message'];
$type = $rule['type'];
$format = isset($rule['format']) ? $rule['format'] : null;
$validation = isset($rule['validation']) ? $rule['validation'] : 'server';
$force = isset($rule['force']) ? $rule['force'] : false;
$result->addRule($name, $message, $type, $format, $validation, $reset, $force);
}
}
}
$result->setDefaults($defaults);
return $result;
}
}
/**
* Cleans HTML text
* Cleans HTML text filter
* @param string $html HTML to clean
* @param int $mode (optional)
* @return string The cleaned HTML

@ -36,7 +36,7 @@ class UploadFileForm extends \FormValidator
$this->addHeader($form_name);
$label = get_lang('File');
$this->add_file('file', $label);
$this->addFile('file', $label);
$this->addRule('file', get_lang('ThisFieldIsRequired'), 'required');
//$this->addCheckBox('replace', '', get_lang('ReplaceExistingEntries'));

@ -39,7 +39,7 @@ class UploadFileForm extends \FormValidator
$this->add_hidden(Request::PARAM_SEC_TOKEN, Access::instance()->get_token());
$label = get_lang('File');
$this->add_file('file', $label);
$this->addFile('file', $label);
$this->addRule('file', get_lang('ThisFieldIsRequired'), 'required');
$this->addButton('save', get_lang('Save'));

@ -106,7 +106,7 @@ if (api_get_setting('allow_message_tool') == 'true') {
$config
);
$form->addHtml('<span id="filepaths"><div id="filepath_1">');
$form->add_file('attach_1', get_lang('AttachmentFiles'));
$form->addFile('attach_1', get_lang('AttachmentFiles'));
$form->addHtml('</div></span>');
$form->addLabel(null,

Loading…
Cancel
Save