diff --git a/main/calendar/agenda.inc.php b/main/calendar/agenda.inc.php index 896b35155e..a36e62e7e5 100644 --- a/main/calendar/agenda.inc.php +++ b/main/calendar/agenda.inc.php @@ -39,33 +39,33 @@ require_once api_get_path(LIBRARY_PATH).'groupmanager.lib.php'; * @param integer $year: the 4-digit year indication e.g. 2005 * @return array */ -function get_calendar_items($select_month, $select_year, $select_day = false) { +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)) { - + + 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(); @@ -75,17 +75,17 @@ function get_calendar_items($select_month, $select_year, $select_day = false) { $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']); @@ -99,7 +99,7 @@ function get_calendar_items($select_month, $select_year, $select_day = false) { $new_group_memberships[]=$id; } } - $group_memberships = $new_group_memberships; + $group_memberships = $new_group_memberships; if (is_array($group_memberships) && count($group_memberships)>0) { $sql="SELECT @@ -219,7 +219,7 @@ function get_calendar_items($select_month, $select_year, $select_day = false) { } } //if (is_allowed_to_edit() OR( api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous())) // B. you are a student - else { + 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 @@ -251,25 +251,25 @@ function get_calendar_items($select_month, $select_year, $select_day = false) { } } } // you are a student - + $my_events = array(); $avoid_doubles = array(); $result = Database::query($sql); - + //Course venets - while($row = Database::fetch_array($result,'ASSOC')) { + while($row = Database::fetch_array($result,'ASSOC')) { $row['calendar_type'] = 'course'; - if (!in_array($row['id'], $avoid_doubles)) { + 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']); + $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['end_date_tms'] = api_strtotime($row['end_date']); } - + $my_events[] = $row; $avoid_doubles[] = $row['id']; } @@ -282,26 +282,26 @@ function get_calendar_items($select_month, $select_year, $select_day = false) { $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')) { + 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']); + $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'] = 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); @@ -310,16 +310,16 @@ function get_calendar_items($select_month, $select_year, $select_day = false) { $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; } @@ -340,12 +340,12 @@ function display_minimonthcalendar($agenda_items, $month, $year) { $month = intval(date('m')); } if (empty($year)) { - $month = date('Y'); + $month = date('Y'); } - - $month_name = $MonthsLong[$month -1]; - - + + $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)) @@ -356,20 +356,20 @@ function display_minimonthcalendar($agenda_items, $month, $year) { $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) { + $my_month = intval(substr($item["start_date"],5,2)); + if ($my_month == $month) { $new_items[$day][] = 1; - } + } } - + $agenda_items = $new_items; - + echo "
| ".Display::return_icon('action_prev.png',get_lang('Previous'))." | ", @@ -394,10 +394,10 @@ function display_minimonthcalendar($agenda_items, $month, $year) { if (($curday == $today['mday']) && ($year == $today['year']) && ($month == $today['mon'])) { $dayheader = "$curday"; $class = "class=\"days_today\""; - } + } echo ""; if (!empty($agenda_items[$curday])) { - echo "".$dayheader.""; + echo "".$dayheader.""; } else { echo $dayheader; } @@ -425,7 +425,7 @@ function display_minimonthcalendar($agenda_items, $month, $year) { function display_monthcalendar($month, $year, $agenda_items) { global $MonthsLong; global $DaysShort; - global $origin; + global $origin; //Handle leap year $numberofdays = array(0,31,28,31,30,31,30,31,31,30,31,30,31); @@ -433,7 +433,7 @@ function display_monthcalendar($month, $year, $agenda_items) { //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; @@ -456,16 +456,16 @@ function display_monthcalendar($month, $year, $agenda_items) { echo ' | '.$dayheader; } else { - $class = 'days_week'; - echo ' | '.$dayheader; + $class = 'days_week'; + echo ' | '.$dayheader; } echo ' | '; $curday++; @@ -564,14 +564,14 @@ function display_monthcalendar($month, $year, $agenda_items) { * @author: Patrick Cool
|---|