Esempio n. 1
0
function JLMS_showMainPage_front($option)
{
    global $my, $JLMS_DB, $JLMS_CONFIG, $Itemid;
    $JLMS_ACL =& JLMSFactory::getACL();
    $assigned_groups_only = $JLMS_ACL->CheckPermissions('advanced', 'assigned_groups_only');
    $pathway = array();
    $pathway[] = array('name' => _JLMS_PATHWAY_HOME, 'link' => sefRelToAbs("index.php?option={$option}&Itemid={$Itemid}"), 'is_home' => true);
    JLMSAppendPathWay($pathway);
    $hp_items = $JLMS_CONFIG->get('homepage_items');
    $lists = array();
    //courses
    $cidsf = $JLMS_CONFIG->get('student_in_future_courses');
    $course_data_sf = array();
    $cidtxt = '0';
    if (!empty($cidsf)) {
        $cidsfxt = implode(',', $cidsf);
        $query = "SELECT a.*, '0' as user_course_role FROM #__lms_courses as a WHERE a.id IN ({$cidsfxt}) AND a.id NOT IN ({$cidtxt})" . "\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);
        $course_data_sf = $JLMS_DB->LoadObjectList();
    }
    $my_courses_r = my_courses_r();
    if (count($my_courses_r) || count($cidsf)) {
    } else {
        JLMSRedirect(sefRelToAbs("index.php?option={$option}&Itemid={$Itemid}&task=courses"));
    }
    $c_ids = array();
    foreach ($my_courses_r as $mcr) {
        $c_ids[] = $mcr->id;
    }
    $my_courses_r = array_merge($my_courses_r, $course_data_sf);
    if ($JLMS_CONFIG->get('frontpage_courses_tree', 0)) {
        $hp_items = 999999999;
    }
    $my_courses = array();
    $i = 0;
    while ($i < $hp_items && $i < count($my_courses_r)) {
        $my_courses[] = $my_courses_r[$i];
        $i++;
    }
    if (!is_array($c_ids)) {
        $c_ids = array(0);
    }
    $c_str = implode(',', $c_ids);
    if ($JLMS_CONFIG->get('frontpage_courses_tree', 0)) {
        //My_courses_tree
        $levellimit = 20;
        $query = "SELECT id, c_category as name, parent, 0 as is_course" . "\n FROM #__lms_course_cats ORDER BY c_category";
        $JLMS_DB->setQuery($query);
        $cats = $JLMS_DB->loadObjectList();
        $query = "SELECT a.id as user_certificate, b.course_id" . "\n FROM #__lms_certificate_users as a, #__lms_users_in_groups as b" . "\n WHERE 1" . "\n AND a.user_id = '" . $my->id . "'" . "\n AND a.crt_option = '1'" . "\n AND b.user_id = a.user_id AND a.course_id = b.course_id";
        $JLMS_DB->setQuery($query);
        $crtfs = $JLMS_DB->loadObjectList();
        $i = 0;
        foreach ($my_courses as $course) {
            $my_courses[$i]->certificate = 0;
            foreach ($crtfs as $crtf) {
                if ($course->id == $crtf->course_id && $crtf->user_certificate) {
                    $my_courses[$i]->certificate = 1;
                    break;
                }
            }
            $i++;
        }
        $children = array();
        foreach ($cats as $v) {
            $pt = $v->parent;
            /** Joomla 1.6 compability { */
            $v->parent_id = $v->parent;
            $v->title = $v->name;
            /** } Joomla 1.6 compability*/
            $list = @$children[$pt] ? $children[$pt] : array();
            array_push($list, $v);
            $children[$pt] = $list;
        }
        $cats = mosTreeRecurse(0, '', array(), $children, max(0, $levellimit - 1));
        $i = 0;
        $tmp_cats = array();
        foreach ($cats as $data) {
            $tmp_cats[$i] = $data;
            $i++;
        }
        $cats = array();
        $cats = $tmp_cats;
        //NEW
        $tmp = array();
        $last_catid = 0;
        foreach ($my_courses as $data) {
            if ($last_catid == 0 || $last_catid != $data->cat_id) {
                $last_catid = $data->cat_id;
            }
            $tmp[$last_catid][] = $data->id;
        }
        $for_not_empty = $tmp;
        //NEW
        $flms_course = array();
        if ($JLMS_CONFIG->get('flms_integration', 0)) {
            $query = "SELECT * FROM #__lmsf_courses";
            $JLMS_DB->setQuery($query);
            $flms_course = $JLMS_DB->loadObjectList();
        }
        $result_tree = array();
        $i = 0;
        while ($i < count($my_courses)) {
            $my_courses[$i]->c_id = $my_courses[$i]->id;
            $my_courses[$i]->id = -$my_courses[$i]->id;
            $i++;
        }
        foreach ($my_courses as $course) {
            $result_tree = new stdClass();
            $result_tree->c_id = $course->c_id;
            $result_tree->id = $course->id;
            $result_tree->parent = 0;
            $result_tree->name = $course->course_name;
            $result_tree->children = 0;
            $result_tree->is_course = 1;
            $result_tree->certificate = $course->certificate;
            $result_tree->ordering = $course->ordering;
            $position = 0;
            $i = 0;
            $level = 0;
            foreach ($cats as $cat) {
                if ($course->cat_id == $cat->id && $cat->parent == 0) {
                    $position = $i;
                    $result_tree->parent = $cat->id;
                }
                //				if ($cat->parent && isset($tmp_courses_cats[$course->c_id]) && count($tmp_courses_cats[$course->c_id]) && in_array($cat->id, $tmp_courses_cats[$course->c_id])) {
                if ($cat->parent && isset($for_not_empty[$cat->id]) && count($for_not_empty[$cat->id]) && in_array($course->c_id, $for_not_empty[$cat->id])) {
                    $position = $i;
                    $result_tree->parent = $cat->id;
                }
                $i++;
            }
            if ($position) {
                $new_cats = array();
                foreach ($cats as $cat) {
                    $new_cats[] = $cat;
                    if (count($new_cats) == $position + 1) {
                        //+1
                        $new_cats[] = $result_tree;
                    }
                }
                $cats = $new_cats;
            } else {
                $cats[] = $result_tree;
            }
        }
        $i = 0;
        while ($i < count($cats)) {
            $j = $i + 1;
            if ($cats[$i]->is_course) {
                while ($j < count($cats)) {
                    if (!$cats[$j]->is_course && $cats[$i]->parent == $cats[$j]->parent) {
                        $temp = new stdClass();
                        $temp = $cats[$j];
                        $cats[$j] = $cats[$i];
                        $cats[$i] = $temp;
                        break;
                    }
                    $j++;
                }
            }
            $i++;
        }
        $i = 0;
        while ($i < count($cats)) {
            $j = $i + 1;
            if ($cats[$i]->is_course) {
                while ($j < count($cats)) {
                    if ($cats[$j]->is_course && $cats[$i]->parent == $cats[$j]->parent) {
                        if ($JLMS_CONFIG->get('lms_courses_sortby', 0)) {
                            if ($cats[$j]->ordering < $cats[$i]->ordering) {
                                $temp = new stdClass();
                                $temp = $cats[$j];
                                $cats[$j] = $cats[$i];
                                $cats[$i] = $temp;
                            }
                        } else {
                            if (strcasecmp($cats[$j]->name, $cats[$i]->name) < 0) {
                                $temp = new stdClass();
                                $temp = $cats[$j];
                                $cats[$j] = $cats[$i];
                                $cats[$i] = $temp;
                            }
                        }
                    }
                    $j++;
                }
            }
            $i++;
        }
        $children = array();
        foreach ($cats as $v) {
            $pt = $v->parent;
            /** Joomla 1.6 compability { */
            $v->parent_id = $v->parent;
            $v->title = $v->name;
            /** } Joomla 1.6 compability*/
            $list = @$children[$pt] ? $children[$pt] : array();
            array_push($list, $v);
            $children[$pt] = $list;
        }
        $cats = mosTreeRecurse(0, '', array(), $children, max(0, $levellimit - 1));
        $tmp_cats_tmp = array();
        $i = 0;
        foreach ($cats as $cat) {
            $tmp_cats_tmp[$i] = $cat;
            $i++;
        }
        $cats = $tmp_cats_tmp;
        foreach ($cats as $key => $data) {
            $cats[$key]->exist_courses = 0;
            if ($data->is_course) {
                $catid = $data->parent;
                $i = $key;
                while ($i >= 0) {
                    if ($cats[$i]->id == $catid) {
                        $cats[$i]->exist_courses = 1;
                        $catid = $cats[$i]->parent;
                    }
                    $i--;
                }
            }
        }
        $tmp_cats = array();
        $i = 0;
        $lists['keep_flesson'] = 0;
        $tmp_data = array();
        foreach ($cats as $key => $data) {
            $tmp_data[$key] = $data;
            unset($tmp_data[$key]->treename);
            $tmp_data[$key]->folder_flag = 0;
            if ($data->children) {
                $tmp_data[$key]->folder_flag = 1;
            }
            $tmp_data[$key]->parent_id = $data->parent;
            $tmp_data[$key]->doc_name = $data->name;
            $tmp_data[$key]->ordering = $i;
            foreach ($flms_course as $f_course) {
                if ($data->is_course && abs($data->id) == $f_course->course_id && $f_course->type_lesson == 2) {
                    if ($f_course->like_theory) {
                        $f_course->pf_time = 0;
                        $f_course->pm_time = $f_course->theory_duration_time;
                    }
                    $pf_time_h = str_pad(floor($f_course->pf_time / 60), 2, "0", STR_PAD_LEFT);
                    $pf_time_m = str_pad($f_course->pf_time - $pf_time_h * 60, 2, "0", STR_PAD_LEFT);
                    $pf_time = $pf_time_h . ':' . $pf_time_m;
                    $pm_time_h = str_pad(floor($f_course->pm_time / 60), 2, "0", STR_PAD_LEFT);
                    $pm_time_m = str_pad($f_course->pm_time - $pm_time_h * 60, 2, "0", STR_PAD_LEFT);
                    $pm_time = $pm_time_h . ':' . $pm_time_m;
                    $pre_total_time = $f_course->pf_time + $f_course->pm_time;
                    $total_time_h = str_pad(floor($pre_total_time / 60), 2, "0", STR_PAD_LEFT);
                    $total_time_m = str_pad($pre_total_time - $total_time_h * 60, 2, "0", STR_PAD_LEFT);
                    $total_time = $total_time_h . ':' . $total_time_m;
                    $tmp_data[$key]->lesson_type = $f_course->type_lesson;
                    $tmp_data[$key]->pf_time = $pf_time;
                    $tmp_data[$key]->pm_time = $pm_time;
                    $tmp_data[$key]->total_time = $total_time;
                    $lists['keep_flesson'] = 1;
                } else {
                    if ($data->is_course && abs($data->id) == $f_course->course_id) {
                        $tmp_data[$key]->lesson_type = $f_course->type_lesson;
                    }
                }
            }
            if ($JLMS_CONFIG->get('multicat_no_display_empty', 1)) {
                //				if($data->is_course == 0 && $data->children && isset($tmp_cats_courses[$data->id]) && count($tmp_cats_courses[$data->id]) ){
                //				if($data->is_course == 0 && $data->children && $data->exist_courses ){
                if ($data->is_course == 0 && $data->children && $data->exist_courses) {
                    $tmp_cats[$i] = $tmp_data[$key];
                    $i++;
                } else {
                    if ($data->is_course && $data->children == 0) {
                        $tmp_cats[$i] = $tmp_data[$key];
                        $i++;
                    }
                }
            } else {
                $tmp_cats[$i] = $tmp_data[$key];
                $i++;
            }
        }
        $cats = $tmp_cats;
        $cats = JLMS_GetTreeStructure($cats);
        $my_courses = $cats;
        $hp_items = $JLMS_CONFIG->get('homepage_items');
    }
    //notices teacher
    if ($JLMS_CONFIG->get('frontpage_notices_teacher')) {
        $lists['my_notices'] = array();
        $hp_items = $JLMS_CONFIG->get('homepage_items');
        $query = "SELECT * " . "\n FROM #__lms_page_notices" . "\n WHERE usr_id = '" . $my->id . "'" . "\n ORDER BY data DESC" . "\n LIMIT 0,{$hp_items}";
        $JLMS_DB->setQuery($query);
        $lists['my_notices'] = $JLMS_DB->loadObjectList();
    }
    //dropbox
    $my_dropbox = array();
    if ($JLMS_CONFIG->get('frontpage_dropbox')) {
        $my_dropbox = my_dropboxes($c_str, $hp_items, $my->id);
    }
    $lists['dropbox_total'] = my_dropboxes_total($c_str, $my->id);
    $lists['dropbox_total_new'] = my_dropboxes_total_new($c_str, $my->id);
    //homework
    $my_hw = array();
    if ($JLMS_CONFIG->get('frontpage_homework')) {
        $my_hw = my_homeworks($c_str, $hp_items, $my->id);
        //		$members = "'0'";
        //		$where = '';
        //		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);
        //				$groups_where_isset_user = JLMS_ACL_HELPER::GetUserGlobalGroup($my->id);
        //
        //				$groups_where_admin_manager = array_merge($groups_where_admin_manager,$groups_where_isset_user);
        //
        //				if (count($groups_where_admin_manager)) {
        //					$where .= "\n AND ( `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 )";
        //				}
        //			}
        //		}
        //		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";
        //				$JLMS_DB->setQuery($query);
        //				$temp1 = $JLMS_DB->loadResultArray();
        //
        //				$query = "select subgroup1_id FROM #__lms_users_in_global_groups WHERE user_id = '".$my->id."'";
        //				$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 (( `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 (`groups` = '' OR `groups` IS NULL))";
        //				}
        //		}
        //
        //
        //		$query = "SELECT a.*, b.course_name, d.hw_status, c.user_id as stu_id, e.user_id as teach_id"
        //		. "\n FROM (#__lms_homework as a, #__lms_courses as b)"
        //		. "\n LEFT JOIN #__lms_users_in_groups as c ON c.user_id = '".$my->id."' AND c.course_id = b.id"
        //		. "\n LEFT JOIN #__lms_homework_results as d ON d.course_id = b.id AND d.user_id = c.user_id AND d.hw_id = a.id"
        //		. "\n LEFT JOIN #__lms_user_courses as e ON e.course_id = b.id AND e.user_id = '".$my->id."'"
        //		. "\n WHERE a.course_id IN ($c_str) AND a.course_id = b.id AND a.end_date >= '".date('Y-m-d',time())."'"
        //		.$where
        //		. "\n LIMIT 0, $hp_items"
        //		;
        //		$JLMS_DB->SetQuery( $query );
        //		$my_hw = $JLMS_DB->LoadObjectList();
    }
    //announcements
    $my_announcements = array();
    if ($JLMS_CONFIG->get('frontpage_announcements')) {
        $my_announcements = my_announcements($c_str, $hp_items, $my->id);
    }
    //mailbox
    $my_mailbox = array();
    if ($JLMS_CONFIG->get('frontpage_mailbox')) {
        $my_mailbox = my_mailbox($c_str, $hp_items, $my->id);
    }
    //certificates
    $my_certificates = array();
    if ($JLMS_CONFIG->get('frontpage_certificates')) {
        $my_certificates = my_certificates($c_str, $hp_items, $my->id);
    }
    //latest forum posts
    $latest_forum_posts = array();
    if ($JLMS_CONFIG->get('frontpage_latest_forum_posts')) {
        $latest_forum_posts = latest_forum_posts($c_str, $hp_items, $my->id);
    }
    $lists['homepage_text'] = $JLMS_CONFIG->get('frontpage_text');
    //end
    JLMS_ShowHeading($JLMS_CONFIG->get('jlms_heading'), false);
    joomla_lms_html::showMainPage_front($option, $lists, $my_courses, $my_dropbox, $my_hw, $my_announcements, $my_mailbox, $my_certificates, $latest_forum_posts);
}