agenda_js.php 7.4 KB

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