user_information.php 16 KB

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