agenda_js.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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(api_get_user_id(), 'google_calendar_url');
  82. if (!empty($extra_field_data) && isset($extra_field_data['google_calendar_url']) && !empty($extra_field_data['google_calendar_url'])) {
  83. $tpl->assign('use_google_calendar', 1);
  84. $tpl->assign('google_calendar_url', $extra_field_data['google_calendar_url']);
  85. }
  86. $this_section = SECTION_MYAGENDA;
  87. if (!api_is_anonymous()) {
  88. $can_add_events = 1;
  89. }
  90. break;
  91. }
  92. //Setting translations
  93. $day_short = api_get_week_days_short();
  94. $days = api_get_week_days_long();
  95. $months = api_get_months_long();
  96. $months_short = api_get_months_short();
  97. //Setting calendar translations
  98. $tpl->assign('month_names', json_encode($months));
  99. $tpl->assign('month_names_short', json_encode($months_short));
  100. $tpl->assign('day_names', json_encode($days));
  101. $tpl->assign('day_names_short', json_encode($day_short));
  102. $tpl->assign('button_text',
  103. json_encode(array(
  104. 'today' => get_lang('Today'),
  105. 'month' => get_lang('Month'),
  106. 'week' => get_lang('Week'),
  107. 'day' => get_lang('Day')
  108. ))
  109. );
  110. //see http://docs.jquery.com/UI/Datepicker/$.datepicker.formatDate
  111. $tpl->assign('js_format_date', 'D d M yy');
  112. $region_value = api_get_language_isocode();
  113. if ($region_value == 'en') {
  114. $region_value = 'en-GB';
  115. }
  116. $tpl->assign('region_value', $region_value);
  117. $export_icon = api_get_path(WEB_IMG_PATH).'img/export.png';
  118. $export_icon_low = api_get_path(WEB_IMG_PATH).'img/export_low_fade.png';
  119. $export_icon_high = api_get_path(WEB_IMG_PATH).'img/export_high_fade.png';
  120. $tpl->assign(
  121. 'export_ical_confidential_icon',
  122. Display::return_icon($export_icon_high, get_lang('ExportiCalConfidential'))
  123. );
  124. $actions = $agenda->displayActions('calendar', $userId);
  125. $tpl->assign('actions', $actions);
  126. //Calendar Type : course, admin, personal
  127. $tpl->assign('type', $type);
  128. $type_event_class = $type.'_event';
  129. $type_label = get_lang(ucfirst($type).'Calendar');
  130. if ($type == 'course' && !empty($group_id)) {
  131. $type_event_class = 'group_event';
  132. $type_label = get_lang('GroupCalendar');
  133. }
  134. $defaultView = api_get_setting('default_calendar_view');
  135. if (empty($defaultView)) {
  136. $defaultView = 'month';
  137. }
  138. /* month, basicWeek, agendaWeek, agendaDay */
  139. $tpl->assign('default_view', $defaultView);
  140. if ($type == 'course' && !empty($session_id)) {
  141. $type_event_class = 'session_event';
  142. $type_label = get_lang('SessionCalendar');
  143. }
  144. $tpl->assign('type_label', $type_label);
  145. $tpl->assign('type_event_class', $type_event_class);
  146. // Current user can add event?
  147. $tpl->assign('can_add_events', $can_add_events);
  148. // Setting AJAX caller
  149. if (!empty($userId)) {
  150. $agenda_ajax_url = api_get_path(WEB_AJAX_PATH).'agenda.ajax.php?user_id='.$userId.'&type='.$type;
  151. } else {
  152. $agenda_ajax_url = api_get_path(WEB_AJAX_PATH).'agenda.ajax.php?type='.$type;
  153. }
  154. $tpl->assign('web_agenda_ajax_url', $agenda_ajax_url);
  155. $course_code = api_get_course_id();
  156. //if ((api_is_allowed_to_edit() || $is_group_tutor) && $course_code != '-1' && $type == 'course') {
  157. $form = new FormValidator('form', 'get', null, null, array('id' => 'add_event_form'));
  158. $form->addElement('html', '<div id="visible_to_input">');
  159. $sendTo = $agenda->parseAgendaFilter($userId);
  160. $addOnlyItemsInSendTo = true;
  161. if ($sendTo['everyone']) {
  162. $addOnlyItemsInSendTo = false;
  163. }
  164. $agenda->showToForm($form, $sendTo, array(), $addOnlyItemsInSendTo);
  165. $form->addElement('html', '</div>');
  166. $form->addElement('html', '<div id="visible_to_read_only" style="display: none">');
  167. $form->addElement('label', get_lang('To'), '<div id="visible_to_read_only_users"></div>');
  168. $form->addElement('html', '</div>');
  169. $form->addElement('label', get_lang('Agenda'), '<div id ="color_calendar"></div>');
  170. $form->addElement('label', get_lang('Date'), '<span id="start_date"></span><span id="end_date"></span>');
  171. $form->addElement('text', 'title', get_lang('Title'), array('id' => 'title'));
  172. $form->addElement('textarea', 'content', get_lang('Description'), array('id' => 'content'));
  173. if ($agenda->type == 'course') {
  174. $form->addElement('html', '<div id="add_as_announcement_div" style="display: none">');
  175. $form->addElement('checkbox', 'add_as_annonuncement', null, get_lang('AddAsAnnouncement'));
  176. $form->addElement('html', '</div>');
  177. }
  178. $tpl->assign('form_add', $form->return_form());
  179. //}
  180. // Loading Agenda template.
  181. $content = $tpl->fetch('default/agenda/month.tpl');
  182. $message = Session::read('message');
  183. $tpl->assign('message', $message);
  184. Session::erase('message');
  185. $tpl->assign('content', $content);
  186. // Loading main Chamilo 1 col template
  187. $tpl->display_one_col_template();