resume_session.php 10.0 KB

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