user_move_stats.php 40 KB

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