myagenda.php 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. // name of the language file that needs to be included
  4. $language_file = 'agenda';
  5. // we are not inside a course, so we reset the course id
  6. $cidReset = true;
  7. // setting the global file that gets the general configuration, the databases, the languages, ...
  8. require_once '../inc/global.inc.php';
  9. $this_section = SECTION_MYAGENDA;
  10. unset($_SESSION['this_section']);//for hmtl editor repository
  11. api_block_anonymous_users();
  12. require_once api_get_path(LIBRARY_PATH).'groupmanager.lib.php';
  13. require_once 'agenda.inc.php';
  14. require_once 'myagenda.inc.php';
  15. // setting the name of the tool
  16. $nameTools = get_lang('MyAgenda');
  17. // if we come from inside a course and click on the 'My Agenda' link we show a link back to the course
  18. // in the breadcrumbs
  19. //remove this if cause it was showing in agenda general
  20. /*if(!empty($_GET['coursePath'])) {
  21. $course_path = api_htmlentities(strip_tags($_GET['coursePath']),ENT_QUOTES,$charset);
  22. $course_path = str_replace(array('../','..\\'),array('',''),$course_path);
  23. }
  24. */
  25. if (!empty ($course_path)) {
  26. $interbreadcrumb[] = array ('url' => api_get_path(WEB_COURSE_PATH).urlencode($course_path).'/index.php', 'name' => Security::remove_XSS($_GET['courseCode']));
  27. }
  28. // this loads the javascript that is needed for the date popup selection
  29. $htmlHeadXtra[] = "<script src=\"tbl_change.js\" type=\"text/javascript\" language=\"javascript\"></script>";
  30. // showing the header
  31. Display::display_header(get_lang('MyAgenda'));
  32. // SETTING SOME VARIABLES
  33. // setting the database variables
  34. $TABLECOURS = Database :: get_main_table(TABLE_MAIN_COURSE);
  35. $TABLECOURSUSER = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  36. $TABLEAGENDA = Database :: get_course_table(TABLE_AGENDA);
  37. $TABLE_ITEMPROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY);
  38. $tbl_personal_agenda= Database :: get_user_personal_table(TABLE_PERSONAL_AGENDA);
  39. // the variables for the days and the months
  40. // Defining the shorts for the days
  41. $DaysShort = api_get_week_days_short();
  42. // Defining the days of the week to allow translation of the days
  43. $DaysLong = api_get_week_days_long();
  44. // Defining the months of the year to allow translation of the months
  45. $MonthsLong = api_get_months_long();
  46. /*
  47. TREATING THE URL PARAMETERS
  48. 1. The default values
  49. 2. storing it in the session
  50. 3. possible view
  51. 3.a Month view
  52. 3.b Week view
  53. 3.c day view
  54. 3.d personal view (only the personal agenda items)
  55. 4. add personal agenda
  56. 5. edit personal agenda
  57. 6. delete personal agenda
  58. */
  59. // 1. The default values. if there is no session yet, we have by default the month view
  60. if (empty($_SESSION['view'])) {
  61. $_SESSION['view'] = 'month';
  62. }
  63. // 2. Storing it in the session. If we change the view by clicking on the links left, we change the session
  64. if (!empty($_GET['view'])) {
  65. $_SESSION['view'] = Security::remove_XSS($_GET['view']);
  66. }
  67. // 3. The views: (month, week, day, personal)
  68. if ($_SESSION['view']) {
  69. switch ($_SESSION['view']) {
  70. // 3.a Month view
  71. case "month" :
  72. $process = 'month_view';
  73. break;
  74. // 3.a Week view
  75. case "week" :
  76. $process = 'week_view';
  77. break;
  78. // 3.a Day view
  79. case "day" :
  80. $process = 'day_view';
  81. break;
  82. // 3.a Personal view
  83. case "personal" :
  84. $process = 'personal_view';
  85. break;
  86. }
  87. }
  88. // 4. add personal agenda
  89. if (!empty($_GET['action']) && $_GET['action'] == 'add_personal_agenda_item' and !$_POST['Submit']) {
  90. $process = "add_personal_agenda_item";
  91. }
  92. if (!empty($_GET['action']) && $_GET['action'] == "add_personal_agenda_item" and $_POST['Submit']) {
  93. $process = "store_personal_agenda_item";
  94. }
  95. // 5. edit personal agenda
  96. if (!empty($_GET['action']) && $_GET['action'] == 'edit_personal_agenda_item' and !$_POST['Submit']) {
  97. $process = "edit_personal_agenda_item";
  98. }
  99. if (!empty($_GET['action']) && $_GET['action'] == 'edit_personal_agenda_item' and $_POST['Submit']) {
  100. $process = "store_personal_agenda_item";
  101. }
  102. // 6. delete personal agenda
  103. if (!empty($_GET['action']) && $_GET['action'] == "delete" AND $_GET['id']) {
  104. $process = "delete_personal_agenda_item";
  105. }
  106. // OUTPUT
  107. if (isset ($_user['user_id'])) {
  108. // getting all the courses that this user is subscribed to
  109. $courses_dbs = get_all_courses_of_user();
  110. if (!is_array($courses_dbs)) {
  111. // this is for the special case if the user has no courses (otherwise you get an error)
  112. $courses_dbs = array ();
  113. }
  114. // setting and/or getting the year, month, day, week
  115. $today = getdate();
  116. $year = (!empty($_GET['year'])? (int)$_GET['year'] : NULL);
  117. if ($year == NULL)
  118. {
  119. $year = $today['year'];
  120. }
  121. $month = (!empty($_GET['month'])? (int)$_GET['month']:NULL);
  122. if ($month == NULL) {
  123. $month = $today['mon'];
  124. }
  125. $day = (!empty($_GET['day']) ? (int)$_GET['day']:NULL);
  126. if ($day == NULL) {
  127. $day = $today['mday'];
  128. }
  129. $week = (!empty($_GET['week']) ?(int)$_GET['week']:NULL);
  130. if ($week == NULL) {
  131. $week = date("W");
  132. }
  133. // The name of the current Month
  134. $monthName = $MonthsLong[$month -1];
  135. // Starting the output
  136. echo "<div class=\"actions\">";
  137. echo "<a href=\"".api_get_self()."?action=view&amp;view=month\">".Display::return_icon('calendar_month.gif', get_lang('MonthView'))." ".get_lang('MonthView')."</a> ";
  138. echo "<a href=\"".api_get_self()."?action=view&amp;view=week\">".Display::return_icon('calendar_week.gif', get_lang('WeekView'))." ".get_lang('WeekView')."</a> ";
  139. echo "<a href=\"".api_get_self()."?action=view&amp;view=day\">".Display::return_icon('calendar_day.gif', get_lang('DayView'))." ".get_lang('DayView')."</a> ";
  140. if (api_get_setting('allow_personal_agenda') == 'true')
  141. {
  142. echo "<a href=\"".api_get_self()."?action=add_personal_agenda_item\">".Display::return_icon('calendar_personal_add.gif', get_lang('AddPersonalItem'))." ".get_lang('AddPersonalItem')."</a> ";
  143. echo "<a href=\"".api_get_self()."?action=view&amp;view=personal\">".Display::return_icon('calendar_personal.gif', get_lang('ViewPersonalItem'))." ".get_lang('ViewPersonalItem')."</a> ";
  144. }
  145. echo "</div>";
  146. echo "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
  147. echo "<tr>";
  148. // output: the small calendar item on the left and the view / add links
  149. echo "<td width=\"220\" valign=\"top\">";
  150. $agendaitems = get_myagendaitems($courses_dbs, $month, $year);
  151. $agendaitems = get_global_agenda_items($agendaitems, $day, $month, $year, $week, "month_view");
  152. if (api_get_setting('allow_personal_agenda') == 'true') {
  153. $agendaitems = get_personal_agenda_items($agendaitems, $day, $month, $year, $week, "month_view");
  154. }
  155. display_myminimonthcalendar($agendaitems, $month, $year, $monthName);
  156. echo "</td>";
  157. // the divider
  158. // 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>";
  159. echo "<td width=\"20\">&nbsp;</td>";
  160. // the main area: day, week, month view
  161. echo "<td valign=\"top\">";
  162. switch ($process) {
  163. case 'month_view' :
  164. $agendaitems = get_myagendaitems($courses_dbs, $month, $year);
  165. $agendaitems = get_global_agenda_items($agendaitems, $day, $month, $year, $week, "month_view");
  166. if (api_get_setting("allow_personal_agenda") == "true")
  167. {
  168. $agendaitems = get_personal_agenda_items($agendaitems, $day, $month, $year, $week, "month_view");
  169. }
  170. display_mymonthcalendar($agendaitems, $month, $year, array(), $monthName);
  171. break;
  172. case 'week_view' :
  173. $agendaitems = get_week_agendaitems($courses_dbs, $month, $year, $week);
  174. $agendaitems = get_global_agenda_items($agendaitems, $day, $month, $year, $week, "week_view");
  175. if (api_get_setting("allow_personal_agenda") == "true") {
  176. $agendaitems = get_personal_agenda_items($agendaitems, $day, $month, $year, $week, "week_view");
  177. }
  178. display_weekcalendar($agendaitems, $month, $year, array(), $monthName);
  179. break;
  180. case 'day_view' :
  181. $agendaitems = get_day_agendaitems($courses_dbs, $month, $year, $day);
  182. $agendaitems = get_global_agenda_items($agendaitems, $day, $month, $year, $week, "day_view");
  183. if (api_get_setting('allow_personal_agenda') == 'true') {
  184. $agendaitems = get_personal_agenda_items($agendaitems, $day, $month, $year, $week, "day_view");
  185. }
  186. display_daycalendar($agendaitems, $day, $month, $year, array(), $monthName);
  187. break;
  188. case 'personal_view' :
  189. show_personal_agenda();
  190. break;
  191. case 'add_personal_agenda_item' :
  192. show_new_personal_item_form();
  193. break;
  194. case 'store_personal_agenda_item' :
  195. 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']);
  196. if ($_GET['id']) {
  197. echo '<br />';
  198. Display :: display_normal_message(get_lang("PeronalAgendaItemEdited"));
  199. } else {
  200. echo '<br />';
  201. Display :: display_normal_message(get_lang("PeronalAgendaItemAdded"));
  202. }
  203. show_personal_agenda();
  204. break;
  205. case 'edit_personal_agenda_item' :
  206. show_new_personal_item_form((int)$_GET['id']);
  207. break;
  208. case 'delete_personal_agenda_item' :
  209. delete_personal_agenda((int)$_GET['id']);
  210. echo '<br />';
  211. Display :: display_normal_message(get_lang('PeronalAgendaItemDeleted'));
  212. show_personal_agenda();
  213. break;
  214. }
  215. }
  216. echo '</td></tr></table>';
  217. Display :: display_footer();
  218. ?>