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) {
  174. echo $sql;
  175. }
  176. $res = Database::query($sql);
  177. $result_message[$TBL_TRACK_E_COURSE_ACCESS]++;
  178. }
  179. }
  180. //4. track_e_lastaccess
  181. $sql = "SELECT access_id FROM $TBL_TRACK_E_LAST_ACCESS
  182. WHERE c_id = $course_id
  183. AND access_session_id = $origin_session_id
  184. AND access_user_id = $user_id ";
  185. $res = Database::query($sql);
  186. $list = array();
  187. while($row = Database::fetch_array($res,'ASSOC')) {
  188. $list[] = $row['access_id'];
  189. }
  190. if (!empty($list))
  191. foreach ($list as $id) {
  192. if ($update_database) {
  193. $sql = "UPDATE $TBL_TRACK_E_LAST_ACCESS SET access_session_id = $new_session_id WHERE access_id = $id";
  194. if ($debug) echo $sql;
  195. $res = Database::query($sql);
  196. if ($debug) var_dump($res);
  197. $result_message[$TBL_TRACK_E_LAST_ACCESS]++;
  198. }
  199. }
  200. //5. lp_item_view
  201. //CHECK ORIGIN
  202. $sql = "SELECT * FROM $TBL_LP_VIEW
  203. WHERE user_id = $user_id AND session_id = $origin_session_id AND c_id = $course_id ";
  204. $res = Database::query($sql);
  205. //Getting the list of LPs in the new session
  206. $lp_list = new LearnpathList($user_id, $origin_course_code, $new_session_id);
  207. $flat_list = $lp_list->get_flat_list();
  208. $list = array();
  209. while($row = Database::fetch_array($res,'ASSOC')) {
  210. //Checking if the LP exist in the new session
  211. if (in_array($row['lp_id'], array_keys($flat_list))) {
  212. $list[$row['id']] = $row;
  213. }
  214. }
  215. if (!empty($list))
  216. foreach ($list as $id=>$data) {
  217. if ($update_database) {
  218. $sql = "UPDATE $TBL_LP_VIEW SET session_id = $new_session_id WHERE c_id = $course_id AND id = $id ";
  219. if ($debug) var_dump($sql);
  220. $res = Database::query($sql);
  221. if ($debug) var_dump($res);
  222. $result_message[$TBL_LP_VIEW]++;
  223. } else {
  224. //Getting all information of that lp_item_id
  225. $score = Tracking::get_avg_student_score($user_id, $origin_course_code, array($data['lp_id']),$origin_session_id);
  226. $progress = Tracking::get_avg_student_progress($user_id, $origin_course_code, array($data['lp_id']),$origin_session_id);
  227. $result_message['LP_VIEW'][$data['lp_id']] = array('score' => $score, 'progress' =>$progress);
  228. }
  229. }
  230. //CHECk DESTINY
  231. if (!$update_database) {
  232. $sql = "SELECT * FROM $TBL_LP_VIEW WHERE user_id = $user_id AND session_id = $new_session_id AND c_id = $course_id";
  233. $res = Database::query($sql);
  234. //Getting the list of LPs in the new session
  235. $lp_list = new LearnpathList($user_id, $origin_course_code, $new_session_id);
  236. $flat_list = $lp_list->get_flat_list();
  237. $list = array();
  238. while($row = Database::fetch_array($res,'ASSOC')) {
  239. //Checking if the LP exist in the new session
  240. if (in_array($row['lp_id'], array_keys($flat_list))) {
  241. $list[$row['id']] = $row;
  242. }
  243. }
  244. if (!empty($list))
  245. foreach ($list as $id=>$data) {
  246. //Getting all information of that lp_item_id
  247. $score = Tracking::get_avg_student_score($user_id, $origin_course_code, array($data['lp_id']), $new_session_id);
  248. $progress = Tracking::get_avg_student_progress($user_id, $origin_course_code, array($data['lp_id']), $new_session_id);
  249. $result_message_compare['LP_VIEW'][$data['lp_id']] = array('score' => $score, 'progress' =>$progress);
  250. }
  251. }
  252. //6. Agenda
  253. //calendar_event_attachment no problems no session_id
  254. $sql = "SELECT ref FROM $TBL_ITEM_PROPERTY WHERE tool = 'calendar_event' AND insert_user_id = $user_id AND c_id = $course_id ";
  255. $res = Database::query($sql);
  256. while($row = Database::fetch_array($res,'ASSOC')) {
  257. $id = $row['ref'];
  258. if ($update_database) {
  259. $sql = "UPDATE $TBL_AGENDA SET session_id = $new_session_id WHERE c_id = $course_id AND id = $id ";
  260. if ($debug) var_dump($sql);
  261. $res_update = Database::query($sql);
  262. if ($debug) var_dump($res_update);
  263. $result_message['agenda']++;
  264. }
  265. }
  266. //7. Forum ?? So much problems when trying to import data
  267. //8. Student publication - Works
  268. //echo '<h1>Student publication</h1>';
  269. $sql = "SELECT ref FROM $TBL_ITEM_PROPERTY WHERE tool = 'work' AND insert_user_id = $user_id AND c_id = $course_id";
  270. if ($debug) echo $sql;
  271. $res = Database::query($sql);
  272. while($row = Database::fetch_array($res,'ASSOC')) {
  273. $id = $row['ref'];
  274. $sql = "SELECT * FROM $TBL_STUDENT_PUBLICATION WHERE id = $id AND session_id = $origin_session_id AND c_id = $course_id";
  275. if ($debug) var_dump($sql);
  276. $sub_res = Database::query($sql);
  277. if (Database::num_rows($sub_res) > 0 ) {
  278. $data = Database::fetch_array($sub_res,'ASSOC');
  279. if ($debug) var_dump($data);
  280. $parent_id = $data['parent_id'];
  281. if (isset($data['parent_id']) && !empty($data['parent_id'])) {
  282. $sql = "SELECT * FROM $TBL_STUDENT_PUBLICATION WHERE id = $parent_id AND c_id = $course_id";
  283. $select_res = Database::query($sql);
  284. $parent_data = Database::fetch_array($select_res,'ASSOC');
  285. if ($debug) var_dump($parent_data);
  286. $sys_course_path = api_get_path(SYS_COURSE_PATH);
  287. $course_dir = $sys_course_path . $course_info['path'];
  288. $base_work_dir = $course_dir . '/work';
  289. require_once api_get_path(SYS_CODE_PATH).'work/work.lib.php';
  290. //Creating the parent folder in the session if does not exists already
  291. //@todo ugly fix
  292. $search_this = "folder_moved_from_session_id_$origin_session_id";
  293. $search_this2 = $parent_data['url'];
  294. $sql = "SELECT * FROM $TBL_STUDENT_PUBLICATION
  295. WHERE description like '%$search_this%' AND url LIKE '%$search_this2%' AND session_id = $new_session_id AND c_id = $course_id
  296. ORDER BY id desc LIMIT 1";
  297. if ($debug) echo $sql;
  298. $sub_res = Database::query($sql);
  299. $num_rows = Database::num_rows($sub_res);
  300. if ($num_rows > 0 ) {
  301. $new_result = Database::fetch_array($sub_res,'ASSOC');
  302. $created_dir = $new_result['url'];
  303. $new_parent_id = $new_result['id'];
  304. } else {
  305. if ($update_database) {
  306. $dir_name = substr($parent_data['url'], 1);
  307. $created_dir = create_unexisting_work_directory($base_work_dir, $dir_name);
  308. $created_dir = '/'.$created_dir;
  309. $now = api_get_utc_datetime();
  310. //Creating directory
  311. $sql_add_publication = "INSERT INTO " . $TBL_STUDENT_PUBLICATION . " SET
  312. url = '".$created_dir."',
  313. c_id = $course_id,
  314. title = '".$parent_data['title']."',
  315. description = '".$parent_data['description']." folder_moved_from_session_id_$origin_session_id ',
  316. author = '',
  317. active = '0',
  318. accepted = '1',
  319. filetype = 'folder',
  320. sent_date = '".$now."',
  321. qualification = '".$parent_data['qualification'] ."',
  322. parent_id = '',
  323. qualificator_id = '',
  324. date_of_qualification = '0000-00-00 00:00:00',
  325. session_id = ".$new_session_id;
  326. $rest_insert = Database::query($sql_add_publication);
  327. if ($debug) echo ($sql_add_publication);
  328. // add the directory
  329. $id = Database::insert_id();
  330. //Folder created
  331. api_item_property_update($course_info, 'work', $id, 'DirectoryCreated', api_get_user_id());
  332. if ($debug) var_dump($rest_insert);
  333. $new_parent_id = $id;
  334. $result_message[$TBL_STUDENT_PUBLICATION.' - new folder created called: '.$created_dir]++;
  335. }
  336. }
  337. //Creating student_publication_assignment if exists
  338. $sql = "SELECT * FROM $TBL_STUDENT_PUBLICATION_ASSIGNMENT WHERE publication_id = $parent_id AND c_id = $course_id";
  339. if ($debug) var_dump($sql);
  340. $rest_select = Database::query($sql);
  341. if (Database::num_rows($rest_select) > 0 ) {
  342. if ($update_database) {
  343. $assignment_data = Database::fetch_array($rest_select,'ASSOC');
  344. $sql_add_publication = "INSERT INTO " . $TBL_STUDENT_PUBLICATION_ASSIGNMENT . " SET
  345. c_id = '$course_id',
  346. expires_on = '".$assignment_data['expires_on']."',
  347. ends_on = '".$assignment_data['ends_on']."',
  348. add_to_calendar = '".$assignment_data['add_to_calendar']."',
  349. enable_qualification = '".$assignment_data['enable_qualification']."',
  350. publication_id = '".$new_parent_id."'";
  351. if ($debug) echo $sql_add_publication;
  352. $rest_select = Database::query($sql_add_publication);
  353. $id = Database::insert_id();
  354. $sql_update = "UPDATE " . $TBL_STUDENT_PUBLICATION . " SET " .
  355. "has_properties = '".$id."',
  356. view_properties = '1'
  357. WHERE id = ".$new_parent_id;
  358. if ($debug) echo $sql_update;
  359. $rest_update = Database::query($sql_update);
  360. if ($debug) var_dump($sql_update);
  361. $result_message[$TBL_STUDENT_PUBLICATION_ASSIGNMENT]++;
  362. }
  363. }
  364. $doc_url = $data['url'];
  365. $new_url = str_replace($parent_data['url'], $created_dir, $doc_url);
  366. if ($update_database) {
  367. //Creating a new work
  368. $sql_add_publication = "INSERT INTO " . $TBL_STUDENT_PUBLICATION . " SET " .
  369. "url = '" . $new_url . "',
  370. c_id = $course_id,
  371. title = '" . $data['title']. "',
  372. description = '" . $data['description'] . " file moved',
  373. author = '" . $data['author'] . "',
  374. active = '" . $data['active']. "',
  375. accepted = '" . $data['accepted']. "',
  376. post_group_id = " . $data['post_group_id'] . ",
  377. sent_date = '".$data['sent_date'] ."',
  378. parent_id = ".$new_parent_id ." ,
  379. session_id = ".$new_session_id;
  380. if ($debug) echo $sql_add_publication;
  381. $rest_insert = Database::query($sql_add_publication);
  382. if ($debug) var_dump($rest_insert);
  383. $id = Database::insert_id();
  384. api_item_property_update($course_info, 'work', $id, 'DocumentAdded', $user_id);
  385. $result_message[$TBL_STUDENT_PUBLICATION]++;
  386. $full_file_name = $course_dir.'/'.$doc_url;
  387. $new_file = $course_dir.'/'.$new_url;
  388. if (file_exists($full_file_name)) {
  389. //deleting old assignment
  390. $result = copy($full_file_name, $new_file);
  391. if ($result) {
  392. unlink($full_file_name);
  393. $sql = "DELETE FROM $TBL_STUDENT_PUBLICATION WHERE id= ".$data['id'];
  394. if ($debug) var_dump($sql);
  395. $result_delete = Database::query($sql);
  396. api_item_property_update($course_info, 'work', $data['id'], 'DocumentDeleted', api_get_user_id());
  397. }
  398. }
  399. }
  400. }
  401. }
  402. }
  403. //9. Survey Pending
  404. //10. Dropbox - not neccesary to move categories (no presence of session_id)
  405. $sql = "SELECT id FROM $TBL_DROPBOX_FILE WHERE uploader_id = $user_id AND session_id = $origin_session_id AND c_id = $course_id";
  406. if ($debug) var_dump($sql);
  407. $res = Database::query($sql);
  408. while($row = Database::fetch_array($res,'ASSOC')) {
  409. $id = $row['id'];
  410. if ($update_database) {
  411. $sql = "UPDATE $TBL_DROPBOX_FILE SET session_id = $new_session_id WHERE c_id = $course_id AND id = $id";
  412. if ($debug) var_dump($sql);
  413. $res = Database::query($sql);
  414. if ($debug) var_dump($res);
  415. $sql = "UPDATE $TBL_DROPBOX_POST SET session_id = $new_session_id WHERE file_id = $id";
  416. if ($debug)
  417. var_dump($sql);
  418. $res = Database::query($sql);
  419. if ($debug)
  420. var_dump($res);
  421. $result_message[$TBL_DROPBOX_FILE]++;
  422. }
  423. }
  424. //11. Notebook
  425. $sql = "SELECT notebook_id FROM $TBL_NOTEBOOK
  426. WHERE user_id = $user_id AND session_id = $origin_session_id AND course = '$origin_course_code' AND c_id = $course_id";
  427. if ($debug) var_dump($sql);
  428. $res = Database::query($sql);
  429. while($row = Database::fetch_array($res,'ASSOC')) {
  430. $id = $row['notebook_id'];
  431. if ($update_database) {
  432. $sql = "UPDATE $TBL_NOTEBOOK SET session_id = $new_session_id WHERE c_id = $course_id AND notebook_id = $id";
  433. if ($debug) var_dump($sql);
  434. $res = Database::query($sql);
  435. if ($debug) var_dump($res);
  436. }
  437. }
  438. if ($update_database) {
  439. echo '<h2>'.get_lang('StatsMoved').'</h2>';
  440. if (is_array($result_message))
  441. foreach ($result_message as $table=>$times) {
  442. echo 'Table '.$table.' - '.$times.' records updated <br />';
  443. }
  444. } else {
  445. echo '<h2>'.get_lang('UserInformationOfThisCourse').'</h2>';
  446. echo '<br />';
  447. echo '<table width="100%">';
  448. echo '<tr>';
  449. echo '<td width="50%" valign="top">';
  450. if ($origin_session_id == 0 ) {
  451. echo '<h4>'.get_lang('OriginCourse').'</h4>';
  452. } else {
  453. echo '<h4>'.get_lang('OriginSession').' #'.$origin_session_id.'</h4>';
  454. }
  455. compare_data($result_message);
  456. echo '</td>';
  457. echo '<td width="50%" valign="top">';
  458. if ($new_session_id == 0 ) {
  459. echo '<h4>'.get_lang('DestinyCourse').'</h4>';
  460. } else {
  461. echo '<h4>'.get_lang('DestinySession').' #'.$new_session_id.'</h4>';
  462. }
  463. compare_data($result_message_compare);
  464. echo '</td>';
  465. echo '</tr>';
  466. echo '</table>';
  467. }
  468. } else {
  469. echo get_lang('CourseDoesNotExistInThisSession');
  470. }
  471. }
  472. } else {
  473. echo get_lang('ThereWasAnError');
  474. }
  475. exit;
  476. }
  477. $htmlHeadXtra[] = '<script type="text/javascript">
  478. function moveto (unique_id, user_id) {
  479. var session_id = document.getElementById(unique_id).options[document.getElementById(unique_id).selectedIndex].value;
  480. $.ajax({
  481. contentType: "application/x-www-form-urlencoded",
  482. beforeSend: function(objeto) {
  483. $("div#reponse_"+unique_id).html("<img src=\'../inc/lib/javascript/indicator.gif\' />"); },
  484. type: "POST",
  485. url: "user_move_stats.php",
  486. data: "load_ajax=1"+"&unique_id="+unique_id+"&user_id="+user_id+"&session_id="+session_id,
  487. success: function(datos) {
  488. $("div#reponse_"+unique_id).html(datos);
  489. }
  490. });
  491. }
  492. function view_stat (unique_id, user_id) {
  493. var session_id = document.getElementById(unique_id).options[document.getElementById(unique_id).selectedIndex].value;
  494. load_thick("user_move_stats.php?load_ajax=1&view_stat=1"+"&unique_id="+unique_id+"&user_id="+user_id+"&session_id="+session_id,"");
  495. /*
  496. $.ajax({
  497. contentType: "application/x-www-form-urlencoded",
  498. beforeSend: function(objeto) {
  499. $("div#reponse_"+unique_id).html("<img src=\'../inc/lib/javascript/indicator.gif\' />"); },
  500. type: "POST",
  501. url: "user_move_stats.php",
  502. data: "load_ajax=1&view_stat=1"+"&unique_id="+unique_id+"&user_id="+user_id+"&session_id="+session_id,
  503. success: function(datos) {
  504. $("div#reponse_"+unique_id).html(datos);
  505. }
  506. });*/
  507. }
  508. </script>';
  509. function get_courses_list_by_user_id_based_in_exercises($user_id) {
  510. $TABLETRACK_EXERCICES = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
  511. $user_id = intval($user_id);
  512. $sql = "SELECT DISTINCT exe_user_id, c_id, session_id
  513. FROM $TABLETRACK_EXERCICES
  514. 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. $name = $user['firstname'].' '.$user['lastname'];
  564. $course_list_registered = CourseManager::get_courses_list_by_user_id(
  565. $user_id,
  566. true,
  567. false
  568. );
  569. $new_course_list = array();
  570. foreach ($course_list_registered as $course_reg) {
  571. if (empty($course_reg['session_id'])) {
  572. $course_reg['session_id'] = 0;
  573. }
  574. // Recover the code for historical reasons. If it can be proven
  575. // that the code can be safely replaced by c_id in the following
  576. // PHP code, feel free to do so
  577. $courseInfo = api_get_course_info_by_id($course_reg['real_id']);
  578. $course_reg['code'] = $courseInfo['code'];
  579. $new_course_list[] = $course_reg['code'].'_'.$course_reg['session_id'];
  580. }
  581. $course_list = get_courses_list_by_user_id_based_in_exercises($user_id);
  582. if (is_array($course_list) && !empty($course_list)) {
  583. foreach ($course_list as $my_course) {
  584. $courseInfo = api_get_course_info_by_id($my_course['c_id']);
  585. $my_course['real_id'] = $my_course['c_id'];
  586. $key = $courseInfo['code'].'_'.$my_course['session_id'];
  587. if (!in_array($key, $new_course_list)) {
  588. $my_course['not_registered'] = 1;
  589. $course_list_registered[] = $my_course;
  590. }
  591. }
  592. }
  593. foreach ($course_list_registered as & $course) {
  594. $courseInfo = api_get_course_info_by_id($course['real_id']);
  595. $course['name'] = $courseInfo['name'];
  596. }
  597. $course_list = $course_list_registered;
  598. echo '<div>';
  599. echo '<table class="data_table">';
  600. echo '<tr>';
  601. echo '<th style="text-align:left;" colspan="'.count($course_list).'">';
  602. echo "<h3>$name #$user_id </h3> ";
  603. echo '</th>';
  604. echo '</tr>';
  605. if (!empty($course_list)) {
  606. echo '<tr>';
  607. foreach ($course_list as $course) {
  608. echo '<td>';
  609. if (isset($course['id_session']) && !empty($course['id_session'])) {
  610. echo '<b>'.get_lang('SessionName').'</b> '.$my_session_list[$course['id_session']].'<br />';
  611. }
  612. echo $course['name'];
  613. echo ' ('.$course['code'].') ';
  614. if (isset($course['not_registered']) && !empty($course['not_registered'])) {
  615. echo ' <i>'.get_lang('UserNotRegistered').'</i>';
  616. }
  617. echo '</td>';
  618. }
  619. echo '</tr>';
  620. echo '<tr>';
  621. foreach ($course_list as $course) {
  622. $course_code = $course['code'];
  623. if (empty($course['id_session'])) {
  624. $session_id = 0;
  625. } else {
  626. $session_id = $course['id_session'];
  627. }
  628. echo '<td>';
  629. echo get_lang('MoveTo'); echo '<br />';
  630. $unique_id = uniqid();
  631. $combinations[$unique_id] = array('course_code' =>$course_code, 'session_id'=>$session_id);
  632. echo '<select id="'.$unique_id.'" name="'.$unique_id.'">';
  633. echo $options;
  634. echo '</select>';
  635. echo '<br />';
  636. echo '<button type="submit" class="btn btn-success" onclick="view_stat(\''.$unique_id.'\', \''.$user_id.'\');"> '.get_lang('CompareStats').'</button>';
  637. echo '<button type="submit" class="btn btn-success" onclick="moveto(\''.$unique_id.'\', \''.$user_id.'\');"> '.get_lang('Move').'</button>';
  638. echo '<div id ="reponse_'.$unique_id.'"></div>';
  639. echo '</td>';
  640. }
  641. echo '</tr>';
  642. } else {
  643. echo '<td>';
  644. echo get_lang('NoCoursesForThisUser');
  645. echo '</td>';
  646. }
  647. echo '</table>';
  648. echo '</div>';
  649. }
  650. }
  651. echo $navigation;
  652. $_SESSION['combination'] = $combinations;