user_move_stats.php 40 KB

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