resume_session.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @author Bart Mollet, Julio Montoya lot of fixes
  5. * @package chamilo.admin
  6. */
  7. /* INIT SECTION */
  8. // name of the language file that needs to be included
  9. $language_file = 'admin';
  10. $cidReset = true;
  11. require_once '../inc/global.inc.php';
  12. // setting the section (for the tabs)
  13. $this_section = SECTION_PLATFORM_ADMIN;
  14. $id_session = (int)$_GET['id_session'];
  15. SessionManager::protect_session_edit($id_session);
  16. $tool_name = get_lang('SessionOverview');
  17. $interbreadcrumb[]=array('url' => 'index.php','name' => get_lang('PlatformAdmin'));
  18. $interbreadcrumb[]=array('url' => 'session_list.php','name' => get_lang('SessionList'));
  19. // Database Table Definitions
  20. $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
  21. $tbl_session_rel_class = Database::get_main_table(TABLE_MAIN_SESSION_CLASS);
  22. $tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
  23. $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
  24. $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
  25. $tbl_session_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_USER);
  26. $tbl_session_rel_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  27. $tbl_session_category = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY);
  28. $table_access_url_user = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
  29. $sql = 'SELECT name, nbr_courses, nbr_users, nbr_classes, DATE_FORMAT(date_start,"%d-%m-%Y") as date_start, DATE_FORMAT(date_end,"%d-%m-%Y") as date_end, lastname, firstname, username, session_admin_id, nb_days_access_before_beginning, nb_days_access_after_end, session_category_id, visibility
  30. FROM '.$tbl_session.' LEFT JOIN '.$tbl_user.' ON id_coach = user_id
  31. WHERE '.$tbl_session.'.id='.$id_session;
  32. $rs = Database::query($sql);
  33. $session = Database::store_result($rs);
  34. $session = $session[0];
  35. $sql = 'SELECT name FROM '.$tbl_session_category.' WHERE id = "'.intval($session['session_category_id']).'"';
  36. $rs = Database::query($sql);
  37. $session_category = '';
  38. if (Database::num_rows($rs)>0) {
  39. $rows_session_category = Database::store_result($rs);
  40. $rows_session_category = $rows_session_category[0];
  41. $session_category = $rows_session_category['name'];
  42. }
  43. $action = $_GET['action'];
  44. $url_id = api_get_current_access_url_id();
  45. switch($action) {
  46. case 'add_user_to_url':
  47. $user_id = $_REQUEST['user_id'];
  48. $result = UrlManager::add_user_to_url($user_id, $url_id);
  49. $user_info = api_get_user_info($user_id);
  50. if ($result) {
  51. $message = Display::return_message(get_lang('UserAdded').' '.api_get_person_name($user_info['firstname'], $user_info['lastname']), 'confirm');
  52. }
  53. break;
  54. case 'delete':
  55. $idChecked = $_GET['idChecked'];
  56. if(is_array($idChecked)) {
  57. $my_temp = array();
  58. foreach ($idChecked as $id){
  59. $my_temp[]= Database::escape_string($id);// forcing the escape_string
  60. }
  61. $idChecked = $my_temp;
  62. $idChecked="'".implode("','",$idChecked)."'";
  63. Database::query("DELETE FROM $tbl_session_rel_course WHERE id_session='$id_session' AND course_code IN($idChecked)");
  64. $nbr_affected_rows=Database::affected_rows();
  65. Database::query("DELETE FROM $tbl_session_rel_course_rel_user WHERE id_session='$id_session' AND course_code IN($idChecked)");
  66. Database::query("UPDATE $tbl_session SET nbr_courses=nbr_courses-$nbr_affected_rows WHERE id='$id_session'");
  67. }
  68. if(!empty($_GET['class'])){
  69. Database::query("DELETE FROM $tbl_session_rel_class WHERE session_id='$id_session' AND class_id=".Database::escape_string($_GET['class']));
  70. $nbr_affected_rows=Database::affected_rows();
  71. Database::query("UPDATE $tbl_session SET nbr_classes=nbr_classes-$nbr_affected_rows WHERE id='$id_session'");
  72. }
  73. if (!empty($_GET['user'])) {
  74. Database::query("DELETE FROM $tbl_session_rel_user WHERE relation_type<>".SESSION_RELATION_TYPE_RRHH." AND id_session='$id_session' AND id_user=".intval($_GET['user']));
  75. $nbr_affected_rows=Database::affected_rows();
  76. Database::query("UPDATE $tbl_session SET nbr_users=nbr_users-$nbr_affected_rows WHERE id='$id_session'");
  77. Database::query("DELETE FROM $tbl_session_rel_course_rel_user WHERE id_session='$id_session' AND id_user=".intval($_GET['user']));
  78. $nbr_affected_rows=Database::affected_rows();
  79. Database::query("UPDATE $tbl_session_rel_course SET nbr_users=nbr_users-$nbr_affected_rows WHERE id_session='$id_session'");
  80. }
  81. break;
  82. }
  83. Display::display_header($tool_name);
  84. if (!empty($_GET['warn'])) {
  85. Display::display_warning_message(urldecode($_GET['warn']));
  86. }
  87. if (!empty($message)) {
  88. echo $message;
  89. }
  90. echo Display::page_header(Display::return_icon('session.png', get_lang('Session')).' '.$session['name']);
  91. ?>
  92. <!-- General properties -->
  93. <table class="data_table" width="100%">
  94. <tr>
  95. <th align="center" colspan="2">
  96. <?php echo get_lang('GeneralProperties'); ?>
  97. <a href="session_edit.php?page=resume_session.php&id=<?php echo $id_session; ?>">
  98. <?php Display::display_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL); ?>
  99. </a>
  100. </th>
  101. </tr>
  102. <tr>
  103. <td><?php echo get_lang('GeneralCoach'); ?> :</td>
  104. <td><?php echo api_get_person_name($session['firstname'], $session['lastname']).' ('.$session['username'].')' ?></td>
  105. </tr>
  106. <?php if(!empty($session_category)) { ?>
  107. <tr>
  108. <td><?php echo get_lang('SessionCategory') ?></td>
  109. <td><?php echo $session_category; ?></td>
  110. </tr>
  111. <?php } ?>
  112. <tr>
  113. <td><?php echo get_lang('Date'); ?> :</td>
  114. <td>
  115. <?php
  116. if ($session['date_start'] == '00-00-0000' && $session['date_end']== '00-00-0000' )
  117. echo get_lang('NoTimeLimits');
  118. else {
  119. if ($session['date_start'] != '00-00-0000') {
  120. //$session['date_start'] = Display::tag('i', get_lang('NoTimeLimits'));
  121. $session['date_start'] = get_lang('From').' '.$session['date_start'];
  122. } else {
  123. $session['date_start'] = '';
  124. }
  125. if ($session['date_end'] == '00-00-0000') {
  126. $session['date_end'] ='';
  127. } else {
  128. $session['date_end'] = get_lang('Until').' '.$session['date_end'];
  129. }
  130. echo $session['date_start'].' '.$session['date_end'];
  131. }
  132. ?>
  133. </td>
  134. </tr>
  135. <!-- show nb_days_before and nb_days_after only if they are different from 0 -->
  136. <tr>
  137. <td>
  138. <?php echo api_ucfirst(get_lang('DaysBefore')) ?> :
  139. </td>
  140. <td>
  141. <?php echo intval($session['nb_days_access_before_beginning']) ?>
  142. </td>
  143. </tr>
  144. <tr>
  145. <td>
  146. <?php echo api_ucfirst(get_lang('DaysAfter')) ?> :
  147. </td>
  148. <td>
  149. <?php echo intval($session['nb_days_access_after_end']) ?>
  150. </td>
  151. </tr>
  152. <tr>
  153. <td>
  154. <?php echo api_ucfirst(get_lang('SessionVisibility')) ?> :
  155. </td>
  156. <td>
  157. <?php if ($session['visibility']==1) echo get_lang('ReadOnly'); elseif($session['visibility']==2) echo get_lang('Visible');elseif($session['visibility']==3) echo api_ucfirst(get_lang('Invisible')) ?>
  158. </td>
  159. </tr>
  160. <?php
  161. $multiple_url_is_on = api_get_multiple_access_url();
  162. if ($multiple_url_is_on) {
  163. echo '<tr><td>';
  164. echo 'URL';
  165. echo '</td>';
  166. echo '<td>';
  167. $url_list = UrlManager::get_access_url_from_session($id_session);
  168. foreach($url_list as $url_data) {
  169. echo $url_data['url'].'<br />';
  170. }
  171. echo '</td></tr>';
  172. }
  173. ?>
  174. </table>
  175. <br />
  176. <!--List of courses -->
  177. <table class="data_table" width="100%">
  178. <tr>
  179. <th align="center" colspan="4">
  180. <?php echo get_lang('CourseList'); ?>
  181. <a href="add_courses_to_session.php?page=resume_session.php&id_session=<?php echo $id_session; ?>">
  182. <?php Display::display_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL); ?>
  183. </a>
  184. </th>
  185. </tr>
  186. <tr>
  187. <th width="35%"><?php echo get_lang('CourseTitle'); ?></th>
  188. <th width="30%"><?php echo get_lang('CourseCoach'); ?></th>
  189. <th width="20%"><?php echo get_lang('UsersNumber'); ?></th>
  190. <th width="15%"><?php echo get_lang('Actions'); ?></th>
  191. </tr>
  192. <?php
  193. if ($session['nbr_courses'] == 0){
  194. echo '<tr>
  195. <td colspan="4">'.get_lang('NoCoursesForThisSession').'</td>
  196. </tr>';
  197. } else {
  198. // select the courses
  199. $sql = "SELECT code,title,visual_code, nbr_users
  200. FROM $tbl_course,$tbl_session_rel_course
  201. WHERE course_code = code
  202. AND id_session='$id_session'
  203. ORDER BY title";
  204. $result=Database::query($sql);
  205. $courses=Database::store_result($result);
  206. foreach ($courses as $course) {
  207. //select the number of users
  208. $sql = " SELECT count(*) FROM $tbl_session_rel_user sru, $tbl_session_rel_course_rel_user srcru
  209. WHERE srcru.id_user = sru.id_user AND srcru.id_session = sru.id_session AND srcru.course_code = '".Database::escape_string($course['code'])."'
  210. AND sru.relation_type<>".SESSION_RELATION_TYPE_RRHH." AND srcru.id_session = '".intval($id_session)."'";
  211. $rs = Database::query($sql);
  212. $course['nbr_users'] = Database::result($rs,0,0);
  213. // Get coachs of the courses in session
  214. $sql = "SELECT user.lastname,user.firstname,user.username FROM $tbl_session_rel_course_rel_user session_rcru, $tbl_user user
  215. WHERE session_rcru.id_user = user.user_id AND session_rcru.id_session = '".intval($id_session)."' AND session_rcru.course_code ='".Database::escape_string($course['code'])."' AND session_rcru.status=2";
  216. $rs = Database::query($sql);
  217. $coachs = array();
  218. if (Database::num_rows($rs) > 0) {
  219. while($info_coach = Database::fetch_array($rs)) {
  220. $coachs[] = api_get_person_name($info_coach['firstname'], $info_coach['lastname']).' ('.$info_coach['username'].')';
  221. }
  222. } else {
  223. $coach = get_lang('None');
  224. }
  225. if (count($coachs) > 0) {
  226. $coach = implode('<br />',$coachs);
  227. } else {
  228. $coach = get_lang('None');
  229. }
  230. $orig_param = '&origin=resume_session';
  231. //hide_course_breadcrumb the parameter has been added to hide the name of the course, that appeared in the default $interbreadcrumb
  232. echo '
  233. <tr>
  234. <td>'.Display::url($course['title'].' ('.$course['visual_code'].')', api_get_path(WEB_COURSE_PATH).$course['code'].'/?id_session='.$id_session),'</td>
  235. <td>'.$coach.'</td>
  236. <td>'.$course['nbr_users'].'</td>
  237. <td>
  238. <a href="'.api_get_path(WEB_COURSE_PATH).$course['code'].'/?id_session='.$id_session.'">'.Display::return_icon('course_home.gif', get_lang('Course')).'</a>
  239. <a href="session_course_user_list.php?id_session='.$id_session.'&course_code='.$course['code'].'">'.Display::return_icon('user.png', get_lang('Edit'), '', ICON_SIZE_SMALL).'</a>
  240. <a href="../tracking/courseLog.php?id_session='.$id_session.'&cidReq='.$course['code'].$orig_param.'&hide_course_breadcrumb=1">'.Display::return_icon('statistics.gif', get_lang('Tracking')).'</a>&nbsp;
  241. <a href="session_course_edit.php?id_session='.$id_session.'&page=resume_session.php&course_code='.$course['code'].''.$orig_param.'">'.Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL).'</a>
  242. <a href="'.api_get_self().'?id_session='.$id_session.'&action=delete&idChecked[]='.$course['code'].'" onclick="javascript:if(!confirm(\''.get_lang('ConfirmYourChoice').'\')) return false;">'.Display::return_icon('delete.png', get_lang('Delete')).'</a>
  243. </td>
  244. </tr>';
  245. }
  246. }
  247. ?>
  248. </table>
  249. <br />
  250. <!--List of courses -->
  251. <table class="data_table" width="100%">
  252. <tr>
  253. <th align="center" colspan="4">
  254. <?php echo get_lang('UserList'); ?>
  255. <a href="add_users_to_session.php?page=resume_session.php&id_session=<?php echo $id_session; ?>">
  256. <?php Display::display_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL); ?>
  257. </a>
  258. </th>
  259. </tr>
  260. <?php
  261. if ($session['nbr_users']==0) {
  262. echo '<tr>
  263. <td colspan="2">'.get_lang('NoUsersForThisSession').'</td>
  264. </tr>';
  265. } else {
  266. $order_clause = api_sort_by_first_name() ? ' ORDER BY firstname, lastname' : ' ORDER BY lastname, firstname';
  267. if ($multiple_url_is_on) {
  268. $sql = "SELECT u.user_id, lastname, firstname, username, access_url_id
  269. FROM $tbl_user u
  270. INNER JOIN $tbl_session_rel_user su
  271. ON u.user_id = su.id_user AND su.relation_type<>".SESSION_RELATION_TYPE_RRHH."
  272. LEFT OUTER JOIN $table_access_url_user uu ON (uu.user_id = u.user_id)
  273. WHERE su.id_session = $id_session AND (access_url_id = $url_id OR access_url_id is null )
  274. $order_clause";
  275. } else {
  276. $sql = "SELECT u.user_id, lastname, firstname, username
  277. FROM $tbl_user u
  278. INNER JOIN $tbl_session_rel_user su
  279. ON u.user_id = su.id_user AND su.relation_type<>".SESSION_RELATION_TYPE_RRHH."
  280. AND su.id_session = ".$id_session.$order_clause;
  281. }
  282. $result = Database::query($sql);
  283. $users = Database::store_result($result);
  284. $orig_param = '&origin=resume_session&id_session='.$id_session; // change breadcrumb in destination page
  285. foreach ($users as $user){
  286. $user_link = '';
  287. if (!empty($user['user_id'])) {
  288. $user_link = '<a href="'.api_get_path(WEB_CODE_PATH).'admin/user_information.php?user_id='.intval($user['user_id']).'">'.api_htmlentities(api_get_person_name($user['firstname'], $user['lastname']),ENT_QUOTES,$charset).' ('.$user['username'].')</a>';
  289. }
  290. $link_to_add_user_in_url = '';
  291. if ($multiple_url_is_on) {
  292. if ($user['access_url_id'] != $url_id) {
  293. $user_link .= ' '.Display::return_icon('warning.png', get_lang('UserNotAddedInURL'), array(), ICON_SIZE_SMALL);
  294. $add = Display::return_icon('add.png', get_lang('AddUsersToURL'), array(), ICON_SIZE_SMALL);
  295. $link_to_add_user_in_url = '<a href="resume_session.php?action=add_user_to_url&id_session='.$id_session.'&user_id='.$user['user_id'].'">'.$add.'</a>';
  296. }
  297. }
  298. echo '<tr>
  299. <td width="90%">
  300. <b>'.$user_link.'</b>
  301. </td>
  302. <td>
  303. <a href="../mySpace/myStudents.php?student='.$user['user_id'].''.$orig_param.'">'.Display::return_icon('statistics.gif', get_lang('Reporting')).'</a>&nbsp;
  304. <a href="session_course_user.php?id_user='.$user['user_id'].'&id_session='.$id_session.'">'.Display::return_icon('course.gif', get_lang('BlockCoursesForThisUser')).'</a>&nbsp;
  305. <a href="'.api_get_self().'?id_session='.$id_session.'&action=delete&user='.$user['user_id'].'" onclick="javascript:if(!confirm(\''.get_lang('ConfirmYourChoice').'\')) return false;">'.Display::return_icon('delete.png', get_lang('Delete')).'</a>
  306. '.$link_to_add_user_in_url.'
  307. </td>
  308. </tr>';
  309. }
  310. }
  311. ?>
  312. </table>
  313. <?php
  314. // footer
  315. Display :: display_footer();