user_information.php 18 KB

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