Should fix bugs when using gradebook, works and agenda see #3660

skala
Julio Montoya 14 years ago
parent fda65c4e74
commit 8c4aa18a70
  1. 129
      main/calendar/agenda.inc.php
  2. 71
      main/work/work.lib.php
  3. 17
      main/work/work.php

@ -736,23 +736,46 @@ function selectAll(cbList,bSelect,showwarning)
msg_err3 = document.getElementById(\"err_end_date\");
msg_err4 = document.getElementById(\"err_title\");
var error = false;
if (start_date > ends_date) {
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=\"\";
} else if (!checkDate(start_month,start_day,start_year)) {
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')."\")) {
@ -765,6 +788,8 @@ function selectAll(cbList,bSelect,showwarning)
document.new_calendar_item.submit();
}
}
function reverseAll(cbList)
@ -1068,10 +1093,11 @@ 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);
@ -1079,6 +1105,10 @@ function store_new_agenda_item() {
$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)
VALUES ('".$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);
@ -2254,20 +2288,27 @@ function show_add_form($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
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
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);
@ -2305,7 +2346,7 @@ function show_add_form($id = '') {
echo '<input type="hidden" name="selectedform[0]" value="GROUP:'.intval($_SESSION['toolgroup']).'"/>' ;
echo '<input type="hidden" name="To" value="true"/>' ;
} else {
echo ' <div class="row">
echo '<div class="row">
<div class="label">
<a href="javascript: void(0);" onclick="if(document.getElementById(\'recipient_list\').style.display==\'none\') document.getElementById(\'recipient_list\').style.display=\'block\'; else document.getElementById(\'recipient_list\').style.display=\'none\';">'.Display::return_icon('group.png', get_lang('SentTo'), array ('align' => 'absmiddle'),22).' '.get_lang('SentTo').'</a>
</div>
@ -2317,14 +2358,16 @@ function show_add_form($id = '') {
if (isset($_GET['id']) && $to!='everyone') {
echo '<script>document.getElementById(\'recipient_list\').style.display=\'block\';</script>';
}
echo ' </div>
echo '</div>
</div>';
}
// start date and time
echo '<div class="row">
<div class="label">
echo '<div class="row">';
echo '<div class="label">
'.get_lang('StartDate').'
</div>
<div class="formw">
@ -2374,7 +2417,10 @@ function show_add_form($id = '') {
} ?>
</select>
<a href="javascript:openCalendar('new_calendar_item', 'f')"><?php Display::display_icon('calendar_select.gif', get_lang('Select'), array ('style' => 'vertical-align: middle;')); ?></a>
<a href="javascript:openCalendar('new_calendar_item', 'f')">
<?php Display::display_icon('calendar_select.gif', get_lang('Select'), array ('style' => 'vertical-align: middle;')); ?>
</a>
&nbsp;<?php echo get_lang('StartTime').": "; ?>&nbsp;
<select name="fhour" onchange="javascript:document.new_calendar_item.end_fhour.value=this.value;">
<!-- <option value="--">--</option> -->
@ -2408,7 +2454,32 @@ function show_add_form($id = '') {
echo ' </div>
</div>';
echo '<div class="row">
<div class="label">
</div><div class="formw">';
echo Display::input('checkbox', 'empty_end_date', 1, array('id'=>'empty_end_date', 'checked'=>"checked")).' '.get_lang('NoEndDate');
echo '</div></div>';
echo '<script>
$(function() {
$("#empty_end_date").click(function(){
if ($("#empty_end_date").is(":checked")) {
$("#end_date_span").hide();
} else {
$("#end_date_span").show();
}
});';
if ($item_2_edit['end_date'] == '0000-00-00 00:00:00') {
echo '$("#end_date_span").hide();';
}
echo '
});
</script>';
// end date and time
echo '<span id="end_date_span">';
echo '<div class="row">
<div class="label">
'.get_lang('EndDate').'
@ -2416,7 +2487,8 @@ function show_add_form($id = '') {
<div class="formw">
<div id="err_end_date" style="display:none;color:red"></div>';
?>
<select name="end_fday">
<select id="end_fday" name="end_fday">
<?php
// small loop for filling all the dates
// 2do: the available dates should be those of the selected month => february is from 1 to 28 (or 29) and not to 31
@ -2432,7 +2504,7 @@ function show_add_form($id = '') {
}?>
</select>
<!-- month: january -> december -->
<select name="end_fmonth">
<select id="end_fmonth" name="end_fmonth">
<?php
foreach (range(1, 12) as $i) {
// values have to have double digits
@ -2443,7 +2515,7 @@ function show_add_form($id = '') {
{ echo "<option value=\"".$value."\">".$MonthsLong[$i-1]."</option>"; }
}?>
</select>
<select name="end_fyear">
<select id="end_fyear" name="end_fyear">
<option value="<?php echo ($end_year-1) ?>"><?php echo ($end_year-1) ?></option>
<option value="<?php echo $end_year ?>" selected> <?php echo $end_year ?> </option>
<?php
@ -2452,10 +2524,12 @@ function show_add_form($id = '') {
echo "<option value=\"$value\">$value</option>";
} ?>
</select>
<a href="javascript:openCalendar('new_calendar_item', 'end_f')"><?php Display::display_icon('calendar_select.gif', get_lang('Select'), array ('style' => 'vertical-align: middle;')); ?></a>
<a href="javascript:openCalendar('new_calendar_item', 'end_f')">
<?php echo Display::span(Display::return_icon('calendar_select.gif', get_lang('Select'), array('style' => 'vertical-align: middle;')), array ('id'=>'end_date_calendar_icon')); ?>
</a>
&nbsp;<?php echo get_lang('EndTime').": "; ?>&nbsp;
<select name="end_fhour">
<select id="end_fhour" name="end_fhour">
<!-- <option value="--">--</option> -->
<?php
foreach (range(0, 23) as $i) {
@ -2469,7 +2543,7 @@ function show_add_form($id = '') {
} ?>
</select>
<select name="end_fminute">
<select id="end_fminute" name="end_fminute">
<!-- <option value="<?php echo $end_minutes; ?>"><?php echo $end_minutes; ?></option> -->
<!-- <option value="--">--</option> -->
<?php
@ -2484,9 +2558,10 @@ function show_add_form($id = '') {
}
} ?>
</select>
<?php
echo ' </div>
</div>';
</div> </span>';
// the title of the agenda item
echo ' <div class="row">
@ -2641,7 +2716,9 @@ function show_add_form($id = '') {
echo "<option value=\"$value\">$value</option>";
} ?>
</select>
<a href="javascript:openCalendar('new_calendar_item', 'repeat_end_')"><?php Display::display_icon('calendar_select.gif', get_lang('Select'), array ('style' => 'vertical-align: middle;')); ?></a>
<a href="javascript:openCalendar('new_calendar_item', 'repeat_end_')">
<?php Display::display_icon('calendar_select.gif', get_lang('Select'), array ('style' => 'vertical-align: middle;')); ?>
</a>
</td>
</tr>
</table>
@ -3980,7 +4057,7 @@ function agenda_add_item($course_info, $title, $content, $db_start_date, $db_end
// check if exists in calendar_event table and if it is not deleted!
$sql = "SELECT * FROM $t_agenda agenda, $item_property item_property
WHERE agenda.title ='$title'
WHERE agenda.title = '$title'
AND agenda.content = '$content'
AND agenda.start_date = '$start_date'
AND agenda.end_date = '$end_date' ".(!empty($parent_id)? "
@ -4008,7 +4085,7 @@ function agenda_add_item($course_info, $title, $content, $db_start_date, $db_end
$done = false;
if ((!is_null($to))or (!empty($_SESSION['toolgroup']))) {
// !is_null($to): when no user is selected we send it to everyone
$send_to=separate_users_groups($to);
$send_to = separate_users_groups($to);
// storing the selected groups
if (is_array($send_to['groups'])) {
foreach ($send_to['groups'] as $group) {

@ -492,41 +492,22 @@ function display_student_publications_list($work_dir, $sub_course_dir, $currentC
//$form_folder-> 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;
if ($row['view_properties'] == '1') {
if ($homework['expires_on'] != '0000-00-00 00:00:00') {
$homework['expires_on'] = api_get_local_time($homework['expires_on']);
$there_is_a_expire_date = true;
$form_folder -> addGroup(create_group_date_select(), 'expires', get_lang('ExpiresAt'));
}
if ($homework['ends_on'] != '0000-00-00 00:00:00') {
$homework['ends_on'] = api_get_local_time($homework['ends_on']);
$there_is_a_end_date = true;
$form_folder -> addGroup(create_group_date_select(), 'ends', get_lang('EndsAt'));
}
if ($row['weight'] > 0) {
if ($there_is_a_expire_date && $there_is_a_end_date) {
$form_folder -> addRule(array('expires', 'ends'), get_lang('DateExpiredNotBeLessDeadLine'), 'comparedate');
}
} else {
$there_is_a_end_date = false;
$form_folder -> addElement('html', '<div class="row">
<div class="label">&nbsp;</div>
<div class="formw">
<a href="javascript://" onclick="javascript: return plus();" ><span id="plus">&nbsp;<img style="vertical-align:middle;" src="../img/div_show.gif" alt="" />&nbsp;'.get_lang('AdvancedParameters').'</span></a>
</div>
</div> ');
$form_folder -> addElement('html', '<div id="options" style="display: none;">');
$form_folder->addElement('html', '<div id="options" style="display: none;">');
if (empty($default)) {
$default = api_get_local_time();
@ -537,15 +518,31 @@ function display_student_publications_list($work_dir, $sub_course_dir, $currentC
list($d_year, $d_month, $d_day) = split('-', $parts[0]);
list($d_hour, $d_minute) = split(':', $parts[1]);
//if ($row['view_properties'] == '1') {
$qualification_input[] = FormValidator :: createElement('text','qualification');
$form_folder -> addGroup($qualification_input, 'qualification', get_lang('QualificationNumeric'), 'size="10"');
if ((int)$row['weight'] == 0) {
$form_folder -> addElement('checkbox', 'make_calification', null, get_lang('MakeQualifiable'), 'onclick="javascript: if(this.checked){document.getElementById(\'option3\').style.display = \'block\';}else{document.getElementById(\'option3\').style.display = \'none\';}"');
$form_folder -> addElement('html', '<div id=\'option3\' style="display:none">');
$weight_input2[] = FormValidator :: createElement('text', 'weight');
$form_folder -> addGroup($weight_input2, 'weight', get_lang('WeightInTheGradebook'), 'size="10"');
$form_folder -> addElement('html', '</div>');
} else {
$weight_input[] = FormValidator :: createElement('text', 'weight');
$form_folder -> addGroup($weight_input, 'weight', get_lang('WeightInTheGradebook'), 'size="10"');
//$form_folder->freeze();
}
if ($homework['expires_on'] == '0000-00-00 00:00:00') {
if ($homework['expires_on'] != '0000-00-00 00:00:00') {
$homework['expires_on'] = api_get_local_time($homework['expires_on']);
$there_is_a_expire_date = true;
$form_folder -> addGroup(create_group_date_select(), 'expires', get_lang('ExpiresAt'));
} else {
$homework['expires_on'] = api_get_local_time();
$there_is_a_expire_date = true;
$form_folder -> addElement('checkbox', 'enableExpiryDate',null,get_lang('EnableExpiryDate'), 'onclick="javascript: if(this.checked){document.getElementById(\'option1\').style.display = \'block\';}else{document.getElementById(\'option1\').style.display = \'none\';}"');
@ -553,19 +550,29 @@ function display_student_publications_list($work_dir, $sub_course_dir, $currentC
$form_folder -> addGroup(create_group_date_select(), 'expires', get_lang('ExpiresAt'));
$form_folder -> addElement('html', '</div>');
}
if ($homework['ends_on'] == '0000-00-00 00:00:00') {
if ($homework['ends_on'] != '0000-00-00 00:00:00') {
$homework['ends_on'] = api_get_local_time($homework['ends_on']);
$there_is_a_end_date = true;
$form_folder -> addGroup(create_group_date_select(), 'ends', get_lang('EndsAt'));
} else {
$homework['ends_on'] = api_get_local_time();
$there_is_a_end_date = true;
$form_folder -> addElement('checkbox', 'enableEndDate', null, get_lang('EnableEndDate'), 'onclick="javascript: if(this.checked){document.getElementById(\'option2\').style.display = \'block\';}else{document.getElementById(\'option2\').style.display = \'none\';}"');
$form_folder -> addElement('html', '<div id=\'option2\' style="display:none">');
$form_folder -> addGroup(create_group_date_select(), 'ends', get_lang('EndsAt'));
$form_folder -> addElement('html', '</div>');
$form_folder -> addRule(array('expires', 'ends'), get_lang('DateExpiredNotBeLessDeadLine'), 'comparedate');
}
if ($there_is_a_expire_date && $there_is_a_end_date) {
$form_folder -> addRule(array('expires', 'ends'), get_lang('DateExpiredNotBeLessDeadLine'), 'comparedate');
$form_folder -> addElement('html', '</div>');
}
$form_folder -> addElement('html', '</div>');
$form_folder -> addElement('style_submit_button', 'submit', get_lang('ModifyDirectory'), 'class="save"');
if ($there_is_a_end_date) {
$end_date_array = convert_date_to_array($homework['ends_on'], 'ends');
@ -655,12 +662,20 @@ function display_student_publications_list($work_dir, $sub_course_dir, $currentC
$sql = "SELECT add_to_calendar FROM $work_assigment WHERE publication_id ='".$row['id']."'";
$res = Database::query($sql);
$calendar_id = Database::fetch_row($res);
$dir_name = sprintf(get_lang('HandingOverOfTaskX'), $dir_name);
$end_date = "0000-00-00 00:00:00:";
if ($_POST['enableExpiryDate'] == '1') {
$end_date = get_date_from_group('ends');
}
// update from agenda if it exists
if (!empty($calendar_id[0])) {
$sql = "UPDATE ".$TABLEAGENDA."
SET title='".$dir_name."',
content = '".$dir_name."',
end_date='".get_date_from_group('ends')."'
content = '".Database::escape_string($_POST['description'])."',
end_date = '".$end_date."'
WHERE id='".$calendar_id[0]."'";
Database::query($sql);
}

@ -496,22 +496,23 @@ if (!empty($_REQUEST['new_dir'])) {
// Insert into agenda
$agenda_id = 0;
$end_date = '';
if (isset($_POST['add_to_calendar']) && $_POST['add_to_calendar'] == 1) {
require_once api_get_path(SYS_CODE_PATH).'calendar/agenda.inc.php';
require_once api_get_path(SYS_CODE_PATH).'resourcelinker/resourcelinker.inc.php';
$course = isset($course_info) ? $course_info : null;
$date = time();
$title = Security::remove_XSS($_POST['new_dir']);
$title = sprintf(get_lang('HandingOverOfTaskX'), $_POST['new_dir']);
if (!empty($_POST['type1'])) {
$date = get_date_from_select('expires');
$title = sprintf(get_lang('HandingOverOfTaskX'),Security::remove_XSS($_POST['new_dir']));
$end_date = get_date_from_select('expires');
}
$content = '<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;curdirpath='.substr(Security::remove_XSS($dir_name_sql), 1).'" >'.Security::remove_XSS($_POST['new_dir']).'</a> - '.Security::remove_XSS($_POST['description']);
$description = isset($_POST['description']) ? $_POST['description'] : '';
$content = '<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;curdirpath='.api_substr($dir_name_sql, 1).'" >'.$_POST['new_dir'].'</a>'.$description;
$agenda_id = agenda_add_item($course, $title, $content, $date, '', array('GROUP:'.$toolgroup), 0);
$agenda_id = agenda_add_item($course, $title, $content, $date, $end_date, array('GROUP:'.$toolgroup), 0);
}
$sql_add_publication = "INSERT INTO " . $work_table . " SET " .
"url = '".Database::escape_string($dir_name_sql)."',
$sql_add_publication = "INSERT INTO " . $work_table . " SET
url = '".Database::escape_string($dir_name_sql)."',
title = '',
description = '".Database::escape_string($_POST['description'])."',
author = '',
@ -556,9 +557,7 @@ if (!empty($_REQUEST['new_dir'])) {
$sql_add_publication = "UPDATE ".$work_table." SET "."has_properties = ".Database::insert_id().", view_properties = 1 ".' where id = '.$id;
Database::query($sql_add_publication);
} else {
$sql_add_homework = "INSERT INTO $TSTDPUBASG SET
expires_on = '0000-00-00 00:00:00',
ends_on = '0000-00-00 00:00:00',

Loading…
Cancel
Save