myagenda.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. <?php //$Id: myagenda.php 20444 2009-05-10 09:18:51Z ivantcholakov $
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004-2008 Dokeos SPRL
  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, rue du Corbeau, 108, B-1030 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.3 : Yannick Warnier, yannick.warnier@dokeos.com 2008
  26. Added repeated events
  27. -> version 2.2 : Patrick Cool, patrick.cool@ugent.be, november 2004
  28. Personal Agenda added. The user can add personal agenda items. The items
  29. are stored in a dokeos_user database because it is not course or platform
  30. based. A personal agenda view was also added. This lists all the personal
  31. agenda items of that user.
  32. -> version 2.1 : Patrick Cool, patrick.cool@ugent.be, , oktober 2004
  33. This is the version that works with the Group based Agenda tool.
  34. -> version 2.0 (alpha): Patrick Cool, patrick.cool@ugent.be, , oktober 2004
  35. The 2.0 version introduces besides the month view also a week- and day view.
  36. In the 2.5 (final) version it will be possible for the student to add his/her
  37. own agenda items. The platform administrator can however decide if the students
  38. are allowed to do this or not.
  39. The alpha version only contains the three views. The personal agenda feature is
  40. not yet completely finished. There are however already some parts of the code
  41. for adding a personal agenda item present.
  42. this code was not released in an official dokeos but was only used in the offical
  43. server of the Ghent University where it underwent serious testing
  44. -> version 1.5: Toon Van Hoecke, toon.vanhoecke@ugent.be, december 2003
  45. -> version 1.0: Eric Remy, eremy@rmwc.edu, 6 Oct 2003
  46. The tool was initially called master-calendar as it collects all the calendar
  47. items of all the courses one is subscribed to. It was very soon integrated in
  48. Dokeos as this was a really basic and very usefull tool.
  49. /* ==============================================================================
  50. HEADER
  51. ============================================================================== */
  52. // name of the language file that needs to be included
  53. $language_file = 'agenda';
  54. // we are not inside a course, so we reset the course id
  55. $cidReset = true;
  56. // setting the global file that gets the general configuration, the databases, the languages, ...
  57. require('../inc/global.inc.php');
  58. $this_section = SECTION_MYAGENDA;
  59. api_block_anonymous_users();
  60. require_once(api_get_path(LIBRARY_PATH).'groupmanager.lib.php');
  61. require_once('agenda.inc.php');
  62. require_once('myagenda.inc.php');
  63. // setting the name of the tool
  64. $nameTools = get_lang('MyAgenda');
  65. // if we come from inside a course and click on the 'My Agenda' link we show a link back to the course
  66. // in the breadcrumbs
  67. if(!empty($_GET['coursePath'])) {
  68. $course_path = api_htmlentities(strip_tags($_GET['coursePath']),ENT_QUOTES,$charset);
  69. $course_path = str_replace(array('../','..\\'),array('',''),$course_path);
  70. }
  71. if (!empty ($course_path)) {
  72. $interbreadcrumb[] = array ('url' => api_get_path(WEB_COURSE_PATH).urlencode($course_path).'/index.php', 'name' => Security::remove_XSS($_GET['courseCode']));
  73. }
  74. // this loads the javascript that is needed for the date popup selection
  75. $htmlHeadXtra[] = "<script src=\"tbl_change.js\" type=\"text/javascript\" language=\"javascript\"></script>";
  76. // showing the header
  77. Display::display_header(get_lang('MyAgenda'));
  78. /* ==============================================================================
  79. SETTING SOME VARIABLES
  80. ============================================================================== */
  81. // setting the database variables
  82. $TABLECOURS = Database :: get_main_table(TABLE_MAIN_COURSE);
  83. $TABLECOURSUSER = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  84. $TABLEAGENDA = Database :: get_course_table(TABLE_AGENDA);
  85. $TABLE_ITEMPROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY);
  86. $tbl_personal_agenda = Database :: get_user_personal_table(TABLE_PERSONAL_AGENDA);
  87. // the variables for the days and the months
  88. // Defining the shorts for the days
  89. $DaysShort = array (get_lang("SundayShort"), get_lang("MondayShort"), get_lang("TuesdayShort"), get_lang("WednesdayShort"), get_lang("ThursdayShort"), get_lang("FridayShort"), get_lang("SaturdayShort"));
  90. // Defining the days of the week to allow translation of the days
  91. $DaysLong = array (get_lang("SundayLong"), get_lang("MondayLong"), get_lang("TuesdayLong"), get_lang("WednesdayLong"), get_lang("ThursdayLong"), get_lang("FridayLong"), get_lang("SaturdayLong"));
  92. // Defining the months of the year to allow translation of the months
  93. $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"));
  94. /*==============================================================================
  95. TREATING THE URL PARAMETERS
  96. 1. The default values
  97. 2. storing it in the session
  98. 3. possible view
  99. 3.a Month view
  100. 3.b Week view
  101. 3.c day view
  102. 3.d personal view (only the personal agenda items)
  103. 4. add personal agenda
  104. 5. edit personal agenda
  105. 6. delete personal agenda
  106. ============================================================================== */
  107. // 1. The default values. if there is no session yet, we have by default the month view
  108. if (empty($_SESSION['view']))
  109. {
  110. $_SESSION['view'] = "month";
  111. }
  112. // 2. Storing it in the session. If we change the view by clicking on the links left, we change the session
  113. if (!empty($_GET['view'])) {
  114. $_SESSION['view'] = Security::remove_XSS($_GET['view']);
  115. }
  116. // 3. The views: (month, week, day, personal)
  117. if ($_SESSION['view'])
  118. {
  119. switch ($_SESSION['view'])
  120. {
  121. // 3.a Month view
  122. case "month" :
  123. $process = "month_view";
  124. break;
  125. // 3.a Week view
  126. case "week" :
  127. $process = "week_view";
  128. break;
  129. // 3.a Day view
  130. case "day" :
  131. $process = "day_view";
  132. break;
  133. // 3.a Personal view
  134. case "personal" :
  135. $process = "personal_view";
  136. break;
  137. }
  138. }
  139. // 4. add personal agenda
  140. if (!empty($_GET['action']) && $_GET['action'] == "add_personal_agenda_item" and !$_POST['Submit'])
  141. {
  142. $process = "add_personal_agenda_item";
  143. }
  144. if (!empty($_GET['action']) && $_GET['action'] == "add_personal_agenda_item" and $_POST['Submit'])
  145. {
  146. $process = "store_personal_agenda_item";
  147. }
  148. // 5. edit personal agenda
  149. if (!empty($_GET['action']) && $_GET['action'] == "edit_personal_agenda_item" and !$_POST['Submit'])
  150. {
  151. $process = "edit_personal_agenda_item";
  152. }
  153. if (!empty($_GET['action']) && $_GET['action'] == "edit_personal_agenda_item" and $_POST['Submit'])
  154. {
  155. $process = "store_personal_agenda_item";
  156. }
  157. // 6. delete personal agenda
  158. if (!empty($_GET['action']) && $_GET['action'] == "delete" AND $_GET['id'])
  159. {
  160. $process = "delete_personal_agenda_item";
  161. }
  162. /* ==============================================================================
  163. OUTPUT
  164. ============================================================================== */
  165. if (isset ($_user['user_id']))
  166. {
  167. // getting all the courses that this user is subscribed to
  168. $courses_dbs = get_all_courses_of_user();
  169. if (!is_array($courses_dbs)) // this is for the special case if the user has no courses (otherwise you get an error)
  170. {
  171. $courses_dbs = array ();
  172. }
  173. // setting and/or getting the year, month, day, week
  174. $today = getdate();
  175. $year = (!empty($_GET['year'])? (int)$_GET['year'] : NULL);
  176. if ($year == NULL)
  177. {
  178. $year = $today['year'];
  179. }
  180. $month = (!empty($_GET['month'])? (int)$_GET['month']:NULL);
  181. if ($month == NULL)
  182. {
  183. $month = $today['mon'];
  184. }
  185. $day = (!empty($_GET['day']) ? (int)$_GET['day']:NULL);
  186. if ($day == NULL)
  187. {
  188. $day = $today['mday'];
  189. }
  190. $week = (!empty($_GET['week']) ?(int)$_GET['week']:NULL);
  191. if ($week == NULL)
  192. {
  193. $week = date("W");
  194. }
  195. // The name of the current Month
  196. $monthName = $MonthsLong[$month -1];
  197. // Starting the output
  198. echo "\n<div class=\"actions\">\n";
  199. echo "\t<a href=\"".api_get_self()."?action=view&amp;view=month\">".Display::return_icon('calendar_month.gif', get_lang('MonthView'))." ".get_lang('MonthView')."</a> \n";
  200. echo "\t<a href=\"".api_get_self()."?action=view&amp;view=week\">".Display::return_icon('calendar_week.gif', get_lang('WeekView'))." ".get_lang('WeekView')."</a> \n";
  201. echo "\t<a href=\"".api_get_self()."?action=view&amp;view=day\">".Display::return_icon('calendar_day.gif', get_lang('DayView'))." ".get_lang('DayView')."</a> \n";
  202. if (get_setting('allow_personal_agenda') == 'true')
  203. {
  204. echo "\t<a href=\"".api_get_self()."?action=add_personal_agenda_item\">".Display::return_icon('calendar_personal_add.gif', get_lang('AddPersonalItem'))." ".get_lang('AddPersonalItem')."</a> \n";
  205. echo "\t<a href=\"".api_get_self()."?action=view&amp;view=personal\">".Display::return_icon('calendar_personal.gif', get_lang('ViewPersonalItem'))." ".get_lang('ViewPersonalItem')."</a> \n";
  206. }
  207. echo "</div>\n\n";
  208. echo "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
  209. echo "<tr>";
  210. // output: the small calendar item on the left and the view / add links
  211. echo "<td width=\"220\" valign=\"top\">";
  212. $agendaitems = get_myagendaitems($courses_dbs, $month, $year);
  213. $agendaitems = get_global_agenda_items($agendaitems, $day, $month, $year, $week, "month_view");
  214. if (get_setting('allow_personal_agenda') == 'true')
  215. {
  216. $agendaitems = get_personal_agenda_items($agendaitems, $day, $month, $year, $week, "month_view");
  217. }
  218. display_myminimonthcalendar($agendaitems, $month, $year, $monthName);
  219. echo "</td>";
  220. // the divider
  221. // 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>";
  222. echo "<td width=\"20\">&nbsp;</td>";
  223. // the main area: day, week, month view
  224. echo "<td valign=\"top\">";
  225. switch ($process)
  226. {
  227. case "month_view" :
  228. $agendaitems = get_myagendaitems($courses_dbs, $month, $year);
  229. $agendaitems = get_global_agenda_items($agendaitems, $day, $month, $year, $week, "month_view");
  230. if (get_setting("allow_personal_agenda") == "true")
  231. {
  232. $agendaitems = get_personal_agenda_items($agendaitems, $day, $month, $year, $week, "month_view");
  233. }
  234. display_mymonthcalendar($agendaitems, $month, $year, array(), $monthName);
  235. break;
  236. case "week_view" :
  237. $agendaitems = get_week_agendaitems($courses_dbs, $month, $year, $week);
  238. $agendaitems = get_global_agenda_items($agendaitems, $day, $month, $year, $week, "week_view");
  239. if (get_setting("allow_personal_agenda") == "true")
  240. {
  241. $agendaitems = get_personal_agenda_items($agendaitems, $day, $month, $year, $week, "week_view");
  242. }
  243. display_weekcalendar($agendaitems, $month, $year, array(), $monthName);
  244. break;
  245. case "day_view" :
  246. $agendaitems = get_day_agendaitems($courses_dbs, $month, $year, $day);
  247. $agendaitems = get_global_agenda_items($agendaitems, $day, $month, $year, $week, "day_view");
  248. if (get_setting("allow_personal_agenda") == "true")
  249. {
  250. $agendaitems = get_personal_agenda_items($agendaitems, $day, $month, $year, $week, "day_view");
  251. }
  252. display_daycalendar($agendaitems, $day, $month, $year, array(), $monthName);
  253. break;
  254. case "personal_view" :
  255. show_personal_agenda();
  256. break;
  257. case "add_personal_agenda_item" :
  258. show_new_personal_item_form();
  259. break;
  260. case "store_personal_agenda_item" :
  261. 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']);
  262. if ($_GET['id'])
  263. {
  264. echo '<br />';
  265. Display :: display_normal_message(get_lang("PeronalAgendaItemEdited"));
  266. }
  267. else
  268. {
  269. echo '<br />';
  270. Display :: display_normal_message(get_lang("PeronalAgendaItemAdded"));
  271. }
  272. show_personal_agenda();
  273. break;
  274. case "edit_personal_agenda_item" :
  275. show_new_personal_item_form((int)$_GET['id']);
  276. break;
  277. case "delete_personal_agenda_item" :
  278. delete_personal_agenda((int)$_GET['id']);
  279. echo '<br />';
  280. Display :: display_normal_message(get_lang('PeronalAgendaItemDeleted'));
  281. show_personal_agenda();
  282. break;
  283. }
  284. }
  285. echo "</td></tr></table>";
  286. Display :: display_footer();
  287. ?>