<?php

/**
 * @author twttwt
 * @copyright 2009
 */
class admin
{
    function topmenu()
    {
        global $curl, $murl, $topmenu;
        if (!IS_ADMIN)
            return;
        foreach ($topmenu as $v)
        {
            $str .= '<li ' . ($murl == $v[0] ? 'class="current"' : '') . '><a href="' . url(RPG .
                $v[1] . '/' . $v[2] . '/') . '">' . htmlspecialchars($v[3]) . '</a></li>';
        }
        return $str;
    }
    function sidebarmenu()
    {
        global $user, $conf, $topmenu, $smenu, $curl, $murl;

        $emenu = array();
        foreach ($smenu as $k => $v)
        {
            if (!empty($conf['sys_teams'][$user['team']]['adminpvs'][$k]))
                $emenu[$k] = $v;
        }

        $m1 = array();
        foreach ($emenu as $v)
        {
            if ($v[1] <> $murl)
                continue;
            $m1[] = $v;
        }

        $m2 = array();
        foreach ($m1 as $v)
        {
            $m2[$v[2]][] = $v;
        }
        $str = '<ul>';
        foreach ($m2 as $k => $_v)
        {

            $str .= '<li>';
            $str .= '<h3>' . htmlspecialchars($k) . '</h3>';
            $str .= '<ul>';
            foreach ($_v as $v)
            {
                $win = !empty($v[7]);
                if (empty($v[6]))
                {
                    $url = url(RPG . $v[4] . '/' . $v[5] . '/' . ($win ? '?win' : ''));
                    $str .= '<li ' . ($v[0] == $curl ? 'class="current"' : '') . '><a ' . ($win ?
                        'class="win"' : '') . ' href="' . $url . '" >' . htmlspecialchars($v[3]) .
                        '</a></li>';
                } else
                {
                    $url = url(RPG . $v[4] . '/' . $v[5] . '/' . $v[6] . '/' . ($win ? '&win' : ''));
                    $str .= '<li ' . (($v[0] == $curl && $v[6] == A) ? 'class="current"' : '') .
                        '><a ' . ($win ? 'class="win"' : '') . ' href="' . $url . '" >' .
                        htmlspecialchars($v[3]) . '</a></li>';
                }
            }
            $str .= '</ul>';
            $str .= '</li>';
        }
        $str .= '</ul>';
        return $str;
    }
    function deldir($dirName)
    {
        if ($handle = @opendir($dirName))
        {
            while (false !== ($item = readdir($handle)))
            {
                if ($item != '.' && $item != '..')
                {
                    if (is_dir($dirName . '/' . $item))
                    {
                        deldir($dirName . '/' . $item);
                    } else
                    {
                        @unlink($dirName . '/' . $item);
                    }
                }
            }
            closedir($handle);
            return rmdir($dirName);
        } else
        {
            return false;
        }
    }
    function getPHPini($varName)
    {
        switch ($res = get_cfg_var($varName))
        {
            case 0:
                return 'NO';
                break;
            case 1:
                return 'YES';
                break;
            default:
                return $res;
                break;
        }
    }
}

?>