calendar.php 10 KB

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