agenda_js.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.calendar
  5. */
  6. // use anonymous mode when accessing this course tool
  7. $use_anonymous = true;
  8. $typeList = array('personal', 'course', 'admin', 'platform');
  9. // Calendar type
  10. $type = isset($_REQUEST['type']) && in_array($_REQUEST['type'], $typeList) ? $_REQUEST['type'] : 'personal';
  11. $userId = isset($_REQUEST['user_id']) ? $_REQUEST['user_id'] : null;
  12. if ($type == 'personal' || $type == 'admin') {
  13. $cidReset = true; // fixes #5162
  14. }
  15. require_once __DIR__.'/../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_asset('qtip2/jquery.qtip.min.js');
  20. $htmlHeadXtra[] = api_get_asset('fullcalendar/dist/fullcalendar.js');
  21. $htmlHeadXtra[] = api_get_asset('fullcalendar/dist/locale-all.js');
  22. $htmlHeadXtra[] = api_get_asset('fullcalendar/dist/gcal.js');
  23. $htmlHeadXtra[] = api_get_css_asset('fullcalendar/dist/fullcalendar.min.css');
  24. $htmlHeadXtra[] = api_get_css_asset('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($type);
  40. $is_group_tutor = false;
  41. $session_id = api_get_session_id();
  42. $group_id = api_get_group_id();
  43. $courseId = api_get_course_int_id();
  44. if (!empty($group_id)) {
  45. $group_properties = GroupManager::get_group_properties($group_id);
  46. $is_group_tutor = GroupManager::is_tutor_of_group(api_get_user_id(), $group_properties);
  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. $allowToEdit = $agenda->getIsAllowedToEdit();
  70. $this_section = SECTION_COURSES;
  71. if ($allowToEdit) {
  72. $can_add_events = 1;
  73. }
  74. break;
  75. case 'personal':
  76. if (api_is_anonymous()) {
  77. api_not_allowed(true);
  78. }
  79. $extra_field_data = UserManager::get_extra_user_data_by_field(
  80. api_get_user_id(),
  81. 'google_calendar_url'
  82. );
  83. if (!empty($extra_field_data) &&
  84. isset($extra_field_data['google_calendar_url']) &&
  85. !empty($extra_field_data['google_calendar_url'])
  86. ) {
  87. $tpl->assign('use_google_calendar', 1);
  88. $tpl->assign('google_calendar_url', $extra_field_data['google_calendar_url']);
  89. }
  90. $this_section = SECTION_MYAGENDA;
  91. if (!api_is_anonymous()) {
  92. $can_add_events = 1;
  93. }
  94. break;
  95. }
  96. $tpl->assign('js_format_date', 'll');
  97. $region_value = api_get_language_isocode();
  98. if ($region_value == 'en') {
  99. $region_value = 'en-GB';
  100. }
  101. $tpl->assign('region_value', $region_value);
  102. $export_icon = Display::return_icon(
  103. 'export.png',
  104. null,
  105. null,
  106. null,
  107. null,
  108. true,
  109. false
  110. );
  111. $export_icon_low = Display::return_icon(
  112. 'export_low_fade.png',
  113. null,
  114. null,
  115. null,
  116. null,
  117. true,
  118. false
  119. );
  120. $export_icon_high = Display::return_icon(
  121. 'export_high_fade.png',
  122. null,
  123. null,
  124. null,
  125. null,
  126. true,
  127. false
  128. );
  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 ($type == 'course' && !empty($courseId)) {
  164. $agenda_ajax_url .= '&'.api_get_cidreq();
  165. }
  166. if (isset($_GET['session_id'])) {
  167. $agenda_ajax_url .= '&session_id='.intval($_GET['session_id']);
  168. }
  169. $tpl->assign('web_agenda_ajax_url', $agenda_ajax_url);
  170. $form = new FormValidator(
  171. 'form',
  172. 'get',
  173. api_get_self().'?'.api_get_cidreq(),
  174. null,
  175. array('id' => 'add_event_form')
  176. );
  177. $form->addHtml('<span id="calendar_course_info"></span><div id="visible_to_input">');
  178. $sendTo = $agenda->parseAgendaFilter($userId);
  179. $addOnlyItemsInSendTo = true;
  180. if ($sendTo['everyone']) {
  181. $addOnlyItemsInSendTo = false;
  182. }
  183. $agenda->showToForm($form, $sendTo, array(), $addOnlyItemsInSendTo);
  184. $form->addHtml('</div>');
  185. $form->addHtml('<div id="visible_to_read_only" style="display: none">');
  186. $form->addElement('label', get_lang('To'), '<div id="visible_to_read_only_users"></div>');
  187. $form->addHtml('</div>');
  188. $form->addElement('label', get_lang('Agenda'), '<div id ="color_calendar"></div>');
  189. $form->addElement('label', get_lang('Date'), '<span id="start_date"></span><span id="end_date"></span>');
  190. $form->addElement('text', 'title', get_lang('Title'), array('id' => 'title'));
  191. $form->addHtmlEditor(
  192. 'content',
  193. get_lang('Description'),
  194. false,
  195. false,
  196. [
  197. 'ToolbarSet' => 'TestProposedAnswer',
  198. 'Height' => '120'
  199. ]
  200. );
  201. if ($agenda->type === 'course') {
  202. $form->addHtml('<div id="add_as_announcement_div" style="display: none">');
  203. $form->addElement('checkbox', 'add_as_annonuncement', null, get_lang('AddAsAnnouncement'));
  204. $form->addHtml('</div>');
  205. $form->addElement('textarea', 'comment', get_lang('Comment'), array('id' => 'comment'));
  206. }
  207. $tpl->assign('form_add', $form->returnForm());
  208. $tpl->assign('legend_list', api_get_configuration_value('agenda_legend'));
  209. $templateName = $tpl->get_template('agenda/month.tpl');
  210. $content = $tpl->fetch($templateName);
  211. $tpl->assign('content', $content);
  212. $tpl->display_one_col_template();