agenda.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  1. <?php //$Id: agenda.php 22201 2009-07-17 19:57:03Z cfasanando $
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004-2008 Dokeos SPRL
  6. Copyright (c) 2003-2005 Ghent University (UGent)
  7. Copyright (c) various contributors
  8. For a full list of contributors, see "credits.txt".
  9. The full license can be read in "license.txt".
  10. This program is free software; you can redistribute it and/or
  11. modify it under the terms of the GNU General Public License
  12. as published by the Free Software Foundation; either version 2
  13. of the License, or (at your option) any later version.
  14. See the GNU General Public License for more details.
  15. Contact address: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium
  16. Mail: info@dokeos.com
  17. ==============================================================================
  18. */
  19. /*
  20. ==============================================================================
  21. INIT SECTION
  22. ==============================================================================
  23. */
  24. // name of the language file that needs to be included
  25. $language_file = array('agenda','group');
  26. // use anonymous mode when accessing this course tool
  27. $use_anonymous = true;
  28. // setting the global file that gets the general configuration, the databases, the languages, ...
  29. include('../inc/global.inc.php');
  30. //session
  31. if(isset($_GET['id_session']))
  32. {
  33. $_SESSION['id_session'] = Security::remove_XSS($_GET['id_session']);
  34. }
  35. $this_section=SECTION_COURSES;
  36. //error_reporting(E_ALL);
  37. require (api_get_path(LIBRARY_PATH).'groupmanager.lib.php');
  38. /* ==============================================================================
  39. ACCESS RIGHTS
  40. ============================================================================== */
  41. // notice for unauthorized people.
  42. api_protect_course_script();
  43. /*
  44. -----------------------------------------------------------
  45. Resource linker (Patrick Cool, march 2004)
  46. -----------------------------------------------------------
  47. */
  48. $_SESSION['source_type'] = 'Agenda';
  49. require_once '../resourcelinker/resourcelinker.inc.php';
  50. require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
  51. if (!empty($addresources)) // When the "Add Resource" button is clicked we store all the form data into a session
  52. {
  53. $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']),
  54. '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']),
  55. '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']));
  56. $_SESSION['formelements']=$form_elements;
  57. // this is to correctly handle edits
  58. if($id){$action="edit";}
  59. //print_r($form_elements);
  60. header('Location: '.api_get_path(WEB_CODE_PATH)."resourcelinker/resourcelinker.php?source_id=1&action=$action&id=$id&originalresource=no");
  61. exit;
  62. }
  63. if (!empty($_GET['view'])) {
  64. $_SESSION['view'] = Security::remove_XSS($_GET['view']);
  65. }
  66. /*
  67. -----------------------------------------------------------
  68. Libraries
  69. -----------------------------------------------------------
  70. */
  71. // containing the functions for the agenda tool
  72. include "agenda.inc.php";
  73. // some debug functions
  74. include($includePath."/lib/debug.lib.inc.php");
  75. /*==============================================================================
  76. TREATING THE PARAMETERS
  77. 1. viewing month only or everything
  78. 2. sort ascending or descending
  79. 3. showing or hiding the send-to-specific-groups-or-users form
  80. 4. filter user or group
  81. ============================================================================== */
  82. // 1. show all or show current month?
  83. if (!$_SESSION['show'])
  84. {
  85. $_SESSION['show']="showall";
  86. }
  87. if (!empty($_GET['action']) and $_GET['action']=="showcurrent")
  88. {
  89. $_SESSION['show']="showcurrent";
  90. }
  91. if (!empty($_GET['action']) and $_GET['action']=="showall")
  92. {
  93. $_SESSION['show']="showall";
  94. }
  95. //echo $_SESSION['show'];
  96. // 2. sorting order (ASC or DESC)
  97. if (empty($_GET['sort']) and empty($_SESSION['sort']))
  98. {
  99. $_SESSION['sort']="DESC";
  100. }
  101. if (!empty($_GET['sort']) and $_GET['sort']=="asc")
  102. {
  103. $_SESSION['sort']="ASC";
  104. }
  105. if (!empty($_GET['sort']) and $_GET['sort']=="desc")
  106. {
  107. $_SESSION['sort']="DESC";
  108. }
  109. // 3. showing or hiding the send-to-specific-groups-or-users form
  110. $setting_allow_individual_calendar=true;
  111. if (empty($_POST['To']) and empty($_SESSION['allow_individual_calendar']))
  112. {
  113. $_SESSION['allow_individual_calendar']="hide";
  114. }
  115. $allow_individual_calendar_status=$_SESSION['allow_individual_calendar'];
  116. if (!empty($_POST['To']) and ($allow_individual_calendar_status=="hide"))
  117. {
  118. $_SESSION['allow_individual_calendar']="show";
  119. }
  120. if (!empty($_GET['sort']) and ($allow_individual_calendar_status=="show"))
  121. {
  122. $_SESSION['allow_individual_calendar']="hide";
  123. }
  124. // 4. filter user or group
  125. if (!empty($_GET['user']) or !empty($_GET['group']))
  126. {
  127. $_SESSION['user']=(int)$_GET['user'];
  128. $_SESSION['group']=(int)$_GET['group'];
  129. }
  130. if ((!empty($_GET['user']) and $_GET['user']=="none") or (!empty($_GET['group']) and $_GET['group']=="none"))
  131. {
  132. api_session_unregister("user");
  133. api_session_unregister("group");
  134. }
  135. if (!$is_courseAdmin){
  136. if (!empty($_GET['toolgroup'])){
  137. //$_SESSION['toolgroup']=$_GET['toolgroup'];
  138. $toolgroup=Security::remove_XSS($_GET['toolgroup']);
  139. api_session_register('toolgroup');
  140. }
  141. }
  142. //It comes from the group tools. If it's define it overwrites $_SESSION['group']
  143. if (!empty($_GET['isStudentView']) and $_GET['isStudentView']=="false")
  144. {
  145. api_session_unregister("user");
  146. api_session_unregister("group");
  147. }
  148. $htmlHeadXtra[] = to_javascript();
  149. $htmlHeadXtra[] = user_group_filter_javascript();
  150. // this loads the javascript that is needed for the date popup selection
  151. $htmlHeadXtra[] = "<script src=\"tbl_change.js\" type=\"text/javascript\" language=\"javascript\"></script>";
  152. // setting the name of the tool
  153. $nameTools = get_lang('Agenda'); // language variable in trad4all.inc.php
  154. // showing the header if we are not in the learning path, if we are in
  155. // the learning path, we do not include the banner so we have to explicitly
  156. // include the stylesheet, which is normally done in the header
  157. if (isset($_GET['toolgroup']) && $_GET['toolgroup']==strval(intval($_GET['toolgroup'])) ){
  158. $_clean['toolgroup']=(int)$_GET['toolgroup'];
  159. $group_properties = GroupManager :: get_group_properties($_clean['toolgroup']);
  160. $interbreadcrumb[] = array ("url" => "../group/group.php", "name" => get_lang('Groups'));
  161. $interbreadcrumb[] = array ("url"=>"../group/group_space.php?gidReq=".Security::remove_XSS($_GET['toolgroup']), "name"=> get_lang('GroupSpace').' ('.$group_properties['name'].')');
  162. Display::display_header($nameTools,'Agenda');
  163. } elseif (empty($_GET['origin']) or $_GET['origin'] != 'learnpath') {
  164. Display::display_header($nameTools,'Agenda');
  165. } else {
  166. echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"".$clarolineRepositoryWeb."css/default.css\"/>";
  167. }
  168. /* ==============================================================================
  169. TRACKING
  170. ============================================================================== */
  171. event_access_tool(TOOL_CALENDAR_EVENT);
  172. /* ==============================================================================
  173. SETTING SOME VARIABLES
  174. ============================================================================== */
  175. // Variable definitions
  176. $dateNow = format_locale_date($dateTimeFormatLong);
  177. // Defining the shorts for the days. We use camelcase because these are arrays of language variables
  178. $DaysShort = api_get_week_days_short();
  179. // Defining the days of the week to allow translation of the days. We use camelcase because these are arrays of language variables
  180. $DaysLong = api_get_week_days_long();
  181. // Defining the months of the year to allow translation of the months. We use camelcase because these are arrays of language variables
  182. $MonthsLong = api_get_months_long();
  183. // Database table definitions
  184. $TABLEAGENDA = Database::get_course_table(TABLE_AGENDA);
  185. $TABLE_ITEM_PROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY);
  186. $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
  187. $tbl_courseUser = Database::get_main_table(TABLE_MAIN_COURSE_USER);
  188. $tbl_group = Database::get_course_table(TABLE_GROUP);
  189. $tbl_groupUser = Database::get_course_table(TABLE_GROUP_USER);
  190. $tbl_session_course_user= Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  191. /* ==============================================================================
  192. ACCESS RIGHTS
  193. ============================================================================== */
  194. // permission stuff - also used by loading from global in agenda.inc.php
  195. $is_allowed_to_edit = api_is_allowed_to_edit(false,true) OR (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous());
  196. /* ==============================================================================
  197. TITLE
  198. ============================================================================== */
  199. // Displaying the title of the tool
  200. //api_display_tool_title($nameTools);
  201. // Tool introduction
  202. Display::display_introduction_section(TOOL_CALENDAR_EVENT);
  203. // insert an anchor (top) so one can jump back to the top of the page
  204. echo '<a name="top"></a>';
  205. /*
  206. ==============================================================================
  207. MAIN SECTION
  208. ==============================================================================
  209. */
  210. //setting the default year and month
  211. $select_year = '';
  212. $select_month = '';
  213. if(!empty($_GET['year']))
  214. {
  215. $select_year = (int)$_GET['year'];
  216. }
  217. if(!empty($_GET['month']))
  218. {
  219. $select_month = (int)$_GET['month'];
  220. }
  221. if (empty($select_year) && empty($select_month))
  222. {
  223. $today = getdate();
  224. $select_year = $today['year'];
  225. $select_month = $today['mon'];
  226. }
  227. echo '<div class="actions">';
  228. 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)) {
  229. display_courseadmin_links();
  230. }
  231. display_student_links();
  232. echo '</div>';
  233. 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)))
  234. {
  235. switch ($_GET['action'])
  236. {
  237. case "importical":
  238. if(isset($_POST['ical_submit']))
  239. {
  240. $course_info = api_get_course_info();
  241. $ical_name = $_FILES['ical_import']['name'];
  242. $ical_type = $_FILES['ical_import']['type'];
  243. $ext = substr($ical_name,(strrpos($ical_name,".")+1));
  244. if ($ical_type === 'text/calendar' || $ext === 'ics') {
  245. agenda_import_ical($course_info,$_FILES['ical_import']);
  246. $is_ical = true;
  247. } else {
  248. $is_ical = false;
  249. }
  250. }
  251. break;
  252. case 'add':
  253. if($_POST['submit_event'])
  254. {
  255. $course_info = api_get_course_info();
  256. $event_start = (int) $_POST['fyear'].'-'.(int) $_POST['fmonth'].'-'.(int) $_POST['fday'].' '.(int) $_POST['fhour'].':'.(int) $_POST['fminute'].':00';
  257. $event_stop = (int) $_POST['end_fyear'].'-'.(int) $_POST['end_fmonth'].'-'.(int) $_POST['end_fday'].' '.(int) $_POST['end_fhour'].':'.(int) $_POST['end_fminute'].':00';
  258. $safe_title = Security::remove_XSS($_POST['title']);
  259. $safe_file_comment = Security::remove_XSS($_POST['file_comment']);
  260. $id = agenda_add_item($course_info,$safe_title,$_POST['content'],$event_start,$event_stop,$_POST['selectedform'],false,$safe_file_comment);
  261. if(!empty($_POST['repeat']))
  262. {
  263. $end_y = intval($_POST['repeat_end_year']);
  264. $end_m = intval($_POST['repeat_end_month']);
  265. $end_d = intval($_POST['repeat_end_day']);
  266. $end = mktime(23, 59, 59, $end_m, $end_d, $end_y);
  267. $res = agenda_add_repeat_item($course_info,$id,Security::remove_XSS($_POST['repeat_type']),$end,Security::remove_XSS($_POST['selectedform']),$safe_file_comment);
  268. }
  269. }
  270. break;
  271. case "edit":
  272. if( ! (api_is_course_coach() && !api_is_element_in_the_session(TOOL_AGENDA, intval($_REQUEST['id']) ) ) )
  273. { // a coach can only delete an element belonging to his session
  274. if ($_POST['submit_event'])
  275. { $my_id_attach = (int)$_REQUEST['id_attach'];
  276. $safe_file_comment = Security::remove_XSS($_REQUEST['file_comment']);
  277. store_edited_agenda_item($my_id_attach,$safe_file_comment);
  278. }
  279. }
  280. break;
  281. case "delete":
  282. $id=(int)$_GET['id'];
  283. if( ! (api_is_course_coach() && !api_is_element_in_the_session(TOOL_AGENDA, $id ) ) )
  284. { // a coach can only delete an element belonging to his session
  285. delete_agenda_item($id);
  286. }
  287. break;
  288. case "showhide":
  289. $id=(int)$_GET['id'];
  290. if( ! (api_is_course_coach() && !api_is_element_in_the_session(TOOL_AGENDA, $id ) ) )
  291. { // a coach can only delete an element belonging to his session
  292. showhide_agenda_item($id);
  293. }
  294. break;
  295. case "announce": //copying the agenda item into an announcement
  296. $id=(int)$_GET['id'];
  297. if( ! (api_is_course_coach() && !api_is_element_in_the_session(TOOL_AGENDA, $id ) ) )
  298. { // a coach can only delete an element belonging to his session
  299. $ann_id = store_agenda_item_as_announcement($id);
  300. $tool_group_link = (isset($_SESSION['toolgroup'])?'&toolgroup='.$_SESSION['toolgroup']:'');
  301. Display::display_normal_message(get_lang('CopiedAsAnnouncement').'&nbsp;<a href="../announcements/announcements.php?id='.$ann_id.$tool_group_link.'">'.get_lang('NewAnnouncement').'</a>', false);
  302. }
  303. break;
  304. case "delete_attach": //delete attachment file
  305. $id_attach = (int)$_GET['id_attach'];
  306. if (!empty($id_attach)) {
  307. delete_attachment_file($id_attach);
  308. }
  309. break;
  310. }
  311. }
  312. echo '<table width="100%" border="0" cellspacing="0" cellpadding="0">'
  313. . '<tr>';
  314. // THE LEFT PART
  315. if (empty($_GET['origin']) or $_GET['origin']!='learnpath')
  316. {
  317. echo '<td width="220" height="19" valign="top">';
  318. // the small calendar
  319. $MonthName = $MonthsLong[$select_month -1];
  320. $agenda_items=get_calendar_items($select_month,$select_year);
  321. if (api_get_setting('display_mini_month_calendar') == 'true')
  322. {
  323. display_minimonthcalendar($agenda_items, $select_month,$select_year, $MonthName);
  324. }
  325. echo '<br />';
  326. if (api_get_setting('display_upcoming_events') == 'true') {
  327. display_upcoming_events();
  328. }
  329. echo '</td>';
  330. echo '<td width="20" background="../img/verticalruler.gif">&nbsp;</td>';
  331. }
  332. // THE RIGHT PART
  333. echo '<td valign="top">';
  334. echo '<div class="sort" style="float:left">';
  335. echo '</div>';
  336. 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) )) {
  337. switch ($_GET['action']) {
  338. case 'importical' :
  339. if (isset($_POST['ical_submit'])) {
  340. if (!$is_ical) {
  341. Display::display_error_message(get_lang('IsNotiCalFormatFile'));
  342. display_ical_import_form();
  343. break;
  344. }
  345. display_agenda_items();
  346. }
  347. else {
  348. display_ical_import_form();
  349. }
  350. break;
  351. case 'add' :
  352. if ($_POST['submit_event']) {
  353. display_agenda_items();
  354. } else {
  355. show_add_form();
  356. }
  357. break;
  358. case 'edit' :
  359. if ( !(api_is_course_coach() && !api_is_element_in_the_session(TOOL_AGENDA, intval($_REQUEST['id'])))) {
  360. if ($_POST['submit_event']) {
  361. display_agenda_items();
  362. }
  363. else {
  364. $id=(int)$_GET['id'];
  365. show_add_form($id);
  366. }
  367. } else {
  368. display_agenda_items();
  369. }
  370. break;
  371. case 'delete':
  372. display_agenda_items();
  373. break;
  374. case 'showhide':
  375. if(!empty($_GET['agenda_id']))
  376. {
  377. display_one_agenda_item((int)$_GET['agenda_id']);
  378. }
  379. else
  380. {
  381. display_agenda_items();
  382. }
  383. break;
  384. case 'announce': display_agenda_items();
  385. break;
  386. case 'delete_attach': display_agenda_items();
  387. break;
  388. }
  389. }
  390. // this is for students and whenever the courseaministrator has not chosen any action. It is in fact the default behaviour
  391. if (!$_GET['action'] || $_GET['action']=="showall" || $_GET['action']=="showcurrent" || $_GET['action']=="view")
  392. {
  393. if ($_GET['origin'] != 'learnpath')
  394. {
  395. if (!$_SESSION['view'] || $_SESSION['view'] <> 'month')
  396. {
  397. if(!empty($_GET['agenda_id']))
  398. {
  399. display_one_agenda_item((int)$_GET['agenda_id']);
  400. }
  401. else
  402. {
  403. display_agenda_items();
  404. }
  405. }
  406. else
  407. {
  408. display_monthcalendar($select_month, $select_year);
  409. }
  410. }
  411. else
  412. {
  413. display_one_agenda_item((int)$_GET['agenda_id']);
  414. }
  415. }
  416. echo '&nbsp;</td></tr></table>';
  417. /*
  418. ==============================================================================
  419. FOOTER
  420. ==============================================================================
  421. */
  422. // The footer is displayed only if we are not in the learnpath
  423. if ($_GET['origin'] != 'learnpath')
  424. {
  425. Display::display_footer();
  426. }
  427. ?>