user_move_stats.php 35 KB

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