agenda.php 12 KB

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