agenda_js.php 8.5 KB

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