user_information.php 15 KB

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