user_information.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  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. api_protect_admin_script();
  14. $interbreadcrumb[] = array("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
  15. $interbreadcrumb[] = array("url" => 'user_list.php', "name" => get_lang('UserList'));
  16. if (!isset($_GET['user_id'])) {
  17. api_not_allowed();
  18. }
  19. $user = api_get_user_info($_GET['user_id'], true);
  20. $tool_name = $user['complete_name'].(empty($user['official_code'])?'':' ('.$user['official_code'].')');
  21. $table_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  22. $table_course = Database :: get_main_table(TABLE_MAIN_COURSE);
  23. // only allow platform admins to login_as, or session admins only for students (not teachers nor other admins)
  24. $login_as_icon = null;
  25. $editUser = null;
  26. if (api_is_platform_admin()) {
  27. $login_as_icon =
  28. '<a href="'.api_get_path(WEB_CODE_PATH).'admin/user_list.php'
  29. .'?action=login_as&user_id='.$user['user_id'].'&'
  30. .'sec_token='.$_SESSION['sec_token'].'">'
  31. .Display::return_icon('login_as.png', get_lang('LoginAs'),
  32. array(), ICON_SIZE_MEDIUM).'</a>';
  33. $editUser = Display::url(
  34. Display::return_icon(
  35. 'edit.png',
  36. get_lang('Edit'),
  37. array(),
  38. ICON_SIZE_MEDIUM
  39. ),
  40. api_get_path(WEB_CODE_PATH).'admin/user_edit.php?user_id='.$user['user_id']
  41. );
  42. $exportLink = Display::url(
  43. Display::return_icon(
  44. 'export_csv.png', get_lang('ExportAsCSV'),'', ICON_SIZE_MEDIUM
  45. ),
  46. api_get_self().'?user_id='.$user['user_id'].'&action=export'
  47. );
  48. $vCardExportLink = Display::url(
  49. Display::return_icon(
  50. 'vcard.png', get_lang('UserInfo'),'', ICON_SIZE_MEDIUM
  51. ),
  52. api_get_path(WEB_PATH).'main/social/vcard_export.php?userId='.$user['user_id']
  53. );
  54. }
  55. // Show info about who created this user and when
  56. $creatorId = $user['creator_id'];
  57. $creatorInfo = api_get_user_info($creatorId);
  58. $registrationDate = $user['registration_date'];
  59. $csvContent = array();
  60. $table = new HTML_Table(array('class' => 'data_table'));
  61. $table->setHeaderContents(0, 0, get_lang('Information'));
  62. $csvContent[] = get_lang('Information');
  63. $data = array(
  64. get_lang('Name') => $user['complete_name'],
  65. get_lang('Email') => $user['email'],
  66. get_lang('Phone') => $user['phone'],
  67. get_lang('OfficialCode') => $user['official_code'],
  68. get_lang('Online') => $user['user_is_online'] ?
  69. Display::return_icon('online.png') : Display::return_icon(
  70. 'offline.png'
  71. ),
  72. get_lang('Status') => $user['status'] == 1 ? get_lang('Teacher') : get_lang(
  73. 'Student'
  74. ),
  75. null => sprintf(
  76. get_lang('CreatedByXYOnZ'),
  77. 'user_information.php?user_id='
  78. .$creatorId,
  79. $creatorInfo['username'],
  80. api_get_utc_datetime($registrationDate)
  81. ),
  82. );
  83. $row = 1;
  84. foreach ($data as $label => $item) {
  85. if (!empty($label)) {
  86. $label = $label.': ';
  87. }
  88. $table->setCellContents($row, 0, $label.$item);
  89. $csvContent[] = array($label, strip_tags($item));
  90. $row++;
  91. }
  92. $userInformation = $table->toHtml();
  93. $table = new HTML_Table(array('class' => 'data_table'));
  94. $table->setHeaderContents(0, 0, get_lang('Tracking'));
  95. $csvContent[] = get_lang('Tracking');
  96. $data = array(
  97. get_lang('FirstLogin') => Tracking :: get_first_connection_date($user['user_id']),
  98. get_lang('LatestLogin') => Tracking :: get_last_connection_date($user['user_id'], true)
  99. );
  100. $row = 1;
  101. foreach ($data as $label => $item) {
  102. if (!empty($label)) {
  103. $label = $label.': ';
  104. }
  105. $table->setCellContents($row, 0, $label.$item);
  106. $csvContent[] = array($label, strip_tags($item));
  107. $row++;
  108. }
  109. $trackingInformation = $table->toHtml();
  110. $tbl_session_course = Database:: get_main_table(TABLE_MAIN_SESSION_COURSE);
  111. $tbl_session_course_user = Database:: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  112. $tbl_session = Database:: get_main_table(TABLE_MAIN_SESSION);
  113. $tbl_course = Database:: get_main_table(TABLE_MAIN_COURSE);
  114. $tbl_user = Database:: get_main_table(TABLE_MAIN_USER);
  115. $user_id = $user['user_id'];
  116. $sessions = SessionManager::get_sessions_by_user($user_id, true);
  117. $personal_course_list = array();
  118. $courseToolInformationTotal = null;
  119. if (count($sessions) > 0) {
  120. $sessionInformation = null;
  121. $header = array(
  122. array(get_lang('Code'), true),
  123. array(get_lang('Title'), true),
  124. array(get_lang('Status'), true),
  125. array(get_lang('TimeSpentInTheCourse'), true),
  126. array(get_lang('TotalPostsInAllForums'), true),
  127. array('', false)
  128. );
  129. $headerList = array();
  130. foreach ($header as $item) {
  131. $headerList[] = $item[0];
  132. }
  133. $csvContent[] = array();
  134. $csvContent[] = array(get_lang('Sessions'));
  135. foreach ($sessions as $session_item) {
  136. $data = array();
  137. $personal_course_list = array();
  138. $id_session = $session_item['session_id'];
  139. $csvContent[] = array($session_item['session_name']);
  140. $csvContent[] = $headerList;
  141. foreach ($session_item['courses'] as $my_course) {
  142. $courseInfo = api_get_course_info_by_id($my_course['real_id']);
  143. $sessionStatus = SessionManager::get_user_status_in_session(
  144. $user['user_id'],
  145. $courseInfo['real_id'],
  146. $id_session
  147. );
  148. $status = null;
  149. switch ($sessionStatus) {
  150. case 0:
  151. case STUDENT:
  152. $status = get_lang('Student');
  153. break;
  154. case 2:
  155. $status = get_lang('CourseCoach');
  156. break;
  157. }
  158. $tools = '<a href="course_information.php?code='.$courseInfo['code'].'&id_session='.$id_session.'">'.
  159. Display::return_icon('synthese_view.gif', get_lang('Overview')).'</a>'.
  160. '<a href="'.$courseInfo['course_public_url'].'?id_session='.$id_session.'">'.
  161. Display::return_icon('course_home.gif', get_lang('CourseHomepage')).'</a>';
  162. if ($my_course['status'] == STUDENT) {
  163. $tools .= '<a href="user_information.php?action=unsubscribeSessionCourse&course_code='.$courseInfo['code'].'&user_id='.$user['user_id'].'&id_session='.$id_session.'">'.
  164. Display::return_icon('delete.png', get_lang('Delete')).'</a>';
  165. }
  166. $timeSpent = api_time_to_hms(
  167. Tracking :: get_time_spent_on_the_course(
  168. $user['user_id'],
  169. $courseInfo['real_id'],
  170. $id_session
  171. )
  172. );
  173. $totalForumMessages = CourseManager::getCountPostInForumPerUser(
  174. $user['user_id'],
  175. $courseInfo['real_id'],
  176. $id_session
  177. );
  178. $row = array(
  179. Display::url(
  180. $courseInfo['code'],
  181. $courseInfo['course_public_url'].'?id_session='.$id_session
  182. ),
  183. $courseInfo['title'],
  184. $status,
  185. $timeSpent,
  186. $totalForumMessages,
  187. $tools
  188. );
  189. $csvContent[] = array_map('strip_tags', $row);
  190. $data[] = $row;
  191. $result = TrackingUserLogCSV::getToolInformation(
  192. $user['user_id'],
  193. $courseInfo,
  194. $id_session
  195. );
  196. if (!empty($result['html'])) {
  197. $courseToolInformationTotal .= $result['html'];
  198. $csvContent = array_merge($csvContent, $result['array']);
  199. }
  200. }
  201. if ($session_item['access_start_date'] == '0000-00-00') {
  202. $session_item['access_start_date'] = null;
  203. }
  204. if ($session_item['access_end_date'] == '0000-00-00') {
  205. $session_item['access_end_date'] = null;
  206. }
  207. $dates = array_filter(
  208. array($session_item['access_start_date'], $session_item['access_end_date'])
  209. );
  210. $sessionInformation .= Display::page_subheader(
  211. '<a href="'.api_get_path(WEB_CODE_PATH).'session/resume_session.php?id_session='.$id_session.'">'.
  212. $session_item['session_name'].'</a>',
  213. ' '.implode(' - ', $dates)
  214. );
  215. $sessionInformation .= Display::return_sortable_table(
  216. $header,
  217. $data,
  218. array(),
  219. array(),
  220. array('user_id' => intval($_GET['user_id']))
  221. );
  222. $sessionInformation .= $courseToolInformationTotal;
  223. }
  224. } else {
  225. $sessionInformation = '<p>'.get_lang('NoSessionsForThisUser').'</p>';
  226. }
  227. $courseToolInformationTotal = null;
  228. /**
  229. * Show the courses in which this user is subscribed
  230. */
  231. $sql = 'SELECT * FROM '.$table_course_user.' cu, '.$table_course.' c
  232. WHERE
  233. cu.user_id = '.$user['user_id'].' AND
  234. cu.c_id = c.id AND
  235. cu.relation_type <> '.COURSE_RELATION_TYPE_RRHH.' ';
  236. $res = Database::query($sql);
  237. if (Database::num_rows($res) > 0) {
  238. $header = array(
  239. array(get_lang('Code')),
  240. array(get_lang('Title')),
  241. array(get_lang('Status')),
  242. array(get_lang('TimeSpentInTheCourse')),
  243. array(get_lang('TotalPostsInAllForums')),
  244. array('')
  245. );
  246. $headerList = array();
  247. foreach ($header as $item) {
  248. $headerList[] = $item[0];
  249. }
  250. $csvContent[] = array();
  251. $csvContent[] = array(get_lang('Courses'));
  252. $csvContent[] = $headerList;
  253. $data = array();
  254. $courseToolInformationTotal = null;
  255. while ($course = Database::fetch_object($res)) {
  256. $courseInfo = api_get_course_info_by_id($course->c_id);
  257. $courseCode = $courseInfo['code'];
  258. $courseToolInformation = null;
  259. $tools = '<a href="course_information.php?code='.$courseCode.'">'.
  260. Display::return_icon('synthese_view.gif', get_lang('Overview')).'</a>'.
  261. '<a href="'.$courseInfo['course_public_url'].'">'.
  262. Display::return_icon('course_home.gif', get_lang('CourseHomepage')).'</a>' .
  263. '<a href="course_edit.php?id='.$course->c_id.'">'.
  264. Display::return_icon('edit.gif', get_lang('Edit')).'</a>';
  265. if ($course->status == STUDENT) {
  266. $tools .= '<a href="user_information.php?action=unsubscribe&course_code='.$courseCode.'&user_id='.$user['user_id'].'">'.
  267. Display::return_icon('delete.png', get_lang('Delete')).'</a>';
  268. }
  269. $timeSpent = api_time_to_hms(
  270. Tracking :: get_time_spent_on_the_course(
  271. $user['user_id'],
  272. $courseInfo['real_id'],
  273. 0
  274. )
  275. );
  276. $totalForumMessages = CourseManager::getCountPostInForumPerUser(
  277. $user['user_id'],
  278. $course->id,
  279. 0
  280. );
  281. $row = array(
  282. Display::url($courseCode, $courseInfo['course_public_url']),
  283. $course->title,
  284. $course->status == STUDENT ? get_lang('Student') : get_lang('Teacher'),
  285. $timeSpent,
  286. $totalForumMessages,
  287. $tools,
  288. );
  289. $csvContent[] = array_map('strip_tags', $row);
  290. $data[] = $row;
  291. $result = TrackingUserLogCSV::getToolInformation(
  292. $user['user_id'],
  293. $courseInfo,
  294. 0
  295. );
  296. $courseToolInformationTotal .= $result['html'];
  297. $csvContent = array_merge($csvContent, $result['array']);
  298. }
  299. $courseInformation = Display::page_subheader(get_lang('Courses'));
  300. $courseInformation .= Display::return_sortable_table(
  301. $header,
  302. $data,
  303. array(),
  304. array(),
  305. array('user_id' => intval($_GET['user_id']))
  306. );
  307. $courseInformation .= $courseToolInformationTotal;
  308. } else {
  309. $courseInformation = '<p>'.get_lang('NoCoursesForThisUser').'</p>';
  310. }
  311. /**
  312. * Show the URL in which this user is subscribed
  313. */
  314. $urlInformation = null;
  315. if (api_is_multiple_url_enabled()) {
  316. $urlList = UrlManager::get_access_url_from_user($user['user_id']);
  317. if (count($urlList) > 0) {
  318. $header = array();
  319. $header[] = array('URL', true);
  320. $data = array();
  321. $csvContent[] = array();
  322. $csvContent[] = array('Url');
  323. foreach ($urlList as $url) {
  324. $row = array();
  325. $row[] = Display::url($url['url'], $url['url']);
  326. $csvContent[] = array_map('strip_tags', $row);
  327. $data[] = $row;
  328. }
  329. $urlInformation = Display::page_subheader(get_lang('URLList'));
  330. $urlInformation .= Display::return_sortable_table(
  331. $header,
  332. $data,
  333. array(),
  334. array(),
  335. array('user_id' => intval($_GET['user_id']))
  336. );
  337. } else {
  338. $urlInformation = '<p>'.get_lang('NoUrlForThisUser').'</p>';
  339. }
  340. }
  341. $message = null;
  342. if (isset($_GET['action'])) {
  343. switch ($_GET['action']) {
  344. case 'unsubscribe':
  345. if (CourseManager::get_user_in_course_status($_GET['user_id'], $_GET['course_code']) == STUDENT) {
  346. CourseManager::unsubscribe_user($_GET['user_id'], $_GET['course_code'], $_GET['id_session']);
  347. $message = Display::return_message(get_lang('UserUnsubscribed'));
  348. } else {
  349. $message = Display::return_message(
  350. get_lang('CannotUnsubscribeUserFromCourse'),
  351. 'error'
  352. );
  353. }
  354. break;
  355. case 'unsubscribeSessionCourse':
  356. SessionManager::removeUsersFromCourseSession(
  357. array($_GET['user_id']),
  358. $_GET['id_session'],
  359. api_get_course_info($_GET['course_code'])
  360. );
  361. $message = Display::return_message(get_lang('UserUnsubscribed'));
  362. break;
  363. case 'export':
  364. Export :: arrayToCsv($csvContent, 'user_information_'.$user);
  365. exit;
  366. break;
  367. }
  368. }
  369. Display::display_header($tool_name);
  370. echo '<div class="actions">
  371. <a href="'.api_get_path(WEB_CODE_PATH).'mySpace/myStudents.php?student='.intval($_GET['user_id']).'" title="'.get_lang('Reporting').'">'.
  372. Display::return_icon('statistics.png', get_lang('Reporting'), '', ICON_SIZE_MEDIUM).'
  373. </a>
  374. '.$login_as_icon.'
  375. '.$editUser.'
  376. '.$exportLink.'
  377. '.$vCardExportLink.'
  378. </div>';
  379. echo Display::page_header($tool_name);
  380. $fullUrlBig = UserManager::getUserPicture(
  381. $user['user_id'],
  382. USER_IMAGE_SIZE_BIG
  383. );
  384. $fullUrl = UserManager::getUserPicture(
  385. $user['user_id'],
  386. USER_IMAGE_SIZE_ORIGINAL
  387. );
  388. echo '<div class="row">';
  389. echo '<div class="col-md-2">';
  390. echo '<a class="expand-image" href="'.$fullUrlBig.'">'
  391. .'<img src="'.$fullUrl.'" /></a><br />';
  392. echo '</div>';
  393. echo $message;
  394. echo '<div class="col-md-5">';
  395. echo $userInformation;
  396. echo '</div>';
  397. echo '<div class="col-md-5">';
  398. echo $trackingInformation;
  399. echo '</div>';
  400. echo '</div>';
  401. echo Display::page_subheader(get_lang('SessionList'));
  402. echo $sessionInformation;
  403. echo $courseInformation;
  404. echo $urlInformation;
  405. Display::display_footer();