agenda_js.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.calendar
  5. */
  6. /**
  7. * INIT SECTION
  8. */
  9. // name of the language file that needs to be included
  10. $language_file = array('agenda', 'group', 'announcements');
  11. // use anonymous mode when accessing this course tool
  12. $use_anonymous = true;
  13. //Calendar type
  14. $type = isset($_REQUEST['type']) && in_array($_REQUEST['type'], array('personal', 'course', 'admin')) ? $_REQUEST['type'] : 'personal';
  15. if ($type == 'personal') {
  16. $cidReset = true; // fixes #5162
  17. }
  18. require_once '../inc/global.inc.php';
  19. require_once 'agenda.lib.php';
  20. require_once 'agenda.inc.php';
  21. $current_course_tool = TOOL_CALENDAR_EVENT;
  22. $this_section = SECTION_MYAGENDA;
  23. $htmlHeadXtra[] = api_get_jquery_libraries_js(array('jquery-ui', 'jquery-ui-i18n'));
  24. $htmlHeadXtra[] = api_get_js('qtip2/jquery.qtip.min.js');
  25. $htmlHeadXtra[] = api_get_js('fullcalendar/fullcalendar.min.js');
  26. $htmlHeadXtra[] = api_get_js('fullcalendar/gcal.js');
  27. $htmlHeadXtra[] = api_get_css(api_get_path(WEB_LIBRARY_PATH).'javascript/fullcalendar/fullcalendar.css');
  28. $htmlHeadXtra[] = api_get_css(api_get_path(WEB_LIBRARY_PATH).'javascript/qtip2/jquery.qtip.min.css');
  29. if (api_is_platform_admin() && $type == 'admin') {
  30. $type = 'admin';
  31. }
  32. if (isset($_REQUEST['cidReq']) && !empty($_REQUEST['cidReq'])) {
  33. $type = 'course';
  34. }
  35. $is_group_tutor = false;
  36. $session_id = api_get_session_id();
  37. $group_id = api_get_group_id();
  38. if (!empty($group_id)) {
  39. $is_group_tutor = GroupManager::is_tutor_of_group(api_get_user_id(), $group_id);
  40. $group_properties = GroupManager :: get_group_properties($group_id);
  41. $interbreadcrumb[] = array("url" => "../group/group.php", "name" => get_lang('Groups'));
  42. $interbreadcrumb[] = array("url" => "../group/group_space.php?gidReq=".$group_id, "name" => get_lang('GroupSpace').' '.$group_properties['name']);
  43. }
  44. $tpl = new Template(get_lang('Agenda'));
  45. $tpl->assign('use_google_calendar', 0);
  46. $can_add_events = 0;
  47. switch ($type) {
  48. case 'admin':
  49. api_protect_admin_script();
  50. $this_section = SECTION_PLATFORM_ADMIN;
  51. if (api_is_platform_admin()) {
  52. $can_add_events = 1;
  53. }
  54. break;
  55. case 'course':
  56. api_protect_course_script();
  57. $this_section = SECTION_COURSES;
  58. if (api_is_allowed_to_edit()) {
  59. $can_add_events = 1;
  60. }
  61. if (!empty($group_id)) {
  62. if ($is_group_tutor) {
  63. $can_add_events = 1;
  64. }
  65. }
  66. break;
  67. case 'personal':
  68. if (api_is_anonymous()) {
  69. api_not_allowed(true);
  70. }
  71. $extra_field_data = UserManager::get_extra_user_data_by_field(api_get_user_id(), 'google_calendar_url');
  72. if (!empty($extra_field_data) && isset($extra_field_data['google_calendar_url']) && !empty($extra_field_data['google_calendar_url'])) {
  73. $tpl->assign('use_google_calendar', 1);
  74. $tpl->assign('google_calendar_url', $extra_field_data['google_calendar_url']);
  75. }
  76. $this_section = SECTION_MYAGENDA;
  77. if (!api_is_anonymous()) {
  78. $can_add_events = 1;
  79. }
  80. break;
  81. }
  82. //Setting translations
  83. $day_short = api_get_week_days_short();
  84. $days = api_get_week_days_long();
  85. $months = api_get_months_long();
  86. $months_short = api_get_months_short();
  87. //Setting calendar translations
  88. $tpl->assign('month_names', json_encode($months));
  89. $tpl->assign('month_names_short', json_encode($months_short));
  90. $tpl->assign('day_names', json_encode($days));
  91. $tpl->assign('day_names_short', json_encode($day_short));
  92. $tpl->assign('button_text',
  93. json_encode(array(
  94. 'today' => get_lang('Today'),
  95. 'month' => get_lang('Month'),
  96. 'week' => get_lang('Week'),
  97. 'day' => get_lang('Day')
  98. ))
  99. );
  100. //see http://docs.jquery.com/UI/Datepicker/$.datepicker.formatDate
  101. $tpl->assign('js_format_date', 'D d M yy');
  102. $region_value = api_get_language_isocode();
  103. if ($region_value == 'en') {
  104. $region_value = 'en-GB';
  105. }
  106. $tpl->assign('region_value', $region_value);
  107. $export_icon = '../img/export.png';
  108. $export_icon_low = '../img/export_low_fade.png';
  109. $export_icon_high = '../img/export_high_fade.png';
  110. $tpl->assign('export_ical_confidential_icon', Display::return_icon($export_icon_high, get_lang('ExportiCalConfidential')));
  111. $actions = null;
  112. if (api_is_allowed_to_edit(false, true) OR
  113. (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous()) && api_is_allowed_to_session_edit(false, true) OR
  114. $is_group_tutor
  115. ) {
  116. if ($type == 'course') {
  117. if (isset($_GET['user_id'])) {
  118. $filter = $_GET['user_id'];
  119. }
  120. $actions = display_courseadmin_links($filter);
  121. }
  122. } else {
  123. $actions = "<a href='agenda_list.php?type=course&".api_get_cidreq()."'>".Display::return_icon('week.png', get_lang('Agenda'), '', ICON_SIZE_MEDIUM)."</a>";
  124. }
  125. $tpl->assign('actions', $actions);
  126. //Calendar Type : course, admin, personal
  127. $tpl->assign('type', $type);
  128. $type_event_class = $type.'_event';
  129. $type_label = get_lang(ucfirst($type).'Calendar');
  130. if ($type == 'course' && !empty($group_id)) {
  131. $type_event_class = 'group_event';
  132. $type_label = get_lang('GroupCalendar');
  133. }
  134. $defaultView = api_get_setting('default_calendar_view');
  135. if (empty($defaultView)) {
  136. $defaultView = 'month';
  137. }
  138. /* month, basicWeek,agendaWeek,agendaDay */
  139. $tpl->assign('default_view', $defaultView);
  140. if ($type == 'course' && !empty($session_id)) {
  141. $type_event_class = 'session_event';
  142. $type_label = get_lang('SessionCalendar');
  143. }
  144. $tpl->assign('type_label', $type_label);
  145. $tpl->assign('type_event_class', $type_event_class);
  146. //Current user can add event?
  147. $tpl->assign('can_add_events', $can_add_events);
  148. //Setting AJAX caller
  149. if (isset($_GET['user_id'])) {
  150. $user_id = $_GET['user_id'];
  151. $agenda_ajax_url = api_get_path(WEB_AJAX_PATH).'agenda.ajax.php?user_id='.$user_id.'&type='.$type;
  152. } else {
  153. $agenda_ajax_url = api_get_path(WEB_AJAX_PATH).'agenda.ajax.php?type='.$type;
  154. }
  155. $tpl->assign('web_agenda_ajax_url', $agenda_ajax_url);
  156. $course_code = api_get_course_id();
  157. if ((api_is_allowed_to_edit() || $is_group_tutor) && $course_code != '-1' && $type == 'course') {
  158. $order = 'lastname';
  159. if (api_is_western_name_order()) {
  160. $order = 'firstname';
  161. }
  162. if (!empty($group_id)) {
  163. $group_list = array($group_id => $group_properties);
  164. $user_list = GroupManager::get_subscribed_users($group_id);
  165. } else {
  166. $user_list = CourseManager::get_user_list_from_course_code(api_get_course_id(), api_get_session_id(), null, $order);
  167. $group_list = CourseManager::get_group_list_of_course(api_get_course_id(), api_get_session_id());
  168. }
  169. $agenda = new Agenda();
  170. //This will fill the select called #users_to_send_id
  171. $select = $agenda->construct_not_selected_select_form($group_list, $user_list, array());
  172. $tpl->assign('visible_to', $select);
  173. }
  174. // Loading Agenda template
  175. $content = $tpl->fetch('default/agenda/month.tpl');
  176. $tpl->assign('content', $content);
  177. // Loading main Chamilo 1 col template
  178. $tpl->display_one_col_template();