user_move_stats.php 38 KB

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