user_move_stats.php 35 KB

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