agenda_js.php 7.9 KB

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