user_move_stats.php 36 KB

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