calendar.php 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  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. /*if (empty($_GET['origin']) or $_GET['origin'] != 'learnpath')
  96. {*/
  97. Display::display_header($nameTools,'Agenda');
  98. /*}
  99. else
  100. {
  101. echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"".$clarolineRepositoryWeb."css/default.css\"/>";
  102. }*/
  103. /*
  104. SETTING SOME VARIABLES
  105. */
  106. // Variable definitions
  107. // Defining the shorts for the days. We use camelcase because these are arrays of language variables
  108. $DaysShort = api_get_week_days_short();
  109. // Defining the days of the week to allow translation of the days. We use camelcase because these are arrays of language variables
  110. $DaysLong = api_get_week_days_long();
  111. // Defining the months of the year to allow translation of the months. We use camelcase because these are arrays of language variables
  112. $MonthsLong = api_get_months_long();
  113. // Database table definitions
  114. $TABLEAGENDA = Database::get_main_table(TABLE_MAIN_SYSTEM_CALENDAR);
  115. $TABLE_ITEM_PROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY);
  116. $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
  117. $tbl_courseUser = Database::get_main_table(TABLE_MAIN_COURSE_USER);
  118. $tbl_group = Database::get_course_table(TABLE_GROUP);
  119. $tbl_groupUser = Database::get_course_table(TABLE_GROUP_USER);
  120. /*
  121. ACCESS RIGHTS
  122. */
  123. // permission stuff - also used by loading from global in agenda.inc.php
  124. $is_allowed_to_edit = is_allowed_to_edit() OR (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous());
  125. // insert an anchor (top) so one can jump back to the top of the page
  126. echo "<a name=\"top\"></a>";
  127. /*
  128. MAIN SECTION
  129. */
  130. //setting the default year and month
  131. $select_year = '';
  132. $select_month = '';
  133. if(!empty($_GET['year'])) {
  134. $select_year = (int)$_GET['year'];
  135. }
  136. if(!empty($_GET['month'])) {
  137. $select_month = (int)$_GET['month'];
  138. }
  139. if (empty($select_year) && empty($select_month)) {
  140. $today = getdate();
  141. $select_year = $today['year'];
  142. $select_month = $today['mon'];
  143. }
  144. echo '<div class="actions">';
  145. if (api_is_allowed_to_edit(false,true) OR (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous())) {
  146. display_student_links();
  147. display_courseadmin_links();
  148. }
  149. echo '</div><br /><br />';
  150. echo '<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr>';
  151. // THE LEFT PART
  152. if (empty($_GET['origin']) or $_GET['origin']!='learnpath') {
  153. echo '<td width="220" height="19" valign="top">';
  154. // the small calendar
  155. $MonthName = $MonthsLong[$select_month -1];
  156. $agenda_items=get_calendar_items($select_month,$select_year);
  157. if (api_get_setting('display_mini_month_calendar') == 'true') {
  158. display_minimonthcalendar($agenda_items, $select_month,$select_year, $MonthName);
  159. }
  160. if (api_get_setting('display_upcoming_events') == 'true') {
  161. display_upcoming_events();
  162. }
  163. echo '</td>';
  164. echo '<td width="20" background="../img/verticalruler.gif">&nbsp;</td>';
  165. }
  166. // THE RIGHT PART
  167. echo '<td valign="top">';
  168. echo '<div class="sort" style="float:right">';
  169. echo '</div>';
  170. if (api_is_allowed_to_edit(false,true)) {
  171. switch ($_GET['action']) {
  172. case "add":
  173. if ($_POST['submit_event']) {
  174. $event_start = (int) $_POST['fyear'].'-'.(int) $_POST['fmonth'].'-'.(int) $_POST['fday'].' '.(int) $_POST['fhour'].':'.(int) $_POST['fminute'].':00';
  175. $event_stop = (int) $_POST['end_fyear'].'-'.(int) $_POST['end_fmonth'].'-'.(int) $_POST['end_fday'].' '.(int) $_POST['end_fhour'].':'.(int) $_POST['end_fminute'].':00';
  176. $id = agenda_add_item($_POST['title'],$_POST['content'],$event_start,$event_stop);
  177. display_agenda_items();
  178. } else {
  179. show_add_form();
  180. }
  181. break;
  182. case "edit":
  183. if( ! (api_is_course_coach() && !api_is_element_in_the_session(TOOL_AGENDA, intval($_REQUEST['id']) ) ) )
  184. { // a coach can only delete an element belonging to his session
  185. if ($_POST['submit_event']) {
  186. $my_id_attach = (int)$_REQUEST['id_attach'];
  187. $my_file_comment = Database::escape_string($_REQUEST['file_comment']);
  188. store_edited_agenda_item($my_id_attach,$my_file_comment);
  189. display_agenda_items();
  190. } else {
  191. $id=(int)$_GET['id'];
  192. show_add_form($id);
  193. }
  194. } else {
  195. display_agenda_items();
  196. }
  197. break;
  198. case "delete":
  199. $id=(int)$_GET['id'];
  200. if( ! (api_is_course_coach() && !api_is_element_in_the_session(TOOL_AGENDA, $id ) ) )
  201. { // a coach can only delete an element belonging to his session
  202. if (is_allowed_to_edit() && !api_is_anonymous()) {
  203. if (!empty($id)) {
  204. $res_del = delete_agenda_item($id);
  205. if ($res_del) {
  206. Display::display_normal_message(get_lang("AgendaDeleteSuccess"));
  207. }
  208. }
  209. }
  210. }
  211. display_agenda_items();
  212. break;
  213. case "showhide":
  214. $id=(int)$_GET['id'];
  215. if( ! (api_is_course_coach() && !api_is_element_in_the_session(TOOL_AGENDA, $id ) ) )
  216. { // a coach can only delete an element belonging to his session
  217. showhide_agenda_item($id);
  218. }
  219. display_agenda_items();
  220. break;
  221. case "announce": //copying the agenda item into an announcement
  222. $id=(int)$_GET['id'];
  223. if( ! (api_is_course_coach() && !api_is_element_in_the_session(TOOL_AGENDA, $id ) ) )
  224. { // a coach can only delete an element belonging to his session
  225. $ann_id = store_agenda_item_as_announcement($id);
  226. $tool_group_link = (isset($_SESSION['toolgroup'])?'&toolgroup='.$_SESSION['toolgroup']:'');
  227. echo '<br />';
  228. Display::display_normal_message(get_lang('CopiedAsAnnouncement').'<a href="../announcements/announcements.php?id='.$ann_id.$tool_group_link.'">'.get_lang('NewAnnouncement').'</a>', false);
  229. }
  230. display_agenda_items();
  231. break;
  232. case "delete_attach": //delete attachment file
  233. $id_attach = (int)$_GET['id_attach'];
  234. if (!empty($id_attach)) {
  235. delete_attachment_file($id_attach);
  236. }
  237. display_agenda_items();
  238. break;
  239. }
  240. }
  241. // this is for students and whenever the courseaministrator has not chosen any action. It is in fact the default behaviour
  242. if (!$_GET['action'] OR $_GET['action']=="showall" OR $_GET['action']=="showcurrent" OR $_GET['action']=="view") {
  243. if ($_GET['origin'] != 'learnpath') {
  244. if (!$_SESSION['view'] OR $_SESSION['view'] <> 'month') {
  245. if(!empty($_GET['agenda_id'])) {
  246. display_one_agenda_item((int)$_GET['agenda_id']);
  247. } else {
  248. display_agenda_items();
  249. }
  250. } else {
  251. display_monthcalendar($select_month, $select_year);
  252. }
  253. } else {
  254. display_one_agenda_item((int)$_GET['agenda_id']);
  255. }
  256. }
  257. echo "&nbsp;</td></tr></table>";
  258. /*
  259. FOOTER
  260. */
  261. // The footer is displayed only if we are not in the learnpath
  262. if ($_GET['origin'] != 'learnpath') {
  263. Display::display_footer();
  264. }