agenda_js.php 8.2 KB

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