<?php

/**
 * 
 * 本类为首页展示类
 * @author 杨金球
 *
 */
class AdminAction extends CommonAction {

    public function index() {
        $this->display();
    }

    //首页顶部
    public function top() {
        //dump($_SESSION);
        $this->assign('user', $_SESSION);
        $this->display();
    }

    //首页左侧菜单
    public function menu() {
        $menu = M('menu');
        
        $menu_list = $menu->field('id, name, path, pid')->where('pid=0')->order('id ASC')->select();
        
        $this->assign('menu',$menu_list);
        if (isset($_SESSION['flag']) && $_SESSION['flag'] == 1) {
            $this->assign('admin', 'admin');
        }
        $this->display();
    }

    //站点地图
    public function sitemap() {
        $id = isset($_GET['id']) ? $_GET['id'] : 0;
        $sitemap = '<a onclick="$(\'#main\').load(\'__URL__/main\'); $(\'#sitemap\').load(\'__URL__/sitemap\')">蓝点市场</a>';

        if ($id != 0) {
            if ($id == 100) {
				$sitemap .= ' &gt; <a onclick="$(\'#main\').load(\'' . __GROUP__ . '/Administrator/\'); $(\'#sitemap\').load(\'__URL__/sitemap&id=100\')">管理员管理</a>';
            } else {
                $map['id'] = $id;

                $menu = M('menu');
                $menu_msg = $menu->field('id, name, path')->where($map)->find();

                $sitemap .= ' &gt; <a onclick="$(\'#main\').load(\'' . $menu_msg['path'] . '\'); $(\'#sitemap\').load(\'__URL__/sitemap&id=' . $menu_msg['id'] . '\')">' . $menu_msg['name'] . '</a>';
            }
        }
        $this->assign('sitemap', $sitemap);
        $this->display();
    }

    //首页主要区域
    public function main() {
         //增加服务器信息显示 By 吴远 /Home/Common/Common.php
		$systemMsg=systemMsg(); 
		$this->assign('systemMsg', $systemMsg);
		$this->display();
    }

    //修改密码
    public function pwd() {
        $this->display();
    }

    //修改密码操作
    public function changePwd() {
        $map['id'] = $_SESSION['adminID'];
        $map['pwd'] = md5(substr(md5($_POST['pwd']), 0, 16));

        $admin = M('admin');
        if (!$admin->where($map)->find()) {
            $this->ajaxReturn('', '', 2);
        } else {
            $map['pwd'] = md5(substr(md5($_POST['newPwd']), 0, 16));
            if (!$admin->save($map)) {
                $this->ajaxReturn('', '', 0);
            } else {
                $this->ajaxReturn('', '', 1);
            }
        }
    }

}