agenda.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  1. <?php //$Id: agenda.php 21101 2009-05-30 14:56:54Z iflorespaz $
  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. require_once '../inc/lib/events.lib.inc.php';
  172. event_access_tool(TOOL_CALENDAR_EVENT);
  173. /* ==============================================================================
  174. SETTING SOME VARIABLES
  175. ============================================================================== */
  176. // Variable definitions
  177. $dateNow = format_locale_date($dateTimeFormatLong);
  178. // Defining the shorts for the days. We use camelcase because these are arrays of language variables
  179. $DaysShort = array (get_lang("SundayShort"), get_lang("MondayShort"), get_lang("TuesdayShort"), get_lang("WednesdayShort"), get_lang("ThursdayShort"), get_lang("FridayShort"), get_lang("SaturdayShort"));
  180. // Defining the days of the week to allow translation of the days. We use camelcase because these are arrays of language variables
  181. $DaysLong = array (get_lang("SundayLong"), get_lang("MondayLong"), get_lang("TuesdayLong"), get_lang("WednesdayLong"), get_lang("ThursdayLong"), get_lang("FridayLong"), get_lang("SaturdayLong"));
  182. // Defining the months of the year to allow translation of the months. We use camelcase because these are arrays of language variables
  183. $MonthsLong = array (get_lang("JanuaryLong"), get_lang("FebruaryLong"), get_lang("MarchLong"), get_lang("AprilLong"), get_lang("MayLong"), get_lang("JuneLong"), get_lang("JulyLong"), get_lang("AugustLong"), get_lang("SeptemberLong"), get_lang("OctoberLong"), get_lang("NovemberLong"), get_lang("DecemberLong"));
  184. // Database table definitions
  185. $TABLEAGENDA = Database::get_course_table(TABLE_AGENDA);
  186. $TABLE_ITEM_PROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY);
  187. $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
  188. $tbl_courseUser = Database::get_main_table(TABLE_MAIN_COURSE_USER);
  189. $tbl_group = Database::get_course_table(TABLE_GROUP);
  190. $tbl_groupUser = Database::get_course_table(TABLE_GROUP_USER);
  191. $tbl_session_course_user= Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  192. /* ==============================================================================
  193. ACCESS RIGHTS
  194. ============================================================================== */
  195. // permission stuff - also used by loading from global in agenda.inc.php
  196. $is_allowed_to_edit = api_is_allowed_to_edit(false,true) OR (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous());
  197. /* ==============================================================================
  198. TITLE
  199. ============================================================================== */
  200. // Displaying the title of the tool
  201. //api_display_tool_title($nameTools);
  202. // Tool introduction
  203. $fck_attribute['Width'] = '100%';
  204. $fck_attribute['Height'] = '300';
  205. $fck_attribute['ToolbarSet'] = 'Introduction';
  206. Display::display_introduction_section(TOOL_CALENDAR_EVENT);
  207. $fck_attribute = null; // Clearing this global variable immediatelly after it has been used.
  208. // insert an anchor (top) so one can jump back to the top of the page
  209. echo '<a name="top"></a>';
  210. /*
  211. ==============================================================================
  212. MAIN SECTION
  213. ==============================================================================
  214. */
  215. //setting the default year and month
  216. $select_year = '';
  217. $select_month = '';
  218. if(!empty($_GET['year']))
  219. {
  220. $select_year = (int)$_GET['year'];
  221. }
  222. if(!empty($_GET['month']))
  223. {
  224. $select_month = (int)$_GET['month'];
  225. }
  226. if (empty($select_year) && empty($select_month))
  227. {
  228. $today = getdate();
  229. $select_year = $today['year'];
  230. $select_month = $today['mon'];
  231. }
  232. echo '<div class="actions">';
  233. display_student_links();
  234. if (api_is_allowed_to_edit(false,true) OR (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous()))
  235. {
  236. display_courseadmin_links();
  237. }
  238. echo '</div><br />';
  239. if (api_is_allowed_to_edit(false,true) OR (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous()))
  240. {
  241. switch ($_GET['action'])
  242. {
  243. case "importical":
  244. if(isset($_POST['ical_submit']))
  245. {
  246. $course_info = api_get_course_info();
  247. $ical_name = $_FILES['ical_import']['name'];
  248. $ical_type = $_FILES['ical_import']['type'];
  249. $ext = substr($ical_name,(strrpos($ical_name,".")+1));
  250. if ($ical_type === 'text/calendar' || $ext === 'ics') {
  251. agenda_import_ical($course_info,$_FILES['ical_import']);
  252. $is_ical = true;
  253. } else {
  254. $is_ical = false;
  255. }
  256. }
  257. break;
  258. case 'add':
  259. if($_POST['submit_event'])
  260. {
  261. $course_info = api_get_course_info();
  262. $event_start = (int) $_POST['fyear'].'-'.(int) $_POST['fmonth'].'-'.(int) $_POST['fday'].' '.(int) $_POST['fhour'].':'.(int) $_POST['fminute'].':00';
  263. $event_stop = (int) $_POST['end_fyear'].'-'.(int) $_POST['end_fmonth'].'-'.(int) $_POST['end_fday'].' '.(int) $_POST['end_fhour'].':'.(int) $_POST['end_fminute'].':00';
  264. $safe_title = Security::remove_XSS($_POST['title']);
  265. $safe_file_comment = Security::remove_XSS($_POST['file_comment']);
  266. $id = agenda_add_item($course_info,$safe_title,$_POST['content'],$event_start,$event_stop,$_POST['selectedform'],false,$safe_file_comment);
  267. if(!empty($_POST['repeat']))
  268. {
  269. $end_y = intval($_POST['repeat_end_year']);
  270. $end_m = intval($_POST['repeat_end_month']);
  271. $end_d = intval($_POST['repeat_end_day']);
  272. $end = mktime(23, 59, 59, $end_m, $end_d, $end_y);
  273. $res = agenda_add_repeat_item($course_info,$id,Security::remove_XSS($_POST['repeat_type']),$end,Security::remove_XSS($_POST['selectedform']),$safe_file_comment);
  274. }
  275. }
  276. break;
  277. case "edit":
  278. if( ! (api_is_course_coach() && !api_is_element_in_the_session(TOOL_AGENDA, intval($_REQUEST['id']) ) ) )
  279. { // a coach can only delete an element belonging to his session
  280. if ($_POST['submit_event'])
  281. { $my_id_attach = (int)$_REQUEST['id_attach'];
  282. $safe_file_comment = Security::remove_XSS($_REQUEST['file_comment']);
  283. store_edited_agenda_item($my_id_attach,$safe_file_comment);
  284. }
  285. }
  286. break;
  287. case "delete":
  288. $id=(int)$_GET['id'];
  289. if( ! (api_is_course_coach() && !api_is_element_in_the_session(TOOL_AGENDA, $id ) ) )
  290. { // a coach can only delete an element belonging to his session
  291. delete_agenda_item($id);
  292. }
  293. break;
  294. case "showhide":
  295. $id=(int)$_GET['id'];
  296. if( ! (api_is_course_coach() && !api_is_element_in_the_session(TOOL_AGENDA, $id ) ) )
  297. { // a coach can only delete an element belonging to his session
  298. showhide_agenda_item($id);
  299. }
  300. break;
  301. case "announce": //copying the agenda item into an announcement
  302. $id=(int)$_GET['id'];
  303. if( ! (api_is_course_coach() && !api_is_element_in_the_session(TOOL_AGENDA, $id ) ) )
  304. { // a coach can only delete an element belonging to his session
  305. $ann_id = store_agenda_item_as_announcement($id);
  306. $tool_group_link = (isset($_SESSION['toolgroup'])?'&toolgroup='.$_SESSION['toolgroup']:'');
  307. Display::display_normal_message(get_lang('CopiedAsAnnouncement').'&nbsp;<a href="../announcements/announcements.php?id='.$ann_id.$tool_group_link.'">'.get_lang('NewAnnouncement').'</a>', false);
  308. }
  309. break;
  310. case "delete_attach": //delete attachment file
  311. $id_attach = (int)$_GET['id_attach'];
  312. if (!empty($id_attach)) {
  313. delete_attachment_file($id_attach);
  314. }
  315. break;
  316. }
  317. }
  318. echo '<table width="100%" border="0" cellspacing="0" cellpadding="0">'
  319. . '<tr>';
  320. // THE LEFT PART
  321. if (empty($_GET['origin']) or $_GET['origin']!='learnpath')
  322. {
  323. echo '<td width="220" height="19" valign="top">';
  324. // the small calendar
  325. $MonthName = $MonthsLong[$select_month -1];
  326. $agenda_items=get_calendar_items($select_month,$select_year);
  327. if (api_get_setting('display_mini_month_calendar') == 'true')
  328. {
  329. display_minimonthcalendar($agenda_items, $select_month,$select_year, $MonthName);
  330. }
  331. echo '<br />';
  332. if (api_get_setting('display_upcoming_events') == 'true') {
  333. display_upcoming_events();
  334. }
  335. echo '</td>';
  336. echo '<td width="20" background="../img/verticalruler.gif">&nbsp;</td>';
  337. }
  338. // THE RIGHT PART
  339. echo '<td valign="top">';
  340. echo '<div class="sort" style="float:left">';
  341. echo '</div>';
  342. if (api_is_allowed_to_edit(false,true) OR (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous())) {
  343. switch ($_GET['action']) {
  344. case 'importical' :
  345. if (isset($_POST['ical_submit'])) {
  346. if (!$is_ical) {
  347. Display::display_error_message(get_lang('IsNotiCalFormatFile'));
  348. display_ical_import_form();
  349. break;
  350. }
  351. display_agenda_items();
  352. }
  353. else {
  354. display_ical_import_form();
  355. }
  356. break;
  357. case 'add' :
  358. if ($_POST['submit_event']) {
  359. display_agenda_items();
  360. } else {
  361. show_add_form();
  362. }
  363. break;
  364. case 'edit' :
  365. if ( !(api_is_course_coach() && !api_is_element_in_the_session(TOOL_AGENDA, intval($_REQUEST['id'])))) {
  366. if ($_POST['submit_event']) {
  367. display_agenda_items();
  368. }
  369. else {
  370. $id=(int)$_GET['id'];
  371. show_add_form($id);
  372. }
  373. } else {
  374. display_agenda_items();
  375. }
  376. break;
  377. case 'delete':
  378. display_agenda_items();
  379. break;
  380. case 'showhide':
  381. display_agenda_items();
  382. break;
  383. case 'announce': display_agenda_items();
  384. break;
  385. case 'delete_attach': display_agenda_items();
  386. break;
  387. }
  388. }
  389. // this is for students and whenever the courseaministrator has not chosen any action. It is in fact the default behaviour
  390. if (!$_GET['action'] || $_GET['action']=="showall" || $_GET['action']=="showcurrent" || $_GET['action']=="view")
  391. {
  392. if ($_GET['origin'] != 'learnpath')
  393. {
  394. if (!$_SESSION['view'] || $_SESSION['view'] <> 'month')
  395. {
  396. if(!empty($_GET['agenda_id']))
  397. {
  398. display_one_agenda_item((int)$_GET['agenda_id']);
  399. }
  400. else
  401. {
  402. display_agenda_items();
  403. }
  404. }
  405. else
  406. {
  407. display_monthcalendar($select_month, $select_year);
  408. }
  409. }
  410. else
  411. {
  412. display_one_agenda_item((int)$_GET['agenda_id']);
  413. }
  414. }
  415. echo '&nbsp;</td></tr></table>';
  416. /*
  417. ==============================================================================
  418. FOOTER
  419. ==============================================================================
  420. */
  421. // The footer is displayed only if we are not in the learnpath
  422. if ($_GET['origin'] != 'learnpath')
  423. {
  424. Display::display_footer();
  425. }
  426. ?>