user_move_stats.php 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use Chamilo\CoreBundle\Framework\Container;
  4. /**
  5. * User move script (to move between courses and sessions)
  6. * @package chamilo.admin
  7. */
  8. $cidReset = true;
  9. $this_section = SECTION_PLATFORM_ADMIN;
  10. api_protect_admin_script();
  11. $interbreadcrumb[] = array ('url' => Container::getRouter()->generate('administration') , "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. // add the directory
  329. $id = $publication->getIid();
  330. //Folder created
  331. api_item_property_update($course_info, 'work', $id, 'DirectoryCreated', api_get_user_id());
  332. $new_parent_id = $id;
  333. $result_message[$TBL_STUDENT_PUBLICATION.' - new folder created called: '.$created_dir]++;
  334. }
  335. }
  336. //Creating student_publication_assignment if exists
  337. $sql = "SELECT * FROM $TBL_STUDENT_PUBLICATION_ASSIGNMENT WHERE publication_id = $parent_id AND c_id = $course_id";
  338. if ($debug) var_dump($sql);
  339. $rest_select = Database::query($sql);
  340. if (Database::num_rows($rest_select) > 0 ) {
  341. if ($update_database) {
  342. $assignment_data = Database::fetch_array($rest_select,'ASSOC');
  343. $sql_add_publication = "INSERT INTO " . $TBL_STUDENT_PUBLICATION_ASSIGNMENT . " SET
  344. c_id = '$course_id',
  345. expires_on = '".$assignment_data['expires_on']."',
  346. ends_on = '".$assignment_data['ends_on']."',
  347. add_to_calendar = '".$assignment_data['add_to_calendar']."',
  348. enable_qualification = '".$assignment_data['enable_qualification']."',
  349. publication_id = '".$new_parent_id."'";
  350. if ($debug) echo $sql_add_publication;
  351. $rest_select = Database::query($sql_add_publication);
  352. $id = Database::insert_id();
  353. $sql_update = "UPDATE " . $TBL_STUDENT_PUBLICATION . " SET " .
  354. "has_properties = '".$id."',
  355. view_properties = '1'
  356. WHERE id = ".$new_parent_id;
  357. if ($debug) echo $sql_update;
  358. $rest_update = Database::query($sql_update);
  359. if ($debug) var_dump($sql_update);
  360. $result_message[$TBL_STUDENT_PUBLICATION_ASSIGNMENT]++;
  361. }
  362. }
  363. $doc_url = $data['url'];
  364. $new_url = str_replace($parent_data['url'], $created_dir, $doc_url);
  365. if ($update_database) {
  366. //Creating a new work
  367. $data['sent_date'] = new DateTime($data['sent_date'], new DateTimeZone('UTC'));
  368. $publication = new \Chamilo\CourseBundle\Entity\CStudentPublication();
  369. $publication
  370. ->setUrl($new_url)
  371. ->setCId($course_id)
  372. ->setTitle($data['title'])
  373. ->setDescription($data['description'] . ' file moved')
  374. ->setActive($data['active'])
  375. ->setAccepted($data['accepted'])
  376. ->setPostGroupId($data['post_group_id'])
  377. ->setSentDate($data['sent_date'])
  378. ->setParentId($new_parent_id)
  379. ->setSession($session);
  380. $em->persist($publication);
  381. $em->flush();
  382. $id = $publication->getIid();
  383. api_item_property_update($course_info, 'work', $id, 'DocumentAdded', $user_id);
  384. $result_message[$TBL_STUDENT_PUBLICATION]++;
  385. $full_file_name = $course_dir.'/'.$doc_url;
  386. $new_file = $course_dir.'/'.$new_url;
  387. if (file_exists($full_file_name)) {
  388. //deleting old assignment
  389. $result = copy($full_file_name, $new_file);
  390. if ($result) {
  391. unlink($full_file_name);
  392. $sql = "DELETE FROM $TBL_STUDENT_PUBLICATION WHERE id= ".$data['id'];
  393. if ($debug) var_dump($sql);
  394. $result_delete = Database::query($sql);
  395. api_item_property_update($course_info, 'work', $data['id'], 'DocumentDeleted', api_get_user_id());
  396. }
  397. }
  398. }
  399. }
  400. }
  401. }
  402. //9. Survey Pending
  403. //10. Dropbox - not neccesary to move categories (no presence of session_id)
  404. $sql = "SELECT id FROM $TBL_DROPBOX_FILE WHERE uploader_id = $user_id AND session_id = $origin_session_id AND c_id = $course_id";
  405. if ($debug) var_dump($sql);
  406. $res = Database::query($sql);
  407. while($row = Database::fetch_array($res,'ASSOC')) {
  408. $id = $row['id'];
  409. if ($update_database) {
  410. $sql = "UPDATE $TBL_DROPBOX_FILE SET session_id = $new_session_id WHERE c_id = $course_id AND id = $id";
  411. if ($debug) var_dump($sql);
  412. $res = Database::query($sql);
  413. if ($debug) var_dump($res);
  414. $sql = "UPDATE $TBL_DROPBOX_POST SET session_id = $new_session_id WHERE file_id = $id";
  415. if ($debug)
  416. var_dump($sql);
  417. $res = Database::query($sql);
  418. if ($debug)
  419. var_dump($res);
  420. $result_message[$TBL_DROPBOX_FILE]++;
  421. }
  422. }
  423. //11. Notebook
  424. $sql = "SELECT notebook_id FROM $TBL_NOTEBOOK
  425. WHERE user_id = $user_id AND session_id = $origin_session_id AND course = '$origin_course_code' AND c_id = $course_id";
  426. if ($debug) var_dump($sql);
  427. $res = Database::query($sql);
  428. while($row = Database::fetch_array($res,'ASSOC')) {
  429. $id = $row['notebook_id'];
  430. if ($update_database) {
  431. $sql = "UPDATE $TBL_NOTEBOOK SET session_id = $new_session_id WHERE c_id = $course_id AND notebook_id = $id";
  432. if ($debug) var_dump($sql);
  433. $res = Database::query($sql);
  434. if ($debug) var_dump($res);
  435. }
  436. }
  437. if ($update_database) {
  438. echo '<h2>'.get_lang('StatsMoved').'</h2>';
  439. if (is_array($result_message))
  440. foreach ($result_message as $table=>$times) {
  441. echo 'Table '.$table.' - '.$times.' records updated <br />';
  442. }
  443. } else {
  444. echo '<h2>'.get_lang('UserInformationOfThisCourse').'</h2>';
  445. echo '<br />';
  446. echo '<table width="100%">';
  447. echo '<tr>';
  448. echo '<td width="50%" valign="top">';
  449. if ($origin_session_id == 0 ) {
  450. echo '<h4>'.get_lang('OriginCourse').'</h4>';
  451. } else {
  452. echo '<h4>'.get_lang('OriginSession').' #'.$origin_session_id.'</h4>';
  453. }
  454. compare_data($result_message);
  455. echo '</td>';
  456. echo '<td width="50%" valign="top">';
  457. if ($new_session_id == 0 ) {
  458. echo '<h4>'.get_lang('DestinyCourse').'</h4>';
  459. } else {
  460. echo '<h4>'.get_lang('DestinySession').' #'.$new_session_id.'</h4>';
  461. }
  462. compare_data($result_message_compare);
  463. echo '</td>';
  464. echo '</tr>';
  465. echo '</table>';
  466. }
  467. } else {
  468. echo get_lang('CourseDoesNotExistInThisSession');
  469. }
  470. }
  471. } else {
  472. echo get_lang('ThereWasAnError');
  473. }
  474. exit;
  475. }
  476. $htmlHeadXtra[] = '<script type="text/javascript">
  477. function moveto (unique_id, user_id) {
  478. var session_id = document.getElementById(unique_id).options[document.getElementById(unique_id).selectedIndex].value;
  479. $.ajax({
  480. contentType: "application/x-www-form-urlencoded",
  481. beforeSend: function(objeto) {
  482. $("div#reponse_"+unique_id).html("<img src=\'../inc/lib/javascript/indicator.gif\' />"); },
  483. type: "POST",
  484. url: "user_move_stats.php",
  485. data: "load_ajax=1"+"&unique_id="+unique_id+"&user_id="+user_id+"&session_id="+session_id,
  486. success: function(datos) {
  487. $("div#reponse_"+unique_id).html(datos);
  488. }
  489. });
  490. }
  491. function view_stat (unique_id, user_id) {
  492. var session_id = document.getElementById(unique_id).options[document.getElementById(unique_id).selectedIndex].value;
  493. $.ajax({
  494. contentType: "application/x-www-form-urlencoded",
  495. beforeSend: function(objeto) {
  496. $("div#reponse_"+unique_id).html("<img src=\'../inc/lib/javascript/indicator.gif\' />"); },
  497. type: "POST",
  498. url: "user_move_stats.php",
  499. data: "load_ajax=1&view_stat=1"+"&unique_id="+unique_id+"&user_id="+user_id+"&session_id="+session_id,
  500. success: function(datos) {
  501. $("div#reponse_"+unique_id).html(datos);
  502. }
  503. });
  504. }
  505. </script>';
  506. function get_courses_list_by_user_id_based_in_exercises($user_id) {
  507. $TABLETRACK_EXERCICES = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
  508. $user_id = intval($user_id);
  509. $sql = "SELECT DISTINCT exe_user_id, c_id, session_id
  510. FROM $TABLETRACK_EXERCICES
  511. WHERE exe_user_id = $user_id
  512. ORDER by exe_user_id, c_id ASC";
  513. $res = Database::query($sql);
  514. $course_list = array();
  515. while ($row = Database::fetch_array($res,'ASSOC')) {
  516. $course_list []= $row;
  517. }
  518. return $course_list;
  519. }
  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. echo Display::display_normal_message(get_lang('CompareUserResultsBetweenCoursesAndCoursesInASession'),false);
  525. // Some pagination
  526. $page = 1;
  527. if (isset($_GET['page']) && !empty($_GET['page'])) {
  528. $page = intval($_GET['page']);
  529. }
  530. $default = 20;
  531. $count = UserManager::get_number_of_users();
  532. $nro_pages = round($count/$default) + 1;
  533. $begin = $default* ($page - 1);
  534. $end = $default*$page;
  535. $navigation = "$begin - $end / $count<br />";
  536. if ($page > 1) {
  537. $navigation .='<a href="'.api_get_self().'?page='.($page - 1).'">'.get_lang('Previous').'</a>';
  538. } else {
  539. $navigation .= get_lang('Previous');
  540. }
  541. $navigation .= '&nbsp;';
  542. $page ++;
  543. if ($page < $nro_pages)
  544. $navigation .= '<a href="'.api_get_self().'?page='.$page.'">'.get_lang('Next').'</a>';
  545. else
  546. $navigation .= get_lang('Next');
  547. echo $navigation;
  548. $user_list = UserManager::get_user_list(array(), array(), $begin, $default);
  549. $session_list = SessionManager::get_sessions_list(array(),array('name'));
  550. $options = '';
  551. $options .= '<option value="0">--'.get_lang('SelectASession').'--</option>';
  552. foreach ($session_list as $session_data) {
  553. $my_session_list[$session_data['id']] =$session_data['name'];
  554. $options .= '<option value="'.$session_data['id'].'">'.$session_data['name'].'</option>';
  555. }
  556. $combinations = array();
  557. if (!empty($user_list)) {
  558. foreach ($user_list as $user) {
  559. $user_id = $user['user_id'];
  560. $name = $user['firstname'].' '.$user['lastname'];
  561. $course_list_registered = CourseManager::get_courses_list_by_user_id(
  562. $user_id,
  563. true,
  564. false
  565. );
  566. $new_course_list = array();
  567. foreach ($course_list_registered as $course_reg) {
  568. if (empty($course_reg['session_id'])) {
  569. $course_reg['session_id'] = 0;
  570. }
  571. // Recover the code for historical reasons. If it can be proven
  572. // that the code can be safely replaced by c_id in the following
  573. // PHP code, feel free to do so
  574. $courseInfo = api_get_course_info_by_id($course_reg['real_id']);
  575. $course_reg['code'] = $courseInfo['code'];
  576. $new_course_list[] = $course_reg['code'].'_'.$course_reg['session_id'];
  577. }
  578. $course_list = get_courses_list_by_user_id_based_in_exercises($user_id);
  579. if (is_array($course_list) && !empty($course_list)) {
  580. foreach ($course_list as $my_course) {
  581. $courseInfo = api_get_course_info_by_id($my_course['c_id']);
  582. $my_course['real_id'] = $my_course['c_id'];
  583. $key = $courseInfo['code'].'_'.$my_course['session_id'];
  584. if (!in_array($key, $new_course_list)) {
  585. $my_course['not_registered'] = 1;
  586. $course_list_registered[] = $my_course;
  587. }
  588. }
  589. }
  590. foreach ($course_list_registered as & $course) {
  591. $courseInfo = api_get_course_info_by_id($course['real_id']);
  592. $course['name'] = $courseInfo['name'];
  593. }
  594. $course_list = $course_list_registered;
  595. echo '<div>';
  596. echo '<table class="data_table">';
  597. echo '<tr>';
  598. echo '<th style="text-align:left;" colspan="'.count($course_list).'">';
  599. echo "<h3>$name #$user_id </h3> ";
  600. echo '</th>';
  601. echo '</tr>';
  602. if (!empty($course_list)) {
  603. echo '<tr>';
  604. foreach ($course_list as $course) {
  605. echo '<td>';
  606. if (isset($course['id_session']) && !empty($course['id_session'])) {
  607. echo '<b>'.get_lang('SessionName').'</b> '.$my_session_list[$course['id_session']].'<br />';
  608. }
  609. echo $course['name'];
  610. echo ' ('.$course['code'].') ';
  611. if (isset($course['not_registered']) && !empty($course['not_registered'])) {
  612. echo ' <i>'.get_lang('UserNotRegistered').'</i>';
  613. }
  614. echo '</td>';
  615. }
  616. echo '</tr>';
  617. echo '<tr>';
  618. foreach ($course_list as $course) {
  619. $course_code = $course['code'];
  620. if (empty($course['id_session'])) {
  621. $session_id = 0;
  622. } else {
  623. $session_id = $course['id_session'];
  624. }
  625. echo '<td>';
  626. echo get_lang('MoveTo'); echo '<br />';
  627. $unique_id = uniqid();
  628. $combinations[$unique_id] = array('course_code' =>$course_code, 'session_id'=>$session_id);
  629. echo '<select id="'.$unique_id.'" name="'.$unique_id.'">';
  630. echo $options;
  631. echo '</select>';
  632. echo '<br />';
  633. echo '<button type="submit" class="btn btn-success" onclick="view_stat(\''.$unique_id.'\', \''.$user_id.'\');"> '.get_lang('CompareStats').'</button>';
  634. echo '<button type="submit" class="btn btn-success" onclick="moveto(\''.$unique_id.'\', \''.$user_id.'\');"> '.get_lang('Move').'</button>';
  635. echo '<div id ="reponse_'.$unique_id.'"></div>';
  636. echo '</td>';
  637. }
  638. echo '</tr>';
  639. } else {
  640. echo '<td>';
  641. echo get_lang('NoCoursesForThisUser');
  642. echo '</td>';
  643. }
  644. echo '</table>';
  645. echo '</div>';
  646. }
  647. }
  648. echo $navigation;
  649. $_SESSION['combination'] = $combinations;