allagendas.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. *
  5. * Get the all events by session/course
  6. * @author Julio Montoya cleaning code, chamilo code style changes, all agenda feature work with courses and sessions, only admins and rrhh users can see this page
  7. *
  8. *
  9. * @author Carlos Brolo First code submittion
  10. */
  11. // name of the language file that needs to be included
  12. $language_file = 'agenda';
  13. // we are not inside a course, so we reset the course id
  14. $cidReset = true;
  15. // setting the global file that gets the general configuration, the databases, the languages, ...
  16. require_once '../inc/global.inc.php';
  17. $this_section = SECTION_MYAGENDA;
  18. require_once api_get_path(LIBRARY_PATH).'groupmanager.lib.php';
  19. require_once api_get_path(LIBRARY_PATH).'sessionmanager.lib.php';
  20. require_once 'agenda.inc.php';
  21. require_once 'myagenda.inc.php';
  22. //This code is not yet stable
  23. //Blocking the access
  24. api_not_allowed();
  25. api_block_anonymous_users();
  26. // setting the name of the tool
  27. $nameTools = get_lang('MyAgenda');
  28. $is_platform_admin = api_is_platform_admin();
  29. $is_drh = api_is_drh();
  30. if (!($is_platform_admin || $is_drh)) {
  31. api_not_allowed();
  32. }
  33. // if we come from inside a course and click on the 'My Agenda' link we show a link back to the course
  34. // in the breadcrumbs
  35. //remove this if cause it was showing in agenda general
  36. /*if(!empty($_GET['coursePath'])) {
  37. $course_path = api_htmlentities(strip_tags($_GET['coursePath']),ENT_QUOTES,$charset);
  38. $course_path = str_replace(array('../','..\\'),array('',''),$course_path);
  39. }
  40. */
  41. if (!empty ($course_path)) {
  42. $interbreadcrumb[] = array ('url' => api_get_path(WEB_COURSE_PATH).urlencode($course_path).'/index.php', 'name' => Security::remove_XSS($_GET['courseCode']));
  43. }
  44. // this loads the javascript that is needed for the date popup selection
  45. //$htmlHeadXtra[] = "<script src=\"tbl_change.js\" type=\"text/javascript\" language=\"javascript\"></script>";
  46. // showing the header
  47. Display::display_header(get_lang('MyAgenda'));
  48. function display_mymonthcalendar_2($agendaitems, $month, $year, $weekdaynames=array(), $monthName, $session_id) {
  49. global $DaysShort, $course_path;
  50. //Handle leap year
  51. $numberofdays = array (0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
  52. if (($year % 400 == 0) or ($year % 4 == 0 and $year % 100 <> 0))
  53. $numberofdays[2] = 29;
  54. //Get the first day of the month
  55. $dayone = getdate(mktime(0, 0, 0, $month, 1, $year));
  56. //Start the week on monday
  57. $startdayofweek = $dayone['wday'] <> 0 ? ($dayone['wday'] - 1) : 6;
  58. $g_cc = (isset($_GET['courseCode'])?$_GET['courseCode']:'');
  59. $backwardsURL = api_get_self()."?coursePath=".urlencode($course_path)."&amp;session=".Security::remove_XSS($session_id)."&amp;courseCode=".Security::remove_XSS($g_cc)."&amp;action=view&amp;view=month&amp;month=". ($month == 1 ? 12 : $month -1)."&amp;year=". ($month == 1 ? $year -1 : $year);
  60. $forewardsURL = api_get_self()."?coursePath=".urlencode($course_path)."&amp;session=".Security::remove_XSS($session_id)."&amp;courseCode=".Security::remove_XSS($g_cc)."&amp;action=view&amp;view=month&amp;month=". ($month == 12 ? 1 : $month +1)."&amp;year=". ($month == 12 ? $year +1 : $year);
  61. echo "<table class=\"data_table\">\n", "<tr>\n", "<th width=\"10%\"><a href=\"", $backwardsURL, "\">&#171;</a></th>\n", "<th width=\"80%\" colspan=\"5\">", $monthName, " ", $year, "</th>\n", "<th width=\"10%\"><a href=\"", $forewardsURL, "\">&#187;</a></th>\n", "</tr>\n";
  62. echo "<tr>\n";
  63. for ($ii = 1; $ii < 8; $ii ++)
  64. {
  65. echo "<td class=\"weekdays\">", $DaysShort[$ii % 7], "</td>\n";
  66. }
  67. echo "</tr>\n";
  68. $curday = -1;
  69. $today = getdate();
  70. while ($curday <= $numberofdays[$month]) {
  71. echo "<tr>\n";
  72. for ($ii = 0; $ii < 7; $ii ++) {
  73. if (($curday == -1) && ($ii == $startdayofweek)) {
  74. $curday = 1;
  75. }
  76. if (($curday > 0) && ($curday <= $numberofdays[$month])) {
  77. $bgcolor = $ii < 5 ? $class = "class=\"days_week\" style=\"width:10%;\"" : $class = "class=\"days_weekend\" style=\"width:10%;\"";
  78. $dayheader = "<b>$curday</b><br />";
  79. if (($curday == $today['mday']) && ($year == $today['year']) && ($month == $today['mon'])) {
  80. $dayheader = "<b>$curday - ".get_lang("Today")."</b><br />";
  81. $class = "class=\"days_today\" style=\"width:10%;\"";
  82. }
  83. echo "<td ".$class.">", "".$dayheader;
  84. if (!empty($agendaitems[$curday])) {
  85. echo "<span class=\"agendaitem\">".$agendaitems[$curday]."</span>";
  86. }
  87. echo "</td>\n";
  88. $curday ++;
  89. } else {
  90. echo "<td>&nbsp;</td>\n";
  91. }
  92. }
  93. echo "</tr>\n";
  94. }
  95. echo "</table>\n";
  96. }
  97. function get_agenda_items_by_course_list($course_list, $month, $year, $session_id = 0) {
  98. global $setting_agenda_link;
  99. //echo $sql = 'SELECT name FROM chamilo_main.class WHERE name = "'.$grado.'" ORDER BY name ASC';
  100. //$result = Database::query($sql);
  101. //while ($row = Database::fetch_array($result, 'ASSOC')) {
  102. $agendaitems = array ();
  103. $course_name_list = array();
  104. foreach ($course_list as $course) {
  105. $db_name = $course['db_name'];
  106. $code = $course['code'];
  107. $title = $course['title'];
  108. $course_name_list[] = $title;
  109. //$sql2 = 'SELECT code, db_name, title FROM chamilo_main.course WHERE category_code = "'.$course_name.'" ';
  110. // $courses_dbs = Database::query($sql2);
  111. $items = array ();
  112. // $courses_dbs = array();
  113. // get agenda-items for every course
  114. //while($row2 = Database::fetch_array($courses_dbs, 'ASSOC')) {
  115. //$db_name = $row2['db_name'];
  116. //$code = $row2['code'];
  117. //$title = $row2['title'];
  118. //echo "<center><h2>".$db_name."</h2></center>";
  119. //databases of the courses
  120. $TABLEAGENDA = Database :: get_course_table(TABLE_AGENDA, $db_name);
  121. $TABLE_ITEMPROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY, $db_name);
  122. //$group_memberships = GroupManager :: get_group_ids($array_course_info["db"], $_user['user_id']);
  123. // if the user is administrator of that course we show all the agenda items
  124. $session_condition = '';
  125. if ($session_id != 0) {
  126. $session_id = intval($session_id);
  127. $session_condition = "AND session_id = $session_id";
  128. }
  129. $sqlquery = "SELECT DISTINCT agenda.*, item_property.*
  130. FROM ".$TABLEAGENDA." agenda,
  131. ".$TABLE_ITEMPROPERTY." item_property
  132. WHERE agenda.id = item_property.ref
  133. AND MONTH(agenda.start_date)='".$month."'
  134. AND YEAR(agenda.start_date)='".$year."'
  135. AND item_property.tool='".TOOL_CALENDAR_EVENT."'
  136. AND item_property.visibility='1' $session_condition
  137. GROUP BY agenda.id
  138. ORDER BY start_date ";
  139. $result = Database::query($sqlquery);
  140. while ($item = Database::fetch_array($result,'ASSOC')) {
  141. //var_dump($item);
  142. //taking the day
  143. $agendaday = date("j",strtotime($item['start_date']));
  144. if(!isset($items[$agendaday])){$items[$agendaday]=array();}
  145. //taking the time
  146. $time = date("H:i",strtotime($item['start_date']));
  147. //var_dump($time );
  148. $end_time= date("H:i",strtotime($item['end_date']));
  149. $URL = api_get_path(WEB_PATH)."main/calendar/allagendas.php?cidReq=".urlencode($code)."&amp;sort=asc&amp;view=list&amp;day=$agendaday&amp;month=$month&amp;year=$year#$agendaday"; // RH //Patrick Cool: to highlight the relevant agenda item
  150. //var_dump($URL);
  151. if ($setting_agenda_link == 'coursecode') {
  152. //$title=$array_course_info['title'];
  153. $agenda_link = api_substr($title, 0, 14);
  154. } else {
  155. $agenda_link = Display::return_icon('course_home.gif');
  156. }
  157. if(!isset($items[$agendaday][$item['start_date']])) {
  158. $items[$agendaday][$item['start_date']] = '';
  159. }
  160. $items[$agendaday][$item['start_date']] .= "".get_lang('StartTimeWindow')."&nbsp;<i>".$time."</i>"."&nbsp;-&nbsp;".get_lang("EndTimeWindow")."&nbsp;<i>".$end_time."</i>&nbsp;";
  161. $items[$agendaday][$item['start_date']] .= '<br />'."<b><a href=\"$URL\" title=\"".Security::remove_XSS($title)."\">".$agenda_link."</a> </b> ".Security::remove_XSS($item['title'])."<br /> ";
  162. $items[$agendaday][$item['start_date']] .= '<br/>';
  163. }
  164. if (is_array($items) && count($items) > 0) {
  165. while (list ($agendaday, $tmpitems) = each($items)) {
  166. if(!isset($agendaitems[$agendaday])) {
  167. $agendaitems[$agendaday] = '';
  168. }
  169. sort($tmpitems);
  170. while (list ($key, $val) = each($tmpitems)) {
  171. $agendaitems[$agendaday] .= $val;
  172. }
  173. }
  174. }
  175. }
  176. echo "<h1>Courses:</h1> <h3>".implode(', ',$course_name_list)."</h3>";
  177. return $agendaitems;
  178. }
  179. /* SETTING SOME VARIABLES */
  180. // the variables for the days and the months
  181. // Defining the shorts for the days
  182. $DaysShort = api_get_week_days_short();
  183. // Defining the days of the week to allow translation of the days
  184. $DaysLong = api_get_week_days_long();
  185. // Defining the months of the year to allow translation of the months
  186. $MonthsLong = api_get_months_long();
  187. /*
  188. TREATING THE URL PARAMETERS
  189. 1. The default values
  190. 2. storing it in the session
  191. 3. possible view
  192. 3.a Month view
  193. 3.b Week view
  194. 3.c day view
  195. 3.d personal view (only the personal agenda items)
  196. */
  197. // 1. The default values. if there is no session yet, we have by default the month view
  198. if (empty($_SESSION['view'])) {
  199. $_SESSION['view'] = 'month';
  200. }
  201. // 2. Storing it in the session. If we change the view by clicking on the links left, we change the session
  202. if (!empty($_GET['view'])) {
  203. $_SESSION['view'] = Security::remove_XSS($_GET['view']);
  204. }
  205. // 3. The views: (month, week, day, personal)
  206. if ($_SESSION['view']) {
  207. switch ($_SESSION['view']) {
  208. // 3.a Month view
  209. case "month" :
  210. $process = "month_view";
  211. break;
  212. // 3.a Week view
  213. case "week" :
  214. $process = "week_view";
  215. break;
  216. // 3.a Day view
  217. case "day" :
  218. $process = "day_view";
  219. break;
  220. // 3.a Personal view
  221. case "personal" :
  222. $process = "personal_view";
  223. break;
  224. }
  225. }
  226. $my_course_id = intval($_GET['course']);
  227. $my_session_id = intval($_GET['session']);
  228. $my_course_list = array();
  229. if(!empty($my_session_id)) {
  230. $_SESSION['my_course_list'] = array();
  231. $my_course_list = array();
  232. } else {
  233. //echo 'here';
  234. $my_course_list = $_SESSION['my_course_list'];
  235. //var_dump($_SESSION['my_course_list'], $my_course_list);
  236. $my_course_list_keys = array_keys($my_course_list);
  237. //var_dump($my_course_list, $my_course_list_keys);
  238. if (!in_array($my_course_id, $my_course_list_keys)) {
  239. $course_info = api_get_course_info_by_id($my_course_id);
  240. $_SESSION['my_course_list'][$my_course_id] = $course_info;
  241. $my_course_list = $_SESSION['my_course_list'];
  242. //echo $my_course_id.'added ';
  243. }
  244. if (isset($_GET['delete_course_option'])) {
  245. $course_id_to_delete = intval($_GET['delete_course_option']);
  246. unset($_SESSION['my_course_list'][$course_id_to_delete]);
  247. $my_course_list = $_SESSION['my_course_list'];
  248. }
  249. //clean the array
  250. $my_course_list = array_filter($my_course_list);
  251. }
  252. /* OUTPUT */
  253. if (isset ($_user['user_id'])) {
  254. // getting all the courses that this user is subscribed to
  255. $courses_dbs = get_all_courses_of_user();
  256. if (!is_array($courses_dbs)) {
  257. // this is for the special case if the user has no courses (otherwise you get an error)
  258. $courses_dbs = array ();
  259. }
  260. // setting and/or getting the year, month, day, week
  261. $today = getdate();
  262. $year = (!empty($_GET['year'])? (int)$_GET['year'] : NULL);
  263. if ($year == NULL)
  264. {
  265. $year = $today['year'];
  266. }
  267. $month = (!empty($_GET['month'])? (int)$_GET['month']:NULL);
  268. if ($month == NULL)
  269. {
  270. $month = $today['mon'];
  271. }
  272. $day = (!empty($_GET['day']) ? (int)$_GET['day']:NULL);
  273. if ($day == NULL)
  274. {
  275. $day = $today['mday'];
  276. }
  277. $week = (!empty($_GET['week']) ?(int)$_GET['week']:NULL);
  278. if ($week == NULL)
  279. {
  280. $week = date("W");
  281. }
  282. // The name of the current Month
  283. $monthName = $MonthsLong[$month -1];
  284. if (api_is_platform_admin()) {
  285. $courses = array();
  286. $sessions = SessionManager::get_sessions_list();
  287. } elseif(api_is_drh()) {
  288. $courses = CourseManager::get_courses_followed_by_drh(api_get_user_id());
  289. $sessions = SessionManager::get_sessions_followed_by_drh(api_get_user_id());
  290. }
  291. echo '<table width="100%" border="0" cellspacing="0" cellpadding="0">';
  292. echo '<tr>';
  293. // output: the small calendar item on the left and the view / add links
  294. echo '<td width="220" valign="top">';
  295. echo '<br />';
  296. if (count($courses) > 0) {
  297. echo '<h1>'.get_lang('SelectACourse').'</h1>';
  298. foreach ($courses as $row_course) {
  299. $course_code = $row_course['id'];
  300. $title = $row_course['title'];
  301. $my_course_list_keys = array_keys($my_course_list);
  302. if (!in_array($course_code, $my_course_list_keys)) {
  303. echo '<a href="allagendas.php?course='.$course_code.'">'.$title.'</a><br />';
  304. } else {
  305. echo ''.$title.' <a href="allagendas.php?delete_course_option='.$course_code.'">Delete</a><br />';
  306. }
  307. }
  308. }
  309. if (count($sessions) > 0) {
  310. echo '<h1>'.get_lang('SelectASession').'</h1>';
  311. foreach ($sessions as $session) {
  312. $id = $session['id'];
  313. $name = $session['name'];
  314. echo '<a href="allagendas.php?session='.$id.'">'.$name.'</a><br />';
  315. }
  316. }
  317. echo '</td>';
  318. // the divider
  319. // OlivierB : the image has a white background, which causes trouble if the portal has another background color. Image should be transparent. ----> echo "<td width=\"20\" background=\"../img/verticalruler.gif\">&nbsp;</td>";
  320. echo "<td width=\"20\">&nbsp;</td>";
  321. // the main area: day, week, month view
  322. echo '<td valign="top">';
  323. //@todo hardcoding option
  324. $process = 'month_view';
  325. switch ($process) {
  326. case "month_view" :
  327. $session_id = 0;
  328. //By courses
  329. if (is_array($my_course_list) && count($my_course_list) > 0) {
  330. $course_list = $my_course_list;
  331. } else {
  332. //session
  333. $course_list = SessionManager::get_course_list_by_session_id($my_session_id);
  334. $session_id = $my_session_id;
  335. echo '<h1>'.$sessions[$session_id]['name'].'</h1>';
  336. }
  337. if (is_array($course_list) && count($course_list) > 0) {
  338. $agendaitems = get_agenda_items_by_course_list($course_list, $month, $year, $session_id);
  339. //$agendaitems = get_global_agenda_items($agendaitems, $day, $month, $year, $week, "month_view");
  340. display_mymonthcalendar_2($agendaitems, $month, $year, array(), $monthName, $session_id);
  341. } else {
  342. Display::display_warning_message(get_lang('PleaseSelectACourseOrASessionInTheLeftColumn'));
  343. }
  344. break;
  345. }
  346. }
  347. echo "</td></tr></table>";
  348. Display :: display_footer();