function JLMS_showLinks($option)
{
    $JLMS_CONFIG =& JLMSFactory::getCOnfig();
    $Itemid = $JLMS_CONFIG->get('Itemid');
    $db =& JFactory::getDbo();
    $user = JLMSFactory::getUser();
    $my_id = $user->get('id');
    $JLMS_ACL =& JLMSFactory::getACL();
    $id = $JLMS_CONFIG->get('course_id');
    $AND_ST = "";
    if (false !== ($enroll_period = JLMS_getEnrolPeriod($my_id, $id))) {
        $AND_ST = " AND IF(a.is_time_related, (a.show_period < '" . $enroll_period . "' ), 1) ";
    }
    if ($id && $JLMS_ACL->CheckPermissions('links', 'view')) {
        $query = "SELECT a.*, b.name as author_name" . "\n FROM #__lms_links as a LEFT JOIN #__users as b ON a.owner_id = b.id" . "\n WHERE a.course_id = '" . $id . "'" . $AND_ST . ($JLMS_ACL->CheckPermissions('links', 'view_all') ? '' : "\n AND a.published = 1") . "\n ORDER BY a.ordering, a.link_name";
        $db->SetQuery($query);
        $rows = $db->LoadObjectList();
        $lms_titles_cache =& JLMSFactory::getTitles();
        $lms_titles_cache->setArray('links', $rows, 'id', 'link_name');
        JLMS_course_links_html::showCourseLinks($id, $option, $rows);
    } elseif ($id) {
        JLMSRedirect(sefRelToAbs("index.php?option={$option}&Itemid={$Itemid}&task=details_course&id={$id}"));
    } else {
        JLMSRedirect(sefRelToAbs("index.php?option={$option}&Itemid={$Itemid}"));
    }
}
function JLMS_showCourseDropBox($course_id, $option)
{
    global $my, $JLMS_DB, $Itemid;
    $JLMS_ACL =& JLMSFactory::getACL();
    if ($course_id && $JLMS_ACL->CheckPermissions('dropbox', 'view')) {
        //	if ( $course_id && JLMS_GetUserType($my->id, $course_id) ) {
        $lists = array();
        $query = "SELECT count(*) FROM #__lms_dropbox" . "\n WHERE course_id = '" . $course_id . "'" . "\n AND recv_id = '" . $my->id . "'";
        $JLMS_DB->SetQuery($query);
        $lists['dropbox_in_total'] = intval($JLMS_DB->LoadResult());
        $query = "SELECT count(*) FROM #__lms_dropbox" . "\n WHERE course_id = '" . $course_id . "'" . "\n AND recv_id = '" . $my->id . "' AND drp_mark = 1";
        $JLMS_DB->SetQuery($query);
        $lists['dropbox_in_new'] = intval($JLMS_DB->LoadResult());
        $query = "SELECT count(*) FROM #__lms_dropbox" . "\n WHERE course_id = '" . $course_id . "'" . "\n AND owner_id = '" . $my->id . "'";
        $JLMS_DB->SetQuery($query);
        $lists['dropbox_out_total'] = intval($JLMS_DB->LoadResult());
        $query = "SELECT a.*" . "\n, b.name as owner_username" . "\n, c.name as recv_username" . "\n FROM #__lms_dropbox as a" . "\n, #__users as b" . "\n, #__users as c" . "\n WHERE a.course_id = '" . $course_id . "'" . "\n AND a.owner_id = b.id AND a.recv_id = c.id AND (a.owner_id = '" . $my->id . "' OR a.recv_id = '" . $my->id . "')" . "\n ORDER BY a.drp_time DESC";
        $JLMS_DB->SetQuery($query);
        $dropbox = $JLMS_DB->LoadObjectList();
        $lms_titles_cache =& JLMSFactory::getTitles();
        $lms_titles_cache->setArray('dropbox', $dropbox, 'id', 'drp_name');
        JLMS_course_dropbox_html::showCourseDropBox($course_id, $option, $dropbox, $lists);
    } elseif ($course_id) {
        JLMSRedirect(sefRelToAbs("index.php?option={$option}&Itemid={$Itemid}&task=details_course&id={$course_id}"));
    } else {
        JLMSRedirect(sefRelToAbs("index.php?option={$option}&Itemid={$Itemid}"));
    }
}
Beispiel #3
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_ListQuizzes_Stu($option, $course_id)
 {
     global $JLMS_DB, $JLMS_SESSION, $my, $JLMS_CONFIG;
     $JLMS_ACL =& JLMSFactory::getACL();
     $cat_id = intval(mosGetParam($_REQUEST, 'cat_id', $JLMS_SESSION->get('cat_id', 0)));
     $JLMS_SESSION->set('cat_id', $cat_id);
     $limit = intval(mosGetParam($_REQUEST, 'limit', $JLMS_SESSION->get('list_limit', $JLMS_CONFIG->get('list_limit'))));
     $JLMS_SESSION->set('list_limit', $limit);
     $limitstart = intval(mosGetParam($_REQUEST, 'limitstart', 0));
     $AND_ST = "";
     if (false !== ($enroll_period = JLMS_getEnrolPeriod($my->id, $course_id))) {
         $AND_ST = " AND IF(a.is_time_related, (a.show_period < '" . $enroll_period . "' ), 1) ";
     }
     $query = "SELECT COUNT(*)" . "\n FROM #__lms_quiz_t_quiz AS a" . "\n WHERE a. course_id = '" . $course_id . "'" . $AND_ST . ($JLMS_ACL->CheckPermissions('quizzes', 'view_all') ? '' : "\n AND a.published = 1") . ($cat_id ? "\n AND a.c_category_id = {$cat_id}" : '');
     $JLMS_DB->setQuery($query);
     $total = $JLMS_DB->loadResult();
     require_once _JOOMLMS_FRONT_HOME . DS . "includes" . DS . "classes" . DS . "lms.pagination.php";
     $pageNav = new JLMSPageNav($total, $limitstart, $limit);
     $query = "SELECT a.*, b.c_category, u.name as author_name " . "\n FROM #__lms_quiz_t_quiz a LEFT JOIN #__lms_quiz_t_category b ON a.c_category_id = b.c_id AND b.course_id = '" . $course_id . "' AND b.is_quiz_cat = 1 LEFT JOIN #__users as u ON a.c_user_id = u.id" . "\n WHERE a.course_id = '" . $course_id . "'" . $AND_ST . ($JLMS_ACL->CheckPermissions('quizzes', 'view_all') ? '' : "\n AND a.published = 1") . ($cat_id ? "\n AND a.c_category_id = {$cat_id}" : '') . "\n ORDER BY a.c_title, b.c_category" . "\n LIMIT {$pageNav->limitstart}, {$pageNav->limit}";
     $JLMS_DB->setQuery($query);
     $rows = $JLMS_DB->loadObjectList();
     $quizzes_i = array();
     foreach ($rows as $row) {
         $quizzes_i[] = $row->c_id;
     }
     $q_items_num = array();
     if (!empty($quizzes_i)) {
         $quizzes_i_cid = implode(',', $quizzes_i);
         $query = "SELECT sum(items_number) as items_count, quiz_id FROM #__lms_quiz_t_quiz_pool WHERE quiz_id IN ({$quizzes_i_cid}) GROUP BY quiz_id";
         $JLMS_DB->SetQuery($query);
         $q_items_num = $JLMS_DB->loadObjectList();
     }
     for ($i = 0, $n = count($rows); $i < $n; $i++) {
         $rows[$i]->quests_from_pool = 0;
         foreach ($q_items_num as $qin) {
             if ($qin->quiz_id == $rows[$i]->c_id) {
                 if ($qin->items_count) {
                     $rows[$i]->quests_from_pool = $qin->items_count;
                 }
                 break;
             }
         }
     }
     $javascript = 'onchange="document.adminForm.submit();"';
     $query = "SELECT c_id AS value, c_category AS text" . "\n FROM #__lms_quiz_t_category WHERE course_id = '" . $course_id . "' AND is_quiz_cat = 1" . "\n ORDER BY c_category";
     $JLMS_DB->setQuery($query);
     $categories[] = mosHTML::makeOption('0', _JLMS_SB_SELECT_CATEGORY);
     $categories = array_merge($categories, $JLMS_DB->loadObjectList());
     $category = mosHTML::selectList($categories, 'cat_id', 'class="inputbox" size="1" ' . $javascript, 'value', 'text', $cat_id);
     $lists['category'] = $category;
     $lists['used_category_filter'] = $cat_id;
     $arr1 = array();
     if (!empty($rows)) {
         if (empty($rows)) {
             $quiz_ids = array(0);
         } else {
             $quiz_ids = array();
             foreach ($rows as $row1) {
                 $quiz_ids[] = $row1->c_id;
             }
             $query = "SELECT * FROM #__lms_quiz_results WHERE quiz_id IN (" . implode(',', $quiz_ids) . ") AND course_id='" . $course_id . "' AND user_id = '" . $my->id . "'";
             //  GROUP BY quiz_id";
             $JLMS_DB->SetQuery($query);
             $user_results = $JLMS_DB->loadObjectList();
             for ($i = 0; $i < count($rows); $i++) {
                 $rows[$i]->user_passed = -1;
                 $rows[$i]->quiz_max_score = 0;
                 $rows[$i]->user_score = 0;
                 foreach ($user_results as $user_result1) {
                     if ($user_result1->course_id == $rows[$i]->course_id && $user_result1->quiz_id == $rows[$i]->c_id) {
                         $rows[$i]->user_passed = $user_result1->user_passed;
                         $rows[$i]->quiz_max_score = $user_result1->quiz_max_score;
                         $rows[$i]->user_score = $user_result1->user_score;
                     }
                 }
             }
         }
         require_once _JOOMLMS_FRONT_HOME . DS . "includes" . DS . "lms_certificates.php";
         $arr = array();
         JLMS_Certificates::JLMS_GB_getUserCertificates($course_id, $my->id, $arr);
         $arr1 = isset($arr['user_quiz_certificates']) ? $arr['user_quiz_certificates'] : array();
     }
     for ($i = 0; $i < count($rows); $i++) {
         for ($j = 0; $j < count($arr1); $j++) {
             if ($arr1[$j]->c_quiz_id == $rows[$i]->c_id) {
                 $rows[$i]->link_certificate = "<a class=\"jlms_img_link\" target = \"_blank\" href = \"" . $JLMS_CONFIG->get('live_site') . "/index.php?tmpl=component&option=" . $option . "&amp;no_html=1&amp;task=print_quiz_cert&amp;course_id=" . $course_id . "&amp;stu_quiz_id=" . $arr1[$j]->stu_quiz_id . "&amp;user_unique_id=" . $arr1[$j]->user_unique_id . "\"><img src = \"" . $JLMS_CONFIG->get('live_site') . "/components/com_joomla_lms/lms_images/toolbar/btn_certificate.png\" border = \"0\" align=\"top\" alt=\"certificate\"/></a>";
                 $rows[$i]->user_score = $arr1[$j]->user_score;
                 $rows[$i]->quiz_max_score = $arr1[$j]->quiz_max_score;
             }
         }
     }
     $lms_titles_cache =& JLMSFactory::getTitles();
     $lms_titles_cache->setArray('quiz_t_quiz', $rows, 'c_id', 'c_title');
     //	echo '<pre>';
     //	print_r($rows);
     //	echo '</pre>';
     JLMS_quiz_admin_html_class::JQ_showQuizList_Stu($rows, $lists, $pageNav, $option, $course_id);
 }
function JLMS_show_calendar($id, $option)
{
    $JLMS_CONFIG =& JLMSFactory::getConfig();
    $Itemid = $JLMS_CONFIG->get('Itemid');
    $db =& JFactory::getDbo();
    $user = JLMSFactory::getUser();
    $my_id = $user->get('id');
    $JLMS_ACL =& JLMSFactory::getACL();
    $assigned_groups_only = $JLMS_ACL->CheckPermissions('advanced', 'assigned_groups_only');
    $view_all_course_categories = $JLMS_ACL->CheckPermissions('advanced', 'view_all_course_categories');
    //show top menu
    JLMS_agenda_html::show_head_menu($id, $option);
    //select all events
    if ($id) {
        $course_id = array($id);
    } else {
        $course_id = JLMS_GetUserCourses_IDs($my_id);
        if (!is_array($course_id) || empty($course_id)) {
            $course_id = array(0);
        }
    }
    //opredeliaem type usera
    $mode = mosGetParam($_REQUEST, 'mode', '');
    $sort = mosGetParam($_REQUEST, 'jlms_agenda_order', 'desc');
    $filter = mosGetParam($_REQUEST, 'jlms_agenda_filter', '');
    $where = '';
    switch ($filter) {
        case 'current':
            $where .= "\n AND end_date >= '" . date('Y-m-d') . "' AND start_date <= '" . date('Y-m-d') . "'";
            break;
        case 'upcoming':
            $where .= "\n AND start_date > '" . date('Y-m-d') . "'";
            break;
    }
    $course_id = implode(',', $course_id);
    if ($mode != 'add_avent' || $mode != 'edit_event') {
        $members = "'0'";
        if ($JLMS_ACL->_role_type == 2 || $JLMS_ACL->_role_type == 3 || $JLMS_ACL->_role_type == 4) {
            if ($assigned_groups_only) {
                $groups_where_admin_manager = JLMS_ACL_HELPER::GetAssignedGroups($my_id, $id);
                $groups_where_isset_user = JLMS_ACL_HELPER::GetUserGlobalGroup($my_id, $id);
                $groups_where_admin_manager = array_merge($groups_where_admin_manager, $groups_where_isset_user);
                if (count($groups_where_admin_manager)) {
                    $where .= "\n AND (is_limited = 0 OR `groups` LIKE '%|{$groups_where_admin_manager['0']}|%'";
                    for ($i = 1; $i < count($groups_where_admin_manager); $i++) {
                        $where .= "\n OR `groups` like '%|{$groups_where_admin_manager[$i]}|%'";
                    }
                    $where .= "\n OR owner_id = '" . $my_id . "')";
                } else {
                    $where .= "\n AND (is_limited = 0 OR owner_id = '" . $my_id . "' OR agenda_id = 0) AND groups = ''";
                }
            }
        } elseif ($JLMS_ACL->_role_type < 2) {
            $query = "select a.group_id FROM #__lms_users_in_global_groups as a WHERE a.user_id = '" . $my_id . "' AND a.subgroup1_id = 0 AND a.group_id > 0";
            $db->setQuery($query);
            $temp1 = $db->loadResultArray();
            $query = "select subgroup1_id FROM #__lms_users_in_global_groups WHERE user_id = '" . $my_id . "' AND subgroup1_id > 0";
            $db->setQuery($query);
            $temp2 = $db->loadResultArray();
            $group_where_isset_user = array_merge($temp1, $temp2);
            if (count($group_where_isset_user)) {
                $where .= "\n AND (( `groups` <> '' AND `groups` IS NOT NULL AND (`groups` LIKE '%|{$group_where_isset_user['0']}|%'";
                for ($i = 1; $i < count($group_where_isset_user); $i++) {
                    $where .= "\n OR `groups` like '%|{$group_where_isset_user[$i]}|%'";
                }
                $where .= "\n )) OR (is_limited = 0 AND (`groups` = '' OR `groups` IS NULL)))";
            }
        }
        $query = "SELECT * FROM #__lms_agenda WHERE course_id IN ({$course_id})" . $where . "\n ORDER BY start_date ";
        $db->setQuery($query);
        $rows = $db->LoadObjectList();
        $lms_titles_cache =& JLMSFactory::getTitles();
        $lms_titles_cache->setArray('agenda', $rows, 'agenda_id', 'title');
        if ($JLMS_ACL->_role_type < 2) {
            $rows = filterByShowPeriod($rows);
        }
    }
    //select date (if no, select current date)
    $cal_date = false;
    if (isset($_REQUEST['cal_date']) && $_REQUEST['cal_date'] != '' && strtotime($_REQUEST['cal_date']) != -1) {
        $cal_date = $_REQUEST['cal_date'];
    } else {
        if (isset($_REQUEST['date']) && $_REQUEST['date'] != '' && strtotime($_REQUEST['date']) != -1) {
            $cal_date = $_REQUEST['date'];
        }
    }
    if ($cal_date) {
        $now_date = JLMS_dateToDB($cal_date);
        $strDate = $now_date;
        $isValid = false;
        //proverka pravilnosti date
        $dateArr = getdate(strtotime($now_date));
        $y = $dateArr['year'];
        $m = $dateArr['mon'];
        $d = $dateArr['mday'];
        $isValid = checkdate($m, $d, $y);
        if (!$isValid) {
            $now_date = date('Y-m-d');
        }
    } else {
        $now_date = date('Y-m-d');
    }
    $date = strtotime($now_date);
    if ($id && $JLMS_ACL->CheckPermissions('announce', 'view')) {
        switch ($mode) {
            case 'view_month':
                JLMS_agenda_html::show_calendar_month($id, $option, $rows, $date);
                break;
            case 'view_week':
                JLMS_agenda_html::show_calendar_week($id, $option, $rows, $date);
                break;
            case 'view_day':
                JLMS_agenda_html::show_calendar_day($id, $option, $rows, $date);
                break;
            case 'add_event':
                $JLMS_ACL =& JLMSFactory::getACL();
                global $JLMS_CONFIG;
                $id = $JLMS_CONFIG->get('course_id');
                if ($id && $JLMS_ACL->CheckPermissions('announce', 'manage')) {
                    $lists['groups'] = JLMSmultiselect(array(), true, $id);
                    if ($assigned_groups_only) {
                        $lists['is_limited'] = mosHTML::yesnoRadioList('is_limited', 'disabled="disabled" class="inputbox" ', 1);
                    } else {
                        $lists['is_limited'] = mosHTML::yesnoRadioList('is_limited', 'class="inputbox" ', 0);
                    }
                    JLMS_agenda_html::show_add_event($id, $option, $agenda_item = '', $lists);
                } else {
                    JLMSRedirect(sefRelToAbs("index.php?option={$option}&Itemid={$Itemid}&task=agenda&id={$id}"));
                }
                break;
            case 'cancel_agenda':
                JLMSRedirect(sefRelToAbs("index.php?option={$option}&Itemid={$Itemid}&task=agenda&id={$id}"));
                break;
            case 'event_save':
                JLMS_save_event($option);
                break;
            case 'edit':
                JLMS_edit_event($option, $id);
                break;
            case 'delete':
                JLMS_delete_event($option, $id);
                break;
            default:
                show_agenda_items($id, $option, $rows, $date, $sort);
                break;
        }
    } else {
        JLMSRedirect(sefRelToAbs("index.php?option={$option}&Itemid={$Itemid}&task=details_course&id={$id}"));
    }
}
function JLMS_showHomeWork($id, $option)
{
    global $my, $JLMS_DB, $Itemid, $JLMS_SESSION, $JLMS_CONFIG;
    $course_id = JRequest::getInt('course_id');
    $id = $course_id ? $course_id : $id;
    $usertype = JLMS_GetUserType($my->id, $id);
    $JLMS_ACL =& JLMSFactory::getACL();
    $assigned_groups_only = $JLMS_ACL->CheckPermissions('advanced', 'assigned_groups_only');
    $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));
    $where = '';
    //	if ($id && ($usertype == 1 || $usertype == 6)) {
    //	if ($id && ($JLMS_ACL->CheckPermissions('homework', 'manage') || $usertype == 6)) {
    if ($id && ($JLMS_ACL->CheckPermissions('homework', 'manage') || $JLMS_ACL->CheckPermissions('homework', 'view_stats'))) {
        $members = "'0'";
        $AND_ST = "";
        $fields = ',0 AS checkedout';
        if ($JLMS_ACL->_role_type == 2 || $JLMS_ACL->_role_type == 3 || $JLMS_ACL->_role_type == 4) {
            if ($assigned_groups_only) {
                $fields = ",IF(a.owner_id != '" . $my->id . "',1 ,0) AS checkedout";
                $groups_where_admin_manager = JLMS_ACL_HELPER::GetAssignedGroups($my->id, $id);
                $groups_where_isset_user = JLMS_ACL_HELPER::GetUserGlobalGroup($my->id, $id);
                $groups_where_admin_manager = array_merge($groups_where_admin_manager, $groups_where_isset_user);
                if (count($groups_where_admin_manager)) {
                    $where .= "\n AND (a.is_limited = 0 OR a.groups LIKE '%|{$groups_where_admin_manager['0']}|%'";
                    for ($i = 1; $i < count($groups_where_admin_manager); $i++) {
                        $where .= "\n OR a.groups like '%|{$groups_where_admin_manager[$i]}|%'";
                    }
                    $where .= "\n OR a.owner_id = '" . $my->id . "')";
                } else {
                    $where .= "\n AND (a.is_limited = 0 OR a.owner_id = '" . $my->id . "' OR a.id = 0) AND a.groups = ''";
                }
            }
        } else {
            if ($JLMS_ACL->_role_type < 2) {
                $query = "select a.group_id FROM #__lms_users_in_global_groups as a WHERE a.user_id = '" . $my->id . "' AND a.subgroup1_id = 0 AND a.group_id > 0";
                $JLMS_DB->setQuery($query);
                $temp1 = $JLMS_DB->loadResultArray();
                $query = "select subgroup1_id FROM #__lms_users_in_global_groups WHERE user_id = '" . $my->id . "' AND subgroup1_id > 0";
                $JLMS_DB->setQuery($query);
                $temp2 = $JLMS_DB->loadResultArray();
                $group_where_isset_user = array_merge($temp1, $temp2);
                if (count($group_where_isset_user)) {
                    $where .= "\n AND (( a.groups <> '' AND a.groups IS NOT NULL AND (groups LIKE '%|{$group_where_isset_user['0']}|%'";
                    for ($i = 1; $i < count($group_where_isset_user); $i++) {
                        $where .= "\n OR groups like '%|{$group_where_isset_user[$i]}|%'";
                    }
                    $where .= "\n )) OR (a.is_limited = 0 AND (a.groups = '' OR a.groups IS NULL)))";
                }
                if (false !== ($enroll_period = JLMS_getEnrolPeriod($my->id, $id))) {
                    $AND_ST = " AND IF(a.is_time_related, (a.show_period < '" . $enroll_period . "' ), 1) ";
                }
            }
        }
        $query = "SELECT count(*) FROM #__lms_homework AS a" . "\n WHERE a.course_id = '" . $id . "'" . $AND_ST . ($JLMS_ACL->CheckPermissions('homework', 'view_all') ? '' : "\n AND a.published = 1") . $where;
        $JLMS_DB->SetQuery($query);
        $total = $JLMS_DB->LoadResult();
        require_once _JOOMLMS_FRONT_HOME . DS . "includes" . DS . "classes" . DS . "lms.pagination.php";
        $pageNav = new JLMSPageNav($total, $limitstart, $limit);
        $query = "SELECT a.*" . $fields . "\n FROM #__lms_homework as a" . "\n WHERE a.course_id = '" . $id . "'" . $AND_ST . ($JLMS_ACL->CheckPermissions('homework', 'view_all') ? '' : "\n AND a.published = 1") . $where . "\n ORDER BY a.post_date DESC, a.hw_name" . "\n LIMIT {$pageNav->limitstart}, {$pageNav->limit}";
        $JLMS_DB->SetQuery($query);
        $rows = $JLMS_DB->LoadObjectList();
        $lms_titles_cache =& JLMSFactory::getTitles();
        $lms_titles_cache->setArray('homework', $rows, 'id', 'hw_name');
        JLMS_homework_html::showHomeWorks($id, $option, $rows, $pageNav, $usertype);
    } elseif ($id && $JLMS_ACL->CheckPermissions('homework', 'view')) {
        $filt_hw = intval(mosGetParam($_GET, 'filt_hw', $JLMS_SESSION->get('filt_hw', 0)));
        $JLMS_SESSION->set('filt_hw', $filt_hw);
        $query = "select a.group_id FROM #__lms_users_in_global_groups as a WHERE a.user_id = '" . $my->id . "' AND a.subgroup1_id = 0 AND a.group_id > 0";
        $JLMS_DB->setQuery($query);
        $temp1 = $JLMS_DB->loadResultArray();
        $query = "select subgroup1_id FROM #__lms_users_in_global_groups WHERE user_id = '" . $my->id . "' AND subgroup1_id > 0";
        $JLMS_DB->setQuery($query);
        $temp2 = $JLMS_DB->loadResultArray();
        $group_where_isset_user = array_merge($temp1, $temp2);
        $AND_ST = "";
        if (false !== ($enroll_period = JLMS_getEnrolPeriod($my->id, $id))) {
            $AND_ST = " AND IF(a.is_time_related, (a.show_period < '" . $enroll_period . "' ), 1) ";
        }
        $query = "SELECT count(*) FROM #__lms_homework as a" . ($filt_hw ? "\n LEFT JOIN #__lms_homework_results as b ON a.id = b.hw_id AND b.user_id = '" . $my->id . "' AND b.course_id = '" . $id . "'" : '') . "\n WHERE a.course_id = '" . $id . "'" . $AND_ST . ($JLMS_ACL->CheckPermissions('homework', 'view_all') ? '' : "\n AND a.published = 1") . ($filt_hw ? $filt_hw == 2 ? "\n AND b.hw_status = 1" : ($filt_hw == 1 ? " AND (b.hw_status IS NULL OR b.hw_status <> 1)" : "") : '');
        $query .= "\n AND a.is_limited = 0";
        if (isset($group_where_isset_user) && count($group_where_isset_user)) {
            $query .= "\n OR (a.is_limited = 1" . "\n AND (a.groups LIKE '%|{$group_where_isset_user['0']}|%'";
            for ($i = 1; $i < count($group_where_isset_user); $i++) {
                $query .= "\n OR a.groups like '%|{$group_where_isset_user[$i]}|%'";
            }
            $query .= "\n ))";
        }
        $JLMS_DB->SetQuery($query);
        $total = $JLMS_DB->LoadResult();
        require_once _JOOMLMS_FRONT_HOME . DS . "includes" . DS . "classes" . DS . "lms.pagination.php";
        $pageNav = new JLMSPageNav($total, $limitstart, $limit);
        $query = "SELECT a.*, b.id as result_id, b.hw_status, b.hw_date, b.grade" . "\n FROM #__lms_homework as a LEFT JOIN #__lms_homework_results as b ON a.id = b.hw_id AND b.user_id = '" . $my->id . "' AND b.course_id = '" . $id . "'" . "\n WHERE a.course_id = '" . $id . "'" . $AND_ST . ($filt_hw ? $filt_hw == 2 ? "\n AND b.hw_status = 1" : ($filt_hw == 1 ? " AND (b.hw_status IS NULL OR b.hw_status <> 1)" : "") : '') . ($JLMS_ACL->CheckPermissions('homework', 'view_all') ? '' : "\n AND a.published = 1");
        $query .= "\n AND (a.is_limited = 0";
        if (isset($group_where_isset_user) && count($group_where_isset_user)) {
            $query .= "\n OR (a.is_limited = 1" . "\n AND (a.groups LIKE '%|{$group_where_isset_user['0']}|%'";
            for ($i = 1; $i < count($group_where_isset_user); $i++) {
                $query .= "\n OR a.groups like '%|{$group_where_isset_user[$i]}|%'";
            }
            $query .= "\n )))";
        } else {
            $query .= "\n )";
        }
        $query .= "\n ORDER BY a.post_date DESC, a.hw_name" . "\n LIMIT {$pageNav->limitstart}, {$pageNav->limit}";
        $JLMS_DB->SetQuery($query);
        $rows = $JLMS_DB->LoadObjectList();
        $lists = array();
        $f_items = array();
        $f_items[] = mosHTML::makeOption(0, _JLMS_HW_FILTER_ALL_RESULTS);
        $f_items[] = mosHTML::makeOption(2, _JLMS_HW_STATUS_COMPLETED);
        $f_items[] = mosHTML::makeOption(1, _JLMS_HW_STATUS_INCOMPLETE);
        $link = "index.php?option={$option}&amp;Itemid={$Itemid}&task=homework&id={$id}";
        $link = $link . "&amp;filt_hw='+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['filter'] = mosHTML::selectList($f_items, 'filt_hw', 'class="inputbox" size="1" onchange="document.location.href=\'' . $link . '\';"', 'value', 'text', $filt_hw);
        $lists['used_filter'] = $filt_hw;
        $lms_titles_cache =& JLMSFactory::getTitles();
        $lms_titles_cache->setArray('homework', $rows, 'id', 'hw_name');
        JLMS_homework_html::showHomeWorks_stu($id, $option, $rows, $pageNav, $lists);
    } else {
        JLMSRedirect(sefRelToAbs("index.php?option={$option}&Itemid={$Itemid}"));
    }
}