myagenda.php 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387
  1. <?php
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004 Dokeos S.A.
  6. Copyright (c) 2003 Ghent University (UGent)
  7. For a full list of contributors, see "credits.txt".
  8. The full license can be read in "license.txt".
  9. This program is free software; you can redistribute it and/or
  10. modify it under the terms of the GNU General Public License
  11. as published by the Free Software Foundation; either version 2
  12. of the License, or (at your option) any later version.
  13. See the GNU General Public License for more details.
  14. Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
  15. ==============================================================================
  16. @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
  17. @author: Toon Van Hoecke <toon.vanhoecke@ugent.be>, Ghent University
  18. @author: Eric Remy (initial version)
  19. @version: 2.2 alpha
  20. @description: this file generates a general agenda of all items of the
  21. courses the user is registered for
  22. ==============================================================================
  23. version info:
  24. -------------
  25. -> version 2.2 : Patrick Cool, patrick.cool@ugent.be, november 2004
  26. Personal Agenda added. The user can add personal agenda items. The items
  27. are stored in a dokeos_user database because it is not course or platform
  28. based. A personal agenda view was also added. This lists all the personal
  29. agenda items of that user.
  30. -> version 2.1 : Patrick Cool, patrick.cool@ugent.be, , oktober 2004
  31. This is the version that works with the Group based Agenda tool.
  32. -> version 2.0 (alpha): Patrick Cool, patrick.cool@ugent.be, , oktober 2004
  33. The 2.0 version introduces besides the month view also a week- and day view.
  34. In the 2.5 (final) version it will be possible for the student to add his/her
  35. own agenda items. The platform administrator can however decide if the students
  36. are allowed to do this or not.
  37. The alpha version only contains the three views. The personal agenda feature is
  38. not yet completely finished. There are however already some parts of the code
  39. for adding a personal agenda item present.
  40. this code was not released in an official dokeos but was only used in the offical
  41. server of the Ghent University where it underwent serious testing
  42. -> version 1.5: Toon Van Hoecke, toon.vanhoecke@ugent.be, december 2003
  43. -> version 1.0: Eric Remy, eremy@rmwc.edu, 6 Oct 2003
  44. The tool was initially called master-calendar as it collects all the calendar
  45. items of all the courses one is subscribed to. It was very soon integrated in
  46. Dokeos as this was a really basic and very usefull tool.
  47. /* ==============================================================================
  48. HEADER
  49. ============================================================================== */
  50. // loading the language file
  51. $langFile = 'agenda';
  52. // we are not inside a course, so we reset the course id
  53. $cidReset = true;
  54. // setting the global file that gets the general configuration, the databases, the languages, ...
  55. require ('../inc/global.inc.php');
  56. $this_section = SECTION_MYAGENDA;
  57. require (api_get_path(LIBRARY_PATH).'groupmanager.lib.php');
  58. // setting the name of the tool
  59. $nameTools = get_lang('MyAgenda');
  60. // if we come from inside a course and click on the 'My Agenda' link we show a link back to the course
  61. // in the breadcrumbs
  62. if (!empty ($_GET['coursePath']))
  63. {
  64. $interbreadcrumb[] = array ('url' => api_get_path(WEB_COURSE_PATH).$_GET['coursePath'].'/index.php', 'name' => $_GET['courseCode']);
  65. }
  66. // this loads the javascript that is needed for the date popup selection
  67. $htmlHeadXtra[] = "<script src=\"tbl_change.js\" type=\"text/javascript\" language=\"javascript\"></script>";
  68. // showing the header
  69. Display::display_header(get_lang('MyAgenda'));
  70. /* ==============================================================================
  71. SETTING SOME VARIABLES
  72. ============================================================================== */
  73. // setting the database variables
  74. $TABLECOURS = Database :: get_main_table(MAIN_COURSE_TABLE);
  75. $TABLECOURSUSER = Database :: get_main_table(MAIN_COURSE_USER_TABLE);
  76. $TABLEAGENDA = Database :: get_course_table(AGENDA_TABLE);
  77. $TABLE_ITEMPROPERTY = Database :: get_course_table(LAST_TOOL_EDIT_TABLE);
  78. $TABLE_PERSONAL_AGENDA = Database :: get_user_personal_table(PERSONAL_AGENDA);
  79. // the variables for the days and the months
  80. // Defining the shorts for the days
  81. $DaysShort = array (get_lang("SundayShort"), get_lang("MondayShort"), get_lang("TuesdayShort"), get_lang("WednesdayShort"), get_lang("ThursdayShort"), get_lang("FridayShort"), get_lang("SaturdayShort"));
  82. // Defining the days of the week to allow translation of the days
  83. $DaysLong = array (get_lang("SundayLong"), get_lang("MondayLong"), get_lang("TuesdayLong"), get_lang("WednesdayLong"), get_lang("ThursdayLong"), get_lang("FridayLong"), get_lang("SaturdayLong"));
  84. // Defining the months of the year to allow translation of the months
  85. $MonthsLong = array (get_lang("JanuaryLong"), get_lang("FebruaryLong"), get_lang("MarchLong"), get_lang("AprilLong"), get_lang("MayLong"), get_lang("JuneLong"), get_lang("JulyLong"), get_lang("AugustLong"), get_lang("SeptemberLong"), get_lang("OctoberLong"), get_lang("NovemberLong"), get_lang("DecemberLong"));
  86. /* ==============================================================================
  87. SANITY CHECK
  88. ============================================================================== */
  89. // You can delete this if you have manually added the new database and tables
  90. // this piece of code was added to avoid having to explain to non sys-admin
  91. // what has to be done in order to get this tool working
  92. if (get_setting("allow_personal_agenda") == "true")
  93. {
  94. // I use a separate database for storing all the information of user driven tools
  95. // as the Personal Agenda tool has the potential to create a large database.
  96. // If you do not want a separate database for the personal agenda tool you can add the table to
  97. // the main dokeos database by changing $DATABASE_USER_TOOLS above to $mainDbName
  98. $sql_create_database = "CREATE DATABASE IF NOT EXISTS `$DATABASE_USER_TOOLS`";
  99. $result = api_sql_query($sql_create_database);
  100. $sql_create_table = "CREATE TABLE IF NOT EXISTS $TABLE_PERSONAL_AGENDA (
  101. `id` int(11) NOT NULL auto_increment,
  102. `user` int(11),
  103. `title` text,
  104. `text` text,
  105. `date` datetime default NULL,
  106. `course` varchar(255),
  107. UNIQUE KEY `id` (`id`))
  108. TYPE=MyISAM AUTO_INCREMENT=1";
  109. $result = api_sql_query($sql_create_table);
  110. }
  111. /*==============================================================================
  112. TREATING THE URL PARAMETERS
  113. 1. The default values
  114. 2. storing it in the session
  115. 3. possible view
  116. 3.a Month view
  117. 3.b Week view
  118. 3.c day view
  119. 3.d personal view (only the personal agenda items)
  120. 4. add personal agenda
  121. 5. edit personal agenda
  122. 6. delete personal agenda
  123. ============================================================================== */
  124. // 1. The default values. if there is no session yet, we have by default the month view
  125. if (!$_SESSION['view'])
  126. {
  127. $_SESSION['view'] = "month";
  128. }
  129. // 2. Storing it in the session. If we change the view by clicking on the links left, we change the session
  130. if ($_GET['view'])
  131. {
  132. $_SESSION['view'] = $_GET['view'];
  133. }
  134. // 3. The views: (month, week, day, personal)
  135. if ($_SESSION['view'])
  136. {
  137. switch ($_SESSION['view'])
  138. {
  139. // 3.a Month view
  140. case "month" :
  141. $proces = "month_view";
  142. break;
  143. // 3.a Week view
  144. case "week" :
  145. $proces = "week_view";
  146. break;
  147. // 3.a Day view
  148. case "day" :
  149. $proces = "day_view";
  150. break;
  151. // 3.a Personal view
  152. case "personal" :
  153. $proces = "personal_view";
  154. break;
  155. }
  156. }
  157. // 4. add personal agenda
  158. if ($_GET['action'] == "add_personal_agenda_item" and !$_POST['Submit'])
  159. {
  160. $proces = "add_personal_agenda_item";
  161. }
  162. if ($_GET['action'] == "add_personal_agenda_item" and $_POST['Submit'])
  163. {
  164. $proces = "store_personal_agenda_item";
  165. }
  166. // 5. edit personal agenda
  167. if ($_GET['action'] == "edit_personal_agenda_item" and !$_POST['Submit'])
  168. {
  169. $proces = "edit_personal_agenda_item";
  170. }
  171. if ($_GET['action'] == "edit_personal_agenda_item" and $_POST['Submit'])
  172. {
  173. $proces = "store_personal_agenda_item";
  174. }
  175. // 6. delete personal agenda
  176. if ($_GET['action'] == "delete" AND $_GET['id'])
  177. {
  178. $proces = "delete_personal_agenda_item";
  179. }
  180. /* ==============================================================================
  181. OUTPUT
  182. ============================================================================== */
  183. if (isset ($_uid))
  184. {
  185. // getting all the courses that this user is subscribed to
  186. $courses_dbs = get_courses_of_user();
  187. if (!is_array($courses_dbs)) // this is for the special case if the user has no courses (otherwise you get an error)
  188. {
  189. $courses_dbs = array ();
  190. }
  191. // setting and/or getting the year, month, day, week
  192. $today = getdate();
  193. $year = $_GET['year'];
  194. if ($year == NULL)
  195. {
  196. $year = $today['year'];
  197. }
  198. $month = $_GET['month'];
  199. if ($month == NULL)
  200. {
  201. $month = $today['mon'];
  202. }
  203. $day = $_GET['day'];
  204. if ($day == NULL)
  205. {
  206. $day = $today['mday'];
  207. }
  208. $week = $_GET['week'];
  209. if ($week == NULL)
  210. {
  211. $week = date("W");
  212. }
  213. // The name of the current Month
  214. $monthName = $MonthsLong[$month -1];
  215. // Starting the output
  216. echo "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
  217. echo "<tr>";
  218. // output: the small calendar item on the left and the view / add links
  219. echo "<td width=\"220\" valign=\"top\">";
  220. $agendaitems = get_agendaitems($rootWeb, $courses_dbs, $month, $year);
  221. if (get_setting('allow_personal_agenda') == 'true')
  222. {
  223. $agendaitems = get_personal_agendaitems($rootWeb, $agendaitems, $day, $month, $year, $week, "month_view");
  224. }
  225. display_minimonthcalendar($agendaitems, $month, $year, $monthName);
  226. echo "\n<ul id=\"agenda_select\">\n";
  227. echo "\t<li><a href=\"".$_SERVER['PHP_SELF']."?action=view&amp;view=month\"><img src=\"../img/calendar_month.gif\" border=\"0\" alt=\"".get_lang('MonthView')."\" /> ".get_lang('MonthView')."</a></li>\n";
  228. echo "\t<li><a href=\"".$_SERVER['PHP_SELF']."?action=view&amp;view=week\"><img src=\"../img/calendar_week.gif\" border=\"0\" alt=\"".get_lang('WeekView')."\" /> ".get_lang('WeekView')."</a></li>\n";
  229. echo "\t<li><a href=\"".$_SERVER['PHP_SELF']."?action=view&amp;view=day\"><img src=\"../img/calendar_day.gif\" border=\"0\" alt=\"".get_lang('DayView')."\" /> ".get_lang('DayView')."</a></li>\n";
  230. if (get_setting('allow_personal_agenda') == 'true')
  231. {
  232. echo "\t<li><a href=\"".$_SERVER['PHP_SELF']."?action=add_personal_agenda_item\"><img src=\"../img/calendar_personal_add.gif\" border=\"0\" /> ".get_lang("AddPersonalItem")."</a></li>\n";
  233. echo "\t<li><a href=\"".$_SERVER['PHP_SELF']."?action=view&amp;view=personal\"><img src=\"../img/calendar_personal.gif\" border=\"0\" /> ".get_lang("ViewPersonalItem")."</a></li>\n";
  234. }
  235. echo "</ul>\n\n";
  236. echo "</td>";
  237. // the divider
  238. // OlivierB : the image has a white background, which causes trouble if the portal has another background color. Image should be transparent. ----> echo "<td width=\"20\" background=\"../img/verticalruler.gif\">&nbsp;</td>";
  239. echo "<td width=\"20\">&nbsp;</td>";
  240. // the main area: day, week, month view
  241. echo "<td valign=\"top\">";
  242. switch ($proces)
  243. {
  244. case "month_view" :
  245. $agendaitems = get_agendaitems($rootWeb, $courses_dbs, $month, $year);
  246. if (get_setting("allow_personal_agenda") == "true")
  247. {
  248. $agendaitems = get_personal_agendaitems($rootWeb, $agendaitems, $day, $month, $year, $week, "month_view");
  249. }
  250. display_monthcalendar($agendaitems, $month, $year, $langDay_of_weekNames['long'], $monthName);
  251. break;
  252. case "week_view" :
  253. $agendaitems = get_week_agendaitems($rootWeb, $courses_dbs, $month, $year, $week);
  254. if (get_setting("allow_personal_agenda") == "true")
  255. {
  256. $agendaitems = get_personal_agendaitems($rootWeb, $agendaitems, $day, $month, $year, $week, "week_view");
  257. }
  258. display_weekcalendar($agendaitems, $month, $year, $langDay_of_weekNames['long'], $monthName);
  259. break;
  260. case "day_view" :
  261. $agendaitems = get_day_agendaitems($rootWeb, $courses_dbs, $month, $year, $day);
  262. if (get_setting("allow_personal_agenda") == "true")
  263. {
  264. $agendaitems = get_personal_agendaitems($rootWeb, $agendaitems, $day, $month, $year, $week, "day_view");
  265. }
  266. display_daycalendar($agendaitems, $day, $month, $year, $langDay_of_weekNames['long'], $monthName);
  267. break;
  268. case "personal_view" :
  269. show_personal_agenda();
  270. break;
  271. case "add_personal_agenda_item" :
  272. show_new_item_form();
  273. break;
  274. case "store_personal_agenda_item" :
  275. store_personal_item($_POST['frm_day'], $_POST['frm_month'], $_POST['frm_year'], $_POST['frm_hour'], $_POST['frm_minute'], $_POST['frm_title'], $_POST['frm_content'], $_GET['id']);
  276. if ($_GET['id'])
  277. {
  278. Display :: display_normal_message(get_lang("PeronalAgendaItemEdited"));
  279. }
  280. else
  281. {
  282. Display :: display_normal_message(get_lang("PeronalAgendaItemAdded"));
  283. }
  284. show_personal_agenda();
  285. break;
  286. case "edit_personal_agenda_item" :
  287. show_new_item_form($_GET['id']);
  288. break;
  289. case "delete_personal_agenda_item" :
  290. delete_personal_agenda($_GET['id']);
  291. Display :: display_normal_message(get_lang('PeronalAgendaItemDeleted'));
  292. show_personal_agenda();
  293. break;
  294. }
  295. }
  296. echo "</td></tr></table>";
  297. Display :: display_footer();
  298. /*============================================================================
  299. get_agendaitems($rootWeb, $courses_db, $month, $year)
  300. ============================================================================*/
  301. // This function retrieves all the agenda items of all the course of the user
  302. function get_agendaitems($rootWeb, $courses_dbs, $month, $year)
  303. {
  304. global $courseTablePrefix, $dbGlu;
  305. global $_uid;
  306. $items = array ();
  307. // get agenda-items for every course
  308. foreach ($courses_dbs as $key => $array_course_info)
  309. {
  310. //databases of the courses
  311. $TABLEAGENDA = Database :: get_course_table(AGENDA_TABLE, $array_course_info["db"]);
  312. $TABLE_ITEMPROPERTY = Database :: get_course_table(LAST_TOOL_EDIT_TABLE, $array_course_info["db"]);
  313. $group_memberships = GroupManager :: get_group_ids($array_course_info["db"], $_uid);
  314. // if the user is administrator of that course we show all the agenda items
  315. if ($array_course_info['status'] == '1')
  316. {
  317. //echo "course admin";
  318. $sqlquery = "SELECT
  319. DISTINCT agenda.*, item_property.*
  320. FROM ".$TABLEAGENDA." agenda,
  321. ".$TABLE_ITEMPROPERTY." item_property
  322. WHERE `agenda`.`id` = `item_property`.`ref` ".$show_all_current."
  323. AND MONTH(`agenda`.`start_date`)='".$month."'
  324. AND YEAR(`agenda`.`start_date`)='".$year."'
  325. AND `item_property`.`tool`='".TOOL_CALENDAR_EVENT."'
  326. AND `item_property`.`visibility`='1'
  327. ORDER BY start_date ".$sort;
  328. }
  329. // if the user is not an administrator of that course
  330. else
  331. {
  332. //echo "GEEN course admin";
  333. if (is_array($group_memberships))
  334. {
  335. $sqlquery = "SELECT
  336. agenda.*, item_property.*
  337. FROM ".$TABLEAGENDA." agenda,
  338. ".$TABLE_ITEMPROPERTY." item_property
  339. WHERE `agenda`.`id` = `item_property`.`ref` ".$show_all_current."
  340. AND MONTH(`agenda`.`start_date`)='".$month."'
  341. AND YEAR(`agenda`.`start_date`)='".$year."'
  342. AND `item_property`.`tool`='".TOOL_CALENDAR_EVENT."'
  343. AND ( `item_property`.`to_user_id`='".$_uid."' OR `item_property`.`to_group_id` IN (0, ".implode(", ", $group_memberships).") )
  344. AND `item_property`.`visibility`='1'
  345. ORDER BY start_date ".$sort;
  346. }
  347. else
  348. {
  349. $sqlquery = "SELECT
  350. agenda.*, item_property.*
  351. FROM ".$TABLEAGENDA." agenda,
  352. ".$TABLE_ITEMPROPERTY." item_property
  353. WHERE `agenda`.`id` = `item_property`.`ref` ".$show_all_current."
  354. AND MONTH(`agenda`.`start_date`)='".$month."'
  355. AND YEAR(`agenda`.`start_date`)='".$year."'
  356. AND `item_property`.`tool`='".TOOL_CALENDAR_EVENT."'
  357. AND ( `item_property`.`to_user_id`='".$_uid."' OR `item_property`.`to_group_id`='0')
  358. AND `item_property`.`visibility`='1'
  359. ORDER BY start_date ".$sort;
  360. }
  361. }
  362. $result = api_sql_query($sqlquery, __FILE__, __LINE__);
  363. while ($item = mysql_fetch_array($result))
  364. {
  365. $agendaday = date("j",strtotime($item['start_date']));
  366. $time= date("H:i",strtotime($item['start_date']));
  367. $URL = $rootWeb."main/calendar/agenda.php?cidReq=".urlencode($array_course_info["code"])."&amp;day=$agendaday&amp;month=$month&amp;year=$year#$agendaday"; // RH //Patrick Cool: to highlight the relevant agenda item
  368. $items[$agendaday][$item['start_time']] .= "<i>".$time."</i> <a href=\"$URL\" title=\"".$array_course_info["name"]."\">".$array_course_info["visual_code"]."</a> ".$item['title']."<br />";
  369. }
  370. }
  371. // sorting by hour for every day
  372. $agendaitems = array ();
  373. while (list ($agendaday, $tmpitems) = each($items))
  374. {
  375. sort($tmpitems);
  376. while (list ($key, $val) = each($tmpitems))
  377. {
  378. $agendaitems[$agendaday] .= $val;
  379. }
  380. }
  381. //print_r($agendaitems);
  382. return $agendaitems;
  383. }
  384. /*============================================================================
  385. display_monthcalendar($agendaitems, $month, $year, $weekdaynames, $monthName)
  386. ============================================================================*/
  387. // show the monthcalender of the given month
  388. function display_monthcalendar($agendaitems, $month, $year, $weekdaynames, $monthName)
  389. {
  390. global $DaysShort;
  391. //Handle leap year
  392. $numberofdays = array (0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
  393. if (($year % 400 == 0) or ($year % 4 == 0 and $year % 100 <> 0))
  394. $numberofdays[2] = 29;
  395. //Get the first day of the month
  396. $dayone = getdate(mktime(0, 0, 0, $month, 1, $year));
  397. //Start the week on monday
  398. $startdayofweek = $dayone['wday'] <> 0 ? ($dayone['wday'] - 1) : 6;
  399. $backwardsURL = $_SERVER['PHP_SELF']."?coursePath=".htmlentities($_GET['coursePath'])."&amp;courseCode=".htmlentities($_GET['courseCode'])."&amp;action=view&amp;view=month&amp;month=". ($month == 1 ? 12 : $month -1)."&amp;year=". ($month == 1 ? $year -1 : $year);
  400. $forewardsURL = $_SERVER['PHP_SELF']."?coursePath=".htmlentities($_GET['coursePath'])."&amp;courseCode=".htmlentities($_GET['courseCode'])."&amp;action=view&amp;view=month&amp;month=". ($month == 12 ? 1 : $month +1)."&amp;year=". ($month == 12 ? $year +1 : $year);
  401. echo "<table id=\"agenda_list\">\n", "<tr class=\"title\">\n", "<td width=\"10%\"><a href=\"", $backwardsURL, "\">«</a></td>\n", "<td width=\"80%\" colspan=\"5\">", $monthName, " ", $year, "</td>\n", "<td width=\"10%\"><a href=\"", $forewardsURL, "\">»</a></td>\n", "</tr>\n";
  402. echo "<tr>\n";
  403. for ($ii = 1; $ii < 8; $ii ++)
  404. {
  405. echo "<td class=\"weekdays\">", $DaysShort[$ii % 7], "</td>\n";
  406. }
  407. echo "</tr>\n";
  408. $curday = -1;
  409. $today = getdate();
  410. while ($curday <= $numberofdays[$month])
  411. {
  412. echo "<tr>\n";
  413. for ($ii = 0; $ii < 7; $ii ++)
  414. {
  415. if (($curday == -1) && ($ii == $startdayofweek))
  416. {
  417. $curday = 1;
  418. }
  419. if (($curday > 0) && ($curday <= $numberofdays[$month]))
  420. {
  421. $bgcolor = $ii < 5 ? $class = "class=\"days_week\"" : $class = "class=\"days_weekend\"";
  422. $dayheader = "<b>$curday</b>";
  423. if (($curday == $today[mday]) && ($year == $today[year]) && ($month == $today[mon]))
  424. {
  425. $dayheader = "$curday - ".get_lang("Today")."<br />";
  426. $class = "class=\"days_today\"";
  427. }
  428. echo "<td ".$class.">", "".$dayheader;
  429. if (!empty($agendaitems[$curday]))
  430. {
  431. echo "<span class=\"agendaitem\">".$agendaitems[$curday]."</span>";
  432. }
  433. echo "</td>\n";
  434. $curday ++;
  435. }
  436. else
  437. {
  438. echo "<td>&nbsp;</td>\n";
  439. }
  440. }
  441. echo "</tr>\n";
  442. }
  443. echo "</table>\n";
  444. }
  445. /*============================================================================
  446. display_minimonthcalendar($agendaitems, $month, $year, $monthName)
  447. ============================================================================*/
  448. // show the mini calender of the given month
  449. function display_minimonthcalendar($agendaitems, $month, $year, $monthName)
  450. {
  451. global $DaysShort;
  452. //Handle leap year
  453. $numberofdays = array (0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
  454. if (($year % 400 == 0) or ($year % 4 == 0 and $year % 100 <> 0))
  455. $numberofdays[2] = 29;
  456. //Get the first day of the month
  457. $dayone = getdate(mktime(0, 0, 0, $month, 1, $year));
  458. //Start the week on monday
  459. $startdayofweek = $dayone['wday'] <> 0 ? ($dayone['wday'] - 1) : 6;
  460. $backwardsURL = $_SERVER['PHP_SELF']."?coursePath=".$_GET['coursePath']."&amp;courseCode=".$_GET['courseCode']."&amp;month=". ($month == 1 ? 12 : $month -1)."&amp;year=". ($month == 1 ? $year -1 : $year);
  461. $forewardsURL = $_SERVER['PHP_SELF']."?coursePath=".$_GET['coursePath']."&amp;courseCode=".$_GET['courseCode']."&amp;month=". ($month == 12 ? 1 : $month +1)."&amp;year=". ($month == 12 ? $year +1 : $year);
  462. echo "<table id=\"smallcalendar\">\n", "<tr class=\"title\">\n", "<td width=\"10%\"><a href=\"", $backwardsURL, "\">«</a></td>\n", "<td width=\"80%\" colspan=\"5\">", $monthName, " ", $year, "</td>\n", "<td width=\"10%\"><a href=\"", $forewardsURL, "\">»</a></td>\n", "</tr>\n";
  463. echo "<tr>\n";
  464. for ($ii = 1; $ii < 8; $ii ++)
  465. {
  466. echo "<td class=\"weekdays\">", $DaysShort[$ii % 7], "</td>\n";
  467. }
  468. echo "</tr>\n";
  469. $curday = -1;
  470. $today = getdate();
  471. while ($curday <= $numberofdays[$month])
  472. {
  473. echo "<tr>\n";
  474. for ($ii = 0; $ii < 7; $ii ++)
  475. {
  476. if (($curday == -1) && ($ii == $startdayofweek))
  477. {
  478. $curday = 1;
  479. }
  480. if (($curday > 0) && ($curday <= $numberofdays[$month]))
  481. {
  482. $bgcolor = $ii < 5 ? $class = "class=\"days_week\"" : $class = "class=\"days_weekend\"";
  483. $dayheader = "$curday";
  484. if (($curday == $today[mday]) && ($year == $today[year]) && ($month == $today[mon]))
  485. {
  486. $dayheader = "$curday";
  487. $class = "class=\"days_today\"";
  488. }
  489. echo "\t<td ".$class.">";
  490. if ($agendaitems[$curday] <> "")
  491. {
  492. echo "<a href=\"".$_SERVER['PHP_SELF']."?action=view&amp;view=day&amp;day=".$curday."&amp;month=".$month."&amp;year=".$year."\">".$dayheader."</a>";
  493. }
  494. else
  495. {
  496. echo $dayheader;
  497. }
  498. // "a".$dayheader." <span class=\"agendaitem\">".$agendaitems[$curday]."</span>\n";
  499. echo "</td>\n";
  500. $curday ++;
  501. }
  502. else
  503. {
  504. echo "<td>&nbsp;</td>\n";
  505. }
  506. }
  507. echo "</tr>\n";
  508. }
  509. echo "</table>\n";
  510. }
  511. /*============================================================================
  512. display_weekcalendar($agendaitems, $month, $year, $weekdaynames, $monthName)
  513. ============================================================================*/
  514. function display_weekcalendar($agendaitems, $month, $year, $weekdaynames, $monthName)
  515. {
  516. global $DaysShort;
  517. global $MonthsLong;
  518. // timestamp of today
  519. $today = mktime();
  520. $day_of_the_week = date("w", $today);
  521. $thisday_of_the_week = date("w", $today);
  522. // the week number of the year
  523. $week_number = date("W", $today);
  524. $thisweek_number = date("W", $today);
  525. // if we moved to the next / previous week we have to recalculate the $today variable
  526. if ($_GET['week'])
  527. {
  528. $today = mktime(0, 0, 0, 1, 1, $year);
  529. $today = $today + (($_GET['week']) * (7 * 24 * 60 * 60));
  530. $week_number = date("W", $today);
  531. }
  532. // calculating the start date of the week
  533. // the date of the monday of this week is the timestamp of today minus
  534. // number of days that have already passed this week * 24 hours * 60 minutes * 60 seconds
  535. $current_day = date("j", $today); // Day of the month without leading zeros (1 to 31) of today
  536. $day_of_the_week = date("w", $today); // Numeric representation of the day of the week 0 (for Sunday) through 6 (for Saturday) of today
  537. $timestamp_first_date_of_week = $today - (($day_of_the_week -1) * 24 * 60 * 60); // timestamp of the monday of this week
  538. $timestamp_last_date_of_week = $today + ((7 - $day_of_the_week) * 24 * 60 * 60); // timestamp of the sunday of this week
  539. $backwardsURL = $_SERVER['PHP_SELF']."?coursePath=".$_GET['coursePath']."&amp;courseCode=".$_GET['courseCode']."&amp;action=view&amp;view=week&amp;week=". ($week_number -1);
  540. $forewardsURL = $_SERVER['PHP_SELF']."?coursePath=".$_GET['coursePath']."&amp;courseCode=".$_GET['courseCode']."&amp;action=view&amp;view=week&amp;week=". ($week_number +1);
  541. echo "<table id=\"agenda_list\">\n";
  542. // The title row containing the the week information (week of the year (startdate of week - enddate of week)
  543. echo "<tr class=\"title\">\n";
  544. echo "<td width=\"10%\"><a href=\"", $backwardsURL, "\">«</a></td>\n";
  545. echo "<td colspan=\"5\">".get_lang("Week")." ".$week_number;
  546. 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).')';
  547. echo "</td>";
  548. echo "<td width=\"10%\"><a href=\"", $forewardsURL, "\">»</a></td>\n", "</tr>\n";
  549. // The second row containing the short names of the days of the week
  550. echo "<tr>\n";
  551. // this is the Day of the month without leading zeros (1 to 31) of the monday of this week
  552. $tmp_timestamp = $timestamp_first_date_of_week;
  553. for ($ii = 1; $ii < 8; $ii ++)
  554. {
  555. echo "\t<td class=\"weekdays\">";
  556. if ($ii == $thisday_of_the_week AND (!isset($_GET['week']) OR $_GET['week']==$thisweek_number))
  557. {
  558. echo "<font color=#CC3300>";
  559. }
  560. echo $DaysShort[$ii % 7]." ".date("j", $tmp_timestamp)." ".$MonthsLong[date("n", $tmp_timestamp) - 1];
  561. if ($ii == $thisday_of_the_week AND (!isset($_GET['week']) OR $_GET['week']==$thisweek_number))
  562. {
  563. echo "</font>";
  564. }
  565. echo "</td>\n";
  566. // we 24 hours * 60 minutes * 60 seconds to the $tmp_timestamp
  567. $array_tmp_timestamp[] = $tmp_timestamp;
  568. $tmp_timestamp = $tmp_timestamp + (24 * 60 * 60);
  569. }
  570. echo "</tr>\n";
  571. // the table cells containing all the entries for that day
  572. echo "<tr>\n";
  573. $counter = 0;
  574. foreach ($array_tmp_timestamp as $key => $value)
  575. {
  576. if ($counter < 5)
  577. {
  578. $class = "class=\"days_week\"";
  579. }
  580. else
  581. {
  582. $class = "class=\"days_weekend\"";
  583. }
  584. if ($counter == $thisday_of_the_week -1 AND (!isset($_GET['week']) OR $_GET['week']==$thisweek_number))
  585. {
  586. $class = "class=\"days_today\"";
  587. }
  588. echo "\t<td ".$class.">";
  589. echo "<span class=\"agendaitem\">".$agendaitems[date("j", $value)]."&nbsp;</span> ";
  590. echo "</td>\n";
  591. $counter ++;
  592. }
  593. echo "</tr>\n";
  594. echo "</table>\n";
  595. }
  596. /*============================================================================
  597. display_daycalendar($agendaitems, $month, $year, $weekdaynames, $monthName)
  598. ============================================================================*/
  599. // show the mini calender of the given month
  600. function display_daycalendar($agendaitems, $day, $month, $year, $weekdaynames, $monthName)
  601. {
  602. global $DaysShort, $DaysLong;
  603. global $MonthsLong;
  604. global $query;
  605. global $courseTablePrefix, $dbGlu;
  606. // some debug information
  607. // echo "dag: ".$day;
  608. // echo "maand: ".$month;
  609. // echo "jaar: ".$year;
  610. // timestamp of today
  611. $today = mktime();
  612. $nextday = $today + (24 * 60 * 60);
  613. $previousday = $today - (24 * 60 * 60);
  614. // the week number of the year
  615. $week_number = date("W", $today);
  616. // if we moved to the next / previous day we have to recalculate the $today variable
  617. if ($_GET['day'])
  618. {
  619. $today = mktime(0, 0, 0, $month, $day, $year);
  620. $nextday = $today + (24 * 60 * 60);
  621. $previousday = $today - (24 * 60 * 60);
  622. $week_number = date("W", $today);
  623. }
  624. // calculating the start date of the week
  625. // the date of the monday of this week is the timestamp of today minus
  626. // number of days that have already passed this week * 24 hours * 60 minutes * 60 seconds
  627. $current_day = date("j", $today); // Day of the month without leading zeros (1 to 31) of today
  628. $day_of_the_week = date("w", $today); // Numeric representation of the day of the week 0 (for Sunday) through 6 (for Saturday) of today
  629. //$timestamp_first_date_of_week=$today-(($day_of_the_week-1)*24*60*60); // timestamp of the monday of this week
  630. //$timestamp_last_date_of_week=$today+((7-$day_of_the_week)*24*60*60); // timestamp of the sunday of this week
  631. // we are loading all the calendar items of all the courses for today
  632. echo "<table id=\"agenda_list\">\n";
  633. // the forward and backwards url
  634. $backwardsURL = $_SERVER['PHP_SELF']."?coursePath=".$_GET['coursePath']."&amp;courseCode=".$_GET['courseCode']."&amp;action=view&amp;view=day&amp;day=".date("j", $previousday)."&amp;month=".date("n", $previousday)."&amp;year=".date("Y", $previousday);
  635. $forewardsURL = $_SERVER['PHP_SELF']."?coursePath=".$_GET['coursePath']."&amp;courseCode=".$_GET['courseCode']."&amp;action=view&amp;view=day&amp;day=".date("j", $nextday)."&amp;month=".date("n", $nextday)."&amp;year=".date("Y", $nextday);
  636. // The title row containing the day
  637. echo "<tr class=\"title\">\n", "<td width=\"10%\"><a href=\"", $backwardsURL, "\">«</a></td>\n", "<td>";
  638. echo $DaysLong[$day_of_the_week]." ".date("j", $today)." ".$MonthsLong[date("n", $today) - 1]." ".date("Y", $today);
  639. echo "</td>";
  640. echo "<td width=\"10%\"><a href=\"", $forewardsURL, "\">»</a></td>\n";
  641. echo "</tr>\n";
  642. // the rows for each half an hour
  643. for ($i = 10; $i < 48; $i ++)
  644. {
  645. echo "<tr>\n";
  646. echo "\t";
  647. if ($i % 2 == 0)
  648. {
  649. $class = "class=\"alternativeBgLight\"";
  650. echo ("<td $class valign=\"top\" width=\"75\">". (($i) / 2)." ".get_lang("HourShort")." 00</td>\n");
  651. }
  652. else
  653. {
  654. $class = "";
  655. echo ("<td valign=\"top\" width=\"75\">". ((($i) / 2) - (1 / 2))." ".get_lang("HourShort")." 30</td>\n");
  656. }
  657. echo "\t<td $class valign=\"top\" colspan=\"2\">\n";
  658. if (is_array($agendaitems[$i]))
  659. {
  660. foreach ($agendaitems[$i] as $key => $value)
  661. {
  662. echo $value;
  663. }
  664. }
  665. else
  666. {
  667. echo $agendaitems[$i];
  668. }
  669. echo "\t</td>\n";
  670. echo "</tr>\n";
  671. }
  672. echo "</table>\n";
  673. }
  674. /*============================================================================
  675. get_day_agendaitems($rootWeb, $query, $month, $year)
  676. ============================================================================*/
  677. // show the monthcalender of the given month
  678. function get_day_agendaitems($rootWeb, $courses_dbs, $month, $year, $day)
  679. {
  680. global $courseTablePrefix, $dbGlu;
  681. global $_uid;
  682. $items = array ();
  683. // get agenda-items for every course
  684. //$query=api_sql_query($sql_select_courses);
  685. foreach ($courses_dbs as $key => $array_course_info)
  686. {
  687. //databases of the courses
  688. $TABLEAGENDA = Database :: get_course_table(AGENDA_TABLE, $array_course_info["db"]);
  689. $TABLE_ITEMPROPERTY = Database :: get_course_table(LAST_TOOL_EDIT_TABLE, $array_course_info["db"]);
  690. // getting all the groups of the user for the current course
  691. $group_memberships = GroupManager :: get_group_ids($array_course_info["db"], $_uid);
  692. // if the user is administrator of that course we show all the agenda items
  693. if ($array_course_info['status'] == '1')
  694. {
  695. //echo "course admin";
  696. $sqlquery = "SELECT
  697. DISTINCT agenda.*, item_property.*
  698. FROM ".$TABLEAGENDA." agenda,
  699. ".$TABLE_ITEMPROPERTY." item_property
  700. WHERE `agenda`.`id` = `item_property`.`ref` ".$show_all_current."
  701. AND DAYOFMONTH(start_date)='".$day."' AND MONTH(start_date)='".$month."' AND YEAR(start_date)='".$year."'
  702. AND `item_property`.`tool`='".TOOL_CALENDAR_EVENT."'
  703. AND `item_property`.`visibility`='1'
  704. ORDER BY start_date ".$sort;
  705. }
  706. // if the user is not an administrator of that course
  707. else
  708. {
  709. //echo "GEEN course admin";
  710. if (is_array($group_memberships))
  711. {
  712. $sqlquery = "SELECT
  713. agenda.*, item_property.*
  714. FROM ".$TABLEAGENDA." agenda,
  715. ".$TABLE_ITEMPROPERTY." item_property
  716. WHERE `agenda`.`id` = `item_property`.`ref` ".$show_all_current."
  717. AND DAYOFMONTH(start_date)='".$day."' AND MONTH(start_date)='".$month."' AND YEAR(start_date)='".$year."'
  718. AND `item_property`.`tool`='".TOOL_CALENDAR_EVENT."'
  719. AND ( `item_property`.`to_user_id`='".$_uid."' OR `item_property`.`to_group_id` IN (0, ".implode(", ", $group_memberships).") )
  720. AND `item_property`.`visibility`='1'
  721. ORDER BY start_date ".$sort;
  722. }
  723. else
  724. {
  725. $sqlquery = "SELECT
  726. agenda.*, item_property.*
  727. FROM ".$TABLEAGENDA." agenda,
  728. ".$TABLE_ITEMPROPERTY." item_property
  729. WHERE `agenda`.`id` = `item_property`.`ref` ".$show_all_current."
  730. AND DAYOFMONTH(start_date)='".$day."' AND MONTH(start_date)='".$month."' AND YEAR(start_date)='".$year."'
  731. AND `item_property`.`tool`='".TOOL_CALENDAR_EVENT."'
  732. AND ( `item_property`.`to_user_id`='".$_uid."' OR `item_property`.`to_group_id`='0')
  733. AND `item_property`.`visibility`='1'
  734. ORDER BY start_date ".$sort;
  735. }
  736. }
  737. //$sqlquery = "SELECT * FROM $agendadb WHERE DAYOFMONTH(day)='$day' AND month(day)='$month' AND year(day)='$year'";
  738. //echo "abc";
  739. //echo $sqlquery;
  740. $result = api_sql_query($sqlquery, __FILE__, __LINE__);
  741. //echo mysql_num_rows($result);
  742. while ($item = mysql_fetch_array($result))
  743. {
  744. // in the display_daycalendar function we use $i (ranging from 0 to 47) for each halfhour
  745. // we want to know for each agenda item for this day to wich halfhour it must be assigned
  746. list ($datepart, $timepart) = split(" ", $item['start_date']);
  747. list ($year, $month, $day) = explode("-", $datepart);
  748. list ($hours, $minutes, $seconds) = explode(":", $timepart);
  749. $halfhour = 2 * $hours;
  750. if ($minutes >= '30')
  751. {
  752. $halfhour = $halfhour +1;
  753. }
  754. //$URL = $rootWeb.$mycours["dir"]."/";
  755. $URL = $rootWeb."main/calendar/agenda.php?cidReq=".urlencode($array_course_info["code"])."&amp;day=$day&amp;month=$month&amp;year=$year#$day"; // RH //Patrick Cool: to highlight the relevant agenda item
  756. $items[$halfhour][] .= "<i>".$hours.":".$minutes."</i> <a href=\"$URL\" title=\"".$array_course_info['name']."\">".$array_course_info['visual_code']."</a> ".$item['title']."<br />";
  757. }
  758. }
  759. // sorting by hour for every day
  760. /*$agendaitems = array();
  761. while (list($agendaday, $tmpitems) = each($items))
  762. {
  763. sort($tmpitems);
  764. while (list($key,$val) = each($tmpitems))
  765. {
  766. $agendaitems[$agendaday].=$val;
  767. }
  768. }*/
  769. $agendaitems = $items;
  770. //print_r($agendaitems);
  771. return $agendaitems;
  772. }
  773. /*============================================================================
  774. function get_week_agendaitems($rootWeb, $courses_dbs, $month, $year,$day)
  775. ============================================================================*/
  776. function get_week_agendaitems($rootWeb, $courses_dbs, $month, $year, $week = '')
  777. {
  778. global $courseTablePrefix, $dbGlu;
  779. global $TABLEAGENDA, $TABLE_ITEMPROPERTY;
  780. global $_uid;
  781. $items = array ();
  782. // The default value of the week
  783. if ($week == '')
  784. {
  785. $week_number = date("W", mktime());
  786. }
  787. else
  788. {
  789. $week_number = $week;
  790. }
  791. $start_end = calculate_start_end_of_week($week_number, $year);
  792. $start_filter = $start_end['start']['year']."-".$start_end['start']['month']."-".$start_end['start']['day'];
  793. $end_filter = $start_end['end']['year']."-".$start_end['end']['month']."-".$start_end['end']['day'];
  794. /*
  795. // determine the start and end date
  796. // step 1: we calculate a timestamp for a day in this week
  797. $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
  798. // step 2: we which day this is (0=sunday, 1=monday, ...)
  799. $number_day_in_week=date("w",$random_day_in_week);
  800. // step 3: we calculate the timestamp of the monday of the week we are in
  801. $start_timestamp=$random_day_in_week-(($number_day_in_week-1)*24*60*60);
  802. // step 4: we calculate the timestamp of the sunday of the week we are in
  803. $end_timestamp=$random_day_in_week+((7-$number_day_in_week+1)*24*60*60)-3600;
  804. // step 5: calculating the start_day, end_day, start_month, end_month, start_year, end_year
  805. $start_day=date("j",$start_timestamp);
  806. $start_month=date("n",$start_timestamp);
  807. $start_year=date("Y",$start_timestamp);
  808. $end_day=date("j",$end_timestamp);
  809. $end_month=date("n",$end_timestamp);
  810. $end_year=date("Y",$end_timestamp);
  811. // in sql statements you have to use year-month-day for date calculations
  812. $start_filter=$start_year."-".$start_month."-".$start_day;
  813. $end_filter=$end_year."-".$end_month."-".$end_day;
  814. */
  815. //$start_end_week=calculate_start_end_of_week($week_number, $year);
  816. // a little bit of debug information
  817. //echo "START: ".date("l dS of F Y H:i:s A",$start_timestamp)."<br />";
  818. //echo "END: ".date("l dS of F Y H:i:s A",$end_timestamp)."<br />";
  819. // this date is the xth day in the week
  820. // if we moved to the next / previous week we have to recalculate the $today variable
  821. /*if ($_GET['week'])
  822. {
  823. $today=mktime(0,0,0,1,1,$year);
  824. $today=$today+(($_GET['week']-1)*(7*24*60*60));
  825. $week_number=date("W",$today);
  826. }*/
  827. // get agenda-items for every course
  828. foreach ($courses_dbs as $key => $array_course_info)
  829. {
  830. //databases of the courses
  831. $TABLEAGENDA = Database :: get_course_table(AGENDA_TABLE, $array_course_info["db"]);
  832. $TABLE_ITEMPROPERTY = Database :: get_course_table(LAST_TOOL_EDIT_TABLE, $array_course_info["db"]);
  833. // getting all the groups of the user for the current course
  834. $group_memberships = GroupManager :: get_group_ids($array_course_info["db"], $_uid);
  835. // if the user is administrator of that course we show all the agenda items
  836. if ($array_course_info['status'] == '1')
  837. {
  838. //echo "course admin";
  839. $sqlquery = "SELECT
  840. DISTINCT agenda.*, item_property.*
  841. FROM ".$TABLEAGENDA." agenda,
  842. ".$TABLE_ITEMPROPERTY." item_property
  843. WHERE `agenda`.`id` = `item_property`.`ref` ".$show_all_current."
  844. AND start_date>='".$start_filter."' AND start_date<='".$end_filter."'
  845. AND `item_property`.`tool`='".TOOL_CALENDAR_EVENT."'
  846. AND `item_property`.`visibility`='1'
  847. ORDER BY start_date ".$sort;
  848. }
  849. // if the user is not an administrator of that course
  850. else
  851. {
  852. //echo "GEEN course admin";
  853. if (is_array($group_memberships))
  854. {
  855. $sqlquery = "SELECT
  856. agenda.*, item_property.*
  857. FROM ".$TABLEAGENDA." agenda,
  858. ".$TABLE_ITEMPROPERTY." item_property
  859. WHERE `agenda`.`id` = `item_property`.`ref` ".$show_all_current."
  860. AND start_date>='".$start_filter."' AND start_date<='".$end_filter."'
  861. AND `item_property`.`tool`='".TOOL_CALENDAR_EVENT."'
  862. AND ( `item_property`.`to_user_id`='".$_uid."' OR `item_property`.`to_group_id` IN (0, ".implode(", ", $group_memberships).") )
  863. AND `item_property`.`visibility`='1'
  864. ORDER BY start_date ".$sort;
  865. }
  866. else
  867. {
  868. $sqlquery = "SELECT
  869. agenda.*, item_property.*
  870. FROM ".$TABLEAGENDA." agenda,
  871. ".$TABLE_ITEMPROPERTY." item_property
  872. WHERE `agenda`.`id` = `item_property`.`ref` ".$show_all_current."
  873. AND start_date>='".$start_filter."' AND start_date<='".$end_filter."'
  874. AND `item_property`.`tool`='".TOOL_CALENDAR_EVENT."'
  875. AND ( `item_property`.`to_user_id`='".$_uid."' OR `item_property`.`to_group_id`='0')
  876. AND `item_property`.`visibility`='1'
  877. ORDER BY start_date ".$sort;
  878. }
  879. }
  880. //echo "<pre>".$sqlquery."</pre>";
  881. // $sqlquery = "SELECT * FROM $agendadb WHERE (DAYOFMONTH(day)>='$start_day' AND DAYOFMONTH(day)<='$end_day')
  882. // AND (MONTH(day)>='$start_month' AND MONTH(day)<='$end_month')
  883. // AND (YEAR(day)>='$start_year' AND YEAR(day)<='$end_year')";
  884. $result = api_sql_query($sqlquery, __FILE__, __LINE__);
  885. while ($item = mysql_fetch_array($result))
  886. {
  887. $agendaday = date("j",strtotime($item['start_date']));
  888. $time= date("H:i",strtotime($item['start_date']));
  889. $URL = $rootWeb."main/calendar/agenda.php?cidReq=".urlencode($array_course_info["code"])."&amp;day=$agendaday&amp;month=$month&amp;year=$year#$agendaday"; // RH //Patrick Cool: to highlight the relevant agenda item
  890. $items[$agendaday][$item['start_time']] .= "<i>$time</i> <a href=\"$URL\" title=\"".$array_course_info["name"]."\">".$array_course_info["visual_code"]."</a> ".$item['title']."<br />";
  891. }
  892. }
  893. // sorting by hour for every day
  894. $agendaitems = array ();
  895. while (list ($agendaday, $tmpitems) = each($items))
  896. {
  897. sort($tmpitems);
  898. while (list ($key, $val) = each($tmpitems))
  899. {
  900. $agendaitems[$agendaday] .= $val;
  901. }
  902. }
  903. //print_r($agendaitems);
  904. return $agendaitems;
  905. }
  906. /*============================================================================
  907. show_new_item_form()
  908. ============================================================================*/
  909. // This function shows all the forms that are needed form adding /editing a new personal agenda item
  910. // when there is no $id passed in the function we are adding a new agenda item, if there is a $id
  911. // we are editing
  912. // attention: we have to check that the student is editing an item that belongs to him/her
  913. function show_new_item_form($id = "")
  914. {
  915. global $year, $MonthsLong;
  916. global $TABLE_PERSONAL_AGENDA;
  917. global $_uid;
  918. // we construct the default time and date data (used if we are not editing a personal agenda item)
  919. $today = getdate();
  920. $day = $today['mday'];
  921. $month = $today['mon'];
  922. $year = $today['year'];
  923. $hours = $today['hours'];
  924. $minutes = $today['minutes'];
  925. // if an $id is passed to this function this means we are editing an item
  926. // we are loading the information here (we do this after everything else
  927. // to overwrite the default information)
  928. if ($id <> "")
  929. {
  930. $sql = "SELECT * FROM ".$TABLE_PERSONAL_AGENDA." WHERE user='".$_uid."' AND id='".$id."'";
  931. $result = api_sql_query($sql, __FILE__, __LINE__);
  932. $aantal = mysql_num_rows($result);
  933. if ($aantal <> 0)
  934. {
  935. $row = mysql_fetch_array($result);
  936. $year = substr($row['date'], 0, 4);
  937. $month = substr($row['date'], 5, 2);
  938. $day = substr($row['date'], 8, 2);
  939. $hours = substr($row['date'], 11, 2);
  940. $minutes = substr($row['date'], 14, 2);
  941. $title = $row['title'];
  942. $text = $row['text'];
  943. }
  944. else
  945. {
  946. return false;
  947. }
  948. }
  949. echo "<form method=\"post\" action=\"myagenda.php?action=add_personal_agenda_item&amp;id=$id\" name=\"newedit_form\">\n";
  950. echo "<table width=\"100%\" id=\"newedit_form\">\n";
  951. echo "\t<tr class=\"title\">\n\t\t<td colspan=\"3\"><h4>";
  952. echo ($_GET['action'] == 'edit_personal_agenda_item') ? get_lang("ModifyPersonalCalendarItem") : get_lang("AddPersonalCalendarItem");
  953. echo "</h4></td>\n\t</tr>\n";
  954. echo "\t<tr class=\"subtitle\">\n\t\t<td>\n";
  955. echo "<!-- date: 1 -> 31 -->\n";
  956. echo "\t\t".get_lang("Date").": \n";
  957. // ********** The form containing the days (0->31) ********** \\
  958. echo "<select name=\"frm_day\">\n";
  959. // small loop for filling all the dates
  960. // 2do: the available dates should be those of the selected month => february is from 1 to 28 (or 29) and not to 31
  961. for ($i = 1; $i <= 31; $i ++)
  962. {
  963. // values have to have double digits
  964. if ($i <= 9)
  965. {
  966. $value = "0".$i;
  967. }
  968. else
  969. {
  970. $value = $i;
  971. }
  972. // the current day is indicated with [] around the date
  973. if ($value == $day)
  974. {
  975. echo "\t\t\t\t <option value=\"".$value."\" selected>".$i."</option>\n";
  976. }
  977. else
  978. {
  979. echo "\t\t\t\t <option value=\"".$value."\">".$i."</option>\n";
  980. }
  981. }
  982. echo "</select>\n\n";
  983. // ********** The form containing the months (jan->dec) ********** \\
  984. echo "<!-- month: january -> december -->\n";
  985. echo "<select name=\"frm_month\">\n";
  986. for ($i = 1; $i <= 12; $i ++)
  987. {
  988. // values have to have double digits
  989. if ($i <= 9)
  990. {
  991. $value = "0".$i;
  992. }
  993. else
  994. {
  995. $value = $i;
  996. }
  997. // the current month is indicated with [] around the month name
  998. if ($value == $month)
  999. {
  1000. echo "\t<option value=\"".$value."\" selected>".$MonthsLong[$i -1]."</option>\n";
  1001. }
  1002. else
  1003. {
  1004. echo "\t<option value=\"".$value."\">".$MonthsLong[$i -1]."</option>\n";
  1005. }
  1006. }
  1007. echo "</select>\n\n";
  1008. // ********** The form containing the years ********** \\
  1009. echo "<!-- year -->\n";
  1010. echo "<select name=\"frm_year\">";
  1011. echo "<option value=\"". ($year -1)."\">". ($year -1)."</option>\n";
  1012. echo "<option value=\"".$year."\" selected>".$year."</option>\n";
  1013. for ($i = 1; $i <= 5; $i ++)
  1014. {
  1015. $value = $year + $i;
  1016. echo "\t<option value=\"".$value."\">".$value."</option>\n";
  1017. }
  1018. echo "</select>";
  1019. echo "<a title=\"Kalender\" href=\"javascript:openCalendar('newedit_form', 'frm_')\"><img src=\"../img/calendar_select.gif\" border=\"0\" valign=\"absmiddle\"/></a>";
  1020. echo "</td><td width=\"50%\">";
  1021. // ********** The form containing the hours (00->23) ********** \\
  1022. echo "<!-- time: hour -->\n";
  1023. echo get_lang("Time").": \n";
  1024. echo "<select name=\"frm_hour\">\n";
  1025. for ($i = 1; $i <= 24; $i ++)
  1026. {
  1027. // values have to have double digits
  1028. if ($i <= 9)
  1029. {
  1030. $value = "0".$i;
  1031. }
  1032. else
  1033. {
  1034. $value = $i;
  1035. }
  1036. // the current hour is indicated with [] around the hour
  1037. if ($hours == $value)
  1038. {
  1039. echo "\t\t\t\t<option value=\"".$value."\" selected> ".$value." </option>\n";
  1040. }
  1041. else
  1042. {
  1043. echo "\t\t\t\t<option value=\"".$value."\"> ".$value." </option>\n";
  1044. }
  1045. }
  1046. echo "</select>";
  1047. // ********** The form containing the minutes ********** \\
  1048. echo "<select name=\"frm_minute\">";
  1049. echo "<option value=\"".$minutes."\">".$minutes."</option>";
  1050. echo "<option value=\"00\">00</option>";
  1051. echo "<option value=\"05\">05</option>";
  1052. echo "<option value=\"10\">10</option>";
  1053. echo "<option value=\"15\">15</option>";
  1054. echo "<option value=\"20\">20</option>";
  1055. echo "<option value=\"25\">25</option>";
  1056. echo "<option value=\"30\">30</option>";
  1057. echo "<option value=\"35\">35</option>";
  1058. echo "<option value=\"40\">40</option>";
  1059. echo "<option value=\"45\">45</option>";
  1060. echo "<option value=\"50\">50</option>";
  1061. echo "<option value=\"55\">55</option>";
  1062. echo "</select>";
  1063. echo "</td></tr>";
  1064. // ********** The title field ********** \\
  1065. echo "<tr class=\"subtitle\"><td colspan=\"2\">";
  1066. echo get_lang('Title').': <input type="text" name="frm_title" size="50" value="'.$title.'" />';
  1067. echo "</td></tr>";
  1068. // ********** The text field ********** \\
  1069. echo "<tr><td colspan=\"2\">";
  1070. api_disp_html_area('frm_content', $text, '300px');
  1071. echo "</td></tr>";
  1072. // ********** The Submit button********** \\
  1073. echo "<tr><td colspan=\"2\">";
  1074. echo '<input type="submit" name="Submit" value="'.get_lang('Ok').'" />';
  1075. echo "</td></tr>";
  1076. echo "</table>\n</form>\n";
  1077. }
  1078. /*============================================================================
  1079. store_personal_item($day, $month, $year, $hour, $minute, $course, $title, $content, $id="")
  1080. ============================================================================*/
  1081. // This function shows all the forms that are needed form adding a new personal agenda item
  1082. function store_personal_item($day, $month, $year, $hour, $minute, $title, $content, $id = "")
  1083. {
  1084. global $TABLE_PERSONAL_AGENDA;
  1085. global $_uid;
  1086. //constructing the date
  1087. $date = $year."-".$month."-".$day." ".$hour.":".$minute.":00";
  1088. if ($id <> "")
  1089. { // we are updating
  1090. $sql = "UPDATE ".$TABLE_PERSONAL_AGENDA." SET user='".$_uid."', title='".$title."', text='".$content."', date='".$date."' WHERE id='".$id."'";
  1091. }
  1092. else
  1093. { // we are adding a new item
  1094. $sql = "INSERT INTO $TABLE_PERSONAL_AGENDA (user, title, text, date) VALUES ('$_uid','$title', '$content', '$date')";
  1095. }
  1096. $result = api_sql_query($sql, __FILE__, __LINE__);
  1097. }
  1098. /*============================================================================
  1099. get_courses_of_user()
  1100. ============================================================================*/
  1101. // This function finds all the courses of the user and returns an array containing the
  1102. // database name of the courses.
  1103. function get_courses_of_user()
  1104. {
  1105. global $TABLECOURS;
  1106. global $TABLECOURSUSER;
  1107. global $_uid;
  1108. $sql_select_courses = "SELECT course.code k, course.visual_code vc,
  1109. course.title i, course.tutor_name t, course.db_name db, course.directory dir, course_rel_user.status status
  1110. FROM $TABLECOURS course,
  1111. $TABLECOURSUSER course_rel_user
  1112. WHERE course.code = course_rel_user.course_code
  1113. AND course_rel_user.user_id = '$_uid'";
  1114. $result = api_sql_query($sql_select_courses);
  1115. while ($row = mysql_fetch_array($result))
  1116. {
  1117. // we only need the database name of the course
  1118. $courses[] = array ("db" => $row['db'], "code" => $row['k'], "visual_code" => $row['vc'], "title" => $row['i'], "directory" => $row['dir'], "status" => $row['status']);
  1119. }
  1120. return $courses;
  1121. }
  1122. /*============================================================================
  1123. get_personal_agendaitems($rootWeb, $agendaitems, $month, $year, $day, $week, $type);
  1124. ============================================================================*/
  1125. // This function retrieves all the personal agenda items and add them to the agenda items found by the other functions.
  1126. function get_personal_agendaitems($rootWeb, $agendaitems, $day = "", $month = "", $year = "", $week = "", $type)
  1127. {
  1128. global $TABLE_PERSONAL_AGENDA;
  1129. global $_uid;
  1130. // 1. creating the SQL statement for getting the personal agenda items in MONTH view
  1131. if ($type == "month_view" or $type == "") // we are in month view
  1132. {
  1133. $sql = "SELECT * FROM ".$TABLE_PERSONAL_AGENDA." WHERE user='".$_uid."' and MONTH(date)='".$month."' AND YEAR(date) = '".$year."' ORDER BY date ASC";
  1134. }
  1135. // 2. creating the SQL statement for getting the personal agenda items in WEEK view
  1136. if ($type == "week_view") // we are in week view
  1137. {
  1138. $start_end_day_of_week = calculate_start_end_of_week($week, $year);
  1139. $start_day = $start_end_day_of_week['start']['day'];
  1140. $start_month = $start_end_day_of_week['start']['month'];
  1141. $start_year = $start_end_day_of_week['start']['year'];
  1142. $end_day = $start_end_day_of_week['end']['day'];
  1143. $end_month = $start_end_day_of_week['end']['month'];
  1144. $end_year = $start_end_day_of_week['end']['year'];
  1145. // in sql statements you have to use year-month-day for date calculations
  1146. $start_filter = $start_year."-".$start_month."-".$start_day;
  1147. $end_filter = $end_year."-".$end_month."-".$end_day;
  1148. $sql = " SELECT * FROM ".$TABLE_PERSONAL_AGENDA." WHERE user='".$_uid."'
  1149. AND date>='".$start_filter."' AND date<='".$end_filter."'";
  1150. }
  1151. // 3. creating the SQL statement for getting the personal agenda items in DAY view
  1152. if ($type == "day_view") // we are in day view
  1153. {
  1154. // we could use mysql date() function but this is only available from 4.1 and higher
  1155. $start_filter = $year."-".$month."-".$day." 00:00:01";
  1156. $end_filter = $year."-".$month."-".$day." 23:59:59";
  1157. $sql = " SELECT * FROM ".$TABLE_PERSONAL_AGENDA." WHERE user='".$_uid."' AND date>='".$start_filter."' AND date<='".$end_filter."'";
  1158. }
  1159. //echo "day:".$day."/";
  1160. //echo "month:".$month."/";
  1161. //echo "year:".$year."/";
  1162. //echo "week:".$week."/";
  1163. //echo $type."<p>";
  1164. //echo "<pre>".$sql."</pre>";
  1165. $result = api_sql_query($sql, __FILE__, __LINE__);
  1166. while ($item = mysql_fetch_array($result))
  1167. {
  1168. // we break the date field in the database into a date and a time part
  1169. $agenda_db_date = explode(" ", $item[date]);
  1170. $date = $agenda_db_date[0];
  1171. $time = $agenda_db_date[1];
  1172. // we divide the date part into a day, a month and a year
  1173. $agendadate = explode("-", $date);
  1174. $year = intval($agendadate[0]);
  1175. $month = intval($agendadate[1]);
  1176. $day = intval($agendadate[2]);
  1177. // we divide the time part into hour, minutes, seconds
  1178. $agendatime = explode(":", $time);
  1179. $hour = $agendatime[0];
  1180. $minute = $agendatime[1];
  1181. $second = $agendatime[2];
  1182. // if the student has specified a course we a add a link to that course
  1183. if ($item['course'] <> "")
  1184. {
  1185. $url = $rootWeb."main/calendar/agenda.php?cidReq=".urlencode($item['course'])."&amp;day=$day&amp;month=$month&amp;year=$year#$day"; // RH //Patrick Cool: to highlight the relevant agenda item
  1186. $course_link = "<a href=\"$url\" title=\"".$item['course']."\">".$item['course']."</a>";
  1187. }
  1188. else
  1189. {
  1190. $course_link = "";
  1191. }
  1192. // Creating the array that will be returned. If we have week or month view we have an array with the date as the key
  1193. // if we have a day_view we use a half hour as index => key 33 = 16h30
  1194. if ($type !== "day_view") // This is the array construction for the WEEK or MONTH view
  1195. {
  1196. $agendaitems[$day] .= "<div><i>$hour:$minute</i> $course_link <a href=\"myagenda.php?action=view&amp;view=personal&amp;day=$day&amp;month=$month&amp;year=$year&amp;id=".$item['id']."#".$item['id']."\" class=\"personal_agenda\">".$item['title']."</a></div>";
  1197. }
  1198. else // this is the array construction for the DAY view
  1199. {
  1200. $halfhour = 2 * $agendatime['0'];
  1201. if ($agendatime['1'] >= '30')
  1202. {
  1203. $halfhour = $halfhour +1;
  1204. }
  1205. $agendaitems[$halfhour] .= "<div><i>$hour:$minute</i> $course_link <a href=\"myagenda.php?action=view&amp;view=personal&amp;day=$day&amp;month=$month&amp;year=$year&amp;id=".$item['id']."#".$item['id']."\" class=\"personal_agenda\">".$item['title']."</a></div>";
  1206. }
  1207. }
  1208. //print_r($agendaitems);
  1209. return $agendaitems;
  1210. }
  1211. /*============================================================================
  1212. show_personal_agenda()
  1213. ============================================================================*/
  1214. // This function retrieves all the personal agenda items of the user and shows
  1215. // these items in one list (ordered by date and grouped by month (the month_bar)
  1216. function show_personal_agenda()
  1217. {
  1218. global $TABLE_PERSONAL_AGENDA;
  1219. global $MonthsLong;
  1220. global $_uid;
  1221. // The SQL statement that retrieves all the personal agenda items of this user
  1222. $sql = "SELECT * FROM ".$TABLE_PERSONAL_AGENDA." WHERE user='".$_uid."' ORDER BY date DESC";
  1223. $result = api_sql_query($sql, __FILE__, __LINE__);
  1224. // variable initialisation
  1225. $month_bar = "";
  1226. // starting the table output
  1227. echo "<table id=\"agenda_list\">\n";
  1228. // setting the default day, month and year
  1229. if (!$_GET['day'] AND !$_GET['month'] AND !$_GET['year'])
  1230. {
  1231. $today = getdate();
  1232. $year = $today['year'];
  1233. $month = $today['mon'];
  1234. $day = $today['mday'];
  1235. }
  1236. if (mysql_num_rows($result) > 0)
  1237. {
  1238. while ($myrow = mysql_fetch_array($result))
  1239. {
  1240. /*--------------------------------------------------
  1241. display: the month bar
  1242. --------------------------------------------------*/
  1243. if ($month_bar != date("m", strtotime($myrow["date"])).date("Y", strtotime($myrow["date"])))
  1244. {
  1245. $month_bar = date("m", strtotime($myrow["date"])).date("Y", strtotime($myrow["date"]));
  1246. echo "<tr><td class=\"title\" colspan=\"2\" class=\"month\" valign=\"top\">".$MonthsLong[date("n", strtotime($myrow["date"])) - 1]." ".date("Y", strtotime($myrow["date"]))."</td></tr>\n";
  1247. }
  1248. // highlight: if a date in the small calendar is clicked we highlight the relevant items
  1249. $db_date = (int) date("d", strtotime($myrow["date"])).date("n", strtotime($myrow["date"])).date("Y", strtotime($myrow["date"]));
  1250. if ($_GET["day"].$_GET["month"].$_GET["year"] <> $db_date)
  1251. {
  1252. $style = "data";
  1253. $text_style = "text";
  1254. }
  1255. else
  1256. {
  1257. $style = "datanow";
  1258. $text_style = "text";
  1259. }
  1260. /*--------------------------------------------------
  1261. display: date and time
  1262. --------------------------------------------------*/
  1263. echo "\t<tr>\n\t\t";
  1264. echo "<td class=\"".$style."\">";
  1265. // adding an internal anchor
  1266. echo "<a name=\"".$myrow["id"]."\"></a>";
  1267. echo date("d", strtotime($myrow["date"]))." ".$MonthsLong[date("n", strtotime($myrow["date"])) - 1]." ".date("Y", strtotime($myrow["date"]))."&nbsp;";
  1268. echo ucfirst(strftime(get_lang("timeNoSecFormat"), strtotime($myrow["date"])));
  1269. echo "</td></tr>";
  1270. /*--------------------------------------------------
  1271. display: the title
  1272. --------------------------------------------------*/
  1273. echo "<tr>";
  1274. echo "<td class=\"".$style."\" colspan='2'>";
  1275. echo $myrow['title'];
  1276. echo "\n\t\t</td colspan='2'>\n\t</tr>\n";
  1277. /*--------------------------------------------------
  1278. display: the content
  1279. --------------------------------------------------*/
  1280. $content = $myrow['text'];
  1281. $content = make_clickable($content);
  1282. $content = text_filter($content);
  1283. echo "\t<tr>\n\t\t<td class=\"".$text_style."\" colspan='2'>";
  1284. echo $content;
  1285. echo "</td></tr>";
  1286. /*--------------------------------------------------
  1287. display: the edit / delete icons
  1288. --------------------------------------------------*/
  1289. echo "\t<tr>\n\t\t<td class=\"".$text_style."\" colspan='2'>";
  1290. echo "<a href=\"myagenda.php?action=edit_personal_agenda_item&amp;id=".$myrow['id']."\"><img src=\"../img/edit.gif\" border=\"0\" alt=\"".get_lang('Edit')."\" /></a>";
  1291. echo "<a href=\"".$_SERVER['PHP_SELF']."?action=delete&amp;id=".$myrow['id']."\" onclick=\"javascript:if(!confirm('".addslashes(htmlentities(get_lang('ConfirmYourChoice')))."')) return false;\"><img src=\"../img/delete.gif\" border=\"0\" alt=\"".get_lang('Delete')."\" /></a>";
  1292. echo "</td></tr>";
  1293. }
  1294. }
  1295. else
  1296. {
  1297. echo '<tr><td colspan="2">'.get_lang('NoAgendaItems').'</td></tr>';
  1298. }
  1299. echo "</table>\n";
  1300. }
  1301. /*============================================================================
  1302. delete_personal_agenda($id)
  1303. ============================================================================*/
  1304. // This function deletes a personal agenda item
  1305. // There is an additional check to make sure that one cannot delete an item that
  1306. // does not belong to him/her
  1307. function delete_personal_agenda($id)
  1308. {
  1309. global $TABLE_PERSONAL_AGENDA;
  1310. global $_uid;
  1311. if ($id <> '')
  1312. {
  1313. $sql = "SELECT * FROM ".$TABLE_PERSONAL_AGENDA." WHERE user='".$_uid."' AND id='".$id."'";
  1314. $result = api_sql_query($sql, __FILE__, __LINE__);
  1315. $aantal = mysql_num_rows($result);
  1316. if ($aantal <> 0)
  1317. {
  1318. $sql = "DELETE FROM ".$TABLE_PERSONAL_AGENDA." WHERE user='".$_uid."' AND id='".$id."'";
  1319. $result = api_sql_query($sql, __FILE__, __LINE__);
  1320. }
  1321. }
  1322. }
  1323. /*============================================================================
  1324. calculate_start_end_of_week($week_number, $year)
  1325. ============================================================================*/
  1326. // This function calculates the startdate of the week (monday)
  1327. // and the enddate of the week (sunday)
  1328. // and returns it as an array
  1329. function calculate_start_end_of_week($week_number, $year)
  1330. {
  1331. // determine the start and end date
  1332. // step 1: we calculate a timestamp for a day in this week
  1333. $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
  1334. // step 2: we which day this is (0=sunday, 1=monday, ...)
  1335. $number_day_in_week = date('w', $random_day_in_week);
  1336. // step 3: we calculate the timestamp of the monday of the week we are in
  1337. $start_timestamp = $random_day_in_week - (($number_day_in_week -1) * 24 * 60 * 60);
  1338. // step 4: we calculate the timestamp of the sunday of the week we are in
  1339. $end_timestamp = $random_day_in_week + ((7 - $number_day_in_week +1) * 24 * 60 * 60) - 3600;
  1340. // step 5: calculating the start_day, end_day, start_month, end_month, start_year, end_year
  1341. $start_day = date('j', $start_timestamp);
  1342. $start_month = date('n', $start_timestamp);
  1343. $start_year = date('Y', $start_timestamp);
  1344. $end_day = date('j', $end_timestamp);
  1345. $end_month = date('n', $end_timestamp);
  1346. $end_year = date('Y', $end_timestamp);
  1347. $start_end_array['start']['day'] = $start_day;
  1348. $start_end_array['start']['month'] = $start_month;
  1349. $start_end_array['start']['year'] = $start_year;
  1350. $start_end_array['end']['day'] = $end_day;
  1351. $start_end_array['end']['month'] = $end_month;
  1352. $start_end_array['end']['year'] = $end_year;
  1353. return $start_end_array;
  1354. }
  1355. ?>