agenda.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  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');
  12. // use anonymous mode when accessing this course tool
  13. $use_anonymous = true;
  14. require_once '../inc/global.inc.php';
  15. // Functions for the agenda tool
  16. require 'agenda.inc.php';
  17. $current_course_tool = TOOL_CALENDAR_EVENT;
  18. $course_info = api_get_course_info();
  19. if (!empty($course_info)) {
  20. api_protect_course_script(true);
  21. }
  22. $action = isset($_GET['action']) ? $_GET['action'] : null;
  23. $origin = isset($_GET['origin']) ? $_GET['origin'] : null;
  24. $this_section = SECTION_COURSES;
  25. if (empty($action)) {
  26. $url = api_get_path(WEB_CODE_PATH).'calendar/agenda_js.php?type=course';
  27. header("Location: $url");
  28. exit;
  29. }
  30. /*
  31. TREATING THE PARAMETERS
  32. 1. viewing month only or everything
  33. 2. sort ascending or descending
  34. 3. showing or hiding the send-to-specific-groups-or-users form
  35. 4. filter user or group
  36. */
  37. // 3. showing or hiding the send-to-specific-groups-or-users form
  38. $setting_allow_individual_calendar = true;
  39. if (empty($_POST['To']) and empty($_SESSION['allow_individual_calendar'])) {
  40. $_SESSION['allow_individual_calendar'] = "hide";
  41. }
  42. $allow_individual_calendar_status = $_SESSION['allow_individual_calendar'];
  43. if (!empty($_POST['To']) and ($allow_individual_calendar_status == "hide")) {
  44. $_SESSION['allow_individual_calendar'] = "show";
  45. }
  46. if (!empty($_GET['sort']) and ($allow_individual_calendar_status == "show")) {
  47. $_SESSION['allow_individual_calendar'] = "hide";
  48. }
  49. // 4. filter user or group
  50. if (!empty($_GET['user']) or !empty($_GET['group'])) {
  51. $_SESSION['user'] = (int)$_GET['user'];
  52. $_SESSION['group'] = (int)$_GET['group'];
  53. }
  54. if ((!empty($_GET['user']) and $_GET['user'] == "none") or (!empty($_GET['group']) and $_GET['group'] == "none")) {
  55. Session::erase("user");
  56. Session::erase("group");
  57. }
  58. $group_id = api_get_group_id();
  59. //It comes from the group tools. If it's define it overwrites $_SESSION['group']
  60. $htmlHeadXtra[] = to_javascript();
  61. $htmlHeadXtra[] = user_group_filter_javascript();
  62. // setting the name of the tool
  63. $nameTools = get_lang('Agenda'); // language variable in trad4all.inc.php
  64. // showing the header if we are not in the learning path, if we are in
  65. // the learning path, we do not include the banner so we have to explicitly
  66. // include the stylesheet, which is normally done in the header
  67. if (!empty($group_id)) {
  68. $group_properties = GroupManager :: get_group_properties($group_id);
  69. $interbreadcrumb[] = array("url" => "../group/group.php", "name" => get_lang('Groups'));
  70. $interbreadcrumb[] = array(
  71. "url" => "../group/group_space.php?gidReq=".$group_id,
  72. "name" => get_lang('GroupSpace').' '.$group_properties['name']
  73. );
  74. Display::display_header($nameTools, 'Agenda');
  75. } elseif (empty($origin) or $origin != 'learnpath') {
  76. Display::display_header($nameTools, 'Agenda');
  77. }
  78. /*
  79. TRACKING
  80. */
  81. event_access_tool(TOOL_CALENDAR_EVENT);
  82. /* SETTING SOME VARIABLES
  83. */
  84. // Variable definitions
  85. // Defining the shorts for the days. We use camelcase because these are arrays of language variables
  86. $DaysShort = api_get_week_days_short();
  87. // Defining the days of the week to allow translation of the days. We use camelcase because these are arrays of language variables
  88. $DaysLong = api_get_week_days_long();
  89. // Defining the months of the year to allow translation of the months. We use camelcase because these are arrays of language variables
  90. $MonthsLong = api_get_months_long();
  91. // Database table definitions
  92. $TABLEAGENDA = Database::get_course_table(TABLE_AGENDA);
  93. $TABLE_ITEM_PROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY);
  94. $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
  95. $tbl_courseUser = Database::get_main_table(TABLE_MAIN_COURSE_USER);
  96. $tbl_group = Database::get_course_table(TABLE_GROUP);
  97. $tbl_groupUser = Database::get_course_table(TABLE_GROUP_USER);
  98. /* ACCESS RIGHTS */
  99. // permission stuff - also used by loading from global in agenda.inc.php
  100. $is_allowed_to_edit = api_is_allowed_to_edit(false, true) OR (api_get_course_setting(
  101. 'allow_user_edit_agenda'
  102. ) && !api_is_anonymous());
  103. // Tool introduction
  104. Display::display_introduction_section(TOOL_CALENDAR_EVENT);
  105. /* MAIN SECTION */
  106. //setting the default year and month
  107. $select_year = '';
  108. $select_month = '';
  109. $select_day = '';
  110. if (!empty($_GET['year'])) {
  111. $select_year = (int)$_GET['year'];
  112. }
  113. if (!empty($_GET['month'])) {
  114. $select_month = (int)$_GET['month'];
  115. }
  116. if (!empty($_GET['day'])) {
  117. $select_day = (int)$_GET['day'];
  118. }
  119. $today = getdate();
  120. if (empty($select_year)) {
  121. $select_year = $today['year'];
  122. }
  123. if (empty($select_month)) {
  124. $select_month = $today['mon'];
  125. }
  126. echo '<div class="actions">';
  127. if (api_is_allowed_to_edit(false, true) OR
  128. (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous()) && api_is_allowed_to_session_edit(
  129. false,
  130. true
  131. ) OR
  132. GroupManager::user_has_access(
  133. api_get_user_id(),
  134. $group_id,
  135. GroupManager::GROUP_TOOL_CALENDAR
  136. ) && GroupManager::is_tutor_of_group(api_get_user_id(), $group_id)
  137. ) {
  138. echo display_courseadmin_links();
  139. }
  140. echo '</div>';
  141. $event_id = isset($_REQUEST['id']) ? $_REQUEST['id'] : null;
  142. $type = $event_type = isset($_GET['type']) ? $_GET['type'] : null;
  143. if ($type == 'fromjs') {
  144. $id_list = explode('_', $event_id);
  145. $event_id = $id_list[1];
  146. $event_type = $id_list[0];
  147. }
  148. if (!api_is_allowed_to_edit(null, true) && $event_type == 'course') {
  149. api_not_allowed();
  150. }
  151. $course_info = api_get_course_info();
  152. if (api_is_allowed_to_edit(false, true) or
  153. (
  154. api_get_course_setting('allow_user_edit_agenda') &&
  155. !api_is_anonymous() &&
  156. api_is_allowed_to_session_edit(false, true)
  157. ) or
  158. GroupManager::user_has_access(api_get_user_id(), $group_id, GroupManager::GROUP_TOOL_CALENDAR) &&
  159. GroupManager::is_tutor_of_group(api_get_user_id(), $group_id)
  160. ) {
  161. switch ($action) {
  162. case 'add':
  163. if (isset($_POST['submit_event']) && $_POST['submit_event']) {
  164. $startDate = Text::return_datetime_from_array($_POST['start_date']);
  165. $endDate = Text::return_datetime_from_array($_POST['end_date']);
  166. $repeatEndDay = Text::return_datetime_from_array($_POST['repeat_end_day']);
  167. $fileComment = isset($_POST['file_comment']) ? $_POST['file_comment'] : null;
  168. $fileAttachment = isset($_FILES['user_upload']) ? $_FILES['user_upload'] : null;
  169. $agenda = new Agenda();
  170. $agenda->setType('course');
  171. $repeatSettings = array();
  172. if (!empty($_POST['repeat'])) {
  173. $repeatSettings = array(
  174. 'repeat_type' => $_POST['repeat_type'],
  175. 'repeat_end' => $repeatEndDay
  176. );
  177. /*
  178. $res = agenda_add_repeat_item(
  179. $course_info,
  180. $id,
  181. $_POST['repeat_type'],
  182. $repeatEndDay,
  183. $_POST['users'],
  184. $safe_file_comment
  185. );*/
  186. }
  187. $id = $agenda->add_event(
  188. $startDate,
  189. $endDate,
  190. null,
  191. null,
  192. $_POST['title'],
  193. $_POST['content'],
  194. $_POST['users'],
  195. false,
  196. null,
  197. array('comment' => $fileComment, 'file' => $fileAttachment),
  198. $repeatSettings
  199. );
  200. Display::display_confirmation_message(get_lang('AddSuccess'));
  201. } else {
  202. show_add_form();
  203. }
  204. break;
  205. case "announce":
  206. //copying the agenda item into an announcement
  207. if (!(api_is_course_coach() && !api_is_element_in_the_session(TOOL_AGENDA, $event_id))) {
  208. // a coach can only delete an element belonging to his session
  209. $ann_id = store_agenda_item_as_announcement($event_id);
  210. $tool_group_link = (isset($_SESSION['toolgroup']) ? '&toolgroup='.$_SESSION['toolgroup'] : '');
  211. Display::display_normal_message(
  212. get_lang(
  213. 'CopiedAsAnnouncement'
  214. ).'&nbsp;<a href="../announcements/announcements.php?id='.$ann_id.$tool_group_link.'">'.get_lang(
  215. 'NewAnnouncement'
  216. ).'</a>',
  217. false
  218. );
  219. }
  220. break;
  221. case 'importical':
  222. if (isset($_POST['ical_submit'])) {
  223. $ical_name = $_FILES['ical_import']['name'];
  224. $ical_type = $_FILES['ical_import']['type'];
  225. $ext = substr($ical_name, (strrpos($ical_name, ".") + 1));
  226. //$ical_type === 'text/calendar'
  227. if ($ext === 'ics' || $ext === 'ical' || $ext === 'icalendar' || $ext === 'ifb') {
  228. $agenda_result = agenda_import_ical($course_info, $_FILES['ical_import']);
  229. $is_ical = true;
  230. } else {
  231. $is_ical = false;
  232. }
  233. if (!$is_ical) {
  234. Display::display_error_message(get_lang('IsNotiCalFormatFile'));
  235. display_ical_import_form();
  236. break;
  237. } else {
  238. Display::display_confirmation_message(get_lang('AddSuccess'));
  239. echo $agenda_result;
  240. }
  241. } else {
  242. display_ical_import_form();
  243. }
  244. break;
  245. case 'edit':
  246. // a coach can only delete an element belonging to his session
  247. if ($_POST['submit_event']) {
  248. store_edited_agenda_item($event_id, $_REQUEST['id_attach'], $_REQUEST['file_comment']);
  249. $action = 'view';
  250. } else {
  251. show_add_form($event_id, $event_type);
  252. }
  253. break;
  254. case "delete":
  255. if (!(api_is_course_coach() && !api_is_element_in_the_session(TOOL_AGENDA, $event_id))) {
  256. // a coach can only delete an element belonging to his session
  257. delete_agenda_item($event_id);
  258. $action = 'view';
  259. }
  260. break;
  261. case "showhide":
  262. if (!(api_is_course_coach() && !api_is_element_in_the_session(TOOL_AGENDA, $event_id))) {
  263. // a coach can only delete an element belonging to his session
  264. showhide_agenda_item($event_id);
  265. $action = 'view';
  266. }
  267. if (!empty($_GET['agenda_id'])) {
  268. display_one_agenda_item($_GET['agenda_id']);
  269. }
  270. break;
  271. case "delete_attach": //delete attachment file
  272. $id_attach = $_GET['id_attach'];
  273. if (!empty($id_attach)) {
  274. delete_attachment_file($id_attach);
  275. $action = 'view';
  276. }
  277. break;
  278. }
  279. }
  280. // The footer is displayed only if we are not in the learnpath
  281. if ($origin != 'learnpath') {
  282. Display::display_footer();
  283. }