Esempio n. 1
0
    function show_billing_form($option, $proc, $user)
    {
        global $Itemid, $JLMS_CONFIG;
        $params2 = new JLMSParameters($proc->params);
        if ($params2->get('description', 'Use this processor if you pay fees by bank account')) {
            // do not use language files here, this is default value for 'description' parameter from processor XML
            ?>
		<br />
		<table cellpadding="0" cellspacing="2" width="100%" border="0" class="jlms_table_no_borders">		
		<tr>
			<td align="left" valign="top" width="50%">
				<?php 
            echo JLMSCSS::h2(_JLMS_DESCRIPTION);
            echo $params2->get('description', 'Use this processor if you pay fees by bank account');
            ?>
			</td>
		</tr>
		</table>
		<br />
		<?php 
        }
    }
Esempio n. 2
0
function moveToCourseFromWaitingList($course_id)
{
    $dbo =& JFactory::getDbo();
    $query = "SELECT * FROM `#__lms_courses` WHERE id = '{$course_id}' AND self_reg != '0'  ";
    $dbo->setQuery($query);
    $course = $dbo->loadObject();
    $params = new JLMSParameters($course->params);
    $max_attendees = $params->get('max_attendees', 0);
    //count users in course
    $query = "SELECT COUNT(DISTINCT(user_id)) FROM `#__lms_users_in_groups` WHERE course_id = {$course_id}";
    // AND role_id = 2";
    $dbo->setQuery($query);
    $current_attendees = $dbo->loadResult();
    $limit = $max_attendees - $current_attendees;
    //course full - return true
    if ($limit <= 0) {
        return false;
    }
    $query = "SELECT user_id FROM #__lms_waiting_lists WHERE course_id={$course_id} ORDER BY ordering ASC";
    $dbo->setQuery($query, 0, $limit);
    $ids = $dbo->loadResultArray();
    $query = "DELETE FROM #__lms_waiting_lists WHERE course_id={$course_id} AND user_id IN (" . implode(',', $ids) . ")";
    $dbo->setQuery($query);
    $dbo->query();
    $result = array();
    $query = "INSERT INTO `#__lms_users_in_groups` ( course_id , user_id, enrol_time ) VALUES ";
    $first = true;
    foreach ($ids as $id) {
        $query .= !$first ? ',' : '';
        $query .= "\n({$course_id}, {$id}, '" . JLMS_gmdate() . "')";
        $first = false;
        $tmp = new stdClass();
        $tmp->user_id = $id;
        $tmp->course_id = $course_id;
        $result[] = $tmp;
    }
    $dbo->setQuery($query);
    $dbo->query();
    if (!count($result)) {
        return false;
    }
    return $result;
}
 function JQ_ViewCharts($quiz_id, $option, $id, $gqp = false)
 {
     global $JLMS_DB, $JLMS_CONFIG, $JLMS_SESSION, $my;
     $JLMS_ACL =& JLMSFactory::getACL();
     $usertype_simple = $JLMS_ACL->_role_type;
     //	$usertype_simple = JLMS_GetUserType_simple($my->id, false, true);
     //-------------------------------------------------------------------
     //FLMS multicat
     $levels = array();
     if ($gqp) {
         /*
         $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, 'filter_id_' . $i . '', $JLMS_SESSION->get('GQP_filter_id_' . $i . '', 0)));
                 $JLMS_SESSION->set('GQP_filter_id_' . $i . '', $level_id[$i]);
             } else {
                 $level_id[$i] = intval(mosGetParam($_REQUEST, 'filter_id_' . $i . '', $JLMS_SESSION->get('GQP_filter_id_' . $i . '', 0)));
                 $JLMS_SESSION->set('GQP_filter_id_' . $i . '', $level_id[$i]);
             }
             if ($i == 0) {
                 $parent_id[$i] = 0;
             } else {
                 $parent_id[$i] = $level_id[$i - 1];
             }
             if ($i == 0 || $parent_id[$i]) {
                 //(Max): extra requests
                 $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_filter_id_' . $i . '', $level_id[$i]);
                 }
             }
         }
         for ($i = 0; $i < count($levels); $i++) {
             if ($i > 0 && $level_id[$i - 1] == 0) {
                 $level_id[$i] = 0;
                 $JLMS_SESSION->set('GQP_filter_id_' . $i . '', $level_id[$i]);
                 $parent_id[$i] = 0;
             } elseif ($i == 0 && $level_id[$i] == 0) {
                 $level_id[$i] = 0;
                 $JLMS_SESSION->set('GQP_filter_id_' . $i . '', $level_id[$i]);
                 $parent_id[$i] = 0;
             }
         }
         $javascript = 'onclick="javascript:read_filter();" onchange="javascript:write_filter();document.adminFormQ.page.value=\'quiz_bars_gqp\';document.adminFormQ.submit();"';
         $query1 = "SELECT group_id FROM `#__lms_users_in_global_groups` WHERE user_id = '" . $my->id . "'";
         $JLMS_DB->setQuery($query1);
         $user_group_ids = $JLMS_DB->loadResultArray();
         for ($i = 0; $i < count($levels); $i++) {
             if ($i == 0 || $parent_id[$i]) {
                 //(Max): extra requests
                 if ($parent_id[$i] == 0 && $usertype_simple == 1) {
                     //(Max): roletype_id
                     $query = "SELECT * FROM `#__lms_gqp_cats` WHERE `parent` = '0'";
                     $query .= "\n ORDER BY `c_category`";
                 } else {
                     $query = "SELECT * FROM `#__lms_gqp_cats` WHERE parent = '" . $parent_id[$i] . "' ORDER BY c_category";
                 }
                 $JLMS_DB->setQuery($query);
                 $groups = $JLMS_DB->loadObjectList();
                 if ($parent_id[$i] && $i > 0 && count($groups)) {
                     $type_level[$i][] = mosHTML::makeOption(0, ' &nbsp; ');
                     foreach ($groups as $group) {
                         $type_level[$i][] = mosHTML::makeOption($group->id, $group->c_category);
                     }
                     $lists['filter_' . $i . ''] = mosHTML::selectList($type_level[$i], 'filter_id_' . $i . '', 'class="inputbox" style="width: 266px;" size="1" ' . $javascript, 'value', 'text', $level_id[$i]);
                     //onchange="document.location.href=\''. $link_multi .'\';"
                 } elseif ($i == 0) {
                     $type_level[$i][] = mosHTML::makeOption(0, ' &nbsp; ');
                     foreach ($groups as $group) {
                         $type_level[$i][] = mosHTML::makeOption($group->id, $group->c_category);
                     }
                     $lists['filter_' . $i . ''] = mosHTML::selectList($type_level[$i], 'filter_id_' . $i . '', 'class="inputbox" style="width: 266px;" size="1" ' . $javascript, 'value', 'text', $level_id[$i]);
                     //onchange="document.location.href=\''. $link_multi .'\';"
                 }
             }
         }
     }
     //-------------------------------------------------------------------
     $is_pool = 0;
     $showtype_id = JRequest::getVar('showtype_id', 0, '', 'ALNUM');
     if (!$quiz_id) {
         $quiz_id = intval(mosGetParam($_REQUEST, 'quiz_id', -1));
     }
     if ($quiz_id == -1 || $quiz_id == 0) {
         $is_pool = 1;
         $quiz_id = 0;
     }
     $group_id = intval(mosGetParam($_REQUEST, 'group_id', 0));
     $questCatId = 0;
     if (strpos($showtype_id, SL_CATPREF) !== false) {
         $questCatId = (int) ltrim($showtype_id, SL_CATPREF);
         $showtype_id = 0;
     }
     if ($group_id) {
         if (!$gqp) {
             $query = "SELECT b.user_id FROM #__lms_users_in_global_groups as b, #__lms_users_in_groups as c";
             $query .= "\n WHERE b.user_id = c.user_id AND c.course_id = '" . $id . "'";
             $query .= "\n AND b.group_id = '" . $group_id . "'";
         } else {
             $query = "SELECT b.user_id FROM #__lms_users_in_global_groups as b";
             $query .= "\n WHERE ";
             $query .= "\n b.group_id = '" . $group_id . "'";
         }
     } else {
         $query = "SELECT c.user_id FROM #__lms_users_in_groups as c";
         $query .= "\n WHERE c.course_id = '" . $id . "'";
     }
     $JLMS_DB->setQuery($query);
     $user_in_groups = $JLMS_DB->loadResultArray();
     $str_user_in_groups = '0';
     if (count($user_in_groups)) {
         $str_user_in_groups = implode(",", $user_in_groups);
     }
     //	echo '<pre>';
     //	print_r($user_in_groups);
     //	echo '</pre>';
     $pageNav = '';
     if (!$gqp) {
         $AND = '';
         if ($questCatId) {
             $AND = ' AND qc.c_id = ' . $questCatId;
         }
         $query = "SELECT a.*, b.c_qtype as qtype_full, c.c_title as quiz_name, qc.c_category" . "\n FROM #__lms_quiz_t_question a LEFT JOIN #__lms_quiz_t_qtypes b ON b.c_id = a.c_type LEFT JOIN #__lms_quiz_t_quiz c ON a.c_quiz_id = c.c_id AND c.course_id = '" . $id . "'" . "\n LEFT JOIN #__lms_quiz_t_category as qc ON a.c_qcat = qc.c_id AND qc.course_id = '" . $id . "' AND qc.is_quiz_cat = 0" . "\n WHERE a.course_id = '" . $id . "'" . "\n AND c_quiz_id = '" . $quiz_id . "'" . $AND . "\n ORDER BY a.ordering, a.c_id";
         $JLMS_DB->setQuery($query);
         $total = count($JLMS_DB->loadObjectList());
         $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));
         require_once _JOOMLMS_FRONT_HOME . DS . "includes" . DS . "classes" . DS . "lms.pagination.php";
         $pageNav = new JLMSPageNav($total, $limitstart, $limit);
         $query = "SELECT a.*, b.c_qtype as qtype_full, c.c_title as quiz_name, qc.c_category" . "\n FROM #__lms_quiz_t_question a LEFT JOIN #__lms_quiz_t_qtypes b ON b.c_id = a.c_type LEFT JOIN #__lms_quiz_t_quiz c ON a.c_quiz_id = c.c_id AND c.course_id = '" . $id . "'" . "\n LEFT JOIN #__lms_quiz_t_category as qc ON a.c_qcat = qc.c_id AND qc.course_id = '" . $id . "' AND qc.is_quiz_cat = 0" . "\n WHERE a.course_id = '" . $id . "'" . "\n AND c_quiz_id = '" . $quiz_id . "'" . $AND . "\n ORDER BY a.ordering, a.c_id" . "\n LIMIT {$pageNav->limitstart}, {$pageNav->limit}";
     } else {
         //echo "qqqq"; die;
         $str = '';
         //NEW MUSLTICATS
         $tmp_level = array();
         $last_catid = 0;
         $i = 0;
         foreach ($_REQUEST as $key => $item) {
             if (preg_match('#filter_id_(\\d+)#', $key, $result)) {
                 if ($item) {
                     $tmp_level[$i] = $result;
                     $last_catid = $item;
                     $i++;
                 }
             }
         }
         if (!$i) {
             foreach ($_SESSION as $key => $item) {
                 if (preg_match('#GQP_filter_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
         /*
         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]."";
         		break;
         	}
         }
         */
         /*---------------navigation-------------------*/
         $query = "SELECT a.*, b.c_qtype as qtype_full, qc.c_category" . "\n FROM" . "\n #__lms_quiz_t_question a," . "\n #__lms_quiz_t_qtypes b," . "\n #__lms_gqp_cats as qc" . "\n WHERE b.c_id = a.c_type" . "\n AND a.c_quiz_id = 0" . "\n AND a.course_id = 0" . $str . "\n GROUP BY a.c_id" . "\n ORDER BY a.ordering, a.c_id";
         $JLMS_DB->setQuery($query);
         $total = count($JLMS_DB->loadObjectList());
         $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));
         require_once _JOOMLMS_FRONT_HOME . DS . "includes" . DS . "classes" . DS . "lms.pagination.php";
         $pageNav = new JLMSPageNav($total, $limitstart, $limit);
         /*--------------------------------------------*/
         $query = "SELECT a.*, b.c_qtype as qtype_full, qc.c_category" . "\n FROM" . "\n #__lms_quiz_t_question a," . "\n #__lms_quiz_t_qtypes b," . "\n #__lms_gqp_cats as qc" . "\n WHERE 1" . "\n AND b.c_id = a.c_type" . "\n AND a.c_quiz_id = 0" . "\n AND a.course_id = 0" . $str . "\n GROUP BY a.c_id" . "\n ORDER BY a.ordering, a.c_id" . "\n LIMIT {$pageNav->limitstart}, {$pageNav->limit}";
     }
     $JLMS_DB->setQuery($query);
     $rows = $JLMS_DB->loadObjectList();
     for ($i = 0; $i < count($rows); $i++) {
         $str = '_JLMS_QUIZ_QTYPE_' . $rows[$i]->c_type;
         if (defined($str)) {
             $rows[$i]->qtype_full = constant($str);
         }
     }
     $q_from_pool = array();
     foreach ($rows as $row) {
         if ($row->c_type == 20) {
             $q_from_pool[] = $row->c_pool;
         }
     }
     if (count($q_from_pool)) {
         $qp_ids = implode(',', $q_from_pool);
         $query = "SELECT a.*, b.c_qtype as qtype_full FROM #__lms_quiz_t_question as a LEFT JOIN #__lms_quiz_t_qtypes b ON b.c_id = a.c_type" . "\n WHERE a.course_id = '" . $id . "' AND a.c_id IN ({$qp_ids})";
         $JLMS_DB->setQuery($query);
         $rows2 = $JLMS_DB->loadObjectList();
         for ($i = 0; $i < count($rows2); $i++) {
             $str = '_JLMS_QUIZ_QTYPE_' . $rows2[$i]->c_type;
             if (defined($str)) {
                 $rows2[$i]->qtype_full = constant($str);
             }
         }
         for ($i = 0, $n = count($rows); $i < $n; $i++) {
             if ($rows[$i]->c_type == 20) {
                 for ($j = 0, $m = count($rows2); $j < $m; $j++) {
                     if ($rows[$i]->c_pool == $rows2[$j]->c_id) {
                         $rows[$i]->c_question = $rows2[$j]->c_question;
                         $rows[$i]->c_type = $rows2[$j]->c_type;
                         $rows[$i]->qtype_full = _JLMS_QUIZ_QUEST_POOL_SHORT . ' - ' . $rows2[$j]->qtype_full;
                         break;
                     }
                 }
             }
         }
     }
     $q_from_pool_gqp = array();
     foreach ($rows as $row) {
         if ($row->c_type == 21) {
             $q_from_pool_gqp[] = $row->c_pool_gqp;
         }
     }
     if (count($q_from_pool_gqp)) {
         $qp_ids_gqp = implode(',', $q_from_pool_gqp);
         $query = "SELECT a.*, b.c_qtype as qtype_full FROM #__lms_quiz_t_question as a LEFT JOIN #__lms_quiz_t_qtypes b ON b.c_id = a.c_type" . "\n WHERE a.course_id = 0 AND a.c_id IN ({$qp_ids_gqp})";
         $JLMS_DB->setQuery($query);
         $rows2 = $JLMS_DB->loadObjectList();
         for ($i = 0; $i < count($rows2); $i++) {
             $str = '_JLMS_QUIZ_QTYPE_' . $rows2[$i]->c_type;
             if (defined($str)) {
                 $rows2[$i]->qtype_full = constant($str);
             }
         }
         for ($i = 0, $n = count($rows); $i < $n; $i++) {
             if ($rows[$i]->c_type == 21) {
                 for ($j = 0, $m = count($rows2); $j < $m; $j++) {
                     if ($rows[$i]->c_pool_gqp == $rows2[$j]->c_id) {
                         $rows[$i]->c_question = $rows2[$j]->c_question;
                         $rows[$i]->c_type = $rows2[$j]->c_type;
                         $rows[$i]->qtype_full = _JLMS_QUIZ_QUEST_POOL_GQP_SHORT . ' - ' . $rows2[$j]->qtype_full;
                         break;
                     }
                 }
             }
         }
     }
     // 18 August 2007 - changes (DEN) - added check for GD and FreeType support
     $generate_images = true;
     $msg = '';
     if (!function_exists('imageftbbox') || !function_exists('imagecreatetruecolor')) {
         $generate_images = false;
         $sec = false;
         if (!function_exists('imagecreatetruecolor')) {
             $msg = 'This function requires GD 2.0.1 or later (2.0.28 or later is recommended).';
             $sec = true;
         }
         if (!function_exists('imageftbbox')) {
             $msg .= ($sec ? '<br />' : '') . 'This function is only available if PHP is compiled with freetype support.';
         }
     }
     // end of GD and FreeType support check
     if ($JLMS_CONFIG->get('temp_folder', '') && $generate_images) {
         // temp folder setup is ready.
         //--------- array of bar-images
         $rows_result = array();
         $img_arr = array();
         $title_arr = array();
         $count_graph = array();
         $img_correct = array();
         $title_correct = array();
         for ($i = 0, $n = count($rows); $i < $n; $i++) {
             $row = $rows[$i];
             $quest_params = new JLMSParameters($row->params);
             $z = 1;
             $show_case = true;
             if ($showtype_id && !$quest_params->get('survey_question')) {
                 $show_case = false;
             }
             if ($row->c_pool) {
                 $c_question_id = $row->c_pool;
             } elseif ($row->c_pool_gqp) {
                 $c_question_id = $row->c_pool_gqp;
             } else {
                 $c_question_id = $row->c_id;
             }
             if ($gqp) {
                 $query = "SELECT c_id FROM #__lms_quiz_t_question WHERE c_pool_gqp = '" . $row->c_id . "'";
                 $JLMS_DB->setQuery($query);
                 $gqp_id = $JLMS_DB->loadResult();
                 if ($gqp_id) {
                     $row->c_id = $gqp_id;
                 }
             }
             if ($show_case) {
                 require_once _JOOMLMS_FRONT_HOME . "/includes/libraries/lms.lib.graph.php";
                 $obj_GraphStat = JLMS_GraphStatistics($option, $id, $quiz_id, $i, $z, $row, $c_question_id, $group_id, $str_user_in_groups);
                 foreach ($obj_GraphStat as $key => $item) {
                     if (preg_match_all('#([a-z]+)_(\\w+)#', $key, $out, PREG_PATTERN_ORDER)) {
                         if ($out[1][0] == 'img') {
                             $img_arr[$i]->{$out}[2][0] = $item;
                             $rows_result[$i]->images_array->{$out}[2][0] = $item;
                         } else {
                             if ($out[1][0] == 'title') {
                                 $title_arr[$i]->{$out}[2][0] = $item;
                                 $rows_result[$i]->title_array->{$out}[2][0] = $item;
                             } else {
                                 if ($out[1][0] == 'count') {
                                     $count_graph[$i]->{$out}[2][0] = $item;
                                     $rows_result[$i]->count_array->{$out}[2][0] = $item;
                                 }
                             }
                         }
                     }
                 }
                 /*if(isset($obj_GraphStat->img_graph)){
                 			$img_arr[$i]->graph = $obj_GraphStat->img_graph;
                 		}*/
                 /*$img_arr[$i]->graph = $JLMS_CONFIG->get('temp_folder', '').'/'.$filename;
                 		$title_arr[$i]->graph = trim(strip_tags($row->c_question)); 	
                 		$count_graph[$i]->graph = 1;
                 		$img_arr[$i]->correct = $JLMS_CONFIG->get('temp_folder', '').'/'.$filename;
                 		$title_arr[$i]->correct = trim(strip_tags($row->c_question));
                 		$count_graph[$i]->correct = 1;*/
             }
         }
     }
     //	echo '<pre>';
     //	print_r($rows_result);
     //	echo '</pre>';
     if (!$gqp) {
         $lists = array();
     }
     $javascript = 'onchange="if(document.adminFormQ.quiz_id.value != 0){document.adminFormQ.submit();}"';
     $query = "SELECT c_id AS value, c_title AS text" . "\n FROM #__lms_quiz_t_quiz" . "\n WHERE course_id = '" . $id . "'" . "\n ORDER BY c_title";
     $JLMS_DB->setQuery($query);
     $quizzes = array();
     $quizzes[] = mosHTML::makeOption('0', _JLMS_SB_SELECT_QUIZ);
     $quizzes[] = mosHTML::makeOption('-1', _JLMS_QUIZ_QUEST_POOL);
     $quizzes = array_merge($quizzes, $JLMS_DB->loadObjectList());
     $quiz = mosHTML::selectList($quizzes, 'quiz_id', 'class="inputbox" size="1" ' . $javascript, 'value', 'text', $is_pool ? -1 : $quiz_id);
     $lists['quiz'] = $quiz;
     if ($gqp) {
         $javascript = 'onchange="document.adminFormQ.page.value=\'quiz_bars_gqp\'; document.adminFormQ.submit();"';
     } else {
         $javascript = 'onchange="document.adminFormQ.submit();"';
     }
     $query = "SELECT CONCAT( '" . SL_CATPREF . "', c_id ) AS value, c_category AS text" . "\n FROM #__lms_quiz_t_category" . "\n WHERE is_quiz_cat = 0 AND course_id = " . $id . "\n ORDER BY c_category";
     $JLMS_DB->setQuery($query);
     $showtype = array();
     $showtype[] = mosHTML::makeOption('0', _JLMS_QUIZ_ALL_QUESTIONS);
     $showtype[] = mosHTML::makeOption('1', _JLMS_QUIZ_SURVEY_QUESTIONS);
     $showtype = array_merge($showtype, $JLMS_DB->loadObjectList());
     if ($questCatId) {
         $showtype_id = SL_CATPREF . $questCatId;
     }
     $shtype = mosHTML::selectList($showtype, 'showtype_id', 'class="inputbox" size="1" ' . $javascript, 'value', 'text', $showtype_id);
     $lists['showtype'] = $shtype;
     $query = "SELECT id as value, ug_name as text FROM #__lms_usergroups WHERE course_id = '0'";
     $JLMS_DB->setQuery($query);
     $showgroups = array();
     $showgroups[] = mosHTML::makeOption('0', _JLMS_ATT_FILTER_ALL_GROUPS);
     $showgroups = array_merge($showgroups, $JLMS_DB->loadObjectList());
     $lists['showgroups'] = mosHTML::selectList($showgroups, 'group_id', 'class="inputbox" size="1" ' . $javascript, 'value', 'text', $group_id);
     JLMS_quiz_admin_html_class::JQ_showBars($rows_result, $lists, $id, $option, $gqp, $levels, $pageNav);
 }
    function JLMS_sreportCertif($hits, $users, $courses, $pageNav, $lists, $levels, $filt_cat, $filt_group, $option, $is_full)
    {
        $JLMS_CONFIG =& JLMSFactory::getConfig();
        global $JLMS_DB;
        $Itemid = $JLMS_CONFIG->get('Itemid');
        //FLMS multicat
        $multicat = array();
        if ($JLMS_CONFIG->get('multicat_use', 0)) {
            $multicat = array();
            $i = 0;
            foreach ($lists as $key => $item) {
                if (substr($key, 0, 7) == 'filter_') {
                    $multicat[] = $lists['filter_' . $i];
                    $i++;
                }
            }
        }
        ?>
	
	<?php 
        JLMS_TMPL::OpenMT();
        if ($is_full) {
            $hparams = array('show_menu' => false);
        } else {
            $hparams = array('simple_menu' => true);
        }
        $toolbar = array();
        $page_heading = _JLMS_REPORTS_CONCLUSION;
        if ($JLMS_CONFIG->get('is_trial', false) && $JLMS_CONFIG->get('trial_reports_heading_text', '')) {
            $page_heading .= $JLMS_CONFIG->get('trial_reports_heading_text', '');
        }
        JLMS_TMPL::ShowHeader('tracking', $page_heading, $hparams, $toolbar);
        JLMS_TMPL::OpenTS();
        ?>
	<script language="javascript" type="text/javascript">
	<!--//--><![CDATA[//><!--
	var old_filters = new Array();
	function read_filter(){
		var form = document.adminForm;
		var count_levels = '<?php 
        echo count($levels);
        ?>
';
		for(var i=0;i<parseInt(count_levels);i++){
			if(form['filter_id_'+i] != null){
				old_filters[i] = form['filter_id_'+i].value;
			}
		}
	}
	function write_filter(){
		var form = document.adminForm;
		var count_levels = '<?php 
        echo count($levels);
        ?>
';
		var j;
		for(var i=0;i<parseInt(count_levels);i++){
			if(form['filter_id_'+i+''] != null && form['filter_id_'+i+''].value != old_filters[i]){
				j = i;
			}
			if(i > j){
				if(form['filter_id_'+i] != null){
					form['filter_id_'+i].value = 0;	
				}
			}
		}
	}
	function submitFormView(view){
		var form = document.adminForm;
		form.view.value = view;
		form.task.value='report_certif';
		form.submit();
	}
	
	//--><!]]>
	</script>
	<?php 
        $action_url = $is_full ? $JLMS_CONFIG->get('live_site') . "/index.php?tmpl=component&amp;option={$option}&amp;Itemid={$Itemid}" : sefRelToAbs("index.php?option={$option}&amp;Itemid={$Itemid}");
        ?>
			<form action="<?php 
        echo $action_url;
        ?>
" method="post" name="adminForm">
					<table width="100%" cellpadding="0" cellspacing="0" border="0" id="TheTable" class="jlms_table_no_borders">
						<?php 
        if (!$is_full) {
            ?>
						<tr>
							<td align="<?php 
            echo $is_full ? "left" : "right";
            ?>
">
								<table <?php 
            echo $is_full ? '' : 'width="30%"';
            ?>
 class="jlms_table_no_borders">
									<tr>
										<td valign="top" <?php 
            echo $is_full ? 'width="400"' : 'width="40%"';
            ?>
>
											<table width="100%" border="0" class="jlms_table_no_borders">
												<tr>
													<td <?php 
            echo $is_full ? 'width="100"' : 'width="20%"';
            ?>
 nowrap="nowrap">
														Report Type:
													</td>
													<td>
														<?php 
            echo JLMS_switchType($option);
            ?>
													</td>
												</tr>
											</table>		
										</td>
									</tr>
								</table>	
							</td>
						</tr>
						<?php 
        }
        ?>
						<tr>	
							<td align="left">
								<table <?php 
        echo $is_full ? '' : 'width="100%"';
        ?>
 class="jlms_table_no_borders">
									<tr>
										<td valign="top" <?php 
        echo $is_full ? 'width="400"' : 'width="40%"';
        ?>
>
											<table width="100%" border="0" class="jlms_table_no_borders">
												<?php 
        if ($is_full) {
            ?>
												<tr>
													<td <?php 
            echo $is_full ? 'width="100"' : 'width="20%"';
            ?>
 nowrap="nowrap">
														Report Type:
													</td>
													<td>
														<?php 
            echo JLMS_switchType($option);
            ?>
													</td>
												</tr>
												<?php 
        }
        ?>
												<tr>
													<td <?php 
        echo $is_full ? 'width="100"' : 'width="20%"';
        ?>
 nowrap="nowrap">
														<?php 
        if ($JLMS_CONFIG->get('multicat_use', 0)) {
            echo isset($levels[0]->cat_name) && $levels[0]->cat_name != '' ? $levels[0]->cat_name : _JLMS_COURSES_COURSES_GROUPS;
        } else {
            echo _JLMS_COURSES_COURSES_GROUPS;
        }
        ?>
													</td>
													<td>
														<?php 
        if ($JLMS_CONFIG->get('multicat_use', 0)) {
            echo $lists['filter_0'];
        } else {
            echo $lists['jlms_course_cats'];
        }
        ?>
													</td>
												</tr>
												<?php 
        if (count($multicat)) {
            for ($i = 0; $i < count($multicat); $i++) {
                if ($i > 0) {
                    ?>
															<tr>
																<td <?php 
                    echo $is_full ? 'width="100"' : 'width="20%"';
                    ?>
 nowrap="nowrap">
																	<?php 
                    echo isset($levels[$i]->cat_name) && $levels[$i]->cat_name != '' ? $levels[$i]->cat_name : _JLMS_COURSES_COURSES_GROUPS;
                    ?>
																</td>
																<td>
																	<?php 
                    echo $lists['filter_' . $i];
                    ?>
																</td>
															</tr>
															<?php 
                }
            }
        }
        ?>
											</table>
										</td>
										
										<td valign="top" <?php 
        echo $is_full ? 'width="400"' : 'width="40%"';
        ?>
>
										<?php 
        if ($JLMS_CONFIG->get('use_global_groups', 1)) {
            ?>
											<table width="100%" border="0" cellpadding="0" cellspacing="0" class="jlms_table_no_borders">
												<?php 
            if ($is_full) {
                ?>
												<tr>
													<td colspan="2">
														&nbsp;
													</td>
												</tr>
												<?php 
            }
            ?>
												<tr>
													<td style="padding-left: 5px;" <?php 
            echo $is_full ? 'width="100"' : 'width="20%"';
            ?>
 nowrap="nowrap">
														<?php 
            echo _JLMS_USER_GROUP_INFO;
            ?>
													</td>
													<td>
														<?php 
            echo $lists['filter'];
            ?>
													</td>
												</tr>
											</table>
										<?php 
        }
        ?>
										</td>
										
										<?php 
        if (!$is_full) {
            ?>
										<td style="padding-left:15px;" align="right" class="jlms_table_no_borders">
											<?php 
            $link = $JLMS_CONFIG->get('live_site') . "/index.php?tmpl=component&amp;option=" . $option . "&amp;Itemid={$Itemid}&amp;task=report_certif&amp;is_full=1";
            if ($filt_group) {
                $link .= "&amp;filt_group=" . $filt_group;
            }
            ?>
										
											<a href="<?php 
            echo $link;
            ?>
" target="_blank" title="<?php 
            echo _JLMS_FULL_VIEW_BUTTON;
            ?>
"><?php 
            echo _JLMS_FULL_VIEW_BUTTON;
            ?>
]</a>
										</td>
										<?php 
        }
        ?>
									</tr>
								</table>		
							</td>
						</tr>
					</table>
					<?php 
        if (!$is_full) {
            $domready = '
							$(\'pre_div\').setStyles({\'display\': \'none\'});
							$(\'vw_div\').setStyles({\'display\': \'block\'});
							var cur_height = $(\'vw_div\').getStyle(\'height\').toInt() + 18;
							$(\'vw_div\').setStyles({\'width\': $(\'TheTable\').offsetWidth+\'px\', \'height\': cur_height+\'px\'});
							';
            $JLMS_CONFIG->set('web20_domready_code', $JLMS_CONFIG->get('web20_domready_code', '') . $domready);
            ?>
					<div id="pre_div" style="display: block; width: 100%; text-align: center;">
						<br />
						Please wait. <?php 
            echo _JLMS_REPORTS_CONCLUSION;
            ?>
 is loading.<br /> If this message stays for over 1 minute, please click <a target="_blank" href="<?php 
            echo $link;
            ?>
">&lt;here&gt;</a> to open <?php 
            echo _JLMS_REPORTS_CONCLUSION;
            ?>
 in new window.
					</div>
					<div id="vw_div" style="overflow: auto; width: 200px; height: auto; display: none;">
					<?php 
        }
        ?>
					<table width="100%" cellpadding="<?php 
        echo $is_full ? '4' : '0';
        ?>
" cellspacing="0" border="0" class="<?php 
        echo JLMSCSS::_('jlmslist', 'jlms_report_fullview_table');
        ?>
" style="margin-bottom: 0px; padding-bottom:0px;">
					<?php 
        $courses_str = implode(',', $courses);
        $users_str = implode(',', $users);
        $JLMS_DB->setQuery('SELECT course_name FROM #__lms_courses WHERE id IN(' . $courses_str . ') ORDER BY course_name');
        $crs_name = $JLMS_DB->loadResultArray();
        $JLMS_DB->setQuery('SELECT * FROM #__lms_courses WHERE id IN(' . $courses_str . ') ORDER BY course_name');
        $crs_options = $JLMS_DB->loadObjectList();
        $cut_for = $JLMS_CONFIG->get('cutoff_reports_coursename', 0);
        echo '<tr>';
        echo '<' . JLMSCSS::tableheadertag() . ' class="' . JLMSCSS::_('sectiontableheader') . '" style="text-align:center; white-space:nowrap">' . _JLMS_OU_USER . '</' . JLMSCSS::tableheadertag() . '>';
        foreach ($crs_name as $key => $c_name) {
            if (!$is_full) {
                if ($cut_for) {
                    if (strlen($c_name) > $cut_for) {
                        $c_name = jlms_string_substr($c_name, 0, $cut_for) . "...";
                    }
                }
            }
            $view_is_course = 1;
            if ($JLMS_CONFIG->get('flms_integration', 1)) {
                $params = new JLMSParameters($crs_options[$key]->params);
                $view_is_course = $params->get('show_in_report', 1);
            }
            if ($view_is_course) {
                echo '<' . JLMSCSS::tableheadertag() . ' class="' . JLMSCSS::_('sectiontableheader') . '" style="text-align:center;">' . $c_name . '</' . JLMSCSS::tableheadertag() . '>';
            }
        }
        echo '</tr>';
        $zzz = 0;
        foreach ($users as $usr_id) {
            $JLMS_DB->setQuery('SELECT name FROM #__users WHERE id =' . $usr_id);
            $usrname = $JLMS_DB->LoadResult();
            $course_hits = 0;
            echo '<tr class="' . JLMSCSS::_('sectiontableentry' . ($zzz % 2 + 1)) . '">';
            $linka = sefRelToAbs(($is_full ? "index.php?tmpl=component&" : "index.php?") . 'option=' . $option . '&amp;Itemid=' . $Itemid . '&amp;task=report_grade&amp;filt_group=' . $filt_group . '&amp;filt_user='******'&amp;is_full=' . $is_full);
            echo '<td nowrap="nowrap"><a href="' . $linka . '">' . $usrname . '</a></td>';
            foreach ($courses as $key => $course_id) {
                $hit_num = _JLMS_NO_ALT_TITLE;
                for ($i = 0; $i < count($hits); $i++) {
                    if ($hits[$i]->c_id == $course_id && $hits[$i]->usr_id == $usr_id) {
                        $hit_num = _JLMS_YES_ALT_TITLE;
                        break;
                        // by DEN
                    }
                }
                $view_is_course = 1;
                if ($JLMS_CONFIG->get('flms_integration', 1)) {
                    $params = new JLMSParameters($crs_options[$key]->params);
                    $view_is_course = $params->get('show_in_report', 1);
                }
                if ($view_is_course) {
                    echo '<td align="center">' . $hit_num . '</td>';
                }
            }
            echo '</tr>';
            $zzz++;
        }
        ?>
					</table>
					<?php 
        if ($is_full) {
            $controls = array();
            $controls[] = array('href' => "javascript:submitFormView('csv');", 'title' => 'CSV', 'img' => 'csv');
            $controls[] = array('href' => "javascript:submitFormView('xls');", 'title' => 'XLS', 'img' => 'xls');
            JLMS_TMPL::ShowControlsFooterC($controls, '', false, false, _JLMS_EXPORT_TO . ':', true);
        } else {
            ?>
	
					</div>
					<table width="100%" cellpadding="0" cellspacing="0" border="0" class="<?php 
            echo JLMSCSS::_('jlmslist');
            ?>
" style="margin-top:0px; padding-top:0px; margin-bottom:0px;">
						<tr>
							<td align="center" style="text-align:center;" class="<?php 
            echo JLMSCSS::_('jlmslist-footer_td');
            ?>
">
								<div align="center" style="white-space:nowrap ">
								<?php 
            $link = "index.php?option={$option}&amp;Itemid={$Itemid}&amp;task=report_certif&amp;filt_group={$filt_group}&amp;filt_cat={$filt_cat}";
            echo _JLMS_PN_DISPLAY_NUM . $pageNav->getLimitBox($link) . '&nbsp;' . $pageNav->getPagesCounter();
            echo '<br />';
            echo $pageNav->writePagesLinks($link);
            ?>
 
								</div>
							</td>
						</tr>
					</table>
						<?php 
            if ($JLMS_CONFIG->get('new_lms_features', 1)) {
                $controls = array();
                $controls[] = array('href' => "javascript:submitFormView('csv');", 'title' => 'CSV', 'img' => 'csv');
                $controls[] = array('href' => "javascript:submitFormView('xls');", 'title' => 'XLS', 'img' => 'xls');
                JLMS_TMPL::ShowControlsFooterC($controls, '', false, false, _JLMS_EXPORT_TO . ':');
            }
            ?>
					<?php 
        }
        ?>
					<input type="hidden" name="option" value="<?php 
        echo $option;
        ?>
" />
					<input type="hidden" name="Itemid" value="<?php 
        echo $Itemid;
        ?>
" />
					<input type="hidden" name="task" value="report_certif" />
					<input type="hidden" name="view" value="" />
					<input type="hidden" name="is_full" value="<?php 
        echo $is_full;
        ?>
" />
			</form>
			
			<?php 
        $action_url = $is_full ? $JLMS_CONFIG->get('live_site') . "/index.php?tmpl=component&amp;option={$option}&amp;Itemid={$Itemid}" : sefRelToAbs("index.php?option={$option}&amp;Itemid={$Itemid}");
        ?>

			<form action="<?php 
        echo $action_url;
        ?>
" method="post" name="adminFormCsv">
					<input type="hidden" name="option" value="<?php 
        echo $option;
        ?>
" />
					<input type="hidden" name="Itemid" value="<?php 
        echo $Itemid;
        ?>
" />
					<input type="hidden" name="task" value="report_certif" />
					<input type="hidden" name="is_full" value="1" />
					<input type="hidden" name="view" value="" />
			</form>
		<?php 
        JLMS_TMPL::CloseTS();
        JLMS_TMPL::CloseMT();
    }
Esempio n. 5
0
    function validate_callback($proc)
    {
        global $JLMS_DB, $Itemid, $JLMS_CONFIG, $JLMS_DB;
        $params = new JLMSParameters($proc->params);
        // assign posted variables to local variables
        $payment_status = $_REQUEST['transStatus'];
        $payment_amount = $_REQUEST['authAmount'];
        $payment_currency = $_REQUEST['authCurrency'];
        $txn_id = $_REQUEST['transId'];
        $payment_date = date("Y-m-d H:i:s", mktime());
        $order = $_REQUEST['MC_order'];
        $tax_amount = $_REQUEST['MC_tax'];
        $user_id = $_REQUEST['MC_user'];
        $callback_pw = @$_REQUEST['callbackPW'];
        if ($payment_status != 'Y') {
            die('Invalid transaction status');
        }
        if ($callback_pw != $params->get('callback_pw')) {
            die('Invalid callback password');
        }
        // check that txn_id has not been previously processed
        $query = "SELECT id FROM `#__lms_payments` WHERE txn_id='" . $txn_id . "'  ";
        $JLMS_DB->setQuery($query);
        $res = $JLMS_DB->query();
        if (mysql_num_rows($res)) {
            die;
        }
        // check that payment_currency is correct
        if ($payment_currency != $JLMS_CONFIG->get('jlms_cur_code')) {
            die;
        }
        require_once _JOOMLMS_FRONT_HOME . '/includes/joomla_lms.subscription.lib.php';
        if ($payment_status == 'Y') {
            if (!jlms_check_payment_transaction($payment_amount - $tax_amount, $order)) {
                die('Invalid payment amount');
            }
            $query = "SELECT status FROM `#__lms_payments` WHERE id = {$order} ";
            $JLMS_DB->setQuery($query);
            $prev_payment = $JLMS_DB->LoadResult();
            jlms_update_payment($order, $txn_id, 'Completed', $payment_date);
            if ($prev_payment == 'Completed') {
            } else {
                jlms_register_new_user($order);
            }
            ?>
		Thanks for your payment, you were successfully added to the course.
<?php 
        } elseif ($payment_status == 'C') {
            jlms_update_payment($order, $txn_id, 'Pending', $payment_date);
            ?>
		Your payment status is still 'pending'. You will be added to the course as soon as your payment is confirmed.
<?php 
        }
    }
    function JQ_ShowQuiz($option, $course_id, $quiz, $jq_language, $self_verification, $is_preview = false, $preview_quest = 0, $preview_id = '')
    {
        global $Itemid, $JLMS_CONFIG, $JLMS_DB;
        $doc =& JFactory::getDocument();
        $domready = '
if (document.constructor) {
	document.constructor.prototype.write = function() { };
} else {
	document.write = function() { };
}
';
        $JLMS_CONFIG->set('web20_domready_code', $JLMS_CONFIG->get('web20_domready_code', '') . $domready);
        $doc->addScript($JLMS_CONFIG->get('live_site') . '/components/com_joomla_lms/includes/quiz/bits_message.js');
        if (JLMS_mootools12()) {
            $doc->addScript($JLMS_CONFIG->get('live_site') . '/components/com_joomla_lms/includes/quiz/dragdrop_1.3.js');
        } else {
            $doc->addScript($JLMS_CONFIG->get('live_site') . '/components/com_joomla_lms/includes/quiz/dragdrop_1.12.js');
        }
        if ($JLMS_CONFIG->get('quiz_progressbar', 0) == 1) {
            $doc->addScript($JLMS_CONFIG->get('live_site') . '/components/com_joomla_lms/includes/quiz/progressbar.js');
        }
        ?>
<script language="JavaScript" type="text/javascript">
<!--//--><![CDATA[//><!--
	var stu_quiz_id = 0;

	// *** DRAG'and'DROP CODE *** //
<?php 
        if ($quiz->if_dragdrop_exist) {
            ?>
	var kol_drag_elems = 0;
	var drag_array = new Array(kol_drag_elems);
	var coord_left = new Array(kol_drag_elems);
	var coord_top = new Array(kol_drag_elems);
	var ids_in_cont = new Array(kol_drag_elems);
	var cont_for_ids = new Array(kol_drag_elems);
	var answ_ids = new Array(kol_drag_elems);
	var cont_index = 0;
	var last_drag_id = '';
	var last_drag_id_drag = '';
	
	/*drag&drop mootools realised*/
	function excute_draggable(){
		var DD = new QuizDragDrop('cont', {dropitems: 'jq_drop', dragitems: 'jq_drag'});
	}
	
	function js_in_array(n, ha){
		for(h in ha){
			if(ha[h]==n){
				return true;
			}
		}
		return false;
	}

//});
	/*drag&drop mootools realised*/
	
<?php 
        }
        ?>
	// *** end of DRAG'and'DROP CODE *** //
	var kol_main_elems = 0;
	var main_ids_array = new Array(kol_main_elems); //for likert quest
	// *** MESSAGES *** (addslashes ???)
	var mes_complete_this_part = '<?php 
        echo $jq_language['mes_complete_this_part'];
        ?>
';
	var mes_loading = '<?php 
        echo $jq_language['quiz_load_data'];
        ?>
';
	var mes_failed = '<?php 
        echo $jq_language['quiz_failed'];
        ?>
';
	var mes_please_wait = '<?php 
        echo $jq_language['mes_please_wait'];
        ?>
';
	var mes_time_is_up = '<?php 
        echo $jq_language['quiz_mes_timeout'];
        ?>
';
	var mes_quest_number = '<?php 
        echo $jq_language['quiz_question_number'];
        ?>
';
	var mes_quest_points = '<?php 
        echo $jq_language['quiz_question_points'];
        ?>
';
	// *** some script variables ***
	var user_email_to = '';
	var user_unique_id = '';
	var cur_quest_type = '';
	var saved_prev_quest_data = '';
	var saved_prev_quest_exec_quiz_script = '';
	var save_prev_quest_exec_quiz_script_data = '';
	var saved_prev_res_data = '';
	var saved_prev_quest_id = 0;
	var saved_prev_quest_type = 0;
	var saved_prev_quest_score = 0;
	var saved_prev_quest_num = 0;
	var cur_quest_id = 0;
	var cur_quest_score = 0;
	var cur_quest_num = 0;
	var quiz_count_quests = 0;
	var cur_impscale_ex = 0;
	var response;
	var prev_correct = 0;
	var allow_attempt = 0;
	var timer_sec = <?php 
        echo isset($quiz->resume_timer_value) && $quiz->resume_timer_value ? $quiz->resume_timer_value : 0;
        ?>
;
	var stop_timer = 0;
	var result_is_shown = 0;
	var max_quiz_time = <?php 
        echo $quiz->c_time_limit ? $quiz->c_time_limit * 60 : 3600;
        ?>
;
	var quiz_blocked = 0; // set block after each question (release after 2 seconds).
	var url_prefix = '<?php 
        echo $JLMS_CONFIG->get('live_site') . "/index.php?option={$option}&Itemid={$Itemid}&jlms=1&task=quiz_ajax_action&id={$course_id}";
        ?>
';//'components/com_joomlaquiz/ajax_quiz.php';
	var mCfg_live_site = '';
	
	var stu_quiz_id = 0;
	var user_unique_id = 0;
	
	var quiz_progress = 0; // progressbar value
	
	var review = 0;

	function jq_MakeRequest(url, do_clear) {
		//if (do_clear == 1) jq_UpdateTaskDiv('clear');
		var http_request = false;
		if (window.ActiveXObject) { // IE
			try { http_request = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try { http_request = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) {}
			}
		} else if (window.XMLHttpRequest) { // Mozilla, Safari,...
			http_request = new XMLHttpRequest();
			if (http_request.overrideMimeType) {
				http_request.overrideMimeType('text/xml');
			}
		}
		if (!http_request) {
			return false;
		}
		if (do_clear == 1) {
			jq_showLoading();
		}
		quiz_blocked == 1;
		http_request.onreadystatechange = function() { jq_AnalizeRequest(http_request); };
		<?php 
        if ($is_preview) {
            ?>
		var url_prefix2 = 'preview_id=<?php 
            echo $preview_id;
            ?>
';
		<?php 
        } else {
            ?>
		var url_prefix2 = 'user_unique_id=' + user_unique_id;
		<?php 
        }
        ?>
		http_request.open('POST', mCfg_live_site + url_prefix, true);
		//http_request.send(null);
		http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		http_request.setRequestHeader("Content-length", url_prefix2.length + url.length);
		//http_request.setRequestHeader("Content-Encoding", "utf-8");
		//http_request.setRequestHeader("Connection", "close"); - if close - bug in IE7 - it hungs up
		http_request.send(url_prefix2 + url);
	}
	function jq_AnalizeRequest(http_request) {
		if (http_request.readyState == 4) {
			if ((http_request.status == 200)) {
				//alert(http_request.responseText);
				if(http_request.responseXML.documentElement == null){
					try {
						http_request.responseXML.loadXML(http_request.responseText)
					} catch (e) {
						/*alert('error');*/
					}
				}

				response  = http_request.responseXML.documentElement;
				var task = response.getElementsByTagName('task')[0].firstChild.data;
				ShowMessage('error_messagebox',0,'');

				switch (task) {
					case 'resume':

						user_unique_id = response.getElementsByTagName('user_unique_id')[0].firstChild.data;
						stu_quiz_id = response.getElementsByTagName('stu_quiz_id')[0].firstChild.data;

						cur_quest_id = response.getElementsByTagName('quest_id')[0].firstChild.data;

						quiz_count_quests = response.getElementsByTagName('quiz_count_quests')[0].firstChild.data;
						saved_prev_quest_id = cur_quest_id;
						
						<?php 
        if ($quiz->c_slide) {
            ?>
							getObj('jq_quiz_result_container').innerHTML = response.getElementsByTagName('quiz_panel_data')[0].firstChild.data;
						<?php 
        }
        ?>

						cur_quest_num = response.getElementsByTagName('quiz_quest_num')[0].firstChild.data;
						quiz_progress = response.getElementsByTagName('progress_quests_done')[0].firstChild.data;

						<?php 
        if ($JLMS_CONFIG->get('quiz_progressbar', 0) == 1) {
            ?>
						progressbar.setProgress(quiz_progress);
						<?php 
        }
        ?>

						jq_QuizContinue();
						jq_Start_TickTackResume();
					break;

					case 'start':
						quiz_blocked = 1;
						setTimeout("jq_releaseBlock()", 1000);
						user_unique_id = response.getElementsByTagName('user_unique_id')[0].firstChild.data;
						stu_quiz_id = response.getElementsByTagName('stu_quiz_id')[0].firstChild.data;
						cur_quest_type = response.getElementsByTagName('quest_type')[0].firstChild.data;
						saved_prev_quest_type = cur_quest_type;
						cur_quest_id = response.getElementsByTagName('quest_id')[0].firstChild.data;
						saved_prev_quest_id = cur_quest_id;
						cur_quest_score = response.getElementsByTagName('quest_score')[0].firstChild.data;
						saved_prev_quest_score = cur_quest_score;
						quiz_count_quests = response.getElementsByTagName('quiz_count_quests')[0].firstChild.data;
						cur_quest_num = response.getElementsByTagName('quiz_quest_num')[0].firstChild.data;
						saved_prev_quest_num = cur_quest_num;
						getObj('jq_quiz_container').innerHTML = '';
						if (cur_quest_type == 7) {
							var div_insidey=document.createElement("div");
							div_insidey.id = 'quest_div_hs';
							getObj('jq_quiz_container').appendChild(div_insidey);
						}
						var div_inside1=document.createElement("div");
						div_inside1.id = 'quest_div';

						div_inside1.innerHTML = response.getElementsByTagName('quest_data')[0].firstChild.data + response.getElementsByTagName('quest_data_user')[0].firstChild.data;
						saved_prev_quest_data = response.getElementsByTagName('quest_data')[0].firstChild.data + response.getElementsByTagName('quest_data_user')[0].firstChild.data;
						getObj('jq_quiz_container').appendChild(div_inside1);

						var quiz_menu = response.getElementsByTagName('quiz_menu')[0].firstChild.data;
						jq_UpdateTaskDiv_htm(quiz_menu);
						jq_UpdateTaskDiv('next');
						var is_exec_quiz_script = response.getElementsByTagName('exec_quiz_script')[0].firstChild.data;
						saved_prev_quest_exec_quiz_script = is_exec_quiz_script;
						if (is_exec_quiz_script == 1 || is_exec_quiz_script == '1' ) {
							var v_quiz_script_data = response.getElementsByTagName('quiz_script_data')[0].firstChild.data;
							saved_prev_quest_exec_quiz_script_data = v_quiz_script_data;
							eval(v_quiz_script_data);
						}
						jq_Start_TickTack();
						<?php 
        if ($quiz->c_slide) {
            ?>
							getObj('jq_quiz_result_container').innerHTML = response.getElementsByTagName('quiz_panel_data')[0].firstChild.data;
						<?php 
        }
        ?>
					break;
					case 'seek_quest':
						quiz_blocked = 1;
						setTimeout("jq_releaseBlock()", 1000);
						cur_quest_type = response.getElementsByTagName('quest_type')[0].firstChild.data;
						saved_prev_quest_type = cur_quest_type;
						cur_quest_id = response.getElementsByTagName('quest_id')[0].firstChild.data;
						saved_prev_quest_id = cur_quest_id;
						cur_quest_score = response.getElementsByTagName('quest_score')[0].firstChild.data;
						saved_prev_quest_score = cur_quest_score;
						cur_quest_num = response.getElementsByTagName('quiz_quest_num')[0].firstChild.data;
						saved_prev_quest_num = cur_quest_num;
						getObj('jq_quiz_container').innerHTML = '';
						if (cur_quest_type == 7) {
							var div_insidey=document.createElement("div");
							div_insidey.id = 'quest_div_hs';
							getObj('jq_quiz_container').appendChild(div_insidey);
						}
						var div_inside1=document.createElement("div");
						div_inside1.id = 'quest_div';
						div_inside1.innerHTML = response.getElementsByTagName('quest_data')[0].firstChild.data + response.getElementsByTagName('quest_data_user')[0].firstChild.data;
						saved_prev_quest_data = response.getElementsByTagName('quest_data')[0].firstChild.data + response.getElementsByTagName('quest_data_user')[0].firstChild.data;
						getObj('jq_quiz_container').appendChild(div_inside1);
						var quiz_menu = response.getElementsByTagName('quiz_menu')[0].firstChild.data;
						jq_UpdateTaskDiv_htm(quiz_menu);
						jq_UpdateTaskDiv('next');

						quiz_progress = response.getElementsByTagName('progress_quests_done')[0].firstChild.data;
						<?php 
        if ($JLMS_CONFIG->get('quiz_progressbar', 0) == 1) {
            ?>
							progressbar.setProgress(quiz_progress);
						<?php 
        }
        ?>

						var is_exec_quiz_script = response.getElementsByTagName('exec_quiz_script')[0].firstChild.data;
						saved_prev_quest_exec_quiz_script = is_exec_quiz_script;
						if (is_exec_quiz_script == 1 || is_exec_quiz_script == '1' ) {
							var v_quiz_script_data = response.getElementsByTagName('quiz_script_data')[0].firstChild.data;
							saved_prev_quest_exec_quiz_script_data = v_quiz_script_data;
							eval(v_quiz_script_data);
						}
					break;
					case 'review_start':
						quiz_blocked = 1;
						review = 1;
						setTimeout("jq_releaseBlock()", 1000);
						cur_quest_type = response.getElementsByTagName('quest_type')[0].firstChild.data;
						saved_prev_quest_type = cur_quest_type;
						cur_quest_id = response.getElementsByTagName('quest_id')[0].firstChild.data;
						saved_prev_quest_id = cur_quest_id;
						cur_quest_score = response.getElementsByTagName('quest_score')[0].firstChild.data;
						saved_prev_quest_score = cur_quest_score;
						quiz_count_quests = response.getElementsByTagName('quiz_count_quests')[0].firstChild.data;
						cur_quest_num = response.getElementsByTagName('quiz_quest_num')[0].firstChild.data;
						saved_prev_quest_num = cur_quest_num;
						
						
						getObj('jq_quiz_container').innerHTML = '';
						var div_inside1=document.createElement("div");
						div_inside1.id = 'quest_div';
						div_inside1.innerHTML = response.getElementsByTagName('quest_data')[0].firstChild.data + response.getElementsByTagName('quest_data_user')[0].firstChild.data;
						saved_prev_quest_data = response.getElementsByTagName('quest_data')[0].firstChild.data + response.getElementsByTagName('quest_data_user')[0].firstChild.data;
						getObj('jq_quiz_container').appendChild(div_inside1);
						var quiz_menu = response.getElementsByTagName('quiz_menu')[0].firstChild.data;
						quiz_review_correct = response.getElementsByTagName('quiz_review_correct')[0].firstChild.data;
						getObj('jq_quiz_result_reviews').innerHTML = quiz_review_correct;
						getObj('jq_quiz_result_reviews').style.display = 'block';
						getObj('jq_quiz_result_reviews').style.visibility = 'visible';
						getObj('jq_quiz_explanation').innerHTML = response.getElementsByTagName('quiz_review_explanation')[0].firstChild.data;;
						getObj('jq_quiz_explanation').style.display = 'block';
						getObj('jq_quiz_explanation').style.visibility = 'visible';
						jq_UpdateTaskDiv_htm(quiz_menu);
						jq_UpdateTaskDiv('review_next');
						
						var is_exec_quiz_script = response.getElementsByTagName('exec_quiz_script')[0].firstChild.data;
						saved_prev_quest_exec_quiz_script = is_exec_quiz_script;
						if (is_exec_quiz_script == 1 || is_exec_quiz_script == '1' ) {
							var v_quiz_script_data = response.getElementsByTagName('quiz_script_data')[0].firstChild.data;
							saved_prev_quest_exec_quiz_script_data = v_quiz_script_data;
							eval(v_quiz_script_data);
						}
						
						<?php 
        if ($quiz->c_slide) {
            ?>
							//getObj('jq_panel_link_container').style.visibility = 'visible';
						<?php 
        }
        ?>
					break;
					case 'review_next':
						quiz_blocked = 1;
						setTimeout("jq_releaseBlock()", 1000);
						cur_quest_type = response.getElementsByTagName('quest_type')[0].firstChild.data;
						saved_prev_quest_type = cur_quest_type;
						cur_quest_id = response.getElementsByTagName('quest_id')[0].firstChild.data;
						saved_prev_quest_id = cur_quest_id;
						prev_quest_id = response.getElementsByTagName('prev_quest_id')[0].firstChild.data;
						cur_quest_score = response.getElementsByTagName('quest_score')[0].firstChild.data;
						saved_prev_quest_score = cur_quest_score;
						cur_quest_num = response.getElementsByTagName('quiz_quest_num')[0].firstChild.data;
						saved_prev_quest_num = cur_quest_num;
						
						getObj('jq_quiz_container').innerHTML = '';
						var div_inside1=document.createElement("div");
						div_inside1.id = 'quest_div';
						div_inside1.innerHTML = response.getElementsByTagName('quest_data')[0].firstChild.data + response.getElementsByTagName('quest_data_user')[0].firstChild.data;
						saved_prev_quest_data = response.getElementsByTagName('quest_data')[0].firstChild.data + response.getElementsByTagName('quest_data_user')[0].firstChild.data;
						getObj('jq_quiz_container').appendChild(div_inside1);
						var quiz_menu = response.getElementsByTagName('quiz_menu')[0].firstChild.data;
						quiz_review_correct = response.getElementsByTagName('quiz_review_correct')[0].firstChild.data;
						getObj('jq_quiz_result_reviews').innerHTML = quiz_review_correct;
						getObj('jq_quiz_result_reviews').style.display = 'block';
						getObj('jq_quiz_result_reviews').style.visibility = 'visible';
						getObj('jq_quiz_explanation').innerHTML = response.getElementsByTagName('quiz_review_explanation')[0].firstChild.data;;
						getObj('jq_quiz_explanation').style.display = 'block';
						getObj('jq_quiz_explanation').style.visibility = 'visible';
						jq_UpdateTaskDiv_htm(quiz_menu);
						jq_UpdateTaskDiv('review_next');
						
						var is_exec_quiz_script = response.getElementsByTagName('exec_quiz_script')[0].firstChild.data;
						saved_prev_quest_exec_quiz_script = is_exec_quiz_script;
						if (is_exec_quiz_script == 1 || is_exec_quiz_script == '1' ) {
							var v_quiz_script_data = response.getElementsByTagName('quiz_script_data')[0].firstChild.data;
							saved_prev_quest_exec_quiz_script_data = v_quiz_script_data;
							eval(v_quiz_script_data);
						}
					break;
					case 'review_finish':
						quiz_blocked = 1;
						review = 0;
						setTimeout("jq_releaseBlock()", 1000);
						jq_UpdateTaskDiv('finish');
						var quiz_cont = getObj('jq_quiz_container');
						quiz_cont.innerHTML = saved_prev_res_data;//'<form name=\'quest_form\'><\/form>'+saved_prev_res_data;
					break;
					case 'next':
						quiz_blocked = 1;

						quiz_progress = response.getElementsByTagName('progress_quests_done')[0].firstChild.data;
						<?php 
        if ($JLMS_CONFIG->get('quiz_progressbar', 0) == 1) {
            ?>
						progressbar.setProgress(quiz_progress);
						<?php 
        }
        ?>

						setTimeout("jq_releaseBlock()", 1000);
						prev_correct = response.getElementsByTagName('quiz_prev_correct')[0].firstChild.data;
						var quiz_cont = getObj('jq_quiz_container');
						var children = quiz_cont.childNodes;
						for (var i = 0; i < children.length; i++) { quiz_cont.removeChild(quiz_cont.childNodes[i]); };
						quiz_cont.innerHTML = '';//'<form name=\'quest_form\'><\/form>';
						quest_feedback = response.getElementsByTagName('quest_feedback')[0].firstChild.data;
						if (quest_feedback == '1') {
							var qmb = response.getElementsByTagName('quiz_message_box')[0].firstChild.data;
							var quiz_menu = response.getElementsByTagName('quiz_menu')[0].firstChild.data;
							jq_UpdateTaskDiv_htm(quiz_menu);
							if (prev_correct == '1') {
							<?php 
        if ($quiz->c_slide) {
            ?>
								getObj('quest_result_'+saved_prev_quest_id).innerHTML = "<img src='<?php 
            echo $JLMS_CONFIG->get('live_site');
            ?>
/components/com_joomla_lms/lms_images/toolbar/btn_accept.png' border=0>";
							<?php 
        }
        ?>
								quiz_cont.innerHTML = qmb;//'<form name=\'quest_form\'><\/form>'+qmb;
								jq_UpdateTaskDiv('continue');
							} else {
							<?php 
        if ($quiz->c_slide) {
            ?>
								getObj('quest_result_'+saved_prev_quest_id).innerHTML = "<img src='<?php 
            echo $JLMS_CONFIG->get('live_site');
            ?>
/components/com_joomla_lms/lms_images/toolbar/btn_cancel.png' border=0>";
							<?php 
        }
        ?>
								quiz_cont.innerHTML = qmb;//'<form name=\'quest_form\'><\/form>'+qmb;
								allow_attempt = response.getElementsByTagName('quiz_allow_attempt')[0].firstChild.data;
								if (allow_attempt == '1') { allow_attempt = 0; jq_UpdateTaskDiv('back_continue');
								} else { allow_attempt = 0; jq_UpdateTaskDiv('continue'); }
							}
						} else {
							var qmb = '';
							var qfrf = response.getElementsByTagName('quest_feedback_repl_func')[0].firstChild.data;
							if (prev_correct == '1') {
							<?php 
        if ($quiz->c_slide) {
            ?>
								getObj('quest_result_'+saved_prev_quest_id).innerHTML = "<img src='<?php 
            echo $JLMS_CONFIG->get('live_site');
            ?>
/components/com_joomla_lms/lms_images/toolbar/btn_accept.png' border=0>";
							<?php 
        }
        ?>
							} else {
							<?php 
        if ($quiz->c_slide) {
            ?>
								getObj('quest_result_'+saved_prev_quest_id).innerHTML = "<img src='<?php 
            echo $JLMS_CONFIG->get('live_site');
            ?>
/components/com_joomla_lms/lms_images/toolbar/btn_cancel.png' border=0>";
							<?php 
        }
        ?>
							}
							eval(qfrf);
						}
					break;
					<?php 
        if ($is_preview) {
            ?>
					case 'quest_preview':
						quiz_blocked = 1;
						setTimeout("jq_releaseBlock()", 1000);
						quiz_count_quests = response.getElementsByTagName('quiz_count_quests')[0].firstChild.data;
						var quiz_cont = getObj('jq_quiz_container');
						var children = quiz_cont.childNodes;
						for (var i = 0; i < children.length; i++) { quiz_cont.removeChild(quiz_cont.childNodes[i]); };
						var qmb = response.getElementsByTagName('quiz_message_box')[0].firstChild.data;
						quiz_cont.innerHTML = '';//<form name=\'quest_form\'></form>';
						cur_quest_type = response.getElementsByTagName('quest_type')[0].firstChild.data;
						saved_prev_quest_type = cur_quest_type;
						cur_quest_id = response.getElementsByTagName('quest_id')[0].firstChild.data;
						saved_prev_quest_id = cur_quest_id;
						cur_quest_score = response.getElementsByTagName('quest_score')[0].firstChild.data;
						saved_prev_quest_score = cur_quest_score;
						cur_quest_num = response.getElementsByTagName('quiz_quest_num')[0].firstChild.data;
						saved_prev_quest_num = cur_quest_num;
						var quiz_cont = getObj('jq_quiz_container');
						quiz_cont.innerHTML = '';
						if (cur_quest_type == 7) {
							var div_insidey=document.createElement("div");
							div_insidey.id = 'quest_div_hs';
							getObj('jq_quiz_container').appendChild(div_insidey);
						}
						var div_inside1=document.createElement("div");
						div_inside1.id = 'quest_div';
						div_inside1.innerHTML = response.getElementsByTagName('quest_data')[0].firstChild.data +response.getElementsByTagName('quest_data_user')[0].firstChild.data;
						saved_prev_quest_data = response.getElementsByTagName('quest_data')[0].firstChild.data + response.getElementsByTagName('quest_data_user')[0].firstChild.data;
						quiz_cont.appendChild(div_inside1);
						var quiz_menu = response.getElementsByTagName('quiz_menu')[0].firstChild.data;
						jq_UpdateTaskDiv_htm(quiz_menu);
						jq_UpdateTaskDiv('next');
						var is_exec_quiz_script = response.getElementsByTagName('exec_quiz_script')[0].firstChild.data;
						saved_prev_quest_exec_quiz_script = is_exec_quiz_script;
						if (is_exec_quiz_script == 1 || is_exec_quiz_script == '1' ) {
							var v_quiz_script_data = response.getElementsByTagName('quiz_script_data')[0].firstChild.data;
							saved_prev_quest_exec_quiz_script_data = v_quiz_script_data;
							eval(v_quiz_script_data);
						}
					break;
					case 'preview_finish':
						quiz_blocked = 1;
						setTimeout("jq_releaseBlock()", 1000);
						prev_correct = response.getElementsByTagName('quiz_prev_correct')[0].firstChild.data;
						var quiz_cont = getObj('jq_quiz_container');
						var children = quiz_cont.childNodes;
						for (var i = 0; i < children.length; i++) { quiz_cont.removeChild(quiz_cont.childNodes[i]); };
						var qmb = response.getElementsByTagName('quiz_message_box')[0].firstChild.data;
						quiz_cont.innerHTML = '';//'<form name=\'quest_form\'><\/form>';
						var quiz_menu = response.getElementsByTagName('quiz_menu')[0].firstChild.data;
						jq_UpdateTaskDiv_htm(quiz_menu);
						if (prev_correct == '1') {
							quiz_cont.innerHTML = qmb;//'<form name=\'quest_form\'><\/form>'+qmb;
							jq_UpdateTaskDiv('preview_back');
						} else {
							quiz_cont.innerHTML = qmb;//'<form name=\'quest_form\'><\/form>'+qmb;
							jq_UpdateTaskDiv('preview_back');
						}
					break;
					<?php 
        }
        ?>
					case 'no_attempts':
						quiz_blocked = 1;
						setTimeout("jq_releaseBlock()", 1000);
						var qmb = response.getElementsByTagName('quiz_message_box')[0].firstChild.data;
						var quiz_cont = getObj('jq_quiz_container');
						quiz_cont.innerHTML = qmb;//'<form name=\'quest_form\'><\/form>'+qmb;
						var quiz_menu = response.getElementsByTagName('quiz_menu')[0].firstChild.data;
						jq_UpdateTaskDiv_htm(quiz_menu);
						jq_UpdateTaskDiv('next_no_attempts');
					break;
					case 'email_results':
						quiz_blocked = 1;
						//setTimeout("jq_releaseBlock()", 1000);
						var email_msg = response.getElementsByTagName('email_msg')[0].firstChild.data;
						ShowMessage('error_messagebox', 1, email_msg);
					break;
					case 'time_is_up':
						quiz_blocked = 1;
						setTimeout("jq_releaseBlock()", 1000);
						var quiz_cont = getObj('jq_quiz_container');
						var children = quiz_cont.childNodes;
						for (var i = 0; i < children.length; i++) { quiz_cont.removeChild(quiz_cont.childNodes[i]); };
						var qmb = response.getElementsByTagName('quiz_message_box')[0].firstChild.data;
														
						stu_quiz_id = response.getElementsByTagName('stu_quiz_id')[0].firstChild.data;
						user_unique_id = response.getElementsByTagName('user_unique_id')[0].firstChild.data;
						
						quiz_cont.innerHTML = '';//'<form name=\'quest_form\'><\/form>';
						quiz_cont.innerHTML = qmb;//'<form name=\'quest_form\'><\/form>'+qmb;
						var quiz_menu = response.getElementsByTagName('quiz_menu')[0].firstChild.data;
						jq_UpdateTaskDiv_htm(quiz_menu);
						jq_UpdateTaskDiv('continue_finish');
					break;
					case 'finish':
						quiz_blocked = 1;

						quiz_progress = response.getElementsByTagName('progress_quests_done')[0].firstChild.data;
						<?php 
        if ($JLMS_CONFIG->get('quiz_progressbar', 0) == 1) {
            ?>
						progressbar.setProgress(quiz_progress);
						<?php 
        }
        ?>

						setTimeout("jq_releaseBlock()", 1000);
						prev_correct = response.getElementsByTagName('quiz_prev_correct')[0].firstChild.data;
						var quiz_cont = getObj('jq_quiz_container');
						var children = quiz_cont.childNodes;
						for (var i = 0; i < children.length; i++) { quiz_cont.removeChild(quiz_cont.childNodes[i]); };
						quest_feedback = response.getElementsByTagName('quest_feedback')[0].firstChild.data;
						quiz_cont.innerHTML = '';//'<form name=\'quest_form\'><\/form>';
						if (quest_feedback == '1') {
							var qmb = response.getElementsByTagName('quiz_message_box')[0].firstChild.data;
							var quiz_menu = response.getElementsByTagName('quiz_menu')[0].firstChild.data;
							jq_UpdateTaskDiv_htm(quiz_menu);
							if (prev_correct == '1') {
							<?php 
        if ($quiz->c_slide) {
            ?>
								getObj('quest_result_'+saved_prev_quest_id).innerHTML = "<img src='<?php 
            echo $JLMS_CONFIG->get('live_site');
            ?>
/components/com_joomla_lms/lms_images/toolbar/btn_accept.png' border=0>";
							<?php 
        }
        ?>
								//stop_timer = 1;
								quiz_cont.innerHTML = qmb;//'<form name=\'quest_form\'><\/form>'+qmb;
								jq_UpdateTaskDiv('continue_finish');
							} else {
							<?php 
        if ($quiz->c_slide) {
            ?>
								getObj('quest_result_'+saved_prev_quest_id).innerHTML = "<img src='<?php 
            echo $JLMS_CONFIG->get('live_site');
            ?>
/components/com_joomla_lms/lms_images/toolbar/btn_cancel.png' border=0>";
							<?php 
        }
        ?>
								quiz_cont.innerHTML = qmb;//'<form name=\'quest_form\'><\/form>'+qmb;
								allow_attempt = response.getElementsByTagName('quiz_allow_attempt')[0].firstChild.data;
								if (allow_attempt == '1') {
									allow_attempt = 0;
									jq_UpdateTaskDiv('back_continue_finish');
								} else {
									allow_attempt = 0;
									//stop_timer = 1;
									jq_UpdateTaskDiv('continue_finish');
								}
							}
						} else {
							var qmb = '';
							var qfrf = response.getElementsByTagName('quest_feedback_repl_func')[0].firstChild.data;
							if (prev_correct == '1') {
							<?php 
        if ($quiz->c_slide) {
            ?>
								getObj('quest_result_'+saved_prev_quest_id).innerHTML = "<img src='<?php 
            echo $JLMS_CONFIG->get('live_site');
            ?>
/components/com_joomla_lms/lms_images/toolbar/btn_accept.png' border=0>";
							<?php 
        }
        ?>
							} else {
							<?php 
        if ($quiz->c_slide) {
            ?>
								getObj('quest_result_'+saved_prev_quest_id).innerHTML = "<img src='<?php 
            echo $JLMS_CONFIG->get('live_site');
            ?>
/components/com_joomla_lms/lms_images/toolbar/btn_cancel.png' border=0>";
							<?php 
        }
        ?>
							}
							eval(qfrf);
						}
					break;
					case 'results':
						quiz_blocked = 1;
						setTimeout("jq_releaseBlock()", 100);
						var quiz_cont = getObj('jq_quiz_container');
						var children = quiz_cont.childNodes;
						for (var i = 0; i < children.length; i++) { quiz_cont.removeChild(quiz_cont.childNodes[i]); };
						quiz_cont.innerHTML = '';//'<form name=\'quest_form\'><\/form>';
						stop_timer = 1;
						getObj('jq_time_tick_container').style.visibility = "hidden";
						jq_UpdateTaskDiv('finish');
						var finish_msg = response.getElementsByTagName('finish_msg')[0].firstChild.data;
						var quiz_results = response.getElementsByTagName('quiz_results')[0].firstChild.data;
						var quiz_footer = response.getElementsByTagName('quiz_footer')[0].firstChild.data;
						var quiz_cont = getObj('jq_quiz_container');
						quiz_cont.innerHTML = quiz_results+finish_msg+quiz_footer;//'<form name=\'quest_form\'><\/form>'+quiz_results+finish_msg+quiz_footer;
						saved_prev_res_data = quiz_results+finish_msg+quiz_footer;
					break;
					case 'failed':
						ShowMessage('error_messagebox', 1, mes_failed);
						quiz_blocked = 1;
						setTimeout("jq_releaseBlock()", 1000);
					break;
					default:
					break;
				}
			} else {
				ShowMessage('error_messagebox', 1, '<?php 
        echo $jq_language['quiz_failed_request'];
        ?>
');
			}
		}
	}
	function jq_releaseBlock() { quiz_blocked = 0; }
	function jq_Start_TickTack() {
		timer_sec = 1;
		getObj('jq_time_tick_container').innerHTML = '00:01';
		getObj('jq_time_tick_container').style.visibility = "visible";
		setTimeout("jq_Continue_TickTack()", 1000);
	}
	function jq_Start_TickTackResume() {
		jq_ParseTickTackTimer(timer_sec);
		getObj('jq_time_tick_container').style.visibility = "visible";
		setTimeout("jq_Continue_TickTack()", 1000);
	}
	function jq_Continue_TickTack() {
		if (stop_timer == 1) {
			getObj('jq_time_tick_container').style.visibility = "hidden";
		} else {
			timer_sec ++;
			if ( max_quiz_time && (timer_sec > max_quiz_time) ) {
				getObj('jq_time_tick_container').innerHTML = mes_time_is_up;
			} else {
				jq_ParseTickTackTimer(timer_sec);
				setTimeout("jq_Continue_TickTack()", 1000);
			}
		}
	}
	function jq_ParseTickTackTimer(timer_sec) {
		var timer_hours = parseInt(timer_sec/3600);
		var timer_min = parseInt(timer_sec/60) - (timer_hours*60);
		var plus_sec = timer_sec - (timer_min*60) - (timer_hours*3600);
		if (timer_min < 0) { timer_min = timer_min*(-1); }
		if (plus_sec < 0) { plus_sec = plus_sec*(-1); }
		if (timer_hours < 0) { timer_hours = timer_hours*(-1); }
		var time_str_hours = '';
		if (timer_hours) {
			time_str_hours = timer_hours + '';
			if (time_str_hours.length == 1) time_str_hours = '0'+time_str_hours;
			time_str_hours = time_str_hours + ':';
		}
		var time_str = timer_min + '';
		if (time_str.length == 1) time_str = '0'+time_str;
		time_str2 = plus_sec + '';
		if (time_str2.length == 1) time_str2 = '0'+time_str2;
		getObj('jq_time_tick_container').innerHTML = time_str_hours + time_str + ':' + time_str2;
	}

		function jq_ResumeQuizOn(resume_id, unique_id, last_question) {
	<?php 
        if ($quiz->c_email_to == 2) {
            ?>
		/*var jq_email_cont = getObj('jq_user_email');
		var re_email = /[0-9a-z_]+@[0-9a-z_^.]+.[a-z]{2,3}/;
		if (!re_email.test(jq_email_cont.value)) {
			alert("Please enter a correct e-mail address");
			return;
		}
		user_email_to = jq_email_cont.value;*/
	<?php 
        }
        ?>
		if (!quiz_blocked) {
			//ShowMessage('error_messagebox', 1, mes_loading);
			//jq_showLoading();//
			timerID = setTimeout("jq_ResumeQuiz("+resume_id+", '"+unique_id+"', "+last_question+")", 300);
		} else {
			ShowMessage('error_messagebox', 1, mes_please_wait);
		}
	}
	function jq_ResumeQuiz(resume_id, unique_id, last_question) { 
		jq_MakeRequest('&atask=resume_quiz&quiz=<?php 
        echo $quiz->c_id;
        ?>
&resume_id='+resume_id+'&unique_id='+unique_id+'&last_question='+last_question,1); 
	}

	
	function jq_StartQuizOn() {
	<?php 
        if ($quiz->c_email_to == 2) {
            ?>
		/*var jq_email_cont = getObj('jq_user_email');
		var re_email = /[0-9a-z_]+@[0-9a-z_^.]+.[a-z]{2,3}/;
		if (!re_email.test(jq_email_cont.value)) {
			alert("Please enter a correct e-mail address");
			return;
		}
		user_email_to = jq_email_cont.value;*/
	<?php 
        }
        ?>
		if (!quiz_blocked) {
			//ShowMessage('error_messagebox', 1, mes_loading);
			//jq_showLoading();//
			timerID = setTimeout("jq_StartQuiz()", 300);
		} else {
			ShowMessage('error_messagebox', 1, mes_please_wait);
		}
	}
	function jq_StartQuiz() { jq_MakeRequest('&atask=start&quiz=<?php 
        echo $quiz->c_id;
        ?>
',1); }
	
	function jq_StartQuizOn_selfver() {
	<?php 
        if ($quiz->c_email_to == 2) {
            ?>
		/*var jq_email_cont = getObj('jq_user_email');
		var re_email = /[0-9a-z_]+@[0-9a-z_^.]+.[a-z]{2,3}/;
		if (!re_email.test(jq_email_cont.value)) {
			alert("Please enter a correct e-mail address");
			return;
		}
		user_email_to = jq_email_cont.value;*/
	<?php 
        }
        ?>
		if (!quiz_blocked) {
			//ShowMessage('error_messagebox', 1, mes_loading);
			//jq_showLoading();//
			timerID = setTimeout("jq_StartQuiz_selfver()", 300);
		} else {
			ShowMessage('error_messagebox', 1, mes_please_wait);
		}
	}
	
	function implode( glue, pieces ) {
	    return ( ( pieces instanceof Array ) ? pieces.join ( glue ) : pieces );
	}
	
	function jq_StartQuiz_selfver(){ 
		var form = document.selfverForm;
		var string_params = '';
		
		if(form.c_pool_type.value == 1){
			string_params = '&mode_self=1&pool_num='+form.pool_qtype_number.value;
		} else if(form.c_pool_type.value == 2){
			if (form['pool_cat_id[]'].length) {
				var arr_cat_id = new Array(form['pool_cat_id[]'].length);
				var arr_cat_number = new Array(form['pool_cat_number[]'].length);
				for (var i = 0; i<form['pool_cat_number[]'].length; i++) {
						if (form['pool_cat_number[]'][i].value > 0) { 
							arr_cat_id[i] = form['pool_cat_id[]'][i].value;
							arr_cat_number[i] = form['pool_cat_number[]'][i].value; 
						} 
				}
				string_params = '&mode_self=2&cats_id='+implode(',', arr_cat_id)+'&pool_num='+implode(',', arr_cat_number);
			} else if (form['pool_cat_id[]'].value > 0) { 
				var arr_cat_id;
				var arr_cat_number;
				arr_cat_id = form['pool_cat_id[]'].value;
				arr_cat_number = form['pool_cat_number[]'].value;
				string_params = '&mode_self=3&cats_id='+arr_cat_id+'&pool_num='+arr_cat_number;
			} 
		}
		jq_MakeRequest('&atask=start&quiz=<?php 
        echo $quiz->c_id;
        ?>
'+string_params,1);
	}
	
	
	function JQ_gotoQuestionOn(qid) {
		if (!quiz_blocked) {
			//ShowMessage('error_messagebox', 1, mes_loading);
			//jq_showLoading();//
			timerID = setTimeout("JQ_gotoQuestion("+qid+")", 300);
		} else {
			ShowMessage('error_messagebox', 1, mes_please_wait);
			setTimeout("jq_releaseBlock()", 1000);
		}
	}
	function JQ_gotoQuestion(qid){
		if(review){
			jq_MakeRequest('&atask=review_next&prev=1&quiz=<?php 
        echo $quiz->c_id;
        ?>
&stu_quiz_id='+stu_quiz_id+'&quest_id='+qid, 1 ); 
		} else {
			jq_MakeRequest('&atask=goto_quest&quiz=<?php 
        echo $quiz->c_id;
        ?>
&stu_quiz_id='+stu_quiz_id+'&seek_quest_id='+qid, 1 ); 
		}
	}
	function jq_emailResults() {
		if (!quiz_blocked) {
			ShowMessage('error_messagebox', 1, mes_loading);
			jq_MakeRequest('&atask=email_results&quiz=<?php 
        echo $quiz->c_id;
        ?>
&stu_quiz_id='+stu_quiz_id<?php 
        echo $quiz->c_email_to == 2 ? "+'&email_address='+user_email_to" : '';
        ?>
,0);
		} else {
			//ShowMessage('error_messagebox', 1, mes_please_wait);// setTimeout("jq_releaseBlock()", 1000);
		}
	}
	function jq_startReview() {
		if (!quiz_blocked) {
			jq_MakeRequest('&atask=review_start&quiz=<?php 
        echo $quiz->c_id;
        ?>
&stu_quiz_id='+stu_quiz_id, 1);
		} else {
			ShowMessage('error_messagebox', 1, mes_please_wait); setTimeout("jq_releaseBlock()", 1000);
		}
	}
	function jq_QuizReviewNext() {
		if (!quiz_blocked) {
			jq_MakeRequest('&atask=review_next&quiz=<?php 
        echo $quiz->c_id;
        ?>
'+'&stu_quiz_id='+stu_quiz_id+'&quest_id='+cur_quest_id, 1);
		} else {
			ShowMessage('error_messagebox', 1, mes_please_wait);
			setTimeout("jq_releaseBlock()", 1000);
		}
	}
	function jq_QuizReviewPrev() {
		if (!quiz_blocked) {
			jq_MakeRequest('&atask=review_next&prev=1&quiz=<?php 
        echo $quiz->c_id;
        ?>
'+'&stu_quiz_id='+stu_quiz_id+'&quest_id='+prev_quest_id, 1);
		} else {
			ShowMessage('error_messagebox', 1, mes_please_wait);
			setTimeout("jq_releaseBlock()", 1000);
		}
	}
	function jq_Check_selectRadio(rad_name, form_name) {
		var tItem = eval('document.'+form_name);
		if (tItem) {
			var selItem = eval('document.'+form_name+'.'+rad_name);
			if (selItem) {
				if (selItem.length) { var i;
					for (i = 0; i<selItem.length; i++) {
						if (selItem[i].checked) {
							if (selItem[i].value > 0) { return selItem[i].value; } } }
				} else if (selItem.checked) { return selItem.value; } }
			return false; }
		return false;
	}
	function jq_Check_selectCheckbox(check_name, form_name) {
		selItem = eval('document.'+form_name+'.'+check_name);
		var rrr = '';
		if (selItem) {
			if (selItem.length) { var i;
				for (i = 0; i<selItem.length; i++) {
					if (selItem[i].checked) {
						if (selItem[i].value > 0) { rrr = rrr + selItem[i].value + ', '; }
					}}
				rrr = rrr.substring(0, rrr.length - 2);
			} else if (selItem.checked) { rrr = rrr + selItem.value; }}
		return rrr;
	}
	function jq_Check_valueItem(item_name, form_name) {
		selItem = eval('document.'+form_name+'.'+item_name);
		var rrr = '';
		if (selItem) {
			if (selItem.length) { var i;
				for (i = 0; i<selItem.length; i++) {
					if (selItem[i].value == '{0}') return '';
					rrr = rrr + selItem[i].value + '```';
				}
				rrr = rrr.substring(0, rrr.length - 3);
			} else { rrr = rrr + selItem.value;	}}
		return rrr;
	}
	function jq_QuizNextOn() { // Two steps CHECK (delete this func in the future)
		switch (cur_quest_type) {
			case '1': //Multi choice
			case '12':
				if (!jq_Check_selectRadio('quest_choice', 'quest_form') && !document.quest_form.ismandatory.value) {
					ShowMessage('error_messagebox', 1, mes_complete_this_part);
					return false;}
			break;
			case '2': //Multi Response
			case '13':
				var res = jq_Check_selectCheckbox('quest_choice', 'quest_form');
				if (res == '') {
					ShowMessage('error_messagebox', 1, mes_complete_this_part);
					return false;}
			break;
			case '3': //true-false
				if (!jq_Check_selectRadio('quest_choice', 'quest_form')) {
					ShowMessage('error_messagebox', 1, mes_complete_this_part);
					return false;}
			break;
			case '4': // Drag'AND'Drop
			case '11':
				var i_id; var i_value; var complete = true;
				for (i=0; i<kol_drag_elems; i++) {
					if ( (ids_in_cont[i] > 0) && (ids_in_cont[i] <= kol_drag_elems) ) {
						//alert(ids_in_cont[i] + ' - ' + cont_for_ids[ids_in_cont[i] - 1] + ' - ' + answ_ids[ids_in_cont[i]])
						if (cont_for_ids[ids_in_cont[i] - 1] == i+1) { ;
						} else { complete = false; }
					} else { complete = false; }
				}
				if (!complete) {
					ShowMessage('error_messagebox', 1, mes_complete_this_part);
					return false;
				}
			break;
			case '5': //drop-down
				var res = jq_Check_valueItem('quest_match', 'quest_form');
				if (res == '') {
					ShowMessage('error_messagebox', 1, mes_complete_this_part);
					return false;
				}
			break;
			case '6': //fill in the blank
				var blank_item = document.quest_form.quest_blank;
				var res = TRIM_str(blank_item.value);
				if (res == '' && !document.quest_form.ismandatory.value) {
					ShowMessage('error_messagebox', 1, mes_complete_this_part);
					return false;}
			break;
			case '7': //hotspot question
				var hs_x = parseInt(document.quest_form.hotspot_x.value);
				var hs_y = parseInt(document.quest_form.hotspot_y.value);
				if ((hs_x == 0) && (hs_y == 0)) {
					ShowMessage('error_messagebox', 1, mes_complete_this_part);
					return false;}
			break;
			case '8': //survey question
				var answer = document.quest_form.survey_box.value;
				if (TRIM_str(answer) == '' && !document.quest_form.ismandatory.value) {
					ShowMessage('error_messagebox', 1, mes_complete_this_part);
					return false;}
			break;
			case '10':
			break;
			/*case '11':
				var i_id; var i_value; var complete = true;
				for (i=0; i<kol_drag_elems; i++) {
					if ( (ids_in_cont[i] > 0) && (ids_in_cont[i] <= kol_drag_elems) ) {
						//alert(ids_in_cont[i] + ' - ' + cont_for_ids[ids_in_cont[i] - 1] + ' - ' + answ_ids[ids_in_cont[i]])
						if (cont_for_ids[ids_in_cont[i] - 1] == i+1) { ;
						} else { complete = false; }
					} else { complete = false; }
				}
				if (!complete) {
					ShowMessage('error_messagebox', 1, mes_complete_this_part);
					return false;}
			break;*/
		}
		if (!quiz_blocked) {
			//ShowMessage('error_messagebox', 1, mes_loading);
			//jq_showLoading();
			quiz_blocked = 1;
			timerID = setTimeout("jq_QuizNext()", 300);
		} else { ShowMessage('error_messagebox', 1, mes_please_wait); setTimeout("jq_releaseBlock()", 1000); }
	}

	function jq_QuizContinue() {

		cur_quest_type = response.getElementsByTagName('quest_type')[0].firstChild.data;
		saved_prev_quest_type = cur_quest_type;
		cur_quest_id = response.getElementsByTagName('quest_id')[0].firstChild.data;
		saved_prev_quest_id = cur_quest_id;
		cur_quest_score = response.getElementsByTagName('quest_score')[0].firstChild.data;
		saved_prev_quest_score = cur_quest_score;
		cur_quest_num = response.getElementsByTagName('quiz_quest_num')[0].firstChild.data;
		saved_prev_quest_num = cur_quest_num;
		skip_next_quest = response.getElementsByTagName('quiz_skip_next_quest')[0].firstChild ? response.getElementsByTagName('quiz_skip_next_quest')[0].firstChild.data : 0;
		var quiz_cont = getObj('jq_quiz_container');
		quiz_cont.innerHTML = '';
		if (cur_quest_type == 7) {
			var div_insidey=document.createElement("div");
			div_insidey.id = 'quest_div_hs';
			getObj('jq_quiz_container').appendChild(div_insidey);
		}
		var div_inside1=document.createElement("div");
		div_inside1.id = 'quest_div';
		div_inside1.innerHTML = response.getElementsByTagName('quest_data')[0].firstChild.data +response.getElementsByTagName('quest_data_user')[0].firstChild.data;
		saved_prev_quest_data = response.getElementsByTagName('quest_data')[0].firstChild.data + response.getElementsByTagName('quest_data_user')[0].firstChild.data;
		quiz_cont.appendChild(div_inside1);
<?php 
        //Max: modign skip question
        ?>
		if(parseInt(skip_next_quest)){
	<?php 
        $toolbar = array();
        $toolbar[] = array('btn_type' => 'quiz_ok', 'btn_js' => "javascript:jq_QuizNextOn(); void(0);");
        $toolbar[] = array('btn_type' => 'skip', 'btn_js' => "javascript:JQ_gotoQuestion(__skip__);void(0);");
        if ($quiz->c_slide) {
            $toolbar[] = array('btn_type' => 'contents', 'btn_js' => "javascript:jq_ShowPanel();");
        }
        $m_str = JLMS_ShowToolbar($toolbar, false);
        ?>
			var subject = '<?php 
        echo str_replace('/', '\\/', addslashes($m_str));
        ?>
';
			html_replace = subject.split('__skip__').join(skip_next_quest);
			jq_UpdateTaskDiv_htm(html_replace);
		} else {
	<?php 
        $toolbar = array();
        $toolbar[] = array('btn_type' => 'quiz_ok', 'btn_js' => "javascript:jq_QuizNextOn(); void(0);");
        if ($quiz->c_slide) {
            $toolbar[] = array('btn_type' => 'contents', 'btn_js' => "javascript:jq_ShowPanel();");
        }
        $m_str = JLMS_ShowToolbar($toolbar, false);
        ?>
			
			jq_UpdateTaskDiv_htm('<?php 
        echo str_replace('/', '\\/', addslashes($m_str));
        ?>
');
		}

			jq_UpdateTaskDiv('next');
		
		var is_exec_quiz_script = response.getElementsByTagName('exec_quiz_script')[0].firstChild.data;
		saved_prev_quest_exec_quiz_script = is_exec_quiz_script;
		if (is_exec_quiz_script == 1 || is_exec_quiz_script == '1' ) {
			var v_quiz_script_data = response.getElementsByTagName('quiz_script_data')[0].firstChild.data;
			saved_prev_quest_exec_quiz_script_data = v_quiz_script_data;
			eval(v_quiz_script_data);
		}
	}
	function jq_QuizContinueFinish() {
		jq_MakeRequest('&atask=finish_stop&quiz=<?php 
        echo $quiz->c_id;
        ?>
'+'&stu_quiz_id='+stu_quiz_id+'&user_unique_id='+user_unique_id, 1);
	}
	function jq_QuizBack() {
		cur_quest_id = saved_prev_quest_id;
		cur_quest_type = saved_prev_quest_type;
		cur_quest_score = saved_prev_quest_score;
		cur_quest_num = saved_prev_quest_num;
		var quiz_cont = getObj('jq_quiz_container');
		quiz_cont.innerHTML = '';
		if (cur_quest_type == 7) {
			var div_insidey=document.createElement("div");
			div_insidey.id = 'quest_div_hs';
			getObj('jq_quiz_container').appendChild(div_insidey);
		}
		var div_inside1=document.createElement("div");
		div_inside1.id = 'quest_div';
		div_inside1.innerHTML = saved_prev_quest_data;
		quiz_cont.appendChild(div_inside1);
<?php 
        $toolbar = array();
        $toolbar[] = array('btn_type' => 'quiz_ok', 'btn_js' => "javascript:jq_QuizNextOn(); void(0);");
        if ($quiz->c_slide) {
            $toolbar[] = array('btn_type' => 'contents', 'btn_js' => "javascript:jq_ShowPanel();");
        }
        $m_str = JLMS_ShowToolbar($toolbar, false);
        ?>
		jq_UpdateTaskDiv_htm('<?php 
        echo str_replace('/', '\\/', addslashes($m_str));
        ?>
');
		jq_UpdateTaskDiv('next');
		var is_exec_quiz_script = saved_prev_quest_exec_quiz_script;
		if (is_exec_quiz_script == 1 || is_exec_quiz_script == '1' ) {
			var v_quiz_script_data = saved_prev_quest_exec_quiz_script_data;
			eval(v_quiz_script_data);
		}
	}
	function URLencode(sStr) {
		return escape(sStr).replace(/\+/g, '%2B').replace(/\"/g,'%22').replace(/\'/g, '%27').replace(/\//g,'%2F');
	}
	function TRIM_str(sStr) {
		return (sStr.replace(/^[\s\xA0]+/, "").replace(/[\s\xA0]+$/, ""));
	}
	function jq_QuizNext() { //send 'TASK = next'
		<?php 
        if ($is_preview) {
            ?>
		var jq_task = 'next_preview';
		<?php 
        } else {
            ?>
		var jq_task = 'next';
		<?php 
        }
        ?>
		switch (cur_quest_type) {
			case '1':
			case '12':
			var answer = jq_Check_selectRadio('quest_choice', 'quest_form');
				if (answer || document.quest_form.ismandatory.value != '0') {
					jq_MakeRequest('&atask=' + jq_task + '&quiz=<?php 
        echo $quiz->c_id;
        ?>
'+'&stu_quiz_id='+stu_quiz_id+'&quest_id='+cur_quest_id+'&answer='+answer, 1);
				} else { ShowMessage('error_messagebox', 1, mes_complete_this_part); setTimeout("jq_releaseBlock()", 1000); return false; }
			break;
			case '3':
				var answer = jq_Check_selectRadio('quest_choice', 'quest_form');
				if (answer) {
					jq_MakeRequest('&atask=' + jq_task + '&quiz=<?php 
        echo $quiz->c_id;
        ?>
'+'&stu_quiz_id='+stu_quiz_id+'&quest_id='+cur_quest_id+'&answer='+answer, 1);
				} else { ShowMessage('error_messagebox', 1, mes_complete_this_part); setTimeout("jq_releaseBlock()", 1000); return false; }
			break;
			case '2':
			case '13':
				var answer = jq_Check_selectCheckbox('quest_choice', 'quest_form');
				if (answer != '') {
					jq_MakeRequest('&atask=' + jq_task + '&quiz=<?php 
        echo $quiz->c_id;
        ?>
'+'&stu_quiz_id='+stu_quiz_id+'&quest_id='+cur_quest_id+'&answer='+answer, 1);
				} else { ShowMessage('error_messagebox', 1, mes_complete_this_part); setTimeout("jq_releaseBlock()", 1000); return false; }
			break;
			case '4':
			case '11':
				var i_id;
				var i_value;
				var answer = '';
				var complete = true;
				var mas_ans = new Array(kol_drag_elems);
				for (i=0; i<kol_drag_elems; i++) {
					mas_ans[i] = 0;
					if ( (ids_in_cont[i] > 0) && (ids_in_cont[i] <= kol_drag_elems) ) {
						if (cont_for_ids[ids_in_cont[i] - 1] == i+1) {
							mas_ans[i] = ids_in_cont[i];
							answer = answer + answ_ids[ids_in_cont[i]] + '```';
						} else { complete = false; }
					} else { complete = false; }
				}
				if (!complete) {
					ShowMessage('error_messagebox', 1, mes_complete_this_part);
					setTimeout("jq_releaseBlock()", 1000);
					return false;
				} else {
					answer = answer.substring(0, answer.length - 3);
					answer = URLencode(answer);
					jq_MakeRequest('&atask=' + jq_task + '&quiz=<?php 
        echo $quiz->c_id;
        ?>
'+'&stu_quiz_id='+stu_quiz_id+'&quest_id='+cur_quest_id+'&answer='+answer, 1);
				}
			break;
			case '5':
				var answer = jq_Check_valueItem('quest_match', 'quest_form');
				answer = URLencode(answer);
				if (answer != '') {
					jq_MakeRequest('&atask=' + jq_task + '&quiz=<?php 
        echo $quiz->c_id;
        ?>
'+'&stu_quiz_id='+stu_quiz_id+'&quest_id='+cur_quest_id+'&answer='+answer, 1);
				} else { ShowMessage('error_messagebox', 1, mes_complete_this_part); setTimeout("jq_releaseBlock()", 1000); return false; }
			break;
			case '6':
				var blank_item = document.quest_form.quest_blank;
				var answer = URLencode(TRIM_str(blank_item.value));
				if (answer != '' || document.quest_form.ismandatory.value != '0') {
					jq_MakeRequest('&atask=' + jq_task + '&quiz=<?php 
        echo $quiz->c_id;
        ?>
'+'&stu_quiz_id='+stu_quiz_id+'&quest_id='+cur_quest_id+'&answer='+answer, 1);
				} else { ShowMessage('error_messagebox', 1, mes_complete_this_part); setTimeout("jq_releaseBlock()", 1000); return false; }
			break;
			case '7':
				var hs_x = parseInt(document.quest_form.hotspot_x.value);
				var hs_y = parseInt(document.quest_form.hotspot_y.value);
				if ((hs_x != 0) && (hs_y != 0)) {
					var answer = hs_x + ',' + hs_y;
					jq_MakeRequest('&atask=' + jq_task + '&quiz=<?php 
        echo $quiz->c_id;
        ?>
'+'&stu_quiz_id='+stu_quiz_id+'&quest_id='+cur_quest_id+'&answer='+answer, 1);
				} else { ShowMessage('error_messagebox', 1, mes_complete_this_part); setTimeout("jq_releaseBlock()", 1000); return false; }
			break;
			case '8':
				var answer = URLencode(TRIM_str(document.quest_form.survey_box.value));
				if (answer != '' || document.quest_form.ismandatory.value != '0') {
					jq_MakeRequest('&atask=' + jq_task + '&quiz=<?php 
        echo $quiz->c_id;
        ?>
'+'&stu_quiz_id='+stu_quiz_id+'&quest_id='+cur_quest_id+'&answer='+answer, 1);
				} else { ShowMessage('error_messagebox', 1, mes_complete_this_part); setTimeout("jq_releaseBlock()", 1000); return false; }
			break;
			case '9':
				var complete = true;
				var scale_count = parseInt(document.quest_form.scale_count.value);
				var answer = new Array(scale_count);
				for(i=0;i<scale_count;i++)
				{
					var cur_answer = jq_Check_selectRadio('ch_scale_'+i, 'quest_form');
					if(!cur_answer)
						complete = false;
					else
						answer[i] = cur_answer;	
				}
				if (!complete && document.quest_form.ismandatory.value!='1') {
					ShowMessage('error_messagebox', 1, mes_complete_this_part);
					setTimeout("jq_releaseBlock()", 1000);
					return false;
				} else {
					
					jq_MakeRequest('&atask=' + jq_task + '&quiz=<?php 
        echo $quiz->c_id;
        ?>
'+'&stu_quiz_id='+stu_quiz_id+'&quest_id='+cur_quest_id+'&answer='+answer, 1);
				}
			break;	
			case '10':
				jq_MakeRequest('&atask=' + jq_task + '&quiz=<?php 
        echo $quiz->c_id;
        ?>
'+'&stu_quiz_id='+stu_quiz_id+'&quest_id='+cur_quest_id+'&answer=0', 1);
			break;
			default:
				ShowMessage('error_messagebox', 1, '<?php 
        echo $jq_language['quiz_unknown_error'];
        ?>
');
				setTimeout("jq_releaseBlock()", 1000);
			break;
		}
	}

	function jq_showLoading() {
		ShowMessage('error_messagebox', 0, '&nbsp;');

		getObj('jq_quiz_result_reviews').style.visibility = 'hidden';
		getObj('jq_quiz_explanation').style.visibility = 'hidden';
		getObj('jq_quiz_result_reviews').style.display = 'none';
		getObj('jq_quiz_explanation').style.display = 'none';
		getObj('jq_quiz_container').innerHTML = '<br /><br /><center><img src="<?php 
        echo $JLMS_CONFIG->get('live_site');
        ?>
/components/com_joomla_lms/lms_images/loading.gif" height="32" width="32" border="0" alt="loading" /><\/center>';
	}

	function jq_UpdateTaskDiv_htm(htm_txt) {
		getObj('jq_quiz_task_container').innerHTML = htm_txt;
	}

	function jq_UpdateTaskDiv(task) {
		switch (task) {
			case 'start':
				getObj('jq_quiz_task_container').innerHTML = jq_StartButton('jq_StartQuizOn()', '<?php 
        echo $jq_language['quiz_start'];
        ?>
');
			break;
			case 'resume':
			case 'next':
				//getObj('jq_quiz_task_container').innerHTML = jq_NextButton('jq_QuizNextOn()', '<?php 
        echo $jq_language['quiz_next'];
        ?>
');
				getObj('jq_quest_num_container').innerHTML = mes_quest_number.replace("{X}", cur_quest_num).replace("{Y}", quiz_count_quests);
				getObj('jq_quest_num_container').style.visibility = "visible";
				getObj('jq_points_container').innerHTML = mes_quest_points.replace("{X}", cur_quest_score);
				getObj('jq_points_container').style.visibility = "visible";
				getObj('jq_question_id_container').style.visibility = "hidden";

				<?php 
        if ($JLMS_CONFIG->get('quizzes_show_quest_id', 0) == 1) {
            ?>

					quest_id_gqp = response.getElementsByTagName('quest_id_gqp')[0].firstChild.data;				
					quest_id_pool = response.getElementsByTagName('quest_id_pool')[0].firstChild.data;	

					if(quest_id_gqp > 0) {
						getObj('jq_question_id_container').innerHTML = "<?php 
            echo $JLMS_CONFIG->get('quizzes_quest_id_title', 0);
            ?>
"+quest_id_gqp;
					}
					if(quest_id_pool > 0) {
						getObj('jq_question_id_container').innerHTML = "<?php 
            echo $JLMS_CONFIG->get('quizzes_quest_id_title', 0);
            ?>
"+quest_id_pool;
					}

					if(quest_id_gqp > 0 || quest_id_pool > 0) {
						getObj('jq_question_id_container').style.display = "block";
						getObj('jq_question_id_container').style.visibility = "visible";
					}
					else {
						getObj('jq_question_id_container').style.display = "none";
						getObj('jq_question_id_container').style.visibility = "hidden";
					}

				<?php 
        }
        ?>
				<?php 
        if ($JLMS_CONFIG->get('quiz_progressbar', 0) == 1) {
            ?>
				getObj('progress_bar').style.display = "block";
				<?php 
        }
        ?>
			break;
			case 'review_next':
				//getObj('jq_quiz_task_container').innerHTML = jq_ContinueButton('jq_QuizReviewNext()', '<?php 
        echo $jq_language['quiz_next'];
        ?>
');
				getObj('jq_quest_num_container').innerHTML = mes_quest_number.replace("{X}", cur_quest_num).replace("{Y}", quiz_count_quests);
				getObj('jq_quest_num_container').style.visibility = "visible";
				getObj('jq_points_container').innerHTML = mes_quest_points.replace("{X}", cur_quest_score);
				getObj('jq_points_container').style.visibility = "visible";
			break;
			case 'next_no_attempts':
				//getObj('jq_quiz_task_container').innerHTML = jq_ContinueButton('jq_QuizContinue()', '<?php 
        echo $jq_language['quiz_continue'];
        ?>
');
			break;
			case 'finish':
				<?php 
        if ($JLMS_CONFIG->get('quiz_progressbar', 0) == 1) {
            ?>
				getObj('progress_bar').style.display = "none";
				if (getObj('jq_question_id_container')) { getObj('jq_question_id_container').style.visibility = "hidden"; }
				<?php 
        }
        ?>
			case 'clear':
				getObj('jq_quiz_task_container').innerHTML = "";
				getObj('jq_quest_num_container').style.visibility = "hidden";
				getObj('jq_points_container').style.visibility = "hidden";
				getObj('jq_question_id_container').style.visibility = "hidden";
			break;
			case 'continue':
			break;
			case 'continue_finish':
			break;
			case 'back_continue':
				//getObj('jq_quiz_task_container').innerHTML = jq_ContinueButton('jq_QuizContinue()', '<?php 
        echo $jq_language['quiz_continue'];
        ?>
')+jq_BackButton('jq_QuizBack()', '<?php 
        echo $jq_language['quiz_back'];
        ?>
');
			break;
			case 'back_continue_finish':
				//getObj('jq_quiz_task_container').innerHTML = jq_ContinueButton('jq_QuizContinueFinish()', '<?php 
        echo $jq_language['quiz_continue'];
        ?>
')+jq_BackButton('jq_QuizBack()', '<?php 
        echo $jq_language['quiz_back'];
        ?>
');
			break;
			<?php 
        if ($is_preview) {
            ?>
			case 'preview_back':
				//getObj('jq_quiz_task_container').innerHTML = jq_BackButton('JQ_previewQuest()', '<?php 
            echo $jq_language['quiz_back'];
            ?>
');
			break;
			<?php 
        }
        ?>
		}
		<?php 
        if ($quiz->c_slide) {
            ?>
		if (result_is_shown == 1) { jq_ShowPanel(); }
		<?php 
        }
        ?>
		if (task == 'finish') {
			//var obj_plc = getObj('jq_panel_link_container');
			//if (obj_plc) obj_plc.style.visibility = 'hidden';
		}
	}
	function jq_NextButton(task, text) {
		return "<div id=\"jq_next_link_container\" onclick=\""+task+"\"><div class=\"back_button\" id=\"jq_quiz_task_link_container\"><a href=\"javascript: void(0)\">"+text+"<\/a><\/div><br /><\/div>";
	}
	function jq_ContinueButton(task, text) {
		return "<div id=\"jq_continue_link_container\" onclick=\""+task+"\"><div class=\"back_button\" id=\"jq_quiz_task_link_container\"><a href=\"javascript: void(0)\">"+text+"<\/a><\/div><br /><\/div>";
	}
	function jq_StartButton(task, text) {
		return "<div id=\"jq_start_link_container\" onclick=\""+task+"\"><div class=\"back_button\" id=\"jq_quiz_task_link_container\"><a href=\"javascript: void(0)\">"+text+"<\/a><\/div><br /><\/div>";
	}
	function jq_BackButton(task, text) {
		return "<div id=\"jq_back_link_container\" onclick=\""+task+"\"><div class=\"back_button\" id=\"jq_quiz_task_link_container\"><a href=\"javascript: void(0)\">"+text+"<\/a><\/div><br /><\/div>";
	}
	function jq_ShowPanel_go() {
		var jq_quiz_c_cont = getObj('jq_quiz_container');
		if (jq_quiz_c_cont) { jq_quiz_c_cont.style.visibility = 'hidden'; jq_quiz_c_cont.style.display = 'none';}
		var jq_quiz_r_c = getObj('jq_quiz_result_container');
		if (jq_quiz_r_c) { jq_quiz_r_c.style.visibility = 'visible'; jq_quiz_r_c.style.display = 'block';}
	}
	function jq_HidePanel_go() {
		var jq_quiz_r_c = getObj('jq_quiz_result_container');
		if (jq_quiz_r_c) { jq_quiz_r_c.style.visibility = 'hidden'; jq_quiz_r_c.style.display = 'none';}
		var jq_quiz_c_cont = getObj('jq_quiz_container');
		if (jq_quiz_c_cont) { jq_quiz_c_cont.style.visibility = 'visible'; jq_quiz_c_cont.style.display = 'block';}
	}
	function jq_ShowPanel() {
<?php 
        if ($quiz->c_slide) {
            ?>
	
		if (result_is_shown == 1) { jq_HidePanel_go(); result_is_shown = 0;	}
		else { jq_ShowPanel_go();	result_is_shown = 1; }
<?php 
        }
        ?>
	}
<?php 
        if ($is_preview) {
            ?>
	function JQ_previewQuest() {
		jq_MakeRequest('&atask=preview_quest&quiz=<?php 
            echo $quiz->c_id;
            ?>
'+'&preview_id=<?php 
            echo $preview_id;
            ?>
&quest_id=<?php 
            echo $preview_quest;
            ?>
', 1);
	}
<?php 
        }
        ?>

//--><!]]>
</script>
<div>
	<?php 
        $quiz->template_name = 'joomlaquiz_lms_template';
        if ($quiz->template_name) {
            require dirname(__FILE__) . '/templates/' . $quiz->template_name . '/jq_template.php';
            //$url_link = 'index.php?option='.$option.'&task=quiz_action&id='.$course_id.'&atask=start&quiz='.$quiz->c_id.'&Itemid='.$Itemid.'';
            //no-js functionality commented in JoomlaLMS 1.1.0 (due to the lost of bugs and lack of usage)
            $url_link = 'javascript:void(0);';
            $page = strval(mosGetParam($_REQUEST, 'page', ''));
            $task_cont = '';
            if ($page != 'view_preview') {
                $task_cont .= "\n\t\t\t<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" align=\"right\" style=\"text-align: right;\" class=\"jlms_table_no_borders\">\n\t\t\t\t<tbody>\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td>";
                if ($self_verification != '') {
                    $task_cont .= "<input type='image' src='" . $JLMS_CONFIG->get('live_site') . "/components/com_joomla_lms/lms_images/buttons/btn_start.png' name='atask' value='start'/>";
                    $task_cont .= "<input type='hidden' name='task' value='quiz_action'/>";
                    $task_cont .= "<input type='hidden' name='id' value='" . $course_id . "'/>";
                    $task_cont .= "<input type='hidden' name='quiz' value='" . $quiz->c_id . "'/>";
                    $task_cont .= "<input type='hidden' name='atask' value='start'/>";
                } else {
                    $task_cont .= "<a style=\"cursor: pointer;\" href=\"" . sefRelToAbs($url_link) . "\">\n\t\t\t\t\t\t\t\t<img width=\"32\" height=\"32\" border=\"0\" title=\"" . _JLMS_START_ALT_TITLE . "\" alt=\"" . _JLMS_START_ALT_TITLE . "\" src=\"" . $JLMS_CONFIG->get('live_site') . "/components/com_joomla_lms/lms_images/buttons/btn_start.png\" class=\"JLMS_png\"/>\n\t\t\t\t\t\t\t</a>";
                }
                $task_cont .= "</td>\n\t\t\t\t\t\t<td valign=\"middle\" style=\"vertical-align: middle;\">";
                if ($self_verification != '') {
                    $task_cont .= "&nbsp;" . _JLMS_START_ALT_TITLE . "&nbsp;";
                } else {
                    $task_cont .= "<a style=\"cursor: pointer;\" href=\"" . sefRelToAbs($url_link) . "\">&nbsp;" . _JLMS_START_ALT_TITLE . "&nbsp;</a>";
                }
                $task_cont .= "</td>\n\t\t\t\t\t</tr>\n\t\t\t\t</tbody>\n\t\t\t</table>";
            }
            $query = "SELECT a.*, 'joomlaquiz_lms_template' as template_name FROM #__lms_quiz_t_quiz as a WHERE a.c_id = " . $quiz->c_id . " and a.course_id = " . $course_id;
            $JLMS_DB->SetQuery($query);
            $quiz_params = $JLMS_DB->LoadObjectList();
            $descr_cont = isset($quiz_params[0]->c_description) ? $quiz_params[0]->c_description : '';
            $descr_cont = JLMS_ShowText_WithFeatures($descr_cont);
            $progress_bar_js = true;
            //by Max
            if ($preview_quest) {
                $progress_bar_js = false;
            }
            echo JoomlaQuiz_template_class::JQ_MainScreen($descr_cont, $task_cont, $self_verification, $progress_bar_js);
            if ($is_preview) {
                ?>
			<script language="JavaScript" type="text/javascript">
			<!--//--><![CDATA[//><!--
				var jq_quiz_c_t = getObj('jq_quiz_container_title');
				if (jq_quiz_c_t) jq_quiz_c_t.innerHTML = "<?php 
                echo addslashes($quiz->c_title);
                ?>
";
				var jq_quiz_c_d = getObj('jq_quiz_container_description');
				if (jq_quiz_c_d) jq_quiz_c_d.innerHTML = "<?php 
                echo "Click <a href='javascript:void(0)' onclick='JQ_previewQuest();'>here<\\/a> to preview the question";
                ?>
";
			//--><!]]>
			</script>
			</div>
			<?php 
            } else {
                $quiz_params = new JLMSParameters($quiz->params);
                if ($quiz_params->get('sh_self_verification', 0) == 1) {
                    $toolbar = array();
                    if ($quiz->attempts_of_this_quiz < $quiz->c_max_numb_attempts || $quiz->c_max_numb_attempts == 0) {
                        $toolbar[] = array('btn_type' => 'start', 'btn_js' => "javascript:jq_StartQuizOn_selfver(); return false;");
                    }
                } else {
                    $toolbar = array();
                    if ($quiz->attempts_of_this_quiz < $quiz->c_max_numb_attempts || $quiz->c_max_numb_attempts == 0) {
                        $toolbar[] = array('btn_type' => 'start', 'btn_js' => "javascript:jq_StartQuizOn(); return false;");
                    }
                }
                //if(isset($quiz->resume_quiz) && $quiz->resume_quiz && $quiz->last_question)
                if (isset($quiz->resume_quiz) && $quiz->resume_quiz && !$quiz->c_total_time) {
                    $toolbar[] = array('btn_type' => 'resume', 'btn_js' => "javascript:jq_ResumeQuizOn(" . $quiz->resume_quiz . ",'" . $quiz->unique_id . "', " . $quiz->last_question . "); return false;");
                }
                $m_str = JLMS_ShowToolbar($toolbar, false);
                //				$m_str = addslashes($m_str);
                //				$m_str = addslashes($m_str);
                $domready2 = '
				jq_UpdateTaskDiv_htm("' . str_replace('/', '\\/', addslashes($m_str)) . '");
				var jq_quiz_c_t = getObj(\'jq_quiz_container_title\');
				if (jq_quiz_c_t) jq_quiz_c_t.innerHTML = "' . addslashes($quiz->c_title) . '";
				var jq_quiz_c_d = getObj(\'jq_quiz_container_description\');
//				if (jq_quiz_c_d) jq_quiz_c_d.innerHTML = "' . str_replace("\n", '', str_replace("\r", '', str_replace("/", "\\/", addslashes($quiz->c_description)))) . '";
				var jq_qiuz_c_selfver = getObj(\'jq_quiz_container_selfver\');
				if (jq_qiuz_c_selfver) jq_qiuz_c_selfver.innerHTML = "' . str_replace("\n", '', str_replace("\r", '', str_replace("/", "\\/", addslashes($self_verification)))) . '";
				';
                $JLMS_CONFIG->set('web20_domready_code', $JLMS_CONFIG->get('web20_domready_code', '') . $domready2);
                ?>

			</div>
<?php 
            }
            //TODO: replace getObj with mootools $ operand.... !!!!!! NOTE !!!!!!!!!!!! we should update DOM using $ only after ondomready !!!
        }
    }
function jlms_booking_edit($cid, $course_id, $option)
{
    global $my, $JLMS_DB, $Itemid, $JLMS_SESSION, $JLMS_CONFIG;
    $JLMS_ACL =& JLMSFactory::getACL();
    if ($course_id && $JLMS_ACL->CheckPermissions('conference', 'manage')) {
        //$usertype = $JLMS_CONFIG->get('current_usertype', 0);
        //if ( $course_id && ($usertype == 1)) {
        $course_params = $JLMS_CONFIG->get('course_params');
        $params_cb = new JLMSParameters($course_params);
        $en_book = $params_cb->get('conf_book', 0);
        if ($cid) {
            $query = "SELECT * FROM #__lms_conference_period WHERE p_id = '" . $cid . "'";
            $JLMS_DB->setQuery($query);
            $row = $JLMS_DB->LoadObjectList();
            $from_hour = date("H", $row[0]->from_time);
            $from_minutes = date("i", $row[0]->from_time);
            $to_hour = date("H", $row[0]->to_time);
            $to_minutes = date("i", $row[0]->to_time);
            $row[0]->cur_date = date("Y-m-d", $row[0]->from_time);
        } else {
            $row[0] = new stdClass();
            $row[0]->p_id = 0;
            $row[0]->public = 0;
            $from_hour = 0;
            $from_minutes = 0;
            $to_hour = 0;
            $to_minutes = 0;
            $row[0]->cur_date = date("Y-m-d");
            $row[0]->p_name = '';
            $row[0]->p_description = '';
            $row[0]->teacher_id = $my->id;
        }
        $lists = array();
        $times = array();
        for ($i = 0; $i < 24; $i++) {
            $times[$i]->value = $i;
            if ($i < 10) {
                $times[$i]->text = '0' . $i;
            } else {
                $times[$i]->text = $i;
            }
        }
        $minutes = array();
        for ($i = 0; $i < 4; $i++) {
            $minutes[$i]->value = $i * 15;
            if ($i == 0) {
                $minutes[$i]->text = '00';
            } else {
                $minutes[$i]->text = $i * 15;
            }
        }
        $lists['from_time'] = mosHTML::selectList($times, 'from_time', 'class="inputbox" size="1" ', 'value', 'text', $from_hour);
        $lists['to_time'] = mosHTML::selectList($times, 'to_time', 'class="inputbox" size="1" ', 'value', 'text', $to_hour);
        $lists['from_minutes'] = mosHTML::selectList($minutes, 'from_min', 'class="inputbox" size="1" ', 'value', 'text', $from_minutes);
        $lists['to_minutes'] = mosHTML::selectList($minutes, 'to_min', 'class="inputbox" size="1" ', 'value', 'text', $to_minutes);
        $query = "SELECT a.id as value, a.name as text FROM #__users as a, #__lms_user_courses as c" . "\n WHERE a.id = c.user_id AND c.course_id = '" . $course_id . "'" . "\n ORDER BY a.name";
        $JLMS_DB->SetQuery($query);
        $teachers = $JLMS_DB->LoadObjectList();
        $teachers_s = array();
        $teachers_s[] = mosHTML::makeOption(0, ' - Select a teacher - ');
        $i = 1;
        foreach ($teachers as $teacher) {
            $teachers_s[] = mosHTML::makeOption($teacher->value, $teacher->text);
            $i++;
        }
        $lists['teacher_id'] = mosHTML::selectList($teachers_s, 'teacher_id', 'class="inputbox" size="1" ', 'value', 'text', $row[0]->teacher_id);
        JLMS_conference_html::jlms_booking_edit($course_id, $option, $row, $lists, $en_book);
    }
}
Esempio n. 8
0
    function show_billing_form($option, $proc, $user, $custom_code = '')
    {
        global $my, $Itemid, $JLMS_CONFIG;
        $params2 = new JLMSParameters($proc->params);
        $app =& JFactory::getApplication();
        $link = sefRelToAbs('index.php?option=com_joomla_lms&Itemid=' . $Itemid);
        if ($params2->get('enable_https')) {
            $link = str_replace('http://', 'https://', $link);
        }
        #Form name should be "JLMS_" + processor name
        ?>
		<script type="text/javascript" language="javascript">
		<!--
		function JLMS_authorize_aim_submit(){
			
			var ttt = jq_Check_selectRadio('jlms_sub', 'JLMS_adminForm');
			var this_form = document.JLMS_authorize_aim;
			err_access = new Array(); plms_focus_access = 0;
			this_form.id.value = ttt;
			this_form.jlms_sub.value = ttt;
			if(this_form.x_first_name.value == ''){
				alert('<?php 
        echo _JLMS_ENTER_FIRST_NAME;
        ?>
');
				this_form.x_first_name.focus();
			}else if(this_form.x_last_name.value == ''){
				alert('<?php 
        echo _JLMS_ENTER_LAST_NAME;
        ?>
');
				this_form.x_last_name.focus();
			}else if(this_form.x_address.value == ''){
				alert('<?php 
        echo _JLMS_ENTER_ADDRESS;
        ?>
');
				this_form.x_address.focus();
			}else if(this_form.x_city.value == ''){
				alert('<?php 
        echo _JLMS_ENTER_CITY;
        ?>
');
				this_form.x_city.focus();
			}else if(this_form.x_zip.value == ''){
				alert('<?php 
        echo _JLMS_ENTER_POSTAL_CODE;
        ?>
');
				this_form.x_zip.focus();
			}else if(this_form.x_country.value == ''){
				alert('<?php 
        echo _JLMS_ENTER_COUNTRY;
        ?>
');
				this_form.x_country.focus();
			}else if(this_form.x_phone.value == ''){
				alert('<?php 
        echo _JLMS_ENTER_PHONE;
        ?>
');
				this_form.x_phone.focus();
			}else if(!validate_email(this_form.x_email.value)){
				alert('<?php 
        echo _JLMS_ENTER_EMAIL;
        ?>
');
				this_form.x_email.focus();
			}else if (this_form.x_card_num.value == ''){
				alert('<?php 
        echo _JLMS_ENTER_CARD_NUMBER;
        ?>
');				
				this_form.x_card_num.focus();
			}else if(this_form.x_card_code.value == ''){
				alert('<?php 
        echo _JLMS_ENTER_CARD_CODE;
        ?>
');
				this_form.x_card_num.focus();
			}else{
				this_form.submit();
			}
		}
		function validate_email(email){
			var reg = new RegExp("[0-9a-z_]+@[0-9a-z\-_^.]+\\.[a-z]", 'i');
			if (!reg.test(email)) { return false;}
			else return true;
		}
		-->
		</script>
		<form action="<?php 
        echo $link;
        ?>
" method="post" name="JLMS_authorize_aim" id="JLMS_authorize_aim"><br />
		<table cellpadding="0" cellspacing="2" width="100%" border="0" class="jlms_table_no_borders">
		<?php 
        if ($params2->get('pre_text')) {
            ?>
		<tr><td colspan="2"><br /><?php 
            echo nl2br($params2->get('pre_text'));
            ?>
</td></tr>						
		<?php 
        }
        ?>
		<tr>
			<td align="left" valign="top" width="50%">
				<table cellpadding="0" cellspacing="2" width="100%" class="jlms_table_no_borders">
					<tr><td colspan="2" class="sectiontableheader"><?php 
        echo $JLMS_CONFIG->get('is_joomla_16', false) ? '<h2>' : '';
        echo _JLMS_SUBSCRIBE_ORDER_INFO;
        echo $JLMS_CONFIG->get('is_joomla_16', false) ? '</h2>' : '';
        ?>
</td></tr>
					<?php 
        /* available user info			
        			$my->id - 			UserID of Joomla
        			$my->username - 	Username
        			$my->name - 		Name
        			$my->email - 		Email
        			//CB Info
        			$user->first_name -	First name
        			$user->last_name - 	Last Name 
        			$user->address - 	Address 
        			$user->city -	 	City
        			$user->state -	 	State
        			$user->postal_code -Postal Code
        			$user->country - 	User Country
        			$user->phone - 	 	Phone
        			 */
        ?>
					
					<tr><td><?php 
        echo _JLMS_USER_FIRSTNAME;
        ?>
 *</td><td><input type="text" name="x_first_name" class="inputbox"  value="<?php 
        echo $user ? $user->first_name : '';
        ?>
"/></td></tr>
					<tr><td><?php 
        echo _JLMS_USER_LASTTNAME;
        ?>
 *</td><td><input type="text" name="x_last_name" class="inputbox" value="<?php 
        echo $user ? $user->last_name : '';
        ?>
" /></td></tr>
					<tr><td><?php 
        echo _JLMS_USER_ADDRESS;
        ?>
 *</td><td><input type="text" name="x_address" class="inputbox" value="<?php 
        echo $user ? $user->address : '';
        ?>
" /></td></tr>
					<tr><td><?php 
        echo _JLMS_USER_CITY;
        ?>
 *</td><td><input type="text" name="x_city" class="inputbox" value="<?php 
        echo $user ? $user->city : '';
        ?>
" /></td></tr>
					<tr><td><?php 
        echo _JLMS_USER_STATE;
        ?>
 </td><td><input type="text" name="x_state" class="inputbox" value="<?php 
        echo isset($user->state) && $user->state ? $user->state : '';
        ?>
"  /></td></tr>
					<tr><td><?php 
        echo _JLMS_USER_POSTAL_CODE;
        ?>
 *</td><td><input type="text" name="x_zip" class="inputbox" value="<?php 
        echo $user ? $user->postal_code : '';
        ?>
"  /></td></tr>
					<tr><td><?php 
        echo _JLMS_USER_COUNTRY;
        ?>
 *</td><td><input type="text" name="x_country" class="inputbox" value="<?php 
        echo $user ? $user->country : '';
        ?>
"  /></td></tr>
					<tr><td><?php 
        echo _JLMS_USER_EMAIL;
        ?>
 *</td><td><input type="text" name="x_email" class="inputbox" value="<?php 
        echo $my->email;
        ?>
" /></td></tr>
					<tr><td><?php 
        echo _JLMS_USER_PHONE;
        ?>
 *</td><td><input type="text" name="x_phone" class="inputbox" value="<?php 
        echo $user ? $user->phone : '';
        ?>
"  /></td></tr>
					<tr><td colspan="2"><div class="joomlalms_info_legend"><div style="text-align: left;"> <?php 
        echo _JLMS_FIELD_REQUIRED;
        ?>
</div></div></td></tr>
					<tr><td colspan="2">&nbsp;</td></tr>
				</table>
			</td>
			<td align="left" valign="top" width="50%">
				<table cellpadding="0" cellspacing="2" width="100%" class="jlms_table_no_borders">
					<tr><td colspan="2"  class="sectiontableheader"><?php 
        echo $JLMS_CONFIG->get('is_joomla_16', false) ? '<h2>' : '';
        echo _JLMS_SUBSCRIBE_CARD_INFO;
        echo $JLMS_CONFIG->get('is_joomla_16', false) ? '</h2>' : '';
        ?>
</td></tr>
					<tr><td id="card_number"><?php 
        echo _JLMS_SUBSCRIBE_CARD_NUMBER;
        ?>
 *</td><td><input type="text" name="x_card_num" class="inputbox" /></td></tr>
					<tr><td id="card_cvn"><?php 
        echo _JLMS_SUBSCRIBE_CARD_CVN;
        ?>
 *</td><td><input type="text" name="x_card_code" class="inputbox" size="5" /></td></tr>
					<tr><td><?php 
        echo _JLMS_SUBSCRIBE_EXP_DATE;
        ?>
 *</td>
						<td><select name="card_expirationMonth" class="inputbox">
							<option value="01">01</option>
							<option value="02">02</option>
							<option value="03">03</option>
							<option value="04">04</option>
							<option value="05">05</option>
							<option value="06">06</option>
							<option value="07">07</option>
							<option value="08">08</option>
							<option value="09">09</option>
							<option value="10">10</option>
							<option value="11">11</option>
							<option value="12">12</option>
							</select>
							&nbsp;
							<select name="card_expirationYear" class="inputbox">
							<?php 
        for ($x = date("Y"); $x < date("Y") + 10; $x++) {
            ?>
							<option value="<?php 
            echo substr($x, 2, 2);
            ?>
"><?php 
            echo $x;
            ?>
</option>
							<?php 
        }
        ?>
							</select>
						</td>
					</tr>
				</table>
			</td>
		</tr>
		</table>
		<input type="hidden" name="Itemid" value="<?php 
        echo $Itemid;
        ?>
" />
		<input type="hidden" name="proc_id" value="<?php 
        echo $proc->id;
        ?>
" />
		<input type="hidden" name="dis_coupon_code2" value="<?php 
        echo $app->getUserStateFromRequest('com_joomla_lms_dis_coupon_code', 'dis_coupon_code', '');
        ?>
" />
		<input type="hidden" name="task" value="<?php 
        echo $JLMS_CONFIG->get('use_cart', false) ? 'checkout_cart' : 'subscribe';
        ?>
" />
		<input type="hidden" name="option" value="<?php 
        echo $option;
        ?>
" />
		<input type="hidden" name="jlms_sub" value="" />
		<input type="hidden" name="id" value="" />
		<input type="hidden" name="act" value="pay" />
		<?php 
        echo $custom_code;
        ?>
		</form>
		<?php 
    }
Esempio n. 9
0
function JLMS_GB_getUsersGrades($id, $uids, &$rows, &$lists, $cycle = 0)
{
    $db =& JFactory::getDbo();
    $JLMS_ACL =& JLMSFactory::getACL();
    $is_teacher = $JLMS_ACL->isTeacher();
    $uids_str = implode(',', $uids);
    if (count($uids)) {
        $query = "SELECT a.*, b.scale_name FROM #__lms_gradebook as a LEFT JOIN #__lms_gradebook_scale as b ON a.gb_points=b.id AND b.course_id = {$id} WHERE a.course_id = '" . $id . "' AND a.user_id IN ({$uids_str})";
        $db->SetQuery($query);
        $gb_rows = $db->LoadObjectList();
        $query = "SELECT * FROM #__lms_certificate_users WHERE course_id = '" . $id . "' AND user_id IN ({$uids_str})";
        $db->SetQuery($query);
        $crt_rows = $db->LoadObjectList();
    } else {
        $crt_rows = array();
        $gb_rows = array();
    }
    $query = "SELECT * FROM #__lms_gradebook_scale WHERE course_id = {$id} ORDER BY ordering, scale_name";
    $db->SetQuery($query);
    $scale_rows = $db->LoadObjectList();
    if (count($uids) == 1) {
        if (count($crt_rows) > 1) {
            $del_ids_tmp = array();
            $del_ids = array();
            foreach ($crt_rows as $crt_row) {
                if ($crt_row->crt_date == '0000-00-00 00:00:00') {
                    $del_ids_tmp[] = $crt_row->id;
                }
            }
            if (count($del_ids) == count($crt_rows)) {
                $del_ii = 1;
                while ($del_ii < count($del_ids_tmp)) {
                    $del_ids[] = $del_ids_tmp[$del_ii];
                    $del_ii++;
                }
            } else {
                $del_ids = $del_ids_tmp;
            }
            $del_ids_str = implode(',', $del_ids);
            $query = "DELETE FROM #__lms_certificate_users WHERE id IN ({$del_ids_str}) AND course_id = '" . $id . "' AND user_id IN ({$uids_str}) AND crt_date = '0000-00-00 00:00:00'";
            $db->SetQuery($query);
            $db->query();
        }
    }
    $query = "SELECT * FROM #__lms_gradebook_items WHERE course_id = '" . $id . "' ORDER BY ordering, gbi_name";
    $db->SetQuery($query);
    $irows = $db->LoadObjectList();
    $query = "SELECT * FROM #__lms_learn_paths WHERE course_id = '" . $id . "' AND item_id <> '0' AND item_id <> '' AND published = '1' ORDER BY ordering";
    $db->SetQuery($query);
    $scorm_rows = $db->LoadObjectList();
    $scorm_ans = array();
    $scorm_n_ans = array();
    if (count($scorm_rows)) {
        $scids = array();
        $scn_ids = array();
        $scrows_i = 0;
        foreach ($scorm_rows as $scorm_row) {
            $tmp_params = new JLMSParameters($scorm_row->lp_params);
            if ($tmp_params->get('show_in_gradebook', 1)) {
                if ($scorm_row->lp_type == 1 || $scorm_row->lp_type == 2) {
                    $scn_ids[] = $scorm_row->item_id;
                } else {
                    $scids[] = $scorm_row->item_id;
                }
            }
            $scorm_rows[$scrows_i]->show_in_gradebook = $tmp_params->get('show_in_gradebook', 1);
            $scrows_i++;
        }
        if ($cycle) {
            $query = "SELECT params FROM #__lms_courses WHERE id = '" . $id . "'";
            //Atention!
            $db->setQuery($query);
            //Atention!
            $course_params = $db->loadResult();
            //Atention!
        } else {
            global $JLMS_CONFIG;
            $course_params = $JLMS_CONFIG->get('course_params');
        }
        $params = new JLMSParameters($course_params);
        if (count($scids) || count($scn_ids)) {
            require_once _JOOMLMS_FRONT_HOME . "/includes/lms_scorm.lib.php";
            if (count($scids)) {
                //nothing here
                $scorm_ans =& JLMS_GetSCORM_userResults($uids, $scids);
            }
            if (count($scn_ids)) {
                $scorm_n_ans = array();
                $uids_groups = array();
                $uids_group = array();
                //group user IDs by 5
                $uid_i = 1;
                foreach ($uids as $uid) {
                    $uids_group[] = $uid;
                    $uid_i++;
                    if ($uid_i > 5) {
                        $uids_groups[] = $uids_group;
                        $uids_group = array();
                        $uid_i = 1;
                    }
                }
                if (count($uids_group)) {
                    $uids_groups[] = $uids_group;
                }
                foreach ($uids_groups as $uids5) {
                    foreach ($scn_ids as $scn_id) {
                        $scn_ids_new_array = array();
                        $scn_ids_new_array[] = $scn_id;
                        $scorm_n_ans1 =& JLMS_Get_N_SCORM_userResults($uids5, $scn_ids_new_array, $params->get('track_type', 0));
                        $scorm_n_ans = array_merge($scorm_n_ans, $scorm_n_ans1);
                    }
                }
            }
        }
    }
    $query = "SELECT * FROM #__lms_quiz_t_quiz WHERE course_id = '" . $id . "' AND c_gradebook = 1 ORDER BY c_title";
    $db->SetQuery($query);
    $quiz_rows = $db->LoadObjectList();
    $quiz_ans = array();
    if (count($quiz_rows)) {
        if (count($uids)) {
            $query = "SELECT a.*, b.c_full_score FROM #__lms_quiz_results as a, #__lms_quiz_t_quiz as b WHERE a.course_id = '" . $id . "'" . "\n AND a.quiz_id = b.c_id AND a.user_id IN ( {$uids_str} ) ORDER BY a.user_id, a.quiz_id";
            $db->SetQuery($query);
            $quiz_ans = $db->LoadObjectList();
        } else {
            $quiz_ans = array();
        }
    }
    $i = 0;
    while ($i < count($rows)) {
        $p = array();
        foreach ($irows as $irow) {
            $pp = new stdClass();
            $pp->gbi_id = $irow->id;
            $pp->gbi_type = 1;
            // 1 - gb_item, 2 - scorm; 3 - quiz;
            $pp->user_grade = '-';
            $pp->scale_id = 0;
            $p[] = $pp;
        }
        $j = 0;
        while ($j < count($gb_rows)) {
            if ($gb_rows[$j]->user_id == $rows[$i]->user_id) {
                $k = 0;
                while ($k < count($p)) {
                    if ($p[$k]->gbi_id == $gb_rows[$j]->gbi_id && $p[$k]->gbi_type == 1) {
                        $p[$k]->user_grade = $gb_rows[$j]->scale_name ? $gb_rows[$j]->scale_name : '-';
                        //$gb_rows[$j]->gb_points;
                        $p[$k]->scale_id = $gb_rows[$j]->gb_points ? $gb_rows[$j]->gb_points : '-';
                    }
                    $k++;
                }
            }
            $j++;
        }
        $rows[$i]->user_certificate = 0;
        $rows[$i]->user_certificate_date = '';
        $j = 0;
        while ($j < count($crt_rows)) {
            if ($crt_rows[$j]->user_id == $rows[$i]->user_id) {
                $rows[$i]->user_certificate = $crt_rows[$j]->crt_option;
                $rows[$i]->user_certificate_date = $crt_rows[$j]->crt_date;
            }
            $j++;
        }
        $rows[$i]->grade_info = $p;
        //scorm
        $p = array();
        foreach ($scorm_rows as $srow) {
            $pp = new stdClass();
            $pp->gbi_id = $srow->item_id;
            $pp->lp_type = $srow->lp_type;
            $pp->gbi_type = 2;
            // 1 - gb_item, 2 - scorm; 3 - quiz;
            $pp->user_grade = '-';
            $pp->user_pts = 0;
            $pp->user_status = -1;
            $p[] = $pp;
        }
        $j = 0;
        while ($j < count($scorm_ans)) {
            if ($scorm_ans[$j]->user_id == $rows[$i]->user_id) {
                $k = 0;
                while ($k < count($p)) {
                    if ($p[$k]->gbi_id == $scorm_ans[$j]->content_id && $p[$k]->gbi_type == 2 && !$p[$k]->lp_type) {
                        /*$p[$k]->user_grade = $scorm_ans[$j]->score;
                        		$p[$k]->user_status = $scorm_ans[$j]->status;*/
                        $user_per = $scorm_ans[$j]->score > 100 ? 100 : $scorm_ans[$j]->score;
                        $sc_i = count($scale_rows) - 1;
                        while ($sc_i >= 0) {
                            if ($scale_rows[$sc_i]->min_val <= $user_per && $scale_rows[$sc_i]->max_val >= $user_per) {
                                $p[$k]->user_grade = $scale_rows[$sc_i]->scale_name;
                                break;
                            }
                            $sc_i--;
                        }
                        $p[$k]->user_pts = $scorm_ans[$j]->score;
                        $p[$k]->user_status = $scorm_ans[$j]->status;
                    }
                    $k++;
                }
            }
            $j++;
        }
        $j = 0;
        while ($j < count($scorm_n_ans)) {
            if ($scorm_n_ans[$j]->user_id == $rows[$i]->user_id) {
                $k = 0;
                while ($k < count($p)) {
                    if ($p[$k]->gbi_id == $scorm_n_ans[$j]->content_id && $p[$k]->gbi_type == 2 && ($p[$k]->lp_type == 1 || $p[$k]->lp_type == 2)) {
                        /*$p[$k]->user_grade = $scorm_n_ans[$j]->score;
                        		$p[$k]->user_status = $scorm_n_ans[$j]->status;*/
                        $user_per = $scorm_n_ans[$j]->score > 100 ? 100 : $scorm_n_ans[$j]->score;
                        //$user_per = intval($quiz_ans[$j]->user_score * 100 / $quiz_ans[$j]->c_full_score);
                        $sc_i = count($scale_rows) - 1;
                        while ($sc_i >= 0) {
                            if ($scale_rows[$sc_i]->min_val <= $user_per && $scale_rows[$sc_i]->max_val >= $user_per) {
                                $p[$k]->user_grade = $scale_rows[$sc_i]->scale_name;
                                break;
                            }
                            $sc_i--;
                        }
                        $p[$k]->user_pts = $scorm_n_ans[$j]->score;
                        $p[$k]->user_status = $scorm_n_ans[$j]->status;
                    }
                    $k++;
                }
            }
            $j++;
        }
        $rows[$i]->scorm_info = $p;
        //quizzes
        $p = array();
        foreach ($quiz_rows as $qrow) {
            $pp = new stdClass();
            $pp->gbi_id = $qrow->c_id;
            $pp->allow_user_pdf_print = $qrow->c_enable_print;
            $pp->gbi_type = 3;
            // 1 - gb_item, 2 - scorm; 3 - quiz;
            $pp->user_grade = '-';
            $pp->user_pts = 0;
            $pp->user_pts_full = '0';
            $pp->user_status = -1;
            $pp->user_passed = -1;
            $pp->user_score = 0;
            $pp->quiz_max_score = 0;
            /*Integration Plugin Percentiles*/
            $_JLMS_PLUGINS =& JLMSFactory::getPlugins();
            $_JLMS_PLUGINS->loadBotGroup('system');
            $data_plugin = new stdClass();
            $data_plugin->course_id = $rows[$i]->course_id;
            $data_plugin->quiz_id = $qrow->c_id;
            $data_plugin->user_id = $rows[$i]->user_id;
            if ($out_plugin = $_JLMS_PLUGINS->trigger('onQuizFinish', array($data_plugin))) {
                if (count($out_plugin)) {
                    $percentiles = $out_plugin[0];
                    if ($percentiles->percent >= 0) {
                        $percent = $percentiles->percent . '%';
                        $pp->user_percentile = $percent;
                    }
                }
            }
            /*Integration Plugin Percentiles*/
            $p[] = $pp;
        }
        $j = 0;
        while ($j < count($quiz_ans)) {
            if ($quiz_ans[$j]->user_id == $rows[$i]->user_id) {
                $k = 0;
                while ($k < count($p)) {
                    if ($p[$k]->gbi_id == $quiz_ans[$j]->quiz_id && $p[$k]->gbi_type == 3) {
                        if ($quiz_ans[$j]->quiz_max_score) {
                            $user_per = intval($quiz_ans[$j]->user_score * 100 / $quiz_ans[$j]->quiz_max_score);
                        } elseif ($quiz_ans[$j]->c_full_score) {
                            $user_per = intval($quiz_ans[$j]->user_score * 100 / $quiz_ans[$j]->c_full_score);
                        } else {
                            if ($quiz_ans[$j]->user_score) {
                                // ...strange ... HOW?
                                $user_per = 100;
                            } else {
                                $user_per = 0;
                            }
                        }
                        $sc_i = count($scale_rows) - 1;
                        while ($sc_i >= 0) {
                            if ($scale_rows[$sc_i]->min_val <= $user_per && $scale_rows[$sc_i]->max_val >= $user_per) {
                                $p[$k]->user_grade = $scale_rows[$sc_i]->scale_name;
                                break;
                            }
                            $sc_i--;
                        }
                        $p[$k]->user_pts = $quiz_ans[$j]->user_score;
                        $p[$k]->user_pts_full = $quiz_ans[$j]->user_score . '/' . $quiz_ans[$j]->quiz_max_score;
                        $p[$k]->user_status = $quiz_ans[$j]->user_passed;
                        $p[$k]->user_passed = $quiz_ans[$j]->user_passed;
                        $p[$k]->user_score = $quiz_ans[$j]->user_score;
                        $p[$k]->quiz_max_score = $quiz_ans[$j]->quiz_max_score;
                    }
                    $k++;
                }
            }
            $j++;
        }
        $rows[$i]->quiz_info = $p;
        $i++;
    }
    global $my;
    //--------------------------
    for ($i = 0; $i < count($scorm_rows); $i++) {
        if ($scorm_rows[$i]->lp_type == 2) {
            $query = "SELECT scorm_package FROM #__lms_n_scorm WHERE id = '" . $scorm_rows[$i]->item_id . "'";
            $db->SetQuery($query);
            $scorm_package = $db->LoadResult();
            $query = "SELECT id FROM #__lms_n_scorm WHERE scorm_package = '" . $scorm_package . "' AND course_id = 0";
            $db->SetQuery($query);
            $scorm_lib_id = $db->LoadResult();
            $outer_doc = null;
            $query = "SELECT outdoc_share, owner_id, allow_link FROM #__lms_outer_documents WHERE file_id = '" . $scorm_lib_id . "' AND folder_flag = 3";
            $db->SetQuery($query);
            $outer_doc = $db->LoadObject();
            if (is_object($outer_doc) && isset($outer_doc->allow_link) && $outer_doc->allow_link == 1) {
            } else {
                unset($scorm_rows[$i]);
            }
        }
    }
    $mas = array();
    foreach ($scorm_rows as $k => $v) {
        $mas[] = $scorm_rows[$k];
    }
    unset($scorm_rows);
    $scorm_rows = $mas;
    //---------------------------------
    if ($cycle) {
        $lists['gb_rows'][] = $irows;
        $lists['sc_rows'][] = $scorm_rows;
        $lists['quiz_rows'][] = $quiz_rows;
    } else {
        $lists['gb_rows'] = $irows;
        $lists['sc_rows'] = $scorm_rows;
        $lists['quiz_rows'] = $quiz_rows;
    }
}
Esempio n. 10
0
 function validate_recurrent_subscription($proc)
 {
     global $Itemid, $JLMS_CONFIG, $JLMS_DB;
     $params = new JLMSParameters($proc->params);
     // post back to PayPal system to validate
     /*
     foreach ($_POST as $key=>$value) $postdata.=$key."=".urlencode($value)."&";	
     $server_url2 = str_replace('https://','',str_replace('/cgi-bin/webscr','', $params->get( 'server_url' ) ));
     $curl = curl_init('https://'.$server_url2.'/cgi-bin/webscr');
     curl_setopt ($curl, CURLOPT_HEADER, 0);
     curl_setopt ($curl, CURLOPT_POST, 1);
     curl_setopt ($curl, CURLOPT_POSTFIELDS, $postdata);
     curl_setopt ($curl, CURLOPT_SSL_VERIFYPEER, 0);
     //curl_setopt ($curl, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt ($curl, CURLOPT_SSL_VERIFYHOST, 1);  
     $response = curl_exec ($curl);  	
     curl_close ($curl);
     */
     $req = 'cmd=_notify-validate';
     foreach ($_POST as $key => $value) {
         $value = urlencode(stripslashes($value));
         $req .= "&{$key}={$value}";
     }
     // post back to PayPal system to validate
     $server_url2 = str_replace('https://', '', str_replace('/cgi-bin/webscr', '', $params->get('server_url')));
     $header = "POST /cgi-bin/webscr HTTP/1.0\r\n";
     $header .= "Host: " . $server_url2 . "\r\n";
     $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
     $header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
     $fp = fsockopen($server_url2, 80, $errno, $errstr, 30);
     $verifed = false;
     if (!$fp) {
         die;
     } else {
         fputs($fp, $header . $req);
         while (!feof($fp)) {
             $res_pp = fgets($fp, 1024);
             if (strcmp($res_pp, "VERIFIED") == 0) {
                 $verifed = true;
             }
         }
         fclose($fp);
     }
     if (!$verifed) {
         die;
     }
     //if ($response != "VERIFIED") die("You should not do that ...");
     //mosMail( '*****@*****.**', 'LMS Trial', '*****@*****.**', 'Paypal', $server_url2, false, NULL, NULL );
     // assign posted variables to local variables
     // assign posted variables to local variables
     $item_name = mosGetParam($_POST, 'item_name', 0);
     $item_number = mosGetParam($_POST, 'item_number', '');
     $payment_status = mosGetParam($_POST, 'payment_status', '');
     $payment_amount = mosGetParam($_POST, 'mc_gross', '');
     $payment_currency = mosGetParam($_POST, 'mc_currency', '');
     $txn_id = mosGetParam($_POST, 'txn_id', '');
     $receiver_email = mosGetParam($_POST, 'receiver_email', '');
     $business = mosGetParam($_POST, 'business', '');
     $payer_email = mosGetParam($_POST, 'payer_email', '');
     $payment_date = mosGetParam($_POST, 'payment_date', '');
     $subscr_date = mosGetParam($_POST, 'subscr_date', '');
     $mc_gross = mosGetParam($_POST, 'mc_gross', '');
     //amount
     $mc_fee = mosGetParam($_POST, 'mc_fee', '');
     $txn_type = mosGetParam($_POST, 'txn_type', '');
     $subscr_id = mosGetParam($_POST, 'subscr_id', '');
     $subscr_date = mosGetParam($_POST, 'subscr_date', '');
     $recurring = mosGetParam($_POST, 'recurring', '');
     $recur_times = mosGetParam($_POST, 'recur_times', '');
     $reattempt = mosGetParam($_POST, 'reattempt', '');
     $period1 = mosGetParam($_POST, 'period1', '');
     $period2 = mosGetParam($_POST, 'period2', '');
     $period3 = mosGetParam($_POST, 'period3', '');
     $amount1 = mosGetParam($_POST, 'amount1', '');
     $amount2 = mosGetParam($_POST, 'amount2', '');
     $amount3 = mosGetParam($_POST, 'amount3', '');
     $mc_amount1 = mosGetParam($_POST, 'mc_amount1', '');
     $mc_amount2 = mosGetParam($_POST, 'mc_amount2', '');
     $mc_amount3 = mosGetParam($_POST, 'mc_amount3', '');
     $tax_amount = isset($_POST['option_selection1']) ? $_POST['option_selection1'] : 0;
     $tax_paypal = isset($_POST['tax']) ? $_POST['tax'] : 0;
     if ($JLMS_CONFIG->get('debug_mode', false)) {
         jimport('joomla.error.log');
         $log =& JLog::getInstance('payments.log');
         ob_start();
         var_dump($_REQUEST);
         $content = ob_get_contents();
         ob_end_clean();
         $entry['COMMENT'] = $content;
         $log->addEntry($entry);
     }
     require_once _JOOMLMS_FRONT_HOME . '/includes/joomla_lms.subscription.lib.php';
     if ($receiver_email != $params->get('business_email') && $business != $params->get('business_email')) {
         die;
     }
     if ($payment_currency != $JLMS_CONFIG->get('jlms_cur_code')) {
         die;
     }
     // new subscription
     if ($txn_type == 'subscr_signup') {
         $query = "SELECT * FROM #__lms_payments_checksum WHERE payment_id = " . $item_number;
         $JLMS_DB->setQuery($query);
         $checksum = $JLMS_DB->loadObject();
         if (!$checksum->a1 && $checksum->p1 || !$checksum->a2 && $checksum->p2) {
             $query = "SELECT * FROM `#__lms_payments` WHERE id = {$item_number}";
             $JLMS_DB->setQuery($query);
             $payment_info = $JLMS_DB->loadObject();
             $subscr_date_obj = JFactory::getDate($subscr_date);
             $subscr_date_mysql = $subscr_date_obj->toMySQL();
             jlms_update_payment($item_number, $txn_id, 'Completed', $subscr_date_mysql, $tax_amount + $tax_paypal, $tax_paypal, $isReccuring = true);
             jlms_register_new_user($item_number);
             if ($checksum->a2) {
                 $next_amount = $checksum->a2;
             } else {
                 if ($checksum->a3) {
                     $next_amount = $checksum->a3;
                 }
             }
             if ($next_amount) {
                 $parent_id = $payment_info->parent_id ? $payment_info->parent_id : $payment_info->id;
                 $query = "INSERT INTO `#__lms_payments` SET txn_id = '', status = 'Pending', tax_amount = '{$tax_amount}', tax2_amount = '{$tax2_amount}', date ='" . JLMS_gmdate() . "', parent_id = '{$parent_id}', amount = '{$next_amount}', cur_code = '{$payment_info->cur_code}', user_id = {$payment_info->user_id}, payment_type = '{$payment_info->payment_type}', sub_id = '{$payment_info->sub_id}', proc_id = '{$payment_info->proc_id}', processor = '{$payment_info->processor}'";
                 $JLMS_DB->setQuery($query);
                 $JLMS_DB->query();
             }
         }
         //get plan_id
         /*$query = "SELECT status FROM `#__lms_payments` WHERE id = $item_number ";
         		$JLMS_DB->setQuery($query);
         		$prev_payment = $JLMS_DB->LoadResult();
         		*/
         //jlms_update_payment( $item_number, $txn_id, 'Completed', $payment_date, $tax_amount, 0, $isReccuring = false );
         //jlms_register_new_user( $item_number );
     } else {
         if ($txn_type == 'subscr_payment') {
             //mosMail( '*****@*****.**', 'LMS Trial', '*****@*****.**', 'Paypal', $payment_status, false, NULL, NULL );
             //if ( $payment_status != 'Completed' ) { die; }
             if ($txn_id) {
                 $query = "SELECT count(1) FROM `#__lms_payments` WHERE txn_id = " . $JLMS_DB->quote($txn_id);
                 $JLMS_DB->setQuery($query);
                 $txt_id_exists = $JLMS_DB->loadResult();
                 if ($txt_id_exists) {
                     die;
                 }
             }
             $query = "SELECT p.id, p.name, p.description, p.published, p.p1, p.t1, p.p2, p.t2, p.p3, p.t3, s.a1, s.a2, s.a3, p.sra, p.src, p.srt, p.params" . "\n FROM #__lms_payment_items pi," . "\n #__lms_subscriptions s," . "\n #__lms_plans_subscriptions ps," . "\n #__lms_plans p" . "\n WHERE pi.payment_id=" . $item_number . "\n AND pi.item_id=s.id" . "\n AND ps.subscr_id=s.id" . "\n AND p.id=ps.plan_id";
             $JLMS_DB->setQuery($query);
             $plan = $JLMS_DB->loadObject();
             if (empty($plan)) {
                 die;
             }
             // checking if subscription data exists
             $query = "SELECT * FROM #__lms_payments_checksum WHERE payment_id = " . $item_number;
             $JLMS_DB->setQuery($query);
             $checksum = $JLMS_DB->loadObject();
             if (empty($checksum)) {
                 die;
             }
             $query = "SELECT * FROM `#__lms_payments` WHERE (id = {$item_number} OR parent_id = {$item_number}) AND status != 'Completed' AND amount = '" . ($mc_gross - $tax_paypal) . "' ORDER BY id DESC LIMIT 1";
             $JLMS_DB->setQuery($query);
             $payment_info = $JLMS_DB->loadObject();
             if (empty($payment_info)) {
                 die;
             }
             jlms_update_payment($payment_info->id, $txn_id, $payment_status, $payment_date, $tax_amount + $tax_paypal, $tax_paypal, $isReccuring = true);
             if ($payment_status == 'Completed' && $checksum->a3) {
                 $next_amount = 0;
                 if (!$payment_info->parent_id && $checksum->a2) {
                     $next_amount = $checksum->a2;
                 } else {
                     $next_amount = $checksum->a3;
                 }
                 if ($next_amount) {
                     $parent_id = $payment_info->parent_id ? $payment_info->parent_id : $payment_info->id;
                     $query = "INSERT INTO `#__lms_payments` SET txn_id = '', status = 'Pending', tax_amount = '{$tax_amount}', tax2_amount = '{$tax2_amount}', date ='" . JLMS_gmdate() . "', parent_id = '{$parent_id}', amount = '{$next_amount}', cur_code = '{$payment_info->cur_code}', user_id = {$payment_info->user_id}, payment_type = '{$payment_info->payment_type}', sub_id = '{$payment_info->sub_id}', proc_id = '{$payment_info->proc_id}', processor = '{$payment_info->processor}'";
                     $JLMS_DB->setQuery($query);
                     $JLMS_DB->query();
                 }
                 jlms_register_new_user($item_number);
             }
             $user_id = $payment_info->user_id;
         } else {
             if ($txn_type == 'subscr_cancel' || $txn_type == 'subscr_eot') {
                 if ($txn_type == 'subscr_cancel') {
                     $query = "SELECT *  FROM `#__lms_payments` WHERE (id = {$item_number} OR parent_id = {$item_number}) AND status != 'Completed' ORDER BY id DESC LIMIT 1";
                     $JLMS_DB->setQuery($query);
                     $payment_info = $JLMS_DB->loadObject();
                     if (is_object($payment_info)) {
                         $query = "UPDATE `#__lms_payments` SET status = 'Canceled' WHERE id = " . $JLMS_DB->quote($payment_info->id);
                         $JLMS_DB->setQuery($query);
                         $JLMS_DB->Query();
                     }
                 }
                 jlms_register_new_user($item_number, 1);
             }
         }
     }
     if ($payment_info->id) {
         return $payment_info->id;
     } else {
         return $item_number;
     }
     //}
     //fclose ($fp);
     //}
 }
Esempio n. 11
0
 function validate_callback($proc)
 {
     global $Itemid, $JLMS_CONFIG, $JLMS_DB;
     $params = new JLMSParameters($proc->params);
     if (!isset($_REQUEST["x_invoice_num"]) || empty($_REQUEST["x_invoice_num"])) {
         echo "Order ID is not set or empty!";
     } else {
         if ($_REQUEST['x_Login'] != $params->get('x_login', '')) {
             die('Invalid account number.');
         }
         // demo transaction
         if (isset($_REQUEST['demo']) && $_REQUEST['demo'] == "Y" && !$params->get('demo', '')) {
             die('Demo mode is switched off.');
         }
         $order_number = mosGetParam($_REQUEST, "x_invoice_num");
         $compare_string = $params->get('x_secret') . $params->get('x_login') . $_REQUEST['order_number'] . $_REQUEST['x_amount'];
         $payment_date = date("Y-m-d H:i:s", mktime());
         $compare_hash1 = strtoupper(md5($compare_string));
         $compare_hash2 = $_REQUEST['x_MD5_Hash'];
         if ($compare_hash1 != $compare_hash2 && !$params->get('demo')) {
             die('Invalid secret hash.');
         }
         if ($_REQUEST['x_response_code'] == '1' && $_REQUEST['x_2checked'] == 'Y') {
             $payment_amount = $_REQUEST['x_amount'];
             $tax_amount = $_REQUEST['tax_amount'];
             $txn_id = $_REQUEST['x_trans_id'];
             if ($params->get('demo')) {
                 $txn_id .= ' - demo mode';
             }
             $payment_date = date("Y-m-d H:i:s");
             $order_id = $_REQUEST['custom'];
             $user_id = $_REQUEST['userid'];
             $payment_currency = $JLMS_CONFIG->get('jlms_cur_code');
             require_once _JOOMLMS_FRONT_HOME . '/includes/joomla_lms.subscription.lib.php';
             if (!jlms_check_payment_transaction($payment_amount - $tax_amount, $order_id)) {
                 die('Invalid payment amount');
             }
             $query = "SELECT status FROM `#__lms_payments` WHERE id = {$order_id} ";
             $JLMS_DB->setQuery($query);
             $prev_payment = $JLMS_DB->LoadResult();
             jlms_update_payment($order_id, $txn_id, 'Completed', $payment_date);
             if ($prev_payment == 'Completed') {
             } else {
                 jlms_register_new_user($order_id);
             }
         }
         if ($params->get('return_url') == '') {
             JLMSRedirect($JLMS_CONFIG->get('live_site'));
         } else {
             JLMSRedirect($params->get('return_url'));
         }
     }
 }
    function showCourseDocuments($option, &$rows, &$lists, $is_teacher)
    {
        global $Itemid, $my, $JLMS_CONFIG;
        $JLMS_ACL =& JLMSFactory::getACL();
        $is_teacher = $JLMS_ACL->isTeacher();
        $can_do_everything = $JLMS_ACL->CheckPermissions('library', 'only_own_items') ? false : ($is_teacher ? true : false);
        $rows_c = $lists['collapsed_folders'];
        ?>
		
<script language="javascript" type="text/javascript">
<!--//--><![CDATA[//><!--
function submitbutton(pressbutton) {
	var form = document.adminForm;
	if ((pressbutton == 'outdoc_delete') && (form.boxchecked.value == '0')) {
		alert( "<?php 
        echo _JLMS_ALERT_SELECT_ITEM;
        ?>
" );
	} else if((pressbutton == 'outdoc_delete')){
		if(confirm('<?php 
        echo _JLMS_OUTDOCS_JS_CONFIRM_DELETE;
        ?>
')){
			form.task.value = pressbutton;
			form.submit();
		}
	} else if ((pressbutton == 'edit_outdoc') && (form.boxchecked.value == '0')) {
		alert( "<?php 
        echo _JLMS_ALERT_SELECT_ITEM;
        ?>
" );
	} else {
		form.task.value = pressbutton;
		form.submit();
	}
}
function submitbutton_change(pressbutton, state) {
	var form = document.adminForm;
	if (pressbutton == 'change_outdoc'){
		if (form.boxchecked.value == '0') {
			alert( "<?php 
        echo _JLMS_ALERT_SELECT_ITEM;
        ?>
" );
		} else {
			form.task.value = pressbutton;
			form.state.value = state;
			form.submit();
		}
	}
}
function submitbutton_change2(pressbutton, state, cid_id) {
	var form = document.adminForm;
	if (pressbutton == 'change_outdoc'){
		form.task.value = pressbutton;
		form.state.value = state;
		form.cid2.value = cid_id;
		form.submit();
	}
}
function submitbutton_order(pressbutton, item_id) {
	var form = document.adminForm;
	if ((pressbutton == 'outdoc_orderup') || (pressbutton == 'outdoc_orderdown')){
		if (item_id) {
		form.task.value = pressbutton;
		form.row_id.value = item_id;
		form.submit();
		}
	}
}

var TreeArray1 = new Array();
var TreeArray2 = new Array();
var Is_ex_Array = new Array();
<?php 
        $i = 1;
        foreach ($rows as $row) {
            echo "TreeArray1[" . $i . "] = " . $row->parent_id . ";";
            echo "TreeArray2[" . $i . "] = " . $row->id . ";";
            if (in_array($row->id, $rows_c)) {
                echo "Is_ex_Array[" . $i . "] = 0;";
            } else {
                echo "Is_ex_Array[" . $i . "] = 1;";
            }
            $i++;
        }
        ?>
function Hide_Folder(fid) {
	var vis_style = 'hidden';
	var dis_style = 'none';
	var i = 1;
	while (i < TreeArray1.length) {
		if (TreeArray1[i] == fid) {
			getObj('tree_row_'+TreeArray2[i]).style.visibility = vis_style;
			getObj('tree_row_'+TreeArray2[i]).style.display = dis_style;
			Hide_Folder(TreeArray2[i])
		}
		i ++;
	}
}
function Show_Folder(fid) {
	var vis_style = 'visible';
	var dis_style = '';
	var i = 1;
	while (i < TreeArray1.length) {
		if (TreeArray1[i] == fid) {
			if (getObj('tree_row_'+TreeArray2[i])) {
				getObj('tree_row_'+TreeArray2[i]).style.display = dis_style;
				getObj('tree_row_'+TreeArray2[i]).style.visibility = vis_style;
			}
			NoChange_Folder(TreeArray2[i])
		}
		i ++;
	}
}
function NoChange_Folder(fid) {
	var vis_style = 'hidden';var dis_style = 'none';var i = 1;var j = 0;
	while (i < TreeArray2.length) {
		if ( (TreeArray2[i] == fid) && (Is_ex_Array[i] == 1) ) {
			vis_style = 'visible';
			dis_style = '';
			j = 1;
		}
		i ++;
	}
	i = 1;
	while (i < TreeArray1.length) {
		if (TreeArray1[i] == fid) {
			getObj('tree_row_'+TreeArray2[i]).style.visibility = vis_style;
			getObj('tree_row_'+TreeArray2[i]).style.display = dis_style;
			if (j == 1) { NoChange_Folder(TreeArray2[i]);
			} else { Hide_Folder(TreeArray2[i]); }
		}
		i ++;
	}
}
function Ex_Folder(fid) {
	var i = 1;
	var j = 1;
	while (i < TreeArray2.length) {
		if ( (TreeArray2[i] == fid) && (Is_ex_Array[i] == 1) ) { j = 0; }
		i ++;
	}
	if (j == 1) {
		Show_Folder(fid);
		if (getObj('tree_img_' + fid).runtimeStyle) {
			var StStr = getObj('tree_img_' + fid).runtimeStyle.filter;
			var imgStr = getObj('tree_img_' + fid).outerHTML;
			imgStr = imgStr.replace('expandall.png','collapseall.png').replace('<?php 
        echo _JLMS_DOCS_EXP_FOLDER;
        ?>
', '<?php 
        echo _JLMS_DOCS_COLL_FOLDER;
        ?>
');
			StStr = StStr.replace('expandall.png','collapseall.png');
			getObj('tree_img_' + fid).outerHTML = imgStr;
			getObj('tree_img_' + fid).runtimeStyle.filter = StStr;
		} else {
			getObj('tree_img_' + fid).src = '<?php 
        echo $JLMS_CONFIG->get('live_site');
        ?>
/components/com_joomla_lms/lms_images/docs/collapseall.png';
			getObj('tree_img_' + fid).alt = '<?php 
        echo _JLMS_DOCS_COLLAPSE;
        ?>
';
			getObj('tree_img_' + fid).title = '<?php 
        echo _JLMS_DOCS_COLL_FOLDER;
        ?>
';
		}
	} else {
		Hide_Folder(fid);
		if (getObj('tree_img_' + fid).runtimeStyle) {
			var StStr = getObj('tree_img_' + fid).runtimeStyle.filter;
			var imgStr = getObj('tree_img_' + fid).outerHTML;
			imgStr = imgStr.replace('collapseall.png','expandall.png').replace('<?php 
        echo _JLMS_DOCS_COLL_FOLDER;
        ?>
', '<?php 
        echo _JLMS_DOCS_EXP_FOLDER;
        ?>
');
			StStr = StStr.replace('collapseall.png','expandall.png');
			getObj('tree_img_' + fid).outerHTML = imgStr;
			getObj('tree_img_' + fid).runtimeStyle.filter = StStr;
		} else {
			getObj('tree_img_' + fid).src = '<?php 
        echo $JLMS_CONFIG->get('live_site');
        ?>
/components/com_joomla_lms/lms_images/docs/expandall.png';
			getObj('tree_img_' + fid).alt = '<?php 
        echo _JLMS_DOCS_EXPAND;
        ?>
';
			getObj('tree_img_' + fid).title = '<?php 
        echo _JLMS_DOCS_EXP_FOLDER;
        ?>
';
		}
	}
	i = 1;
	while (i < TreeArray2.length) {
		if ( (TreeArray2[i] == fid) ) {
			if (Is_ex_Array[i] == 1) { Is_ex_Array[i] = 0;
			} else { Is_ex_Array[i] = 1; }
		}
		i ++;
	}
}
JLMS_preloadImages('<?php 
        echo $JLMS_CONFIG->get('live_site');
        ?>
/components/com_joomla_lms/lms_images/docs/expandall.png','<?php 
        echo $JLMS_CONFIG->get('live_site');
        ?>
/components/com_joomla_lms/lms_images/docs/collapseall.png'<?php 
        if ($is_teacher) {
            echo ", '" . $JLMS_CONFIG->get('live_site') . '/' . $JLMS_CONFIG->get('ajax_settings_small_indicator') . "'";
        }
        ?>
);
//--><!]]>
</script>
<?php 
        JLMS_TMPL::OpenMT();
        $hparams = array('show_menu' => true, 'simple_menu' => true);
        $toolbar = array();
        JLMS_TMPL::ShowHeader('outdocs', _JLMS_TOOLBAR_LIBRARY, $hparams, $toolbar);
        $max_tree_width = 0;
        if (isset($rows[0])) {
            $max_tree_width = $rows[0]->tree_max_width;
        }
        JLMS_TMPL::OpenTS('', ' align="right" style="text-align:right " width="100%"');
        $is_teacher = $JLMS_ACL->isTeacher();
        ?>
			<form action="<?php 
        echo $JLMS_CONFIG->get('live_site') . "/index.php?option=" . $option . "&amp;Itemid=" . $Itemid;
        ?>
" method="post" name="adminForm" enctype="multipart/form-data">
<?php 
        if (!empty($rows)) {
            ?>
				<table width="100%" cellpadding="0" cellspacing="0" border="0" class="<?php 
            echo JLMSCSS::_('jlmslist');
            ?>
">
					<tr>
						<<?php 
            echo JLMSCSS::tableheadertag();
            ?>
 width="20" class="<?php 
            echo JLMSCSS::_('sectiontableheader');
            ?>
" align="center">#</<?php 
            echo JLMSCSS::tableheadertag();
            ?>
>
					<?php 
            //if ($JLMS_ACL->CheckPermissions('docs', 'manage')) {
            ?>
						<<?php 
            echo JLMSCSS::tableheadertag();
            ?>
 width="20" class="<?php 
            echo JLMSCSS::_('sectiontableheader');
            ?>
"><input type="checkbox" style="visibility:hidden;" /></<?php 
            echo JLMSCSS::tableheadertag();
            ?>
>
					<?php 
            //}
            ?>
						<?php 
            for ($th_i = 0; $th_i < $max_tree_width + 1; $th_i++) {
                ?>
						<<?php 
                echo JLMSCSS::tableheadertag();
                ?>
 width="1%" class="<?php 
                echo JLMSCSS::_('sectiontableheader');
                ?>
"><span style="display: block; width: 16px;">&nbsp;</span></<?php 
                echo JLMSCSS::tableheadertag();
                ?>
>
						<?php 
            }
            ?>
						<<?php 
            echo JLMSCSS::tableheadertag();
            ?>
 class="<?php 
            echo JLMSCSS::_('sectiontableheader');
            ?>
" width="45%"><span style="display: block; width: 150px; text-align: left;"><?php 
            echo _JLMS_DOCS_TBL_DOCNAME;
            ?>
</span></<?php 
            echo JLMSCSS::tableheadertag();
            ?>
>
					<?php 
            //if ($JLMS_ACL->CheckPermissions('docs', 'manage')) {
            ?>
						<<?php 
            echo JLMSCSS::tableheadertag();
            ?>
 class="<?php 
            echo JLMSCSS::_('sectiontableheader');
            ?>
" colspan="2">&nbsp;</<?php 
            echo JLMSCSS::tableheadertag();
            ?>
>
						<<?php 
            echo JLMSCSS::tableheadertag();
            ?>
 class="<?php 
            echo JLMSCSS::_('sectiontableheader');
            ?>
" width="1">&nbsp;</<?php 
            echo JLMSCSS::tableheadertag();
            ?>
>
						<<?php 
            echo JLMSCSS::tableheadertag();
            ?>
 class="<?php 
            echo JLMSCSS::_('sectiontableheader');
            ?>
"><?php 
            echo _JLMS_DOCS_TBL_STARTING;
            ?>
</<?php 
            echo JLMSCSS::tableheadertag();
            ?>
>
						<<?php 
            echo JLMSCSS::tableheadertag();
            ?>
 class="<?php 
            echo JLMSCSS::_('sectiontableheader');
            ?>
"><?php 
            echo _JLMS_DOCS_TBL_ENDING;
            ?>
</<?php 
            echo JLMSCSS::tableheadertag();
            ?>
>
					<?php 
            //}
            ?>
						<<?php 
            echo JLMSCSS::tableheadertag();
            ?>
 class="<?php 
            echo JLMSCSS::_('sectiontableheader');
            ?>
" width="60%"><?php 
            echo _JLMS_DOCS_TBL_DESCR;
            ?>
</<?php 
            echo JLMSCSS::tableheadertag();
            ?>
>
					</tr>
				<?php 
            $k = 1;
            $tree_modes = array();
            $visible_folder = true;
            //$next_row_is_visible = true;
            $vis_mode = 0;
            for ($i = 0, $n = count($rows); $i < $n; $i++) {
                $row = $rows[$i];
                $max_tree_width = $row->tree_max_width;
                $link = '';
                $link_title = '';
                if ($row->folder_flag == 2) {
                    $link = sefRelToAbs("index.php?option=" . $option . "&amp;Itemid=" . $Itemid . "&amp;task=docs_view_zip&amp;id=" . $row->id);
                    $link_title = _JLMS_T_A_VIEW_ZIP_PACK;
                } elseif (!$row->folder_flag && $row->file_id) {
                    $link = sefRelToAbs("index.php?option=" . $option . "&amp;Itemid=" . $Itemid . "&amp;task=get_outdoc&amp;id=" . $row->id);
                    $link_title = _JLMS_DOCS_LINK_DOWNLOAD;
                } elseif (!$row->folder_flag && !$row->file_id) {
                    $link = sefRelToAbs("index.php?option=" . $option . "&amp;Itemid=" . $Itemid . "&amp;task=outdocs_view_content&amp;id=" . $row->id);
                    $link_title = _JLMS_T_A_VIEW_CONTENT;
                } elseif ($row->folder_flag == 3 && $row->file_id) {
                    $link = sefRelToAbs("index.php?option=" . $option . "&amp;Itemid=" . $Itemid . "&amp;task=playerSCORMFiles&amp;id=" . $row->file_id . "&amp;doc_id=" . $row->id);
                    $link_title = _JLMS_T_A_VIEW_CONTENT;
                }
                $time_p = $row->publish_start || $row->publish_end;
                $alt = $row->published ? $time_p ? _JLMS_STATUS_PUB2 : _JLMS_STATUS_PUB : _JLMS_STATUS_UNPUB;
                $image = $row->published ? $time_p ? 'btn_publish_wait.png' : 'btn_accept.png' : 'btn_cancel.png';
                //($time_p?'btn_unpublish_wait.png':'btn_cancel.png');
                if ($time_p) {
                    $is_expired = false;
                    if ($row->publish_start) {
                        $s_date = strtotime($row->start_date);
                        if ($s_date > time()) {
                            $is_expired = true;
                        }
                    }
                    if ($row->publish_end && !$is_expired) {
                        $e_date = strtotime($row->end_date);
                        if ($e_date < time()) {
                            $is_expired = true;
                        }
                    }
                    if ($is_expired) {
                        $alt = _JLMS_STATUS_EXPIRED;
                        $image = 'btn_expired.png';
                    }
                }
                $state = $row->published ? 0 : 1;
                $checked = mosHTML::idBox($i, $row->id);
                // Collapsed/Expanded view
                $tree_row_style = '';
                $visible_folder = true;
                //$next_row_is_visible;
                //$next_row_is_visible = true;
                if ($vis_mode) {
                    if ($row->tree_mode_num < $vis_mode) {
                        $vis_mode = 0;
                    }
                }
                if (in_array($row->id, $rows_c)) {
                    //$next_row_is_visible = false;
                    if ($vis_mode) {
                        if ($row->tree_mode_num < $vis_mode) {
                            $vis_mode = $row->tree_mode_num;
                        } else {
                            $visible_folder = false;
                        }
                    } else {
                        $vis_mode = $row->tree_mode_num + 1;
                    }
                } elseif ($vis_mode) {
                    if ($row->tree_mode_num >= $vis_mode) {
                        $visible_folder = false;
                    } else {
                        $vis_mode = 0;
                    }
                }
                if (!$visible_folder) {
                    $tree_row_style = ' style="visibility:hidden;display:none"';
                }
                ?>
					<tr id="tree_row_<?php 
                echo $row->id;
                ?>
" class="<?php 
                echo JLMSCSS::_('sectiontableentry' . $k);
                ?>
"<?php 
                echo $tree_row_style;
                ?>
>
						<td align="center" valign="middle"><?php 
                echo $i + 1;
                ?>
</td>
					
						<td valign="middle"><?php 
                if ($my->id == $row->owner_id || $can_do_everything) {
                    echo $checked;
                }
                ?>
</td>
					
						<?php 
                $add_img = '';
                if ($row->tree_mode_num) {
                    $g = 0;
                    $tree_modes[$row->tree_mode_num - 1] = $row->tree_mode;
                    while ($g < $row->tree_mode_num - 1) {
                        $pref = '';
                        if (isset($tree_modes[$g]) && $tree_modes[$g] == 2) {
                            $pref = 'empty_';
                        }
                        $add_img .= "<td width='16' valign='middle'><img src=\"" . $JLMS_CONFIG->get('live_site') . "/components/com_joomla_lms/lms_images/treeview/" . $pref . "line.png\" width='16' height='16' alt='" . $pref . "line' /></td>";
                        $g++;
                    }
                    $add_img .= "<td width='16' valign='middle'><img src=\"" . $JLMS_CONFIG->get('live_site') . "/components/com_joomla_lms/lms_images/treeview/sub" . $row->tree_mode . ".png\" width='16' height='16' alt='sub" . $row->tree_mode . "' /></td>";
                    $max_tree_width = $max_tree_width - $g - 1;
                }
                echo $add_img;
                ?>
						<td align="center" valign="middle" width='16'>
						<?php 
                if ($row->folder_flag == 1) {
                    $collapse_img = 'collapseall.png';
                    $collapse_alt = _JLMS_DOCS_COLL_FOLDER;
                    if (in_array($row->id, $rows_c)) {
                        $collapse_img = 'expandall.png';
                        $collapse_alt = _JLMS_DOCS_EXP_FOLDER;
                    }
                    echo "<span id='tree_div_" . $row->id . "' style='alignment:center; width:16px; font-weight:bold; cursor:pointer; vertical-align:middle;' onclick='Ex_Folder(" . $row->id . "," . $row->id . ",true)'><img class='JLMS_png' id='tree_img_" . $row->id . "' src=\"" . $JLMS_CONFIG->get('live_site') . "/components/com_joomla_lms/lms_images/docs/{$collapse_img}\" width='13' height='13' alt='" . $collapse_alt . "' title='" . $collapse_alt . "' /></span>";
                } else {
                    echo "<span style='alignment:center; width:16px; font-weight:bold; vertical-align:middle;'><img class='JLMS_png' src=\"" . $JLMS_CONFIG->get('live_site') . "/components/com_joomla_lms/lms_images/files/" . $row->file_icon . ".png\" width='16' height='16' alt='{$row->file_icon}' /></span>";
                }
                ?>
						</td>
						<td align="left" valign="middle" <?php 
                if ($max_tree_width > 0) {
                    echo "colspan='" . ($max_tree_width + 1) . "'";
                }
                ?>
 width="45%">
						<span style='font-weight:bold; vertical-align:middle;'>
						<?php 
                if ($row->folder_flag == 1) {
                    echo '&nbsp;<strong>' . $row->doc_name . '</strong>';
                } else {
                    ?>
							<?php 
                    if ($is_teacher && $row->outdoc_share || !$is_teacher && $row->outdoc_share == 2 || $my->id == $row->owner_id || $can_do_everything) {
                        $add_link_params = '';
                        if ($row->folder_flag == 3 && isset($row->scorm_params) && $row->scorm_params) {
                            $tmp_params = new JLMSParameters($row->scorm_params);
                            if ($tmp_params->get('scorm_layout', 0) == 1) {
                                $x_size = 0;
                                $y_size = 0;
                                if (isset($row->scorm_width) && $row->scorm_width > 100) {
                                    $x_size = $row->scorm_width;
                                }
                                if (isset($row->scorm_height) && $row->scorm_height > 100) {
                                    $y_size = $row->scorm_height;
                                }
                                $add_link_params = ' class="scorm_modal" rel="{handler:\'iframe\', size:{x:' . $x_size . ',y:' . $y_size . '}}"';
                                JLMS_initialize_SqueezeBox();
                            }
                        }
                        if ($link) {
                            ?>
							<a href="<?php 
                            echo $link;
                            ?>
"<?php 
                            echo $add_link_params;
                            ?>
 title="<?php 
                            echo str_replace('"', '&quot;', $row->doc_name);
                            ?>
">
<?php 
                        }
                        ?>
							<?php 
                    }
                    ?>
								&nbsp;<?php 
                    echo $row->doc_name;
                    ?>
								<?php 
                    if ($is_teacher && $row->outdoc_share || !$is_teacher && $row->outdoc_share == 2 || $my->id == $row->owner_id || $can_do_everything) {
                        if ($link) {
                            ?>
							</a>
<?php 
                        }
                        ?>
						<?php 
                    }
                }
                ?>
						</span>
						<?php 
                if ($JLMS_CONFIG->get('show_library_authors', 0) && $row->author_name) {
                    ?>
						<br />
						<span class="small"><?php 
                    echo _JLMS_HOME_AUTHOR . "&nbsp;" . $row->author_name;
                    ?>
</span>
						<?php 
                }
                ?>

						</td>
					<?php 
                //if ($JLMS_ACL->CheckPermissions('docs', 'manage')) {
                ?>
						<td valign="middle" style="vertical-align:middle "><?php 
                if ($row->allow_up == 1 && ($my->id == $row->owner_id || $can_do_everything)) {
                    echo JLMS_orderUpIcon(1, $row->id, true, 'outdoc_orderup');
                } else {
                    echo '&nbsp;';
                }
                ?>
</td>
						<td valign="middle" style="vertical-align:middle "><?php 
                if ($row->allow_down == 1 && ($my->id == $row->owner_id || $can_do_everything)) {
                    echo JLMS_orderDownIcon(1, 3, $row->id, true, 'outdoc_orderdown');
                } else {
                    echo '&nbsp;';
                }
                ?>
</td>
						<td valign="middle">
							<?php 
                if ($my->id == $row->owner_id || $can_do_everything) {
                    echo '<a class="jlms_img_link" href="javascript:submitbutton_change2(\'change_outdoc\',' . $state . ',' . $row->id . ')" title="' . $alt . '">';
                    echo '<img class="JLMS_png" src="' . $JLMS_CONFIG->get('live_site') . '/components/com_joomla_lms/lms_images/toolbar/' . $image . '" width="16" height="16" border="0" alt="' . $alt . '" />';
                    echo '</a>';
                } else {
                    echo '&nbsp;';
                }
                ?>
						</td>
						
						<td align="center" nowrap='nowrap' valign="middle"><?php 
                echo $row->publish_start ? JLMS_dateToDisplay($row->start_date) : '-';
                ?>
</td>
						<td align="center" nowrap='nowrap' valign="middle"><?php 
                echo $row->publish_end ? JLMS_dateToDisplay($row->end_date) : '-';
                ?>
</td>
					<?php 
                //}
                ?>
						<td><?php 
                $doc_descr = strip_tags($row->doc_description);
                if (!$row->folder_flag && !$row->file_id) {
                    if (strlen($doc_descr) > 75) {
                        $doc_descr = substr($doc_descr, 0, 75) . "...";
                    }
                }
                echo $doc_descr ? $doc_descr : '&nbsp;';
                ?>
						</td>
					</tr>
					<?php 
                $k = 3 - $k;
            }
            ?>
				</table>
<?php 
        } else {
            echo '<div class="joomlalms_user_message">' . _JLMS_NO_ITEMS_HERE . '</div>';
        }
        ?>
				<input type="hidden" name="option" value="<?php 
        echo $option;
        ?>
" />
				<input type="hidden" name="Itemid" value="<?php 
        echo $Itemid;
        ?>
" />
				<input type="hidden" name="task" value="" />
				<input type="hidden" name="boxchecked" value="0" />
				<input type="hidden" name="row_id" value="0" />
				<input type="hidden" name="state" value="0" />
				<input type="hidden" name="cid2" value="0" />
			</form>

<?php 
        JLMS_TMPL::CloseTS();
        //if ($JLMS_ACL->CheckPermissions('docs', 'manage')) {
        if ($is_teacher) {
            $link_foldernew = ampReplace(sefRelToAbs("index.php?option={$option}&amp;Itemid={$Itemid}&amp;task=new_outfolder"));
            $link_filenew = ampReplace(sefRelToAbs("index.php?option={$option}&amp;Itemid={$Itemid}&amp;task=new_outdocs"));
            $link_scormnew = ampReplace(sefRelToAbs("index.php?option={$option}&amp;Itemid={$Itemid}&amp;task=new_scorm"));
            $controls = array();
            $controls[] = array('href' => "javascript:submitbutton_change('change_outdoc',1);", 'title' => _JLMS_SET_PUB, 'img' => 'publish');
            $controls[] = array('href' => "javascript:submitbutton_change('change_outdoc',0);", 'title' => _JLMS_SET_UNPUB, 'img' => 'unpublish');
            $controls[] = array('href' => 'spacer');
            $controls[] = array('href' => $link_foldernew, 'title' => _JLMS_DOCS_LNK_NEW_FOLDER, 'img' => 'foldernew');
            $controls[] = array('href' => $link_filenew, 'title' => _JLMS_DOCS_LNK_NEW_DOC, 'img' => 'filenew');
            $controls[] = array('href' => "javascript:submitbutton('outdoc_delete');", 'title' => _JLMS_DELETE, 'img' => 'delete');
            $controls[] = array('href' => "javascript:submitbutton('edit_outdoc');", 'title' => _JLMS_EDIT, 'img' => 'edit');
            $controls[] = array('href' => $link_scormnew, 'title' => _JLMS_DOCS_NEW_SCORM_PACKAGE, 'img' => 'add_scorm');
            JLMS_TMPL::ShowControlsFooter($controls);
            //}
        }
        JLMS_TMPL::CloseMT();
    }
Esempio n. 13
0
function JLMS_REP_exportCsv($hits, $tot_hits = array(), $users, $courses, $pageNav, $lists, $levels, $filt_cat, $filt_group, $option, $is_full)
{
    global $JLMS_DB, $JLMS_CONFIG, $JLMS_SESSION, $task;
    switch ($task) {
        case 'report_access':
            $users_str = implode(',', $users);
            $courses_str = implode(',', $courses);
            $JLMS_DB->setQuery('SELECT course_name FROM #__lms_courses WHERE id IN(' . $courses_str . ') ORDER BY course_name');
            $crs_name = $JLMS_DB->loadResultArray();
            $JLMS_DB->setQuery('SELECT * FROM #__lms_courses WHERE id IN(' . $courses_str . ') ORDER BY course_name');
            $crs_options = $JLMS_DB->loadObjectList();
            $text_to_csv = 'username,name,email,';
            $array_zagolovk = array();
            foreach ($crs_name as $key => $c_name) {
                $view_is_course = 1;
                if ($JLMS_CONFIG->get('flms_integration', 1)) {
                    $params = new JLMSParameters($crs_options[$key]->params);
                    $view_is_course = $params->get('show_in_report', 1);
                }
                if ($view_is_course) {
                    $array_zagolovk[] = JLMS_processCSVField($c_name);
                    //echo '<th class="sectiontableheader" style="text-align:center;">'.$c_name.'</th>';
                }
            }
            $zagolovk = implode(',', $array_zagolovk);
            if ($zagolovk) {
                $text_to_csv .= $zagolovk . "\n";
            } else {
                $text_to_csv .= "\n";
            }
            $zzz = 0;
            foreach ($users as $usr_id) {
                $JLMS_DB->setQuery('SELECT username,name, email FROM #__users WHERE id =' . $usr_id);
                $usrname = $JLMS_DB->LoadObject();
                $course_hits = 0;
                $text_to_csv .= $usrname->username . ',' . JLMS_processCSVField($usrname->name) . ',' . $usrname->email . ',';
                $count = 0;
                foreach ($courses as $key => $course_id) {
                    $count++;
                    $hit_num = 0;
                    for ($i = 0; $i < count($hits); $i++) {
                        if ($hits[$i]->c_id == $course_id && $hits[$i]->usr_id == $usr_id) {
                            $hit_num = $hits[$i]->hits;
                            break;
                            // by DEN
                        }
                    }
                    $view_is_course = 1;
                    if ($JLMS_CONFIG->get('flms_integration', 1)) {
                        $params = new JLMSParameters($crs_options[$key]->params);
                        $view_is_course = $params->get('show_in_report', 1);
                    }
                    if ($view_is_course) {
                        $text_to_csv .= $hit_num;
                        if ($count != count($courses)) {
                            $text_to_csv .= ',';
                        }
                    }
                }
                $text_to_csv .= "\n";
                $zzz++;
            }
            $text_to_csv .= 'Total,,,';
            $results_total_hits = array();
            $k = 0;
            foreach ($courses as $i => $course_id) {
                foreach ($tot_hits as $j => $hit) {
                    if ($course_id == $hit->c_id) {
                        foreach ($hit as $key => $tmp_hit) {
                            if ($key == 'hits') {
                                $results_total_hits[] = $tmp_hit;
                                $k++;
                            }
                        }
                    }
                }
            }
            $text_to_csv .= implode(",", $results_total_hits);
            $text_to_csv .= "\n";
            break;
        case 'report_certif':
            $users_str = implode(',', $users);
            $courses_str = implode(',', $courses);
            $query = "SELECT h.user_id as usr_id,h.course_id as c_id FROM #__lms_certificate_users as h LEFT JOIN #__users as u ON h.user_id=u.id LEFT JOIN #__lms_courses as c ON h.course_id = c.id WHERE h.course_id IN (" . $courses_str . ") AND h.user_id IN  (" . $users_str . ")  ORDER BY h.course_id,h.user_id";
            $JLMS_DB->SetQuery($query);
            $hits = $JLMS_DB->LoadObjectLIST();
            $JLMS_DB->setQuery('SELECT course_name FROM #__lms_courses WHERE id IN(' . $courses_str . ') ORDER BY course_name');
            $crs_name = $JLMS_DB->loadResultArray();
            $JLMS_DB->setQuery('SELECT * FROM #__lms_courses WHERE id IN(' . $courses_str . ') ORDER BY course_name');
            $crs_options = $JLMS_DB->loadObjectList();
            $text_to_csv = 'username,name,email,';
            $array_zagolovk = array();
            foreach ($crs_name as $key => $c_name) {
                $view_is_course = 1;
                if ($JLMS_CONFIG->get('flms_integration', 1)) {
                    $params = new JLMSParameters($crs_options[$key]->params);
                    $view_is_course = $params->get('show_in_report', 1);
                }
                if ($view_is_course) {
                    $array_zagolovk[] = JLMS_processCSVField($c_name);
                    //echo '<th class="sectiontableheader" style="text-align:center;">'.$c_name.'</th>';
                }
            }
            $zagolovk = implode(',', $array_zagolovk);
            if ($zagolovk) {
                $text_to_csv .= $zagolovk . "\n";
            } else {
                $text_to_csv .= "\n";
            }
            $zzz = 0;
            foreach ($users as $usr_id) {
                $JLMS_DB->setQuery('SELECT username,name, email FROM #__users WHERE id =' . $usr_id);
                $usrname = $JLMS_DB->LoadObject();
                $course_hits = 0;
                $text_to_csv .= $usrname->username . ',' . JLMS_processCSVField($usrname->name) . ',' . $usrname->email . ',';
                $count = 0;
                foreach ($courses as $key => $course_id) {
                    $count++;
                    $hit_num = _JLMS_NO_ALT_TITLE;
                    for ($i = 0; $i < count($hits); $i++) {
                        if ($hits[$i]->c_id == $course_id && $hits[$i]->usr_id == $usr_id) {
                            $hit_num = _JLMS_YES_ALT_TITLE;
                            break;
                            // by DEN
                        }
                    }
                    $view_is_course = 1;
                    if ($JLMS_CONFIG->get('flms_integration', 1)) {
                        $params = new JLMSParameters($crs_options[$key]->params);
                        $view_is_course = $params->get('show_in_report', 1);
                    }
                    if ($view_is_course) {
                        $text_to_csv .= $hit_num;
                        if ($count != count($courses)) {
                            $text_to_csv .= ',';
                        }
                    }
                }
                $text_to_csv .= "\n";
                $zzz++;
            }
            break;
        case 'report_scorm':
            $rows = $courses;
            $array_zagolovk = array();
            $array_zagolovk[] = 'Username';
            $array_zagolovk[] = 'Name';
            $array_zagolovk[] = 'Email';
            $array_zagolovk[] = 'Course Name';
            $array_zagolovk[] = 'Course ID';
            $array_zagolovk[] = 'Date';
            $array_zagolovk[] = 'Score';
            $array_zagolovk[] = 'Course Status';
            $zagolovk = implode(',', $array_zagolovk);
            $text_to_csv = '';
            if ($zagolovk) {
                $text_to_csv .= $zagolovk . "\n";
            } else {
                $text_to_csv .= "\n";
            }
            foreach ($rows as $row) {
                $text = array();
                $text[] = $row->username;
                $text[] = JLMS_processCSVField($row->name);
                $text[] = $row->email;
                $text[] = JLMS_processCSVField($row->course_name);
                $text[] = JLMS_processCSVField($row->lpath_name);
                if (isset($row->scorm_data) && $row->scorm_data->status) {
                    if ($row->scorm_data->end) {
                        $date_end = date("Y-m-d H:i:s", $row->scorm_data->end);
                        $text[] = JLMS_dateToDisplay($date_end);
                    } else {
                        $text[] = '';
                    }
                } else {
                    $text[] = '';
                }
                if (isset($row->scorm_data)) {
                    $text[] = $row->scorm_data->score;
                } else {
                    $text[] = '';
                }
                if ($row->course_status) {
                    $text[] = 'Completed';
                } else {
                    $text[] = 'Incompleted';
                }
                $text_to_csv .= implode(",", $text);
                $text_to_csv .= "\n";
            }
            break;
    }
    global $task;
    if ($task == 'report_access') {
        $tmpl_name = 'access_report';
        $prefix_title = str_replace("_", " ", $tmpl_name);
    } else {
        if ($task == 'report_certif') {
            $tmpl_name = 'completion_report';
            $prefix_title = str_replace("_", " ", $tmpl_name);
        } else {
            if ($task == 'report_grade') {
                $tmpl_name = 'user_report';
                $prefix_title = str_replace("_", " ", $tmpl_name);
            } else {
                if ($task == 'report_scorm') {
                    $tmpl_name = 'scorm_report';
                    $prefix_title = str_replace("_", " ", $tmpl_name);
                }
            }
        }
    }
    $ug_name = $tmpl_name . '_' . date('dMY');
    if (preg_match('/Opera(\\/| )([0-9].[0-9]{1,2})/', $_SERVER['HTTP_USER_AGENT'])) {
        $UserBrowser = "Opera";
    } elseif (preg_match('/MSIE ([0-9].[0-9]{1,2})/', $_SERVER['HTTP_USER_AGENT'])) {
        $UserBrowser = "IE";
    } else {
        $UserBrowser = '';
    }
    header("Content-type: application/csv");
    header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT');
    header("Content-Length: " . strlen(trim($text_to_csv)));
    header('Content-Disposition: attachment; filename="' . $ug_name . '.csv"');
    if ($UserBrowser == 'IE') {
        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
        header('Pragma: public');
    } else {
        header('Pragma: no-cache');
    }
    echo $text_to_csv;
    exit;
}
Esempio n. 14
0
    function JQ_LoadNextData_nojs()
    {
        global $JLMS_DB, $option, $Itemid, $JLMS_CONFIG;
        $id = intval(mosGetParam($_REQUEST, 'id', 0));
        $quest_id = intval(mosGetParam($_REQUEST, 'quest_id', 0));
        $quiz_id = intval(mosGetParam($_REQUEST, 'quiz', 0));
        $inside_lp = intval(mosGetParam($_REQUEST, 'inside_lp', 0));
        $QA = new JLMS_quiz_API($quiz_id, $inside_lp);
        if (!$QA->quiz_valid()) {
            return '';
        }
        //		$toolbar_no_a = $QA->quiz_Get_NoAtToolbar();
        $stu_quiz_id = intval(mosGetParam($_REQUEST, 'stu_quiz_id', 0));
        $quest_id = intval(mosGetParam($_REQUEST, 'quest_id', 0));
        $user_unique_id = strval(mosGetParam($_REQUEST, 'user_unique_id', ''));
        $quest_score = intval(mosGetParam($_REQUEST, 'quest_score', 0));
        //		$answer = strval( mosGetParam( $_REQUEST, 'answer', '' ) );
        $QA->set('stu_quiz_id', $stu_quiz_id);
        $QA->set('user_unique_id', $user_unique_id);
        $QA->quiz_ProcessStartData();
        $q_data = $QA->quiz_Get_QuestionList();
        $is_quest_exists = false;
        $qtype = 0;
        $c_pool_quest = 0;
        foreach ($q_data as $qd) {
            if ($qd->c_id == $quest_id) {
                $is_quest_exists = true;
                $qtype = $qd->c_type;
                $c_pool_quest = $qd->c_pool;
                $quest_params = new JLMSParameters($qd->params);
                break;
            }
        }
        if (!$is_quest_exists) {
            return '';
        }
        $kol_quests = count($q_data);
        $quiz = $QA->quiz_data;
        // temporary for compatibility
        $quiz_params = new JLMSParameters($QA->get_qvar('params'));
        global $JLMS_LANGUAGE, $JLMS_CONFIG;
        JLMS_require_lang($JLMS_LANGUAGE, 'quiz.lang', $JLMS_CONFIG->get('default_language'));
        //require(_JOOMLMS_FRONT_HOME . "/languages/".$JLMS_CONFIG->get('default_language').'/quiz.lang.php');
        require _JOOMLMS_FRONT_HOME . '/includes/quiz/quiz_language.php';
        global $jq_language;
        if ($quiz->c_wrong_message) {
            $jq_language['quiz_answer_incorrect'] = htmlspecialchars(nl2br($quiz->c_wrong_message));
        }
        if ($quiz->c_right_message) {
            $jq_language['quiz_answer_correct'] = htmlspecialchars(nl2br($quiz->c_right_message));
        }
        //$q_t_params = $QA->get_qvar('params');
        if ($quiz_params->get('disable_quest_feedback') || $quest_params->get('disable_quest_feedback')) {
        } else {
            $query = "SELECT * FROM #__lms_quiz_t_question_fb WHERE quest_id = {$quest_id}";
            $JLMS_DB->SetQuery($query);
            $q_fbs = $JLMS_DB->LoadObjectList();
            foreach ($q_fbs as $qfb) {
                if ($qfb->choice_id == -1) {
                    if ($qfb->fb_text) {
                        $jq_language['quiz_answer_incorrect'] = $qfb->fb_text;
                    }
                } elseif (!$qfb->choice_id) {
                    if ($qfb->fb_text) {
                        $jq_language['quiz_answer_correct'] = $qfb->fb_text;
                    }
                }
            }
        }
        $quest_num = 1;
        $query = "SELECT c_question_id FROM #__lms_quiz_r_student_question WHERE c_stu_quiz_id = '" . $stu_quiz_id . "'";
        $JLMS_DB->SetQuery($query);
        $q_ids = $JLMS_DB->LoadResultArray();
        $q_num = 0;
        $q_num_ar = 0;
        $qqn = 0;
        foreach ($q_data as $qd) {
            if ($qd->c_id == $quest_id) {
                $q_num = $qqn + 1;
                $q_num_ar = $qqn;
                break;
            }
            $qqn++;
        }
        if (!$q_num) {
            return '';
        } else {
            $q_num = 0;
            $q_num_ar = 0;
            // here we are using $q_num and $q_num_ar for other needs (don't warry :) )
            // find next not answered question
            for ($i = $qqn, $n = count($q_data); $i < $n; $i++) {
                if (!in_array($q_data[$i]->c_id, $q_ids) && $q_data[$i]->c_id != $quest_id) {
                    $q_num = $i + 1;
                    $q_num_ar = $i;
                    break;
                }
            }
            if (!$q_num) {
                // find not answered question from prev questions
                for ($i = 0; $i < $qqn; $i++) {
                    if (!in_array($q_data[$i]->c_id, $q_ids) && $q_data[$i]->c_id != $quest_id) {
                        $q_num = $i + 1;
                        $q_num_ar = $i;
                        break;
                    }
                }
            }
            if ($q_num) {
                $quest_num = $q_num;
                $j = $q_num_ar;
            }
        }
        $quest_score = $q_data[$j]->c_point;
        $quest_id = $q_data[$j]->c_id;
        $query = "SELECT a.*, b.lpath_id FROM #__lms_learn_path_step_quiz_results as a, #__lms_learn_path_steps as b WHERE a.stu_quiz_id = '" . $stu_quiz_id . "' AND a.step_id = b.id";
        $JLMS_DB->setQuery($query);
        $this_lpath = $JLMS_DB->LoadObject();
        $toolbar = array();
        if (isset($QA->lpath_stu_quiz_id) && $QA->lpath_stu_quiz_id == $stu_quiz_id) {
            if ($q_data[$j]->c_type == 10) {
                if (isset($q_data[$j]->c_slide) && $q_data[$j]->c_slide) {
                    $toolbar[] = array('kol_quests' => $kol_quests, 'num_quest' => $quest_num, 'quest_score' => $quest_score, 'img_btn' => 'btn_start.png', 'text_btn' => _JLMS_NEXT_ALT_TITLE, 'link_cont' => '&task=show_lpath_nojs&action=contents_lpath&course_id=' . $id . '&id=' . $this_lpath->lpath_id . '&stu_quiz_id=' . $stu_quiz_id . '&user_unique_id=' . $this_lpath->unique_id . '&step_id=' . $this_lpath->step_id . '&user_start_id=' . $this_lpath->start_id . '&quest_id=' . $quest_id . '&quiz_id=' . $quiz_id . '&stu_quiz_id=' . $stu_quiz_id . '');
                } else {
                    $toolbar[] = array('kol_quests' => $kol_quests, 'num_quest' => $quest_num, 'quest_score' => $quest_score, 'img_btn' => 'btn_start.png', 'text_btn' => _JLMS_NEXT_ALT_TITLE);
                }
            } else {
                if (isset($q_data[$j]->c_slide) && $q_data[$j]->c_slide) {
                    $toolbar[] = array('kol_quests' => $kol_quests, 'num_quest' => $quest_num, 'quest_score' => $quest_score, 'img_btn' => 'btn_complete.png', 'text_btn' => _JLMS_OK_ALT_TITLE, 'link_cont' => '&task=show_lpath_nojs&action=contents_lpath&course_id=' . $id . '&id=' . $this_lpath->lpath_id . '&stu_quiz_id=' . $stu_quiz_id . '&user_unique_id=' . $this_lpath->unique_id . '&step_id=' . $this_lpath->step_id . '&user_start_id=' . $this_lpath->start_id . '&quest_id=' . $quest_id . '&quiz_id=' . $quiz_id . '&stu_quiz_id=' . $stu_quiz_id . '');
                } else {
                    $toolbar[] = array('kol_quests' => $kol_quests, 'num_quest' => $quest_num, 'quest_score' => $quest_score, 'img_btn' => 'btn_complete.png', 'text_btn' => _JLMS_OK_ALT_TITLE);
                }
            }
        } else {
            if ($q_data[$j]->c_type == 10) {
                if (isset($q_data[$j]->c_slide) && $q_data[$j]->c_slide) {
                    $toolbar[] = array('kol_quests' => $kol_quests, 'num_quest' => $quest_num, 'quest_score' => $quest_score, 'img_btn' => 'btn_start.png', 'text_btn' => _JLMS_NEXT_ALT_TITLE, 'link_cont' => '&task=quiz_action&atask=contents&id=' . $id . '&quiz=' . $quiz_id . '&stu_quiz_id=' . $stu_quiz_id . '&user_unique_id=' . $user_unique_id . '&quest_id=' . $quest_id . '');
                } else {
                    $toolbar[] = array('kol_quests' => $kol_quests, 'num_quest' => $quest_num, 'quest_score' => $quest_score, 'img_btn' => 'btn_start.png', 'text_btn' => _JLMS_NEXT_ALT_TITLE);
                }
            } else {
                if (isset($q_data[$j]->c_slide) && $q_data[$j]->c_slide) {
                    $toolbar[] = array('kol_quests' => $kol_quests, 'num_quest' => $quest_num, 'quest_score' => $quest_score, 'img_btn' => 'btn_complete.png', 'text_btn' => _JLMS_OK_ALT_TITLE, 'link_cont' => '&task=quiz_action&atask=contents&id=' . $id . '&quiz=' . $quiz_id . '&stu_quiz_id=' . $stu_quiz_id . '&user_unique_id=' . $user_unique_id . '&quest_id=' . $quest_id . '');
                } else {
                    $toolbar[] = array('kol_quests' => $kol_quests, 'num_quest' => $quest_num, 'quest_score' => $quest_score, 'img_btn' => 'btn_complete.png', 'text_btn' => _JLMS_OK_ALT_TITLE);
                }
            }
        }
        ?>
		<form action="<?php 
        echo ampReplace($JLMS_CONFIG->get('live_site') . "/index.php?option={$option}&Itemid={$Itemid}");
        ?>
" method="post" name="quest_form">
			<table width="100%" cellpadding="0" cellspacing="0" border="0" class="jlms_table_no_borders">
				<tr>
					<td>
					<?php 
        JLMS_quiz_ajax_class::JQ_toolbar_nojs($toolbar, $q_data[$j]->c_type, 1);
        ?>
					</td>
				</tr>
				<tr>
					<td>
						<?php 
        echo JLMS_quiz_ajax_class::JQ_GetQuestData_nojs($q_data[$j], $jq_language, $QA->get('stu_quiz_id', 0));
        ?>
					</td>
				</tr>
			</table>
			
			<input type="hidden" name="atask" value="next"/>
			<input type="hidden" name="user_unique_id" value="<?php 
        echo $user_unique_id;
        ?>
"/>
			<input type="hidden" name="stu_quiz_id" value="<?php 
        echo $stu_quiz_id;
        ?>
"/>
			<input type="hidden" name="quiz" value="<?php 
        echo $quiz_id;
        ?>
"/>
			
			<input type="hidden" name="option" value="<?php 
        echo $option;
        ?>
"/>
			<input type="hidden" name="task" value="quiz_action"/>
			<input type="hidden" name="id" value="<?php 
        echo $id;
        ?>
"/>
		</form>
		<?php 
    }
    function showLPathRow(&$k, $row, $i, $topic_id, $checked = null, $manage = 1, $span = 1)
    {
        global $option, $Itemid, $my, $JLMS_DB, $Itemid, $JLMS_CONFIG, $JLMS_SESSION;
        $usertype = $JLMS_CONFIG->get('current_usertype', 0);
        $course_id = intval(mosGetParam($_REQUEST, 'id', 0));
        $k = 3 - $k;
        $is_hidden = false;
        if (isset($row->item_id) && $row->item_id) {
            $tmp_params = new JLMSParameters($row->lp_params);
            if ($tmp_params->get('hide_in_list', 0) == 1) {
                $is_hidden = true;
            }
        }
        if ($usertype == 1) {
            $task = 'compose_lpath';
            $title = _JLMS_LPATH_LINK_TITLE_COMPOSE;
        } elseif ($usertype == 2) {
            $task = 'show_lpath';
            $title = _JLMS_LPATH_LINK_TITLE_VIEW;
            if ($is_hidden) {
                return 0;
            }
        }
        if (isset($row->is_hidden) && $row->is_hidden && $usertype == 2) {
            return 0;
        }
        $link = "index.php?option=" . $option . "&Itemid=" . $Itemid . "&task=" . $task . "&course_id=" . $course_id . "&id=" . $row->id;
        $icon_img = "toolbar/tlb_lpath";
        $icon_alt = "learnpath";
        if ($row->item_id) {
            $title = _JLMS_LPATH_LINK_TITLE_SCORM;
            //$link = "index.php?option=".$option."&Itemid=".$Itemid."&task=player_scorm&course_id=".$course_id."&id=".$row->item_id."&lp_type=".$row->lp_type;
            $link = "index.php?option=" . $option . "&Itemid=" . $Itemid . "&task=show_lpath&course_id=" . $course_id . "&id=" . $row->id;
            //."&lp_type=".$row->lp_type;
            $icon_img = "toolbar/tlb_scorm";
            $icon_alt = _JLMS_TOPIC_SCORM;
        }
        $title = $row->lpath_name;
        if (!$checked && $manage == 1) {
            $checked = mosHTML::idBox($topic_id * 1000 + $i, $row->link_id);
        }
        // 01.12.2007 '$i' chenged to '$topic_id*1000+$i' by DEN - to avoid dublicate id's
        $alt = $row->published ? _JLMS_LPATH_STATUS_PUB : _JLMS_LPATH_STATUS_UNPUB;
        $image = $row->published ? $is_hidden ? 'btn_publish_hidden.png' : 'btn_accept.png' : 'btn_cancel.png';
        $state = $row->published ? 0 : 1;
        ?>
		<tr class="<?php 
        echo JLMSCSS::_('sectiontableentry' . $k);
        ?>
">
			<td width='1%' valign="middle" align="center"><?php 
        if ($usertype != 2) {
            echo $i + 1;
        } else {
            echo '&nbsp;';
        }
        ?>
</td>
		<?php 
        if ($usertype == 1) {
            ?>
			<?php 
            if ($checked) {
                echo "<td width='1%'>";
                if (!isset($row->is_link)) {
                    echo $checked;
                }
                echo "</td>";
            }
            ?>
		<?php 
        }
        ?>
			<td valign="middle" align="center" width="1%">				
					<img class='JLMS_png' src="<?php 
        echo $JLMS_CONFIG->get('live_site');
        ?>
/components/com_joomla_lms/lms_images/<?php 
        echo $icon_img;
        ?>
.png" width='16' height='16' alt="<?php 
        echo $icon_alt;
        ?>
" />
			</td>
			<td valign="middle" align="left" colspan="<?php 
        echo $span;
        ?>
">
			<?php 
        if (!isset($row->is_link)) {
            $add_link_params = '';
            if (isset($row->scorm_params) && $row->scorm_params) {
                $tmp_params = new JLMSParameters($row->scorm_params);
                if ($tmp_params->get('scorm_layout', 0) == 1) {
                    $x_size = 0;
                    $y_size = 0;
                    if (isset($row->scorm_width) && $row->scorm_width > 100) {
                        $x_size = $row->scorm_width;
                    }
                    if (isset($row->scorm_height) && $row->scorm_height > 100) {
                        $y_size = $row->scorm_height;
                    }
                    $add_link_params = ' class="scorm_modal" rel="{handler:\'iframe\', size:{x:' . $x_size . ',y:' . $y_size . '}}"';
                    JLMS_initialize_SqueezeBox();
                }
            }
            ?>
				<a href="<?php 
            echo sefRelToAbs($link);
            ?>
"<?php 
            echo $add_link_params;
            ?>
 title="<?php 
            echo $title;
            ?>
">
			<?php 
        }
        ?>
	
					<?php 
        echo $row->lpath_name;
        ?>
			<?php 
        if (!isset($row->is_link)) {
            ?>
		
				</a>
			<?php 
        }
        ?>
	
			</td>
		<?php 
        if ($usertype != 2) {
            //teacher/admin table handler
            ?>
			<?php 
            if ($manage == 1) {
                ?>
	
				<td valign="middle" class="controltd"><?php 
                if ($row->allow_up == 1) {
                    echo JLMS_orderIcon_element($topic_id, $course_id, 'orderup_element', _JLMS_TOPIC_I_MOVEUP, $row->ordering);
                } else {
                    echo '&nbsp;';
                }
                ?>
</td>
				<td valign="middle" class="controltd"><?php 
                if ($row->allow_down == 1 && $manage == 1) {
                    echo JLMS_orderIcon_element($topic_id, $course_id, 'orderdown_element', _JLMS_TOPIC_I_MOVEDOWN, $row->ordering);
                } else {
                    echo '&nbsp;';
                }
                ?>
</td>
				<?php 
                $state = publishUtility($row->published, $row->show);
                ?>
				<td valign="middle" class="controltd"><?php 
                echo JLMS_showHideIcon($row->link_id, $course_id, $topic_id, $state, 'change_element', $option);
                ?>
</td>
			<?php 
            }
            ?>
			<td align="center">-</td>
			<td align="center">-</td>
		<?php 
        } else {
            //user/student table handler
            $r_img = 'btn_cancel';
            $r_sta = _JLMS_LPATH_STU_LPSTATUS_NOTCOMPLETED;
            $r_start = '-';
            $r_end = '-';
            if (!$row->item_id) {
                if (isset($row->r_status) && $row->r_status == 1) {
                    $r_img = 'btn_accept';
                    $r_sta = _JLMS_LPATH_STU_LPSTATUS_COMPLETED;
                    if ($row->r_start) {
                        $r_start = JLMS_dateToDisplay($row->r_start, false, $JLMS_CONFIG->get('offset') * 60 * 60, '\\<\\b\\r \\/>H:i:s');
                    }
                    if ($row->r_end) {
                        $r_end = JLMS_dateToDisplay($row->r_end, false, $JLMS_CONFIG->get('offset') * 60 * 60, '\\<\\b\\r \\/>H:i:s');
                    }
                } elseif (isset($row->r_status) && $row->r_status == 0) {
                    $r_img = 'btn_pending_cur';
                    if ($row->r_start) {
                        $r_start = JLMS_dateToDisplay($row->r_start, false, $JLMS_CONFIG->get('offset') * 60 * 60, '\\<\\b\\r \\/>H:i:s');
                    }
                }
            } else {
                if (isset($row->s_status) && $row->s_status == 1) {
                    $r_img = 'btn_accept';
                    $r_sta = _JLMS_LPATH_STU_LPSTATUS_COMPLETED;
                    $r_start = '-';
                    $r_end = '-';
                }
                if ($row->lp_type == 1 || $row->lp_type == 2) {
                    if (isset($row->r_end) && $row->r_end) {
                        $r_end = JLMS_dateToDisplay($row->r_end, true, $JLMS_CONFIG->get('offset') * 60 * 60, '\\<\\b\\r \\/>H:i:s');
                    }
                    if (isset($row->r_start) && $row->r_start) {
                        $r_start = JLMS_dateToDisplay($row->r_start, true, $JLMS_CONFIG->get('offset') * 60 * 60, '\\<\\b\\r \\/>H:i:s');
                    }
                }
            }
            ?>
			<td valign="middle" align="center" width="1%">
				<?php 
            //Show Status Lapths/Scorms //by Max - 25.02.2011
            joomla_lms_html::ShowStatusAs($row);
            ?>
			</td>
			<td valign="middle" align="center" nowrap="nowrap"><?php 
            echo $r_start;
            ?>
</td>
			<td valign="middle" align="center" nowrap="nowrap"><?php 
            echo $r_end;
            ?>
</td>
		<?php 
        }
        ?>
			<td><?php 
        $descr = strip_tags($row->lpath_shortdescription);
        if (strlen($descr) > 75) {
            $descr = substr($descr, 0, 75) . "...";
        }
        echo $descr ? $descr : '&nbsp;';
        ?>
			</td>
		</tr>
		<?php 
        return 1;
    }
    function showCourseLPaths($course_id, $option, &$lpaths)
    {
        global $Itemid, $my, $JLMS_DB, $JLMS_CONFIG;
        $JLMS_ACL =& JLMSFactory::getACL();
        ?>
<script language="javascript" type="text/javascript">
<!--
function submitbutton(pressbutton) {
	var form = document.adminForm;
		
			if ( ((pressbutton == 'edit_lpath') || (pressbutton == 'lpath_delete') ) && (form.boxchecked.value == "0")) {
				alert('<?php 
        echo _JLMS_ALERT_SELECT_ITEM;
        ?>
');
			} else {
				if( pressbutton == 'lpath_delete' ) {
					if (confirm('<?php 
        echo _JLMS_ALERT_DELETE_ITEM;
        ?>
')) {
						form.task.value = pressbutton;
						form.submit();
					}
				}
				else {	
						form.task.value = pressbutton;
						form.submit();
				}
			}	
}
	
function submitbutton_order(pressbutton, item_id) {
	var form = document.adminForm;
	if ((pressbutton == 'lpath_orderup') || (pressbutton == 'lpath_orderdown')){
		if (item_id) {
		form.task.value = pressbutton;
		form.row_id.value = item_id;
		form.submit();
		}
	}
}
function submitbutton_change(pressbutton, state) {
	var form = document.adminForm;
	if (pressbutton == 'change_lpath'){
		if (form.boxchecked.value == 0 || form.boxchecked.value == "0") {
			alert('<?php 
        echo _JLMS_ALERT_SELECT_ITEM;
        ?>
');
		} else {
			form.task.value = pressbutton;
			form.state.value = state;
			form.submit();
		}
	}
}
function submitbutton_change2(pressbutton, state, cid_id) {
	var form = document.adminForm;
	if (pressbutton == 'change_lpath'){
		form.task.value = pressbutton;
		form.state.value = state;
		form.cid2.value = cid_id;
		form.submit();
	}
}
function submitbutton_allorder(n) {
	var form = document.adminForm;

	for ( var j = 0; j <= n; j++ ) {
		box = eval( "document.adminForm.cb" + j );
		if ( box ) {
			if ( box.checked == false ) {
				box.checked = true;
			}
		}
	}
	form.task.value = 'lpath_saveorederall';
	form.submit();
}
//-->
</script>
<?php 
        JLMS_TMPL::OpenMT();
        $hparams = array();
        JLMS_TMPL::ShowHeader('lpath', _JLMS_LPATH_TITLE, $hparams);
        JLMS_TMPL::OpenTS();
        //temporary check for number of items
        $num_items = 0;
        $there_were_squeezeboxes = false;
        for ($i = 0, $n = count($lpaths); $i < $n; $i++) {
            $row_path = $lpaths[$i];
            $is_hidden = false;
            if ($row_path->item_id) {
                $tmp_params = new JLMSParameters($row_path->lp_params);
                if ($tmp_params->get('hide_in_list', 0) == 1) {
                    $is_hidden = true;
                }
            }
            if ($JLMS_ACL->CheckPermissions('lpaths', 'manage')) {
                $task = 'compose_lpath';
                $title = _JLMS_LPATH_LINK_TITLE_COMPOSE;
            } elseif ($JLMS_ACL->CheckPermissions('lpaths', 'view')) {
                $task = 'show_lpath';
                $title = _JLMS_LPATH_LINK_TITLE_VIEW;
                if ($is_hidden) {
                    continue;
                }
            }
            if (isset($row_path->is_hidden) && $row_path->is_hidden && !$JLMS_ACL->CheckPermissions('lpaths', 'view_all')) {
                continue;
            }
            $num_items++;
        }
        ?>
			<form action="<?php 
        echo $JLMS_CONFIG->getCfg('live_site') . "/index.php?option={$option}&amp;Itemid={$Itemid}";
        ?>
" method="post" name="adminForm">
<?php 
        if ($num_items) {
            ?>
				<table width="100%" cellpadding="0" cellspacing="0" border="0" class="<?php 
            echo JLMSCSS::_('jlmslist');
            ?>
">
					<tr>
						<<?php 
            echo JLMSCSS::tableheadertag();
            ?>
 width="20" class="<?php 
            echo JLMSCSS::_('sectiontableheader');
            ?>
" align="center">#</<?php 
            echo JLMSCSS::tableheadertag();
            ?>
>
					<?php 
            if ($JLMS_ACL->CheckPermissions('lpaths', 'manage') || $JLMS_ACL->CheckPermissions('lpaths', 'publish')) {
                ?>
						<<?php 
                echo JLMSCSS::tableheadertag();
                ?>
 width="25" class="<?php 
                echo JLMSCSS::_('sectiontableheader');
                ?>
" align="center"><input type="checkbox" name="toggle" value="" onclick="checkAll(<?php 
                echo count($lpaths);
                ?>
);" /></<?php 
                echo JLMSCSS::tableheadertag();
                ?>
>
					<?php 
            }
            ?>
						<<?php 
            echo JLMSCSS::tableheadertag();
            ?>
 width="20" class="<?php 
            echo JLMSCSS::_('sectiontableheader');
            ?>
" align="center">&nbsp;</<?php 
            echo JLMSCSS::tableheadertag();
            ?>
>
						<<?php 
            echo JLMSCSS::tableheadertag();
            ?>
 class="<?php 
            echo JLMSCSS::_('sectiontableheader');
            ?>
"><?php 
            echo _JLMS_LPATH_TBL_HEAD_NAME;
            ?>
</<?php 
            echo JLMSCSS::tableheadertag();
            ?>
>
					<?php 
            if ($JLMS_ACL->CheckPermissions('lpaths', 'publish')) {
                ?>
						<<?php 
                echo JLMSCSS::tableheadertag();
                ?>
 class="<?php 
                echo JLMSCSS::_('sectiontableheader');
                ?>
" width="1">&nbsp;</<?php 
                echo JLMSCSS::tableheadertag();
                ?>
>
					<?php 
            }
            ?>
					<?php 
            if ($JLMS_ACL->CheckPermissions('lpaths', 'order')) {
                ?>
						<<?php 
                echo JLMSCSS::tableheadertag();
                ?>
 class="<?php 
                echo JLMSCSS::_('sectiontableheader');
                ?>
" width="1">&nbsp;</<?php 
                echo JLMSCSS::tableheadertag();
                ?>
>
						<<?php 
                echo JLMSCSS::tableheadertag();
                ?>
 class="<?php 
                echo JLMSCSS::_('sectiontableheader');
                ?>
" width="1">&nbsp;</<?php 
                echo JLMSCSS::tableheadertag();
                ?>
>
						<<?php 
                echo JLMSCSS::tableheadertag();
                ?>
 class="<?php 
                echo JLMSCSS::_('sectiontableheader');
                ?>
" width="1"><?php 
                echo _JLMS_REORDER;
                ?>
</<?php 
                echo JLMSCSS::tableheadertag();
                ?>
>
						<<?php 
                echo JLMSCSS::tableheadertag();
                ?>
 class="<?php 
                echo JLMSCSS::_('sectiontableheader');
                ?>
" width="1"><a class="jlms_img_link" href="javascript:submitbutton_allorder(<?php 
                echo count($lpaths) - 1;
                ?>
)"><img width="16" height="16" border="0" title="<?php 
                echo _JLMS_SAVEORDER;
                ?>
" alt="<?php 
                echo _JLMS_SAVEORDER;
                ?>
" src="<?php 
                echo $JLMS_CONFIG->get('live_site');
                ?>
/components/com_joomla_lms/lms_images/filesave.png"/></a></<?php 
                echo JLMSCSS::tableheadertag();
                ?>
>
					<?php 
            }
            ?>
					<?php 
            if ($JLMS_ACL->CheckPermissions('lpaths', 'manage')) {
                ?>
						<<?php 
                echo JLMSCSS::tableheadertag();
                ?>
 class="<?php 
                echo JLMSCSS::_('sectiontableheader');
                ?>
" width="1">&nbsp;</<?php 
                echo JLMSCSS::tableheadertag();
                ?>
>
					<?php 
            }
            ?>
					<?php 
            if (!$JLMS_ACL->CheckPermissions('lpaths', 'manage')) {
                ?>
						<<?php 
                echo JLMSCSS::tableheadertag();
                ?>
 class="<?php 
                echo JLMSCSS::_('sectiontableheader');
                ?>
" width="1">&nbsp;</<?php 
                echo JLMSCSS::tableheadertag();
                ?>
>
						<<?php 
                echo JLMSCSS::tableheadertag();
                ?>
 class="<?php 
                echo JLMSCSS::_('sectiontableheader');
                ?>
" align="center"><?php 
                echo _JLMS_LPATH_TBL_STARTING;
                ?>
</<?php 
                echo JLMSCSS::tableheadertag();
                ?>
>
						<<?php 
                echo JLMSCSS::tableheadertag();
                ?>
 class="<?php 
                echo JLMSCSS::_('sectiontableheader');
                ?>
" align="center"><?php 
                echo _JLMS_LPATH_TBL_ENDING;
                ?>
</<?php 
                echo JLMSCSS::tableheadertag();
                ?>
>
					<?php 
            }
            ?>
						<<?php 
            echo JLMSCSS::tableheadertag();
            ?>
 class="<?php 
            echo JLMSCSS::_('sectiontableheader');
            ?>
"><?php 
            echo _JLMS_LPATH_TBL_HEAD_DESCR;
            ?>
</<?php 
            echo JLMSCSS::tableheadertag();
            ?>
>
					</tr>
				<?php 
            $k = 1;
            $i_counter = 0;
            for ($i = 0, $n = count($lpaths); $i < $n; $i++) {
                $row_path = $lpaths[$i];
                $is_hidden = false;
                $is_squeezebox = false;
                if ($row_path->item_id) {
                    $tmp_params = new JLMSParameters($row_path->lp_params);
                    if ($tmp_params->get('hide_in_list', 0) == 1) {
                        $is_hidden = true;
                    }
                    if (isset($row_path->scorm_params)) {
                        $tmp_params2 = new JLMSParameters($row_path->scorm_params);
                        if ($tmp_params2->get('scorm_layout', 0) == 1) {
                            $is_squeezebox = true;
                            $there_were_squeezeboxes = true;
                        }
                    }
                }
                $manage_item = false;
                if ($JLMS_ACL->CheckPermissions('lpaths', 'manage')) {
                    $manage_item = true;
                }
                if ($JLMS_ACL->CheckPermissions('lpaths', 'only_own_items') && $row_path->owner_id != $my->id) {
                    $manage_item = false;
                } elseif ($JLMS_ACL->CheckPermissions('lpaths', 'only_own_role') && $JLMS_ACL->GetRole() != $JLMS_ACL->UserSystemRole($JLMS_DB, $row_path->owner_id)) {
                    $manage_item = false;
                }
                if ($manage_item) {
                    $task = 'compose_lpath';
                    $title = _JLMS_LPATH_LINK_TITLE_COMPOSE;
                } elseif ($JLMS_ACL->CheckPermissions('lpaths', 'view')) {
                    $task = 'show_lpath';
                    $title = _JLMS_LPATH_LINK_TITLE_VIEW;
                    if ($is_hidden && !$JLMS_ACL->CheckPermissions('lpaths', 'view_all')) {
                        continue;
                    }
                }
                if (isset($row_path->is_hidden) && $row_path->is_hidden && !$JLMS_ACL->CheckPermissions('lpaths', 'view_all')) {
                    continue;
                }
                $link = "index.php?option=" . $option . "&Itemid=" . $Itemid . "&task=" . $task . "&course_id=" . $course_id . "&id=" . $row_path->id;
                // sefRelToAbs() - est' nige
                $icon_img = "toolbar/tlb_lpath";
                $icon_alt = "learnpath";
                if ($row_path->item_id) {
                    $title = _JLMS_LPATH_LINK_TITLE_SCORM;
                    //$link = "index.php?option=".$option."&Itemid=".$Itemid."&task=player_scorm&course_id=".$course_id."&id=".$row_path->item_id."&lp_type=".$row_path->lp_type;
                    $link = "index.php?option=" . $option . "&Itemid=" . $Itemid . "&task=show_lpath&course_id=" . $course_id . "&id=" . $row_path->id;
                    //."&lp_type=".$row_path->lp_type;
                    $icon_img = "toolbar/tlb_scorm";
                    $icon_alt = "scorm";
                }
                $checked = mosHTML::idBox($i_counter, $row_path->id);
                $alt = $row_path->published ? $is_hidden ? _JLMS_STATUS_PUBLISHED_AND_HIDDEN : _JLMS_LPATH_STATUS_PUB : _JLMS_LPATH_STATUS_UNPUB;
                $image = $row_path->published ? $is_hidden ? 'btn_publish_hidden.png' : 'btn_accept.png' : 'btn_cancel.png';
                $state = $row_path->published ? 0 : 1;
                $released_info_txt = '';
                if ($row_path->is_time_related) {
                    $released_info_txt = _JLMS_WILL_BE_RELEASED_IN;
                    $showperiod = $row_path->show_period;
                    $ost1 = $showperiod % (24 * 60);
                    $sp_days = ($showperiod - $ost1) / (24 * 60);
                    $ost2 = $showperiod % 60;
                    $sp_hours = ($ost1 - $ost2) / 60;
                    $sp_mins = $ost2;
                    $release_time_info = false;
                    if ($sp_days) {
                        $released_info_txt .= ' ' . $sp_days . ' ' . _JLMS_RELEASED_IN_DAYS;
                        $release_time_info = true;
                    }
                    if ($sp_hours) {
                        $released_info_txt .= ' ' . $sp_hours . ' ' . _JLMS_RELEASED_IN_HOURS;
                        $release_time_info = true;
                    }
                    if ($sp_mins) {
                        $released_info_txt .= ' ' . $sp_mins . ' ' . _JLMS_RELEASED_IN_MINUTES;
                        $release_time_info = true;
                    }
                    if ($release_time_info) {
                        $released_info_txt .= ' ' . _JLMS_RELEASED_AFTER_ENROLLMENT;
                    }
                    if ($image == 'btn_accept.png') {
                        $image = 'btn_publish_wait.png';
                    }
                }
                $publish_icon = '&nbsp;';
                if ($JLMS_ACL->CheckPermissions('lpaths', 'publish')) {
                    /*$publish_icon = '<a href="javascript:submitbutton_change2(\'change_lpath\','.$state.','.$row_path->id.')" title="'.$alt.'">';
                    		$publish_icon .= '<img class="JLMS_png" src="'.$JLMS_CONFIG->get('live_site').'/components/com_joomla_lms/lms_images/toolbar/'.$image.'" width="16" height="16" border="0" alt="'.$alt.'" />';
                    		$publish_icon .= '</a>';*/
                    $title_tt = $alt;
                    $content_tt = $released_info_txt;
                    if (isset($row_path->is_prereqs) && $row_path->is_prereqs) {
                        if ($content_tt) {
                            $content_tt .= '<br />';
                        }
                        $content_tt .= _JLMS_STATUS_CONFIGURED_PREREQUISITES;
                    }
                    $name_tt = '<img class="JLMS_png" src="' . $JLMS_CONFIG->get('live_site') . '/components/com_joomla_lms/lms_images/toolbar/' . $image . '" width="16" height="16" border="0" alt="' . $alt . '" />';
                    $link_tt = 'javascript:submitbutton_change2(\'change_lpath\',' . $state . ',' . $row_path->id . ')';
                    $publish_icon = JLMS_toolTip($title_tt, $content_tt, $name_tt, $link_tt);
                }
                if ($JLMS_ACL->CheckPermissions('lpaths', 'only_own_items') && $row_path->owner_id != $my->id) {
                    $checked = '&nbsp;';
                    $publish_icon = '&nbsp;';
                } elseif ($JLMS_ACL->CheckPermissions('lpaths', 'only_own_role') && $JLMS_ACL->GetRole() != $JLMS_ACL->UserSystemRole($JLMS_DB, $row_path->owner_id)) {
                    $checked = '&nbsp;';
                    $publish_icon = '&nbsp;';
                }
                ?>
					<tr class="<?php 
                echo JLMSCSS::_('sectiontableentry' . $k);
                ?>
">
						<td valign="middle" align="center"><?php 
                echo $i_counter + 1;
                ?>
</td>
					<?php 
                if ($JLMS_ACL->CheckPermissions('lpaths', 'manage') || $JLMS_ACL->CheckPermissions('lpaths', 'publish')) {
                    ?>
						<td valign="middle" align="center"><?php 
                    if (!isset($row_path->is_link)) {
                        echo $checked;
                    }
                    ?>
</td>
					<?php 
                }
                ?>
						<td valign="middle" align="center">
							<span style="vertical-align:middle; text-align:center">
								<img class='JLMS_png' src="<?php 
                echo $JLMS_CONFIG->get('live_site');
                ?>
/components/com_joomla_lms/lms_images/<?php 
                echo $icon_img;
                ?>
.png" width='16' height='16' alt="<?php 
                echo $icon_alt;
                ?>
" />
							</span>
						</td>
						<td valign="middle" align="left">
							<?php 
                if (isset($row_path->is_link) && $row_path->is_link) {
                    echo $row_path->lpath_name;
                } elseif ($is_squeezebox) {
                    $x_size = 0;
                    $y_size = 0;
                    if (isset($row_path->scorm_width)) {
                        $x_size = $row_path->scorm_width;
                        if ($x_size == 100) {
                            //settings from 1.0.6 version (means 100% width)
                            $x_size = 0;
                        }
                    }
                    if (isset($row_path->scorm_height)) {
                        $y_size = $row_path->scorm_height;
                    }
                    ?>
									<a href="<?php 
                    echo sefRelToAbs($link);
                    ?>
" class="scorm_modal" rel="{handler:'iframe', size:{x:<?php 
                    echo $x_size;
                    ?>
,y:<?php 
                    echo $y_size;
                    ?>
}}" title="<?php 
                    echo str_replace('"', '&quot;', $row_path->lpath_name);
                    ?>
">
										<?php 
                    echo $row_path->lpath_name;
                    ?>
									</a>
							<?php 
                } else {
                    ?>
									<a href="<?php 
                    echo sefRelToAbs($link);
                    ?>
" title="<?php 
                    echo str_replace('"', '&quot;', $row_path->lpath_name);
                    ?>
">
										<?php 
                    echo $row_path->lpath_name;
                    ?>
									</a>
							<?php 
                }
                ?>
							
							<?php 
                if ($JLMS_CONFIG->get('show_lpaths_authors', 0)) {
                    ?>
							<br />
							<span class="small"><?php 
                    echo _JLMS_HOME_AUTHOR . "&nbsp;" . $row_path->author_name;
                    ?>
</span>
							<?php 
                }
                ?>
						</td>
					<?php 
                if ($JLMS_ACL->CheckPermissions('lpaths', 'publish')) {
                    ?>
						<td valign="middle">
							<?php 
                    echo $publish_icon;
                    ?>
						</td>
					<?php 
                }
                ?>
					<?php 
                if ($JLMS_ACL->CheckPermissions('lpaths', 'order')) {
                    ?>
						<td valign="middle"><?php 
                    echo JLMS_orderUpIcon($i_counter, $row_path->id, true, 'lpath_orderup');
                    ?>
</td>
						<td valign="middle"><?php 
                    echo JLMS_orderDownIcon($i_counter, $n, $row_path->id, true, 'lpath_orderdown');
                    ?>
</td>
						<td colspan="2">
							<input type="text" name="order[]" size="5" value="<?php 
                    echo $row_path->ordering;
                    ?>
" class="inputbox" style="text-align: center" />
						</td>
					<?php 
                }
                ?>
					<?php 
                if ($JLMS_ACL->CheckPermissions('lpaths', 'manage')) {
                    ?>
						<td valign="middle">
						<?php 
                    if ($manage_item && ($row_path->item_id && $row_path->lp_type != 2 || !$row_path->item_id)) {
                        $download_message = _JLMS_LPATH_LINK_TITLE_DOWN_SCORM;
                        if (!$row_path->item_id) {
                            $download_message = _JLMS_LPATH_EXPORT_LP;
                        }
                        ?>
						<a class="jlms_img_link" href="<?php 
                        echo sefRelToAbs("index.php?option={$option}&amp;Itemid={$Itemid}&amp;task=download_scorm&amp;course_id={$course_id}&amp;id={$row_path->id}");
                        ?>
" title="<?php 
                        echo $download_message;
                        ?>
"><img class='JLMS_png' src="<?php 
                        echo $JLMS_CONFIG->get('live_site');
                        ?>
/components/com_joomla_lms/lms_images/toolbar/btn_export.png" border="0" width="16" height="16" alt="<?php 
                        echo $download_message;
                        ?>
" title="<?php 
                        echo $download_message;
                        ?>
" /></a>
						<?php 
                    } else {
                        echo '&nbsp;';
                    }
                    ?>
						</td>
					<?php 
                }
                ?>
					<?php 
                if (!$JLMS_ACL->CheckPermissions('lpaths', 'manage')) {
                    $r_img = 'btn_cancel';
                    $r_sta = _JLMS_LPATH_STU_LPSTATUS_NOTCOMPLETED;
                    $r_start = '-';
                    $r_end = '-';
                    if (!$row_path->item_id) {
                        if (isset($row_path->r_status) && $row_path->r_status == 1) {
                            $r_img = 'btn_accept';
                            $r_sta = _JLMS_LPATH_STU_LPSTATUS_COMPLETED;
                            if ($row_path->r_start) {
                                $r_start = JLMS_dateToDisplay($row_path->r_start, false, $JLMS_CONFIG->get('offset') * 60 * 60, '\\<\\b\\r \\/>H:i:s');
                            }
                            if ($row_path->r_end) {
                                $r_end = JLMS_dateToDisplay($row_path->r_end, false, $JLMS_CONFIG->get('offset') * 60 * 60, '\\<\\b\\r \\/>H:i:s');
                            }
                        } elseif (isset($row_path->r_status) && $row_path->r_status == 0) {
                            $r_img = 'btn_pending_cur';
                            if ($row_path->r_start) {
                                $r_start = JLMS_dateToDisplay($row_path->r_start, false, $JLMS_CONFIG->get('offset') * 60 * 60, '\\<\\b\\r \\/>H:i:s');
                            }
                        }
                    } else {
                        if (isset($row_path->s_status) && $row_path->s_status == 1) {
                            $r_img = 'btn_accept';
                            $r_sta = _JLMS_LPATH_STU_LPSTATUS_COMPLETED;
                            $r_start = '-';
                            $r_end = '-';
                        }
                        if ($row_path->lp_type == 1 || $row_path->lp_type == 2) {
                            if (isset($row_path->r_end) && $row_path->r_end) {
                                $r_end = JLMS_dateToDisplay($row_path->r_end, true, $JLMS_CONFIG->get('offset') * 60 * 60, '\\<\\b\\r \\/>H:i:s');
                            }
                            if (isset($row_path->r_start) && $row_path->r_start) {
                                $r_start = JLMS_dateToDisplay($row_path->r_start, true, $JLMS_CONFIG->get('offset') * 60 * 60, '\\<\\b\\r \\/>H:i:s');
                            }
                        }
                    }
                    ?>
						<td valign="middle" align="center" width="16">
							<?php 
                    //Show Status Lapths/Scorms //by Max - 25.02.2011
                    joomla_lms_html::ShowStatusAs($row_path);
                    ?>
	
						</td>
						<td valign="middle" align="center" nowrap="nowrap"><?php 
                    echo $r_start;
                    ?>
</td>
						<td valign="middle" align="center" nowrap="nowrap"><?php 
                    echo $r_end;
                    ?>
</td>
					<?php 
                }
                ?>
						<td valign="middle"><?php 
                echo $row_path->lpath_shortdescription ? $row_path->lpath_shortdescription : '&nbsp;';
                ?>
</td>
					</tr>
					<?php 
                $k = 3 - $k;
                $i_counter++;
            }
            ?>
				</table>
<?php 
        } else {
            echo '<div class="joomlalms_user_message">' . _JLMS_NO_ITEMS_HERE . '</div>';
        }
        if ($there_were_squeezeboxes) {
            JLMS_initialize_SqueezeBox();
        }
        ?>
				<input type="hidden" name="option" value="<?php 
        echo $option;
        ?>
" />
				<input type="hidden" name="Itemid" value="<?php 
        echo $Itemid;
        ?>
" />
				<input type="hidden" name="task" value="learnpaths" />
				<input type="hidden" name="id" value="<?php 
        echo $course_id;
        ?>
" />
				<input type="hidden" name="boxchecked" value="0" />
				<input type="hidden" name="row_id" value="0" />
				<input type="hidden" name="state" value="0" />
				<input type="hidden" name="cid2" value="0" />
			</form>
<?php 
        JLMS_TMPL::CloseTS();
        if ($JLMS_ACL->CheckPermissions('lpaths', 'manage') || $JLMS_ACL->CheckPermissions('lpaths', 'publish')) {
            $link_new = JLMSRoute::_("index.php?option=" . $option . "&amp;Itemid=" . $Itemid . "&amp;task=new_lpath&amp;id=" . $course_id);
            $link_new_scorm = JLMSRoute::_("index.php?option=" . $option . "&amp;Itemid=" . $Itemid . "&amp;task=new_lpath_scorm&amp;id=" . $course_id);
            $link_new_scormlib = JLMSRoute::_("index.php?option={$option}&amp;Itemid={$Itemid}&amp;task=new_scorm_from_library&amp;id=" . $course_id);
            $controls = array();
            if ($JLMS_ACL->CheckPermissions('lpaths', 'publish')) {
                $controls[] = array('href' => "javascript:submitbutton_change('change_lpath',1);", 'title' => _JLMS_LPATH_SET_PUB, 'img' => 'publish');
                $controls[] = array('href' => "javascript:submitbutton_change('change_lpath',0);", 'title' => _JLMS_LPATH_SET_UNPUB, 'img' => 'unpublish');
                if ($JLMS_ACL->CheckPermissions('lpaths', 'manage')) {
                    $controls[] = array('href' => 'spacer');
                }
            }
            if ($JLMS_ACL->CheckPermissions('lpaths', 'manage')) {
                $controls[] = array('href' => ampReplace($link_new), 'onclick' => "", 'title' => _JLMS_LPATH_DO_NEW_LP, 'img' => 'add_lpath');
                //TODO: translate 'Import SCORM package'
                $controls[] = array('href' => ampReplace($link_new_scorm), 'onclick' => "", 'title' => _JLMS_LPATH_IMPORT_SCORM, 'img' => 'add_scorm');
                $controls[] = array('href' => $link_new_scormlib, 'title' => _JLMS_SCORM_ADD_A_SCORM_PACKAGE_FROM_THE_LIBRARY, 'img' => 'add_library');
                $controls[] = array('href' => 'spacer');
                $controls[] = array('href' => "javascript:submitbutton('lpath_delete');", 'title' => _JLMS_LPATH_DO_DEL_LP, 'img' => 'delete');
                $controls[] = array('href' => "javascript:submitbutton('edit_lpath');", 'title' => _JLMS_LPATH_DO_EDIT_LP, 'img' => 'edit');
            }
            JLMS_TMPL::ShowControlsFooter($controls);
        }
        JLMS_TMPL::CloseMT();
    }
Esempio n. 17
0
function JLMS_showCoursesForGuest($option, $enrollment = false)
{
    global $JLMS_DB, $JLMS_CONFIG, $JLMS_SESSION, $Itemid;
    $app =& JFactory::getApplication();
    $filter_groups = intval(mosGetParam($_REQUEST, 'groups_course', 0));
    $limit = intval(mosGetParam($_GET, 'limit', $JLMS_SESSION->get('list_limit', $JLMS_CONFIG->get('list_limit'))));
    $JLMS_SESSION->set('list_limit', $limit);
    $limitstart = intval(mosGetParam($_GET, 'limitstart', 0));
    $lists = array();
    /*Courses Blog*/
    $menu_params = '';
    if ($Itemid) {
        $query = "SELECT params FROM #__menu WHERE id = '" . $Itemid . "'";
        $JLMS_DB->setQuery($query);
        $menu_params = $JLMS_DB->loadResult();
    }
    $menu_params = new JLMSParameters($menu_params);
    if ($Itemid) {
        $lists['menu_params'] = $menu_params;
    }
    /*Courses Blog*/
    if ($JLMS_CONFIG->get('meta_desc')) {
        $doc =& JFactory::getDocument();
        $doc->setMetaData('description', $JLMS_CONFIG->get('meta_desc'));
    }
    if ($JLMS_CONFIG->get('meta_keys')) {
        $doc =& JFactory::getDocument();
        $doc->setMetaData('keywords', $JLMS_CONFIG->get('meta_keys'));
    }
    $query = "SELECT * FROM `#__lms_course_cats` WHERE `parent` = '0' AND `restricted` = 0 ORDER BY c_category";
    $JLMS_DB->setQuery($query);
    $groups = $JLMS_DB->loadObjectList();
    $type_g[] = mosHTML::makeOption(0, _JLMS_COURSES_ALL_CATEGORIES);
    $i = 1;
    foreach ($groups as $group) {
        $type_g[] = mosHTML::makeOption($group->id, $group->c_category);
        $i++;
    }
    $link = "index.php?option={$option}&amp;Itemid={$Itemid}&amp;task=courses";
    $link = $link . "&amp;groups_course='+this.options[selectedIndex].value+'";
    $link = sefRelToAbs($link);
    $link = str_replace('%5C%27', "'", $link);
    $link = str_replace('%5B', "[", $link);
    $link = str_replace('%5D', "]", $link);
    $link = str_replace('%20', "+", $link);
    $link = str_replace("\\\\\\", "", $link);
    $link = str_replace('%27', "'", $link);
    $lists['groups_course'] = mosHTML::selectList($type_g, 'groups_course', 'class="inputbox" size="1" onchange="document.location.href=\'' . $link . '\';"', 'value', 'text', $filter_groups);
    //FLMS multicat
    if ($JLMS_CONFIG->get('multicat_use', 0)) {
        $query = "SELECT * FROM #__lms_course_cats_config ORDER BY id";
        $JLMS_DB->setQuery($query);
        $levels = $JLMS_DB->loadObjectList();
        if (count($levels) == 0) {
            for ($i = 0; $i < 5; $i++) {
                if ($i > 0) {
                    $levels[$i]->cat_name = _JLMS_COURSES_COURSES_GROUPS;
                } else {
                    $levels[$i]->cat_name = _JLMS_COURSES_COURSES_GROUPS;
                }
            }
        }
        $lists['levels'] = $levels;
        $level_id = array();
        for ($i = 0; $i < count($levels); $i++) {
            if (isset($_REQUEST['category_filter']) && $_REQUEST['category_filter']) {
                if ($i == 0) {
                    $level_id[$i] = $_REQUEST['category_filter'];
                    $parent_id[$i] = 0;
                } else {
                    $level_id[$i] = 0;
                    $parent_id[$i] = $level_id[$i - 1];
                }
            } else {
                if ($i == 0) {
                    $level_id[$i] = intval(mosGetParam($_REQUEST, 'filter_id_' . $i . '', $JLMS_SESSION->get('FLMS_filter_id_' . $i . '', 0)));
                    $_REQUEST['filter_id_' . $i] = $level_id[$i];
                    $JLMS_SESSION->set('FLMS_filter_id_' . $i . '', $level_id[$i]);
                } else {
                    $level_id[$i] = intval(mosGetParam($_REQUEST, 'filter_id_' . $i . '', $JLMS_SESSION->get('FLMS_filter_id_' . $i . '', 0)));
                    $_REQUEST['filter_id_' . $i] = $level_id[$i];
                    $JLMS_SESSION->set('FLMS_filter_id_' . $i . '', $level_id[$i]);
                }
                if ($i == 0) {
                    $parent_id[$i] = 0;
                } else {
                    $parent_id[$i] = $level_id[$i - 1];
                }
                if ($i == 0 || $parent_id[$i]) {
                    //(Max): extra requests
                    $query = "SELECT count(id) FROM `#__lms_course_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('FLMS_filter_id_' . $i . '', $level_id[$i]);
                    }
                }
            }
        }
        for ($i = 0; $i < count($levels); $i++) {
            if ($i > 0 && $level_id[$i - 1] == 0) {
                $level_id[$i] = 0;
                $JLMS_SESSION->set('FLMS_filter_id_' . $i . '', $level_id[$i]);
                $parent_id[$i] = 0;
            } elseif ($i == 0 && $level_id[$i] == 0) {
                $level_id[$i] = 0;
                $JLMS_SESSION->set('FLMS_filter_id_' . $i . '', $level_id[$i]);
                $parent_id[$i] = 0;
            }
        }
        $javascript = 'onclick="javascript:read_filter();" onchange="javascript:write_filter();document.adminForm.task.value=\'courses\';document.adminForm.submit();"';
        for ($i = 0; $i < count($levels); $i++) {
            if ($i == 0 || $parent_id[$i]) {
                //(Max): extra requests
                if ($parent_id[$i] == 0) {
                    $query = "SELECT * FROM `#__lms_course_cats` WHERE `parent` = '0' AND `restricted` = 0";
                    $query .= "\n ORDER BY `c_category`";
                } else {
                    $query = "SELECT * FROM `#__lms_course_cats` WHERE parent = '" . $parent_id[$i] . "' ORDER BY c_category";
                }
                $JLMS_DB->setQuery($query);
                $groups = $JLMS_DB->loadObjectList();
                if ($parent_id[$i] && $i > 0 && count($groups)) {
                    $type_level[$i][] = mosHTML::makeOption(0, ' &nbsp; ');
                    foreach ($groups as $group) {
                        $type_level[$i][] = mosHTML::makeOption($group->id, $group->c_category);
                    }
                    $lists['filter_' . $i . ''] = mosHTML::selectList($type_level[$i], 'filter_id_' . $i . '', 'class="inputbox" size="1" style="width: 266px;" ' . $javascript, 'value', 'text', $level_id[$i]);
                    //onchange="document.location.href=\''. $link_multi .'\';"
                } elseif ($i == 0) {
                    $type_level[$i][] = mosHTML::makeOption(0, ' &nbsp; ');
                    foreach ($groups as $group) {
                        $type_level[$i][] = mosHTML::makeOption($group->id, $group->c_category);
                    }
                    $lists['filter_' . $i . ''] = mosHTML::selectList($type_level[$i], 'filter_id_' . $i . '', 'class="inputbox" size="1" style="width: 266px;" ' . $javascript, 'value', 'text', $level_id[$i]);
                    //onchange="document.location.href=\''. $link_multi .'\';"
                }
            }
        }
    }
    //FLMS multicat
    //FILTER
    $where = '';
    if ($JLMS_CONFIG->get('multicat_use', 0)) {
        //NEW MUSLTICATS
        //		$tmp_level = array();
        $last_catid = 0;
        $tmp_cats_filter = JLMS_getFilterMulticategories($last_catid);
        /*
        if(isset($_REQUEST['category_filter']) && $_REQUEST['category_filter']){
        	$last_catid = $_REQUEST['category_filter'];
        } else {
        	$i=0;
        	foreach($_REQUEST as $key=>$item){
        		if(preg_match('#filter_id_(\d+)#', $key, $result)){
        			if($item){
        				$tmp_level[$i] = $result;
        				$last_catid = $item;
        				$i++;
        			}	
        		}	
        	}
        }
        
        $query = "SELECT * FROM #__lms_course_cats 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)) {
            $where .= "\n AND ( a.cat_id IN (" . $catids . ")";
            if ($JLMS_CONFIG->get('sec_cat_use', 0)) {
                foreach ($tmp_cats_filter as $tmp_cats_filter_one) {
                    $where .= "\n OR a.sec_cat LIKE '%|" . $tmp_cats_filter_one . "|%'";
                }
            }
            $where .= "\n )";
        }
        //NEW MUSLTICATS
    } else {
        if ($filter_groups) {
            if ($JLMS_CONFIG->get('sec_cat_use', 0)) {
                $where .= " AND (a.cat_id = '{$filter_groups}' OR a.sec_cat LIKE '%|{$filter_groups}|%') ";
            } else {
                $where .= " AND a.cat_id = '{$filter_groups}' ";
            }
        }
    }
    $show_paid_courses = $JLMS_CONFIG->get('show_paid_courses', 1);
    $where .= $show_paid_courses ? '' : ' AND a.paid <> 1 ';
    $restricted_courses = JLMS_illegal_courses_guest();
    $restricted_courses = implode(',', $restricted_courses);
    if ($restricted_courses == '') {
        $restricted_courses = "''";
    }
    $query = "SELECT a.*, b.username, b.email, b.name as user_fullname, a.id as course_id, d.c_category  FROM `#__lms_courses` as a " . "\n LEFT JOIN `#__lms_course_cats` as d ON d.id = a.cat_id " . "\n ,`#__users` as b " . "\n WHERE a.owner_id = b.id" . "\n AND ( a.published = 1" . ($JLMS_CONFIG->get('show_future_courses', false) ? '' : "\n AND ( ((a.publish_start = 1) AND (a.start_date <= '" . date('Y-m-d') . "')) OR (a.publish_start = 0) )") . "\n AND ( ((a.publish_end = 1) AND (a.end_date >= '" . date('Y-m-d') . "')) OR (a.publish_end = 0) )" . "\n )" . "\n AND a.id NOT IN ({$restricted_courses})" . "\n AND a.gid = 0" . "\n {$where} " . "\n ORDER BY " . ($JLMS_CONFIG->get('lms_courses_sortby', 0) ? "a.ordering, a.course_name, a.id" : "a.course_name, a.ordering, a.id");
    $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 );
    $JLMS_DB->setQuery($query);
    $rows = $JLMS_DB->LoadObjectList();
    //Leading Courses - Blog parametrs
    if (strlen($menu_params->get('leading_courses', ''))) {
        $leading_courses = array();
        $leading_courses = explode(',', $menu_params->get('leading_courses', ''));
        for ($i = 0; $i < count($rows); $i++) {
            $rows[$i]->leading_course = 0;
            if (in_array($rows[$i]->id, $leading_courses)) {
                $rows[$i]->leading_course = 1;
                $lists['leading_courses'] = 1;
            }
        }
        $ordering = 0;
        $i = 0;
        while ($i < count($rows)) {
            $j = $i + 1;
            while ($j < count($rows)) {
                if ($rows[$j]->leading_course) {
                    $temp = new stdClass();
                    $rows[$i]->ordering = $j;
                    $rows[$j]->ordering = $i;
                    $temp = $rows[$j];
                    $rows[$j] = $rows[$i];
                    $rows[$i] = $temp;
                    break;
                }
                $j++;
            }
            $i++;
        }
        $ordering = 0;
        $i = 0;
        while ($i < count($rows)) {
            if ($rows[$i]->leading_course) {
                $j = $i + 1;
                while ($j < count($rows)) {
                    if (isset($leading_courses[$i]) && $rows[$j]->id == $leading_courses[$i]) {
                        $rows[$i]->ordering = $j;
                        $rows[$j]->ordering = $i;
                        $temp = new stdClass();
                        $temp = $rows[$j];
                        $rows[$j] = $rows[$i];
                        $rows[$i] = $temp;
                        break;
                    }
                    $j++;
                }
            }
            $i++;
        }
    }
    //Leading Courses - Blog parametrs
    $tmp_rows = $rows;
    $rows = array();
    for ($i = $pageNav->limitstart; $i < $pageNav->limitstart + $pageNav->limit; $i++) {
        if (isset($tmp_rows[$i]) && $tmp_rows[$i]->id) {
            $rows[] = $tmp_rows[$i];
        }
    }
    //$lists = array();
    $lists['homepage_text'] = $JLMS_CONFIG->get('frontpage_text');
    JLMS_ShowHeading($JLMS_CONFIG->get('jlms_heading'), false);
    $lms_titles_cache =& JLMSFactory::getTitles();
    $lms_titles_cache->setArray('courses', $rows, 'id', 'course_name');
    if ($menu_params->get('blog', 0)) {
        joomla_lms_html::showCoursesForGuest_blog($option, $lists, $rows, $pageNav, $enrollment);
    } else {
        joomla_lms_html::showCoursesForGuest($option, $lists, $rows, $pageNav, $enrollment);
    }
}
 function JQ_FinishQuiz($quiz_id, $stu_quiz_id, $user_unique_id, $id)
 {
     global $JLMS_DB, $my, $Itemid, $JLMS_CONFIG;
     $ret_str = '';
     require_once dirname(__FILE__) . '/ajax_quiz.class.php';
     $query = "SELECT * FROM #__lms_quiz_t_quiz WHERE c_id = '" . $quiz_id . "'";
     $JLMS_DB->SetQuery($query);
     $quiz = $JLMS_DB->LoadObjectList();
     if (count($quiz)) {
         $quiz = $quiz[0];
     } else {
         return $ret_str;
     }
     $quiz_params = new JLMSParameters($quiz->params);
     $inside_lp = intval(mosGetParam($_REQUEST, 'inside_lp', 0));
     $QA = new JLMS_quiz_API($quiz_id, $inside_lp);
     if (!$QA->quiz_valid()) {
         return '';
     }
     $toolbar_no_a = $QA->quiz_Get_NoAtToolbar();
     $QA->set('stu_quiz_id', $stu_quiz_id);
     $QA->set('user_unique_id', $user_unique_id);
     $QA->quiz_ProcessStartData();
     if ($QA->start_valid() && $quiz_id) {
         $query = "SELECT SUM(c_score) FROM #__lms_quiz_r_student_question WHERE c_stu_quiz_id = '" . $stu_quiz_id . "'";
         $JLMS_DB->SetQuery($query);
         $user_score = $JLMS_DB->LoadResult();
         if (!$user_score) {
             $user_score = 0;
         }
         $max_score = $QA->quiz_Get_MaxScore();
         $nugno_score = $QA->get_qvar('c_passing_score', 0) * $max_score / 100;
         $user_passed = 0;
         if ($user_score >= $nugno_score) {
             $user_passed = 1;
         }
         $user_time = 0;
         $quiz_time1 = time() - date('Z');
         $query = "SELECT c_date_time FROM #__lms_quiz_r_student_quiz WHERE c_id = '" . $stu_quiz_id . "'";
         $JLMS_DB->SetQuery($query);
         $quiz_time2 = $JLMS_DB->LoadResult();
         $quiz_time2a = strtotime($quiz_time2);
         $user_time = $quiz_time1 - $quiz_time2a;
         $query = "SELECT c_total_score, c_passed, c_total_time FROM #__lms_quiz_r_student_quiz WHERE c_id = '" . $stu_quiz_id . "' and c_quiz_id = '" . $quiz_id . "' and c_student_id = '" . $my->id . "'";
         $JLMS_DB->SetQuery($query);
         $user_quiz_results_obj = $JLMS_DB->LoadObject();
         if (is_object($user_quiz_results_obj)) {
             $user_score = $user_quiz_results_obj->c_total_score;
             $user_passed = $user_quiz_results_obj->c_passed;
             $user_time = $user_quiz_results_obj->c_total_time;
         }
         // update lms results
         $lms_course = $QA->get_qvar('course_id', 0);
         $lms_quiz = $quiz_id;
         $lms_user = $my->id;
         $lms_score = $user_score;
         $lms_time = $user_time;
         $lms_date = date('Y-m-d H:i:s', time() - date('Z'));
         //the same as gmdate
         $lms_passed = $user_passed;
         global $JLMS_CONFIG;
         if ($lms_course && $JLMS_CONFIG->get('course_id') == $lms_course) {
             $course_params = $JLMS_CONFIG->get('course_params');
             $params = new JLMSParameters($course_params);
             $do_insert_new_res = false;
             if ($params->get('track_type', 0) == 1) {
                 $query = "SELECT * FROM #__lms_quiz_results WHERE course_id = '" . $lms_course . "' AND quiz_id = '" . $lms_quiz . "' AND user_id = '" . $lms_user . "'";
                 $JLMS_DB->SetQuery($query);
                 $old_user_results = $JLMS_DB->LoadObject();
                 if (is_object($old_user_results)) {
                     if (!$lms_passed && !$old_user_results->user_passed && $lms_score > $old_user_results->user_score) {
                         $do_insert_new_res = true;
                     } elseif ($lms_passed && !$old_user_results->user_passed) {
                         $do_insert_new_res = true;
                     } elseif ($lms_passed && $old_user_results->user_passed && $lms_score > $old_user_results->user_score) {
                         $do_insert_new_res = true;
                     } elseif ($lms_passed && $old_user_results->user_passed && $lms_score == $old_user_results->user_score && $lms_time < $old_user_results->user_time) {
                         $do_insert_new_res = true;
                     }
                 } else {
                     $do_insert_new_res = true;
                 }
             } else {
                 $do_insert_new_res = true;
             }
             if ($do_insert_new_res) {
                 $query = "DELETE FROM #__lms_quiz_results WHERE course_id = '" . $lms_course . "' AND quiz_id = '" . $lms_quiz . "' AND user_id = '" . $lms_user . "'";
                 $JLMS_DB->SetQuery($query);
                 $JLMS_DB->query();
                 $query = "INSERT INTO #__lms_quiz_results (course_id, quiz_id, user_id, user_score, quiz_max_score, user_time, quiz_date, user_passed)" . "\n VALUES ('" . $lms_course . "', '" . $lms_quiz . "', '" . $lms_user . "', '" . $lms_score . "', " . intval($max_score) . ", '" . $lms_time . "', '" . $lms_date . "', '" . $lms_passed . "')";
                 $JLMS_DB->SetQuery($query);
                 $JLMS_DB->query();
             }
         }
         // end of lms results section
         $cur_tmpl = 'joomlaquiz_lms_template';
         if ($cur_tmpl) {
             require_once dirname(__FILE__) . '/templates/' . $cur_tmpl . '/jq_template.php';
             global $JLMS_LANGUAGE, $JLMS_CONFIG;
             JLMS_require_lang($JLMS_LANGUAGE, 'quiz.lang', $JLMS_CONFIG->get('default_language'));
             require _JOOMLMS_FRONT_HOME . '/includes/quiz/quiz_language.php';
             global $jq_language;
             #$ret_str .= "\t" . '<task>results</task>' . "\n";
             $eee = $jq_language['quiz_header_fin_message'];
             #$ret_str .= "\t" . '<finish_msg><![CDATA[';
             if ($user_passed) {
                 if ($QA->get_qvar('c_pass_message', '')) {
                     $jq_language['quiz_user_passes'] = nl2br($QA->get_qvar('c_pass_message', ''));
                 }
             } else {
                 if ($QA->get_qvar('c_unpass_message', '')) {
                     $jq_language['quiz_user_fails'] = nl2br($QA->get_qvar('c_unpass_message', ''));
                 }
             }
             #$ret_str .= ']]></finish_msg>' . "\n";
             $t_ar = array();
             $t_ar[] = mosHTML::makeOption($user_score . " of " . $max_score, $jq_language['quiz_res_mes_score']);
             $t_ar[] = mosHTML::makeOption($nugno_score ? $nugno_score . " (" . $QA->get_qvar('c_passing_score', 0) . "%)" : '', $jq_language['quiz_res_mes_pas_score']);
             $tot_hour = floor($user_time / 3600);
             if ($tot_hour) {
                 $tot_min = floor(($user_time - $tot_hour * 3600) / 60);
                 $tot_sec = $user_time - $tot_hour * 3600 - $tot_min * 60;
                 $tot_time = str_pad($tot_hour, 2, "0", STR_PAD_LEFT) . ":" . str_pad($tot_min, 2, "0", STR_PAD_LEFT) . ":" . str_pad($tot_sec, 2, "0", STR_PAD_LEFT);
             } else {
                 $tot_min = floor($user_time / 60);
                 $tot_sec = $user_time - $tot_min * 60;
                 $tot_time = str_pad($tot_min, 2, "0", STR_PAD_LEFT) . ":" . str_pad($tot_sec, 2, "0", STR_PAD_LEFT);
             }
             $t_ar[] = mosHTML::makeOption($tot_time, $jq_language['quiz_res_mes_time']);
             if ($quiz_params->get('sh_final_page_text', 1) == 1) {
                 $results_txt = JoomlaQuiz_template_class::JQ_show_results($jq_language['quiz_header_fin_results'], $t_ar);
             } else {
                 $results_txt = '';
             }
             $footer_ar = array();
             $footer_ar[] = mosHTML::makeOption(0, $jq_language['quiz_fin_btn_review']);
             $footer_ar[] = mosHTML::makeOption(1, $jq_language['quiz_fin_btn_print']);
             $footer_ar[] = mosHTML::makeOption(2, $jq_language['quiz_fin_btn_certificate']);
             $footer_ar[] = mosHTML::makeOption(3, $jq_language['quiz_fin_btn_email']);
             $toolbar_fotter = array();
             if ($QA->get_qvar('c_certificate', 0) && $user_passed) {
                 $link_inside_1 = ampReplace($JLMS_CONFIG->get('live_site') . '/index.php?tmpl=component&option=com_joomla_lms&Itemid=' . $Itemid . '&no_html=1&task=print_quiz_cert&course_id=' . $lms_course . '&stu_quiz_id=' . $stu_quiz_id . '&user_unique_id=' . $user_unique_id);
                 $btn_certificate = 'window.open(\'' . $link_inside_1 . '\',\'blank\');';
                 $footer_ar[2]->text = "<div class='back_button'><a href='javascript:void(0)' onclick=\"window.open ('" . $JLMS_CONFIG->get('live_site') . "/index.php?tmpl=component&option=com_joomla_lms&Itemid=" . $Itemid . "&no_html=1&task=print_quiz_cert&course_id=" . $lms_course . "&stu_quiz_id=" . $stu_quiz_id . "&user_unique_id=" . $user_unique_id . "','blank');\">" . $jq_language['quiz_fin_btn_certificate'] . "</a></div>";
                 $toolbar_footer[2] = array('btn_type' => 'certificate_fbar', 'btn_js' => $btn_certificate);
             }
             if ($QA->get_qvar('c_enable_print', 0)) {
                 $link_inside_2 = ampReplace($JLMS_CONFIG->get('live_site') . '/index.php?tmpl=component&option=com_joomla_lms&Itemid=' . $Itemid . '&no_html=1&task=print_quiz_result&course_id=' . $lms_course . '&stu_quiz_id=' . $stu_quiz_id . '&user_unique_id=');
                 $btn_print = 'window.open(\'' . $link_inside_2 . '\'+user_unique_id,\'blank\');';
                 $footer_ar[1]->text = "<div class='back_button'><a href='javascript:void(0)' onclick=\"window.open ('" . $JLMS_CONFIG->get('live_site') . "/index.php?tmpl=component&option=com_joomla_lms&Itemid=" . $Itemid . "&no_html=1&task=print_quiz_result&course_id=" . $lms_course . "&stu_quiz_id=" . $stu_quiz_id . "&user_unique_id=' + user_unique_id,'blank');\">" . $jq_language['quiz_fin_btn_print'] . "</a></div>";
                 $toolbar_footer[1] = array('btn_type' => 'print_fbar', 'btn_js' => $btn_print);
             }
             if ($QA->get_qvar('c_email_to', 0)) {
                 $btn_email_to = 'jq_emailResults();';
                 $footer_ar[3]->text = "<div class='back_button'><a href='javascript:void(0)' onclick=\"jq_emailResults();\">" . $jq_language['quiz_fin_btn_email'] . "</a></div>";
                 $toolbar_footer[3] = array('btn_type' => 'email_to_fbar', 'btn_js' => $btn_email_to);
             }
             if ($QA->get_qvar('c_enable_review', 0)) {
                 $btn_review = 'jq_startReview();';
                 $query = "UPDATE #__lms_quiz_r_student_quiz SET allow_review = 1 WHERE c_id = '" . $stu_quiz_id . "' and c_quiz_id = '" . $quiz_id . "' and c_student_id = '" . $my->id . "'";
                 $JLMS_DB->SetQuery($query);
                 $JLMS_DB->query();
                 $footer_ar[0]->text = "<div class='back_button'><a href='javascript:void(0)' onclick=\"jq_startReview();\">" . $jq_language['quiz_fin_btn_review'] . "</a></div>";
                 $toolbar_footer[0] = array('btn_type' => 'review_fbar', 'btn_js' => $btn_review);
             }
             $footer_html_graf = '';
             if ($quiz_params->get('sh_final_page_grafic', 0) == 1) {
                 ////----barss----////
                 $is_pool = 0;
                 if ($quiz_id == -1 || $quiz_id == 0) {
                     $is_pool = 1;
                     $quiz_id = 0;
                 }
                 $rows = $QA->quiz_Get_QuestionList();
                 // 18 August 2007 - changes (DEN) - added check for GD and FreeType support
                 $generate_images = true;
                 $msg = '';
                 if (!function_exists('imageftbbox') || !function_exists('imagecreatetruecolor')) {
                     $generate_images = false;
                     $sec = false;
                     if (!function_exists('imagecreatetruecolor')) {
                         $msg = 'This function requires GD 2.0.1 or later (2.0.28 or later is recommended).';
                         $sec = true;
                     }
                     if (!function_exists('imageftbbox')) {
                         $msg .= ($sec ? '<br />' : '') . 'This function is only available if PHP is compiled with freetype support.';
                     }
                 }
                 // end of GD and FreeType support check
                 if ($JLMS_CONFIG->get('temp_folder', '') && $generate_images) {
                     // temp folder setup is ready.
                     //--------- array of bar-images
                     $img_arr = array();
                     $title_arr = array();
                     $count_graph = array();
                     global $option;
                     for ($i = 0, $n = count($rows); $i < $n; $i++) {
                         $row = $rows[$i];
                         $quest_params = new JLMSParameters($row->params);
                         $z = 1;
                         if (isset($row->c_pool) && $row->c_pool) {
                             $row->c_pool_id = $row->c_pool;
                         } else {
                             $row->c_pool_id = $row->c_id;
                         }
                         $show_case = true;
                         //					if($showtype_id && !$quest_params->get('survey_question'))
                         if (false && !$quest_params->get('survey_question')) {
                             $show_case = false;
                         }
                         if ($show_case) {
                             require_once _JOOMLMS_FRONT_HOME . "/includes/libraries/lms.lib.graph.php";
                             $group_id = 0;
                             $str_user_in_groups = '';
                             $c_question_id = $row->c_pool_id;
                             $obj_GraphStat = JLMS_GraphStatistics($option, $id, $quiz_id, $i, $z, $row, $c_question_id, $group_id, $str_user_in_groups);
                             foreach ($obj_GraphStat as $key => $item) {
                                 if (preg_match_all('#([a-z]+)_(\\w+)#', $key, $out, PREG_PATTERN_ORDER)) {
                                     if ($out[1][0] == 'img') {
                                         $img_arr[$i]->{$out}[2][0] = $item;
                                     } else {
                                         if ($out[1][0] == 'title') {
                                             $title_arr[$i]->{$out}[2][0] = $item;
                                         } else {
                                             if ($out[1][0] == 'count') {
                                                 $count_graph[$i]->{$out}[2][0] = $item;
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
                 $footer_html_graf = JoomlaQuiz_template_class::JQ_show_results_footer_content_bars($img_arr, $title_arr, $count_graph, $id);
             }
             $ret_str .= $results_txt;
             // this filed shouldn't be a null - null caused errors in Safari
             if ($quiz_params->get('sh_final_page_fdbck', 1) == 1) {
                 $ret_str .= '<br />';
                 $ret_str .= JoomlaQuiz_template_class::JQ_show_results_msg($eee, $user_passed ? $jq_language['quiz_user_passes'] : $jq_language['quiz_user_fails'], $user_passed);
                 $ret_str .= '<br />';
             } else {
                 $ret_str .= '<br />';
             }
             if (isset($toolbar_footer) && count($toolbar_footer) > 0) {
                 ksort($toolbar_footer);
                 $footer_html = JLMS_ShowToolbar($toolbar_footer, false, 'center');
                 $footer_html = str_replace('"components/com_joomla_lms', '"' . $JLMS_CONFIG->get('live_site') . '/components/com_joomla_lms', $footer_html);
             } else {
                 $footer_html = '';
             }
             $entire_footer_data = $footer_html . ($footer_html_graf ? '<br />' . $footer_html_graf : '');
             $ret_str .= $entire_footer_data ? $entire_footer_data : ' ';
         }
     }
     return $ret_str;
 }
Esempio n. 19
0
function JLMS_playerSCORM($id, $option)
{
    global $JLMS_DB, $my, $JLMS_CONFIG, $Itemid, $JLMS_SESSION;
    $course_id = $JLMS_CONFIG->get('course_id');
    $usertype = $JLMS_CONFIG->get('current_usertype', 0);
    $lpath_id = intval(mosGetParam($_REQUEST, 'lpath_id', 0));
    $int_skip_resume = intval(mosGetParam($_REQUEST, 'int_skip_resume', 0));
    $scorm = null;
    //new stdClass();
    if ($course_id && ($usertype == 1 || $usertype == 2) && JLMS_CheckSCORM($id, $lpath_id, $course_id, $scorm, $usertype)) {
        if (!empty($scorm)) {
            // 11.04.2007 (parameter 'redirect_to_learnpath' used to avoid redirect cycles from course home to LP and back
            $JLMS_SESSION->clear('redirect_to_learnpath');
            // sleep one second. SCORM could send some requests on onCloasPage event. We need wait for these requests to be processed.
            #sleep(2);
            $scoid = intval(mosGetParam($_REQUEST, 'scoid', 0));
            $mode = 'normal';
            //strval(mosGetParam($_REQUEST, 'mode','normal'));//optional_param('mode', 'normal', PARAM_ALPHA);
            $currentorg = strval(mosGetParam($_REQUEST, 'currentorg', ''));
            //, PARAM_RAW);
            $newattempt = strval(mosGetParam($_REQUEST, 'newattempt', 'on'));
            require_once _JOOMLMS_FRONT_HOME . "/includes/n_scorm/lms_scorm.play.php";
            $query = "SELECT * FROM #__lms_learn_paths WHERE id = '" . $lpath_id . "' AND course_id = '" . $course_id . "'";
            $JLMS_DB->SetQuery($query);
            $lpath_data = $JLMS_DB->LoadObjectList();
            $box_view = false;
            if (count($lpath_data) == 1) {
                $pathway = array();
                $pathway[] = array('name' => $lpath_data[0]->lpath_name, 'link' => sefRelToAbs("index.php?option={$option}&amp;Itemid={$Itemid}&amp;task=player_scorm&amp;id={$id}&amp;course_id={$course_id}&amp;lpath_id=" . $lpath_data[0]->id));
                JLMSAppendPathWay($pathway);
            }
            if (isset($scorm->params)) {
                $params = new JLMSParameters($scorm->params);
                if ($params->get('scorm_layout', 0) && $params->get('scorm_layout', 0) == 1) {
                    $box_view = true;
                }
            }
            if ($box_view) {
                // SqueezeBox view - don't show Heading.
                echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
                echo '<html xmlns="http://www.w3.org/1999/xhtml" style="margin:0;padding:0"><head>';
                $iso_site = 'charset=utf-8';
                if (defined('_ISO')) {
                    $iso_site = _ISO;
                    if (!$iso_site) {
                        $iso_site = 'charset=utf-8';
                    }
                }
                echo '<meta http-equiv="Content-Type" content="text/html; ' . $iso_site . '" />';
                echo '</head><body style="margin:0;padding:0">';
            } else {
                JLMS_ShowHeading();
            }
            /*JLMS_TMPL::OpenMT();
            
            			$hparams = array();
            			JLMS_TMPL::ShowHeader('scorm', $scorm->scorm_name, $hparams);
            */
            $skip_resume = $int_skip_resume ? true : false;
            JLMS_SCORM_PLAY_MAIN($scorm, $option, $course_id, $lpath_id, $scoid, $mode, $currentorg, $newattempt, false, false, $box_view, $skip_resume);
            if ($box_view) {
                echo '</body></html>';
                JLMS_die();
            }
            //JLMS_TMPL::CloseMT();
        } else {
            JLMSRedirect(sefRelToAbs("index.php?option={$option}&Itemid={$Itemid}&task=learnpaths&id={$course_id}"));
        }
    } else {
        JLMSRedirect(sefRelToAbs("index.php?option={$option}&Itemid={$Itemid}&task=learnpaths&id={$course_id}"));
    }
}
    function showLPath_MainPage($course_id, $lpath_id, $option, &$lpath_data, &$lpath_contents, &$quizzes_data)
    {
        $JLMS_CONFIG =& JLMSFactory::getConfig();
        $Itemid = $JLMS_CONFIG->get('Itemid');
        $lp_params = new JLMSParameters($lpath_data->lp_params);
        $show_lpath_contents_at_the_left = $lp_params->get('navigation_type', 0) ? true : false;
        $is_quiz = count($quizzes_data) ? true : false;
        $is_drag_drop = false;
        $c_time_limit = 0;
        $inside_lp = 1;
        $c_slide = false;
        //pri starte quiza
        $c_generated_panel = true;
        // Contents of quiz will be generated on 'satrt' action
        $c_slide_update = false;
        $quiz_id = 0;
        foreach ($quizzes_data as $qd) {
            $quiz_id = $qd->c_id;
            foreach ($qd->panel_data as $q) {
                if ($q->c_type == 4) {
                    $is_drag_drop = true;
                    break;
                }
            }
        }
        require_once _JOOMLMS_FRONT_HOME . "/includes/ajax_features.class.php";
        // preloading QUIZ languge (28.02.2007 new method) (all quizzes messages now in global quiz language)
        global $JLMS_LANGUAGE;
        JLMS_require_lang($JLMS_LANGUAGE, 'quiz.lang', $JLMS_CONFIG->get('default_language'));
        require dirname(__FILE__) . '/includes/quiz/quiz_language.php';
        global $jq_language;
        $e = true;
        // enable force echo
        $AF = new JLMS_Ajax_Features();
        $AF->set('c_slide', $c_slide);
        $AF->set('c_generated_panel', $c_generated_panel);
        $AF->set('c_slide_update', $c_slide_update);
        $AF->set('quiz_id', $quiz_id);
        if ($is_quiz) {
            $AF->GetInclude_Msgs($e);
        }
        $AF->JS_open($e);
        $AF->GetFunc_JS_in_array($e);
        $AF->GetFunc_RFE($e);
        if ($is_quiz) {
            $document =& JFactory::getDocument();
            $document->addStyleSheet($JLMS_CONFIG->getCfg('live_site') . '/components/com_joomla_lms/includes/quiz/templates/joomlaquiz_lms_template/jq_template.css');
            echo "function jlms_gotoQuestion(qid) { if (stu_step_type == 5 && user_unique_id && quiz_id) { jlms_SwitchOpenedContents();JQ_gotoQuestionOn(qid);} }";
            $AF->QUIZ_JS_DrDr_Code($e);
            $AF->QUIZ_preloadMsgs($e, $jq_language);
            $AF->QUIZ_doInitialize($e, $JLMS_CONFIG->getCfg('live_site') . "/index.php?tmpl=component&option={$option}&inside_lp={$inside_lp}&Itemid={$Itemid}&jlms=1&task=quiz_ajax_action&id={$course_id}", '');
            /* We must override this func (to reduce JS weigth)
            			$AF->QUIZ_MakeRequest($e); */
            ?>
function jq_MakeRequest(url, do_clear) {
	if (do_clear == 1) {
		jq_showLoading();
	}
	quiz_blocked == 1;
	jlms_MakeRequest('jq_AnalizeRequest', url, 'quiz');
}			
<?php 
            $req_tasks = array('start', 'seek_quest', 'review_start', 'review_next', 'review_finish', 'next', 'no_attempts', 'email_results', 'time_is_up', 'finish', 'results', 'failed');
            $AF->QUIZ_AnalizeRequest($e, 'jq_AnalizeRequest', $req_tasks);
            $AF->QUIZ_releaseblock($e);
            $AF->QUIZ_StartTickTack($e);
            $AF->QUIZ_ContinueTickTack($e);
            //$AF->QUIZ_StartQuizOn($e);
            $AF->QUIZ_StartQuizOn($e);
            $AF->QUIZ_StartQuiz($e);
            $AF->QUIZ_GoToQuestionOn($e);
            $AF->QUIZ_GoToQuestion($e);
            $AF->QUIZ_EmailResults($e);
            $AF->QUIZ_StartReview($e);
            $AF->QUIZ_ReviewNext($e);
            $AF->QUIZ_ReviewPrev($e);
            $AF->QUIZ_Check_selectRadio($e);
            $AF->QUIZ_Check_selectCheckbox($e);
            $AF->QUIZ_Check_valueItem($e);
            $AF->QUIZ_QuizNextOn($e);
            $toolbar = array();
            $toolbar[] = array('btn_type' => 'quiz_ok', 'btn_js' => "javascript:jq_QuizNextOn(); void(0);");
            if ($inside_lp && !$show_lpath_contents_at_the_left) {
                $toolbar[] = array('btn_type' => 'contents', 'btn_js' => "javascript:ajax_action('contents_lpath');");
            } else {
                if ($c_slide && !$show_lpath_contents_at_the_left) {
                    $toolbar[] = array('btn_type' => 'contents', 'btn_js' => "javascript:jq_ShowPanel();");
                }
            }
            $m_str_no_skip = JLMS_ShowToolbar($toolbar);
            //8.10.08 - (Max) - dva toolbars dlia skip i standart
            $toolbar = array();
            $toolbar[] = array('btn_type' => 'quiz_ok', 'btn_js' => "javascript:jq_QuizNextOn(); void(0);");
            $toolbar[] = array('btn_type' => 'skip', 'btn_js' => "javascript:JQ_gotoQuestion(__skip__);void(0);");
            if ($inside_lp && !$show_lpath_contents_at_the_left) {
                $toolbar[] = array('btn_type' => 'contents', 'btn_js' => "javascript:ajax_action('contents_lpath');");
            } else {
                if ($c_slide && !$show_lpath_contents_at_the_left) {
                    $toolbar[] = array('btn_type' => 'contents', 'btn_js' => "javascript:jq_ShowPanel();");
                }
            }
            $m_str_skip = JLMS_ShowToolbar($toolbar);
            $AF->QUIZ_QuizContinue($e, $m_str_no_skip, $m_str_skip);
            $cf_url = "'&atask=finish_stop&quiz='+quiz_id+'&stu_quiz_id='+stu_quiz_id";
            $AF->QUIZ_QuizContinueFinish($e, $cf_url);
            $toolbar = array();
            $toolbar[] = array('btn_type' => 'quiz_ok', 'btn_js' => "javascript:jq_QuizNextOn(); void(0);");
            if ($inside_lp && !$show_lpath_contents_at_the_left) {
                $toolbar[] = array('btn_type' => 'contents', 'btn_js' => "javascript:ajax_action('contents_lpath');");
            } else {
                if ($c_slide && !$show_lpath_contents_at_the_left) {
                    $toolbar[] = array('btn_type' => 'contents', 'btn_js' => "javascript:jq_ShowPanel();");
                }
            }
            $m_str = JLMS_ShowToolbar($toolbar);
            $AF->QUIZ_QuizBack($e, $m_str);
            $AF->QUIZ_Next($e);
            $AF->QUIZ_showLoading($e);
            /*
            			$AF->QUIZ_UpdateTaskDiv_htm($e);
            			$AF->QUIZ_UpdateTaskDiv($e, $c_slide);*/
            // We must override task div functionality for quiz
            ?>
function jq_UpdateTaskDiv_htm(htm_txt) {
	getObj('jlms_lpath_menu').innerHTML = htm_txt;
}
function jq_UpdateTaskDiv(task) {

	switch (task) {
		case 'start':
			getObj('jlms_lpath_menu').innerHTML = jq_StartButton('jq_StartQuizOn()', mes_quiz_start);
		break;
		case 'next':
			getObj('jq_quest_num_container').innerHTML = mes_quest_number.replace("{X}", cur_quest_num).replace("{Y}", quiz_count_quests);
			getObj('jq_quest_num_container').style.visibility = "visible";
			getObj('jq_points_container').innerHTML = mes_quest_points.replace("{X}", cur_quest_score);
			getObj('jq_points_container').style.visibility = "visible";
			<?php 
            if ($JLMS_CONFIG->get('quiz_progressbar', 0) == 1) {
                ?>
			if (getObj('progress_bar')) { getObj('progress_bar').style.display = "block"; }
			<?php 
            }
            ?>
		break;
		case 'review_next':
			getObj('jq_quest_num_container').innerHTML = mes_quest_number.replace("{X}", cur_quest_num).replace("{Y}", quiz_count_quests);
			getObj('jq_quest_num_container').style.visibility = "visible";
			getObj('jq_points_container').innerHTML = mes_quest_points.replace("{X}", cur_quest_score);
			getObj('jq_points_container').style.visibility = "visible";
		break;
		case 'continue':
			<?php 
            if ($JLMS_CONFIG->get('quiz_progressbar', 0) == 1) {
                ?>
			if (getObj('progress_bar')) { getObj('progress_bar').style.display = "block"; }
			<?php 
            }
            ?>
		break;
		case 'continue_finish':
			<?php 
            if ($JLMS_CONFIG->get('quiz_progressbar', 0) == 1) {
                ?>
			if (getObj('progress_bar')) { getObj('progress_bar').style.display = "block"; }
			<?php 
            }
            ?>
		break;
		case 'finish':
			getObj('jlms_lpath_menu').innerHTML = lp_menu_item_contents;
			getObj('jq_quest_num_container').style.visibility = 'hidden';
			getObj('jq_points_container').style.visibility = 'hidden';
			<?php 
            if ($JLMS_CONFIG->get('quiz_progressbar', 0) == 1) {
                ?>
			if (getObj('progress_bar')) { getObj('progress_bar').style.display = "none"; }
			<?php 
            }
            ?>
		break;
		case 'clear':
			getObj('jlms_lpath_menu').innerHTML = '';
			getObj('jq_quest_num_container').style.visibility = 'hidden';
			getObj('jq_points_container').style.visibility = 'hidden';
		break;
	}
<?php 
            if ($c_slide) {
                ?>
	
	if (result_is_shown == 1) { jq_ShowPanel(); }
<?php 
            }
            ?>
}
<?php 
            $AF->QUIZ_NextButton($e);
            $AF->QUIZ_ContinueButton($e);
            $AF->QUIZ_StartButton($e);
            $AF->QUIZ_BackButton($e);
            if ($c_slide) {
                $AF->QUIZ_ShowPanel_go($e);
                $AF->QUIZ_HidePanel_go($e);
                $AF->QUIZ_ShowPanel($e);
            }
        }
        $AF->GetFunc_JS_URLencode($e);
        $AF->GetFunc_JS_TRIM_str($e);
        $AF->JS_close($e);
        $lpc_btn = $AF->Get_LPContents_btn(false);
        $toolbar = array();
        $toolbar[] = array('btn_type' => 'next', 'btn_js' => "javascript:ajax_action('next_lpathstep');");
        if (!$show_lpath_contents_at_the_left) {
            $toolbar[] = array('btn_type' => 'contents', 'btn_js' => "javascript:ajax_action('contents_lpath');");
        }
        $rs = JLMS_ShowToolbar($toolbar);
        $rs = str_replace('"components/com_joomla_lms', '"' . $JLMS_CONFIG->getCfg('live_site') . '/components/com_joomla_lms', $rs);
        $lpc_btn = str_replace('/', '\\/', str_replace('"', "\\\"", $rs));
        ?>
<script language="javascript" type="text/javascript">
<!--//--><![CDATA[//><!--
var timer_KeepAL = 990066;
<?php 
        /* variable timer_keepAl was added 21.08.2007 - for keeping joomla session whilst SCORM playing */
        ?>
var lp_menu_item_contents = "<?php 
        echo $lpc_btn;
        ?>
";
var jlms_contents_visible = 0;
var jlms_contents_visible_only = 0;
var jlms_lpath = <?php 
        echo $lpath_id;
        ?>
;
var jlms_course = <?php 
        echo $course_id;
        ?>
;
function ajax_action(pressbutton) {
	if ((jlms_blocked == 1) && (pressbutton != 'contents_lpath') && (pressbutton != 'get_document')) {
		if (jlms_allow_pending_task == 1) {
			if (jlms_is_pending_task == 0) {
				jlms_is_pending_task = 1;
				jlms_pending_task = pressbutton;
			}
		}
	} else {
		jlms_blocked = 1;
		if ((pressbutton != 'contents_lpath') && (pressbutton != 'get_document')) {
			$('jlms_lpath_completion_msg_container').setStyles({visibility: 'hidden',display: 'none'});
		}
		switch (pressbutton) {
			case 'lpath_restart':
<?php 
        if (!$show_lpath_contents_at_the_left) {
            ?>
				jlms_SwitchOpenedContents();
<?php 
        }
        ?>
				jlms_MakeRequest('jlms_AnalizeRequest', '&action=restart_lpath&id='+jlms_lpath, 'lpath');
			break;
			case 'start_lpath':
<?php 
        if (!$show_lpath_contents_at_the_left) {
            ?>
				jlms_SwitchOpenedContents();
<?php 
        }
        ?>
				jlms_MakeRequest('jlms_AnalizeRequest', '&action=start_lpath&id='+jlms_lpath, 'lpath');
			break;
			case 'next_lpathstep':
<?php 
        if (!$show_lpath_contents_at_the_left) {
            ?>
				jlms_SwitchOpenedContents();
<?php 
        }
        ?>
				jlms_MakeRequest('jlms_AnalizeRequest', '&action=next_lpathstep&id='+jlms_lpath+'&step_id='+stu_step_id, 'lpath');
			break;
			case 'prev_lpathstep':
<?php 
        if (!$show_lpath_contents_at_the_left) {
            ?>
				jlms_SwitchOpenedContents();
<?php 
        }
        ?>
				jlms_MakeRequest('jlms_AnalizeRequest', '&action=prev_lpathstep&id='+jlms_lpath+'&step_id='+stu_step_id, 'lpath');
			break;
			case 'lpath_seek':
<?php 
        if (!$show_lpath_contents_at_the_left) {
            ?>
				jlms_SwitchOpenedContents();
<?php 
        }
        ?>
				jlms_MakeRequest('jlms_AnalizeRequest', '&action=seek_lpathstep&id='+jlms_lpath+'&step_id='+seek_step_id, 'lpath');
			break;
			case 'contents_lpath':
				jlms_blocked = 0;
<?php 
        if (!$show_lpath_contents_at_the_left) {
            ?>
				jlms_SwitchContents();
<?php 
        } else {
            ?>
				jlms_SwitchContents2();
<?php 
        }
        ?>
			break;
			case 'get_document':
				jlms_blocked = 0;
				/*window.open('index.php?tmpl=component&no_html=1&option=<?php 
        echo $option;
        ?>
&Itemid=<?php 
        echo $Itemid;
        ?>
&task=show_lpath&action=get_lpath_doc&user_unique_id=' + user_unique_id +'&user_start_id='+user_start_id+'&id='+jlms_lpath+'&course_id='+jlms_course+'&doc_id='+get_doc_id+'&step_id='+stu_step_id
				,null,"height=200,width=400,status=yes,toolbar=no,menubar=no,location=no");*/
				window.location.href = '<?php 
        echo $JLMS_CONFIG->getCfg('live_site');
        ?>
/index.php?tmpl=component&no_html=1&option=<?php 
        echo $option;
        ?>
&Itemid=<?php 
        echo $Itemid;
        ?>
&task=show_lpath&action=get_lpath_doc&user_unique_id=' + lp_user_unique_id +'&user_start_id='+user_start_id+'&id='+jlms_lpath+'&course_id='+jlms_course+'&doc_id='+get_doc_id+'&step_id='+stu_step_id;
				//return true;
				void(0);
			break;
			default:
				jlms_blocked = 0;
			break;
		}
	}
}
<?php 
        if (JLMS_mootools12()) {
            $fxFunc = 'Tween';
        } else {
            $fxFunc = 'Style';
        }
        $additon_js = '
var mySlide_contents2;
var mySlide_contents2_width_start = 0;
var mySlide_contents2_width_end = 0;
var mySlide_contents3;
var mySlide_contents2_mode = 2;
var mySlide_contents3_margin_start = 0;
var mySlide_contents3_margin_end = 10;
var mySlide_contents4;
var winScroller2 = new Fx.Scroll(window);
function jlms_prepare_el_mySlide_contents2() {
	mySlide_contents2 = new Fx.' . $fxFunc . '(\'jlms_lpath_contents_container\', \'width\');
	mySlide_contents2_width_start = $(\'jlms_lpath_contents_container\').getStyle(\'width\');
	mySlide_contents3_margin_start = $(\'jlms_lpath_descr\').getStyle(\'margin-left\');
	mySlide_contents3 = new Fx.' . $fxFunc . '(\'jlms_lpath_descr\', \'margin-left\');
	mySlide_contents4 = new Fx.' . $fxFunc . '(\'jlms_lpath_completion_msg_container\', \'margin-left\');
	$(\'jlms_lpath_completion_msg_container\').setStyles({\'margin-left\': \'0\'});
	$(\'jlms_lpath_descr\').setStyles({\'margin-left\': \'0\'});
	//mySlide_contents2.hide();
	//$(\'jlms_lpath_contents_container\').setStyles({visibility: \'visible\',display: \'\'});
}
function jlms_SwitchContents2() {
	if (mySlide_contents2_mode == 2) {
		$(\'jlms_lpath_contents_container\').setStyles({visibility: \'visible\',display: \'\'});
		mySlide_contents2.start(0, mySlide_contents2_width_start);
		mySlide_contents3.start(0, mySlide_contents3_margin_start);
		mySlide_contents4.start(0, mySlide_contents3_margin_start);
		mySlide_contents2_mode = 1;
		$(\'left_nav_collapser_container\').setStyles({visibility: \'visible\',display: \'\'});
	} else if (mySlide_contents2_mode == 1) {
		mySlide_contents2.start(mySlide_contents2_width_end);
		mySlide_contents3.start(mySlide_contents3_margin_end);
		mySlide_contents4.start(mySlide_contents3_margin_end);
		$(\'left_nav_collapser_container\').setStyles({visibility: \'hidden\',display: \'none\'});
		mySlide_contents2_mode = 0;
	} else {
		$(\'jlms_lpath_contents_container\').setStyles({visibility: \'visible\',display: \'\'});
		mySlide_contents2.start(mySlide_contents2_width_start);
		mySlide_contents3.start(mySlide_contents3_margin_start);
		mySlide_contents4.start(mySlide_contents3_margin_start);
		mySlide_contents2_mode = 1;
		$(\'left_nav_collapser_container\').setStyles({visibility: \'visible\',display: \'\'});
	}
}
';
        if (JLMS_mootools12()) {
            $setHTML = 'set(\'html\',';
        } else {
            $setHTML = 'setHTML(';
        }
        $JLMS_CONFIG->set('jlms_aditional_js_code', $JLMS_CONFIG->get('jlms_aditional_js_code', '') . $additon_js);
        $domready = '
jlms_prepare_el_mySlide_contents2();
';
        $JLMS_CONFIG->set('web20_domready_code', $JLMS_CONFIG->get('web20_domready_code', '') . $domready);
        ?>


<?php 
        if ($JLMS_CONFIG->get('web20_effects', true) && !$show_lpath_contents_at_the_left) {
            $additon_js = '
var mySlide_contents;
function jlms_prepare_el_mySlide_contents() {
	mySlide_contents = new Fx.Slide(\'jlms_lpath_contents_container\');
	mySlide_contents.hide();
	$(\'jlms_lpath_contents_container\').setStyles({visibility: \'visible\',display: \'\'});
}
';
            $JLMS_CONFIG->set('jlms_aditional_js_code', $JLMS_CONFIG->get('jlms_aditional_js_code', '') . $additon_js);
            $domready = '
jlms_prepare_el_mySlide_contents();
';
            $JLMS_CONFIG->set('web20_domready_code', $JLMS_CONFIG->get('web20_domready_code', '') . $domready);
            ?>

function jlms_SwitchOpenedContents() {
	if ($defined(mySlide_contents)) {
		var type = typeof mySlide_contents;
		if (type == 'object') {
			mySlide_contents.hide();
		}
	} else {
		jlms_prepare_el_mySlide_contents();
	}
}
function jlms_SwitchContentsOnly(par) {
	if (par == 'show') {
		mySlide_contents.slideIn();
	} else {
		mySlide_contents.hide();
	}
}
function jlms_SwitchContents() {
	mySlide_contents.toggle();
}
<?php 
        } elseif ($show_lpath_contents_at_the_left) {
            ?>
function jlms_SwitchOpenedContents() {
	jlms_SwitchContents();
}
function jlms_SwitchContentsOnly(par) {
	if (par == 'show') {
		if (jlms_contents_visible == 1) {
			
		} else {
			var vis_style1 = 'visible';
			var disp_style1 = '';
			var jlcc = getObj('jlms_lpath_contents_container');
			jlcc.style.visibility = vis_style1;
			jlcc.style.display = disp_style1;
		}
	}
}
function jlms_SwitchContents() {
	if (jlms_contents_visible == 1) {
		
	} else {
		var vis_style1 = 'visible';
		var disp_style1 = '';
		var vis_style2 = 'visible';
		var disp_style2 = '';
		var jlcc = getObj('jlms_lpath_contents_container');
		var jldc = getObj('jlms_lpath_descr');
		jlcc.style.visibility = vis_style1;
		jlcc.style.display = disp_style1;
		jldc.style.visibility = vis_style2;
		jldc.style.display = disp_style2;
		if (jlms_contents_visible == 1) { jlms_contents_visible = 0;}
		else { jlms_contents_visible = 1; }
	}
}
<?php 
        } else {
            ?>
function jlms_SwitchOpenedContents() {
	if (jlms_contents_visible == 1) {
		jlms_SwitchContents();
	}
}
function jlms_SwitchContentsOnly(par) {
	if (par == 'show') {
		var vis_style1 = 'visible';
		var disp_style1 = '';
	} else {
		var vis_style1 = 'hidden';
		var disp_style1 = 'none';
	}
	var jlcc = getObj('jlms_lpath_contents_container');
	jlcc.style.visibility = vis_style1;
	jlcc.style.display = disp_style1;
}
function jlms_SwitchContents() {
	var vis_style1 = 'visible';
	var disp_style1 = '';
	var vis_style2 = 'hidden';
	var disp_style2 = 'none';
	if (jlms_contents_visible == 1) {
		var vis_style2 = 'visible';
		var disp_style2 = '';
		var vis_style1 = 'hidden';
		var disp_style1 = 'none';
	}
	var jlcc = getObj('jlms_lpath_contents_container');
	var jldc = getObj('jlms_lpath_descr');
	jlcc.style.visibility = vis_style1;
	jlcc.style.display = disp_style1;
	jldc.style.visibility = vis_style2;
	jldc.style.display = disp_style2;
	if (jlms_contents_visible == 1) { jlms_contents_visible = 0;}
	else { jlms_contents_visible = 1; }
}
<?php 
        }
        ?>
function jlms_SwitchContentsOnly2(par) {
	if (par == 'show') {
		mySlide_contents2.slideIn();
	} else {
		mySlide_contents2.hide();
	}
}
var stu_step_id = 0;
var stu_last_cur_id = 0;
var stu_step_type = 0;
var jlms_blocked = 0;
var jlms_is_pending_task = 0;
var jlms_pending_task = '';
var jlms_allow_pending_task = 1;
var seek_step_id = 0;
var get_doc_id = 0;
var lp_url_prefix = '<?php 
        echo $JLMS_CONFIG->get('live_site');
        ?>
/index.php?option=<?php 
        echo $option;
        ?>
&Itemid=<?php 
        echo $Itemid;
        ?>
';
var lp_user_unique_id = '';
var user_start_id = 0;
var mCfg_live_site = '';
function jlms_MakeRequest(onstate, url, mr_type) {
	var http_request = false;
	if (window.ActiveXObject) { // IE
		try { http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try { http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	} else if (window.XMLHttpRequest) { // Mozilla, Safari,...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			http_request.overrideMimeType('text/xml');
		}
	}
	if (!http_request) {
		return false;
	}
	http_request.onreadystatechange = function() { eval(onstate+'(http_request);') };
	var lp_url_prefix2 = '';
	var post_target = '<?php 
        echo $JLMS_CONFIG->get('live_site');
        ?>
/index.php?jlms=1';
	if (mr_type == 'lpath') {
		jlms_blocked == 1;
		jlms_showLoading();
		lp_url_prefix2 = 'jlms=1&option=<?php 
        echo $option;
        ?>
&Itemid=<?php 
        echo $Itemid;
        ?>
&task=show_lpath&user_unique_id=' + lp_user_unique_id +'&user_start_id='+user_start_id+'&id='+jlms_lpath+'&course_id='+jlms_course;
		post_target = mCfg_live_site + lp_url_prefix;
	} else if (mr_type == 'quiz'){
		lp_url_prefix2 = 'user_unique_id=' + user_unique_id + '&lp_user_unique_id=' + lp_user_unique_id +'&user_start_id='+user_start_id+'&lpath_id='+jlms_lpath+'&step_id='+stu_step_id;
		post_target = mCfg_live_site + url_prefix;
	}
	//http_request.open('GET', mCfg_live_site + lp_url_prefix + lp_url_prefix2 + url, true);
	//http_request.send(null);
	http_request.open("POST", post_target, false);
	http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http_request.setRequestHeader("Content-length", lp_url_prefix2.length + url.length);
	//http_request.setRequestHeader("Connection", "close"); - if close - bug in IE7 - it hungs up
	http_request.send(lp_url_prefix2 + url);
	if (mr_type == 'lpath') {
		jlms_allow_pending_task = 0;
	}
}
function jlms_AnalizeRequest(http_request) {
	if (http_request.readyState == 4) {
		if ((http_request.status == 200)) {
			jlms_WStatus('');
			
			if(http_request.responseXML.documentElement == null){
				try {
					//alert(http_request.responseXML.parseError.reason);
					http_request.responseXML.loadXML(http_request.responseText)
				} catch (e) {
					/*alert("Can't load");*/
				}
			}
			response = http_request.responseXML.documentElement;
			var task = jlms_RFE(response,'task');
			jlms_blocked = 1;
			jlms_allow_pending_task = 1;
			setTimeout("jlms_releaseBlock()", 1000);
<?php 
        if (!$show_lpath_contents_at_the_left) {
            ?>
			jlms_SwitchOpenedContents();
<?php 
        }
        ?>
			switch (task) {
				case 'start_restart':
				case 'start':
					if ($('joomlalms_sys_message_container')) {
		                //hide course enrollment message (if autoredirect to lpath enabled)
		                $('joomlalms_sys_message_container').setStyles({visibility: 'hidden',display: 'none'});
					}
					lp_user_unique_id = jlms_RFE(response,'user_unique_id');
					user_start_id = jlms_RFE(response,'user_start_id');
					stu_step_type = jlms_RFE(response,'step_type');
					if (stu_step_type == 5) {
						quiz_blocked = 0;
						timer_sec = 0;
						stop_timer = 0;
						quiz_id = jlms_RFE(response,'step_item_id');
					}
					prev_step_type = stu_step_type;
					stu_step_id = jlms_RFE(response,'step_id');
					stu_last_cur_id = stu_step_id;
					prev_step_id = stu_step_id;
					jlms_ChangeFrontPage(response);
					if (task == 'start_restart') {
						$('jlms_lpath_completion_msg_container').setStyles({visibility: 'hidden',display: 'none'});
						jlms_setPendingSteps('cancel',response);
						jlms_setPendingSteps('quiz',response);
					}
					jlms_setPendingSteps('pending',response);
					jlms_setPendingSteps('accept',response);
				break;
				case 'restart':
					$('jlms_lpath_completion_msg_container').setStyles({visibility: 'hidden',display: 'none'});
					jlms_ChangeFrontPage(response);
					getObj('jlms_lpath_contents').innerHTML = jlms_RFE(response,'contents_data');
					jlms_setPendingSteps('pending',response);
				break;
				case 'check_cond':
					lp_user_unique_id = jlms_RFE(response,'user_unique_id');
					user_start_id = jlms_RFE(response,'user_start_id');	
				
					//stu_step_id = jlms_RFE(response,'step_id');
					//prev_step_id = stu_step_id;
					jlms_ChangeFrontPage(response);
					jlms_changePendingSteps();
					//jlms_setPendingSteps('pending',response);
					jlms_setPendingSteps('accept',response);
				break;
				case 'seek_step':
				case 'next_step':
					user_unique_id = '';
					quiz_id = 0;
					stu_step_type = jlms_RFE(response,'step_type');
					if (stu_step_type == 5) {
						quiz_id = jlms_RFE(response,'step_item_id');
					}
					prev_step_type = stu_step_type;
					stu_step_id = jlms_RFE(response,'step_id');
					prev_step_id = stu_step_id;
					jlms_ChangeFrontPage(response);
					jlms_setPendingSteps('pending',response);
					jlms_setPendingSteps('accept',response);
				break;
				case 'finish_lpath_quick':// without break;
					lp_user_unique_id = jlms_RFE(response,'user_unique_id');
					user_start_id = jlms_RFE(response,'user_start_id');
				case 'finish_lpath':
					jlms_ChangeFrontPage(response);

					var is_show_cmsg = jlms_RFE(response,'show_completion_msg');
					if (is_show_cmsg == 1 || is_show_cmsg == '1') {
						var cmsg_txt = jlms_RFE(response,'lpath_completion_msg');
						$('jlms_lpath_completion_msg_container').<?php 
        echo $setHTML;
        ?>
cmsg_txt);
						$('jlms_lpath_completion_msg_container').setStyles({visibility: 'visible',display: ''});
					}

					jlms_setPendingSteps('accept',response);
<?php 
        if (!$show_lpath_contents_at_the_left) {
            ?>
					jlms_SwitchContentsOnly('show');
<?php 
        }
        ?>
				break;
				case 'failed':
					getObj('jlms_lpath_descr').innerHTML = '<div class="joomlalms_sys_message"><?php 
        echo str_replace('/', '\\/', _JLMS_LPATH_LOAD_DATA_ERROR);
        ?>
<\/div>';
					//getObj('jlms_lpath_menu').innerHTML = jlms_RFE(response,'menu_contents');
				break;
				default:
					getObj('jlms_lpath_descr').innerHTML = '<div class="joomlalms_sys_message"><?php 
        echo str_replace('/', '\\/', _JLMS_LPATH_LOAD_DATA_ERROR);
        ?>
<\/div>';
					getObj('jlms_lpath_menu').innerHTML = '';
				break;
			}
		} else {
			alert('Bad Request status');
		}
	}
}
function jlms_RFE(response,elem_name) {
	return response.getElementsByTagName(''+elem_name)[0].firstChild ? response.getElementsByTagName(''+elem_name)[0].firstChild.data : 0;
}
var is_collapser_timer = 0;
<?php 
        echo JLMSCSS::h2_js();
        //JLMSCSS_h2_js function
        ?>
function jlms_ChangeFrontPage(response) {
	var head_data = jlms_RFE(response,'step_name');
	if (head_data != '') {
		getObj('jlms_lpath_head').innerHTML = JLMSCSS_h2_js(head_data);
	}
	var tmp_div = document.createElement("div");
	tmp_div.id = 'temporary_div_tst';
	tmp_div.innerHTML = jlms_RFE(response,'step_descr');
	tmp_div.style.width = '100%';
	getObj('jlms_lpath_descr').innerHTML = '';
	getObj('jlms_lpath_descr').appendChild(tmp_div);

	//getObj('jlms_lpath_descr').innerHTML = jlms_RFE(response,'step_descr');
	getObj('jlms_lpath_menu').innerHTML = jlms_RFE(response,'menu_contents');
	var temp_script = jlms_RFE(response,'step_exec_script');
	if (temp_script == 1 || temp_script == '1') {
		var exec_script = jlms_RFE(response,'step_exec_script_contents');
		var new_script_el = document.createElement("script");
		new_script_el.text = exec_script;
		new_script_el.type="text/javascript";
		document.getElementsByTagName("head")[0].appendChild(new_script_el);
		//eval(exec_script);
	}
<?php 
        if ($show_lpath_contents_at_the_left) {
            ?>
	jlms_ChangeCollapserHeight(0);
<?php 
        }
        ?>
	if (window.set_height) {
		set_height();
	}
	jlms_ScrollBrowserWindow();
	setTimeout("jlms_ScrollBrowserWindow()", 300);
}
function jlms_ScrollBrowserWindow() {
	window.scrollTo(0,$('jlms_topdiv').getTop());
}
function jlms_ChangeCollapserHeight(by_timer) {
	var leftnav_h, main_st_h = 0;
	leftnav_h = $('jlms_lpath_contents_container').getStyle('height').toInt();
	main_st_h = $('jlms_lpath_descr').getStyle('height').toInt();
	if (leftnav_h < main_st_h) {
		leftnav_h = main_st_h;
	}
	$('left_nav_collapser_container').setStyle('height', leftnav_h+'px');
	if (is_collapser_timer == 1) {
		if (by_timer == 1) {
			setTimeout("jlms_ChangeCollapserHeight(1)", 300);
		}
	} else {
		is_collapser_timer = 1;
		setTimeout("jlms_ChangeCollapserHeight(1)", 300);
	}
}
function jlms_releaseBlock() {
	jlms_blocked = 0;
	if (jlms_is_pending_task == 1) {
		if (jlms_pending_task != '') {
			jlms_is_pending_task = 0;
			eval("ajax_action('"+jlms_pending_task+"')");
			jlms_pending_task = '';
		}
	}
}
function jlms_showLoading() {
	jlms_SwitchContentsOnly('hide');
	getObj('jlms_lpath_descr').innerHTML = '<br \/><br \/><center><img src="<?php 
        echo str_replace('/', '\\/', $JLMS_CONFIG->get('live_site'));
        ?>
\/components\/com_joomla_lms\/lms_images\/loading.gif" height="32" width="32" border="0" alt="loading" \/><\/center>';
}
function jlms_setPendingSteps(step_type, response) {
	var st = 'pending_steps';
	var prfx = 'jlms_step_';
	var is_lp = true;
	switch (step_type) {
		case 'pending': st = 'pending_steps'; break;
		case 'accept': st = 'completed_steps'; break;
		case 'cancel': st = 'incompleted_steps'; break;
		case 'quiz': st = 'incompleted_quests'; prfx = 'quest_result_'; is_lp = false; break;
	}
	if (is_lp) {
		var steps_ids;
		steps_ids = jlms_RFE(response,st);
		var arr = steps_ids.split(',');
		var i = 0;
		while (i < arr.length ) {
			if (getObj(prfx+arr[i])) {
				getObj(prfx+arr[i]).innerHTML = '<img class=\'JLMS_png\' src="<?php 
        echo $JLMS_CONFIG->get('live_site');
        ?>
/components/com_joomla_lms/lms_images/toolbar/btn_'+step_type+'.png" height="16" width="16" border="0" alt="'+step_type+'" />';
			}
			i ++;
		}
		if (step_type == 'pending') {
			var r = getObj(prfx+stu_step_id);
			if (r) {r.innerHTML = '<img class=\'JLMS_png\' src="<?php 
        echo $JLMS_CONFIG->get('live_site');
        ?>
/components/com_joomla_lms/lms_images/toolbar/btn_'+step_type+'_cur.png" height="16" width="16" border="0" alt="'+step_type+'" />';}
			if (stu_last_cur_id != stu_step_id) {
				r = getObj(prfx+stu_last_cur_id);
				if (r) {r.innerHTML = '<img class=\'JLMS_png\' src="<?php 
        echo $JLMS_CONFIG->get('live_site');
        ?>
/components/com_joomla_lms/lms_images/toolbar/btn_'+step_type+'.png" height="16" width="16" border="0" alt="'+step_type+'" />';}
			}
			stu_last_cur_id = stu_step_id;
		}
	} else {
		var steps_ids;
		steps_ids = jlms_RFE(response,st);
		var arr = steps_ids.split(',');
		var i = 0;
		while (i < arr.length ) {
			if (getObj(prfx+arr[i])) {
				getObj(prfx+arr[i]).innerHTML = '-';
			}
			i ++;
		}
	}
}
function jlms_changePendingSteps() {
	r = getObj('jlms_step_'+stu_last_cur_id);
	if (r) {r.innerHTML = '<img class=\'JLMS_png\' src="<?php 
        echo $JLMS_CONFIG->get('live_site');
        ?>
/components/com_joomla_lms/lms_images/toolbar/btn_pending.png" height="16" width="16" border="0" alt="pending" />';}
}
JLMS_preloadImages('<?php 
        echo $JLMS_CONFIG->getCfg('live_site');
        ?>
/components/com_joomla_lms/lms_images/loading.gif','<?php 
        echo $JLMS_CONFIG->getCfg('live_site');
        ?>
/components/com_joomla_lms/lms_images/buttons/btn_back.png','<?php 
        echo $JLMS_CONFIG->getCfg('live_site');
        ?>
/components/com_joomla_lms/lms_images/buttons/btn_restart.png', '<?php 
        echo $JLMS_CONFIG->getCfg('live_site');
        ?>
/components/com_joomla_lms/lms_images/toolbar/btn_pending.png', '<?php 
        echo $JLMS_CONFIG->getCfg('live_site');
        ?>
/components/com_joomla_lms/lms_images/toolbar/btn_accept.png');
//--><!]]>
</script>
<?php 
        JLMS_TMPL::OpenMT();
        $hparams = array();
        //$toolbar = array();
        //$toolbar[] = array('btn_type' => 'start', 'btn_js' => "javascript:ajax_action('start_lpath');");
        JLMS_TMPL::ShowHeader('lpath', '', $hparams);
        //JLMS_TMPL::ShowToolbar($toolbar, 'right', true, $lpath_data->lpath_name, 2);
        //JLMS_TMPL::CloseMT();
        JLMS_TMPL::OpenTS();
        ?>
		<table width="100%" cellpadding="0" cellspacing="0" border="0" class="jlms_table_no_borders">
			<tr>
				<td align="left" valign="middle" id="jlms_lpath_head" width="100%">
					<?php 
        echo JLMSCSS::h2($lpath_data->lpath_name);
        ?>
				</td>
				<td align="right" style="text-align:right " valign="middle" id="jlms_lpath_menu">
					<?php 
        $toolbar = array();
        $toolbar[] = array('btn_type' => 'start', 'btn_js' => "javascript:void(0);");
        //$toolbar[] = array('btn_type' => 'start', 'btn_js' => sefrelToAbs("index.php?option=$option&amp;Itemid=$Itemid&amp;task=show_lpath_nojs&amp;course_id=$course_id&amp;id=$lpath_id&amp;action=start_lpath"));
        //no-js functionality commented (version 1.1.0) due to the lots of bugs, lack of usage/testing
        echo JLMS_ShowToolbar($toolbar);
        ?>
				</td>
			</tr>
		</table>
<?php 
        JLMS_TMPL::CloseTS();
        JLMS_TMPL::OpenTS();
        $toolbar = array();
        $toolbar[] = array('btn_type' => 'start', 'btn_js' => "javascript:ajax_action('start_lpath');");
        $rs = JLMS_ShowToolbar($toolbar);
        $rs = str_replace('"components/com_joomla_lms', '"' . $JLMS_CONFIG->getCfg('live_site') . '/components/com_joomla_lms', $rs);
        $lpc_btn = str_replace('/', '\\/', str_replace('"', "\\\"", $rs));
        $additon_js = '
var lp_menu_item_contents_pre = "' . $lpc_btn . '";
';
        $JLMS_CONFIG->set('jlms_aditional_js_code', $JLMS_CONFIG->get('jlms_aditional_js_code', '') . $additon_js);
        $domready = '
$(\'jlms_lpath_menu\').innerHTML = lp_menu_item_contents_pre;

if (document.constructor) {
	document.constructor.prototype.write = function() { };
} else {
	document.write = function() { };
}
';
        $JLMS_CONFIG->set('web20_domready_code', $JLMS_CONFIG->get('web20_domready_code', '') . $domready);
        if ($show_lpath_contents_at_the_left) {
            ?>
		<div id="jlms_lpath_contents_container" style="visibility:hidden; display:none; width:203px; float:left; overflow-x:hidden; margin-right: -1px">
		<?php 
            global $JLMS_CONFIG;
            $JLMS_CONFIG->set('show_lpath_contents_at_the_left', $show_lpath_contents_at_the_left);
            ?>

			<?php 
            JLMS_course_lpathstu_html::showLPath_contents($lpath_contents, $quizzes_data);
            ?>
<br />
		</div>
		<div id="left_nav_collapser_container" style="width:7px; float:left; overflow-x:hidden; visibility:hidden; display:none ">
			<a id="left_nav_collapser" href="javascript:jlms_SwitchContents2();"><img class="collapse_button_maximized_xxx" border="1" width="1" height="1" src="<?php 
            echo $JLMS_CONFIG->get('live_site');
            ?>
/components/com_joomla_lms/lms_images/spacer.png"/></a>
		</div>
		<div id="jlms_lpath_completion_msg_container" class="jlms_lpath_completion_message" style="visibility:hidden; display:none; margin-left:210px; width:auto;">
			<!--x-->
		</div>
		<div id="jlms_lpath_descr" style="margin-left:210px; width:auto;">
			<?php 
            $text = JLMS_ShowText_WithFeatures($lpath_data->lpath_description);
            echo $text;
            ?>
		</div>
		<br />
<?php 
        } else {
            ?>
		<div id="jlms_lpath_completion_msg_container" class="jlms_lpath_completion_message" style="visibility:hidden; display:none">
			<!--x-->
		</div>
		<div id="jlms_lpath_contents_container" style="visibility:hidden; display:none; width:100%">
			<?php 
            JLMS_course_lpathstu_html::showLPath_contents($lpath_contents, $quizzes_data);
            ?>
<br />
		</div>
		<div id="jlms_lpath_descr" style="width:100%">
			<?php 
            $text = JLMS_ShowText_WithFeatures($lpath_data->lpath_description);
            echo $text;
            ?>
		</div>
<?php 
        }
        JLMS_TMPL::CloseTS();
        JLMS_TMPL::CloseMT();
    }
Esempio n. 21
0
function JLMS_GraphStatistics($option, $id, $quiz_id, $i, $z, $row = array(), $c_question_id = 0, $group_id = 0, $str_user_in_groups = '', $no_js = 0)
{
    global $JLMS_DB, $JLMS_CONFIG;
    $obj = new stdClass();
    if (isset($row->c_type)) {
        switch ($row->c_type) {
            case '1':
            case '2':
            case '3':
            case '12':
            case '13':
                $query = "SELECT c_id FROM #__lms_quiz_t_choice WHERE c_question_id = '" . $c_question_id . "' ORDER BY ordering";
                $JLMS_DB->SetQuery($query);
                $choice_ids = $JLMS_DB->LoadResultArray();
                $choice_id = implode(',', $choice_ids);
                if (!$choice_id) {
                    $choice_id = '0';
                }
                $query = "SELECT COUNT(*) FROM #__lms_quiz_r_student_quiz as a, #__lms_quiz_r_student_question as q, #__lms_quiz_r_student_choice as c";
                $query .= "\n WHERE q.c_id = c.c_sq_id AND q.c_question_id = '" . $row->c_id . "' AND c.c_choice_id IN (" . $choice_id . ")";
                $query .= "\n AND a.c_id = q.c_stu_quiz_id";
                if ($group_id) {
                    $query .= "\n AND a.c_student_id IN (" . $str_user_in_groups . ")";
                }
                $JLMS_DB->setQuery($query);
                $total_count = $JLMS_DB->loadResult();
                if ($row->c_type == '12' || $row->c_type == '13') {
                    $query = "SELECT a.c_id as value, a.c_choice as text, a.c_right, b.imgs_name" . "\n FROM #__lms_quiz_t_choice as a" . "\n, #__lms_quiz_images as b" . "\n WHERE a.c_question_id = '" . $c_question_id . "'" . "\n AND a.c_choice = b.imgs_id" . "\n ORDER BY a.ordering";
                } else {
                    $query = "SELECT a.c_id as value, a.c_choice as text, a.c_right" . "\n FROM #__lms_quiz_t_choice as a" . "\n WHERE a.c_question_id = '" . $c_question_id . "'" . "\n ORDER BY a.ordering";
                }
                $JLMS_DB->SetQuery($query);
                $choice_data = $JLMS_DB->LoadObjectList();
                if ($total_count) {
                    $chart = new MultiVerticalChart(600, 200, 1);
                    $chart->maxval = 100;
                    $chart->maintitle = '';
                    for ($j = 0; $j < count($choice_data); $j++) {
                        $query = "SELECT count(*) FROM #__lms_quiz_r_student_quiz as a, #__lms_quiz_r_student_choice as sch, #__lms_quiz_r_student_question as qst" . "\n WHERE sch.c_choice_id = '" . $choice_data[$j]->value . "' AND sch.c_sq_id=qst.c_id AND qst.c_question_id='" . $row->c_id . "'" . "\n AND a.c_id = qst.c_stu_quiz_id" . ($group_id ? "\n AND a.c_student_id IN (" . $str_user_in_groups . ")" : '');
                        $JLMS_DB->setQuery($query);
                        $choice_this = $JLMS_DB->loadResult();
                        $row_percent = round($choice_this * 100 / $total_count);
                        if ($row->c_type == '12' || $row->c_type == '13') {
                            $chart->addPoint($z, new Point(trim(strip_tags($choice_data[$j]->imgs_name)), $row_percent), $choice_this);
                        } else {
                            $chart->addPoint($z, new Point(trim(strip_tags($choice_data[$j]->text)), $row_percent), $choice_this);
                        }
                    }
                    $chart->usr_answers[$z] = $i + 1;
                    $chart->titles[$z] = '';
                    $filename = time() . '_' . md5(uniqid(rand(), true)) . ".png";
                    //$this->clearOldImages(1);
                    $chart->render($JLMS_CONFIG->get('temp_folder', '') . '/' . $filename);
                    $obj->img_graph = $JLMS_CONFIG->get('temp_folder', '') . '/' . $filename;
                    $obj->title_graph = trim(strip_tags($row->c_question));
                    $obj->count_graph = 1;
                    $obj->points = array();
                    if (true) {
                        $query = "SELECT a.c_student_id, q.* FROM #__lms_quiz_r_student_quiz as a, #__lms_quiz_r_student_question as q, #__lms_quiz_r_student_choice as c";
                        $query .= "\n WHERE q.c_id = c.c_sq_id AND q.c_question_id = '" . $row->c_id . "' AND c.c_choice_id IN (" . $choice_id . ")";
                        $query .= "\n AND a.c_id = q.c_stu_quiz_id";
                        if ($group_id) {
                            $query .= "\n AND a.c_student_id IN (" . $str_user_in_groups . ")";
                        }
                        $JLMS_DB->setQuery($query);
                        $answers_students = $JLMS_DB->loadObjectList();
                        $right_answ = 0;
                        foreach ($answers_students as $answ_stu) {
                            if ($answ_stu->c_correct == 2) {
                                $right_answ = $right_answ + 1;
                            }
                        }
                        $no_right_answ = $total_count - $right_answ;
                        $chart = new MultiVerticalChart(600, 200, 1);
                        $chart->maxval = 100;
                        $chart->maintitle = '';
                        $row_percent = round($right_answ * 100 / $total_count);
                        $chart->addPoint($z, new Point(_JLMS_GRAPH_STATISTICS_CORRECT, $row_percent), $right_answ);
                        $row_percent = round($no_right_answ * 100 / $total_count);
                        $chart->addPoint($z, new Point(_JLMS_GRAPH_STATISTICS_INCORRECT, $row_percent), $no_right_answ);
                        $chart->usr_answers[$z] = $i + 1;
                        $chart->titles[$z] = '';
                        $filename = $row->c_type . '_' . time() . '_' . md5(uniqid(rand(), true)) . ".png";
                        $chart->render($JLMS_CONFIG->get('temp_folder', '') . '/' . $filename);
                        $obj->img_correct = $JLMS_CONFIG->get('temp_folder', '') . '/' . $filename;
                        $obj->title_correct = trim(strip_tags($row->c_question));
                        $obj->count_correct = 1;
                    }
                }
                break;
            case '4':
            case '5':
            case '11':
                $query = "SELECT a.c_id, a.c_right_text, a.c_left_text" . ($row->c_type == '11' ? "\n, b.imgs_name as left_imgs, b.imgs_name as right_imgs" : '') . "\n FROM #__lms_quiz_t_matching as a" . ($row->c_type == '11' ? "\n, #__lms_quiz_images as b" : '') . "\n WHERE a.c_question_id = '" . $c_question_id . "'" . ($row->c_type == '11' ? "\n AND a.c_left_text = b.imgs_id AND a.c_right_text = b.imgs_id" : '') . "\n ORDER BY a.ordering";
                $JLMS_DB->SetQuery($query);
                $fields_ids = $JLMS_DB->LoadObjectList();
                $left_answ = array();
                $left_imgs = array();
                for ($j = 0; $j < count($fields_ids); $j++) {
                    $left_answ[] = $fields_ids[$j]->c_right_text;
                    if ($row->c_type == '11') {
                        $left_imgs[] = $fields_ids[$j]->right_imgs;
                    }
                }
                $chart = new MultiVerticalChart(600, 200 * count($fields_ids), count($fields_ids));
                $chart->maxval = 100;
                $chart->maintitle = '';
                $adxz = 0;
                for ($j = 0; $j < count($fields_ids); $j++) {
                    $fields = $fields_ids[$j];
                    $query = "SELECT c_sel_text FROM #__lms_quiz_r_student_quiz as a, #__lms_quiz_r_student_question as q, #__lms_quiz_r_student_matching as c";
                    $query .= "\n WHERE q.c_id = c.c_sq_id AND q.c_question_id = '" . $row->c_id . "' AND c.c_matching_id = '" . $fields->c_id . "'";
                    $query .= "\n AND a.c_id = q.c_stu_quiz_id";
                    if ($group_id) {
                        $query .= "\n AND a.c_student_id IN (" . $str_user_in_groups . ")";
                    }
                    $JLMS_DB->setQuery($query);
                    $total_ids = $JLMS_DB->LoadObjectList();
                    $total_count = 0;
                    for ($g = 0; $g < count($total_ids); $g++) {
                        if (in_array($total_ids[$g]->c_sel_text, $left_answ)) {
                            $total_count++;
                        }
                    }
                    for ($g = 0; $g < count($left_answ); $g++) {
                        $query = "SELECT COUNT(*) FROM #__lms_quiz_r_student_quiz as a, #__lms_quiz_r_student_question as q, #__lms_quiz_r_student_matching as c";
                        $query .= "\n WHERE q.c_id = c.c_sq_id AND q.c_question_id = '" . $row->c_id . "' AND c.c_matching_id = '" . $fields->c_id . "' AND c.c_sel_text = '" . addslashes($left_answ[$g]) . "'";
                        $query .= "\n AND a.c_id = q.c_stu_quiz_id";
                        if ($group_id) {
                            $query .= "\n AND a.c_student_id IN (" . $str_user_in_groups . ")";
                        }
                        $JLMS_DB->setQuery($query);
                        $cur_count = $JLMS_DB->LoadResult();
                        if (!$total_count) {
                            $row_percent = 0;
                        } else {
                            $row_percent = round($cur_count * 100 / $total_count);
                        }
                        if ($row->c_type == '11') {
                            $chart->addPoint($z, new Point(trim(strip_tags($left_imgs[$g])), $row_percent), $cur_count);
                        } else {
                            $chart->addPoint($z, new Point(trim(strip_tags($left_answ[$g])), $row_percent), $cur_count);
                        }
                        $adxz++;
                    }
                    $chart->usr_answers[$z] = $i + 1;
                    if ($row->c_type == '11') {
                        $chart->titles[$z] = trim(strip_tags($fields_ids[$j]->left_imgs));
                    } else {
                        $chart->titles[$z] = trim(strip_tags($fields_ids[$j]->c_left_text));
                    }
                    $z++;
                }
                if ($z > 1 && $adxz) {
                    $filename = time() . '_' . md5(uniqid(rand(), true)) . ".png";
                    $chart->render($JLMS_CONFIG->get('temp_folder', '') . '/' . $filename);
                    $obj->img_graph = $JLMS_CONFIG->get('temp_folder', '') . '/' . $filename;
                    $obj->title_graph = trim(strip_tags($row->c_question));
                    $obj->count_graph = count($fields_ids);
                }
                if ($z > 1 && $adxz) {
                    $z = 1;
                    $query = "SELECT COUNT(*) FROM #__lms_quiz_r_student_quiz as a, #__lms_quiz_r_student_question as q";
                    //, #__lms_quiz_r_student_matching as c
                    $query .= "\n WHERE q.c_question_id = '" . $row->c_id . "'";
                    // AND c.c_matching_id IN (".$str_fields.") AND c.c_sel_text = '".addslashes($left_answ[$g])."'
                    $query .= "\n AND a.c_id = q.c_stu_quiz_id";
                    if ($group_id) {
                        $query .= "\n AND a.c_student_id IN (" . $str_user_in_groups . ")";
                    }
                    $JLMS_DB->setQuery($query);
                    $answers_count = $JLMS_DB->loadResult();
                    $query = "SELECT a.c_student_id, q.* FROM #__lms_quiz_r_student_quiz as a, #__lms_quiz_r_student_question as q";
                    //, #__lms_quiz_r_student_matching as c
                    $query .= "\n WHERE q.c_question_id = '" . $row->c_id . "'";
                    // AND c.c_matching_id IN (".$str_fields.") AND c.c_sel_text = '".addslashes($left_answ[$g])."'
                    $query .= "\n AND a.c_id = q.c_stu_quiz_id";
                    if ($group_id) {
                        $query .= "\n AND a.c_student_id IN (" . $str_user_in_groups . ")";
                    }
                    $JLMS_DB->setQuery($query);
                    $answers_students = $JLMS_DB->loadObjectList();
                    $right_answ = 0;
                    foreach ($answers_students as $answ_stu) {
                        if ($answ_stu->c_correct == 2) {
                            $right_answ = $right_answ + 1;
                        }
                    }
                    $no_right_answ = $answers_count - $right_answ;
                    $chart = new MultiVerticalChart(600, 200, 1);
                    $chart->maxval = 100;
                    $chart->maintitle = '';
                    $row_percent = $answers_count ? round($right_answ * 100 / $answers_count) : 0;
                    $chart->addPoint($z, new Point(_JLMS_GRAPH_STATISTICS_CORRECT, $row_percent), $right_answ);
                    $row_percent = $answers_count ? round($no_right_answ * 100 / $answers_count) : 0;
                    $chart->addPoint($z, new Point(_JLMS_GRAPH_STATISTICS_INCORRECT, $row_percent), $no_right_answ);
                    $chart->usr_answers[$z] = '';
                    $chart->titles[$z] = '';
                    $filename = $row->c_type . '_' . time() . '_' . md5(uniqid(rand(), true)) . ".png";
                    $chart->render($JLMS_CONFIG->get('temp_folder', '') . '/' . $filename);
                    $obj->img_correct = $JLMS_CONFIG->get('temp_folder', '') . '/' . $filename;
                    $obj->title_correct = trim(strip_tags($row->c_question));
                    $obj->count_correct = 1;
                }
                break;
            case '6':
                $quest_params = new JLMSParameters($row->params);
                if ($quest_params->get('survey_question')) {
                    $display_count = 5;
                    $popualr = array();
                    $query = "SELECT c.* FROM #__lms_quiz_r_student_quiz as a, #__lms_quiz_r_student_question as q, #__lms_quiz_r_student_blank as c";
                    $query .= "\n WHERE q.c_id = c.c_sq_id AND q.c_question_id = '" . $row->c_id . "'";
                    $query .= "\n AND a.c_id = q.c_stu_quiz_id";
                    if ($group_id) {
                        $query .= "\n AND a.c_student_id IN (" . $str_user_in_groups . ")";
                    }
                    $JLMS_DB->setQuery($query);
                    $total_answer = $JLMS_DB->loadObjectList();
                    $total_count = count($total_answer);
                    if ($total_count) {
                        $query = "SELECT DISTINCT(c.c_answer) FROM #__lms_quiz_r_student_quiz as a, #__lms_quiz_r_student_question as q, #__lms_quiz_r_student_blank as c";
                        $query .= "\n WHERE q.c_id = c.c_sq_id AND q.c_question_id = '" . $row->c_id . "'";
                        $query .= "\n AND a.c_id = q.c_stu_quiz_id";
                        if ($group_id) {
                            $query .= "\n AND a.c_student_id IN (" . $str_user_in_groups . ")";
                        }
                        $JLMS_DB->setQuery($query);
                        $notdubl_answer = $JLMS_DB->loadObjectList();
                        for ($j = 0; $j < count($notdubl_answer); $j++) {
                            $query = "SELECT COUNT(*) FROM #__lms_quiz_r_student_quiz as a, #__lms_quiz_r_student_question as q, #__lms_quiz_r_student_blank as c";
                            $query .= "\n WHERE q.c_id = c.c_sq_id AND q.c_question_id = '" . $row->c_id . "' AND c.c_answer = '" . $notdubl_answer[$j]->c_answer . "'";
                            $query .= "\n AND a.c_id = q.c_stu_quiz_id";
                            if ($group_id) {
                                $query .= "\n AND a.c_student_id IN (" . $str_user_in_groups . ")";
                            }
                            $JLMS_DB->setQuery($query);
                            $local_count = $JLMS_DB->loadResult();
                            $popualr[$j][0] = $local_count;
                            $popualr[$j][1] = $notdubl_answer[$j]->c_answer;
                        }
                        if (count($popualr)) {
                            $chart = new MultiVerticalChart(600, 200, 1);
                            $chart->maxval = 100;
                            $chart->maintitle = '';
                            rsort($popualr);
                            for ($j = 0; $j < $display_count; $j++) {
                                if (!empty($popualr[$j][0])) {
                                    $row_percent = round($popualr[$j][0] * 100 / $total_count);
                                    $chart->addPoint($z, new Point(trim(strip_tags($popualr[$j][1])), $row_percent), $popualr[$j][0]);
                                }
                            }
                            $chart->usr_answers[$z] = $i + 1;
                            $chart->titles[$z] = '';
                            $filename = time() . '_' . md5(uniqid(rand(), true)) . ".png";
                            //$this->clearOldImages(1);
                            $chart->render($JLMS_CONFIG->get('temp_folder', '') . '/' . $filename);
                            $obj->img_graph = $JLMS_CONFIG->get('temp_folder', '') . '/' . $filename;
                            $obj->title_graph = trim(strip_tags($row->c_question));
                            $obj->count_graph = 1;
                        }
                    }
                } else {
                    $query = "SELECT c.* FROM #__lms_quiz_r_student_quiz as a, #__lms_quiz_r_student_question as q, #__lms_quiz_r_student_blank as c";
                    $query .= "\n WHERE q.c_id = c.c_sq_id AND q.c_question_id = '" . $row->c_id . "'";
                    $query .= "\n AND a.c_id = q.c_stu_quiz_id";
                    if ($group_id) {
                        $query .= "\n AND a.c_student_id IN (" . $str_user_in_groups . ")";
                    }
                    $JLMS_DB->setQuery($query);
                    $total_answer = $JLMS_DB->loadObjectList();
                    $total_count = count($total_answer);
                    if ($total_count) {
                        $query = "SELECT c_text FROM  #__lms_quiz_t_blank as b, #__lms_quiz_t_text as t ";
                        $query .= "\n WHERE b.c_id = t.c_blank_id AND b.c_question_id = '" . $row->c_id . "'";
                        //$query .= "\n AND a.c_id = b.c_stu_quiz_id";
                        if ($group_id) {
                            //$query .= "\n AND a.c_student_id IN (".$str_user_in_groups.")";
                        }
                        $JLMS_DB->setQuery($query);
                        $r_answer = $JLMS_DB->loadObjectList();
                        $right_answers = array();
                        for ($g = 0; $g < count($r_answer); $g++) {
                            $right_answers[] = $r_answer[$g]->c_text;
                        }
                        if (count($right_answers)) {
                            $total_right = 0;
                            for ($g = 0; $g < count($total_answer); $g++) {
                                if (in_array($total_answer[$g]->c_answer, $right_answers)) {
                                    $total_right++;
                                }
                            }
                            $row_percent = round($total_right * 100 / $total_count);
                            $row_percent_wrong = 100 - $row_percent;
                            $chart = new MultiVerticalChart(600, 200, 1);
                            $chart->maxval = 100;
                            $chart->maintitle = '';
                            $chart->addPoint($z, new Point(_JLMS_GRAPH_STATISTICS_CORRECT, $row_percent), $total_right);
                            $chart->addPoint($z, new Point(_JLMS_GRAPH_STATISTICS_INCORRECT, $row_percent_wrong), $total_count - $total_right);
                            $chart->usr_answers[$z] = $i + 1;
                            $chart->titles[$z] = '';
                            $filename = time() . '_' . md5(uniqid(rand(), true)) . ".png";
                            $chart->render($JLMS_CONFIG->get('temp_folder', '') . '/' . $filename);
                            $obj->img_graph = $JLMS_CONFIG->get('temp_folder', '') . '/' . $filename;
                            $obj->title_graph = trim(strip_tags($row->c_question));
                            $obj->count_graph = 1;
                        }
                    }
                }
                break;
            case '7':
                $query = "SELECT c.* FROM #__lms_quiz_r_student_quiz as a, #__lms_quiz_r_student_question as q, #__lms_quiz_r_student_hotspot as c";
                $query .= "\n WHERE q.c_id = c.c_sq_id AND q.c_question_id = '" . $row->c_id . "'";
                $query .= "\n AND a.c_id = q.c_stu_quiz_id";
                if ($group_id) {
                    $query .= "\n AND a.c_student_id IN (" . $str_user_in_groups . ")";
                }
                $JLMS_DB->SetQuery($query);
                $total_answer = $JLMS_DB->LoadObjectList();
                $total_count = count($total_answer);
                $right_answers = 0;
                if ($total_count) {
                    $query = "SELECT a.c_point, a.c_attempts, b.c_start_x, b.c_start_y, b.c_width, b.c_height FROM #__lms_quiz_t_question as a, #__lms_quiz_t_hotspot as b WHERE a.c_id = '" . $row->c_id . "' and b.c_question_id = a.c_id";
                    $JLMS_DB->SetQuery($query);
                    $ddd = $JLMS_DB->LoadObjectList();
                    if (count($ddd)) {
                        for ($g = 0; $g < $total_count; $g++) {
                            if ($total_answer[$g]->c_select_x >= $ddd[0]->c_start_x && $total_answer[$g]->c_select_x <= $ddd[0]->c_start_x + $ddd[0]->c_width && $total_answer[$g]->c_select_y >= $ddd[0]->c_start_y && $total_answer[$g]->c_select_y <= $ddd[0]->c_start_y + $ddd[0]->c_height) {
                                $right_answers++;
                            }
                        }
                        $row_percent = round($right_answers * 100 / $total_count);
                        $row_percent_wrong = 100 - $row_percent;
                        $chart = new MultiVerticalChart(600, 200, 1);
                        $chart->maxval = 100;
                        $chart->maintitle = '';
                        $chart->addPoint($z, new Point(_JLMS_GRAPH_STATISTICS_CORRECT, $row_percent), $right_answers);
                        $chart->addPoint($z, new Point(_JLMS_GRAPH_STATISTICS_INCORRECT, $row_percent_wrong), $total_count - $right_answers);
                        $chart->usr_answers[$z] = $i + 1;
                        $chart->titles[$z] = '';
                        $filename = time() . '_' . md5(uniqid(rand(), true)) . ".png";
                        //$this->clearOldImages(1);
                        $chart->render($JLMS_CONFIG->get('temp_folder', '') . '/' . $filename);
                        $obj->img_graph = $JLMS_CONFIG->get('temp_folder', '') . '/' . $filename;
                        $obj->title_graph = trim(strip_tags($row->c_question));
                        $obj->count_graph = 1;
                    }
                }
                break;
            case '8':
                $extra = $group_id ? "&group_id=" . $group_id . "" : '';
                $obj->img_is_survey = 1;
                $obj->title_quest_survey = trim(strip_tags($row->c_question));
                $obj->title_link_survey = sefRelToAbs('index.php?option=' . $option . '&Itemid=' . $JLMS_CONFIG->get('Itemid') . '&task=quizzes&page=view_answ_survey&id=' . $id . '&quiz_id=' . $quiz_id . '&quest_id=' . $row->c_id . '' . $extra);
                break;
                /*
                Max: Den skazal ne vivodit etott tip voprosa
                Max:-(10.12.08)- prishel task vivesti etot tip
                */
            /*
            Max: Den skazal ne vivodit etott tip voprosa
            Max:-(10.12.08)- prishel task vivesti etot tip
            */
            case '9':
                $query = "SELECT * FROM #__lms_quiz_t_scale";
                $query .= "\n WHERE c_question_id = '" . $row->c_id . "' ORDER BY ordering";
                $JLMS_DB->SetQuery($query);
                $total_quest = $JLMS_DB->LoadObjectList();
                $scale_quest = array();
                $scale_answ = array();
                $quest_text = array();
                $answ_text = array();
                for ($g = 0; $g < count($total_quest); $g++) {
                    if ($total_quest[$g]->c_type) {
                        $scale_answ[] = $total_quest[$g]->c_id;
                        $answ_text[] = $total_quest[$g]->c_field;
                    } else {
                        $scale_quest[] = $total_quest[$g]->c_id;
                        $quest_text[] = $total_quest[$g]->c_field;
                    }
                }
                if (count($total_quest)) {
                    $scale_answ_id = implode(',', $scale_answ);
                    if (count($scale_quest)) {
                        $chart = new MultiVerticalChart(600, 200 * count($scale_quest), count($scale_quest));
                        $chart->maxval = 100;
                        $chart->maintitle = '';
                        for ($g = 0; $g < count($scale_quest); $g++) {
                            $query = "SELECT COUNT(*) FROM #__lms_quiz_r_student_quiz as a, #__lms_quiz_r_student_question as q, #__lms_quiz_r_student_scale as c";
                            $query .= "\n WHERE q.c_id = c.c_sq_id AND q.c_question_id = '" . $row->c_id . "'";
                            $query .= "\n AND c.q_scale_id = '" . $scale_quest[$g] . "' AND scale_id IN (" . $scale_answ_id . ")";
                            $query .= "\n AND a.c_id = q.c_stu_quiz_id";
                            if ($group_id) {
                                $query .= "\n AND a.c_student_id IN (" . $str_user_in_groups . ")";
                            }
                            $JLMS_DB->SetQuery($query);
                            $total_answer = $JLMS_DB->LoadResult();
                            for ($t = 0; $t < count($scale_answ); $t++) {
                                $query = "SELECT COUNT(*) FROM #__lms_quiz_r_student_quiz as a, #__lms_quiz_r_student_question as q, #__lms_quiz_r_student_scale as c";
                                $query .= "\n WHERE q.c_id = c.c_sq_id AND q.c_question_id = '" . $row->c_id . "'";
                                $query .= "\n AND c.q_scale_id = '" . $scale_quest[$g] . "' AND scale_id = '" . $scale_answ[$t] . "'";
                                $query .= "\n AND a.c_id = q.c_stu_quiz_id";
                                if ($group_id) {
                                    $query .= "\n AND a.c_student_id IN (" . $str_user_in_groups . ")";
                                }
                                $JLMS_DB->SetQuery($query);
                                $count_answer = $JLMS_DB->LoadResult();
                                if ($total_answer) {
                                    $row_percent = round($count_answer * 100 / $total_answer);
                                } else {
                                    $row_percent = 0;
                                    $count_answer = 0;
                                }
                                $chart->addPoint($z, new Point(trim(strip_tags($answ_text[$t])), $row_percent), $count_answer);
                            }
                            $chart->usr_answers[$z] = $g + 1;
                            $chart->titles[$z] = trim(strip_tags($quest_text[$g]));
                            $z++;
                        }
                        if ($z > 1) {
                            $filename = time() . '_' . md5(uniqid(rand(), true)) . ".png";
                            $chart->render($JLMS_CONFIG->get('temp_folder', '') . '/' . $filename);
                            $obj->img_graph = $JLMS_CONFIG->get('temp_folder', '') . '/' . $filename;
                            $obj->title_graph = trim(strip_tags($row->c_question));
                            $obj->count_graph = count($scale_quest);
                        }
                    }
                }
                /* This graph not use
                					if($z>1){
                						$z=1;
                						$query = "SELECT COUNT(*) FROM #__lms_quiz_r_student_quiz as a, #__lms_quiz_r_student_question as q";
                						$query .= "\n WHERE q.c_question_id = '".$row->c_id."'";	
                						$query .= "\n AND a.c_id = q.c_stu_quiz_id";
                						if($group_id){
                							$query .= "\n AND a.c_student_id IN (".$str_user_in_groups.")";
                						}
                						$JLMS_DB->setQuery($query);
                						$answers_count = $JLMS_DB->loadResult();
                
                						$query = "SELECT a.c_student_id, q.* FROM #__lms_quiz_r_student_quiz as a, #__lms_quiz_r_student_question as q";
                						$query .= "\n WHERE q.c_question_id = '".$row->c_id."'";	
                						$query .= "\n AND a.c_id = q.c_stu_quiz_id";
                						if($group_id){
                							$query .= "\n AND a.c_student_id IN (".$str_user_in_groups.")";
                						}
                						$JLMS_DB->setQuery($query);
                						$answers_students = $JLMS_DB->loadObjectList();
                
                						$right_answ = 0;
                						foreach($answers_students as $answ_stu){
                							if($answ_stu->c_correct == 2){
                								$right_answ = $right_answ + 1;	
                							}
                						}
                						$no_right_answ = $answers_count - $right_answ;
                						$chart = new MultiVerticalChart(600, 200, 1);
                						$chart->maxval = 100;
                						$chart->maintitle = '';
                						$row_percent = $answers_count ? round(($right_answ*100)/$answers_count) : 0;
                						$chart->addPoint($z, new Point(_JLMS_GRAPH_STATISTICS_CORRECT, $row_percent), $right_answ);
                						$row_percent = $answers_count ? round(($no_right_answ*100)/$answers_count) : 0;
                						$chart->addPoint($z, new Point(_JLMS_GRAPH_STATISTICS_INCORRECT, $row_percent), $no_right_answ);
                						$chart->usr_answers[$z] = '';
                						$chart->titles[$z] = '';
                						$filename = $row->c_type . '_' . time() . '_' . md5(uniqid(rand(), true)) . ".png";
                						$chart->render($JLMS_CONFIG->get('temp_folder', '').'/'.$filename);
                						$obj->img_correct = $JLMS_CONFIG->get('temp_folder', '').'/'.$filename;
                						$obj->title_correct = trim(strip_tags($row->c_question));
                						$obj->count_correct = 1; 
                					}
                					*/
                break;
        }
    }
    return $obj;
}
Esempio n. 22
0
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;
}