allagendas.php 13 KB

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