myagenda.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. <?php //$Id: myagenda.php 21102 2009-05-30 14:58:16Z iflorespaz $
  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_once '../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. //remove this if cause it was showing in agenda general
  68. /*if(!empty($_GET['coursePath'])) {
  69. $course_path = api_htmlentities(strip_tags($_GET['coursePath']),ENT_QUOTES,$charset);
  70. $course_path = str_replace(array('../','..\\'),array('',''),$course_path);
  71. }
  72. */
  73. if (!empty ($course_path)) {
  74. $interbreadcrumb[] = array ('url' => api_get_path(WEB_COURSE_PATH).urlencode($course_path).'/index.php', 'name' => Security::remove_XSS($_GET['courseCode']));
  75. }
  76. // this loads the javascript that is needed for the date popup selection
  77. $htmlHeadXtra[] = "<script src=\"tbl_change.js\" type=\"text/javascript\" language=\"javascript\"></script>";
  78. // showing the header
  79. Display::display_header(get_lang('MyAgenda'));
  80. /* ==============================================================================
  81. SETTING SOME VARIABLES
  82. ============================================================================== */
  83. // setting the database variables
  84. $TABLECOURS = Database :: get_main_table(TABLE_MAIN_COURSE);
  85. $TABLECOURSUSER = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  86. $TABLEAGENDA = Database :: get_course_table(TABLE_AGENDA);
  87. $TABLE_ITEMPROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY);
  88. $tbl_personal_agenda = Database :: get_user_personal_table(TABLE_PERSONAL_AGENDA);
  89. // the variables for the days and the months
  90. // Defining the shorts for the days
  91. $DaysShort = api_get_week_days_short();
  92. // Defining the days of the week to allow translation of the days
  93. $DaysLong = api_get_week_days_long();
  94. // Defining the months of the year to allow translation of the months
  95. $MonthsLong = api_get_months_long();
  96. /*==============================================================================
  97. TREATING THE URL PARAMETERS
  98. 1. The default values
  99. 2. storing it in the session
  100. 3. possible view
  101. 3.a Month view
  102. 3.b Week view
  103. 3.c day view
  104. 3.d personal view (only the personal agenda items)
  105. 4. add personal agenda
  106. 5. edit personal agenda
  107. 6. delete personal agenda
  108. ============================================================================== */
  109. // 1. The default values. if there is no session yet, we have by default the month view
  110. if (empty($_SESSION['view']))
  111. {
  112. $_SESSION['view'] = "month";
  113. }
  114. // 2. Storing it in the session. If we change the view by clicking on the links left, we change the session
  115. if (!empty($_GET['view'])) {
  116. $_SESSION['view'] = Security::remove_XSS($_GET['view']);
  117. }
  118. // 3. The views: (month, week, day, personal)
  119. if ($_SESSION['view'])
  120. {
  121. switch ($_SESSION['view'])
  122. {
  123. // 3.a Month view
  124. case "month" :
  125. $process = "month_view";
  126. break;
  127. // 3.a Week view
  128. case "week" :
  129. $process = "week_view";
  130. break;
  131. // 3.a Day view
  132. case "day" :
  133. $process = "day_view";
  134. break;
  135. // 3.a Personal view
  136. case "personal" :
  137. $process = "personal_view";
  138. break;
  139. }
  140. }
  141. // 4. add personal agenda
  142. if (!empty($_GET['action']) && $_GET['action'] == "add_personal_agenda_item" and !$_POST['Submit'])
  143. {
  144. $process = "add_personal_agenda_item";
  145. }
  146. if (!empty($_GET['action']) && $_GET['action'] == "add_personal_agenda_item" and $_POST['Submit'])
  147. {
  148. $process = "store_personal_agenda_item";
  149. }
  150. // 5. edit personal agenda
  151. if (!empty($_GET['action']) && $_GET['action'] == "edit_personal_agenda_item" and !$_POST['Submit'])
  152. {
  153. $process = "edit_personal_agenda_item";
  154. }
  155. if (!empty($_GET['action']) && $_GET['action'] == "edit_personal_agenda_item" and $_POST['Submit'])
  156. {
  157. $process = "store_personal_agenda_item";
  158. }
  159. // 6. delete personal agenda
  160. if (!empty($_GET['action']) && $_GET['action'] == "delete" AND $_GET['id'])
  161. {
  162. $process = "delete_personal_agenda_item";
  163. }
  164. /* ==============================================================================
  165. OUTPUT
  166. ============================================================================== */
  167. if (isset ($_user['user_id']))
  168. {
  169. // getting all the courses that this user is subscribed to
  170. $courses_dbs = get_all_courses_of_user();
  171. if (!is_array($courses_dbs)) // this is for the special case if the user has no courses (otherwise you get an error)
  172. {
  173. $courses_dbs = array ();
  174. }
  175. // setting and/or getting the year, month, day, week
  176. $today = getdate();
  177. $year = (!empty($_GET['year'])? (int)$_GET['year'] : NULL);
  178. if ($year == NULL)
  179. {
  180. $year = $today['year'];
  181. }
  182. $month = (!empty($_GET['month'])? (int)$_GET['month']:NULL);
  183. if ($month == NULL)
  184. {
  185. $month = $today['mon'];
  186. }
  187. $day = (!empty($_GET['day']) ? (int)$_GET['day']:NULL);
  188. if ($day == NULL)
  189. {
  190. $day = $today['mday'];
  191. }
  192. $week = (!empty($_GET['week']) ?(int)$_GET['week']:NULL);
  193. if ($week == NULL)
  194. {
  195. $week = date("W");
  196. }
  197. // The name of the current Month
  198. $monthName = $MonthsLong[$month -1];
  199. // Starting the output
  200. echo "\n<div class=\"actions\">\n";
  201. 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";
  202. 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";
  203. 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";
  204. if (api_get_setting('allow_personal_agenda') == 'true')
  205. {
  206. 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";
  207. 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";
  208. }
  209. echo "</div>\n\n";
  210. echo "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
  211. echo "<tr>";
  212. // output: the small calendar item on the left and the view / add links
  213. echo "<td width=\"220\" valign=\"top\">";
  214. $agendaitems = get_myagendaitems($courses_dbs, $month, $year);
  215. $agendaitems = get_global_agenda_items($agendaitems, $day, $month, $year, $week, "month_view");
  216. if (api_get_setting('allow_personal_agenda') == 'true')
  217. {
  218. $agendaitems = get_personal_agenda_items($agendaitems, $day, $month, $year, $week, "month_view");
  219. }
  220. display_myminimonthcalendar($agendaitems, $month, $year, $monthName);
  221. echo "</td>";
  222. // the divider
  223. // 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>";
  224. echo "<td width=\"20\">&nbsp;</td>";
  225. // the main area: day, week, month view
  226. echo "<td valign=\"top\">";
  227. switch ($process)
  228. {
  229. case "month_view" :
  230. $agendaitems = get_myagendaitems($courses_dbs, $month, $year);
  231. $agendaitems = get_global_agenda_items($agendaitems, $day, $month, $year, $week, "month_view");
  232. if (api_get_setting("allow_personal_agenda") == "true")
  233. {
  234. $agendaitems = get_personal_agenda_items($agendaitems, $day, $month, $year, $week, "month_view");
  235. }
  236. display_mymonthcalendar($agendaitems, $month, $year, array(), $monthName);
  237. break;
  238. case "week_view" :
  239. $agendaitems = get_week_agendaitems($courses_dbs, $month, $year, $week);
  240. $agendaitems = get_global_agenda_items($agendaitems, $day, $month, $year, $week, "week_view");
  241. if (api_get_setting("allow_personal_agenda") == "true")
  242. {
  243. $agendaitems = get_personal_agenda_items($agendaitems, $day, $month, $year, $week, "week_view");
  244. }
  245. display_weekcalendar($agendaitems, $month, $year, array(), $monthName);
  246. break;
  247. case "day_view" :
  248. $agendaitems = get_day_agendaitems($courses_dbs, $month, $year, $day);
  249. $agendaitems = get_global_agenda_items($agendaitems, $day, $month, $year, $week, "day_view");
  250. if (api_get_setting("allow_personal_agenda") == "true")
  251. {
  252. $agendaitems = get_personal_agenda_items($agendaitems, $day, $month, $year, $week, "day_view");
  253. }
  254. display_daycalendar($agendaitems, $day, $month, $year, array(), $monthName);
  255. break;
  256. case "personal_view" :
  257. show_personal_agenda();
  258. break;
  259. case "add_personal_agenda_item" :
  260. show_new_personal_item_form();
  261. break;
  262. case "store_personal_agenda_item" :
  263. 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']);
  264. if ($_GET['id'])
  265. {
  266. echo '<br />';
  267. Display :: display_normal_message(get_lang("PeronalAgendaItemEdited"));
  268. }
  269. else
  270. {
  271. echo '<br />';
  272. Display :: display_normal_message(get_lang("PeronalAgendaItemAdded"));
  273. }
  274. show_personal_agenda();
  275. break;
  276. case "edit_personal_agenda_item" :
  277. show_new_personal_item_form((int)$_GET['id']);
  278. break;
  279. case "delete_personal_agenda_item" :
  280. delete_personal_agenda((int)$_GET['id']);
  281. echo '<br />';
  282. Display :: display_normal_message(get_lang('PeronalAgendaItemDeleted'));
  283. show_personal_agenda();
  284. break;
  285. }
  286. }
  287. echo "</td></tr></table>";
  288. Display :: display_footer();
  289. ?>