calendar.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  1. <?php // $id: $
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2008 Dokeos S.A.
  6. For a full list of contributors, see "credits.txt".
  7. The full license can be read in "license.txt".
  8. This program is free software; you can redistribute it and/or
  9. modify it under the terms of the GNU General Public License
  10. as published by the Free Software Foundation; either version 2
  11. of the License, or (at your option) any later version.
  12. See the GNU General Public License for more details.
  13. Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
  14. ==============================================================================
  15. */
  16. /**
  17. ==============================================================================
  18. * @package dokeos.admin
  19. * @author Carlos Vargas
  20. * This file is the calendar/agenda.php
  21. ==============================================================================
  22. */
  23. // name of the language file that needs to be included
  24. $language_file[] = 'admin';
  25. $language_file[] = 'agenda';
  26. // resetting the course id
  27. $cidReset=true;
  28. // including some necessary dokeos files
  29. require('../inc/global.inc.php');
  30. $this_section = SECTION_PLATFORM_ADMIN;
  31. $_SESSION['this_section']=$this_section;
  32. // Access restrictions
  33. api_protect_admin_script(true);
  34. // setting breadcrumbs
  35. $interbreadcrumb[] = array('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
  36. //$interbreadcrumb[] = array('url' => 'session_list.php','name' => get_lang('SessionList'));
  37. // Database Table Definitions
  38. // $tbl_session_rel_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  39. // $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
  40. // $tbl_session_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_USER);
  41. // $tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
  42. // $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
  43. // setting the name of the tool
  44. $tool_name= get_lang('SubscribeCoursesToSession');
  45. $id_session=intval($_GET['id_session']);
  46. if(!api_is_platform_admin())
  47. {
  48. $sql = 'SELECT session_admin_id FROM '.Database :: get_main_table(TABLE_MAIN_SESSION).' WHERE id='.$id_session;
  49. $rs = Database::query($sql,__FILE__,__LINE__);
  50. if(Database::result($rs,0,0)!=$_user['user_id'])
  51. {
  52. api_not_allowed(true);
  53. }
  54. }
  55. /*
  56. -----------------------------------------------------------
  57. Libraries
  58. -----------------------------------------------------------
  59. */
  60. // containing the functions for the agenda tool
  61. include "calendar.lib.php";
  62. // some debug functions
  63. include($includePath."/lib/debug.lib.inc.php");
  64. /*==============================================================================
  65. TREATING THE PARAMETERS
  66. 1. viewing month only or everything
  67. 2. sort ascending or descending
  68. 3. showing or hiding the send-to-specific-groups-or-users form
  69. 4. filter user or group
  70. ============================================================================== */
  71. // 1. show all or show current month?
  72. if (!$_SESSION['show'])
  73. {
  74. $_SESSION['show']="showall";
  75. }
  76. if (!empty($_GET['action']) and $_GET['action']=="showcurrent")
  77. {
  78. $_SESSION['show']="showcurrent";
  79. }
  80. if (!empty($_GET['action']) and $_GET['action']=="showall")
  81. {
  82. $_SESSION['show']="showall";
  83. }
  84. //echo $_SESSION['show'];
  85. // 2. sorting order (ASC or DESC)
  86. if (empty($_GET['sort']) and empty($_SESSION['sort']))
  87. {
  88. $_SESSION['sort']="DESC";
  89. }
  90. if (!empty($_GET['sort']) and $_GET['sort']=="asc")
  91. {
  92. $_SESSION['sort']="ASC";
  93. }
  94. if (!empty($_GET['sort']) and $_GET['sort']=="desc")
  95. {
  96. $_SESSION['sort']="DESC";
  97. }
  98. if (!empty($_GET['view']))
  99. {
  100. $_SESSION['view'] = $_GET['view'];
  101. }
  102. // 3. showing or hiding the send-to-specific-groups-or-users form
  103. $setting_allow_individual_calendar=true;
  104. if (empty($_POST['To']) and empty($_SESSION['allow_individual_calendar']))
  105. {
  106. $_SESSION['allow_individual_calendar']="hide";
  107. }
  108. $allow_individual_calendar_status=$_SESSION['allow_individual_calendar'];
  109. if (!empty($_POST['To']) and ($allow_individual_calendar_status=="hide"))
  110. {
  111. $_SESSION['allow_individual_calendar']="show";
  112. }
  113. if (!empty($_GET['sort']) and ($allow_individual_calendar_status=="show"))
  114. {
  115. $_SESSION['allow_individual_calendar']="hide";
  116. }
  117. $htmlHeadXtra[] = to_javascript();
  118. // this loads the javascript that is needed for the date popup selection
  119. $htmlHeadXtra[] = "<script src=\"calendar_tbl_change.js\" type=\"text/javascript\" language=\"javascript\"></script>";
  120. // setting the name of the tool
  121. $nameTools = get_lang('GlobalAgenda'); // language variable in trad4all.inc.php
  122. // showing the header if we are not in the learning path, if we are in
  123. // the learning path, we do not include the banner so we have to explicitly
  124. // include the stylesheet, which is normally done in the header
  125. /*if (empty($_GET['origin']) or $_GET['origin'] != 'learnpath')
  126. {*/
  127. Display::display_header($nameTools,'Agenda');
  128. /*}
  129. else
  130. {
  131. echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"".$clarolineRepositoryWeb."css/default.css\"/>";
  132. }*/
  133. /* ==============================================================================
  134. SETTING SOME VARIABLES
  135. ============================================================================== */
  136. // Variable definitions
  137. $dateNow = format_locale_date($dateTimeFormatLong);
  138. // Defining the shorts for the days. We use camelcase because these are arrays of language variables
  139. $DaysShort = api_get_week_days_short();
  140. // Defining the days of the week to allow translation of the days. We use camelcase because these are arrays of language variables
  141. $DaysLong = api_get_week_days_long();
  142. // Defining the months of the year to allow translation of the months. We use camelcase because these are arrays of language variables
  143. $MonthsLong = api_get_months_long();
  144. // Database table definitions
  145. $TABLEAGENDA = Database::get_main_table(TABLE_MAIN_SYSTEM_CALENDAR);
  146. $TABLE_ITEM_PROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY);
  147. $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
  148. $tbl_courseUser = Database::get_main_table(TABLE_MAIN_COURSE_USER);
  149. $tbl_group = Database::get_course_table(TABLE_GROUP);
  150. $tbl_groupUser = Database::get_course_table(TABLE_GROUP_USER);
  151. $tbl_session_course_user= Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  152. /* ==============================================================================
  153. ACCESS RIGHTS
  154. ============================================================================== */
  155. // permission stuff - also used by loading from global in agenda.inc.php
  156. $is_allowed_to_edit = is_allowed_to_edit() OR (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous());
  157. // Displaying the title of the tool
  158. // api_display_tool_title($nameTools);
  159. // tool introduction
  160. //Display::display_introduction_section(TOOL_CALENDAR_EVENT);
  161. // insert an anchor (top) so one can jump back to the top of the page
  162. echo "<a name=\"top\"></a>";
  163. /*
  164. ==============================================================================
  165. MAIN SECTION
  166. ==============================================================================
  167. */
  168. //setting the default year and month
  169. $select_year = '';
  170. $select_month = '';
  171. if(!empty($_GET['year']))
  172. {
  173. $select_year = (int)$_GET['year'];
  174. }
  175. if(!empty($_GET['month']))
  176. {
  177. $select_month = (int)$_GET['month'];
  178. }
  179. if (empty($select_year) && empty($select_month))
  180. {
  181. $today = getdate();
  182. $select_year = $today['year'];
  183. $select_month = $today['mon'];
  184. }
  185. echo '<div class="actions">';
  186. if (api_is_allowed_to_edit(false,true) OR (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous()))
  187. {
  188. display_student_links();
  189. display_courseadmin_links();
  190. }
  191. echo '</div><br /><br />';
  192. echo '<table width="100%" border="0" cellspacing="0" cellpadding="0">'
  193. . '<tr>';
  194. // THE LEFT PART
  195. if (empty($_GET['origin']) or $_GET['origin']!='learnpath')
  196. {
  197. echo '<td width="220" height="19" valign="top">';
  198. // the small calendar
  199. $MonthName = $MonthsLong[$select_month -1];
  200. $agenda_items=get_calendar_items($select_month,$select_year);
  201. if (api_get_setting('display_mini_month_calendar') == 'true')
  202. {
  203. display_minimonthcalendar($agenda_items, $select_month,$select_year, $MonthName);
  204. }
  205. /*if (api_get_setting('display_upcoming_events') == 'true') {
  206. display_upcoming_events();
  207. }*/
  208. echo '</td>';
  209. echo '<td width="20" background="../img/verticalruler.gif">&nbsp;</td>';
  210. }
  211. // THE RIGHT PART
  212. echo '<td valign="top">';
  213. echo '<div class="sort" style="float:right">';
  214. echo '</div>';
  215. if (api_is_allowed_to_edit(false,true))
  216. {
  217. switch ($_GET['action'])
  218. {
  219. case "add":
  220. if(!empty($_POST['ical_submit'])) {
  221. $course_info = api_get_course_info();
  222. agenda_import_ical($course_info,$_FILES['ical_import']);
  223. if (api_get_setting('display_upcoming_events') == 'true') {
  224. display_upcoming_events();
  225. }
  226. display_agenda_items();
  227. } elseif ($_POST['submit_event']) {
  228. $course_info = api_get_course_info();
  229. $event_start = (int) $_POST['fyear'].'-'.(int) $_POST['fmonth'].'-'.(int) $_POST['fday'].' '.(int) $_POST['fhour'].':'.(int) $_POST['fminute'].':00';
  230. $event_stop = (int) $_POST['end_fyear'].'-'.(int) $_POST['end_fmonth'].'-'.(int) $_POST['end_fday'].' '.(int) $_POST['end_fhour'].':'.(int) $_POST['end_fminute'].':00';
  231. $id = agenda_add_item($course_info,$_POST['title'],$_POST['content'],$event_start,$event_stop,$_POST['selectedform'],false,$_POST['file_comment']);
  232. if(!empty($_POST['repeat'])) {
  233. $end_y = intval($_POST['repeat_end_year']);
  234. $end_m = intval($_POST['repeat_end_month']);
  235. $end_d = intval($_POST['repeat_end_day']);
  236. $end = mktime(23, 59, 59, $end_m, $end_d, $end_y);
  237. $res = agenda_add_repeat_item($course_info,$id,$_POST['repeat_type'],$end,null,$_POST['file_comment']);
  238. }
  239. if (api_get_setting('display_upcoming_events') == 'true') {
  240. display_upcoming_events();
  241. }
  242. display_agenda_items();
  243. } else {
  244. show_add_form();
  245. }
  246. break;
  247. case "edit":
  248. if( ! (api_is_course_coach() && !api_is_element_in_the_session(TOOL_AGENDA, intval($_REQUEST['id']) ) ) )
  249. { // a coach can only delete an element belonging to his session
  250. if ($_POST['submit_event'])
  251. { $my_id_attach = (int)$_REQUEST['id_attach'];
  252. $my_file_comment = Database::escape_string($_REQUEST['file_comment']);
  253. store_edited_agenda_item($my_id_attach,$my_file_comment);
  254. if (api_get_setting('display_upcoming_events') == 'true') {
  255. display_upcoming_events();
  256. }
  257. display_agenda_items();
  258. }
  259. else
  260. {
  261. $id=(int)$_GET['id'];
  262. show_add_form($id);
  263. }
  264. }
  265. else
  266. {
  267. if (api_get_setting('display_upcoming_events') == 'true') {
  268. display_upcoming_events();
  269. }
  270. display_agenda_items();
  271. }
  272. break;
  273. case "delete":
  274. $id=(int)$_GET['id'];
  275. if( ! (api_is_course_coach() && !api_is_element_in_the_session(TOOL_AGENDA, $id ) ) )
  276. { // a coach can only delete an element belonging to his session
  277. delete_agenda_item($id);
  278. }
  279. if (api_get_setting('display_upcoming_events') == 'true') {
  280. display_upcoming_events();
  281. }
  282. display_agenda_items();
  283. break;
  284. case "showhide":
  285. $id=(int)$_GET['id'];
  286. if( ! (api_is_course_coach() && !api_is_element_in_the_session(TOOL_AGENDA, $id ) ) )
  287. { // a coach can only delete an element belonging to his session
  288. showhide_agenda_item($id);
  289. }
  290. if (api_get_setting('display_upcoming_events') == 'true') {
  291. display_upcoming_events();
  292. }
  293. display_agenda_items();
  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. echo '<br />';
  302. Display::display_normal_message(get_lang('CopiedAsAnnouncement').'<a href="../announcements/announcements.php?id='.$ann_id.$tool_group_link.'">'.get_lang('NewAnnouncement').'</a>', false);
  303. }
  304. if (api_get_setting('display_upcoming_events') == 'true') {
  305. display_upcoming_events();
  306. }
  307. display_agenda_items();
  308. break;
  309. case "delete_attach": //delete attachment file
  310. $id_attach = (int)$_GET['id_attach'];
  311. if (!empty($id_attach)) {
  312. delete_attachment_file($id_attach);
  313. }
  314. if (api_get_setting('display_upcoming_events') == 'true') {
  315. display_upcoming_events();
  316. }
  317. display_agenda_items();
  318. break;
  319. }
  320. }
  321. // this is for students and whenever the courseaministrator has not chosen any action. It is in fact the default behaviour
  322. if (!$_GET['action'] OR $_GET['action']=="showall" OR $_GET['action']=="showcurrent" OR $_GET['action']=="view")
  323. {
  324. if ($_GET['origin'] != 'learnpath')
  325. {
  326. if (!$_SESSION['view'] OR $_SESSION['view'] <> 'month')
  327. {
  328. if(!empty($_GET['agenda_id']))
  329. {
  330. display_one_agenda_item((int)$_GET['agenda_id']);
  331. }
  332. else
  333. {
  334. display_agenda_items();
  335. }
  336. }
  337. else
  338. {
  339. display_monthcalendar($select_month, $select_year);
  340. }
  341. }
  342. else
  343. {
  344. display_one_agenda_item((int)$_GET['agenda_id']);
  345. }
  346. }
  347. echo "&nbsp;</td></tr></table>";
  348. /*
  349. ==============================================================================
  350. FOOTER
  351. ==============================================================================
  352. */
  353. // The footer is displayed only if we are not in the learnpath
  354. if ($_GET['origin'] != 'learnpath')
  355. {
  356. Display::display_footer();
  357. }
  358. ?>