function JQ_editQuestion($id, $option, $qtype, $page, $course_id, $gqp = false) { global $JLMS_DB, $my, $JLMS_SESSION, $Itemid, $JLMS_CONFIG; if ($gqp && mosGetParam($_REQUEST, 'c_id')) { $query = "SELECT c_id FROM #__lms_quiz_t_question" . "\n WHERE c_id = '" . intval(mosGetParam($_REQUEST, 'c_id')) . "' AND course_id > 0 AND c_quiz_id > 0"; $JLMS_DB->setQuery($query); $c_id = $JLMS_DB->loadResult(); if ($c_id) { JLMSRedirect(sefRelToAbs("index.php?option={$option}&Itemid={$Itemid}&task=quizzes&page=setup_gqp")); } } $row = new mos_JoomQuiz_Question($JLMS_DB); $row->load($id); $quiz_id = intval(mosGetParam($_REQUEST, 'quiz_id', $JLMS_SESSION->get('quiz_id', 0))); $JLMS_ACL =& JLMSFactory::getACL(); if (!$JLMS_ACL->CheckPermissions('quizzes', 'manage')) { if ($JLMS_ACL->CheckPermissions('quizzes', 'manage_pool')) { $quiz_id = -1; if ($id) { if ($row->c_quiz_id == 0) { } else { JLMSRedirect(sefRelToAbs("index.php?option={$option}&Itemid={$Itemid}&task=quizzes&id={$course_id}&page=quizzes")); } } } } if ($id) { if ($row->c_quiz_id == 0) { $row->c_quiz_id = -1; } } elseif (mosGetParam($_REQUEST, 'level_id_0')) { $row->bind($_POST); /*Fix params (Max)*/ if (isset($row->params) && count($row->params)) { $row_params = $row->params; $row->params = ''; $i = 0; if (isset($row_params) && is_array($row_params) && count($row_params)) { foreach ($row_params as $key => $item) { $row->params .= $key . '=' . $item; if ($i < count($row_params)) { $row->params .= "\n"; } $i++; } } } /*Fix params (Max)*/ } else { // do stuff for new records $row->ordering = 0; $row->c_quiz_id = $quiz_id; //intval( mosGetParam( $_REQUEST, 'quiz_id', $JLMS_SESSION->get('quiz_id', 0 )) ); $row->c_type = intval(mosGetParam($_REQUEST, 'new_qtype_id', 1)); $row->c_question = "Enter question text here"; //$row->c_qcat = 0; } $params = new JLMSParameters($row->params); $params->def('disable_quest_feedback', 0); $params->def('survey_question', 0); $params->def('case_sensivity', 0); $lists = array(); $query = "SELECT c_id as value, c_category as text FROM #__lms_quiz_t_category WHERE course_id = '" . $course_id . "' AND is_quiz_cat = 0 order by c_category"; $JLMS_DB->setQuery($query); $jq_cats = array(); $jq_cats[] = mosHTML::makeOption(0, ' - ' . _JLMS_QUIZ_CAT_TYPE_QUEST . ' - '); $jq_cats = array_merge($jq_cats, $JLMS_DB->loadObjectList()); $lists['jq_categories'] = mosHTML::selectList($jq_cats, 'c_qcat', 'class="inputbox" size="1"', 'value', 'text', $row->c_qcat); $is_pool = false; if ($row->c_quiz_id == -1) { $is_pool = true; } $query = "SELECT a.ordering AS value, a.c_question AS text, a.c_type, a.c_id, a.c_pool, a.c_pool_gqp" . "\n FROM #__lms_quiz_t_question AS a" . "\n WHERE a.course_id = '" . $course_id . "' " . ($row->c_quiz_id ? "\n AND a.c_quiz_id = " . ($is_pool ? 0 : $row->c_quiz_id) : '') . "\n ORDER BY a.ordering, a.c_id"; //$text_new_order = _C M N_NEW_ITEM_FIRST; //if ( $id ) { if (true) { ### $chop = 30; $order = array(); $JLMS_DB->setQuery($query); $orders = $JLMS_DB->loadObjectList(); if (empty($orders)) { $order[] = mosHTML::makeOption(0, _JLMS_SB_FIRST_ITEM); } else { // QuestPool compatibility $q_from_pool = array(); foreach ($orders as $rowtmp) { if ($rowtmp->c_type == 20) { $q_from_pool[] = $rowtmp->c_pool; } } if (count($q_from_pool)) { $qp_ids = implode(',', $q_from_pool); $query = "SELECT a.* FROM #__lms_quiz_t_question as a" . "\n WHERE a.course_id = '" . $course_id . "' AND a.c_id IN ({$qp_ids})"; $JLMS_DB->setQuery($query); $orders2 = $JLMS_DB->loadObjectList(); for ($i = 0, $n = count($orders); $i < $n; $i++) { if ($orders[$i]->c_type == 20) { for ($j = 0, $m = count($orders2); $j < $m; $j++) { if ($orders[$i]->c_pool == $orders2[$j]->c_id) { $orders[$i]->text = $orders2[$j]->c_question; break; } } } } } // Global QuestPool compatibility $q_from_pool_gqp = array(); foreach ($orders as $rowtmp) { if ($rowtmp->c_type == 21) { $q_from_pool_gqp[] = $rowtmp->c_pool_gqp; } } if (count($q_from_pool_gqp)) { $qp_ids_gqp = implode(',', $q_from_pool_gqp); $query = "SELECT a.* FROM #__lms_quiz_t_question as a" . "\n WHERE a.course_id = 0 AND a.c_id IN ({$qp_ids_gqp})"; $JLMS_DB->setQuery($query); $orders2 = $JLMS_DB->loadObjectList(); for ($i = 0, $n = count($orders); $i < $n; $i++) { if ($orders[$i]->c_type == 21) { for ($j = 0, $m = count($orders2); $j < $m; $j++) { if ($orders[$i]->c_pool_gqp == $orders2[$j]->c_id) { $orders[$i]->text = $orders2[$j]->c_question; break; } } } } } $order[] = mosHTML::makeOption(0, '0 ' . _JLMS_SB_FIRST_ITEM); for ($i = 0, $n = count($orders); $i < $n; $i++) { $temp_txt = $orders[$i]->text; mosMakeHtmlSafe($temp_txt); $temp_txt = strip_tags($temp_txt); if (strlen($temp_txt) > $chop) { $text = substr($temp_txt, 0, $chop) . "..."; } else { $text = $temp_txt; } $order[] = mosHTML::makeOption($orders[$i]->c_id, $orders[$i]->value . ' (' . $text . ')'); } $order[] = mosHTML::makeOption(-1, $orders[$i - 1]->value + 1 . ' ' . _JLMS_SB_LAST_ITEM); } ### $ordering = mosHTML::selectList($order, 'q_ordering', 'class="inputbox" size="1"', 'value', 'text', intval($row->c_id ? $row->c_id : -1)); //set ordering to last element for new questions and without changes for existent questions } $lists['ordering'] = $ordering; $query = "SELECT c_id AS value, c_title AS text" . "\n FROM #__lms_quiz_t_quiz" . "\n WHERE course_id = '" . $course_id . "' " . "\n ORDER BY c_title"; $JLMS_DB->setQuery($query); $quizzes = array(); $quizzes[] = mosHTML::makeOption('-1', _JLMS_QUIZ_QUEST_POOL); $quizzes = array_merge($quizzes, $JLMS_DB->loadObjectList()); $quiz = mosHTML::selectList($quizzes, 'c_quiz_id', 'class="inputbox" size="1" ', 'value', 'text', intval($row->c_quiz_id)); $lists['quiz'] = $quiz; $lists['c_wrong_message'] = ''; $lists['c_right_message'] = ''; $query = "SELECT * FROM #__lms_quiz_t_question_fb WHERE quest_id = {$id}"; $JLMS_DB->SetQuery($query); $q_fbs = $JLMS_DB->LoadObjectList(); foreach ($q_fbs as $qfb) { if ($qfb->choice_id == -1) { $lists['c_wrong_message'] = $qfb->fb_text; } elseif (!$qfb->choice_id) { $lists['c_right_message'] = $qfb->fb_text; } } $JLMS_DB->SetQuery("SELECT c_qtype FROM #__lms_quiz_t_qtypes WHERE c_id = '" . $row->c_type . "'"); $qtype_str = $JLMS_DB->LoadResult(); $str = '_JLMS_QUIZ_QTYPE_' . $row->c_type; if (defined($str)) { $qtype_str = constant($str); } if (mosGetParam($_REQUEST, 'c_type')) { $row->c_type = mosGetParam($_REQUEST, 'c_type'); } //---------------------------------------kosmos if ($row->c_type == 21) { $javascript = 'onclick="read_filter();" onchange="javascript:write_filter();form.page.value=\'add_quest\';document.adminForm.submit();"'; } else { $javascript = 'onclick="read_filter();" onchange="javascript:write_filter();form.page.value=\'edit_quest_gqp\';document.adminForm.submit();"'; } //FLMS multicategories $levels = array(); //NEW MULTICAT if ($id) { $tmp_level = array(); $last_catid = 0; $i = 0; foreach ($_REQUEST as $key => $item) { if (preg_match('#level_id_(\\d+)#', $key, $result)) { if ($item) { $tmp_level[$i] = $result; $last_catid = $item; $i++; } } } if (!$i) { $query = "SELECT c_qcat FROM #__lms_quiz_t_question WHERE c_id = '" . $id . "'"; $JLMS_DB->setQuery($query); $last_catid = $JLMS_DB->loadResult(); } $tmp = array(); $tmp = JLMS_quiz_admin_class::JLMS_multicats($last_catid, $tmp); $tmp = array_reverse($tmp); $tmp_pop = $tmp; $tmp_p = array_pop($tmp_pop); if (count($tmp) && $tmp_p->catid) { $next = count($tmp); $tmp[$next] = new stdClass(); $tmp[$next]->catid = 0; $tmp[$next]->parent = $tmp_p->catid; } } else { $tmp_level = array(); $last_catid = 0; $exist_in_request = 0; $i = 0; foreach ($_REQUEST as $key => $item) { if (preg_match('#level_id_(\\d+)#', $key, $result)) { if (isset($item)) { $exist_in_request = 1; if ($item) { $tmp_level[$i] = $result; $last_catid = intval($item); $i++; } } } } if (!$last_catid && !$exist_in_request) { $last_catid = $JLMS_SESSION->get('S_last_catid'); } $JLMS_SESSION->set('S_last_catid', $last_catid); $tmp = array(); $tmp = JLMS_quiz_admin_class::JLMS_multicats($last_catid, $tmp); $tmp = array_reverse($tmp); $tmp_pop = $tmp; $tmp_p = array_pop($tmp_pop); if (count($tmp) && $tmp_p->catid) { $next = count($tmp); $tmp[$next] = new stdClass(); $tmp[$next]->catid = 0; $tmp[$next]->parent = isset($tmp_p->catid) ? $tmp_p->catid : 0; } } /* $query = "SELECT * FROM #__lms_gqp_cats_config ORDER BY id"; $JLMS_DB->setQuery($query); $levels = $JLMS_DB->loadObjectList(); */ if (count($levels) == 0) { for ($i = 0; $i < 15; $i++) { $num = $i + 1; if ($i > 0) { // $levels[$i]->cat_name = _JLMS_COURSES_COURSES_GROUPS; $levels[$i]->cat_name = 'Level #' . $num; } else { // $levels[$i]->cat_name = _JLMS_COURSES_COURSES_GROUPS; $levels[$i]->cat_name = 'Level #' . $num; } } } $level_id = array(); for ($i = 0; $i < count($levels); $i++) { if ($i == 0) { $level_id[$i] = intval(mosGetParam($_REQUEST, 'level_id_' . $i, 0)); $_REQUEST['level_id_' . $i] = $level_id[$i]; $JLMS_SESSION->set('GQP_level_id_' . $i, $level_id[$i]); } else { $level_id[$i] = intval(mosGetParam($_REQUEST, 'level_id_' . $i, $JLMS_SESSION->get('GQP_level_id_' . $i, 0))); $_REQUEST['level_id_' . $i] = $level_id[$i]; $JLMS_SESSION->set('GQP_level_id_' . $i, $level_id[$i]); } if ($i == 0) { $parent_id[$i] = 0; } else { $parent_id[$i] = $level_id[$i - 1]; } $query = "SELECT count(id) FROM `#__lms_gqp_cats` WHERE parent = '" . $parent_id[$i] . "' ORDER BY c_category"; $JLMS_DB->setQuery($query); $groups = $JLMS_DB->loadResult(); if ($groups == 0) { $level_id[$i] = 0; $JLMS_SESSION->set('GQP_level_id_' . $i, $level_id[$i]); } } for ($i = 0; $i < count($levels); $i++) { if ($i > 0 && $level_id[$i - 1] == 0) { $level_id[$i] = 0; $_REQUEST['level_id_' . $i] = $level_id[$i]; $JLMS_SESSION->set('GQP_level_id_' . $i, $level_id[$i]); $parent_id[$i] = 0; } elseif ($i == 0 && $level_id[$i] == 0) { $level_id[$i] = 0; $_REQUEST['level_id_' . $i] = $level_id[$i]; $JLMS_SESSION->set('GQP_level_id_' . $i, $level_id[$i]); $parent_id[$i] = 0; } } for ($i = 0; $i < count($levels); $i++) { if ($i == 0 || isset($tmp[$i]->parent) && $tmp[$i]->parent) { //(Max): extra requests $query = "SELECT * FROM `#__lms_gqp_cats` WHERE parent = '" . $tmp[$i]->parent . "' ORDER BY c_category"; $JLMS_DB->setQuery($query); $groups = $JLMS_DB->loadObjectList(); if ($tmp[$i]->parent && $i > 0 && count($groups)) { $type_level[$i][] = mosHTML::makeOption(0, ' '); foreach ($groups as $group) { $type_level[$i][] = mosHTML::makeOption($group->id, $group->c_category); } $lists['level_' . $i] = mosHTML::selectList($type_level[$i], 'level_id_' . $i, 'class="inputbox" size="1" style="width:266px;" ' . $javascript, 'value', 'text', $tmp[$i]->catid); } elseif ($i == 0) { $type_level[$i][] = mosHTML::makeOption(0, ' '); foreach ($groups as $group) { $type_level[$i][] = mosHTML::makeOption($group->id, $group->c_category); } $lists['level_' . $i] = mosHTML::selectList($type_level[$i], 'level_id_' . $i, 'class="inputbox" size="1" style="width:266px;" ' . $javascript, 'value', 'text', $tmp[$i]->catid); } } } $multicat = array(); $i = 0; foreach ($lists as $key => $item) { if (substr($key, 0, 6) == 'level_') { $multicat[] = $lists['level_' . $i]; $i++; } } $data = new stdClass(); $i = 0; foreach ($multicat as $m) { if (isset($level_id[$i])) { $str_preobj = 'level_' . $i; $data->{$str_preobj} = $level_id[$i]; } $i++; } $lists['data'] = $data; //---------------------------------------------- //echo $row->c_type; die; switch ($row->c_type) { case 1: case 12: if ($row->c_type == 12) { $query = "SELECT a.*, b.imgs_name FROM #__lms_quiz_t_choice as a, #__lms_quiz_images as b WHERE a.c_question_id = '" . $row->c_id . "' AND b.imgs_id = a.c_choice ORDER BY a.ordering"; } else { $query = "SELECT * FROM #__lms_quiz_t_choice WHERE c_question_id = '" . $row->c_id . "' ORDER BY ordering"; $lists['random_answers'] = mosHTML::yesnoradioList('params[random_answers]', '', $params->get('random_answers', 0)); } $JLMS_DB->SetQuery($query); $row->choices = array(); $row->choices = $JLMS_DB->LoadObjectList(); if ($row->c_type == 12) { $query = "SELECT imgs_id, imgs_name, c_id as i_id FROM #__lms_quiz_images WHERE course_id = '" . $course_id . "'"; $JLMS_DB->SetQuery($query); $row->images = array(); $row->images = $JLMS_DB->LoadObjectList(); } $q_om_type = $row->c_type; JLMS_quiz_admin_html_class::JQ_editQuest_MChoice($row, $lists, $option, $page, $course_id, $q_om_type, $qtype_str, $params, $id, $gqp, $levels); break; case 2: case 13: if ($row->c_type == 13) { $query = "SELECT a.*, b.imgs_name FROM #__lms_quiz_t_choice as a, #__lms_quiz_images as b WHERE a.c_question_id = '" . $row->c_id . "' AND b.imgs_id = a.c_choice ORDER BY a.ordering"; } else { $query = "SELECT * FROM #__lms_quiz_t_choice WHERE c_question_id = '" . $row->c_id . "' ORDER BY ordering"; $lists['random_answers'] = mosHTML::yesnoradioList('params[random_answers]', '', $params->get('random_answers', 0)); } $JLMS_DB->SetQuery($query); $row->choices = array(); $row->choices = $JLMS_DB->LoadObjectList(); if ($row->c_type == 13) { $query = "SELECT imgs_id, imgs_name, c_id as i_id FROM #__lms_quiz_images WHERE course_id = '" . $course_id . "'"; $JLMS_DB->SetQuery($query); $row->images = array(); $row->images = $JLMS_DB->LoadObjectList(); } $q_om_type = $row->c_type; JLMS_quiz_admin_html_class::JQ_editQuest_MChoice($row, $lists, $option, $page, $course_id, $q_om_type, $qtype_str, $params, $id, $gqp, $levels); break; case 3: $query = "SELECT * FROM #__lms_quiz_t_choice WHERE c_question_id = '" . $row->c_id . "' ORDER BY ordering"; $JLMS_DB->SetQuery($query); $row->choices = array(); $row->choices = $JLMS_DB->LoadObjectList(); $row->choice_true = 1; foreach ($row->choices as $eee) { if (strtolower($eee->c_choice) == "false" && $eee->c_right == 1) { $row->choice_true = 0; } } JLMS_quiz_admin_html_class::JQ_editQuest_TrueFalse($row, $lists, $option, $page, $course_id, 3, $qtype_str, $params, $id, $gqp, $levels); break; case 4: $query = "SELECT * FROM #__lms_quiz_t_matching WHERE c_question_id = '" . $row->c_id . "' ORDER BY ordering"; $JLMS_DB->SetQuery($query); $row->matching = array(); $row->matching = $JLMS_DB->LoadObjectList(); JLMS_quiz_admin_html_class::JQ_editQuest_MDragDrop($row, $lists, $option, $page, $course_id, 4, $qtype_str, $params, $id, $gqp, $levels); break; case 5: $query = "SELECT * FROM #__lms_quiz_t_matching WHERE c_question_id = '" . $row->c_id . "' ORDER BY ordering"; $JLMS_DB->SetQuery($query); $row->matching = array(); $row->matching = $JLMS_DB->LoadObjectList(); JLMS_quiz_admin_html_class::JQ_editQuest_MDragDrop($row, $lists, $option, $page, $course_id, 5, $qtype_str, $params, $id, $gqp, $levels); break; case 6: $query = "SELECT b.*,a.c_default FROM #__lms_quiz_t_blank as a, #__lms_quiz_t_text as b WHERE a.c_question_id = '" . $row->c_id . "' and b.c_blank_id = a.c_id ORDER BY b.ordering"; $JLMS_DB->SetQuery($query); $row->blank_data = array(); $row->blank_data = $JLMS_DB->LoadObjectList(); $query = "SELECT c_default FROM #__lms_quiz_t_blank WHERE c_question_id = '" . $row->c_id . "'"; $JLMS_DB->SetQuery($query); $lists['c_def'] = $JLMS_DB->LoadResult(); JLMS_quiz_admin_html_class::JQ_editQuest_Blank($row, $lists, $option, $page, $course_id, 6, $qtype_str, $params, $id, $gqp, $levels); break; case 7: $directory_js = $JLMS_CONFIG->get('live_site') . '/images/joomlaquiz/images/'; $directory = 'images/joomlaquiz/images/'; $javascript = "onchange=\"javascript:if (document.adminForm.c_image.options[selectedIndex].value!='') {" . " document.imagelib.src='{$directory}' + document.adminForm.c_image.options[selectedIndex].value; } else {" . " document.imagelib.src='" . $JLMS_CONFIG->get('live_site') . "/images/blank.png'}\""; $imageFiles = mosReadDirectory($JLMS_CONFIG->get('absolute_path') . '/' . $directory); $images = array(mosHTML::makeOption('', '- Select Image -')); foreach ($imageFiles as $file) { if (preg_match("/bmp|gif|jpg|png/i", $file)) { $images[] = mosHTML::makeOption($file); } } $lists['images'] = mosHTML::selectList($images, 'c_image', 'class="inputbox" size="1" ' . $javascript, 'value', 'text', $row->c_image); //$lists['images'] = mosAdminMenus::images('c_image', $row->c_image, $javascript, $directory); $query = "SELECT * FROM #__lms_quiz_t_hotspot WHERE c_question_id = '" . $row->c_id . "'"; $JLMS_DB->SetQuery($query); $row->hotspot_data = array(); $row->hotspot_data = $JLMS_DB->LoadObjectList(); JLMS_quiz_admin_html_class::JQ_editQuest_HotSpot($row, $lists, $option, $page, $course_id, 7, $qtype_str, $params, $id, $gqp, $levels); break; case 8: JLMS_quiz_admin_html_class::JQ_editQuest_Survey($row, $lists, $option, $page, $course_id, 8, $qtype_str, $params, $id, $gqp, $levels); break; case 9: $query = "SELECT * FROM #__lms_quiz_t_scale WHERE c_question_id = '" . $row->c_id . "' ORDER BY ordering"; $JLMS_DB->SetQuery($query); $row->scale = array(); $row->scale = $JLMS_DB->LoadObjectList(); JLMS_quiz_admin_html_class::JQ_editQuest_Scale($row, $lists, $option, $page, $course_id, 9, $qtype_str, $params, $id, $gqp, $levels); break; case 10: JLMS_quiz_admin_html_class::JQ_editQuest_Boilerplate($row, $lists, $option, $page, $course_id, 10, $qtype_str, $params, $id, $gqp, $levels); break; case 11: $query = "SELECT a.*, b.imgs_name as left_name, c.imgs_name as right_name FROM #__lms_quiz_t_matching as a, #__lms_quiz_images as b, #__lms_quiz_images as c WHERE a.c_question_id = '" . $row->c_id . "' AND b.imgs_id = a.c_left_text AND c.imgs_id = a.c_right_text ORDER BY a.ordering"; $JLMS_DB->SetQuery($query); $row->matching = array(); $row->matching = $JLMS_DB->LoadObjectList(); $query = "SELECT imgs_id, imgs_name, c_id as i_id FROM #__lms_quiz_images WHERE course_id = '" . $course_id . "'"; $JLMS_DB->SetQuery($query); $row->images = array(); $row->images = $JLMS_DB->LoadObjectList(); JLMS_quiz_admin_html_class::JQ_editQuest_MDragDrop2($row, $lists, $option, $page, $course_id, 11, $qtype_str, $params, $id, $gqp, $levels); break; case 20: //add question from pool $query = "SELECT a.c_id AS value, a.c_question AS text" . "\n FROM #__lms_quiz_t_question AS a" . "\n WHERE a.course_id = '" . $course_id . "' " . "\n AND a.c_quiz_id = 0" . "\n ORDER BY a.ordering"; $qp_array = array(); $JLMS_DB->setQuery($query); $qp_list = $JLMS_DB->loadObjectList(); $qp_array[] = mosHTML::makeOption(0, '- Select question -'); for ($i = 0, $n = count($qp_list); $i < $n; $i++) { if (strlen(strip_tags($qp_list[$i]->text)) > 30) { $text = substr(strip_tags($qp_list[$i]->text), 0, 30) . "..."; } else { $text = strip_tags($qp_list[$i]->text); } $qp_array[] = mosHTML::makeOption($qp_list[$i]->value, $text); } $pool_quests = mosHTML::selectList($qp_array, 'c_pool', 'class="inputbox" size="1"', 'value', 'text', intval($row->c_pool)); $lists['pool_quests'] = $pool_quests; JLMS_quiz_admin_html_class::JQ_editQuest_Pool($row, $lists, $option, $page, $course_id, 20, $qtype_str); break; case 21: //add question from pool if (!$row->c_id) { $limit = intval(mosGetParam($_GET, 'limit', $JLMS_SESSION->get('list_limit', $JLMS_CONFIG->get('list_limit')))); $JLMS_SESSION->set('list_limit', $limit); $limitstart = intval(mosGetParam($_REQUEST, 'limitstart', 0)); $qtype_id = mosGetParam($_REQUEST, 'qtype_id', 0); $query = "SELECT c_pool_gqp" . "\n FROM #__lms_quiz_t_question" . "\n WHERE c_pool_gqp > 0 AND c_quiz_id = {$quiz_id}"; $JLMS_DB->setQuery($query); $result_array = $JLMS_DB->loadResultArray(); $use_ids = implode(',', $result_array); if ($use_ids) { $sql_use_ids = "\n AND a.c_id NOT IN ( {$use_ids} )"; } else { $sql_use_ids = ''; } $str = ''; //NEW MUSLTICATS /* $tmp_level = array(); $last_catid = 0; if(isset($_REQUEST['category_filter']) && $_REQUEST['category_filter']){ $last_catid = $_REQUEST['category_filter']; } else { $i=0; foreach($_REQUEST as $key=>$item){ if(preg_match('#level_id_(\d+)#', $key, $result)){ if($item){ $tmp_level[$i] = $result; $last_catid = $item; $i++; } } } } */ $query = "SELECT * FROM #__lms_gqp_cats" . "\n ORDER BY id"; $JLMS_DB->setQuery($query); $all_cats = $JLMS_DB->loadObjectList(); $tmp_cats_filter = array(); $children = array(); foreach ($all_cats as $cat) { $pt = $cat->parent; $list = @$children[$pt] ? $children[$pt] : array(); array_push($list, $cat->id); $children[$pt] = $list; } $tmp_cats_filter[0] = $last_catid; $i = 1; foreach ($children as $key => $childs) { if ($last_catid == $key) { foreach ($children[$key] as $v) { if (!in_array($v, $tmp_cats_filter)) { $tmp_cats_filter[$i] = $v; $i++; } } } } foreach ($children as $key => $childs) { if (in_array($key, $tmp_cats_filter)) { foreach ($children[$key] as $v) { if (!in_array($v, $tmp_cats_filter)) { $tmp_cats_filter[$i] = $v; $i++; } } } } $tmp_cats_filter = array_unique($tmp_cats_filter); $catids = implode(",", $tmp_cats_filter); if ($last_catid && count($tmp_cats_filter)) { $str .= "\n AND a.c_qcat IN (" . $catids . ")"; } //NEW MUSLTICATS /*Old kosmosa for ($i=count($level_id);$i>-1;$i--) { if(isset($level_id[$i]) && $level_id[$i]) { $str = "\n AND d.cat_id = ".$level_id[$i]." AND d.level = $i"; break; } } */ $qp_array = array(); $query = "SELECT a.*, b.c_qtype as qtype_full, qc1.c_category" . "\n FROM #__lms_quiz_t_question AS a" . "\n LEFT JOIN #__lms_quiz_t_qtypes b ON b.c_id = a.c_type" . "\n LEFT JOIN #__lms_quiz_t_category as qc ON a.c_qcat = qc.c_id" . "\n LEFT JOIN #__lms_gqp_cats AS qc1 ON a.c_qcat = qc1.id" . "\n WHERE a.course_id = 0 " . "\n AND a.c_quiz_id = 0" . "\n AND a.published = 1" . ($str ? $str : ' ') . ($sql_use_ids ? $sql_use_ids : ' ') . ($qtype_id ? "\n AND a.c_type = '" . $qtype_id . "'" : '') . "\n GROUP BY a.c_id" . "\n ORDER BY a.ordering"; $JLMS_DB->setQuery($query); $JLMS_DB->query(); $total = $JLMS_DB->getNumRows(); require_once _JOOMLMS_FRONT_HOME . DS . "includes" . DS . "classes" . DS . "lms.pagination.php"; $pageNav = new JLMSPageNav($total, $limitstart, $limit); $JLMS_DB->setQuery($query, $pageNav->limitstart, $pageNav->limit); $rows = $JLMS_DB->loadObjectList(); //Tooltip Right Answer (Max - 15.04.2011) for ($i = 0; $i < count($rows); $i++) { if (in_array($rows[$i]->c_type, array(1, 2, 3))) { $right_answer = ''; $query = "SELECT c_choice" . "\n FROM" . "\n #__lms_quiz_t_choice" . "\n WHERE 1" . "\n AND c_right = 1" . "\n AND c_question_id = '" . $rows[$i]->c_id . "'"; $JLMS_DB->setQuery($query); $right_answer = $JLMS_DB->loadResult(); if (strlen($right_answer)) { $rows[$i]->right_answer = $right_answer; } } else { if (in_array($rows[$i]->c_type, array(20, 21))) { if ($rows[$i]->c_type == 20) { $select_field = "c_pool"; } else { if ($rows[$i]->c_type == 21) { $select_field = "c_pool_gqp"; } } $query = "SELECT " . $select_field . "\n FROM" . "\n #__lms_quiz_t_question" . "\n WHERE 1" . "\n AND c_id = '" . $rows[$i]->c_id . "'"; $JLMS_DB->setQuery($query); $question_id = $JLMS_DB->loadResult(); $right_answer = ''; if (intval($question_id)) { $query = "SELECT b.c_choice" . "\n FROM" . "\n #__lms_quiz_t_question as a" . "\n, #__lms_quiz_t_choice as b" . "\n WHERE 1" . "\n AND a.c_id = '" . $question_id . "'" . "\n AND b.c_question_id = '" . $question_id . "'" . "\n AND a.c_type IN (" . implode(',', array(1, 2, 3)) . ")" . "\n AND b.c_right = 1"; $JLMS_DB->setQuery($query); $right_answer = $JLMS_DB->loadResult(); } if (strlen($right_answer)) { $rows[$i]->right_answer = $right_answer; } } } } //Tooltip Right Answer (Max - 15.04.2011) /*old kosmosa if(mosGetParam($_REQUEST,'filter_id_0') || isset($_SESSION['GQP_filter_id_0'])) { for($i=0;$i<count($rows);$i++) { $new_level = $rows[$i]->level+1; $query = "SELECT b.c_category FROM #__lms_gqp_levels AS a, #__lms_gqp_cats AS b WHERE a.quest_id = '".$rows[$i]->c_id."' AND a.cat_id = b.id AND a.level = '".$new_level."'"; $JLMS_DB->SetQuery($query); $cat_name = $JLMS_DB->LoadResult(); if($cat_name) { $rows[$i]->c_category = $cat_name; } } } */ // $qp_array[] = mosHTML::makeOption( 0, '- Select question -' ); // for ($i=0, $n=count( $rows ); $i < $n; $i++) { // if (strlen($rows[$i]->text) > 30) { // $text = substr($rows[$i]->text,0,30)."..."; // } else { // $text = $qp_list[$i]->text; // } // $qp_array[] = mosHTML::makeOption( $qp_list[$i]->value, $text ); // } // $pool_quests = mosHTML::selectList( $qp_array, 'c_pool', 'class="inputbox" size="1"', 'value', 'text', intval( $row->c_pool ) ); // $lists['pool_quests'] = $pool_quests; $query = "SELECT c_id AS value, c_qtype AS text" . "\n FROM #__lms_quiz_t_qtypes" . "\n ORDER BY c_id"; $JLMS_DB->setQuery($query); $qtypes_lang = $JLMS_DB->loadObjectList(); for ($i = 0; $i < count($qtypes_lang); $i++) { $j = $i + 1; $str = '_JLMS_QUIZ_QTYPE_' . $j; if (defined($str)) { $qtypes_lang[$i]->value = $j; $qtypes_lang[$i]->text = constant($str); } } $qtypes[] = mosHTML::makeOption('0', _JLMS_SB_QUIZ_SELECT_QTYPE); $qtypes = array_merge($qtypes, $qtypes_lang); $qtype = mosHTML::selectList($qtypes, 'qtype_id', 'class="inputbox" style="width:200px" size="1" ' . $javascript, 'value', 'text', $qtype_id); $lists['qtype'] = $qtype; $lists['qtype_id'] = $qtype_id; $lists['published'] = mosHTML::yesnoradioList('published', '', 1); JLMS_quiz_admin_html_class::JQ_editQuest_Pool_GQP($row, $lists, $option, $page, $course_id, 21, $qtype_str, $rows, $pageNav, $levels); } else { // $query = "SELECT a.c_id AS value, a.c_question AS text" // . "\n FROM #__lms_quiz_t_question AS a " // . "\n , #__lms_gqp_levels d, #__lms_gqp_cats qc1" // . "\n WHERE a.course_id = 0 " // . "\n AND a.c_quiz_id = 0" // . "\n AND d.quest_id = a.c_id AND d.cat_id =qc1.id " // . "\n GROUP BY d.quest_id" // . "\n ORDER BY a.ordering" // ; // // $qp_array = array(); // $JLMS_DB->setQuery( $query ); // $qp_list = $JLMS_DB->loadObjectList(); // // $qp_array[] = mosHTML::makeOption( 0, '- Select question -' ); // // for ($i=0, $n=count( $qp_list ); $i < $n; $i++) { // if (strlen($qp_list[$i]->text) > 30) { // $text = substr($qp_list[$i]->text,0,30)."..."; // } else { // $text = $qp_list[$i]->text; // } // $qp_array[] = mosHTML::makeOption( $qp_list[$i]->value, $text ); // } // // $pool_quests = mosHTML::selectList( $qp_array, 'c_pool', 'class="inputbox" size="1"', 'value', 'text', intval( $row->c_pool_gqp ) ); // $lists['pool_quests'] = $pool_quests; // JLMS_quiz_admin_html_class::JQ_editQuest_Pool_gqp_edit($row, $lists, $option, $page, $course_id, 21, $qtype_str); } break; } }
function JLMS_courseImport_main($backupfile, $option, $course_id, $imp_tools, $course_zname = '', $is_template = false) { global $JLMS_DB, $JLMS_CONFIG, $my; if (!$backupfile) { mosErrorAlert(_JLMS_EM_SELECT_FILE); } $backupfile_name = $backupfile['name']; $filename = explode(".", $backupfile_name); if (empty($backupfile_name)) { mosErrorAlert(_JLMS_EM_SELECT_FILE); } //commented (12.01.2007 Bjarne request forum post #331) #if (eregi("[^0-9a-zA-Z_]", $filename[0])) { # mosErrorAlert("File must only contain alphanumeric characters and no special symbols and spaces please."); #} if (strcmp(substr($backupfile_name, -4, 1), ".")) { mosErrorAlert(_JLMS_EM_BAD_FILEEXT); } if (strcmp(substr($backupfile_name, -4), ".zip")) { mosErrorAlert(_JLMS_EM_BAD_FILEEXT); } $tmp_name = $backupfile['tmp_name']; if (!file_exists($tmp_name)) { mosErrorAlert(_JLMS_EM_UPLOAD_SIZE_ERROR); } if (preg_match("/.zip\$/", strtolower($backupfile_name))) { $zipFile = new pclZip($tmp_name); $zipContentArray = $zipFile->listContent(); $exp_xml_file = false; if (!empty($zipContentArray)) { foreach ($zipContentArray as $thisContent) { if (preg_match('~.(php.*|phtml)$~i', $thisContent['filename'])) { mosErrorAlert(_JLMS_EM_READ_PACKAGE_ERROR); } if ($thisContent['filename'] == 'export.xml') { $exp_xml_file = true; } } } if ($exp_xml_file == false) { mosErrorAlert("Could not find a Course XML setup file in the package."); } } else { mosErrorAlert(_JLMS_EM_BAD_FILEEXT); } $config =& JFactory::getConfig(); $tmp_dest = $config->getValue('config.tmp_path') . DS . $backupfile['name']; $tmp_src = $backupfile['tmp_name']; // Move uploaded file jimport('joomla.filesystem.file'); if ($is_template) { $uploaded = JFile::copy($tmp_src, $tmp_dest); } else { $uploaded = JFile::upload($tmp_src, $tmp_dest); } $extract_dir = $config->getValue('config.tmp_path') . DS . "course_backup_" . uniqid(rand(), true) . DS; $archive = $tmp_dest; //$JLMS_CONFIG->getCfg('absolute_path')."/media/".$backupfile['name']; if (!is_file($archive)) { $archive = $backupfile['tmp_name']; } //exstract archive in uniqfolder media JLMS_Zip::extractFile($archive, $extract_dir); $xmlFile = $extract_dir . "export.xml"; $xmlDoc =& JLMSFactory::getXMLParser(); //$xmlDoc->resolveErrors( true ); if (!$xmlDoc->loadFile($xmlFile)) { echo "<script> alert('Error during reading xml file'); window.history.go(-1); </script>\n"; exit; } $root =& $xmlDoc->document; if ($root->name() != 'course_backup') { echo "<script> alert('Not a Course installation file'); window.history.go(-1); </script>\n"; exit; } $course = new stdClass(); // **************************************************************************************************** //get config values $query = "SELECT * FROM `#__lms_config`"; $JLMS_DB->SetQuery($query); $lms_cfg = $JLMS_DB->LoadObjectList(); $lms_cfg_doc_folder = ''; $lms_cfg_scorm = ''; $lms_cfg_backup_folder = ''; $lms_cfg_quiz_enabled = 0; foreach ($lms_cfg as $lcf) { if ($lcf->lms_config_var == 'plugin_quiz') { $lms_cfg_quiz_enabled = $lcf->lms_config_value; } elseif ($lcf->lms_config_var == 'jlms_doc_folder') { $lms_cfg_doc_folder = $lcf->lms_config_value; } elseif ($lcf->lms_config_var == 'scorm_folder') { $lms_cfg_scorm = $lcf->lms_config_value; } elseif ($lcf->lms_config_var == 'jlms_backup_folder') { $lms_cfg_backup_folder = $lcf->lms_config_value; } } // **************************************************************************************************** // Get course DATA and insert it into the 'lms_courses' table if (!$course_id) { $element =& $root->getElementByPath('name'); if (!$course_zname) { $course->course_name = $element ? $element->data() : ''; } else { $course->course_name = $course_zname; } if ($course->course_name) { $element =& $root->getElementByPath('description'); $course->course_description = $element ? $element->data() : ''; // echo $xmlDoc->getErrorString(); // var_dump($course->course_description); die; $element =& $root->getElementByPath('metadesc'); $course->metadesc = $element ? $element->data() : ''; $element =& $root->getElementByPath('metakeys'); $course->metakeys = $element ? $element->data() : ''; $element =& $root->getElementByPath('self_registration'); $course->self_reg = $element ? $element->data() : ''; $element =& $root->getElementByPath('course_paid'); $course->paid = $element ? $element->data() : 0; $course->add_forum = 0; $course->add_chat = 0; $course->owner_id = $my->id; $course->published = 0; $element =& $root->getElementByPath('publish_start'); $course->publish_start = $element ? $element->data() : 0; $element =& $root->getElementByPath('publish_end'); $course->publish_end = $element ? $element->data() : 0; $element =& $root->getElementByPath('publish_start_date'); $course->start_date = $element ? $element->data() : '0000-00-00'; $element =& $root->getElementByPath('publish_end_date'); $course->end_date = $element ? $element->data() : '0000-00-00'; $element =& $root->getElementByPath('spec_reg'); $course->spec_reg = $element ? $element->data() : 0; $course->cat_id = 0; $element =& $root->getElementByPath('course_category'); $course_category_txt = $element ? $element->data() : ''; $element =& $root->getElementByPath('course_question'); $course_question_txt = $element ? $element->data() : ''; // 02.03.2007 1.0.1 support $element =& $root->getElementByPath('course_params'); $params_txt = $element ? $element->data() : ''; $course->params = ''; $params = new JLMSParameters($params_txt); $params->def('lpath_redirect', 0); $params->def('agenda_view', 0); $params->def('dropbox_view', 0); $params->def('homework_view', 0); $params->def('learn_path', 0); $course_redirect_lp = $params->get('learn_path'); $params->set('learn_path', 0); $params_ar = $params->toArray(); if (is_array($params_ar)) { foreach ($params_ar as $k => $v) { $txt[] = "{$k}={$v}"; } $course->params = implode("\n", $txt); } // to do: // check lpath_redirect parameter !!!!!!!!! $course->gid = 0; if ($course_category_txt) { $query = "SELECT id FROM #__lms_course_cats WHERE c_category = '" . $course_category_txt . "'"; $JLMS_DB->SetQuery($query); $course_cat_id = $JLMS_DB->LoadResult(); if ($course_cat_id) { $course->cat_id = $course_cat_id; } } $course->language = 0; $element =& $root->getElementByPath('language_name'); $course_lang_txt = $element ? $element->data() : ''; if ($course_lang_txt) { $query = "SELECT id FROM #__lms_languages WHERE lang_name = '" . $course_lang_txt . "'"; $JLMS_DB->SetQuery($query); $course_lang_id = $JLMS_DB->LoadResult(); if ($course_lang_id) { $course->language = $course_lang_id; } } $JLMS_DB->insertObject("#__lms_courses", $course, "id"); //get new Course_id $course_id = $JLMS_DB->insertid(); $is_new_course = true; $default_teacher_role = 0; $query = "SELECT id FROM #__lms_usertypes WHERE roletype_id = 2 AND default_role = 1 LIMIT 0,1"; $JLMS_DB->setQuery($query); $default_teacher_role = intval($JLMS_DB->LoadResult()); if (!$default_teacher_role) { $query = "SELECT id FROM #__lms_usertypes WHERE roletype_id = 2 LIMIT 0,1"; $JLMS_DB->setQuery($query); $default_teacher_role = intval($JLMS_DB->LoadResult()); if (!$default_teacher_role) { $default_teacher_role = 1; } } // create teacher for imported course $query = "INSERT INTO `#__lms_user_courses` (user_id, course_id, role_id) VALUES ('" . $my->id . "','" . $course_id . "','" . $default_teacher_role . "')"; $JLMS_DB->setQuery($query); $JLMS_DB->query(); // commented by DEN - 27.03.2008 - enrollment questions are moved into another section /*if ($course->spec_reg && $course_question_txt) { $query = "INSERT INTO #__lms_spec_reg_questions (course_id, course_question) VALUES ($course_id, ".$JLMS_DB->Quote($course_question_txt).")"; $JLMS_DB->SetQuery( $query ); $JLMS_DB->query(); }*/ // **************************************************************************************************** // Get hidden menu items DATA, insert it into 'lms_local_menu' table //get hidden menu items array from xml $element =& $root->getElementByPath('hidden_menu_items'); $hidden_menus = JLMS_parse_XML_elements($element->children(), array('menu_id', 'user_access'), array()); $i = 0; while ($i < count($hidden_menus)) { $hdmn = new stdClass(); $hdmn->course_id = $course_id; $hdmn->menu_id = $hidden_menus[$i]->menu_id; $hdmn->user_access = $hidden_menus[$i]->user_access; $query = "INSERT INTO #__lms_local_menu (course_id, menu_id, user_access) " . "\n VALUES (" . $course_id . ", " . intval($hdmn->menu_id) . ", " . intval($hdmn->user_access) . ")"; $JLMS_DB->SetQuery($query); $JLMS_DB->query(); $i++; } } } if ($course_id) { //get hidden menu items array from xml $element =& $root->getElementByPath('course_questions'); $course_questions = JLMS_parse_XML_elements($element->children(), array('is_optional', 'ordering'), array('question_text', 'default_answer')); if (isset($course_question_txt) && $course_question_txt) { $add = new stdClass(); $add->is_optional = 0; $add->ordering = 0; $add->question_text = $course_question_txt; $add->default_answer = ''; $course_questions[] = $add; } $i = 0; while ($i < count($course_questions)) { $insert = new stdClass(); $insert->course_id = $course_id; $insert->is_optional = $course_questions[$i]->is_optional; $insert->ordering = $course_questions[$i]->ordering; $insert->question_text = $course_questions[$i]->question_text; $insert->default_answer = $course_questions[$i]->default_answer; $insert->role_id = 0; $JLMS_DB->insertObject("#__lms_spec_reg_questions", $insert, "id"); $i++; } /*$element = &$root->getElementsByPath('course_price', 1); $course_price = $element ? $element->data() : 0; $query = "INSERT INTO #__lms_course_price (course_id, price ) VALUES('".$course_id."', '".$course_price."')"; $JLMS_DB->SetQuery( $query ); $JLMS_DB->query();*/ // **************************************************************************************************** // Get files DATA, insert it into 'lms_files' table and copy files to the 'lms_files' folder //get files array from xml $element =& $root->getElementByPath('files'); $files_pre = JLMS_parse_XML_elements($element->children(), array('id'), array('filename', 'servername')); // 05 June 2007. Nugno sformirovat' spisok of files - tol'ko tex? kotoryi deistvitel'no budut importirovat'sya // (t.e. s uchetom vybrannyx tools pri 'import'). $documents = array(); if (in_array(1, $imp_tools)) { $element =& $root->getElementByPath('documents'); $documents = JLMS_parse_XML_elements($element->children(), array('id', 'file_id', 'folder_flag', 'collapsed_folder', 'parent_id', 'ordering', 'published', 'publish_start', 'start_date', 'publish_start', 'publish_end', 'end_date', 'is_time_related', 'show_period'), array('doc_name', 'doc_description')); } $element =& $root->getElementByPath('certificates'); $certificates = JLMS_parse_XML_elements($element->children(), array('id', 'file_id', 'crtf_type', 'text_x', 'text_y', 'text_size'), array('certificate_text', 'certificate_font')); $element =& $root->getElementByPath('certificate_texts'); $certificate_texts = JLMS_parse_XML_elements($element->children(), array('parent_id', 'crtf_type', 'text_x', 'text_y', 'text_size'), array('add_certificate_text', 'certificate_font')); $quiz_images2 = array(); // for fields 'c_image' of the question (e.g. hostspot) $quiz_images = array(); if (in_array(5, $imp_tools)) { $element_qimg =& $root->getElementByPath('quizzes_images'); $quiz_images = JLMS_parse_XML_elements($element_qimg->children(), array('c_id', 'file_id'), array('quiz_image_name')); } /*if (in_array(5,$cid)) { $query = "SELECT * FROM `#__lms_certificates` WHERE course_id = '$course_id'"; } else { $query = "SELECT * FROM `#__lms_certificates` WHERE course_id = '$course_id' AND crtf_type <> 2"; }*/ $files = array(); foreach ($documents as $doc) { foreach ($files_pre as $file_pre) { if ($doc->file_id == $file_pre->id) { $is_exists = false; foreach ($files as $file_ex) { if ($file_ex->id == $file_pre->id) { $is_exists = true; break; } } if (!$is_exists) { $files[] = $file_pre; } break; } } } foreach ($certificates as $crtf) { foreach ($files_pre as $file_pre) { if ($crtf->file_id == $file_pre->id) { $do_add = false; if ($crtf->crtf_type == 2) { if (in_array(5, $imp_tools)) { $do_add = true; } } else { $do_add = true; } if ($do_add) { $is_exists = false; foreach ($files as $file_ex) { if ($file_ex->id == $file_pre->id) { $is_exists = true; break; } } if (!$is_exists) { $files[] = $file_pre; } break; } } } } foreach ($quiz_images as $qimg) { foreach ($files_pre as $file_pre) { if ($qimg->file_id == $file_pre->id) { $is_exists = false; foreach ($files as $file_ex) { if ($file_ex->id == $file_pre->id) { $is_exists = true; break; } } if (!$is_exists) { $files[] = $file_pre; } break; } } } $i = 0; $fromDir = $extract_dir . "files/"; $toDir = $lms_cfg_doc_folder . "/"; while ($i < count($files)) { $insert_file = new stdClass(); $insert_file->file_name = $files[$i]->filename; $file_unique_name = str_pad($course_id, 4, '0', STR_PAD_LEFT) . '_' . md5(uniqid(rand(), true)) . '.' . substr($files[$i]->servername, -3); $insert_file->file_srv_name = $file_unique_name; $insert_file->owner_id = $my->id; $JLMS_DB->insertObject("#__lms_files", $insert_file, "id"); $files[$i]->new_file_id = $JLMS_DB->insertid(); rename($fromDir . $files[$i]->servername, $toDir . $file_unique_name); $i++; } $zip_docs = array(); if (in_array(1, $imp_tools)) { // **************************************************************************************************** // Get ZIPPACK's DATA, insert it into 'lms_documents_zip' table and copy zippack files to the 'lms_scorm' folder $fromDir = $extract_dir . "zippacks/"; $toDir = $JLMS_CONFIG->getCfg('absolute_path') . "/" . $lms_cfg_scorm . "/"; $element =& $root->getElementByPath('zipped_documents'); $zip_docs = JLMS_parse_XML_elements($element->children(), array('id', 'upload_time', 'count_files', 'zip_size', 'zipfile_size', 'is_time_related', 'show_period'), array('zip_folder', 'zip_srv_name', 'zip_name', 'startup_file')); $i = 0; while ($i < count($zip_docs)) { $insert = new stdClass(); $insert->owner_id = $my->id; $insert->course_id = $course_id; $folder_unique_name = str_pad($my->id, 4, '0', STR_PAD_LEFT) . '_zip_' . md5(uniqid(rand(), true)); $insert->zip_folder = $folder_unique_name; $file_unique_name = $folder_unique_name . ".zip"; $insert->zip_srv_name = $file_unique_name; $insert->zip_name = $zip_docs[$i]->zip_name; $insert->startup_file = $zip_docs[$i]->startup_file; $insert->count_files = $zip_docs[$i]->count_files; $insert->zip_size = $zip_docs[$i]->zip_size; $insert->zipfile_size = $zip_docs[$i]->zipfile_size; $insert->upload_time = date('Y-m-d H:i:s'); //$scorms[$i]->upload_time; //insert into DB $JLMS_DB->insertObject("#__lms_documents_zip", $insert, "id"); $zip_docs[$i]->new_zip_id = $JLMS_DB->insertid(); //move scrom package rename($fromDir . $zip_docs[$i]->zip_srv_name, $toDir . $file_unique_name); //extract SCORM package archive extractBackupArchive($toDir . $file_unique_name, $toDir . $folder_unique_name); $i++; } } if (in_array(1, $imp_tools)) { // **************************************************************************************************** // Get documents DATA and insert it into the 'lms_documents' table //$element = &$root->getElementsByPath('documents', 1); //$documents = JLMS_parse_XML_elements($element->children(), array('id', 'file_id', 'folder_flag', 'parent_id', 'ordering', 'published', 'publish_start', 'start_date', 'publish_start', 'publish_end', 'end_date'), array('doc_name', 'doc_description')); // 05 June 2007 - this array is generated above (~~ line 270) $j = 0; $collapsed_folders = array(); while ($j < count($documents)) { $insert = new stdClass(); $insert->course_id = $course_id; $insert->owner_id = $my->id; $insert->file_id = 0; if ($documents[$j]->file_id) { if ($documents[$j]->folder_flag == 2) { // search $zip_docs for new file_id for ($i = 0; $i < count($zip_docs); $i++) { if ($zip_docs[$i]->id == $documents[$j]->file_id) { $insert->file_id = $zip_docs[$i]->new_zip_id; break; } } } else { // search $files for new file_id for ($i = 0; $i < count($files); $i++) { if ($files[$i]->id == $documents[$j]->file_id) { $insert->file_id = $files[$i]->new_file_id; break; } } } } $insert->folder_flag = $documents[$j]->folder_flag; $insert->doc_name = $documents[$j]->doc_name; $insert->doc_description = $documents[$j]->doc_description; $insert->ordering = $documents[$j]->ordering; $insert->published = $documents[$j]->published; $insert->publish_start = $documents[$j]->publish_start; $insert->start_date = $documents[$j]->start_date; $insert->publish_end = $documents[$j]->publish_end; $insert->end_date = $documents[$j]->end_date; $insert->is_time_related = $documents[$i]->is_time_related; $insert->show_period = $documents[$i]->show_period; // search processed $documents for parent_id $parent = $documents[$j]->parent_id; if ($parent) { $a = 0; while ($a < $j) { if ($documents[$a]->id == $parent) { $parent = $documents[$a]->new_doc_id; break; } $a++; } } $insert->parent_id = $parent; $do_ins_object = true; $ins_object_folder_already_exists_id = 0; if ($insert->folder_flag == 1 && $course_id) { //if we are merging imported course with already existeten course, then some folders can be already exists $query = "SELECT id FROM #__lms_documents WHERE doc_name = " . $JLMS_DB->quote($insert->doc_name) . " AND parent_id = " . intval($insert->parent_id) . " AND folder_flag = 1 AND file_id = 0 AND course_id = {$course_id}"; $JLMS_DB->SetQuery($query); $ins_object_folder_already_exists_id = $JLMS_DB->LoadResult(); if ($ins_object_folder_already_exists_id) { $do_ins_object = false; } } if ($do_ins_object) { $JLMS_DB->insertObject("#__lms_documents", $insert, "id"); $documents[$j]->new_doc_id = $JLMS_DB->insertid(); } else { $documents[$j]->new_doc_id = $ins_object_folder_already_exists_id; } if ($do_ins_object) { if ($documents[$j]->folder_flag == 1 && !$documents[$j]->file_id && $documents[$j]->collapsed_folder) { $collapsed_folders[] = $documents[$j]->new_doc_id; } } $j++; } if (!empty($collapsed_folders)) { $query = "INSERT INTO #__lms_documents_view (course_id, doc_id) VALUES"; $s = ''; $is_add = false; foreach ($collapsed_folders as $cf) { if ($cf) { $is_add = true; $query .= $s . "\n ({$course_id}, {$cf})"; $s = ','; } } if ($is_add) { $JLMS_DB->SetQuery($query); $JLMS_DB->query(); } } } $scorms = array(); if (in_array(3, $imp_tools)) { // **************************************************************************************************** // Get SCORM's DATA, insert it into 'lms_scorm_packages' table and copy scorm files to the 'lms_scorm' folder $fromDir = $extract_dir . "scorm/"; $toDir = $JLMS_CONFIG->getCfg('absolute_path') . "/" . $lms_cfg_scorm . "/"; $element =& $root->getElementByPath('scorms'); $scorms = JLMS_parse_XML_elements($element->children(), array('id', 'upload_time'), array('foldersrvname', 'packagesrvname', 'packageusername')); $i = 0; while ($i < count($scorms)) { $insert = new stdClass(); $insert->owner_id = $my->id; $insert->course_id = $course_id; $folder_unique_name = str_pad($my->id, 4, '0', STR_PAD_LEFT) . '_' . md5(uniqid(rand(), true)); $insert->folder_srv_name = $folder_unique_name; $file_unique_name = $folder_unique_name . ".zip"; $insert->package_srv_name = $file_unique_name; $insert->package_user_name = $scorms[$i]->packageusername; $insert->upload_time = date('Y-m-d H:i:s'); //$scorms[$i]->upload_time; //insert into DB $JLMS_DB->insertObject("#__lms_scorm_packages", $insert, "id"); $scorms[$i]->new_sco_id = $JLMS_DB->insertid(); //move scrom package rename($fromDir . $scorms[$i]->packagesrvname, $toDir . $file_unique_name); //extract SCORM package archive extractBackupArchive($toDir . $file_unique_name, $toDir . $folder_unique_name); $i++; } } $links = array(); if (in_array(4, $imp_tools)) { // **************************************************************************************************** // Get links DATA and insert it into the 'lms_links' table $element =& $root->getElementByPath('links'); $links = JLMS_parse_XML_elements($element->children(), array('id', 'link_type', 'ordering', 'published', 'is_time_related', 'show_period'), array('linkname', 'linkhref', 'description', 'link_params')); $i = 0; while ($i < count($links)) { $insert = new stdClass(); $insert->course_id = $course_id; $insert->owner_id = $my->id; $insert->link_name = $links[$i]->linkname; $insert->link_href = $links[$i]->linkhref; $insert->link_description = $links[$i]->description; $insert->link_type = $links[$i]->link_type; $insert->ordering = $links[$i]->ordering; $insert->published = $links[$i]->published; $insert->is_time_related = $links[$i]->is_time_related; $insert->show_period = $links[$i]->show_period; $insert->params = $links[$i]->link_params; $JLMS_DB->insertObject("#__lms_links", $insert, "id"); $links[$i]->new_link_id = $JLMS_DB->insertid(); $i++; } } $homeworks = array(); if (in_array(7, $imp_tools)) { // **************************************************************************************************** // Get homeworks DATA and insert it into the 'lms_homework' table $element =& $root->getElementByPath('homework_tool'); $homeworks = JLMS_parse_XML_elements($element->children(), array('id', 'post_date', 'end_date', 'is_time_related', 'show_period'), array('hw_name', 'description', 'short_description')); $i = 0; while ($i < count($homeworks)) { $insert = new stdClass(); $insert->course_id = $course_id; $insert->hw_name = $homeworks[$i]->hw_name; $insert->hw_description = $homeworks[$i]->description; $insert->hw_shortdescription = $homeworks[$i]->short_description; $insert->post_date = $homeworks[$i]->post_date; $insert->end_date = $homeworks[$i]->end_date; $insert->is_time_related = $homeworks[$i]->is_time_related; $insert->show_period = $homeworks[$i]->show_period; $JLMS_DB->insertObject("#__lms_homework", $insert, "id"); $homeworks[$i]->new_hw_id = $JLMS_DB->insertid(); $i++; } } $announcements = array(); if (in_array(6, $imp_tools)) { // **************************************************************************************************** // Get announcements DATA and insert it into the 'lms_agenda' table $element =& $root->getElementByPath('announcement_tool'); $announcements = JLMS_parse_XML_elements($element->children(), array('id', 'start_date', 'end_date', 'is_time_related', 'show_period'), array('announcement_title', 'announcement_content')); $i = 0; while ($i < count($announcements)) { $insert = new stdClass(); $insert->course_id = $course_id; $insert->owner_id = $my->id; $insert->title = $announcements[$i]->announcement_title; $insert->content = $announcements[$i]->announcement_content; $insert->start_date = $announcements[$i]->start_date; $insert->end_date = $announcements[$i]->end_date; $insert->is_time_related = $announcements[$i]->is_time_related; $insert->show_period = $announcements[$i]->show_period; $JLMS_DB->insertObject("#__lms_agenda", $insert, "agenda_id"); $announcements[$i]->new_ag_id = $JLMS_DB->insertid(); $i++; } } // **************************************************************************************************** // Get certificates DATA and insert it into the 'lms_certificates' table //$element = &$root->getElementsByPath('certificates', 1); //$certificates = JLMS_parse_XML_elements($element->children(), array('id', 'file_id', 'crtf_type', 'text_x', 'text_y', 'text_size'), array('certificate_text')); // 05 June 2007 - this array is generated above (~~ line 270) $i = 0; $crtf_ids_exp = array(); while ($i < count($certificates)) { $do_add = false; if ($certificates[$i]->crtf_type == 2) { if (in_array(5, $imp_tools)) { $do_add = true; } } else { $do_add = true; } if ($do_add) { $insert = new stdClass(); $insert->course_id = $course_id; $insert->file_id = 0; $insert->parent_id = 0; if ($certificates[$i]->file_id) { for ($k = 0; $k < count($files); $k++) { if ($files[$k]->id == $certificates[$i]->file_id) { $insert->file_id = $files[$k]->new_file_id; break; } } } $insert->crtf_text = $certificates[$i]->certificate_text; $insert->crtf_font = $certificates[$i]->certificate_font; $insert->text_x = $certificates[$i]->text_x; $insert->text_y = $certificates[$i]->text_y; $insert->text_size = $certificates[$i]->text_size; $insert->crtf_type = $certificates[$i]->crtf_type; if ($insert->crtf_type == 1) { $insert->published = 0; } $JLMS_DB->insertObject("#__lms_certificates", $insert, "id"); $certificates[$i]->new_id = $JLMS_DB->insertid(); $crtf_ids_exp[] = $certificates[$i]->id; } $i++; } // 27.03.2008 (DEN) - Additional certificate texts $i = 0; while ($i < count($certificate_texts)) { $do_add = false; if ($certificates[$i]->crtf_type == -2 && $certificates[$i]->parent_id) { if (in_array($certificates[$i]->parent_id, $crtf_ids_exp)) { $do_add = true; } } if ($do_add) { $insert = new stdClass(); $insert->course_id = $course_id; $insert->file_id = 0; $insert->parent_id = 0; for ($k = 0; $k < count($certificates); $k++) { if ($certificates[$k]->id == $certificate_texts[$i]->parent_id) { $insert->parent_id = $certificates[$k]->new_id; break; } } if ($insert->parent_id) { $insert->crtf_text = $certificate_texts[$i]->add_certificate_text; $insert->crtf_font = $certificate_texts[$i]->certificate_font; $insert->text_x = $certificate_texts[$i]->text_x; $insert->text_y = $certificate_texts[$i]->text_y; $insert->text_size = $certificate_texts[$i]->text_size; $insert->crtf_type = $certificate_texts[$i]->crtf_type; $JLMS_DB->insertObject("#__lms_certificates", $insert, "id"); $certificate_texts[$i]->new_id = $JLMS_DB->insertid(); } } $i++; } $quizzes = array(); if (in_array(5, $imp_tools)) { // **************************************************************************************************** // Get Quizzes DATA and insert it into the DB //if ($lms_cfg_quiz_enabled) { // commented 05.03.2007 (to put exported quizzes into LP anywhere) (else we've got errors in LP) /* 28 April 2007 (DEN) - Question categories processing * */ $element_qcat =& $root->getElementByPath('quizzes_quest_categories'); $quest_cats = JLMS_parse_XML_elements($element_qcat->children(), array('c_id'), array('quest_category_name', 'quest_category_instr')); $i = 0; while ($i < count($quest_cats)) { $insert = new stdClass(); $insert->course_id = $course_id; $insert->c_category = $quest_cats[$i]->quest_category_name; $insert->c_instruction = $quest_cats[$i]->quest_category_instr; $insert->is_quiz_cat = 0; $JLMS_DB->insertObject("#__lms_quiz_t_category", $insert, "c_id"); $quest_cats[$i]->new_qcat_id = $JLMS_DB->insertid(); $i++; } /* 27 March 2008 (DEN) - Quizzes images processing * (variable $quiz_images defined above) */ $i = 0; while ($i < count($quiz_images)) { $insert = new stdClass(); $insert->course_id = $course_id; $insert->imgs_name = $quiz_images[$i]->quiz_image_name; $insert->imgs_id = 0; if ($quiz_images[$i]->file_id) { for ($k = 0; $k < count($files); $k++) { if ($files[$k]->id == $quiz_images[$i]->file_id) { $insert->imgs_id = $files[$k]->new_file_id; break; } } } if ($insert->imgs_id) { $JLMS_DB->insertObject("#__lms_quiz_images", $insert, "c_id"); $quiz_images[$i]->new_img_id = $JLMS_DB->insertid(); $quiz_images[$i]->imgs_new_id = $insert->imgs_id; // Axtung!: vse tablicy nabora question options (like 't_choice', 't_matching') are stores imgs_id instead of id from #__lms_quiz_images } $i++; } /* 28 April 2007 (DEN) - Questions Pool processing * */ $element_pool =& $root->getElementByPath('quizzes_question_pool'); $q_pool = JLMS_parse_XML_elements($element_pool->children(), array(), array(), true, array('pool_questions', 'question_feedbacks', 'choice_data', 'match_data', 'scale_data', 'blank_data', 'hotspot_data'), array(array('c_id', 'c_point', 'c_attempts', 'c_type', 'c_pool', 'c_qcat', 'ordering'), array('quest_id', 'choice_id'), array('c_question_id', 'c_right', 'ordering'), array('c_question_id', 'ordering'), array('c_question_id', 'c_type', 'ordering'), array('c_question_id', 'ordering'), array('c_question_id')), array(array('question_text', 'question_image', 'question_params', 'question_explanation'), array('fb_text'), array('choice_text'), array('match_text_left', 'match_text_right'), array('scale_field'), array('blank_text', 'default_answer'), array('hs_start_x', 'hs_start_y', 'hs_width', 'hs_height'))); $i = 0; while ($i < count($q_pool)) { //questions processing $j = 0; while ($j < count($q_pool[$i]->pool_questions)) { $quest = new stdClass(); $quest->course_id = $course_id; $quest->c_quiz_id = 0; //$new_quiz_id; $quest->c_point = $q_pool[$i]->pool_questions[$j]->c_point; $quest->c_attempts = $q_pool[$i]->pool_questions[$j]->c_attempts; $quest->c_question = $q_pool[$i]->pool_questions[$j]->question_text; $quest->c_image = $q_pool[$i]->pool_questions[$j]->question_image; $quest->params = $q_pool[$i]->pool_questions[$j]->question_params; $quest->c_explanation = $q_pool[$i]->pool_questions[$j]->question_explanation; // added 27.03.2008 (DEN) $quest->c_type = $q_pool[$i]->pool_questions[$j]->c_type; $quest->c_pool = 0; //$q_pool[$i]->pool_questions[$j]->c_pool; $quest->c_qcat = 0; if ($q_pool[$i]->pool_questions[$j]->c_qcat) { for ($ij = 0; $ij < count($quest_cats); $ij++) { if ($quest_cats[$ij]->c_id == $q_pool[$i]->pool_questions[$j]->c_qcat) { $quest->c_qcat = $quest_cats[$ij]->new_qcat_id; break; } } } $quest->ordering = $q_pool[$i]->pool_questions[$j]->ordering; if ($q_pool[$i]->pool_questions[$j]->question_image && !in_array($q_pool[$i]->pool_questions[$j]->question_image, $quiz_images2)) { // Changed 20.08.2007 by DEN - from: //if ($q_pool[$i]->pool_questions[$j]->question_image) { $quiz_images2[] = $q_pool[$i]->pool_questions[$j]->question_image; } $JLMS_DB->insertObject("#__lms_quiz_t_question", $quest, "c_id"); $q_pool[$i]->pool_questions[$j]->new_id = $JLMS_DB->insertid(); $j++; } //feedbacks processing $j = 0; while ($j < count($q_pool[$i]->question_feedbacks)) { $q_fb = new stdClass(); $q_fb->choice_id = $q_pool[$i]->question_feedbacks[$j]->choice_id; $q_fb->fb_text = $q_pool[$i]->question_feedbacks[$j]->fb_text; $q_fb->quest_id = 0; for ($k = 0; $k < count($q_pool[$i]->pool_questions); $k++) { if ($q_pool[$i]->pool_questions[$k]->c_id == $q_pool[$i]->question_feedbacks[$j]->quest_id) { $q_fb->quest_id = isset($q_pool[$i]->pool_questions[$k]->new_id) ? intval($q_pool[$i]->pool_questions[$k]->new_id) : 0; break; } } if ($q_fb->quest_id && $q_fb->fb_text && ($q_fb->choice_id == -1 || $q_fb->choice_id == 0)) { $query = "INSERT INTO #__lms_quiz_t_question_fb (quest_id, choice_id, fb_text) VALUES ({$q_fb->quest_id}, {$q_fb->choice_id}, " . $JLMS_DB->Quote($q_fb->fb_text) . ")"; $JLMS_DB->SetQuery($query); $JLMS_DB->query(); } $j++; } //choices processing $j = 0; while ($j < count($q_pool[$i]->choice_data)) { $q_choice = new stdClass(); $q_choice->c_choice = $q_pool[$i]->choice_data[$j]->choice_text; $q_choice->c_right = $q_pool[$i]->choice_data[$j]->c_right; $q_choice->ordering = $q_pool[$i]->choice_data[$j]->ordering; $q_choice->c_question_id = 0; for ($k = 0; $k < count($q_pool[$i]->pool_questions); $k++) { if ($q_pool[$i]->pool_questions[$k]->c_id == $q_pool[$i]->choice_data[$j]->c_question_id) { $q_choice->c_question_id = isset($q_pool[$i]->pool_questions[$k]->new_id) ? $q_pool[$i]->pool_questions[$k]->new_id : 0; if ($q_pool[$i]->pool_questions[$k]->c_type == 12 || $q_pool[$i]->pool_questions[$k]->c_type == 13) { $q_choice->c_choice = intval($q_choice->c_choice); for ($kk = 0; $kk < count($quiz_images); $kk++) { if ($q_choice->c_choice == $quiz_images[$kk]->file_id) { $q_choice->c_choice = isset($quiz_images[$kk]->imgs_new_id) ? intval($quiz_images[$kk]->imgs_new_id) : 0; break; } } } break; } } if ($q_choice->c_question_id) { $JLMS_DB->insertObject("#__lms_quiz_t_choice", $q_choice, "c_id"); } $j++; } //matching processing $j = 0; while ($j < count($q_pool[$i]->match_data)) { $q_match = new stdClass(); $q_match->c_left_text = $q_pool[$i]->match_data[$j]->match_text_left; $q_match->c_right_text = $q_pool[$i]->match_data[$j]->match_text_right; $q_match->ordering = $q_pool[$i]->match_data[$j]->ordering; $q_match->c_question_id = 0; for ($k = 0; $k < count($q_pool[$i]->pool_questions); $k++) { if ($q_pool[$i]->pool_questions[$k]->c_id == $q_pool[$i]->match_data[$j]->c_question_id) { $q_match->c_question_id = isset($q_pool[$i]->pool_questions[$k]->new_id) ? $q_pool[$i]->pool_questions[$k]->new_id : 0; if ($q_pool[$i]->pool_questions[$k]->c_type == 11) { $q_match->c_left_text = intval($q_match->c_left_text); $q_match->c_right_text = intval($q_match->c_right_text); $is_changed_match_images = 0; for ($kk = 0; $kk < count($quiz_images); $kk++) { if ($q_match->c_left_text == $quiz_images[$kk]->file_id) { $q_match->c_left_text = isset($quiz_images[$kk]->imgs_new_id) ? intval($quiz_images[$kk]->imgs_new_id) : 0; $is_changed_match_images++; if ($is_changed_match_images == 2) { break; } } if ($q_match->c_right_text == $quiz_images[$kk]->file_id) { $q_match->c_right_text = isset($quiz_images[$kk]->imgs_new_id) ? intval($quiz_images[$kk]->imgs_new_id) : 0; $is_changed_match_images++; if ($is_changed_match_images == 2) { break; } } } } break; } } if ($q_match->c_question_id) { $JLMS_DB->insertObject("#__lms_quiz_t_matching", $q_match, "c_id"); } $j++; } //likert scale processing (27.03.2008 - DEN) $j = 0; while ($j < count($q_pool[$i]->scale_data)) { $q_scale = new stdClass(); $q_scale->c_field = $q_pool[$i]->scale_data[$j]->scale_field; $q_scale->c_type = $q_pool[$i]->scale_data[$j]->c_type; $q_scale->ordering = $q_pool[$i]->scale_data[$j]->ordering; $q_scale->c_question_id = 0; for ($k = 0; $k < count($q_pool[$i]->pool_questions); $k++) { if ($q_pool[$i]->pool_questions[$k]->c_id == $q_pool[$i]->scale_data[$j]->c_question_id) { $q_scale->c_question_id = isset($q_pool[$i]->pool_questions[$k]->new_id) ? $q_pool[$i]->pool_questions[$k]->new_id : 0; break; } } if ($q_scale->c_question_id) { $JLMS_DB->insertObject("#__lms_quiz_t_scale", $q_scale, "c_id"); } $j++; } //hotspot processing $j = 0; while ($j < count($q_pool[$i]->hotspot_data)) { $q_hotspot = new stdClass(); $q_hotspot->c_start_x = $q_pool[$i]->hotspot_data[$j]->hs_start_x; $q_hotspot->c_start_y = $q_pool[$i]->hotspot_data[$j]->hs_start_y; $q_hotspot->c_width = $q_pool[$i]->hotspot_data[$j]->hs_width; $q_hotspot->c_height = $q_pool[$i]->hotspot_data[$j]->hs_height; $q_hotspot->c_question_id = 0; for ($k = 0; $k < count($q_pool[$i]->pool_questions); $k++) { if ($q_pool[$i]->pool_questions[$k]->c_id == $q_pool[$i]->hotspot_data[$j]->c_question_id) { $q_hotspot->c_question_id = isset($q_pool[$i]->pool_questions[$k]->new_id) ? $q_pool[$i]->pool_questions[$k]->new_id : 0; break; } } if ($q_hotspot->c_question_id) { $JLMS_DB->insertObject("#__lms_quiz_t_hotspot", $q_hotspot, "c_id"); } $j++; } //blank quests processing $j = 0; $blank_inserted = array(); while ($j < count($q_pool[$i]->blank_data)) { $q_blank = new stdClass(); $q_blank->c_question_id = 0; $q_blank->c_default = $q_pool[$i]->blank_data[$j]->default_answer; for ($k = 0; $k < count($q_pool[$i]->pool_questions); $k++) { if ($q_pool[$i]->pool_questions[$k]->c_id == $q_pool[$i]->blank_data[$j]->c_question_id) { $q_blank->c_question_id = isset($q_pool[$i]->pool_questions[$k]->new_id) ? $q_pool[$i]->pool_questions[$k]->new_id : 0; break; } } if ($q_blank->c_question_id) { $proceed_insert = true; foreach ($blank_inserted as $bains) { if ($bains->quest_id == $q_blank->c_question_id) { $proceed_insert = false; $new_blank_id = $bains->blank_id; break; } } if ($proceed_insert) { $JLMS_DB->insertObject("#__lms_quiz_t_blank", $q_blank, "c_id"); $new_blank_id = $JLMS_DB->insertid(); $blankins = new stdClass(); $blankins->quest_id = $q_blank->c_question_id; $blankins->blank_id = $new_blank_id; $blank_inserted[] = $blankins; } $q_blank_text = new stdClass(); $q_blank_text->c_blank_id = $new_blank_id; $q_blank_text->c_text = $q_pool[$i]->blank_data[$j]->blank_text; $q_blank_text->ordering = $q_pool[$i]->blank_data[$j]->ordering; if ($q_blank_text->c_blank_id) { $JLMS_DB->insertObject("#__lms_quiz_t_text", $q_blank_text, "c_id"); } } $j++; } $i++; } $element =& $root->getElementByPath('quizzes'); $quizzes = JLMS_parse_XML_elements($element->children(), array('c_id', 'published'), array('quiz_title', 'quiz_description', 'quiz_category', 'quiz_full_score', 'quiz_time_limit', 'quiz_min_after', 'quiz_passing_score', 'quiz_right_message', 'quiz_wrong_message', 'quiz_pass_message', 'quiz_unpass_message', 'quiz_review', 'quiz_email', 'quiz_print', 'quiz_certif', 'quiz_skin', 'quiz_random', 'quiz_guest', 'quiz_slide', 'quiz_language', 'quiz_certificate', 'quiz_gradebook', 'quiz_params', 'is_time_related', 'show_period'), true, array('quiz_pool_assoc', 'quiz_questions', 'question_feedbacks', 'choice_data', 'match_data', 'scale_data', 'blank_data', 'hotspot_data'), array(array('qcat_id', 'items_number'), array('c_id', 'c_point', 'c_attempts', 'c_type', 'c_pool', 'c_qcat', 'ordering'), array('quest_id', 'choice_id'), array('c_question_id', 'c_right', 'ordering'), array('c_question_id', 'ordering'), array('c_question_id', 'c_type', 'ordering'), array('c_question_id', 'ordering'), array('c_question_id')), array(array(), array('question_text', 'question_image', 'question_params', 'question_explanation'), array('fb_text'), array('choice_text'), array('match_text_left', 'match_text_right'), array('scale_field'), array('blank_text', 'default_answer'), array('hs_start_x', 'hs_start_y', 'hs_width', 'hs_height'))); $i = 0; while ($i < count($quizzes)) { $insert = new stdClass(); $insert->course_id = $course_id; $insert->c_category_id = 0; $quiz_cat_name = $quizzes[$i]->quiz_category; $query = "SELECT c_id FROM #__lms_quiz_t_category WHERE c_category = '" . $quiz_cat_name . "' AND is_quiz_cat = 1"; $JLMS_DB->SetQuery($query); $quiz_cat_id = $JLMS_DB->LoadResult(); if ($quiz_cat_id) { $insert->c_category_id = $quiz_cat_id; } elseif ($quiz_cat_name) { $query = "INSERT INTO #__lms_quiz_t_category (course_id, c_category, c_instruction, is_quiz_cat) VALUES ({$course_id}, " . $JLMS_DB->Quote($quiz_cat_name) . ", '', 1)"; $JLMS_DB->SetQuery($query); $JLMS_DB->query(); $insert->c_category_id = $JLMS_DB->insertid(); } $insert->c_user_id = $my->id; $insert->c_full_score = $quizzes[$i]->quiz_full_score; $insert->c_title = $quizzes[$i]->quiz_title; $insert->c_description = $quizzes[$i]->quiz_description; $insert->c_time_limit = $quizzes[$i]->quiz_time_limit; $insert->c_min_after = $quizzes[$i]->quiz_min_after; $insert->c_passing_score = $quizzes[$i]->quiz_passing_score; $insert->c_created_time = date('Y-m-d'); $insert->published = $quizzes[$i]->published; //!!! $insert->c_right_message = $quizzes[$i]->quiz_right_message; $insert->c_wrong_message = $quizzes[$i]->quiz_wrong_message; $insert->c_pass_message = $quizzes[$i]->quiz_pass_message; $insert->c_unpass_message = $quizzes[$i]->quiz_unpass_message; $insert->c_enable_review = $quizzes[$i]->quiz_review; $insert->c_email_to = $quizzes[$i]->quiz_email; $insert->c_enable_print = $quizzes[$i]->quiz_print; $insert->c_enable_sertif = $quizzes[$i]->quiz_certif; $insert->c_skin = $quizzes[$i]->quiz_skin; $insert->c_random = $quizzes[$i]->quiz_random; $insert->c_guest = $quizzes[$i]->quiz_guest; $insert->c_skin = $quizzes[$i]->quiz_skin; $insert->c_slide = $quizzes[$i]->quiz_slide; $insert->c_language = $quizzes[$i]->quiz_language; $insert->params = $quizzes[$i]->quiz_params; $insert->is_time_related = $quizzes[$i]->is_time_related; $insert->show_period = $quizzes[$i]->show_period; $insert->c_certificate = 0; if ($quizzes[$i]->quiz_certificate) { for ($r = 0; $r < count($certificates); $r++) { if ($certificates[$r]->id == $quizzes[$i]->quiz_certificate) { $insert->c_certificate = $certificates[$r]->new_id; break; } } } $insert->c_gradebook = $quizzes[$i]->quiz_gradebook; $JLMS_DB->insertObject("#__lms_quiz_t_quiz", $insert, "c_id"); $new_quiz_id = $JLMS_DB->insertid(); $quizzes[$i]->new_quiz_id = $new_quiz_id; if (!empty($quizzes[$i]->quiz_pool_assoc)) { $j = 0; while ($j < count($quizzes[$i]->quiz_pool_assoc)) { $ins_qp = new stdClass(); $ins_qp->quiz_id = $new_quiz_id; $ins_qp->qcat_id = 0; //$quizzes[$i]->quiz_pool_assoc[$j]->qcat_id; if ($quizzes[$i]->quiz_pool_assoc[$j]->qcat_id) { for ($ij = 0; $ij < count($quest_cats); $ij++) { if ($quest_cats[$ij]->c_id == $quizzes[$i]->quiz_pool_assoc[$j]->qcat_id) { $ins_qp->qcat_id = $quest_cats[$ij]->new_qcat_id; break; } } } $ins_qp->items_number = $quizzes[$i]->quiz_pool_assoc[$j]->items_number; $query = "INSERT INTO #__lms_quiz_t_quiz_pool (quiz_id, qcat_id, items_number) VALUES ({$ins_qp->quiz_id}, {$ins_qp->qcat_id}, {$ins_qp->items_number})"; $JLMS_DB->SetQuery($query); $JLMS_DB->query(); $j++; } } //questions processing $j = 0; while ($j < count($quizzes[$i]->quiz_questions)) { $quest = new stdClass(); $quest->course_id = $course_id; $quest->c_quiz_id = $new_quiz_id; $quest->c_point = $quizzes[$i]->quiz_questions[$j]->c_point; $quest->c_attempts = $quizzes[$i]->quiz_questions[$j]->c_attempts; $quest->c_question = $quizzes[$i]->quiz_questions[$j]->question_text; $quest->c_image = $quizzes[$i]->quiz_questions[$j]->question_image; $quest->c_type = $quizzes[$i]->quiz_questions[$j]->c_type; $quest->params = $quizzes[$i]->quiz_questions[$j]->question_params; $quest->c_explanation = $quizzes[$i]->quiz_questions[$j]->question_explanation; // added 27.03.2008 (DEN) $quest->c_pool = 0; //$q_pool[$i]->pool_questions[$j]->c_pool; $quest->c_qcat = 0; if ($quizzes[$i]->quiz_questions[$j]->c_qcat) { for ($ij = 0; $ij < count($quest_cats); $ij++) { if ($quest_cats[$ij]->c_id == $quizzes[$i]->quiz_questions[$j]->c_qcat) { $quest->c_qcat = $quest_cats[$ij]->new_qcat_id; break; } } } if ($quizzes[$i]->quiz_questions[$j]->c_pool && $quest->c_type == 20) { if (!empty($q_pool[0]->pool_questions)) { for ($ij = 0; $ij < count($q_pool[0]->pool_questions); $ij++) { if ($q_pool[0]->pool_questions[$ij]->c_id == $quizzes[$i]->quiz_questions[$j]->c_pool) { $quest->c_pool = $q_pool[0]->pool_questions[$ij]->new_id; break; } } } } $quest->ordering = $quizzes[$i]->quiz_questions[$j]->ordering; if ($quizzes[$i]->quiz_questions[$j]->question_image && !in_array($quizzes[$i]->quiz_questions[$j]->question_image, $quiz_images2)) { // Changed 20.08.2007 by DEN - from: //if ($q_pool[$i]->pool_questions[$j]->question_image) { $quiz_images2[] = $quizzes[$i]->quiz_questions[$j]->question_image; } $JLMS_DB->insertObject("#__lms_quiz_t_question", $quest, "c_id"); $quizzes[$i]->quiz_questions[$j]->new_id = $JLMS_DB->insertid(); $j++; } //feedbacks processing $j = 0; while ($j < count($quizzes[$i]->question_feedbacks)) { $q_fb = new stdClass(); $q_fb->choice_id = $quizzes[$i]->question_feedbacks[$j]->choice_id; $q_fb->fb_text = $quizzes[$i]->question_feedbacks[$j]->fb_text; $q_fb->quest_id = 0; for ($k = 0; $k < count($quizzes[$i]->quiz_questions); $k++) { if ($quizzes[$i]->quiz_questions[$k]->c_id == $quizzes[$i]->question_feedbacks[$j]->quest_id) { $q_fb->quest_id = isset($quizzes[$i]->quiz_questions[$k]->new_id) ? intval($quizzes[$i]->quiz_questions[$k]->new_id) : 0; break; } } if ($q_fb->quest_id && $q_fb->fb_text && ($q_fb->choice_id == -1 || $q_fb->choice_id == 0)) { $query = "INSERT INTO #__lms_quiz_t_question_fb (quest_id, choice_id, fb_text) VALUES ({$q_fb->quest_id}, {$q_fb->choice_id}, " . $JLMS_DB->Quote($q_fb->fb_text) . ")"; $JLMS_DB->SetQuery($query); $JLMS_DB->query(); } $j++; } //choices processing $j = 0; while ($j < count($quizzes[$i]->choice_data)) { $q_choice = new stdClass(); $q_choice->c_choice = $quizzes[$i]->choice_data[$j]->choice_text; $q_choice->c_right = $quizzes[$i]->choice_data[$j]->c_right; $q_choice->ordering = $quizzes[$i]->choice_data[$j]->ordering; $q_choice->c_question_id = 0; for ($k = 0; $k < count($quizzes[$i]->quiz_questions); $k++) { if ($quizzes[$i]->quiz_questions[$k]->c_id == $quizzes[$i]->choice_data[$j]->c_question_id) { $q_choice->c_question_id = isset($quizzes[$i]->quiz_questions[$k]->new_id) ? $quizzes[$i]->quiz_questions[$k]->new_id : 0; if ($quizzes[$i]->quiz_questions[$k]->c_type == 12 || $quizzes[$i]->quiz_questions[$k]->c_type == 13) { $q_choice->c_choice = intval($q_choice->c_choice); for ($kk = 0; $kk < count($quiz_images); $kk++) { if ($q_choice->c_choice == $quiz_images[$kk]->file_id) { $q_choice->c_choice = isset($quiz_images[$kk]->imgs_new_id) ? intval($quiz_images[$kk]->imgs_new_id) : 0; break; } } } break; } } if ($q_choice->c_question_id) { $JLMS_DB->insertObject("#__lms_quiz_t_choice", $q_choice, "c_id"); } $j++; } //matching processing $j = 0; while ($j < count($quizzes[$i]->match_data)) { $q_match = new stdClass(); $q_match->c_left_text = $quizzes[$i]->match_data[$j]->match_text_left; $q_match->c_right_text = $quizzes[$i]->match_data[$j]->match_text_right; $q_match->ordering = $quizzes[$i]->match_data[$j]->ordering; $q_match->c_question_id = 0; for ($k = 0; $k < count($quizzes[$i]->quiz_questions); $k++) { if ($quizzes[$i]->quiz_questions[$k]->c_id == $quizzes[$i]->match_data[$j]->c_question_id) { $q_match->c_question_id = isset($quizzes[$i]->quiz_questions[$k]->new_id) ? $quizzes[$i]->quiz_questions[$k]->new_id : 0; break; if ($quizzes[$i]->quiz_questions[$k]->c_type == 11) { $q_match->c_left_text = intval($q_match->c_left_text); $q_match->c_right_text = intval($q_match->c_right_text); $is_changed_match_images = 0; for ($kk = 0; $kk < count($quiz_images); $kk++) { if ($q_match->c_left_text == $quiz_images[$kk]->file_id) { $q_match->c_left_text = isset($quiz_images[$kk]->imgs_new_id) ? intval($quiz_images[$kk]->imgs_new_id) : 0; $is_changed_match_images++; if ($is_changed_match_images == 2) { break; } } if ($q_match->c_right_text == $quiz_images[$kk]->file_id) { $q_match->c_right_text = isset($quiz_images[$kk]->imgs_new_id) ? intval($quiz_images[$kk]->imgs_new_id) : 0; $is_changed_match_images++; if ($is_changed_match_images == 2) { break; } } } } } } if ($q_match->c_question_id) { $JLMS_DB->insertObject("#__lms_quiz_t_matching", $q_match, "c_id"); } $j++; } //likert scale processing (27.03.2008 - DEN) $j = 0; while ($j < count($quizzes[$i]->scale_data)) { $q_scale = new stdClass(); $q_scale->c_field = $quizzes[$i]->scale_data[$j]->scale_field; $q_scale->c_type = $quizzes[$i]->scale_data[$j]->c_type; $q_scale->ordering = $quizzes[$i]->scale_data[$j]->ordering; $q_scale->c_question_id = 0; for ($k = 0; $k < count($quizzes[$i]->quiz_questions); $k++) { if ($quizzes[$i]->quiz_questions[$k]->c_id == $quizzes[$i]->scale_data[$j]->c_question_id) { $q_scale->c_question_id = isset($quizzes[$i]->quiz_questions[$k]->new_id) ? $quizzes[$i]->quiz_questions[$k]->new_id : 0; break; } } if ($q_scale->c_question_id) { $JLMS_DB->insertObject("#__lms_quiz_t_scale", $q_scale, "c_id"); } $j++; } //hotspot processing $j = 0; while ($j < count($quizzes[$i]->hotspot_data)) { $q_hotspot = new stdClass(); $q_hotspot->c_start_x = $quizzes[$i]->hotspot_data[$j]->hs_start_x; $q_hotspot->c_start_y = $quizzes[$i]->hotspot_data[$j]->hs_start_y; $q_hotspot->c_width = $quizzes[$i]->hotspot_data[$j]->hs_width; $q_hotspot->c_height = $quizzes[$i]->hotspot_data[$j]->hs_height; $q_hotspot->c_question_id = 0; for ($k = 0; $k < count($quizzes[$i]->quiz_questions); $k++) { if ($quizzes[$i]->quiz_questions[$k]->c_id == $quizzes[$i]->hotspot_data[$j]->c_question_id) { $q_hotspot->c_question_id = isset($quizzes[$i]->quiz_questions[$k]->new_id) ? $quizzes[$i]->quiz_questions[$k]->new_id : 0; break; } } if ($q_hotspot->c_question_id) { $JLMS_DB->insertObject("#__lms_quiz_t_hotspot", $q_hotspot, "c_id"); } $j++; } //blank quests processing $j = 0; $blank_inserted = array(); while ($j < count($quizzes[$i]->blank_data)) { $q_blank = new stdClass(); $q_blank->c_question_id = 0; $q_blank->c_default = $quizzes[$i]->blank_data[$j]->default_answer; for ($k = 0; $k < count($quizzes[$i]->quiz_questions); $k++) { if ($quizzes[$i]->quiz_questions[$k]->c_id == $quizzes[$i]->blank_data[$j]->c_question_id) { $q_blank->c_question_id = isset($quizzes[$i]->quiz_questions[$k]->new_id) ? $quizzes[$i]->quiz_questions[$k]->new_id : 0; break; } } if ($q_blank->c_question_id) { $proceed_insert = true; foreach ($blank_inserted as $bains) { if ($bains->quest_id == $q_blank->c_question_id) { $proceed_insert = false; $new_blank_id = $bains->blank_id; break; } } if ($proceed_insert) { $JLMS_DB->insertObject("#__lms_quiz_t_blank", $q_blank, "c_id"); $new_blank_id = $JLMS_DB->insertid(); $blankins = new stdClass(); $blankins->quest_id = $q_blank->c_question_id; $blankins->blank_id = $new_blank_id; $blank_inserted[] = $blankins; } $q_blank_text = new stdClass(); $q_blank_text->c_blank_id = $new_blank_id; $q_blank_text->c_text = $quizzes[$i]->blank_data[$j]->blank_text; $q_blank_text->ordering = $quizzes[$i]->blank_data[$j]->ordering; if ($q_blank_text->c_blank_id) { $JLMS_DB->insertObject("#__lms_quiz_t_text", $q_blank_text, "c_id"); } } $j++; } $i++; } // **************************************************************************************************** // Copy quiz images if (count($quiz_images2)) { $fromDir = $extract_dir . "quiz_images/"; $toDir = $JLMS_CONFIG->getCfg('absolute_path') . "/images/joomlaquiz/images/"; $i = 0; while ($i < count($quiz_images2)) { if (file_exists($fromDir . $quiz_images2[$i])) { @rename($fromDir . $quiz_images2[$i], $toDir . $quiz_images2[$i]); } $i++; } } //} // end if ($lms_cfg_quiz_enabled) } $l_paths = array(); $lpath_prerequisites = array(); if (in_array(2, $imp_tools)) { // **************************************************************************************************** // Get LearningPaths DATA and insert it into the DB $element =& $root->getElementByPath('learn_paths'); $l_paths = JLMS_parse_XML_elements($element->children(), array('id', 'item_id', 'ordering', 'published', 'is_time_related', 'show_period'), array('lp_name', 'lp_shortdescription', 'lp_description', 'lp_params'), true, array('prerequisites', 'steps', 'conds'), array(array('lpath_id', 'req_id', 'time_minutes'), array('id', 'item_id', 'lpath_id', 'step_type', 'parent_id', 'ordering'), array('lpath_id', 'step_id', 'ref_step', 'cond_type', 'cond_value')), array(array(), array('step_name', 'step_shortdescription', 'step_description'), array())); $i = 0; $process_steps_on_exit = array(); while ($i < count($l_paths)) { $insert = new stdClass(); $insert->course_id = $course_id; $insert->owner_id = $my->id; $insert->lpath_name = $l_paths[$i]->lp_name; if ($l_paths[$i]->item_id) { $n = 0; $scorm_found = false; while ($n < count($scorms)) { if ($scorms[$n]->id == $l_paths[$i]->item_id) { $insert->item_id = $scorms[$n]->new_sco_id; $scorm_found = true; break; } $n++; } if (!$scorm_found) { $i++; continue; } } else { $insert->item_id = 0; } $insert->lpath_shortdescription = $l_paths[$i]->lp_shortdescription; $insert->lp_params = $l_paths[$i]->lp_params; $insert->lpath_description = $l_paths[$i]->lp_description; $insert->ordering = $l_paths[$i]->ordering; $insert->published = $l_paths[$i]->published; $insert->lp_type = 0; // for compatibility with SCORM import/export (if lp_type == 0, then new instance in 'lms_n_scorm' will be added automatically) $insert->is_time_related = $l_paths[$i]->is_time_related; $insert->show_period = $l_paths[$i]->show_period; $JLMS_DB->insertObject("#__lms_learn_paths", $insert, "id"); $l_paths[$i]->new_step_id = $JLMS_DB->insertid(); // 18 August 2007 - DEN - prerequisites import $j = 0; while ($j < count($l_paths[$i]->prerequisites)) { $new_prereq = new stdClass(); $new_prereq->old_lpath_id = $l_paths[$i]->prerequisites[$j]->lpath_id; $new_prereq->old_req_id = $l_paths[$i]->prerequisites[$j]->req_id; $new_prereq->lpath_id = 0; $new_prereq->req_id = 0; $new_prereq->time_minutes = 0; $lpath_prerequisites[] = $new_prereq; $j++; } if ($l_paths[$i]->item_id) { } else { $j = 0; while ($j < count($l_paths[$i]->steps)) { $step = new stdClass(); $step->course_id = $course_id; $step->lpath_id = $l_paths[$i]->new_step_id; $step->step_type = $l_paths[$i]->steps[$j]->step_type; $do_process_on_exit = false; $proc_exit_item = 0; if ($step->step_type == 2) { //document $is_doc_found = false; for ($k = 0; $k < count($documents); $k++) { if ($documents[$k]->id == $l_paths[$i]->steps[$j]->item_id) { $step->item_id = $documents[$k]->new_doc_id; $is_doc_found = true; break; } } if (!$is_doc_found) { $step->step_type = 4; } } elseif ($step->step_type == 3) { //link $is_link_found = false; for ($k = 0; $k < count($links); $k++) { if ($links[$k]->id == $l_paths[$i]->steps[$j]->item_id) { $step->item_id = $links[$k]->new_link_id; $is_link_found = true; break; } } if (!$is_link_found) { $step->step_type = 4; } } elseif ($step->step_type == 5) { //quiz $is_quiz_found = false; for ($k = 0; $k < count($quizzes); $k++) { if ($quizzes[$k]->c_id == $l_paths[$i]->steps[$j]->item_id) { $step->item_id = $quizzes[$k]->new_quiz_id; $is_quiz_found = true; break; } } if (!$is_quiz_found) { $step->step_type = 4; } } elseif ($step->step_type == 6) { //scorm // Axtung - we should make all scorm steps - as 4 (content) and after processing all LPaths -> upgrade them to type 6 (scorm) and link to scorm LPath // (because) at this step not all Lpaths are processed !!! $step->step_type = 4; $do_process_on_exit = true; $proc_exit_item = $l_paths[$i]->steps[$j]->item_id; } else { //other $step->item_id = $l_paths[$i]->steps[$j]->item_id; } $parent = $l_paths[$i]->steps[$j]->parent_id; // search processed steps for parent_id if ($parent) { $a = 0; while ($a < $j) { if ($l_paths[$i]->steps[$a]->id == $parent) { $parent = $l_paths[$i]->steps[$a]->new_id; break; } $a++; } } $step->parent_id = $parent; $step->step_name = $l_paths[$i]->steps[$j]->step_name; $step->step_shortdescription = $l_paths[$i]->steps[$j]->step_shortdescription; $step->step_description = $l_paths[$i]->steps[$j]->step_description; $step->ordering = $l_paths[$i]->steps[$j]->ordering; $JLMS_DB->insertObject("#__lms_learn_path_steps", $step, "id"); $l_paths[$i]->steps[$j]->new_id = $JLMS_DB->insertid(); if ($do_process_on_exit) { $pr_step = new stdClass(); $pr_step->step_id = $l_paths[$i]->steps[$j]->new_id; $pr_step->item_id = $proc_exit_item; $pr_step->new_item_id = 0; $process_steps_on_exit[] = $pr_step; } $j++; } $j = 0; while ($j < count($l_paths[$i]->conds)) { $cond = new stdClass(); $cond->course_id = $course_id; $cond->lpath_id = $l_paths[$i]->new_step_id; $cond->cond_type = $l_paths[$i]->conds[$j]->cond_type; $cond->cond_value = $l_paths[$i]->conds[$j]->cond_value; $st1 = $l_paths[$i]->conds[$j]->step_id; if ($st1) { $a = 0; while ($a < count($l_paths[$i]->steps)) { if ($l_paths[$i]->steps[$a]->id == $st1) { $st1 = $l_paths[$i]->steps[$a]->new_id; break; } $a++; } } $cond->step_id = $st1; $st2 = $l_paths[$i]->conds[$j]->ref_step; if ($st2) { $a = 0; while ($a < count($l_paths[$i]->steps)) { if ($l_paths[$i]->steps[$a]->id == $st2) { $st2 = $l_paths[$i]->steps[$a]->new_id; break; } $a++; } } $cond->ref_step = $st2; $JLMS_DB->insertObject("#__lms_learn_path_conds", $cond, "id"); $j++; } } $i++; } // 18 August 2007 - DEN - import scorm steps if (!empty($process_steps_on_exit)) { $a = 0; while ($a < count($process_steps_on_exit)) { foreach ($l_paths as $lp) { if ($lp->id == $process_steps_on_exit[$a]->item_id) { $process_steps_on_exit[$a]->new_item_id = $lp->new_step_id; // xm.. why 'step' ?? (bad name) } } $a++; } foreach ($process_steps_on_exit as $lp_pse) { if ($lp_pse->new_item_id && $lp_pse->step_id) { $query = "UPDATE #__lms_learn_path_steps SET step_type = 6, item_id = " . intval($lp_pse->new_item_id) . " WHERE id = " . intval($lp_pse->step_id); $JLMS_DB->SetQuery($query); $JLMS_DB->query(); } } } // 18 August 2007 - DEN - prerequisites import if (!empty($lpath_prerequisites)) { $a = 0; while ($a < count($lpath_prerequisites)) { foreach ($l_paths as $lp) { if ($lp->id == $lpath_prerequisites[$a]->old_lpath_id) { $lpath_prerequisites[$a]->lpath_id = $lp->new_step_id; // xm.. why 'step' ?? (bad name) } if ($lp->id == $lpath_prerequisites[$a]->old_req_id) { $lpath_prerequisites[$a]->req_id = $lp->new_step_id; // xm.. why 'step' ?? (bad name) } } $a++; } foreach ($lpath_prerequisites as $lp_pre) { if ($lp_pre->lpath_id && $lp_pre->req_id && $lp_pre->lpath_id != $lp_pre->req_id) { $query = "INSERT INTO #__lms_learn_path_prerequisites (lpath_id, req_id, time_minutes) VALUES (" . intval($lp_pre->lpath_id) . ", " . intval($lp_pre->req_id) . ", " . intval($lp_pre->time_minutes) . ")"; $JLMS_DB->SetQuery($query); $JLMS_DB->query(); } } } if ($course_redirect_lp) { $lp_id = 0; foreach ($l_paths as $lp) { if ($lp->id == $course_redirect_lp) { $lp_id = $lp->new_step_id; // xm.. why 'step' ?? (bad name) break; } } if ($lp_id) { $params->set('learn_path', $lp_id); $params_ar = $params->toArray(); if (is_array($params_ar)) { foreach ($params_ar as $k => $v) { $txt[] = "{$k}={$v}"; } $new_params = implode("\n", $txt); if ($new_params) { $query = "UPDATE #__lms_courses SET " . $JLMS_DB->NameQuote('params') . " = " . $JLMS_DB->Quote($new_params) . " WHERE id = {$course_id}"; $JLMS_DB->SetQuery($query); $JLMS_DB->query(); } } } } } $course_topics = array(); // **************************************************************************************************** // Get TOPICS Items DATA and insert it into the 'lms_topics', 'lms_topic_items' tables - 27.03.2008 (DEN) $element =& $root->getElementByPath('course_topics'); $course_topics = JLMS_parse_XML_elements($element->children(), array('topic_id', 'ordering', 'published', 'publish_start', 'start_date', 'publish_end', 'end_date', 'is_time_related', 'show_period'), array('topic_name', 'topic_description')); $i = 0; while ($i < count($course_topics)) { $insert = new stdClass(); $insert->course_id = $course_id; $insert->ordering = $course_topics[$i]->ordering; $insert->name = $course_topics[$i]->topic_name; $insert->description = $course_topics[$i]->topic_description; $insert->published = $course_topics[$i]->published; $insert->start_date = $course_topics[$i]->start_date; $insert->publish_start = $course_topics[$i]->publish_start; $insert->end_date = $course_topics[$i]->end_date; $insert->publish_end = $course_topics[$i]->publish_end; $insert->is_time_related = $course_topics[$i]->is_time_related; $insert->show_period = $course_topics[$i]->show_period; $JLMS_DB->insertObject("#__lms_topics", $insert, "id"); $course_topics[$i]->new_topic_id = $JLMS_DB->insertid(); $i++; } $element =& $root->getElementByPath('course_topic_items'); $course_topic_items = JLMS_parse_XML_elements($element->children(), array('topic_id', 'item_id', 'item_type', 'ordering', 'is_shown'), array()); $i = 0; while ($i < count($course_topic_items)) { $insert = new stdClass(); $insert->course_id = $course_id; $insert->topic_id = 0; foreach ($course_topics as $ct) { if ($course_topic_items[$i]->topic_id == $ct->topic_id) { $insert->topic_id = $ct->new_topic_id; } } if ($insert->topic_id) { $insert->ordering = $course_topic_items[$i]->ordering; $insert->item_type = $course_topic_items[$i]->item_type; $insert->show = $course_topic_items[$i]->is_shown ? 1 : 0; $insert->item_id = 0; $do_add_topic_item = false; if ($insert->item_type == 2) { // documents if (in_array(1, $imp_tools)) { for ($k = 0; $k < count($documents); $k++) { if ($documents[$k]->id == $course_topic_items[$i]->item_id) { $insert->item_id = $documents[$k]->new_doc_id; $do_add_topic_item = true; break; } } } } elseif ($insert->item_type == 3) { // links if (in_array(4, $imp_tools)) { for ($k = 0; $k < count($links); $k++) { if ($links[$k]->id == $course_topic_items[$i]->item_id) { $insert->item_id = $links[$k]->new_link_id; $do_add_topic_item = true; break; } } } } elseif ($insert->item_type == 5) { // quizzes if (in_array(5, $imp_tools)) { for ($k = 0; $k < count($quizzes); $k++) { if ($quizzes[$k]->c_id == $course_topic_items[$i]->item_id) { $insert->item_id = $quizzes[$k]->new_quiz_id; $do_add_topic_item = true; break; } } } } elseif ($insert->item_type == 7) { // learning paths if (in_array(2, $imp_tools)) { for ($k = 0; $k < count($l_paths); $k++) { if ($l_paths[$k]->id == $course_topic_items[$i]->item_id) { $insert->item_id = $l_paths[$k]->new_step_id; $do_add_topic_item = true; break; } } } } if ($do_add_topic_item && $insert->item_id) { $JLMS_DB->insertObject("#__lms_topic_items", $insert, "id"); $course_topic_items[$i]->new_topic_item_id = $JLMS_DB->insertid(); } } $i++; } if (in_array(8, $imp_tools)) { // **************************************************************************************************** // Get GradeBook Items DATA and insert it into the 'lms_gradebook_items' table $element =& $root->getElementByPath('gradebook_items'); $gb_items = JLMS_parse_XML_elements($element->children(), array('gbi_option', 'ordering'), array('gbi_name', 'gbi_description', 'gb_category')); $i = 0; while ($i < count($gb_items)) { $insert = new stdClass(); $query = "SELECT id FROM #__lms_gradebook_cats WHERE gb_category = '" . $gb_items[$i]->gb_category . "'"; $JLMS_DB->SetQuery($query); $cat_id = $JLMS_DB->LoadResult(); if (!$cat_id) { $cat_id = 0; } $insert->course_id = $course_id; $insert->gbc_id = $cat_id; $insert->gbi_name = $gb_items[$i]->gbi_name; $insert->gbi_description = $gb_items[$i]->gbi_description; $insert->gbi_points = 0; $insert->gbi_option = $gb_items[$i]->gbi_option; $insert->ordering = $gb_items[$i]->ordering; $JLMS_DB->insertObject("#__lms_gradebook_items", $insert, "id"); $gb_items[$i]->new_gbi_id = $JLMS_DB->insertid(); $i++; } // **************************************************************************************************** // Get GradeBook Scale DATA and insert it into the 'lms_gradebook_scale' table $element =& $root->getElementByPath('gradebook_scale'); $gb_scale = JLMS_parse_XML_elements($element->children(), array('min_val', 'max_val', 'ordering'), array('scale_name')); $i = 0; while ($i < count($gb_scale)) { $insert = new stdClass(); $insert->course_id = $course_id; $insert->scale_name = $gb_scale[$i]->scale_name; $insert->min_val = $gb_scale[$i]->min_val; $insert->max_val = $gb_scale[$i]->max_val; $insert->ordering = $gb_scale[$i]->ordering; $JLMS_DB->insertObject("#__lms_gradebook_scale", $insert, "id"); $gb_scale[$i]->new_gbs_id = $JLMS_DB->insertid(); $i++; } // **************************************************************************************************** // Get GradeBook Scale DATA and insert it into the 'lms_gradebook_scale' table $element =& $root->getElementByPath('gradebook_lpaths'); $gb_lpaths = JLMS_parse_XML_elements($element->children(), array('learn_path_id'), array()); $i = 0; while ($i < count($gb_lpaths)) { $insert = new stdClass(); $insert->course_id = $course_id; $insert->learn_path_id = 0; foreach ($l_paths as $lp) { if ($gb_lpaths[$i]->learn_path_id == $lp->id) { $insert->learn_path_id = $lp->new_step_id; } } if ($insert->learn_path_id) { $JLMS_DB->insertObject("#__lms_gradebook_lpaths", $insert, "id"); } $i++; } } } // delete temporary files deldir($extract_dir); return $archive; }