user_information.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  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. // name of the language file that needs to be included
  9. $language_file = array('registration', 'index', 'tracking', 'exercice', 'admin', 'gradebook');
  10. $cidReset = true;
  11. require_once '../inc/global.inc.php';
  12. $this_section = SECTION_PLATFORM_ADMIN;
  13. require_once api_get_path(LIBRARY_PATH).'export.lib.inc.php';
  14. require_once api_get_path(SYS_CODE_PATH).'forum/forumfunction.inc.php';
  15. require_once api_get_path(SYS_CODE_PATH).'work/work.lib.php';
  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'], true);
  23. $tool_name = $user['complete_name'].(empty($user['official_code'])?'':' ('.$user['official_code'].')');
  24. $table_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  25. $table_course = Database :: get_main_table(TABLE_MAIN_COURSE);
  26. // only allow platform admins to login_as, or session admins only for students (not teachers nor other admins)
  27. $login_as_icon = null;
  28. $editUser = null;
  29. if (api_is_platform_admin()) {
  30. $login_as_icon =
  31. '<a href="'.api_get_path(WEB_CODE_PATH).'admin/user_list.php'
  32. .'?action=login_as&amp;user_id='.$user['user_id'].'&amp;'
  33. .'sec_token='.$_SESSION['sec_token'].'">'
  34. .Display::return_icon('login_as.png', get_lang('LoginAs'),
  35. array(), ICON_SIZE_MEDIUM).'</a>';
  36. $editUser = Display::url(
  37. Display::return_icon(
  38. 'edit.png',
  39. get_lang('Edit'),
  40. array(),
  41. ICON_SIZE_MEDIUM
  42. ),
  43. api_get_path(WEB_CODE_PATH).'admin/user_edit.php?user_id='.$user['user_id']
  44. );
  45. $exportLink = Display::url(
  46. Display::return_icon(
  47. 'export_csv.png', get_lang('ExportAsCSV'),'', ICON_SIZE_MEDIUM),
  48. api_get_self().'?user_id='.$user['user_id'].'&action=export'
  49. );
  50. }
  51. // Getting the user image
  52. $sysdir_array = UserManager::get_user_picture_path_by_id($user['user_id'], 'system', false, true);
  53. $sysdir = $sysdir_array['dir'];
  54. $webdir_array = UserManager::get_user_picture_path_by_id($user['user_id'], 'web', false, true);
  55. $webdir = $webdir_array['dir'];
  56. $fullurl = $webdir.$webdir_array['file'];
  57. $system_image_path = $sysdir.$webdir_array['file'];
  58. list($width, $height, $type, $attr) = @getimagesize($system_image_path);
  59. $resizing = (($height > 200) ? 'height="200"' : '');
  60. $height += 30;
  61. $width += 30;
  62. $window_name = 'window'.uniqid('');
  63. $onclick = $window_name."=window.open('".$fullurl."','".$window_name
  64. ."','alwaysRaised=yes, alwaysLowered=no,alwaysOnTop=yes,toolbar=no,"
  65. ."location=no,directories=no,status=no,menubar=no,scrollbars=no,"
  66. ."resizable=no,width=".$width.",height=".$height.",left=200,top=20');"
  67. ." return false;";
  68. // Show info about who created this user and when
  69. $creatorId = $user['creator_id'];
  70. $creatorInfo = api_get_user_info($creatorId);
  71. $registrationDate = $user['registration_date'];
  72. $csvContent = array();
  73. $table = new HTML_Table(array('class' => 'data_table'));
  74. $table->setHeaderContents(0, 0, get_lang('Information'));
  75. $csvContent[] = get_lang('Information');
  76. $data = array(
  77. get_lang('Name') => $user['complete_name'],
  78. get_lang('Email') => $user['email'],
  79. get_lang('Phone') => $user['phone'],
  80. get_lang('OfficialCode') => $user['official_code'],
  81. get_lang('Online') => $user['user_is_online'] ?
  82. Display::return_icon('online.png') : Display::return_icon('offline.png'),
  83. get_lang('Status') => $user['status'] == 1 ? get_lang('Teacher') : get_lang('Student'),
  84. null => sprintf(get_lang('CreatedByXYOnZ'), 'user_information.php?user_id='
  85. .$creatorId, $creatorInfo['username'], api_get_utc_datetime($registrationDate))
  86. );
  87. $row = 1;
  88. foreach ($data as $label => $item) {
  89. if (!empty($label)) {
  90. $label = $label.': ';
  91. }
  92. $table->setCellContents($row, 0, $label.$item);
  93. $csvContent[] = array($label, strip_tags($item));
  94. $row++;
  95. }
  96. $userInformation = $table->toHtml();
  97. $table = new HTML_Table(array('class' => 'data_table'));
  98. $table->setHeaderContents(0, 0, get_lang('Tracking'));
  99. $csvContent[] = get_lang('Tracking');
  100. $data = array(
  101. get_lang('FirstLogin') => Tracking :: get_first_connection_date($user['user_id']),
  102. get_lang('LatestLogin') => Tracking :: get_last_connection_date($user['user_id'], true)
  103. );
  104. $row = 1;
  105. foreach ($data as $label => $item) {
  106. if (!empty($label)) {
  107. $label = $label.': ';
  108. }
  109. $table->setCellContents($row, 0, $label.$item);
  110. $csvContent[] = array($label, strip_tags($item));
  111. $row++;
  112. }
  113. $trackingInformation = $table->toHtml();
  114. $tbl_session_course = Database:: get_main_table(TABLE_MAIN_SESSION_COURSE);
  115. $tbl_session_course_user = Database:: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  116. $tbl_session = Database:: get_main_table(TABLE_MAIN_SESSION);
  117. $tbl_course = Database:: get_main_table(TABLE_MAIN_COURSE);
  118. $tbl_user = Database:: get_main_table(TABLE_MAIN_USER);
  119. $user_id = $user['user_id'];
  120. $sessions = SessionManager::get_sessions_by_user($user_id, true);
  121. $personal_course_list = array();
  122. $courseToolInformationTotal = null;
  123. if (count($sessions) > 0) {
  124. $sessionInformation = null;
  125. $header = array(
  126. array(get_lang('Code'), true),
  127. array(get_lang('Title'), true),
  128. array(get_lang('Status'), true),
  129. array(get_lang('TimeSpentInTheCourse'), true),
  130. array(get_lang('TotalPostsInAllForums'), true),
  131. array('', false)
  132. );
  133. $headerList = array();
  134. foreach ($header as $item) {
  135. $headerList[] = $item[0];
  136. }
  137. $csvContent[] = array();
  138. $csvContent[] = array(get_lang('Sessions'));
  139. foreach ($sessions as $session_item) {
  140. $data = array();
  141. $personal_course_list = array();
  142. $id_session = $session_item['session_id'];
  143. $csvContent[] = array($session_item['session_name']);
  144. $csvContent[] = $headerList;
  145. foreach ($session_item['courses'] as $my_course) {
  146. $courseInfo = api_get_course_info($my_course['code']);
  147. $sessionStatus = SessionManager::get_user_status_in_session(
  148. $user['user_id'],
  149. $my_course['code'],
  150. $id_session
  151. );
  152. $status = null;
  153. switch ($sessionStatus) {
  154. case 0:
  155. case STUDENT:
  156. $status = get_lang('Student');
  157. break;
  158. case 2:
  159. $status = get_lang('CourseCoach');
  160. break;
  161. }
  162. $tools = '<a href="course_information.php?code='.$courseInfo['code'].'&id_session='.$id_session.'">'.
  163. Display::return_icon('synthese_view.gif', get_lang('Overview')).'</a>'.
  164. '<a href="'.api_get_path(WEB_COURSE_PATH).$courseInfo['path'].'?id_session='.$id_session.'">'.
  165. Display::return_icon('course_home.gif', get_lang('CourseHomepage')).'</a>';
  166. if ($my_course['status'] == STUDENT) {
  167. $tools .= '<a href="user_information.php?action=unsubscribe&course_code='.$courseInfo['code'].'&user_id='.$user['user_id'].'">'.
  168. Display::return_icon('delete.png', get_lang('Delete')).'</a>';
  169. }
  170. $timeSpent = api_time_to_hms(
  171. Tracking :: get_time_spent_on_the_course(
  172. $user['user_id'],
  173. $courseInfo['code'],
  174. $id_session
  175. )
  176. );
  177. $totalForumMessages = CourseManager::getCountPostInForumPerUser(
  178. $user['user_id'],
  179. $courseInfo['real_id'],
  180. $id_session
  181. );
  182. $row = array(
  183. Display::url(
  184. $my_course['code'],
  185. $courseInfo['course_public_url'].'?id_session='.$id_session
  186. ),
  187. $courseInfo['title'],
  188. $status,
  189. $timeSpent,
  190. $totalForumMessages,
  191. $tools
  192. );
  193. $csvContent[] = array_map('strip_tags', $row);
  194. $data[] = $row;
  195. $result = TrackingUserLogCSV::getToolInformation(
  196. $user['user_id'],
  197. $courseInfo,
  198. $id_session
  199. );
  200. if (!empty($result['html'])) {
  201. $courseToolInformationTotal .= $result['html'];
  202. $csvContent = array_merge($csvContent, $result['array']);
  203. }
  204. }
  205. if ($session_item['date_start'] == '0000-00-00') {
  206. $session_item['date_start'] = null;
  207. }
  208. if ($session_item['date_end'] == '0000-00-00') {
  209. $session_item['date_end'] = null;
  210. }
  211. $dates = array_filter(
  212. array($session_item['date_start'], $session_item['date_end'])
  213. );
  214. $sessionInformation .= Display::page_subheader(
  215. '<a href="'.api_get_path(WEB_CODE_PATH).'admin/resume_session.php?id_session='.$id_session.'">'.
  216. $session_item['session_name'].'</a>',
  217. ' '.implode(' - ', $dates)
  218. );
  219. $sessionInformation .= Display::return_sortable_table(
  220. $header,
  221. $data,
  222. array(),
  223. array(),
  224. array('user_id' => intval($_GET['user_id']))
  225. );
  226. $sessionInformation .= $courseToolInformationTotal;
  227. }
  228. } else {
  229. $sessionInformation = '<p>'.get_lang('NoSessionsForThisUser').'</p>';
  230. }
  231. $courseToolInformationTotal = null;
  232. /**
  233. * Show the courses in which this user is subscribed
  234. */
  235. $sql = 'SELECT * FROM '.$table_course_user.' cu, '.$table_course.' c'.
  236. ' WHERE cu.user_id = '.$user['user_id'].' AND cu.course_code = c.code '.
  237. ' AND cu.relation_type <> '.COURSE_RELATION_TYPE_RRHH.' ';
  238. $res = Database::query($sql);
  239. if (Database::num_rows($res) > 0) {
  240. $header = array(
  241. array(get_lang('Code'), true),
  242. array(get_lang('Title'), true),
  243. array(get_lang('Status'), true),
  244. array(get_lang('TimeSpentInTheCourse'), true),
  245. array(get_lang('TotalPostsInAllForums'), true),
  246. array('', false)
  247. );
  248. $headerList = array();
  249. foreach ($header as $item) {
  250. $headerList[] = $item[0];
  251. }
  252. $csvContent[] = array();
  253. $csvContent[] = array(get_lang('Courses'));
  254. $csvContent[] = $headerList;
  255. $data = array();
  256. $courseToolInformationTotal = null;
  257. while ($course = Database::fetch_object($res)) {
  258. $courseToolInformation = null;
  259. $tools = '<a href="course_information.php?code='.$course->code.'">'.Display::return_icon('synthese_view.gif', get_lang('Overview')).'</a>'.
  260. '<a href="'.api_get_path(WEB_COURSE_PATH).$course->directory.'">'.Display::return_icon('course_home.gif', get_lang('CourseHomepage')).'</a>' .
  261. '<a href="course_edit.php?course_code='.$course->code.'">'.Display::return_icon('edit.gif', get_lang('Edit')).'</a>';
  262. if ($course->status == STUDENT) {
  263. $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>';
  264. }
  265. $timeSpent = api_time_to_hms(
  266. Tracking :: get_time_spent_on_the_course(
  267. $user['user_id'],
  268. $course->code,
  269. 0
  270. )
  271. );
  272. $totalForumMessages = CourseManager::getCountPostInForumPerUser(
  273. $user['user_id'],
  274. $course->id,
  275. 0
  276. );
  277. $courseInfo = api_get_course_info($course->code);
  278. $row = array(
  279. Display::url($course->code, $courseInfo['course_public_url']),
  280. $course->title,
  281. $course->status == STUDENT ? get_lang('Student') : get_lang('Teacher'),
  282. $timeSpent,
  283. $totalForumMessages,
  284. $tools,
  285. );
  286. $csvContent[] = array_map('strip_tags', $row);
  287. $data[] = $row;
  288. $result = TrackingUserLogCSV::getToolInformation(
  289. $user['user_id'],
  290. $courseInfo,
  291. 0
  292. );
  293. $courseToolInformationTotal .= $result['html'];
  294. $csvContent = array_merge($csvContent, $result['array']);
  295. }
  296. $courseInformation = Display::page_subheader(get_lang('Courses'));
  297. $courseInformation .= Display::return_sortable_table(
  298. $header,
  299. $data,
  300. array(),
  301. array(),
  302. array('user_id' => intval($_GET['user_id']))
  303. );
  304. $courseInformation .= $courseToolInformationTotal;
  305. } else {
  306. $courseInformation = '<p>'.get_lang('NoCoursesForThisUser').'</p>';
  307. }
  308. /**
  309. * Show the URL in which this user is subscribed
  310. */
  311. $urlInformation = null;
  312. if (api_is_multiple_url_enabled()) {
  313. $urlList= UrlManager::get_access_url_from_user($user['user_id']);
  314. if (count($urlList) > 0) {
  315. $header = array();
  316. $header[] = array('URL', true);
  317. $data = array();
  318. $csvContent[] = array();
  319. $csvContent[] = array('Url');
  320. foreach ($urlList as $url) {
  321. $row = array();
  322. $row[] = Display::url($url['url'], $url['url']);
  323. $csvContent[] = array_map('strip_tags', $row);
  324. $data[] = $row;
  325. }
  326. $urlInformation = Display::page_subheader(get_lang('URLList'));
  327. $urlInformation .= Display::return_sortable_table(
  328. $header,
  329. $data,
  330. array(),
  331. array(),
  332. array('user_id' => intval($_GET['user_id']))
  333. );
  334. } else {
  335. $urlInformation = '<p>'.get_lang('NoUrlForThisUser').'</p>';
  336. }
  337. }
  338. $message = null;
  339. if (isset($_GET['action'])) {
  340. switch ($_GET['action']) {
  341. case 'unsubscribe':
  342. if (CourseManager::get_user_in_course_status($_GET['user_id'], $_GET['course_code']) == STUDENT) {
  343. CourseManager::unsubscribe_user($_GET['user_id'], $_GET['course_code']);
  344. $message = Display::return_message(get_lang('UserUnsubscribed'));
  345. } else {
  346. $message = Display::return_message(
  347. get_lang('CannotUnsubscribeUserFromCourse'),
  348. 'error'
  349. );
  350. }
  351. break;
  352. case 'export':
  353. Export :: export_table_csv_utf8($csvContent, 'user_information_'.$user);
  354. exit;
  355. break;
  356. }
  357. }
  358. Display::display_header($tool_name);
  359. echo '<div class="actions">
  360. <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).'
  361. </a>
  362. '.$login_as_icon.'
  363. '.$editUser.'
  364. '.$exportLink.'
  365. </div>';
  366. echo Display::page_header($tool_name);
  367. echo '<div class="row">';
  368. echo '<div class="span2">';
  369. echo '<a href="javascript: void(0);" onclick="'.$onclick.'" >'
  370. .'<img src="'.$fullurl.'" '.$resizing.' /></a><br />';
  371. echo '</div>';
  372. echo $message;
  373. echo '<div class="span5">';
  374. echo $userInformation;
  375. echo '</div>';
  376. echo '<div class="span5">';
  377. echo $trackingInformation;
  378. echo '</div>';
  379. echo '</div>';
  380. echo Display::page_subheader(get_lang('SessionList'));
  381. echo $sessionInformation;
  382. echo $courseInformation;
  383. echo $urlInformation;
  384. Display::display_footer();