user_move_stats.php 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * User move script (to move between courses and sessions)
  5. * @package chamilo.admin
  6. */
  7. $cidReset = true;
  8. require_once __DIR__.'/../inc/global.inc.php';
  9. $this_section = SECTION_PLATFORM_ADMIN;
  10. api_protect_admin_script();
  11. $interbreadcrumb[] = array("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
  12. $debug = 0;
  13. function compare_data($result_message) {
  14. foreach ($result_message as $table=>$data) {
  15. $title = $table;
  16. if ($table == 'TRACK_E_EXERCISES') {
  17. $title = get_lang('Exercises');
  18. } elseif ($table == 'TRACK_E_EXERCISES_IN_LP') {
  19. $title = get_lang('ExercisesInLp');
  20. } elseif ($table == 'LP_VIEW') {
  21. $title = get_lang('LearningPaths');
  22. }
  23. echo '<br / ><h3>'.get_lang($title).' </h3><hr />';
  24. if (is_array($data)) {
  25. foreach ($data as $id => $item) {
  26. if ($table == 'TRACK_E_EXERCISES' || $table == 'TRACK_E_EXERCISES_IN_LP') {
  27. echo "<br /><h3>".get_lang('Attempt')." #$id</h3>";
  28. echo '<h3>';
  29. echo get_lang('Exercise').' #'.$item['exe_exo_id'];
  30. echo '</h3>';
  31. if (!empty($item['orig_lp_id'])) {
  32. echo '<h3>';
  33. echo get_lang('LearningPath').' #'.$item['orig_lp_id'];
  34. echo '</h3>';
  35. }
  36. //Process data
  37. $array = array('exe_date' =>get_lang('Date'), 'exe_result' =>get_lang('Score'), 'exe_weighting'=>get_lang('Weighting'));
  38. foreach ($item as $key=> $value) {
  39. if (in_array($key, array_keys($array))) {
  40. $key = $array[$key];
  41. echo "$key = $value <br />";
  42. }
  43. }
  44. } else {
  45. echo "<br /><h3>".get_lang('Id')." #$id</h3>";
  46. //process data
  47. foreach ($item as $key=> $value) {
  48. echo "$key = $value <br />";
  49. }
  50. }
  51. }
  52. } else {
  53. echo get_lang('NoResults');
  54. }
  55. }
  56. }
  57. if (isset($_REQUEST['load_ajax'])) {
  58. //Checking the variable $_SESSION['combination'] that has all the information of the selected course (instead of using a lots of hidden variables ... )
  59. if (isset($_SESSION['combination']) && !empty($_SESSION['combination'])) {
  60. $combinations = $_SESSION['combination'];
  61. $combination_result = $combinations[$_REQUEST['unique_id']];
  62. if (empty($combination_result)) {
  63. echo get_lang('ThereWasAnError');
  64. } else {
  65. $origin_course_code = $combination_result['course_code'];
  66. $origin_session_id = intval($combination_result['session_id']);
  67. $new_session_id = intval($_REQUEST['session_id']);
  68. $session = $em->find('ChamiloCoreBundle:Session', $new_session_id);
  69. //if (!isset($_REQUEST['view_stat'])) {
  70. if ($origin_session_id == $new_session_id) {
  71. echo get_lang('CantMoveToTheSameSession');
  72. exit;
  73. }
  74. //}
  75. $user_id = intval($_REQUEST['user_id']);
  76. $new_course_list = SessionManager::get_course_list_by_session_id($new_session_id);
  77. $course_founded = false;
  78. foreach ($new_course_list as $course_item) {
  79. if ($origin_course_code == $course_item['code']) {
  80. $course_founded = true;
  81. }
  82. }
  83. $result_message = array();
  84. $result_message_compare = array();
  85. $update_database = true;
  86. if (isset($_REQUEST['view_stat']) && $_REQUEST['view_stat'] == 1) {
  87. $update_database = false;
  88. }
  89. //Check if the same course exist in the session destination
  90. if ($course_founded) {
  91. //Check if the user is registered in the session otherwise we will add it
  92. $result = SessionManager::get_users_by_session($new_session_id);
  93. if (empty($result) || !in_array($user_id, array_keys($result))) {
  94. if ($debug) echo 'User added to the session';
  95. //Registering user to the new session
  96. SessionManager::subscribe_users_to_session($new_session_id, array($user_id), false);
  97. }
  98. //Begin with the import process
  99. $course_info = api_get_course_info($origin_course_code);
  100. $course_id = $course_info['real_id'];
  101. $TABLETRACK_EXERCICES = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
  102. $TBL_TRACK_ATTEMPT = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
  103. $TBL_TRACK_E_COURSE_ACCESS = Database::get_main_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
  104. $TBL_TRACK_E_LAST_ACCESS = Database::get_main_table(TABLE_STATISTIC_TRACK_E_LASTACCESS);
  105. $TBL_LP_VIEW = Database::get_course_table(TABLE_LP_VIEW);
  106. $TBL_NOTEBOOK = Database::get_course_table(TABLE_NOTEBOOK);
  107. $TBL_STUDENT_PUBLICATION = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
  108. $TBL_STUDENT_PUBLICATION_ASSIGNMENT = Database::get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT);
  109. $TBL_ITEM_PROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY);
  110. $TBL_DROPBOX_FILE = Database::get_course_table(TABLE_DROPBOX_FILE);
  111. $TBL_DROPBOX_POST = Database::get_course_table(TABLE_DROPBOX_POST);
  112. $TBL_AGENDA = Database::get_course_table(TABLE_AGENDA);
  113. //1. track_e_exercises
  114. //ORIGINAL COURSE
  115. $sql = "SELECT * FROM $TABLETRACK_EXERCICES
  116. WHERE c_id = $course_id AND session_id = $origin_session_id AND exe_user_id = $user_id ";
  117. $res = Database::query($sql);
  118. $list = array();
  119. while ($row = Database::fetch_array($res, 'ASSOC')) {
  120. $list[$row['exe_id']] = $row;
  121. }
  122. if (!empty($list))
  123. foreach ($list as $exe_id =>$data) {
  124. if ($update_database) {
  125. $sql = "UPDATE $TABLETRACK_EXERCICES SET session_id = '$new_session_id' WHERE exe_id = $exe_id";
  126. $res = Database::query($sql);
  127. $result_message[$TABLETRACK_EXERCICES]++;
  128. } else {
  129. if (!empty($data['orig_lp_id']) && !empty($data['orig_lp_item_id'])) {
  130. $result_message['TRACK_E_EXERCISES'][$exe_id] = $data;
  131. } else {
  132. $result_message['TRACK_E_EXERCISES_IN_LP'][$exe_id] = $data;
  133. }
  134. }
  135. }
  136. //DESTINY COURSE
  137. if (!$update_database) {
  138. $sql = "SELECT * FROM $TABLETRACK_EXERCICES
  139. WHERE c_id = $course_id AND session_id = $new_session_id AND exe_user_id = $user_id ";
  140. $res = Database::query($sql);
  141. $list = array();
  142. while ($row = Database::fetch_array($res, 'ASSOC')) {
  143. $list[$row['exe_id']] = $row;
  144. }
  145. if (!empty($list))
  146. foreach ($list as $exe_id =>$data) {
  147. if ($update_database) {
  148. $sql = "UPDATE $TABLETRACK_EXERCICES SET session_id = '$new_session_id' WHERE exe_id = $exe_id";
  149. $res = Database::query($sql);
  150. $result_message[$TABLETRACK_EXERCICES]++;
  151. } else {
  152. if (!empty($data['orig_lp_id']) && !empty($data['orig_lp_item_id'])) {
  153. $result_message_compare['TRACK_E_EXERCISES'][$exe_id] = $data;
  154. } else {
  155. $result_message_compare['TRACK_E_EXERCISES_IN_LP'][$exe_id] = $data;
  156. }
  157. }
  158. }
  159. }
  160. //2.track_e_attempt, track_e_attempt_recording, track_e_downloads
  161. //Nothing to do because there are not relationship with a session
  162. //3. track_e_course_access
  163. $sql = "SELECT * FROM $TBL_TRACK_E_COURSE_ACCESS
  164. WHERE c_id = $course_id AND session_id = $origin_session_id AND user_id = $user_id ";
  165. $res = Database::query($sql);
  166. $list = array();
  167. while ($row = Database::fetch_array($res, 'ASSOC')) {
  168. $list[$row['course_access_id']] = $row;
  169. }
  170. if (!empty($list))
  171. foreach ($list as $id => $data) {
  172. if ($update_database) {
  173. $sql = "UPDATE $TBL_TRACK_E_COURSE_ACCESS SET session_id = $new_session_id WHERE course_access_id = $id";
  174. if ($debug) {
  175. echo $sql;
  176. }
  177. $res = Database::query($sql);
  178. $result_message[$TBL_TRACK_E_COURSE_ACCESS]++;
  179. }
  180. }
  181. //4. track_e_lastaccess
  182. $sql = "SELECT access_id FROM $TBL_TRACK_E_LAST_ACCESS
  183. WHERE c_id = $course_id
  184. AND access_session_id = $origin_session_id
  185. AND access_user_id = $user_id ";
  186. $res = Database::query($sql);
  187. $list = array();
  188. while ($row = Database::fetch_array($res, 'ASSOC')) {
  189. $list[] = $row['access_id'];
  190. }
  191. if (!empty($list))
  192. foreach ($list as $id) {
  193. if ($update_database) {
  194. $sql = "UPDATE $TBL_TRACK_E_LAST_ACCESS SET access_session_id = $new_session_id WHERE access_id = $id";
  195. if ($debug) echo $sql;
  196. $res = Database::query($sql);
  197. //if ($debug) var_dump($res);
  198. $result_message[$TBL_TRACK_E_LAST_ACCESS]++;
  199. }
  200. }
  201. //5. lp_item_view
  202. //CHECK ORIGIN
  203. $sql = "SELECT * FROM $TBL_LP_VIEW
  204. WHERE user_id = $user_id AND session_id = $origin_session_id AND c_id = $course_id ";
  205. $res = Database::query($sql);
  206. //Getting the list of LPs in the new session
  207. $lp_list = new LearnpathList($user_id, $origin_course_code, $new_session_id);
  208. $flat_list = $lp_list->get_flat_list();
  209. $list = array();
  210. while ($row = Database::fetch_array($res, 'ASSOC')) {
  211. //Checking if the LP exist in the new session
  212. if (in_array($row['lp_id'], array_keys($flat_list))) {
  213. $list[$row['id']] = $row;
  214. }
  215. }
  216. if (!empty($list))
  217. foreach ($list as $id=>$data) {
  218. if ($update_database) {
  219. $sql = "UPDATE $TBL_LP_VIEW SET session_id = $new_session_id WHERE c_id = $course_id AND id = $id ";
  220. if ($debug) var_dump($sql);
  221. $res = Database::query($sql);
  222. if ($debug) var_dump($res);
  223. $result_message[$TBL_LP_VIEW]++;
  224. } else {
  225. //Getting all information of that lp_item_id
  226. $score = Tracking::get_avg_student_score($user_id, $origin_course_code, array($data['lp_id']), $origin_session_id);
  227. $progress = Tracking::get_avg_student_progress($user_id, $origin_course_code, array($data['lp_id']), $origin_session_id);
  228. $result_message['LP_VIEW'][$data['lp_id']] = array('score' => $score, 'progress' =>$progress);
  229. }
  230. }
  231. //CHECk DESTINY
  232. if (!$update_database) {
  233. $sql = "SELECT * FROM $TBL_LP_VIEW WHERE user_id = $user_id AND session_id = $new_session_id AND c_id = $course_id";
  234. $res = Database::query($sql);
  235. //Getting the list of LPs in the new session
  236. $lp_list = new LearnpathList($user_id, $origin_course_code, $new_session_id);
  237. $flat_list = $lp_list->get_flat_list();
  238. $list = array();
  239. while ($row = Database::fetch_array($res, 'ASSOC')) {
  240. //Checking if the LP exist in the new session
  241. if (in_array($row['lp_id'], array_keys($flat_list))) {
  242. $list[$row['id']] = $row;
  243. }
  244. }
  245. if (!empty($list))
  246. foreach ($list as $id=>$data) {
  247. //Getting all information of that lp_item_id
  248. $score = Tracking::get_avg_student_score($user_id, $origin_course_code, array($data['lp_id']), $new_session_id);
  249. $progress = Tracking::get_avg_student_progress($user_id, $origin_course_code, array($data['lp_id']), $new_session_id);
  250. $result_message_compare['LP_VIEW'][$data['lp_id']] = array('score' => $score, 'progress' =>$progress);
  251. }
  252. }
  253. //6. Agenda
  254. //calendar_event_attachment no problems no session_id
  255. $sql = "SELECT ref FROM $TBL_ITEM_PROPERTY WHERE tool = 'calendar_event' AND insert_user_id = $user_id AND c_id = $course_id ";
  256. $res = Database::query($sql);
  257. while ($row = Database::fetch_array($res, 'ASSOC')) {
  258. $id = $row['ref'];
  259. if ($update_database) {
  260. $sql = "UPDATE $TBL_AGENDA SET session_id = $new_session_id WHERE c_id = $course_id AND id = $id ";
  261. if ($debug) var_dump($sql);
  262. $res_update = Database::query($sql);
  263. if ($debug) var_dump($res_update);
  264. $result_message['agenda']++;
  265. }
  266. }
  267. //7. Forum ?? So much problems when trying to import data
  268. //8. Student publication - Works
  269. //echo '<h1>Student publication</h1>';
  270. $sql = "SELECT ref FROM $TBL_ITEM_PROPERTY WHERE tool = 'work' AND insert_user_id = $user_id AND c_id = $course_id";
  271. if ($debug) echo $sql;
  272. $res = Database::query($sql);
  273. while ($row = Database::fetch_array($res, 'ASSOC')) {
  274. $id = $row['ref'];
  275. $sql = "SELECT * FROM $TBL_STUDENT_PUBLICATION WHERE id = $id AND session_id = $origin_session_id AND c_id = $course_id";
  276. if ($debug) var_dump($sql);
  277. $sub_res = Database::query($sql);
  278. if (Database::num_rows($sub_res) > 0) {
  279. $data = Database::fetch_array($sub_res, 'ASSOC');
  280. if ($debug) var_dump($data);
  281. $parent_id = $data['parent_id'];
  282. if (isset($data['parent_id']) && !empty($data['parent_id'])) {
  283. $sql = "SELECT * FROM $TBL_STUDENT_PUBLICATION WHERE id = $parent_id AND c_id = $course_id";
  284. $select_res = Database::query($sql);
  285. $parent_data = Database::fetch_array($select_res, 'ASSOC');
  286. if ($debug) var_dump($parent_data);
  287. $sys_course_path = api_get_path(SYS_COURSE_PATH);
  288. $course_dir = $sys_course_path.$course_info['path'];
  289. $base_work_dir = $course_dir.'/work';
  290. require_once api_get_path(SYS_CODE_PATH).'work/work.lib.php';
  291. //Creating the parent folder in the session if does not exists already
  292. //@todo ugly fix
  293. $search_this = "folder_moved_from_session_id_$origin_session_id";
  294. $search_this2 = $parent_data['url'];
  295. $sql = "SELECT * FROM $TBL_STUDENT_PUBLICATION
  296. WHERE description like '%$search_this%' AND url LIKE '%$search_this2%' AND session_id = $new_session_id AND c_id = $course_id
  297. ORDER BY id desc LIMIT 1";
  298. if ($debug) echo $sql;
  299. $sub_res = Database::query($sql);
  300. $num_rows = Database::num_rows($sub_res);
  301. if ($num_rows > 0) {
  302. $new_result = Database::fetch_array($sub_res, 'ASSOC');
  303. $created_dir = $new_result['url'];
  304. $new_parent_id = $new_result['id'];
  305. } else {
  306. if ($update_database) {
  307. $dir_name = substr($parent_data['url'], 1);
  308. $created_dir = create_unexisting_work_directory($base_work_dir, $dir_name);
  309. $created_dir = '/'.$created_dir;
  310. $now = new DateTime(api_get_utc_datetime(), new DateTimeZone('UTC'));
  311. //Creating directory
  312. $publication = new \Chamilo\CourseBundle\Entity\CStudentPublication();
  313. $publication
  314. ->setUrl($created_dir)
  315. ->setCId($course_id)
  316. ->setTitle($parent_data['title'])
  317. ->setDescription(
  318. $parent_data['description']."folder_moved_from_session_id_$origin_session_id"
  319. )
  320. ->setActive(false)
  321. ->setAccepted(true)
  322. ->setFiletype('folder')
  323. ->setSentDate($now)
  324. ->setQualification($parent_data['qualification'])
  325. ->setParentId(0)
  326. ->setQualificatorId(0)
  327. ->setSession($session);
  328. $id = $publication->getIid();
  329. //Folder created
  330. api_item_property_update($course_info, 'work', $id, 'DirectoryCreated', api_get_user_id());
  331. $new_parent_id = $id;
  332. $result_message[$TBL_STUDENT_PUBLICATION.' - new folder created called: '.$created_dir]++;
  333. }
  334. }
  335. //Creating student_publication_assignment if exists
  336. $sql = "SELECT * FROM $TBL_STUDENT_PUBLICATION_ASSIGNMENT WHERE publication_id = $parent_id AND c_id = $course_id";
  337. if ($debug) var_dump($sql);
  338. $rest_select = Database::query($sql);
  339. if (Database::num_rows($rest_select) > 0) {
  340. if ($update_database) {
  341. $assignment_data = Database::fetch_array($rest_select, 'ASSOC');
  342. $sql_add_publication = "INSERT INTO ".$TBL_STUDENT_PUBLICATION_ASSIGNMENT." SET
  343. c_id = '$course_id',
  344. expires_on = '".$assignment_data['expires_on']."',
  345. ends_on = '".$assignment_data['ends_on']."',
  346. add_to_calendar = '".$assignment_data['add_to_calendar']."',
  347. enable_qualification = '".$assignment_data['enable_qualification']."',
  348. publication_id = '".$new_parent_id."'";
  349. if ($debug) echo $sql_add_publication;
  350. $rest_select = Database::query($sql_add_publication);
  351. $id = Database::insert_id();
  352. $sql_update = "UPDATE ".$TBL_STUDENT_PUBLICATION." SET ".
  353. "has_properties = '".$id."',
  354. view_properties = '1'
  355. WHERE id = ".$new_parent_id;
  356. if ($debug) echo $sql_update;
  357. $rest_update = Database::query($sql_update);
  358. if ($debug) var_dump($sql_update);
  359. $result_message[$TBL_STUDENT_PUBLICATION_ASSIGNMENT]++;
  360. }
  361. }
  362. $doc_url = $data['url'];
  363. $new_url = str_replace($parent_data['url'], $created_dir, $doc_url);
  364. if ($update_database) {
  365. //Creating a new work
  366. $data['sent_date'] = new DateTime($data['sent_date'], new DateTimeZone('UTC'));
  367. $publication = new \Chamilo\CourseBundle\Entity\CStudentPublication();
  368. $publication
  369. ->setUrl($new_url)
  370. ->setCId($course_id)
  371. ->setTitle($data['title'])
  372. ->setDescription($data['description'].' file moved')
  373. ->setActive($data['active'])
  374. ->setAccepted($data['accepted'])
  375. ->setPostGroupId($data['post_group_id'])
  376. ->setSentDate($data['sent_date'])
  377. ->setParentId($new_parent_id)
  378. ->setSession($session);
  379. $em->persist($publication);
  380. $em->flush();
  381. $id = $publication->getIid();
  382. api_item_property_update($course_info, 'work', $id, 'DocumentAdded', $user_id);
  383. $result_message[$TBL_STUDENT_PUBLICATION]++;
  384. $full_file_name = $course_dir.'/'.$doc_url;
  385. $new_file = $course_dir.'/'.$new_url;
  386. if (file_exists($full_file_name)) {
  387. //deleting old assignment
  388. $result = copy($full_file_name, $new_file);
  389. if ($result) {
  390. unlink($full_file_name);
  391. $sql = "DELETE FROM $TBL_STUDENT_PUBLICATION WHERE id= ".$data['id'];
  392. if ($debug) var_dump($sql);
  393. $result_delete = Database::query($sql);
  394. api_item_property_update($course_info, 'work', $data['id'], 'DocumentDeleted', api_get_user_id());
  395. }
  396. }
  397. }
  398. }
  399. }
  400. }
  401. //9. Survey Pending
  402. //10. Dropbox - not neccesary to move categories (no presence of session_id)
  403. $sql = "SELECT id FROM $TBL_DROPBOX_FILE WHERE uploader_id = $user_id AND session_id = $origin_session_id AND c_id = $course_id";
  404. if ($debug) var_dump($sql);
  405. $res = Database::query($sql);
  406. while ($row = Database::fetch_array($res, 'ASSOC')) {
  407. $id = $row['id'];
  408. if ($update_database) {
  409. $sql = "UPDATE $TBL_DROPBOX_FILE SET session_id = $new_session_id WHERE c_id = $course_id AND id = $id";
  410. if ($debug) var_dump($sql);
  411. $res = Database::query($sql);
  412. if ($debug) var_dump($res);
  413. $sql = "UPDATE $TBL_DROPBOX_POST SET session_id = $new_session_id WHERE file_id = $id";
  414. if ($debug)
  415. var_dump($sql);
  416. $res = Database::query($sql);
  417. if ($debug)
  418. var_dump($res);
  419. $result_message[$TBL_DROPBOX_FILE]++;
  420. }
  421. }
  422. //11. Notebook
  423. $sql = "SELECT notebook_id FROM $TBL_NOTEBOOK
  424. WHERE user_id = $user_id AND session_id = $origin_session_id AND course = '$origin_course_code' AND c_id = $course_id";
  425. if ($debug) var_dump($sql);
  426. $res = Database::query($sql);
  427. while ($row = Database::fetch_array($res, 'ASSOC')) {
  428. $id = $row['notebook_id'];
  429. if ($update_database) {
  430. $sql = "UPDATE $TBL_NOTEBOOK SET session_id = $new_session_id WHERE c_id = $course_id AND notebook_id = $id";
  431. if ($debug) var_dump($sql);
  432. $res = Database::query($sql);
  433. if ($debug) var_dump($res);
  434. }
  435. }
  436. if ($update_database) {
  437. echo '<h2>'.get_lang('StatsMoved').'</h2>';
  438. if (is_array($result_message))
  439. foreach ($result_message as $table=>$times) {
  440. echo 'Table '.$table.' - '.$times.' records updated <br />';
  441. }
  442. } else {
  443. echo '<h2>'.get_lang('UserInformationOfThisCourse').'</h2>';
  444. echo '<br />';
  445. echo '<table width="100%">';
  446. echo '<tr>';
  447. echo '<td width="50%" valign="top">';
  448. if ($origin_session_id == 0) {
  449. echo '<h4>'.get_lang('OriginCourse').'</h4>';
  450. } else {
  451. echo '<h4>'.get_lang('OriginSession').' #'.$origin_session_id.'</h4>';
  452. }
  453. compare_data($result_message);
  454. echo '</td>';
  455. echo '<td width="50%" valign="top">';
  456. if ($new_session_id == 0) {
  457. echo '<h4>'.get_lang('DestinyCourse').'</h4>';
  458. } else {
  459. echo '<h4>'.get_lang('DestinySession').' #'.$new_session_id.'</h4>';
  460. }
  461. compare_data($result_message_compare);
  462. echo '</td>';
  463. echo '</tr>';
  464. echo '</table>';
  465. }
  466. } else {
  467. echo get_lang('CourseDoesNotExistInThisSession');
  468. }
  469. }
  470. } else {
  471. echo get_lang('ThereWasAnError');
  472. }
  473. exit;
  474. }
  475. $htmlHeadXtra[] = '<script type="text/javascript">
  476. function moveto (unique_id, user_id) {
  477. var session_id = document.getElementById(unique_id).options[document.getElementById(unique_id).selectedIndex].value;
  478. $.ajax({
  479. contentType: "application/x-www-form-urlencoded",
  480. beforeSend: function(objeto) {
  481. $("div#reponse_"+unique_id).html("<img src=\'../inc/lib/javascript/indicator.gif\' />"); },
  482. type: "POST",
  483. url: "user_move_stats.php",
  484. data: "load_ajax=1"+"&unique_id="+unique_id+"&user_id="+user_id+"&session_id="+session_id,
  485. success: function(datos) {
  486. $("div#reponse_"+unique_id).html(datos);
  487. }
  488. });
  489. }
  490. function view_stat (unique_id, user_id) {
  491. var session_id = document.getElementById(unique_id).options[document.getElementById(unique_id).selectedIndex].value;
  492. $.ajax({
  493. contentType: "application/x-www-form-urlencoded",
  494. beforeSend: function(objeto) {
  495. $("div#reponse_"+unique_id).html("<img src=\'../inc/lib/javascript/indicator.gif\' />"); },
  496. type: "POST",
  497. url: "user_move_stats.php",
  498. data: "load_ajax=1&view_stat=1"+"&unique_id="+unique_id+"&user_id="+user_id+"&session_id="+session_id,
  499. success: function(datos) {
  500. $("div#reponse_"+unique_id).html(datos);
  501. }
  502. });
  503. }
  504. </script>';
  505. function get_courses_list_by_user_id_based_in_exercises($user_id) {
  506. $TABLETRACK_EXERCICES = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
  507. $user_id = intval($user_id);
  508. $sql = "SELECT DISTINCT exe_user_id, c_id, session_id
  509. FROM $TABLETRACK_EXERCICES
  510. WHERE exe_user_id = $user_id
  511. ORDER by exe_user_id, c_id ASC";
  512. $res = Database::query($sql);
  513. $course_list = array();
  514. while ($row = Database::fetch_array($res, 'ASSOC')) {
  515. $course_list [] = $row;
  516. }
  517. return $course_list;
  518. }
  519. Display::addFlash(Display::return_message(get_lang('CompareUserResultsBetweenCoursesAndCoursesInASession'), 'normal', false));
  520. Display::display_header(get_lang('MoveUserStats'));
  521. echo '<div class="actions">';
  522. echo '<a href="../admin/index.php">'.Display::return_icon('back.png', get_lang('BackTo').' '.get_lang('PlatformAdmin'), '', ICON_SIZE_MEDIUM).'</a>';
  523. echo '</div>';
  524. // Some pagination
  525. $page = 1;
  526. if (isset($_GET['page']) && !empty($_GET['page'])) {
  527. $page = intval($_GET['page']);
  528. }
  529. $default = 20;
  530. $count = UserManager::get_number_of_users();
  531. $nro_pages = round($count / $default) + 1;
  532. $begin = $default * ($page - 1);
  533. $end = $default * $page;
  534. $navigation = "$begin - $end / $count<br />";
  535. if ($page > 1) {
  536. $navigation .= '<a href="'.api_get_self().'?page='.($page - 1).'">'.get_lang('Previous').'</a>';
  537. } else {
  538. $navigation .= get_lang('Previous');
  539. }
  540. $navigation .= '&nbsp;';
  541. $page++;
  542. if ($page < $nro_pages)
  543. $navigation .= '<a href="'.api_get_self().'?page='.$page.'">'.get_lang('Next').'</a>';
  544. else
  545. $navigation .= get_lang('Next');
  546. echo $navigation;
  547. $user_list = UserManager::get_user_list(array(), array(), $begin, $default);
  548. $session_list = SessionManager::get_sessions_list(array(), array('name'));
  549. $options = '';
  550. $options .= '<option value="0">--'.get_lang('SelectASession').'--</option>';
  551. foreach ($session_list as $session_data) {
  552. $my_session_list[$session_data['id']] = $session_data['name'];
  553. $options .= '<option value="'.$session_data['id'].'">'.$session_data['name'].'</option>';
  554. }
  555. $combinations = array();
  556. if (!empty($user_list)) {
  557. foreach ($user_list as $user) {
  558. $user_id = $user['user_id'];
  559. $name = $user['firstname'].' '.$user['lastname'];
  560. $course_list_registered = CourseManager::get_courses_list_by_user_id(
  561. $user_id,
  562. true,
  563. false
  564. );
  565. $new_course_list = array();
  566. foreach ($course_list_registered as $course_reg) {
  567. if (empty($course_reg['session_id'])) {
  568. $course_reg['session_id'] = 0;
  569. }
  570. // Recover the code for historical reasons. If it can be proven
  571. // that the code can be safely replaced by c_id in the following
  572. // PHP code, feel free to do so
  573. $courseInfo = api_get_course_info_by_id($course_reg['real_id']);
  574. $course_reg['code'] = $courseInfo['code'];
  575. $new_course_list[] = $course_reg['code'].'_'.$course_reg['session_id'];
  576. }
  577. $course_list = get_courses_list_by_user_id_based_in_exercises($user_id);
  578. if (is_array($course_list) && !empty($course_list)) {
  579. foreach ($course_list as $my_course) {
  580. $courseInfo = api_get_course_info_by_id($my_course['c_id']);
  581. $my_course['real_id'] = $my_course['c_id'];
  582. $key = $courseInfo['code'].'_'.$my_course['session_id'];
  583. if (!in_array($key, $new_course_list)) {
  584. $my_course['not_registered'] = 1;
  585. $course_list_registered[] = $my_course;
  586. }
  587. }
  588. }
  589. foreach ($course_list_registered as & $course) {
  590. $courseInfo = api_get_course_info_by_id($course['real_id']);
  591. $course['name'] = $courseInfo['name'];
  592. }
  593. $course_list = $course_list_registered;
  594. echo '<div>';
  595. echo '<table class="data_table">';
  596. echo '<tr>';
  597. echo '<th style="text-align:left;" colspan="'.count($course_list).'">';
  598. echo "<h3>$name #$user_id </h3> ";
  599. echo '</th>';
  600. echo '</tr>';
  601. if (!empty($course_list)) {
  602. echo '<tr>';
  603. foreach ($course_list as $course) {
  604. echo '<td>';
  605. if (isset($course['id_session']) && !empty($course['id_session'])) {
  606. echo '<b>'.get_lang('SessionName').'</b> '.$my_session_list[$course['id_session']].'<br />';
  607. }
  608. echo $course['name'];
  609. echo ' ('.$course['code'].') ';
  610. if (isset($course['not_registered']) && !empty($course['not_registered'])) {
  611. echo ' <i>'.get_lang('UserNotRegistered').'</i>';
  612. }
  613. echo '</td>';
  614. }
  615. echo '</tr>';
  616. echo '<tr>';
  617. foreach ($course_list as $course) {
  618. $course_code = $course['code'];
  619. if (empty($course['id_session'])) {
  620. $session_id = 0;
  621. } else {
  622. $session_id = $course['id_session'];
  623. }
  624. echo '<td>';
  625. echo get_lang('MoveTo'); echo '<br />';
  626. $unique_id = uniqid();
  627. $combinations[$unique_id] = array('course_code' =>$course_code, 'session_id'=>$session_id);
  628. echo '<select id="'.$unique_id.'" name="'.$unique_id.'">';
  629. echo $options;
  630. echo '</select>';
  631. echo '<br />';
  632. echo '<button type="submit" class="btn btn-success" onclick="view_stat(\''.$unique_id.'\', \''.$user_id.'\');"> '.get_lang('CompareStats').'</button>';
  633. echo '<button type="submit" class="btn btn-success" onclick="moveto(\''.$unique_id.'\', \''.$user_id.'\');"> '.get_lang('Move').'</button>';
  634. echo '<div id ="reponse_'.$unique_id.'"></div>';
  635. echo '</td>';
  636. }
  637. echo '</tr>';
  638. } else {
  639. echo '<td>';
  640. echo get_lang('NoCoursesForThisUser');
  641. echo '</td>';
  642. }
  643. echo '</table>';
  644. echo '</div>';
  645. }
  646. }
  647. echo $navigation;
  648. $_SESSION['combination'] = $combinations;