agenda_js.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.calendar
  5. */
  6. /**
  7. * INIT SECTION
  8. */
  9. // name of the language file that needs to be included
  10. $language_file = array('agenda', 'group', 'announcements');
  11. // use anonymous mode when accessing this course tool
  12. $use_anonymous = true;
  13. //Calendar type
  14. $type = isset($_REQUEST['type']) && in_array($_REQUEST['type'], array('personal', 'course', 'admin')) ? $_REQUEST['type'] : 'personal';
  15. if ($type == 'personal') {
  16. $cidReset = true; // fixes #5162
  17. }
  18. require_once '../inc/global.inc.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') {
  29. $type = 'admin';
  30. }
  31. //if (api_get_course_id() != -1 && $type == 'course') {
  32. if (isset($_REQUEST['cidReq']) && !empty($_REQUEST['cidReq'])) {
  33. $type = 'course';
  34. }
  35. $is_group_tutor = false;
  36. $session_id = api_get_session_id();
  37. $group_id = api_get_group_id();
  38. if (!empty($group_id)) {
  39. $is_group_tutor = GroupManager::is_tutor_of_group(api_get_user_id(), $group_id);
  40. $group_properties = GroupManager :: get_group_properties($group_id);
  41. $interbreadcrumb[] = array ("url" => "../group/group.php", "name" => get_lang('Groups'));
  42. $interbreadcrumb[] = array ("url"=>"../group/group_space.php?gidReq=".$group_id, "name"=> get_lang('GroupSpace').' '.$group_properties['name']);
  43. }
  44. $app['title'] = get_lang('Agenda');
  45. $tpl = $app['template'];
  46. $tpl->assign('use_google_calendar', 0);
  47. $can_add_events = 0;
  48. switch($type) {
  49. case 'admin':
  50. api_protect_admin_script();
  51. $this_section = SECTION_PLATFORM_ADMIN;
  52. if (api_is_platform_admin()) {
  53. $can_add_events = 1;
  54. }
  55. break;
  56. case 'course':
  57. api_protect_course_script();
  58. $this_section = SECTION_COURSES;
  59. if (api_is_allowed_to_edit()) {
  60. $can_add_events = 1;
  61. }
  62. if (!empty($group_id)) {
  63. if ($is_group_tutor) {
  64. $can_add_events = 1;
  65. }
  66. }
  67. break;
  68. case 'personal':
  69. if (api_is_anonymous()) {
  70. api_not_allowed(true);
  71. }
  72. $extra_field_data = UserManager::get_extra_user_data_by_field(api_get_user_id(), 'google_calendar_url');
  73. if (!empty($extra_field_data) && isset($extra_field_data['google_calendar_url']) && !empty($extra_field_data['google_calendar_url'])) {
  74. $tpl->assign('use_google_calendar', 1);
  75. $tpl->assign('google_calendar_url', $extra_field_data['google_calendar_url']);
  76. }
  77. $this_section = SECTION_MYAGENDA;
  78. if (!api_is_anonymous()) {
  79. $can_add_events = 1;
  80. }
  81. break;
  82. }
  83. //Setting translations
  84. $day_short = api_get_week_days_short();
  85. $days = api_get_week_days_long();
  86. $months = api_get_months_long();
  87. $months_short = api_get_months_short();
  88. //Setting calendar translations
  89. $tpl->assign('month_names', json_encode($months));
  90. $tpl->assign('month_names_short', json_encode($months_short));
  91. $tpl->assign('day_names', json_encode($days));
  92. $tpl->assign('day_names_short', json_encode($day_short));
  93. $tpl->assign('button_text', json_encode(array(
  94. 'today' => get_lang('Today'),
  95. 'month' => get_lang('Month'),
  96. 'week' => get_lang('Week'),
  97. 'day' => get_lang('Day')
  98. )));
  99. //see http://docs.jquery.com/UI/Datepicker/$.datepicker.formatDate
  100. $tpl->assign('js_format_date', 'D d M yy');
  101. $region_value = api_get_language_isocode();
  102. if ($region_value == 'en') {
  103. $region_value = 'en-GB';
  104. }
  105. $tpl->assign('region_value', $region_value);
  106. $export_icon = '../img/export.png';
  107. $export_icon_low = '../img/export_low_fade.png';
  108. $export_icon_high = '../img/export_high_fade.png';
  109. $tpl->assign('export_ical_confidential_icon', Display::return_icon($export_icon_high, get_lang('ExportiCalConfidential')));
  110. $actions = null;
  111. if (api_is_allowed_to_edit(false,true) OR (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous()) && api_is_allowed_to_session_edit(false,true) OR $is_group_tutor) {
  112. if ($type == 'course') {
  113. if (isset($_GET['user_id'])) {
  114. $filter = $_GET['user_id'];
  115. }
  116. $actions = display_courseadmin_links($filter);
  117. }
  118. $tpl->assign('actions', $actions);
  119. }
  120. //Calendar Type : course, admin, personal
  121. $tpl->assign('type', $type);
  122. $type_event_class = $type.'_event';
  123. $type_label = get_lang(ucfirst($type).'Calendar');
  124. if ($type == 'course' && !empty($group_id)) {
  125. $type_event_class = 'group_event';
  126. $type_label = get_lang('GroupCalendar');
  127. }
  128. if ($type == 'course' && !empty($session_id)) {
  129. $type_event_class = 'session_event';
  130. $type_label = get_lang('SessionCalendar');
  131. }
  132. $tpl->assign('type_label', $type_label);
  133. $tpl->assign('type_event_class', $type_event_class);
  134. //Current user can add event?
  135. $tpl->assign('can_add_events', $can_add_events);
  136. //Setting AJAX caller
  137. if (isset($_GET['user_id'])) {
  138. $user_id = $_GET['user_id'];
  139. $agenda_ajax_url = api_get_path(WEB_AJAX_PATH).'agenda.ajax.php?user_id='.$user_id.'&type='.$type;
  140. } else {
  141. $agenda_ajax_url = api_get_path(WEB_AJAX_PATH).'agenda.ajax.php?type='.$type;
  142. }
  143. $tpl->assign('web_agenda_ajax_url', $agenda_ajax_url);
  144. $course_code = api_get_course_id();
  145. if ((api_is_allowed_to_edit() || $is_group_tutor) && $course_code != '-1' && $type == 'course') {
  146. $order = 'lastname';
  147. if (api_is_western_name_order()) {
  148. $order = 'firstname';
  149. }
  150. if (!empty($group_id)) {
  151. $group_list = array($group_id => $group_properties);
  152. $user_list = GroupManager::get_subscribed_users($group_id);
  153. } else {
  154. $user_list = CourseManager::get_user_list_from_course_code(api_get_course_id(), api_get_session_id(), null, $order);
  155. $group_list = CourseManager::get_group_list_of_course(api_get_course_id(), api_get_session_id());
  156. }
  157. $agenda = new Agenda();
  158. //This will fill the select called #users_to_send_id
  159. $select = $agenda->construct_not_selected_select_form($group_list, $user_list, array());
  160. $tpl->assign('visible_to', $select);
  161. }
  162. $tpl->display('default/agenda/month.tpl');