allagendas.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  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,
  7. * all agenda feature work with courses and sessions,
  8. * only admins and rrhh users can see this page
  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. //taking the day
  141. $agendaday = date("j",strtotime($item['start_date']));
  142. if(!isset($items[$agendaday])){$items[$agendaday]=array();}
  143. //taking the time
  144. $time = date("H:i",strtotime($item['start_date']));
  145. $end_time= date("H:i",strtotime($item['end_date']));
  146. $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
  147. if ($setting_agenda_link == 'coursecode') {
  148. //$title=$array_course_info['title'];
  149. $agenda_link = api_substr($title, 0, 14);
  150. } else {
  151. $agenda_link = Display::return_icon('course_home.gif');
  152. }
  153. if(!isset($items[$agendaday][$item['start_date']])) {
  154. $items[$agendaday][$item['start_date']] = '';
  155. }
  156. $items[$agendaday][$item['start_date']] .= "".get_lang('StartTimeWindow')."&nbsp;<i>".$time."</i>"."&nbsp;-&nbsp;".get_lang("EndTimeWindow")."&nbsp;<i>".$end_time."</i>&nbsp;";
  157. $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 /> ";
  158. $items[$agendaday][$item['start_date']] .= '<br/>';
  159. }
  160. if (is_array($items) && count($items) > 0) {
  161. while (list ($agendaday, $tmpitems) = each($items)) {
  162. if(!isset($agendaitems[$agendaday])) {
  163. $agendaitems[$agendaday] = '';
  164. }
  165. sort($tmpitems);
  166. while (list ($key, $val) = each($tmpitems)) {
  167. $agendaitems[$agendaday] .= $val;
  168. }
  169. }
  170. }
  171. }
  172. echo "<h1>Courses:</h1> <h3>".implode(', ',$course_name_list)."</h3>";
  173. return $agendaitems;
  174. }
  175. /* SETTING SOME VARIABLES */
  176. // the variables for the days and the months
  177. // Defining the shorts for the days
  178. $DaysShort = api_get_week_days_short();
  179. // Defining the days of the week to allow translation of the days
  180. $DaysLong = api_get_week_days_long();
  181. // Defining the months of the year to allow translation of the months
  182. $MonthsLong = api_get_months_long();
  183. /*
  184. TREATING THE URL PARAMETERS
  185. 1. The default values
  186. 2. storing it in the session
  187. 3. possible view
  188. 3.a Month view
  189. 3.b Week view
  190. 3.c day view
  191. 3.d personal view (only the personal agenda items)
  192. */
  193. // 1. The default values. if there is no session yet, we have by default the month view
  194. if (empty($_SESSION['view'])) {
  195. $_SESSION['view'] = 'month';
  196. }
  197. // 2. Storing it in the session. If we change the view by clicking on the links left, we change the session
  198. if (!empty($_GET['view'])) {
  199. $_SESSION['view'] = Security::remove_XSS($_GET['view']);
  200. }
  201. // 3. The views: (month, week, day, personal)
  202. if ($_SESSION['view']) {
  203. switch ($_SESSION['view']) {
  204. // 3.a Month view
  205. case "month" :
  206. $process = "month_view";
  207. break;
  208. // 3.a Week view
  209. case "week" :
  210. $process = "week_view";
  211. break;
  212. // 3.a Day view
  213. case "day" :
  214. $process = "day_view";
  215. break;
  216. // 3.a Personal view
  217. case "personal" :
  218. $process = "personal_view";
  219. break;
  220. }
  221. }
  222. $my_course_id = intval($_GET['course']);
  223. $my_session_id = intval($_GET['session']);
  224. $my_course_list = array();
  225. if(!empty($my_session_id)) {
  226. $_SESSION['my_course_list'] = array();
  227. $my_course_list = array();
  228. } else {
  229. $my_course_list = $_SESSION['my_course_list'];
  230. $my_course_list_keys = array_keys($my_course_list);
  231. if (!in_array($my_course_id, $my_course_list_keys)) {
  232. $course_info = api_get_course_info_by_id($my_course_id);
  233. $_SESSION['my_course_list'][$my_course_id] = $course_info;
  234. $my_course_list = $_SESSION['my_course_list'];
  235. //echo $my_course_id.'added ';
  236. }
  237. if (isset($_GET['delete_course_option'])) {
  238. $course_id_to_delete = intval($_GET['delete_course_option']);
  239. unset($_SESSION['my_course_list'][$course_id_to_delete]);
  240. $my_course_list = $_SESSION['my_course_list'];
  241. }
  242. //clean the array
  243. $my_course_list = array_filter($my_course_list);
  244. }
  245. /* OUTPUT */
  246. if (isset ($_user['user_id'])) {
  247. // getting all the courses that this user is subscribed to
  248. $courses_dbs = get_all_courses_of_user();
  249. if (!is_array($courses_dbs)) {
  250. // this is for the special case if the user has no courses (otherwise you get an error)
  251. $courses_dbs = array ();
  252. }
  253. // setting and/or getting the year, month, day, week
  254. $today = getdate();
  255. $year = (!empty($_GET['year'])? (int)$_GET['year'] : NULL);
  256. if ($year == NULL)
  257. {
  258. $year = $today['year'];
  259. }
  260. $month = (!empty($_GET['month'])? (int)$_GET['month']:NULL);
  261. if ($month == NULL)
  262. {
  263. $month = $today['mon'];
  264. }
  265. $day = (!empty($_GET['day']) ? (int)$_GET['day']:NULL);
  266. if ($day == NULL)
  267. {
  268. $day = $today['mday'];
  269. }
  270. $week = (!empty($_GET['week']) ?(int)$_GET['week']:NULL);
  271. if ($week == NULL)
  272. {
  273. $week = date("W");
  274. }
  275. // The name of the current Month
  276. $monthName = $MonthsLong[$month -1];
  277. if (api_is_platform_admin()) {
  278. $courses = array();
  279. $sessions = SessionManager::get_sessions_list();
  280. } elseif(api_is_drh()) {
  281. $courses = CourseManager::get_courses_followed_by_drh(api_get_user_id());
  282. $sessions = SessionManager::get_sessions_followed_by_drh(api_get_user_id());
  283. }
  284. echo '<table width="100%" border="0" cellspacing="0" cellpadding="0">';
  285. echo '<tr>';
  286. // output: the small calendar item on the left and the view / add links
  287. echo '<td width="220" valign="top">';
  288. echo '<br />';
  289. if (count($courses) > 0) {
  290. echo '<h1>'.get_lang('SelectACourse').'</h1>';
  291. foreach ($courses as $row_course) {
  292. $course_code = $row_course['id'];
  293. $title = $row_course['title'];
  294. $my_course_list_keys = array_keys($my_course_list);
  295. if (!in_array($course_code, $my_course_list_keys)) {
  296. echo '<a href="allagendas.php?course='.$course_code.'">'.$title.'</a><br />';
  297. } else {
  298. echo ''.$title.' <a href="allagendas.php?delete_course_option='.$course_code.'">Delete</a><br />';
  299. }
  300. }
  301. }
  302. if (count($sessions) > 0) {
  303. echo '<h1>'.get_lang('SelectASession').'</h1>';
  304. foreach ($sessions as $session) {
  305. $id = $session['id'];
  306. $name = $session['name'];
  307. echo '<a href="allagendas.php?session='.$id.'">'.$name.'</a><br />';
  308. }
  309. }
  310. echo '</td>';
  311. // the divider
  312. // 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>";
  313. echo "<td width=\"20\">&nbsp;</td>";
  314. // the main area: day, week, month view
  315. echo '<td valign="top">';
  316. //@todo hardcoding option
  317. $process = 'month_view';
  318. switch ($process) {
  319. case "month_view" :
  320. $session_id = 0;
  321. //By courses
  322. if (is_array($my_course_list) && count($my_course_list) > 0) {
  323. $course_list = $my_course_list;
  324. } else {
  325. //session
  326. $course_list = SessionManager::get_course_list_by_session_id($my_session_id);
  327. $session_id = $my_session_id;
  328. echo '<h1>'.$sessions[$session_id]['name'].'</h1>';
  329. }
  330. if (is_array($course_list) && count($course_list) > 0) {
  331. $agendaitems = get_agenda_items_by_course_list($course_list, $month, $year, $session_id);
  332. //$agendaitems = get_global_agenda_items($agendaitems, $day, $month, $year, $week, "month_view");
  333. display_mymonthcalendar_2($agendaitems, $month, $year, array(), $monthName, $session_id);
  334. } else {
  335. Display::display_warning_message(get_lang('PleaseSelectACourseOrASessionInTheLeftColumn'));
  336. }
  337. break;
  338. }
  339. }
  340. echo "</td></tr></table>";
  341. Display :: display_footer();