From 8c4aa18a70bf2122c4323106370e3edd453798c6 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Wed, 20 Jul 2011 20:38:07 +0200 Subject: [PATCH] Should fix bugs when using gradebook, works and agenda see #3660 --- main/calendar/agenda.inc.php | 161 ++++++++++++++++++++++++++--------- main/work/work.lib.php | 147 ++++++++++++++++++-------------- main/work/work.php | 31 ++++--- 3 files changed, 215 insertions(+), 124 deletions(-) diff --git a/main/calendar/agenda.inc.php b/main/calendar/agenda.inc.php index 25b80b2366..aaa7d333f0 100755 --- a/main/calendar/agenda.inc.php +++ b/main/calendar/agenda.inc.php @@ -735,24 +735,47 @@ function selectAll(cbList,bSelect,showwarning) msg_err2 = document.getElementById(\"err_start_date\"); msg_err3 = document.getElementById(\"err_end_date\"); msg_err4 = document.getElementById(\"err_title\"); + + + var error = false; if (start_date > ends_date) { - msg_err1.style.display =\"block\"; - msg_err1.innerHTML=\"".get_lang('EndDateCannotBeBeforeTheStartDate')."\"; - msg_err2.innerHTML=\"\";msg_err3.innerHTML=\"\"; - } else if (!checkDate(start_month,start_day,start_year)) { + if ($('#empty_end_date').is(':checked')) { + msg_err1.innerHTML=\"\"; + msg_err2.innerHTML=\"\"; + msg_err3.innerHTML=\"\"; + + } else { + error = true; + msg_err1.style.display =\"block\"; + msg_err1.innerHTML=\"".get_lang('EndDateCannotBeBeforeTheStartDate')."\"; + msg_err2.innerHTML=\"\"; + msg_err3.innerHTML=\"\"; + } + } + + if (!checkDate(start_month,start_day,start_year)) { msg_err2.style.display =\"block\"; msg_err2.innerHTML=\"".get_lang('InvalidDate')."\"; - msg_err1.innerHTML=\"\";msg_err3.innerHTML=\"\"; - } else if (!checkDate(ends_month,ends_day,ends_year)) { + msg_err1.innerHTML=\"\"; + msg_err3.innerHTML=\"\"; + error = true; + } + + if (!checkDate(ends_month,ends_day,ends_year)) { msg_err3.style.display =\"block\"; msg_err3.innerHTML=\"".get_lang('InvalidDate')."\"; msg_err1.innerHTML=\"\";msg_err2.innerHTML=\"\"; - } else if (document.new_calendar_item.title.value == '') { + error = true; + } + + if (document.new_calendar_item.title.value == '') { msg_err4.style.display =\"block\"; msg_err4.innerHTML=\"".get_lang('FieldRequired')."\"; msg_err1.innerHTML=\"\";msg_err2.innerHTML=\"\";msg_err3.innerHTML=\"\"; - } else { + error = true; + } + if (error == false) { if (cbList) { if (cbList.length < 1) { if (!confirm(\"".get_lang('Send2All')."\")) { @@ -764,6 +787,8 @@ function selectAll(cbList,bSelect,showwarning) } document.new_calendar_item.submit(); } + + } @@ -1068,16 +1093,21 @@ function store_new_agenda_item() { $t_agenda_repeat = Database::get_course_Table(TABLE_AGENDA_REPEAT); // some filtering of the input data - $title=strip_tags(trim($_POST['title'])); // no html allowed in the title - $content=trim($_POST['content']); - $start_date=(int)$_POST['fyear']."-".(int)$_POST['fmonth']."-".(int)$_POST['fday']." ".(int)$_POST['fhour'].":".(int)$_POST['fminute'].":00"; - $end_date=(int)$_POST['end_fyear']."-".(int)$_POST['end_fmonth']."-".(int)$_POST['end_fday']." ".(int)$_POST['end_fhour'].":".(int)$_POST['end_fminute'].":00"; - + $title = strip_tags(trim($_POST['title'])); // no html allowed in the title + $content = trim($_POST['content']); + $start_date = (int)$_POST['fyear']."-".(int)$_POST['fmonth']."-".(int)$_POST['fday']." ".(int)$_POST['fhour'].":".(int)$_POST['fminute'].":00"; + $end_date = (int)$_POST['end_fyear']."-".(int)$_POST['end_fmonth']."-".(int)$_POST['end_fday']." ".(int)$_POST['end_fhour'].":".(int)$_POST['end_fminute'].":00"; + + $title = Database::escape_string($title); $content = Database::escape_string($content); $start_date = Database::escape_string($start_date); $end_date = Database::escape_string($end_date); - + + + if ($_POST['empty_end_date'] == 1) { + $end_date = "0000-00-00 00:00:00"; + } // store in the table calendar_event $sql = "INSERT INTO ".$TABLEAGENDA." (title,content, start_date, end_date) @@ -1628,6 +1658,10 @@ function store_edited_agenda_item($id_attach,$file_comment) { $start_date = api_get_utc_datetime($start_date); $end_date = api_get_utc_datetime($end_date); + if ($_POST['empty_end_date'] == 1) { + $end_date = "0000-00-00 00:00:00"; + } + // 1.b. the actual saving in calendar_event table $edit_result = save_edit_agenda_item($id, $title, $content, $start_date, $end_date); @@ -2253,21 +2287,28 @@ function show_add_form($id = '') { if (is_int($id)) { //echo "before get_agenda_item".$_SESSION['allow_individual_calendar']; $item_2_edit=get_agenda_item($id); + $title = $item_2_edit['title']; $content= $item_2_edit['content']; // start date - $item_2_edit['start_date'] = api_get_local_time($item_2_edit['start_date']); - list($datepart, $timepart) = split(" ", $item_2_edit['start_date']); - list($year, $month, $day) = explode("-", $datepart); - list($hours, $minutes, $seconds) = explode(":", $timepart); + if ($item_2_edit['start_date'] != '0000-00-00 00:00:00') { + $item_2_edit['start_date'] = api_get_local_time($item_2_edit['start_date']); + list($datepart, $timepart) = split(" ", $item_2_edit['start_date']); + list($year, $month, $day) = explode("-", $datepart); + list($hours, $minutes, $seconds) = explode(":", $timepart); + } // end date - $item_2_edit['end_date'] = api_get_local_time($item_2_edit['end_date']); - list($datepart, $timepart) = split(" ", $item_2_edit['end_date']); - list($end_year, $end_month, $end_day) = explode("-", $datepart); - list($end_hours, $end_minutes, $end_seconds) = explode(":", $timepart); + if ($item_2_edit['end_date'] != '0000-00-00 00:00:00') { + $item_2_edit['end_date'] = api_get_local_time($item_2_edit['end_date']); + + list($datepart, $timepart) = split(" ", $item_2_edit['end_date']); + list($end_year, $end_month, $end_day) = explode("-", $datepart); + + list($end_hours, $end_minutes, $end_seconds) = explode(":", $timepart); + } // attachments edit_added_resources("Agenda", $id); @@ -2299,13 +2340,13 @@ function show_add_form($id = '') { $form_title = get_lang('AddCalendarItem'); } echo '
'.$form_title.'
'; - + // selecting the users / groups if (isset ($_SESSION['toolgroup'])) { echo '' ; echo '' ; } else { - echo '
+ echo '
@@ -2317,20 +2358,22 @@ function show_add_form($id = '') { if (isset($_GET['id']) && $to!='everyone') { echo ''; } - echo '
+ echo '
'; - } + + + // start date and time - echo '
-
+ echo '
'; + echo '
'.get_lang('StartDate').'
'; - ?> + ?> - 'vertical-align: middle;')); ?> + + 'vertical-align: middle;')); ?> + +    + ?> + + - ".$MonthsLong[$i-1].""; } }?> - $value"; } ?> - 'vertical-align: middle;')); ?> + + 'vertical-align: middle;')), array ('id'=>'end_date_calendar_icon')); ?> +    - - + -
'; +
'; // the title of the agenda item echo '
@@ -2641,8 +2716,10 @@ function show_add_form($id = '') { echo ""; } ?> - 'vertical-align: middle;')); ?> - + + 'vertical-align: middle;')); ?> + + addElement('textarea', 'description', get_lang('Description'), array('rows' => 5, 'cols' => 50)); $form_folder->add_html_editor('description', get_lang('Description'), false, false, array('ToolbarSet' => 'work', 'Width' => '100%', 'Height' => '200')); - $qualification_input[] = FormValidator :: createElement('text','qualification'); - $form_folder -> addGroup($qualification_input, 'qualification', get_lang('QualificationNumeric'), 'size="10"'); + + if ($row['weight'] > 0) { - $weight_input[] = FormValidator :: createElement('text', 'weight'); - $form_folder -> addGroup($weight_input, 'weight', get_lang('WeightInTheGradebook'), 'size="10"'); + } $there_is_a_end_date = false; + + $form_folder -> addElement('html', ' '); + $form_folder->addElement('html', '