Add new form input types - refs BT#9089

1.10.x
Angel Fernando Quiroz Campos 10 years ago
parent 129430ece4
commit bff0d4ea90
  1. 4
      main/admin/session_add.php
  2. 4
      main/admin/session_edit.php
  3. 43
      main/inc/lib/extra_field.lib.php
  4. 30
      main/inc/lib/formvalidator/Element/Number.class.php
  5. 1
      main/inc/lib/formvalidator/FormValidator.class.php
  6. 16
      tests/scripts/insert_session_fields.php

@ -294,12 +294,12 @@ $form->addElement('advanced_settings','<a class="btn-show" id="advanced_paramete
$form->addElement('html','<div id="options" style="display:none">'); $form->addElement('html','<div id="options" style="display:none">');
$form->addElement('text', 'nb_days_acess_before', get_lang('DaysBefore'), array( $form->addElement('text', 'nb_days_acess_before', array('', '', get_lang('DaysBefore')), array(
'style' => 'width: 30px;', 'style' => 'width: 30px;',
'value' => $nb_days_acess_before 'value' => $nb_days_acess_before
)); ));
$form->addElement('text', 'nb_days_acess_after', get_lang('DaysAfter'), array( $form->addElement('text', 'nb_days_acess_after', array('', '', get_lang('DaysAfter')), array(
'style' => 'width: 30px;', 'style' => 'width: 30px;',
'value' => $nb_days_acess_after 'value' => $nb_days_acess_after
)); ));

@ -155,11 +155,11 @@ if ($infos['nb_days_access_before_beginning'] != 0 || $infos['nb_days_access_aft
$form->addElement('html','<div id="options" style="display:none;">'); $form->addElement('html','<div id="options" style="display:none;">');
} }
$form->addElement('text', 'nb_days_access_before', get_lang('DaysBefore'), array( $form->addElement('text', 'nb_days_access_before', arra('', '', get_lang('DaysBefore')), array(
'style' => 'width: 30px;' 'style' => 'width: 30px;'
)); ));
$form->addElement('text', 'nb_days_access_after', get_lang('DaysAfter'), array( $form->addElement('text', 'nb_days_access_after', array('', '', get_lang('DaysAfter')), array(
'style' => 'width: 30px;' 'style' => 'width: 30px;'
)); ));

@ -52,6 +52,8 @@ class ExtraField extends Model
const FIELD_TYPE_SOCIAL_PROFILE = 12; const FIELD_TYPE_SOCIAL_PROFILE = 12;
const FIELD_TYPE_CHECKBOX = 13; const FIELD_TYPE_CHECKBOX = 13;
const FIELD_TYPE_MOBILE_PHONE_NUMBER = 14; const FIELD_TYPE_MOBILE_PHONE_NUMBER = 14;
const FIELD_TYPE_INTEGER = 15;
const FIELD_TYPE_FILE = 16;
public $type = 'user'; //or session or course public $type = 'user'; //or session or course
public $handler_id = 'user_id'; public $handler_id = 'user_id';
@ -228,6 +230,9 @@ class ExtraField extends Model
$types[self::FIELD_TYPE_TIMEZONE] = get_lang('FieldTypeTimezone'); $types[self::FIELD_TYPE_TIMEZONE] = get_lang('FieldTypeTimezone');
$types[self::FIELD_TYPE_SOCIAL_PROFILE] = get_lang('FieldTypeSocialProfile'); $types[self::FIELD_TYPE_SOCIAL_PROFILE] = get_lang('FieldTypeSocialProfile');
$types[self::FIELD_TYPE_MOBILE_PHONE_NUMBER] = get_lang('FieldTypeMobilePhoneNumber'); $types[self::FIELD_TYPE_MOBILE_PHONE_NUMBER] = get_lang('FieldTypeMobilePhoneNumber');
$types[self::FIELD_TYPE_CHECKBOX] = get_lang('FieldTypeCheckbox');
$types[self::FIELD_TYPE_INTEGER] = get_lang('FieldTypeInteger');
$types[self::FIELD_TYPE_FILE] = get_lang('FieldTypeFile');
switch ($handler) { switch ($handler) {
case 'course': case 'course':
@ -988,6 +993,44 @@ EOF;
$form->freeze('extra_'.$field_details['field_variable']); $form->freeze('extra_'.$field_details['field_variable']);
} }
break; break;
case ExtraField::FIELD_TYPE_INTEGER:
$form->addElement(
'number',
'extra_'.$field_details['field_variable'],
$field_details['field_display_text'],
array('class' => 'span1')
);
$form->applyFilter('extra_'.$field_details['field_variable'], 'stripslashes');
$form->applyFilter('extra_'.$field_details['field_variable'], 'trim');
if (!$admin_permissions) {
if ($field_details['field_visible'] == 0) {
$form->freeze(
'extra_'.$field_details['field_variable']
);
}
}
break;
case ExtraField::FIELD_TYPE_FILE:
$form->addElement(
'file',
'extra_'.$field_details['field_variable'],
$field_details['field_display_text'],
array('class' => 'span8')
);
$form->applyFilter('extra_'.$field_details['field_variable'], 'stripslashes');
$form->applyFilter('extra_'.$field_details['field_variable'], 'trim');
if (!$admin_permissions) {
if ($field_details['field_visible'] == 0) {
$form->freeze(
'extra_'.$field_details['field_variable']
);
}
}
break;
} }
} }
} }

@ -0,0 +1,30 @@
<?php
/* For licensing terms, see /license.txt */
require_once 'HTML/QuickForm/text.php';
/**
* Form element to select a date and hour (with popup datepicker)
*
* Class DatePicker
*/
class Number extends HTML_QuickForm_text
{
/**
* @param string $elementName
* @param string $elementLabel
* @param array $attributes
*/
public function Number($elementName = null, $elementLabel = null, $attributes = null)
{
if (!isset($attributes['id'])) {
$attributes['id'] = $elementName;
}
$attributes['type'] = 'number';
HTML_QuickForm_element::HTML_QuickForm_element($elementName, $elementLabel, $attributes);
$this->_appendName = true;
$this->_type = 'number';
}
}

@ -140,6 +140,7 @@ class FormValidator extends HTML_QuickForm
$this->registerElementType('button', $dir . 'Element/style_submit_button.php', 'HTML_QuickForm_stylesubmitbutton'); $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', 'HTML/QuickForm/CAPTCHA.php', 'HTML_QuickForm_CAPTCHA');
$this->registerElementType('CAPTCHA_Image', 'HTML/QuickForm/CAPTCHA/Image.php', 'HTML_QuickForm_CAPTCHA_Image'); $this->registerElementType('CAPTCHA_Image', 'HTML/QuickForm/CAPTCHA/Image.php', 'HTML_QuickForm_CAPTCHA_Image');
$this->registerElementType('number', $dir . 'Element/Number.class.php', 'Number');
$this->registerRule('date', null, 'HTML_QuickForm_Rule_Date', $dir . 'Rule/Date.php'); $this->registerRule('date', null, 'HTML_QuickForm_Rule_Date', $dir . 'Rule/Date.php');
$this->registerRule('datetime', null, 'DateTimeRule', $dir . 'Rule/DateTimeRule.php'); $this->registerRule('datetime', null, 'DateTimeRule', $dir . 'Rule/DateTimeRule.php');

@ -11,7 +11,7 @@ api_protect_admin_script();
$horasLectivas = new ExtraField('session'); $horasLectivas = new ExtraField('session');
$horasLectivas->save(array( $horasLectivas->save(array(
'field_type' => ExtraField::FIELD_TYPE_TEXT, 'field_type' => ExtraField::FIELD_TYPE_INTEGER,
'field_variable' => 'horas_lectivas', 'field_variable' => 'horas_lectivas',
'field_display_text' => 'Horas lectivas', 'field_display_text' => 'Horas lectivas',
'field_visible' => 1, 'field_visible' => 1,
@ -20,7 +20,7 @@ $horasLectivas->save(array(
$costo = new ExtraField('session'); $costo = new ExtraField('session');
$costo->save(array( $costo->save(array(
'field_type' => ExtraField::FIELD_TYPE_TEXT, 'field_type' => ExtraField::FIELD_TYPE_INTEGER,
'field_variable' => 'costo', 'field_variable' => 'costo',
'field_display_text' => 'Costo', 'field_display_text' => 'Costo',
'field_visible' => 1, 'field_visible' => 1,
@ -29,7 +29,7 @@ $costo->save(array(
$vacantes = new ExtraField('session'); $vacantes = new ExtraField('session');
$vacantes->save(array( $vacantes->save(array(
'field_type' => ExtraField::FIELD_TYPE_TEXT, 'field_type' => ExtraField::FIELD_TYPE_INTEGER,
'field_variable' => 'vacantes', 'field_variable' => 'vacantes',
'field_display_text' => 'Vacantes', 'field_display_text' => 'Vacantes',
'field_visible' => 1, 'field_visible' => 1,
@ -38,7 +38,7 @@ $vacantes->save(array(
$numeroRecomendadoParticipantes = new ExtraField('session'); $numeroRecomendadoParticipantes = new ExtraField('session');
$numeroRecomendadoParticipantes->save(array( $numeroRecomendadoParticipantes->save(array(
'field_type' => ExtraField::FIELD_TYPE_TEXT, 'field_type' => ExtraField::FIELD_TYPE_INTEGER,
'field_variable' => 'numero_recomendado_participantes', 'field_variable' => 'numero_recomendado_participantes',
'field_display_text' => 'Número recomendado de participantes', 'field_display_text' => 'Número recomendado de participantes',
'field_visible' => 1, 'field_visible' => 1,
@ -102,7 +102,7 @@ $esSesionAbierta->save(array(
$duracion = new ExtraField('session'); $duracion = new ExtraField('session');
$duracion->save(array( $duracion->save(array(
'field_type' => ExtraField::FIELD_TYPE_TEXT, 'field_type' => ExtraField::FIELD_TYPE_INTEGER,
'field_variable' => 'duracion', 'field_variable' => 'duracion',
'field_display_text' => 'Duración', 'field_display_text' => 'Duración',
'field_visible' => 1, 'field_visible' => 1,
@ -139,9 +139,9 @@ $finPublicacion->save(array(
$banner = new ExtraField('session'); $banner = new ExtraField('session');
$banner->save(array( $banner->save(array(
'field_type' => ExtraField::FIELD_TYPE_TEXT, 'field_type' => ExtraField::FIELD_TYPE_FILE,
'field_variable' => 'fin_publicacion', 'field_variable' => 'banner',
'field_display_text' => 'Fin de publicación', 'field_display_text' => 'Banner de la sesión',
'field_visible' => 1, 'field_visible' => 1,
'field_changeable' => 1 'field_changeable' => 1
)); ));

Loading…
Cancel
Save