PageRenderTime 45ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/main/calendar/allagendas.php

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