agenda_js.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.calendar
  5. */
  6. use \ChamiloSession as Session;
  7. // name of the language file that needs to be included
  8. $language_file = array('agenda', 'group', 'announcements');
  9. // use anonymous mode when accessing this course tool
  10. $use_anonymous = true;
  11. // Calendar type
  12. $type = isset($_REQUEST['type']) && in_array($_REQUEST['type'], array('personal', 'course', 'admin', 'platform')) ? $_REQUEST['type'] : 'personal';
  13. $userId = isset($_REQUEST['user_id']) ? $_REQUEST['user_id'] : null;
  14. if ($type == 'personal') {
  15. $cidReset = true; // fixes #5162
  16. }
  17. require_once '../inc/global.inc.php';
  18. require_once 'agenda.lib.php';
  19. require_once 'agenda.inc.php';
  20. $current_course_tool = TOOL_CALENDAR_EVENT;
  21. $this_section = SECTION_MYAGENDA;
  22. $htmlHeadXtra[] = api_get_jquery_libraries_js(array('jquery-ui', 'jquery-ui-i18n'));
  23. $htmlHeadXtra[] = api_get_js('qtip2/jquery.qtip.min.js');
  24. $htmlHeadXtra[] = api_get_js('fullcalendar/fullcalendar.min.js');
  25. $htmlHeadXtra[] = api_get_js('fullcalendar/gcal.js');
  26. $htmlHeadXtra[] = api_get_css(api_get_path(WEB_LIBRARY_PATH).'javascript/fullcalendar/fullcalendar.css');
  27. $htmlHeadXtra[] = api_get_css(api_get_path(WEB_LIBRARY_PATH).'javascript/qtip2/jquery.qtip.min.css');
  28. if (api_is_platform_admin() && ($type == 'admin' || $type == 'platform')) {
  29. $type = 'admin';
  30. }
  31. if (isset($_REQUEST['cidReq']) && !empty($_REQUEST['cidReq'])) {
  32. if ($_REQUEST['cidReq'] == -1) {
  33. // When is out of the course tool (e.g My agenda)
  34. header('Location: ' . api_get_self());
  35. exit;
  36. } else {
  37. $type = 'course';
  38. $this_section = SECTION_COURSES;
  39. }
  40. }
  41. $agenda = new Agenda();
  42. $agenda->type = $type;
  43. $is_group_tutor = false;
  44. $session_id = api_get_session_id();
  45. $group_id = api_get_group_id();
  46. if (!empty($group_id)) {
  47. $is_group_tutor = GroupManager::is_tutor_of_group(api_get_user_id(), $group_id);
  48. $group_properties = GroupManager::get_group_properties($group_id);
  49. $interbreadcrumb[] = array(
  50. "url" => api_get_path(WEB_CODE_PATH)."group/group.php?".api_get_cidreq(),
  51. "name" => get_lang('Groups')
  52. );
  53. $interbreadcrumb[] = array(
  54. "url" => api_get_path(WEB_CODE_PATH)."group/group_space.php?".api_get_cidreq(),
  55. "name" => get_lang('GroupSpace').' '.$group_properties['name']
  56. );
  57. }
  58. $tpl = new Template(get_lang('Agenda'));
  59. $tpl->assign('use_google_calendar', 0);
  60. $can_add_events = 0;
  61. switch ($type) {
  62. case 'admin':
  63. api_protect_admin_script();
  64. $this_section = SECTION_PLATFORM_ADMIN;
  65. if (api_is_platform_admin()) {
  66. $can_add_events = 1;
  67. }
  68. break;
  69. case 'course':
  70. api_protect_course_script(true);
  71. $this_section = SECTION_COURSES;
  72. if (api_is_allowed_to_edit()) {
  73. $can_add_events = 1;
  74. }
  75. if (!empty($group_id)) {
  76. if ($is_group_tutor) {
  77. $can_add_events = 1;
  78. }
  79. }
  80. break;
  81. case 'personal':
  82. if (api_is_anonymous()) {
  83. api_not_allowed(true);
  84. }
  85. $extra_field_data = UserManager::get_extra_user_data_by_field(
  86. api_get_user_id(),
  87. 'google_calendar_url'
  88. );
  89. if (!empty($extra_field_data) &&
  90. isset($extra_field_data['google_calendar_url']) &&
  91. !empty($extra_field_data['google_calendar_url'])
  92. ) {
  93. $tpl->assign('use_google_calendar', 1);
  94. $tpl->assign('google_calendar_url', $extra_field_data['google_calendar_url']);
  95. }
  96. $this_section = SECTION_MYAGENDA;
  97. if (!api_is_anonymous()) {
  98. $can_add_events = 1;
  99. }
  100. break;
  101. }
  102. //Setting translations
  103. $day_short = api_get_week_days_short();
  104. $days = api_get_week_days_long();
  105. $months = api_get_months_long();
  106. $months_short = api_get_months_short();
  107. //Setting calendar translations
  108. $tpl->assign('month_names', json_encode($months));
  109. $tpl->assign('month_names_short', json_encode($months_short));
  110. $tpl->assign('day_names', json_encode($days));
  111. $tpl->assign('day_names_short', json_encode($day_short));
  112. $tpl->assign('button_text',
  113. json_encode(array(
  114. 'today' => get_lang('Today'),
  115. 'month' => get_lang('Month'),
  116. 'week' => get_lang('Week'),
  117. 'day' => get_lang('Day')
  118. ))
  119. );
  120. //see http://docs.jquery.com/UI/Datepicker/$.datepicker.formatDate
  121. $tpl->assign('js_format_date', 'D d M yy');
  122. $region_value = api_get_language_isocode();
  123. if ($region_value == 'en') {
  124. $region_value = 'en-GB';
  125. }
  126. $tpl->assign('region_value', $region_value);
  127. $export_icon = api_get_path(WEB_IMG_PATH).'img/export.png';
  128. $export_icon_low = api_get_path(WEB_IMG_PATH).'img/export_low_fade.png';
  129. $export_icon_high = api_get_path(WEB_IMG_PATH).'img/export_high_fade.png';
  130. $tpl->assign(
  131. 'export_ical_confidential_icon',
  132. Display::return_icon($export_icon_high, get_lang('ExportiCalConfidential'))
  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('GroupCalendar');
  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('SessionCalendar');
  153. }
  154. $tpl->assign('type_label', $type_label);
  155. $tpl->assign('type_event_class', $type_event_class);
  156. // Current user can add event?
  157. $tpl->assign('can_add_events', $can_add_events);
  158. // Setting AJAX caller
  159. if (!empty($userId)) {
  160. $agenda_ajax_url = api_get_path(WEB_AJAX_PATH).'agenda.ajax.php?user_id='.$userId.'&type='.$type;
  161. } else {
  162. $agenda_ajax_url = api_get_path(WEB_AJAX_PATH).'agenda.ajax.php?type='.$type;
  163. }
  164. $tpl->assign('web_agenda_ajax_url', $agenda_ajax_url);
  165. $course_code = api_get_course_id();
  166. $form = new FormValidator('form', 'get', null, null, array('id' => 'add_event_form'));
  167. $form->addElement('html', '<div id="visible_to_input">');
  168. $sendTo = $agenda->parseAgendaFilter($userId);
  169. $addOnlyItemsInSendTo = true;
  170. if ($sendTo['everyone']) {
  171. $addOnlyItemsInSendTo = false;
  172. }
  173. $agenda->showToForm($form, $sendTo, array(), $addOnlyItemsInSendTo);
  174. $form->addElement('html', '</div>');
  175. $form->addElement('html', '<div id="visible_to_read_only" style="display: none">');
  176. $form->addElement('label', get_lang('To'), '<div id="visible_to_read_only_users"></div>');
  177. $form->addElement('html', '</div>');
  178. $form->addElement('label', get_lang('Agenda'), '<div id ="color_calendar"></div>');
  179. $form->addElement('label', get_lang('Date'), '<span id="start_date"></span><span id="end_date"></span>');
  180. $form->addElement('text', 'title', get_lang('Title'), array('id' => 'title'));
  181. $form->addElement('textarea', 'content', get_lang('Description'), array('id' => 'content'));
  182. $allowEventComment = api_get_configuration_value('allow_agenda_event_comment');
  183. if ($agenda->type == 'course') {
  184. $form->addElement('html', '<div id="add_as_announcement_div" style="display: none">');
  185. $form->addElement('checkbox', 'add_as_annonuncement', null, get_lang('AddAsAnnouncement'));
  186. $form->addElement('html', '</div>');
  187. if ($allowEventComment) {
  188. $form->addElement('textarea', 'comment', get_lang('Comment'), array('id' => 'comment'));
  189. }
  190. }
  191. $tpl->assign('form_add', $form->return_form());
  192. $tpl->assign('allow_agenda_event_comment', $allowEventComment);
  193. // Loading Agenda template.
  194. $content = $tpl->fetch('default/agenda/month.tpl');
  195. $message = Session::read('message');
  196. $tpl->assign('message', $message);
  197. Session::erase('message');
  198. $tpl->assign('content', $content);
  199. // Loading main Chamilo 1 col template
  200. $tpl->display_one_col_template();