user_information.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592
  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. $socialInformation = '';
  216. /**
  217. * Show social activity
  218. */
  219. if (api_get_setting('allow_social_tool') === 'true') {
  220. $em = Database::getManager();
  221. $userObject = $em->find('ChamiloUserBundle:User', $user['user_id']);
  222. $data = [];
  223. // Calculate values
  224. if (api_get_setting('allow_message_tool') === 'true') {
  225. $messagesSent = SocialManager::getCountMessagesSent($user['user_id']);
  226. $data[] = [get_lang('MessagesSent'), $messagesSent];
  227. $messagesReceived = SocialManager::getCountMessagesReceived($user['user_id']);
  228. $data[] = [get_lang('MessagesReceived'), $messagesReceived];
  229. }
  230. $wallMessagesPosted = SocialManager::getCountWallPostedMessages($user['user_id']);
  231. $data[] = [get_lang('WallMessagesPosted'), $wallMessagesPosted];
  232. $friends = SocialManager::getCountFriends($user['user_id']);
  233. $data[] = [get_lang('Friends'), $friends];
  234. $count = SocialManager::getCountInvitationSent($user['user_id']);
  235. $data[] = [get_lang('InvitationSent'), $count];
  236. $count = SocialManager::get_message_number_invitation_by_user_id($user['user_id']);
  237. $data[] = [get_lang('InvitationReceived'), $count];
  238. $socialInformation = Display::return_sortable_table(
  239. '',
  240. $data
  241. );
  242. }
  243. /**
  244. * Show the sessions in which this user is subscribed
  245. */
  246. $sessions = SessionManager::get_sessions_by_user($userId, true);
  247. $personal_course_list = array();
  248. $courseToolInformationTotal = null;
  249. if (count($sessions) > 0) {
  250. $sessionInformation = null;
  251. $header = array(
  252. array(get_lang('Code'), true),
  253. array(get_lang('Title'), true),
  254. array(get_lang('Status'), true),
  255. array(get_lang('TimeSpentInTheCourse'), true),
  256. array(get_lang('TotalPostsInAllForums'), true),
  257. array('', false)
  258. );
  259. $headerList = array();
  260. foreach ($header as $item) {
  261. $headerList[] = $item[0];
  262. }
  263. $csvContent[] = array();
  264. $csvContent[] = array(get_lang('Sessions'));
  265. foreach ($sessions as $session_item) {
  266. $data = array();
  267. $personal_course_list = array();
  268. $id_session = $session_item['session_id'];
  269. $csvContent[] = array($session_item['session_name']);
  270. $csvContent[] = $headerList;
  271. foreach ($session_item['courses'] as $my_course) {
  272. $courseInfo = api_get_course_info_by_id($my_course['real_id']);
  273. $sessionStatus = SessionManager::get_user_status_in_session(
  274. $userId,
  275. $courseInfo['real_id'],
  276. $id_session
  277. );
  278. $status = null;
  279. switch ($sessionStatus) {
  280. case 0:
  281. case STUDENT:
  282. $status = get_lang('Student');
  283. break;
  284. case 2:
  285. $status = get_lang('CourseCoach');
  286. break;
  287. }
  288. $tools = '<a href="course_information.php?code='.$courseInfo['code'].'&id_session='.$id_session.'">'.
  289. Display::return_icon('synthese_view.gif', get_lang('Overview')).'</a>'.
  290. '<a href="'.$courseInfo['course_public_url'].'?id_session='.$id_session.'">'.
  291. Display::return_icon('course_home.gif', get_lang('CourseHomepage')).'</a>';
  292. if ($my_course['status'] == STUDENT) {
  293. $tools .= '<a href="user_information.php?action=unsubscribeSessionCourse&course_code='.$courseInfo['code'].'&user_id='.$userId.'&id_session='.$id_session.'">'.
  294. Display::return_icon('delete.png', get_lang('Delete')).'</a>';
  295. }
  296. $timeSpent = api_time_to_hms(
  297. Tracking :: get_time_spent_on_the_course(
  298. $userId,
  299. $courseInfo['real_id'],
  300. $id_session
  301. )
  302. );
  303. $totalForumMessages = CourseManager::getCountPostInForumPerUser(
  304. $userId,
  305. $courseInfo['real_id'],
  306. $id_session
  307. );
  308. $row = array(
  309. Display::url(
  310. $courseInfo['code'],
  311. $courseInfo['course_public_url'].'?id_session='.$id_session
  312. ),
  313. $courseInfo['title'],
  314. $status,
  315. $timeSpent,
  316. $totalForumMessages,
  317. $tools
  318. );
  319. $csvContent[] = array_map('strip_tags', $row);
  320. $data[] = $row;
  321. $result = TrackingUserLogCSV::getToolInformation(
  322. $userId,
  323. $courseInfo,
  324. $id_session
  325. );
  326. if (!empty($result['html'])) {
  327. $courseToolInformationTotal .= $result['html'];
  328. $csvContent = array_merge($csvContent, $result['array']);
  329. }
  330. }
  331. $dates = array_filter(
  332. array($session_item['access_start_date'], $session_item['access_end_date'])
  333. );
  334. $sessionInformation .= Display::page_subheader(
  335. '<a href="'.api_get_path(WEB_CODE_PATH).'session/resume_session.php?id_session='.$id_session.'">'.
  336. $session_item['session_name'].'</a>',
  337. ' '.implode(' - ', $dates)
  338. );
  339. $sessionInformation .= Display::return_sortable_table(
  340. $header,
  341. $data,
  342. array(),
  343. array(),
  344. array('user_id' => intval($_GET['user_id']))
  345. );
  346. $sessionInformation .= $courseToolInformationTotal;
  347. }
  348. } else {
  349. $sessionInformation = '<p>'.get_lang('NoSessionsForThisUser').'</p>';
  350. }
  351. $courseToolInformationTotal = null;
  352. /**
  353. * Show the courses in which this user is subscribed
  354. */
  355. $sql = 'SELECT * FROM '.$table_course_user.' cu, '.$table_course.' c
  356. WHERE
  357. cu.user_id = '.$userId.' AND
  358. cu.c_id = c.id AND
  359. cu.relation_type <> '.COURSE_RELATION_TYPE_RRHH.' ';
  360. $res = Database::query($sql);
  361. if (Database::num_rows($res) > 0) {
  362. $header = array(
  363. array(get_lang('Code')),
  364. array(get_lang('Title')),
  365. array(get_lang('Status')),
  366. array(get_lang('TimeSpentInTheCourse')),
  367. array(get_lang('TotalPostsInAllForums')),
  368. array('')
  369. );
  370. $headerList = array();
  371. foreach ($header as $item) {
  372. $headerList[] = $item[0];
  373. }
  374. $csvContent[] = array();
  375. $csvContent[] = array(get_lang('Courses'));
  376. $csvContent[] = $headerList;
  377. $data = array();
  378. $courseToolInformationTotal = null;
  379. while ($course = Database::fetch_object($res)) {
  380. $courseInfo = api_get_course_info_by_id($course->c_id);
  381. $courseCode = $courseInfo['code'];
  382. $courseToolInformation = null;
  383. $tools = '<a href="course_information.php?code='.$courseCode.'">'.
  384. Display::return_icon('synthese_view.gif', get_lang('Overview')).'</a>'.
  385. '<a href="'.$courseInfo['course_public_url'].'">'.
  386. Display::return_icon('course_home.gif', get_lang('CourseHomepage')).'</a>'.
  387. '<a href="course_edit.php?id='.$course->c_id.'">'.
  388. Display::return_icon('edit.gif', get_lang('Edit')).'</a>';
  389. if ($course->status == STUDENT) {
  390. $tools .= '<a href="user_information.php?action=unsubscribe&course_code='.$courseCode.'&user_id='.$userId.'">'.
  391. Display::return_icon('delete.png', get_lang('Delete')).'</a>';
  392. }
  393. $timeSpent = api_time_to_hms(
  394. Tracking :: get_time_spent_on_the_course(
  395. $userId,
  396. $courseInfo['real_id'],
  397. 0
  398. )
  399. );
  400. $totalForumMessages = CourseManager::getCountPostInForumPerUser(
  401. $userId,
  402. $course->id,
  403. 0
  404. );
  405. $row = array(
  406. Display::url($courseCode, $courseInfo['course_public_url']),
  407. $course->title,
  408. $course->status == STUDENT ? get_lang('Student') : get_lang('Teacher'),
  409. $timeSpent,
  410. $totalForumMessages,
  411. $tools,
  412. );
  413. $csvContent[] = array_map('strip_tags', $row);
  414. $data[] = $row;
  415. $result = TrackingUserLogCSV::getToolInformation(
  416. $userId,
  417. $courseInfo,
  418. 0
  419. );
  420. $courseToolInformationTotal .= $result['html'];
  421. $csvContent = array_merge($csvContent, $result['array']);
  422. }
  423. $courseInformation = Display::page_subheader(get_lang('Courses'));
  424. $courseInformation .= Display::return_sortable_table(
  425. $header,
  426. $data,
  427. array(),
  428. array(),
  429. array('user_id' => intval($_GET['user_id']))
  430. );
  431. $courseInformation .= $courseToolInformationTotal;
  432. } else {
  433. $courseInformation = '<p>'.get_lang('NoCoursesForThisUser').'</p>';
  434. }
  435. /**
  436. * Show the URL in which this user is subscribed
  437. */
  438. $urlInformation = '';
  439. if (api_is_multiple_url_enabled()) {
  440. $urlList = UrlManager::get_access_url_from_user($userId);
  441. if (count($urlList) > 0) {
  442. $header = array();
  443. $header[] = array('URL', true);
  444. $data = array();
  445. $csvContent[] = array();
  446. $csvContent[] = array('Url');
  447. foreach ($urlList as $url) {
  448. $row = array();
  449. $row[] = Display::url($url['url'], $url['url']);
  450. $csvContent[] = array_map('strip_tags', $row);
  451. $data[] = $row;
  452. }
  453. $urlInformation = Display::page_subheader(get_lang('URLList'));
  454. $urlInformation .= Display::return_sortable_table(
  455. $header,
  456. $data,
  457. array(),
  458. array(),
  459. array('user_id' => intval($_GET['user_id']))
  460. );
  461. } else {
  462. $urlInformation = '<p>'.get_lang('NoUrlForThisUser').'</p>';
  463. }
  464. }
  465. if (isset($_GET['action'])) {
  466. switch ($_GET['action']) {
  467. case 'export':
  468. Export :: arrayToCsv($csvContent, 'user_information_'.$user);
  469. exit;
  470. break;
  471. }
  472. }
  473. Display::display_header($tool_name);
  474. echo '<div class="actions">
  475. <a href="'.api_get_path(WEB_CODE_PATH).'mySpace/myStudents.php?student='.intval($_GET['user_id']).'" title="'.get_lang('Reporting').'">'.
  476. Display::return_icon('statistics.png', get_lang('Reporting'), '', ICON_SIZE_MEDIUM).'
  477. </a>
  478. '.$login_as_icon.'
  479. '.$editUser.'
  480. '.$exportLink.'
  481. '.$vCardExportLink.'
  482. </div>';
  483. echo Display::page_header($tool_name);
  484. $fullUrlBig = UserManager::getUserPicture(
  485. $userId,
  486. USER_IMAGE_SIZE_BIG
  487. );
  488. $fullUrl = UserManager::getUserPicture(
  489. $userId,
  490. USER_IMAGE_SIZE_ORIGINAL
  491. );
  492. echo '<div class="row">';
  493. echo '<div class="col-md-2">';
  494. echo '<a class="expand-image" href="'.$fullUrlBig.'">'
  495. .'<img src="'.$fullUrl.'" /></a><br />';
  496. echo '</div>';
  497. echo '<div class="col-md-5">';
  498. echo $userInformation;
  499. echo '</div>';
  500. echo '<div class="col-md-5">';
  501. echo $trackingInformation;
  502. echo '</div>';
  503. echo '</div>';
  504. if ($studentBossList) {
  505. echo Display::page_subheader(get_lang('StudentBossList'));
  506. echo $studentBossListToString;
  507. }
  508. if (api_get_setting('allow_social_tool') === 'true') {
  509. echo Display::page_subheader(get_lang('SocialData'));
  510. echo $socialInformation;
  511. }
  512. echo Display::page_subheader(get_lang('SessionList'));
  513. echo $sessionInformation;
  514. echo Display::page_subheader(get_lang('CourseList'));
  515. echo $courseInformation;
  516. echo $urlInformation;
  517. Display::display_footer();