user_information.php 15 KB

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