user_information.php 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Script showing information about a user (name, e-mail, courses and sessions)
  5. * @author Bart Mollet
  6. * @package chamilo.admin
  7. */
  8. /**
  9. * INIT SECTION
  10. */
  11. // name of the language file that needs to be included
  12. $language_file = 'admin';
  13. $cidReset = true;
  14. require_once '../inc/global.inc.php';
  15. $this_section=SECTION_PLATFORM_ADMIN;
  16. api_protect_admin_script();
  17. $interbreadcrumb[] = array ("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
  18. $interbreadcrumb[] = array ("url" => 'user_list.php', "name" => get_lang('UserList'));
  19. if (!isset($_GET['user_id'])) {
  20. api_not_allowed();
  21. }
  22. $user = api_get_user_info($_GET['user_id']);
  23. $tool_name = $user['complete_name'].(empty($user['official_code'])?'':' ('.$user['official_code'].')');
  24. /**
  25. * Display
  26. */
  27. Display::display_header($tool_name);
  28. $table_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  29. $table_course = Database :: get_main_table(TABLE_MAIN_COURSE);
  30. if (isset($_GET['action'])) {
  31. switch ($_GET['action']) {
  32. case 'unsubscribe':
  33. if (CourseManager::get_user_in_course_status($_GET['user_id'], $_GET['course_code']) == STUDENT) {
  34. CourseManager::unsubscribe_user($_GET['user_id'], $_GET['course_code']);
  35. Display::display_normal_message(get_lang('UserUnsubscribed'));
  36. } else {
  37. Display::display_error_message(get_lang('CannotUnsubscribeUserFromCourse'));
  38. }
  39. break;
  40. }
  41. }
  42. // only allow platform admins to login_as, or session admins only for students (not teachers nor other admins)
  43. $login_as_icon = null;
  44. $editUser = null;
  45. if (api_is_platform_admin()) {
  46. $login_as_icon =
  47. '<a href="'.api_get_path(WEB_CODE_PATH).'admin/user_list.php'
  48. .'?action=login_as&amp;user_id='.$user['user_id'].'&amp;'
  49. .'sec_token='.$_SESSION['sec_token'].'">'
  50. .Display::return_icon('login_as.gif', get_lang('LoginAs')).'</a>';
  51. $editUser = Display::url(
  52. Display::return_icon(
  53. 'edit.png',
  54. get_lang('Edit'),
  55. array()
  56. ),
  57. api_get_path(WEB_CODE_PATH).'admin/user_edit.php?user_id='.$user['user_id']
  58. );
  59. }
  60. echo '<div class="actions">
  61. <a href="'.api_get_path(WEB_CODE_PATH).'mySpace/myStudents.php?student='.intval($_GET['user_id']).'" title="'.get_lang('Reporting').'">'.Display::return_icon('statistics.png', get_lang('Reporting'), '', ICON_SIZE_MEDIUM).'
  62. </a>
  63. '.$login_as_icon.'
  64. '.$editUser.'
  65. </div>';
  66. echo Display::page_header($tool_name);
  67. // Getting the user image
  68. $sysdir_array = UserManager::get_user_picture_path_by_id($user['user_id'], 'system', false, true);
  69. $sysdir = $sysdir_array['dir'];
  70. $webdir_array = UserManager::get_user_picture_path_by_id($user['user_id'], 'web', false, true);
  71. $webdir = $webdir_array['dir'];
  72. $fullurl = $webdir.$webdir_array['file'];
  73. $system_image_path = $sysdir.$webdir_array['file'];
  74. list($width, $height, $type, $attr) = @getimagesize($system_image_path);
  75. $resizing = (($height > 200) ? 'height="200"' : '');
  76. $height += 30;
  77. $width += 30;
  78. $window_name = 'window'.uniqid('');
  79. $onclick = $window_name."=window.open('".$fullurl."','".$window_name
  80. ."','alwaysRaised=yes, alwaysLowered=no,alwaysOnTop=yes,toolbar=no,"
  81. ."location=no,directories=no,status=no,menubar=no,scrollbars=no,"
  82. ."resizable=no,width=".$width.",height=".$height.",left=200,top=20');"
  83. ." return false;";
  84. echo '<a href="javascript: void(0);" onclick="'.$onclick.'" >'
  85. .'<img src="'.$fullurl.'" '.$resizing.' alt="'.$alt.'"/></a><br />';
  86. echo '<p>'.($user['status'] == 1 ? get_lang('Teacher') : get_lang('Student'))
  87. .'</p>';
  88. echo '<p>'.Display :: encrypted_mailto_link($user['mail'], $user['mail']).'</p>';
  89. // Show info about who created this user and when
  90. $creatorId = $user['creator_id'];
  91. $creatorInfo = api_get_user_info($creatorId);
  92. $registrationDate = $user['registration_date'];
  93. echo '<p>'.sprintf(get_lang('CreatedByXYOnZ'), 'user_information.php?user_id='.$creatorId, $creatorInfo['username'], api_get_utc_datetime($registrationDate)).'</p>';
  94. /**
  95. * Show the sessions and the courses in which this user is subscribed
  96. */
  97. echo Display::page_subheader(get_lang('SessionList'));
  98. $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
  99. $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  100. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  101. $tbl_course = Database :: get_main_table(TABLE_MAIN_COURSE);
  102. $tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
  103. $user_id = $user['user_id'];
  104. $sessions = SessionManager::get_sessions_by_user($user_id, true);
  105. $personal_course_list = array();
  106. if (count($sessions) > 0) {
  107. $header[] = array (get_lang('Code'), true);
  108. $header[] = array (get_lang('Title'), true);
  109. $header[] = array (get_lang('Status'), true);
  110. $header[] = array ('', false);
  111. foreach ($sessions as $session_item) {
  112. $data = array ();
  113. $personal_course_list = array();
  114. $id_session = $session_item['session_id'];
  115. foreach ($session_item['courses'] as $my_course) {
  116. $course_info = api_get_course_info($my_course['code']);
  117. $row = array();
  118. $row[] = $my_course['code'];
  119. $row[] = $course_info['title'];
  120. $sessionStatus = SessionManager::get_user_status_in_session($user['user_id'], $my_course['code'], $id_session);
  121. $status = null;
  122. switch($sessionStatus) {
  123. case STUDENT:
  124. $status = get_lang('Student');
  125. break;
  126. case 2:
  127. $status = get_lang('CourseCoach');
  128. break;
  129. }
  130. $row[] = $status;
  131. $tools = '<a href="course_information.php?code='.$course_info['code'].'&id_session='.$id_session.'">'.
  132. Display::return_icon('synthese_view.gif', get_lang('Overview')).'</a>'.
  133. '<a href="'.api_get_path(WEB_COURSE_PATH).$course_info['path'].'?id_session='.$id_session.'">'.
  134. Display::return_icon('course_home.gif', get_lang('CourseHomepage')).'</a>';
  135. if ($my_course['status'] == STUDENT) {
  136. $tools .= '<a href="user_information.php?action=unsubscribe&course_code='.$course_info['code'].'&user_id='.$user['user_id'].'">'.
  137. Display::return_icon('delete.png', get_lang('Delete')).'</a>';
  138. }
  139. $row[] = $tools;
  140. $data[] = $row;
  141. }
  142. if ($session_item['date_start'] == '0000-00-00') {
  143. $session_item['date_start'] = null;
  144. }
  145. if ($session_item['date_end'] == '0000-00-00') {
  146. $session_item['date_end'] = null;
  147. }
  148. $dates = array_filter(
  149. array($session_item['date_start'], $session_item['date_end'])
  150. );
  151. echo Display::page_subheader(
  152. '<a href="'.api_get_path(WEB_CODE_PATH).'admin/resume_session.php?id_session='.$id_session.'">'.$session_item['session_name'].'</a>',
  153. ' '.implode(' - ', $dates)
  154. );
  155. Display :: display_sortable_table(
  156. $header,
  157. $data,
  158. array (),
  159. array(),
  160. array ('user_id' => intval($_GET['user_id']))
  161. );
  162. }
  163. } else {
  164. echo '<p>'.get_lang('NoSessionsForThisUser').'</p>';
  165. }
  166. /**
  167. * Show the courses in which this user is subscribed
  168. */
  169. $sql = 'SELECT * FROM '.$table_course_user.' cu, '.$table_course.' c'.
  170. ' WHERE cu.user_id = '.$user['user_id'].' AND cu.course_code = c.code '.
  171. ' AND cu.relation_type <> '.COURSE_RELATION_TYPE_RRHH.' ';
  172. $res = Database::query($sql);
  173. if (Database::num_rows($res) > 0) {
  174. $header=array();
  175. $header[] = array (get_lang('Code'), true);
  176. $header[] = array (get_lang('Title'), true);
  177. $header[] = array (get_lang('Status'), true);
  178. $header[] = array ('', false);
  179. $data = array ();
  180. while ($course = Database::fetch_object($res)) {
  181. $row = array ();
  182. $row[] = $course->code;
  183. $row[] = $course->title;
  184. $row[] = $course->status == STUDENT ? get_lang('Student') : get_lang('Teacher');
  185. $tools = '<a href="course_information.php?code='.$course->code.'">'.Display::return_icon('synthese_view.gif', get_lang('Overview')).'</a>'.
  186. '<a href="'.api_get_path(WEB_COURSE_PATH).$course->directory.'">'.Display::return_icon('course_home.gif', get_lang('CourseHomepage')).'</a>' .
  187. '<a href="course_edit.php?course_code='.$course->code.'">'.Display::return_icon('edit.gif', get_lang('Edit')).'</a>';
  188. if ($course->status == STUDENT) {
  189. $tools .= '<a href="user_information.php?action=unsubscribe&course_code='.$course->code.'&user_id='.$user['user_id'].'">'.Display::return_icon('delete.png', get_lang('Delete')).'</a>';
  190. }
  191. $row[] = $tools;
  192. $data[] = $row;
  193. }
  194. echo Display::page_subheader(get_lang('Courses'));
  195. Display :: display_sortable_table(
  196. $header,
  197. $data,
  198. array (),
  199. array (),
  200. array ('user_id' => intval($_GET['user_id']))
  201. );
  202. } else {
  203. echo '<p>'.get_lang('NoCoursesForThisUser').'</p>';
  204. }
  205. /**
  206. * Show the URL in which this user is subscribed
  207. */
  208. if (api_is_multiple_url_enabled()) {
  209. $url_list= UrlManager::get_access_url_from_user($user['user_id']);
  210. if (count($url_list) > 0) {
  211. $header = array();
  212. $header[] = array ('URL', true);
  213. $data = array ();
  214. foreach ($url_list as $url) {
  215. $row = array();
  216. $row[] = Display::url($url['url'], $url['url']);
  217. $data[] = $row;
  218. }
  219. echo '<p><b>'.get_lang('URLList').'</b></p>';
  220. Display :: display_sortable_table(
  221. $header,
  222. $data,
  223. array (),
  224. array (),
  225. array ('user_id' => intval($_GET['user_id']))
  226. );
  227. } else {
  228. echo '<p>'.get_lang('NoUrlForThisUser').'</p>';
  229. }
  230. }
  231. Display::display_footer();