agenda_js.php 7.2 KB

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