|
@@ -1,1289 +0,0 @@
|
|
|
-<?php
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- * Chamilo LMS
|
|
|
- * Script handling the migration between an old Dokeos platform (<1.8.0) to
|
|
|
- * setup the new database system (4 scorm tables inside the course's database)
|
|
|
- * @package chamilo.scorm
|
|
|
- * @author Yannick Warnier <ywarnier@beeznest.org>
|
|
|
- */
|
|
|
-
|
|
|
-
|
|
|
- * Include mandatory libraries
|
|
|
- */
|
|
|
-Log::notice('Entering file');
|
|
|
-
|
|
|
-if (!defined('SYSTEM_INSTALLATION')) {
|
|
|
- echo 'You are not allowed here !' . __FILE__;
|
|
|
- return;
|
|
|
-}
|
|
|
-
|
|
|
-require_once api_get_path(LIBRARY_PATH).'document.lib.php';
|
|
|
-require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
|
|
|
-require_once api_get_path(SYS_CODE_PATH).'newscorm/learnpath.class.php';
|
|
|
-require_once api_get_path(SYS_CODE_PATH).'newscorm/scorm.class.php';
|
|
|
-
|
|
|
-$loglevel = 0;
|
|
|
-
|
|
|
-
|
|
|
-$table_prefix = $prefix;
|
|
|
-$sys_course_path = $pathForm.'courses/';
|
|
|
-$upd_course_path = $proposedUpdatePath.'courses/';
|
|
|
-
|
|
|
-function my_get_time($time) {
|
|
|
- $matches = array();
|
|
|
- if (preg_match('/(\d{1,4}):(\d{2})(:(\d{2})(\.\d*)?)?/', $time, $matches)) {
|
|
|
- if (count($matches) == 3) {
|
|
|
- return ($matches[1] * 60) + ($matches[2]);
|
|
|
- } else {
|
|
|
- return ($matches[1] * 3600) + ($matches[2] * 60) + ($matches[4]);
|
|
|
- }
|
|
|
- }
|
|
|
- else return 0;
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-$fh = fopen(api_get_path(SYS_ARCHIVE_PATH).'newscorm_'.time().'.log', 'w');
|
|
|
-$fh_revert = fopen(api_get_path(SYS_ARCHIVE_PATH).'newscorm_'.time().'_revert.log', 'w');
|
|
|
-$fh_res = fopen(api_get_path(SYS_ARCHIVE_PATH).'newscorm_'.time().'_res.log', 'w');
|
|
|
-fwrite($fh, "-- Recording course homepages links changes to enable reverting\n");
|
|
|
-fwrite($fh_revert, "-- Recording reverted course homepages links changes to enable reverting\n");
|
|
|
-fwrite($fh_res, "-- Recording resulting course homepages links changes\n");
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- * New tables definition:
|
|
|
- */
|
|
|
-$new_lp = 'lp';
|
|
|
-$new_lp_view = 'lp_view';
|
|
|
-$new_lp_item = 'lp_item';
|
|
|
-$new_lp_item_view = 'lp_item_view';
|
|
|
-$new_lp_type = 'lp_type';
|
|
|
-
|
|
|
-$max_dsp_lp = 0;
|
|
|
-$courses_list = array();
|
|
|
-$courses_id_list = array();
|
|
|
-$courses_id_full_table_prefix_list = array();
|
|
|
-$courses_dir_list = array();
|
|
|
-
|
|
|
-Database::select_db($dbNameForm);
|
|
|
-
|
|
|
-$sql = "SELECT * FROM course";
|
|
|
-$res = Database::query($sql);
|
|
|
-
|
|
|
-while ($row = Database::fetch_array($res)) {
|
|
|
- $course_pref = $table_prefix;
|
|
|
- if ($singleDbForm) {
|
|
|
- $dbname = $_configuration['main_database'].'.'.$course_pref.$row['db_name'].'_';
|
|
|
- } else {
|
|
|
- $dbname = $row['db_name'].'.'.$course_pref;
|
|
|
- }
|
|
|
- $courses_list[] = $row['db_name'];
|
|
|
- $courses_id_list[$row['code']] = $row['db_name'];
|
|
|
- $courses_id_full_table_prefix_list[$row['code']] = $dbname;
|
|
|
- $courses_dir_list[$row['code']] = $row['directory'];
|
|
|
-}
|
|
|
-
|
|
|
-if ($loglevel > 0) { Log::notice("Tables created/deleted for all courses"); }
|
|
|
-
|
|
|
-
|
|
|
- * The migration needs to take all data from the original learnpath tables and add them to the new
|
|
|
- * lp, lp_view, lp_item and lp_item_view tables
|
|
|
- */
|
|
|
-
|
|
|
-
|
|
|
-foreach ($courses_id_full_table_prefix_list as $course_code => $db) {
|
|
|
- if (strlen($courses_id_list[$course_code]) > 40) {
|
|
|
- Log::error('Database '.$courses_id_list[$course_code].' is too long, skipping');
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- $incoherences = 0;
|
|
|
- if ($loglevel > 0) { Log::notice("Now starting migration of learnpath tables from $db database..."); }
|
|
|
- $lp_doc = $db.TABLE_DOCUMENT;
|
|
|
- $lp_main = $db.TABLE_LEARNPATH_MAIN;
|
|
|
- $lp_ids = array();
|
|
|
- $lp_user = $db.TABLE_LEARNPATH_USER;
|
|
|
- $lp_users = array();
|
|
|
- $lp_chap = $db.TABLE_LEARNPATH_CHAPTER;
|
|
|
- $parent_chaps = array();
|
|
|
- $lp_chap_items = array();
|
|
|
- $ordered_chaps = array();
|
|
|
- $lp_item = $db.TABLE_LEARNPATH_ITEM;
|
|
|
- $lp_items = array();
|
|
|
- $lp_ordered_items = array();
|
|
|
- $parent_lps = array();
|
|
|
- $my_new_lp = $db.$new_lp;
|
|
|
- $my_new_lp_item = $db.$new_lp_item;
|
|
|
- $my_new_lp_view = $db.$new_lp_view;
|
|
|
- $my_new_lp_item_view = $db.$new_lp_item_view;
|
|
|
-
|
|
|
-
|
|
|
- $sql_test = "SELECT * FROM $my_new_lp";
|
|
|
- $res_test = Database::query($sql_test);
|
|
|
- $sql_lp = "SELECT * FROM $lp_main";
|
|
|
- if ($loglevel > 1) { Log::notice("$sql_lp"); }
|
|
|
- $res_lp = Database::query($sql_lp);
|
|
|
- if (!$res_lp or !$res_test) {
|
|
|
- if ($loglevel > 1) {
|
|
|
- Log::error("+++Problem querying DB $lp_main+++ skipping (".Database::error().")");
|
|
|
- if (!$res_test) {
|
|
|
- Log::error("This might be due to no existing table in the destination course");
|
|
|
- }
|
|
|
- }
|
|
|
- continue;
|
|
|
- }
|
|
|
- $dsp_ord = 1;
|
|
|
- while ($row = Database::fetch_array($res_lp)) {
|
|
|
-
|
|
|
- $ins_lp_sql = "INSERT INTO $my_new_lp (lp_type,name,description,display_order,content_maker) " .
|
|
|
- "VALUES (1," .
|
|
|
- "'".Database::escape_string($row['learnpath_name'])."'," .
|
|
|
- "'".Database::escape_string($row['learnpath_description'])."',$dsp_ord,'Dokeos')";
|
|
|
- $ins_lp_res = Database::query($ins_lp_sql);
|
|
|
- $in_id = Database::insert_id();
|
|
|
- if (!$in_id) die('Could not insert lp: '.$ins_lp_sql);
|
|
|
- $lp_ids[$row['learnpath_id']] = $in_id;
|
|
|
- $dsp_ord++;
|
|
|
- $max_dsp_lp = $dsp_ord;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- $sql_lp_chap = "ALTER TABLE $lp_chap ADD INDEX ( parent_chapter_id, display_order )";
|
|
|
- $res_lp_chap = Database::query($sql_lp_chap);
|
|
|
-
|
|
|
- $sql_lp_chap = "SELECT * FROM $lp_chap ORDER BY parent_chapter_id, display_order";
|
|
|
-
|
|
|
- $res_lp_chap = Database::query($sql_lp_chap);
|
|
|
- while ($row = Database::fetch_array($res_lp_chap)) {
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- $my_lp_item = $my_new_lp_item;
|
|
|
- $myname = Database::escape_string($row['chapter_name']);
|
|
|
- $mydesc = Database::escape_string($row['chapter_description']);
|
|
|
- $ins_lp_sql = "INSERT INTO $my_new_lp_item (" .
|
|
|
- "lp_id," .
|
|
|
- "item_type," .
|
|
|
- "title," .
|
|
|
- "description," .
|
|
|
- "path, " .
|
|
|
- "display_order, " .
|
|
|
- "next_item_id) " .
|
|
|
- "VALUES (" .
|
|
|
- "'".$lp_ids[$row['learnpath_id']]."'," .
|
|
|
- "'dokeos_chapter'," .
|
|
|
- "'".$myname."'," .
|
|
|
- "'".$mydesc."'," .
|
|
|
- "''," .
|
|
|
- $row['display_order'].", " .
|
|
|
- "123456" .
|
|
|
- ")";
|
|
|
-
|
|
|
- $ins_res = Database::query($ins_lp_sql);
|
|
|
- $in_id = Database::insert_id();
|
|
|
-
|
|
|
- if (!$in_id) die('Could not insert lp: '.$ins_sql);
|
|
|
- $parent_chaps[$row['id']] = $row['parent_chapter_id'];
|
|
|
- $lp_chap_items[$row['id']] = $in_id;
|
|
|
- $parent_lps[$row['id']] = $row['learnpath_id'];
|
|
|
- $ordered_chaps[$row['parent_chapter_id']][$row['display_order']] = $in_id;
|
|
|
- $lp_chaps_list[$row['learnpath_id']][] = $in_id;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- foreach ($parent_chaps as $old_chap => $old_parent_chap) {
|
|
|
- if ($old_parent_chap != 0) {
|
|
|
- $new_chap = $lp_chap_items[$old_chap];
|
|
|
- $new_parent = $lp_chap_items[$old_parent_chap];
|
|
|
- if (isset($new_chap) && $new_chap != '' && isset($new_parent) && $new_parent != '') {
|
|
|
- $sql_par_chap = "UPDATE $my_new_lp_item " .
|
|
|
- "SET parent_item_id = $new_parent " .
|
|
|
- "WHERE id = $new_chap";
|
|
|
- $res_par_chap = Database::query($sql_par_chap);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- unset($parent_chaps);
|
|
|
-
|
|
|
-
|
|
|
- foreach ($ordered_chaps as $parent_chap) {
|
|
|
- $last = 0;
|
|
|
- foreach ($ordered_chaps[$parent_chap] as $order => $new_id) {
|
|
|
- $sql_upd_chaps = "UPDATE $my_new_lp_item " .
|
|
|
- "SET previous_item_id = $last " .
|
|
|
- "WHERE id = $new_id";
|
|
|
- $res_upd_chaps = Database::query($sql_upd_chaps);
|
|
|
-
|
|
|
- $next = 0;
|
|
|
- if (!empty($ordered_chaps[$parent_chap][$order + 1])) {
|
|
|
- $next = $ordered_chaps[$parent_chap][$order + 1];
|
|
|
- }
|
|
|
- $sql_upd_chaps = "UPDATE $my_new_lp_item " .
|
|
|
- "SET next_item_id = $next " .
|
|
|
- "WHERE id = $new_id";
|
|
|
- $res_upd_chaps = Database::query($sql_upd_chaps);
|
|
|
- $last = $new_id;
|
|
|
- }
|
|
|
- }
|
|
|
- unset($ordered_chaps);
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- $type_trans = array(
|
|
|
- 'document' => TOOL_DOCUMENT,
|
|
|
- 'exercise' => TOOL_QUIZ,
|
|
|
- 'forum' => TOOL_FORUM,
|
|
|
- 'Agenda' => TOOL_CALENDAR_EVENT,
|
|
|
- 'Ad_Valvas' => TOOL_ANNOUNCEMENT,
|
|
|
- 'Link' => TOOL_LINK,
|
|
|
- 'Link _blank' => TOOL_LINK,
|
|
|
- 'Exercise' => TOOL_QUIZ,
|
|
|
- 'HotPotatoes'=> 'HotPotatoes',
|
|
|
- 'Forum' => TOOL_FORUM,
|
|
|
- 'Thread' => TOOL_THREAD,
|
|
|
- 'Topic' => TOOL_THREAD,
|
|
|
- 'Post' => TOOL_POST,
|
|
|
- 'Document' => TOOL_DOCUMENT,
|
|
|
- 'Assignments'=> 'Assignments',
|
|
|
- 'Dropbox' => TOOL_DROPBOX,
|
|
|
- 'Introduction_text'=> 'Introduction_text',
|
|
|
- 'Course_description' => TOOL_COURSE_DESCRIPTION,
|
|
|
- 'Groups' => TOOL_GROUP,
|
|
|
- 'Users' => TOOL_USER,
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- );
|
|
|
-
|
|
|
-
|
|
|
- $sql_lp_item = "ALTER TABLE $lp_item ADD INDEX ( chapter_id, display_order)";
|
|
|
- $res_lp_item = Database::query($sql_lp_item);
|
|
|
- $sql_lp_item = "SELECT * FROM $lp_item ORDER BY chapter_id, display_order";
|
|
|
-
|
|
|
- $res_lp_item = Database::query($sql_lp_item);
|
|
|
- while ($row = Database::fetch_array($res_lp_item)) {
|
|
|
-
|
|
|
- $type = $type_trans[$row['item_type']];
|
|
|
- $ref = $row['item_id'];
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- $prereq_id = '';
|
|
|
- if (!empty($row['prereq_id'])) {
|
|
|
- switch ($row['prereq_type']) {
|
|
|
- case 'c':
|
|
|
-
|
|
|
- $prereq_id = $lp_chap_items[$row['prereq_id']];
|
|
|
- if (empty($prereq_id) && $loglevel > 1) { Log::error("Could not find prereq chapter ".$row['prereq_id']); }
|
|
|
- break;
|
|
|
- case 'i':
|
|
|
- default:
|
|
|
-
|
|
|
- $prereq_id = $lp_items[$parent_lps[$row['chapter_id']]][$row['prereq_id']];
|
|
|
- if (empty($prereq_id) && $loglevel > 1) { Log::error("Could not find prereq item ".$row['prereq_id']); }
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- $my_parent_id = 0;
|
|
|
- if (isset($lp_chap_items[$row['chapter_id']])) {
|
|
|
- $my_parent_id = $lp_chap_items[$row['chapter_id']];
|
|
|
- }
|
|
|
- $title = '';
|
|
|
- if (empty($row['title']) && $type == 'Document' && !empty($row['item_id'])) {
|
|
|
- $my_sql_doctitle = "SELECT title FROM $lp_doc WHERE id = ".$row['item_id'];
|
|
|
- $my_res_doctitle = Database::query($my_sql_doctitle);
|
|
|
- if ($row_doctitle = Database::fetch_array($my_res_doctitle)) {
|
|
|
- $title = $row_doctitle['title'];
|
|
|
- } else {
|
|
|
- $title = '-';
|
|
|
- }
|
|
|
- } else {
|
|
|
- $title = $row['title'];
|
|
|
- }
|
|
|
- if (isset($lp_ids[$parent_lps[$row['chapter_id']]])) {
|
|
|
-
|
|
|
- $ins_lp_sql = "INSERT INTO $my_new_lp_item (" .
|
|
|
- "lp_id," .
|
|
|
- "item_type," .
|
|
|
- "ref, " .
|
|
|
- "title," .
|
|
|
- "description," .
|
|
|
- "path, " .
|
|
|
- "parent_item_id," .
|
|
|
- "prerequisite," .
|
|
|
- "display_order" .
|
|
|
- ") VALUES (" .
|
|
|
- "'".$lp_ids[$parent_lps[$row['chapter_id']]]."'," .
|
|
|
- "'$type'," .
|
|
|
- "'$ref', " .
|
|
|
- "'".Database::escape_string($row['title'])."'," .
|
|
|
- "'".Database::escape_string($row['description'])."'," .
|
|
|
- "'$ref'," .
|
|
|
- "".$my_parent_id."," .
|
|
|
- "'$prereq_id'," .
|
|
|
- $row['display_order']." " .
|
|
|
- ")";
|
|
|
- $ins_res = Database::query($ins_lp_sql);
|
|
|
- $in_id = Database::insert_id();
|
|
|
-
|
|
|
- if (!$in_id) die('Could not insert lp_item: '.$ins_sql);
|
|
|
- $lp_items[$parent_lps[$row['chapter_id']]][$row['id']] = $in_id;
|
|
|
- $lp_ordered_items[$parent_lps[$row['chapter_id']]][$row['chapter_id']][] = $in_id;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- $order_sql = "ALTER TABLE $my_new_lp_item ADD INDEX (lp_id, parent_item_id, display_order)";
|
|
|
- $order_res = Database::query($order_sql);
|
|
|
- $order_sql = "SELECT * FROM $my_new_lp_item ORDER by lp_id ASC, parent_item_id ASC, display_order ASC";
|
|
|
-
|
|
|
- $order_res = Database::query($order_sql);
|
|
|
- $order_item = array();
|
|
|
- $lp_id = 0;
|
|
|
-
|
|
|
- while ($row = Database::fetch_array($order_res)) {
|
|
|
-
|
|
|
- if ($row['lp_id'] != $lp_id) {
|
|
|
-
|
|
|
- $last = 0;
|
|
|
- foreach ($order_item as $order_id => $item_id) {
|
|
|
- $next = 0;
|
|
|
- if (!empty($order_item[$order_id+1])) {
|
|
|
- $next = $order_item[$order_id+1];
|
|
|
- }
|
|
|
- $upd = "UPDATE $my_new_lp_item " .
|
|
|
- "SET next_item_id = ".$next."," .
|
|
|
- " previous_item_id = ".$last." " .
|
|
|
- "WHERE id = ".$item_id;
|
|
|
-
|
|
|
- Database::query($upd);
|
|
|
- $last = $item_id;
|
|
|
- }
|
|
|
- $order_item = array();
|
|
|
- $lp_id = $row['lp_id'];
|
|
|
- $order_item[] = $row['id'];
|
|
|
- } else {
|
|
|
- $order_item[] = $row['id'];
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- $last = 0;
|
|
|
- foreach ($order_item as $order_id => $item_id) {
|
|
|
- $next = 0;
|
|
|
- if (!empty($order_item[$order_id + 1])) {
|
|
|
- $next = $order_item[$order_id + 1];
|
|
|
- }
|
|
|
- $upd = "UPDATE $my_new_lp_item " .
|
|
|
- "SET next_item_id = ".$next."," .
|
|
|
- " previous_item_id = ".$last." " .
|
|
|
- "WHERE id = ".$item_id;
|
|
|
-
|
|
|
- Database::query($upd);
|
|
|
- $last = $item_id;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- $mysql = "ALTER TABLE $my_new_lp_item_view ADD INDEX (lp_view_id)";
|
|
|
- $myres = Database::query($mysql);
|
|
|
- $sql_lp_user = "ALTER TABLE $lp_user ADD INDEX (user_id, learnpath_id, learnpath_item_id)";
|
|
|
- $res_lp_user = Database::query($sql_lp_user);
|
|
|
- $sql_lp_user = "SELECT * FROM $lp_user ORDER BY user_id, learnpath_id, learnpath_item_id";
|
|
|
-
|
|
|
- $res_lp_user = Database::query($sql_lp_user);
|
|
|
- $user_id = 0;
|
|
|
- $learnpath_id = 0;
|
|
|
- $lp_view = 0;
|
|
|
- while ($row = Database::fetch_array($res_lp_user)) {
|
|
|
- if ($row['user_id']!=$user_id OR $row['learnpath_id']!=$learnpath_id) {
|
|
|
-
|
|
|
- $last = 0;
|
|
|
- if (!empty($lp_chaps_list[$row['learnpath_id']][0])) {
|
|
|
- $last = $lp_chaps_list[$row['learnpath_id']][0];
|
|
|
- }
|
|
|
- if (empty($lp_ids[$row['learnpath_id']])) {
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- $incoherences ++;
|
|
|
- } else {
|
|
|
- $mylpid = $lp_ids[$row['learnpath_id']];
|
|
|
- $sql_ins_view = "INSERT INTO $my_new_lp_view(" .
|
|
|
- "lp_id," .
|
|
|
- "user_id," .
|
|
|
- "view_count," .
|
|
|
- "last_item" .
|
|
|
- ")VALUES(" .
|
|
|
- "".$mylpid."," .
|
|
|
- "".$row['user_id']."," .
|
|
|
- "1," .
|
|
|
- "".$last."" .
|
|
|
- ")";
|
|
|
-
|
|
|
- $res_ins_view = Database::query($sql_ins_view);
|
|
|
- $in_id = Database::insert_id();
|
|
|
- $user_id = $row['user_id'];
|
|
|
- $learnpath_id = $row['learnpath_id'];
|
|
|
- $lp_view = $in_id;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- $my_new_lp_item_id = $lp_items[$learnpath_id][$row['learnpath_item_id']];
|
|
|
- if (empty($my_new_lp_item_id)) {
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- $incoherences ++;
|
|
|
- } else {
|
|
|
- $start_time = 0;
|
|
|
- $my_time = my_get_time($row['time']);
|
|
|
- if ($my_time > 0) {
|
|
|
- $start_time = time() - $my_time;
|
|
|
- }
|
|
|
- $sql_ins_iv = "INSERT INTO $my_new_lp_item_view(" .
|
|
|
- "lp_item_id," .
|
|
|
- "lp_view_id," .
|
|
|
- "view_count," .
|
|
|
- "start_time," .
|
|
|
- "total_time," .
|
|
|
- "score," .
|
|
|
- "status" .
|
|
|
- ")VALUES(" .
|
|
|
- "".$lp_items[$learnpath_id][$row['learnpath_item_id']]."," .
|
|
|
- "".$lp_view."," .
|
|
|
- "1," .
|
|
|
- "$start_time," .
|
|
|
- "".$my_time."," .
|
|
|
- "".$row['score']."," .
|
|
|
- "'".$row['status']."'" .
|
|
|
- ")";
|
|
|
-
|
|
|
- $res_ins_iv = Database::query($sql_ins_iv);
|
|
|
- }
|
|
|
-
|
|
|
- $mysql = "SELECT count(distinct(lp_item_id)) FROM $my_new_lp_item_view WHERE lp_view_id = ".$lp_view." AND status IN ('passed','completed','succeeded','browsed','failed')";
|
|
|
- $myres = Database::query($mysql);
|
|
|
- $myrow = Database::fetch_array($myres);
|
|
|
- $completed = $myrow[0];
|
|
|
- $mylpid = $lp_ids[$row['learnpath_id']];
|
|
|
- $sql = "SELECT count(*) FROM $my_new_lp_item WHERE lp_id = '".$mylpid."'";
|
|
|
- $myres = Database::query($sql);
|
|
|
- $myrow = Database::fetch_array($myres);
|
|
|
- $total = $myrow[0];
|
|
|
- $progress = ((float)$completed / (float)$total) * 100;
|
|
|
- $progress = number_format($progress, 0);
|
|
|
- $sql = "UPDATE $my_new_lp_view SET progress = '$progress' WHERE id = '$lp_view'";
|
|
|
- $myres = Database::query($sql);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- * Move prerequisites
|
|
|
- * TODO: Integrate prerequisites migration into learnpath_item migration
|
|
|
- */
|
|
|
-
|
|
|
- $msg = '';
|
|
|
- if ($incoherences > 0) {
|
|
|
- $msg = "(found $incoherences incoherences between views and items - ignored)";
|
|
|
- }
|
|
|
-
|
|
|
- * Migrate links on the homepage as well now (look into the TABLE_TOOL_LIST table and
|
|
|
- * update the links to newscorm/lp_controller.php?action=view&lp_id=x)
|
|
|
- * Only normal learnpaths were visible from the homepage so we only need to update here
|
|
|
- */
|
|
|
-
|
|
|
- $tbl_tool = $db.TABLE_TOOL_LIST;
|
|
|
- $sql_tool = "SELECT * FROM $tbl_tool WHERE image='scormbuilder.gif' AND link LIKE '%learnpath_handler%'";
|
|
|
- $res_tool = Database::query($sql_tool);
|
|
|
- while ($row_tool = Database::fetch_array($res_tool)) {
|
|
|
- $name = $row_tool['name'];
|
|
|
- $link = $row_tool['link'];
|
|
|
-
|
|
|
- $matches = array();
|
|
|
- if (preg_match('/learnpath_id=(\d+)$/', $link,$matches)) {
|
|
|
- $old_lp_id = $matches[1];
|
|
|
- $new_lp_id = $lp_ids[$old_lp_id];
|
|
|
- $sql_tool_upd = "UPDATE $tbl_tool " .
|
|
|
- "SET link='newscorm/lp_controller.php?action=view&lp_id=$new_lp_id' " .
|
|
|
- "WHERE id = ".$row_tool['id'];
|
|
|
- Log::notice('New LP - Migration - Updating tool table: '.$sql_tool_upd);
|
|
|
-
|
|
|
- fwrite($fh,$sql_tool_upd." AND link ='$link'");
|
|
|
- fwrite($fh_revert, "UPDATE $tbl_tool SET link='$link' WHERE id=".$row_tool['id']." AND link ='newscorm/lp_controller.php?action=view&lp_id=$new_lp_id';\n");
|
|
|
-
|
|
|
- $res_tool_upd = Database::query($sql_tool_upd);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- $tbl_tool = $db.TABLE_TOOL_LIST;
|
|
|
- $sql_tool = "SELECT * FROM $tbl_tool";
|
|
|
- $res_tool = Database::query($sql_tool);
|
|
|
- while ($row_tool = Database::fetch_array($res_tool)) {
|
|
|
- $link = $row_tool['link'];
|
|
|
- $matches = array();
|
|
|
- $pattern = '@scorm/showinframes\.php([^\s"\'&]*)(&|&)file=([^\s"\'&]*)@';
|
|
|
- if (preg_match($pattern, $link, $matches)) {
|
|
|
-
|
|
|
- if (!empty($matches[3]) && (strtolower(substr($matches[3], -15)) == 'imsmanifest.xml') && !is_file(realpath(urldecode($matches[3])))) {
|
|
|
-
|
|
|
- $sql_tool_upd = "DELETE FROM $tbl_tool WHERE id = ".$row_tool['id'];
|
|
|
- Log::notice('New LP - Migration - Updating tool table (dead link): '.$sql_tool_upd);
|
|
|
-
|
|
|
- fwrite($fh, $sql_tool_upd." AND link ='$link'");
|
|
|
- fwrite($fh_revert, "INSERT INTO $tbl_tool (link) VALUES ('$link');\n");
|
|
|
-
|
|
|
- $res_tool_upd = Database::query($sql_tool_upd);
|
|
|
- }
|
|
|
- } else {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- * Update course description (intro page) to use new links instead of learnpath/learnpath_handler.php
|
|
|
- */
|
|
|
- $tbl_intro = $db.TABLE_TOOL_INTRO;
|
|
|
- $sql_i = "SELECT * FROM $tbl_intro WHERE id='course_homepage'";
|
|
|
- $res_i = Database::query($sql_i);
|
|
|
-
|
|
|
- while ($row_i = Database::fetch_array($res_i)) {
|
|
|
- $intro = $row_i['intro_text'];
|
|
|
- $update = 0;
|
|
|
- $out = array();
|
|
|
- if (preg_match_all('/claroline\/learnpath\/showinframes\.php([^\s"\']*)learnpath_id=(\d*)/', $intro, $out, PREG_SET_ORDER)) {
|
|
|
- foreach ($out as $results) {
|
|
|
-
|
|
|
- $intro = preg_replace('/claroline\/learnpath\/showinframes\.php([^\s"\']*)learnpath_id='.$results[2].'/','main/newscorm/lp_controller.php'.$results[1].'action=view&lp_id='.$lp_ids[$results[2]], $intro);
|
|
|
- }
|
|
|
- }
|
|
|
- if (preg_match_all('/claroline\/phpbb\/index.php/', $intro, $out, PREG_SET_ORDER)) {
|
|
|
- foreach ($out as $results) {
|
|
|
- $intro = preg_replace('/claroline\/phpbb\/index\.php([^\s"\']*)/','main/forum/index.php'.$results[1], $intro);
|
|
|
- }
|
|
|
- }
|
|
|
- if ($intrp != $row_i['intro_text']) {
|
|
|
-
|
|
|
- $sql_upd = "update $tbl_intro set intro_text = '".Database::escape_string($intro)."' WHERE id = 'course_homepage' AND intro_text = '".Database::escape_string($row_i['intro_text'])."'";
|
|
|
-
|
|
|
- fwrite($fh,"$sql_upd\n");
|
|
|
- fwrite($fh_revert,"UPDATE $tbl_intro set intro_text = '".$row_i['intro_text']."' WHERE id = 'course_homepage' AND intro_text = '$intro';\n");
|
|
|
- fwrite($fh_res,"$intro\n");
|
|
|
- Database::query($sql_upd);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if ($loglevel > 0) { Log::notice("Done!".$msg); }
|
|
|
-
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
-unset($lp_ids);
|
|
|
-unset($lp_users);
|
|
|
-unset($parent_chaps);
|
|
|
-unset($lp_chap_items);
|
|
|
-unset($ordered_chaps);
|
|
|
-unset($lp_items);
|
|
|
-unset($lp_ordered_items);
|
|
|
-unset($parent_lps);
|
|
|
-
|
|
|
-fwrite($fh, "-- Recording course homepages links changes for SCORM to enable reverting\n");
|
|
|
-fwrite($fh_revert, "-- Recording reverted course homepages links changes for SCORM to enable reverting\n");
|
|
|
-fwrite($fh_res, "-- Recording resulting course homepages links changes for SCORM\n");
|
|
|
-
|
|
|
-
|
|
|
- * SCORM
|
|
|
- * The migration needs to take all data from the scorm.scorm_main and scorm.scorm_sco_data tables
|
|
|
- * and add them to the new lp, lp_view, lp_item and lp_item_view tables.
|
|
|
- */
|
|
|
-if ($loglevel > 0) { Log::notice("Now starting migration of scorm tables from global SCORM database"); }
|
|
|
-
|
|
|
-$scorm_main = $dbScormForm.'.'.TABLE_SCORM_MAIN;
|
|
|
-$scorm_item = $dbScormForm.'.'.TABLE_SCORM_SCO_DATA;
|
|
|
-
|
|
|
-$course_pref = $table_prefix;
|
|
|
-$lp_ids = array();
|
|
|
-$lp_item_ids = array();
|
|
|
-$lp_item_refs = array();
|
|
|
-$lp_course = array();
|
|
|
-$lp_course_code = array();
|
|
|
-$scorm_lp_paths = array();
|
|
|
-
|
|
|
-
|
|
|
-Database::select_db($dbNameForm);
|
|
|
-$course_main = TABLE_MAIN_COURSE;
|
|
|
-$sql_crs = "SELECT * FROM $course_main WHERE target_course_code IS NULL";
|
|
|
-if ($loglevel > 0) { Log::notice("$sql_crs"); }
|
|
|
-$res_crs = Database::query($sql_crs);
|
|
|
-$num = Database::num_rows($res_crs);
|
|
|
-
|
|
|
-
|
|
|
-$scorms = array();
|
|
|
-$course_code_swap = '';
|
|
|
-$scormdocuments_lps = array();
|
|
|
-while ($course_row = Database::fetch_array($res_crs)) {
|
|
|
-
|
|
|
- if ($loglevel > 0) { Log::notice("Now dealing with course ".$course_row['code']."..."); }
|
|
|
-
|
|
|
- $my_course_code = $course_row['code'];
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- $db_name = $courses_id_full_table_prefix_list[$my_course_code];
|
|
|
- if (strlen($courses_id_list[$course_code]) > 40) {
|
|
|
- Log::notice('Database '.$courses_id_list[$course_code].' is too long, skipping');
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- $tblscodoc = $db_name.TABLE_SCORMDOC;
|
|
|
- $sql_scodoc = "SELECT path FROM $tblscodoc WHERE path IS NOT NULL AND path != ''";
|
|
|
- if ($loglevel > 1) { Log::notice("$sql_scodoc"); }
|
|
|
- $res_scodoc = Database::query($sql_scodoc);
|
|
|
- while ($row_scodoc = Database::fetch_array($res_scodoc)) {
|
|
|
-
|
|
|
-
|
|
|
- if (strpos($row_scodoc['path'], '/', 1) === false) {
|
|
|
- $tmp_path = $row_scodoc['path'];
|
|
|
- if ($loglevel > 1) { Log::notice("++Now opening $tmp_path"); }
|
|
|
-
|
|
|
-
|
|
|
- if (substr($tmp_path, 0, 1) != '/') {
|
|
|
- $tmp_path = '/'.$tmp_path;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- if ($tmp_path == '/') {
|
|
|
- $tmp_path = '';
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- $courses_dir = $sys_course_path.''.$courses_dir_list[$my_course_code].'/scorm'.$tmp_path;
|
|
|
- if (!is_dir($courses_dir)) {
|
|
|
-
|
|
|
- continue;
|
|
|
-
|
|
|
- } elseif (!is_file($courses_dir."/imsmanifest.xml")) {
|
|
|
-
|
|
|
- if ($loglevel > 2) { Log::error(" !!imsmanifest.xml not found at scormdocument's $courses_dir/imsmanifest.xml, skipping"); }
|
|
|
-
|
|
|
- if ($loglevel > 2) { Log::notice(" Trying subdirectories..."); }
|
|
|
- $dh = opendir($courses_dir);
|
|
|
- while ($entry = readdir($dh)) {
|
|
|
- if (substr($entry, 0, 1) != '.') {
|
|
|
- if (is_dir($courses_dir."/".$entry)) {
|
|
|
- if (is_file($courses_dir."/".$entry."/imsmanifest.xml")) {
|
|
|
- if ($loglevel > 2) { Log::notice(". .. and found $courses_dir/$entry/imsmanifest.xml!"); }
|
|
|
- if (!in_array($tmp_path."/".$entry."/imsmanifest.xml",$scormdocuments_lps)) {
|
|
|
- if ($loglevel > 2){ Log::notice(" Recording.<br />"); }
|
|
|
- $scormdocuments_lps[] = $tmp_path."/".$entry;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- if ($loglevel > 2) { Log::notice(" Found scormdocument $tmp_path in ".$sys_course_path.$courses_dir_list[$my_course_code]."/scorm, treating it."); }
|
|
|
- $scormdocuments_lps[] = $tmp_path;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- $tbl_intro = $db_name.TABLE_TOOL_INTRO;
|
|
|
- $sql_i = "SELECT * FROM $tbl_intro WHERE id='course_homepage'";
|
|
|
-
|
|
|
- $res_i = Database::query($sql_i);
|
|
|
-
|
|
|
- while ($row_scodoc = Database::fetch_array($res_i)) {
|
|
|
- $intro = $row_scodoc['intro_text'];
|
|
|
-
|
|
|
- $matches = array();
|
|
|
- $pattern = '@scorm/showinframes\.php([^\s"\']*)file=([^\s"\'&]*)@';
|
|
|
- if (preg_match_all($pattern, $intro, $matches, PREG_SET_ORDER)) {
|
|
|
- if (count($matches) < 1) {
|
|
|
-
|
|
|
- } else {
|
|
|
-
|
|
|
- foreach ($matches as $match) {
|
|
|
-
|
|
|
- $mymatch = urldecode($match[2]);
|
|
|
- $mymatch = str_replace($sys_course_path, $upd_course_path, $mymatch);
|
|
|
- if (!empty($mymatch) && (strtolower(substr($mymatch, -15)) == 'imsmanifest.xml') && is_file(realpath(urldecode($mymatch)))) {
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- $courses_dir = $upd_course_path.''.$courses_dir_list[$my_course_code].'/scorm';
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- if (strpos($mymatch, $courses_dir) !== false) {
|
|
|
-
|
|
|
- $entry = substr($mymatch, strlen($courses_dir));
|
|
|
-
|
|
|
- $entry = substr($entry, 0, -16);
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- if (is_file($courses_dir.$entry."/imsmanifest.xml")) {
|
|
|
-
|
|
|
- if ($loglevel > 2) { Log::notice(". .. and found $courses_dir/$entry/imsmanifest.xml!"); }
|
|
|
- if (!in_array($entry."/imsmanifest.xml", $scormdocuments_lps)) {
|
|
|
- if ($loglevel > 2) { Log::notice(" Recording.<br />"); }
|
|
|
-
|
|
|
- $scormdocuments_lps[] = $entry;
|
|
|
- }
|
|
|
- } else {
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- $scorms[$my_course_code] = array();
|
|
|
-
|
|
|
- $sql_paths = "SELECT * FROM $scorm_main WHERE dokeosCourse = '".$my_course_code."'";
|
|
|
- if ($loglevel > 0) { Log::notice("$sql_paths"); }
|
|
|
- $res_paths = Database::query($sql_paths);
|
|
|
- $num = Database::num_rows($res_paths);
|
|
|
- while ($scorm_row = Database::fetch_array($res_paths)) {
|
|
|
-
|
|
|
- $my_content_id = $scorm_row['contentId'];
|
|
|
- $my_path = $scorm_row['contentTitle'];
|
|
|
- if (substr($my_path, 0, 1) != '/') {
|
|
|
- $my_path = '/'.$my_path;
|
|
|
- }
|
|
|
- if ($my_path == '/') {
|
|
|
- $my_path = '';
|
|
|
- }
|
|
|
- if ($loglevel > 1) { Log::notice("++++Now opening $my_path"); }
|
|
|
- if (!is_dir($courses_dir = $sys_course_path.''.$courses_dir_list[$my_course_code].'/scorm'.$my_path)) {
|
|
|
- if ($loglevel > 1) { Log::notice("Path $my_content_id: $my_path doesn't exist in ".$sys_course_path.$courses_dir_list[$my_course_code]."/scorm, skipping"); }
|
|
|
- continue;
|
|
|
-
|
|
|
- } elseif (!is_file($sys_course_path.$courses_dir_list[$my_course_code].'/scorm'.$my_path."/imsmanifest.xml")) {
|
|
|
- if ($loglevel > 1) { Log::notice("!!imsmanifest.xml not found at ".$sys_course_path.$courses_dir_list[$my_course_code].'/scorm'.$my_path."/imsmanifest.xml, skipping"); }
|
|
|
- continue;
|
|
|
- } else {
|
|
|
- if ($loglevel > 1) { Log::notice("Found $my_path in ".$sys_course_path.$courses_dir_list[$my_course_code]."/scorm".$mypath."/imsmanifest.xml, keeping it."); }
|
|
|
- $scorms[$my_course_code][$my_path] = $my_content_id;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- foreach ($scormdocuments_lps as $path) {
|
|
|
- if (!in_array($path,array_keys($scorms[$my_course_code]))) {
|
|
|
-
|
|
|
- if ($loglevel > 1) { Log::notice("** Scormdocument path $path wasn't recorded yet. Added."); }
|
|
|
- $scorms[$my_course_code][$path] = -1;
|
|
|
- }
|
|
|
- }
|
|
|
- $course_code_swap = $my_course_code;
|
|
|
- unset($scormdocuments_lps);
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-$my_count = 0;
|
|
|
-foreach ($scorms as $mycourse => $my_paths) {
|
|
|
- $my_count += count($my_paths);
|
|
|
-}
|
|
|
-if ($loglevel > 0) { Log::notice("---- Scorms array now contains ".$mycount." paths to migrate. Starting migration..."); }
|
|
|
-
|
|
|
-
|
|
|
- * Looping through the SCO_MAIN table for SCORM learnpath attached to courses
|
|
|
- * Order by course to try and reuse the maximum data
|
|
|
- */
|
|
|
-$i_count = 0;
|
|
|
-foreach ($scorms as $my_course_code => $paths_list) {
|
|
|
- $max_dsp_lp = 0;
|
|
|
- $course_lp_done = array();
|
|
|
- $db_name = $courses_id_full_table_prefix_list[$my_course_code];
|
|
|
- foreach ($paths_list as $my_path => $old_id) {
|
|
|
- if ($loglevel > 1) { Log::notice("Migrating lp $my_path from course $my_course_code..."); }
|
|
|
- $i_count ++;
|
|
|
-
|
|
|
-
|
|
|
- $embedded = false;
|
|
|
- foreach ($course_lp_done as $tmp_lp) {
|
|
|
- if (empty($tmp_lp)) {
|
|
|
- $tmp_lp = '/';
|
|
|
- }
|
|
|
- if (strstr($my_path, $tmp_lp) === false) {
|
|
|
-
|
|
|
- } else {
|
|
|
-
|
|
|
- if ($loglevel > 1) { Log::notice("LP $my_path is embedded into $tmp_lp, ignoring..."); }
|
|
|
- $embedded = true;
|
|
|
- continue;
|
|
|
- }
|
|
|
- }
|
|
|
- if ($embedded) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- $course_lp_done[] = $my_path;
|
|
|
-
|
|
|
- $my_content_id = $old_id;
|
|
|
- $my_path = $my_path;
|
|
|
- $my_name = basename($my_path);
|
|
|
-
|
|
|
- if ($loglevel > 1) { Log::notice("Try importing LP $my_path from imsmanifest first as it is more reliable"); }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- $courses_dir = $upd_course_path.$courses_dir_list[$my_course_code];
|
|
|
- $sco_path_temp = ($my_path == '/') ? '' : $my_path;
|
|
|
- $sco_middle_path = (empty($sco_path_temp) ? '' : (substr($sco_path_temp, 0, 1) == '/') ? substr($sco_path_temp, 1).'/' : $sco_path_temp.'/');
|
|
|
- $ims = $courses_dir.'/scorm'.$sco_path_temp.'/imsmanifest.xml';
|
|
|
-
|
|
|
- if (is_file($ims)){
|
|
|
-
|
|
|
- $oScorm = new scorm();
|
|
|
-
|
|
|
-
|
|
|
- if ($loglevel > 1) { Log::notice("Found imsmanifest ($ims), importing..."); }
|
|
|
- if (!empty($sco_middle_path)) { $oScorm->subdir = $sco_middle_path; }
|
|
|
-
|
|
|
- $manifest = $oScorm->parse_manifest($ims);
|
|
|
-
|
|
|
- $oScorm->import_manifest($my_course_code);
|
|
|
-
|
|
|
-
|
|
|
- $lp_ids[$my_content_id] = $oScorm->lp_id;
|
|
|
- if ($loglevel > 1) { Log::notice(" @@@ Created scorm lp ".$oScorm->lp_id." from imsmanifest [".$ims."] in course $my_course_code"); }
|
|
|
- $lp_course[$my_content_id] = $courses_id_list[$my_course_code];
|
|
|
- $lp_course_code[$my_content_id] = $my_course_code;
|
|
|
- $max_dsp_lp++;
|
|
|
-
|
|
|
-
|
|
|
- * QUERY SCORM ITEMS FROM SCORM_SCO_DATA
|
|
|
- * The danger here is that we might have several users for the same data, and so
|
|
|
- * we have to avoid entering the same elements twice
|
|
|
- */
|
|
|
- $sql_items = "SELECT * FROM $scorm_item WHERE contentId = '".$my_content_id."' ORDER BY scoId";
|
|
|
-
|
|
|
- $res_items = Database::query($sql_items);
|
|
|
- while ($scormItem = Database::fetch_array($res_items)) {
|
|
|
- $my_sco_id = $scormItem['scoId'];
|
|
|
- $my_identifier = $scormItem['scoIdentifier'];
|
|
|
- $my_title = Database::escape_string($scormItem['scoTitle']);
|
|
|
- $my_status = $scormItem['status'];
|
|
|
- $my_student = $scormItem['studentId'];
|
|
|
- $my_score = $scormItem['score'];
|
|
|
- $my_time = my_get_time($scormItem['time']);
|
|
|
- $my_type = 'sco';
|
|
|
-
|
|
|
- $my_item_path = '';
|
|
|
-
|
|
|
-
|
|
|
- $my_new_lp_item = $db_name.$new_lp_item;
|
|
|
- $my_new_lp_view = $db_name.$new_lp_view;
|
|
|
- $my_new_lp_item_view = $db_name.$new_lp_item_view;
|
|
|
-
|
|
|
-
|
|
|
- * Check if a view is needed
|
|
|
- */
|
|
|
- if ($my_score != '' and $my_status != 'not attempted') {
|
|
|
-
|
|
|
- $sel_sqlb = "SELECT * FROM $my_new_lp_view " .
|
|
|
- "WHERE lp_id = ".$lp_ids[$my_content_id]." AND user_id = $my_student";
|
|
|
- $sel_resb = Database::query($sel_sqlb);
|
|
|
- if (Database::num_rows($sel_resb) > 0) {
|
|
|
-
|
|
|
- $rowb = Database::fetch_array($sel_resb);
|
|
|
- $view_insert_id = $rowb['id'];
|
|
|
- } else {
|
|
|
- $ins_sql = "INSERT INTO $my_new_lp_view (" .
|
|
|
- "lp_id," .
|
|
|
- "user_id," .
|
|
|
- "view_count" .
|
|
|
- ") VALUES (" .
|
|
|
- $lp_ids[$my_content_id].", " .
|
|
|
- $my_student.", " .
|
|
|
- "1" .
|
|
|
- ")";
|
|
|
-
|
|
|
- $ins_res = Database::query($ins_sql);
|
|
|
- $view_insert_id = Database::insert_id();
|
|
|
- }
|
|
|
- $sel_sqlc = "SELECT * FROM $my_new_lp_item " .
|
|
|
- "WHERE lp_id = ".$lp_ids[$my_content_id]." AND ref = '$my_identifier'";
|
|
|
- $sel_resc = Database::query($sel_sqlc);
|
|
|
- if (Database::num_rows($sel_resc) > 0) {
|
|
|
- $my_item_id_row = Database::fetch_array($sel_resc);
|
|
|
- $item_insert_id = $my_item_id_row['id'];
|
|
|
- $ins_sql = "INSERT INTO $my_new_lp_item_view (" .
|
|
|
- "lp_item_id, lp_view_id, view_count," .
|
|
|
- "start_time, total_time, score," .
|
|
|
- "status" .
|
|
|
- ") VALUES (" .
|
|
|
- "$item_insert_id, $view_insert_id, 1," .
|
|
|
- "0, $my_time, $my_score," .
|
|
|
- "'$my_status'" .
|
|
|
- ")";
|
|
|
-
|
|
|
- $ins_res = Database::query($ins_sql);
|
|
|
- } else {
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- } else {
|
|
|
-
|
|
|
- if ($loglevel > 1) { Log::notice("This is a normal SCORM path"); }
|
|
|
- $scorm_lp_paths[$my_content_id]['path'] = $my_path;
|
|
|
-
|
|
|
- $table_name = $db_name.$new_lp;
|
|
|
- $sql_ins = "INSERT INTO $table_name (" .
|
|
|
- "lp_type," .
|
|
|
- "name," .
|
|
|
- "description," .
|
|
|
- "path," .
|
|
|
- "force_commit, " .
|
|
|
- "default_encoding," .
|
|
|
- "display_order," .
|
|
|
- "content_maker," .
|
|
|
- "content_local," .
|
|
|
- "js_lib" .
|
|
|
- ") VALUES (" .
|
|
|
- "2," .
|
|
|
- "'$my_name'," .
|
|
|
- "''," .
|
|
|
- "'$my_path'," .
|
|
|
- "0," .
|
|
|
- "'UTF-8'," .
|
|
|
- "".$max_dsp_lp."," .
|
|
|
- "'Unknown'," .
|
|
|
- "'Unknown'," .
|
|
|
- "'scorm_api.php'" .
|
|
|
- ")";
|
|
|
- if ($loglevel > 1) { Log::notice("$sql_ins"); }
|
|
|
- $sql_res = Database::query($sql_ins);
|
|
|
- $in_id = Database::insert_id();
|
|
|
- if (!$in_id) die('Could not insert scorm lp: '.$sql_ins);
|
|
|
-
|
|
|
- $lp_ids[$my_content_id] = $in_id;
|
|
|
- $lp_course[$my_content_id] = $courses_id_list[$my_course_code];
|
|
|
- $lp_course_code[$my_content_id] = $my_course_code;
|
|
|
- $max_dsp_lp++;
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- $courses_dir = $sys_course_path.$courses_dir_list[$lp_course_code[$my_content_id]];
|
|
|
-
|
|
|
- $sco_path_temp = ($scorm_lp_paths[$my_content_id]['path'] == '/') ? '' : $scorm_lp_paths[$my_content_id]['path'];
|
|
|
- $scorm_lp_paths[$my_content_id]['ims'] = $courses_dir.'/scorm'.$sco_path_temp.'/imsmanifest.xml';
|
|
|
-
|
|
|
-
|
|
|
- $oScorm = new scorm();
|
|
|
-
|
|
|
-
|
|
|
- if (!is_file($scorm_lp_paths[$my_content_id]['ims'])) {
|
|
|
- if ($loglevel > 1) { Log::notice("!!! imsmanifest file not found at ".$scorm_lp_paths[$my_content_id]['ims'].' for old lp '.$my_content_id.' and new '.$lp_ids[$my_content_id]); }
|
|
|
- $manifest = false;
|
|
|
- } else {
|
|
|
-
|
|
|
-
|
|
|
- $manifest = $oScorm->parse_manifest($scorm_lp_paths[$my_content_id]['ims']);
|
|
|
-
|
|
|
-
|
|
|
- $my_lp_title = api_convert_encoding($oScorm->get_title(), 'ISO-8859-1', 'UTF-8');
|
|
|
- if (!empty($my_lp_title)) {
|
|
|
- $my_new_lp = $db_name.$new_lp;
|
|
|
- $my_sql = "UPDATE $my_new_lp " .
|
|
|
- "SET name = '$my_lp_title', " .
|
|
|
- "default_encoding = '".strtoupper($oScorm->manifest_encoding)."' " .
|
|
|
- "WHERE id = ".$lp_ids[$my_content_id];
|
|
|
- if ($loglevel > 1) { Log::notice("Updating title and encoding: ".$my_sql); }
|
|
|
- $my_res = Database::query($my_sql);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- * QUERY SCORM ITEMS FROM SCORM_SCO_DATA
|
|
|
- * The danger here is that we might have several users for the same data, and so
|
|
|
- * we have to avoid entering the same elements twice
|
|
|
- */
|
|
|
- $sql_items = "SELECT * FROM $scorm_item WHERE contentId = '".$my_content_id."' ORDER BY scoId";
|
|
|
-
|
|
|
- $res_items = Database::query($sql_items);
|
|
|
- while ($scormItem = Database::fetch_array($res_items)) {
|
|
|
- $my_sco_id = $scormItem['scoId'];
|
|
|
- $my_identifier = $scormItem['scoIdentifier'];
|
|
|
- $my_title = Database::escape_string($scormItem['scoTitle']);
|
|
|
- $my_status = $scormItem['status'];
|
|
|
- $my_student = $scormItem['studentId'];
|
|
|
- $my_score = $scormItem['score'];
|
|
|
- $my_time = my_get_time($scormItem['time']);
|
|
|
- $my_type = 'sco';
|
|
|
-
|
|
|
- $my_item_path = '';
|
|
|
-
|
|
|
-
|
|
|
- $my_new_lp_item = $db_name.$new_lp_item;
|
|
|
- $my_new_lp_view = $db_name.$new_lp_view;
|
|
|
- $my_new_lp_item_view = $db_name.$new_lp_item_view;
|
|
|
-
|
|
|
-
|
|
|
- * Query items from the new table to check if it doesn't exist already
|
|
|
- * Otherwise insert it
|
|
|
- */
|
|
|
- $sel_sql = "SELECT * FROM $my_new_lp_item " .
|
|
|
- "WHERE ref = '$my_identifier' " .
|
|
|
- "AND lp_id = ".$lp_ids[$my_content_id]."";
|
|
|
-
|
|
|
- $sel_res = Database::query($sel_sql);
|
|
|
- if (Database::num_rows($sel_res) > 0) {
|
|
|
-
|
|
|
- $row = Database::fetch_array($sel_res);
|
|
|
- $item_insert_id = $row['lp_id'];
|
|
|
- } else {
|
|
|
- $ins_sql = "INSERT INTO $my_new_lp_item (" .
|
|
|
- "lp_id," .
|
|
|
- "item_type," .
|
|
|
- "ref," .
|
|
|
- "title," .
|
|
|
- "path" .
|
|
|
- ") " .
|
|
|
- "VALUES (" .
|
|
|
- "'".$lp_ids[$my_content_id]."'," .
|
|
|
- "'$my_type'," .
|
|
|
- "'".$my_identifier."'," .
|
|
|
- "'".$my_title."'," .
|
|
|
- "'$my_item_path'" .
|
|
|
- ")";
|
|
|
- $ins_res = Database::query($ins_sql);
|
|
|
- $item_insert_id = Database::insert_id();
|
|
|
- $lp_item_ids[$lp_ids[$my_content_id]][$my_sco_id] = $item_insert_id;
|
|
|
- $lp_item_refs[$lp_ids[$my_content_id]][$my_identifier] = $item_insert_id;
|
|
|
- }
|
|
|
-
|
|
|
- * Check if a view is needed
|
|
|
- */
|
|
|
- if ($my_score != '' and $my_status != 'not attempted') {
|
|
|
-
|
|
|
- $sel_sqlb = "SELECT * FROM $my_new_lp_view " .
|
|
|
- "WHERE lp_id = ".$lp_ids[$my_content_id]." AND user_id = $my_student";
|
|
|
- $sel_resb = Database::query($sel_sqlb);
|
|
|
- if (Database::num_rows($sel_resb) > 0) {
|
|
|
-
|
|
|
- $rowb = Database::fetch_array($sel_resb);
|
|
|
- $view_insert_id = $rowb['id'];
|
|
|
- } else {
|
|
|
- $ins_sql = "INSERT INTO $my_new_lp_view (" .
|
|
|
- "lp_id," .
|
|
|
- "user_id," .
|
|
|
- "view_count" .
|
|
|
- ") VALUES (" .
|
|
|
- $lp_ids[$my_content_id].", " .
|
|
|
- $my_student.", " .
|
|
|
- "1" .
|
|
|
- ")";
|
|
|
- $ins_res = Database::query($ins_sql);
|
|
|
- $view_insert_id = Database::insert_id();
|
|
|
- }
|
|
|
- $ins_sql = "INSERT INTO $my_new_lp_item_view (" .
|
|
|
- "lp_item_id, lp_view_id, view_count," .
|
|
|
- "start_time, total_time, score," .
|
|
|
- "status" .
|
|
|
- ") VALUES (" .
|
|
|
- "$item_insert_id, $view_insert_id, 1," .
|
|
|
- "0, $my_time, $my_score," .
|
|
|
- "'$my_status'" .
|
|
|
- ")";
|
|
|
- $ins_res = Database::query($ins_sql);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (!empty($view_insert_id)) {
|
|
|
- $sql = "SELECT count(distinct(lp_item_id)) FROM $my_new_lp_item_view WHERE lp_view_id = ".$view_insert_id." AND status IN ('passed','completed','succeeded','browsed','failed')";
|
|
|
- $myres = Database::query($sql);
|
|
|
- $myrow = Database::fetch_array($myres);
|
|
|
- $completed = $myrow[0];
|
|
|
- $mylpid = $lp_ids[$my_content_id];
|
|
|
- $sql = "SELECT count(*) FROM $my_new_lp_item WHERE lp_id = '".$mylpid."'";
|
|
|
- $myres = Database::query($sql);
|
|
|
- $myrow = Database::fetch_array($myres);
|
|
|
- $total = $myrow[0];
|
|
|
- $progress = ((float)$completed / (float)$total) * 100;
|
|
|
- $progress = number_format($progress, 0);
|
|
|
- $sql = "UPDATE $my_new_lp_view SET progress = '$progress' WHERE id = '$view_insert_id'";
|
|
|
- $myres = Database::query($sql);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- * Set all information that might be more correct coming from imsmanifest
|
|
|
- */
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- $lp_details = array();
|
|
|
-
|
|
|
- $ordered_list = array();
|
|
|
- $mylist = array();
|
|
|
- foreach ($oScorm->organizations as $org) {
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- if (count($ordered_list) > 0) {
|
|
|
- break;
|
|
|
- }
|
|
|
- $ordered_list = $org->get_flat_items_list();
|
|
|
- }
|
|
|
- $previous = 0;
|
|
|
- $stock = array(0);
|
|
|
- $level = 0;
|
|
|
- $parent_id = 0;
|
|
|
- foreach ($ordered_list as $index => $subarray) {
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- if (!empty($lp_item_refs[$in_id][$subarray['identifier']])) {
|
|
|
- $new_id = $lp_item_refs[$in_id][$subarray['identifier']];
|
|
|
- $next = 0;
|
|
|
- $dsp = $subarray['rel_order'];
|
|
|
- if ($subarray['level'] > $level) {
|
|
|
-
|
|
|
- $parent_id = $previous;
|
|
|
- array_push($stock,$previous);
|
|
|
- $level = $subarray['level'];
|
|
|
- } elseif ($subarray['level'] == $level) {
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- } else {
|
|
|
-
|
|
|
- array_pop($stock);
|
|
|
- $parent_id = array_pop($stock);
|
|
|
- array_push($stock, $parent_id);
|
|
|
- $level = $subarray['level'];
|
|
|
- }
|
|
|
- if (!empty($ordered_list[$index + 1]['identifier']) && !empty($lp_item_refs[$in_id][$ordered_list[$index + 1]['identifier']])){
|
|
|
- $next = $lp_item_refs[$in_id][$ordered_list[$index + 1]['identifier']];
|
|
|
- }
|
|
|
- $path = $oScorm->get_res_path($subarray['identifierref']);
|
|
|
- $update_path = '';
|
|
|
- if (!empty($path)) {
|
|
|
-
|
|
|
- $update_path = "path = '$path', ";
|
|
|
- }
|
|
|
- $type = $oScorm->get_res_type($subarray['identifierref']);
|
|
|
- $update_type = '';
|
|
|
- if (!empty($type)) {
|
|
|
-
|
|
|
- $update_type = "item_type = '$type', ";
|
|
|
- }
|
|
|
- if (empty($path)) {
|
|
|
-
|
|
|
- $update_type = "item_type = 'dir', ";
|
|
|
- }
|
|
|
- $prereq = $subarray['prerequisites'];
|
|
|
- $update_prereq = '';
|
|
|
- if (!empty($prereq)) {
|
|
|
- $update_prereq = "prerequisite = '$prereq', ";
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- $sql2 = "UPDATE $my_new_lp_item " .
|
|
|
- "SET parent_item_id = $parent_id, " .
|
|
|
- "previous_item_id = $previous, " .
|
|
|
- "next_item_id = $next, " .
|
|
|
- $update_path.
|
|
|
- $update_type.
|
|
|
- $update_prereq.
|
|
|
- "display_order = $dsp " .
|
|
|
- "WHERE lp_id = ".$in_id." AND id = ".$new_id;
|
|
|
-
|
|
|
- $res2 = Database::query($sql2);
|
|
|
- $previous = $new_id;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- * Migrate links on the homepage as well now (look into the TABLE_TOOL_LIST table and
|
|
|
- * update the links to newscorm/lp_controller.php?action=view&lp_id=x)
|
|
|
- * See scorm_migrate_hometools.php
|
|
|
- */
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- * Update course description (intro page) to use new links instead of learnpath/learnpath_handler.php
|
|
|
- */
|
|
|
- $tbl_intro = $db_name.TABLE_TOOL_INTRO;
|
|
|
- $sql_i = "SELECT * FROM $tbl_intro WHERE id='course_homepage'";
|
|
|
- $res_i = Database::query($sql_i);
|
|
|
-
|
|
|
- while ($row_i = Database::fetch_array($res_i)) {
|
|
|
- $intro = $row_i['intro_text'];
|
|
|
- $out = array();
|
|
|
- $enc_path = str_replace('/', '%2F', $my_path);
|
|
|
- $enc_path = str_replace(' ', '\+', $enc_path);
|
|
|
-
|
|
|
- $pattern = '@claroline/scorm/scormdocument\.php([^\s"\']*)openDir='.$enc_path.'([\\"\'\s&]*)@';
|
|
|
- if (preg_match_all($pattern, $intro, $out, PREG_SET_ORDER)) {
|
|
|
- foreach ($out as $results) {
|
|
|
-
|
|
|
-
|
|
|
- $intro = preg_replace('@claroline/scorm/scormdocument\.php([^\s"\']*)openDir='.$enc_path.'([^\s"\']*)@','main/newscorm/lp_controller.php'.$results[1].'action=view&lp_id='.$lp_ids[$my_content_id], $intro);
|
|
|
- }
|
|
|
- } else {
|
|
|
-
|
|
|
- }
|
|
|
- $pattern = '@claroline/scorm/showinframes\.php([^\s"\']*)file=([^\s"\'&]*)'.$enc_path.'@';
|
|
|
- if (preg_match_all($pattern, $intro, $out, PREG_SET_ORDER)) {
|
|
|
- foreach ($out as $results) {
|
|
|
-
|
|
|
-
|
|
|
- $intro = preg_replace('@claroline/scorm/showinframes\.php([^\s"\']*)file=([^\s"\'&]*)'.$enc_path.'([^\s"\']*)@','main/newscorm/lp_controller.php'.$results[1].'action=view&lp_id='.$lp_ids[$my_content_id], $intro);
|
|
|
- }
|
|
|
- } else {
|
|
|
-
|
|
|
- }
|
|
|
- if ($intro != $row_i['intro_text']) {
|
|
|
-
|
|
|
- $sql_upd = "update $tbl_intro set intro_text = '".Database::escape_string($intro)."' WHERE id = 'course_homepage' AND intro_text = '".Database::escape_string($row_i['intro_text'])."'";
|
|
|
-
|
|
|
- fwrite($fh, $sql_upd."\n");
|
|
|
- fwrite($fh_revert, "UPDATE $tbl_intro set intro_text = '".$row_i['intro_text']."' WHERE id = 'course_homepage' AND intro_text = '$intro';\n");
|
|
|
- fwrite($fh_res, $intro."\n");
|
|
|
- Database::query($sql_upd);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- flush();
|
|
|
- }
|
|
|
-}
|
|
|
-fclose($fh);
|
|
|
-fclose($fh_revert);
|
|
|
-fclose($fh_res);
|
|
|
-if ($loglevel > 0) { Log::notice("All done!"); }
|
|
|
-
|