agenda_js.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  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 = ['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(['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(
  47. api_get_user_id(),
  48. $group_properties,
  49. $courseId
  50. );
  51. $interbreadcrumb[] = [
  52. "url" => api_get_path(WEB_CODE_PATH)."group/group.php?".api_get_cidreq(),
  53. "name" => get_lang('Groups'),
  54. ];
  55. $interbreadcrumb[] = [
  56. "url" => api_get_path(WEB_CODE_PATH)."group/group_space.php?".api_get_cidreq(),
  57. "name" => get_lang('GroupSpace').' '.$group_properties['name'],
  58. ];
  59. }
  60. $tpl = new Template(get_lang('Agenda'));
  61. $tpl->assign('use_google_calendar', 0);
  62. $can_add_events = 0;
  63. switch ($type) {
  64. case 'admin':
  65. api_protect_admin_script();
  66. $this_section = SECTION_PLATFORM_ADMIN;
  67. if (api_is_platform_admin()) {
  68. $can_add_events = 1;
  69. }
  70. break;
  71. case 'course':
  72. api_protect_course_script(true);
  73. $allowToEdit = $agenda->getIsAllowedToEdit();
  74. $this_section = SECTION_COURSES;
  75. if ($allowToEdit) {
  76. $can_add_events = 1;
  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. $tpl->assign('js_format_date', 'll');
  101. $region_value = api_get_language_isocode();
  102. if ($region_value == 'en') {
  103. $region_value = 'en-GB';
  104. }
  105. $tpl->assign('region_value', $region_value);
  106. $export_icon = Display::return_icon(
  107. 'export.png',
  108. null,
  109. null,
  110. null,
  111. null,
  112. true,
  113. false
  114. );
  115. $export_icon_low = Display::return_icon(
  116. 'export_low_fade.png',
  117. null,
  118. null,
  119. null,
  120. null,
  121. true,
  122. false
  123. );
  124. $export_icon_high = Display::return_icon(
  125. 'export_high_fade.png',
  126. null,
  127. null,
  128. null,
  129. null,
  130. true,
  131. false
  132. );
  133. $tpl->assign(
  134. 'export_ical_confidential_icon',
  135. Display::return_icon($export_icon_high, get_lang('ExportiCalConfidential'))
  136. );
  137. $actions = $agenda->displayActions('calendar', $userId);
  138. $tpl->assign('toolbar', $actions);
  139. // Calendar Type : course, admin, personal
  140. $tpl->assign('type', $type);
  141. $type_event_class = $type.'_event';
  142. $type_label = get_lang(ucfirst($type).'Calendar');
  143. if ($type == 'course' && !empty($group_id)) {
  144. $type_event_class = 'group_event';
  145. $type_label = get_lang('GroupCalendar');
  146. }
  147. $defaultView = api_get_setting('default_calendar_view');
  148. if (empty($defaultView)) {
  149. $defaultView = 'month';
  150. }
  151. /* month, basicWeek, agendaWeek, agendaDay */
  152. $tpl->assign('default_view', $defaultView);
  153. if ($type == 'course' && !empty($session_id)) {
  154. $type_event_class = 'session_event';
  155. $type_label = get_lang('SessionCalendar');
  156. }
  157. $agendaColors = array_merge(
  158. [
  159. 'platform' => 'red', //red
  160. 'course' => '#458B00', //green
  161. 'group' => '#A0522D', //siena
  162. 'session' => '#00496D', // kind of green
  163. 'other_session' => '#999', // kind of green
  164. 'personal' => 'steel blue', //steel blue
  165. 'student_publication' => '#FF8C00', //DarkOrange
  166. ],
  167. api_get_configuration_value('agenda_colors') ?: []
  168. );
  169. switch ($type_event_class) {
  170. case 'admin_event':
  171. $tpl->assign('type_event_color', $agendaColors['platform']);
  172. break;
  173. case 'course_event':
  174. $tpl->assign('type_event_color', $agendaColors['course']);
  175. break;
  176. case 'group_event':
  177. $tpl->assign('type_event_color', $agendaColors['group']);
  178. break;
  179. case 'session_event':
  180. $tpl->assign('type_event_color', $agendaColors['session']);
  181. break;
  182. case 'personal_event':
  183. $tpl->assign('type_event_color', $agendaColors['personal']);
  184. break;
  185. }
  186. $tpl->assign('type_label', $type_label);
  187. $tpl->assign('type_event_class', $type_event_class);
  188. // Current user can add event?
  189. $tpl->assign('can_add_events', $can_add_events);
  190. // Setting AJAX caller
  191. if (!empty($userId)) {
  192. $agenda_ajax_url = api_get_path(WEB_AJAX_PATH).'agenda.ajax.php?user_id='.$userId.'&type='.$type;
  193. } else {
  194. $agenda_ajax_url = api_get_path(WEB_AJAX_PATH).'agenda.ajax.php?type='.$type;
  195. }
  196. if ($type == 'course' && !empty($courseId)) {
  197. $agenda_ajax_url .= '&'.api_get_cidreq();
  198. }
  199. if (isset($_GET['session_id'])) {
  200. $agenda_ajax_url .= '&session_id='.intval($_GET['session_id']);
  201. }
  202. $tpl->assign('web_agenda_ajax_url', $agenda_ajax_url);
  203. $form = new FormValidator(
  204. 'form',
  205. 'get',
  206. api_get_self().'?'.api_get_cidreq(),
  207. null,
  208. ['id' => 'add_event_form']
  209. );
  210. $form->addHtml('<span id="calendar_course_info"></span><div id="visible_to_input">');
  211. $sendTo = $agenda->parseAgendaFilter($userId);
  212. $addOnlyItemsInSendTo = true;
  213. if ($sendTo['everyone']) {
  214. $addOnlyItemsInSendTo = false;
  215. }
  216. $agenda->showToForm($form, $sendTo, [], $addOnlyItemsInSendTo);
  217. $form->addHtml('</div>');
  218. $form->addHtml('<div id="visible_to_read_only" style="display: none">');
  219. $form->addElement('label', get_lang('To'), '<div id="visible_to_read_only_users"></div>');
  220. $form->addHtml('</div>');
  221. $form->addElement('label', get_lang('Agenda'), '<div id ="color_calendar"></div>');
  222. $form->addElement('label', get_lang('Date'), '<span id="start_date"></span><span id="end_date"></span>');
  223. $form->addElement('text', 'title', get_lang('Title'), ['id' => 'title']);
  224. $form->addHtmlEditor(
  225. 'content',
  226. get_lang('Description'),
  227. false,
  228. false,
  229. [
  230. 'ToolbarSet' => 'TestProposedAnswer',
  231. 'Height' => '120',
  232. ]
  233. );
  234. if ($agenda->type === 'course') {
  235. $form->addHtml('<div id="add_as_announcement_div" style="display: none">');
  236. $form->addElement('checkbox', 'add_as_annonuncement', null, get_lang('AddAsAnnouncement'));
  237. $form->addHtml('</div>');
  238. $form->addElement('textarea', 'comment', get_lang('Comment'), ['id' => 'comment']);
  239. }
  240. $tpl->assign('form_add', $form->returnForm());
  241. $tpl->assign('legend_list', api_get_configuration_value('agenda_legend'));
  242. $onHoverInfo = api_get_configuration_value('agenda_on_hover_info');
  243. if (!empty($onHoverInfo)) {
  244. $options = $onHoverInfo['options'];
  245. } else {
  246. $options = [
  247. 'comment' => true,
  248. 'description' => true,
  249. ];
  250. }
  251. $tpl->assign('on_hover_info', $options);
  252. $templateName = $tpl->get_template('agenda/month.tpl');
  253. $content = $tpl->fetch($templateName);
  254. $tpl->assign('content', $content);
  255. $tpl->display_one_col_template();