agenda.php 12 KB

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