agenda.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  1. <?php //$Id: agenda.php 20413 2009-05-08 16:23:16Z 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'] = $_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. include('../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'=>$_POST['fday'], 'month'=>$_POST['fmonth'], 'year'=>$_POST['fyear'], 'hour'=>$_POST['fhour'], 'minutes'=>$_POST['fminute'],
  54. 'end_day'=>$_POST['end_fday'], 'end_month'=>$_POST['end_fmonth'], 'end_year'=>$_POST['end_fyear'], 'end_hours'=>$_POST['end_fhour'], 'end_minutes'=>$_POST['end_fminute'],
  55. 'title'=>stripslashes($_POST['title']), 'content'=>stripslashes($_POST['content']), 'id'=>$_POST['id'], 'action'=>$_POST['action'], 'to'=>$_POST['selectedform']);
  56. $_SESSION['formelements']=$form_elements;
  57. if($id) // this is to correctly handle edits
  58. {$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. {
  65. $_SESSION['view'] = $_GET['view'];
  66. }
  67. /*
  68. -----------------------------------------------------------
  69. Libraries
  70. -----------------------------------------------------------
  71. */
  72. // containing the functions for the agenda tool
  73. include "agenda.inc.php";
  74. // some debug functions
  75. include($includePath."/lib/debug.lib.inc.php");
  76. /*==============================================================================
  77. TREATING THE PARAMETERS
  78. 1. viewing month only or everything
  79. 2. sort ascending or descending
  80. 3. showing or hiding the send-to-specific-groups-or-users form
  81. 4. filter user or group
  82. ============================================================================== */
  83. // 1. show all or show current month?
  84. if (!$_SESSION['show'])
  85. {
  86. $_SESSION['show']="showall";
  87. }
  88. if (!empty($_GET['action']) and $_GET['action']=="showcurrent")
  89. {
  90. $_SESSION['show']="showcurrent";
  91. }
  92. if (!empty($_GET['action']) and $_GET['action']=="showall")
  93. {
  94. $_SESSION['show']="showall";
  95. }
  96. //echo $_SESSION['show'];
  97. // 2. sorting order (ASC or DESC)
  98. if (empty($_GET['sort']) and empty($_SESSION['sort']))
  99. {
  100. $_SESSION['sort']="DESC";
  101. }
  102. if (!empty($_GET['sort']) and $_GET['sort']=="asc")
  103. {
  104. $_SESSION['sort']="ASC";
  105. }
  106. if (!empty($_GET['sort']) and $_GET['sort']=="desc")
  107. {
  108. $_SESSION['sort']="DESC";
  109. }
  110. // 3. showing or hiding the send-to-specific-groups-or-users form
  111. $setting_allow_individual_calendar=true;
  112. if (empty($_POST['To']) and empty($_SESSION['allow_individual_calendar']))
  113. {
  114. $_SESSION['allow_individual_calendar']="hide";
  115. }
  116. $allow_individual_calendar_status=$_SESSION['allow_individual_calendar'];
  117. if (!empty($_POST['To']) and ($allow_individual_calendar_status=="hide"))
  118. {
  119. $_SESSION['allow_individual_calendar']="show";
  120. }
  121. if (!empty($_GET['sort']) and ($allow_individual_calendar_status=="show"))
  122. {
  123. $_SESSION['allow_individual_calendar']="hide";
  124. }
  125. // 4. filter user or group
  126. if (!empty($_GET['user']) or !empty($_GET['group']))
  127. {
  128. $_SESSION['user']=(int)$_GET['user'];
  129. $_SESSION['group']=(int)$_GET['group'];
  130. }
  131. if ((!empty($_GET['user']) and $_GET['user']=="none") or (!empty($_GET['group']) and $_GET['group']=="none"))
  132. {
  133. api_session_unregister("user");
  134. api_session_unregister("group");
  135. }
  136. if (!$is_courseAdmin){
  137. if (!empty($_GET['toolgroup'])){
  138. //$_SESSION['toolgroup']=$_GET['toolgroup'];
  139. $toolgroup=$_GET['toolgroup'];
  140. api_session_register('toolgroup');
  141. }
  142. }
  143. //It comes from the group tools. If it's define it overwrites $_SESSION['group']
  144. if (!empty($_GET['isStudentView']) and $_GET['isStudentView']=="false")
  145. {
  146. api_session_unregister("user");
  147. api_session_unregister("group");
  148. }
  149. $htmlHeadXtra[] = to_javascript();
  150. $htmlHeadXtra[] = user_group_filter_javascript();
  151. // this loads the javascript that is needed for the date popup selection
  152. $htmlHeadXtra[] = "<script src=\"tbl_change.js\" type=\"text/javascript\" language=\"javascript\"></script>";
  153. // setting the name of the tool
  154. $nameTools = get_lang('Agenda'); // language variable in trad4all.inc.php
  155. // showing the header if we are not in the learning path, if we are in
  156. // the learning path, we do not include the banner so we have to explicitly
  157. // include the stylesheet, which is normally done in the header
  158. if ($_GET['toolgroup']){
  159. $_clean['toolgroup']=(int)$_GET['toolgroup'];
  160. $group_properties = GroupManager :: get_group_properties($_clean['toolgroup']);
  161. $interbreadcrumb[] = array ("url" => "../group/group.php", "name" => get_lang('Groups'));
  162. $interbreadcrumb[] = array ("url"=>"../group/group_space.php?gidReq=".$_SESSION['toolgroup'], "name"=> get_lang('GroupSpace').' ('.$group_properties['name'].')');
  163. Display::display_header($nameTools,'Agenda');
  164. } elseif (empty($_GET['origin']) or $_GET['origin'] != 'learnpath') {
  165. Display::display_header($nameTools,'Agenda');
  166. } else {
  167. echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"".$clarolineRepositoryWeb."css/default.css\"/>";
  168. }
  169. /* ==============================================================================
  170. TRACKING
  171. ============================================================================== */
  172. require_once '../inc/lib/events.lib.inc.php';
  173. event_access_tool(TOOL_CALENDAR_EVENT);
  174. /* ==============================================================================
  175. SETTING SOME VARIABLES
  176. ============================================================================== */
  177. // Variable definitions
  178. $dateNow = format_locale_date($dateTimeFormatLong);
  179. // Defining the shorts for the days. We use camelcase because these are arrays of language variables
  180. $DaysShort = array (get_lang("SundayShort"), get_lang("MondayShort"), get_lang("TuesdayShort"), get_lang("WednesdayShort"), get_lang("ThursdayShort"), get_lang("FridayShort"), get_lang("SaturdayShort"));
  181. // Defining the days of the week to allow translation of the days. We use camelcase because these are arrays of language variables
  182. $DaysLong = array (get_lang("SundayLong"), get_lang("MondayLong"), get_lang("TuesdayLong"), get_lang("WednesdayLong"), get_lang("ThursdayLong"), get_lang("FridayLong"), get_lang("SaturdayLong"));
  183. // Defining the months of the year to allow translation of the months. We use camelcase because these are arrays of language variables
  184. $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"));
  185. // Database table definitions
  186. $TABLEAGENDA = Database::get_course_table(TABLE_AGENDA);
  187. $TABLE_ITEM_PROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY);
  188. $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
  189. $tbl_courseUser = Database::get_main_table(TABLE_MAIN_COURSE_USER);
  190. $tbl_group = Database::get_course_table(TABLE_GROUP);
  191. $tbl_groupUser = Database::get_course_table(TABLE_GROUP_USER);
  192. $tbl_session_course_user= Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  193. /* ==============================================================================
  194. ACCESS RIGHTS
  195. ============================================================================== */
  196. // permission stuff - also used by loading from global in agenda.inc.php
  197. $is_allowed_to_edit = api_is_allowed_to_edit(false,true) OR (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous());
  198. /* ==============================================================================
  199. TITLE
  200. ============================================================================== */
  201. // Displaying the title of the tool
  202. //api_display_tool_title($nameTools);
  203. // Tool introduction
  204. $fck_attribute['Width'] = '100%';
  205. $fck_attribute['Height'] = '300';
  206. $fck_attribute['ToolbarSet'] = 'Introduction';
  207. Display::display_introduction_section(TOOL_CALENDAR_EVENT);
  208. $fck_attribute = null; // Clearing this global variable immediatelly after it has been used.
  209. // insert an anchor (top) so one can jump back to the top of the page
  210. echo '<a name="top"></a>';
  211. /*
  212. ==============================================================================
  213. MAIN SECTION
  214. ==============================================================================
  215. */
  216. //setting the default year and month
  217. $select_year = '';
  218. $select_month = '';
  219. if(!empty($_GET['year']))
  220. {
  221. $select_year = (int)$_GET['year'];
  222. }
  223. if(!empty($_GET['month']))
  224. {
  225. $select_month = (int)$_GET['month'];
  226. }
  227. if (empty($select_year) && empty($select_month))
  228. {
  229. $today = getdate();
  230. $select_year = $today['year'];
  231. $select_month = $today['mon'];
  232. }
  233. echo '<div class="actions">';
  234. display_student_links();
  235. if (api_is_allowed_to_edit(false,true) OR (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous()))
  236. {
  237. display_courseadmin_links();
  238. }
  239. echo '</div><br />';
  240. if (api_is_allowed_to_edit(false,true) OR (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous()))
  241. {
  242. switch ($_GET['action'])
  243. {
  244. case "importical":
  245. if(isset($_POST['ical_submit']))
  246. {
  247. $course_info = api_get_course_info();
  248. $ical_name = $_FILES['ical_import']['name'];
  249. $ical_type = $_FILES['ical_import']['type'];
  250. $ext = substr($ical_name,(strrpos($ical_name,".")+1));
  251. if ($ical_type === 'text/calendar' || $ext === 'ics') {
  252. agenda_import_ical($course_info,$_FILES['ical_import']);
  253. $is_ical = true;
  254. } else {
  255. $is_ical = false;
  256. }
  257. }
  258. break;
  259. case 'add':
  260. if($_POST['submit_event'])
  261. {
  262. $course_info = api_get_course_info();
  263. $event_start = (int) $_POST['fyear'].'-'.(int) $_POST['fmonth'].'-'.(int) $_POST['fday'].' '.(int) $_POST['fhour'].':'.(int) $_POST['fminute'].':00';
  264. $event_stop = (int) $_POST['end_fyear'].'-'.(int) $_POST['end_fmonth'].'-'.(int) $_POST['end_fday'].' '.(int) $_POST['end_fhour'].':'.(int) $_POST['end_fminute'].':00';
  265. $safe_title = Security::remove_XSS($_POST['title']);
  266. $safe_file_comment = Security::remove_XSS($_POST['file_comment']);
  267. $id = agenda_add_item($course_info,$safe_title,$_POST['content'],$event_start,$event_stop,$_POST['selectedform'],false,$safe_file_comment);
  268. if(!empty($_POST['repeat']))
  269. {
  270. $end_y = intval($_POST['repeat_end_year']);
  271. $end_m = intval($_POST['repeat_end_month']);
  272. $end_d = intval($_POST['repeat_end_day']);
  273. $end = mktime(23, 59, 59, $end_m, $end_d, $end_y);
  274. $res = agenda_add_repeat_item($course_info,$id,$_POST['repeat_type'],$end,$_POST['selectedform'],$safe_file_comment);
  275. }
  276. }
  277. break;
  278. case "edit":
  279. if( ! (api_is_course_coach() && !api_is_element_in_the_session(TOOL_AGENDA, intval($_REQUEST['id']) ) ) )
  280. { // a coach can only delete an element belonging to his session
  281. if ($_POST['submit_event'])
  282. { $my_id_attach = (int)$_REQUEST['id_attach'];
  283. $safe_file_comment = Security::remove_XSS($_REQUEST['file_comment']);
  284. store_edited_agenda_item($my_id_attach,$safe_file_comment);
  285. }
  286. }
  287. break;
  288. case "delete":
  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. delete_agenda_item($id);
  293. }
  294. break;
  295. case "showhide":
  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. showhide_agenda_item($id);
  300. }
  301. break;
  302. case "announce": //copying the agenda item into an announcement
  303. $id=(int)$_GET['id'];
  304. if( ! (api_is_course_coach() && !api_is_element_in_the_session(TOOL_AGENDA, $id ) ) )
  305. { // a coach can only delete an element belonging to his session
  306. $ann_id = store_agenda_item_as_announcement($id);
  307. $tool_group_link = (isset($_SESSION['toolgroup'])?'&toolgroup='.$_SESSION['toolgroup']:'');
  308. Display::display_normal_message(get_lang('CopiedAsAnnouncement').'&nbsp;<a href="../announcements/announcements.php?id='.$ann_id.$tool_group_link.'">'.get_lang('NewAnnouncement').'</a>', false);
  309. }
  310. break;
  311. case "delete_attach": //delete attachment file
  312. $id_attach = (int)$_GET['id_attach'];
  313. if (!empty($id_attach)) {
  314. delete_attachment_file($id_attach);
  315. }
  316. break;
  317. }
  318. }
  319. echo '<table width="100%" border="0" cellspacing="0" cellpadding="0">'
  320. . '<tr>';
  321. // THE LEFT PART
  322. if (empty($_GET['origin']) or $_GET['origin']!='learnpath')
  323. {
  324. echo '<td width="220" height="19" valign="top">';
  325. // the small calendar
  326. $MonthName = $MonthsLong[$select_month -1];
  327. $agenda_items=get_calendar_items($select_month,$select_year);
  328. if (api_get_setting('display_mini_month_calendar') == 'true')
  329. {
  330. display_minimonthcalendar($agenda_items, $select_month,$select_year, $MonthName);
  331. }
  332. echo '<br />';
  333. if (api_get_setting('display_upcoming_events') == 'true') {
  334. display_upcoming_events();
  335. }
  336. echo '</td>';
  337. echo '<td width="20" background="../img/verticalruler.gif">&nbsp;</td>';
  338. }
  339. // THE RIGHT PART
  340. echo '<td valign="top">';
  341. echo '<div class="sort" style="float:left">';
  342. echo '</div>';
  343. if (api_is_allowed_to_edit(false,true) OR (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous())) {
  344. switch ($_GET['action']) {
  345. case 'importical' :
  346. if (isset($_POST['ical_submit'])) {
  347. if (!$is_ical) {
  348. Display::display_error_message(get_lang('IsNotiCalFormatFile'));
  349. display_ical_import_form();
  350. break;
  351. }
  352. display_agenda_items();
  353. }
  354. else {
  355. display_ical_import_form();
  356. }
  357. break;
  358. case 'add' :
  359. if ($_POST['submit_event']) {
  360. display_agenda_items();
  361. } else {
  362. show_add_form();
  363. }
  364. break;
  365. case 'edit' :
  366. if ( !(api_is_course_coach() && !api_is_element_in_the_session(TOOL_AGENDA, intval($_REQUEST['id'])))) {
  367. if ($_POST['submit_event']) {
  368. display_agenda_items();
  369. }
  370. else {
  371. $id=(int)$_GET['id'];
  372. show_add_form($id);
  373. }
  374. } else {
  375. display_agenda_items();
  376. }
  377. break;
  378. case 'delete':
  379. display_agenda_items();
  380. break;
  381. case 'showhide':
  382. display_agenda_items();
  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. ?>