user_information.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558
  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. $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. $dates = array_filter(
  310. array($session_item['access_start_date'], $session_item['access_end_date'])
  311. );
  312. $sessionInformation .= Display::page_subheader(
  313. '<a href="'.api_get_path(WEB_CODE_PATH).'session/resume_session.php?id_session='.$id_session.'">'.
  314. $session_item['session_name'].'</a>',
  315. ' '.implode(' - ', $dates)
  316. );
  317. $sessionInformation .= Display::return_sortable_table(
  318. $header,
  319. $data,
  320. array(),
  321. array(),
  322. array('user_id' => intval($_GET['user_id']))
  323. );
  324. $sessionInformation .= $courseToolInformationTotal;
  325. }
  326. } else {
  327. $sessionInformation = '<p>'.get_lang('NoSessionsForThisUser').'</p>';
  328. }
  329. $courseToolInformationTotal = null;
  330. /**
  331. * Show the courses in which this user is subscribed
  332. */
  333. $sql = 'SELECT * FROM '.$table_course_user.' cu, '.$table_course.' c
  334. WHERE
  335. cu.user_id = '.$userId.' AND
  336. cu.c_id = c.id AND
  337. cu.relation_type <> '.COURSE_RELATION_TYPE_RRHH.' ';
  338. $res = Database::query($sql);
  339. if (Database::num_rows($res) > 0) {
  340. $header = array(
  341. array(get_lang('Code')),
  342. array(get_lang('Title')),
  343. array(get_lang('Status')),
  344. array(get_lang('TimeSpentInTheCourse')),
  345. array(get_lang('TotalPostsInAllForums')),
  346. array('')
  347. );
  348. $headerList = array();
  349. foreach ($header as $item) {
  350. $headerList[] = $item[0];
  351. }
  352. $csvContent[] = array();
  353. $csvContent[] = array(get_lang('Courses'));
  354. $csvContent[] = $headerList;
  355. $data = array();
  356. $courseToolInformationTotal = null;
  357. while ($course = Database::fetch_object($res)) {
  358. $courseInfo = api_get_course_info_by_id($course->c_id);
  359. $courseCode = $courseInfo['code'];
  360. $courseToolInformation = null;
  361. $tools = '<a href="course_information.php?code='.$courseCode.'">'.
  362. Display::return_icon('synthese_view.gif', get_lang('Overview')).'</a>'.
  363. '<a href="'.$courseInfo['course_public_url'].'">'.
  364. Display::return_icon('course_home.gif', get_lang('CourseHomepage')).'</a>' .
  365. '<a href="course_edit.php?id='.$course->c_id.'">'.
  366. Display::return_icon('edit.gif', get_lang('Edit')).'</a>';
  367. if ($course->status == STUDENT) {
  368. $tools .= '<a href="user_information.php?action=unsubscribe&course_code='.$courseCode.'&user_id='.$userId.'">'.
  369. Display::return_icon('delete.png', get_lang('Delete')).'</a>';
  370. }
  371. $timeSpent = api_time_to_hms(
  372. Tracking :: get_time_spent_on_the_course(
  373. $userId,
  374. $courseInfo['real_id'],
  375. 0
  376. )
  377. );
  378. $totalForumMessages = CourseManager::getCountPostInForumPerUser(
  379. $userId,
  380. $course->id,
  381. 0
  382. );
  383. $row = array(
  384. Display::url($courseCode, $courseInfo['course_public_url']),
  385. $course->title,
  386. $course->status == STUDENT ? get_lang('Student') : get_lang('Teacher'),
  387. $timeSpent,
  388. $totalForumMessages,
  389. $tools,
  390. );
  391. $csvContent[] = array_map('strip_tags', $row);
  392. $data[] = $row;
  393. $result = TrackingUserLogCSV::getToolInformation(
  394. $userId,
  395. $courseInfo,
  396. 0
  397. );
  398. $courseToolInformationTotal .= $result['html'];
  399. $csvContent = array_merge($csvContent, $result['array']);
  400. }
  401. $courseInformation = Display::page_subheader(get_lang('Courses'));
  402. $courseInformation .= Display::return_sortable_table(
  403. $header,
  404. $data,
  405. array(),
  406. array(),
  407. array('user_id' => intval($_GET['user_id']))
  408. );
  409. $courseInformation .= $courseToolInformationTotal;
  410. } else {
  411. $courseInformation = '<p>'.get_lang('NoCoursesForThisUser').'</p>';
  412. }
  413. /**
  414. * Show the URL in which this user is subscribed
  415. */
  416. $urlInformation = '';
  417. if (api_is_multiple_url_enabled()) {
  418. $urlList = UrlManager::get_access_url_from_user($userId);
  419. if (count($urlList) > 0) {
  420. $header = array();
  421. $header[] = array('URL', true);
  422. $data = array();
  423. $csvContent[] = array();
  424. $csvContent[] = array('Url');
  425. foreach ($urlList as $url) {
  426. $row = array();
  427. $row[] = Display::url($url['url'], $url['url']);
  428. $csvContent[] = array_map('strip_tags', $row);
  429. $data[] = $row;
  430. }
  431. $urlInformation = Display::page_subheader(get_lang('URLList'));
  432. $urlInformation .= Display::return_sortable_table(
  433. $header,
  434. $data,
  435. array(),
  436. array(),
  437. array('user_id' => intval($_GET['user_id']))
  438. );
  439. } else {
  440. $urlInformation = '<p>'.get_lang('NoUrlForThisUser').'</p>';
  441. }
  442. }
  443. if (isset($_GET['action'])) {
  444. switch ($_GET['action']) {
  445. case 'export':
  446. Export :: arrayToCsv($csvContent, 'user_information_'.$user);
  447. exit;
  448. break;
  449. }
  450. }
  451. Display::display_header($tool_name);
  452. echo '<div class="actions">
  453. <a href="'.api_get_path(WEB_CODE_PATH).'mySpace/myStudents.php?student='.intval($_GET['user_id']).'" title="'.get_lang('Reporting').'">'.
  454. Display::return_icon('statistics.png', get_lang('Reporting'), '', ICON_SIZE_MEDIUM).'
  455. </a>
  456. '.$login_as_icon.'
  457. '.$editUser.'
  458. '.$exportLink.'
  459. '.$vCardExportLink.'
  460. </div>';
  461. echo Display::page_header($tool_name);
  462. $fullUrlBig = UserManager::getUserPicture(
  463. $userId,
  464. USER_IMAGE_SIZE_BIG
  465. );
  466. $fullUrl = UserManager::getUserPicture(
  467. $userId,
  468. USER_IMAGE_SIZE_ORIGINAL
  469. );
  470. echo '<div class="row">';
  471. echo '<div class="col-md-2">';
  472. echo '<a class="expand-image" href="'.$fullUrlBig.'">'
  473. .'<img src="'.$fullUrl.'" /></a><br />';
  474. echo '</div>';
  475. echo '<div class="col-md-5">';
  476. echo $userInformation;
  477. echo '</div>';
  478. echo '<div class="col-md-5">';
  479. echo $trackingInformation;
  480. echo '</div>';
  481. echo '</div>';
  482. if ($studentBossList) {
  483. echo Display::page_subheader(get_lang('StudentBossList'));
  484. echo $studentBossListToString;
  485. }
  486. echo Display::page_subheader(get_lang('SessionList'));
  487. echo $sessionInformation;
  488. echo Display::page_subheader(get_lang('CourseList'));
  489. echo $courseInformation;
  490. echo $urlInformation;
  491. Display::display_footer();