myagenda.php 9.5 KB

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