From 8694ff7c0307075b91c4a2653c8dfaf6a4b0e2a0 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Mon, 30 Mar 2015 14:10:25 +0200 Subject: [PATCH] Remove unused calendar code. --- main/admin/calendar.lib.php | 2543 -------------- main/admin/calendar.php | 283 -- main/admin/calendar_ical_export.php | 133 - main/admin/user_list.php | 23 +- main/calendar/agenda.inc.php | 3851 --------------------- main/calendar/agenda.php | 2 +- main/calendar/agenda_js.php | 1 - main/calendar/agenda_list.php | 1 - main/calendar/allagendas.php | 379 -- main/calendar/download.php | 2 - main/calendar/myagenda.inc.php | 789 ----- main/calendar/myagenda.php | 251 -- main/inc/ajax/agenda.ajax.php | 12 +- main/inc/lib/agenda.lib.php | 634 ++++ main/inc/lib/system_announcements.lib.php | 15 +- main/webservices/user_info.soap.php | 3 +- main/work/work.lib.php | 1 - tests/main/admin/calendar.lib.test.php | 247 -- tests/test_manager.inc.php | 1 - 19 files changed, 656 insertions(+), 8515 deletions(-) delete mode 100755 main/admin/calendar.lib.php delete mode 100755 main/admin/calendar.php delete mode 100755 main/admin/calendar_ical_export.php delete mode 100755 main/calendar/agenda.inc.php delete mode 100755 main/calendar/allagendas.php delete mode 100755 main/calendar/myagenda.inc.php delete mode 100755 main/calendar/myagenda.php diff --git a/main/admin/calendar.lib.php b/main/admin/calendar.lib.php deleted file mode 100755 index 3f8027e4b3..0000000000 --- a/main/admin/calendar.lib.php +++ /dev/null @@ -1,2543 +0,0 @@ -, Ghent University -* @author Yannick Warnier - cleanup -* @param integer $month: the integer value of the month we are viewing -* @param integer $year: the 4-digit year indication e.g. 2005 -* @return array -*/ - -/** -* show the mini calender of the given month -* @author Patrick Cool , Ghent University -* @param array an array containing all the agenda items for the given month -* @param integer $month: the integer value of the month we are viewing -* @param integer $year: the 4-digit year indication e.g. 2005 -* @param string $monthName: the language variable for the mont name -* @return html code -* @todo refactor this so that $monthName is no longer needed as a parameter -*/ -function display_minimonthcalendar($agendaitems, $month, $year, $monthName) { - global $DaysShort; - //Handle leap year - $numberofdays = array (0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); - if (($year % 400 == 0) or ($year % 4 == 0 and $year % 100 <> 0)) - $numberofdays[2] = 29; - //Get the first day of the month - $dayone = getdate(mktime(0, 0, 0, $month, 1, $year)); - //Start the week on monday - $startdayofweek = $dayone['wday'] <> 0 ? ($dayone['wday'] - 1) : 6; - $backwardsURL = api_get_self()."?".api_get_cidreq()."&coursePath=".(empty($_GET['coursePath'])?'':$_GET['coursePath'])."&courseCode=".(empty($_GET['courseCode'])?'':$_GET['courseCode'])."&month=". ($month == 1 ? 12 : $month -1)."&year=". ($month == 1 ? $year -1 : $year); - $forewardsURL = api_get_self()."?".api_get_cidreq()."&coursePath=".(empty($_GET['coursePath'])?'':$_GET['coursePath'])."&courseCode=".(empty($_GET['courseCode'])?'':$_GET['courseCode'])."&month=". ($month == 12 ? 1 : $month +1)."&year=". ($month == 12 ? $year +1 : $year); - - echo "", - "", - "", - "", - "", ""; - echo ""; - for ($ii = 1; $ii < 8; $ii ++) - { - echo ""; - } - echo ""; - $curday = -1; - $today = getdate(); - while ($curday <= $numberofdays[$month]) - { - echo ""; - for ($ii = 0; $ii < 7; $ii ++) - { - if (($curday == -1) && ($ii == $startdayofweek)) - { - $curday = 1; - } - if (($curday > 0) && ($curday <= $numberofdays[$month])) - { - $bgcolor = $ii < 5 ? $class="class=\"days_week\"" : $class="class=\"days_weekend\""; - $dayheader = "$curday"; - if (($curday == $today['mday']) && ($year == $today['year']) && ($month == $today['mon'])) - { - $dayheader = "$curday"; - $class = "class=\"days_today\""; - } - echo ""; - $curday ++; - } - else - { - echo ""; - } - } - echo ""; - } - echo "
".Display::return_icon('action_prev.png',get_lang('Previous'))." ", $monthName, " ", $year, " ".Display::return_icon('action_next.png',get_lang('Next'))."
", $DaysShort[$ii % 7], "
"; - if (!empty($agendaitems[$curday])) - { - echo "".$dayheader.""; - } - else - { - echo $dayheader; - } - // "a".$dayheader." ".$agendaitems[$curday].""; - echo " 
"; -} -/** -* show the calender of the given month -* @author Patrick Cool , Ghent University -* @param integer $month: the integer value of the month we are viewing -* @param integer $year: the 4-digit year indication e.g. 2005 -* @return html code -*/ -/** -* returns all the javascript that is required for easily selecting the target people/groups this goes into the $htmlHeadXtra[] array -* @author Patrick Cool , Ghent University -* @return javascript code -*/ -function to_javascript() { - $Send2All=get_lang("Send2All"); - return ""; -} - - - -/** -* returns the javascript for setting a filter. This is a jump menu -* @author Patrick Cool , Ghent University -* @return javascript code -*/ -function user_group_filter_javascript() { - return " - "; -} - -function display_monthcalendar($month, $year) { - global $MonthsLong; - global $DaysShort; - global $origin; - - // grabbing all the calendar items for this year and storing it in a array - $data=get_calendar_items($month,$year); - - - //Handle leap year - $numberofdays = array(0,31,28,31,30,31,30,31,31,30,31,30,31); - if (($year%400 == 0) or ($year%4==0 and $year%100<>0)) $numberofdays[2] = 29; - - //Get the first day of the month - $dayone = getdate(mktime(0,0,0,$month,1,$year)); - //Start the week on monday - $startdayofweek = $dayone['wday']<>0 ? ($dayone['wday']-1) : 6; - - $backwardsURL = api_get_self()."?".api_get_cidreq()."&origin=$origin&month=".($month==1 ? 12 : $month-1)."&year=".($month==1 ? $year-1 : $year); - $forewardsURL = api_get_self()."?".api_get_cidreq()."&origin=$origin&month=".($month==12 ? 1 : $month+1)."&year=".($month==12 ? $year+1 : $year); - - $maand_array_maandnummer=$month-1; - - echo "", - "", - "", - "", - "", - ""; - - echo ""; - - for ($ii=1;$ii<8; $ii++) { - echo ""; - } - - echo ""; - $curday = -1; - $today = getdate(); - while ($curday <=$numberofdays[$month]) { - echo ""; - for ($ii=0; $ii<7; $ii++) { - if (($curday == -1)&&($ii==$startdayofweek)) { - $curday = 1; - } - if (($curday>0)&&($curday<=$numberofdays[$month])) { - $bgcolor = $ii<5 ? "class=\"row_odd\"" : "class=\"row_even\""; - - $dayheader = "$curday"; - if (array_key_exists($curday,$data)) { - $dayheader="".$curday.""; - 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 ""; - - $curday++; - } else { - echo ""; - } - } - echo ""; - } - echo "
".Display::return_icon('action_prev.png',get_lang('Previous'))."",$MonthsLong[$maand_array_maandnummer]," ",$year," ".Display::return_icon('action_next.png',get_lang('Next'))."
",$DaysShort[$ii%7],"
".$dayheader." "; - } else { - echo "".$dayheader." "; - } - echo " 
"; -} -/** -* this function shows the form with the user that were not selected -* @author Patrick Cool , Ghent University -* @return html code -*/ -/** -* This function stores the Agenda Item in the table calendar_event and updates the item_property table also -* @author Patrick Cool , Ghent University -* @return integer the id of the last added agenda item -*/ -function store_new_agenda_item() { - - $TABLEAGENDA = Database::get_main_table(TABLE_MAIN_SYSTEM_CALENDAR); - //$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"; - - // store in the table calendar_event - $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(); - - // store in last_tooledit (first the groups, then the users - $to=$_POST['selectedform']; - /* 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); - // storing the selected groups - if (is_array($send_to['groups'])) - { - foreach ($send_to['groups'] as $group) - { - api_item_property_update($_course, TOOL_CALENDAR_EVENT, $last_id,"AgendaAdded", $_user['user_id'], $group,'',$start_date, $end_date); - } - } - // storing the selected users - if (is_array($send_to['users'])) - { - foreach ($send_to['users'] as $user) - { - api_item_property_update($_course, TOOL_CALENDAR_EVENT, $last_id,"AgendaAdded", $_user['user_id'],'',$user, $start_date,$end_date); - } - } - } - else // the message is sent to everyone, so we set the group to 0 - { - api_item_property_update($_course, TOOL_CALENDAR_EVENT, $last_id,"AgendaAdded", $_user['user_id'], '','',$start_date,$end_date); - }*/ - -// storing the resources - //store_resources($_SESSION['source_type'],$last_id); - - //if repetitive, insert element into agenda_repeat table -/* if(!empty($_POST['repeat']) && !empty($_POST['repeat_type'])) - { - if(!empty($_POST['repeat_end_year']) && !empty($_POST['repeat_end_month']) && !empty($_POST['repeat_end_day'])) - { - $end_y = intval($_POST['repeat_end_year']); - $end_m = intval($_POST['repeat_end_month']); - $end_d = intval($_POST['repeat_end_day']); - $end = mktime((int)$_POST['fhour'],(int)$_POST['fminute'],0,$end_m,$end_d,$end_y); - $now = time(); - $type = Database::escape_string($_POST['repeat_type']); - - if($end > $now - && in_array($type,array('daily','weekly','monthlyByDate','monthlyByDay','monthlyByDayR','yearly'))) - { - $sql = "INSERT INTO $t_agenda_repeat (cal_id, cal_type, cal_end)" . - " VALUES ($last_id,'$type',$end)"; - $res = Database::query($sql); - } - } - } - return $last_id;*/ - return $last_id; -} - -function display_student_links() { - if ($_SESSION['view'] <> 'month') { - echo ''. - Display::return_icon('month_empty.png',get_lang('MonthView'),'',ICON_SIZE_MEDIUM).''; - if ($_SESSION['sort'] == 'DESC') { - echo ''.Display::return_icon('calendar_normal.png',get_lang('AgendaSortChronologicallyUp'),'',ICON_SIZE_MEDIUM).''; - } else { - //echo ' '.Display::return_icon('calendar_inverse.png',get_lang('AgendaSortChronologicallyDown'),'',ICON_SIZE_MEDIUM).''; - } - } else { - echo ''.Display::return_icon('week.png', get_lang('ListView'),'',ICON_SIZE_MEDIUM).''; - - } -} -/** -* get all the information of the agenda_item from the database -* @author Patrick Cool , Ghent University -* @param integer the id of the agenda item we are getting all the information of -* @return an associative array that contains all the information of the agenda item. The keys are the database fields -*/ -function get_agenda_item($id) { - $TABLEAGENDA = Database::get_main_table(TABLE_MAIN_SYSTEM_CALENDAR); - //$t_agenda_repeat = Database::get_course_table(TABLE_AGENDA_REPEAT); - $item = array(); - if(empty($id)) { - $id=intval($_GET['id']); - } else { - $id = intval($id); - } - if(empty($id)){return $item;} - $sql = "SELECT * FROM ".$TABLEAGENDA." WHERE id='".$id."'"; - $result = Database::query($sql); - $entry_to_edit = Database::fetch_array($result); - $item['title'] = $entry_to_edit["title"]; - $item['content'] = $entry_to_edit["content"]; - $item['start_date'] = $entry_to_edit["start_date"]; - $item['end_date'] = $entry_to_edit["end_date"]; - $item['to'] == "everyone"; - // if the item has been sent to everybody then we show the compact to form - if ($item['to']=="everyone") { - $_SESSION['allow_individual_calendar']="hide"; - } else { - $_SESSION['allow_individual_calendar']="show"; - } - - return $item; -} -/** -* This is the function that updates an agenda item. It does 3 things -* 1. storethe start_date, end_date, title and message in the calendar_event table -* 2. store the groups/users who this message is meant for in the item_property table -* 3. modify the attachments (if needed) -* @author Patrick Cool , Ghent University -*/ -function store_edited_agenda_item() { - - // STEP 1: editing the calendar_event table - // 1.a. some filtering of the input data - $id=(int)$_POST['id']; - $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"; - $to=$_POST['selectedform']; - // 1.b. the actual saving in calendar_event table - $edit_result=save_edit_agenda_item($id,$title,$content,$start_date,$end_date); - - echo '
'; - Display::display_normal_message(get_lang("EditSuccess")); - -} - -/** -* 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) { - $TABLEAGENDA = Database::get_main_table(TABLE_MAIN_SYSTEM_CALENDAR); - - $id=intval($id); - $title=Database::escape_string($title); - $content=Database::escape_string($content); - - $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."'"; - $result = Database::query($sql) or die (Database::error()); - return true; -} - -/** -* This is the function that deletes an agenda item. -* The agenda item is no longer fycically deleted but the visibility in the item_property table is set to 2 -* which means that it is invisible for the student AND course admin. Only the platform administrator can see it. -* This will in a later stage allow the platform administrator to recover resources that were mistakenly deleted -* by the course administrator -* @author Patrick Cool , Ghent University -* @param integer the id of the agenda item wa are deleting -* @return bool true if it's success or false otherwise -*/ -function delete_agenda_item($id) -{ - global $_course; - - $t_agenda = Database::get_main_table(TABLE_MAIN_SYSTEM_CALENDAR); - $id = intval($id); - $sql = "SELECT * FROM $t_agenda WHERE id = '$id'"; - $res = Database::query($sql); - if(Database::num_rows($res) > 0) - { - $sql = "DELETE FROM ".$t_agenda." WHERE id='$id'"; - $result = Database::query($sql) or die (Database::error()); - api_item_property_update($_course,TOOL_CALENDAR_EVENT,$id,'delete',api_get_user_id()); - return true; - } - return false; -} -/** -* Makes an agenda item visible or invisible for a student -* @author Patrick Cool , Ghent University -* @param integer id the id of the agenda item we are changing the visibility of -*/ -function showhide_agenda_item($id) { - global $nameTools; - /*================================================== - SHOW / HIDE A CALENDAR ITEM - ==================================================*/ - // and $_GET['isStudentView']<>"false" is added to prevent that the visibility is changed after you do the following: - // change visibility -> studentview -> course manager view - if ((api_is_allowed_to_edit() && !api_is_anonymous()) and $_GET['isStudentView']<>"false") - { - if (isset($_GET['id'])&&$_GET['id']&&isset($_GET['action'])&&$_GET['action']=="showhide") - { - $id=(int)addslashes($_GET['id']); - change_visibility($nameTools,$id); - Display::display_normal_message(get_lang("VisibilityChanged")); - } - } -} -/** -* Displays all the agenda items -* @author Patrick Cool , Ghent University -* @author Yannick Warnier - cleanup -*/ -function display_agenda_items() { - global $select_month, $select_year; - global $DaysShort, $DaysLong, $MonthsLong; - global $is_courseAdmin; - global $dateFormatLong, $timeNoSecFormat,$charset, $_user, $_course; - - $TABLEAGENDA = Database::get_main_table(TABLE_MAIN_SYSTEM_CALENDAR); - - // getting the group memberships - //$group_memberships=GroupManager::get_group_ids($_course['dbName'],$_user['user_id']); - - // getting the name of the groups - //$group_names=get_course_groups(); - - /*-------------------------------------------------- - CONSTRUCT THE SQL STATEMENT - --------------------------------------------------*/ - - $start = 0; - $stop = 0; - // this is to make a difference between showing everything (all months) or only the current month) - // $show_all_current is a part of the sql statement - if ($_SESSION['show_all_admin']!=="showall") - { - $show_all_current=" AND MONTH(start_date)=$select_month AND year(start_date)=$select_year"; - $start = mktime(0,0,0,$select_month,1,$select_year); - $stop = 0; - if(empty($select_year)){$select_year = date('Y');} - if(empty($select_month)){$select_month = date('m');} - if($select_month==12) - { - $stop = mktime(0,0,0,1,1,$select_year+1)-1; - } - else - { - $stop = mktime(0,0,0,$select_month+1,1,$select_year)-1; - } - } - else - { - $show_all_current=""; - $start = time(); - $stop = mktime(0,0,0,1,1,2038);//by default, set year to maximum for mktime() - } - - // by default we use the id of the current user. The course administrator can see the agenda of other users by using the user / group filter - - $repeats = array(); //placeholder for repeated events - - if (api_is_allowed_to_edit() && !api_is_anonymous()) { - $sql="SELECT * FROM ".$TABLEAGENDA; - - global $_configuration; - $current_access_url_id = 1; - if ($_configuration['multiple_access_urls']) { - $current_access_url_id = api_get_current_access_url_id(); - } - $sql .= " WHERE access_url_id = $current_access_url_id"; - $sql .= ' ORDER BY start_date '.$_SESSION['sort']; - //echo "
".$sql."
"; - $result=Database::query($sql) or die(Database::error()); - $number_items=Database::num_rows($result); - } else { - $number_items = 0; - } - - - /*-------------------------------------------------- - DISPLAY: NO ITEMS - --------------------------------------------------*/ - if ($number_items==0) - { - echo "
".get_lang("NoAgendaItems")."
"; - } - - /*-------------------------------------------------- - DISPLAY: THE ITEMS - --------------------------------------------------*/ - - $month_bar=""; - $event_list=""; - $counter=0; - $export_icon = 'export.png'; - $export_icon_low = 'export_low_fade.png'; - $export_icon_high = 'export_high_fade.png'; - - while($myrow=Database::fetch_array($result)) { - $is_repeated = !empty($myrow['parent_event_id']); - echo ''; - - $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 ""; - } - - /*-------------------------------------------------- - display: the icon, title, destinees of the item - -------------------------------------------------*/ - 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') { - $style="data_hidden"; - $stylenotbold="datanotbold_hidden"; - $text_style="text_hidden"; - } else { - $style="data"; - $stylenotbold="datanotbold"; - $text_style="text"; - } - } else { - $style="datanow"; - $stylenotbold="datanotboldnow"; - $text_style="textnow"; - } - - echo ""; - - // the message has been sent to - echo ""; - - 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 ''; - } - } - - // display: the title - echo ""; - echo ""; - echo ""; - - 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']; - echo ''; - echo ''; - } - - /*-------------------------------------------------- - display: the content - --------------------------------------------------*/ - $content = $myrow['content']; - $content = make_clickable($content); - echo ""; - echo "'; - - - /*-------------------------------------------------- - display: the added resources - -------------------------------------------------- - if (check_added_resources("Agenda", $myrow["id"])) - { - - echo ''; - echo '"; - }*/ - - - $event_list.=$myrow['id'].','; - - $counter++; - /*-------------------------------------------------- - display: jump-to-top icon - --------------------------------------------------*/ - echo ''; - echo '"; - echo "
". - api_format_date($myrow["start_date"], "%B %Y"). - "
"; - // adding an internal anchor - echo ""; - // the icons. If the message is sent to one or more specific users/groups - // we add the groups icon - // 2do: if it is sent to groups we display the group icon, if it is sent to a user we show the user icon - Display::display_icon('platform_event.png', get_lang('GlobalEvent'),'',ICON_SIZE_SMALL); - /*if ($myrow['to_group_id']!=='0') { - echo Display::return_icon('group.gif', get_lang('AllUsersOfThePlatform')); - }*/ - echo " ".$myrow['title'].""; - echo "".get_lang("SentTo").": ".get_lang('AllUsersOfThePlatform'); - //$sent_to=sent_to(TOOL_CALENDAR_EVENT, $myrow["ref"]); - //$sent_to_form=sent_to_form($sent_to); - // echo $sent_to_form; - echo "'.get_lang('Actions'); - 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") { - $myrow["end_date"] = api_get_local_time($myrow["end_date"]); - echo get_lang("EndTimeWindow").": "; - echo api_format_date($myrow["end_date"], DATE_TIME_FORMAT_LONG); - } - echo "'; - // edit - echo ''; - echo Display::return_icon('edit.gif', get_lang('ModifyCalendarItem')).""; - - echo " "; - 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 - $td_colspan= ''; - } else { - $td_colspan= ''; - } - } else { - $td_colspan= ''; - } - $mylink = 'calendar_ical_export.php?'.api_get_cidreq().'&type=course&id='.$myrow['id']; - echo ''.Display::return_icon($export_icon_high, get_lang('ExportiCalConfidential')).' '; - echo ''.Display::return_icon($export_icon_low, get_lang('ExportiCalPrivate')).' '; - echo ''.Display::return_icon($export_icon, get_lang('ExportiCalPublic')).' '; - echo ''.Display::return_icon('print.gif', get_lang('Print')).' '; - echo '
"; - - echo $content; - // show attachment list - if (!empty($attachment_list)) { - - $realname=$attachment_list['path']; - $user_filename=$attachment_list['filename']; - $full_file_name = 'download.php?file='.$realname; - echo Display::return_icon('attachment.gif',get_lang('Attachment')); - echo ' '.$user_filename.' '; - echo ''.$attachment_list['comment'].''; - if (api_is_allowed_to_edit()) { - echo '  '.Display::return_icon('delete.gif',get_lang('Delete')).'
'; - } - - } - - echo '
'; - echo "".get_lang("AddedResources")."
"; - if ($myrow['visibility']==0) - { - $addedresource_style="invisible"; - } - display_added_resources("Agenda", $myrow["id"], $addedresource_style); - echo "
'; - if($is_repeated){echo get_lang('RepeatedEvent'),'',get_lang('RepeatedEventViewOriginalEvent'),'';} - echo "".Display::return_icon('top.gif', get_lang('Top'))."


"; - } // end while ($myrow=Database::fetch_array($result)) - - if(!empty($event_list)) - { - $event_list=substr($event_list,0,-1); - } - else - { - $event_list='0'; - } - - echo "
"; - - // closing the layout table - echo "", - "", - ""; -} - -/** -* Displays only 1 agenda item. This is used when an agenda item is added to the learning path. -* @author Patrick Cool , Ghent University -*/ -function display_one_agenda_item($agenda_id) -{ - global $select_month, $select_year; - global $DaysShort, $DaysLong, $MonthsLong; - global $is_courseAdmin; - global $dateFormatLong, $timeNoSecFormat, $charset; - global $_user; - - $TABLEAGENDA = Database::get_main_table(TABLE_MAIN_SYSTEM_CALENDAR); - $TABLE_ITEM_PROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY); - - $agenda_id = intval($agenda_id); - //echo "displaying agenda items"; - - // getting the name of the groups - //$group_names=get_course_groups(); - - /*-------------------------------------------------- - CONSTRUCT THE SQL STATEMENT - --------------------------------------------------*/ - - $sql="SELECT * FROM ".$TABLEAGENDA; - $result=Database::query($sql) or die(Database::error()); - $number_items=Database::num_rows($result); - $myrow=Database::fetch_array($result); // there should be only one item so no need for a while loop - - $sql_rep = "SELECT * FROM $TABLEAGENDA WHERE id = $agenda_id"; - $res_rep = Database::query($sql_rep); - $repeat = false; - $repeat_id = 0; - if(Database::num_rows($res_rep)>0) - { - $repeat=true; - $row_rep = Database::fetch_array($res_rep); - //$repeat_id = $row_rep['parent_event_id']; - } - - /*-------------------------------------------------- - DISPLAY: NO ITEMS - --------------------------------------------------*/ - if ($number_items==0) - { - echo "
".get_lang("NoAgendaItems")."
"; - } - - /*-------------------------------------------------- - DISPLAY: THE ITEMS - --------------------------------------------------*/ - echo ""; - - /*-------------------------------------------------- - DISPLAY : the icon, title, destinees of the item - --------------------------------------------------*/ - echo ""; - - // highlight: if a date in the small calendar is clicked we highlight the relevant items - $myrow["start_date"] = api_get_local_time($myrow["start_date"], null, date_default_timezone_get()); - $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') - { - $style="data_hidden"; - $stylenotbold="datanotbold_hidden"; - $text_style="text_hidden"; - } - else - { - $style="data"; - $stylenotbold="datanotbold"; - $text_style="text"; - } - } - else - { - $style="datanow"; - $stylenotbold="datanotboldnow"; - $text_style="textnow"; - } - - - echo ""; - - // the message has been sent to - echo ""; - - /*-------------------------------------------------- - DISPLAY: the title - --------------------------------------------------*/ - echo ""; - echo ""; - echo ""; - echo ""; - - /*-------------------------------------------------- - DISPLAY: the content - --------------------------------------------------*/ - $export_icon = '../img/export.png'; - $export_icon_low = '../img/export_low_fade.png'; - $export_icon_high = '../img/export_high_fade.png'; - - $content = $myrow['content']; - $content = make_clickable($content); - //echo ""; - echo ""; - echo ''; - - /*-------------------------------------------------- - DISPLAY: the added resources - --------------------------------------------------*/ - /* - if (check_added_resources("Agenda", $myrow["id"])) - { - echo ""; - } - */ - /*-------------------------------------------------- - DISPLAY: edit delete button (course admin only) - --------------------------------------------------*/ - echo '"; - if($repeat) { - echo ''; - echo ''; - echo ''; - } - echo "
"; - - // adding an internal anchor - echo ""; - - // the icons. If the message is sent to one or more specific users/groups - // we add the groups icon - // 2do: if it is sent to groups we display the group icon, if it is sent to a user we show the user icon - echo Display::return_icon('agenda.gif'); - if ($myrow['to_group_id']!=='0') - { - echo Display::return_icon('group.gif'); - } - echo " ".$myrow['title'].""; - echo "".get_lang("SentTo").": ".get_lang('AllUsersOfThePlatform'); - //$sent_to = sent_to(TOOL_CALENDAR_EVENT, $myrow["ref"]); - //sent_to_form=sent_to_form($sent_to); - //echo $sent_to_form; - echo "
".get_lang("StartTime").": "; - echo api_format_date($myrow["start_date"]); - echo "".get_lang("EndTime").": "; - echo api_convert_and_format_date($myrow["end_date"], null, date_default_timezone_get()); - echo "
"; - //echo $content; - //echo "
'; - echo $content; - echo '
"; - echo "".get_lang("AddedResources")."
"; - if ($myrow['visibility']==0) - { - $addedresource_style="invisible"; - } - display_added_resources("Agenda", $myrow["id"], $addedresource_style); - echo "
'; - if (!$repeat && api_is_allowed_to_edit(false,true)) { - // edit - $mylink = api_get_self()."?".api_get_cidreq()."&origin=".Security::remove_XSS($_GET['origin'])."&id=".$myrow['id']; - echo "", - Display::return_icon('edit.gif', get_lang('ModifyCalendarItem')), "", - "", - Display::return_icon('delete.gif', get_lang('Delete')),""; - if ($myrow['visibility']==1) { - $image_visibility="visible"; - } else { - $image_visibility="invisible"; - } - echo '',Display::return_icon($image_visibility, get_lang('Visible')),'

'; - } - $mylink = 'calendar_ical_export.php?'.api_get_cidreq().'&type=course&id='.$myrow['id']; - echo ''.Display::return_icon($export_icon_high, get_lang('ExportiCalConfidential')).' '; - echo ''.Display::return_icon($export_icon_low, get_lang('ExportiCalPrivate')).' '; - echo ''.Display::return_icon($export_icon, get_lang('ExportiCalPublic')).' '; - echo ''.Display::return_icon('print.gif', get_lang('Print')).' '; - echo "
',get_lang('RepeatedEvent'),'',get_lang('RepeatedEventViewOriginalEvent'),'
"; - - // closing the layout table - echo "", - "", - ""; -} -/** - * (This function is probably deprecated for this module) -* Show the form for adding a new agenda item. This is the same function that is used whenever we are editing an -* agenda item. When the id parameter is empty (default behaviour), then we show an empty form, else we are editing and -* we have to retrieve the information that is in the database and use this information in the forms. -* @author Patrick Cool , Ghent University -* @param integer id, the id of the agenda item we are editing. By default this is empty which means that we are adding an -* agenda item. -*/ -function show_group_filter_form() -{ -/** @todo this select missing to implement */ -//$group_list=get_course_groups(); - -echo ""; -} - -function show_user_filter_form() -{ - -/** @todo this select missing to implement */ - -echo ""; -} - -function show_user_group_filter_form() -{ - /** @todo this select missing to implement */ - echo ""; -} - -function display_upcoming_events() { - echo '
'.get_lang('UpcomingEvent').'
'; - $number_of_items_to_show = (int)api_get_setting('number_of_upcoming_events'); - - //databases of the courses - $TABLEAGENDA = Database :: get_main_table(TABLE_MAIN_SYSTEM_CALENDAR); - //$TABLE_ITEMPROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY); - //$mycourse = api_get_course_info(); - //$myuser = api_get_user_info(); - - //$group_memberships = GroupManager :: get_group_ids($mycourse['dbName'], $myuser['user_id']); - // if the user is administrator of that course we show all the agenda items - /*if (api_is_allowed_to_edit()) - {*/ - //echo "course admin"; - $sqlquery = "SELECT DISTINCT * FROM ".$TABLEAGENDA; - - global $_configuration; - $current_access_url_id = 1; - if ($_configuration['multiple_access_urls']) { - $current_access_url_id = api_get_current_access_url_id(); - } - $sqlquery .= "WHERE access_url_id = $current_access_url_id "; - - $sqlquery .= " ORDER BY start_date "; - //} - // if the user is not an administrator of that course - $result = Database::query($sqlquery); - $counter = 0; - while ($item = Database::fetch_array($result,'ASSOC')) { - if ($counter < $number_of_items_to_show) { - echo api_get_local_time($item['start_date']),' - ',$item['title'],'
'; - $counter++; - } - } -} -/** - * This function calculates the startdate of the week (monday) - * and the enddate of the week (sunday) - * and returns it as an array - */ -function calculate_start_end_of_week($week_number, $year) -{ - // determine the start and end date - // step 1: we calculate a timestamp for a day in this week - $random_day_in_week = mktime(0, 0, 0, 1, 1, $year) + ($week_number) * (7 * 24 * 60 * 60); // we calculate a random day in this week - // step 2: we which day this is (0=sunday, 1=monday, ...) - $number_day_in_week = date('w', $random_day_in_week); - // step 3: we calculate the timestamp of the monday of the week we are in - $start_timestamp = $random_day_in_week - (($number_day_in_week -1) * 24 * 60 * 60); - // step 4: we calculate the timestamp of the sunday of the week we are in - $end_timestamp = $random_day_in_week + ((7 - $number_day_in_week +1) * 24 * 60 * 60) - 3600; - // step 5: calculating the start_day, end_day, start_month, end_month, start_year, end_year - $start_day = date('j', $start_timestamp); - $start_month = date('n', $start_timestamp); - $start_year = date('Y', $start_timestamp); - $end_day = date('j', $end_timestamp); - $end_month = date('n', $end_timestamp); - $end_year = date('Y', $end_timestamp); - $start_end_array['start']['day'] = $start_day; - $start_end_array['start']['month'] = $start_month; - $start_end_array['start']['year'] = $start_year; - $start_end_array['end']['day'] = $end_day; - $start_end_array['end']['month'] = $end_month; - $start_end_array['end']['year'] = $end_year; - return $start_end_array; -} -/** - * Show the mini calendar of the given month - */ -function display_daycalendar($agendaitems, $day, $month, $year, $weekdaynames, $monthName) -{ - global $DaysShort, $DaysLong, $course_path; - global $MonthsLong; - global $query; - - // timestamp of today - $today = mktime(); - $nextday = $today + (24 * 60 * 60); - $previousday = $today - (24 * 60 * 60); - // the week number of the year - $week_number = date("W", $today); - // if we moved to the next / previous day we have to recalculate the $today variable - if ($_GET['day']) - { - $today = mktime(0, 0, 0, $month, $day, $year); - $nextday = $today + (24 * 60 * 60); - $previousday = $today - (24 * 60 * 60); - $week_number = date("W", $today); - } - // calculating the start date of the week - // the date of the monday of this week is the timestamp of today minus - // number of days that have already passed this week * 24 hours * 60 minutes * 60 seconds - $current_day = date("j", $today); // Day of the month without leading zeros (1 to 31) of today - $day_of_the_week = date("w", $today); // Numeric representation of the day of the week 0 (for Sunday) through 6 (for Saturday) of today - //$timestamp_first_date_of_week=$today-(($day_of_the_week-1)*24*60*60); // timestamp of the monday of this week - //$timestamp_last_date_of_week=$today+((7-$day_of_the_week)*24*60*60); // timestamp of the sunday of this week - // we are loading all the calendar items of all the courses for today - echo "\n"; - // the forward and backwards url - $backwardsURL = api_get_self()."?coursePath=".urlencode($course_path)."&courseCode=".Security::remove_XSS($_GET['courseCode'])."&action=view&view=day&day=".date("j", $previousday)."&month=".date("n", $previousday)."&year=".date("Y", $previousday); - $forewardsURL = api_get_self()."?coursePath=".urlencode($course_path)."&courseCode=".Security::remove_XSS($_GET['courseCode'])."&action=view&view=day&day=".date("j", $nextday)."&month=".date("n", $nextday)."&year=".date("Y", $nextday); - // The title row containing the day - echo "\n", "\n", ""; - echo "\n"; - echo "\n"; - // the rows for each half an hour - for ($i = 10; $i < 48; $i ++) - { - if ($i % 2 == 0) - { - $class = "class=\"row_even\""; - } - else - { - $class = "class=\"row_odd\""; - } - echo "\n"; - echo ""; - if ($i % 2 == 0) - { - echo ("\n"); - } - else - { - echo ("\n"); - } - echo "\n"; - echo "\n"; - } - echo "
".Display::return_icon('action_prev.png',get_lang('Previous')).""; - echo $DaysLong[$day_of_the_week]." ".date("j", $today)." ".$MonthsLong[date("n", $today) - 1]." ".date("Y", $today); - echo "".Display::return_icon('action_next.png',get_lang('Next'))."
". (($i) / 2)." ".get_lang("HourShort")." 00". ((($i) / 2) - (1 / 2))." ".get_lang("HourShort")." 30\n"; - if (is_array($agendaitems[$i])) - { - foreach ($agendaitems[$i] as $key => $value) - { - echo $value; - } - } - else - { - echo $agendaitems[$i]; - } - echo "
\n"; -} -/** - * Display the weekly view of the calendar - */ -function display_weekcalendar($agendaitems, $month, $year, $weekdaynames, $monthName) -{ - global $DaysShort,$course_path; - global $MonthsLong; - // timestamp of today - $today = time(); - $day_of_the_week = date("w", $today); - $thisday_of_the_week = date("w", $today); - // the week number of the year - $week_number = date("W", $today); - $thisweek_number = $week_number; - // if we moved to the next / previous week we have to recalculate the $today variable - if ($_GET['week']) - { - $today = mktime(0, 0, 0, 1, 1, $year); - $today = $today + (((int)$_GET['week']-1) * (7 * 24 * 60 * 60)); - $week_number = date("W", $today); - } - // calculating the start date of the week - // the date of the monday of this week is the timestamp of today minus - // number of days that have already passed this week * 24 hours * 60 minutes * 60 seconds - $current_day = date("j", $today); // Day of the month without leading zeros (1 to 31) of today - $day_of_the_week = date("w", $today); // Numeric representation of the day of the week 0 (for Sunday) through 6 (for Saturday) of today - $timestamp_first_date_of_week = $today - (($day_of_the_week -1) * 24 * 60 * 60); // timestamp of the monday of this week - $timestamp_last_date_of_week = $today + ((7 - $day_of_the_week) * 24 * 60 * 60); // timestamp of the sunday of this week - $backwardsURL = api_get_self()."?coursePath=".urlencode($course_path)."&courseCode=".Security::remove_XSS($_GET['courseCode'])."&action=view&view=week&week=". ($week_number -1); - $forewardsURL = api_get_self()."?coursePath=".urlencode($course_path)."&courseCode=".Security::remove_XSS($_GET['courseCode'])."&action=view&view=week&week=". ($week_number +1); - echo "\n"; - // The title row containing the the week information (week of the year (startdate of week - enddate of week) - echo "\n"; - echo "\n"; - echo ""; - echo "", ""; - // The second row containing the short names of the days of the week - echo "\n"; - // this is the Day of the month without leading zeros (1 to 31) of the monday of this week - $tmp_timestamp = $timestamp_first_date_of_week; - for ($ii = 1; $ii < 8; $ii ++) - { - $is_today = ($ii == $thisday_of_the_week AND (!isset($_GET['week']) OR $_GET['week']==$thisweek_number)); - echo "\n"; - // we 24 hours * 60 minutes * 60 seconds to the $tmp_timestamp - $array_tmp_timestamp[] = $tmp_timestamp; - $tmp_timestamp = $tmp_timestamp + (24 * 60 * 60); - } - echo "\n"; - // the table cells containing all the entries for that day - echo "\n"; - $counter = 0; - foreach ($array_tmp_timestamp as $key => $value) - { - if ($counter < 5) - { - $class = "class=\"days_week\""; - } - else - { - $class = "class=\"days_weekend\""; - } - if ($counter == $thisday_of_the_week -1 AND (!isset($_GET['week']) OR $_GET['week']==$thisweek_number)) - { - $class = "class=\"days_today\""; - } - - echo "\n"; - $counter ++; - } - echo "\n"; - echo "
".Display::return_icon('action_prev.png',get_lang('Previous'))."".get_lang("Week")." ".$week_number; - echo " (".$DaysShort['1']." ".date("j", $timestamp_first_date_of_week)." ".$MonthsLong[date("n", $timestamp_first_date_of_week) - 1]." ".date("Y", $timestamp_first_date_of_week)." - ".$DaysShort['0']." ".date("j", $timestamp_last_date_of_week)." ".$MonthsLong[date("n", $timestamp_last_date_of_week) - 1]." ".date("Y", $timestamp_last_date_of_week).')'; - echo "".Display::return_icon('action_next.png',get_lang('Next'))."
"; - if ($is_today) - { - echo ""; - } - echo $DaysShort[$ii % 7]." ".date("j", $tmp_timestamp)." ".$MonthsLong[date("n", $tmp_timestamp) - 1]; - if ($is_today) - { - echo ""; - } - echo "
"; - echo "".$agendaitems[date('j', $value)]."  "; - echo "
\n"; -} -/** - * Show the monthcalender of the given month - */ -function get_day_agendaitems($courses_dbs, $month, $year, $day) -{ - global $_user; - global $_configuration; - global $setting_agenda_link; - - $items = array (); - - // get agenda-items for every course - //$query=Database::query($sql_select_courses); - foreach ($courses_dbs as $key => $array_course_info) - { - //databases of the courses - $TABLEAGENDA = Database :: get_main_table(TABLE_MAIN_SYSTEM_CALENDAR); - //$TABLE_ITEMPROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY, $array_course_info['db']); - - // getting all the groups of the user for the current course - //$group_memberships = GroupManager :: get_group_ids($array_course_info['db'], $_user['user_id']); - // if the user is administrator of that course we show all the agenda items - if ($array_course_info['status'] == '1') - { - //echo "course admin"; - $sqlquery = "SELECT DISTINCT * - FROM ".$TABLEAGENDA." - WHERE - DAYOFMONTH(start_date)='".$day."' AND MONTH(start_date)='".$month."' AND YEAR(start_date)='".$year."' - GROUP BY agenda.id - ORDER BY start_date "; - } - // if the user is not an administrator of that course - /*else - { - //echo "GEEN course admin"; - if (is_array($group_memberships) && count($group_memberships)>0) - { - $sqlquery = "SELECT - agenda.* - FROM ".$TABLEAGENDA." - WHERE - DAYOFMONTH(start_date)='".$day."' AND MONTH(start_date)='".$month."' AND YEAR(start_date)='".$year."' - ORDER BY start_date "; - } - else - { - $sqlquery = "SELECT - agenda.* - FROM ".$TABLEAGENDA." - WHERE - DAYOFMONTH(start_date)='".$day."' AND MONTH(start_date)='".$month."' AND YEAR(start_date)='".$year."' - ORDER BY start_date "; - } - }*/ - //$sqlquery = "SELECT * FROM $agendadb WHERE DAYOFMONTH(day)='$day' AND month(day)='$month' AND year(day)='$year'"; - //echo "abc"; - //echo $sqlquery; - $result = Database::query($sqlquery); - $portal_url = $_configuration['root_web']; - if ($_configuration['multiple_access_urls']) { - $access_url_id = api_get_current_access_url_id(); - if ($access_url_id != -1 ){ - $url = api_get_access_url($access_url_id); - $portal_url = $url['url']; - } - } - - //echo Database::num_rows($result); - while ($item = Database::fetch_array($result)) - { - // in the display_daycalendar function we use $i (ranging from 0 to 47) for each halfhour - // we want to know for each agenda item for this day to wich halfhour it must be assigned - $item['start_date'] = api_get_local_time($item['start_date'], null, date_default_timezone_get()); - list ($datepart, $timepart) = split(" ", $item['start_date']); - list ($year, $month, $day) = explode("-", $datepart); - list ($hours, $minutes, $seconds) = explode(":", $timepart); - - $halfhour = 2 * $hours; - if ($minutes >= '30') - { - $halfhour = $halfhour +1; - } - - if ($setting_agenda_link == 'coursecode') - { - $title=$array_course_info['title']; - $agenda_link = api_substr($title, 0, 14); - } - else - { - $agenda_link = Display::return_icon('course_home.gif'); - } - - //$URL = $_configuration['root_web'].$mycours["dir"]."/"; - $URL = $portal_url.'main/admin/agenda.php?cidReq='."&day=$day&month=$month&year=$year#$day"; // RH //Patrick Cool: to highlight the relevant agenda item - $items[$halfhour][] .= "".$hours.":".$minutes." ".$agenda_link." ".$item['title']."
"; - } - } - // sorting by hour for every day - $agendaitems = array(); - while (list($agendaday, $tmpitems) = each($items)) - { - sort($tmpitems); - while (list($key,$val) = each($tmpitems)) - { - $agendaitems[$agendaday].=$val; - } - } - $agendaitems = $items; - //print_r($agendaitems); - return $agendaitems; -} - -/** - * Return agenda items of the week - */ -function get_week_agendaitems($courses_dbs, $month, $year, $week = '') -{ - global $_user; - global $_configuration; - global $setting_agenda_link; - - $TABLEAGENDA = Database :: get_main_table(TABLE_MAIN_SYSTEM_CALENDAR); - - $items = array (); - // The default value of the week - if ($week == '') - { - $week_number = date("W", time()); - } - else - { - $week_number = $week; - } - $start_end = calculate_start_end_of_week($week_number, $year); - $start_filter = $start_end['start']['year']."-".$start_end['start']['month']."-".$start_end['start']['day']; - $end_filter = $start_end['end']['year']."-".$start_end['end']['month']."-".$start_end['end']['day']; - // get agenda-items for every course - foreach ($courses_dbs as $key => $array_course_info) - { - //databases of the courses - $TABLEAGENDA = Database :: get_main_table(TABLE_MAIN_SYSTEM_CALENDAR); - //$TABLE_ITEMPROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY, $array_course_info["db"]); - - // getting all the groups of the user for the current course - // $group_memberships = GroupManager :: get_group_ids($array_course_info["db"], $_user['user_id']); - - // if the user is administrator of that course we show all the agenda items - //if ($array_course_info['status'] == '1') - //{ - //echo "course admin"; - $sqlquery = "SELECT DISTINCT * FROM ".$TABLEAGENDA." ORDER BY start_date"; - //} - // if the user is not an administrator of that course - //else - //{ - //echo "GEEN course admin"; -/* if (is_array($group_memberships) && count($group_memberships)>0) - { - $sqlquery = "SELECT * FROM ".$TABLEAGENDA." ORDER BY a.start_date"; - } - else*/ - //{ - // $sqlquery = "SELECT * FROM ".$TABLEAGENDA." ORDER BY a.start_date"; - //} - //} - //echo "
".$sqlquery."
"; - // $sqlquery = "SELECT * FROM $agendadb WHERE (DAYOFMONTH(day)>='$start_day' AND DAYOFMONTH(day)<='$end_day') - // AND (MONTH(day)>='$start_month' AND MONTH(day)<='$end_month') - // AND (YEAR(day)>='$start_year' AND YEAR(day)<='$end_year')"; - $result = Database::query($sqlquery); - - $portal_url = $_configuration['root_web']; - if ($_configuration['multiple_access_urls']) { - $access_url_id = api_get_current_access_url_id(); - if ($access_url_id != -1 ){ - $url = api_get_access_url($access_url_id); - $portal_url = $url['url']; - } - } - - while ($item = Database::fetch_array($result)) - { - $agendaday_string = api_convert_and_format_date($item['start_date'], "%d", date_default_timezone_get()); - $agendaday = intval($agendaday_string); - $time = api_convert_and_format_date($item['start_date'], TIME_NO_SEC_FORMAT, date_default_timezone_get()); - - if ($setting_agenda_link == 'coursecode') - { - $title=$array_course_info['title']; - $agenda_link = api_substr($title, 0, 14); - } - else - { - $agenda_link = Display::return_icon('course_home.gif'); - } - - $URL = $portal_url."main/admin/agenda.php?cidReq=".urlencode($array_course_info["code"])."&day=$agendaday&month=$month&year=$year#$agendaday"; // RH //Patrick Cool: to highlight the relevant agenda item - $items[$agendaday][$item['start_time']] .= "$time ".$agenda_link." ".$item['title']."
"; - } - } - // sorting by hour for every day - $agendaitems = array (); - while (list ($agendaday, $tmpitems) = each($items)) - { - sort($tmpitems); - while (list ($key, $val) = each($tmpitems)) - { - $agendaitems[$agendaday] .= $val; - } - } - //print_r($agendaitems); - return $agendaitems; -} -/** - * Get repeated events of a course between two dates (timespan of a day). - * Returns an array containing the events - * @param string Course info array (as returned by api_get_course_info()) - * @param int UNIX timestamp of span start. Defaults 0, later transformed into today's start - * @param int UNIX timestamp. Defaults to 0, later transformed into today's end - * @param array A set of parameters to alter the SQL query - * @return array [int] => [course_id,parent_event_id,start_date,end_date,title,description] - */ -function get_repeated_events_day_view($course_info,$start=0,$end=0,$params) -{ - $events = array(); - //initialise all values - $y=0; - $m=0; - $d=0; - //block $end if higher than 2038 -- PHP doesn't go past that - if($end>2145934800){$end = 2145934800;} - if($start == 0 or $end == 0) - { - $y=date('Y'); - $m=date('m'); - $d=date('j'); - } - if($start==0) - { - $start = mktime(0,0,0,$m,$d,$y); - } - $db_start = date('Y-m-d H:i:s',$start); - if($end==0) - { - $end = mktime(23,59,59,$m,$d,$y); - } - //$db_end = date('Y-m-d H:i:s',$end); - - $t_cal = Database::get_main_table(TABLE_MAIN_SYSTEM_CALENDAR,$course_info['dbName']); - $t_cal_repeat = Database::get_course_table(TABLE_AGENDA_REPEAT,$course_info['dbName']); - $t_ip = Database::get_course_table(TABLE_ITEM_PROPERTY,$course_info['dbName']); - $sql = "SELECT c.id, c.title, c.content, " . - " UNIX_TIMESTAMP(c.start_date) as orig_start, UNIX_TIMESTAMP(c.end_date) as orig_end, " . - " cr.cal_type, cr.cal_end " . - " FROM $t_cal c, $t_cal_repeat cr, $t_ip as item_property " . - " WHERE cr.cal_end >= $start " . - " AND cr.cal_id = c.id " . - " AND item_property.ref = c.id ". - " AND item_property.tool = '".TOOL_CALENDAR_EVENT."' ". - " AND c.start_date <= '$db_start' " - .(!empty($params['conditions'])?$params['conditions']:'') - .(!empty($params['groupby'])?' GROUP BY '.$params['groupby']:'') - .(!empty($params['orderby'])?' ORDER BY '.$params['orderby']:''); - $res = Database::query($sql); - if(Database::num_rows($res)>0) - { - while($row = Database::fetch_array($res)) - { - $orig_start = $row['orig_start']; - $orig_end = $row['orig_start']; - $repeat_type = $row['cal_type']; - switch($repeat_type) - { - case 'daily': - //we are in the daily view, so if this element is repeated daily and - //the repetition is still active today (which is a condition of the SQL query) - //then the event happens today. Just build today's timestamp for start and end - $time_orig_h = date('H',$orig_start); - $time_orig_m = date('i',$orig_start); - $time_orig_s = date('s',$orig_start); - $int_time = (($time_orig_h*60)+$time_orig_m)*60+$time_orig_s; //time in seconds since 00:00:00 - $span = $orig_end - $orig_start; //total seconds between start and stop of original event - $current_start =$start + $int_time; //unixtimestamp start of today's event - $current_stop = $start+$int_time+$span; //unixtimestamp stop of today's event - $events[] = array($course_info['id'],$row['id'],$current_start,$current_stop,$row['title'],$row['content']); - break; - case 'weekly': - $time_orig = date('Y/n/W/j/N/G/i/s',$orig_start); - list($y_orig,$m_orig,$w_orig,$d_orig,$dw_orig,$h_orig,$n_orig,$s_orig) = split('/',$time_orig); - $time_now = date('Y/n/W/j/N/G/i/s',$end); - list($y_now,$m_now,$w_now,$d_now,$dw_now,$h_now,$n_now,$s_now) = split('/',$time_now); - if((($y_now>$y_orig) OR (($y_now == $y_orig) && ($w_now>$w_orig))) && ($dw_orig == $dw_now)) - { //if the event is after the original (at least one week) and the day of the week is the same - $time_orig_end = date('Y/n/W/j/N/G/i/s',$orig_end); - list($y_orig_e,$m_orig_e,$w_orig_e,$d_orig_e,$dw_orig_e,$h_orig_e,$n_orig_e,$s_orig_e) = split('/',$time_orig_end); - $events[] = array($course_info['id'],$row['id'],mktime($h_orig,$n_orig,$s_orig,$m_now,$d_orig,$y_now),mktime($h_orig_e,$n_orig_e,$s_orig_e,$m_now,$d_orig_e,$y_now),$row['title'],$row['content']); - } - break; - case 'monthlyByDate': - $time_orig = date('Y/n/j/G/i/s',$orig_start); - list($y_orig,$m_orig,$d_orig,$h_orig,$n_orig,$s_orig) = split('/',$time_orig); - $time_now = date('Y/n/j/G/i/s',$end); - list($y_now,$m_now,$d_now,$h_now,$n_now,$s_now) = split('/',$time_now); - if((($y_now>$y_orig) OR (($y_now == $y_orig) && ($m_now>$m_orig))) && ($d_orig == $d_now)) - { - $time_orig_end = date('Y/n/j/G/i/s',$orig_end); - list($y_orig_e,$m_orig_e,$d_orig_e,$h_orig_e,$n_orig_e,$s_orig_e) = split('/',$time_orig_end); - $events[] = array($course_info['id'],$row['id'],mktime($h_orig,$n_orig,$s_orig,$m_now,$d_orig,$y_now),mktime($h_orig_e,$n_orig_e,$s_orig_e,$m_now,$d_orig_e,$y_now),$row['title'],$row['content']); - } - break; - case 'monthlyByDayR': - //not implemented yet - break; - case 'monthlyByDay': - //not implemented yet - break; - case 'yearly': - $time_orig = date('Y/n/j/z/G/i/s',$orig_start); - list($y_orig,$m_orig,$d_orig,$dy_orig,$h_orig,$n_orig,$s_orig) = split('/',$time_orig); - $time_now = date('Y/n/j/z/G/i/s',$end); - list($y_now,$m_now,$d_now,$dy_now,$h_now,$n_now,$s_now) = split('/',$time_now); - if(($y_now>$y_orig) && ($dy_orig == $dy_now)) - { - $time_orig_end = date('Y/n/j/G/i/s',$orig_end); - list($y_orig_e,$m_orig_e,$d_orig_e,$dy_orig_e,$h_orig_e,$n_orig_e,$s_orig_e) = split('/',$time_orig_end); - $events[] = array($course_info['id'],$row['id'],mktime($h_orig,$n_orig,$s_orig,$m_now,$d_orig,$y_now),mktime($h_orig_e,$n_orig_e,$s_orig_e,$m_now,$d_orig_e,$y_now),$row['title'],$row['content']); - } - break; - default: - break; - } - } - } - return $events; -} -/** - * Get repeated events of a course between two dates (timespan of a week). - * Returns an array containing the events - * @param string Course info array (as returned by api_get_course_info()) - * @param int UNIX timestamp of span start. Defaults 0, later transformed into today's start - * @param int UNIX timestamp. Defaults to 0, later transformed into today's end - * @param array A set of parameters to alter the SQL query - * @return array [int] => [course_id,parent_event_id,start_date,end_date,title,description] - */ -function get_repeated_events_week_view($course_info,$start=0,$end=0,$params) -{ - $events = array(); - //block $end if higher than 2038 -- PHP doesn't go past that - if($end>2145934800){$end = 2145934800;} - //initialise all values - $y=0; - $m=0; - $d=0; - if($start == 0 or $end == 0) - { - $time = time(); - $dw = date('w',$time); - $week_start = $time - (($dw-1)*86400); - $y = date('Y',$week_start); - $m = date('m',$week_start); - $d = date('j',$week_start); - $w = date('W',$week_start); - } - if($start==0) - { - $start = mktime(0,0,0,$m,$d,$y); - } - $db_start = date('Y-m-d H:i:s',$start); - if($end==0) - { - $end = $start+(86400*7)-1; //start of week, more 7 days, minus 1 second to get back to the previoyus day - } - //$db_end = date('Y-m-d H:i:s',$end); - - $t_cal = Database::get_main_table(TABLE_MAIN_SYSTEM_CALENDAR); - //$t_cal_repeat = Database::get_course_table(TABLE_AGENDA_REPEAT,$course_info['dbName']); - //$t_ip = Database::get_course_table(TABLE_ITEM_PROPERTY,$course_info['dbName']); - $sql = "SELECT c.id, c.title, c.content, " . - " UNIX_TIMESTAMP(c.start_date) as orig_start, UNIX_TIMESTAMP(c.end_date) as orig_end " . - " FROM ". $t_cal ." - AS c WHERE c.start_date <= '$db_start' " - .(!empty($params['conditions'])?$params['conditions']:'') - .(!empty($params['groupby'])?' GROUP BY '.$params['groupby']:'') - .(!empty($params['orderby'])?' ORDER BY '.$params['orderby']:''); - $res = Database::query($sql); - if(Database::num_rows($res)>0) - { - while($row = Database::fetch_array($res)) - { - $orig_start = $row['orig_start']; - $orig_end = $row['orig_end']; - $repeat_type = $row['cal_type']; - switch($repeat_type) - { - case 'daily': - $time_orig_h = date('H',$orig_start); - $time_orig_m = date('i',$orig_start); - $time_orig_s = date('s',$orig_start); - $int_time = (($time_orig_h*60)+$time_orig_m)*60+$time_orig_s; //time in seconds since 00:00:00 - $span = $orig_end - $orig_start; //total seconds between start and stop of original event - for($i=0;$i<7;$i++) - { - $current_start = $start + ($i*86400) + $int_time; //unixtimestamp start of today's event - $current_stop = $start + ($i*86400) + $int_time + $span; //unixtimestamp stop of today's event - $events[] = array($course_info['id'],$row['id'],$current_start,$current_stop,$row['title'],$row['content']); - } - break; - case 'weekly': - $time_orig = date('Y/n/W/j/N/G/i/s',$orig_start); - list($y_orig,$m_orig,$w_orig,$d_orig,$dw_orig,$h_orig,$n_orig,$s_orig) = split('/',$time_orig); - $time_now = date('Y/n/W/j/N/G/i/s',$end); - list($y_now,$m_now,$w_now,$d_now,$dw_now,$h_now,$n_now,$s_now) = split('/',$time_now); - if((($y_now>$y_orig) OR (($y_now == $y_orig) && ($w_now>$w_orig)))) - { //if the event is after the original (at least one week) and the day of the week is the same - $time_orig_end = date('Y/n/W/j/N/G/i/s',$orig_end); - list($y_orig_e,$m_orig_e,$w_orig_e,$d_orig_e,$dw_orig_e,$h_orig_e,$n_orig_e,$s_orig_e) = split('/',$time_orig_end); - $events[] = array($course_info['id'],$row['id'],mktime($h_orig,$n_orig,$s_orig,$m_now,$d_orig,$y_now),mktime($h_orig_e,$n_orig_e,$s_orig_e,$m_now,$d_orig_e,$y_now),$row['title'],$row['content']); - } - break; - case 'monthlyByDate': - $time_orig = date('Y/n/W/j/G/i/s',$orig_start); - list($y_orig,$m_orig,$w_orig,$d_orig,$h_orig,$n_orig,$s_orig) = split('/',$time_orig); - $time_now = date('Y/n/W/j/G/i/s',$end); - list($y_now,$m_now,$w_now,$d_now,$h_now,$n_now,$s_now) = split('/',$time_now); - $event_repetition_time = mktime($h_orig,$n_orig,$s_orig,$m_now,$d_orig,$y_now); - if((($y_now>$y_orig) OR (($y_now == $y_orig) && ($m_now>$m_orig))) && ($start<$event_repetition_time && $event_repetition_time<$end)) - { //if the event is after the original (at least one month) and the original event's day is between the first day of the week and the last day of the week - $time_orig_end = date('Y/n/j/G/i/s',$orig_end); - list($y_orig_e,$m_orig_e,$d_orig_e,$h_orig_e,$n_orig_e,$s_orig_e) = split('/',$time_orig_end); - $events[] = array($course_info['id'],$row['id'],mktime($h_orig,$n_orig,$s_orig,$m_now,$d_orig,$y_now),mktime($h_orig_e,$n_orig_e,$s_orig_e,$m_now,$d_orig_e,$y_now),$row['title'],$row['content']); - } - break; - case 'monthlyByDayR': - //not implemented yet - break; - case 'monthlyByDay': - //not implemented yet - break; - case 'yearly': - $time_orig = date('Y/n/j/z/G/i/s',$orig_start); - list($y_orig,$m_orig,$d_orig,$dy_orig,$h_orig,$n_orig,$s_orig) = split('/',$time_orig); - $time_now = date('Y/n/j/z/G/i/s',$end); - list($y_now,$m_now,$d_now,$dy_now,$h_now,$n_now,$s_now) = split('/',$time_now); - $event_repetition_time = mktime($h_orig,$n_orig,$s_orig,$m_orig,$d_orig,$y_now); - if((($y_now>$y_orig) && ($start<$event_repetition_time && $event_repetition_time<$end))) - { - $time_orig_end = date('Y/n/j/G/i/s',$orig_end); - list($y_orig_e,$m_orig_e,$d_orig_e,$dy_orig_e,$h_orig_e,$n_orig_e,$s_orig_e) = split('/',$time_orig_end); - $events[] = array($course_info['id'],$row['id'],mktime($h_orig,$n_orig,$s_orig,$m_now,$d_orig,$y_now),mktime($h_orig_e,$n_orig_e,$s_orig_e,$m_now,$d_orig_e,$y_now),$row['title'],$row['content']); - } - break; - default: - break; - } - } - } - return $events; -} -/** - * Get repeated events of a course between two dates (timespan of a month). - * Returns an array containing the events - * @param string Course info array (as returned by api_get_course_info()) - * @param int UNIX timestamp of span start. Defaults 0, later transformed into today's start - * @param int UNIX timestamp. Defaults to 0, later transformed into today's end - * @param array A set of parameters to alter the SQL query - * @return array [int] => [course_id,parent_event_id,start_date,end_date,title,description] - */ -function get_repeated_events_month_view($course_info,$start=0,$end=0,$params) -{ - $events = array(); - //block $end if higher than 2038 -- PHP doesn't go past that - if($end>2145934800){$end = 2145934800;} - //initialise all values - $y=0; - $m=0; - $d=0; - if($start == 0 or $end == 0) - { - $time = time(); - $y = date('Y'); - $m = date('m'); - } - if($start==0) - { - $start = mktime(0,0,0,$m,1,$y); - } - $db_start = date('Y-m-d H:i:s',$start); - if($end==0) - { - if($m==12) - { - $end = mktime(0,0,0,1,1,$y+1)-1; //start of next month, minus 1 second to get back to the previoyus day - } - else - { - $end = mktime(0,0,0,$m+1,1,$y)-1; - } - } - //$db_end = date('Y-m-d H:i:s',$end); - - $t_cal = Database::get_main_table(TABLE_MAIN_SYSTEM_CALENDAR); - $t_cal_repeat = Database::get_course_table(TABLE_AGENDA_REPEAT,$course_info['dbName']); - $t_ip = Database::get_course_table(TABLE_ITEM_PROPERTY,$course_info['dbName']); - $sql = "SELECT c.id, c.title, c.content, " . - " UNIX_TIMESTAMP(c.start_date) as orig_start, UNIX_TIMESTAMP(c.end_date) as orig_end, " . - " cr.cal_type, cr.cal_end " . - " FROM $t_cal c, $t_cal_repeat cr, $t_ip as item_property " . - " WHERE cr.cal_end >= $start " . - " AND cr.cal_id = c.id " . - " AND item_property.ref = c.id ". - " AND item_property.tool = '".TOOL_CALENDAR_EVENT."' ". - " AND c.start_date <= '$db_start' " - .(!empty($params['conditions'])?$params['conditions']:'') - .(!empty($params['groupby'])?' GROUP BY '.$params['groupby']:'') - .(!empty($params['orderby'])?' ORDER BY '.$params['orderby']:''); - $res = Database::query($sql); - if(Database::num_rows($res)>0) - { - while($row = Database::fetch_array($res)) - { - $orig_start = $row['orig_start']; - $orig_end = $row['orig_end']; - $repeat_type = $row['cal_type']; - switch($repeat_type) - { - case 'daily': - $time_orig_h = date('H',$orig_start); - $time_orig_m = date('i',$orig_start); - $time_orig_s = date('s',$orig_start); - $month_last_day = date('d',$end); - $int_time = (($time_orig_h*60)+$time_orig_m)*60+$time_orig_s; //time in seconds since 00:00:00 - $span = $orig_end - $orig_start; //total seconds between start and stop of original event - for($i=0;$i<$month_last_day;$i++) - { - $current_start = $start + ($i*86400) + $int_time; //unixtimestamp start of today's event - $current_stop = $start + ($i*86400) + $int_time + $span; //unixtimestamp stop of today's event - $events[] = array($course_info['id'],$row['id'],$current_start,$current_stop,$row['title'],$row['content']); - } - break; - case 'weekly': - //A weekly repeated event is very difficult to catch in a month view, - //because weeks start before or at the same time as the first day of the month - //The same can be said for the end of the month. - // The idea is thus to get all possible events by enlarging the scope of - // the month to get complete weeks covering the complete month, and then take out - // the events that start before the 1st ($start) or after the last day of the month ($end) - $time_orig = date('Y/n/W/j/N/G/i/s',$orig_start); - list($y_orig,$m_orig,$w_orig,$d_orig,$dw_orig,$h_orig,$n_orig,$s_orig) = split('/',$time_orig); - $time_orig_end = date('Y/n/W/j/N/G/i/s',$orig_end); - list($y_orig_e,$m_orig_e,$w_orig_e,$d_orig_e,$dw_orig_e,$h_orig_e,$n_orig_e,$s_orig_e) = split('/',$time_orig_end); - - $time_now = date('Y/n/W/j/N/G/i/s',$end); - list($y_now,$m_now,$w_now,$d_now,$dw_now,$h_now,$n_now,$s_now) = split('/',$time_now); - - $month_first_week = date('W',$start); - $month_last_week = date('W',$end); - - if(($y_now>$y_orig) OR (($y_now == $y_orig) && ($w_now>$w_orig))) - { //if the event is after the original (at least one week) and the day of the week is the same - for($i=$month_first_week;$i<=$month_last_week;$i++) - { - //the "day of the week" of repetition is the same as the $dw_orig, - //so to get the "day of the month" from the "day of the week", we have - //to get the first "day of the week" for this week and add the number - //of days (in seconds) to reach the $dw_orig - //example: the first week spans between the 28th of April (Monday) to the - // 4th of May (Sunday). The event occurs on the 2nd day of each week. - // This means the event occurs on 29/4, 6/5, 13/5, 20/5 and 27/5. - // We want to get all of these, and then reject 29/4 because it is out - // of the month itself. - - //First, to get the start time of the first day of the month view (even if - // the day is from the past month), we get the month start date (1/5) and - // see which day of the week it is, and subtract the number of days necessary - // to get back to the first day of the week. - $month_first_day_weekday = date('N',$start); - $first_week_start = $start - (($month_first_day_weekday-1)*86400); - - //Second, we add the week day of the original event, so that we have an - // absolute time that represents the first repetition of the event in - // our 4- or 5-weeks timespan - $first_event_repeat_start = $first_week_start + (($dw_orig-1)*86400) + ($h_orig*3600) + ($n_orig*60) + $s_orig; - - //Third, we start looping through the repetitions and see if they are between - // $start and $end - for($i = $first_event_repeat_start; $i<=$end; $i+=604800) - { - if($start<$i && $i<$end) - { - list($y_repeat,$m_repeat,$d_repeat,$h_repeat,$n_repeat,$s_repeat) = split('/',date('Y/m/j/H/i/s',$i)); - $events[] = array($course_info['id'],$row['id'],mktime($h_orig,$n_orig,$s_orig,$m_now,$d_orig,$y_now),mktime($h_orig_e,$n_orig_e,$s_orig_e,$m_now,$d_orig_e,$y_now),$row['title'],$row['content']); - } - } - } - } - break; - case 'monthlyByDate': - $time_orig = date('Y/n/W/j/G/i/s',$orig_start); - list($y_orig,$m_orig,$w_orig,$d_orig,$h_orig,$n_orig,$s_orig) = split('/',$time_orig); - $time_now = date('Y/n/W/j/G/i/s',$end); - list($y_now,$m_now,$w_now,$d_now,$h_now,$n_now,$s_now) = split('/',$time_now); - $event_repetition_time = mktime($h_orig,$n_orig,$s_orig,$m_now,$d_orig,$y_now); - if(($y_now>$y_orig) OR (($y_now == $y_orig) && ($m_now>$m_orig))) - { //if the event is after the original (at least one month) and the original event's day is between the first day of the week and the last day of the week - $time_orig_end = date('Y/n/j/G/i/s',$orig_end); - list($y_orig_e,$m_orig_e,$d_orig_e,$h_orig_e,$n_orig_e,$s_orig_e) = split('/',$time_orig_end); - $events[] = array($course_info['id'],$row['id'],mktime($h_orig,$n_orig,$s_orig,$m_now,$d_orig,$y_now),mktime($h_orig_e,$n_orig_e,$s_orig_e,$m_now,$d_orig_e,$y_now),$row['title'],$row['content']); - } - break; - case 'monthlyByDayR': - //not implemented yet - break; - case 'monthlyByDay': - //not implemented yet - break; - case 'yearly': - $time_orig = date('Y/n/j/z/G/i/s',$orig_start); - list($y_orig,$m_orig,$d_orig,$dy_orig,$h_orig,$n_orig,$s_orig) = split('/',$time_orig); - $time_now = date('Y/n/j/z/G/i/s',$end); - list($y_now,$m_now,$d_now,$dy_now,$h_now,$n_now,$s_now) = split('/',$time_now); - $event_repetition_time = mktime($h_orig,$n_orig,$s_orig,$m_orig,$d_orig,$y_now); - if((($y_now>$y_orig) && ($start<$event_repetition_time && $event_repetition_time<$end))) - { - $time_orig_end = date('Y/n/j/G/i/s',$orig_end); - list($y_orig_e,$m_orig_e,$d_orig_e,$dy_orig_e,$h_orig_e,$n_orig_e,$s_orig_e) = split('/',$time_orig_end); - $events[] = array($course_info['id'],$row['id'],mktime($h_orig,$n_orig,$s_orig,$m_now,$d_orig,$y_now),mktime($h_orig_e,$n_orig_e,$s_orig_e,$m_now,$d_orig_e,$y_now),$row['title'],$row['content']); - } - break; - default: - break; - } - } - } - return $events; -} -/** - * Get repeated events of a course between two dates (1 year timespan). Used for the list display. - * This is virtually unlimited but by default it shortens to 100 years from now (even a birthday shouldn't be useful more than this time - except for turtles) - * Returns an array containing the events - * @param string Course info array (as returned by api_get_course_info()) - * @param int UNIX timestamp of span start. Defaults 0, later transformed into today's start - * @param int UNIX timestamp. Defaults to 0, later transformed into today's end - * @param array A set of parameters to alter the SQL query - * @return array [int] => [course_id,parent_event_id,start_date,end_date,title,description] - */ -function get_repeated_events_list_view($course_info,$start=0,$end=0,$params) -{ - $events = array(); - //block $end if higher than 2038 -- PHP doesn't go past that - if($end>2145934800){$end = 2145934800;} - //initialise all values - $y=0; - $m=0; - $d=0; - if(empty($start) or empty($end)) - { - $time = time(); - $y = date('Y'); - $m = date('m'); - } - if(empty($start)) - { - $start = mktime(0, 0, 0, $m, 1, $y); - } - $db_start = date('Y-m-d H:i:s', $start); - if(empty($end)) - { - $end = mktime(0, 0, 0, 1, 1, 2037); - } - //$db_end = date('Y-m-d H:i:s',$end); - - $t_cal = Database::get_main_table(TABLE_MAIN_SYSTEM_CALENDAR,$course_info['dbName']); - $t_cal_repeat = Database::get_course_table(TABLE_AGENDA_REPEAT,$course_info['dbName']); - $t_ip = Database::get_course_table(TABLE_ITEM_PROPERTY,$course_info['dbName']); - $sql = "SELECT c.id, c.title, c.content, " . - " UNIX_TIMESTAMP(c.start_date) as orig_start, UNIX_TIMESTAMP(c.end_date) as orig_end, " . - " cr.cal_type, cr.cal_end " . - " FROM $t_cal c, $t_cal_repeat cr, $t_ip as item_property " . - " WHERE cr.cal_end >= $start " . - " AND cr.cal_id = c.id " . - " AND item_property.ref = c.id ". - " AND item_property.tool = '".TOOL_CALENDAR_EVENT."' ". - " AND c.start_date <= '$db_start' " - .(!empty($params['conditions'])?$params['conditions']:'') - .(!empty($params['groupby'])?' GROUP BY '.$params['groupby']:'') - .(!empty($params['orderby'])?' ORDER BY '.$params['orderby']:''); - $res = Database::query($sql); - if(Database::num_rows($res)>0) - { - while($row = Database::fetch_array($res)) - { - $orig_start = $row['orig_start']; - $orig_end = $row['orig_end']; - $repeat_type = $row['cal_type']; - $repeat_end = $row['cal_end']; - switch($repeat_type) - { - case 'daily': - $time_orig_h = date('H',$orig_start); - $time_orig_m = date('i',$orig_start); - $time_orig_s = date('s',$orig_start); - $span = $orig_end - $orig_start; //total seconds between start and stop of original event - for($i=$orig_start+86400;($i<$end && $i<=$repeat_end);$i+=86400) - { - $current_start = $i; //unixtimestamp start of today's event - $current_stop = $i + $span; //unixtimestamp stop of today's event - $events[] = array($course_info['id'],$row['id'],$current_start,$current_stop,$row['title'],$row['content']); - } - break; - case 'weekly': - //A weekly repeated event is very difficult to catch in a month view, - // because weeks start before or at the same time as the first day of the month - //The same can be said for the end of the month. - // The idea is thus to get all possible events by enlarging the scope of - // the month to get complete weeks covering the complete month, and then take out - // the events that start before the 1st ($start) or after the last day of the month ($end) - $time_orig = date('Y/n/W/j/N/G/i/s',$orig_start); - list($y_orig,$m_orig,$w_orig,$d_orig,$dw_orig,$h_orig,$n_orig,$s_orig) = split('/',$time_orig); - $time_orig_end = date('Y/n/W/j/N/G/i/s',$orig_end); - list($y_orig_e,$m_orig_e,$w_orig_e,$d_orig_e,$dw_orig_e,$h_orig_e,$n_orig_e,$s_orig_e) = split('/',$time_orig_end); - - $time_now = date('Y/n/W/j/N/G/i/s',$end); - list($y_now,$m_now,$w_now,$d_now,$dw_now,$h_now,$n_now,$s_now) = split('/',$time_now); - if($w_now==52) - { - ++$y_now; - $w_now=1; - } - else - { - ++$w_now; - } - $month_first_week = date('W',$start); - $total_weeks = ((date('Y',$end)-$y_orig)-1)*52; - $month_last_week = $month_first_week + $total_weeks; - - if(($y_now>$y_orig) OR (($y_now == $y_orig) && ($w_now>$w_orig))) - { //if the event is after the original (at least one week) and the day of the week is the same - //for($i=$month_first_week;($i<=$month_last_week && $i<1000);$i++) - //{ - - - /* - The "day of the week" of repetition is the same as the $dw_orig, - so to get the "day of the month" from the "day of the week", we have - to get the first "day of the week" for this week and add the number - of days (in seconds) to reach the $dw_orig - example: the first week spans between the 28th of April (Monday) to the - 4th of May (Sunday). The event occurs on the 2nd day of each week. - This means the event occurs on 29/4, 6/5, 13/5, 20/5 and 27/5. - We want to get all of these, and then reject 29/4 because it is out - of the month itself. - First, to get the start time of the first day of the month view (even if - the day is from the past month), we get the month start date (1/5) and - see which day of the week it is, and subtract the number of days necessary - to get back to the first day of the week. - */ - $month_first_day_weekday = date('N',$start); - $first_week_start = $start - (($month_first_day_weekday-1)*86400); - - //Second, we add the week day of the original event, so that we have an - // absolute time that represents the first repetition of the event in - // our 4- or 5-weeks timespan - $first_event_repeat_start = $first_week_start + (($dw_orig-1)*86400) + ($h_orig*3600) + ($n_orig*60) + $s_orig; - - //Third, we start looping through the repetitions and see if they are between - // $start and $end - for($i = $first_event_repeat_start; ($i<=$end && $i<=$repeat_end); $i+=604800) - { - if($start<$i && $i<=$end && $i<=$repeat_end) - { - list($y_repeat,$m_repeat,$d_repeat,$h_repeat,$n_repeat,$s_repeat) = split('/',date('Y/m/j/H/i/s',$i)); - $new_start_time = mktime($h_orig,$n_orig,$s_orig,$m_now,$d_orig,$y_now); - $new_stop_time = mktime($h_orig_e,$n_orig_e,$s_orig_e,$m_now,$d_orig_e,$y_now); - $events[] = array($course_info['id'], $row['id'], $new_start_time, $new_stop_time, $row['title'], $row['content']); - } - $time_now = date('Y/n/W/j/N/G/i/s',$i+604800); - list($y_now,$m_now,$w_now,$d_now,$dw_now,$h_now,$n_now,$s_now) = split('/',$time_now); - } - //} - } - break; - case 'monthlyByDate': - $time_orig = date('Y/n/W/j/G/i/s',$orig_start); - list($y_orig,$m_orig,$w_orig,$d_orig,$h_orig,$n_orig,$s_orig) = split('/',$time_orig); - - $time_now = date('Y/n/W/j/G/i/s',$start); - list($y_now,$m_now,$w_now,$d_now,$h_now,$n_now,$s_now) = split('/',$time_now); - //make sure we are one month ahead (to avoid being the same month as the original event) - if($m_now==12) - { - ++$y_now; - $m_now = 1; - } - else - { - ++$m_now; - } - - $time_orig_end = date('Y/n/j/G/i/s',$orig_end); - list($y_orig_e,$m_orig_e,$d_orig_e,$h_orig_e,$n_orig_e,$s_orig_e) = split('/',$time_orig_end); - - $event_repetition_time = mktime($h_orig,$n_orig,$s_orig,$m_now,$d_orig,$y_now); - $diff = $orig_end - $orig_start; - while((($y_now>$y_orig) OR (($y_now == $y_orig) && ($m_now>$m_orig))) && ($event_repetition_time < $end) && ($event_repetition_time < $repeat_end)) - { //if the event is after the original (at least one month) and the original event's day is between the first day of the week and the last day of the week - $new_start_time = mktime($h_orig,$n_orig,$s_orig,$m_now,$d_orig,$y_now); - $new_stop_time = mktime($h_orig_e,$n_orig_e,$s_orig_e,$m_now,$d_orig_e,$y_now); - $events[] = array($course_info['id'],$row['id'],$new_start_time,$new_stop_time,$row['title'],$row['content']); - if($m_now==12) - { - ++$y_now; - $m_now = 1; - } - else - { - ++$m_now; - } - $event_repetition_time = mktime($h_orig,$n_orig,$s_orig,$m_now,$d_orig,$y_now); - } - break; - case 'monthlyByDayR': - //not implemented yet - break; - case 'monthlyByDay': - //not implemented yet - break; - case 'yearly': - $time_orig = date('Y/n/j/z/G/i/s',$orig_start); - list($y_orig,$m_orig,$d_orig,$dy_orig,$h_orig,$n_orig,$s_orig) = split('/',$time_orig); - $time_now = date('Y/n/j/z/G/i/s',$end); - list($y_now,$m_now,$d_now,$dy_now,$h_now,$n_now,$s_now) = split('/',$time_now); - $event_repetition_time = mktime($h_orig,$n_orig,$s_orig,$m_orig,$d_orig,$y_now); - while((($y_now>$y_orig) && ($start<$event_repetition_time && $event_repetition_time<$end && $event_repetition_time<$repeat_end))) - { - $time_orig_end = date('Y/n/j/G/i/s',$orig_end); - list($y_orig_e,$m_orig_e,$d_orig_e,$dy_orig_e,$h_orig_e,$n_orig_e,$s_orig_e) = split('/',$time_orig_end); - $events[] = array($course_info['id'],$row['id'],mktime($h_orig,$n_orig,$s_orig,$m_now,$d_orig,$y_now),mktime($h_orig_e,$n_orig_e,$s_orig_e,$m_now,$d_orig_e,$y_now),$row['title'],$row['content']); - ++$y_now; - $event_repetition_time = mktime($h_orig,$n_orig,$s_orig,$m_orig,$d_orig,$y_now); - } - break; - default: - break; - } - } - } - return $events; -} -/** - * Tells if an agenda item is repeated - * @param string Course database - * @param int The agenda item - * @return boolean True if repeated, false otherwise - */ -function is_repeated_event($id,$course=null) -{ - if(empty($course)) - { - $course_info = api_get_course_info(); - $course = $course_info['dbName']; - } - $id = (int) $id; - $t_agenda_repeat = Database::get_course_table(TABLE_AGENDA_REPEAT); - $sql = "SELECT * FROM $t_agenda_repeat WHERE cal_id = $id"; - $res = Database::query($sql); - if(Database::num_rows($res)>0) - { - return true; - } - return false; -} - -/** - * Adds x weeks to a UNIX timestamp - * @param int The timestamp - * @param int The number of weeks to add - * @return int The new timestamp - */ -function add_week($timestamp,$num=1) -{ - return $timestamp + $num*604800; -} -/** - * Adds x months to a UNIX timestamp - * @param int The timestamp - * @param int The number of years to add - * @return int The new timestamp - */ -function add_month($timestamp,$num=1) -{ - list($y, $m, $d, $h, $n, $s) = split('/',date('Y/m/d/h/i/s',$timestamp)); - if($m+$num>12) - { - $y += floor($num/12); - $m += $num%12; - } - else - { - $m += $num; - } - return mktime($h, $n, $s, $m, $d, $y); -} -/** - * Adds x years to a UNIX timestamp - * @param int The timestamp - * @param int The number of years to add - * @return int The new timestamp - */ -function add_year($timestamp,$num=1) -{ - list($y, $m, $d, $h, $n, $s) = split('/',date('Y/m/d/h/i/s',$timestamp)); - return mktime($h, $n, $s, $m, $d, $y+$num); -} -/** - * Adds an agenda item in the database. Similar to store_new_agenda_item() except it takes parameters - * @param array Course info - * @param string Event title - * @param string Event content/description - * @param string Start date - * @param string End date - * @param array List of groups to which this event is added - * @param int Parent id (optional) - * @return int The new item's DB ID - */ -function agenda_add_item($title, $content, $db_start_date, $db_end_date) { - $user_id = api_get_user_id(); - $t_agenda = Database::get_main_table(TABLE_MAIN_SYSTEM_CALENDAR); - - // 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); - - $db_end_date = api_get_utc_datetime($db_end_date); - $end_date = Database::escape_string($db_end_date); - - // check if exists in calendar_event table - $sql = "SELECT * FROM $t_agenda WHERE title='$title' AND content = '$content' AND start_date = '$start_date' AND end_date = '$end_date' "; - $result = Database::query($sql); - $count = Database::num_rows($result); - if ($count > 0) { - return false; - } - $sql = "INSERT INTO $t_agenda (title,content, start_date, end_date, access_url_id) - VALUES ('".$title."','".$content."', '".$start_date."','".$end_date."', '".api_get_current_access_url_id()."')"; - - $result = Database::query($sql); - $last_id = Database::insert_id(); - return $last_id; -} -/** - * Gets calendar items - * @param int Month - * @param int Year - * @return array Array of events - */ -function get_calendar_items($month, $year) -{ - global $_user, $_course; - global $is_allowed_to_edit; - - $month = intval($month); - $year = intval($year); - - // database variables - $TABLEAGENDA = Database::get_main_table(TABLE_MAIN_SYSTEM_CALENDAR); - - $month_first_day = mktime(0,0,0,$month,1,$year); - $month_last_day = mktime(0,0,0,$month+1,1,$year)-1; - if ($month==12) { - $month_last_day = mktime(0,0,0,1,1,$year+1)-1; - } - $repeats = array(); - $data=array(); - if (api_is_allowed_to_edit()) { - $sql="SELECT DISTINCT * - FROM ".$TABLEAGENDA." agenda - WHERE MONTH(start_date)='".$month."' AND YEAR(start_date)='".$year."'"; - - global $_configuration; - $current_access_url_id = 1; - if ($_configuration['multiple_access_urls']) { - $current_access_url_id = api_get_current_access_url_id(); - } - $sql .= " AND access_url_id = '$current_access_url_id' "; - - $sql .= "GROUP BY id ORDER BY start_date "; - - $result=Database::query($sql); - - while ($row=Database::fetch_array($result)) { - $datum_item=(int)substr($row["start_date"],8,2); - $data[$datum_item][intval($datum_item)][] = $row; - } - } - return $data; -} -/** - * This function is not been used or deprecated - */ -function agenda_add_repeat_item($course_info,$orig_id,$type,$end,$orig_dest) -{/* - $t_agenda = Database::get_main_table(TABLE_MAIN_SYSTEM_CALENDAR,$course_info['dbName']); - // $t_agenda_r = Database::get_course_table(TABLE_AGENDA_REPEAT,$course_info['dbName']); - //$sql = "SELECT title, content, UNIX_TIMESTAMP(start_date) as sd, UNIX_TIMESTAMP(end_date) as ed FROM $t_agenda WHERE id = $orig_id"; - $sql = "SELECT title, content, start_date as sd, end_date as ed FROM $t_agenda WHERE id = $orig_id"; - $res = Database::query($sql); - if(Database::num_rows($res)!==1){return false;} - $row = Database::fetch_array($res); - //$orig_start = $row['sd']; - $orig_start = mktime(substr($row['sd'],11,2),substr($row['sd'],14,2),substr($row['sd'],17,2),substr($row['sd'],5,2),substr($row['sd'],8,2),substr($row['sd'],0,4)); - //$orig_end = $row['ed']; - $orig_end = mktime(substr($row['ed'],11,2),substr($row['ed'],14,2),substr($row['ed'],17,2),substr($row['ed'],5,2),substr($row['ed'],8,2),substr($row['ed'],0,4)); - $diff = $orig_end - $orig_start; - $orig_title = $row['title']; - $orig_content = $row['content']; - $now = time(); - $type = Database::escape_string($type); - $end = (int) $end; - if(1<=$end && $end<=500) - { - //we assume that, with this type of value, the user actually gives a count of repetitions - //and that he wants us to calculate the end date with that (particularly in case of imports from ical) - switch($type) - { - case 'daily': - $end = $orig_start + (86400*$end); - break; - case 'weekly': - $end = add_week($orig_start,$end); - break; - case 'monthlyByDate': - $end = add_month($orig_start,$end); - break; - case 'monthlyByDay': - //TODO - break; - case 'monthlyByDayR': - //TODO - break; - case 'yearly': - $end = add_year($orig_start,$end); - break; - } - } - if($end > $now - && in_array($type,array('daily','weekly','monthlyByDate','monthlyByDay','monthlyByDayR','yearly'))) - { - $sql = "INSERT INTO $t_agenda_r (cal_id, cal_type, cal_end)" . - " VALUES ($orig_id,'$type',$end)"; - $res = Database::query($sql); - switch($type) - { - case 'daily': - for($i = $orig_start + 86400; ($i <= $end); $i += 86400) - { - $res = agenda_add_item($course_info, $orig_title, $orig_content, date('Y-m-d H:i:s', $i), date('Y-m-d H:i:s', $i+$diff), $orig_dest, $orig_id); - } - break; - case 'weekly': - for($i = $orig_start + 604800; ($i <= $end); $i += 604800) - { - $res = agenda_add_item($course_info, $orig_title, $orig_content, date('Y-m-d H:i:s', $i), date('Y-m-d H:i:s', $i+$diff), $orig_dest, $orig_id); - } - break; - case 'monthlyByDate': - $next_start = add_month($orig_start); - while($next_start <= $end) - { - $res = agenda_add_item($course_info, $orig_title, $orig_content, date('Y-m-d H:i:s', $next_start), date('Y-m-d H:i:s', $next_start+$diff), $orig_dest, $orig_id); - $next_start = add_month($next_start); - } - break; - case 'monthlyByDay': - //not yet implemented - break; - case 'monthlyByDayR': - //not yet implemented - break; - case 'yearly': - $next_start = add_year($orig_start); - while($next_start <= $end) - { - $res = agenda_add_item($course_info, $orig_title, $orig_content, date('Y-m-d H:i:s', $next_start), date('Y-m-d H:i:s', $next_start+$diff), $orig_dest, $orig_id); - $next_start = add_year($next_start); - } - break; - } - } - return true;*/ -} -/** - * Import an iCal file into the database - * @param array Course info - * @return boolean True on success, false otherwise - */ - -function agenda_import_ical($course_info,$file) { - - $charset = api_get_system_encoding(); - $filepath = api_get_path(SYS_ARCHIVE_PATH).$file['name']; - if(!@move_uploaded_file($file['tmp_name'],$filepath)) - { - error_log('Problem moving uploaded file: '.$file['error'].' in '.__FILE__.' line '.__LINE__); - return false; - } - - $ical = new vcalendar(); - $ical->setConfig('directory', dirname($filepath) ); - $ical->setConfig('filename', basename($filepath) ); - $ical->parse(); - //we need to recover: summary, description, dtstart, dtend, organizer, attendee, location (=course name), - // rrule - $ve = $ical->getComponent(VEVENT); - //print_r($ve); - $ttitle = $ve->getProperty('summary'); - //print_r($ttitle); - $title = api_convert_encoding($ttitle,$charset,'UTF-8'); - $tdesc = $ve->getProperty('description'); - $desc = api_convert_encoding($tdesc,$charset,'UTF-8'); - $ts = $ve->getProperty('dtstart'); - $start_date = $ts['year'].'-'.$ts['month'].'-'.$ts['day'].' '.$ts['hour'].':'.$ts['min'].':'.$ts['sec']; - $ts = $ve->getProperty('dtend'); - $end_date = $ts['year'].'-'.$ts['month'].'-'.$ts['day'].' '.$ts['hour'].':'.$ts['min'].':'.$ts['sec']; - //echo $start_date.' - '.$end_date; - $organizer = $ve->getProperty('organizer'); - $attendee = $ve->getProperty('attendee'); - $course_name = $ve->getProperty('location'); - //insert the event in our database - $id = agenda_add_item($course_info,$title,$desc,$start_date,$end_date,$_POST['selectedform']); - - $repeat = $ve->getProperty('rrule'); - if(is_array($repeat) && !empty($repeat['FREQ'])) - { - $trans = array('DAILY'=>'daily','WEEKLY'=>'weekly','MONTHLY'=>'monthlyByDate','YEARLY'=>'yearly'); - $freq = $trans[$repeat['FREQ']]; - $interval = $repeat['INTERVAL']; - if(isset($repeat['UNTIL']) && is_array($repeat['UNTIL'])) - { - $until = mktime(23,59,59,$repeat['UNTIL']['month'],$repeat['UNTIL']['day'],$repeat['UNTIL']['year']); - $res = agenda_add_repeat_item($course_info,$id,$freq,$until,$_POST['selectedform']); - } - //TODO: deal with count - if(!empty($repeat['COUNT'])) - { - $count = $repeat['COUNT']; - $res = agenda_add_repeat_item($course_info,$id,$freq,$count,$_POST['selectedform']); - } - } - return true; -} -?> diff --git a/main/admin/calendar.php b/main/admin/calendar.php deleted file mode 100755 index b75bd1434d..0000000000 --- a/main/admin/calendar.php +++ /dev/null @@ -1,283 +0,0 @@ - 'index.php', 'name' => get_lang('PlatformAdmin')); - -// setting the name of the tool -$tool_name= get_lang('SubscribeCoursesToSession'); - -$id_session=intval($_GET['id_session']); - -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)!= api_get_user_id()) { - api_not_allowed(true); - } -} - -/* - Libraries -*/ -// containing the functions for the agenda tool -require_once 'calendar.lib.php'; - -/* - TREATING THE PARAMETERS - 1. viewing month only or everything - 2. sort ascending or descending - 3. showing or hiding the send-to-specific-groups-or-users form - 4. filter user or group - */ -// 1. show all or show current month? -if (!$_SESSION['show_all_admin']) { - $_SESSION['show_all_admin']="showall"; -} -if (!empty($_GET['action']) and $_GET['action']=="showcurrent") -{ - $_SESSION['show_all_admin']='showcurrent'; -} -if (!empty($_GET['action']) and $_GET['action']=="showall") -{ - $_SESSION['show_all_admin']='showall'; -} - -// 2. sorting order (ASC or DESC) -if (empty($_GET['sort']) and empty($_SESSION['sort'])) -{ - $_SESSION['sort']="DESC"; -} -if (!empty($_GET['sort']) and $_GET['sort']=="asc") -{ - $_SESSION['sort']="ASC"; -} -if (!empty($_GET['sort']) and $_GET['sort']=="desc") -{ - $_SESSION['sort']="DESC"; -} -if (!empty($_GET['view'])) -{ - $_SESSION['view'] = $_GET['view']; -} - -// 3. showing or hiding the send-to-specific-groups-or-users form -$setting_allow_individual_calendar=true; -if (empty($_POST['To']) and empty($_SESSION['allow_individual_calendar'])) -{ - $_SESSION['allow_individual_calendar']="hide"; -} -$allow_individual_calendar_status=$_SESSION['allow_individual_calendar']; -if (!empty($_POST['To']) and ($allow_individual_calendar_status=="hide")) -{ - $_SESSION['allow_individual_calendar']="show"; -} -if (!empty($_GET['sort']) and ($allow_individual_calendar_status=="show")) -{ - $_SESSION['allow_individual_calendar']="hide"; -} - -$htmlHeadXtra[] = to_javascript(); - -// this loads the javascript that is needed for the date popup selection -$htmlHeadXtra[] = ""; - -// setting the name of the tool -$nameTools = get_lang('GlobalAgenda'); // language variable in trad4all.inc.php - -// showing the header if we are not in the learning path, if we are in -// the learning path, we do not include the banner so we have to explicitly -// include the stylesheet, which is normally done in the header -Display::display_header($nameTools,'Agenda'); - -/* SETTING SOME VARIABLES */ -// Variable definitions -// Defining the shorts for the days. We use camelcase because these are arrays of language variables -$DaysShort = api_get_week_days_short(); -// Defining the days of the week to allow translation of the days. We use camelcase because these are arrays of language variables -$DaysLong = api_get_week_days_long(); -// Defining the months of the year to allow translation of the months. We use camelcase because these are arrays of language variables -$MonthsLong = api_get_months_long(); - -// Database table definitions -$TABLEAGENDA = Database::get_main_table(TABLE_MAIN_SYSTEM_CALENDAR); -$tbl_user = Database::get_main_table(TABLE_MAIN_USER); -$tbl_courseUser = Database::get_main_table(TABLE_MAIN_COURSE_USER); - -/* - ACCESS RIGHTS -*/ -// permission stuff - also used by loading from global in agenda.inc.php -$is_allowed_to_edit = api_is_allowed_to_edit() OR (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous()); - -// insert an anchor (top) so one can jump back to the top of the page -echo ""; - -/* - MAIN SECTION -*/ - -//setting the default year and month -$select_year = ''; -$select_month = ''; -if(!empty($_GET['year'])) { - $select_year = (int)$_GET['year']; -} -if(!empty($_GET['month'])) { - $select_month = (int)$_GET['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())) { - display_student_links(); - // Deprecated since 2014-10-31 - //display_courseadmin_links(); -} - -echo '


'; -echo ''; - -// THE LEFT PART -if (empty($_GET['origin']) or $_GET['origin']!='learnpath') { - echo ''; - echo ''; -} - - -// THE RIGHT PART -echo '
'; - // the small calendar - $MonthName = $MonthsLong[$select_month -1]; - $agenda_items=get_calendar_items($select_month,$select_year); - if (api_get_setting('display_mini_month_calendar') == 'true') { - display_minimonthcalendar($agenda_items, $select_month,$select_year, $MonthName); - } - if (api_get_setting('display_upcoming_events') == 'true') { - display_upcoming_events(); - } - echo ' '; -echo '
'; - -echo '
'; -if (api_is_allowed_to_edit(false,true)) { - switch ($_GET['action']) { - case "add": - if ($_POST['submit_event']) { - $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($_POST['title'],$_POST['content'],$event_start,$event_stop); - display_agenda_items(); - } else { - show_add_form(); - } - break; - - 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(); - } else { - $id=(int)$_GET['id']; - show_add_form($id); - } - } else { - display_agenda_items(); - } - break; - - case "delete": - $id=(int)$_GET['id']; - if( ! (api_is_course_coach() && !api_is_element_in_the_session(TOOL_AGENDA, $id ) ) ) - { // a coach can only delete an element belonging to his session - if (api_is_allowed_to_edit() && !api_is_anonymous()) { - if (!empty($id)) { - $res_del = delete_agenda_item($id); - if ($res_del) { - Display::display_normal_message(get_lang("AgendaDeleteSuccess")); - } - } - } - } - display_agenda_items(); - break; - - case "showhide": - $id=(int)$_GET['id']; - if( ! (api_is_course_coach() && !api_is_element_in_the_session(TOOL_AGENDA, $id ) ) ) - { // a coach can only delete an element belonging to his session - showhide_agenda_item($id); - } - display_agenda_items(); - break; - case "announce": //copying the agenda item into an announcement - $id=(int)$_GET['id']; - if( ! (api_is_course_coach() && !api_is_element_in_the_session(TOOL_AGENDA, $id ) ) ) - { // a coach can only delete an element belonging to his session - $ann_id = store_agenda_item_as_announcement($id); - $tool_group_link = (isset($_SESSION['toolgroup'])?'&toolgroup='.$_SESSION['toolgroup']:''); - echo '
'; - Display::display_normal_message(get_lang('CopiedAsAnnouncement').''.get_lang('NewAnnouncement').'', false); - } - display_agenda_items(); - break; - case "delete_attach": //delete attachment file - $id_attach = (int)$_GET['id_attach']; - if (!empty($id_attach)) { - delete_attachment_file($id_attach); - } - display_agenda_items(); - break; - - } -} - -// 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'])) { - display_one_agenda_item((int)$_GET['agenda_id']); - } else { - display_agenda_items(); - } - } else { - display_monthcalendar($select_month, $select_year); - } - } else { - display_one_agenda_item((int)$_GET['agenda_id']); - } -} -echo " 
"; - -/* - FOOTER -*/ -// The footer is displayed only if we are not in the learnpath -if ($_GET['origin'] != 'learnpath') { - Display::display_footer(); -} diff --git a/main/admin/calendar_ical_export.php b/main/admin/calendar_ical_export.php deleted file mode 100755 index 9727e6b9ed..0000000000 --- a/main/admin/calendar_ical_export.php +++ /dev/null @@ -1,133 +0,0 @@ -setConfig('unique_id',api_get_path(WEB_PATH)); - $ical->setProperty( 'method', 'PUBLISH' ); - $ical->setConfig('url',api_get_path(WEB_PATH)); - $vevent = new vevent(); - switch($_GET['class']) - { - case 'public': - $vevent->setClass('PUBLIC'); - break; - case 'private': - $vevent->setClass('PRIVATE'); - break; - case 'confidential': - $vevent->setClass('CONFIDENTIAL'); - break; - default: - $vevent->setClass('PRIVATE'); - break; - } - - switch($_GET['type']) - { - case 'personal': - //require_once (api_get_path(SYS_CODE_PATH).'calendar/myagenda.inc.php'); - $ai = get_personal_agenda_item($_GET['id']); - $vevent->setProperty( 'summary', api_convert_encoding($ai['title'],'UTF-8',$charset)); - if(empty($ai['date'])){header('location:'.$_SERVER['REFERER_URI']);} - list($y,$m,$d,$h,$M,$s) = preg_split('/[\s:-]/',$ai['date']); - $vevent->setProperty('dtstart',array('year'=>$y,'month'=>$m,'day'=>$d,'hour'=>$h,'min'=>$M,'sec'=>$s)); - if(empty($ai['enddate'])) - { - $y2=$y;$m2=$m;$d2=$d;$h2=$h;$M2=$M+15;$s2=$s; - if($M2>60){$M2=$M2-60;$h2+=1;} - } - else - { - list($y2,$m2,$d2,$h2,$M2,$s2) = preg_split('/[\s:-]/',$ai['enddate']); - } - $vevent->setProperty('dtend',array('year'=>$y2,'month'=>$m2,'day'=>$d2,'hour'=>$h2,'min'=>$M2,'sec'=>$s2)); - //$vevent->setProperty( 'LOCATION', get_lang('Unknown') ); // property name - case independent - $vevent->setProperty( 'description', api_convert_encoding($ai['text'],'UTF-8',$charset)); - //$vevent->setProperty( 'comment', 'This is a comment' ); - $user = api_get_user_info($ai['user']); - $vevent->setProperty('organizer',$user['mail']); - $vevent->setProperty('attendee',$user['mail']); - //$vevent->setProperty( 'rrule', array( 'FREQ' => 'WEEKLY', 'count' => 4));// occurs also four next weeks - $ical->setConfig('filename',$y.$m.$d.$h.$M.$s.'-'.rand(1,1000).'.ics'); - $ical->setComponent ($vevent); // add event to calendar - $ical->returnCalendar(); - break; - case 'course': - $TABLEAGENDA =Database::get_main_table(TABLE_MAIN_SYSTEM_CALENDAR); - require_once api_get_path(SYS_CODE_PATH).'admin/calendar.lib.php'; - $ai = get_agenda_item($_GET['id']); - $vevent->setProperty( 'summary', api_convert_encoding($ai['title'],'UTF-8',$charset)); - if(empty($ai['start_date'])){header('location:'.$_SERVER['REFERER_URI']);} - list($y,$m,$d,$h,$M,$s) = preg_split('/[\s:-]/',$ai['start_date']); - $vevent->setProperty('dtstart',array('year'=>$y,'month'=>$m,'day'=>$d,'hour'=>$h,'min'=>$M,'sec'=>$s)); - if(empty($ai['end_date'])) - { - $y2=$y;$m2=$m;$d2=$d;$h2=$h;$M2=$M+15;$s2=$s; - if($M2>60){$M2=$M2-60;$h2+=1;} - } - else - { - list($y2,$m2,$d2,$h2,$M2,$s2) = preg_split('/[\s:-]/',$ai['end_date']); - } - $vevent->setProperty('dtend',array('year'=>$y2,'month'=>$m2,'day'=>$d2,'hour'=>$h2,'min'=>$M2,'sec'=>$s2)); - $vevent->setProperty( 'description', api_convert_encoding($ai['content'],'UTF-8',$charset)); - //$vevent->setProperty( 'comment', 'This is a comment' ); - $user = api_get_user_info($ai['user']); - $vevent->setProperty('organizer',$user['mail']); - //$vevent->setProperty('attendee',$user['mail']); - $course = api_get_course_info(); - $vevent->setProperty('location', $course['name']); // property name - case independent - if($ai['repeat']) - { - $trans = array('daily'=>'DAILY','weekly'=>'WEEKLY','monthlyByDate'=>'MONTHLY','yearly'=>'YEARLY'); - $freq = $trans[$ai['repeat_type']]; - list($e_y,$e_m,$e_d) = split('/',date('Y/m/d',$ai['repeat_end'])); - $vevent->setProperty('rrule',array('FREQ'=>$freq,'UNTIL'=>array('year'=>$e_y,'month'=>$e_m,'day'=>$e_d),'INTERVAL'=>'1')); - } - //$vevent->setProperty( 'rrule', array( 'FREQ' => 'WEEKLY', 'count' => 4));// occurs also four next weeks - $ical->setConfig('filename',$y.$m.$d.$h.$M.$s.'-'.rand(1,1000).'.ics'); - $ical->setComponent ($vevent); // add event to calendar - $ical->returnCalendar(); - break; - default: - header('location:'.$_SERVER['REFERER_URI']); - die(); - } - } -} -else -{ - header('location:'.$_SERVER['REFERER_URI']); - die(); -} -?> diff --git a/main/admin/user_list.php b/main/admin/user_list.php index a399539f7a..b55eed7820 100755 --- a/main/admin/user_list.php +++ b/main/admin/user_list.php @@ -1,5 +1,6 @@ BeezNest 2011 @@ -123,25 +124,6 @@ $(document).ready(function() { document.getElementById(\'extra_data_text\').style.display="none"; } } - - $(".agenda_opener").live("click", function() { - var url = this.href; - var dialog = $("#dialog"); - - if ($("#dialog").length == 0) { - dialog = $(\'
\').appendTo(\'body\'); - } - // load remote content - dialog.load( - url, - {}, - function(responseText, textStatus, XMLHttpRequest) { - dialog.dialog({width:720, height:550, modal:true}); - } - ); - //prevent the browser to follow the link - return false; - }); }); //Load user calendar @@ -627,7 +609,8 @@ function modify_filter($user_id, $url_params, $row) { } if (api_is_platform_admin()) { - $result .= ' '.Display::return_icon('month.png', get_lang('FreeBusyCalendar'), array(), ICON_SIZE_SMALL).''; + $result .= ' '. + Display::return_icon('month.png', get_lang('FreeBusyCalendar'), array(), ICON_SIZE_SMALL).''; if ($delete_user_available) { if ($user_id != api_get_user_id() && !$user_is_anonymous && diff --git a/main/calendar/agenda.inc.php b/main/calendar/agenda.inc.php deleted file mode 100755 index 8295d21b6f..0000000000 --- a/main/calendar/agenda.inc.php +++ /dev/null @@ -1,3851 +0,0 @@ - BeezNest 2011 - Lots of fixes - UI improvements, security fixes, - * @author: Patrick Cool, patrick.cool@UGent.be - * @todo this code should be clean as well as the myagenda.inc.php - jmontoya - * @package chamilo.calendar - * @deprecated use agenda.lib.php - */ -/** - * Code - */ -// the variables for the days and the months -// Defining the shorts for the days -$DaysShort = api_get_week_days_short(); -// Defining the days of the week to allow translation of the days -$DaysLong = api_get_week_days_long(); -// Defining the months of the year to allow translation of the months -$MonthsLong = api_get_months_long(); - -$htmlHeadXtra[] = to_javascript(); -$htmlHeadXtra[] = ''; - -/** - * Retrieves all the agenda items from the table - * @author: Patrick Cool , Ghent University - * @author Yannick Warnier - cleanup - * @author Julio Montoya - Refactoring - * @param integer $month: the integer value of the month we are viewing - * @param integer $year: the 4-digit year indication e.g. 2005 - * @return array - */ -function get_calendar_items($select_month, $select_year, $select_day = false) -{ - $course_info = api_get_course_info(); - $select_month = intval($select_month); - $select_year = intval($select_year); - if ($select_day) - $select_day = intval($select_day); - - if (!empty($select_month) && !empty($select_year)) { - - $show_all_current = " AND MONTH(start_date) = $select_month AND year(start_date) = $select_year"; - if ($select_day) { - $show_all_current .= ' AND DAY(start_date) = '.$select_day; - } - $show_all_current_personal = " AND MONTH(date) = $select_month AND year(date) = $select_year"; - - if ($select_day) { - $show_all_current_personal .= ' AND DAY(date) = '.$select_day; - } - } else { - $show_all_current = ''; - $show_all_current_personal = ''; - } - - // database variables - $TABLEAGENDA = Database::get_course_table(TABLE_AGENDA); - $TABLE_ITEM_PROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY); - - $group_memberships = GroupManager::get_group_ids($course_info['real_id'], api_get_user_id()); - $repeats = array(); - - /* CONSTRUCT THE SQL STATEMENT */ - - // by default we use the id of the current user. The course administrator can see the agenda of other users by using the user / group filter - $user_id = api_get_user_id(); - if (isset($_SESSION['user'])) { - $user_id = intval($_SESSION['user']); - } - - $group_id = api_get_group_id(); - - $session_condition = api_get_session_condition(api_get_session_id()); - - if (api_is_allowed_to_edit(false, true) OR (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous())) { - // A.1. you are a course admin with a USER filter - // => see only the messages of this specific user + the messages of the group (s)he is member of. - - if (!empty($_SESSION['user'])) { - $group_memberships = GroupManager::get_group_ids($course_info['real_id'], $_SESSION['user']); - - $show_user = true; - $new_group_memberships = array(); - foreach ($group_memberships as $id) { - // did i have access to the same - $has_access = GroupManager::user_has_access(api_get_user_id(), $id, GroupManager::GROUP_TOOL_CALENDAR); - $result = GroupManager::get_group_properties($id); - if ($has_access && $result['calendar_state'] != '0') { - $new_group_memberships[] = $id; - } - } - $group_memberships = $new_group_memberships; - - if (is_array($group_memberships) && count($group_memberships) > 0) { - $sql = "SELECT - agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref - FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." ip - WHERE agenda.id = ip.ref ".$show_all_current." - AND ip.tool='".TOOL_CALENDAR_EVENT."' - AND ( ip.to_user_id = $user_id OR ip.to_group_id IN (0, ".implode(", ", $group_memberships).") ) - AND ip.visibility='1' - $session_condition"; - } else { - //AND ( ip.to_user_id=$user_id OR ip.to_group_id='0') - $sql = "SELECT agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref - FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." ip - WHERE agenda.id = ip.ref ".$show_all_current." - AND ip.tool='".TOOL_CALENDAR_EVENT."' - AND ( ip.to_user_id = $user_id ) - AND ip.visibility='1' - $session_condition"; - } - } - // A.2. you are a course admin with a GROUP filter - // => see only the messages of this specific group - elseif (!empty($_SESSION['group'])) { - if (!empty($group_id)) { - $result = GroupManager::get_group_properties($group_id); - $has_access = GroupManager::user_has_access(api_get_user_id(), $group_id, GroupManager::GROUP_TOOL_CALENDAR); - //echo '
';print_R($result);
-                // lastedit
-                if (!$has_access || $result['calendar_state'] == '0') {
-                    $group_id = 0;
-                }
-            }
-
-            $sql = "SELECT agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref
-                FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." ip
-                WHERE agenda.id = ip.ref  ".$show_all_current."
-                AND ip.tool='".TOOL_CALENDAR_EVENT."'
-                AND ( ip.to_group_id=$group_id)
-                AND ip.lastedit_type<>'CalendareventDeleted'
-                $session_condition
-                GROUP BY ip.ref";
-            //removed   - > AND toolitemproperties.visibility='1'
-        }
-        // A.3 you are a course admin without any group or user filter
-        else {
-            // A.3.a you are a course admin without user or group filter but WITH studentview
-            // => see all the messages of all the users and groups without editing possibilities
-            if (isset($_GET['isStudentView']) && $_GET['isStudentView'] == 'true') {
-                $sql = "SELECT
-                    agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref
-                    FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." ip
-                    WHERE agenda.id = ip.ref  ".$show_all_current."
-                    AND ip.tool='".TOOL_CALENDAR_EVENT."'
-                    AND ip.visibility='1'
-                    $session_condition
-                    GROUP BY ip.ref";
-            }
-            // A.3.b you are a course admin or a student
-            else {
-                // A.3.b.1 you are a course admin without user or group filter and WITHOUT studentview (= the normal course admin view)
-                //  => see all the messages of all the users and groups with editing possibilities
-
-                if (api_is_course_admin()) {
-                    $sql = "SELECT
-                        agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref
-                        FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." ip
-                        WHERE agenda.id = ip.ref  ".$show_all_current."
-                        AND ip.tool='".TOOL_CALENDAR_EVENT."'
-                        AND ( ip.visibility='0' OR ip.visibility='1')
-                        $session_condition
-                        GROUP BY ip.ref";
-                } else {
-                    // A.3.b.2 you are a student with no group filter possibly showall
-                    //when showing all the events we do not show the group events
-                    //todo showing ALL events including the groups events that are available
-                    $sql = "SELECT
-                        agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref
-                        FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." ip
-                        WHERE agenda.id = ip.ref  ".$show_all_current."
-                        AND ip.tool='".TOOL_CALENDAR_EVENT."'
-                        AND ( ip.visibility='0' OR ip.visibility='1')
-                        $session_condition
-                        GROUP BY ip.ref";
-                }
-            }
-        }
-    } //if (is_allowed_to_edit() OR( api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous()))
-    // B. you are a student
-    else {
-        if (is_array($group_memberships) && count($group_memberships) > 0) {
-            $sql = "SELECT
-                agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref
-                FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." ip
-                WHERE agenda.id = ip.ref   ".$show_all_current."
-                AND ip.tool='".TOOL_CALENDAR_EVENT."'
-                AND ( ip.to_user_id=$user_id OR ip.to_group_id IN (0, ".implode(", ", $group_memberships).") )
-                AND ip.visibility='1'
-                $session_condition";
-        } else {
-            if (api_get_user_id()) {
-                $sql = "SELECT
-                    agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref
-                    FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." ip
-                    WHERE agenda.id = ip.ref   ".$show_all_current."
-                    AND ip.tool='".TOOL_CALENDAR_EVENT."'
-                    AND ( ip.to_user_id=$user_id OR ip.to_group_id='0')
-                    AND ip.visibility='1'
-                    $session_condition";
-            } else {
-                $sql = "SELECT
-                    agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref
-                    FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." ip
-                    WHERE agenda.id = ip.ref   ".$show_all_current."
-                    AND ip.tool='".TOOL_CALENDAR_EVENT."'
-                    AND ip.to_group_id='0'
-                    AND ip.visibility='1'
-                    $session_condition";
-            }
-        }
-    } // you are a student
-
-    $my_events = array();
-    $avoid_doubles = array();
-    $result = Database::query($sql);
-
-    //Course venets
-    while ($row = Database::fetch_array($result, 'ASSOC')) {
-        $row['calendar_type'] = 'course';
-        if (!in_array($row['id'], $avoid_doubles)) {
-            if (!empty($row['start_date']) && $row['start_date'] != '0000-00-00 00:00:00') {
-                $row['start_date'] = api_get_local_time($row['start_date']);
-                $row['start_date_tms'] = api_strtotime($row['start_date']);
-            }
-
-            if (!empty($row['end_date']) && $row['end_date'] != '0000-00-00 00:00:00') {
-                $row['end_date'] = api_get_local_time($row['end_date']);
-                $row['end_date_tms'] = api_strtotime($row['end_date']);
-            }
-
-            $my_events[] = $row;
-            $avoid_doubles[] = $row['id'];
-        }
-    }
-
-    //Check my personal calendar items
-    if (api_get_setting('allow_personal_agenda') == 'true' && empty($_SESSION['user']) && empty($_SESSION['group'])) {
-        $tbl_personal_agenda = Database :: get_main_table(TABLE_PERSONAL_AGENDA);
-        // 1. creating the SQL statement for getting the personal agenda items in MONTH view
-        $sql = "SELECT id, title, text as content , date as start_date, enddate as end_date, parent_event_id FROM ".$tbl_personal_agenda."
-                WHERE user='".api_get_user_id()."' ".$show_all_current_personal;
-        $result = Database::query($sql);
-        while ($row = Database::fetch_array($result, 'ASSOC')) {
-            $row['calendar_type'] = 'personal';
-            if (!empty($row['start_date']) && $row['start_date'] != '0000-00-00 00:00:00') {
-                $row['start_date'] = api_get_local_time($row['start_date']);
-                $row['start_date_tms'] = api_strtotime($row['start_date']);
-            }
-
-            if (!empty($row['end_date']) && $row['end_date'] != '0000-00-00 00:00:00') {
-                $row['end_date'] = api_get_local_time($row['end_date']);
-                $row['end_date_tms'] = api_strtotime($row['end_date']);
-            }
-            $my_events[] = $row;
-        }
-    }
-
-    //Check global agenda events
-    if (empty($_SESSION['user']) && empty($_SESSION['group'])) {
-        $table_agenda_system = Database :: get_main_table(TABLE_MAIN_SYSTEM_CALENDAR);
-        $current_access_url_id = api_get_current_access_url_id();
-
-        $sql = "SELECT DISTINCT id, title, content , start_date, end_date FROM ".$table_agenda_system."
-                WHERE 1=1  ".$show_all_current." AND access_url_id = $current_access_url_id";
-        $result = Database::query($sql);
-        while ($row = Database::fetch_array($result, 'ASSOC')) {
-            if (!empty($row['start_date']) && $row['start_date'] != '0000-00-00 00:00:00') {
-                $row['start_date'] = api_get_local_time($row['start_date']);
-                $row['start_date_tms'] = api_strtotime($row['start_date']);
-            }
-
-            if (!empty($row['end_date']) && $row['end_date'] != '0000-00-00 00:00:00') {
-                $row['end_date'] = api_get_local_time($row['end_date']);
-                $row['end_date_tms'] = api_strtotime($row['end_date']);
-            }
-
-            $row['calendar_type'] = 'global';
-            $my_events[] = $row;
-        }
-    }
-    return $my_events;
-}
-
-/**
- * show the mini calender of the given month
- * @author: Patrick Cool , Ghent University
- * @param array an array containing all the agenda items for the given month
- * @param integer $month: the integer value of the month we are viewing
- * @param integer $year: the 4-digit year indication e.g. 2005
- * @param string $monthName: the language variable for the mont name
- * @return html code
- * @todo refactor this so that $monthName is no longer needed as a parameter
- */
-function display_minimonthcalendar($agenda_items, $month, $year)
-{
-    global $DaysShort, $MonthsLong;
-    if (empty($month)) {
-        $month = intval(date('m'));
-    }
-    if (empty($year)) {
-        $month = date('Y');
-    }
-
-    $month_name = $MonthsLong[$month - 1];
-
-
-    //Handle leap year
-    $numberofdays = array(0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
-    if (($year % 400 == 0) or ($year % 4 == 0 and $year % 100 <> 0))
-        $numberofdays[2] = 29;
-    //Get the first day of the month
-    $dayone = getdate(mktime(0, 0, 0, $month, 1, $year));
-    //Start the week on monday
-    $startdayofweek = $dayone['wday'] <> 0 ? ($dayone['wday'] - 1) : 6;
-    $backwardsURL = api_get_self()."?".api_get_cidreq()."&coursePath=".(empty($_GET['coursePath']) ? '' : Security::remove_XSS($_GET['coursePath']))."&courseCode=".(empty($_GET['courseCode']) ? '' : Security::remove_XSS($_GET['courseCode']))."&month=".($month == 1 ? 12 : $month - 1)."&year=".($month == 1 ? $year - 1 : $year);
-    $forewardsURL = api_get_self()."?".api_get_cidreq()."&coursePath=".(empty($_GET['coursePath']) ? '' : Security::remove_XSS($_GET['coursePath']))."&courseCode=".(empty($_GET['courseCode']) ? '' : Security::remove_XSS($_GET['courseCode']))."&month=".($month == 12 ? 1 : $month + 1)."&year=".($month == 12 ? $year + 1 : $year);
-
-    $month_link = Display::url($month_name." ".$year, api_get_self()."?".api_get_cidreq()."&month=".($month)."&year=".$year);
-
-    $new_items = array();
-    foreach ($agenda_items as $item) {
-        $day = intval(substr($item["start_date"], 8, 2));
-        $my_month = intval(substr($item["start_date"], 5, 2));
-        if ($my_month == $month) {
-            $new_items[$day][] = 1;
-        }
-    }
-
-    $agenda_items = $new_items;
-
-    echo "",
-    "",
-    "",
-    "",
-    "";
-    echo "";
-    for ($ii = 1; $ii < 8; $ii++) {
-        echo "";
-    }
-    echo "";
-    $curday = -1;
-    $today = getdate();
-    while ($curday <= $numberofdays[$month]) {
-        echo "";
-        for ($ii = 0; $ii < 7; $ii++) {
-            if (($curday == -1) && ($ii == $startdayofweek)) {
-                $curday = 1;
-            }
-            if (($curday > 0) && ($curday <= $numberofdays[$month])) {
-                $bgcolor = $ii < 5 ? $class = "class=\"days_week\"" : $class = "class=\"days_weekend\"";
-                $dayheader = "$curday";
-                if (($curday == $today['mday']) && ($year == $today['year']) && ($month == $today['mon'])) {
-                    $dayheader = "$curday";
-                    $class = "class=\"days_today\"";
-                }
-                echo "";
-                $curday++;
-            } else {
-                echo "";
-            }
-        }
-        echo "";
-    }
-    echo "
".Display::return_icon('action_prev.png', get_lang('Previous'))." ".$month_link." ".Display::return_icon('action_next.png', get_lang('Next'))."
", $DaysShort[$ii % 7], "
"; - if (!empty($agenda_items[$curday])) { - echo "".$dayheader.""; - } else { - echo $dayheader; - } - // "a".$dayheader." ".$agenda_items[$curday].""; - echo "
"; -} - -/** - * show the calender of the given month - * @author: Patrick Cool , Ghent University - * @author Julio Montoya - adding some nice styles - * @param integer $month: the integer value of the month we are viewing - * @param integer $year: the 4-digit year indication e.g. 2005 - * @return html code - */ -function display_monthcalendar($month, $year, $agenda_items) -{ - global $MonthsLong; - global $DaysShort; - global $origin; - - //Handle leap year - $numberofdays = array(0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); - if (($year % 400 == 0) or ($year % 4 == 0 and $year % 100 <> 0)) - $numberofdays[2] = 29; - - //Get the first day of the month - $dayone = getdate(mktime(0, 0, 0, $month, 1, $year)); - - //Start the week on monday - $startdayofweek = $dayone['wday'] <> 0 ? ($dayone['wday'] - 1) : 6; - - $backwardsURL = api_get_self()."?".api_get_cidreq()."&view=".Security::remove_XSS($_GET['view'])."&origin=$origin&month=".($month == 1 ? 12 : $month - 1)."&year=".($month == 1 ? $year - 1 : $year); - $forewardsURL = api_get_self()."?".api_get_cidreq()."&view=".Security::remove_XSS($_GET['view'])."&origin=$origin&month=".($month == 12 ? 1 : $month + 1)."&year=".($month == 12 ? $year + 1 : $year); - - $new_month = $month - 1; - - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - - echo ''; - for ($ii = 1; $ii < 8; $ii++) { - echo ''; - } - - echo ''; - $curday = -1; - $today = getdate(); - - $new_items = array(); - foreach ($agenda_items as $item) { - $day = intval(substr($item["start_date"], 8, 2)); - $my_month = intval(substr($item["start_date"], 5, 2)); - if ($my_month == $month) { - $new_items[$day][] = $item; - } - } - $agenda_items = $new_items; - - while ($curday <= $numberofdays[$month]) { - echo ''; - //week - for ($ii = 0; $ii < 7; $ii++) { - if (($curday == -1) && ($ii == $startdayofweek)) { - $curday = 1; - } - if (($curday > 0) && ($curday <= $numberofdays[$month])) { - - $bgcolor = $ii < 5 ? 'class="row_odd"' : 'class="row_even"'; - $dayheader = Display::div($curday, array('class' => 'agenda_day')); - - if (array_key_exists($curday, $agenda_items)) { - $dayheader = Display::div($curday, array('class' => 'agenda_day')); - $events_in_day = msort($agenda_items[$curday], 'start_date_tms'); - foreach ($events_in_day as $value) { - - $some_content = false; - $month_start_date = (int) substr($value['start_date'], 5, 2); - - if ($month == $month_start_date) { - $some_content = true; - - $start_time = api_format_date($value['start_date'], TIME_NO_SEC_FORMAT); - $end_time = ''; - if (!empty($value['end_date']) && $value['end_date'] != '0000-00-00 00:00:00') { - $end_time = '- '.api_format_date($value['end_date'], DATE_TIME_FORMAT_LONG).''; - } - $complete_time = ''.api_format_date($value['start_date'], DATE_TIME_FORMAT_LONG).' '.$end_time; - $time = ''.$start_time.''; - - switch ($value['calendar_type']) { - case 'personal': - $bg_color = '#D0E7F4'; - $icon = Display::return_icon('user.png', get_lang('MyAgenda'), array(), 22); - break; - case 'global': - $bg_color = '#FFBC89'; - $icon = Display::return_icon('view_remove.png', get_lang('GlobalEvent'), array(), 22); - break; - case 'course': - $bg_color = '#CAFFAA'; - $value['course_name'] = isset($value['course_name']) ? $value['course_name'] : null; - $value['url'] = isset($value['url']) ? $value['url'] : null; - $icon = Display::url(Display::return_icon('course.png', $value['course_name'].' '.get_lang('Course'), array(), 22), $value['url']); - break; - default: - break; - } - $icon = Display::div($icon, array('style' => 'float:right')); - - //Setting a personal event to green - $dayheader.= '
'; - - //Link to bubble - $url = Display::url(cut($value['title'], 40), '#', array('id' => $value['calendar_type'].'_'.$value['id'], 'class' => 'opener')); - $dayheader .= $time.' '.$icon.' '.Display::div($url); - - //Hidden content - $content = Display::div($icon.Display::tag('h1', $value['title']).$complete_time.'
'.$value['content']); - - //Main div - $dayheader .= Display::div($content, array('id' => 'main_'.$value['calendar_type'].'_'.$value['id'], 'class' => 'dialog', 'style' => 'display:none')); - - $dayheader .= '
'; - } - - //Do not show links with no content - if (!$some_content) { - $dayheader = Display::div($curday, array('class' => 'agenda_day')); - } - } - } - if (($curday == $today['mday']) && ($year == $today['year']) && ($month == $today['mon'])) { - echo ''; - $curday++; - } else { - echo ''; - } - } - echo ''; - } // end while - echo '
'.Display::return_icon('action_prev.png', get_lang('Previous'), array(), 32).'

'.$MonthsLong[$new_month].' '.$year.'

'.Display::return_icon('action_next.png', get_lang('Next'), array(), 32).'
'.$DaysShort[$ii % 7].'
'.$dayheader; - } else { - $class = 'days_week'; - echo ''.$dayheader; - } - echo ' 
'; -} - -/** - * returns all the javascript that is required for easily selecting the target people/groups this goes into the $htmlHeadXtra[] array - * @author: Patrick Cool , Ghent University - * @return javascript code - */ -function to_javascript() -{ - return ""; -} - -/** - * returns the javascript for setting a filter. This is a jump menu - * @author: Patrick Cool , Ghent University - * @return javascript code - */ -function user_group_filter_javascript() -{ - return ""; -} - -/** - * this function gets all the users of the current course - * @author Patrick Cool , Ghent University - * @return array: associative array where the key is the id of the user and the value is an array containing - the first name, the last name, the user id - */ -function get_course_users() -{ - global $_cid; - - $tbl_user = Database::get_main_table(TABLE_MAIN_USER); - $tbl_courseUser = Database::get_main_table(TABLE_MAIN_COURSE_USER); - $tbl_session_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER); - - // not 100% if this is necessary, this however prevents a notice - if (!isset($courseadmin_filter)) { - $courseadmin_filter = ''; - } - // - $order_clause = api_sort_by_first_name() ? ' ORDER BY u.firstname, u.lastname' : ' ORDER BY u.lastname, u.firstname'; - $sql = "SELECT u.user_id uid, u.lastname lastName, u.firstname firstName, u.username - FROM $tbl_user as u, $tbl_courseUser as cu - WHERE cu.course_code = '".api_get_course_id()."' - AND cu.user_id = u.user_id $courseadmin_filter".$order_clause; - $result = Database::query($sql); - while ($user = Database::fetch_array($result)) { - $users[$user[0]] = $user; - } - - $session_id = api_get_session_id(); - if (!empty($session_id)) { - $users = array(); - $sql = "SELECT u.user_id uid, u.lastname lastName, u.firstName firstName, u.username - FROM $tbl_session_course_user AS session_course_user - INNER JOIN $tbl_user u ON u.user_id = session_course_user.id_user - WHERE id_session = ".$session_id." - AND course_code = '".api_get_course_id()."'"; - - $result = Database::query($sql); - while ($user = Database::fetch_array($result)) { - $users[$user[0]] = $user; - } - } - return $users; -} - -/** - * this function gets all the groups of the course - * @author Patrick Cool , Ghent University - * @return array - */ -function get_course_groups() -{ - $group_list = CourseManager::get_group_list_of_course(api_get_course_id(), api_get_session_id()); - return $group_list; -} - -/** - * this function shows the form for sending a message to a specific group or user. - * @author: Patrick Cool , Ghent University - * - * @return html code - */ -function show_to_form($to_already_selected) -{ - $order = 'lastname'; - if (api_is_western_name_order()) { - $order = 'firstname'; - } - - $user_list = CourseManager::get_user_list_from_course_code(api_get_course_id(), api_get_session_id(), null, $order); - $group_list = CourseManager::get_group_list_of_course(api_get_course_id(), api_get_session_id()); - return construct_not_selected_select_form($group_list, $user_list, $to_already_selected); -} - - -function show_to($filter = 0, $id = null) -{ - $order = 'lastname'; - if (api_is_western_name_order()) { - $order = 'firstname'; - } - - $user_list = CourseManager::get_user_list_from_course_code(api_get_course_id(), api_get_session_id(), null, $order); - $group_list = CourseManager::get_group_list_of_course(api_get_course_id(), api_get_session_id()); - - return construct_to_select_form($group_list, $user_list, $filter, $id); -} - -function construct_to_select_form($group_list = null, $user_list = null, $filter = 0, $id = null) { - $result = '"; - return $result; -} - -/** - * This function shows the form with the user that were selected - * @author: Patrick Cool , Ghent University - * @return html code - */ -function construct_selected_select_form($group_list = null, $user_list = null, $to_already_selected) -{ - // we separate the $to_already_selected array (containing groups AND users into - // two separate arrays - if (is_array($to_already_selected)) { - $groupuser = separate_users_groups($to_already_selected); - } - $groups_to_already_selected = $groupuser['groups']; - $users_to_already_selected = $groupuser['users']; - - // we load all the groups and all the users into a reference array that we use to search the name of the group / user - $ref_array_groups = get_course_groups(); - $ref_array_users = get_course_users(); - // we construct the form of the already selected groups / users - echo ""; -} - -/** - * This function stores the Agenda Item in the table calendar_event and updates the item_property table also - * @author: Patrick Cool , Ghent University - * @return integer the id of the last added agenda item - */ -function store_new_agenda_item() -{ - $_course = api_get_course_info(); - $TABLEAGENDA = Database::get_course_table(TABLE_AGENDA); - $t_agenda_repeat = Database::get_course_Table(TABLE_AGENDA_REPEAT); - - $course_id = api_get_course_int_id(); - - // some filtering of the input data - $title = 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'] == 'on') { - $end_date = "0000-00-00 00:00:00"; - } - - // store in the table calendar_event - $sql = "INSERT INTO ".$TABLEAGENDA." (c_id, title,content, start_date, end_date) - VALUES ($course_id, '".$title."','".$content."', '".$start_date."','".$end_date."')"; - $result = Database::query($sql); - $last_id = Database::insert_id(); - - // store in last_tooledit (first the groups, then the users - $to = $_POST['selectedform']; - - if ((!is_null($to)) || (!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(explode('|', $to)); - // storing the selected groups - if (is_array($send_to['groups'])) { - foreach ($send_to['groups'] as $group) { - api_item_property_update($_course, TOOL_CALENDAR_EVENT, $last_id, "AgendaAdded", api_get_user_id(), $group, '', $start_date, $end_date); - } - } - // storing the selected users - if (is_array($send_to['users'])) { - foreach ($send_to['users'] as $user) { - api_item_property_update($_course, TOOL_CALENDAR_EVENT, $last_id, "AgendaAdded", api_get_user_id(), '', $user, $start_date, $end_date); - } - } - } else { // the message is sent to everyone, so we set the group to 0 - api_item_property_update($_course, TOOL_CALENDAR_EVENT, $last_id, "AgendaAdded", api_get_user_id(), '', '', $start_date, $end_date); - } - // storing the resources - store_resources($_SESSION['source_type'], $last_id); - $course_id = api_get_course_int_id(); - - //if repetitive, insert element into agenda_repeat table - if (!empty($_POST['repeat']) && !empty($_POST['repeat_type'])) { - if (!empty($_POST['repeat_end_year']) && !empty($_POST['repeat_end_month']) && !empty($_POST['repeat_end_day'])) { - $end_y = intval($_POST['repeat_end_year']); - $end_m = intval($_POST['repeat_end_month']); - $end_d = intval($_POST['repeat_end_day']); - $end = mktime((int) $_POST['fhour'], (int) $_POST['fminute'], 0, $end_m, $end_d, $end_y); - $now = time(); - $type = Database::escape_string($_POST['repeat_type']); - - if ($end > $now && in_array($type, array('daily', 'weekly', 'monthlyByDate', 'monthlyByDay', 'monthlyByDayR', 'yearly'))) { - $sql = "INSERT INTO $t_agenda_repeat (c_id, cal_id, cal_type, cal_end)". - " VALUES ($course_id, $last_id,'$type',$end)"; - $res = Database::query($sql); - } - } - } - return $last_id; -} - -/** - * Stores the given agenda item as an announcement (unlinked copy) - * @param integer Agenda item's ID - * @return integer New announcement item's ID - */ -function store_agenda_item_as_announcement($item_id) -{ - $table_agenda = Database::get_course_table(TABLE_AGENDA); - $table_ann = Database::get_course_table(TABLE_ANNOUNCEMENT); - //check params - if (empty($item_id) or $item_id != strval(intval($item_id))) { - return -1; - } - //get the agenda item - - $item_id = intval($item_id); - $sql = "SELECT * FROM $table_agenda WHERE id = ".$item_id; - $res = Database::query($sql); - $course_id = api_get_course_int_id(); - - if (Database::num_rows($res) > 0) { - $row = Database::fetch_array($res); - - //we have the agenda event, copy it - //get the maximum value for display order in announcement table - $sql_max = "SELECT MAX(display_order) FROM $table_ann WHERE c_id = $course_id "; - $res_max = Database::query($sql_max); - $row_max = Database::fetch_array($res_max); - $max = intval($row_max[0]) + 1; - //build the announcement text - $content = $row['content']; - //insert announcement - $session_id = api_get_session_id(); - - - $sql_ins = "INSERT INTO $table_ann (c_id, title,content,end_date,display_order,session_id) ". - "VALUES ($course_id, '".Database::escape_string($row['title'])."','".Database::escape_string($content)."','".Database::escape_string($row['end_date'])."','$max','$session_id')"; - $res_ins = Database::query($sql_ins); - if ($res > 0) { - $ann_id = Database::insert_id(); - //Now also get the list of item_properties rows for this agenda_item (calendar_event) - //and copy them into announcement item_properties - $table_props = Database::get_course_table(TABLE_ITEM_PROPERTY); - $sql_props = "SELECT * FROM $table_props WHERE tool = 'calendar_event' AND ref='$item_id'"; - $res_props = Database::query($sql_props); - if (Database::num_rows($res_props) > 0) { - while ($row_props = Database::fetch_array($res_props)) { - //insert into announcement item_property - $time = api_get_utc_datetime(); - $sql_ins_props = "INSERT INTO $table_props ". - "(c_id, tool, insert_user_id, insert_date, ". - "lastedit_date, ref, lastedit_type,". - "lastedit_user_id, to_group_id, to_user_id, ". - "visibility, start_visible, end_visible)". - " VALUES ". - "($course_id, 'announcement','".$row_props['insert_user_id']."','".$time."',". - "'$time','$ann_id','AnnouncementAdded',". - "'".$row_props['last_edit_user_id']."','".$row_props['to_group_id']."','".$row_props['to_user_id']."',". - "'".$row_props['visibility']."','".$row_props['start_visible']."','".$row_props['end_visible']."')"; - $res_ins_props = Database::query($sql_ins_props); - if ($res_ins_props <= 0) { - return -1; - } else { - //copy was a success - return $ann_id; - } - } - } - } else { - return -1; - } - } - return -1; -} - -/** - * This function separates the users from the groups - * users have a value USER:XXX (with XXX the dokeos id - * groups have a value GROUP:YYY (with YYY the group id) - * @author: Patrick Cool , Ghent University - * @return array - */ -function separate_users_groups($to) -{ - $grouplist = array(); - $userlist = array(); - $send_to = null; - - $send_to['everyone'] = false; - - if (is_array($to) && count($to) > 0) { - foreach ($to as $to_item) { - - list($type, $id) = explode(':', $to_item); - switch ($type) { - case 'everyone': - $send_to['everyone'] = true; - case 'GROUP': - $grouplist[] = $id; - break; - case 'USER': - $userlist[] = $id; - break; - } - } - $send_to['groups'] = $grouplist; - $send_to['users'] = $userlist; - } - return $send_to; -} - -/** - * returns all the users and all the groups a specific Agenda item has been sent to - * @author: Patrick Cool , Ghent University - * @return array - */ -function sent_to($tool, $id) -{ - $TABLE_ITEM_PROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY); - $tool = Database::escape_string($tool); - $id = intval($id); - - $sql = "SELECT * FROM $TABLE_ITEM_PROPERTY WHERE tool='".$tool."' AND ref= ".$id.""; - $result = Database::query($sql); - while ($row = Database::fetch_array($result)) { - // if to_group_id is null then it is sent to a specific user - // if to_group_id = 0 then it is sent to everybody - if (!is_null($row['to_group_id'])) { - $sent_to_group[] = $row['to_group_id']; - //echo $row['to_group_id']; - } - // if to_user_id <> 0 then it is sent to a specific user - if ($row['to_user_id'] <> 0) { - $sent_to_user[] = $row['to_user_id']; - } - } - if (isset($sent_to_group)) { - $sent_to['groups'] = $sent_to_group; - } - if (isset($sent_to_user)) { - $sent_to['users'] = $sent_to_user; - } - return $sent_to; -} - -/** - * constructs the form to display all the groups and users the message has been sent to - * @author: Patrick Cool , Ghent University - * @param array $sent_to_array: a 2 dimensional array containing the groups and the users - * the first level is a distinction between groups and users: $sent_to_array['groups'] and $sent_to_array['users'] - * $sent_to_array['groups'] (resp. $sent_to_array['users']) is also an array containing all the id's of the - * groups (resp. users) who have received this message. - * @return html - */ -function sent_to_form($sent_to_array) -{ - // we find all the names of the groups - $group_names = get_course_groups(); - - // we count the number of users and the number of groups - if (isset($sent_to_array['users'])) { - $number_users = count($sent_to_array['users']); - } else { - $number_users = 0; - } - if (isset($sent_to_array['groups'])) { - $number_groups = count($sent_to_array['groups']); - } else { - $number_groups = 0; - } - $total_numbers = $number_users + $number_groups; - $output = array(); - // starting the form if there is more than one user/group - if ($total_numbers > 1) { - //$output.=""; - // outputting the name of the groups - if (is_array($sent_to_array['groups'])) { - foreach ($sent_to_array['groups'] as $group_id) { - if (isset($group_names[$group_id]['name'])) { - $output[] = $group_names[$group_id]['name']; - } - } - } - if (isset($sent_to_array['users'])) { - if (is_array($sent_to_array['users'])) { - foreach ($sent_to_array['users'] as $user_id) { - // @todo add username as tooltip - is this function still used ? - // $user_info= api_get_user_info($user_id); - // $username = api_htmlentities(sprintf(get_lang('LoginX'), $user_info['username']), ENT_QUOTES); - $output[] = api_get_person_name($user_info['firstName'], $user_info['lastName']); - } - } - } - } else { - // there is only one user/group - if (is_array($sent_to_array['users'])) { - // @todo add username as tooltip - is this fucntion still used ? - // $user_info = api_get_user_info($sent_to_array['users'][0]); - // $username = api_htmlentities(sprintf(get_lang('LoginX'), $user_info['username']), ENT_QUOTES); - $output[] = api_get_person_name($user_info['firstName'], $user_info['lastName']); - } - if (is_array($sent_to_array['groups']) and $sent_to_array['groups'][0] !== 0) { - $group_id = $sent_to_array['groups'][0]; - $output[] = $group_names[$group_id]['name']; - } - if (is_array($sent_to_array['groups']) and $sent_to_array['groups'][0] == 0) { - $output[] = get_lang("Everybody"); - } - } - - if (!empty($output)) { - $output = array_filter($output); - if (count($output) > 0) { - $output = implode(', ', $output); - } - return $output; - } -} - -/** - * This function displays a dropdown list that allows the course administrator do view the calendar items of one specific group - * @author: Patrick Cool , Ghent University - */ -function show_group_filter_form() -{ - $group_list = get_course_groups(); - - echo ""; -} - -/** - * This function displays a dropdown list that allows the course administrator do view the calendar items of one specific group - * @author: Patrick Cool , Ghent University - */ -function show_user_filter_form() -{ - $user_list = get_course_users(); - - echo ""; -} - -/** - * This function displays a dropdown list that allows the course administrator do view the calendar items of one specific group - * @author: Patrick Cool , Ghent University - */ -function show_user_group_filter_form() -{ - echo ""; -} - -/** - * This tools loads all the users and all the groups who have received a specific item (in this case an agenda item) - * @author: Patrick Cool , Ghent University - */ -function load_edit_users($tool, $id) -{ - $tool = Database::escape_string($tool); - $id = intval($id); - $TABLE_ITEM_PROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY); - $course_id = api_get_course_int_id(); - - $sql = "SELECT * FROM $TABLE_ITEM_PROPERTY - WHERE c_id = $course_id AND tool='$tool' AND ref= $id "; - $result = Database::query($sql); - - $to = array(); - while ($row = Database::fetch_array($result)) { - $to_group = $row['to_group_id']; - switch ($to_group) { - // it was send to one specific user - case null: - $to[] = "USER:".$row['to_user_id']; - break; - // it was sent to everyone - case 0: - return "everyone"; - exit; - break; - default: - $to[] = "GROUP:".$row['to_group_id']; - } - } - return $to; -} - -/** - * This functions swithes the visibility a course resource using the visible field in 'last_tooledit' values: 0 = invisible - * @author: Patrick Cool , Ghent University - */ -function change_visibility($tool, $id, $visibility) -{ - $_course = api_get_course_info(); - $TABLE_ITEM_PROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY); - $tool = Database::escape_string($tool); - $id = intval($id); - - if ($visibility == 0) { - $sql_visibility = "UPDATE $TABLE_ITEM_PROPERTY SET visibility='0' WHERE tool='$tool' AND ref= $id "; - api_item_property_update($_course, TOOL_CALENDAR_EVENT, $id, "invisible", api_get_user_id()); - } else { - $sql_visibility = "UPDATE $TABLE_ITEM_PROPERTY SET visibility='1' WHERE tool='$tool' AND ref= $id "; - api_item_property_update($_course, TOOL_CALENDAR_EVENT, $id, "visible", api_get_user_id()); - } -} - -/** - * The links that allows the course administrator to add a new agenda item, to filter on groups or users - * @author Patrick Cool , Ghent University - * @deprecated - */ -function display_courseadmin_links($filter = 0) -{ - if (!api_get_course_int_id()) { - $type = isset($_REQUEST['type']) ? Security::remove_XSS($_REQUEST['type']) : 'personal'; - if ($type == 'platform') { - $type = 'admin'; - } - return "".Display::return_icon('calendar.png', get_lang('Agenda'), '', ICON_SIZE_MEDIUM).""; - } - $form = null; - if (!isset($_GET['action'])) { - $form = show_to($filter, 'select_form_id_search'); - $actions = "".Display::return_icon('calendar_na.png', get_lang('Agenda'), '', ICON_SIZE_MEDIUM).""; - } else { - $actions = "".Display::return_icon('calendar.png', get_lang('Agenda'), '', ICON_SIZE_MEDIUM).""; - } - - $actions .= "".Display::return_icon('week.png', get_lang('Agenda'), '', ICON_SIZE_MEDIUM).""; - $actions .= "".Display::return_icon('new_event.png', get_lang('AgendaAdd'), '', ICON_SIZE_MEDIUM).""; - $actions .= "".Display::return_icon('import_calendar.png', get_lang('ICalFileImport'), '', ICON_SIZE_MEDIUM).""; - $actions .= $form; - return $actions; -} - -/** - * The links that allows the student AND course administrator to show all agenda items and sort up/down - * @author Patrick Cool , Ghent University - * @author Julio Montoya removing options, changing to a simple agenda tool - */ -function display_student_links() -{ - $month = isset($_GET['month']) ? intval($_GET['month']) : null; - $year = isset($_GET['year']) ? intval($_GET['year']) : null; - - $day_url = '&month='.$month.'&year='.$year; - if ($_SESSION['view'] <> 'month') { - echo "".Display::return_icon('month_empty.png', get_lang('MonthView'), '', ICON_SIZE_MEDIUM)." "; - } else { - echo "".Display::return_icon('week.png', get_lang('ListView'), '', ICON_SIZE_MEDIUM)." "; - } - $day_url = '&month='.date('m').'&year='.date('Y').'&view='.Security::remove_XSS($_GET['view']); - $today_url = api_get_self()."?action=view".$day_url."&toolgroup=".api_get_group_id(); - echo Display::url(get_lang('Today'), $today_url, array('class' => 'btn')); -} - -/** - * get all the information of the agenda_item from the database - * @author Patrick Cool , Ghent University - * @param integer the id of the agenda item we are getting all the information of - * @return array an associative array that contains all the information of the agenda item. The keys are the database fields - * @deprecated - */ -function get_agenda_item($id) -{ - global $TABLEAGENDA; - - $t_agenda_repeat = Database::get_course_table(TABLE_AGENDA_REPEAT); - $id = intval($id); - $item = array(); - if (empty($id)) { - $id = intval($_GET['id']); - } else { - $id = intval($id); - } - $course_id = api_get_course_int_id(); - if (empty($id)) { - return $item; - } - $sql = "SELECT * FROM ".$TABLEAGENDA." WHERE id = ".$id." AND c_id = $course_id "; - $result = Database::query($sql); - $entry_to_edit = Database::fetch_array($result); - $item['title'] = $entry_to_edit["title"]; - $item['content'] = $entry_to_edit["content"]; - $item['start_date'] = $entry_to_edit["start_date"]; - $item['end_date'] = $entry_to_edit["end_date"]; - $item['to'] = load_edit_users(TOOL_CALENDAR_EVENT, $id); - // if the item has been sent to everybody then we show the compact to form - if ($item['to'] == "everyone") { - $_SESSION['allow_individual_calendar'] = "hide"; - } else { - $_SESSION['allow_individual_calendar'] = "show"; - } - $item['repeat'] = false; - $sql = "SELECT * FROM $t_agenda_repeat WHERE c_id = $course_id AND cal_id = $id"; - $res = Database::query($sql); - if (Database::num_rows($res) > 0) { - //this event is repetitive - $row = Database::fetch_array($res); - $item['repeat'] = true; - $item['repeat_type'] = $row['cal_type']; - $item['repeat_end'] = $row['cal_end']; - $item['repeat_frequency'] = $row['cal_frequency']; //unused in 1.8.5 RC1 - will be used later to say if once every 2 or 3 weeks, for example - $item['repeat_days'] = $row['cal_days']; //unused in 1.8.5 RC1 - will be used later - } - - //TODO - add management of repeat exceptions - return $item; -} - -/** - * This is the function that updates an agenda item. It does 3 things - * 1. storethe start_date, end_date, title and message in the calendar_event table - * 2. store the groups/users who this message is meant for in the item_property table - * 3. modify the attachments (if needed) - * @author Patrick Cool , Ghent University - * @author Julio Montoya Adding UTC support - */ -function store_edited_agenda_item($event_id, $id_attach, $file_comment) -{ - // STEP 1: editing the calendar_event table - // 1.a. some filtering of the input data - $id = $event_id; - $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"; - $to = $_POST['selectedform']; - - if ($_POST['empty_end_date'] == 'on') { - $end_date = "0000-00-00 00:00:00"; - } - $course_info = api_get_course_info(); - - $agendaObj = new Agenda(); - if (empty($course_info)) { - $agendaObj->type = 'personal'; - } else { - $agendaObj->set_course($course_info); - $agendaObj->type = 'course'; - - if (api_is_course_coach() && !api_is_element_in_the_session(TOOL_AGENDA, $event_id)) { - return false; - } - - if (!api_is_allowed_to_edit(null, true)) { - return false; - } - } - - $all_day = isset($_REQUEST['all_day']) && !empty($_REQUEST['all_day']) ? 1 : 0; - - $agendaObj->edit_event( - $id, - $start_date, - $end_date, - $all_day, - $title, - $content - ); - - if (empty($id_attach)) { - add_agenda_attachment_file($file_comment, $id); - } else { - edit_agenda_attachment_file($file_comment, $id, $id_attach); - } - // step 3: update the attachments (=delete all and add those in the session - update_added_resources("Agenda", $id); - - // return the message; - Display::display_confirmation_message(get_lang("EditSuccess")); -} - -/** - * 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) -{ - $TABLEAGENDA = Database::get_course_table(TABLE_AGENDA); - $id = intval($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); - - // 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."'"; - $result = Database::query($sql); - return true; -} - -/** - * This is the function that deletes an agenda item. - * The agenda item is no longer physically deleted but the visibility in the item_property table is set to 2 - * which means that it is invisible for the student AND course admin. Only the platform administrator can see it. - * This will in a later stage allow the platform administrator to recover resources that were mistakenly deleted - * by the course administrator - * @author Patrick Cool , Ghent University - * @param integer the id of the agenda item wa are deleting - */ -function delete_agenda_item($id) -{ - $_course = api_get_course_info(); - $id = intval($id); - if (api_is_allowed_to_edit(false, true) OR (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous())) { - if (!empty($_GET['id']) && isset($_GET['action']) && $_GET['action'] == "delete") { - $t_agenda = Database::get_course_table(TABLE_AGENDA); - $t_agenda_r = Database::get_course_table(TABLE_AGENDA_REPEAT); - $sql = "SELECT * FROM $t_agenda_r WHERE cal_id = $id"; - $res = Database::query($sql); - if (Database::num_rows($res) > 0) { - $sql_children = "SELECT * FROM $t_agenda WHERE parent_event_id = $id"; - $res_children = Database::query($sql_children); - if (Database::num_rows($res_children) > 0) { - while ($row_child = Database::fetch_array($res_children)) { - api_item_property_update($_course, TOOL_CALENDAR_EVENT, $row_child['id'], 'delete', api_get_user_id()); - } - } - $sql_del = "DELETE FROM $t_agenda_r WHERE cal_id = $id"; - Database::query($sql_del); - } - - api_item_property_update($_course, TOOL_CALENDAR_EVENT, $id, 'delete', api_get_user_id()); - - // delete the resources that were added to this agenda item - // 2DO: as we no longer fysically delete the agenda item (to make it possible to 'restore' - // deleted items, we should not delete the added resources either. - // delete_added_resource("Agenda", $id); // -> this is no longer needed as the message is not really deleted but only visibility=2 (only platform admin can see it) - //resetting the $id; - $id = null; - - // displaying the result message in the yellow box - return Display::return_message(get_lang("AgendaDeleteSuccess"), 'confirmation'); - } - } -} - -/** - * Makes an agenda item visible or invisible for a student - * @author Patrick Cool , Ghent University - * @param integer id the id of the agenda item we are changing the visibility of - */ -function showhide_agenda_item($id) -{ - global $nameTools; - /* - SHOW / HIDE A CALENDAR ITEM - */ - // and $_GET['isStudentView']<>"false" is added to prevent that the visibility is changed after you do the following: - // change visibility -> studentview -> course manager view - if ((api_is_allowed_to_edit(false, true) OR (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous())) and $_GET['isStudentView'] <> "false") { - if (isset($_GET['id']) && isset($_GET['action']) && $_GET['action'] == "showhide") { - $id = intval($_GET['id']); - if (isset($_GET['next_action']) && $_GET['next_action'] == strval(intval($_GET['next_action']))) { - $visibility = $_GET['next_action']; - change_visibility($nameTools, $id, $visibility); - return Display::return_message(get_lang("VisibilityChanged"), 'confirmation'); - } - } - } -} - -/** - * Displays all the agenda items - * @author Patrick Cool , Ghent University - * @author Yannick Warnier - cleanup - * @author Julio Montoya - Refactoring - */ -function display_agenda_items($agenda_items, $day = false) -{ - global $charset; - if (isset($day) && $day) { - $new_items = array(); - foreach ($agenda_items as $item) { - if (substr($item['start_date'], 8, 2) == $day) { - $new_items[] = $item; - } - } - $agenda_items = $new_items; - } - - if (isset($_GET['sort']) && $_GET['sort'] == 'asc') { - $sort_inverse = 'desc'; - $sort = 'asc'; - } else { - $sort_inverse = 'asc'; - $sort = 'desc'; - } - - if (isset($_GET['col']) && $_GET['col'] == 'end') { - $sort_item = 'end_date_tms'; - $col = 'end'; - } else { - $sort_item = 'start_date_tms'; - $col = 'start'; - } - - $agenda_items = msort($agenda_items, $sort_item, $sort); - - //DISPLAY: NO ITEMS - if (empty($agenda_items)) { - echo Display::display_warning_message(get_lang('NoAgendaItems')); - } else { - echo ''; - $th = Display::tag('th', get_lang('Title')); - - $month = isset($_GET['month']) ? intval($_GET['month']) : null; - $year = isset($_GET['year']) ? intval($_GET['year']) : null; - $day = isset($_GET['day']) ? intval($_GET['day']) : null; - - - $url = api_get_self().'?'.api_get_cidreq().'&month='.$month.'&year='.$year.'&day='.$day; - - $th .= Display::tag('th', Display::url(get_lang('StartTimeWindow'), $url.'&sort='.$sort_inverse.'&col=start')); - $th .= Display::tag('th', Display::url(get_lang('EndTimeWindow'), $url.'&sort='.$sort_inverse.'&col=end')); - - if ((api_is_allowed_to_edit(false, true) OR (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous()))) { - $th .= Display::tag('th', get_lang('Modify')); - } - - echo Display::tag('tr', $th); - $counter = 0; - foreach ($agenda_items as $myrow) { - $is_repeated = !empty($myrow['parent_event_id']); - - $class = 'row_even'; - if ($counter % 2) { - $class = 'row_odd'; - } - /* display: the icon, title, destinees of the item */ - echo ''; - - //Title - echo "'; - - //Start date - echo ''; - - //End date - echo ''; - - /* 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())) && $myrow['calendar_type'] == 'course') { - echo ''; - } else { - if ($is_repeated && (api_is_allowed_to_edit(false, true) || api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous() )) { - echo ''; - } - if ((api_is_allowed_to_edit(false, true) || (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous()) ) && ($myrow['calendar_type'] == 'personal' OR $myrow['calendar_type'] == 'global')) { - echo ''; - } - } - $counter++; - echo ""; - } // end while ($myrow=Database::fetch_array($result)) - echo "
"; - $attach_icon = ''; - - // attachment list - $attachment_list = get_attachment($myrow['id']); - - if (!empty($attachment_list)) { - $attach_icon = ' '.Display::return_icon('attachment.gif', get_lang('Attachment')); - } - $title_class = ''; - if (isset($myrow['visibility']) && $myrow['visibility'] == 0) { - $title_class = 'invisible'; - } - - switch ($myrow['calendar_type']) { - case 'global': - $icon_type = Display::return_icon('view_remove.png', get_lang('GlobalEvent'), array(), 22); - echo $icon_type.' '.$myrow['title'].$attach_icon; - break; - case 'personal': - $icon_type = Display::return_icon('user.png', get_lang(' '), array(), 22); - echo $icon_type.' '.$myrow['title'].$attach_icon; - break; - case 'course': - $icon_type = Display::return_icon('course.png', get_lang('Course'), array(), 22); - $agenda_url = api_get_path(WEB_CODE_PATH).'calendar/agenda.php?agenda_id='.$myrow['id'].'&action=view'; - echo Display::url($icon_type.' '.$myrow['title'].$attach_icon, $agenda_url, array('class' => $title_class)); - break; - } - echo ''; - if (!empty($myrow['start_date']) && $myrow['start_date'] != '0000-00-00 00:00:00') { - echo api_format_date($myrow['start_date']); - } - echo ''; - if (!empty($myrow['end_date']) && $myrow['end_date'] != '0000-00-00 00:00:00') { - echo api_format_date($myrow['end_date']); - } - echo ''; - 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'].'&sort='.$sort.'&col='.$col.'&'; - - // edit - echo ''; - echo Display::return_icon('edit.png', get_lang('ModifyCalendarItem'), '', ICON_SIZE_SMALL).""; - - echo ''; - echo Display::return_icon('new_announce.png', get_lang('AddAnnouncement'), array(), ICON_SIZE_SMALL)." "; - - if ($myrow['visibility'] == 1) { - $image_visibility = "visible"; - $text_visibility = get_lang("Hide"); - $next_action = 0; - } else { - $image_visibility = "invisible"; - $text_visibility = get_lang("Show"); - $next_action = 1; - } - echo ''.Display::return_icon($image_visibility.'.png', $text_visibility, '', ICON_SIZE_SMALL).' '; - echo " "; - echo Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL)." "; - } - - $mylink = 'ical_export.php?'.api_get_cidreq().'&type=course&id='.$myrow['id']; - //echo ''.Display::return_icon($export_icon_high, get_lang('ExportiCalConfidential')).' '; - //echo ''.Display::return_icon($export_icon_low, get_lang('ExportiCalPrivate')).' '; - //echo ''.Display::return_icon($export_icon, get_lang('ExportiCalPublic')).' '; - echo ''.Display::return_icon('printer.png', get_lang('Print'), '', ICON_SIZE_SMALL).' '; - echo ''; - echo get_lang('RepeatedEvent'), ' ', get_lang('RepeatedEventViewOriginalEvent'), ''; - echo ''; - echo '


"; - } - - if (!empty($event_list)) { - $event_list = api_substr($event_list, 0, -1); - } else { - $event_list = '0'; - } - echo "
"; - - // closing the layout table - echo "", - "", - ""; -} - -/** - * Show a list with all the attachments according to the post's id - * @param the post's id - * @return array with the post info - * @author Christian Fasanando - * @version November 2008, dokeos 1.8.6 - */ -function get_attachment($agenda_id, $course_id = null) -{ - $agenda_table_attachment = Database::get_course_table(TABLE_AGENDA_ATTACHMENT); - if (empty($course_id)) { - $course_id = api_get_course_int_id(); - } else { - $course_id = intval($course_id); - } - $agenda_id = intval($agenda_id); - $row = array(); - $sql = 'SELECT id,path, filename,comment FROM '.$agenda_table_attachment.' WHERE c_id = '.$course_id.' AND agenda_id = '.$agenda_id.''; - $result = Database::query($sql); - if (Database::num_rows($result) != 0) { - $row = Database::fetch_array($result); - } - return $row; -} - -/** - * Show the form for adding a new agenda item. This is the same function that is used whenever we are editing an - * agenda item. When the id parameter is empty (default behaviour), then we show an empty form, else we are editing and - * we have to retrieve the information that is in the database and use this information in the forms. - * @author Patrick Cool , Ghent University - * @param integer id, the id of the agenda item we are editing. By default this is empty which means that we are adding an - * agenda item. - * @deprecated - */ -function show_add_form($id = '', $type = null) -{ - $htmlHeadXtra[] = to_javascript(); - $course_info = null; - $agendaObj = new Agenda(); - - // if the id is set then we are editing an agenda item - if (!empty($id)) { - $course_info = api_get_course_info(); - if (!empty($course_info)) { - $agendaObj->set_course($course_info); - $agendaObj->type = 'course'; - } else { - if (api_is_platform_admin() && $type == 'platform') { - $agendaObj->type = 'admin'; - } else { - $agendaObj->type = 'personal'; - } - } - $agendaItem = $agendaObj->get_event($id); - - $title = $agendaItem['title']; - $content = $agendaItem['description']; - - // start date - if ($agendaItem['start_date'] != '0000-00-00 00:00:00') { - $agendaItem['start_date'] = api_get_local_time($agendaItem['start_date']); - list($datepart, $timepart) = explode(" ", $agendaItem['start_date']); - list($year, $month, $day) = explode("-", $datepart); - list($hours, $minutes, $seconds) = explode(":", $timepart); - } - - // end date - if (!empty($agendaItem['end_date']) && $agendaItem['end_date'] != '0000-00-00 00:00:00') { - - $agendaItem['end_date'] = api_get_local_time($agendaItem['end_date']); - list($datepart, $timepart) = explode(" ", $agendaItem['end_date']); - list($end_year, $end_month, $end_day) = explode("-", $datepart); - list($end_hours, $end_minutes, $end_seconds) = explode(":", $timepart); - } else { - if ($agendaItem['all_day']) { - $end_year = $year; - $end_month = $month; - $end_day = $day; - $end_hours = $hours; - $end_minutes = $minutes; - $end_seconds = $seconds; - } - } - // attachments - //edit_added_resources("Agenda", $id); - //$to = $item_2_edit['to']; - } else { - $to = load_edit_users(TOOL_CALENDAR_EVENT, $id); - } - - // we start a completely new item, we do not come from the resource linker - if (isset($_GET['originalresource']) && $_GET['originalresource'] !== "no" and $_GET['action'] == "add") { - $_SESSION["formelements"] = null; - unset_session_resources(); - } - $origin = isset($_GET['origin']) ? Security::remove_XSS($_GET['origin']) : null; - $action = isset($_GET['action']) ? Security::remove_XSS($_GET['action']) : null; - $idAttach = isset($_GET['id_attach']) ? Security::remove_XSS($_GET['id_attach']) : null; - $course_url = empty($course_info) ? null : api_get_cidreq(); - $id = isset($id) ? intval($id) : null; - - $url = api_get_self().'?type='.Security::remove_XSS($type).'&origin='.$origin.'&'.$course_url.'&sort=asc&toolgroup='.api_get_group_id().'&action='.Security::remove_XSS($_GET['action']); - $form = new FormValidator('new_calendar_item', 'post', $url, null, array('enctype' => 'multipart/form-data')); - $form->addElement('hidden', 'id', $id); - $form->addElement('hidden', 'action', $action); - $form->addElement('hidden', 'id_attach', $idAttach); - $form->addElement('hidden', 'sort', 'asc'); - $form->addElement('hidden', 'submit_event', 'ok'); - - // The form title - if (isset($id) AND $id <> '') { - $form_title = get_lang('ModifyCalendarItem'); - } else { - $form_title = get_lang('AddCalendarItem'); - } - - $form->addElement('header', $form_title); - $form->addElement('text', 'title', get_lang('ItemTitle')); - - // selecting the users / groups - $group_id = api_get_group_id(); - if (empty($id)) { - if (isset($group_id) && !empty($group_id)) { - $form->addElement('hidden', 'selected_form[0]', "GROUP:'.$group_id.'"); - $form->addElement('hidden', 'To', 'true'); - //$form .= ''; - //$form .= ''; - } else { - $agendaObj->show_to_form($form, $to); - } - } - - // start date and time - - $form->addElement('text', 'start_date', get_lang('StartDate')); - $form->addElement('text', 'end_date', get_lang('EndDate')); - - // Repeating the calendar item - if (empty($id)) { - $form->addElement( - 'label', - null, - ' -  '.get_lang('RepeatEvent').' - ' - ); - $form->addElement('html', ''); - } - - - if (isset($agendaItem['all_day'])) { - $checked = null; - if ($agendaItem['all_day']) { - $checked = 'checked'; - } - $form->addElement('checkbox', 'all_day', get_lang('AllDay')); - } - - $form->addElement('html_editor', 'content', get_lang('Description')); - $form->addElement('checkbox', 'add_announcement', get_lang('AddAnnouncement').' ('.get_lang('SendMail').')'); - - if ($agendaObj->type == 'course') { - // File attachment - $form->addElement('file', 'user_upload', get_lang('AddAnAttachment')); - $form->addElement('textarea', 'file_comment', get_lang('Comment')); - $form->add_progress_bar(); - } - - if (isset($_GET['id'])) { - $text = get_lang('ModifyEvent'); - } else { - $text = get_lang('AgendaAdd'); - } - $form->addElement('button', 'submit', $text); - return $form->return_form(); -} - - /** - * This function calculates the startdate of the week (monday) - * and the enddate of the week (sunday) - * and returns it as an array - * @todo check if this function is correct - */ - function calculate_start_end_of_week($week_number, $year) - { - // determine the start and end date - // step 1: we calculate a timestamp for a day in this week - //@todo Why ($week_number - 1) ? - //$random_day_in_week = mktime(0, 0, 0, 1, 1, $year) + ($week_number-1) * (7 * 24 * 60 * 60); // we calculate a random day in this week - $random_day_in_week = mktime(0, 0, 0, 1, 1, $year) + ($week_number) * (7 * 24 * 60 * 60); // we calculate a random day in this week - // step 2: we which day this is (0=sunday, 1=monday, ...) - $number_day_in_week = date('w', $random_day_in_week); - // step 3: we calculate the timestamp of the monday of the week we are in - $start_timestamp = $random_day_in_week - (($number_day_in_week - 1) * 24 * 60 * 60); - // step 4: we calculate the timestamp of the sunday of the week we are in - $end_timestamp = $random_day_in_week + ((7 - $number_day_in_week + 1) * 24 * 60 * 60) - 3600; - // step 5: calculating the start_day, end_day, start_month, end_month, start_year, end_year - $start_day = date('j', $start_timestamp); - $start_month = date('n', $start_timestamp); - $start_year = date('Y', $start_timestamp); - $end_day = date('j', $end_timestamp); - $end_month = date('n', $end_timestamp); - $end_year = date('Y', $end_timestamp); - $start_end_array['start']['day'] = $start_day; - $start_end_array['start']['month'] = $start_month; - $start_end_array['start']['year'] = $start_year; - $start_end_array['end']['day'] = $end_day; - $start_end_array['end']['month'] = $end_month; - $start_end_array['end']['year'] = $end_year; - return $start_end_array; - } - - /** - * Show the mini calendar of the given month - * @deprecated - */ - function display_daycalendar($agendaitems, $day, $month, $year, $weekdaynames, $monthName) - { - global $DaysShort, $DaysLong, $course_path; - global $MonthsLong; - global $query; - - // timestamp of today - $today = mktime(); - $nextday = $today + (24 * 60 * 60); - $previousday = $today - (24 * 60 * 60); - // the week number of the year - $week_number = date("W", $today); - // if we moved to the next / previous day we have to recalculate the $today variable - if (isset($_GET['day'])) { - $today = mktime(0, 0, 0, $month, $day, $year); - $nextday = $today + (24 * 60 * 60); - $previousday = $today - (24 * 60 * 60); - $week_number = date("W", $today); - } - - // calculating the start date of the week - // the date of the monday of this week is the timestamp of today minus - // number of days that have already passed this week * 24 hours * 60 minutes * 60 seconds - $current_day = date("j", $today); // Day of the month without leading zeros (1 to 31) of today - $day_of_the_week = date("w", $today); // Numeric representation of the day of the week 0 (for Sunday) through 6 (for Saturday) of today - // we are loading all the calendar items of all the courses for today - echo ""; - // the forward and backwards url - $course_code = isset($_GET['courseCode']) ? Security::remove_XSS($_GET['courseCode']) : null; - $backwardsURL = api_get_self()."?coursePath=".urlencode($course_path)."&courseCode=".$course_code."&action=view&view=day&day=".date("j", $previousday)."&month=".date("n", $previousday)."&year=".date("Y", $previousday); - $forewardsURL = api_get_self()."?coursePath=".urlencode($course_path)."&courseCode=".$course_code."&action=view&view=day&day=".date("j", $nextday)."&month=".date("n", $nextday)."&year=".date("Y", $nextday); - // The title row containing the day - echo "", "", ""; - echo ""; - echo ""; - - // From 0 to 5h - $class = "class=\"row_even\""; - echo ""; - echo (""); - echo ""; - echo ""; - - // the rows for each half an hour - for ($i = 10; $i < 48; $i++) { - if ($i % 2 == 0) { - $class = "class=\"row_even\""; - } else { - $class = "class=\"row_odd\""; - } - echo ""; - echo ""; - if ($i % 2 == 0) { - echo (""); - } else { - echo (""); - } - echo ""; - echo ""; - } - echo "
".Display::return_icon('action_prev.png', get_lang('Previous')).""; - echo $DaysLong[$day_of_the_week]." ".date("j", $today)." ".$MonthsLong[date("n", $today) - 1]." ".date("Y", $today); - echo "".Display::return_icon('action_next.png', get_lang('Next'))."
0:00 ".get_lang("HourShort")." - 4:30 ".get_lang("HourShort").""; - for ($i = 0; $i < 10; $i++) { - if (isset($agendaitems[$i])) { - if (is_array($agendaitems[$i])) { - foreach ($agendaitems[$i] as $key => $value) { - echo $value; - } - } else { - echo $agendaitems[$i]; - } - } - } - echo "
".(($i) / 2)." ".get_lang("HourShort")." 00".((($i) / 2) - (1 / 2))." ".get_lang("HourShort")." 30"; - if (isset($agendaitems[$i])) { - if (is_array($agendaitems[$i])) { - foreach ($agendaitems[$i] as $key => $value) { - echo $value; - } - } else { - echo $agendaitems[$i]; - } - } - echo "
"; - } - - /** - * Display the weekly view of the calendar - * @deprecated - */ - function display_weekcalendar($agendaitems, $month, $year, $weekdaynames, $monthName) - { - - global $DaysShort, $course_path; - global $MonthsLong; - - // timestamp of today - $today = time(); - $day_of_the_week = date("w", $today); - $thisday_of_the_week = date("w", $today); - // the week number of the year - $week_number = date("W", $today); - $thisweek_number = $week_number; - // if we moved to the next / previous week we have to recalculate the $today variable - - if (!isset($_GET['week'])) { - $week_number = date("W", $today); - } else { - $week_number = intval($_GET['week']); - } - - // calculating the start date of the week - // the date of the monday of this week is the timestamp of today minus - // number of days that have already passed this week * 24 hours * 60 minutes * 60 seconds - $current_day = date("j", $today); // Day of the month without leading zeros (1 to 31) of today - $day_of_the_week = date("w", $today); // Numeric representation of the day of the week 0 (for Sunday) through 6 (for Saturday) of today - //Using the same script to calculate the start/end of a week - $start_end = calculate_start_end_of_week($week_number, $year); - - $timestamp_first_date_of_week = mktime(0, 0, 0, $start_end['start']['month'], $start_end['start']['day'], $start_end['start']['year']); - $timestamp_last_date_of_week = mktime(0, 0, 0, $start_end['end']['month'], $start_end['end']['day'], $start_end['end']['year']); - - $backwardsURL = api_get_self()."?coursePath=".urlencode($course_path)."&courseCode=".api_get_course_id()."&action=view&view=week&week=".($week_number - 1); - $forewardsURL = api_get_self()."?coursePath=".urlencode($course_path)."&courseCode=".api_get_course_id()."&action=view&view=week&week=".($week_number + 1); - - echo ''; - // The title row containing the the week information (week of the year (startdate of week - enddate of week) - echo ''; - echo ""; - echo ""; - echo "", ""; - // The second row containing the short names of the days of the week - echo ""; - - //Printing the week days - // this is the Day of the month without leading zeros (1 to 31) of the monday of this week - $tmp_timestamp = $timestamp_first_date_of_week; - for ($ii = 1; $ii < 8; $ii++) { - $is_today = ($ii == $thisday_of_the_week AND (!isset($_GET['week']) OR $_GET['week'] == $thisweek_number)); - echo ""; - // we 24 hours * 60 minutes * 60 seconds to the $tmp_timestamp - $array_tmp_timestamp[] = $tmp_timestamp; - $tmp_timestamp = $tmp_timestamp + (24 * 60 * 60); - } - echo ""; - - // The table cells containing all the entries for that day - echo ""; - $counter = 0; - - foreach ($array_tmp_timestamp as $key => $value) { - if ($counter < 5) { - $class = "class=\"days_week\""; - } else { - $class = "class=\"days_weekend\""; - } - if ($counter == $thisday_of_the_week - 1 AND (!isset($_GET['week']) OR $_GET['week'] == $thisweek_number)) { - $class = "class=\"days_today\""; - } - echo ""; - $counter++; - } - echo ""; - echo "
".Display::return_icon('action_prev.png', get_lang('Previous'))."".get_lang("Week")." ".$week_number; - echo " (".$DaysShort['1']." ".date("j", $timestamp_first_date_of_week)." ".$MonthsLong[date("n", $timestamp_first_date_of_week) - 1]." ".date("Y", $timestamp_first_date_of_week)." - ".$DaysShort['0']." ".date("j", $timestamp_last_date_of_week)." ".$MonthsLong[date("n", $timestamp_last_date_of_week) - 1]." ".date("Y", $timestamp_last_date_of_week).')'; - echo "".Display::return_icon('action_next.png', get_lang('Next'))."
"; - if ($is_today) { - echo ""; - } - echo $DaysShort[$ii % 7]." ".date("j", $tmp_timestamp)." ".$MonthsLong[date("n", $tmp_timestamp) - 1]; - if ($is_today) { - echo ""; - } - echo "
"; - $data = isset($agendaitems[date('j', $value)]) ? $agendaitems[date('j', $value)] : null; - echo "".$data."  "; - echo "
"; - } - - /** - * Show the monthcalender of the given month - * @deprecated - */ - function get_day_agendaitems($courses_dbs, $month, $year, $day) - { - global $setting_agenda_link; - - $items = array(); - - // get agenda-items for every course - //$query=Database::query($sql_select_courses); - foreach ($courses_dbs as $key => $array_course_info) { - //echo $array_course_info['db']; - //databases of the courses - $TABLEAGENDA = Database :: get_course_table(TABLE_AGENDA); - $TABLE_ITEMPROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY); - - // getting all the groups of the user for the current course - $group_memberships = GroupManager :: get_group_ids($array_course_info['real_id'], api_get_user_id()); - $course_user_status = CourseManager::get_user_in_course_status(api_get_user_id(), $array_course_info['code']); - - - $start_filter = $year."-".$month."-".$day." 00:00:00"; - $start_filter = api_get_utc_datetime($start_filter); - $end_filter = $year."-".$month."-".$day." 23:59:59"; - $end_filter = api_get_utc_datetime($end_filter); - - - // if the user is administrator of that course we show all the agenda items - if ($course_user_status == '1') { - //echo "course admin"; - $sqlquery = "SELECT - DISTINCT agenda.*, item_property.* - FROM ".$TABLEAGENDA." agenda, - ".$TABLE_ITEMPROPERTY." item_property - WHERE agenda.id = item_property.ref - AND start_date>='".$start_filter."' AND start_date<='".$end_filter."' - AND item_property.tool='".TOOL_CALENDAR_EVENT."' - AND item_property.visibility='1' - GROUP BY agenda.id - ORDER BY start_date "; - } - // if the user is not an administrator of that course - else { - //echo "course admin"; - if (is_array($group_memberships) && count($group_memberships) > 0) { - $sqlquery = "SELECT - agenda.*, item_property.* - FROM ".$TABLEAGENDA." agenda, - ".$TABLE_ITEMPROPERTY." item_property - WHERE agenda.id = item_property.ref - AND start_date>='".$start_filter."' AND start_date<='".$end_filter."' - AND item_property.tool='".TOOL_CALENDAR_EVENT."' - AND ( item_property.to_user_id='".api_get_user_id()."' OR item_property.to_group_id IN (0, ".implode(", ", $group_memberships).") ) - AND item_property.visibility='1' - ORDER BY start_date "; - } else { - $sqlquery = "SELECT - agenda.*, item_property.* - FROM ".$TABLEAGENDA." agenda, - ".$TABLE_ITEMPROPERTY." item_property - WHERE agenda.id = item_property.ref - AND start_date>='".$start_filter."' AND start_date<='".$end_filter."' - AND item_property.tool='".TOOL_CALENDAR_EVENT."' - AND ( item_property.to_user_id='".api_get_user_id()."' OR item_property.to_group_id='0') - AND item_property.visibility='1' - ORDER BY start_date "; - } - } - - $result = Database::query($sqlquery); - while ($item = Database::fetch_array($result)) { - // in the display_daycalendar function we use $i (ranging from 0 to 47) for each halfhour - // we want to know for each agenda item for this day to wich halfhour it must be assigned - $item['start_date'] = api_get_local_time($item['start_date']); - $time_minute = api_format_date($item['start_date'], TIME_NO_SEC_FORMAT); - - list ($datepart, $timepart) = explode(" ", $item['start_date']); - list ($year, $month, $day) = explode("-", $datepart); - list ($hours, $minutes, $seconds) = explode(":", $timepart); - - $halfhour = 2 * $hours; - if ($minutes >= '30') { - $halfhour = $halfhour + 1; - } - - if ($setting_agenda_link == 'coursecode') { - $title = $array_course_info['title']; - $agenda_link = cut($title, 14, true); - } else { - $agenda_link = Display::return_icon('course_home.png', ' ', '', ICON_SIZE_SMALL); - } - $URL = api_get_path(WEB_CODE_PATH).'calendar/agenda.php?cidReq='.urlencode($array_course_info["code"])."&day=$day&month=$month&year=$year#$day"; // RH //Patrick Cool: to highlight the relevant agenda item - - $items[$halfhour][] .= "$time_minute ".$agenda_link." ".$item['title']."
"; - } - } - - // sorting by hour for every day - $agendaitems = array(); - while (list($agendaday, $tmpitems) = each($items)) { - sort($tmpitems); - while (list($key, $val) = each($tmpitems)) { - $agendaitems[$agendaday].=$val; - } - } - return $agendaitems; - } - - /** - * Return agenda items of the week - * @deprecated - */ - function get_week_agendaitems($courses_dbs, $month, $year, $week = '') - { - global $setting_agenda_link; - - $TABLEAGENDA = Database :: get_course_table(TABLE_AGENDA); - $TABLE_ITEMPROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY); - - $items = array(); - // The default value of the week - if ($week == '') { - $week_number = date("W", time()); - } else { - $week_number = $week; - } - - $start_end = calculate_start_end_of_week($week_number, $year); - - $start_filter = $start_end['start']['year']."-".$start_end['start']['month']."-".$start_end['start']['day']." 00:00:00"; - $start_filter = api_get_utc_datetime($start_filter); - $end_filter = $start_end['end']['year']."-".$start_end['end']['month']."-".$start_end['end']['day']." 23:59:59"; - $end_filter = api_get_utc_datetime($end_filter); - - // get agenda-items for every course - foreach ($courses_dbs as $key => $array_course_info) { - //databases of the courses - $TABLEAGENDA = Database :: get_course_table(TABLE_AGENDA); - $TABLE_ITEMPROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY); - - // getting all the groups of the user for the current course - $group_memberships = GroupManager :: get_group_ids($array_course_info["real_id"], api_get_user_id()); - - $user_course_status = CourseManager::get_user_in_course_status(api_get_user_id(), $array_course_info["code"]); - - // if the user is administrator of that course we show all the agenda items - if ($user_course_status == '1') { - //echo "course admin"; - $sqlquery = "SELECT - DISTINCT a.*, i.* - FROM ".$TABLEAGENDA." a, - ".$TABLE_ITEMPROPERTY." i - WHERE a.id = i.ref - AND a.start_date>='".$start_filter."' AND a.start_date<='".$end_filter."' - AND i.tool='".TOOL_CALENDAR_EVENT."' - AND i.visibility='1' - GROUP BY a.id - ORDER BY a.start_date"; - } - // if the user is not an administrator of that course - else { - //echo "GEEN course admin"; - if (is_array($group_memberships) && count($group_memberships) > 0) { - $sqlquery = "SELECT - a.*, i.* - FROM ".$TABLEAGENDA." a, - ".$TABLE_ITEMPROPERTY." i - WHERE a.id = i.ref - AND a.start_date>='".$start_filter."' AND a.start_date<='".$end_filter."' - AND i.tool='".TOOL_CALENDAR_EVENT."' - AND ( i.to_user_id='".api_get_user_id()."' OR i.to_group_id IN (0, ".implode(", ", $group_memberships).") ) - AND i.visibility='1' - ORDER BY a.start_date"; - } else { - $sqlquery = "SELECT - a.*, i.* - FROM ".$TABLEAGENDA." a, - ".$TABLE_ITEMPROPERTY." i - WHERE a.id = i.ref - AND a.start_date>='".$start_filter."' AND a.start_date<='".$end_filter."' - AND i.tool='".TOOL_CALENDAR_EVENT."' - AND ( i.to_user_id='".api_get_user_id()."' OR i.to_group_id='0') - AND i.visibility='1' - ORDER BY a.start_date"; - } - } - $result = Database::query($sqlquery); - while ($item = Database::fetch_array($result)) { - $agendaday_string = api_convert_and_format_date($item['start_date'], "%d", date_default_timezone_get()); - $agendaday = intval($agendaday_string); - $start_time = api_convert_and_format_date($item['start_date'], TIME_NO_SEC_FORMAT); - $end_time = api_convert_and_format_date($item['end_date'], DATE_TIME_FORMAT_LONG); - - if ($setting_agenda_link == 'coursecode') { - $title = $array_course_info['title']; - $agenda_link = cut($title, 14, true); - } else { - $agenda_link = Display::return_icon('course_home.png', ' ', '', ICON_SIZE_SMALL); - } - - $URL = api_get_path(WEB_CODE_PATH)."calendar/agenda.php?cidReq=".urlencode($array_course_info["code"])."&day=$agendaday&month=$month&year=$year#$agendaday"; // RH //Patrick Cool: to highlight the relevant agenda item - //Display the events in agenda - $content = "$start_time - $end_time
".$agenda_link."
"; - $content .= "
".$item['title']."

"; - $items[$agendaday][$item['start_date']] .= $content; - } - } - - $agendaitems = array(); - // sorting by hour for every day - while (list ($agendaday, $tmpitems) = each($items)) { - sort($tmpitems); - while (list ($key, $val) = each($tmpitems)) { - $agendaitems[$agendaday] .= $val; - } - } - - return $agendaitems; - } - - /** - * Get repeated events of a course between two dates (timespan of a day). - * Returns an array containing the events - * @param string Course info array (as returned by api_get_course_info()) - * @param int UNIX timestamp of span start. Defaults 0, later transformed into today's start - * @param int UNIX timestamp. Defaults to 0, later transformed into today's end - * @param array A set of parameters to alter the SQL query - * @return array [int] => [course_id,parent_event_id,start_date,end_date,title,description] - */ - function get_repeated_events_day_view($course_info, $start = 0, $end = 0, $params) - { - $events = array(); - //initialise all values - $y = 0; - $m = 0; - $d = 0; - //block $end if higher than 2038 -- PHP doesn't go past that - if ($end > 2145934800) { - $end = 2145934800; - } - if ($start == 0 or $end == 0) { - $y = date('Y'); - $m = date('m'); - $d = date('j'); - } - if ($start == 0) { - $start = mktime(0, 0, 0, $m, $d, $y); - } - $db_start = date('Y-m-d H:i:s', $start); - if ($end == 0) { - $end = mktime(23, 59, 59, $m, $d, $y); - } - //$db_end = date('Y-m-d H:i:s',$end); - - $t_cal = Database::get_course_table(TABLE_AGENDA, $course_info['dbName']); - $t_cal_repeat = Database::get_course_table(TABLE_AGENDA_REPEAT, $course_info['dbName']); - $t_ip = Database::get_course_table(TABLE_ITEM_PROPERTY, $course_info['dbName']); - $sql = "SELECT c.id, c.title, c.content, ". - " UNIX_TIMESTAMP(c.start_date) as orig_start, UNIX_TIMESTAMP(c.end_date) as orig_end, ". - " cr.cal_type, cr.cal_end ". - " FROM $t_cal c, $t_cal_repeat cr, $t_ip as item_property ". - " WHERE cr.cal_end >= $start ". - " AND cr.cal_id = c.id ". - " AND item_property.ref = c.id ". - " AND item_property.tool = '".TOOL_CALENDAR_EVENT."' ". - " AND c.start_date <= '$db_start' " - .(!empty($params['conditions']) ? $params['conditions'] : '') - .(!empty($params['groupby']) ? ' GROUP BY '.$params['groupby'] : '') - .(!empty($params['orderby']) ? ' ORDER BY '.$params['orderby'] : ''); - $res = Database::query($sql); - if (Database::num_rows($res) > 0) { - while ($row = Database::fetch_array($res)) { - $orig_start = $row['orig_start']; - $orig_end = $row['orig_end']; - $repeat_type = $row['cal_type']; - switch ($repeat_type) { - case 'daily': - //we are in the daily view, so if this element is repeated daily and - //the repetition is still active today (which is a condition of the SQL query) - //then the event happens today. Just build today's timestamp for start and end - $time_orig_h = date('H', $orig_start); - $time_orig_m = date('i', $orig_start); - $time_orig_s = date('s', $orig_start); - $int_time = (($time_orig_h * 60) + $time_orig_m) * 60 + $time_orig_s; //time in seconds since 00:00:00 - $span = $orig_end - $orig_start; //total seconds between start and stop of original event - $current_start = $start + $int_time; //unixtimestamp start of today's event - $current_stop = $start + $int_time + $span; //unixtimestamp stop of today's event - $events[] = array($course_info['id'], $row['id'], $current_start, $current_stop, $row['title'], $row['content']); - break; - case 'weekly': - $time_orig = date('Y/n/W/j/N/G/i/s', $orig_start); - list($y_orig, $m_orig, $w_orig, $d_orig, $dw_orig, $h_orig, $n_orig, $s_orig) = split('/', $time_orig); - $time_now = date('Y/n/W/j/N/G/i/s', $end); - list($y_now, $m_now, $w_now, $d_now, $dw_now, $h_now, $n_now, $s_now) = split('/', $time_now); - if ((($y_now > $y_orig) OR (($y_now == $y_orig) && ($w_now > $w_orig))) && ($dw_orig == $dw_now)) { //if the event is after the original (at least one week) and the day of the week is the same - $time_orig_end = date('Y/n/W/j/N/G/i/s', $orig_end); - list($y_orig_e, $m_orig_e, $w_orig_e, $d_orig_e, $dw_orig_e, $h_orig_e, $n_orig_e, $s_orig_e) = split('/', $time_orig_end); - $events[] = array($course_info['id'], $row['id'], mktime($h_orig, $n_orig, $s_orig, $m_now, $d_orig, $y_now), mktime($h_orig_e, $n_orig_e, $s_orig_e, $m_now, $d_orig_e, $y_now), $row['title'], $row['content']); - } - break; - case 'monthlyByDate': - $time_orig = date('Y/n/j/G/i/s', $orig_start); - list($y_orig, $m_orig, $d_orig, $h_orig, $n_orig, $s_orig) = split('/', $time_orig); - $time_now = date('Y/n/j/G/i/s', $end); - list($y_now, $m_now, $d_now, $h_now, $n_now, $s_now) = split('/', $time_now); - if ((($y_now > $y_orig) OR (($y_now == $y_orig) && ($m_now > $m_orig))) && ($d_orig == $d_now)) { - $time_orig_end = date('Y/n/j/G/i/s', $orig_end); - list($y_orig_e, $m_orig_e, $d_orig_e, $h_orig_e, $n_orig_e, $s_orig_e) = split('/', $time_orig_end); - $events[] = array($course_info['id'], $row['id'], mktime($h_orig, $n_orig, $s_orig, $m_now, $d_orig, $y_now), mktime($h_orig_e, $n_orig_e, $s_orig_e, $m_now, $d_orig_e, $y_now), $row['title'], $row['content']); - } - break; - case 'monthlyByDayR': - //not implemented yet - break; - case 'monthlyByDay': - //not implemented yet - break; - case 'yearly': - $time_orig = date('Y/n/j/z/G/i/s', $orig_start); - list($y_orig, $m_orig, $d_orig, $dy_orig, $h_orig, $n_orig, $s_orig) = split('/', $time_orig); - $time_now = date('Y/n/j/z/G/i/s', $end); - list($y_now, $m_now, $d_now, $dy_now, $h_now, $n_now, $s_now) = split('/', $time_now); - if (($y_now > $y_orig) && ($dy_orig == $dy_now)) { - $time_orig_end = date('Y/n/j/G/i/s', $orig_end); - list($y_orig_e, $m_orig_e, $d_orig_e, $dy_orig_e, $h_orig_e, $n_orig_e, $s_orig_e) = split('/', $time_orig_end); - $events[] = array($course_info['id'], $row['id'], mktime($h_orig, $n_orig, $s_orig, $m_now, $d_orig, $y_now), mktime($h_orig_e, $n_orig_e, $s_orig_e, $m_now, $d_orig_e, $y_now), $row['title'], $row['content']); - } - break; - default: - break; - } - } - } - return $events; - } - - /** - * (This function is not been use in the code) - * Get repeated events of a course between two dates (timespan of a week). - * Returns an array containing the events - * @param string Course info array (as returned by api_get_course_info()) - * @param int UNIX timestamp of span start. Defaults 0, later transformed into today's start - * @param int UNIX timestamp. Defaults to 0, later transformed into today's end - * @param array A set of parameters to alter the SQL query - * @return array [int] => [course_id,parent_event_id,start_date,end_date,title,description] - */ - function get_repeated_events_week_view($course_info, $start = 0, $end = 0, $params) - { - $events = array(); - //block $end if higher than 2038 -- PHP doesn't go past that - if ($end > 2145934800) { - $end = 2145934800; - } - //initialise all values - $y = 0; - $m = 0; - $d = 0; - if ($start == 0 or $end == 0) { - $time = time(); - $dw = date('w', $time); - $week_start = $time - (($dw - 1) * 86400); - $y = date('Y', $week_start); - $m = date('m', $week_start); - $d = date('j', $week_start); - $w = date('W', $week_start); - } - if ($start == 0) { - $start = mktime(0, 0, 0, $m, $d, $y); - } - $db_start = date('Y-m-d H:i:s', $start); - if ($end == 0) { - $end = $start + (86400 * 7) - 1; //start of week, more 7 days, minus 1 second to get back to the previoyus day - } - //$db_end = date('Y-m-d H:i:s',$end); - - $t_cal = Database::get_course_table(TABLE_AGENDA, $course_info['dbName']); - $t_cal_repeat = Database::get_course_table(TABLE_AGENDA_REPEAT, $course_info['dbName']); - $t_ip = Database::get_course_table(TABLE_ITEM_PROPERTY, $course_info['dbName']); - $sql = "SELECT c.id, c.title, c.content, ". - " UNIX_TIMESTAMP(c.start_date) as orig_start, UNIX_TIMESTAMP(c.end_date) as orig_end, ". - " cr.cal_type, cr.cal_end ". - " FROM $t_cal c, $t_cal_repeat cr, $t_ip as item_property ". - " WHERE cr.cal_end >= $start ". - " AND cr.cal_id = c.id ". - " AND item_property.ref = c.id ". - " AND item_property.tool = '".TOOL_CALENDAR_EVENT."' ". - " AND c.start_date <= '$db_start' " - .(!empty($params['conditions']) ? $params['conditions'] : '') - .(!empty($params['groupby']) ? ' GROUP BY '.$params['groupby'] : '') - .(!empty($params['orderby']) ? ' ORDER BY '.$params['orderby'] : ''); - $res = Database::query($sql); - if (Database::num_rows($res) > 0) { - while ($row = Database::fetch_array($res)) { - $orig_start = $row['orig_start']; - $orig_end = $row['orig_end']; - $repeat_type = $row['cal_type']; - switch ($repeat_type) { - case 'daily': - $time_orig_h = date('H', $orig_start); - $time_orig_m = date('i', $orig_start); - $time_orig_s = date('s', $orig_start); - $int_time = (($time_orig_h * 60) + $time_orig_m) * 60 + $time_orig_s; //time in seconds since 00:00:00 - $span = $orig_end - $orig_start; //total seconds between start and stop of original event - for ($i = 0; $i < 7; $i++) { - $current_start = $start + ($i * 86400) + $int_time; //unixtimestamp start of today's event - $current_stop = $start + ($i * 86400) + $int_time + $span; //unixtimestamp stop of today's event - $events[] = array($course_info['id'], $row['id'], $current_start, $current_stop, $row['title'], $row['content']); - } - break; - case 'weekly': - $time_orig = date('Y/n/W/j/N/G/i/s', $orig_start); - list($y_orig, $m_orig, $w_orig, $d_orig, $dw_orig, $h_orig, $n_orig, $s_orig) = split('/', $time_orig); - $time_now = date('Y/n/W/j/N/G/i/s', $end); - list($y_now, $m_now, $w_now, $d_now, $dw_now, $h_now, $n_now, $s_now) = split('/', $time_now); - if ((($y_now > $y_orig) OR (($y_now == $y_orig) && ($w_now > $w_orig)))) { //if the event is after the original (at least one week) and the day of the week is the same - $time_orig_end = date('Y/n/W/j/N/G/i/s', $orig_end); - list($y_orig_e, $m_orig_e, $w_orig_e, $d_orig_e, $dw_orig_e, $h_orig_e, $n_orig_e, $s_orig_e) = split('/', $time_orig_end); - $events[] = array($course_info['id'], $row['id'], mktime($h_orig, $n_orig, $s_orig, $m_now, $d_orig, $y_now), mktime($h_orig_e, $n_orig_e, $s_orig_e, $m_now, $d_orig_e, $y_now), $row['title'], $row['content']); - } - break; - case 'monthlyByDate': - $time_orig = date('Y/n/W/j/G/i/s', $orig_start); - list($y_orig, $m_orig, $w_orig, $d_orig, $h_orig, $n_orig, $s_orig) = split('/', $time_orig); - $time_now = date('Y/n/W/j/G/i/s', $end); - list($y_now, $m_now, $w_now, $d_now, $h_now, $n_now, $s_now) = split('/', $time_now); - $event_repetition_time = mktime($h_orig, $n_orig, $s_orig, $m_now, $d_orig, $y_now); - if ((($y_now > $y_orig) OR (($y_now == $y_orig) && ($m_now > $m_orig))) && ($start < $event_repetition_time && $event_repetition_time < $end)) { //if the event is after the original (at least one month) and the original event's day is between the first day of the week and the last day of the week - $time_orig_end = date('Y/n/j/G/i/s', $orig_end); - list($y_orig_e, $m_orig_e, $d_orig_e, $h_orig_e, $n_orig_e, $s_orig_e) = split('/', $time_orig_end); - $events[] = array($course_info['id'], $row['id'], mktime($h_orig, $n_orig, $s_orig, $m_now, $d_orig, $y_now), mktime($h_orig_e, $n_orig_e, $s_orig_e, $m_now, $d_orig_e, $y_now), $row['title'], $row['content']); - } - break; - case 'monthlyByDayR': - //not implemented yet - break; - case 'monthlyByDay': - //not implemented yet - break; - case 'yearly': - $time_orig = date('Y/n/j/z/G/i/s', $orig_start); - list($y_orig, $m_orig, $d_orig, $dy_orig, $h_orig, $n_orig, $s_orig) = split('/', $time_orig); - $time_now = date('Y/n/j/z/G/i/s', $end); - list($y_now, $m_now, $d_now, $dy_now, $h_now, $n_now, $s_now) = split('/', $time_now); - $event_repetition_time = mktime($h_orig, $n_orig, $s_orig, $m_orig, $d_orig, $y_now); - if ((($y_now > $y_orig) && ($start < $event_repetition_time && $event_repetition_time < $end))) { - $time_orig_end = date('Y/n/j/G/i/s', $orig_end); - list($y_orig_e, $m_orig_e, $d_orig_e, $dy_orig_e, $h_orig_e, $n_orig_e, $s_orig_e) = split('/', $time_orig_end); - $events[] = array($course_info['id'], $row['id'], mktime($h_orig, $n_orig, $s_orig, $m_now, $d_orig, $y_now), mktime($h_orig_e, $n_orig_e, $s_orig_e, $m_now, $d_orig_e, $y_now), $row['title'], $row['content']); - } - break; - default: - break; - } - } - } - return $events; - } - - /** - * Get repeated events of a course between two dates (timespan of a month). - * Returns an array containing the events - * @param string Course info array (as returned by api_get_course_info()) - * @param int UNIX timestamp of span start. Defaults 0, later transformed into today's start - * @param int UNIX timestamp. Defaults to 0, later transformed into today's end - * @param array A set of parameters to alter the SQL query - * @return array [int] => [course_id,parent_event_id,start_date,end_date,title,description] - */ - function get_repeated_events_month_view($course_info, $start = 0, $end = 0, $params) - { - $events = array(); - //block $end if higher than 2038 -- PHP doesn't go past that - if ($end > 2145934800) { - $end = 2145934800; - } - //initialise all values - $y = 0; - $m = 0; - $d = 0; - if ($start == 0 or $end == 0) { - $time = time(); - $y = date('Y'); - $m = date('m'); - } - if ($start == 0) { - $start = mktime(0, 0, 0, $m, 1, $y); - } - $db_start = date('Y-m-d H:i:s', $start); - if ($end == 0) { - if ($m == 12) { - $end = mktime(0, 0, 0, 1, 1, $y + 1) - 1; //start of next month, minus 1 second to get back to the previoyus day - } else { - $end = mktime(0, 0, 0, $m + 1, 1, $y) - 1; - } - } - //$db_end = date('Y-m-d H:i:s',$end); - - $t_cal = Database::get_course_table(TABLE_AGENDA, $course_info['dbName']); - $t_cal_repeat = Database::get_course_table(TABLE_AGENDA_REPEAT, $course_info['dbName']); - $t_ip = Database::get_course_table(TABLE_ITEM_PROPERTY, $course_info['dbName']); - $sql = "SELECT c.id, c.title, c.content, ". - " UNIX_TIMESTAMP(c.start_date) as orig_start, UNIX_TIMESTAMP(c.end_date) as orig_end, ". - " cr.cal_type, cr.cal_end ". - " FROM $t_cal c, $t_cal_repeat cr, $t_ip as item_property ". - " WHERE cr.cal_end >= $start ". - " AND cr.cal_id = c.id ". - " AND item_property.ref = c.id ". - " AND item_property.tool = '".TOOL_CALENDAR_EVENT."' ". - " AND c.start_date <= '$db_start' " - .(!empty($params['conditions']) ? $params['conditions'] : '') - .(!empty($params['groupby']) ? ' GROUP BY '.$params['groupby'] : '') - .(!empty($params['orderby']) ? ' ORDER BY '.$params['orderby'] : ''); - $res = Database::query($sql); - if (Database::num_rows($res) > 0) { - while ($row = Database::fetch_array($res)) { - $orig_start = $row['orig_start']; - $orig_end = $row['orig_end']; - $repeat_type = $row['cal_type']; - switch ($repeat_type) { - case 'daily': - $time_orig_h = date('H', $orig_start); - $time_orig_m = date('i', $orig_start); - $time_orig_s = date('s', $orig_start); - $month_last_day = date('d', $end); - $int_time = (($time_orig_h * 60) + $time_orig_m) * 60 + $time_orig_s; //time in seconds since 00:00:00 - $span = $orig_end - $orig_start; //total seconds between start and stop of original event - for ($i = 0; $i < $month_last_day; $i++) { - $current_start = $start + ($i * 86400) + $int_time; //unixtimestamp start of today's event - $current_stop = $start + ($i * 86400) + $int_time + $span; //unixtimestamp stop of today's event - $events[] = array($course_info['id'], $row['id'], $current_start, $current_stop, $row['title'], $row['content']); - } - break; - case 'weekly': - //A weekly repeated event is very difficult to catch in a month view, - //because weeks start before or at the same time as the first day of the month - //The same can be said for the end of the month. - // The idea is thus to get all possible events by enlarging the scope of - // the month to get complete weeks covering the complete month, and then take out - // the events that start before the 1st ($start) or after the last day of the month ($end) - $time_orig = date('Y/n/W/j/N/G/i/s', $orig_start); - list($y_orig, $m_orig, $w_orig, $d_orig, $dw_orig, $h_orig, $n_orig, $s_orig) = split('/', $time_orig); - $time_orig_end = date('Y/n/W/j/N/G/i/s', $orig_end); - list($y_orig_e, $m_orig_e, $w_orig_e, $d_orig_e, $dw_orig_e, $h_orig_e, $n_orig_e, $s_orig_e) = split('/', $time_orig_end); - - $time_now = date('Y/n/W/j/N/G/i/s', $end); - list($y_now, $m_now, $w_now, $d_now, $dw_now, $h_now, $n_now, $s_now) = split('/', $time_now); - - $month_first_week = date('W', $start); - $month_last_week = date('W', $end); - - if (($y_now > $y_orig) OR (($y_now == $y_orig) && ($w_now > $w_orig))) { //if the event is after the original (at least one week) and the day of the week is the same - for ($i = $month_first_week; $i <= $month_last_week; $i++) { - //the "day of the week" of repetition is the same as the $dw_orig, - //so to get the "day of the month" from the "day of the week", we have - //to get the first "day of the week" for this week and add the number - //of days (in seconds) to reach the $dw_orig - //example: the first week spans between the 28th of April (Monday) to the - // 4th of May (Sunday). The event occurs on the 2nd day of each week. - // This means the event occurs on 29/4, 6/5, 13/5, 20/5 and 27/5. - // We want to get all of these, and then reject 29/4 because it is out - // of the month itself. - //First, to get the start time of the first day of the month view (even if - // the day is from the past month), we get the month start date (1/5) and - // see which day of the week it is, and subtract the number of days necessary - // to get back to the first day of the week. - $month_first_day_weekday = date('N', $start); - $first_week_start = $start - (($month_first_day_weekday - 1) * 86400); - - //Second, we add the week day of the original event, so that we have an - // absolute time that represents the first repetition of the event in - // our 4- or 5-weeks timespan - $first_event_repeat_start = $first_week_start + (($dw_orig - 1) * 86400) + ($h_orig * 3600) + ($n_orig * 60) + $s_orig; - - //Third, we start looping through the repetitions and see if they are between - // $start and $end - for ($i = $first_event_repeat_start; $i <= $end; $i+=604800) { - if ($start < $i && $i < $end) { - list($y_repeat, $m_repeat, $d_repeat, $h_repeat, $n_repeat, $s_repeat) = split('/', date('Y/m/j/H/i/s', $i)); - $events[] = array($course_info['id'], $row['id'], mktime($h_orig, $n_orig, $s_orig, $m_now, $d_orig, $y_now), mktime($h_orig_e, $n_orig_e, $s_orig_e, $m_now, $d_orig_e, $y_now), $row['title'], $row['content']); - } - } - } - } - break; - case 'monthlyByDate': - $time_orig = date('Y/n/W/j/G/i/s', $orig_start); - list($y_orig, $m_orig, $w_orig, $d_orig, $h_orig, $n_orig, $s_orig) = split('/', $time_orig); - $time_now = date('Y/n/W/j/G/i/s', $end); - list($y_now, $m_now, $w_now, $d_now, $h_now, $n_now, $s_now) = split('/', $time_now); - $event_repetition_time = mktime($h_orig, $n_orig, $s_orig, $m_now, $d_orig, $y_now); - if (($y_now > $y_orig) OR (($y_now == $y_orig) && ($m_now > $m_orig))) { //if the event is after the original (at least one month) and the original event's day is between the first day of the week and the last day of the week - $time_orig_end = date('Y/n/j/G/i/s', $orig_end); - list($y_orig_e, $m_orig_e, $d_orig_e, $h_orig_e, $n_orig_e, $s_orig_e) = split('/', $time_orig_end); - $events[] = array($course_info['id'], $row['id'], mktime($h_orig, $n_orig, $s_orig, $m_now, $d_orig, $y_now), mktime($h_orig_e, $n_orig_e, $s_orig_e, $m_now, $d_orig_e, $y_now), $row['title'], $row['content']); - } - break; - case 'monthlyByDayR': - //not implemented yet - break; - case 'monthlyByDay': - //not implemented yet - break; - case 'yearly': - $time_orig = date('Y/n/j/z/G/i/s', $orig_start); - list($y_orig, $m_orig, $d_orig, $dy_orig, $h_orig, $n_orig, $s_orig) = split('/', $time_orig); - $time_now = date('Y/n/j/z/G/i/s', $end); - list($y_now, $m_now, $d_now, $dy_now, $h_now, $n_now, $s_now) = split('/', $time_now); - $event_repetition_time = mktime($h_orig, $n_orig, $s_orig, $m_orig, $d_orig, $y_now); - if ((($y_now > $y_orig) && ($start < $event_repetition_time && $event_repetition_time < $end))) { - $time_orig_end = date('Y/n/j/G/i/s', $orig_end); - list($y_orig_e, $m_orig_e, $d_orig_e, $dy_orig_e, $h_orig_e, $n_orig_e, $s_orig_e) = split('/', $time_orig_end); - $events[] = array($course_info['id'], $row['id'], mktime($h_orig, $n_orig, $s_orig, $m_now, $d_orig, $y_now), mktime($h_orig_e, $n_orig_e, $s_orig_e, $m_now, $d_orig_e, $y_now), $row['title'], $row['content']); - } - break; - default: - break; - } - } - } - return $events; - } - - /** - * Get repeated events of a course between two dates (1 year timespan). Used for the list display. - * This is virtually unlimited but by default it shortens to 100 years from now (even a birthday shouldn't be useful more than this time - except for turtles) - * Returns an array containing the events - * @param string Course info array (as returned by api_get_course_info()) - * @param int UNIX timestamp of span start. Defaults 0, later transformed into today's start - * @param int UNIX timestamp. Defaults to 0, later transformed into today's end - * @param array A set of parameters to alter the SQL query - * @return array [int] => [course_id,parent_event_id,start_date,end_date,title,description] - */ - function get_repeated_events_list_view($course_info, $start = 0, $end = 0, $params) - { - $events = array(); - //block $end if higher than 2038 -- PHP doesn't go past that - if ($end > 2145934800) { - $end = 2145934800; - } - //initialise all values - $y = 0; - $m = 0; - $d = 0; - if (empty($start) or empty($end)) { - $time = time(); - $y = date('Y'); - $m = date('m'); - } - if (empty($start)) { - $start = mktime(0, 0, 0, $m, 1, $y); - } - $db_start = date('Y-m-d H:i:s', $start); - if (empty($end)) { - $end = mktime(0, 0, 0, 1, 1, 2037); - } - //$db_end = date('Y-m-d H:i:s',$end); - - $t_cal = Database::get_course_table(TABLE_AGENDA, $course_info['dbName']); - $t_cal_repeat = Database::get_course_table(TABLE_AGENDA_REPEAT, $course_info['dbName']); - $t_ip = Database::get_course_table(TABLE_ITEM_PROPERTY, $course_info['dbName']); - $sql = "SELECT c.id, c.title, c.content, ". - " UNIX_TIMESTAMP(c.start_date) as orig_start, UNIX_TIMESTAMP(c.end_date) as orig_end, ". - " cr.cal_type, cr.cal_end ". - " FROM $t_cal c, $t_cal_repeat cr, $t_ip as item_property ". - " WHERE cr.cal_end >= $start ". - " AND cr.cal_id = c.id ". - " AND item_property.ref = c.id ". - " AND item_property.tool = '".TOOL_CALENDAR_EVENT."' ". - " AND c.start_date <= '$db_start' " - .(!empty($params['conditions']) ? $params['conditions'] : '') - .(!empty($params['groupby']) ? ' GROUP BY '.$params['groupby'] : '') - .(!empty($params['orderby']) ? ' ORDER BY '.$params['orderby'] : ''); - $res = Database::query($sql); - if (Database::num_rows($res) > 0) { - while ($row = Database::fetch_array($res)) { - $orig_start = $row['orig_start']; - $orig_end = $row['orig_end']; - $repeat_type = $row['cal_type']; - $repeat_end = $row['cal_end']; - switch ($repeat_type) { - case 'daily': - $time_orig_h = date('H', $orig_start); - $time_orig_m = date('i', $orig_start); - $time_orig_s = date('s', $orig_start); - $span = $orig_end - $orig_start; //total seconds between start and stop of original event - for ($i = $orig_start + 86400; ($i < $end && $i <= $repeat_end); $i+=86400) { - $current_start = $i; //unixtimestamp start of today's event - $current_stop = $i + $span; //unixtimestamp stop of today's event - $events[] = array($course_info['id'], $row['id'], $current_start, $current_stop, $row['title'], $row['content']); - } - break; - case 'weekly': - //A weekly repeated event is very difficult to catch in a month view, - // because weeks start before or at the same time as the first day of the month - //The same can be said for the end of the month. - // The idea is thus to get all possible events by enlarging the scope of - // the month to get complete weeks covering the complete month, and then take out - // the events that start before the 1st ($start) or after the last day of the month ($end) - $time_orig = date('Y/n/W/j/N/G/i/s', $orig_start); - list($y_orig, $m_orig, $w_orig, $d_orig, $dw_orig, $h_orig, $n_orig, $s_orig) = split('/', $time_orig); - $time_orig_end = date('Y/n/W/j/N/G/i/s', $orig_end); - list($y_orig_e, $m_orig_e, $w_orig_e, $d_orig_e, $dw_orig_e, $h_orig_e, $n_orig_e, $s_orig_e) = split('/', $time_orig_end); - - $time_now = date('Y/n/W/j/N/G/i/s', $end); - list($y_now, $m_now, $w_now, $d_now, $dw_now, $h_now, $n_now, $s_now) = split('/', $time_now); - if ($w_now == 52) { - ++$y_now; - $w_now = 1; - } else { - ++$w_now; - } - $month_first_week = date('W', $start); - $total_weeks = ((date('Y', $end) - $y_orig) - 1) * 52; - $month_last_week = $month_first_week + $total_weeks; - - if (($y_now > $y_orig) OR (($y_now == $y_orig) && ($w_now > $w_orig))) { //if the event is after the original (at least one week) and the day of the week is the same - //for($i=$month_first_week;($i<=$month_last_week && $i<1000);$i++) - //{ - - - /* - The "day of the week" of repetition is the same as the $dw_orig, - so to get the "day of the month" from the "day of the week", we have - to get the first "day of the week" for this week and add the number - of days (in seconds) to reach the $dw_orig - example: the first week spans between the 28th of April (Monday) to the - 4th of May (Sunday). The event occurs on the 2nd day of each week. - This means the event occurs on 29/4, 6/5, 13/5, 20/5 and 27/5. - We want to get all of these, and then reject 29/4 because it is out - of the month itself. - First, to get the start time of the first day of the month view (even if - the day is from the past month), we get the month start date (1/5) and - see which day of the week it is, and subtract the number of days necessary - to get back to the first day of the week. - */ - $month_first_day_weekday = date('N', $start); - $first_week_start = $start - (($month_first_day_weekday - 1) * 86400); - - //Second, we add the week day of the original event, so that we have an - // absolute time that represents the first repetition of the event in - // our 4- or 5-weeks timespan - $first_event_repeat_start = $first_week_start + (($dw_orig - 1) * 86400) + ($h_orig * 3600) + ($n_orig * 60) + $s_orig; - - //Third, we start looping through the repetitions and see if they are between - // $start and $end - for ($i = $first_event_repeat_start; ($i <= $end && $i <= $repeat_end); $i+=604800) { - if ($start < $i && $i <= $end && $i <= $repeat_end) { - list($y_repeat, $m_repeat, $d_repeat, $h_repeat, $n_repeat, $s_repeat) = split('/', date('Y/m/j/H/i/s', $i)); - $new_start_time = mktime($h_orig, $n_orig, $s_orig, $m_now, $d_orig, $y_now); - $new_stop_time = mktime($h_orig_e, $n_orig_e, $s_orig_e, $m_now, $d_orig_e, $y_now); - $events[] = array($course_info['id'], $row['id'], $new_start_time, $new_stop_time, $row['title'], $row['content']); - } - $time_now = date('Y/n/W/j/N/G/i/s', $i + 604800); - list($y_now, $m_now, $w_now, $d_now, $dw_now, $h_now, $n_now, $s_now) = split('/', $time_now); - } - //} - } - break; - case 'monthlyByDate': - $time_orig = date('Y/n/W/j/G/i/s', $orig_start); - list($y_orig, $m_orig, $w_orig, $d_orig, $h_orig, $n_orig, $s_orig) = split('/', $time_orig); - - $time_now = date('Y/n/W/j/G/i/s', $start); - list($y_now, $m_now, $w_now, $d_now, $h_now, $n_now, $s_now) = split('/', $time_now); - //make sure we are one month ahead (to avoid being the same month as the original event) - if ($m_now == 12) { - ++$y_now; - $m_now = 1; - } else { - ++$m_now; - } - - $time_orig_end = date('Y/n/j/G/i/s', $orig_end); - list($y_orig_e, $m_orig_e, $d_orig_e, $h_orig_e, $n_orig_e, $s_orig_e) = split('/', $time_orig_end); - - $event_repetition_time = mktime($h_orig, $n_orig, $s_orig, $m_now, $d_orig, $y_now); - $diff = $orig_end - $orig_start; - while ((($y_now > $y_orig) OR (($y_now == $y_orig) && ($m_now > $m_orig))) && ($event_repetition_time < $end) && ($event_repetition_time < $repeat_end)) { //if the event is after the original (at least one month) and the original event's day is between the first day of the week and the last day of the week - $new_start_time = mktime($h_orig, $n_orig, $s_orig, $m_now, $d_orig, $y_now); - $new_stop_time = mktime($h_orig_e, $n_orig_e, $s_orig_e, $m_now, $d_orig_e, $y_now); - $events[] = array($course_info['id'], $row['id'], $new_start_time, $new_stop_time, $row['title'], $row['content']); - if ($m_now == 12) { - ++$y_now; - $m_now = 1; - } else { - ++$m_now; - } - $event_repetition_time = mktime($h_orig, $n_orig, $s_orig, $m_now, $d_orig, $y_now); - } - break; - case 'monthlyByDayR': - //not implemented yet - break; - case 'monthlyByDay': - //not implemented yet - break; - case 'yearly': - $time_orig = date('Y/n/j/z/G/i/s', $orig_start); - list($y_orig, $m_orig, $d_orig, $dy_orig, $h_orig, $n_orig, $s_orig) = split('/', $time_orig); - $time_now = date('Y/n/j/z/G/i/s', $end); - list($y_now, $m_now, $d_now, $dy_now, $h_now, $n_now, $s_now) = split('/', $time_now); - $event_repetition_time = mktime($h_orig, $n_orig, $s_orig, $m_orig, $d_orig, $y_now); - while ((($y_now > $y_orig) && ($start < $event_repetition_time && $event_repetition_time < $end && $event_repetition_time < $repeat_end))) { - $time_orig_end = date('Y/n/j/G/i/s', $orig_end); - list($y_orig_e, $m_orig_e, $d_orig_e, $dy_orig_e, $h_orig_e, $n_orig_e, $s_orig_e) = split('/', $time_orig_end); - $events[] = array($course_info['id'], $row['id'], mktime($h_orig, $n_orig, $s_orig, $m_now, $d_orig, $y_now), mktime($h_orig_e, $n_orig_e, $s_orig_e, $m_now, $d_orig_e, $y_now), $row['title'], $row['content']); - ++$y_now; - $event_repetition_time = mktime($h_orig, $n_orig, $s_orig, $m_orig, $d_orig, $y_now); - } - break; - default: - break; - } - } - } - return $events; - } - - /** - * Tells if an agenda item is repeated - * @param string Course database - * @param int The agenda item - * @return boolean True if repeated, false otherwise - */ - function is_repeated_event($id, $course = null) - { - if (empty($course)) { - $course_info = api_get_course_info(); - $course = $course_info['dbName']; - } - $id = (int) $id; - $t_agenda_repeat = Database::get_course_table(TABLE_AGENDA_REPEAT, $course); - $sql = "SELECT * FROM $t_agenda_repeat WHERE cal_id = $id"; - $res = Database::query($sql); - if (Database::num_rows($res) > 0) { - return true; - } - return false; - } - - /** - * Adds x weeks to a UNIX timestamp - * @param int The timestamp - * @param int The number of weeks to add - * @return int The new timestamp - */ - function add_week($timestamp, $num = 1) - { - return $timestamp + $num * 604800; - } - - /** - * Adds x months to a UNIX timestamp - * @param int The timestamp - * @param int The number of years to add - * @return int The new timestamp - */ - function add_month($timestamp, $num = 1) - { - list($y, $m, $d, $h, $n, $s) = split('/', date('Y/m/d/h/i/s', $timestamp)); - if ($m + $num > 12) { - $y += floor($num / 12); - $m += $num % 12; - } else { - $m += $num; - } - return mktime($h, $n, $s, $m, $d, $y); - } - - /** - * Adds x years to a UNIX timestamp - * @param int The timestamp - * @param int The number of years to add - * @return int The new timestamp - */ - function add_year($timestamp, $num = 1) - { - list($y, $m, $d, $h, $n, $s) = split('/', date('Y/m/d/h/i/s', $timestamp)); - return mktime($h, $n, $s, $m, $d, $y + $num); - } - - /** - * Adds an agenda item in the database. Similar to store_new_agenda_item() except it takes parameters - * @param array Course info - * @param string Event title - * @param string Event content/description - * @param string Start date - * @param string End date - * @param array List of groups to which this event is added - * @param int Parent id (optional) - * @return int The new item's DB ID - */ - function agenda_add_item($course_info, $title, $content, $db_start_date, $db_end_date, $to = array(), $parent_id = null, $file_comment = '') - { - $user_id = api_get_user_id(); - - // database table definitions - $t_agenda = Database::get_course_table(TABLE_AGENDA); - $item_property = Database::get_course_table(TABLE_ITEM_PROPERTY); - - // some filtering of the input data - $title = Database::escape_string($title); - $content = Database::escape_string($content); - $db_start_date = api_get_utc_datetime($db_start_date); - $start_date = Database::escape_string($db_start_date); - if (!empty($db_end_date)) { - $db_end_date = api_get_utc_datetime($db_end_date); - } - $end_date = Database::escape_string($db_end_date); - $id_session = api_get_session_id(); - $course_id = api_get_course_int_id(); - $group_id = api_get_group_id(); - - // 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.c_id = $course_id AND - item_property.c_id = $course_id AND - agenda.title = '$title' - AND agenda.content = '$content' - AND agenda.start_date = '$start_date' - AND agenda.end_date = '$end_date' ".(!empty($parent_id) ? " - AND agenda.parent_event_id = '$parent_id'" : "")." - AND agenda.session_id = '$id_session' - AND item_property.tool = '".TOOL_CALENDAR_EVENT."' - AND item_property.ref = agenda.id - AND item_property.visibility <> 2"; - - $result = Database::query($sql); - $count = Database::num_rows($result); - if ($count > 0) { - return false; - } - $course_id = api_get_course_int_id(); - - $sql = "INSERT INTO ".$t_agenda." (c_id, title,content, start_date, end_date".(!empty($parent_id) ? ',parent_event_id' : '').", session_id) - VALUES($course_id, '".$title."','".$content."', '".$start_date."','".$end_date."'".(!empty($parent_id) ? ','.((int) $parent_id) : '').", '".$id_session."')"; - - Database::query($sql); - $last_id = Database::insert_id(); - - // add a attachment file in agenda - - add_agenda_attachment_file($file_comment, $last_id); - - // store in last_tooledit (first the groups, then the users - - if (!empty($to)) { - $send_to = separate_users_groups($to); - // storing the selected groups - if (is_array($send_to['groups'])) { - foreach ($send_to['groups'] as $group) { - api_item_property_update($course_info, TOOL_CALENDAR_EVENT, $last_id, "AgendaAdded", $user_id, $group, 0, $start_date, $end_date); - $done = true; - } - } - // storing the selected users - if (is_array($send_to['users'])) { - foreach ($send_to['users'] as $user) { - api_item_property_update($course_info, TOOL_CALENDAR_EVENT, $last_id, "AgendaAdded", $user_id, 0, $user, $start_date, $end_date); - $done = true; - } - } - if (isset($send_to['everyone']) && $send_to['everyone']) { - api_item_property_update($course_info, TOOL_CALENDAR_EVENT, $last_id, "AgendaAdded", $user_id, 0, 0, $start_date, $end_date); - } - } - - // storing the resources - if (!empty($_SESSION['source_type']) && !empty($last_id)) { - store_resources($_SESSION['source_type'], $last_id); - } - return $last_id; - } - - /** - * This function delete a attachment file by id - * @param integer attachment file Id - * - */ - function delete_attachment_file($id_attach) - { - global $_course; - $agenda_table_attachment = Database::get_course_table(TABLE_AGENDA_ATTACHMENT); - $id_attach = intval($id_attach); - - $sql = "DELETE FROM $agenda_table_attachment WHERE id = ".$id_attach; - $result = Database::query($sql); - // update item_property - api_item_property_update($_course, 'calendar_event_attachment', $id_attach, 'AgendaAttachmentDeleted', api_get_user_id()); - if (!empty($result)) { - return Display::return_message(get_lang("AttachmentFileDeleteSuccess"), 'confirmation'); - } - } - - /** - * This function add a attachment file into agenda - * @param string a comment about file - * @param int last id from calendar table - * - */ - function add_agenda_attachment_file($file_comment, $last_id) - { - - global $_course; - $agenda_table_attachment = Database::get_course_table(TABLE_AGENDA_ATTACHMENT); - $last_id = intval($last_id); - // Storing the attachments - if (!empty($_FILES['user_upload']['name'])) { - $upload_ok = process_uploaded_file($_FILES['user_upload']); - } - - if (!empty($upload_ok)) { - $courseDir = $_course['path'].'/upload/calendar'; - $sys_course_path = api_get_path(SYS_COURSE_PATH); - $updir = $sys_course_path.$courseDir; - - // Try to add an extension to the file if it hasn't one - $new_file_name = add_ext_on_mime(stripslashes($_FILES['user_upload']['name']), $_FILES['user_upload']['type']); - // user's file name - $file_name = $_FILES['user_upload']['name']; - - if (!filter_extension($new_file_name)) { - Display :: display_error_message(get_lang('UplUnableToSaveFileFilteredExtension')); - } else { - $new_file_name = uniqid(''); - $new_path = $updir.'/'.$new_file_name; - $result = @move_uploaded_file($_FILES['user_upload']['tmp_name'], $new_path); - $safe_file_comment = Database::escape_string($file_comment); - $safe_file_name = Database::escape_string($file_name); - $safe_new_file_name = Database::escape_string($new_file_name); - $course_id = api_get_course_int_id(); - // Storing the attachments if any - if ($result) { - $sql = 'INSERT INTO '.$agenda_table_attachment.'(c_id, filename,comment, path,agenda_id,size) '. - "VALUES ($course_id, '".$safe_file_name."', '".$safe_file_comment."', '".$safe_new_file_name."' , '".$last_id."', '".intval($_FILES['user_upload']['size'])."' )"; - Database::query($sql); - //$message.=' / '.get_lang('FileUploadSucces').'
'; - - $last_id_file = Database::insert_id(); - api_item_property_update($_course, 'calendar_event_attachment', $last_id_file, 'AgendaAttachmentAdded', api_get_user_id()); - } - } - } - } - - /** - * This function edit a attachment file into agenda - * @param string a comment about file - * @param int Agenda Id - * @param int attachment file Id - */ - function edit_agenda_attachment_file($file_comment, $agenda_id, $id_attach) - { - - global $_course; - $agenda_table_attachment = Database::get_course_table(TABLE_AGENDA_ATTACHMENT); - // Storing the attachments - - if (!empty($_FILES['user_upload']['name'])) { - $upload_ok = process_uploaded_file($_FILES['user_upload']); - } - - if (!empty($upload_ok)) { - $courseDir = $_course['path'].'/upload/calendar'; - $sys_course_path = api_get_path(SYS_COURSE_PATH); - $updir = $sys_course_path.$courseDir; - - // Try to add an extension to the file if it hasn't one - $new_file_name = add_ext_on_mime(stripslashes($_FILES['user_upload']['name']), $_FILES['user_upload']['type']); - // user's file name - $file_name = $_FILES['user_upload']['name']; - - if (!filter_extension($new_file_name)) { - Display :: display_error_message(get_lang('UplUnableToSaveFileFilteredExtension')); - } else { - $new_file_name = uniqid(''); - $new_path = $updir.'/'.$new_file_name; - $result = @move_uploaded_file($_FILES['user_upload']['tmp_name'], $new_path); - $safe_file_comment = Database::escape_string($file_comment); - $safe_file_name = Database::escape_string($file_name); - $safe_new_file_name = Database::escape_string($new_file_name); - $safe_agenda_id = intval($agenda_id); - $safe_id_attach = intval($id_attach); - // Storing the attachments if any - if ($result) { - $sql = "UPDATE $agenda_table_attachment SET filename = '$safe_file_name', comment = '$safe_file_comment', path = '$safe_new_file_name', agenda_id = '$safe_agenda_id', size ='".intval($_FILES['user_upload']['size'])."' - WHERE id = '$safe_id_attach'"; - Database::query($sql); - api_item_property_update($_course, 'calendar_event_attachment', $safe_id_attach, 'AgendaAttachmentUpdated', api_get_user_id()); - } - } - } - } - - /** - * Adds a repetitive item to the database - * @param array Course info - * @param int The original event's id - * @param string Type of repetition - * @param int Timestamp of end of repetition (repeating until that date) - * @param array Original event's destination (users list) - * @param string a comment about a attachment file into agenda - * @return boolean False if error, True otherwise - */ - function agenda_add_repeat_item($course_info, $orig_id, $type, $end, $orig_dest, $file_comment = '') - { - $t_agenda = Database::get_course_table(TABLE_AGENDA); - $t_agenda_r = Database::get_course_table(TABLE_AGENDA_REPEAT); - - $course_id = $course_info['real_id']; - - $sql = 'SELECT title, content, start_date as sd, end_date as ed FROM '.$t_agenda.' WHERE c_id = '.$course_id.' AND id ="'.intval($orig_id).'" '; - $res = Database::query($sql); - if (Database::num_rows($res) !== 1) { - return false; - } - $row = Database::fetch_array($res); - $orig_start = api_strtotime(api_get_local_time($row['sd'])); - $orig_end = api_strtotime(api_get_local_time($row['ed'])); - - $diff = $orig_end - $orig_start; - $orig_title = $row['title']; - $orig_content = $row['content']; - $now = time(); - $type = Database::escape_string($type); - $end = intval($end); - - if (1 <= $end && $end <= 500) { - //we assume that, with this type of value, the user actually gives a count of repetitions - //and that he wants us to calculate the end date with that (particularly in case of imports from ical) - switch ($type) { - case 'daily': - $end = $orig_start + (86400 * $end); - break; - case 'weekly': - $end = add_week($orig_start, $end); - break; - case 'monthlyByDate': - $end = add_month($orig_start, $end); - break; - case 'monthlyByDay': - //TODO - break; - case 'monthlyByDayR': - //TODO - break; - case 'yearly': - $end = add_year($orig_start, $end); - break; - } - } - - if ($end > $now - && in_array($type, array('daily', 'weekly', 'monthlyByDate', 'monthlyByDay', 'monthlyByDayR', 'yearly'))) { - $sql = "INSERT INTO $t_agenda_r (c_id, cal_id, cal_type, cal_end) VALUES ($course_id, '$orig_id','$type',$end)"; - $res = Database::query($sql); - switch ($type) { - case 'daily': - for ($i = $orig_start + 86400; ($i <= $end); $i += 86400) { - $res = agenda_add_item($course_info, $orig_title, $orig_content, date('Y-m-d H:i:s', $i), date('Y-m-d H:i:s', $i + $diff), $orig_dest, $orig_id, $file_comment); - } - break; - case 'weekly': - for ($i = $orig_start + 604800; ($i <= $end); $i += 604800) { - $res = agenda_add_item($course_info, $orig_title, $orig_content, date('Y-m-d H:i:s', $i), date('Y-m-d H:i:s', $i + $diff), $orig_dest, $orig_id, $file_comment); - } - break; - case 'monthlyByDate': - $next_start = add_month($orig_start); - while ($next_start <= $end) { - $res = agenda_add_item($course_info, $orig_title, $orig_content, date('Y-m-d H:i:s', $next_start), date('Y-m-d H:i:s', $next_start + $diff), $orig_dest, $orig_id, $file_comment); - $next_start = add_month($next_start); - } - break; - case 'monthlyByDay': - //not yet implemented - break; - case 'monthlyByDayR': - //not yet implemented - break; - case 'yearly': - $next_start = add_year($orig_start); - while ($next_start <= $end) { - $res = agenda_add_item($course_info, $orig_title, $orig_content, date('Y-m-d H:i:s', $next_start), date('Y-m-d H:i:s', $next_start + $diff), $orig_dest, $orig_id, $file_comment); - $next_start = add_year($next_start); - } - break; - } - } - return true; - } - - /** - * Import an iCal file into the database - * @param array Course info - * @return boolean True on success, false otherwise - * @deprecated - */ - function agenda_import_ical($course_info, $file) - { - $charset = api_get_system_encoding(); - $filepath = api_get_path(SYS_ARCHIVE_PATH).$file['name']; - if (!@move_uploaded_file($file['tmp_name'], $filepath)) { - error_log('Problem moving uploaded file: '.$file['error'].' in '.__FILE__.' line '.__LINE__); - return false; - } - - $ical = new vcalendar(); - $ical->setConfig('directory', dirname($filepath)); - $ical->setConfig('filename', basename($filepath)); - $return = $ical->parse(); - - //we need to recover: summary, description, dtstart, dtend, organizer, attendee, location (=course name), - /* - $ve = $ical->getComponent(VEVENT); - - $ttitle = $ve->getProperty('summary'); - $title = api_convert_encoding($ttitle,$charset,'UTF-8'); - - $tdesc = $ve->getProperty('description'); - $desc = api_convert_encoding($tdesc,$charset,'UTF-8'); - - $start_date = $ve->getProperty('dtstart'); - $start_date_string = $start_date['year'].'-'.$start_date['month'].'-'.$start_date['day'].' '.$start_date['hour'].':'.$start_date['min'].':'.$start_date['sec']; - - - $ts = $ve->getProperty('dtend'); - if ($ts) { - $end_date_string = $ts['year'].'-'.$ts['month'].'-'.$ts['day'].' '.$ts['hour'].':'.$ts['min'].':'.$ts['sec']; - } else { - //Check duration if dtend does not exist - $duration = $ve->getProperty('duration'); - if ($duration) { - $duration = $ve->getProperty('duration'); - $duration_string = $duration['year'].'-'.$duration['month'].'-'.$duration['day'].' '.$duration['hour'].':'.$duration['min'].':'.$duration['sec']; - $start_date_tms = mktime(intval($start_date['hour']), intval($start_date['min']), intval($start_date['sec']), intval($start_date['month']), intval($start_date['day']), intval($start_date['year'])); - //$start_date_tms = mktime(($start_date['hour']), ($start_date['min']), ($start_date['sec']), ($start_date['month']), ($start_date['day']), ($start_date['year'])); - //echo date('d-m-Y - h:i:s', $start_date_tms); - - $end_date_string = mktime(intval($start_date['hour']) +$duration['hour'], intval($start_date['min']) + $duration['min'], intval($start_date['sec']) + $duration['sec'], intval($start_date['month']) + $duration['month'], intval($start_date['day'])+$duration['day'], intval($start_date['year']) + $duration['year']); - $end_date_string = date('Y-m-d H:i:s', $end_date_string); - //echo date('d-m-Y - h:i:s', $end_date_string); - } - } - - - //echo $start_date.' - '.$end_date; - $organizer = $ve->getProperty('organizer'); - $attendee = $ve->getProperty('attendee'); - $course_name = $ve->getProperty('location'); - //insert the event in our database - $id = agenda_add_item($course_info,$title,$desc,$start_date_string,$end_date_string,$_POST['selectedform']); - - - $repeat = $ve->getProperty('rrule'); - if(is_array($repeat) && !empty($repeat['FREQ'])) { - $trans = array('DAILY'=>'daily','WEEKLY'=>'weekly','MONTHLY'=>'monthlyByDate','YEARLY'=>'yearly'); - $freq = $trans[$repeat['FREQ']]; - $interval = $repeat['INTERVAL']; - if(isset($repeat['UNTIL']) && is_array($repeat['UNTIL'])) { - $until = mktime(23,59,59,$repeat['UNTIL']['month'],$repeat['UNTIL']['day'],$repeat['UNTIL']['year']); - $res = agenda_add_repeat_item($course_info,$id,$freq,$until,$_POST['selectedform']); - } */ - $eventcount = 0; - $message = array(); - $agenda_obj = new Agenda(); - - while (true) { - //we need to recover: summary, description, dtstart, dtend, organizer, attendee, location (=course name) - $ve = $ical->getComponent('VEVENT', $eventcount); - - if (!$ve) { - break; - } - - $ttitle = $ve->getProperty('summary'); - $title = api_convert_encoding($ttitle, $charset, 'UTF-8'); - - $tdesc = $ve->getProperty('description'); - $desc = api_convert_encoding($tdesc, $charset, 'UTF-8'); - - $start_date = $ve->getProperty('dtstart', false, true); - - if (isset($start_date['params']['VALUE'])) { - $start_date_value = $start_date['value']; - if ($start_date['params']['VALUE'] == 'DATE') { - $start_date_string = $start_date_value['year'].'-'.$start_date_value['month'].'-'.$start_date_value['day'].''; - } else { - $start_date_string = $start_date_value['year'].'-'.$start_date_value['month'].'-'.$start_date_value['day'].' '.$start_date_value['hour'].':'.$start_date_value['min'].':'.$start_date_value['sec']; - } - } else { - continue; - } - - $ts = $ve->getProperty('dtend'); - - if ($ts) { - $end_date = $ve->getProperty('dtend', false, true); - if (isset($end_date['params']['VALUE'])) { - $end_date_value = $end_date['value']; - if ($end_date['params']['VALUE'] == 'DATE') { - $end_date_string = $end_date_value['year'].'-'.$end_date_value['month'].'-'.$end_date_value['day'].''; - } else { - $end_date_string = $end_date_value['year'].'-'.$end_date_value['month'].'-'.$end_date_value['day'].' '.$end_date_value['hour'].':'.$end_date_value['min'].':'.$end_date_value['sec']; - } - } else { - //Default behaviour - $end_date_string = $ts['year'].'-'.$ts['month'].'-'.$ts['day'].' '.$ts['hour'].':'.$ts['min'].':'.$ts['sec']; - } - } else { - //Check duration if dtend does not exist - $duration = $ve->getProperty('duration'); - if ($duration) { - $duration = $ve->getProperty('duration'); - $duration_string = $duration['year'].'-'.$duration['month'].'-'.$duration['day'].' '.$duration['hour'].':'.$duration['min'].':'.$duration['sec']; - $start_date_tms = mktime(intval($start_date['hour']), intval($start_date['min']), intval($start_date['sec']), intval($start_date['month']), intval($start_date['day']), intval($start_date['year'])); - //$start_date_tms = mktime(($start_date['hour']), ($start_date['min']), ($start_date['sec']), ($start_date['month']), ($start_date['day']), ($start_date['year'])); - //echo date('d-m-Y - h:i:s', $start_date_tms); - - $end_date_string = mktime(intval($start_date['hour']) + $duration['hour'], intval($start_date['min']) + $duration['min'], intval($start_date['sec']) + $duration['sec'], intval($start_date['month']) + $duration['month'], intval($start_date['day']) + $duration['day'], intval($start_date['year']) + $duration['year']); - $end_date_string = api_get_utc_datetime($end_date_string); - //echo date('d-m-Y - h:i:s', $end_date_string); - } - } - - //echo $start_date.' - '.$end_date; - $organizer = $ve->getProperty('organizer'); - $attendee = $ve->getProperty('attendee'); - $course_name = $ve->getProperty('location'); - - //insert the event in our database - $agenda_obj->type = 'course'; - - $all_day = 'false'; - - if ($start_date_string == $end_date_string) { - $all_day = 'true'; - } - $date = new DateTime($start_date_string); - $date->add(new DateInterval('P1D')); - - if ($start_date_string == $date->format('Y-m-d h:i:s')) { - $all_day = 'true'; - } - $id = $agenda_obj->add_event( - $start_date_string, - $end_date_string, - $all_day, - $title, - $desc, - array('everyone') - ); - - $message[] = " $title - ".$start_date_string." - ".$end_date_string; - - $repeat = $ve->getProperty('rrule'); - if (is_array($repeat) && !empty($repeat['FREQ'])) { - $trans = array( - 'DAILY' => 'daily', - 'WEEKLY' => 'weekly', - 'MONTHLY' => 'monthlyByDate', - 'YEARLY' => 'yearly' - ); - $freq = $trans[$repeat['FREQ']]; - $interval = $repeat['INTERVAL']; - if (isset($repeat['UNTIL']) && is_array($repeat['UNTIL'])) { - $until = mktime(23, 59, 59, $repeat['UNTIL']['month'], $repeat['UNTIL']['day'], $repeat['UNTIL']['year']); - $res = agenda_add_repeat_item($course_info, $id, $freq, $until, $attendee); - } - - //TODO: deal with count - if (!empty($repeat['COUNT'])) { - $count = $repeat['COUNT']; - $res = agenda_add_repeat_item($course_info, $id, $freq, $count, $attendee); - } - } - $eventcount++; - } - if (!empty($message)) { - $message = implode('
', $message); - } - return $message; - } - - /** - * This function retrieves one personal agenda item returns it. - * @param array The array containing existing events. We add to this array. - * @param int Day - * @param int Month - * @param int Year (4 digits) - * @param int Week number - * @param string Type of view (month_view, week_view, day_view) - * @return array The results of the database query, or null if not found - */ - function get_global_agenda_items($agendaitems, $day = "", $month = "", $year = "", $week = "", $type) - { - $tbl_global_agenda = Database::get_main_table(TABLE_MAIN_SYSTEM_CALENDAR); - $month = intval($month); - $year = intval($year); - $week = intval($week); - $day = intval($day); - // 1. creating the SQL statement for getting the personal agenda items in MONTH view - - $current_access_url_id = api_get_current_access_url_id(); - - if ($type == "month_view" or $type == "") { - // We are in month view - $sql = "SELECT * FROM ".$tbl_global_agenda." WHERE MONTH(start_date) = ".$month." AND YEAR(start_date) = ".$year." AND access_url_id = $current_access_url_id ORDER BY start_date ASC"; - } - // 2. creating the SQL statement for getting the personal agenda items in WEEK view - if ($type == "week_view") { // we are in week view - $start_end_day_of_week = calculate_start_end_of_week($week, $year); - $start_day = $start_end_day_of_week['start']['day']; - $start_month = $start_end_day_of_week['start']['month']; - $start_year = $start_end_day_of_week['start']['year']; - $end_day = $start_end_day_of_week['end']['day']; - $end_month = $start_end_day_of_week['end']['month']; - $end_year = $start_end_day_of_week['end']['year']; - // in sql statements you have to use year-month-day for date calculations - $start_filter = $start_year."-".$start_month."-".$start_day." 00:00:00"; - $start_filter = api_get_utc_datetime($start_filter); - - $end_filter = $end_year."-".$end_month."-".$end_day." 23:59:59"; - $end_filter = api_get_utc_datetime($end_filter); - $sql = " SELECT * FROM ".$tbl_global_agenda." WHERE start_date>='".$start_filter."' AND start_date<='".$end_filter."' AND access_url_id = $current_access_url_id "; - } - // 3. creating the SQL statement for getting the personal agenda items in DAY view - if ($type == "day_view") { // we are in day view - // we could use mysql date() function but this is only available from 4.1 and higher - $start_filter = $year."-".$month."-".$day." 00:00:00"; - $start_filter = api_get_utc_datetime($start_filter); - - $end_filter = $year."-".$month."-".$day." 23:59:59"; - $end_filter = api_get_utc_datetime($end_filter); - $sql = " SELECT * FROM ".$tbl_global_agenda." WHERE start_date>='".$start_filter."' AND start_date<='".$end_filter."' AND access_url_id = $current_access_url_id"; - } - - $result = Database::query($sql); - - while ($item = Database::fetch_array($result)) { - - if ($item['start_date'] != '0000-00-00 00:00:00') { - $item['start_date'] = api_get_local_time($item['start_date']); - $item['start_date_tms'] = api_strtotime($item['start_date']); - } - if ($item['end_date'] != '0000-00-00 00:00:00') { - $item['end_date'] = api_get_local_time($item['end_date']); - } - - // we break the date field in the database into a date and a time part - $agenda_db_date = explode(" ", $item['start_date']); - $date = $agenda_db_date[0]; - $time = $agenda_db_date[1]; - // we divide the date part into a day, a month and a year - $agendadate = explode("-", $date); - $year = intval($agendadate[0]); - $month = intval($agendadate[1]); - $day = intval($agendadate[2]); - // we divide the time part into hour, minutes, seconds - $agendatime = explode(":", $time); - $hour = $agendatime[0]; - $minute = $agendatime[1]; - $second = $agendatime[2]; - - if ($type == 'month_view') { - $item['calendar_type'] = 'global'; - $agendaitems[$day][] = $item; - continue; - } - - $start_time = api_format_date($item['start_date'], TIME_NO_SEC_FORMAT); - $end_time = ''; - if ($item['end_date'] != '0000-00-00 00:00:00') { - $end_time = ' - '.api_format_date($item['end_date'], DATE_TIME_FORMAT_LONG); - } - - // if the student has specified a course we a add a link to that course - if ($item['course'] <> "") { - $url = api_get_path(WEB_CODE_PATH)."admin/agenda.php?cidReq=".urlencode($item['course'])."&day=$day&month=$month&year=$year#$day"; // RH //Patrick Cool: to highlight the relevant agenda item - $course_link = "".$item['course'].""; - } else { - $course_link = ""; - } - // Creating the array that will be returned. If we have week or month view we have an array with the date as the key - // if we have a day_view we use a half hour as index => key 33 = 16h30 - if ($type !== "day_view") { - // This is the array construction for the WEEK or MONTH view - //Display the Agenda global in the tab agenda (administrator) - $agendaitems[$day] .= "$start_time $end_time - "; - $agendaitems[$day] .= "".get_lang('GlobalEvent').""; - $agendaitems[$day] .= "
".$item['title']."

"; - } else { - // this is the array construction for the DAY view - $halfhour = 2 * $agendatime['0']; - if ($agendatime['1'] >= '30') { - $halfhour = $halfhour + 1; - } - if (!is_array($agendaitems[$halfhour])) - $content = $agendaitems[$halfhour]; - $agendaitems[$halfhour] = $content."
$hour:$minute ".get_lang('GlobalEvent').": ".$item['title']."
"; - } - } - return $agendaitems; - } - - function display_ical_import_form() - { - $form = new FormValidator('frm_import_ical', 'post', api_get_self().'?action='.Security::remove_XSS($_GET['action']), array('enctype' => 'multipart/form-data')); - $form->addElement('header', get_lang('ICalFileImport')); - $form->addElement('file', 'ical_import', get_lang('ICalFileImport')); - $form->addRule('ical_import', get_lang('ThisFieldIsRequired'), 'required'); - $form->addElement('button', 'ical_submit', get_lang('Import')); - return $form->return_form(); - } diff --git a/main/calendar/agenda.php b/main/calendar/agenda.php index 1acfb60291..a5be16136c 100755 --- a/main/calendar/agenda.php +++ b/main/calendar/agenda.php @@ -240,10 +240,10 @@ if (api_is_allowed_to_edit(false, true) OR exit; } else { $content = $form->return_form(); - } break; case 'importical': + $actionName = get_lang('Import'); $form = $agenda->getImportCalendarForm(); $content = $form->return_form(); diff --git a/main/calendar/agenda_js.php b/main/calendar/agenda_js.php index 92c9fbf81e..39b1857c16 100755 --- a/main/calendar/agenda_js.php +++ b/main/calendar/agenda_js.php @@ -18,7 +18,6 @@ if ($type == 'personal') { $cidReset = true; // fixes #5162 } require_once '../inc/global.inc.php'; -require_once 'agenda.inc.php'; $current_course_tool = TOOL_CALENDAR_EVENT; $this_section = SECTION_MYAGENDA; diff --git a/main/calendar/agenda_list.php b/main/calendar/agenda_list.php index 0f6bffc2b2..ad10cebbec 100755 --- a/main/calendar/agenda_list.php +++ b/main/calendar/agenda_list.php @@ -5,7 +5,6 @@ */ require_once '../inc/global.inc.php'; -require_once 'agenda.inc.php'; $interbreadcrumb[] = array( 'url' => api_get_path(WEB_CODE_PATH) . "calendar/agenda_js.php", diff --git a/main/calendar/allagendas.php b/main/calendar/allagendas.php deleted file mode 100755 index bd08a63369..0000000000 --- a/main/calendar/allagendas.php +++ /dev/null @@ -1,379 +0,0 @@ - api_get_path(WEB_COURSE_PATH).urlencode($course_path).'/index.php', 'name' => Security::remove_XSS($_GET['courseCode'])); -} -// this loads the javascript that is needed for the date popup selection -//$htmlHeadXtra[] = ""; - -// showing the header -Display::display_header(get_lang('MyAgenda')); - -function display_mymonthcalendar_2($agendaitems, $month, $year, $weekdaynames=array(), $monthName, $session_id) { - global $DaysShort, $course_path; - //Handle leap year - $numberofdays = array (0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); - if (($year % 400 == 0) or ($year % 4 == 0 and $year % 100 <> 0)) - $numberofdays[2] = 29; - //Get the first day of the month - $dayone = getdate(mktime(0, 0, 0, $month, 1, $year)); - //Start the week on monday - $startdayofweek = $dayone['wday'] <> 0 ? ($dayone['wday'] - 1) : 6; - $g_cc = (isset($_GET['courseCode'])?$_GET['courseCode']:''); - $backwardsURL = api_get_self()."?coursePath=".urlencode($course_path)."&session=".Security::remove_XSS($session_id)."&courseCode=".Security::remove_XSS($g_cc)."&action=view&view=month&month=". ($month == 1 ? 12 : $month -1)."&year=". ($month == 1 ? $year -1 : $year); - $forewardsURL = api_get_self()."?coursePath=".urlencode($course_path)."&session=".Security::remove_XSS($session_id)."&courseCode=".Security::remove_XSS($g_cc)."&action=view&view=month&month=". ($month == 12 ? 1 : $month +1)."&year=". ($month == 12 ? $year +1 : $year); - - echo "\n", "\n", "\n", "\n", "\n", "\n"; - - echo "\n"; - for ($ii = 1; $ii < 8; $ii ++) - { - echo "\n"; - } - echo "\n"; - $curday = -1; - $today = getdate(); - while ($curday <= $numberofdays[$month]) { - echo "\n"; - for ($ii = 0; $ii < 7; $ii ++) { - if (($curday == -1) && ($ii == $startdayofweek)) { - $curday = 1; - } - if (($curday > 0) && ($curday <= $numberofdays[$month])) { - $bgcolor = $ii < 5 ? $class = "class=\"days_week\" style=\"width:10%;\"" : $class = "class=\"days_weekend\" style=\"width:10%;\""; - $dayheader = "$curday
"; - if (($curday == $today['mday']) && ($year == $today['year']) && ($month == $today['mon'])) { - $dayheader = "$curday - ".get_lang("Today")."
"; - $class = "class=\"days_today\" style=\"width:10%;\""; - } - echo "\n"; - $curday ++; - } else { - echo "\n"; - } - } - echo "\n"; - } - echo "
«", $monthName, " ", $year, "»
", $DaysShort[$ii % 7], "
", "".$dayheader; - if (!empty($agendaitems[$curday])) { - echo "".$agendaitems[$curday].""; - } - echo " 
\n"; -} - -function get_agenda_items_by_course_list($course_list, $month, $year, $session_id = 0) { - global $setting_agenda_link; - //echo $sql = 'SELECT name FROM chamilo_main.class WHERE name = "'.$grado.'" ORDER BY name ASC'; - //$result = Database::query($sql); - //while ($row = Database::fetch_array($result, 'ASSOC')) { - - $agendaitems = array (); - $course_name_list = array(); - foreach ($course_list as $course) { - - $db_name = $course['db_name']; - $code = $course['code']; - $title = $course['title']; - $course_name_list[] = $title; - //$sql2 = 'SELECT code, db_name, title FROM chamilo_main.course WHERE category_code = "'.$course_name.'" '; -// $courses_dbs = Database::query($sql2); - - $items = array (); - // $courses_dbs = array(); - // get agenda-items for every course - //while($row2 = Database::fetch_array($courses_dbs, 'ASSOC')) { - //$db_name = $row2['db_name']; - //$code = $row2['code']; - //$title = $row2['title']; - //echo "

".$db_name."

"; - - //databases of the courses - $TABLEAGENDA = Database :: get_course_table(TABLE_AGENDA, $db_name); - $TABLE_ITEMPROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY, $db_name); - - //$group_memberships = GroupManager :: get_group_ids($array_course_info["db"], $_user['user_id']); - // if the user is administrator of that course we show all the agenda items - $session_condition = ''; - if ($session_id != 0) { - $session_id = intval($session_id); - $session_condition = "AND session_id = $session_id"; - } - - $sqlquery = "SELECT DISTINCT agenda.*, item_property.* - FROM ".$TABLEAGENDA." agenda, - ".$TABLE_ITEMPROPERTY." item_property - WHERE agenda.id = item_property.ref - AND MONTH(agenda.start_date)='".$month."' - AND YEAR(agenda.start_date)='".$year."' - AND item_property.tool='".TOOL_CALENDAR_EVENT."' - AND item_property.visibility='1' $session_condition - GROUP BY agenda.id - ORDER BY start_date "; - $result = Database::query($sqlquery); - while ($item = Database::fetch_array($result,'ASSOC')) { - //taking the day - $agendaday = date("j",strtotime($item['start_date'])); - if(!isset($items[$agendaday])){$items[$agendaday]=array();} - //taking the time - $time = date("H:i",strtotime($item['start_date'])); - $end_time= date("H:i",strtotime($item['end_date'])); - $URL = api_get_path(WEB_PATH)."main/calendar/allagendas.php?cidReq=".urlencode($code)."&sort=asc&view=list&day=$agendaday&month=$month&year=$year#$agendaday"; // RH //Patrick Cool: to highlight the relevant agenda item - if ($setting_agenda_link == 'coursecode') { - //$title=$array_course_info['title']; - $agenda_link = api_substr($title, 0, 14); - } else { - $agenda_link = Display::return_icon('course_home.gif'); - } - if(!isset($items[$agendaday][$item['start_date']])) { - $items[$agendaday][$item['start_date']] = ''; - } - - $items[$agendaday][$item['start_date']] .= "".get_lang('StartTimeWindow')." ".$time.""." - ".get_lang("EndTimeWindow")." ".$end_time." "; - $items[$agendaday][$item['start_date']] .= '
'."".$agenda_link." ".Security::remove_XSS($item['title'])."
"; - $items[$agendaday][$item['start_date']] .= '
'; - } - - if (is_array($items) && count($items) > 0) { - while (list ($agendaday, $tmpitems) = each($items)) { - if(!isset($agendaitems[$agendaday])) { - $agendaitems[$agendaday] = ''; - } - sort($tmpitems); - while (list ($key, $val) = each($tmpitems)) { - $agendaitems[$agendaday] .= $val; - } - } - } - } - echo "

Courses:

".implode(', ',$course_name_list)."

"; - return $agendaitems; -} - -/* SETTING SOME VARIABLES */ - -// the variables for the days and the months -// Defining the shorts for the days -$DaysShort = api_get_week_days_short(); -// Defining the days of the week to allow translation of the days -$DaysLong = api_get_week_days_long(); -// Defining the months of the year to allow translation of the months -$MonthsLong = api_get_months_long(); - -/* - TREATING THE URL PARAMETERS - 1. The default values - 2. storing it in the session - 3. possible view - 3.a Month view - 3.b Week view - 3.c day view - 3.d personal view (only the personal agenda items) -*/ -// 1. The default values. if there is no session yet, we have by default the month view -if (empty($_SESSION['view'])) { - $_SESSION['view'] = 'month'; -} -// 2. Storing it in the session. If we change the view by clicking on the links left, we change the session -if (!empty($_GET['view'])) { - $_SESSION['view'] = Security::remove_XSS($_GET['view']); - -} -// 3. The views: (month, week, day, personal) -if ($_SESSION['view']) { - switch ($_SESSION['view']) { - // 3.a Month view - case "month" : - $process = "month_view"; - break; - // 3.a Week view - case "week" : - $process = "week_view"; - break; - // 3.a Day view - case "day" : - $process = "day_view"; - break; - // 3.a Personal view - case "personal" : - $process = "personal_view"; - break; - } -} - -$my_course_id = intval($_GET['course']); -$my_session_id = intval($_GET['session']); - -$my_course_list = array(); - -if(!empty($my_session_id)) { - $_SESSION['my_course_list'] = array(); - $my_course_list = array(); -} else { - $my_course_list = $_SESSION['my_course_list']; - $my_course_list_keys = array_keys($my_course_list); - if (!in_array($my_course_id, $my_course_list_keys)) { - $course_info = api_get_course_info_by_id($my_course_id); - $_SESSION['my_course_list'][$my_course_id] = $course_info; - $my_course_list = $_SESSION['my_course_list']; - //echo $my_course_id.'added '; - } - - if (isset($_GET['delete_course_option'])) { - $course_id_to_delete = intval($_GET['delete_course_option']); - unset($_SESSION['my_course_list'][$course_id_to_delete]); - $my_course_list = $_SESSION['my_course_list']; - } - //clean the array - $my_course_list = array_filter($my_course_list); -} - -/* OUTPUT */ -if (isset ($_user['user_id'])) { - // getting all the courses that this user is subscribed to - $courses_dbs = get_all_courses_of_user(); - if (!is_array($courses_dbs)) { - // this is for the special case if the user has no courses (otherwise you get an error) - $courses_dbs = array (); - } - // setting and/or getting the year, month, day, week - $today = getdate(); - $year = (!empty($_GET['year'])? (int)$_GET['year'] : NULL); - if ($year == NULL) - { - $year = $today['year']; - } - $month = (!empty($_GET['month'])? (int)$_GET['month']:NULL); - if ($month == NULL) - { - $month = $today['mon']; - } - $day = (!empty($_GET['day']) ? (int)$_GET['day']:NULL); - if ($day == NULL) - { - $day = $today['mday']; - } - $week = (!empty($_GET['week']) ?(int)$_GET['week']:NULL); - if ($week == NULL) - { - $week = date("W"); - } - // The name of the current Month - $monthName = $MonthsLong[$month -1]; - - if (api_is_platform_admin()) { - $courses = array(); - $sessions = SessionManager::get_sessions_list(); - - } elseif(api_is_drh()) { - $courses = CourseManager::get_courses_followed_by_drh(api_get_user_id()); - $sessions = SessionManager::get_sessions_followed_by_drh(api_get_user_id()); - } - - echo ''; - echo ''; - - // output: the small calendar item on the left and the view / add links - echo ''; - - // the divider - // OlivierB : the image has a white background, which causes trouble if the portal has another background color. Image should be transparent. ----> echo ""; - echo ""; - // the main area: day, week, month view - echo '
'; - - echo '
'; - if (count($courses) > 0) { - echo '

'.get_lang('SelectACourse').'

'; - - foreach ($courses as $row_course) { - $course_code = $row_course['id']; - $title = $row_course['title']; - $my_course_list_keys = array_keys($my_course_list); - if (!in_array($course_code, $my_course_list_keys)) { - echo ''.$title.'
'; - } else { - echo ''.$title.' Delete
'; - } - } - } - if (count($sessions) > 0) { - echo '

'.get_lang('SelectASession').'

'; - foreach ($sessions as $session) { - $id = $session['id']; - $name = $session['name']; - echo ''.$name.'
'; - } - } - echo '
  '; - - //@todo hardcoding option - $process = 'month_view'; - - switch ($process) { - case "month_view" : - $session_id = 0; - //By courses - if (is_array($my_course_list) && count($my_course_list) > 0) { - $course_list = $my_course_list; - } else { - //session - $course_list = SessionManager::get_course_list_by_session_id($my_session_id); - $session_id = $my_session_id; - echo '

'.$sessions[$session_id]['name'].'

'; - } - if (is_array($course_list) && count($course_list) > 0) { - - $agendaitems = get_agenda_items_by_course_list($course_list, $month, $year, $session_id); - //$agendaitems = get_global_agenda_items($agendaitems, $day, $month, $year, $week, "month_view"); - display_mymonthcalendar_2($agendaitems, $month, $year, array(), $monthName, $session_id); - } else { - Display::display_warning_message(get_lang('PleaseSelectACourseOrASessionInTheLeftColumn')); - } - break; - } -} -echo "
"; -Display :: display_footer(); diff --git a/main/calendar/download.php b/main/calendar/download.php index b5722adc1e..0014821c4e 100755 --- a/main/calendar/download.php +++ b/main/calendar/download.php @@ -17,8 +17,6 @@ session_cache_limiter('public'); require_once '../inc/global.inc.php'; $this_section = SECTION_COURSES; -require_once 'agenda.inc.php'; - // IMPORTANT to avoid caching of documents header('Expires: Wed, 01 Jan 1990 00:00:00 GMT'); header('Cache-Control: public'); diff --git a/main/calendar/myagenda.inc.php b/main/calendar/myagenda.inc.php deleted file mode 100755 index cee0680891..0000000000 --- a/main/calendar/myagenda.inc.php +++ /dev/null @@ -1,789 +0,0 @@ - BeezNest 2011 Bugfixes - - //Original code found in Dok€os - @author: Patrick Cool , Ghent University - @author: Toon Van Hoecke , Ghent University - @author: Eric Remy (initial version) - - @todo create a class and merge with the agenda.inc.php -*/ - -/** - * Settings (you may alter this at will - */ -$setting_agenda_link = 'coursecode'; // valid values are coursecode and icon - -/** - * This function retrieves all the agenda items of all the courses the user is subscribed to - */ -function get_myagendaitems($user_id, $courses_dbs, $month, $year) { - global $setting_agenda_link; - $user_id = intval($user_id); - - $items = array(); - $my_list = array(); - - // get agenda-items for every course - foreach ($courses_dbs as $key => $array_course_info) { - //databases of the courses - $TABLEAGENDA = Database :: get_course_table(TABLE_AGENDA); - $TABLE_ITEMPROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY); - - $group_memberships = GroupManager :: get_group_ids($array_course_info["real_id"], $user_id); - $course_user_status = CourseManager::get_user_in_course_status($user_id, $array_course_info["code"]); - // if the user is administrator of that course we show all the agenda items - if ($course_user_status == '1') { - //echo "course admin"; - $sqlquery = "SELECT DISTINCT agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref - FROM ".$TABLEAGENDA." agenda, - ".$TABLE_ITEMPROPERTY." ip - WHERE agenda.id = ip.ref - AND MONTH(agenda.start_date)='".$month."' - AND YEAR(agenda.start_date)='".$year."' - AND ip.tool='".TOOL_CALENDAR_EVENT."' - AND ip.visibility='1' - GROUP BY agenda.id - ORDER BY start_date "; - } else { - // if the user is not an administrator of that course - if (is_array($group_memberships) && count($group_memberships)>0) { - $sqlquery = "SELECT agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref - FROM ".$TABLEAGENDA." agenda, - ".$TABLE_ITEMPROPERTY." ip - WHERE agenda.id = ip.ref - AND MONTH(agenda.start_date)='".$month."' - AND YEAR(agenda.start_date)='".$year."' - AND ip.tool='".TOOL_CALENDAR_EVENT."' - AND ( ip.to_user_id='".$user_id."' OR ip.to_group_id IN (0, ".implode(", ", $group_memberships).") ) - AND ip.visibility='1' - ORDER BY start_date "; - } else { - $sqlquery = "SELECT agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref - FROM ".$TABLEAGENDA." agenda, - ".$TABLE_ITEMPROPERTY." ip - WHERE agenda.id = ip.ref - AND MONTH(agenda.start_date)='".$month."' - AND YEAR(agenda.start_date)='".$year."' - AND ip.tool='".TOOL_CALENDAR_EVENT."' - AND ( ip.to_user_id='".$user_id."' OR ip.to_group_id='0') - AND ip.visibility='1' - ORDER BY start_date "; - } - } - $result = Database::query($sqlquery); - - while ($item = Database::fetch_array($result, 'ASSOC')) { - $agendaday = -1; - if ($item['start_date'] != '0000-00-00 00:00:00') { - $item['start_date'] = api_get_local_time($item['start_date']); - $item['start_date_tms'] = api_strtotime($item['start_date']); - $agendaday = date("j", $item['start_date_tms']); - } - if ($item['end_date'] != '0000-00-00 00:00:00') { - $item['end_date'] = api_get_local_time($item['end_date']); - } - - $url = api_get_path(WEB_CODE_PATH)."calendar/agenda.php?cidReq=".urlencode($array_course_info["code"])."&day=$agendaday&month=$month&year=$year#$agendaday"; - - $item['url'] = $url; - $item['course_name'] = $array_course_info['title']; - $item['calendar_type'] = 'course'; - $item['course_id'] = $array_course_info['course_id']; - - $my_list[$agendaday][] = $item; - } - } - - // sorting by hour for every day - $agendaitems = array (); - while (list ($agendaday, $tmpitems) = each($items)) { - if(!isset($agendaitems[$agendaday])) { - $agendaitems[$agendaday] = ''; - } - sort($tmpitems); - while (list ($key, $val) = each($tmpitems)) { - $agendaitems[$agendaday] .= $val; - } - } - return $my_list; -} - -/** - * Show the monthcalender of the given month - * @param array Agendaitems - * @param int Month number - * @param int Year number - * @param array Array of strings containing long week day names (deprecated, you can send an empty array instead) - * @param string The month name - * @return void Direct output - */ -function display_mymonthcalendar($user_id, $agendaitems, $month, $year, $weekdaynames = array(), $monthName, $show_content = true) { - global $DaysShort, $course_path; - //Handle leap year - $numberofdays = array (0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); - if (($year % 400 == 0) or ($year % 4 == 0 and $year % 100 <> 0)) - $numberofdays[2] = 29; - //Get the first day of the month - $dayone = getdate(mktime(0, 0, 0, $month, 1, $year)); - //Start the week on monday - $startdayofweek = $dayone['wday'] <> 0 ? ($dayone['wday'] - 1) : 6; - $g_cc = (isset($_GET['courseCode'])?$_GET['courseCode']:''); - - $prev_icon = Display::return_icon('action_prev.png',get_lang('Previous')); - $next_icon = Display::return_icon('action_next.png',get_lang('Next')); - - $next_month = ($month == 1 ? 12 : $month -1); - $prev_month = ($month == 12 ? 1 : $month +1); - - $next_year = ($month == 1 ? $year -1 : $year); - $prev_year = ($month == 12 ? $year +1 : $year); - - if ($show_content) { - $back_url = Display::url($prev_icon, api_get_self()."?coursePath=".urlencode($course_path)."&courseCode=".Security::remove_XSS($g_cc)."&action=view&view=month&month=".$next_month."&year=".$next_year); - $next_url = Display::url($next_icon, api_get_self()."?coursePath=".urlencode($course_path)."&courseCode=".Security::remove_XSS($g_cc)."&action=view&view=month&month=".$prev_month."&year=".$prev_year); - } else { - $back_url = Display::url($prev_icon, '', array('onclick'=>"load_calendar('".$user_id."','".$next_month."', '".$next_year."'); ")); - $next_url = Display::url($next_icon, '', array('onclick'=>"load_calendar('".$user_id."','".$prev_month."', '".$prev_year."'); ")); - } - - echo ''; - echo ''; - echo ''; - echo ''; - - echo ''; - - echo ''; - for ($ii = 1; $ii < 8; $ii ++) { - echo ''; - } - echo ''; - - $curday = -1; - $today = getdate(); - while ($curday <= $numberofdays[$month]) { - echo ""; - for ($ii = 0; $ii < 7; $ii ++) { - if (($curday == -1) && ($ii == $startdayofweek)) { - $curday = 1; - } - if (($curday > 0) && ($curday <= $numberofdays[$month])) { - $bgcolor = $class = 'class="days_week"'; - $dayheader = Display::div($curday, array('class'=>'agenda_day')); - if (($curday == $today['mday']) && ($year == $today['year']) && ($month == $today['mon'])) { - $class = "class=\"days_today\" style=\"width:10%;\""; - } - - echo ""; - $curday ++; - } else { - echo ""; - } - } - echo ""; - } - echo "
'.$back_url.'

'.$monthName." ".$year.'

'.$next_url.'
'.$DaysShort[$ii % 7].'
".$dayheader; - - if (!empty($agendaitems[$curday])) { - $items = $agendaitems[$curday]; - $items = msort($items, 'start_date_tms'); - - foreach($items as $value) { - $value['title'] = Security::remove_XSS($value['title']); - $start_time = api_format_date($value['start_date'], TIME_NO_SEC_FORMAT); - $end_time = ''; - - if (!empty($value['end_date']) && $value['end_date'] != '0000-00-00 00:00:00') { - $end_time = '- '.api_format_date($value['end_date'], DATE_TIME_FORMAT_LONG).''; - } - $complete_time = ''.api_format_date($value['start_date'], DATE_TIME_FORMAT_LONG).' '.$end_time; - $time = ''.$start_time.''; - - switch($value['calendar_type']) { - case 'personal': - $bg_color = '#D0E7F4'; - $icon = Display::return_icon('user.png', get_lang('MyAgenda'), array(), ICON_SIZE_SMALL); - break; - case 'global': - $bg_color = '#FFBC89'; - $icon = Display::return_icon('view_remove.png', get_lang('GlobalEvent'), array(), ICON_SIZE_SMALL); - break; - case 'course': - $bg_color = '#CAFFAA'; - $icon_name = 'course.png'; - if (!empty($value['session_id'])) { - $icon_name = 'session.png'; - } - if ($show_content) { - $icon = Display::url(Display::return_icon($icon_name, $value['course_name'].' '.get_lang('Course'), array(), ICON_SIZE_SMALL), $value['url']); - } else { - $icon = Display::return_icon($icon_name, $value['course_name'].' '.get_lang('Course'), array(), ICON_SIZE_SMALL); - } - break; - default: - break; - } - - $result = '
'; - - if ($show_content) { - - //Setting a personal event to green - $icon = Display::div($icon, array('style'=>'float:right')); - - $link = $value['calendar_type'].'_'.$value['id'].'_'.$value['course_id'].'_'.$value['session_id']; - - //Link to bubble - $url = Display::url(cut($value['title'], 40), '#', array('id'=>$link, 'class'=>'opener')); - $result .= $time.' '.$icon.' '.Display::div($url); - - //Hidden content - $content = Display::div($icon.Display::tag('h2', $value['course_name']).'
'.Display::tag('h3', $value['title']).$complete_time.'
'.Security::remove_XSS($value['content'])); - - //Main div - $result .= Display::div($content, array('id'=>'main_'.$link, 'class' => 'dialog', 'style' => 'display:none')); - $result .= '
'; - echo $result; - //echo Display::div($content, array('id'=>'main_'.$value['calendar_type'].'_'.$value['id'], 'class' => 'dialog')); - } else { - echo $result .= $icon.''; - } - } - } - echo "
"; -} -/** - * Show the mini calender of the given month - */ -function display_myminimonthcalendar($agendaitems, $month, $year, $monthName) { - global $DaysShort,$course_path; - //Handle leap year - $numberofdays = array (0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); - if (($year % 400 == 0) or ($year % 4 == 0 and $year % 100 <> 0)) - $numberofdays[2] = 29; - //Get the first day of the month - $dayone = getdate(mktime(0, 0, 0, $month, 1, $year)); - //Start the week on monday - $startdayofweek = $dayone['wday'] <> 0 ? ($dayone['wday'] - 1) : 6; - $g_cc = (isset($_GET['courseCode'])?$_GET['courseCode']:''); - $backwardsURL = api_get_self()."?coursePath=".Security::remove_XSS($course_path)."&courseCode=".Security::remove_XSS($g_cc)."&month=". ($month == 1 ? 12 : $month -1)."&year=". ($month == 1 ? $year -1 : $year); - $forewardsURL = api_get_self()."?coursePath=".Security::remove_XSS($course_path)."&courseCode=".Security::remove_XSS($g_cc)."&month=". ($month == 12 ? 1 : $month +1)."&year=". ($month == 12 ? $year +1 : $year); - - echo "", "", ""; - echo "", "", ""; - - echo ""; - for ($ii = 1; $ii < 8; $ii ++) - { - echo ""; - } - echo ""; - $curday = -1; - $today = getdate(); - while ($curday <= $numberofdays[$month]) - { - echo ""; - for ($ii = 0; $ii < 7; $ii ++) { - if (($curday == -1) && ($ii == $startdayofweek)) - { - $curday = 1; - } - if (($curday > 0) && ($curday <= $numberofdays[$month])) { - $bgcolor = $ii < 5 ? $class = 'class="days_week"' : $class = 'class="days_weekend"'; - $dayheader = "$curday"; - if (($curday == $today['mday']) && ($year == $today['year']) && ($month == $today['mon'])) { - $dayheader = "$curday"; - $class = "class=\"days_today\""; - } - echo ""; - $curday ++; - } - else - { - echo ""; - } - } - echo ""; - } - echo "
".Display::return_icon('action_prev.png',get_lang('Previous'))."", $monthName, " ", $year, "".Display::return_icon('action_next.png',get_lang('Next'))."
", $DaysShort[$ii % 7], "
"; - if (!empty($agendaitems[$curday])) { - echo "".$dayheader.""; - } else { - echo $dayheader; - } - // "a".$dayheader." ".$agendaitems[$curday].""; - echo " 
"; -} - -/** - * This function shows all the forms that are needed form adding/editing a new personal agenda item - * @param date is the time in day - * @param date is the time in month - * @param date is the time in year - * @param date is the time in hour - * @param date is the time in minute - * @param string is the agenda title - * @param string is the content - * @param int is the id this param is optional, but is necessary if the item require be edited - */ -function store_personal_item($day, $month, $year, $hour, $minute, $title, $content, $id = "") { - - $tbl_personal_agenda = Database :: get_main_table(TABLE_PERSONAL_AGENDA); - - //constructing the date - $date = $year."-".$month."-".$day." ".$hour.":".$minute.":00"; - - if (!empty($date)) { - $date = api_get_utc_datetime($date); - } - - $date = Database::escape_string($date); - $title = Database::escape_string($title); - $content = Database::escape_string($content); - $id = intval($id); - - if (!empty($id)) { - // we are updating - $sql = "UPDATE ".$tbl_personal_agenda." SET user='".api_get_user_id()."', title='".$title."', text='".$content."', date='".$date."' WHERE id= ".$id; - } else { - // we are adding a new item - $sql = "INSERT INTO $tbl_personal_agenda (user, title, text, date) VALUES ('".api_get_user_id()."','$title', '$content', '$date')"; - } - $result = Database::query($sql); -} - -/** - * This function finds all the courses (also those of sessions) of the user and returns an array containing the - * database name of the courses. - * Xritten by Noel Dieschburg - * @todo remove this function and use the CourseManager get_courses_list_by_user_id - */ - -function get_all_courses_of_user() { - $TABLECOURS = Database :: get_main_table(TABLE_MAIN_COURSE); - $TABLECOURSUSER = Database :: get_main_table(TABLE_MAIN_COURSE_USER); - $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE); - $tbl_session_course_user= Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER); - $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION); - $sql_select_courses = "SELECT c.code k, c.visual_code vc, c.title i, c.tutor_name t, - c.db_name db, c.directory dir, '5' as status - FROM $TABLECOURS c, $tbl_session_course_user srcu - WHERE srcu.id_user='".api_get_user_id()."' - AND c.code=srcu.course_code - UNION - SELECT c.code k, c.visual_code vc, c.title i, c.tutor_name t, - c.db_name db, c.directory dir, cru.status status - FROM $TABLECOURS c, $TABLECOURSUSER cru - WHERE cru.user_id='".api_get_user_id()."' - AND c.code=cru.course_code"; - $result = Database::query($sql_select_courses); - while ($row = Database::fetch_array($result)) { - // we only need the database name of the course - $courses[] = array ("db" => $row['db'], "code" => $row['k'], "visual_code" => $row['vc'], "title" => $row['i'], "directory" => $row['dir'], "status" => $row['status']); - } - return $courses; - } - - - - -/** - * This function finds all the courses of the user and returns an array containing the - * database name of the courses. - */ -function get_courses_of_user() { - $TABLECOURS = Database :: get_main_table(TABLE_MAIN_COURSE); - $TABLECOURSUSER = Database :: get_main_table(TABLE_MAIN_COURSE_USER); - $sql_select_courses = "SELECT course.code k, course.visual_code vc, - course.title i, course.tutor_name t, course.db_name db, course.directory dir, course_rel_user.status status - FROM $TABLECOURS course, - $TABLECOURSUSER course_rel_user - WHERE course.code = course_rel_user.course_code - AND course_rel_user.user_id = '".api_get_user_id()."'"; - $result = Database::query($sql_select_courses); - while ($row = Database::fetch_array($result)) - { - // we only need the database name of the course - $courses[] = array ("db" => $row['db'], "code" => $row['k'], "visual_code" => $row['vc'], "title" => $row['i'], "directory" => $row['dir'], "status" => $row['status']); - } - return $courses; -} -/** - * This function retrieves all the personal agenda items and add them to the agenda items found by the other functions. - */ -function get_personal_agenda_items($user_id, $agendaitems, $day = "", $month = "", $year = "", $week = "", $type) { - $tbl_personal_agenda = Database :: get_main_table(TABLE_PERSONAL_AGENDA); - $user_id = intval($user_id); - - // 1. creating the SQL statement for getting the personal agenda items in MONTH view - if ($type == "month_view" or $type == "") { - // we are in month view - $sql = "SELECT * FROM ".$tbl_personal_agenda." WHERE user='".$user_id."' and MONTH(date)='".$month."' AND YEAR(date) = '".$year."' ORDER BY date ASC"; - } - - // 2. creating the SQL statement for getting the personal agenda items in WEEK view - // we are in week view - if ($type == "week_view") { - $start_end_day_of_week = calculate_start_end_of_week($week, $year); - $start_day = $start_end_day_of_week['start']['day']; - $start_month = $start_end_day_of_week['start']['month']; - $start_year = $start_end_day_of_week['start']['year']; - $end_day = $start_end_day_of_week['end']['day']; - $end_month = $start_end_day_of_week['end']['month']; - $end_year = $start_end_day_of_week['end']['year']; - // in sql statements you have to use year-month-day for date calculations - $start_filter = $start_year."-".$start_month."-".$start_day." 00:00:00"; - $start_filter = api_get_utc_datetime($start_filter); - $end_filter = $end_year."-".$end_month."-".$end_day." 23:59:59"; - $end_filter = api_get_utc_datetime($end_filter); - $sql = " SELECT * FROM ".$tbl_personal_agenda." WHERE user='".$user_id."' AND date>='".$start_filter."' AND date<='".$end_filter."'"; - } - // 3. creating the SQL statement for getting the personal agenda items in DAY view - if ($type == "day_view") { - // we are in day view - // we could use mysql date() function but this is only available from 4.1 and higher - $start_filter = $year."-".$month."-".$day." 00:00:00"; - $start_filter = api_get_utc_datetime($start_filter); - $end_filter = $year."-".$month."-".$day." 23:59:59"; - $end_filter = api_get_utc_datetime($end_filter); - $sql = " SELECT * FROM ".$tbl_personal_agenda." WHERE user='".$user_id."' AND date>='".$start_filter."' AND date<='".$end_filter."'"; - } - - $result = Database::query($sql); - while ($item = Database::fetch_array($result, 'ASSOC')) { - - $time_minute = api_convert_and_format_date($item['date'], TIME_NO_SEC_FORMAT); - $item['date'] = api_get_local_time($item['date']); - $item['start_date_tms'] = api_strtotime($item['date']); - $item['content'] = $item['text']; - - // we break the date field in the database into a date and a time part - $agenda_db_date = explode(" ", $item['date']); - $date = $agenda_db_date[0]; - $time = $agenda_db_date[1]; - // we divide the date part into a day, a month and a year - $agendadate = explode("-", $item['date']); - $year = intval($agendadate[0]); - $month = intval($agendadate[1]); - $day = intval($agendadate[2]); - // we divide the time part into hour, minutes, seconds - $agendatime = explode(":", $time); - - $hour = $agendatime[0]; - $minute = $agendatime[1]; - $second = $agendatime[2]; - - if ($type == 'month_view') { - $item['calendar_type'] = 'personal'; - $item['start_date'] = $item['date']; - $agendaitems[$day][] = $item; - continue; - } - - // if the student has specified a course we a add a link to that course - if ($item['course'] <> "") { - $url = api_get_path(WEB_CODE_PATH)."calendar/agenda.php?cidReq=".urlencode($item['course'])."&day=$day&month=$month&year=$year#$day"; // RH //Patrick Cool: to highlight the relevant agenda item - $course_link = "".$item['course'].""; - } else { - $course_link = ""; - } - // Creating the array that will be returned. If we have week or month view we have an array with the date as the key - // if we have a day_view we use a half hour as index => key 33 = 16h30 - if ($type !== "day_view") { - // This is the array construction for the WEEK or MONTH view - - //Display events in agenda - $agendaitems[$day] .= "
$time_minute $course_link ".$item['title']."

"; - - } else { - // this is the array construction for the DAY view - $halfhour = 2 * $agendatime['0']; - if ($agendatime['1'] >= '30') { - $halfhour = $halfhour +1; - } - - //Display events by list - $agendaitems[$halfhour] .= "
$time_minute $course_link ".$item['title']."
"; - } - } - return $agendaitems; -} -/** - * This function retrieves one personal agenda item returns it. - * @param int The agenda item ID - * @return array The results of the database query, or null if not found - */ -function get_personal_agenda_item($id) { - $tbl_personal_agenda = Database :: get_main_table(TABLE_PERSONAL_AGENDA); - $id = intval($id); - // make sure events of the personal agenda can only be seen by the user himself - $user = api_get_user_id(); - $sql = " SELECT * FROM ".$tbl_personal_agenda." WHERE id=".$id." AND user = ".$user; - $result = Database::query($sql); - if(Database::num_rows($result)==1) { - $item = Database::fetch_array($result); - } else { - $item = null; - } - return $item; -} -/** - * This function retrieves all the personal agenda items of the user and shows - * these items in one list (ordered by date and grouped by month (the month_bar) - */ -function show_personal_agenda() { - global $MonthsLong, $charset; - - $tbl_personal_agenda = Database :: get_main_table(TABLE_PERSONAL_AGENDA); - - // The SQL statement that retrieves all the personal agenda items of this user - $sql = "SELECT * FROM ".$tbl_personal_agenda." WHERE user='".api_get_user_id()."' ORDER BY date DESC"; - $result = Database::query($sql); - // variable initialisation - $month_bar = ""; - // setting the default day, month and year - if (!isset($_GET['day']) AND !isset($_GET['month']) AND !isset($_GET['year'])) { - $today = getdate(); - $year = $today['year']; - $month = $today['mon']; - $day = $today['mday']; - } - $export_icon = 'export.png'; - $export_icon_low = 'export_low_fade.png'; - $export_icon_high = 'export_high_fade.png'; - - // starting the table output - echo ''; - - $th = Display::tag('th', get_lang('Title')); - $th .= Display::tag('th', get_lang('Content')); - $th .= Display::tag('th', get_lang('StartTimeWindow')); - $th .= Display::tag('th', get_lang('Modify')); - - echo Display::tag('tr', $th); - - if (Database::num_rows($result) > 0) { - $counter = 0; - while ($myrow = Database::fetch_array($result)) { - /* display: the month bar */ - if ($month_bar != date("m", strtotime($myrow["date"])).date("Y", strtotime($myrow["date"]))) { - $month_bar = date("m", strtotime($myrow["date"])).date("Y", strtotime($myrow["date"])); - //echo ""; - } - // highlight: if a date in the small calendar is clicked we highlight the relevant items - $db_date = (int) date("d", strtotime($myrow["date"])).date("n", strtotime($myrow["date"])).date("Y", strtotime($myrow["date"])); - /* - if ($_GET["day"].$_GET["month"].$_GET["year"] <> $db_date) { - $style = "data"; - $text_style = "text"; - } else { - $style = "datanow"; - $text_style = "text"; - }*/ - - $class = 'row_even'; - if ($counter % 2) { - $class = 'row_odd'; - } - - echo ''; - echo '"; - - // display: the content - $content = $myrow['text']; - echo ""; - - - //display: date and time - echo '"; - //echo ''; //remove when enabling ical - //echo '"; - //echo ""; - - - /* display: the edit / delete icons */ - echo ""; - $counter++; - } - } else { - echo ''; - } - echo "
".$MonthsLong[date("n", strtotime($myrow["date"])) - 1]." ".date("Y", strtotime($myrow["date"]))."
'; - /* display: the title */ - echo $myrow['title']; - echo ""; - echo $content; - echo "'; - // adding an internal anchor - /*echo ""; - echo date("d", strtotime($myrow["date"]))." ".$MonthsLong[date("n", strtotime($myrow["date"])) - 1]." ".date("Y", strtotime($myrow["date"]))." ";*/ - - $myrow["date"] = api_get_local_time($myrow["date"]); - echo api_format_date($myrow["date"], DATE_TIME_FORMAT_LONG); - echo "'; - //echo ''.Display::return_icon($export_icon_high, get_lang('ExportiCalConfidential')).''; - //echo ''.Display::return_icon($export_icon_low, get_lang('ExportiCalPrivate')).''; - //echo ''.Display::return_icon($export_icon, get_lang('ExportiCalPublic')).''; - //echo "
"; - echo "".Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL)." "; - echo "".Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL).""; - echo "
'.get_lang('NoAgendaItems').'
"; -} - -/** - * This function retrieves all the personal agenda items of the given user_id and shows - * these items in one list (ordered by date and grouped by month (the month_bar) - * @param int user id - */ -function show_simple_personal_agenda($user_id) { - global $MonthsLong, $charset; - - $tbl_personal_agenda = Database :: get_main_table(TABLE_PERSONAL_AGENDA); - - // The SQL statement that retrieves all the personal agenda items of this user - $sql = "SELECT * FROM ".$tbl_personal_agenda." WHERE user='".$user_id."' ORDER BY date DESC"; - $result = Database::query($sql); - // variable initialisation - $month_bar = ""; - // setting the default day, month and year - if (!$_GET['day'] AND !$_GET['month'] AND !$_GET['year']) { - $today = getdate(); - $year = $today['year']; - $month = $today['mon']; - $day = $today['mday']; - } - $export_icon = 'export.png'; - $export_icon_low = 'export_low_fade.png'; - $export_icon_high = 'export_high_fade.png'; - $content = ''; - // starting the table output - if (Database::num_rows($result) > 0) { - while ($myrow = Database::fetch_array($result)) { - /*-------------------------------------------------- - display: the month bar - --------------------------------------------------*/ - if ($month_bar != date("m", strtotime($myrow["date"])).date("Y", strtotime($myrow["date"]))) { - $month_bar = date("m", strtotime($myrow["date"])).date("Y", strtotime($myrow["date"])); - $content.= $MonthsLong[date("n", strtotime($myrow["date"])) - 1]." ".date("Y", strtotime($myrow["date"])); - } - // highlight: if a date in the small calendar is clicked we highlight the relevant items - $db_date = (int) date("d", strtotime($myrow["date"])).date("n", strtotime($myrow["date"])).date("Y", strtotime($myrow["date"])); - if ($_GET["day"].$_GET["month"].$_GET["year"] <> $db_date) { - $style = "data"; - $text_style = "text"; - } else { - $style = "datanow"; - $text_style = "text"; - } - - // adding an internal anchor - $content.= date("d", strtotime($myrow["date"]))." ".$MonthsLong[date("n", strtotime($myrow["date"])) - 1]." ".date("Y", strtotime($myrow["date"]))." "; - $content.= strftime(get_lang("timeNoSecFormat"), strtotime($myrow["date"])); - - $content.= '
'; - $content.= $myrow['title']; - $content.= '
'; - - return $content; - } - } else { - return $content; - } -} - - -/** - * Get personal agenda items between two dates (=all events from all registered courses) - * @param int user ID of the user - * @param string Optional start date in datetime format (if no start date is given, uses today) - * @param string Optional end date in datetime format (if no date is given, uses one year from now) - * @return array Array of events ordered by start date, in [0]('datestart','dateend','title'),[1]('datestart','dateend','title','link','coursetitle') format, where datestart and dateend are in yyyyMMddhhmmss format. - * @TODO Implement really personal events (from user DB) and global events (from main DB) - */ -function get_personal_agenda_items_between_dates($user_id, $date_start='', $date_end='') { - $items = array (); - if ($user_id != strval(intval($user_id))) { return $items; } - if (empty($date_start)) { $date_start = date('Y-m-d H:i:s');} - if (empty($date_end)) { $date_end = date('Y-m-d H:i:s',mktime(0, 0, 0, date("m"), date("d"), date("Y")+1));} - $expr = '/\d{4}-\d{2}-\d{2}\ \d{2}:\d{2}:\d{2}/'; - if(!preg_match($expr,$date_start)) { return $items; } - if(!preg_match($expr,$date_end)) { return $items; } - - // get agenda-items for every course - $courses = api_get_user_courses($user_id,false); - foreach ($courses as $id => $course) { - $c = api_get_course_info($course['code']); - //databases of the courses - $t_a = Database :: get_course_table(TABLE_AGENDA, $course['db']); - $t_ip = Database :: get_course_table(TABLE_ITEM_PROPERTY, $course['db']); - // get the groups to which the user belong - $group_memberships = GroupManager :: get_group_ids($course['db'], $user_id); - // if the user is administrator of that course we show all the agenda items - if ($course['status'] == '1') { - //echo "course admin"; - $sqlquery = "SELECT ". - " DISTINCT agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref ". - " FROM ".$t_a." agenda, ". - $t_ip." ip ". - " WHERE agenda.id = ip.ref ". - " AND agenda.start_date>='$date_start' ". - " AND agenda.end_date<='$date_end' ". - " AND ip.tool='".TOOL_CALENDAR_EVENT."' ". - " AND ip.visibility='1' ". - " GROUP BY agenda.id ". - " ORDER BY start_date "; - } else { - // if the user is not an administrator of that course, then... - if (is_array($group_memberships) && count($group_memberships)>0) - { - $sqlquery = "SELECT " . - "DISTINCT agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref ". - " FROM ".$t_a." agenda, ". - $t_ip." ip ". - " WHERE agenda.id = ip.ref ". - " AND agenda.start_date>='$date_start' ". - " AND agenda.end_date<='$date_end' ". - " AND ip.tool='".TOOL_CALENDAR_EVENT."' ". - " AND ( ip.to_user_id='".$user_id."' OR ip.to_group_id IN (0, ".implode(", ", $group_memberships).") ) ". - " AND ip.visibility='1' ". - " ORDER BY start_date "; - } else { - $sqlquery = "SELECT ". - "DISTINCT agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref ". - " FROM ".$t_a." agenda, ". - $t_ip." ip ". - " WHERE agenda.id = ip.ref ". - " AND agenda.start_date>='$date_start' ". - " AND agenda.end_date<='$date_end' ". - " AND ip.tool='".TOOL_CALENDAR_EVENT."' ". - " AND ( ip.to_user_id='".$user_id."' OR ip.to_group_id='0') ". - " AND ip.visibility='1' ". - " ORDER BY start_date "; - } - } - - $result = Database::query($sqlquery); - while ($item = Database::fetch_array($result)) { - $agendaday = date("j",strtotime($item['start_date'])); - $month = date("n",strtotime($item['start_date'])); - $year = date("Y",strtotime($item['start_date'])); - $URL = api_get_path(WEB_PATH)."main/calendar/agenda.php?cidReq=".urlencode($course["code"])."&day=$agendaday&month=$month&year=$year#$agendaday"; - list($year,$month,$day,$hour,$min,$sec) = split('[-: ]',$item['start_date']); - $start_date = $year.$month.$day.$hour.$min; - list($year,$month,$day,$hour,$min,$sec) = split('[-: ]',$item['end_date']); - $end_date = $year.$month.$day.$hour.$min; - - $items[] = array( - 'datestart'=>$start_date, - 'dateend'=>$end_date, - 'title'=>$item['title'], - 'link'=>$URL, - 'coursetitle'=>$c['name'], - ); - } - } - return $items; -} diff --git a/main/calendar/myagenda.php b/main/calendar/myagenda.php deleted file mode 100755 index 7448b77d1f..0000000000 --- a/main/calendar/myagenda.php +++ /dev/null @@ -1,251 +0,0 @@ - api_get_path(WEB_COURSE_PATH).urlencode($course_path).'/index.php', 'name' => Security::remove_XSS($_GET['courseCode'])); -} -// this loads the javascript that is needed for the date popup selection -$htmlHeadXtra[] = to_javascript(); -$htmlHeadXtra[] = ""; -$htmlHeadXtra[] = " -"; - -// showing the header -Display::display_header(get_lang('MyAgenda')); - - -// SETTING SOME VARIABLES - -// setting the database variables -$TABLECOURS = Database :: get_main_table(TABLE_MAIN_COURSE); -$TABLECOURSUSER = Database :: get_main_table(TABLE_MAIN_COURSE_USER); -$TABLEAGENDA = Database :: get_course_table(TABLE_AGENDA); -$TABLE_ITEMPROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY); -$tbl_personal_agenda= Database :: get_main_table(TABLE_PERSONAL_AGENDA); - -// the variables for the days and the months -// Defining the shorts for the days -$DaysShort = api_get_week_days_short(); -// Defining the days of the week to allow translation of the days -$DaysLong = api_get_week_days_long(); -// Defining the months of the year to allow translation of the months -$MonthsLong = api_get_months_long(); - -/* - TREATING THE URL PARAMETERS - 1. The default values - 2. storing it in the session - 3. possible view - 3.a Month view - 3.b Week view - 3.c day view - 3.d personal view (only the personal agenda items) - 4. add personal agenda - 5. edit personal agenda - 6. delete personal agenda -*/ - -// 1. The default values. if there is no session yet, we have by default the month view -if (empty($_SESSION['view'])) { - $_SESSION['view'] = 'month'; -} -// 2. Storing it in the session. If we change the view by clicking on the links left, we change the session -if (!empty($_GET['view'])) { - $_SESSION['view'] = Security::remove_XSS($_GET['view']); -} - -// 3. The views: (month, week, day, personal) -if ($_SESSION['view']) { - switch ($_SESSION['view']) { - // 3.a Month view - case "month" : - $process = 'month_view'; - break; - // 3.a Week view - case "week" : - $process = 'week_view'; - break; - // 3.a Day view - case "day" : - $process = 'day_view'; - break; - // 3.a Personal view - case "personal" : - $process = 'personal_view'; - break; - } -} -// 4. add personal agenda -if (!empty($_GET['action']) && $_GET['action'] == 'add_personal_agenda_item' and !$_POST['Submit']) { - $process = "add_personal_agenda_item"; -} - -if (!empty($_REQUEST['action']) && $_REQUEST['action'] == "add_personal_agenda_item" and $_POST['Submit']) { - $process = "store_personal_agenda_item"; -} -// 5. edit personal agenda -if (!empty($_GET['action']) && $_GET['action'] == 'edit_personal_agenda_item' and !$_POST['Submit']) { - $process = "edit_personal_agenda_item"; -} -if (!empty($_GET['action']) && $_GET['action'] == 'edit_personal_agenda_item' and $_POST['Submit']) { - $process = "store_personal_agenda_item"; -} -// 6. delete personal agenda -if (!empty($_GET['action']) && $_GET['action'] == "delete" AND $_GET['id']) { - $process = "delete_personal_agenda_item"; -} - -// OUTPUT -if (isset($_user['user_id'])) { - // getting all the courses that this user is subscribed to - //$courses_dbs = get_all_courses_of_user(); - $my_course_list = CourseManager::get_courses_list_by_user_id(api_get_user_id(), true); - - if (!is_array($my_course_list)) { - // this is for the special case if the user has no courses (otherwise you get an error) - $my_course_list = array(); - } - // setting and/or getting the year, month, day, week - $today = getdate(); - $year = (!empty($_GET['year'])? (int)$_GET['year'] : NULL); - if ($year == NULL) { - $year = $today['year']; - } - $month = (!empty($_GET['month'])? (int)$_GET['month']:NULL); - if ($month == NULL) { - $month = $today['mon']; - } - $day = (!empty($_GET['day']) ? (int)$_GET['day']:NULL); - if ($day == NULL) { - $day = $today['mday']; - } - $week = (!empty($_GET['week']) ?(int)$_GET['week']:NULL); - if ($week == NULL) { - $week = date("W"); - } - // The name of the current Month - $monthName = $MonthsLong[$month -1]; - // Starting the output - - echo ""; - - $agendaitems = get_myagendaitems(api_get_user_id(), $my_course_list, $month, $year); - $agendaitems = get_global_agenda_items($agendaitems, $day, $month, $year, $week, "month_view"); - - if (api_get_setting('allow_personal_agenda') == 'true') { - $agendaitems = get_personal_agenda_items(api_get_user_id(), $agendaitems, $day, $month, $year, $week, "month_view"); - } - - if ($process != 'month_view') { - echo ""; - echo ""; - // output: the small calendar item on the left and the view / add links - echo ""; - // the divider - // OlivierB : the image has a white background, which causes trouble if the portal has another background color. Image should be transparent. ----> echo ""; - echo ""; - // the main area: day, week, month view - echo "
"; - display_myminimonthcalendar($agendaitems, $month, $year, $monthName); - echo "  "; - } - - switch ($process) { - case 'month_view' : - display_mymonthcalendar(api_get_user_id(), $agendaitems, $month, $year, array(), $monthName); - break; - case 'week_view' : - $agendaitems = get_week_agendaitems($my_course_list, $month, $year, $week); - $agendaitems = get_global_agenda_items($agendaitems, $day, $month, $year, $week, "week_view"); - if (api_get_setting("allow_personal_agenda") == "true") { - $agendaitems = get_personal_agenda_items(api_get_user_id(), $agendaitems, $day, $month, $year, $week, "week_view"); - } - display_weekcalendar($agendaitems, $month, $year, array(), $monthName); - break; - case 'day_view' : - $agendaitems = get_day_agendaitems($my_course_list, $month, $year, $day); - $agendaitems = get_global_agenda_items($agendaitems, $day, $month, $year, $week, "day_view"); - if (api_get_setting('allow_personal_agenda') == 'true') { - $agendaitems = get_personal_agenda_items(api_get_user_id(), $agendaitems, $day, $month, $year, $week, "day_view"); - } - display_daycalendar($agendaitems, $day, $month, $year, array(), $monthName); - break; - case 'personal_view' : - show_personal_agenda(); - break; - case 'add_personal_agenda_item' : - //show_new_personal_item_form(); - break; - case 'store_personal_agenda_item' : - store_personal_item($_POST['frm_day'], $_POST['frm_month'], $_POST['frm_year'], $_POST['frm_hour'], $_POST['frm_minute'], $_POST['frm_title'], $_POST['frm_content'], $_GET['id']); - if ($_GET['id']) { - echo '
'; - Display :: display_normal_message(get_lang("PeronalAgendaItemEdited")); - } else { - echo '
'; - Display :: display_normal_message(get_lang("PeronalAgendaItemAdded")); - } - show_personal_agenda(); - break; - case 'edit_personal_agenda_item' : - //show_new_personal_item_form($_GET['id']); - break; - case 'delete_personal_agenda_item' : - //delete_personal_agenda($_GET['id']); - echo '
'; - Display :: display_normal_message(get_lang('PeronalAgendaItemDeleted')); - show_personal_agenda(); - break; - } -} -if ($process != 'month_view') { - echo '
'; -} -Display :: display_footer(); diff --git a/main/inc/ajax/agenda.ajax.php b/main/inc/ajax/agenda.ajax.php index 0b01c07370..658eddc8e0 100755 --- a/main/inc/ajax/agenda.ajax.php +++ b/main/inc/ajax/agenda.ajax.php @@ -12,9 +12,6 @@ if ($type == 'personal') { require_once '../global.inc.php'; -require_once api_get_path(SYS_CODE_PATH).'calendar/agenda.inc.php'; -require_once api_get_path(SYS_CODE_PATH).'calendar/myagenda.inc.php'; - $action = isset($_REQUEST['a']) ? $_REQUEST['a'] : null; $group_id = api_get_group_id(); @@ -142,14 +139,15 @@ switch ($action) { $day = $today['mday']; } $monthName = $MonthsLong[$month - 1]; + $week = null; - $agendaitems = get_myagendaitems( + $agendaitems = Agenda::get_myagendaitems( $user_id, $my_course_list, $month, $year ); - $agendaitems = get_global_agenda_items( + $agendaitems = Agenda::get_global_agenda_items( $agendaitems, $day, $month, @@ -159,7 +157,7 @@ switch ($action) { ); if (api_get_setting('allow_personal_agenda') == 'true') { - $agendaitems = get_personal_agenda_items( + $agendaitems = Agenda::get_personal_agenda_items( $user_id, $agendaitems, $day, @@ -169,7 +167,7 @@ switch ($action) { "month_view" ); } - display_mymonthcalendar( + Agenda::display_mymonthcalendar( $user_id, $agendaitems, $month, diff --git a/main/inc/lib/agenda.lib.php b/main/inc/lib/agenda.lib.php index 346b78aed5..086941351e 100644 --- a/main/inc/lib/agenda.lib.php +++ b/main/inc/lib/agenda.lib.php @@ -2433,4 +2433,638 @@ class Agenda 'groups' => array($groupId) ); } + + /** + * This function retrieves all the agenda items of all the courses the user is subscribed to + */ + public static function get_myagendaitems($user_id, $courses_dbs, $month, $year) + { + $user_id = intval($user_id); + + $items = array(); + $my_list = array(); + + // get agenda-items for every course + foreach ($courses_dbs as $key => $array_course_info) { + //databases of the courses + $TABLEAGENDA = Database :: get_course_table(TABLE_AGENDA); + $TABLE_ITEMPROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY); + + $group_memberships = GroupManager :: get_group_ids($array_course_info["real_id"], $user_id); + $course_user_status = CourseManager::get_user_in_course_status($user_id, $array_course_info["code"]); + // if the user is administrator of that course we show all the agenda items + if ($course_user_status == '1') { + //echo "course admin"; + $sqlquery = "SELECT DISTINCT agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref + FROM ".$TABLEAGENDA." agenda, + ".$TABLE_ITEMPROPERTY." ip + WHERE agenda.id = ip.ref + AND MONTH(agenda.start_date)='".$month."' + AND YEAR(agenda.start_date)='".$year."' + AND ip.tool='".TOOL_CALENDAR_EVENT."' + AND ip.visibility='1' + GROUP BY agenda.id + ORDER BY start_date "; + } else { + // if the user is not an administrator of that course + if (is_array($group_memberships) && count($group_memberships)>0) { + $sqlquery = "SELECT agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref + FROM ".$TABLEAGENDA." agenda, + ".$TABLE_ITEMPROPERTY." ip + WHERE agenda.id = ip.ref + AND MONTH(agenda.start_date)='".$month."' + AND YEAR(agenda.start_date)='".$year."' + AND ip.tool='".TOOL_CALENDAR_EVENT."' + AND ( ip.to_user_id='".$user_id."' OR ip.to_group_id IN (0, ".implode(", ", $group_memberships).") ) + AND ip.visibility='1' + ORDER BY start_date "; + } else { + $sqlquery = "SELECT agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref + FROM ".$TABLEAGENDA." agenda, + ".$TABLE_ITEMPROPERTY." ip + WHERE agenda.id = ip.ref + AND MONTH(agenda.start_date)='".$month."' + AND YEAR(agenda.start_date)='".$year."' + AND ip.tool='".TOOL_CALENDAR_EVENT."' + AND ( ip.to_user_id='".$user_id."' OR ip.to_group_id='0') + AND ip.visibility='1' + ORDER BY start_date "; + } + } + $result = Database::query($sqlquery); + + while ($item = Database::fetch_array($result, 'ASSOC')) { + $agendaday = -1; + if ($item['start_date'] != '0000-00-00 00:00:00') { + $item['start_date'] = api_get_local_time($item['start_date']); + $item['start_date_tms'] = api_strtotime($item['start_date']); + $agendaday = date("j", $item['start_date_tms']); + } + if ($item['end_date'] != '0000-00-00 00:00:00') { + $item['end_date'] = api_get_local_time($item['end_date']); + } + + $url = api_get_path(WEB_CODE_PATH)."calendar/agenda.php?cidReq=".urlencode($array_course_info["code"])."&day=$agendaday&month=$month&year=$year#$agendaday"; + + $item['url'] = $url; + $item['course_name'] = $array_course_info['title']; + $item['calendar_type'] = 'course'; + $item['course_id'] = $array_course_info['course_id']; + + $my_list[$agendaday][] = $item; + } + } + + // sorting by hour for every day + $agendaitems = array (); + while (list ($agendaday, $tmpitems) = each($items)) { + if(!isset($agendaitems[$agendaday])) { + $agendaitems[$agendaday] = ''; + } + sort($tmpitems); + while (list ($key, $val) = each($tmpitems)) { + $agendaitems[$agendaday] .= $val; + } + } + return $my_list; + } + + /** + * This function retrieves one personal agenda item returns it. + * @param array The array containing existing events. We add to this array. + * @param int Day + * @param int Month + * @param int Year (4 digits) + * @param int Week number + * @param string Type of view (month_view, week_view, day_view) + * @return array The results of the database query, or null if not found + */ + public static function get_global_agenda_items($agendaitems, $day = "", $month = "", $year = "", $week = "", $type) + { + $tbl_global_agenda = Database::get_main_table( + TABLE_MAIN_SYSTEM_CALENDAR + ); + $month = intval($month); + $year = intval($year); + $week = intval($week); + $day = intval($day); + // 1. creating the SQL statement for getting the personal agenda items in MONTH view + + $current_access_url_id = api_get_current_access_url_id(); + + if ($type == "month_view" or $type == "") { + // We are in month view + $sql = "SELECT * FROM ".$tbl_global_agenda." WHERE MONTH(start_date) = ".$month." AND YEAR(start_date) = ".$year." AND access_url_id = $current_access_url_id ORDER BY start_date ASC"; + } + // 2. creating the SQL statement for getting the personal agenda items in WEEK view + if ($type == "week_view") { // we are in week view + $start_end_day_of_week = self::calculate_start_end_of_week($week, $year); + $start_day = $start_end_day_of_week['start']['day']; + $start_month = $start_end_day_of_week['start']['month']; + $start_year = $start_end_day_of_week['start']['year']; + $end_day = $start_end_day_of_week['end']['day']; + $end_month = $start_end_day_of_week['end']['month']; + $end_year = $start_end_day_of_week['end']['year']; + // in sql statements you have to use year-month-day for date calculations + $start_filter = $start_year."-".$start_month."-".$start_day." 00:00:00"; + $start_filter = api_get_utc_datetime($start_filter); + + $end_filter = $end_year."-".$end_month."-".$end_day." 23:59:59"; + $end_filter = api_get_utc_datetime($end_filter); + $sql = " SELECT * FROM ".$tbl_global_agenda." WHERE start_date>='".$start_filter."' AND start_date<='".$end_filter."' AND access_url_id = $current_access_url_id "; + } + // 3. creating the SQL statement for getting the personal agenda items in DAY view + if ($type == "day_view") { // we are in day view + // we could use mysql date() function but this is only available from 4.1 and higher + $start_filter = $year."-".$month."-".$day." 00:00:00"; + $start_filter = api_get_utc_datetime($start_filter); + + $end_filter = $year."-".$month."-".$day." 23:59:59"; + $end_filter = api_get_utc_datetime($end_filter); + $sql = " SELECT * FROM ".$tbl_global_agenda." WHERE start_date>='".$start_filter."' AND start_date<='".$end_filter."' AND access_url_id = $current_access_url_id"; + } + + $result = Database::query($sql); + + while ($item = Database::fetch_array($result)) { + + if ($item['start_date'] != '0000-00-00 00:00:00') { + $item['start_date'] = api_get_local_time($item['start_date']); + $item['start_date_tms'] = api_strtotime($item['start_date']); + } + if ($item['end_date'] != '0000-00-00 00:00:00') { + $item['end_date'] = api_get_local_time($item['end_date']); + } + + // we break the date field in the database into a date and a time part + $agenda_db_date = explode(" ", $item['start_date']); + $date = $agenda_db_date[0]; + $time = $agenda_db_date[1]; + // we divide the date part into a day, a month and a year + $agendadate = explode("-", $date); + $year = intval($agendadate[0]); + $month = intval($agendadate[1]); + $day = intval($agendadate[2]); + // we divide the time part into hour, minutes, seconds + $agendatime = explode(":", $time); + $hour = $agendatime[0]; + $minute = $agendatime[1]; + $second = $agendatime[2]; + + if ($type == 'month_view') { + $item['calendar_type'] = 'global'; + $agendaitems[$day][] = $item; + continue; + } + + $start_time = api_format_date( + $item['start_date'], + TIME_NO_SEC_FORMAT + ); + $end_time = ''; + if ($item['end_date'] != '0000-00-00 00:00:00') { + $end_time = ' - '.api_format_date( + $item['end_date'], + DATE_TIME_FORMAT_LONG + ); + } + + // if the student has specified a course we a add a link to that course + if ($item['course'] <> "") { + $url = api_get_path( + WEB_CODE_PATH + )."admin/agenda.php?cidReq=".urlencode( + $item['course'] + )."&day=$day&month=$month&year=$year#$day"; // RH //Patrick Cool: to highlight the relevant agenda item + $course_link = "".$item['course'].""; + } else { + $course_link = ""; + } + // Creating the array that will be returned. If we have week or month view we have an array with the date as the key + // if we have a day_view we use a half hour as index => key 33 = 16h30 + if ($type !== "day_view") { + // This is the array construction for the WEEK or MONTH view + //Display the Agenda global in the tab agenda (administrator) + $agendaitems[$day] .= "$start_time $end_time - "; + $agendaitems[$day] .= "".get_lang('GlobalEvent').""; + $agendaitems[$day] .= "
".$item['title']."

"; + } else { + // this is the array construction for the DAY view + $halfhour = 2 * $agendatime['0']; + if ($agendatime['1'] >= '30') { + $halfhour = $halfhour + 1; + } + if (!is_array($agendaitems[$halfhour])) { + $content = $agendaitems[$halfhour]; + } + $agendaitems[$halfhour] = $content."
$hour:$minute ".get_lang( + 'GlobalEvent' + ).": ".$item['title']."
"; + } + } + + return $agendaitems; + } + + /** + * This function retrieves all the personal agenda items and add them to the agenda items found by the other functions. + */ + public static function get_personal_agenda_items($user_id, $agendaitems, $day = "", $month = "", $year = "", $week = "", $type) + { + $tbl_personal_agenda = Database :: get_main_table(TABLE_PERSONAL_AGENDA); + $user_id = intval($user_id); + + // 1. creating the SQL statement for getting the personal agenda items in MONTH view + if ($type == "month_view" or $type == "") { + // we are in month view + $sql = "SELECT * FROM ".$tbl_personal_agenda." WHERE user='".$user_id."' and MONTH(date)='".$month."' AND YEAR(date) = '".$year."' ORDER BY date ASC"; + } + + // 2. creating the SQL statement for getting the personal agenda items in WEEK view + // we are in week view + if ($type == "week_view") { + $start_end_day_of_week = self::calculate_start_end_of_week($week, $year); + $start_day = $start_end_day_of_week['start']['day']; + $start_month = $start_end_day_of_week['start']['month']; + $start_year = $start_end_day_of_week['start']['year']; + $end_day = $start_end_day_of_week['end']['day']; + $end_month = $start_end_day_of_week['end']['month']; + $end_year = $start_end_day_of_week['end']['year']; + // in sql statements you have to use year-month-day for date calculations + $start_filter = $start_year."-".$start_month."-".$start_day." 00:00:00"; + $start_filter = api_get_utc_datetime($start_filter); + $end_filter = $end_year."-".$end_month."-".$end_day." 23:59:59"; + $end_filter = api_get_utc_datetime($end_filter); + $sql = " SELECT * FROM ".$tbl_personal_agenda." WHERE user='".$user_id."' AND date>='".$start_filter."' AND date<='".$end_filter."'"; + } + // 3. creating the SQL statement for getting the personal agenda items in DAY view + if ($type == "day_view") { + // we are in day view + // we could use mysql date() function but this is only available from 4.1 and higher + $start_filter = $year."-".$month."-".$day." 00:00:00"; + $start_filter = api_get_utc_datetime($start_filter); + $end_filter = $year."-".$month."-".$day." 23:59:59"; + $end_filter = api_get_utc_datetime($end_filter); + $sql = " SELECT * FROM ".$tbl_personal_agenda." WHERE user='".$user_id."' AND date>='".$start_filter."' AND date<='".$end_filter."'"; + } + + $result = Database::query($sql); + while ($item = Database::fetch_array($result, 'ASSOC')) { + + $time_minute = api_convert_and_format_date($item['date'], TIME_NO_SEC_FORMAT); + $item['date'] = api_get_local_time($item['date']); + $item['start_date_tms'] = api_strtotime($item['date']); + $item['content'] = $item['text']; + + // we break the date field in the database into a date and a time part + $agenda_db_date = explode(" ", $item['date']); + $date = $agenda_db_date[0]; + $time = $agenda_db_date[1]; + // we divide the date part into a day, a month and a year + $agendadate = explode("-", $item['date']); + $year = intval($agendadate[0]); + $month = intval($agendadate[1]); + $day = intval($agendadate[2]); + // we divide the time part into hour, minutes, seconds + $agendatime = explode(":", $time); + + $hour = $agendatime[0]; + $minute = $agendatime[1]; + $second = $agendatime[2]; + + if ($type == 'month_view') { + $item['calendar_type'] = 'personal'; + $item['start_date'] = $item['date']; + $agendaitems[$day][] = $item; + continue; + } + + // if the student has specified a course we a add a link to that course + if ($item['course'] <> "") { + $url = api_get_path(WEB_CODE_PATH)."calendar/agenda.php?cidReq=".urlencode($item['course'])."&day=$day&month=$month&year=$year#$day"; // RH //Patrick Cool: to highlight the relevant agenda item + $course_link = "".$item['course'].""; + } else { + $course_link = ""; + } + // Creating the array that will be returned. If we have week or month view we have an array with the date as the key + // if we have a day_view we use a half hour as index => key 33 = 16h30 + if ($type !== "day_view") { + // This is the array construction for the WEEK or MONTH view + + //Display events in agenda + $agendaitems[$day] .= "
$time_minute $course_link ".$item['title']."

"; + + } else { + // this is the array construction for the DAY view + $halfhour = 2 * $agendatime['0']; + if ($agendatime['1'] >= '30') { + $halfhour = $halfhour +1; + } + + //Display events by list + $agendaitems[$halfhour] .= "
$time_minute $course_link ".$item['title']."
"; + } + } + return $agendaitems; + } + + + /** + * Show the monthcalender of the given month + * @param array Agendaitems + * @param int Month number + * @param int Year number + * @param array Array of strings containing long week day names (deprecated, you can send an empty array instead) + * @param string The month name + * @return void Direct output + */ + public static function display_mymonthcalendar($user_id, $agendaitems, $month, $year, $weekdaynames = array(), $monthName, $show_content = true) + { + global $DaysShort, $course_path; + //Handle leap year + $numberofdays = array (0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); + if (($year % 400 == 0) or ($year % 4 == 0 and $year % 100 <> 0)) + $numberofdays[2] = 29; + //Get the first day of the month + $dayone = getdate(mktime(0, 0, 0, $month, 1, $year)); + //Start the week on monday + $startdayofweek = $dayone['wday'] <> 0 ? ($dayone['wday'] - 1) : 6; + $g_cc = (isset($_GET['courseCode'])?$_GET['courseCode']:''); + + $prev_icon = Display::return_icon('action_prev.png',get_lang('Previous')); + $next_icon = Display::return_icon('action_next.png',get_lang('Next')); + + $next_month = ($month == 1 ? 12 : $month -1); + $prev_month = ($month == 12 ? 1 : $month +1); + + $next_year = ($month == 1 ? $year -1 : $year); + $prev_year = ($month == 12 ? $year +1 : $year); + + if ($show_content) { + $back_url = Display::url($prev_icon, api_get_self()."?coursePath=".urlencode($course_path)."&courseCode=".Security::remove_XSS($g_cc)."&action=view&view=month&month=".$next_month."&year=".$next_year); + $next_url = Display::url($next_icon, api_get_self()."?coursePath=".urlencode($course_path)."&courseCode=".Security::remove_XSS($g_cc)."&action=view&view=month&month=".$prev_month."&year=".$prev_year); + } else { + $back_url = Display::url($prev_icon, '', array('onclick'=>"load_calendar('".$user_id."','".$next_month."', '".$next_year."'); ")); + $next_url = Display::url($next_icon, '', array('onclick'=>"load_calendar('".$user_id."','".$prev_month."', '".$prev_year."'); ")); + } + + echo ''; + echo ''; + echo ''; + echo ''; + + echo ''; + + echo ''; + for ($ii = 1; $ii < 8; $ii ++) { + echo ''; + } + echo ''; + + $curday = -1; + $today = getdate(); + while ($curday <= $numberofdays[$month]) { + echo ""; + for ($ii = 0; $ii < 7; $ii ++) { + if (($curday == -1) && ($ii == $startdayofweek)) { + $curday = 1; + } + if (($curday > 0) && ($curday <= $numberofdays[$month])) { + $bgcolor = $class = 'class="days_week"'; + $dayheader = Display::div($curday, array('class'=>'agenda_day')); + if (($curday == $today['mday']) && ($year == $today['year']) && ($month == $today['mon'])) { + $class = "class=\"days_today\" style=\"width:10%;\""; + } + + echo ""; + $curday ++; + } else { + echo ""; + } + } + echo ""; + } + echo "
'.$back_url.'

'.$monthName." ".$year.'

'.$next_url.'
'.$DaysShort[$ii % 7].'
".$dayheader; + + if (!empty($agendaitems[$curday])) { + $items = $agendaitems[$curday]; + $items = msort($items, 'start_date_tms'); + + foreach($items as $value) { + $value['title'] = Security::remove_XSS($value['title']); + $start_time = api_format_date($value['start_date'], TIME_NO_SEC_FORMAT); + $end_time = ''; + + if (!empty($value['end_date']) && $value['end_date'] != '0000-00-00 00:00:00') { + $end_time = '- '.api_format_date($value['end_date'], DATE_TIME_FORMAT_LONG).''; + } + $complete_time = ''.api_format_date($value['start_date'], DATE_TIME_FORMAT_LONG).' '.$end_time; + $time = ''.$start_time.''; + + switch($value['calendar_type']) { + case 'personal': + $bg_color = '#D0E7F4'; + $icon = Display::return_icon('user.png', get_lang('MyAgenda'), array(), ICON_SIZE_SMALL); + break; + case 'global': + $bg_color = '#FFBC89'; + $icon = Display::return_icon('view_remove.png', get_lang('GlobalEvent'), array(), ICON_SIZE_SMALL); + break; + case 'course': + $bg_color = '#CAFFAA'; + $icon_name = 'course.png'; + if (!empty($value['session_id'])) { + $icon_name = 'session.png'; + } + if ($show_content) { + $icon = Display::url(Display::return_icon($icon_name, $value['course_name'].' '.get_lang('Course'), array(), ICON_SIZE_SMALL), $value['url']); + } else { + $icon = Display::return_icon($icon_name, $value['course_name'].' '.get_lang('Course'), array(), ICON_SIZE_SMALL); + } + break; + default: + break; + } + + $result = '
'; + + if ($show_content) { + + //Setting a personal event to green + $icon = Display::div($icon, array('style'=>'float:right')); + + $link = $value['calendar_type'].'_'.$value['id'].'_'.$value['course_id'].'_'.$value['session_id']; + + //Link to bubble + $url = Display::url(cut($value['title'], 40), '#', array('id'=>$link, 'class'=>'opener')); + $result .= $time.' '.$icon.' '.Display::div($url); + + //Hidden content + $content = Display::div($icon.Display::tag('h2', $value['course_name']).'
'.Display::tag('h3', $value['title']).$complete_time.'
'.Security::remove_XSS($value['content'])); + + //Main div + $result .= Display::div($content, array('id'=>'main_'.$link, 'class' => 'dialog', 'style' => 'display:none')); + $result .= '
'; + echo $result; + //echo Display::div($content, array('id'=>'main_'.$value['calendar_type'].'_'.$value['id'], 'class' => 'dialog')); + } else { + echo $result .= $icon.''; + } + } + } + echo "
"; + } + + /** + * Get personal agenda items between two dates (=all events from all registered courses) + * @param int user ID of the user + * @param string Optional start date in datetime format (if no start date is given, uses today) + * @param string Optional end date in datetime format (if no date is given, uses one year from now) + * @return array Array of events ordered by start date, in + * [0]('datestart','dateend','title'),[1]('datestart','dateend','title','link','coursetitle') format, + * where datestart and dateend are in yyyyMMddhhmmss format. + * @TODO Implement really personal events (from user DB) and global events (from main DB) + */ + public static function get_personal_agenda_items_between_dates($user_id, $date_start='', $date_end='') + { + $items = array (); + if ($user_id != strval(intval($user_id))) { return $items; } + if (empty($date_start)) { $date_start = date('Y-m-d H:i:s');} + if (empty($date_end)) { $date_end = date('Y-m-d H:i:s',mktime(0, 0, 0, date("m"), date("d"), date("Y")+1));} + $expr = '/\d{4}-\d{2}-\d{2}\ \d{2}:\d{2}:\d{2}/'; + if(!preg_match($expr,$date_start)) { return $items; } + if(!preg_match($expr,$date_end)) { return $items; } + + // get agenda-items for every course + $courses = api_get_user_courses($user_id,false); + foreach ($courses as $id => $course) { + $c = api_get_course_info($course['code']); + //databases of the courses + $t_a = Database :: get_course_table(TABLE_AGENDA, $course['db']); + $t_ip = Database :: get_course_table(TABLE_ITEM_PROPERTY, $course['db']); + // get the groups to which the user belong + $group_memberships = GroupManager :: get_group_ids($course['db'], $user_id); + // if the user is administrator of that course we show all the agenda items + if ($course['status'] == '1') { + //echo "course admin"; + $sqlquery = "SELECT ". + " DISTINCT agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref ". + " FROM ".$t_a." agenda, ". + $t_ip." ip ". + " WHERE agenda.id = ip.ref ". + " AND agenda.start_date>='$date_start' ". + " AND agenda.end_date<='$date_end' ". + " AND ip.tool='".TOOL_CALENDAR_EVENT."' ". + " AND ip.visibility='1' ". + " GROUP BY agenda.id ". + " ORDER BY start_date "; + } else { + // if the user is not an administrator of that course, then... + if (is_array($group_memberships) && count($group_memberships)>0) + { + $sqlquery = "SELECT " . + "DISTINCT agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref ". + " FROM ".$t_a." agenda, ". + $t_ip." ip ". + " WHERE agenda.id = ip.ref ". + " AND agenda.start_date>='$date_start' ". + " AND agenda.end_date<='$date_end' ". + " AND ip.tool='".TOOL_CALENDAR_EVENT."' ". + " AND ( ip.to_user_id='".$user_id."' OR ip.to_group_id IN (0, ".implode(", ", $group_memberships).") ) ". + " AND ip.visibility='1' ". + " ORDER BY start_date "; + } else { + $sqlquery = "SELECT ". + "DISTINCT agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref ". + " FROM ".$t_a." agenda, ". + $t_ip." ip ". + " WHERE agenda.id = ip.ref ". + " AND agenda.start_date>='$date_start' ". + " AND agenda.end_date<='$date_end' ". + " AND ip.tool='".TOOL_CALENDAR_EVENT."' ". + " AND ( ip.to_user_id='".$user_id."' OR ip.to_group_id='0') ". + " AND ip.visibility='1' ". + " ORDER BY start_date "; + } + } + + $result = Database::query($sqlquery); + while ($item = Database::fetch_array($result)) { + $agendaday = date("j",strtotime($item['start_date'])); + $month = date("n",strtotime($item['start_date'])); + $year = date("Y",strtotime($item['start_date'])); + $URL = api_get_path(WEB_PATH)."main/calendar/agenda.php?cidReq=".urlencode($course["code"])."&day=$agendaday&month=$month&year=$year#$agendaday"; + list($year,$month,$day,$hour,$min,$sec) = split('[-: ]',$item['start_date']); + $start_date = $year.$month.$day.$hour.$min; + list($year,$month,$day,$hour,$min,$sec) = split('[-: ]',$item['end_date']); + $end_date = $year.$month.$day.$hour.$min; + + $items[] = array( + 'datestart'=>$start_date, + 'dateend'=>$end_date, + 'title'=>$item['title'], + 'link'=>$URL, + 'coursetitle'=>$c['name'], + ); + } + } + return $items; + } + + + /** + * This function retrieves one personal agenda item returns it. + * @param int The agenda item ID + * @return array The results of the database query, or null if not found + */ + public static function get_personal_agenda_item($id) + { + $tbl_personal_agenda = Database :: get_main_table(TABLE_PERSONAL_AGENDA); + $id = intval($id); + // make sure events of the personal agenda can only be seen by the user himself + $user = api_get_user_id(); + $sql = " SELECT * FROM ".$tbl_personal_agenda." WHERE id=".$id." AND user = ".$user; + $result = Database::query($sql); + if(Database::num_rows($result)==1) { + $item = Database::fetch_array($result); + } else { + $item = null; + } + return $item; + } + + + /** + * This function calculates the startdate of the week (monday) + * and the enddate of the week (sunday) + * and returns it as an array + */ + public static function calculate_start_end_of_week($week_number, $year) + { + // determine the start and end date + // step 1: we calculate a timestamp for a day in this week + $random_day_in_week = mktime(0, 0, 0, 1, 1, $year) + ($week_number) * (7 * 24 * 60 * 60); // we calculate a random day in this week + // step 2: we which day this is (0=sunday, 1=monday, ...) + $number_day_in_week = date('w', $random_day_in_week); + // step 3: we calculate the timestamp of the monday of the week we are in + $start_timestamp = $random_day_in_week - (($number_day_in_week -1) * 24 * 60 * 60); + // step 4: we calculate the timestamp of the sunday of the week we are in + $end_timestamp = $random_day_in_week + ((7 - $number_day_in_week +1) * 24 * 60 * 60) - 3600; + // step 5: calculating the start_day, end_day, start_month, end_month, start_year, end_year + $start_day = date('j', $start_timestamp); + $start_month = date('n', $start_timestamp); + $start_year = date('Y', $start_timestamp); + $end_day = date('j', $end_timestamp); + $end_month = date('n', $end_timestamp); + $end_year = date('Y', $end_timestamp); + $start_end_array['start']['day'] = $start_day; + $start_end_array['start']['month'] = $start_month; + $start_end_array['start']['year'] = $start_year; + $start_end_array['end']['day'] = $end_day; + $start_end_array['end']['month'] = $end_month; + $start_end_array['end']['year'] = $end_year; + return $start_end_array; + } + + } diff --git a/main/inc/lib/system_announcements.lib.php b/main/inc/lib/system_announcements.lib.php index 5af4b465dc..2b34fa408f 100755 --- a/main/inc/lib/system_announcements.lib.php +++ b/main/inc/lib/system_announcements.lib.php @@ -378,11 +378,20 @@ class SystemAnnouncementManager Debug::log_s(mysql_error()); return false; } + $id = null; if ($add_to_calendar) { - require_once 'calendar.lib.php'; - $agenda_id = agenda_add_item($title, $original_content, $date_start, $date_end); + $agenda = new Agenda(); + $agenda->setType('admin'); + $id = $agenda->add_event( + $date_start, + $date_end, + false, + $title, + $original_content + ); } - return Database::insert_id(); + + return $id; } /** diff --git a/main/webservices/user_info.soap.php b/main/webservices/user_info.soap.php index 10845551bf..2c08c83c58 100755 --- a/main/webservices/user_info.soap.php +++ b/main/webservices/user_info.soap.php @@ -171,10 +171,9 @@ function WSEventsList($username, $signature, $datestart = 0, $dateend = 0) { $user_id = UserManager::get_user_id_from_username($username); if ($user_id === false) { return $events_list; } // Error in user id recovery. - require_once '../calendar/myagenda.inc.php'; $ds = substr($datestart,0,4).'-'.substr($datestart,4,2).'-'.substr($datestart,6,2).' 00:00:00'; $de = substr($dateend,0,4).'-'.substr($dateend,4,2).'-'.substr($dateend,6,2).' 00:00:00'; - $events_list = get_personal_agenda_items_between_dates($user_id, $ds, $de); + $events_list = Agenda::get_personal_agenda_items_between_dates($user_id, $ds, $de); return $events_list; } diff --git a/main/work/work.lib.php b/main/work/work.lib.php index 60a21e9d49..4d3e1f2a15 100755 --- a/main/work/work.lib.php +++ b/main/work/work.lib.php @@ -4132,7 +4132,6 @@ function updatePublicationAssignment($workId, $params, $courseInfo, $groupId) $agendaId = 0; if (isset($params['add_to_calendar']) && $params['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'; // Setting today date diff --git a/tests/main/admin/calendar.lib.test.php b/tests/main/admin/calendar.lib.test.php index b2a76b0eb8..af282af155 100755 --- a/tests/main/admin/calendar.lib.test.php +++ b/tests/main/admin/calendar.lib.test.php @@ -12,30 +12,6 @@ class TestCalendar extends UnitTestCase //var_dump($res); } - /** - * Adds an agenda item in the database. Similar to store_new_agenda_item() except it takes parameters - * @param array Course info - * @param string Event title - * @param string Event content/description - * @param string Start date - * @param string End date - * @param array List of groups to which this event is added - * @param int Parent id (optional) - * @return int The new item's DB ID - */ - public function testAgendaAddItem(){ - global $_course; - $course_code=$_course; - $course_info = ''; - $title='test'; - $content='test function'; - $db_start_date='07/11/2009'; - $db_end_date='07/20/2009'; - $res = agenda_add_item($course_info, $title, $content, $db_start_date, $db_end_date, $to=array(), $parent_id=null); - $this->assertTrue($res>0,'Global agenda item could not be inserted'); - delete_agenda_item($res); - //var_dump($res); - } public function testStoreNewAgendaItem(){ global $_user; @@ -49,16 +25,6 @@ class TestCalendar extends UnitTestCase } } - public function testShowAddForm(){ - ob_start(); - global $MonthsLong; - $id=''; - $res= show_add_form($id); - ob_end_clean(); - $this->assertTrue(is_null($res)); - //var_dump($res); - } - public function testAddWeek(){ $timestamp=12; $num=1; @@ -98,57 +64,6 @@ class TestCalendar extends UnitTestCase //this function is not used or deprecated } - public function testGetCalendarItems(){ - global $_course; - $month=01; - $year=2010; - $res = get_calendar_items($month, $year); - $this->assertTrue(is_array($res)); - //var_dump($res); - } - - //This funtion need a path where will copy to the other folder. -/* - public function testAgendaImportIcal() { - global $_course; - $course_info = $_course; - $file = api_get_path(SYS_PATH).'tests/main/admin/icals/test.ics'; - $res = agenda_import_ical($course_info, $file); - if(is_bool($res)){ - $this->assertTrue(is_bool($res)); - $this->assertTrue($res===false || $res === true); - }else{ - $this->assertTrue($res); - } - } -*/ - - public function testStoreEditedAgendaItem(){ - ob_start(); - $id=1; - $title=''; - $content=''; - $start_date= 21; - $end_date=25; - $res = store_edited_agenda_item(); - $edit_result=save_edit_agenda_item($id,$title,$content,$start_date,$end_date); - ob_end_clean(); - $this->assertTrue($edit_result); - //var_dump($edit_result); - } - - public function testSaveEditAgendaItem(){ - $id=intval($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); - $res = save_edit_agenda_item($id,$title,$content,$start_date,$end_date); - $this->assertTrue($res); - $this->assertTrue(is_bool($res)); - //var_dump($res); - } - public function testCalculateStartEndOfWeek(){ $week_number=4; $year=2011; @@ -158,44 +73,6 @@ class TestCalendar extends UnitTestCase //var_dump($res); } - /** - * Displays all the agenda items - */ - public function testDisplayAgendaItems() { - global $is_courseAdmin; - ob_start(); - $TABLEAGENDA = Database::get_main_table(TABLE_MAIN_SYSTEM_CALENDAR); - $res = display_agenda_items(); - ob_end_clean(); - $this->assertTrue(is_null($res)); - } - - public function testDisplayDaycalendar(){ - ob_start(); - $agendaitems=''; - $day=''; - $month=''; - $year=''; - $weekdaynames=''; - $monthName=''; - $res = display_daycalendar($agendaitems, $day, $month, $year, $weekdaynames, $monthName); - ob_end_clean(); - $this->assertTrue(is_null($res)); - //var_dump($res); - } - - public function testDisplayWeekcalendar() { - ob_start(); - $agendaitems=''; - $month=10; - $year=2011; - $weekdaynames=''; - $monthName=''; - $res = display_weekcalendar($agendaitems, $month, $year, $weekdaynames, $monthName); - ob_end_clean(); - $this->assertTrue(is_null($res)); - //var_dump($res); - } public function testGetDayAgendaitems() { $courses_dbs=array(); @@ -204,50 +81,8 @@ class TestCalendar extends UnitTestCase $day='1'; $res = get_day_agendaitems($courses_dbs, $month, $year, $day); $this->assertTrue(is_array($res)); - //var_dump($res); } - public function testGetWeekAgendaitems() { - $courses_dbs=array(); - $month=01; - $year=2010; - $res = get_week_agendaitems($courses_dbs, $month, $year); - $this->assertTrue(is_array($res)); - } - -/* public function testGetRepeatedEventsDayView(){ - global $_course; - $start = 0; - $end = 0; - $params = array(); - $course_code = 'COURSETEST'; - $course_info = api_get_course_info($course_code); - $resul = get_repeated_events_day_view($course_info,$start,$end,$params); - $this->assertTrue(is_array($resul)); - } -*/ - public function testGetRepeatedEventsWeekView(){ - $course_info = 'COURSETEST'; - $resul = get_repeated_events_week_view($course_info, 0, 0, ''); - $this->assertTrue(is_array($resul)); - } -/* - public function testGetRepeatedEventsMonthView(){ - $course_code='COURSETEST'; - $course_info = api_get_course_info($course_code); - $resul= get_repeated_events_month_view($course_info,0,0,''); - $this->assertTrue(is_array($resul)); - //var_dump($resul); - } - public function testGetRepeatedEventsListView(){ - $course_code='COURSETEST'; - $course_info = api_get_course_info($course_code); - $resul = get_repeated_events_list_view($course_info,0,0,''); - $this->assertTrue(is_array($resul)); - //var_dump($resul); - } -*/ - public function testDeleteAgendaItem(){ $id=1; $res = delete_agenda_item($id); @@ -266,81 +101,6 @@ class TestCalendar extends UnitTestCase //var_dump($res); } - public function testUserGroupFilterJavascript(){ - $res = user_group_filter_javascript(); - $this->assertTrue($res); - $this->assertTrue(is_string($res)); - //var_dump($res); - } - - public function testDisplayMonthcalendar(){ - ob_start(); - global $MonthsLong; - global $DaysShort; - global $origin; - $month=05; - $year=2010; - $res = display_monthcalendar($month, $year); - ob_end_clean(); - $this->assertTrue(is_null($res)); - $this->assertNull($res); - //var_dump($res); - } - - public function testGetAgendaItem(){ - $id=4; - $res = get_agenda_item($id); - if(is_array($res)) { - $this->assertTrue(is_array($res)); - } - } - - - /** - * Makes an agenda item visible or invisible for a student - * @param integer id the id of the agenda item we are changing the visibility of - */ - public function testShowhideAgendaItem(){ - ob_start(); - $id=1; - global $nameTools; - $res = showhide_agenda_item($id); - //Show the message when the visibility was changed - $real_show = Display::display_normal_message(get_lang("VisibilityChanged")); - ob_end_clean(); - if(!empty($res)){ - $this->assertTrue($res); - $this->assertTrue($real_show); - } else { - $this->assertNull($res); - } - //var_dump($res); - } - - /** - * Displays only 1 agenda item. This is used when an agenda item is added to the learning path. - */ - public function testDisplayOneAgendaItem(){ - ob_start(); - $agenda_id=1; - $res = display_one_agenda_item($agenda_id); - ob_end_clean(); - $this->assertTrue(is_null($res)); - - } - - /** - * Show the form for adding a new agenda item. This is the same function that is used whenever we are editing an - * agenda item. When the id parameter is empty (default behaviour), then we show an empty form, else we are editing and - * we have to retrieve the information that is in the database and use this information in the forms. - */ - public function testShowGroupFilterForm(){ - ob_start(); - $res = show_group_filter_form(); - ob_end_clean(); - $this->assertTrue(is_null($res)); - } - public function testShowUserFilterForm(){ ob_start(); $res = show_user_filter_form(); @@ -348,13 +108,6 @@ class TestCalendar extends UnitTestCase $this->assertTrue(is_null($res)); } - public function testDisplayUpcomingEvents(){ - ob_start(); - $res = display_upcoming_events(); - ob_end_clean(); - $this->assertNull($res); - } - public function testIsRepeatedEvent() { //This is deprecated or not used } diff --git a/tests/test_manager.inc.php b/tests/test_manager.inc.php index f72a6fbdf6..0b04fca2b1 100755 --- a/tests/test_manager.inc.php +++ b/tests/test_manager.inc.php @@ -35,7 +35,6 @@ $libdir = dirname(__FILE__).'/../main/inc/lib/'; /**Files inside '/../main' */ require_once $maindir.'permissions/permissions_functions.inc.php'; -require_once $maindir.'admin/calendar.lib.php'; require_once $maindir.'dropbox/dropbox_class.inc.php'; require_once $maindir.'dropbox/dropbox_functions.inc.php'; require_once $maindir.'survey/survey.lib.php';