diff --git a/main/calendar/agenda.inc.php b/main/calendar/agenda.inc.php index 6a998dc3b7..e1d6ebb8fc 100644 --- a/main/calendar/agenda.inc.php +++ b/main/calendar/agenda.inc.php @@ -1,4 +1,4 @@ -\n"; + // the forward and backwards url + $backwardsURL = api_get_self()."?coursePath=".urlencode($course_path)."&courseCode=".Security::remove_XSS($_GET['courseCode'])."&action=view&view=day&day=".date("j", $previousday)."&month=".date("n", $previousday)."&year=".date("Y", $previousday); + $forewardsURL = api_get_self()."?coursePath=".urlencode($course_path)."&courseCode=".Security::remove_XSS($_GET['courseCode'])."&action=view&view=day&day=".date("j", $nextday)."&month=".date("n", $nextday)."&year=".date("Y", $nextday); + // The title row containing the day + echo "\n", "«\n", ""; + echo $DaysLong[$day_of_the_week]." ".date("j", $today)." ".$MonthsLong[date("n", $today) - 1]." ".date("Y", $today); + echo ""; + echo "»\n"; + echo "\n"; + // the rows for each half an hour + for ($i = 10; $i < 48; $i ++) + { + echo "\n"; + echo "\t"; + if ($i % 2 == 0) + { + $class = "class=\"alternativeBgLight\""; + echo ("". (($i) / 2)." ".get_lang("HourShort")." 00\n"); + } + else + { + $class = ""; + echo ("". ((($i) / 2) - (1 / 2))." ".get_lang("HourShort")." 30\n"); + } + echo "\t\n"; + if (is_array($agendaitems[$i])) + { + foreach ($agendaitems[$i] as $key => $value) + { + echo $value; + } + } + else + { + echo $agendaitems[$i]; + } + echo "\t\n"; + echo "\n"; + } + echo "\n"; +} +/** + * Display the weekly view of the calendar + */ +function display_weekcalendar($agendaitems, $month, $year, $weekdaynames, $monthName) +{ + global $DaysShort,$course_path; + global $MonthsLong; + // timestamp of today + $today = time(); + $day_of_the_week = date("w", $today); + $thisday_of_the_week = date("w", $today); + // the week number of the year + $week_number = date("W", $today); + $thisweek_number = $week_number; + // if we moved to the next / previous week we have to recalculate the $today variable + if ($_GET['week']) + { + $today = mktime(0, 0, 0, 1, 1, $year); + $today = $today + (((int)$_GET['week']-1) * (7 * 24 * 60 * 60)); + $week_number = date("W", $today); + } + // calculating the start date of the week + // the date of the monday of this week is the timestamp of today minus + // number of days that have already passed this week * 24 hours * 60 minutes * 60 seconds + $current_day = date("j", $today); // Day of the month without leading zeros (1 to 31) of today + $day_of_the_week = date("w", $today); // Numeric representation of the day of the week 0 (for Sunday) through 6 (for Saturday) of today + $timestamp_first_date_of_week = $today - (($day_of_the_week -1) * 24 * 60 * 60); // timestamp of the monday of this week + $timestamp_last_date_of_week = $today + ((7 - $day_of_the_week) * 24 * 60 * 60); // timestamp of the sunday of this week + $backwardsURL = api_get_self()."?coursePath=".urlencode($course_path)."&courseCode=".Security::remove_XSS($_GET['courseCode'])."&action=view&view=week&week=". ($week_number -1); + $forewardsURL = api_get_self()."?coursePath=".urlencode($course_path)."&courseCode=".Security::remove_XSS($_GET['courseCode'])."&action=view&view=week&week=". ($week_number +1); + echo "\n"; + // The title row containing the the week information (week of the year (startdate of week - enddate of week) + echo "\n"; + echo "\n"; + echo ""; + echo "\n", "\n"; + // The second row containing the short names of the days of the week + echo "\n"; + // this is the Day of the month without leading zeros (1 to 31) of the monday of this week + $tmp_timestamp = $timestamp_first_date_of_week; + for ($ii = 1; $ii < 8; $ii ++) + { + $is_today = ($ii == $thisday_of_the_week AND (!isset($_GET['week']) OR $_GET['week']==$thisweek_number)); + echo "\t\n"; + // we 24 hours * 60 minutes * 60 seconds to the $tmp_timestamp + $array_tmp_timestamp[] = $tmp_timestamp; + $tmp_timestamp = $tmp_timestamp + (24 * 60 * 60); + } + echo "\n"; + // the table cells containing all the entries for that day + echo "\n"; + $counter = 0; + foreach ($array_tmp_timestamp as $key => $value) + { + if ($counter < 5) + { + $class = "class=\"days_week\""; + } + else + { + $class = "class=\"days_weekend\""; + } + if ($counter == $thisday_of_the_week -1 AND (!isset($_GET['week']) OR $_GET['week']==$thisweek_number)) + { + $class = "class=\"days_today\""; + } + + echo "\t\n"; + $counter ++; + } + echo "\n"; + echo "
«".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 "»
"; + if ($is_today) + { + echo ""; + } + echo $DaysShort[$ii % 7]." ".date("j", $tmp_timestamp)." ".$MonthsLong[date("n", $tmp_timestamp) - 1]; + if ($is_today) + { + echo ""; + } + echo "
"; + echo "".$agendaitems[date("j", $value)]."  "; + echo "
\n"; +} +/** + * Show the monthcalender of the given month + */ +function get_day_agendaitems($courses_dbs, $month, $year, $day) +{ + global $_user; + global $_configuration; + global $setting_agenda_link; + + $items = array (); + + // get agenda-items for every course + //$query=api_sql_query($sql_select_courses); + foreach ($courses_dbs as $key => $array_course_info) + { + //databases of the courses + $TABLEAGENDA = Database :: get_course_table(TABLE_AGENDA, $array_course_info["db"]); + $TABLE_ITEMPROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY, $array_course_info["db"]); + + // getting all the groups of the user for the current course + $group_memberships = GroupManager :: get_group_ids($array_course_info["db"], $_user['user_id']); + // if the user is administrator of that course we show all the agenda items + if ($array_course_info['status'] == '1') + { + //echo "course admin"; + $sqlquery = "SELECT + DISTINCT agenda.*, item_property.* + FROM ".$TABLEAGENDA." agenda, + ".$TABLE_ITEMPROPERTY." item_property + WHERE `agenda`.`id` = `item_property`.`ref` ".$show_all_current." + AND DAYOFMONTH(start_date)='".$day."' AND MONTH(start_date)='".$month."' AND YEAR(start_date)='".$year."' + AND `item_property`.`tool`='".TOOL_CALENDAR_EVENT."' + AND `item_property`.`visibility`='1' + GROUP BY agenda.id + ORDER BY start_date ".$sort; + } + // if the user is not an administrator of that course + else + { + //echo "GEEN course admin"; + if (is_array($group_memberships)) + { + $sqlquery = "SELECT + agenda.*, item_property.* + FROM ".$TABLEAGENDA." agenda, + ".$TABLE_ITEMPROPERTY." item_property + WHERE `agenda`.`id` = `item_property`.`ref` ".$show_all_current." + AND DAYOFMONTH(start_date)='".$day."' AND MONTH(start_date)='".$month."' AND YEAR(start_date)='".$year."' + AND `item_property`.`tool`='".TOOL_CALENDAR_EVENT."' + AND ( `item_property`.`to_user_id`='".$_user['user_id']."' OR `item_property`.`to_group_id` IN (0, ".implode(", ", $group_memberships).") ) + AND `item_property`.`visibility`='1' + ORDER BY start_date ".$sort; + } + else + { + $sqlquery = "SELECT + agenda.*, item_property.* + FROM ".$TABLEAGENDA." agenda, + ".$TABLE_ITEMPROPERTY." item_property + WHERE `agenda`.`id` = `item_property`.`ref` ".$show_all_current." + AND DAYOFMONTH(start_date)='".$day."' AND MONTH(start_date)='".$month."' AND YEAR(start_date)='".$year."' + AND `item_property`.`tool`='".TOOL_CALENDAR_EVENT."' + AND ( `item_property`.`to_user_id`='".$_user['user_id']."' OR `item_property`.`to_group_id`='0') + AND `item_property`.`visibility`='1' + ORDER BY start_date ".$sort; + } + } + //$sqlquery = "SELECT * FROM $agendadb WHERE DAYOFMONTH(day)='$day' AND month(day)='$month' AND year(day)='$year'"; + //echo "abc"; + //echo $sqlquery; + $result = api_sql_query($sqlquery, __FILE__, __LINE__); + //echo mysql_num_rows($result); + while ($item = mysql_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 + list ($datepart, $timepart) = split(" ", $item['start_date']); + list ($year, $month, $day) = explode("-", $datepart); + list ($hours, $minutes, $seconds) = explode(":", $timepart); + + $halfhour = 2 * $hours; + if ($minutes >= '30') + { + $halfhour = $halfhour +1; + } + + if ($setting_agenda_link == 'coursecode') + { + $title=$array_course_info['title']; + $agenda_link = substr($title, 0, 14); + } + else + { + $agenda_link = Display::return_icon('course_home.gif'); + } + + //$URL = $_configuration['root_web'].$mycours["dir"]."/"; + $URL = $_configuration['root_web']."main/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][] .= "".$hours.":".$minutes." ".$agenda_link." ".$item['title']."
"; + } + } + // sorting by hour for every day + /*$agendaitems = array(); + while (list($agendaday, $tmpitems) = each($items)) + { + sort($tmpitems); + while (list($key,$val) = each($tmpitems)) + { + $agendaitems[$agendaday].=$val; + } + }*/ + $agendaitems = $items; + //print_r($agendaitems); + return $agendaitems; +} +/** + * Return agenda items of the week + */ +function get_week_agendaitems($courses_dbs, $month, $year, $week = '') +{ + global $TABLEAGENDA, $TABLE_ITEMPROPERTY; + global $_user; + global $_configuration; + global $setting_agenda_link; + + $items = array (); + // The default value of the week + if ($week == '') + { + $week_number = date("W", time()); + } + else + { + $week_number = $week; + } + $start_end = calculate_start_end_of_week($week_number, $year); + $start_filter = $start_end['start']['year']."-".$start_end['start']['month']."-".$start_end['start']['day']; + $end_filter = $start_end['end']['year']."-".$start_end['end']['month']."-".$start_end['end']['day']; + // get agenda-items for every course + foreach ($courses_dbs as $key => $array_course_info) + { + //databases of the courses + $TABLEAGENDA = Database :: get_course_table(TABLE_AGENDA, $array_course_info["db"]); + $TABLE_ITEMPROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY, $array_course_info["db"]); + + // getting all the groups of the user for the current course + $group_memberships = GroupManager :: get_group_ids($array_course_info["db"], $_user['user_id']); + + // if the user is administrator of that course we show all the agenda items + if ($array_course_info['status'] == '1') + { + //echo "course admin"; + $sqlquery = "SELECT + DISTINCT a.*, i.* + FROM ".$TABLEAGENDA." a, + ".$TABLE_ITEMPROPERTY." i + WHERE a.id = i.ref + AND a.start_date>='".$start_filter."' AND a.start_date<='".$end_filter."' + AND i.tool='".TOOL_CALENDAR_EVENT."' + AND i.visibility='1' + GROUP BY a.id + ORDER BY a.start_date"; + } + // if the user is not an administrator of that course + else + { + //echo "GEEN course admin"; + if (is_array($group_memberships)) + { + $sqlquery = "SELECT + a.*, i.* + FROM ".$TABLEAGENDA." a, + ".$TABLE_ITEMPROPERTY." i + WHERE a.id = i.`ref` + AND a.start_date>='".$start_filter."' AND a.start_date<='".$end_filter."' + AND i.tool='".TOOL_CALENDAR_EVENT."' + AND ( i.to_user_id='".$_user['user_id']."' OR i.to_group_id IN (0, ".implode(", ", $group_memberships).") ) + AND i.visibility='1' + ORDER BY a.start_date"; + } + else + { + $sqlquery = "SELECT + a.*, i.* + FROM ".$TABLEAGENDA." a, + ".$TABLE_ITEMPROPERTY." i + WHERE a.id = i.ref + AND a.start_date>='".$start_filter."' AND a.start_date<='".$end_filter."' + AND i.tool='".TOOL_CALENDAR_EVENT."' + AND ( i.to_user_id='".$_user['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')"; + $result = api_sql_query($sqlquery, __FILE__, __LINE__); + while ($item = mysql_fetch_array($result)) + { + $agendaday = date("j",strtotime($item['start_date'])); + $time= date("H:i",strtotime($item['start_date'])); + + if ($setting_agenda_link == 'coursecode') + { + $title=$array_course_info['title']; + $agenda_link = substr($title, 0, 14); + } + else + { + $agenda_link = Display::return_icon('course_home.gif'); + } + + $URL = $_configuration['root_web']."main/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 + $items[$agendaday][$item['start_time']] .= "$time ".$agenda_link." ".$item['title']."
"; + } + } + // sorting by hour for every day + $agendaitems = array (); + while (list ($agendaday, $tmpitems) = each($items)) + { + sort($tmpitems); + while (list ($key, $val) = each($tmpitems)) + { + $agendaitems[$agendaday] .= $val; + } + } + //print_r($agendaitems); + return $agendaitems; +} +/** + * Get repeated events of a course between two dates (timespan of a month, a week, a day). + * Returns an array containing the events + * @param string Course database name + * @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 + * @return array [int] => [parent_event_id,start_date,end_date,title,description] + */ +function get_repeated_events_day_view($course_db,$course_db,$start=0,$end=0) +{ + $events = array(); + //initialise all values + $y=0; + $m=0; + $d=0; + 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_db); + $t_cal_repeat = Database::get_course_table(TABLE_AGENDA_REPEAT,$course_db); + $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 " . + " WHERE cr.cal_end >= $end " . + " AND cr.cal_id = c.id" . + " AND c.start_date <= $db_start"; + $res = api_sql_query($sql,__FILE__,__LINE__); + 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($row['id'],$current_start,$current_stop,$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($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': + break; + case 'monthlyByDay': + 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($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 '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) OR (($y_now == $y_orig) && ($m_now>$m_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($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; +} ?> \ No newline at end of file diff --git a/main/calendar/calendar.php b/main/calendar/calendar.php index 5aa23d306f..f2b7195e0b 100644 --- a/main/calendar/calendar.php +++ b/main/calendar/calendar.php @@ -7,7 +7,7 @@ include('../inc/global.inc.php'); //session if(isset($_GET['id_session'])) $_SESSION['id_session'] = $_GET['id_session']; - + // the variables for the days and the months // Defining the shorts for the days $DaysShort = array(get_lang("SundayShort"), get_lang("MondayShort"), get_lang("TuesdayShort"), get_lang("WednesdayShort"), get_lang("ThursdayShort"), get_lang("FridayShort"), get_lang("SaturdayShort")); diff --git a/main/calendar/ical_export.php b/main/calendar/ical_export.php index 28e182c8b8..8f475efb89 100644 --- a/main/calendar/ical_export.php +++ b/main/calendar/ical_export.php @@ -2,6 +2,7 @@ /** * This file exclusively export calendar items to iCal or similar formats * @author Yannick Warnier + * See copyright information in the Dokeos root directory, dokeos_license.txt */ /** * Initialisation diff --git a/main/calendar/myagenda.inc.php b/main/calendar/myagenda.inc.php index 9669b76a74..6fe752ebee 100644 --- a/main/calendar/myagenda.inc.php +++ b/main/calendar/myagenda.inc.php @@ -3,7 +3,7 @@ ============================================================================== Dokeos - elearning and course management software - Copyright (c) 2004 Dokeos S.A. + Copyright (c) 2004-2008 Dokeos SPRL Copyright (c) 2003 Ghent University (UGent) For a full list of contributors, see "credits.txt". @@ -16,7 +16,7 @@ See the GNU General Public License for more details. - Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com + Contact: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium, info@dokeos.com ============================================================================== @author: Patrick Cool , Ghent University @author: Toon Van Hoecke , Ghent University @@ -61,9 +61,9 @@ $setting_agenda_link = 'coursecode'; // valid values are coursecode and icon /** - * This function retrieves all the agenda items of all the course of the user + * This function retrieves all the agenda items of all the courses the user is subscribed to */ -function get_agendaitems($courses_dbs, $month, $year) +function get_myagendaitems($courses_dbs, $month, $year) { global $_user; global $_configuration; @@ -178,7 +178,7 @@ function get_agendaitems($courses_dbs, $month, $year) * @param string The month name * @return void Direct output */ -function display_monthcalendar($agendaitems, $month, $year, $weekdaynames=array(), $monthName) +function display_mymonthcalendar($agendaitems, $month, $year, $weekdaynames=array(), $monthName) { global $DaysShort,$course_path; //Handle leap year @@ -241,7 +241,7 @@ function display_monthcalendar($agendaitems, $month, $year, $weekdaynames=array( /** * Show the mini calender of the given month */ -function display_minimonthcalendar($agendaitems, $month, $year, $monthName) +function display_myminimonthcalendar($agendaitems, $month, $year, $monthName) { global $DaysShort,$course_path; //Handle leap year @@ -306,404 +306,14 @@ function display_minimonthcalendar($agendaitems, $month, $year, $monthName) } echo "\n"; } -/** - * Display the weekly view of the calendar - */ -function display_weekcalendar($agendaitems, $month, $year, $weekdaynames, $monthName) -{ - global $DaysShort,$course_path; - global $MonthsLong; - // timestamp of today - $today = time(); - $day_of_the_week = date("w", $today); - $thisday_of_the_week = date("w", $today); - // the week number of the year - $week_number = date("W", $today); - $thisweek_number = $week_number; - // if we moved to the next / previous week we have to recalculate the $today variable - if ($_GET['week']) - { - $today = mktime(0, 0, 0, 1, 1, $year); - $today = $today + (((int)$_GET['week']-1) * (7 * 24 * 60 * 60)); - $week_number = date("W", $today); - } - // calculating the start date of the week - // the date of the monday of this week is the timestamp of today minus - // number of days that have already passed this week * 24 hours * 60 minutes * 60 seconds - $current_day = date("j", $today); // Day of the month without leading zeros (1 to 31) of today - $day_of_the_week = date("w", $today); // Numeric representation of the day of the week 0 (for Sunday) through 6 (for Saturday) of today - $timestamp_first_date_of_week = $today - (($day_of_the_week -1) * 24 * 60 * 60); // timestamp of the monday of this week - $timestamp_last_date_of_week = $today + ((7 - $day_of_the_week) * 24 * 60 * 60); // timestamp of the sunday of this week - $backwardsURL = api_get_self()."?coursePath=".urlencode($course_path)."&courseCode=".Security::remove_XSS($_GET['courseCode'])."&action=view&view=week&week=". ($week_number -1); - $forewardsURL = api_get_self()."?coursePath=".urlencode($course_path)."&courseCode=".Security::remove_XSS($_GET['courseCode'])."&action=view&view=week&week=". ($week_number +1); - echo "\n"; - // The title row containing the the week information (week of the year (startdate of week - enddate of week) - echo "\n"; - echo "\n"; - echo ""; - echo "\n", "\n"; - // The second row containing the short names of the days of the week - echo "\n"; - // this is the Day of the month without leading zeros (1 to 31) of the monday of this week - $tmp_timestamp = $timestamp_first_date_of_week; - for ($ii = 1; $ii < 8; $ii ++) - { - $is_today = ($ii == $thisday_of_the_week AND (!isset($_GET['week']) OR $_GET['week']==$thisweek_number)); - echo "\t\n"; - // we 24 hours * 60 minutes * 60 seconds to the $tmp_timestamp - $array_tmp_timestamp[] = $tmp_timestamp; - $tmp_timestamp = $tmp_timestamp + (24 * 60 * 60); - } - echo "\n"; - // the table cells containing all the entries for that day - echo "\n"; - $counter = 0; - foreach ($array_tmp_timestamp as $key => $value) - { - if ($counter < 5) - { - $class = "class=\"days_week\""; - } - else - { - $class = "class=\"days_weekend\""; - } - if ($counter == $thisday_of_the_week -1 AND (!isset($_GET['week']) OR $_GET['week']==$thisweek_number)) - { - $class = "class=\"days_today\""; - } - - echo "\t\n"; - $counter ++; - } - echo "\n"; - echo "
«".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 "»
"; - if ($is_today) - { - echo ""; - } - echo $DaysShort[$ii % 7]." ".date("j", $tmp_timestamp)." ".$MonthsLong[date("n", $tmp_timestamp) - 1]; - if ($is_today) - { - echo ""; - } - echo "
"; - echo "".$agendaitems[date("j", $value)]."  "; - echo "
\n"; -} -/** - * Show the mini calender of the given month - */ -function display_daycalendar($agendaitems, $day, $month, $year, $weekdaynames, $monthName) -{ - global $DaysShort, $DaysLong, $course_path; - global $MonthsLong; - global $query; - - // timestamp of today - $today = mktime(); - $nextday = $today + (24 * 60 * 60); - $previousday = $today - (24 * 60 * 60); - // the week number of the year - $week_number = date("W", $today); - // if we moved to the next / previous day we have to recalculate the $today variable - if ($_GET['day']) - { - $today = mktime(0, 0, 0, $month, $day, $year); - $nextday = $today + (24 * 60 * 60); - $previousday = $today - (24 * 60 * 60); - $week_number = date("W", $today); - } - // calculating the start date of the week - // the date of the monday of this week is the timestamp of today minus - // number of days that have already passed this week * 24 hours * 60 minutes * 60 seconds - $current_day = date("j", $today); // Day of the month without leading zeros (1 to 31) of today - $day_of_the_week = date("w", $today); // Numeric representation of the day of the week 0 (for Sunday) through 6 (for Saturday) of today - //$timestamp_first_date_of_week=$today-(($day_of_the_week-1)*24*60*60); // timestamp of the monday of this week - //$timestamp_last_date_of_week=$today+((7-$day_of_the_week)*24*60*60); // timestamp of the sunday of this week - // we are loading all the calendar items of all the courses for today - echo "\n"; - // the forward and backwards url - $backwardsURL = api_get_self()."?coursePath=".urlencode($course_path)."&courseCode=".Security::remove_XSS($_GET['courseCode'])."&action=view&view=day&day=".date("j", $previousday)."&month=".date("n", $previousday)."&year=".date("Y", $previousday); - $forewardsURL = api_get_self()."?coursePath=".urlencode($course_path)."&courseCode=".Security::remove_XSS($_GET['courseCode'])."&action=view&view=day&day=".date("j", $nextday)."&month=".date("n", $nextday)."&year=".date("Y", $nextday); - // The title row containing the day - echo "\n", "\n", ""; - echo "\n"; - echo "\n"; - // the rows for each half an hour - for ($i = 10; $i < 48; $i ++) - { - echo "\n"; - echo "\t"; - if ($i % 2 == 0) - { - $class = "class=\"alternativeBgLight\""; - echo ("\n"); - } - else - { - $class = ""; - echo ("\n"); - } - echo "\t\n"; - echo "\n"; - } - echo "
«"; - echo $DaysLong[$day_of_the_week]." ".date("j", $today)." ".$MonthsLong[date("n", $today) - 1]." ".date("Y", $today); - echo "»
". (($i) / 2)." ".get_lang("HourShort")." 00". ((($i) / 2) - (1 / 2))." ".get_lang("HourShort")." 30\n"; - if (is_array($agendaitems[$i])) - { - foreach ($agendaitems[$i] as $key => $value) - { - echo $value; - } - } - else - { - echo $agendaitems[$i]; - } - echo "\t
\n"; -} -/** - * Show the monthcalender of the given month - */ -function get_day_agendaitems($courses_dbs, $month, $year, $day) -{ - global $_user; - global $_configuration; - global $setting_agenda_link; - - $items = array (); - - // get agenda-items for every course - //$query=api_sql_query($sql_select_courses); - foreach ($courses_dbs as $key => $array_course_info) - { - //databases of the courses - $TABLEAGENDA = Database :: get_course_table(TABLE_AGENDA, $array_course_info["db"]); - $TABLE_ITEMPROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY, $array_course_info["db"]); - - // getting all the groups of the user for the current course - $group_memberships = GroupManager :: get_group_ids($array_course_info["db"], $_user['user_id']); - // if the user is administrator of that course we show all the agenda items - if ($array_course_info['status'] == '1') - { - //echo "course admin"; - $sqlquery = "SELECT - DISTINCT agenda.*, item_property.* - FROM ".$TABLEAGENDA." agenda, - ".$TABLE_ITEMPROPERTY." item_property - WHERE `agenda`.`id` = `item_property`.`ref` ".$show_all_current." - AND DAYOFMONTH(start_date)='".$day."' AND MONTH(start_date)='".$month."' AND YEAR(start_date)='".$year."' - AND `item_property`.`tool`='".TOOL_CALENDAR_EVENT."' - AND `item_property`.`visibility`='1' - GROUP BY agenda.id - ORDER BY start_date ".$sort; - } - // if the user is not an administrator of that course - else - { - //echo "GEEN course admin"; - if (is_array($group_memberships)) - { - $sqlquery = "SELECT - agenda.*, item_property.* - FROM ".$TABLEAGENDA." agenda, - ".$TABLE_ITEMPROPERTY." item_property - WHERE `agenda`.`id` = `item_property`.`ref` ".$show_all_current." - AND DAYOFMONTH(start_date)='".$day."' AND MONTH(start_date)='".$month."' AND YEAR(start_date)='".$year."' - AND `item_property`.`tool`='".TOOL_CALENDAR_EVENT."' - AND ( `item_property`.`to_user_id`='".$_user['user_id']."' OR `item_property`.`to_group_id` IN (0, ".implode(", ", $group_memberships).") ) - AND `item_property`.`visibility`='1' - ORDER BY start_date ".$sort; - } - else - { - $sqlquery = "SELECT - agenda.*, item_property.* - FROM ".$TABLEAGENDA." agenda, - ".$TABLE_ITEMPROPERTY." item_property - WHERE `agenda`.`id` = `item_property`.`ref` ".$show_all_current." - AND DAYOFMONTH(start_date)='".$day."' AND MONTH(start_date)='".$month."' AND YEAR(start_date)='".$year."' - AND `item_property`.`tool`='".TOOL_CALENDAR_EVENT."' - AND ( `item_property`.`to_user_id`='".$_user['user_id']."' OR `item_property`.`to_group_id`='0') - AND `item_property`.`visibility`='1' - ORDER BY start_date ".$sort; - } - } - //$sqlquery = "SELECT * FROM $agendadb WHERE DAYOFMONTH(day)='$day' AND month(day)='$month' AND year(day)='$year'"; - //echo "abc"; - //echo $sqlquery; - $result = api_sql_query($sqlquery, __FILE__, __LINE__); - //echo mysql_num_rows($result); - while ($item = mysql_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 - list ($datepart, $timepart) = split(" ", $item['start_date']); - list ($year, $month, $day) = explode("-", $datepart); - list ($hours, $minutes, $seconds) = explode(":", $timepart); - $halfhour = 2 * $hours; - if ($minutes >= '30') - { - $halfhour = $halfhour +1; - } - - if ($setting_agenda_link == 'coursecode') - { - $title=$array_course_info['title']; - $agenda_link = substr($title, 0, 14); - } - else - { - $agenda_link = Display::return_icon('course_home.gif'); - } - - //$URL = $_configuration['root_web'].$mycours["dir"]."/"; - $URL = $_configuration['root_web']."main/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][] .= "".$hours.":".$minutes." ".$agenda_link." ".$item['title']."
"; - } - } - // sorting by hour for every day - /*$agendaitems = array(); - while (list($agendaday, $tmpitems) = each($items)) - { - sort($tmpitems); - while (list($key,$val) = each($tmpitems)) - { - $agendaitems[$agendaday].=$val; - } - }*/ - $agendaitems = $items; - //print_r($agendaitems); - return $agendaitems; -} -/** - * Return agenda items of the week - */ -function get_week_agendaitems($courses_dbs, $month, $year, $week = '') -{ - global $TABLEAGENDA, $TABLE_ITEMPROPERTY; - global $_user; - global $_configuration; - global $setting_agenda_link; - - $items = array (); - // The default value of the week - if ($week == '') - { - $week_number = date("W", time()); - } - else - { - $week_number = $week; - } - $start_end = calculate_start_end_of_week($week_number, $year); - $start_filter = $start_end['start']['year']."-".$start_end['start']['month']."-".$start_end['start']['day']; - $end_filter = $start_end['end']['year']."-".$start_end['end']['month']."-".$start_end['end']['day']; - // get agenda-items for every course - foreach ($courses_dbs as $key => $array_course_info) - { - //databases of the courses - $TABLEAGENDA = Database :: get_course_table(TABLE_AGENDA, $array_course_info["db"]); - $TABLE_ITEMPROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY, $array_course_info["db"]); - - // getting all the groups of the user for the current course - $group_memberships = GroupManager :: get_group_ids($array_course_info["db"], $_user['user_id']); - - // if the user is administrator of that course we show all the agenda items - if ($array_course_info['status'] == '1') - { - //echo "course admin"; - $sqlquery = "SELECT - DISTINCT a.*, i.* - FROM ".$TABLEAGENDA." a, - ".$TABLE_ITEMPROPERTY." i - WHERE a.id = i.ref - AND a.start_date>='".$start_filter."' AND a.start_date<='".$end_filter."' - AND i.tool='".TOOL_CALENDAR_EVENT."' - AND i.visibility='1' - GROUP BY a.id - ORDER BY a.start_date"; - } - // if the user is not an administrator of that course - else - { - //echo "GEEN course admin"; - if (is_array($group_memberships)) - { - $sqlquery = "SELECT - a.*, i.* - FROM ".$TABLEAGENDA." a, - ".$TABLE_ITEMPROPERTY." i - WHERE a.id = i.`ref` - AND a.start_date>='".$start_filter."' AND a.start_date<='".$end_filter."' - AND i.tool='".TOOL_CALENDAR_EVENT."' - AND ( i.to_user_id='".$_user['user_id']."' OR i.to_group_id IN (0, ".implode(", ", $group_memberships).") ) - AND i.visibility='1' - ORDER BY a.start_date"; - } - else - { - $sqlquery = "SELECT - a.*, i.* - FROM ".$TABLEAGENDA." a, - ".$TABLE_ITEMPROPERTY." i - WHERE a.id = i.ref - AND a.start_date>='".$start_filter."' AND a.start_date<='".$end_filter."' - AND i.tool='".TOOL_CALENDAR_EVENT."' - AND ( i.to_user_id='".$_user['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')"; - $result = api_sql_query($sqlquery, __FILE__, __LINE__); - while ($item = mysql_fetch_array($result)) - { - $agendaday = date("j",strtotime($item['start_date'])); - $time= date("H:i",strtotime($item['start_date'])); - - if ($setting_agenda_link == 'coursecode') - { - $title=$array_course_info['title']; - $agenda_link = substr($title, 0, 14); - } - else - { - $agenda_link = Display::return_icon('course_home.gif'); - } - - $URL = $_configuration['root_web']."main/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 - $items[$agendaday][$item['start_time']] .= "$time ".$agenda_link." ".$item['title']."
"; - } - } - // sorting by hour for every day - $agendaitems = array (); - while (list ($agendaday, $tmpitems) = each($items)) - { - sort($tmpitems); - while (list ($key, $val) = each($tmpitems)) - { - $agendaitems[$agendaday] .= $val; - } - } - //print_r($agendaitems); - return $agendaitems; -} /** * This function shows all the forms that are needed form adding /editing a new personal agenda item * when there is no $id passed in the function we are adding a new agenda item, if there is a $id * we are editing * attention: we have to check that the student is editing an item that belongs to him/her */ -function show_new_item_form($id = "") +function show_new_personal_item_form($id = "") { global $year, $MonthsLong; global $tbl_personal_agenda; @@ -1037,8 +647,6 @@ function show_personal_agenda() $result = api_sql_query($sql, __FILE__, __LINE__); // variable initialisation $month_bar = ""; - // starting the table output - echo "\n"; // setting the default day, month and year if (!$_GET['day'] AND !$_GET['month'] AND !$_GET['year']) { @@ -1050,6 +658,10 @@ function show_personal_agenda() $export_icon = api_get_path('WEB_IMG_PATH').'export.png'; $export_icon_low = api_get_path('WEB_IMG_PATH').'export_low_fade.png'; $export_icon_high = api_get_path('WEB_IMG_PATH').'export_high_fade.png'; + + // starting the table output + echo "
\n"; + if (Database::num_rows($result) > 0) { while ($myrow = Database::fetch_array($result)) @@ -1143,35 +755,4 @@ function delete_personal_agenda($id) } } } -/** - * This function calculates the startdate of the week (monday) - * and the enddate of the week (sunday) - * and returns it as an array - */ -function calculate_start_end_of_week($week_number, $year) -{ - // determine the start and end date - // step 1: we calculate a timestamp for a day in this week - $random_day_in_week = mktime(0, 0, 0, 1, 1, $year) + ($week_number-1) * (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; -} -?> +?> \ No newline at end of file diff --git a/main/calendar/myagenda.php b/main/calendar/myagenda.php index 3a8e9e70d0..6dd0adbdd8 100644 --- a/main/calendar/myagenda.php +++ b/main/calendar/myagenda.php @@ -1,9 +1,9 @@ -, Ghent University @author: Toon Van Hoecke , Ghent University @@ -27,6 +27,8 @@ ============================================================================== version info: ------------- + -> version 2.3 : Yannick Warnier, yannick.warnier@dokeos.com 2008 + Added repeated events -> version 2.2 : Patrick Cool, patrick.cool@ugent.be, november 2004 Personal Agenda added. The user can add personal agenda items. The items are stored in a dokeos_user database because it is not course or platform @@ -64,10 +66,11 @@ $language_file = 'agenda'; // we are not inside a course, so we reset the course id $cidReset = true; // setting the global file that gets the general configuration, the databases, the languages, ... -require ('../inc/global.inc.php'); +require('../inc/global.inc.php'); $this_section = SECTION_MYAGENDA; api_block_anonymous_users(); require_once(api_get_path(LIBRARY_PATH).'groupmanager.lib.php'); +require_once('agenda.inc.php'); require_once('myagenda.inc.php'); // setting the name of the tool $nameTools = get_lang('MyAgenda'); @@ -86,6 +89,7 @@ if (!empty ($course_path)) $htmlHeadXtra[] = ""; // showing the header Display::display_header(get_lang('MyAgenda')); + /* ============================================================================== SETTING SOME VARIABLES ============================================================================== */ @@ -134,44 +138,44 @@ if ($_SESSION['view']) { // 3.a Month view case "month" : - $proces = "month_view"; + $process = "month_view"; break; // 3.a Week view case "week" : - $proces = "week_view"; + $process = "week_view"; break; // 3.a Day view case "day" : - $proces = "day_view"; + $process = "day_view"; break; // 3.a Personal view case "personal" : - $proces = "personal_view"; + $process = "personal_view"; break; } } // 4. add personal agenda if (!empty($_GET['action']) && $_GET['action'] == "add_personal_agenda_item" and !$_POST['Submit']) { - $proces = "add_personal_agenda_item"; + $process = "add_personal_agenda_item"; } if (!empty($_GET['action']) && $_GET['action'] == "add_personal_agenda_item" and $_POST['Submit']) { - $proces = "store_personal_agenda_item"; + $process = "store_personal_agenda_item"; } // 5. edit personal agenda if (!empty($_GET['action']) && $_GET['action'] == "edit_personal_agenda_item" and !$_POST['Submit']) { - $proces = "edit_personal_agenda_item"; + $process = "edit_personal_agenda_item"; } if (!empty($_GET['action']) && $_GET['action'] == "edit_personal_agenda_item" and $_POST['Submit']) { - $proces = "store_personal_agenda_item"; + $process = "store_personal_agenda_item"; } // 6. delete personal agenda if (!empty($_GET['action']) && $_GET['action'] == "delete" AND $_GET['id']) { - $proces = "delete_personal_agenda_item"; + $process = "delete_personal_agenda_item"; } /* ============================================================================== OUTPUT @@ -213,12 +217,12 @@ if (isset ($_user['user_id'])) echo ""; // output: the small calendar item on the left and the view / add links echo ""; // the main area: day, week, month view echo "
"; - $agendaitems = get_agendaitems($courses_dbs, $month, $year); + $agendaitems = get_myagendaitems($courses_dbs, $month, $year); if (get_setting('allow_personal_agenda') == 'true') { $agendaitems = get_personal_agenda_items($agendaitems, $day, $month, $year, $week, "month_view"); } - display_minimonthcalendar($agendaitems, $month, $year, $monthName); + display_myminimonthcalendar($agendaitems, $month, $year, $monthName); echo "\n "; - switch ($proces) + switch ($process) { case "month_view" : - $agendaitems = get_agendaitems($courses_dbs, $month, $year); + $agendaitems = get_myagendaitems($courses_dbs, $month, $year); if (get_setting("allow_personal_agenda") == "true") { $agendaitems = get_personal_agenda_items($agendaitems, $day, $month, $year, $week, "month_view"); } - display_monthcalendar($agendaitems, $month, $year, array(), $monthName); + display_mymonthcalendar($agendaitems, $month, $year, array(), $monthName); break; case "week_view" : $agendaitems = get_week_agendaitems($courses_dbs, $month, $year, $week); @@ -265,7 +269,7 @@ if (isset ($_user['user_id'])) show_personal_agenda(); break; case "add_personal_agenda_item" : - show_new_item_form(); + show_new_personal_item_form(); break; case "store_personal_agenda_item" : store_personal_item($_POST['frm_day'], $_POST['frm_month'], $_POST['frm_year'], $_POST['frm_hour'], $_POST['frm_minute'], $_POST['frm_title'], $_POST['frm_content'], (int)$_GET['id']); @@ -280,7 +284,7 @@ if (isset ($_user['user_id'])) show_personal_agenda(); break; case "edit_personal_agenda_item" : - show_new_item_form((int)$_GET['id']); + show_new_personal_item_form((int)$_GET['id']); break; case "delete_personal_agenda_item" : delete_personal_agenda((int)$_GET['id']); diff --git a/main/calendar/print.php b/main/calendar/print.php index 3c0d68b837..1616d382ea 100644 --- a/main/calendar/print.php +++ b/main/calendar/print.php @@ -1,4 +1,8 @@