diff --git a/main/admin/calendar.lib.php b/main/admin/calendar.lib.php index 8e5964056f..7052a8a808 100755 --- a/main/admin/calendar.lib.php +++ b/main/admin/calendar.lib.php @@ -5,7 +5,7 @@ * @author Carlos Vargas * This file is the calendar/agenda.inc.php * -* @todo This file should not exist since redeclares many of the functions in calendar/agenda.inc.php J.M +* @todo This file should not exist since it redeclares many of the functions in calendar/agenda.inc.php thanks cvargas!!! : jmontoya */ /* @@ -340,52 +340,41 @@ function display_monthcalendar($month, $year) { $today = getdate(); while ($curday <=$numberofdays[$month]) { echo ""; - for ($ii=0; $ii<7; $ii++) - { - if (($curday == -1)&&($ii==$startdayofweek)) - { + for ($ii=0; $ii<7; $ii++) { + if (($curday == -1)&&($ii==$startdayofweek)) { $curday = 1; } - if (($curday>0)&&($curday<=$numberofdays[$month])) - { + if (($curday>0)&&($curday<=$numberofdays[$month])) { $bgcolor = $ii<5 ? "class=\"row_odd\"" : "class=\"row_even\""; $dayheader = "$curday"; - if (key_exists($curday,$data)) - { + if (key_exists($curday,$data)) { $dayheader="".$curday.""; - foreach ($data[$curday] as $key=>$agenda_item) - { - foreach ($agenda_item as $key=>$value) - { - $dayheader .= '
'.substr($value['start_date'],11,8).''; + foreach ($data[$curday] as $key=>$agenda_item) { + foreach ($agenda_item as $key=>$value) { + $start_time = api_convert_and_format_date($value['start_date'], TIME_NO_SEC_FORMAT); + $end_time = api_convert_and_format_date($value['end_date'], TIME_NO_SEC_FORMAT); + $dayheader .= '
'.$start_time.' - '.$end_time.''; $dayheader .= ' - '; $dayheader .= $value['title']; } } } - - if (($curday==$today['mday'])&&($year ==$today['year'])&&($month == $today['mon'])) - { - echo "".$dayheader." "; - } - else - { - echo "".$dayheader." "; + if (($curday==$today['mday'])&&($year ==$today['year'])&&($month == $today['mon'])) { + echo "".$dayheader." "; + } else { + echo "".$dayheader." "; } - echo ""; + echo ""; $curday++; - } - else - { - echo " "; - - } + } else { + echo " "; + } } - echo ""; + echo ""; } -echo ""; + echo ""; } /** * this function shows the form with the user that were not selected @@ -409,10 +398,8 @@ function store_new_agenda_item() { $end_date=(int)$_POST['end_fyear']."-".(int)$_POST['end_fmonth']."-".(int)$_POST['end_fday']." ".(int)$_POST['end_fhour'].":".(int)$_POST['end_fminute'].":00"; // store in the table calendar_event - $sql = "INSERT INTO ".$TABLEAGENDA." - (title,content, start_date, end_date) - VALUES - ('".$title."','".$content."', '".$start_date."','".$end_date."')"; + $sql = "INSERT INTO ".$TABLEAGENDA." (title,content, start_date, end_date) + VALUES ('".$title."','".$content."', '".$start_date."','".$end_date."')"; $result = Database::query($sql) or die (Database::error()); $last_id=Database::insert_id(); @@ -482,8 +469,6 @@ function display_courseadmin_links() { } function display_student_links() { - - if ($_SESSION['view'] <> 'month') { echo ''. Display::return_icon('month_empty.png',get_lang('MonthView'),'','32').''; @@ -493,8 +478,7 @@ function display_student_links() { else { echo ' '.Display::return_icon('calendar_inverse.png',get_lang('AgendaSortChronologicallyDown'),'','32').''; } - } - else { + } else { echo ''.Display::return_icon('appointments.png', get_lang('ListView'),'','32').''; } @@ -561,23 +545,27 @@ function store_edited_agenda_item() { * This function stores the Agenda Item in the table calendar_event and updates the item_property table also (after an edit) * @author: Patrick Cool , Ghent University */ -function save_edit_agenda_item($id,$title,$content,$start_date,$end_date) -{ +function save_edit_agenda_item($id, $title, $content, $start_date, $end_date) { $TABLEAGENDA = Database::get_main_table(TABLE_MAIN_SYSTEM_CALENDAR); $id=Database::escape_string($id); $title=Database::escape_string($title); $content=Database::escape_string($content); - $start_date=Database::escape_string($start_date); - $end_date=Database::escape_string($end_date); + + $start_date = api_get_utc_datetime($start_date); + $start_date = Database::escape_string($start_date); + + $end_date = api_get_utc_datetime($end_date); + $end_date = Database::escape_string($end_date); + // store the modifications in the table calendar_event $sql = "UPDATE ".$TABLEAGENDA." - SET title='".$title."', - content='".$content."', - start_date='".$start_date."', - end_date='".$end_date."' - WHERE id='".$id."'"; + SET title='".$title."', + content='".$content."', + start_date='".$start_date."', + end_date='".$end_date."' + WHERE id='".$id."'"; $result = Database::query($sql) or die (Database::error()); return true; } @@ -636,8 +624,7 @@ function showhide_agenda_item($id) { * @author Patrick Cool , Ghent University * @author Yannick Warnier - cleanup */ -function display_agenda_items() -{ +function display_agenda_items() { global $select_month, $select_year; global $DaysShort, $DaysLong, $MonthsLong; global $is_courseAdmin; @@ -723,17 +710,13 @@ function display_agenda_items() $export_icon_low = 'export_low_fade.png'; $export_icon_high = 'export_high_fade.png'; - while($myrow=Database::fetch_array($result)) - { + while($myrow=Database::fetch_array($result)) { $is_repeated = !empty($myrow['parent_event_id']); - echo '',""; - /*-------------------------------------------------- - display: the month bar - --------------------------------------------------*/ + echo '
'; - $myrow["start_date"] = api_get_local_time($myrow["start_date"], null, date_default_timezone_get()); - if ($month_bar != api_format_date($myrow["start_date"], "%m%Y")) - { + $myrow["start_date"] = api_get_local_time($myrow["start_date"]); + + if ($month_bar != api_format_date($myrow["start_date"], "%m%Y")) { $month_bar = api_format_date($myrow["start_date"], "%m%Y"); echo "'; // highlight: if a date in the small calendar is clicked we highlight the relevant items + $db_date = (int)api_format_date($myrow["start_date"], "%d").intval(api_format_date($myrow["start_date"], "%m")).api_format_date($myrow["start_date"], "%Y"); - if ($_GET["day"].$_GET["month"].$_GET["year"] <>$db_date) - { - if ($myrow['visibility']=='0') - { + if ($_GET["day"].$_GET["month"].$_GET["year"] <>$db_date) { + if ($myrow['visibility']=='0') { $style="data_hidden"; $stylenotbold="datanotbold_hidden"; $text_style="text_hidden"; - } - else - { + } else { $style="data"; $stylenotbold="datanotbold"; $text_style="text"; } - - } - else - { + } else { $style="datanow"; $stylenotbold="datanotboldnow"; $text_style="textnow"; @@ -790,8 +767,7 @@ function display_agenda_items() // echo $sent_to_form; echo ""; - if (!$is_repeated && (api_is_allowed_to_edit(false,true) OR (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous()))) - { + if (!$is_repeated && (api_is_allowed_to_edit(false,true) OR (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous()))) { if( ! (api_is_course_coach() && !api_is_element_in_the_session(TOOL_AGENDA, $myrow['id'] ) ) ) { // a coach can only delete an element belonging to his session echo '"; - echo ""; echo ""; - - // attachment list - //$attachment_list=get_attachment($myrow['id']); - - /*-------------------------------------------------- - display: edit delete button (course admin only) - --------------------------------------------------*/ - - - if (!$is_repeated && (api_is_allowed_to_edit(false,true) OR (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous()))) - { + + if (!$is_repeated && (api_is_allowed_to_edit(false,true) OR (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous()))) { if( ! (api_is_course_coach() && !api_is_element_in_the_session(TOOL_AGENDA, $myrow['id'] ) ) ) { // a coach can only delete an element belonging to his session $mylink = api_get_self().'?'.api_get_cidreq().'&origin='.Security::remove_XSS($_GET['origin']).'&id='.$myrow['id']; @@ -836,19 +801,14 @@ function display_agenda_items() echo Display::return_icon('delete.gif', get_lang('Delete')).""; } - if (!$is_repeated && (api_is_allowed_to_edit(false,true) OR (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous()))) - { - if( ! (api_is_course_coach() && !api_is_element_in_the_session(TOOL_AGENDA, $myrow['id'] ) ) ) - { // a coach can only delete an element belonging to his session + if (!$is_repeated && (api_is_allowed_to_edit(false,true) OR (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous()))) { + if( ! (api_is_course_coach() && !api_is_element_in_the_session(TOOL_AGENDA, $myrow['id'] ) ) ) { + // a coach can only delete an element belonging to his session $td_colspan= '
". api_format_date($myrow["start_date"], "%B %Y"). @@ -746,25 +729,19 @@ function display_agenda_items() echo '
'.get_lang('Actions'); @@ -799,31 +775,20 @@ function display_agenda_items() } } - /*-------------------------------------------------- - display: the title - --------------------------------------------------*/ + // display: the title echo "
".get_lang("StartTimeWindow").": "; - echo api_format_date($myrow["start_date"]); + echo "".get_lang("StartTimeWindow").": "; + echo api_format_date($myrow["start_date"], DATE_TIME_FORMAT_LONG); echo ""; - if ($myrow["end_date"]<>"0000-00-00 00:00:00") - { + if ($myrow["end_date"]<>"0000-00-00 00:00:00") { + $myrow["end_date"] = api_get_local_time($myrow["end_date"]); echo get_lang("EndTimeWindow").": "; - echo api_convert_and_format_date($myrow["end_date"], null, date_default_timezone_get()); + echo api_format_date($myrow["end_date"], DATE_TIME_FORMAT_LONG); } echo "'; - } - else - { + } else { $td_colspan= ''; } - } - else - { + } else { $td_colspan= ''; } $mylink = 'calendar_ical_export.php?'.api_get_cidreq().'&type=course&id='.$myrow['id']; @@ -1210,8 +1170,7 @@ function show_add_form($id = '') $htmlHeadXtra[] = to_javascript(); // the default values for the forms - if ($_GET['originalresource'] !== 'no') - { + if ($_GET['originalresource'] !== 'no') { $day = date('d'); $month = date('m'); $year = date('Y'); @@ -1224,9 +1183,7 @@ function show_add_form($id = '') $end_hours = 17; $end_minutes= '00'; $repeat = false; - } - else - { + } else { // we are coming from the resource linker so there might already have been some information in the form. // When we clicked on the button to add resources we stored every form information into a session and now we @@ -1252,8 +1209,7 @@ function show_add_form($id = '') // switching the send to all/send to groups/send to users - if ($_POST['To']) - { + if ($_POST['To']) { $day = $_POST['fday']; $month = $_POST['fmonth']; $year = $_POST['fyear']; @@ -1274,17 +1230,22 @@ function show_add_form($id = '') // if the id is set then we are editing an agenda item - if (is_int($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']); + // 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); @@ -1710,7 +1671,7 @@ function display_upcoming_events() { $counter = 0; while ($item = Database::fetch_array($result,'ASSOC')) { if ($counter < $number_of_items_to_show) { - echo $item['start_date'],' - ',$item['title'],'
'; + echo api_get_local_time($item['start_date']),' - ',$item['title'],'
'; $counter++; } } @@ -2847,10 +2808,15 @@ function agenda_add_item($course_info, $title, $content, $db_start_date, $db_end // some filtering of the input data $title = Database::escape_string($title); // no html allowed in the title $content = Database::escape_string($content); + + $db_start_date = api_get_utc_datetime($db_start_date); $start_date = Database::escape_string($db_start_date); - $end_date = Database::escape_string($db_end_date); + + $db_end_date = api_get_utc_datetime($db_end_date); + $end_date = Database::escape_string($db_end_date); + - isset($_SESSION['id_session'])?$id_session=intval($_SESSION['id_session']):$id_session=null; + isset($_SESSION['id_session'])?$id_session=intval($_SESSION['id_session']):$id_session=null; // store in the table calendar_event // check if exists in calendar_event table diff --git a/main/admin/calendar.php b/main/admin/calendar.php index bf48c1632a..ad2c90d1e8 100755 --- a/main/admin/calendar.php +++ b/main/admin/calendar.php @@ -29,15 +29,14 @@ $tool_name= get_lang('SubscribeCoursesToSession'); $id_session=intval($_GET['id_session']); -if(!api_is_platform_admin()) -{ +if (!api_is_platform_admin()) { $sql = 'SELECT session_admin_id FROM '.Database :: get_main_table(TABLE_MAIN_SESSION).' WHERE id='.$id_session; $rs = Database::query($sql); - if(Database::result($rs,0,0)!=$_user['user_id']) - { + if(Database::result($rs,0,0)!= api_get_user_id()) { api_not_allowed(true); } } + /* Libraries */ @@ -153,33 +152,26 @@ echo ""; //setting the default year and month $select_year = ''; $select_month = ''; -if(!empty($_GET['year'])) -{ +if(!empty($_GET['year'])) { $select_year = (int)$_GET['year']; } -if(!empty($_GET['month'])) -{ +if(!empty($_GET['month'])) { $select_month = (int)$_GET['month']; } -if (empty($select_year) && empty($select_month)) -{ +if (empty($select_year) && empty($select_month)) { $today = getdate(); $select_year = $today['year']; $select_month = $today['mon']; } echo '
'; -if (api_is_allowed_to_edit(false,true) OR (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous())) -{ +if (api_is_allowed_to_edit(false,true) OR (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous())) { display_student_links(); display_courseadmin_links(); } echo '


'; - - -echo '' - . ''; +echo '
'; // THE LEFT PART if (empty($_GET['origin']) or $_GET['origin']!='learnpath') { @@ -204,28 +196,27 @@ echo '
'; echo '
'; if (api_is_allowed_to_edit(false,true)) { - switch ($_GET['action']) - { + switch ($_GET['action']) { case "add": if(!empty($_POST['ical_submit'])) { $course_info = api_get_course_info(); - agenda_import_ical($course_info,$_FILES['ical_import']); + agenda_import_ical($course_info, $_FILES['ical_import']); display_agenda_items(); } elseif ($_POST['submit_event']) { - $course_info = api_get_course_info(); + $course_info = api_get_course_info(); $event_start = (int) $_POST['fyear'].'-'.(int) $_POST['fmonth'].'-'.(int) $_POST['fday'].' '.(int) $_POST['fhour'].':'.(int) $_POST['fminute'].':00'; $event_stop = (int) $_POST['end_fyear'].'-'.(int) $_POST['end_fmonth'].'-'.(int) $_POST['end_fday'].' '.(int) $_POST['end_fhour'].':'.(int) $_POST['end_fminute'].':00'; - + $id = agenda_add_item($course_info,$_POST['title'],$_POST['content'],$event_start,$event_stop,$_POST['selectedform'],false,$_POST['file_comment']); - +/* if(!empty($_POST['repeat'])) { $end_y = intval($_POST['repeat_end_year']); $end_m = intval($_POST['repeat_end_month']); $end_d = intval($_POST['repeat_end_day']); $end = mktime(23, 59, 59, $end_m, $end_d, $end_y); $res = agenda_add_repeat_item($course_info,$id,$_POST['repeat_type'],$end,null,$_POST['file_comment']); - } + }*/ display_agenda_items(); } else { show_add_form(); @@ -235,14 +226,14 @@ if (api_is_allowed_to_edit(false,true)) { case "edit": if( ! (api_is_course_coach() && !api_is_element_in_the_session(TOOL_AGENDA, intval($_REQUEST['id']) ) ) ) { // a coach can only delete an element belonging to his session - if ($_POST['submit_event']) - { $my_id_attach = (int)$_REQUEST['id_attach']; - $my_file_comment = Database::escape_string($_REQUEST['file_comment']); - store_edited_agenda_item($my_id_attach,$my_file_comment); - display_agenda_items(); + if ($_POST['submit_event']) { + $my_id_attach = (int)$_REQUEST['id_attach']; + $my_file_comment = Database::escape_string($_REQUEST['file_comment']); + store_edited_agenda_item($my_id_attach,$my_file_comment); + display_agenda_items(); } else { - $id=(int)$_GET['id']; - show_add_form($id); + $id=(int)$_GET['id']; + show_add_form($id); } } else { display_agenda_items(); @@ -296,28 +287,18 @@ if (api_is_allowed_to_edit(false,true)) { } // this is for students and whenever the courseaministrator has not chosen any action. It is in fact the default behaviour -if (!$_GET['action'] OR $_GET['action']=="showall" OR $_GET['action']=="showcurrent" OR $_GET['action']=="view") -{ - if ($_GET['origin'] != 'learnpath') - { - if (!$_SESSION['view'] OR $_SESSION['view'] <> 'month') - { - if(!empty($_GET['agenda_id'])) - { +if (!$_GET['action'] OR $_GET['action']=="showall" OR $_GET['action']=="showcurrent" OR $_GET['action']=="view") { + if ($_GET['origin'] != 'learnpath') { + if (!$_SESSION['view'] OR $_SESSION['view'] <> 'month') { + if(!empty($_GET['agenda_id'])) { display_one_agenda_item((int)$_GET['agenda_id']); - } - else - { + } else { display_agenda_items(); } - } - else - { + } else { display_monthcalendar($select_month, $select_year); } - } - else - { + } else { display_one_agenda_item((int)$_GET['agenda_id']); } } @@ -329,5 +310,4 @@ echo " 
"; // The footer is displayed only if we are not in the learnpath if ($_GET['origin'] != 'learnpath') { Display::display_footer(); -} -?> \ No newline at end of file +} \ No newline at end of file