agenda.php 13 KB

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