user_move_stats.php 36 KB

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