예제 #1
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}&Itemid={$Itemid}&task=courses";
    $link = $link . "&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);
    }
}