agenda_js.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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_JS_PATH).'fullcalendar/fullcalendar.css');
  27. $htmlHeadXtra[] = api_get_css(api_get_path(WEB_LIBRARY_JS_PATH).'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(
  94. 'button_text',
  95. json_encode(
  96. array(
  97. 'today' => get_lang('Today'),
  98. 'month' => get_lang('Month'),
  99. 'week' => get_lang('Week'),
  100. 'day' => get_lang('Day')
  101. )
  102. )
  103. );
  104. //see http://docs.jquery.com/UI/Datepicker/$.datepicker.formatDate
  105. $tpl->assign('js_format_date', 'D d M yy');
  106. $region_value = api_get_language_isocode();
  107. if ($region_value == 'en') {
  108. $region_value = 'en-GB';
  109. }
  110. $tpl->assign('region_value', $region_value);
  111. $tpl->assign('export_ical_confidential_icon', Display::return_icon('export.png', get_lang('ExportiCalConfidential')));
  112. $actions = null;
  113. $filter = null;
  114. if (api_is_allowed_to_edit(false,true) OR
  115. (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous()) &&
  116. api_is_allowed_to_session_edit(false,true) OR
  117. $is_group_tutor
  118. ) {
  119. if ($type == 'course') {
  120. if (isset($_GET['user_id'])) {
  121. $filter = $_GET['user_id'];
  122. }
  123. $actions = display_courseadmin_links($filter);
  124. }
  125. $tpl->assign('actions', $actions);
  126. }
  127. //Calendar Type : course, admin, personal
  128. $tpl->assign('type', $type);
  129. $type_event_class = $type.'_event';
  130. $type_label = get_lang(ucfirst($type).'Calendar');
  131. if ($type == 'course' && !empty($group_id)) {
  132. $type_event_class = 'group_event';
  133. $type_label = get_lang('GroupCalendar');
  134. }
  135. if ($type == 'course' && !empty($session_id)) {
  136. $type_event_class = 'session_event';
  137. $type_label = get_lang('SessionCalendar');
  138. }
  139. $tpl->assign('type_label', $type_label);
  140. $tpl->assign('type_event_class', $type_event_class);
  141. //Current user can add event?
  142. $tpl->assign('can_add_events', $can_add_events);
  143. //Setting AJAX caller
  144. if (isset($_GET['user_id'])) {
  145. $user_id = $_GET['user_id'];
  146. $agenda_ajax_url = api_get_path(WEB_AJAX_PATH).'agenda.ajax.php?user_id='.$user_id.'&type='.$type;
  147. } else {
  148. $agenda_ajax_url = api_get_path(WEB_AJAX_PATH).'agenda.ajax.php?type='.$type;
  149. }
  150. $tpl->assign('web_agenda_ajax_url', $agenda_ajax_url);
  151. $course_code = api_get_course_id();
  152. $select = null;
  153. if ((api_is_allowed_to_edit() || $is_group_tutor) && $course_code != '-1' && $type == 'course') {
  154. $order = 'lastname';
  155. if (api_is_western_name_order()) {
  156. $order = 'firstname';
  157. }
  158. if (!empty($group_id)) {
  159. $group_list = array($group_id => $group_properties);
  160. $user_list = GroupManager::get_subscribed_users($group_id);
  161. } else {
  162. $user_list = CourseManager::get_user_list_from_course_code(api_get_course_id(), api_get_session_id(), null, $order);
  163. $group_list = CourseManager::get_group_list_of_course(api_get_course_id(), api_get_session_id());
  164. }
  165. $agenda = new Agenda();
  166. //This will fill the select called #users_to_send_id
  167. $select = $agenda->construct_not_selected_select_form($group_list, $user_list, array());
  168. $tpl->assign('visible_to', $select);
  169. }
  170. $form = new FormValidator('form-simple', '', null);
  171. $form->addElement('label', get_lang('Date'), '<span id="simple_start_date"></span><span id="simple_end_date"></span>');
  172. $form->addElement('label', get_lang('Title'), '<div id="simple_title"></div>');
  173. $form->addElement('label', get_lang('Description'), '<div id="simple_content"></div>');
  174. $tpl->assign('form_simple', $form->return_form());
  175. $form = new FormValidator('add_event_form', null, null);
  176. if (!empty($select)) {
  177. $form->addElement(
  178. 'label',
  179. get_lang('To'),
  180. $select,
  181. array('id' => 'visible_to_input', 'style' => 'display:none')
  182. );
  183. }
  184. $form->addElement(
  185. 'label',
  186. get_lang('To'),
  187. '<div id="visible_to_read_only_users"></div>',
  188. array('id' => 'visible_to_read_only', 'style' => 'display:none')
  189. );
  190. $form->addElement('label', get_lang('Agenda'), '<div id="color_calendar"></div>');
  191. $form->addElement('label', get_lang('Date'), '<span id="start_date"></span><span id="end_date"></span>');
  192. $form->addElement(
  193. 'label',
  194. get_lang('Title'),
  195. '<input type="text" name="title" id="title" size="40" /><span id="title_edit"></span>'
  196. );
  197. $form->addElement(
  198. 'label',
  199. get_lang('Description'),
  200. '<textarea name="content" id="content" class="span3" rows="5"></textarea>
  201. <span id="content_edit"></span>'
  202. );
  203. if ($type == 'course') {
  204. $form->addElement('html', '<div id="add_as_announcement_div">');
  205. $form->addElement('checkbox', 'add_as_annonuncement', array(null, null, get_lang('AddAsAnnouncement').' ('.get_lang('SendEmail').')'));
  206. $form->addElement('html', '</div>');
  207. }
  208. $tpl->assign('form_add', $form->return_form());
  209. $tpl->display('default/agenda/month.tpl');