<?php
/**
 * 
 * @file head.php
 * @copyright (c) 2005 - 2011 eifr.com
 * @license http://www.gnu.org/copyleft/gpl.html gnu/gpl
 * eifr is free software
 */

require_once ('../../includes/inc_admin.php');
require_once(EIFR_ROOT . 'admin/mod_adminmenu/class_adminmenu.php');
$clComAdminmenu = new ComAdminmenu();

$issysadmin = Common::checkSysAdmin();

function isShowSystemInfo() {
    global $issysadmin;
    if ($issysadmin) {
        return true;
    } 
    require_once(EIFR_ROOT . 'admin/mod_adminmenu/acl_adminmenu.php');
    $clCAclAdminmenu = new CAclAdminmenu();
    $acls = $clCAclAdminmenu -> getUserAcls();
    foreach($acls as $key => $val) {
        if (substr($key, 0, 2) == '00')
            return true;
    } 

    return false;
} 

function getSoftNews($is_show_sysinfo = false) {
    global $db;

    $rtn = '';
    if (!$is_show_sysinfo)
        return $rtn;

    if (empty ($_SERVER['HTTP_HOST']))
        $web_url = $_SERVER['HTTP_HOST'];
    else
        $web_url = $_SERVER['SERVER_NAME'];
    $varvalue = '';
    $sql = "select * from " . TB_CONFIG . " where type=1 and varname='is_accept_soft_news' ";
    $rs = $db -> Execute($sql);
    $num = 0;
    if (!$rs -> EOF) {
        $varvalue = $rs -> fields['varvalue'];
    } 
    $rs -> Close();
    if (strtolower($varvalue) == 'true') {
        $rtn = SOFT_WEBURL . "/eifr_soft_news.php?lid=" . SOFT_LICENSE . "&vid=" . SOFT_VERSION . "&weburl=" . $web_url;
    } 

    return $rtn;
} 

function isSoftUpdate($is_show_sysinfo = false) {
    global $db;
    if (!$is_show_sysinfo)
        return false;
    $rtn = true;

    $sql = "select * from " . TB_CONFIG . " where type=1 and varname='is_accept_soft_update' ";
    $rs = $db -> Execute($sql);
    if (!$rs -> EOF) {
        $varvalue = $rs -> fields['varvalue'];
        if (strtolower($varvalue) == 'true')
            $rtn = true;
        else
            $rtn = false;
    } 
    $rs -> Close();

    return $rtn;
} 

function checkUpdate($name = '') {
    global $db;
    $rtn = false;
    if (defined('TB_SOFT_UPDATE')) {
        $sql = "select * from " . TB_SOFT_UPDATE . " where name='$name' "; 
        // echo $sql;
        $rs = $db -> Execute($sql);
        if (!$rs -> EOF) {
            $rtn = true;
        } else {
            $rtn = false;
        } 
        $rs -> Close();
    } 

    return $rtn;
} 

function showUpdateList() {
    $rtn = '';
    $folder = CFile::getRelativePath(DIR_INSTALL . "update/");
    if (is_dir($folder)) {
        $fp = opendir($folder);
        while (false !== $file = readdir($fp)) {
            if ($file != '.' && $file != '..') {
                $dirname = "$file";
                if (!checkUpdate($dirname)) {
                    $rtn .= "<script src='" . DIR_INSTALL . "update/$dirname/eifr_update.php' type='text/javascript'></script>";
                } 
            } 
        } 
        closedir($fp);
    } 
    return $rtn;
} 
// ---start---
$url = 'main/home.php';

$user_class = '';
if ($issysadmin) {
    $user_class = 'superadmin';
} else {
    require_once(EIFR_ROOT . 'admin/mod_user_class/class_user_class.php');
    if ($row = ComUserClass::getUserClassById(getCookie(COOKIE_USERCLASS))) {
        $user_class = $row['title'];
    }
}

$sys_charset = SYS_CHARSET;
$username = getCookie(COOKIE_USERNAME);
$phpversion = phpversion();
$register_globals = ini_get("register_globals") ? '<font color=green><b>√</b></font>' : '<font color=red><b>x</b></font>';
$post_max_size = ini_get("post_max_size");
$upload_max_filesize = ini_get("upload_max_filesize");
$allow_url_fopen = ini_get("allow_url_fopen") ? '<font color=green><b>√</b></font>' : '<font color=red><b>x</b></font>';
$soft_name = SOFT_NAME;
$soft_weburl = SOFT_WEBURL;
$soft_version = SOFT_VERSION;

$adminmenu_array = $clComAdminmenu -> getVisibleAdminmenusLevel1();
if (! $adminmenu_array) $adminmenu_array = array();

$is_show_sysinfo = isShowSystemInfo();
$eifr_soft_news = getSoftNews($is_show_sysinfo);

$eifr_soft_update = '';
if (isSoftUpdate($is_show_sysinfo))
    $eifr_soft_update = showUpdateList();

require_once (getAdminTemplatePath('home', $url));

?>
