resume_session.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @author Bart Mollet
  5. * @package chamilo.admin
  6. */
  7. /*
  8. INIT SECTION
  9. */
  10. // name of the language file that needs to be included
  11. $language_file = 'admin';
  12. $cidReset = true;
  13. require_once '../inc/global.inc.php';
  14. // setting the section (for the tabs)
  15. $this_section=SECTION_PLATFORM_ADMIN;
  16. api_protect_admin_script(true);
  17. $tool_name = get_lang('SessionOverview');
  18. $interbreadcrumb[]=array('url' => 'index.php','name' => get_lang('PlatformAdmin'));
  19. $interbreadcrumb[]=array('url' => 'session_list.php','name' => get_lang('SessionList'));
  20. // Database Table Definitions
  21. $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
  22. $tbl_session_rel_class = Database::get_main_table(TABLE_MAIN_SESSION_CLASS);
  23. $tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
  24. $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
  25. $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
  26. $tbl_session_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_USER);
  27. $tbl_session_rel_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  28. $tbl_class = Database::get_main_table(TABLE_MAIN_CLASS);
  29. $tbl_class_rel_user = Database::get_main_table(TABLE_MAIN_CLASS_USER);
  30. $tbl_session_category = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY);
  31. $id_session = (int)$_GET['id_session'];
  32. $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
  33. FROM '.$tbl_session.'
  34. LEFT JOIN '.$tbl_user.'
  35. ON id_coach = user_id
  36. WHERE '.$tbl_session.'.id='.$id_session;
  37. $rs = Database::query($sql);
  38. $session = Database::store_result($rs);
  39. $session = $session[0];
  40. if(!api_is_platform_admin() && $session['session_admin_id']!=$_user['user_id']) {
  41. api_not_allowed(true);
  42. }
  43. $sql = 'SELECT name FROM '.$tbl_session_category.' WHERE id = "'.intval($session['session_category_id']).'"';
  44. $rs = Database::query($sql);
  45. $session_category = '';
  46. if(Database::num_rows($rs)>0) {
  47. $rows_session_category = Database::store_result($rs);
  48. $rows_session_category = $rows_session_category[0];
  49. $session_category = $rows_session_category['name'];
  50. }
  51. if($_GET['action'] == 'delete')
  52. {
  53. $idChecked = $_GET['idChecked'];
  54. if(is_array($idChecked)) {
  55. $my_temp = array();
  56. foreach ($idChecked as $id){
  57. $my_temp[]= Database::escape_string($id);// forcing the escape_string
  58. }
  59. $idChecked = $my_temp;
  60. $idChecked="'".implode("','",$idChecked)."'";
  61. Database::query("DELETE FROM $tbl_session_rel_course WHERE id_session='$id_session' AND course_code IN($idChecked)");
  62. $nbr_affected_rows=Database::affected_rows();
  63. Database::query("DELETE FROM $tbl_session_rel_course_rel_user WHERE id_session='$id_session' AND course_code IN($idChecked)");
  64. Database::query("UPDATE $tbl_session SET nbr_courses=nbr_courses-$nbr_affected_rows WHERE id='$id_session'");
  65. }
  66. if(!empty($_GET['class'])){
  67. Database::query("DELETE FROM $tbl_session_rel_class WHERE session_id='$id_session' AND class_id=".Database::escape_string($_GET['class']));
  68. $nbr_affected_rows=Database::affected_rows();
  69. Database::query("UPDATE $tbl_session SET nbr_classes=nbr_classes-$nbr_affected_rows WHERE id='$id_session'");
  70. }
  71. if (!empty($_GET['user'])) {
  72. 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']));
  73. $nbr_affected_rows=Database::affected_rows();
  74. Database::query("UPDATE $tbl_session SET nbr_users=nbr_users-$nbr_affected_rows WHERE id='$id_session'");
  75. Database::query("DELETE FROM $tbl_session_rel_course_rel_user WHERE id_session='$id_session' AND id_user=".intval($_GET['user']));
  76. $nbr_affected_rows=Database::affected_rows();
  77. Database::query("UPDATE $tbl_session_rel_course SET nbr_users=nbr_users-$nbr_affected_rows WHERE id_session='$id_session'");
  78. }
  79. }
  80. Display::display_header($tool_name);
  81. if (!empty($_GET['warn'])) {
  82. Display::display_warning_message(urldecode($_GET['warn']));
  83. }
  84. api_display_tool_title($tool_name);
  85. ?>
  86. <!-- General properties -->
  87. <table class="data_table" width="100%">
  88. <tr>
  89. <th colspan="2"><?php echo get_lang('GeneralProperties'); ?>
  90. <a href="session_edit.php?page=resume_session.php&id=<?php echo $id_session; ?>"><?php Display::display_icon('edit.gif', get_lang('Edit')); ?></a></th>
  91. </th>
  92. </tr>
  93. <tr>
  94. <td><?php echo get_lang('SessionName');?> :</td>
  95. <td><?php echo $session['name'] ?></td>
  96. </tr>
  97. <tr>
  98. <td><?php echo get_lang('GeneralCoach'); ?> :</td>
  99. <td><?php echo api_get_person_name($session['firstname'], $session['lastname']).' ('.$session['username'].')' ?></td>
  100. </tr>
  101. <?php if(!empty($session_category)): ?>
  102. <tr>
  103. <td><?php echo get_lang('SessionCategory') ?></td>
  104. <td><?php echo $session_category; ?></td>
  105. </tr>
  106. <?php endif; ?>
  107. <tr>
  108. <td><?php echo get_lang('Date'); ?> :</td>
  109. <td>
  110. <?php
  111. if($session['date_start']=='00-00-0000')
  112. echo get_lang('NoTimeLimits');
  113. else
  114. echo get_lang('From').' '.$session['date_start'].' '.get_lang('To').' '.$session['date_end'];
  115. ?>
  116. </td>
  117. </tr>
  118. <!-- show nb_days_before and nb_days_after only if they are different from 0 -->
  119. <tr>
  120. <td>
  121. <?php echo api_ucfirst(get_lang('DaysBefore')) ?> :
  122. </td>
  123. <td>
  124. <?php echo intval($session['nb_days_access_before_beginning']) ?>
  125. </td>
  126. </tr>
  127. <tr>
  128. <td>
  129. <?php echo api_ucfirst(get_lang('DaysAfter')) ?> :
  130. </td>
  131. <td>
  132. <?php echo intval($session['nb_days_access_after_end']) ?>
  133. </td>
  134. </tr>
  135. <tr>
  136. <td>
  137. <?php echo api_ucfirst(get_lang('SessionVisibility')) ?> :
  138. </td>
  139. <td>
  140. <?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')) ?>
  141. </td>
  142. </tr>
  143. </table>
  144. <br />
  145. <!--List of courses -->
  146. <table class="data_table" width="100%">
  147. <tr>
  148. <th colspan="4"><?php echo get_lang('CourseList'); ?>
  149. <a href="add_courses_to_session.php?page=resume_session.php&id_session=<?php echo $id_session; ?>"><?php Display::display_icon('edit.gif', get_lang('Edit')); ?></a></th>
  150. </th>
  151. </tr>
  152. <tr>
  153. <tr>
  154. <th width="35%"><?php echo get_lang('CourseTitle'); ?></th>
  155. <th width="30%"><?php echo get_lang('CourseCoach'); ?></th>
  156. <th width="20%"><?php echo get_lang('UsersNumber'); ?></th>
  157. <th width="15%"><?php echo get_lang('Actions'); ?></th>
  158. </tr>
  159. </tr>
  160. <?php
  161. if($session['nbr_courses']==0){
  162. echo '
  163. <tr>
  164. <td colspan="4">'.get_lang('NoCoursesForThisSession').'</td>
  165. </tr>';
  166. }
  167. else {
  168. // select the courses
  169. $sql = "SELECT code,title,visual_code, nbr_users
  170. FROM $tbl_course,$tbl_session_rel_course
  171. WHERE course_code = code
  172. AND id_session='$id_session'
  173. ORDER BY title";
  174. $result=Database::query($sql);
  175. $courses=Database::store_result($result);
  176. foreach($courses as $course){
  177. //select the number of users
  178. $sql = " SELECT count(*) FROM $tbl_session_rel_user sru, $tbl_session_rel_course_rel_user srcru
  179. WHERE srcru.id_user = sru.id_user AND srcru.id_session = sru.id_session AND srcru.course_code = '".Database::escape_string($course['code'])."'
  180. AND sru.relation_type<>".SESSION_RELATION_TYPE_RRHH." AND srcru.id_session = '".intval($id_session)."'";
  181. $rs = Database::query($sql);
  182. $course['nbr_users'] = Database::result($rs,0,0);
  183. // Get coachs of the courses in session
  184. $sql = "SELECT user.lastname,user.firstname,user.username FROM $tbl_session_rel_course_rel_user session_rcru, $tbl_user user
  185. 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";
  186. $rs = Database::query($sql);
  187. $coachs = array();
  188. if (Database::num_rows($rs) > 0) {
  189. while($info_coach = Database::fetch_array($rs)) {
  190. $coachs[] = api_get_person_name($info_coach['firstname'], $info_coach['lastname']).' ('.$info_coach['username'].')';
  191. }
  192. } else {
  193. $coach = get_lang('None');
  194. }
  195. if (count($coachs) > 0) {
  196. $coach = implode('<br />',$coachs);
  197. } else {
  198. $coach = get_lang('None');
  199. }
  200. $orig_param = '&origin=resume_session';
  201. //hide_course_breadcrumb the parameter has been added to hide the name of the course, that appeared in the default $interbreadcrumb
  202. echo '
  203. <tr>
  204. <td>'.$course['title'].' ('.$course['visual_code'].')</td>
  205. <td>'.$coach.'</td>
  206. <td>'.$course['nbr_users'].'</td>
  207. <td>
  208. <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;
  209. <a href="session_course_edit.php?id_session='.$id_session.'&page=resume_session.php&course_code='.$course['code'].''.$orig_param.'">'.Display::return_icon('edit.gif', get_lang('Edit')).'</a>
  210. <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.gif', get_lang('Delete')).'</a>
  211. </td>
  212. </tr>';
  213. }
  214. }
  215. ?>
  216. </table>
  217. <br />
  218. <!--List of courses -->
  219. <table class="data_table" width="100%">
  220. <tr>
  221. <th colspan="4"><?php echo get_lang('UserList'); ?>
  222. <a href="add_users_to_session.php?page=resume_session.php&id_session=<?php echo $id_session; ?>"><?php Display::display_icon('edit.gif', get_lang('Edit')); ?></a></th>
  223. </th>
  224. </tr>
  225. </tr>
  226. <?php
  227. if($session['nbr_users']==0){
  228. echo '
  229. <tr>
  230. <td colspan="2">'.get_lang('NoUsersForThisSession').'</td>
  231. </tr>';
  232. }
  233. else {
  234. // classe development, obsolete for the moment
  235. $order_clause = api_sort_by_first_name() ? ' ORDER BY firstname, lastname' : ' ORDER BY lastname, firstname';
  236. $sql = 'SELECT '.$tbl_user.'.user_id, lastname, firstname, username
  237. FROM '.$tbl_user.'
  238. INNER JOIN '.$tbl_session_rel_user.'
  239. ON '.$tbl_user.'.user_id = '.$tbl_session_rel_user.'.id_user AND '.$tbl_session_rel_user.'.relation_type<>'.SESSION_RELATION_TYPE_RRHH.'
  240. AND '.$tbl_session_rel_user.'.id_session = '.$id_session.$order_clause;
  241. $result=Database::query($sql);
  242. $users=Database::store_result($result);
  243. $orig_param = '&origin=resume_session&id_session='.$id_session; // change breadcrumb in destination page
  244. foreach($users as $user){
  245. echo '<tr>
  246. <td width="90%">
  247. <b>'.api_get_person_name($user['firstname'], $user['lastname']).' ('.$user['username'].')</b>
  248. </td>
  249. <td>
  250. <a href="../mySpace/myStudents.php?student='.$user['user_id'].''.$orig_param.'">'.Display::return_icon('statistics.gif', get_lang('Reporting')).'</a>&nbsp;
  251. <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;
  252. <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.gif', get_lang('Delete')).'</a>
  253. </td>
  254. </tr>';
  255. }
  256. }
  257. ?>
  258. </table>
  259. <?php
  260. // footer
  261. Display :: display_footer();
  262. ?>