user_information.php 19 KB

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