resume_session.php 14 KB

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