diff --git a/main/calendar/agenda.inc.php b/main/calendar/agenda.inc.php index fb42a64221..74dde4b70b 100644 --- a/main/calendar/agenda.inc.php +++ b/main/calendar/agenda.inc.php @@ -2,10 +2,10 @@ /* For licensing terms, see /license.txt */ /** * @author: Julio Montoya 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 + * @author: Patrick Cool, patrick.cool@UGent.be + * @todo this code should be clean as well as the myagenda.inc.php - jmontoya * @package chamilo.calendar -*/ + */ /** * Code */ @@ -39,80 +39,80 @@ $(function() { require_once api_get_path(LIBRARY_PATH).'groupmanager.lib.php'; - /** -* 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); + * 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"; + $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"; + $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 = ''; $show_all_current_personal = ''; } - // database variables - $TABLEAGENDA = Database::get_course_table(TABLE_AGENDA); - $TABLE_ITEM_PROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY); + // 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()); + $group_memberships = GroupManager::get_group_ids($course_info['real_id'], api_get_user_id()); $repeats = array(); - /* CONSTRUCT THE SQL STATEMENT */ + /* 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']); - } + // 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(); + $group_id = api_get_group_id(); - $session_condition = api_get_session_condition(api_get_session_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())) { + 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) { + $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); + $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; + 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 + 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." @@ -122,7 +122,7 @@ function get_calendar_items($select_month, $select_year, $select_day = false) { $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 + $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."' @@ -136,16 +136,15 @@ function get_calendar_items($select_month, $select_year, $select_day = false) { 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); + $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;
+                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
+            $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."'
@@ -153,14 +152,14 @@ function get_calendar_items($select_month, $select_year, $select_day = false) {
                 AND ip.lastedit_type<>'CalendareventDeleted'
                 $session_condition
                 GROUP BY ip.ref";
-                //removed   - > AND toolitemproperties.visibility='1'
+            //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
+            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."
@@ -169,15 +168,14 @@ function get_calendar_items($select_month, $select_year, $select_day = false) {
                     $session_condition
                     GROUP BY ip.ref
                     ORDER $sort_item $sort";
-
             }
             // 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
+                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."
@@ -185,11 +183,11 @@ function get_calendar_items($select_month, $select_year, $select_day = false) {
                         AND ( ip.visibility='0' OR ip.visibility='1')
                         $session_condition
                         GROUP BY ip.ref";
-                 } else {
+                } 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
+                    $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."
@@ -199,39 +197,39 @@ function get_calendar_items($select_month, $select_year, $select_day = false) {
                         GROUP BY ip.ref";
 
                     /*
-                    if (is_array($group_memberships) && count($group_memberships)>0)
-                    {
-                        echo $sql="SELECT
-                        agenda.*, toolitemproperties.*
-                        FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." toolitemproperties
-                        WHERE agenda.id = toolitemproperties.ref  ".$show_all_current."
-                        AND toolitemproperties.tool='".TOOL_CALENDAR_EVENT."'
-                        AND toolitemproperties.visibility='1' AND toolitemproperties.to_group_id IN (0, ".implode(", ", $group_memberships).")
-                        $session_condition
-                        GROUP BY toolitemproperties.ref
-                        ORDER BY start_date ".$sort;
-                    }
-                    else
-                    {
-                        $sql="SELECT
-                        agenda.*, toolitemproperties.*
-                        FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." toolitemproperties
-                        WHERE agenda.id = toolitemproperties.ref  ".$show_all_current."
-                        AND toolitemproperties.tool='".TOOL_CALENDAR_EVENT."'
-                        AND toolitemproperties.visibility='1' AND toolitemproperties.to_group_id='0'
-                        $session_condition
-                        GROUP BY toolitemproperties.ref
-                        ORDER BY start_date ".$sort;
-                    }
-                    */
-                 }
+                      if (is_array($group_memberships) && count($group_memberships)>0)
+                      {
+                      echo $sql="SELECT
+                      agenda.*, toolitemproperties.*
+                      FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." toolitemproperties
+                      WHERE agenda.id = toolitemproperties.ref  ".$show_all_current."
+                      AND toolitemproperties.tool='".TOOL_CALENDAR_EVENT."'
+                      AND toolitemproperties.visibility='1' AND toolitemproperties.to_group_id IN (0, ".implode(", ", $group_memberships).")
+                      $session_condition
+                      GROUP BY toolitemproperties.ref
+                      ORDER BY start_date ".$sort;
+                      }
+                      else
+                      {
+                      $sql="SELECT
+                      agenda.*, toolitemproperties.*
+                      FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." toolitemproperties
+                      WHERE agenda.id = toolitemproperties.ref  ".$show_all_current."
+                      AND toolitemproperties.tool='".TOOL_CALENDAR_EVENT."'
+                      AND toolitemproperties.visibility='1' AND toolitemproperties.to_group_id='0'
+                      $session_condition
+                      GROUP BY toolitemproperties.ref
+                      ORDER BY start_date ".$sort;
+                      }
+                     */
+                }
             }
         }
     } //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
+        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."
@@ -241,7 +239,7 @@ function get_calendar_items($select_month, $select_year, $select_day = false) {
                 $session_condition";
         } else {
             if (api_get_user_id()) {
-                 $sql="SELECT
+                $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."
@@ -250,7 +248,7 @@ function get_calendar_items($select_month, $select_year, $select_day = false) {
                     AND ip.visibility='1'
                     $session_condition";
             } else {
-                $sql="SELECT
+                $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."
@@ -267,17 +265,17 @@ function get_calendar_items($select_month, $select_year, $select_day = false) {
     $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 (!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'] = 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['end_date'] = api_get_local_time($row['end_date']);
+                $row['end_date_tms'] = api_strtotime($row['end_date']);
             }
 
             $my_events[] = $row;
@@ -286,7 +284,7 @@ function get_calendar_items($select_month, $select_year, $select_day = false) {
     }
 
     //Check my personal calendar items
-    if (api_get_setting('allow_personal_agenda') == 'true' && empty($_SESSION['user']) &&  empty($_SESSION['group'])) {
+    if (api_get_setting('allow_personal_agenda') == 'true' && empty($_SESSION['user']) && empty($_SESSION['group'])) {
         $tbl_personal_agenda = Database :: get_user_personal_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."
@@ -295,13 +293,13 @@ function get_calendar_items($select_month, $select_year, $select_day = false) {
         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'] = 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['end_date'] = api_get_local_time($row['end_date']);
+                $row['end_date_tms'] = api_strtotime($row['end_date']);
             }
             $my_events[] = $row;
         }
@@ -314,268 +312,269 @@ function get_calendar_items($select_month, $select_year, $select_day = false) {
 
         $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);
+        $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']);
+                $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['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;
+    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)) {
+ * 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;
-	    }
-	}
+    $month_name = $MonthsLong[$month - 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])) { + //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 "
"; + } 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; + * 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; + //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)); + //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; + //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); + $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; + $new_month = $month - 1; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; + 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).'
'; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; - echo ''; - for ($ii=1;$ii<8; $ii++) { - echo ''; - } + echo ''; + for ($ii = 1; $ii < 8; $ii++) { + echo ''; + } - echo ''; - $curday = -1; - $today = getdate(); + 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)); + $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 (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 ''; + 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 (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].'
'.$DaysShort[$ii % 7].'
'.$dayheader; - } else { - $class = 'days_week'; - echo ''.$dayheader; - } - echo ' 
'.$dayheader; + } else { + $class = 'days_week'; + echo ''.$dayheader; + } + echo ' 
'; + 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 "'; - }*/ - echo ' + /* if ((isset($_GET['id']) && $to=='everyone') || !isset($_GET['id'])) { + echo get_lang('Everybody').' '; + } */ + show_to_form($to); + /* if (isset($_GET['id']) && $to!='everyone') { + echo ''; + } */ + echo ' '; - } + } - // start date and time - echo '
'; - echo ' + // start date and time + echo '
'; + echo '
'; - ?> - - - - - - 'vertical-align: middle;')); ?> - - -    - - - + ?> + + + + + + 'vertical-align: middle;')); ?> + + +    + + +
'; - echo ''; - // end date and time - echo ''; - echo '
+ // end date and time + echo ''; + echo '
'; - ?> - - - - - - - 'vertical-align: middle;')), array ('id'=>'end_date_calendar_icon')); ?> - -    - - - - - - + ?> + + + + + + + 'vertical-align: middle;')), array('id' => 'end_date_calendar_icon')); ?> + +    + + + + + +
'; - // Repeating the calendar item - if (empty($id)) { - //only show repeat fields when adding, not for editing an calendar item - echo '
+ // Repeating the calendar item + if (empty($id)) { + //only show repeat fields when adding, not for editing an calendar item + echo '
 '.get_lang('RepeatEvent').' '; - ?> - - - - - - - - - - - - - - - + ?> + + + + + + + + + + + + + + +
'; - }//only show repeat fields if adding, not if editing - - // the main area of the agenda item: the wysiwyg editor - echo '
+ }//only show repeat fields if adding, not if editing + // the main area of the agenda item: the wysiwyg editor + echo '
'; - require_once api_get_path(LIBRARY_PATH) . "/fckeditor/fckeditor.php"; - $oFCKeditor = new FCKeditor('content') ; - $oFCKeditor->Width = '100%'; - $oFCKeditor->Height = '200'; - if(!api_is_allowed_to_edit(null,true)) { - $oFCKeditor->ToolbarSet = 'AgendaStudent'; - } else { - $oFCKeditor->ToolbarSet = 'Agenda'; - } - $oFCKeditor->Value = $content; - $return = $oFCKeditor->CreateHtml(); - echo $return; - //echo ''; - echo '
-
'; - - // the added resources - /*echo '
-
- '.get_lang('AddedResources').' -
-
'; - if ($_SESSION['allow_individual_calendar']=='show') - show_addresource_button('onclick="selectAll(this.form.elements[6],true)"'); - else - show_addresource_button(); - $form_elements=$_SESSION['formelements']; - echo display_resources(0); - $test=$_SESSION['addedresource']; - echo '
+ require_once api_get_path(LIBRARY_PATH)."/fckeditor/fckeditor.php"; + $oFCKeditor = new FCKeditor('content'); + $oFCKeditor->Width = '100%'; + $oFCKeditor->Height = '200'; + if (!api_is_allowed_to_edit(null, true)) { + $oFCKeditor->ToolbarSet = 'AgendaStudent'; + } else { + $oFCKeditor->ToolbarSet = 'Agenda'; + } + $oFCKeditor->Value = $content; + $return = $oFCKeditor->CreateHtml(); + echo $return; + //echo ''; + echo '
'; - */ - // File attachment - echo '
+ // the added resources + /* echo '
+
+ '.get_lang('AddedResources').' +
+
'; + if ($_SESSION['allow_individual_calendar']=='show') + show_addresource_button('onclick="selectAll(this.form.elements[6],true)"'); + else + show_addresource_button(); + $form_elements=$_SESSION['formelements']; + echo display_resources(0); + $test=$_SESSION['addedresource']; + echo '
+
'; + */ + + // File attachment + echo '
@@ -2735,41 +2725,42 @@ function show_add_form($id = '') { - // the submit button for storing the calendar item - echo '
+ // the submit button for storing the calendar item + echo '
'; - if(isset($_GET['id']) ) { - $class='save'; - $text=get_lang('ModifyEvent'); - } else { - $class='add'; - $text=get_lang('AgendaAdd'); - } - echo ''; - echo '
+ if (isset($_GET['id'])) { + $class = 'save'; + $text = get_lang('ModifyEvent'); + } else { + $class = 'add'; + $text = get_lang('AgendaAdd'); + } + echo ''; + echo '
'; - ?> - - + + 0) - { - $sqlquery = "SELECT + } + // 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.*, item_property.* FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEMPROPERTY." item_property @@ -2798,10 +2787,8 @@ function get_agendaitems($month, $year) { 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 + } else { + $sqlquery = "SELECT agenda.*, item_property.* FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEMPROPERTY." item_property @@ -2812,52 +2799,51 @@ function get_agendaitems($month, $year) { 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 "; - } - } + } + } - $mycourse = api_get_course_info(); - $result = Database::query($sqlquery); + $mycourse = api_get_course_info(); + $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); - $time = api_convert_and_format_date($item['start_date'], TIME_NO_SEC_FORMAT); - $URL = api_get_path(WEB_CODE_PATH).'calendar/agenda.php?cidReq='.$mycourse['id']."&day=$agendaday&month=$month&year=$year#$agendaday"; // RH //Patrick Cool: to highlight the relevant agenda item - $items[$agendaday][$item['start_time']] .= ''.$time.' '.$mycourse['official_code'].' '.$item['title'].'
'; - } + 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); + $URL = api_get_path(WEB_CODE_PATH).'calendar/agenda.php?cidReq='.$mycourse['id']."&day=$agendaday&month=$month&year=$year#$agendaday"; // RH //Patrick Cool: to highlight the relevant agenda item + $items[$agendaday][$item['start_time']] .= ''.$time.' '.$mycourse['official_code'].' '.$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; -} + // 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; + } -function display_upcoming_events() { + function display_upcoming_events() + { - $number_of_items_to_show = (int)api_get_setting('number_of_upcoming_events'); + $number_of_items_to_show = (int) api_get_setting('number_of_upcoming_events'); - //databases of the courses - $TABLEAGENDA = Database :: get_course_table(TABLE_AGENDA); - $TABLE_ITEMPROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY); - $mycourse = api_get_course_info(); - $myuser = api_get_user_info(); - $session_id = api_get_session_id(); + //databases of the courses + $TABLEAGENDA = Database :: get_course_table(TABLE_AGENDA); + $TABLE_ITEMPROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY); + $mycourse = api_get_course_info(); + $myuser = api_get_user_info(); + $session_id = api_get_session_id(); - $course_id = $mycourse['real_id']; + $course_id = $mycourse['real_id']; - $group_memberships = GroupManager :: get_group_ids($mycourse['real_id'], $myuser['user_id']); - // if the user is administrator of that course we show all the agenda items - if (api_is_allowed_to_edit(false,true)) { - //echo "course admin"; - $sqlquery = "SELECT + $group_memberships = GroupManager :: get_group_ids($mycourse['real_id'], $myuser['user_id']); + // if the user is administrator of that course we show all the agenda items + if (api_is_allowed_to_edit(false, true)) { + //echo "course admin"; + $sqlquery = "SELECT DISTINCT agenda.*, item_property.* FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEMPROPERTY." item_property @@ -2871,12 +2857,12 @@ function display_upcoming_events() { AND session_id = '".$session_id."' 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) and count($group_memberships)>0) { - $sqlquery = "SELECT + } + // if the user is not an administrator of that course + else { + //echo "GEEN course admin"; + if (is_array($group_memberships) and count($group_memberships) > 0) { + $sqlquery = "SELECT agenda.*, item_property.* FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEMPROPERTY." item_property @@ -2890,8 +2876,8 @@ function display_upcoming_events() { AND agenda.start_date > NOW() AND session_id = '".$session_id."' ORDER BY start_date "; - } else { - $sqlquery = "SELECT + } else { + $sqlquery = "SELECT agenda.*, item_property.* FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEMPROPERTY." item_property @@ -2905,268 +2891,271 @@ function display_upcoming_events() { AND agenda.start_date > NOW() AND session_id = '".$session_id."' ORDER BY start_date "; - } - } - $result = Database::query($sqlquery); - $counter = 0; - - if (Database::num_rows($result) > 0 ) { - echo '

'.get_lang('UpcomingEvent').'


'; - 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++; - } - } - } -} + } + } + $result = Database::query($sqlquery); + $counter = 0; -/** - * 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 - */ -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); - } + if (Database::num_rows($result) > 0) { + echo '

'.get_lang('UpcomingEvent').'


'; + 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++; + } + } + } + } - // 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 ""; + /** + * 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; + } - // 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 - */ -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']); - } + /** + * 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 (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 - - - //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 ""; + // 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 "
".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 "
"; + // 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 "
"; + } - // The table cells containing all the entries for that day - echo ""; - $counter = 0; + /** + * Display the weekly view of the calendar + */ + function display_weekcalendar($agendaitems, $month, $year, $weekdaynames, $monthName) + { - 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 ""; - $data = isset($agendaitems[date('j', $value)]) ? $agendaitems[date('j', $value)] : null; - echo "".$data."  "; - echo ""; - $counter ++; - } - echo ""; - echo ""; -} -/** - * Show the monthcalender of the given month - */ -function get_day_agendaitems($courses_dbs, $month, $year, $day) { - global $setting_agenda_link; + 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); - $items = array (); + 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 + */ + 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); + // 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']); + // 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); + $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 + // 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 @@ -3176,12 +3165,12 @@ function get_day_agendaitems($courses_dbs, $month, $year, $day) { 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 + } + // 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 @@ -3191,8 +3180,8 @@ function get_day_agendaitems($courses_dbs, $month, $year, $day) { 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 + } else { + $sqlquery = "SELECT agenda.*, item_property.* FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEMPROPERTY." item_property @@ -3202,87 +3191,88 @@ function get_day_agendaitems($courses_dbs, $month, $year, $day) { 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); + $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); + 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; - } + $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 + 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']."
"; - } - } + $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 - */ -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; - } + // 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 + */ + 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); - $start_end = calculate_start_end_of_week($week_number, $year); + $items = array(); + // The default value of the week + if ($week == '') { + $week_number = date("W", time()); + } else { + $week_number = $week; + } - $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); + $start_end = calculate_start_end_of_week($week_number, $year); - // 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); + $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); - // 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()); + // 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); - $user_course_status = CourseManager::get_user_in_course_status(api_get_user_id(),$array_course_info["code"]); + // 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()); - // if the user is administrator of that course we show all the agenda items - if ($user_course_status == '1') { - //echo "course admin"; - $sqlquery = "SELECT + $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 @@ -3292,12 +3282,12 @@ function get_week_agendaitems($courses_dbs, $month, $year, $week = '') { 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 + } + // 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 @@ -3307,8 +3297,8 @@ function get_week_agendaitems($courses_dbs, $month, $year, $week = '') { 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 + } else { + $sqlquery = "SELECT a.*, i.* FROM ".$TABLEAGENDA." a, ".$TABLE_ITEMPROPERTY." i @@ -3318,1377 +3308,1338 @@ function get_week_agendaitems($courses_dbs, $month, $year, $week = '') { AND ( i.to_user_id='".api_get_user_id()."' OR i.to_group_id='0') AND i.visibility='1' 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')"; - //var_dump($sqlquery); - $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); - } + } + } + //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')"; + //var_dump($sqlquery); + $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; - } - } + $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; - } - } + $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 " . + 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': - $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); + .(!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; } - $db_start = date('Y-m-d H:i:s', $start); - if(empty($end)) + + /** + * (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) { - $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 " . + $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) + .(!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) { - 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']); + $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']); + } + } } - $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; + } + 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; } - 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)) + + /** + * 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) { - $course_info = api_get_course_info(); - $course = $course_info['dbName']; + $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; } - $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) + + /** + * 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) { - return true; + 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; } - 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) + + /** + * 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) { - $y += floor($num/12); - $m += $num%12; + return $timestamp + $num * 604800; } - else + + /** + * 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) { - $m += $num; + 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); } - 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); + /** + * 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); } - $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 + /** + * 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.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(); + $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."')"; + $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."')"; - $result = Database::query($sql); - $last_id = Database::insert_id(); + $result = Database::query($sql); + $last_id = Database::insert_id(); - // add a attachment file in agenda + // add a attachment file in agenda - add_agenda_attachment_file($file_comment, $last_id); + add_agenda_attachment_file($file_comment, $last_id); - // store in last_tooledit (first the groups, then the users + // 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; + 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; + // 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); } } - 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; } - // storing the resources - if (!empty($_SESSION['source_type']) && !empty($last_id)) { - store_resources($_SESSION['source_type'], $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); + $last_id_file = Database::insert_id(); + // update item_property + api_item_property_update($_course, 'calendar_event_attachment', $id_attach, 'AgendaAttachmentDeleted', api_get_user_id()); + if (!empty($result)) { + Display::display_confirmation_message(get_lang("AttachmentFileDeleteSuccess")); + } } - 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); - $last_id_file=Database::insert_id(); - // update item_property - api_item_property_update($_course, 'calendar_event_attachment', $id_attach ,'AgendaAttachmentDeleted', api_get_user_id()); - if (!empty($result)) { - Display::display_confirmation_message(get_lang("AttachmentFileDeleteSuccess")); - } -} + /** + * 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) + { -/** - * 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']); - } + 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; + 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']; + // 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); + 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'])."' )"; - $result=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()); + // 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'])."' )"; + $result = 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) { + /** + * 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 + 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($_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; + 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']; + // 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 = (int)$agenda_id; - $safe_id_attach = (int)$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'])."' + 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 = (int) $agenda_id; + $safe_id_attach = (int) $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'"; - $result=Database::query($sql); - api_item_property_update($_course, 'calendar_event_attachment', $safe_id_attach ,'AgendaAttachmentUpdated', api_get_user_id()); - - } - } - } -} + $result = 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); + /** + * 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']; + $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; + $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; + 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 - */ -function agenda_import_ical($course_info,$file) { - require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php'; - - $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; + return true; } - require_once api_get_path(LIBRARY_PATH).'icalcreator/iCalcreator.class.php'; + /** + * 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) + { + require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php'; - $ical = new vcalendar(); - $ical->setConfig('directory', dirname($filepath) ); - $ical->setConfig('filename', basename($filepath) ); - $return = $ical->parse(); + $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; + } - //we need to recover: summary, description, dtstart, dtend, organizer, attendee, location (=course name), -/* - $ve = $ical->getComponent(VEVENT); + require_once api_get_path(LIBRARY_PATH).'icalcreator/iCalcreator.class.php'; + + $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 + //var_dump($title,$desc,$start_date,$end_date); + $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'); + $ttitle = $ve->getProperty('summary'); + $title = api_convert_encoding($ttitle, $charset, 'UTF-8'); - $tdesc = $ve->getProperty('description'); - $desc = api_convert_encoding($tdesc,$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']; + $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_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); - } - } + $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 - //var_dump($title,$desc,$start_date,$end_date); - $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; - } + //echo $start_date.' - '.$end_date; + $organizer = $ve->getProperty('organizer'); + $attendee = $ve->getProperty('attendee'); + $course_name = $ve->getProperty('location'); - $ttitle = $ve->getProperty('summary'); - $title = api_convert_encoding($ttitle, $charset, 'UTF-8'); + //insert the event in our database + $agenda_obj->type = 'course'; - $tdesc = $ve->getProperty('description'); - $desc = api_convert_encoding($tdesc,$charset,'UTF-8'); + $all_day = 'false'; - $start_date = $ve->getProperty('dtstart', false, true); + if ($start_date_string == $end_date_string) { + $all_day = 'true'; + } + $date = new DateTime($start_date_string); + $date->add(new DateInterval('P1D')); - 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']; + if ($start_date_string == $date->format('Y-m-d h:i:s')) { + $all_day = 'true'; } - } else { - continue; - } - $ts = $ve->getProperty('dtend'); + //var_dump($start_date_string, $end_date_string, $all_day); + $id = $agenda_obj->add_event($start_date_string, $end_date_string, $all_day, null, $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); + } - 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']; + //TODO: deal with count + if (!empty($repeat['COUNT'])) { + $count = $repeat['COUNT']; + $res = agenda_add_repeat_item($course_info, $id, $freq, $count, $attendee); } - } 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'; + $eventcount++; } - $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'; + if (!empty($message)) { + $message = implode('
', $message); } - - //var_dump($start_date_string, $end_date_string, $all_day); - $id = $agenda_obj->add_event($start_date_string, $end_date_string, $all_day, null, $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; } - 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 = Database::escape_string($month); - $year = Database::escape_string($year); - $week = Database::escape_string($week); - $day = Database::escape_string($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); + /** + * 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 = Database::escape_string($month); + $year = Database::escape_string($year); + $week = Database::escape_string($week); + $day = Database::escape_string($day); + // 1. creating the SQL statement for getting the personal agenda items in MONTH view - $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"; - } + $current_access_url_id = api_get_current_access_url_id(); - $result = Database::query($sql); + 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"; + } - while ($item = Database::fetch_array($result)) { + $result = Database::query($sql); - 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']); - } + while ($item = Database::fetch_array($result)) { - // 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; - } + 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']); + } - $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); - } + // 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; + } - // 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']."
"; + $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); + } - } - } - return $agendaitems; -} + // 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')); - $form->display(); -} \ No newline at end of file + 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')); + $form->display(); + } \ No newline at end of file diff --git a/main/calendar/agenda.lib.php b/main/calendar/agenda.lib.php index 94c34a5eeb..6f39c87e12 100644 --- a/main/calendar/agenda.lib.php +++ b/main/calendar/agenda.lib.php @@ -4,80 +4,83 @@ /** * @author: Julio Montoya Implementing a real agenda lib */ +class Agenda +{ + var $events = array(); + var $type = 'personal'; // personal, admin or course + + function __construct() + { + //Table definitions + $this->tbl_global_agenda = Database::get_main_table(TABLE_MAIN_SYSTEM_CALENDAR); + $this->tbl_personal_agenda = Database::get_user_personal_table(TABLE_PERSONAL_AGENDA); + $this->tbl_course_agenda = Database::get_course_table(TABLE_AGENDA); + + //Setting the course object if we are in a course + $this->course = null; + $course_info = api_get_course_info(); + if (!empty($course_info)) { + $this->course = $course_info; + } + + $this->events = array(); + + //Event colors + $this->event_platform_color = 'red'; //red + $this->event_course_color = '#458B00'; //green + $this->event_group_color = '#A0522D'; //siena + $this->event_session_color = '#00496D'; // kind of green + $this->event_personal_color = 'steel blue'; //steel blue + } -class Agenda { - var $events = array(); - var $type = 'personal'; // personal, admin or course - - function __construct() { - //Table definitions - $this->tbl_global_agenda = Database::get_main_table(TABLE_MAIN_SYSTEM_CALENDAR); - $this->tbl_personal_agenda = Database::get_user_personal_table(TABLE_PERSONAL_AGENDA); - $this->tbl_course_agenda = Database::get_course_table(TABLE_AGENDA); - - //Setting the course object if we are in a course - $this->course = null; - $course_info = api_get_course_info(); - if (!empty($course_info)) { - $this->course = $course_info; - } - - $this->events = array(); - - //Event colors - $this->event_platform_color = 'red';//red - $this->event_course_color = '#458B00'; //green - $this->event_group_color = '#A0522D'; //siena - $this->event_session_color = '#00496D'; // kind of green - $this->event_personal_color = 'steel blue'; //steel blue - } - - function set_course($course_info) { + function set_course($course_info) + { $this->course = $course_info; } - /** - * - * Adds an event to the calendar + /** + * + * Adds an event to the calendar * - * @param string start datetime format: 2012-06-14 09:00:00 - * @param string end datetime format: 2012-06-14 09:00:00 + * @param string start datetime format: 2012-06-14 09:00:00 + * @param string end datetime format: 2012-06-14 09:00:00 * @param string all day (true, false) - * @param string view agendaDay, agendaWeek, month @todo seems not to be used + * @param string view agendaDay, agendaWeek, month @todo seems not to be used * @param string title * @param string content * @param array users to send array('everyone') or a list of user ids * @param bool add event as a *course* announcement * - */ - function add_event($start, $end, $all_day, $view, $title, $content, $users_to_send = array(), $add_as_announcement = false) { - $start = api_get_utc_datetime($start); - $end = api_get_utc_datetime($end); - $all_day = isset($all_day) && $all_day == 'true' ? 1:0; - - $attributes = array(); - $id = null; - switch ($this->type) { - case 'personal': - $attributes['user'] = api_get_user_id(); - $attributes['title'] = $title; - $attributes['text'] = $content; - $attributes['date'] = $start; - $attributes['enddate'] = $end; - $attributes['all_day'] = $all_day; - $id = Database::insert($this->tbl_personal_agenda, $attributes); - break; - case 'course': - $attributes['title'] = $title; - $attributes['content'] = $content; - $attributes['start_date'] = $start; - $attributes['end_date'] = $end; - $attributes['all_day'] = $all_day; - $attributes['session_id'] = api_get_session_id(); - $attributes['c_id'] = $this->course['real_id']; - - //simple course event - $id = Database::insert($this->tbl_course_agenda, $attributes); + */ + function add_event($start, $end, $all_day, $view, $title, $content, $users_to_send = array(), $add_as_announcement = false) + { + $start = api_get_utc_datetime($start); + $end = api_get_utc_datetime($end); + $all_day = isset($all_day) && $all_day == 'true' ? 1 : 0; + + $attributes = array(); + $id = null; + switch ($this->type) { + case 'personal': + $attributes['user'] = api_get_user_id(); + $attributes['title'] = $title; + $attributes['text'] = $content; + $attributes['date'] = $start; + $attributes['enddate'] = $end; + $attributes['all_day'] = $all_day; + $id = Database::insert($this->tbl_personal_agenda, $attributes); + break; + case 'course': + $attributes['title'] = $title; + $attributes['content'] = $content; + $attributes['start_date'] = $start; + $attributes['end_date'] = $end; + $attributes['all_day'] = $all_day; + $attributes['session_id'] = api_get_session_id(); + $attributes['c_id'] = $this->course['real_id']; + + //simple course event + $id = Database::insert($this->tbl_course_agenda, $attributes); if ($id) { $group_id = api_get_group_id(); @@ -85,12 +88,12 @@ class Agenda { if ((!is_null($users_to_send)) or (!empty($group_id))) { $send_to = self::separate_users_groups($users_to_send); if (isset($send_to['everyone']) && $send_to['everyone']) { - api_item_property_update($this->course, TOOL_CALENDAR_EVENT, $id, "AgendaAdded", api_get_user_id(), $group_id ,'', $start, $end); + api_item_property_update($this->course, TOOL_CALENDAR_EVENT, $id, "AgendaAdded", api_get_user_id(), $group_id, '', $start, $end); } else { // storing the selected groups if (isset($send_to['groups']) && is_array($send_to['groups'])) { foreach ($send_to['groups'] as $group) { - api_item_property_update($this->course, TOOL_CALENDAR_EVENT, $id, "AgendaAdded", api_get_user_id(), $group,0, $start, $end); + api_item_property_update($this->course, TOOL_CALENDAR_EVENT, $id, "AgendaAdded", api_get_user_id(), $group, 0, $start, $end); } } @@ -107,40 +110,40 @@ class Agenda { self::store_agenda_item_as_announcement($id, $users_to_send); } } - break; - case 'admin': - $attributes['title'] = $title; - $attributes['content'] = $content; - $attributes['start_date'] = $start; - $attributes['end_date'] = $end; - $attributes['all_day'] = $all_day; - $attributes['access_url_id']= api_get_current_access_url_id(); - $id = Database::insert($this->tbl_global_agenda, $attributes); - break; - } - return $id; - } - - + break; + case 'admin': + $attributes['title'] = $title; + $attributes['content'] = $content; + $attributes['start_date'] = $start; + $attributes['end_date'] = $end; + $attributes['all_day'] = $all_day; + $attributes['access_url_id'] = api_get_current_access_url_id(); + $id = Database::insert($this->tbl_global_agenda, $attributes); + break; + } + return $id; + } /** * @param agenda_id * @sent agenda event to - **/ - - function store_agenda_item_as_announcement($item_id, $sent_to = array()){ - $table_agenda = Database::get_course_table(TABLE_AGENDA); - $course_id = api_get_course_int_id(); + * */ + function store_agenda_item_as_announcement($item_id, $sent_to = array()) + { + $table_agenda = Database::get_course_table(TABLE_AGENDA); + $course_id = api_get_course_int_id(); //check params - if (empty($item_id) or $item_id != strval(intval($item_id))) { return -1; } + if (empty($item_id) or $item_id != strval(intval($item_id))) { + return -1; + } //get the agenda item $item_id = Database::escape_string($item_id); $sql = "SELECT * FROM $table_agenda WHERE c_id = $course_id AND id = ".$item_id; $res = Database::query($sql); - if (Database::num_rows($res)>0) { + if (Database::num_rows($res) > 0) { $row = Database::fetch_array($res, 'ASSOC'); //Sending announcement @@ -157,103 +160,106 @@ class Agenda { * Edits an event * * @param int event id - * @param string start datetime format: 2012-06-14 09:00:00 - * @param string end datetime format: 2012-06-14 09:00:00 + * @param string start datetime format: 2012-06-14 09:00:00 + * @param string end datetime format: 2012-06-14 09:00:00 * @param int event is all day? 1|0 * @param string view * @param string event title * @param string event content */ - function edit_event($id, $start, $end, $all_day, $view, $title, $content) { - $start = api_get_utc_datetime($start); - - if ($all_day == '0') { - $end = api_get_utc_datetime($end); - } - $all_day = isset($all_day) && $all_day == '1' ? 1 : 0; - - $attributes = array(); - - switch($this->type) { - case 'personal': - $attributes['title'] = $title; - $attributes['text'] = $content; - $attributes['date'] = $start; - $attributes['enddate'] = $end; - Database::update($this->tbl_personal_agenda, $attributes, array('id = ?' => $id)); - break; - case 'course': + function edit_event($id, $start, $end, $all_day, $view, $title, $content) + { + $start = api_get_utc_datetime($start); + + if ($all_day == '0') { + $end = api_get_utc_datetime($end); + } + $all_day = isset($all_day) && $all_day == '1' ? 1 : 0; + + $attributes = array(); + + switch ($this->type) { + case 'personal': + $attributes['title'] = $title; + $attributes['text'] = $content; + $attributes['date'] = $start; + $attributes['enddate'] = $end; + Database::update($this->tbl_personal_agenda, $attributes, array('id = ?' => $id)); + break; + case 'course': $course_id = api_get_course_int_id(); - $attributes['title'] = $title; - $attributes['content'] = $content; - $attributes['start_date'] = $start; - $attributes['end_date'] = $end; + $attributes['title'] = $title; + $attributes['content'] = $content; + $attributes['start_date'] = $start; + $attributes['end_date'] = $end; if (!empty($course_id)) { Database::update($this->tbl_course_agenda, $attributes, array('id = ? AND c_id = ?' => array($id, $course_id))); } - break; - case 'admin': - $attributes['title'] = $title; - $attributes['content'] = $content; - $attributes['start_date'] = $start; - $attributes['end_date'] = $end; - Database::update($this->tbl_global_agenda, $attributes, array('id = ?' => $id)); - break; - break; - } - } - - function delete_event($id) { - switch($this->type) { - case 'personal': - Database::delete($this->tbl_personal_agenda, array('id = ?' => $id)); - break; - case 'course': + break; + case 'admin': + $attributes['title'] = $title; + $attributes['content'] = $content; + $attributes['start_date'] = $start; + $attributes['end_date'] = $end; + Database::update($this->tbl_global_agenda, $attributes, array('id = ?' => $id)); + break; + break; + } + } + + function delete_event($id) + { + switch ($this->type) { + case 'personal': + Database::delete($this->tbl_personal_agenda, array('id = ?' => $id)); + break; + case 'course': $course_id = api_get_course_int_id(); if (!empty($course_id)) { Database::delete($this->tbl_course_agenda, array('id = ? AND c_id = ?' => array($id, $course_id))); } - break; - case 'admin': - Database::delete($this->tbl_global_agenda, array('id = ?' => $id)); - break; - } - } - - /** - * - * Get agenda events - * @param int start tms - * @param int end tms - * @param int course id *integer* not the course code - * - */ - function get_events($start, $end, $course_id = null, $group_id = null,$sel_user = 0) { - - switch ($this->type) { - case 'admin': - $this->get_platform_events($start, $end); - break; - case 'course': + break; + case 'admin': + Database::delete($this->tbl_global_agenda, array('id = ?' => $id)); + break; + } + } + + /** + * + * Get agenda events + * @param int start tms + * @param int end tms + * @param int course id *integer* not the course code + * + */ + function get_events($start, $end, $course_id = null, $group_id = null, $sel_user = 0) + { + + switch ($this->type) { + case 'admin': + $this->get_platform_events($start, $end); + break; + case 'course': $session_id = api_get_session_id(); - $course_info = api_get_course_info_by_id($course_id); - $this->get_course_events($start, $end, $course_info, $group_id, $session_id,$sel_user); - break; - case 'personal': - default: + $course_info = api_get_course_info_by_id($course_id); + $this->get_course_events($start, $end, $course_info, $group_id, $session_id, $sel_user); + break; + case 'personal': + default: //Getting personal events - $this->get_personal_events($start, $end); + $this->get_personal_events($start, $end); //Getting platform/admin events - $this->get_platform_events($start, $end); + $this->get_platform_events($start, $end); //Getting course events - $my_course_list = array(); + $my_course_list = array(); - if (!api_is_anonymous()) { + if (!api_is_anonymous()) { $session_list = SessionManager::get_sessions_by_user(api_get_user_id()); - $my_course_list = CourseManager::get_courses_list_by_user_id(api_get_user_id(), true); - } + $my_course_list = CourseManager::get_courses_list_by_user_id(api_get_user_id(), true); + } if (!empty($session_list)) { foreach ($session_list as $session_item) { @@ -268,106 +274,108 @@ class Agenda { } } - if (!empty($my_course_list)) { - foreach ($my_course_list as $course_info_item) { - if (isset($course_id) && !empty($course_id)) { - if ($course_info_item['real_id'] == $course_id) { - $this->get_course_events($start, $end, $course_info_item); - } - } else { - $this->get_course_events($start, $end, $course_info_item); - } - } - } - break; - } - if (!empty($this->events)) { - return json_encode($this->events); - } - return ''; - } - - function resize_event($id, $day_delta, $minute_delta) { + if (!empty($my_course_list)) { + foreach ($my_course_list as $course_info_item) { + if (isset($course_id) && !empty($course_id)) { + if ($course_info_item['real_id'] == $course_id) { + $this->get_course_events($start, $end, $course_info_item); + } + } else { + $this->get_course_events($start, $end, $course_info_item); + } + } + } + break; + } + if (!empty($this->events)) { + return json_encode($this->events); + } + return ''; + } + + function resize_event($id, $day_delta, $minute_delta) + { // we convert the hour delta into minutes and add the minute delta - $delta = ($day_delta * 60 * 24) + $minute_delta; - $delta = intval($delta); + $delta = ($day_delta * 60 * 24) + $minute_delta; + $delta = intval($delta); - $event = $this->get_event($id); + $event = $this->get_event($id); if (!empty($event)) { - switch($this->type) { - case 'personal': - $sql = "UPDATE $this->tbl_personal_agenda SET all_day = 0, enddate = DATE_ADD(enddate, INTERVAL $delta MINUTE) + switch ($this->type) { + case 'personal': + $sql = "UPDATE $this->tbl_personal_agenda SET all_day = 0, enddate = DATE_ADD(enddate, INTERVAL $delta MINUTE) WHERE id=".intval($id); - $result = Database::query($sql); - break; - case 'course': - $sql = "UPDATE $this->tbl_course_agenda SET all_day = 0, end_date = DATE_ADD(end_date, INTERVAL $delta MINUTE) + $result = Database::query($sql); + break; + case 'course': + $sql = "UPDATE $this->tbl_course_agenda SET all_day = 0, end_date = DATE_ADD(end_date, INTERVAL $delta MINUTE) WHERE c_id = ".$this->course['real_id']." AND id=".intval($id); - $result = Database::query($sql); - break; - case 'admin': - $sql = "UPDATE $this->tbl_global_agenda SET all_day = 0, end_date = DATE_ADD(end_date, INTERVAL $delta MINUTE) + $result = Database::query($sql); + break; + case 'admin': + $sql = "UPDATE $this->tbl_global_agenda SET all_day = 0, end_date = DATE_ADD(end_date, INTERVAL $delta MINUTE) WHERE id=".intval($id); - $result = Database::query($sql); - break; - } - } - return 1; - + $result = Database::query($sql); + break; + } + } + return 1; } - function move_event($id, $day_delta, $minute_delta) { - // we convert the hour delta into minutes and add the minute delta - $delta = ($day_delta * 60 * 24) + $minute_delta; - $delta = intval($delta); + function move_event($id, $day_delta, $minute_delta) + { + // we convert the hour delta into minutes and add the minute delta + $delta = ($day_delta * 60 * 24) + $minute_delta; + $delta = intval($delta); - $event = $this->get_event($id); + $event = $this->get_event($id); $all_day = 0; if ($day_delta == 0 && $minute_delta == 0) { $all_day = 1; } - if (!empty($event)) { - switch($this->type) { - case 'personal': - $sql = "UPDATE $this->tbl_personal_agenda SET all_day = $all_day, date = DATE_ADD(date, INTERVAL $delta MINUTE), enddate = DATE_ADD(enddate, INTERVAL $delta MINUTE) + if (!empty($event)) { + switch ($this->type) { + case 'personal': + $sql = "UPDATE $this->tbl_personal_agenda SET all_day = $all_day, date = DATE_ADD(date, INTERVAL $delta MINUTE), enddate = DATE_ADD(enddate, INTERVAL $delta MINUTE) WHERE id=".intval($id); - $result = Database::query($sql); - break; - case 'course': - $sql = "UPDATE $this->tbl_course_agenda SET all_day = $all_day, start_date = DATE_ADD(start_date,INTERVAL $delta MINUTE), end_date = DATE_ADD(end_date, INTERVAL $delta MINUTE) + $result = Database::query($sql); + break; + case 'course': + $sql = "UPDATE $this->tbl_course_agenda SET all_day = $all_day, start_date = DATE_ADD(start_date,INTERVAL $delta MINUTE), end_date = DATE_ADD(end_date, INTERVAL $delta MINUTE) WHERE c_id = ".$this->course['real_id']." AND id=".intval($id); - $result = Database::query($sql); - break; - case 'admin': - $sql = "UPDATE $this->tbl_global_agenda SET all_day = $all_day, start_date = DATE_ADD(start_date,INTERVAL $delta MINUTE), end_date = DATE_ADD(end_date, INTERVAL $delta MINUTE) + $result = Database::query($sql); + break; + case 'admin': + $sql = "UPDATE $this->tbl_global_agenda SET all_day = $all_day, start_date = DATE_ADD(start_date,INTERVAL $delta MINUTE), end_date = DATE_ADD(end_date, INTERVAL $delta MINUTE) WHERE id=".intval($id); - $result = Database::query($sql); - break; - } - } - return 1; - } - - /** - * Gets a single event - * @param int event id - */ - function get_event($id) { - // make sure events of the personal agenda can only be seen by the user himself - $id = intval($id); - $event = null; - switch ($this->type) { - case 'personal': - $sql = " SELECT * FROM ".$this->tbl_personal_agenda." WHERE id = $id AND user = ".api_get_user_id(); - $result = Database::query($sql); - if (Database::num_rows($result)) { - $event = Database::fetch_array($result, 'ASSOC'); + $result = Database::query($sql); + break; + } + } + return 1; + } + + /** + * Gets a single event + * @param int event id + */ + function get_event($id) + { + // make sure events of the personal agenda can only be seen by the user himself + $id = intval($id); + $event = null; + switch ($this->type) { + case 'personal': + $sql = " SELECT * FROM ".$this->tbl_personal_agenda." WHERE id = $id AND user = ".api_get_user_id(); + $result = Database::query($sql); + if (Database::num_rows($result)) { + $event = Database::fetch_array($result, 'ASSOC'); $event['description'] = $event['text']; - } - break; - case 'course': + } + break; + case 'course': if (!empty($this->course['real_id'])) { $sql = " SELECT * FROM ".$this->tbl_course_agenda." WHERE c_id = ".$this->course['real_id']." AND id = ".$id; $result = Database::query($sql); @@ -376,87 +384,89 @@ class Agenda { $event['description'] = $event['content']; } } - break; - case 'admin': + break; + case 'admin': case 'platform': - $sql = " SELECT * FROM ".$this->tbl_global_agenda." WHERE id=".$id; - $result = Database::query($sql); - if (Database::num_rows($result)) { - $event = Database::fetch_array($result, 'ASSOC'); + $sql = " SELECT * FROM ".$this->tbl_global_agenda." WHERE id=".$id; + $result = Database::query($sql); + if (Database::num_rows($result)) { + $event = Database::fetch_array($result, 'ASSOC'); $event['description'] = $event['content']; - } - break; - } - return $event; - } - - /** - * - * Gets personal events - * @param int start date tms - * @param int end date tms - */ - function get_personal_events($start, $end) { - $start = intval($start); - $end = intval($end); - $start = api_get_utc_datetime($start); - $end = api_get_utc_datetime($end); - $user_id = api_get_user_id(); - - $sql = "SELECT * FROM ".$this->tbl_personal_agenda." + } + break; + } + return $event; + } + + /** + * + * Gets personal events + * @param int start date tms + * @param int end date tms + */ + function get_personal_events($start, $end) + { + $start = intval($start); + $end = intval($end); + $start = api_get_utc_datetime($start); + $end = api_get_utc_datetime($end); + $user_id = api_get_user_id(); + + $sql = "SELECT * FROM ".$this->tbl_personal_agenda." WHERE date >= '".$start."' AND (enddate <='".$end."' OR enddate IS NULL) AND user = $user_id"; - $result = Database::query($sql); + $result = Database::query($sql); $my_events = array(); - if (Database::num_rows($result)) { - while ($row = Database::fetch_array($result, 'ASSOC')) { - $event = array(); - $event['id'] = 'personal_'.$row['id']; - $event['title'] = $row['title']; - $event['className'] = 'personal'; - $event['borderColor'] = $event['backgroundColor'] = $this->event_personal_color; - $event['editable'] = true; - - $event['sent_to'] = get_lang('Me'); - $event['type'] = 'personal'; - - if (!empty($row['date']) && $row['date'] != '0000-00-00 00:00:00') { - $event['start'] = $this->format_event_date($row['date']); - } - - if (!empty($row['enddate']) && $row['enddate'] != '0000-00-00 00:00:00') { - $event['end'] = $this->format_event_date($row['enddate']); - } - $event['description'] = $row['text']; - $event['allDay'] = isset($row['all_day']) && $row['all_day'] == 1 ? $row['all_day'] : 0; - $my_events[] = $event; - $this->events[]= $event; - } - } - return $my_events; - } - - function get_course_events($start, $end, $course_info, $group_id = 0, $session_id = 0, $sel_user = 0) { - $course_id = $course_info['real_id']; + if (Database::num_rows($result)) { + while ($row = Database::fetch_array($result, 'ASSOC')) { + $event = array(); + $event['id'] = 'personal_'.$row['id']; + $event['title'] = $row['title']; + $event['className'] = 'personal'; + $event['borderColor'] = $event['backgroundColor'] = $this->event_personal_color; + $event['editable'] = true; + + $event['sent_to'] = get_lang('Me'); + $event['type'] = 'personal'; + + if (!empty($row['date']) && $row['date'] != '0000-00-00 00:00:00') { + $event['start'] = $this->format_event_date($row['date']); + } + + if (!empty($row['enddate']) && $row['enddate'] != '0000-00-00 00:00:00') { + $event['end'] = $this->format_event_date($row['enddate']); + } + $event['description'] = $row['text']; + $event['allDay'] = isset($row['all_day']) && $row['all_day'] == 1 ? $row['all_day'] : 0; + $my_events[] = $event; + $this->events[] = $event; + } + } + return $my_events; + } + + function get_course_events($start, $end, $course_info, $group_id = 0, $session_id = 0, $sel_user = 0) + { + $course_id = $course_info['real_id']; $group_list = GroupManager::get_group_list(null, $course_info['code']); $group_name_list = array(); if (!empty($group_list)) { - foreach($group_list as $group) { - $group_name_list[$group['id']]= $group['name']; + foreach ($group_list as $group) { + $group_name_list[$group['id']] = $group['name']; } } if (!api_is_allowed_to_edit()) { - $group_memberships = GroupManager::get_group_ids($course_id, api_get_user_id()); + $group_memberships = GroupManager::get_group_ids($course_id, api_get_user_id()); } else { $group_memberships = array_keys($group_name_list); } - $tlb_course_agenda = Database::get_course_table(TABLE_AGENDA); - $tbl_property = Database::get_course_table(TABLE_ITEM_PROPERTY); + $tlb_course_agenda = Database::get_course_table(TABLE_AGENDA); + $tbl_property = Database::get_course_table(TABLE_ITEM_PROPERTY); if (api_is_allowed_to_edit()) { - $user_id = $sel_user; + $user_id = $sel_user; } else { $user_id = api_get_user_id(); } @@ -467,14 +477,13 @@ class Agenda { $session_id = intval($session_id); - if (is_array($group_memberships) && count($group_memberships) > 0) { - if (api_is_allowed_to_edit()) { - if($user_id !=0) { + if (is_array($group_memberships) && count($group_memberships) > 0) { + if (api_is_allowed_to_edit()) { + if ($user_id != 0) { $where_condition = "( ip.to_user_id = $user_id AND ip.to_group_id is null OR ip.to_group_id IN (0, ".implode(", ", $group_memberships).") ) "; - } else { - $where_condition = "( ip.to_group_id is null OR ip.to_group_id IN (0, ".implode(", ", $group_memberships).") ) "; + } else { + $where_condition = "( ip.to_group_id is null OR ip.to_group_id IN (0, ".implode(", ", $group_memberships).") ) "; } - } else { $where_condition = "( ip.to_user_id = $user_id OR ip.to_group_id IN (0, ".implode(", ", $group_memberships).") ) "; } @@ -489,10 +498,9 @@ class Agenda { ip.c_id = $course_id GROUP BY id"; - - } else { - if (api_is_allowed_to_edit()) { - $where_condition = ""; + } else { + if (api_is_allowed_to_edit()) { + $where_condition = ""; } else { $where_condition = "( ip.to_user_id=$user_id OR ip.to_group_id='0') AND "; } @@ -508,14 +516,13 @@ class Agenda { agenda.session_id = $session_id AND ip.id_session = $session_id "; + } - } - - $result = Database::query($sql); - $events = array(); - if (Database::num_rows($result)) { + $result = Database::query($sql); + $events = array(); + if (Database::num_rows($result)) { $events_added = array(); - while ($row = Database::fetch_array($result, 'ASSOC')) { + while ($row = Database::fetch_array($result, 'ASSOC')) { //to gather sent_tos $sql = "SELECT to_user_id, to_group_id FROM ".$tbl_property." ip @@ -531,20 +538,20 @@ class Agenda { $group_to_array[] = $row_send_to['to_group_id']; } if (!empty($row_send_to['to_user_id'])) { - $user_to_array[] = $row_send_to['to_user_id']; + $user_to_array[] = $row_send_to['to_user_id']; } } - //Only show events from the session - /*if (api_get_course_int_id()) { - if ($row['session_id'] != api_get_session_id()) { - continue; - } - }*/ + //Only show events from the session + /* if (api_get_course_int_id()) { + if ($row['session_id'] != api_get_session_id()) { + continue; + } + } */ - $event = array(); + $event = array(); - $event['id'] = 'course_'.$row['id']; + $event['id'] = 'course_'.$row['id']; //To avoid doubles if (in_array($row['id'], $events_added)) { @@ -558,68 +565,68 @@ class Agenda { $has_attachment = ''; if (!empty($attachment)) { - $has_attachment = Display::return_icon('attachment.gif',get_lang('Attachment')); - $user_filename = $attachment['filename']; + $has_attachment = Display::return_icon('attachment.gif', get_lang('Attachment')); + $user_filename = $attachment['filename']; $full_file_name = 'download.php?file='.$attachment['path'].'&course_id='.$course_id; $event['attachment'] = $has_attachment.Display::url($user_filename, $full_file_name); } else { $event['attachment'] = ''; } - $event['title'] = $row['title']; - $event['className'] = 'course'; - $event['allDay'] = 'false'; + $event['title'] = $row['title']; + $event['className'] = 'course'; + $event['allDay'] = 'false'; - $event['course_id'] = $course_id; + $event['course_id'] = $course_id; - $event['borderColor'] = $event['backgroundColor'] = $this->event_course_color; - if (isset($row['session_id']) && !empty($row['session_id'])) { - $event['borderColor'] = $event['backgroundColor'] = $this->event_session_color; - } + $event['borderColor'] = $event['backgroundColor'] = $this->event_course_color; + if (isset($row['session_id']) && !empty($row['session_id'])) { + $event['borderColor'] = $event['backgroundColor'] = $this->event_session_color; + } - if (isset($row['to_group_id']) && !empty($row['to_group_id'])) { - $event['borderColor'] = $event['backgroundColor'] = $this->event_group_color; - } + if (isset($row['to_group_id']) && !empty($row['to_group_id'])) { + $event['borderColor'] = $event['backgroundColor'] = $this->event_group_color; + } - $event['editable'] = false; + $event['editable'] = false; - if (api_is_allowed_to_edit() && $this->type == 'course') { - $event['editable'] = true; - } + if (api_is_allowed_to_edit() && $this->type == 'course') { + $event['editable'] = true; + } - if (!empty($row['start_date']) && $row['start_date'] != '0000-00-00 00:00:00') { - $event['start'] = $this->format_event_date($row['start_date']); - } - if (!empty($row['end_date']) && $row['end_date'] != '0000-00-00 00:00:00') { - $event['end'] = $this->format_event_date($row['end_date']); - } + if (!empty($row['start_date']) && $row['start_date'] != '0000-00-00 00:00:00') { + $event['start'] = $this->format_event_date($row['start_date']); + } + if (!empty($row['end_date']) && $row['end_date'] != '0000-00-00 00:00:00') { + $event['end'] = $this->format_event_date($row['end_date']); + } $event['sent_to'] = ''; //$event['type'] = $this->type; - $event['type'] = 'course'; + $event['type'] = 'course'; if ($row['session_id'] != 0) { - $event['type'] = 'session'; + $event['type'] = 'session'; } //Event Sent to a group? if (isset($row['to_group_id']) && !empty($row['to_group_id'])) { $sent_to = array(); if (!empty($group_to_array)) { - foreach($group_to_array as $group_item) { + foreach ($group_to_array as $group_item) { $sent_to[] = $group_name_list[$group_item]; } } $sent_to = implode('@@', $sent_to); - $sent_to = str_replace('@@', '
', $sent_to); + $sent_to = str_replace('@@', '
', $sent_to); $event['sent_to'] = '
'.$sent_to.'
'; - $event['type'] = 'group'; + $event['type'] = 'group'; } //Event sent to a user? if (isset($row['to_user_id'])) { $sent_to = array(); if (!empty($user_to_array)) { - foreach($user_to_array as $item) { + foreach ($user_to_array as $item) { $user_info = api_get_user_info($item); // add username as tooltip for $event['sent_to'] - ref #4226 $username = api_htmlentities(sprintf(get_lang('LoginX'), $user_info['username']), ENT_QUOTES); @@ -627,7 +634,7 @@ class Agenda { } } $sent_to = implode('@@', $sent_to); - $sent_to = str_replace('@@', '
', $sent_to); + $sent_to = str_replace('@@', '
', $sent_to); $event['sent_to'] = '
'.$sent_to.'
'; } @@ -636,79 +643,82 @@ class Agenda { $event['sent_to'] = '
'.get_lang('Everyone').'
'; } - $event['description'] = $row['content']; - $event['allDay'] = isset($row['all_day']) && $row['all_day'] == 1 ? $row['all_day'] : 0; + $event['description'] = $row['content']; + $event['allDay'] = isset($row['all_day']) && $row['all_day'] == 1 ? $row['all_day'] : 0; - $this->events[] = $event; - } - } - //return $events; - } + $this->events[] = $event; + } + } + //return $events; + } - function get_platform_events($start, $end) { - $start = intval($start); - $end = intval($end); + function get_platform_events($start, $end) + { + $start = intval($start); + $end = intval($end); - $start = api_get_utc_datetime($start); - $end = api_get_utc_datetime($end); + $start = api_get_utc_datetime($start); + $end = api_get_utc_datetime($end); - $access_url_id = api_get_current_access_url_id(); + $access_url_id = api_get_current_access_url_id(); - $sql = "SELECT * FROM ".$this->tbl_global_agenda." + $sql = "SELECT * FROM ".$this->tbl_global_agenda." WHERE start_date >= '".$start."' AND end_date <= '".$end."' AND access_url_id = $access_url_id "; - $result = Database::query($sql); - $my_events = array(); - if (Database::num_rows($result)) { - while ($row = Database::fetch_array($result, 'ASSOC')) { - $event = array(); - $event['id'] = 'platform_'.$row['id']; - $event['title'] = $row['title']; - $event['className'] = 'platform'; - $event['allDay'] = 'false'; - $event['borderColor'] = $event['backgroundColor'] = $this->event_platform_color; - $event['editable'] = false; - - $event['type'] = 'admin'; - - if (api_is_platform_admin() && $this->type == 'admin') { - $event['editable'] = true; - } - - if (!empty($row['start_date']) && $row['start_date'] != '0000-00-00 00:00:00') { - $event['start'] = $this->format_event_date($row['start_date']); - } - if (!empty($row['end_date']) && $row['end_date'] != '0000-00-00 00:00:00') { - $event['end'] = $this->format_event_date($row['end_date']); - } - - $event['description'] = $row['content']; - $event['allDay'] = isset($row['all_day']) && $row['all_day'] == 1 ? $row['all_day'] : 0; - - $my_events[] = $event; - $this->events[]= $event; - } - } - return $my_events; - } + $result = Database::query($sql); + $my_events = array(); + if (Database::num_rows($result)) { + while ($row = Database::fetch_array($result, 'ASSOC')) { + $event = array(); + $event['id'] = 'platform_'.$row['id']; + $event['title'] = $row['title']; + $event['className'] = 'platform'; + $event['allDay'] = 'false'; + $event['borderColor'] = $event['backgroundColor'] = $this->event_platform_color; + $event['editable'] = false; + + $event['type'] = 'admin'; + + if (api_is_platform_admin() && $this->type == 'admin') { + $event['editable'] = true; + } + + if (!empty($row['start_date']) && $row['start_date'] != '0000-00-00 00:00:00') { + $event['start'] = $this->format_event_date($row['start_date']); + } + if (!empty($row['end_date']) && $row['end_date'] != '0000-00-00 00:00:00') { + $event['end'] = $this->format_event_date($row['end_date']); + } + + $event['description'] = $row['content']; + $event['allDay'] = isset($row['all_day']) && $row['all_day'] == 1 ? $row['all_day'] : 0; + + $my_events[] = $event; + $this->events[] = $event; + } + } + return $my_events; + } /** * Format needed for the Fullcalendar js lib * @param string UTC time */ - function format_event_date($utc_time) { + function format_event_date($utc_time) + { return date('c', api_strtotime(api_get_local_time($utc_time))); - } + } /** - * this function shows the form with the user that were not selected - * @author: Patrick Cool , Ghent University - * @return html code - */ - static function construct_not_selected_select_form($group_list = null, $user_list = null, $to_already_selected = array()) { + * this function shows the form with the user that were not selected + * @author: Patrick Cool , Ghent University + * @return html code + */ + static function construct_not_selected_select_form($group_list = null, $user_list = null, $to_already_selected = array()) + { $html = '"; + $html .= ""; } return $html; } - static function construct_not_selected_select_form_validator($form, $group_list = null, $user_list = null, $to_already_selected = array()) { + static function construct_not_selected_select_form_validator($form, $group_list = null, $user_list = null, $to_already_selected = array()) + { $params = array( 'id' => 'users_to_send_id', - 'data-placeholder'=> get_lang('Select'), + 'data-placeholder' => get_lang('Select'), 'multiple' => 'multiple', 'style' => 'width:250px', 'class' => 'chzn-select' @@ -778,13 +789,13 @@ class Agenda { $options = array(); foreach ($user_list as $this_user) { // $to_already_selected is the array containing the users (and groups) that are already selected - if (!is_array($to_already_selected) || !in_array("USER:".$this_user['user_id'],$to_already_selected)) { + if (!is_array($to_already_selected) || !in_array("USER:".$this_user['user_id'], $to_already_selected)) { //$username = api_htmlentities(sprintf(get_lang('LoginX'), $this_user['username']), ENT_QUOTES); // @todo : add title attribute $username in the jqdialog window. wait for a chosen version to inherit title attribute // from
'); - if(!api_is_allowed_to_edit(null,true)) { + if (!api_is_allowed_to_edit(null, true)) { $toolbar = 'AgendaStudent'; } else { $toolbar = 'Agenda'; @@ -892,17 +904,15 @@ class Agenda { $form->display(); } - - static function show_to_form($form, $to_already_selected) { + static function show_to_form($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); + $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()); self::construct_not_selected_select_form_validator($form, $group_list, $user_list, $to_already_selected); } - - } \ No newline at end of file diff --git a/main/calendar/agenda_js.php b/main/calendar/agenda_js.php index e13443b63c..27a6ba17f3 100644 --- a/main/calendar/agenda_js.php +++ b/main/calendar/agenda_js.php @@ -6,7 +6,6 @@ /** * INIT SECTION */ - // name of the language file that needs to be included $language_file = array('agenda', 'group', 'announcements'); @@ -14,7 +13,7 @@ $language_file = array('agenda', 'group', 'announcements'); $use_anonymous = true; //Calendar type -$type = isset($_REQUEST['type']) && in_array($_REQUEST['type'], array('personal', 'course', 'admin')) ? $_REQUEST['type'] : 'personal'; +$type = isset($_REQUEST['type']) && in_array($_REQUEST['type'], array('personal', 'course', 'admin')) ? $_REQUEST['type'] : 'personal'; if ($type == 'personal') { $cidReset = true; // fixes #5162 @@ -24,11 +23,11 @@ require_once '../inc/global.inc.php'; require_once 'agenda.lib.php'; require_once 'agenda.inc.php'; -$current_course_tool = TOOL_CALENDAR_EVENT; +$current_course_tool = TOOL_CALENDAR_EVENT; $this_section = SECTION_MYAGENDA; -$htmlHeadXtra[] = api_get_jquery_libraries_js(array('jquery-ui','jquery-ui-i18n')); +$htmlHeadXtra[] = api_get_jquery_libraries_js(array('jquery-ui', 'jquery-ui-i18n')); $htmlHeadXtra[] = api_get_js('qtip2/jquery.qtip.min.js'); $htmlHeadXtra[] = api_get_js('fullcalendar/fullcalendar.min.js'); $htmlHeadXtra[] = api_get_js('fullcalendar/gcal.js'); @@ -36,12 +35,12 @@ $htmlHeadXtra[] = api_get_css(api_get_path(WEB_LIBRARY_PATH).'javascript/fullcal $htmlHeadXtra[] = api_get_css(api_get_path(WEB_LIBRARY_PATH).'javascript/qtip2/jquery.qtip.min.css'); if (api_is_platform_admin() && $type == 'admin') { - $type = 'admin'; + $type = 'admin'; } //if (api_get_course_id() != -1 && $type == 'course') { if (isset($_REQUEST['cidReq']) && !empty($_REQUEST['cidReq'])) { - $type = 'course'; + $type = 'course'; } @@ -52,28 +51,28 @@ $group_id = api_get_group_id(); if (!empty($group_id)) { $is_group_tutor = GroupManager::is_tutor_of_group(api_get_user_id(), $group_id); - $group_properties = GroupManager :: get_group_properties($group_id); - $interbreadcrumb[] = array ("url" => "../group/group.php", "name" => get_lang('Groups')); - $interbreadcrumb[] = array ("url"=>"../group/group_space.php?gidReq=".$group_id, "name"=> get_lang('GroupSpace').' '.$group_properties['name']); + $group_properties = GroupManager :: get_group_properties($group_id); + $interbreadcrumb[] = array("url" => "../group/group.php", "name" => get_lang('Groups')); + $interbreadcrumb[] = array("url" => "../group/group_space.php?gidReq=".$group_id, "name" => get_lang('GroupSpace').' '.$group_properties['name']); } -$tpl = new Template(get_lang('Agenda')); +$tpl = new Template(get_lang('Agenda')); $tpl->assign('use_google_calendar', 0); $can_add_events = 0; -switch($type) { - case 'admin': +switch ($type) { + case 'admin': api_protect_admin_script(); - $this_section = SECTION_PLATFORM_ADMIN; + $this_section = SECTION_PLATFORM_ADMIN; if (api_is_platform_admin()) { $can_add_events = 1; } - break; - case 'course': + break; + case 'course': api_protect_course_script(); - $this_section = SECTION_COURSES; + $this_section = SECTION_COURSES; if (api_is_allowed_to_edit()) { $can_add_events = 1; } @@ -82,8 +81,8 @@ switch($type) { $can_add_events = 1; } } - break; - case 'personal': + break; + case 'personal': if (api_is_anonymous()) { api_not_allowed(true); } @@ -92,57 +91,57 @@ switch($type) { $tpl->assign('use_google_calendar', 1); $tpl->assign('google_calendar_url', $extra_field_data['google_calendar_url']); } - $this_section = SECTION_MYAGENDA; + $this_section = SECTION_MYAGENDA; if (!api_is_anonymous()) { $can_add_events = 1; } - break; + break; } //Setting translations -$day_short = api_get_week_days_short(); -$days = api_get_week_days_long(); -$months = api_get_months_long(); -$months_short = api_get_months_short(); +$day_short = api_get_week_days_short(); +$days = api_get_week_days_long(); +$months = api_get_months_long(); +$months_short = api_get_months_short(); //Setting calendar translations -$tpl->assign('month_names', json_encode($months)); -$tpl->assign('month_names_short', json_encode($months_short)); -$tpl->assign('day_names', json_encode($days)); -$tpl->assign('day_names_short', json_encode($day_short)); -$tpl->assign('button_text', json_encode(array( 'today' => get_lang('Today'), - 'month' => get_lang('Month'), - 'week' => get_lang('Week'), - 'day' => get_lang('Day')))); +$tpl->assign('month_names', json_encode($months)); +$tpl->assign('month_names_short', json_encode($months_short)); +$tpl->assign('day_names', json_encode($days)); +$tpl->assign('day_names_short', json_encode($day_short)); +$tpl->assign('button_text', json_encode(array('today' => get_lang('Today'), + 'month' => get_lang('Month'), + 'week' => get_lang('Week'), + 'day' => get_lang('Day')))); //see http://docs.jquery.com/UI/Datepicker/$.datepicker.formatDate -$tpl->assign('js_format_date', 'D d M yy'); +$tpl->assign('js_format_date', 'D d M yy'); $region_value = api_get_language_isocode(); if ($region_value == 'en') { $region_value = 'en-GB'; } -$tpl->assign('region_value', $region_value); +$tpl->assign('region_value', $region_value); $export_icon = '../img/export.png'; $export_icon_low = '../img/export_low_fade.png'; $export_icon_high = '../img/export_high_fade.png'; -$tpl->assign('export_ical_confidential_icon', Display::return_icon($export_icon_high, get_lang('ExportiCalConfidential'))); +$tpl->assign('export_ical_confidential_icon', Display::return_icon($export_icon_high, get_lang('ExportiCalConfidential'))); $actions = null; -if (api_is_allowed_to_edit(false,true) OR (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous()) && api_is_allowed_to_session_edit(false,true) OR $is_group_tutor) { +if (api_is_allowed_to_edit(false, true) OR (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous()) && api_is_allowed_to_session_edit(false, true) OR $is_group_tutor) { if ($type == 'course') { if (isset($_GET['user_id'])) { $filter = $_GET['user_id']; } $actions = display_courseadmin_links($filter); } - $tpl->assign('actions', $actions); + $tpl->assign('actions', $actions); } //Calendar Type : course, admin, personal @@ -174,7 +173,7 @@ if (isset($_GET['user_id'])) { $agenda_ajax_url = api_get_path(WEB_AJAX_PATH).'agenda.ajax.php?type='.$type; } $tpl->assign('web_agenda_ajax_url', $agenda_ajax_url); -$course_code = api_get_course_id(); +$course_code = api_get_course_id(); if ((api_is_allowed_to_edit() || $is_group_tutor) && $course_code != '-1' && $type == 'course') { $order = 'lastname'; @@ -182,10 +181,10 @@ if ((api_is_allowed_to_edit() || $is_group_tutor) && $course_code != '-1' && $ty $order = 'firstname'; } if (!empty($group_id)) { - $group_list = array($group_id => $group_properties); - $user_list = GroupManager::get_subscribed_users($group_id); + $group_list = array($group_id => $group_properties); + $user_list = GroupManager::get_subscribed_users($group_id); } else { - $user_list = CourseManager::get_user_list_from_course_code(api_get_course_id(), api_get_session_id(), null, $order); + $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()); } diff --git a/main/inc/ajax/agenda.ajax.php b/main/inc/ajax/agenda.ajax.php index 37d784688e..bfd3321266 100644 --- a/main/inc/ajax/agenda.ajax.php +++ b/main/inc/ajax/agenda.ajax.php @@ -3,8 +3,7 @@ /** * Responses to AJAX calls */ - -$type = isset($_REQUEST['type']) && in_array($_REQUEST['type'], array('personal', 'course', 'admin')) ? $_REQUEST['type'] : 'personal'; +$type = isset($_REQUEST['type']) && in_array($_REQUEST['type'], array('personal', 'course', 'admin')) ? $_REQUEST['type'] : 'personal'; if ($type == 'personal') { $cidReset = true; // fixes #5162 @@ -20,7 +19,7 @@ $action = isset($_REQUEST['a']) ? $_REQUEST['a'] : null; $group_id = api_get_group_id(); //var_dump($group_id); -if ($type =='course') { +if ($type == 'course') { api_protect_course_script(true); } @@ -32,98 +31,97 @@ $agenda = new Agenda(); $agenda->type = $type; //course,admin or personal switch ($action) { - case 'add_event': + case 'add_event': if ((!api_is_allowed_to_edit(null, true) && !$is_group_tutor) && $type == 'course') { break; } $add_as_announcement = isset($_REQUEST['add_as_annonuncement']) ? $_REQUEST['add_as_annonuncement'] : null; - echo $agenda->add_event($_REQUEST['start'], $_REQUEST['end'], $_REQUEST['all_day'], $_REQUEST['view'], - $_REQUEST['title'], $_REQUEST['content'], $_REQUEST['users_to_send'], $add_as_announcement); - break; - case 'edit_event': + echo $agenda->add_event($_REQUEST['start'], $_REQUEST['end'], $_REQUEST['all_day'], $_REQUEST['view'], $_REQUEST['title'], $_REQUEST['content'], $_REQUEST['users_to_send'], $add_as_announcement); + break; + case 'edit_event': if (!api_is_allowed_to_edit(null, true) && $type == 'course') { break; } - $id_list = explode('_', $_REQUEST['id']); - $id = $id_list[1]; - $agenda->edit_event($id, $_REQUEST['start'], $_REQUEST['end'], $_REQUEST['all_day'], $_REQUEST['view'], $_REQUEST['title'], $_REQUEST['content']); - break; - case 'delete_event': + $id_list = explode('_', $_REQUEST['id']); + $id = $id_list[1]; + $agenda->edit_event($id, $_REQUEST['start'], $_REQUEST['end'], $_REQUEST['all_day'], $_REQUEST['view'], $_REQUEST['title'], $_REQUEST['content']); + break; + case 'delete_event': if (!api_is_allowed_to_edit(null, true) && $type == 'course') { break; } - $id_list = explode('_', $_REQUEST['id']); - $id = $id_list[1]; - $agenda->delete_event($id); - break; + $id_list = explode('_', $_REQUEST['id']); + $id = $id_list[1]; + $agenda->delete_event($id); + break; case 'resize_event': if (!api_is_allowed_to_edit(null, true) && $type == 'course') { break; } - $day_delta = $_REQUEST['day_delta']; - $minute_delta = $_REQUEST['minute_delta']; - $id = explode('_', $_REQUEST['id']); - $id = $id[1]; - $agenda->resize_event($id, $day_delta, $minute_delta); - break; - case 'move_event': + $day_delta = $_REQUEST['day_delta']; + $minute_delta = $_REQUEST['minute_delta']; + $id = explode('_', $_REQUEST['id']); + $id = $id[1]; + $agenda->resize_event($id, $day_delta, $minute_delta); + break; + case 'move_event': if (!api_is_allowed_to_edit(null, true) && $type == 'course') { break; } - $day_delta = $_REQUEST['day_delta']; - $minute_delta = $_REQUEST['minute_delta']; - $id = explode('_', $_REQUEST['id']); - $id = $id[1]; - $agenda->move_event($id, $day_delta, $minute_delta); - break; - case 'get_events': - $start = $_REQUEST['start']; - $end = $_REQUEST['end']; + $day_delta = $_REQUEST['day_delta']; + $minute_delta = $_REQUEST['minute_delta']; + $id = explode('_', $_REQUEST['id']); + $id = $id[1]; + $agenda->move_event($id, $day_delta, $minute_delta); + break; + case 'get_events': + $start = $_REQUEST['start']; + $end = $_REQUEST['end']; if (isset($_REQUEST['user_id'])) { $sel_user = $_REQUEST['user_id']; } else { $sel_user = 0; } - $events = $agenda->get_events($start, $end, api_get_course_int_id(), $group_id,$_REQUEST['user_id']); - echo $events; - break; + $events = $agenda->get_events($start, $end, api_get_course_int_id(), $group_id, $_REQUEST['user_id']); + echo $events; + break; case 'get_user_agenda': - //Used in the admin user list - api_protect_admin_script(); + //Used in the admin user list + api_protect_admin_script(); if (api_is_allowed_to_edit(null, true)) { //@todo move this in the agenda class - $DaysShort = api_get_week_days_short(); + $DaysShort = api_get_week_days_short(); $MonthsLong = api_get_months_long(); $user_id = intval($_REQUEST['user_id']); - $my_course_list = CourseManager::get_courses_list_by_user_id($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(); - } - $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']; - } - $monthName = $MonthsLong[$month -1]; + $my_course_list = CourseManager::get_courses_list_by_user_id($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(); + } + $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']; + } + $monthName = $MonthsLong[$month - 1]; - $agendaitems = get_myagendaitems($user_id, $my_course_list, $month, $year); - $agendaitems = get_global_agenda_items($agendaitems, $day, $month, $year, $week, "month_view"); + $agendaitems = get_myagendaitems($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($user_id, $agendaitems, $day, $month, $year, $week, "month_view"); - } - display_mymonthcalendar($user_id, $agendaitems, $month, $year, array(), $monthName, false); + if (api_get_setting('allow_personal_agenda') == 'true') { + $agendaitems = get_personal_agenda_items($user_id, $agendaitems, $day, $month, $year, $week, "month_view"); + } + display_mymonthcalendar($user_id, $agendaitems, $month, $year, array(), $monthName, false); } break; default: