myagenda.php 9.5 KB

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