agenda.php 13 KB

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