calendar.php 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. <?php
  2. // @deprecated unused file
  3. exit;
  4. /* For licensing terms, see /license.txt */
  5. /**
  6. * @package chamilo.admin
  7. * @author Carlos Vargas
  8. * This file is the calendar/agenda.php
  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 files
  16. require_once '../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. // setting the name of the tool
  24. $tool_name= get_lang('SubscribeCoursesToSession');
  25. $id_session=intval($_GET['id_session']);
  26. if (!api_is_platform_admin()) {
  27. $sql = 'SELECT session_admin_id FROM '.Database :: get_main_table(TABLE_MAIN_SESSION).' WHERE id='.$id_session;
  28. $rs = Database::query($sql);
  29. if(Database::result($rs,0,0)!= api_get_user_id()) {
  30. api_not_allowed(true);
  31. }
  32. }
  33. /*
  34. Libraries
  35. */
  36. // containing the functions for the agenda tool
  37. require_once 'calendar.lib.php';
  38. /*
  39. TREATING THE PARAMETERS
  40. 1. viewing month only or everything
  41. 2. sort ascending or descending
  42. 3. showing or hiding the send-to-specific-groups-or-users form
  43. 4. filter user or group
  44. */
  45. // 1. show all or show current month?
  46. if (!$_SESSION['show_all_admin']) {
  47. $_SESSION['show_all_admin']="showall";
  48. }
  49. if (!empty($_GET['action']) and $_GET['action']=="showcurrent")
  50. {
  51. $_SESSION['show_all_admin']='showcurrent';
  52. }
  53. if (!empty($_GET['action']) and $_GET['action']=="showall")
  54. {
  55. $_SESSION['show_all_admin']='showall';
  56. }
  57. // 2. sorting order (ASC or DESC)
  58. if (empty($_GET['sort']) and empty($_SESSION['sort']))
  59. {
  60. $_SESSION['sort']="DESC";
  61. }
  62. if (!empty($_GET['sort']) and $_GET['sort']=="asc")
  63. {
  64. $_SESSION['sort']="ASC";
  65. }
  66. if (!empty($_GET['sort']) and $_GET['sort']=="desc")
  67. {
  68. $_SESSION['sort']="DESC";
  69. }
  70. if (!empty($_GET['view']))
  71. {
  72. $_SESSION['view'] = $_GET['view'];
  73. }
  74. // 3. showing or hiding the send-to-specific-groups-or-users form
  75. $setting_allow_individual_calendar=true;
  76. if (empty($_POST['To']) and empty($_SESSION['allow_individual_calendar']))
  77. {
  78. $_SESSION['allow_individual_calendar']="hide";
  79. }
  80. $allow_individual_calendar_status=$_SESSION['allow_individual_calendar'];
  81. if (!empty($_POST['To']) and ($allow_individual_calendar_status=="hide"))
  82. {
  83. $_SESSION['allow_individual_calendar']="show";
  84. }
  85. if (!empty($_GET['sort']) and ($allow_individual_calendar_status=="show"))
  86. {
  87. $_SESSION['allow_individual_calendar']="hide";
  88. }
  89. $htmlHeadXtra[] = to_javascript();
  90. // this loads the javascript that is needed for the date popup selection
  91. $htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/calendar/calendar_tbl_change.js" type="text/javascript" ></script>';
  92. // setting the name of the tool
  93. $nameTools = get_lang('GlobalAgenda'); // language variable in trad4all.inc.php
  94. // showing the header if we are not in the learning path, if we are in
  95. // the learning path, we do not include the banner so we have to explicitly
  96. // include the stylesheet, which is normally done in the header
  97. Display::display_header($nameTools,'Agenda');
  98. /* SETTING SOME VARIABLES */
  99. // Variable definitions
  100. // Defining the shorts for the days. We use camelcase because these are arrays of language variables
  101. $DaysShort = api_get_week_days_short();
  102. // Defining the days of the week to allow translation of the days. We use camelcase because these are arrays of language variables
  103. $DaysLong = api_get_week_days_long();
  104. // Defining the months of the year to allow translation of the months. We use camelcase because these are arrays of language variables
  105. $MonthsLong = api_get_months_long();
  106. // Database table definitions
  107. $TABLEAGENDA = Database::get_main_table(TABLE_MAIN_SYSTEM_CALENDAR);
  108. $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
  109. $tbl_courseUser = Database::get_main_table(TABLE_MAIN_COURSE_USER);
  110. /*
  111. ACCESS RIGHTS
  112. */
  113. // permission stuff - also used by loading from global in agenda.inc.php
  114. $is_allowed_to_edit = api_is_allowed_to_edit() OR (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous());
  115. // insert an anchor (top) so one can jump back to the top of the page
  116. echo "<a name=\"top\"></a>";
  117. /*
  118. MAIN SECTION
  119. */
  120. //setting the default year and month
  121. $select_year = '';
  122. $select_month = '';
  123. if(!empty($_GET['year'])) {
  124. $select_year = (int)$_GET['year'];
  125. }
  126. if(!empty($_GET['month'])) {
  127. $select_month = (int)$_GET['month'];
  128. }
  129. if (empty($select_year) && empty($select_month)) {
  130. $today = getdate();
  131. $select_year = $today['year'];
  132. $select_month = $today['mon'];
  133. }
  134. echo '<div class="actions">';
  135. if (api_is_allowed_to_edit(false,true) OR (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous())) {
  136. display_student_links();
  137. display_courseadmin_links();
  138. }
  139. echo '</div><br /><br />';
  140. echo '<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr>';
  141. // THE LEFT PART
  142. if (empty($_GET['origin']) or $_GET['origin']!='learnpath') {
  143. echo '<td width="220" height="19" valign="top">';
  144. // the small calendar
  145. $MonthName = $MonthsLong[$select_month -1];
  146. $agenda_items=get_calendar_items($select_month,$select_year);
  147. if (api_get_setting('display_mini_month_calendar') == 'true') {
  148. display_minimonthcalendar($agenda_items, $select_month,$select_year, $MonthName);
  149. }
  150. if (api_get_setting('display_upcoming_events') == 'true') {
  151. display_upcoming_events();
  152. }
  153. echo '</td>';
  154. echo '<td width="20" background="../img/verticalruler.gif">&nbsp;</td>';
  155. }
  156. // THE RIGHT PART
  157. echo '<td valign="top">';
  158. echo '<div class="sort" style="float:right">';
  159. echo '</div>';
  160. if (api_is_allowed_to_edit(false,true)) {
  161. switch ($_GET['action']) {
  162. case "add":
  163. if ($_POST['submit_event']) {
  164. $event_start = (int) $_POST['fyear'].'-'.(int) $_POST['fmonth'].'-'.(int) $_POST['fday'].' '.(int) $_POST['fhour'].':'.(int) $_POST['fminute'].':00';
  165. $event_stop = (int) $_POST['end_fyear'].'-'.(int) $_POST['end_fmonth'].'-'.(int) $_POST['end_fday'].' '.(int) $_POST['end_fhour'].':'.(int) $_POST['end_fminute'].':00';
  166. $id = agenda_add_item($_POST['title'],$_POST['content'],$event_start,$event_stop);
  167. display_agenda_items();
  168. } else {
  169. show_add_form();
  170. }
  171. break;
  172. case "edit":
  173. if( ! (api_is_course_coach() && !api_is_element_in_the_session(TOOL_AGENDA, intval($_REQUEST['id']) ) ) )
  174. { // a coach can only delete an element belonging to his session
  175. if ($_POST['submit_event']) {
  176. $my_id_attach = (int)$_REQUEST['id_attach'];
  177. $my_file_comment = Database::escape_string($_REQUEST['file_comment']);
  178. store_edited_agenda_item($my_id_attach,$my_file_comment);
  179. display_agenda_items();
  180. } else {
  181. $id=(int)$_GET['id'];
  182. show_add_form($id);
  183. }
  184. } else {
  185. display_agenda_items();
  186. }
  187. break;
  188. case "delete":
  189. $id=(int)$_GET['id'];
  190. if( ! (api_is_course_coach() && !api_is_element_in_the_session(TOOL_AGENDA, $id ) ) )
  191. { // a coach can only delete an element belonging to his session
  192. if (api_is_allowed_to_edit() && !api_is_anonymous()) {
  193. if (!empty($id)) {
  194. $res_del = delete_agenda_item($id);
  195. if ($res_del) {
  196. Display::display_normal_message(get_lang("AgendaDeleteSuccess"));
  197. }
  198. }
  199. }
  200. }
  201. display_agenda_items();
  202. break;
  203. case "showhide":
  204. $id=(int)$_GET['id'];
  205. if( ! (api_is_course_coach() && !api_is_element_in_the_session(TOOL_AGENDA, $id ) ) )
  206. { // a coach can only delete an element belonging to his session
  207. showhide_agenda_item($id);
  208. }
  209. display_agenda_items();
  210. break;
  211. case "announce": //copying the agenda item into an announcement
  212. $id=(int)$_GET['id'];
  213. if( ! (api_is_course_coach() && !api_is_element_in_the_session(TOOL_AGENDA, $id ) ) )
  214. { // a coach can only delete an element belonging to his session
  215. $ann_id = store_agenda_item_as_announcement($id);
  216. $tool_group_link = (isset($_SESSION['toolgroup'])?'&toolgroup='.$_SESSION['toolgroup']:'');
  217. echo '<br />';
  218. Display::display_normal_message(get_lang('CopiedAsAnnouncement').'<a href="../announcements/announcements.php?id='.$ann_id.$tool_group_link.'">'.get_lang('NewAnnouncement').'</a>', false);
  219. }
  220. display_agenda_items();
  221. break;
  222. case "delete_attach": //delete attachment file
  223. $id_attach = (int)$_GET['id_attach'];
  224. if (!empty($id_attach)) {
  225. delete_attachment_file($id_attach);
  226. }
  227. display_agenda_items();
  228. break;
  229. }
  230. }
  231. // this is for students and whenever the courseaministrator has not chosen any action. It is in fact the default behaviour
  232. if (!$_GET['action'] OR $_GET['action']=="showall" OR $_GET['action']=="showcurrent" OR $_GET['action']=="view") {
  233. if ($_GET['origin'] != 'learnpath') {
  234. if (!$_SESSION['view'] OR $_SESSION['view'] <> 'month') {
  235. if(!empty($_GET['agenda_id'])) {
  236. display_one_agenda_item((int)$_GET['agenda_id']);
  237. } else {
  238. display_agenda_items();
  239. }
  240. } else {
  241. display_monthcalendar($select_month, $select_year);
  242. }
  243. } else {
  244. display_one_agenda_item((int)$_GET['agenda_id']);
  245. }
  246. }
  247. echo "&nbsp;</td></tr></table>";
  248. /*
  249. FOOTER
  250. */
  251. // The footer is displayed only if we are not in the learnpath
  252. if ($_GET['origin'] != 'learnpath') {
  253. Display::display_footer();
  254. }