calendar.php 9.2 KB

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