agenda.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. <?php //$Id: agenda.php 14609 2008-03-16 02:07:51Z yannoo $
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004-2005 Dokeos S.A.
  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, 44 rue des palais, 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','resourcelinker');
  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. if ($addresources) // When the "Add Resource" button is clicked we store all the form data into a session
  51. {
  52. $form_elements= array ('day'=>$_POST['fday'], 'month'=>$_POST['fmonth'], 'year'=>$_POST['fyear'], 'hour'=>$_POST['fhour'], 'minutes'=>$_POST['fminute'],
  53. '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'],
  54. 'title'=>stripslashes($_POST['title']), 'content'=>stripslashes($_POST['content']), 'id'=>$_POST['id'], 'action'=>$_POST['action'], 'to'=>$_POST['selectedform']);
  55. $_SESSION['formelements']=$form_elements;
  56. if($id) // this is to correctly handle edits
  57. {$action="edit";}
  58. //print_r($form_elements);
  59. header('Location: '.api_get_path(WEB_CODE_PATH)."resourcelinker/resourcelinker.php?source_id=1&action=$action&id=$id&originalresource=no");
  60. exit;
  61. }
  62. /*
  63. -----------------------------------------------------------
  64. Libraries
  65. -----------------------------------------------------------
  66. */
  67. // containing the functions for the agenda tool
  68. include "agenda.inc.php";
  69. // some debug functions
  70. include($includePath."/lib/debug.lib.inc.php");
  71. /*==============================================================================
  72. TREATING THE PARAMETERS
  73. 1. viewing month only or everything
  74. 2. sort ascending or descending
  75. 3. showing or hiding the send-to-specific-groups-or-users form
  76. 4. filter user or group
  77. ============================================================================== */
  78. // 1. show all or show current month?
  79. if (!$_SESSION['show'])
  80. {
  81. $_SESSION['show']="showall";
  82. }
  83. if ($_GET['action']=="showcurrent")
  84. {
  85. $_SESSION['show']="showcurrent";
  86. }
  87. if ($_GET['action']=="showall")
  88. {
  89. $_SESSION['show']="showall";
  90. }
  91. //echo $_SESSION['show'];
  92. // 2. sorting order (ASC or DESC)
  93. if (!$_GET['sort'] and !$_SESSION['sort'])
  94. {
  95. $_SESSION['sort']="DESC";
  96. }
  97. if ($_GET['sort']=="asc")
  98. {
  99. $_SESSION['sort']="ASC";
  100. }
  101. if ($_GET['sort']=="desc")
  102. {
  103. $_SESSION['sort']="DESC";
  104. }
  105. // 3. showing or hiding the send-to-specific-groups-or-users form
  106. $setting_allow_individual_calendar=true;
  107. if (!$_POST['To'] and !$_SESSION['allow_individual_calendar'])
  108. {
  109. $_SESSION['allow_individual_calendar']="hide";
  110. }
  111. $allow_individual_calendar_status=$_SESSION['allow_individual_calendar'];
  112. if ($_POST['To'] and ($allow_individual_calendar_status=="hide"))
  113. {
  114. $_SESSION['allow_individual_calendar']="show";
  115. }
  116. if ($_POST['To'] and ($allow_individual_calendar_status=="show"))
  117. {
  118. $_SESSION['allow_individual_calendar']="hide";
  119. }
  120. // 4. filter user or group
  121. if ($_GET['user'] or $_GET['group'])
  122. {
  123. $_SESSION['user']=(int)$_GET['user'];
  124. $_SESSION['group']=(int)$_GET['group'];
  125. }
  126. if ($_GET['user']=="none" or $_GET['group']=="none")
  127. {
  128. api_session_unregister("user");
  129. api_session_unregister("group");
  130. }
  131. if (!$is_courseAdmin){
  132. if (!empty($_GET['toolgroup'])){
  133. //$_SESSION['toolgroup']=$_GET['toolgroup'];
  134. $toolgroup=$_GET['toolgroup'];
  135. api_session_register('toolgroup');
  136. }
  137. }
  138. //It comes from the group tools. If it's define it overwrites $_SESSION['group']
  139. if ($_GET['isStudentView']=="false")
  140. {
  141. api_session_unregister("user");
  142. api_session_unregister("group");
  143. }
  144. $htmlHeadXtra[] = to_javascript();
  145. $htmlHeadXtra[] = user_group_filter_javascript();
  146. // this loads the javascript that is needed for the date popup selection
  147. $htmlHeadXtra[] = "<script src=\"tbl_change.js\" type=\"text/javascript\" language=\"javascript\"></script>";
  148. // setting the name of the tool
  149. $nameTools = get_lang('Agenda'); // language variable in trad4all.inc.php
  150. // showing the header if we are not in the learning path, if we are in
  151. // the learning path, we do not include the banner so we have to explicitly
  152. // include the stylesheet, which is normally done in the header
  153. if ($_GET['origin'] != 'learnpath')
  154. {
  155. Display::display_header($nameTools,'Agenda');
  156. }
  157. else
  158. {
  159. echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"".$clarolineRepositoryWeb."css/default.css\"/>";
  160. }
  161. /* ==============================================================================
  162. TRACKING
  163. ============================================================================== */
  164. include('../inc/lib/events.lib.inc.php');
  165. event_access_tool(TOOL_CALENDAR_EVENT);
  166. /* ==============================================================================
  167. SETTING SOME VARIABLES
  168. ============================================================================== */
  169. // Variable definitions
  170. $dateNow = format_locale_date($dateTimeFormatLong);
  171. // Defining the shorts for the days. We use camelcase because these are arrays of language variables
  172. $DaysShort = array (get_lang("SundayShort"), get_lang("MondayShort"), get_lang("TuesdayShort"), get_lang("WednesdayShort"), get_lang("ThursdayShort"), get_lang("FridayShort"), get_lang("SaturdayShort"));
  173. // Defining the days of the week to allow translation of the days. We use camelcase because these are arrays of language variables
  174. $DaysLong = array (get_lang("SundayLong"), get_lang("MondayLong"), get_lang("TuesdayLong"), get_lang("WednesdayLong"), get_lang("ThursdayLong"), get_lang("FridayLong"), get_lang("SaturdayLong"));
  175. // Defining the months of the year to allow translation of the months. We use camelcase because these are arrays of language variables
  176. $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"));
  177. // Database table definitions
  178. $TABLEAGENDA = Database::get_course_table(TABLE_AGENDA);
  179. $TABLE_ITEM_PROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY);
  180. $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
  181. $tbl_courseUser = Database::get_main_table(TABLE_MAIN_COURSE_USER);
  182. $tbl_group = Database::get_course_table(TABLE_GROUP);
  183. $tbl_groupUser = Database::get_course_table(TABLE_GROUP_USER);
  184. $tbl_session_course_user= Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  185. /* ==============================================================================
  186. ACCESS RIGHTS
  187. ============================================================================== */
  188. // permission stuff - also used by loading from global in agenda.inc.php
  189. $is_allowed_to_edit = is_allowed_to_edit() OR (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous());
  190. /* ==============================================================================
  191. TITLE
  192. ============================================================================== */
  193. // Displaying the title of the tool
  194. //api_display_tool_title($nameTools);
  195. // tool introduction
  196. Display::display_introduction_section(TOOL_CALENDAR_EVENT);
  197. // insert an anchor (top) so one can jump back to the top of the page
  198. echo "<a name=\"top\"></a>";
  199. /*
  200. ==============================================================================
  201. MAIN SECTION
  202. ==============================================================================
  203. */
  204. //setting the default year and month
  205. $select_year = (int)$_GET['year'];
  206. $select_month = (int)$_GET['month'];
  207. if (($select_year==NULL) && ($select_month==NULL))
  208. {
  209. $today = getdate();
  210. $select_year = $today['year'];
  211. $select_month = $today['mon'];
  212. }
  213. echo '<table width="100%" border="0" cellspacing="0" cellpadding="0">'
  214. . '<tr>';
  215. // THE LEFT PART
  216. if ($_GET['origin']!='learnpath')
  217. {
  218. echo '<td width="220" height="19" valign="top">';
  219. // the small calendar
  220. $MonthName = $MonthsLong[$select_month -1];
  221. $agenda_items=get_calendar_items($select_month,$select_year);
  222. display_minimonthcalendar($agenda_items, $select_month,$select_year, $MonthName);
  223. // the links for adding, filtering, showall, ...
  224. echo '<ul id="agenda_select">';
  225. if (is_allowed_to_edit() OR (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous()))
  226. {
  227. display_courseadmin_links();
  228. }
  229. display_student_links();
  230. echo '</ul>';
  231. echo '</td>';
  232. echo '<td width="20" background="../img/verticalruler.gif">&nbsp;</td>';
  233. }
  234. $fck_attribute['Width'] = '600';
  235. $fck_attribute['Height'] = '400';
  236. $fck_attribute['ToolbarSet'] = 'Middle';
  237. // THE RIGHT PART
  238. echo "<td valign=\"top\">";
  239. if (is_allowed_to_edit() OR (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous()))
  240. {
  241. switch ($_GET['action'])
  242. {
  243. case "add":
  244. if ($_POST['submit_event'])
  245. {
  246. store_new_agenda_item();
  247. display_agenda_items();
  248. }
  249. else
  250. {
  251. show_add_form();
  252. }
  253. break;
  254. case "edit":
  255. if ($_POST['submit_event'])
  256. {
  257. store_edited_agenda_item();
  258. display_agenda_items();
  259. }
  260. else
  261. {
  262. $id=(int)$_GET['id'];
  263. show_add_form($id);
  264. }
  265. break;
  266. case "delete":
  267. $id=(int)$_GET['id'];
  268. delete_agenda_item($id);
  269. display_agenda_items();
  270. break;
  271. case "showhide":
  272. $id=(int)$_GET['id'];
  273. showhide_agenda_item($id);
  274. display_agenda_items();
  275. break;
  276. case "announce": //copying the agenda item into an announcement
  277. $id=(int)$_GET['id'];
  278. $ann_id = store_agenda_item_as_announcement($id);
  279. $tool_group_link = (isset($_SESSION['toolgroup'])?'&toolgroup='.$_SESSION['toolgroup']:'');
  280. Display::display_normal_message(get_lang('CopiedAsAnnouncement').'<a href="../announcements/announcements.php?id='.$ann_id.$tool_group_link.'">'.get_lang('NewAnnouncement').'</a>', false);
  281. display_agenda_items();
  282. }
  283. }
  284. // this is for students and whenever the courseaministrator has not chosen any action. It is in fact the default behaviour
  285. if (!$_GET['action'] OR $_GET['action']=="showall" OR $_GET['action']=="showcurrent" OR $_GET['action']=="view")
  286. {
  287. if ($_GET['origin'] != 'learnpath')
  288. {
  289. display_agenda_items();
  290. }
  291. else
  292. {
  293. display_one_agenda_item((int)$_GET['agenda_id']);
  294. }
  295. }
  296. echo "&nbsp;</td></tr></table>";
  297. /*
  298. ==============================================================================
  299. FOOTER
  300. ==============================================================================
  301. */
  302. // The footer is displayed only if we are not in the learnpath
  303. if ($_GET['origin'] != 'learnpath')
  304. {
  305. Display::display_footer();
  306. }
  307. ?>