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, ' '); 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, ' '); 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); }