calendar.php 13 KB

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