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