user_information.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use Chamilo\CoreBundle\Framework\Container;
  4. /**
  5. * Script showing information about a user (name, e-mail, courses and sessions)
  6. * @author Bart Mollet
  7. * @package chamilo.admin
  8. */
  9. $cidReset = true;
  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' => Container::getRouter()->generate('administration') , "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. $subject = get_lang('SendLegalSubject');
  98. $content = sprintf(
  99. get_lang('SendLegalDescriptionToUrlX'),
  100. api_get_path(WEB_PATH)
  101. );
  102. MessageManager::send_message_simple($userId, $subject, $content);
  103. Display::addFlash(Display::return_message(get_lang('Sent')));
  104. break;
  105. case 'delete_legal':
  106. $extraFieldValue = new ExtraFieldValue('user');
  107. $value = $extraFieldValue->get_values_by_handler_and_field_variable($userId, 'legal_accept');
  108. $result = $extraFieldValue->delete($value['id']);
  109. if ($result) {
  110. Display::addFlash(Display::return_message(get_lang('Deleted')));
  111. }
  112. break;
  113. case 'unsubscribe':
  114. $courseCode = empty($_GET['course_code']) ? '' : intval($_GET['course_code']);
  115. $sessionId = empty($_GET['id_session']) ? 0 : intval($_GET['id_session']);
  116. if (CourseManager::get_user_in_course_status($userId, $courseCode) == STUDENT) {
  117. CourseManager::unsubscribe_user($userId, $courseCode, $sessionId);
  118. Display::addFlash(Display::return_message(get_lang('UserUnsubscribed')));
  119. } else {
  120. Display::addFlash(Display::return_message(
  121. get_lang('CannotUnsubscribeUserFromCourse'),
  122. 'error',
  123. false
  124. ));
  125. }
  126. break;
  127. case 'unsubscribeSessionCourse':
  128. $userId = empty($_GET['user_id']) ? 0 : intval($_GET['user_id']);
  129. $courseCode = empty($_GET['course_code']) ? '' : intval($_GET['course_code']);
  130. $sessionId = empty($_GET['id_session']) ? 0 : intval($_GET['id_session']);
  131. SessionManager::removeUsersFromCourseSession(
  132. array($userId),
  133. $sessionId,
  134. api_get_course_info($courseCode)
  135. );
  136. Display::addFlash(Display::return_message(get_lang('UserUnsubscribed')));
  137. break;
  138. case 'export':
  139. Export :: arrayToCsv($csvContent, 'user_information_'.$user);
  140. exit;
  141. break;
  142. }
  143. }
  144. // Show info about who created this user and when
  145. $creatorId = $user['creator_id'];
  146. $creatorInfo = api_get_user_info($creatorId);
  147. $registrationDate = $user['registration_date'];
  148. $table = new HTML_Table(array('class' => 'data_table'));
  149. $table->setHeaderContents(0, 0, get_lang('Information'));
  150. $csvContent[] = [get_lang('Information')];
  151. $data = array(
  152. get_lang('Name') => $user['complete_name'],
  153. get_lang('Email') => $user['email'],
  154. get_lang('Phone') => $user['phone'],
  155. get_lang('OfficialCode') => $user['official_code'],
  156. get_lang('Online') => $user['user_is_online'] ?
  157. Display::return_icon('online.png') : Display::return_icon(
  158. 'offline.png'
  159. ),
  160. get_lang('Status') => $user['status'] == 1 ? get_lang('Teacher') : get_lang(
  161. 'Student'
  162. ),
  163. null => sprintf(
  164. get_lang('CreatedByXYOnZ'),
  165. 'user_information.php?user_id='
  166. .$creatorId,
  167. $creatorInfo['username'],
  168. api_get_utc_datetime($registrationDate)
  169. )
  170. );
  171. $row = 1;
  172. foreach ($data as $label => $item) {
  173. if (!empty($label)) {
  174. $label = $label.': ';
  175. }
  176. $table->setCellContents($row, 0, $label.$item);
  177. $csvContent[] = array($label, strip_tags($item));
  178. $row++;
  179. }
  180. $userInformation = $table->toHtml();
  181. $table = new HTML_Table(array('class' => 'data_table'));
  182. $table->setHeaderContents(0, 0, get_lang('Tracking'));
  183. $csvContent[] = [get_lang('Tracking')];
  184. $data = array(
  185. get_lang('FirstLogin') => Tracking :: get_first_connection_date($userId),
  186. get_lang('LatestLogin') => Tracking :: get_last_connection_date($userId, true)
  187. );
  188. if (api_get_setting('allow_terms_conditions') === 'true') {
  189. $extraFieldValue = new ExtraFieldValue('user');
  190. $value = $extraFieldValue->get_values_by_handler_and_field_variable($userId, 'legal_accept');
  191. $icon = Display::return_icon('accept_na.png');
  192. if (isset($value['value'])) {
  193. list($legalId, $legalLanguageId, $legalTime) = explode(':', $value['value']);
  194. $icon = Display::return_icon('accept.png').' '.api_get_local_time($legalTime);
  195. $icon .= ' '.Display::url(
  196. get_lang('DeleteLegal'),
  197. api_get_self().'?action=delete_legal&user_id='.$userId,
  198. ['class' => 'btn btn-danger btn-xs']
  199. );
  200. } else {
  201. $icon .= ' '.Display::url(
  202. get_lang('SendLegal'),
  203. api_get_self().'?action=send_legal&user_id='.$userId,
  204. ['class' => 'btn btn-primary btn-xs']
  205. );
  206. }
  207. $data[get_lang('LegalAccepted')] = $icon;
  208. }
  209. $row = 1;
  210. foreach ($data as $label => $item) {
  211. if (!empty($label)) {
  212. $label = $label.': ';
  213. }
  214. $table->setCellContents($row, 0, $label.$item);
  215. $csvContent[] = array($label, strip_tags($item));
  216. $row++;
  217. }
  218. $trackingInformation = $table->toHtml();
  219. $tbl_session_course = Database:: get_main_table(TABLE_MAIN_SESSION_COURSE);
  220. $tbl_session_course_user = Database:: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  221. $tbl_session = Database:: get_main_table(TABLE_MAIN_SESSION);
  222. $tbl_course = Database:: get_main_table(TABLE_MAIN_COURSE);
  223. $tbl_user = Database:: get_main_table(TABLE_MAIN_USER);
  224. $sessions = SessionManager::get_sessions_by_user($userId, true);
  225. $personal_course_list = array();
  226. $courseToolInformationTotal = null;
  227. if (count($sessions) > 0) {
  228. $sessionInformation = null;
  229. $header = array(
  230. array(get_lang('Code'), true),
  231. array(get_lang('Title'), true),
  232. array(get_lang('Status'), true),
  233. array(get_lang('TimeSpentInTheCourse'), true),
  234. array(get_lang('TotalPostsInAllForums'), true),
  235. array('', false)
  236. );
  237. $headerList = array();
  238. foreach ($header as $item) {
  239. $headerList[] = $item[0];
  240. }
  241. $csvContent[] = array();
  242. $csvContent[] = array(get_lang('Sessions'));
  243. foreach ($sessions as $session_item) {
  244. $data = array();
  245. $personal_course_list = array();
  246. $id_session = $session_item['session_id'];
  247. $csvContent[] = array($session_item['session_name']);
  248. $csvContent[] = $headerList;
  249. foreach ($session_item['courses'] as $my_course) {
  250. $courseInfo = api_get_course_info_by_id($my_course['real_id']);
  251. $sessionStatus = SessionManager::get_user_status_in_session(
  252. $userId,
  253. $courseInfo['real_id'],
  254. $id_session
  255. );
  256. $status = null;
  257. switch ($sessionStatus) {
  258. case 0:
  259. case STUDENT:
  260. $status = get_lang('Student');
  261. break;
  262. case 2:
  263. $status = get_lang('CourseCoach');
  264. break;
  265. }
  266. $tools = '<a href="course_information.php?code='.$courseInfo['code'].'&id_session='.$id_session.'">'.
  267. Display::return_icon('synthese_view.gif', get_lang('Overview')).'</a>'.
  268. '<a href="'.$courseInfo['course_public_url'].'?id_session='.$id_session.'">'.
  269. Display::return_icon('course_home.gif', get_lang('CourseHomepage')).'</a>';
  270. if ($my_course['status'] == STUDENT) {
  271. $tools .= '<a href="user_information.php?action=unsubscribeSessionCourse&course_code='.$courseInfo['code'].'&user_id='.$userId.'&id_session='.$id_session.'">'.
  272. Display::return_icon('delete.png', get_lang('Delete')).'</a>';
  273. }
  274. $timeSpent = api_time_to_hms(
  275. Tracking :: get_time_spent_on_the_course(
  276. $userId,
  277. $courseInfo['real_id'],
  278. $id_session
  279. )
  280. );
  281. $totalForumMessages = CourseManager::getCountPostInForumPerUser(
  282. $userId,
  283. $courseInfo['real_id'],
  284. $id_session
  285. );
  286. $row = array(
  287. Display::url(
  288. $courseInfo['code'],
  289. $courseInfo['course_public_url'].'?id_session='.$id_session
  290. ),
  291. $courseInfo['title'],
  292. $status,
  293. $timeSpent,
  294. $totalForumMessages,
  295. $tools
  296. );
  297. $csvContent[] = array_map('strip_tags', $row);
  298. $data[] = $row;
  299. $result = TrackingUserLogCSV::getToolInformation(
  300. $userId,
  301. $courseInfo,
  302. $id_session
  303. );
  304. if (!empty($result['html'])) {
  305. $courseToolInformationTotal .= $result['html'];
  306. $csvContent = array_merge($csvContent, $result['array']);
  307. }
  308. }
  309. if ($session_item['access_start_date'] == '0000-00-00') {
  310. $session_item['access_start_date'] = null;
  311. }
  312. if ($session_item['access_end_date'] == '0000-00-00') {
  313. $session_item['access_end_date'] = null;
  314. }
  315. $dates = array_filter(
  316. array($session_item['access_start_date'], $session_item['access_end_date'])
  317. );
  318. $sessionInformation .= Display::page_subheader(
  319. '<a href="'.api_get_path(WEB_CODE_PATH).'session/resume_session.php?id_session='.$id_session.'">'.
  320. $session_item['session_name'].'</a>',
  321. ' '.implode(' - ', $dates)
  322. );
  323. $sessionInformation .= Display::return_sortable_table(
  324. $header,
  325. $data,
  326. array(),
  327. array(),
  328. array('user_id' => intval($_GET['user_id']))
  329. );
  330. $sessionInformation .= $courseToolInformationTotal;
  331. }
  332. } else {
  333. $sessionInformation = '<p>'.get_lang('NoSessionsForThisUser').'</p>';
  334. }
  335. $courseToolInformationTotal = null;
  336. /**
  337. * Show the courses in which this user is subscribed
  338. */
  339. $sql = 'SELECT * FROM '.$table_course_user.' cu, '.$table_course.' c
  340. WHERE
  341. cu.user_id = '.$userId.' AND
  342. cu.c_id = c.id AND
  343. cu.relation_type <> '.COURSE_RELATION_TYPE_RRHH.' ';
  344. $res = Database::query($sql);
  345. if (Database::num_rows($res) > 0) {
  346. $header = array(
  347. array(get_lang('Code')),
  348. array(get_lang('Title')),
  349. array(get_lang('Status')),
  350. array(get_lang('TimeSpentInTheCourse')),
  351. array(get_lang('TotalPostsInAllForums')),
  352. array('')
  353. );
  354. $headerList = array();
  355. foreach ($header as $item) {
  356. $headerList[] = $item[0];
  357. }
  358. $csvContent[] = array();
  359. $csvContent[] = array(get_lang('Courses'));
  360. $csvContent[] = $headerList;
  361. $data = array();
  362. $courseToolInformationTotal = null;
  363. while ($course = Database::fetch_object($res)) {
  364. $courseInfo = api_get_course_info_by_id($course->c_id);
  365. $courseCode = $courseInfo['code'];
  366. $courseToolInformation = null;
  367. $tools = '<a href="course_information.php?code='.$courseCode.'">'.
  368. Display::return_icon('synthese_view.gif', get_lang('Overview')).'</a>'.
  369. '<a href="'.$courseInfo['course_public_url'].'">'.
  370. Display::return_icon('course_home.gif', get_lang('CourseHomepage')).'</a>' .
  371. '<a href="course_edit.php?id='.$course->c_id.'">'.
  372. Display::return_icon('edit.gif', get_lang('Edit')).'</a>';
  373. if ($course->status == STUDENT) {
  374. $tools .= '<a href="user_information.php?action=unsubscribe&course_code='.$courseCode.'&user_id='.$userId.'">'.
  375. Display::return_icon('delete.png', get_lang('Delete')).'</a>';
  376. }
  377. $timeSpent = api_time_to_hms(
  378. Tracking :: get_time_spent_on_the_course(
  379. $userId,
  380. $courseInfo['real_id'],
  381. 0
  382. )
  383. );
  384. $totalForumMessages = CourseManager::getCountPostInForumPerUser(
  385. $userId,
  386. $course->id,
  387. 0
  388. );
  389. $row = array(
  390. Display::url($courseCode, $courseInfo['course_public_url']),
  391. $course->title,
  392. $course->status == STUDENT ? get_lang('Student') : get_lang('Teacher'),
  393. $timeSpent,
  394. $totalForumMessages,
  395. $tools,
  396. );
  397. $csvContent[] = array_map('strip_tags', $row);
  398. $data[] = $row;
  399. $result = TrackingUserLogCSV::getToolInformation(
  400. $userId,
  401. $courseInfo,
  402. 0
  403. );
  404. $courseToolInformationTotal .= $result['html'];
  405. $csvContent = array_merge($csvContent, $result['array']);
  406. }
  407. $courseInformation = Display::page_subheader(get_lang('Courses'));
  408. $courseInformation .= Display::return_sortable_table(
  409. $header,
  410. $data,
  411. array(),
  412. array(),
  413. array('user_id' => intval($_GET['user_id']))
  414. );
  415. $courseInformation .= $courseToolInformationTotal;
  416. } else {
  417. $courseInformation = '<p>'.get_lang('NoCoursesForThisUser').'</p>';
  418. }
  419. /**
  420. * Show the URL in which this user is subscribed
  421. */
  422. $urlInformation = '';
  423. if (api_is_multiple_url_enabled()) {
  424. $urlList = UrlManager::get_access_url_from_user($userId);
  425. if (count($urlList) > 0) {
  426. $header = array();
  427. $header[] = array('URL', true);
  428. $data = array();
  429. $csvContent[] = array();
  430. $csvContent[] = array('Url');
  431. foreach ($urlList as $url) {
  432. $row = array();
  433. $row[] = Display::url($url['url'], $url['url']);
  434. $csvContent[] = array_map('strip_tags', $row);
  435. $data[] = $row;
  436. }
  437. $urlInformation = Display::page_subheader(get_lang('URLList'));
  438. $urlInformation .= Display::return_sortable_table(
  439. $header,
  440. $data,
  441. array(),
  442. array(),
  443. array('user_id' => intval($_GET['user_id']))
  444. );
  445. } else {
  446. $urlInformation = '<p>'.get_lang('NoUrlForThisUser').'</p>';
  447. }
  448. }
  449. if (isset($_GET['action'])) {
  450. switch ($_GET['action']) {
  451. case 'unsubscribe':
  452. if (CourseManager::get_user_in_course_status($_GET['user_id'], $_GET['course_code']) == STUDENT) {
  453. CourseManager::unsubscribe_user($_GET['user_id'], $_GET['course_code'], $_GET['id_session']);
  454. $message = Display::return_message(get_lang('UserUnsubscribed'));
  455. } else {
  456. $message = Display::return_message(
  457. get_lang('CannotUnsubscribeUserFromCourse'),
  458. 'error'
  459. );
  460. }
  461. break;
  462. case 'unsubscribeSessionCourse':
  463. SessionManager::removeUsersFromCourseSession(
  464. array($_GET['user_id']),
  465. $_GET['id_session'],
  466. api_get_course_info($_GET['course_code'])
  467. );
  468. $message = Display::return_message(get_lang('UserUnsubscribed'));
  469. break;
  470. case 'export':
  471. Export :: arrayToCsv($csvContent, 'user_information_'.$user);
  472. exit;
  473. break;
  474. }
  475. }
  476. Display::display_header($tool_name);
  477. echo '<div class="actions">
  478. <a href="'.api_get_path(WEB_CODE_PATH).'mySpace/myStudents.php?student='.intval($_GET['user_id']).'" title="'.get_lang('Reporting').'">'.
  479. Display::return_icon('statistics.png', get_lang('Reporting'), '', ICON_SIZE_MEDIUM).'
  480. </a>
  481. '.$login_as_icon.'
  482. '.$editUser.'
  483. '.$exportLink.'
  484. '.$vCardExportLink.'
  485. </div>';
  486. echo Display::page_header($tool_name);
  487. $fullUrlBig = UserManager::getUserPicture(
  488. $userId,
  489. USER_IMAGE_SIZE_BIG
  490. );
  491. $fullUrl = UserManager::getUserPicture(
  492. $userId,
  493. USER_IMAGE_SIZE_ORIGINAL
  494. );
  495. echo '<div class="row">';
  496. echo '<div class="col-md-2">';
  497. echo '<a class="expand-image" href="'.$fullUrlBig.'">'
  498. .'<img src="'.$fullUrl.'" /></a><br />';
  499. echo '</div>';
  500. echo '<div class="col-md-5">';
  501. echo $userInformation;
  502. echo '</div>';
  503. echo '<div class="col-md-5">';
  504. echo $trackingInformation;
  505. echo '</div>';
  506. echo '</div>';
  507. if ($studentBossList) {
  508. echo Display::page_subheader(get_lang('StudentBossList'));
  509. echo $studentBossListToString;
  510. }
  511. echo Display::page_subheader(get_lang('SessionList'));
  512. echo $sessionInformation;
  513. echo $courseInformation;
  514. echo $urlInformation;
  515. Display::display_footer();