agenda.php 13 KB

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