agenda_js.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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. //Setting translations
  97. /*$day_short = api_get_week_days_short();
  98. $days = api_get_week_days_long();
  99. $months = api_get_months_long();
  100. $months_short = api_get_months_short();*/
  101. //Setting calendar translations
  102. /*$tpl->assign('month_names', json_encode($months));
  103. $tpl->assign('month_names_short', json_encode($months_short));
  104. $tpl->assign('day_names', json_encode($days));
  105. $tpl->assign('day_names_short', json_encode($day_short));
  106. $tpl->assign(
  107. 'button_text',
  108. json_encode(array(
  109. 'today' => get_lang('Today'),
  110. 'month' => get_lang('Month'),
  111. 'week' => get_lang('Week'),
  112. 'day' => get_lang('Day')
  113. ))
  114. );*/
  115. //see http://docs.jquery.com/UI/Datepicker/$.datepicker.formatDate
  116. $tpl->assign('js_format_date', 'll');
  117. $region_value = api_get_language_isocode();
  118. if ($region_value == 'en') {
  119. $region_value = 'en-GB';
  120. }
  121. $tpl->assign('region_value', $region_value);
  122. $export_icon = Display::return_icon('export.png', null, null, null, null, true, false);
  123. $export_icon_low = Display::return_icon('export_low_fade.png', null, null, null, null, true, false);
  124. $export_icon_high = Display::return_icon('export_high_fade.png', null, null, null, null, true, false);
  125. $tpl->assign(
  126. 'export_ical_confidential_icon',
  127. Display::return_icon($export_icon_high, get_lang('ExportiCalConfidential'))
  128. );
  129. $actions = $agenda->displayActions('calendar', $userId);
  130. $tpl->assign('toolbar', $actions);
  131. // Calendar Type : course, admin, personal
  132. $tpl->assign('type', $type);
  133. $type_event_class = $type.'_event';
  134. $type_label = get_lang(ucfirst($type).'Calendar');
  135. if ($type == 'course' && !empty($group_id)) {
  136. $type_event_class = 'group_event';
  137. $type_label = get_lang('GroupCalendar');
  138. }
  139. $defaultView = api_get_setting('default_calendar_view');
  140. if (empty($defaultView)) {
  141. $defaultView = 'month';
  142. }
  143. /* month, basicWeek, agendaWeek, agendaDay */
  144. $tpl->assign('default_view', $defaultView);
  145. if ($type == 'course' && !empty($session_id)) {
  146. $type_event_class = 'session_event';
  147. $type_label = get_lang('SessionCalendar');
  148. }
  149. $tpl->assign('type_label', $type_label);
  150. $tpl->assign('type_event_class', $type_event_class);
  151. // Current user can add event?
  152. $tpl->assign('can_add_events', $can_add_events);
  153. // Setting AJAX caller
  154. if (!empty($userId)) {
  155. $agenda_ajax_url = api_get_path(WEB_AJAX_PATH).'agenda.ajax.php?user_id='.$userId.'&type='.$type;
  156. } else {
  157. $agenda_ajax_url = api_get_path(WEB_AJAX_PATH).'agenda.ajax.php?type='.$type;
  158. }
  159. if ($type == 'course' && !empty($courseId)) {
  160. $agenda_ajax_url .= '&'.api_get_cidreq();
  161. }
  162. if (isset($_GET['session_id'])) {
  163. $agenda_ajax_url .= '&session_id='.intval($_GET['session_id']);
  164. }
  165. $tpl->assign('web_agenda_ajax_url', $agenda_ajax_url);
  166. $form = new FormValidator(
  167. 'form',
  168. 'get',
  169. null,
  170. null,
  171. array('id' => 'add_event_form')
  172. );
  173. $form->addHtml('<span id="calendar_course_info"></span><div id="visible_to_input">');
  174. $sendTo = $agenda->parseAgendaFilter($userId);
  175. $addOnlyItemsInSendTo = true;
  176. if ($sendTo['everyone']) {
  177. $addOnlyItemsInSendTo = false;
  178. }
  179. $agenda->showToForm($form, $sendTo, array(), $addOnlyItemsInSendTo);
  180. $form->addHtml('</div>');
  181. $form->addHtml('<div id="visible_to_read_only" style="display: none">');
  182. $form->addElement('label', get_lang('To'), '<div id="visible_to_read_only_users"></div>');
  183. $form->addHtml('</div>');
  184. $form->addElement('label', get_lang('Agenda'), '<div id ="color_calendar"></div>');
  185. $form->addElement('label', get_lang('Date'), '<span id="start_date"></span><span id="end_date"></span>');
  186. $form->addElement('text', 'title', get_lang('Title'), array('id' => 'title'));
  187. $form->addHtmlEditor(
  188. 'content',
  189. get_lang('Description'),
  190. false,
  191. false,
  192. [
  193. 'ToolbarSet' => 'TestProposedAnswer',
  194. 'Height' => '120'
  195. ]
  196. );
  197. if ($agenda->type === 'course') {
  198. $form->addHtml('<div id="add_as_announcement_div" style="display: none">');
  199. $form->addElement('checkbox', 'add_as_annonuncement', null, get_lang('AddAsAnnouncement'));
  200. $form->addHtml('</div>');
  201. $form->addElement('textarea', 'comment', get_lang('Comment'), array('id' => 'comment'));
  202. }
  203. $tpl->assign('form_add', $form->returnForm());
  204. $templateName = $tpl->get_template('agenda/month.tpl');
  205. $content = $tpl->fetch($templateName);
  206. $tpl->assign('content', $content);
  207. $tpl->display_one_col_template();