agenda_js.php 8.6 KB

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