<?php

namespace web\admin;

class manage {
    public static function json_init() {
        global $db;
        $rsuser = verifyfast();
        $csql = new \ciy\sql('zc_icon');
        $csql->where('icontarget', 10);
        $csql->column('targetid as id,icon');
        $ret['icon'] = $db->get($csql);
        $csql = new \ciy\sql('zc_menu');
        $csql->where('isuse', 1)->order('csort desc,id')->column('id,upid,name,url,pow');
        $ret['menu'] = $db->get($csql);
        if (count($ret['menu']) == 0)
            $ret['menu'][] = array('id' => 2, 'upid' => 0, 'name' => '您无任何菜单权限', 'url' => '', 'pow' => '', 'csort' => 0);

        $csql = new \ciy\sql('zc_mnufav');
        $csql->where('user', $rsuser['id']);
        $csql->column('menuid');
        $ret['mnufav'] = $db->get($csql);
        $ret['welcome'] = array('url' => 'welcome.html', 'name' => '控制台');
        $ret['title'] = 'Ciyon SaaS总控台';
        return succjson($ret);
    }
    public static function json_favadd() {
        global $db;
        $rsuser = verifyfast();
        $post = new \ciy\post();
        $menuid = $post->getint('id');
        $csql = new \ciy\sql('zc_mnufav');
        $csql->where('user', $rsuser['id']);
        $csql->where('menuid', $menuid);
        $favrow = $db->getone($csql);
        if (!is_array($favrow)) {
            $updata = array();
            $updata['user'] = $rsuser['id'];
            $updata['menuid'] = $menuid;
            $updata['addtimes'] = tostamp();
            $csql = new \ciy\sql('zc_mnufav');
            $db->insert($csql, $updata);
        }
        return succjson();
    }
    public static function json_favdel() {
        global $db;
        $rsuser = verifyfast();
        $post = new \ciy\post();
        $menuid = $post->getint('id');
        $csql = new \ciy\sql('zc_mnufav');
        $csql->where('user', $rsuser['id']);
        $csql->where('menuid', $menuid);
        $db->delete($csql);
        return succjson();
    }
    public static function json_setssh() {
        global $db;
        $rsuser = verifyfast();
        if (nopower($db, $rsuser['id'], 'x1ssh'))
            return errjson('您未被授权操作');
        $post = new \ciy\post();
        $able = $post->getbool('able');  //true，打开SSH允许远程访问。   false，关闭防火墙禁止访问
        if ($able) {
            //开启后，需定时关闭防火墙
        }
        return succjson();
    }
}
