user_information.php 20 KB

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