Replacing datepickerdate with date_picker element

1.9.x
Julio Montoya 11 years ago
parent e0584540e3
commit fa112d7888
  1. 26
      main/attendance/attendance_calendar.php
  2. 23
      main/attendance/attendance_controller.php
  3. 1
      main/attendance/attendance_edit.php
  4. 4
      main/inc/lib/formvalidator/Element/DateRangePicker.php
  5. 37
      main/inc/lib/formvalidator/Rule/Date.php
  6. 41
      main/inc/lib/formvalidator/Rule/DateCompare.php
  7. 8
      main/inc/lib/usermanager.lib.php
  8. 4
      main/survey/create_new_survey.php
  9. 5
      main/survey/survey.lib.php

@ -50,11 +50,18 @@ if (isset($action) && $action == 'calendar_add') {
// calendar add form
$form = new FormValidator('attendance_calendar_add','POST','index.php?action=calendar_add&attendance_id='.$attendance_id.$param_gradebook.'&'.api_get_cidreq(),'');
$form->addElement('header', get_lang('AddADateTime'));
$form->addElement('datepicker', 'date_time', '', array('form_name'=>'attendance_calendar_add'), 5);
$form->addElement('date_time_picker', 'date_time');
$defaults['date_time'] = date('Y-m-d H:i', api_strtotime(api_get_local_time()));
$form->addElement('checkbox', 'repeat', null, get_lang('RepeatDate'), array('onclick' => "javascript: if(this.checked){document.getElementById('repeat-date-attendance').style.display='block';}else{document.getElementById('repeat-date-attendance').style.display='none';}",
));
$form->addElement(
'checkbox',
'repeat',
null,
get_lang('RepeatDate'),
array(
'onclick' => "javascript: if(this.checked){document.getElementById('repeat-date-attendance').style.display='block';}else{document.getElementById('repeat-date-attendance').style.display='none';}",
)
);
$defaults['repeat'] = $repeat;
@ -63,10 +70,15 @@ if (isset($action) && $action == 'calendar_add') {
} else {
$form->addElement('html', '<div id="repeat-date-attendance" style="display:none">');
}
$a_repeat_type = array('daily'=>get_lang('RepeatDaily'), 'weekly'=>get_lang('RepeatWeekly'), 'monthlyByDate'=>get_lang('RepeatMonthlyByDate'));
$a_repeat_type = array(
'daily' => get_lang('RepeatDaily'),
'weekly' => get_lang('RepeatWeekly'),
'monthlyByDate' => get_lang('RepeatMonthlyByDate')
);
$form->addElement('select', 'repeat_type', get_lang('RepeatType') , $a_repeat_type);
$form->addElement('datepickerdate', 'end_date_time', get_lang('RepeatEnd'), array('form_name'=>'attendance_calendar_add'));
$defaults['end_date_time'] = date('Y-m-d 12:00:00');
$form->addElement('date_picker', 'end_date_time', get_lang('RepeatEnd'), array('form_name'=>'attendance_calendar_add'));
$defaults['end_date_time'] = date('Y-m-d');
$form->addElement('html', '</div>');
$defaults['repeat_type'] = 'weekly';
@ -85,7 +97,7 @@ if (isset($action) && $action == 'calendar_add') {
// calendar edit form
echo '<div class="attendance-calendar-edit">';
$form = new FormValidator('attendance_calendar_edit','POST','index.php?action=calendar_edit&attendance_id='.$attendance_id.'&calendar_id='.$calendar_id.'&'.api_get_cidreq().$param_gradebook,'');
$form->addElement('datepicker', 'date_time', '', array('form_name'=>'attendance_calendar_edit'), 5);
$form->addElement('date_time_picker', 'date_time', '', array('form_name'=>'attendance_calendar_edit'), 5);
$defaults['date_time'] = $calendar['date_time'];
$form->addElement('style_submit_button', null, get_lang('Save'), 'class="save"');
$form->addElement('style_submit_button', 'cancel', get_lang('Cancel'), 'class="cancel"');

@ -316,20 +316,21 @@
if (!isset($_POST['cancel'])) {
if (isset($_POST['repeat'])) {
//@todo check this error_logs
$start_datetime = api_strtotime(api_get_utc_datetime($attendance->build_datetime_from_array($_POST['date_time'])),'UTC');
//error_log('$start_datetime '.$start_datetime);
$_POST['end_date_time']['H'] = $_POST['date_time']['H'];
$_POST['end_date_time']['i'] = $_POST['date_time']['i'];
//error_log($attendance->build_datetime_from_array($_POST['end_date_time']));
$start_datetime = api_strtotime(
api_get_utc_datetime($_POST['date_time']), 'UTC'
);
$end_datetime = api_strtotime(api_get_utc_datetime($attendance->build_datetime_from_array($_POST['end_date_time'])),'UTC');
//error_log('$end_datetime '.$end_datetime);
$checkdate = checkdate($_POST['end_date_time']['F'], $_POST['end_date_time']['d'], $_POST['end_date_time']['Y']);
$end_datetime = api_strtotime(api_get_utc_datetime($_POST['end_date_time'].' 23:59:59'), 'UTC');
$checkdate = api_is_valid_date(api_get_utc_datetime($_POST['end_date_time'].' 23:59:59'));
$repeat_type = $_POST['repeat_type'];
if (($end_datetime > $start_datetime) && $checkdate) {
$affected_rows = $attendance->attendance_repeat_calendar_add($attendance_id, $start_datetime, $end_datetime, $repeat_type);
$affected_rows = $attendance->attendance_repeat_calendar_add(
$attendance_id,
$start_datetime,
$end_datetime,
$repeat_type
);
$action = 'calendar_list';
} else {
if (!$checkdate) {
@ -341,7 +342,7 @@
$action = 'calendar_add';
}
} else {
$datetime = $attendance->build_datetime_from_array($_POST['date_time']);
$datetime = $_POST['date_time'];
$datetimezone = api_get_utc_datetime($datetime);
if (!empty($datetime)) {
$attendance->set_date_time($datetimezone);

@ -7,7 +7,6 @@
* @package chamilo.attendance
*/
// protect a course script
api_protect_course_script(true);

@ -98,7 +98,6 @@ class DateRangePicker extends HTML_QuickForm_text
*/
function validateDates($dates)
{
if (empty($dates['start']) || empty($dates['end'])) {
return false;
}
@ -115,7 +114,4 @@ class DateRangePicker extends HTML_QuickForm_text
return true;
}
}

@ -1,40 +1,23 @@
<?php
// $Id: Date.php 6187 2005-09-07 10:23:57Z bmol $
/*
==============================================================================
Dokeos - elearning and course management software
/* For licensing terms, see /license.txt */
/** @author Bart Mollet, Julio Montoya */
require_once 'HTML/QuickForm/Rule.php';
Copyright (c) 2004-2005 Dokeos S.A.
Copyright (c) Bart Mollet, Hogeschool Gent
For a full list of contributors, see "credits.txt".
The full license can be read in "license.txt".
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
See the GNU General Public License for more details.
Contact address: Dokeos, 44 rue des palais, B-1030 Brussels, Belgium
Mail: info@dokeos.com
==============================================================================
*/
require_once ('HTML/QuickForm/Rule.php');
/**
* QuickForm rule to check a date
* Class HTML_QuickForm_Rule_Date
*/
class HTML_QuickForm_Rule_Date extends HTML_QuickForm_Rule
{
/**
* Function to check a date
* Check a date
* @see HTML_QuickForm_Rule
* @param array $date An array with keys F (month), d (day) and Y (year)
* @param string $date example 2014-04-30
* @param array $options
*
* @return boolean True if date is valid
*/
function validate($date, $options)
public function validate($date, $options)
{
return checkdate($date['F'], $date['d'], $date['Y']);
return api_is_valid_date($date, 'Y-m-d');
}
}

@ -1,46 +1,21 @@
<?php
// $Id: DateCompare.php 6187 2005-09-07 10:23:57Z bmol $
/*
==============================================================================
Dokeos - elearning and course management software
Copyright (c) 2004-2005 Dokeos S.A.
Copyright (c) Bart Mollet, Hogeschool Gent
For a full list of contributors, see "credits.txt".
The full license can be read in "license.txt".
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
See the GNU General Public License for more details.
Contact address: Dokeos, 44 rue des palais, B-1030 Brussels, Belgium
Mail: info@dokeos.com
==============================================================================
*/
/* For licensing terms, see /license.txt */
/** @author Bart Mollet, Julio Montoya */
require_once 'HTML/QuickForm/Rule/Compare.php';
/**
* QuickForm rule to compare 2 dates
* Class HTML_QuickForm_Rule_DateCompare
*/
class HTML_QuickForm_Rule_DateCompare extends HTML_QuickForm_Rule_Compare
{
/**
* Validate 2 dates
* @param array $values Array with the 2 dates. Each element in this array
* should be an array width keys F (month), d (day) and Y (year)
* @param string $operator The operator to use (default '==')
* @return boolean True if the 2 given dates match the operator
* @param array $values Array with the 2 dates.
* @param $operator
*
* @return boolean true if the 2 given dates match the operator
*/
function validate($values, $operator = null)
{
$date1 = $values[0];
$date2 = $values[1];
$time1 = mktime($date1['H'],$date1['i'],0,$date1['F'],$date1['d'],$date1['Y']);
$time2 = mktime($date2['H'],$date2['i'],0,$date2['F'],$date2['d'],$date2['Y']);
return parent::validate(array($time1,$time2),$operator);
return api_strtotime($values[0]) < api_strtotime($values[1]);
}
}
?>

@ -4205,8 +4205,8 @@ class UserManager
}
break;
case self::USER_FIELD_TYPE_DATE:
$form->addElement('datepickerdate', 'extra_'.$field_details[1], $field_details[3], array('form_name' => $form_name));
$form->_elements[$form->_elementIndex['extra_'.$field_details[1]]]->setLocalOption('minYear', 1900);
$form->addElement('date_picker', 'extra_'.$field_details[1], $field_details[3]);
//$form->_elements[$form->_elementIndex['extra_'.$field_details[1]]]->setLocalOption('minYear', 1900);
$defaults['extra_'.$field_details[1]] = date('Y-m-d 12:00:00');
$form->setDefaults($defaults);
if (!$admin_permissions) {
@ -4216,8 +4216,8 @@ class UserManager
$form->applyFilter('theme', 'trim');
break;
case self::USER_FIELD_TYPE_DATETIME:
$form->addElement('datepicker', 'extra_'.$field_details[1], $field_details[3], array('form_name' => $form_name));
$form->_elements[$form->_elementIndex['extra_'.$field_details[1]]]->setLocalOption('minYear', 1900);
$form->addElement('date_time_picker', 'extra_'.$field_details[1], $field_details[3]);
//$form->_elements[$form->_elementIndex['extra_'.$field_details[1]]]->setLocalOption('minYear', 1900);
$defaults['extra_'.$field_details[1]] = date('Y-m-d 12:00:00');
$form->setDefaults($defaults);
if (!$admin_permissions) {

@ -151,8 +151,8 @@ $form->addElement('html_editor', 'survey_subtitle', get_lang('SurveySubTitle'),
// Pass the language of the survey in the form
$form->addElement('hidden', 'survey_language');
$form->addElement('datepickerdate', 'start_date', get_lang('StartDate'), array('form_name' => 'survey'));
$form->addElement('datepickerdate', 'end_date', get_lang('EndDate'), array('form_name' => 'survey'));
$form->addElement('date_picker', 'start_date', get_lang('StartDate'));
$form->addElement('date_picker', 'end_date', get_lang('EndDate'));
//$group = '';
//$group[] =& HTML_QuickForm::createElement('radio', 'survey_share', null, get_lang('Yes'), $form_share_value);

@ -155,13 +155,10 @@ class survey_manager
public static function store_survey($values)
{
$_user = api_get_user_info();
// Table defnitions
$course_id = api_get_course_int_id();
$table_survey = Database :: get_course_table(TABLE_SURVEY);
$shared_survey_id = 0;
$course_id = api_get_course_int_id();
if (!$values['survey_id'] || !is_numeric($values['survey_id'])) {
// Check if the code doesn't soon exists in this language
$sql = 'SELECT 1 FROM '.$table_survey.'

Loading…
Cancel
Save