agenda_js.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.calendar
  5. */
  6. use ChamiloSession as Session;
  7. // use anonymous mode when accessing this course tool
  8. $use_anonymous = true;
  9. // Calendar type
  10. $type = isset($_REQUEST['type']) && in_array($_REQUEST['type'], array('personal', 'course', 'admin', 'platform')) ? $_REQUEST['type'] : 'personal';
  11. $userId = isset($_REQUEST['user_id']) ? $_REQUEST['user_id'] : null;
  12. if ($type == 'personal') {
  13. $cidReset = true; // fixes #5162
  14. }
  15. require_once '../inc/global.inc.php';
  16. $current_course_tool = TOOL_CALENDAR_EVENT;
  17. $this_section = SECTION_MYAGENDA;
  18. $htmlHeadXtra[] = api_get_jquery_libraries_js(array('jquery-ui', 'jquery-ui-i18n'));
  19. $htmlHeadXtra[] = api_get_js('qtip2/jquery.qtip.min.js');
  20. $htmlHeadXtra[] = api_get_asset('fullcalendar/dist/fullcalendar.min.js');
  21. $htmlHeadXtra[] = api_get_asset('fullcalendar/dist/gcal.js');
  22. $htmlHeadXtra[] = api_get_css(api_get_path(WEB_PATH).'web/assets/fullcalendar/dist/fullcalendar.min.css');
  23. $htmlHeadXtra[] = api_get_css(api_get_path(WEB_LIBRARY_PATH).'javascript/qtip2/jquery.qtip.min.css');
  24. if (api_is_platform_admin() && ($type == 'admin' || $type == 'platform')) {
  25. $type = 'admin';
  26. }
  27. if (isset($_REQUEST['cidReq']) && !empty($_REQUEST['cidReq'])) {
  28. if ($_REQUEST['cidReq'] == -1) {
  29. // When is out of the course tool (e.g My agenda)
  30. header('Location: ' . api_get_self());
  31. exit;
  32. } else {
  33. $type = 'course';
  34. $this_section = SECTION_COURSES;
  35. }
  36. }
  37. api_protect_course_group(GroupManager::GROUP_TOOL_CALENDAR);
  38. $agenda = new Agenda();
  39. $agenda->type = $type;
  40. $is_group_tutor = false;
  41. $session_id = api_get_session_id();
  42. $group_id = api_get_group_id();
  43. if (!empty($group_id)) {
  44. $is_group_tutor = GroupManager::is_tutor_of_group(api_get_user_id(), $group_id);
  45. $group_properties = GroupManager::get_group_properties($group_id);
  46. $interbreadcrumb[] = array(
  47. "url" => api_get_path(WEB_CODE_PATH)."group/group.php?".api_get_cidreq(),
  48. "name" => get_lang('Groups')
  49. );
  50. $interbreadcrumb[] = array(
  51. "url" => api_get_path(WEB_CODE_PATH)."group/group_space.php?".api_get_cidreq(),
  52. "name" => get_lang('GroupSpace').' '.$group_properties['name']
  53. );
  54. }
  55. $tpl = new Template(get_lang('Agenda'));
  56. $tpl->assign('use_google_calendar', 0);
  57. $can_add_events = 0;
  58. switch ($type) {
  59. case 'admin':
  60. api_protect_admin_script();
  61. $this_section = SECTION_PLATFORM_ADMIN;
  62. if (api_is_platform_admin()) {
  63. $can_add_events = 1;
  64. }
  65. break;
  66. case 'course':
  67. api_protect_course_script(true);
  68. $this_section = SECTION_COURSES;
  69. if (api_is_allowed_to_edit()) {
  70. $can_add_events = 1;
  71. }
  72. if (!empty($group_id)) {
  73. if ($is_group_tutor) {
  74. $can_add_events = 1;
  75. }
  76. }
  77. break;
  78. case 'personal':
  79. if (api_is_anonymous()) {
  80. api_not_allowed(true);
  81. }
  82. $extra_field_data = UserManager::get_extra_user_data_by_field(
  83. api_get_user_id(),
  84. 'google_calendar_url'
  85. );
  86. if (!empty($extra_field_data) &&
  87. isset($extra_field_data['google_calendar_url']) &&
  88. !empty($extra_field_data['google_calendar_url'])
  89. ) {
  90. $tpl->assign('use_google_calendar', 1);
  91. $tpl->assign('google_calendar_url', $extra_field_data['google_calendar_url']);
  92. }
  93. $this_section = SECTION_MYAGENDA;
  94. if (!api_is_anonymous()) {
  95. $can_add_events = 1;
  96. }
  97. break;
  98. }
  99. //Setting translations
  100. $day_short = api_get_week_days_short();
  101. $days = api_get_week_days_long();
  102. $months = api_get_months_long();
  103. $months_short = api_get_months_short();
  104. //Setting calendar translations
  105. $tpl->assign('month_names', json_encode($months));
  106. $tpl->assign('month_names_short', json_encode($months_short));
  107. $tpl->assign('day_names', json_encode($days));
  108. $tpl->assign('day_names_short', json_encode($day_short));
  109. $tpl->assign('button_text',
  110. json_encode(array(
  111. 'today' => get_lang('Today'),
  112. 'month' => get_lang('Month'),
  113. 'week' => get_lang('Week'),
  114. 'day' => get_lang('Day')
  115. ))
  116. );
  117. //see http://docs.jquery.com/UI/Datepicker/$.datepicker.formatDate
  118. $tpl->assign('js_format_date', 'll');
  119. $region_value = api_get_language_isocode();
  120. if ($region_value == 'en') {
  121. $region_value = 'en-GB';
  122. }
  123. $tpl->assign('region_value', $region_value);
  124. $export_icon = api_get_path(WEB_IMG_PATH).'img/export.png';
  125. $export_icon_low = api_get_path(WEB_IMG_PATH).'img/export_low_fade.png';
  126. $export_icon_high = api_get_path(WEB_IMG_PATH).'img/export_high_fade.png';
  127. $tpl->assign(
  128. 'export_ical_confidential_icon',
  129. Display::return_icon($export_icon_high, get_lang('ExportiCalConfidential'))
  130. );
  131. $actions = $agenda->displayActions('calendar', $userId);
  132. $tpl->assign('actions', $actions);
  133. // Calendar Type : course, admin, personal
  134. $tpl->assign('type', $type);
  135. $type_event_class = $type.'_event';
  136. $type_label = get_lang(ucfirst($type).'Calendar');
  137. if ($type == 'course' && !empty($group_id)) {
  138. $type_event_class = 'group_event';
  139. $type_label = get_lang('GroupCalendar');
  140. }
  141. $defaultView = api_get_setting('default_calendar_view');
  142. if (empty($defaultView)) {
  143. $defaultView = 'month';
  144. }
  145. /* month, basicWeek, agendaWeek, agendaDay */
  146. $tpl->assign('default_view', $defaultView);
  147. if ($type == 'course' && !empty($session_id)) {
  148. $type_event_class = 'session_event';
  149. $type_label = get_lang('SessionCalendar');
  150. }
  151. $tpl->assign('type_label', $type_label);
  152. $tpl->assign('type_event_class', $type_event_class);
  153. // Current user can add event?
  154. $tpl->assign('can_add_events', $can_add_events);
  155. // Setting AJAX caller
  156. if (!empty($userId)) {
  157. $agenda_ajax_url = api_get_path(WEB_AJAX_PATH).'agenda.ajax.php?user_id='.$userId.'&type='.$type;
  158. } else {
  159. $agenda_ajax_url = api_get_path(WEB_AJAX_PATH).'agenda.ajax.php?type='.$type;
  160. }
  161. if (isset($_GET['session_id'])) {
  162. $agenda_ajax_url .= '&session_id='.intval($_GET['session_id']);
  163. }
  164. $tpl->assign('web_agenda_ajax_url', $agenda_ajax_url);
  165. $course_code = api_get_course_id();
  166. $form = new FormValidator(
  167. 'form',
  168. 'get',
  169. null,
  170. null,
  171. array('id' => 'add_event_form')
  172. );
  173. $form->addElement('html', '<span id="calendar_course_info"></span><div id="visible_to_input">');
  174. $sendTo = $agenda->parseAgendaFilter($userId);
  175. $addOnlyItemsInSendTo = true;
  176. if ($sendTo['everyone']) {
  177. $addOnlyItemsInSendTo = false;
  178. }
  179. $agenda->showToForm($form, $sendTo, array(), $addOnlyItemsInSendTo);
  180. $form->addElement('html', '</div>');
  181. $form->addElement('html', '<div id="visible_to_read_only" style="display: none">');
  182. $form->addElement('label', get_lang('To'), '<div id="visible_to_read_only_users"></div>');
  183. $form->addElement('html', '</div>');
  184. $form->addElement('label', get_lang('Agenda'), '<div id ="color_calendar"></div>');
  185. $form->addElement('label', get_lang('Date'), '<span id="start_date"></span><span id="end_date"></span>');
  186. $form->addElement('text', 'title', get_lang('Title'), array('id' => 'title'));
  187. $form->addHtmlEditor(
  188. 'content',
  189. get_lang('Description'),
  190. false,
  191. false,
  192. [
  193. 'ToolbarSet' => 'TestProposedAnswer',
  194. 'Height' => '120'
  195. ]
  196. );
  197. if ($agenda->type == 'course') {
  198. $form->addElement('html', '<div id="add_as_announcement_div" style="display: none">');
  199. $form->addElement('checkbox', 'add_as_annonuncement', null, get_lang('AddAsAnnouncement'));
  200. $form->addElement('html', '</div>');
  201. $form->addElement('textarea', 'comment', get_lang('Comment'), array('id' => 'comment'));
  202. }
  203. $tpl->assign('form_add', $form->returnForm());
  204. // Loading Agenda template.
  205. $content = $tpl->fetch('default/agenda/month.tpl');
  206. $message = Session::read('message');
  207. $tpl->assign('message', $message);
  208. Session::erase('message');
  209. $tpl->assign('content', $content);
  210. // Loading main Chamilo 1 col template
  211. $tpl->display_one_col_template();