user_move_stats.php 36 KB

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