Fixing exercise edition.

1.9.x
Julio Montoya 11 years ago
parent e4e1719ed8
commit c9fac12553
  1. 33
      main/exercice/exercise.class.php
  2. 156
      main/exercice/exercise_admin.php
  3. 2
      main/exercice/overview.php
  4. 1
      main/inc/lib/formvalidator/FormValidator.class.php
  5. 23
      main/inc/lib/formvalidator/Rule/DateTimeRule.php

@ -905,7 +905,8 @@ class Exercise {
* Creates the form to create / edit an exercise
* @param FormValidator $form
*/
function createForm ($form, $type='full') {
function createForm($form, $type='full')
{
global $id;
if (empty($type)){
@ -924,11 +925,12 @@ class Exercise {
// Title.
$form->addElement('text', 'exerciseTitle', get_lang('ExerciseName'), array('class' => 'span6','id'=>'exercise_title'));
$form->addElement('advanced_settings','
<a href="javascript://" onclick=" return show_media()">
$form->addElement('advanced_settings',
'<a href="javascript://" onclick=" return show_media()">
<span id="media_icon">
<img style="vertical-align: middle;" src="../img/looknfeel.png" alt="" /> '.addslashes(api_htmlentities(get_lang('ExerciseDescription'))).'
</span>
<img style="vertical-align: middle;" src="../img/looknfeel.png" alt="" />'.
addslashes(api_htmlentities(get_lang('ExerciseDescription'))).'
</span>
</a>
');
@ -1076,7 +1078,7 @@ class Exercise {
else
$form->addElement('html','<div id="start_date_div" style="display:none;">');
$form->addElement('datepicker', 'start_time', '', array('form_name'=>'exercise_admin'), 5);
$form->addElement('date_time_picker', 'start_time');
$form->addElement('html','</div>');
@ -1087,7 +1089,7 @@ class Exercise {
else
$form->addElement('html','<div id="end_date_div" style="display:none;">');
$form->addElement('datepicker', 'end_time', '', array('form_name'=>'exercise_admin'), 5);
$form->addElement('date_time_picker', 'end_time');
$form->addElement('html','</div>');
//$check_option=$this->selectType();
@ -1157,8 +1159,8 @@ class Exercise {
if ($type == 'full') {
// rules
$form->addRule('exerciseAttempts', get_lang('Numeric'), 'numeric');
$form->addRule('start_time', get_lang('InvalidDate'), 'date');
$form->addRule('end_time', get_lang('InvalidDate'), 'date');
$form->addRule('start_time', get_lang('InvalidDate'), 'datetime');
$form->addRule('end_time', get_lang('InvalidDate'), 'datetime');
}
// defaults
@ -1271,23 +1273,14 @@ class Exercise {
if ($form->getSubmitValue('activate_start_date_check') == 1) {
$start_time = $form->getSubmitValue('start_time');
$start_time['F'] = sprintf('%02d', $start_time['F']);
$start_time['i'] = sprintf('%02d', $start_time['i']);
$start_time['d'] = sprintf('%02d', $start_time['d']);
$this->start_time = api_get_utc_datetime($start_time['Y'].'-'.$start_time['F'].'-'.$start_time['d'].' '.$start_time['H'].':'.$start_time['i'].':00');
$this->start_time = api_get_utc_datetime($start_time);
} else {
$this->start_time = '0000-00-00 00:00:00';
}
if ($form->getSubmitValue('activate_end_date_check') == 1) {
$end_time = $form->getSubmitValue('end_time');
$end_time['F'] = sprintf('%02d', $end_time['F']);
$end_time['i'] = sprintf('%02d', $end_time['i']);
$end_time['d'] = sprintf('%02d', $end_time['d']);
$this->end_time = api_get_utc_datetime($end_time['Y'].'-'.$end_time['F'].'-'.$end_time['d'].' '.$end_time['H'].':'.$end_time['i'].':00');
$this->end_time = api_get_utc_datetime($end_time);
} else {
$this->end_time = '0000-00-00 00:00:00';
}

@ -28,112 +28,100 @@ if (!api_is_allowed_to_edit(null,true)) {
}
$htmlHeadXtra[] = '<script>
function advanced_parameters() {
if(document.getElementById(\'options\').style.display == \'none\') {
document.getElementById(\'options\').style.display = \'block\';
document.getElementById(\'img_plus_and_minus\').innerHTML=\' <img style="vertical-align:middle;" src="../img/div_hide.gif" alt="" /> '.addslashes(api_htmlentities(get_lang('AdvancedParameters'))).'\';
} else {
document.getElementById(\'options\').style.display = \'none\';
document.getElementById(\'img_plus_and_minus\').innerHTML=\' <img style="vertical-align:middle;" src="../img/div_show.gif" alt="" /> '.addslashes(api_htmlentities(get_lang('AdvancedParameters'))).'\';
}
function advanced_parameters() {
if(document.getElementById(\'options\').style.display == \'none\') {
document.getElementById(\'options\').style.display = \'block\';
document.getElementById(\'img_plus_and_minus\').innerHTML=\' <img style="vertical-align:middle;" src="../img/div_hide.gif" alt="" /> '.addslashes(api_htmlentities(get_lang('AdvancedParameters'))).'\';
} else {
document.getElementById(\'options\').style.display = \'none\';
document.getElementById(\'img_plus_and_minus\').innerHTML=\' <img style="vertical-align:middle;" src="../img/div_show.gif" alt="" /> '.addslashes(api_htmlentities(get_lang('AdvancedParameters'))).'\';
}
}
function FCKeditor_OnComplete( editorInstance ) {
if (document.getElementById ( \'HiddenFCK\' + editorInstance.Name )) {
HideFCKEditorByInstanceName (editorInstance.Name);
}
}
function FCKeditor_OnComplete( editorInstance ) {
if (document.getElementById ( \'HiddenFCK\' + editorInstance.Name )) {
HideFCKEditorByInstanceName (editorInstance.Name);
}
}
function HideFCKEditorByInstanceName ( editorInstanceName ) {
if (document.getElementById ( \'HiddenFCK\' + editorInstanceName ).className == "HideFCKEditor" )
{
document.getElementById ( \'HiddenFCK\' + editorInstanceName ).className = "media";
}
function HideFCKEditorByInstanceName ( editorInstanceName ) {
if (document.getElementById ( \'HiddenFCK\' + editorInstanceName ).className == "HideFCKEditor" ) {
document.getElementById ( \'HiddenFCK\' + editorInstanceName ).className = "media";
}
}
function show_media() {
var my_display = document.getElementById(\'HiddenFCKexerciseDescription\').style.display;
if(my_display== \'none\' || my_display == \'\') {
document.getElementById(\'HiddenFCKexerciseDescription\').style.display = \'block\';
document.getElementById(\'media_icon\').innerHTML=\' <img src="../img/looknfeelna.png" alt="" /> '.addslashes(api_htmlentities(get_lang('ExerciseDescription'))).'\';
} else {
document.getElementById(\'HiddenFCKexerciseDescription\').style.display = \'none\';
document.getElementById(\'media_icon\').innerHTML=\' <img src="../img/looknfeel.png" alt="" /> '.addslashes(api_htmlentities(get_lang('ExerciseDescription'))).'\';
}
function show_media() {
var my_display = document.getElementById(\'HiddenFCKexerciseDescription\').style.display;
if(my_display== \'none\' || my_display == \'\') {
document.getElementById(\'HiddenFCKexerciseDescription\').style.display = \'block\';
document.getElementById(\'media_icon\').innerHTML=\' <img src="../img/looknfeelna.png" alt="" /> '.addslashes(api_htmlentities(get_lang('ExerciseDescription'))).'\';
} else {
document.getElementById(\'HiddenFCKexerciseDescription\').style.display = \'none\';
document.getElementById(\'media_icon\').innerHTML=\' <img src="../img/looknfeel.png" alt="" /> '.addslashes(api_htmlentities(get_lang('ExerciseDescription'))).'\';
}
}
function activate_start_date() {
if(document.getElementById(\'start_date_div\').style.display == \'none\') {
document.getElementById(\'start_date_div\').style.display = \'block\';
} else {
document.getElementById(\'start_date_div\').style.display = \'none\';
}
function activate_start_date() {
if(document.getElementById(\'start_date_div\').style.display == \'none\') {
document.getElementById(\'start_date_div\').style.display = \'block\';
} else {
document.getElementById(\'start_date_div\').style.display = \'none\';
}
}
function activate_end_date() {
if(document.getElementById(\'end_date_div\').style.display == \'none\') {
document.getElementById(\'end_date_div\').style.display = \'block\';
} else {
document.getElementById(\'end_date_div\').style.display = \'none\';
}
function activate_end_date() {
if(document.getElementById(\'end_date_div\').style.display == \'none\') {
document.getElementById(\'end_date_div\').style.display = \'block\';
} else {
document.getElementById(\'end_date_div\').style.display = \'none\';
}
}
function feedbackselection() {
var index = document.exercise_admin.exerciseFeedbackType.selectedIndex;
function feedbackselection() {
var index = document.exercise_admin.exerciseFeedbackType.selectedIndex;
if (index == \'1\') {
document.exercise_admin.exerciseType[1].checked=true;
document.exercise_admin.exerciseType[0].disabled=true;
} else {
document.exercise_admin.exerciseType[0].disabled=false;
}
}
function option_time_expired() {
if(document.getElementById(\'timercontrol\').style.display == \'none\')
{
document.getElementById(\'timercontrol\').style.display = \'block\';
} else {
document.getElementById(\'timercontrol\').style.display = \'none\';
}
if (index == \'1\') {
document.exercise_admin.exerciseType[1].checked=true;
document.exercise_admin.exerciseType[0].disabled=true;
} else {
document.exercise_admin.exerciseType[0].disabled=false;
}
}
function check_per_page_one() {
/*if (document.getElementById(\'divtimecontrol\').style.display==\'none\') {
document.getElementById(\'divtimecontrol\').style.display=\'block\';
document.getElementById(\'divtimecontrol\').display=block;
document.getElementById(\'timecontrol\').display=none;
}*/
document.getElementById(\'exerciseType_0\').checked=true;
function option_time_expired() {
if(document.getElementById(\'timercontrol\').style.display == \'none\')
{
document.getElementById(\'timercontrol\').style.display = \'block\';
} else {
document.getElementById(\'timercontrol\').style.display = \'none\';
}
}
function check_per_page_all() {
/*if (document.getElementById(\'divtimecontrol\').style.display==\'block\') {
document.getElementById(\'divtimecontrol\').style.display=\'none\';
document.getElementById(\'enabletimercontroltotalminutes\').value=\'\';
}*/
if (document.getElementById(\'exerciseType_1\') && document.getElementById(\'exerciseType_1\').checked) {
document.getElementById(\'exerciseType_0\').checked = true;
}
}
function check_per_page_one() {
document.getElementById(\'exerciseType_0\').checked=true;
}
function check_feedback() {
if (document.getElementById(\'result_disabled_1\').checked == true) {
document.getElementById(\'result_disabled_0\').checked = true;
}
function check_per_page_all() {
if (document.getElementById(\'exerciseType_1\') && document.getElementById(\'exerciseType_1\').checked) {
document.getElementById(\'exerciseType_0\').checked = true;
}
}
function check_direct_feedback() {
document.getElementById(\'option_page_one\').checked = true;
function check_feedback() {
if (document.getElementById(\'result_disabled_1\').checked == true) {
document.getElementById(\'result_disabled_0\').checked = true;
}
}
function check_results_disabled() {
document.getElementById(\'exerciseType_2\').checked = true;
}
</script>';
function check_direct_feedback() {
document.getElementById(\'option_page_one\').checked = true;
document.getElementById(\'result_disabled_0\').checked = true;
}
function check_results_disabled() {
document.getElementById(\'exerciseType_2\').checked = true;
}
</script>';
// to correct #4029 Random and number of attempt menu empty added window.onload=advanced_parameters;
$htmlHeadXtra[] = '<script>

@ -74,7 +74,7 @@ $message = '';
$is_allowed_to_edit = api_is_allowed_to_edit(null,true);
$edit_link = '';
if ($is_allowed_to_edit ) {
if ($is_allowed_to_edit) {
$edit_link = Display::url(Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL), api_get_path(WEB_CODE_PATH).'exercice/admin.php?'.api_get_cidreq().'&id_session='.api_get_session_id().'&exerciseId='.$objExercise->id);
}

@ -143,6 +143,7 @@ class FormValidator extends HTML_QuickForm
$this->registerElementType('CAPTCHA_Image', 'HTML/QuickForm/CAPTCHA/Image.php', 'HTML_QuickForm_CAPTCHA_Image');
$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');
$this->registerRule('html', null, 'HTML_QuickForm_Rule_HTML', $dir . 'Rule/HTML.php');
$this->registerRule('username_available', null, 'HTML_QuickForm_Rule_UsernameAvailable', $dir . 'Rule/UsernameAvailable.php');

@ -0,0 +1,23 @@
<?php
/* For licensing terms, see /license.txt */
/** @author Bart Mollet, Julio Montoya */
require_once 'HTML/QuickForm/Rule.php';
/**
* Class HTML_QuickForm_Rule_Date
*/
class DateTimeRule extends HTML_QuickForm_Rule
{
/**
* Check a date
* @see HTML_QuickForm_Rule
* @param string $date example 2014-04-30
* @param array $options
*
* @return boolean True if date is valid
*/
public function validate($date, $options)
{
return api_is_valid_date($date, 'Y-m-d h:i');
}
}
Loading…
Cancel
Save