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 api_get_path(LIBRARY_PATH).'course.lib.php';
  8. require_once api_get_path(LIBRARY_PATH).'tracking.lib.php';
  9. require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php';
  10. require_once api_get_path(LIBRARY_PATH).'sessionmanager.lib.php';
  11. require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
  12. require_once '../newscorm/learnpathList.class.php';
  13. $interbreadcrumb[] = array ("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
  14. $debug = 0;
  15. function compare_data($result_message) {
  16. foreach ($result_message as $table=>$data) {
  17. $title = $table;
  18. if ($table == 'TRACK_E_EXERCISES') {
  19. $title = get_lang('Exercises');
  20. } elseif ($table == 'TRACK_E_EXERCISES_IN_LP') {
  21. $title = get_lang('ExercisesInLp');
  22. } elseif ($table == 'LP_VIEW') {
  23. $title = get_lang('LearningPath');
  24. }
  25. echo '<br / ><h2>'.get_lang($title).' </h2><hr />';
  26. if (is_array($data)) {
  27. foreach ($data as $id => $item) {
  28. if ($table == 'TRACK_E_EXERCISES' || $table == 'TRACK_E_EXERCISES_IN_LP' ) {
  29. echo "<br /><h3>".get_lang('Attempt')." #$id</h3>";
  30. echo '<h3>';
  31. echo get_lang('Exercise').' #'.$item['exe_exo_id'];
  32. echo '</h3>';
  33. if (!empty($item['orig_lp_id'])) {
  34. echo '<h3>';
  35. echo get_lang('LearningPath').' #'.$item['orig_lp_id'];
  36. echo '</h3>';
  37. }
  38. //Process data
  39. $array = array('exe_date' =>get_lang('Date'), 'exe_result' =>get_lang('Score'),'exe_weighting'=>get_lang('Weighting'));
  40. foreach($item as $key=> $value) {
  41. if (in_array($key,array_keys($array))) {
  42. $key = $array[$key];
  43. echo "$key = $value <br />";
  44. }
  45. }
  46. } else {
  47. echo "<br /><h3>".get_lang('Id')." #$id</h3>";
  48. //process data
  49. foreach($item as $key=> $value) {
  50. echo "$key = $value <br />";
  51. }
  52. }
  53. }
  54. } else {
  55. echo get_lang('NoResults');
  56. }
  57. }
  58. }
  59. if (isset($_REQUEST['load_ajax'])) {
  60. //Checking the variable $_SESSION['combination'] that has all the information of the selected course (instead of using a lots of hidden variables ... )
  61. if (isset($_SESSION['combination']) && !empty($_SESSION['combination'])) {
  62. $combinations = $_SESSION['combination'];
  63. $combination_result = $combinations[$_REQUEST['unique_id']];
  64. if (empty($combination_result)) {
  65. echo get_lang('ThereWasAnError');
  66. } else {
  67. $origin_course_code = $combination_result['course_code'];
  68. $origin_session_id = intval($combination_result['session_id']);
  69. $new_session_id = intval($_REQUEST['session_id']);
  70. //if (!isset($_REQUEST['view_stat'])) {
  71. if ($origin_session_id == $new_session_id ) {
  72. echo get_lang('CantMoveToTheSameSession');
  73. exit;
  74. }
  75. //}
  76. $user_id = intval($_REQUEST['user_id']);
  77. $new_course_list = SessionManager::get_course_list_by_session_id($new_session_id);
  78. $result_message = array();
  79. $result_message_compare = array();
  80. $view_stat = false;
  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 (isset($new_course_list[$origin_course_code])) {
  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. $TABLETRACK_EXERCICES = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  97. $TBL_TRACK_ATTEMPT = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
  98. $TBL_TRACK_E_COURSE_ACCESS = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
  99. $TBL_TRACK_E_LAST_ACCESS = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_LASTACCESS);
  100. $TBL_LP_VIEW = Database::get_course_table(TABLE_LP_VIEW, $course_info['dbName']);
  101. $TBL_NOTEBOOK = Database::get_course_table(TABLE_NOTEBOOK, $course_info['dbName']);
  102. $TBL_STUDENT_PUBLICATION = Database::get_course_table(TABLE_STUDENT_PUBLICATION, $course_info['dbName']);
  103. $TBL_STUDENT_PUBLICATION_ASSIGNMENT = Database::get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT, $course_info['dbName']);
  104. $TBL_ITEM_PROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY, $course_info['dbName']);
  105. $TBL_DROPBOX_FILE = Database::get_course_table(TABLE_DROPBOX_FILE, $course_info['dbName']);
  106. $TBL_DROPBOX_POST = Database::get_course_table(TABLE_DROPBOX_POST, $course_info['dbName']);
  107. $TBL_AGENDA = Database::get_course_table(TABLE_AGENDA, $course_info['dbName']);
  108. //$TBL_DROPBOX_CATEGORY = Database::get_course_table(TABLE_DROPBOX_CATEGORY, $course_info['dbName']);
  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 ";
  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 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 ";
  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";
  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 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";
  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 ";
  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";
  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 WHERE description like '%$search_this%' AND url LIKE '%$search_this2%' AND session_id = $new_session_id ORDER BY id desc LIMIT 1";
  287. if ($debug) echo $sql;
  288. $sub_res = Database::query($sql);
  289. $num_rows = Database::num_rows($sub_res);
  290. if ($num_rows > 0 ) {
  291. $new_result = Database::fetch_array($sub_res,'ASSOC');
  292. $created_dir = $new_result['url'];
  293. $new_parent_id = $new_result['id'];
  294. } else {
  295. if ($update_database) {
  296. $dir_name = substr($parent_data['url'], 1);
  297. $created_dir = create_unexisting_work_directory($base_work_dir, $dir_name);
  298. $created_dir = '/'.$created_dir;
  299. $now = api_get_utc_datetime();
  300. //Creating directory
  301. $sql_add_publication = "INSERT INTO " . $TBL_STUDENT_PUBLICATION . " SET " .
  302. "url = '".$created_dir."',
  303. title = '".$parent_data['title']."',
  304. description = '".$parent_data['description']." folder_moved_from_session_id_$origin_session_id ',
  305. author = '',
  306. active = '0',
  307. accepted = '1',
  308. filetype = 'folder',
  309. sent_date = '".$now."',
  310. qualification = '".$parent_data['qualification'] ."',
  311. parent_id = '',
  312. qualificator_id = '',
  313. date_of_qualification = '0000-00-00 00:00:00',
  314. session_id = ".$new_session_id;
  315. $rest_insert = Database::query($sql_add_publication);
  316. if ($debug) echo ($sql_add_publication);
  317. // add the directory
  318. $id = Database::insert_id();
  319. //Folder created
  320. api_item_property_update($course_info, 'work', $id, 'DirectoryCreated', api_get_user_id());
  321. if ($debug) var_dump($rest_insert);
  322. $new_parent_id = $id;
  323. $result_message[$TBL_STUDENT_PUBLICATION.' - new folder created called: '.$created_dir]++;
  324. }
  325. }
  326. //Creating student_publication_assignment if exists
  327. $sql = "SELECT * FROM $TBL_STUDENT_PUBLICATION_ASSIGNMENT WHERE publication_id = $parent_id";
  328. if ($debug) var_dump($sql);
  329. $rest_select = Database::query($sql);
  330. if (Database::num_rows($rest_select) > 0 ) {
  331. if ($update_database) {
  332. $assignment_data = Database::fetch_array($rest_select,'ASSOC');
  333. $sql_add_publication = "INSERT INTO " . $TBL_STUDENT_PUBLICATION_ASSIGNMENT . " SET " .
  334. "expires_on = '".$assignment_data['expires_on']."',
  335. ends_on = '".$assignment_data['ends_on']."',
  336. add_to_calendar = '".$assignment_data['add_to_calendar']."',
  337. enable_qualification = '".$assignment_data['enable_qualification']."',
  338. publication_id = '".$new_parent_id."'";
  339. if ($debug) echo $sql_add_publication;
  340. $rest_select = Database::query($sql_add_publication);
  341. $id = Database::insert_id();
  342. $sql_update = "UPDATE " . $TBL_STUDENT_PUBLICATION . " SET " .
  343. "has_properties = '".$id."',
  344. view_properties = '1'
  345. WHERE id = ".$new_parent_id;
  346. if ($debug) echo $sql_update;
  347. $rest_update = Database::query($sql_update);
  348. if ($debug) var_dump($sql_update);
  349. $result_message[$TBL_STUDENT_PUBLICATION_ASSIGNMENT]++;
  350. }
  351. }
  352. $doc_url = $data['url'];
  353. $new_url = str_replace($parent_data['url'], $created_dir, $doc_url);
  354. if ($update_database) {
  355. //Creating a new work
  356. $sql_add_publication = "INSERT INTO " . $TBL_STUDENT_PUBLICATION . " SET " .
  357. "url = '" . $new_url . "',
  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 ";
  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 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 WHERE user_id = $user_id AND session_id = $origin_session_id AND course = '$origin_course_code' ";
  411. if ($debug) var_dump($sql);
  412. $res = Database::query($sql);
  413. while($row = Database::fetch_array($res,'ASSOC')) {
  414. $id = $row['notebook_id'];
  415. if ($update_database) {
  416. $sql = "UPDATE $TBL_NOTEBOOK SET session_id = '$new_session_id' WHERE notebook_id = $id";
  417. if ($debug) var_dump($sql);
  418. $res = Database::query($sql);
  419. if ($debug) var_dump($res);
  420. }
  421. }
  422. if ($update_database) {
  423. echo '<h2>'.get_lang('StatsMoved').'</h2>';
  424. if (is_array($result_message))
  425. foreach ($result_message as $table=>$times) {
  426. echo 'Table '.$table.' - '.$times.' records updated <br />';
  427. }
  428. } else {
  429. echo '<h1>'.get_lang('UserInformationOfThisCourse').'</h1>';
  430. //var_dump($result_message);
  431. echo '<br />';
  432. echo '<table width="100%">';
  433. echo '<tr>';
  434. echo '<td width="50%" valign="top">';
  435. if ($origin_session_id == 0 ) {
  436. echo '<h1>'.get_lang('OriginCourse').'</h1>';
  437. } else {
  438. echo '<h1>'.get_lang('OriginSession').' #'.$origin_session_id.'</h1>';
  439. }
  440. compare_data($result_message);
  441. echo '</td>';
  442. echo '<td width="50%" valign="top">';
  443. if ($new_session_id == 0 ) {
  444. echo '<h1>'.get_lang('DestinyCourse').'</h1>';
  445. } else {
  446. echo '<h1>'.get_lang('DestinySession').' #'.$new_session_id.'</h1>';
  447. }
  448. compare_data($result_message_compare);
  449. echo '</td>';
  450. echo '</tr>';
  451. echo '</table>';
  452. }
  453. } else {
  454. echo get_lang('CourseDoesNotExistInThisSession');
  455. }
  456. }
  457. } else {
  458. echo get_lang('ThereWasAnError');
  459. }
  460. exit;
  461. }
  462. $htmlHeadXtra[] = '<script type="text/javascript">
  463. function moveto (unique_id, user_id) {
  464. var session_id = document.getElementById(unique_id).options[document.getElementById(unique_id).selectedIndex].value;
  465. $.ajax({
  466. contentType: "application/x-www-form-urlencoded",
  467. beforeSend: function(objeto) {
  468. $("div#reponse_"+unique_id).html("<img src=\'../inc/lib/javascript/indicator.gif\' />"); },
  469. type: "POST",
  470. url: "user_move_stats.php",
  471. data: "load_ajax=1"+"&unique_id="+unique_id+"&user_id="+user_id+"&session_id="+session_id,
  472. success: function(datos) {
  473. $("div#reponse_"+unique_id).html(datos);
  474. }
  475. });
  476. }
  477. function view_stat (unique_id, user_id) {
  478. var session_id = document.getElementById(unique_id).options[document.getElementById(unique_id).selectedIndex].value;
  479. load_thick("user_move_stats.php?load_ajax=1&view_stat=1"+"&unique_id="+unique_id+"&user_id="+user_id+"&session_id="+session_id,"");
  480. /*
  481. $.ajax({
  482. contentType: "application/x-www-form-urlencoded",
  483. beforeSend: function(objeto) {
  484. $("div#reponse_"+unique_id).html("<img src=\'../inc/lib/javascript/indicator.gif\' />"); },
  485. type: "POST",
  486. url: "user_move_stats.php",
  487. data: "load_ajax=1&view_stat=1"+"&unique_id="+unique_id+"&user_id="+user_id+"&session_id="+session_id,
  488. success: function(datos) {
  489. $("div#reponse_"+unique_id).html(datos);
  490. }
  491. });*/
  492. }
  493. </script>';
  494. function get_courses_list_by_user_id_based_in_exercises($user_id) {
  495. $TABLETRACK_EXERCICES = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  496. $user_id = intval($user_id);
  497. //$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";
  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 ORDER by exe_user_id, exe_cours_id ASC";
  499. $res = Database::query($sql);
  500. $course_list = array();
  501. while($row = Database::fetch_array($res,'ASSOC')) {
  502. $course_list []= $row;
  503. }
  504. return $course_list;
  505. }
  506. Display::display_header(get_lang('MoveUserStats'));
  507. echo '<div class="actions">';
  508. echo '<a href="../admin/index.php">'.Display::return_icon('back.png', get_lang('BackTo').' '.get_lang('PlatformAdmin'),'','32').'</a>';
  509. echo '</div>';
  510. echo Display::display_normal_message(get_lang('CompareUserResultsBetweenCoursesAndCoursesInASession'),false);
  511. // Some pagination
  512. $page = 1;
  513. if (isset($_GET['page']) && !empty($_GET['page'])) {
  514. $page = intval($_GET['page']);
  515. }
  516. $default = 20;
  517. $count = UserManager::get_number_of_users();
  518. $nro_pages = round($count/$default) + 1;
  519. $begin = $default* ($page - 1);
  520. $end = $default*$page;
  521. $navigation = "$begin - $end / $count<br />";
  522. if ($page > 1) {
  523. $navigation .='<a href="'.api_get_self().'?page='.($page - 1).'">'.get_lang('Previous').'</a>';
  524. } else {
  525. $navigation .= get_lang('Previous');
  526. }
  527. $navigation .= '&nbsp;';
  528. $page ++;
  529. if ($page < $nro_pages)
  530. $navigation .= '<a href="'.api_get_self().'?page='.$page.'">'.get_lang('Next').'</a>';
  531. else
  532. $navigation .= get_lang('Next');
  533. echo $navigation;
  534. $user_list = UserManager::get_user_list(array(), array(), $begin, $default);
  535. $session_list = SessionManager::get_sessions_list(array(),array('name'));
  536. $options = '';
  537. $options .= '<option value="0">--'.get_lang('SelectASession').'--</option>';
  538. foreach ($session_list as $session_data) {
  539. $my_session_list[$session_data['id']] =$session_data['name'];
  540. $options .= '<option value="'.$session_data['id'].'">'.$session_data['name'].'</option>';
  541. }
  542. $combinations = array();
  543. if (!empty($user_list)) {
  544. foreach ($user_list as $user) {
  545. $user_id = $user['user_id'];
  546. //if ($user_id != 78 ) continue;
  547. $name = $user['firstname'].' '.$user['lastname'];
  548. $course_list_registered = CourseManager::get_courses_list_by_user_id($user_id, true, false);
  549. $new_course_list = array();
  550. foreach ($course_list_registered as $course_reg) {
  551. if (empty($course_reg['id_session'])) {
  552. $course_reg['id_session'] = 0;
  553. }
  554. $new_course_list[] = $course_reg['code'].'_'.$course_reg['id_session'];
  555. }
  556. $course_list = get_courses_list_by_user_id_based_in_exercises($user_id);
  557. if (is_array($course_list) && !empty($course_list)) {
  558. foreach ($course_list as $my_course) {
  559. $key = $my_course['code'].'_'.$my_course['id_session'];
  560. if(!in_array($key,$new_course_list)) {
  561. $my_course['not_registered'] = 1;
  562. $course_list_registered[] = $my_course;
  563. }
  564. }
  565. }
  566. $course_list = $course_list_registered;
  567. echo '<div>';
  568. echo '<table class="data_table">';
  569. echo '<tr>';
  570. echo '<th style="text-align:left;" colspan="'.count($course_list).'">';
  571. echo "<h3> $name #$user_id </h3> ";
  572. echo '</th>';
  573. echo '</tr>';
  574. if (!empty($course_list)) {
  575. echo '<tr>';
  576. foreach ($course_list as $course) {
  577. echo '<td>';
  578. if (isset($course['id_session']) && !empty($course['id_session'])) {
  579. echo '<b>'.get_lang('SessionName').'</b> '.$my_session_list[$course['id_session']].'<br />';
  580. }
  581. echo $course['title'];
  582. echo ' ('.$course['code'].') ';
  583. if (isset($course['not_registered']) && !empty($course['not_registered'])) {
  584. echo ' <i>'.get_lang('UserNotRegistered').'</i>';
  585. }
  586. echo '</td>';
  587. }
  588. echo '</tr>';
  589. echo '<tr>';
  590. foreach ($course_list as $course) {
  591. $course_code = $course['code'];
  592. if (empty($course['id_session'])) {
  593. $session_id = 0;
  594. } else {
  595. $session_id = $course['id_session'];
  596. }
  597. echo '<td>';
  598. echo get_lang('MoveTo'); echo '<br />';
  599. $unique_id = uniqid();
  600. $combinations[$unique_id] = array('course_code' =>$course_code, 'session_id'=>$session_id);
  601. echo '<select id="'.$unique_id.'" name="'.$unique_id.'">';
  602. echo $options;
  603. echo '</select>';
  604. echo '<br />';
  605. //KK(\''.$unique_id.'\', \''.$user_id.'\')
  606. //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.'" >';
  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 '<button type="submit" class="save" onclick="view_stat(\''.$unique_id.'\', \''.$user_id.'\');"> '.get_lang('CompareStats').'</button>';
  609. echo '<button type="submit" class="save" onclick="moveto(\''.$unique_id.'\', \''.$user_id.'\');"> '.get_lang('Move').'</button>';
  610. echo '<div id ="reponse_'.$unique_id.'"></div>';
  611. echo '</td>';
  612. }
  613. echo '</tr>';
  614. } else {
  615. echo '<td>';
  616. echo get_lang('NoCoursesForThisUser');
  617. echo '</td>';
  618. }
  619. echo '</table>';
  620. echo '</div>';
  621. }
  622. }
  623. echo $navigation;
  624. $_SESSION['combination'] = $combinations;