PageRenderTime 23ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/php/main/calendar/allagendas.php

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