<!DOCTYPE html>
<html class="no-js">
    <head>
        <title>Admin Home Page</title>
        <link href="<?= base_url().'/'; ?>theme/bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen">
        <link href="<?= base_url().'/'; ?>theme/bootstrap/css/bootstrap-responsive.min.css" rel="stylesheet" media="screen">
        <link href="<?= base_url().'/'; ?>theme/vendors/easypiechart/jquery.easy-pie-chart.css" rel="stylesheet" media="screen">
        <link href="<?= base_url().'/'; ?>theme/assets/styles.css" rel="stylesheet" media="screen">
        <link href="<?= base_url().'/'; ?>theme/vendors/uniform.default.css" rel="stylesheet" media="screen">

        <script src="<?= base_url().'/'; ?>theme/vendors/modernizr-2.6.2-respond-1.1.0.min.js"></script>
        <script src="<?= base_url().'/'; ?>theme/vendors/jquery-1.9.1.min.js"></script>
        <script src="<?= base_url().'/'; ?>theme/bootstrap/js/bootstrap.min.js"></script>
        <script src="<?= base_url().'/'; ?>js/jquery.cookie.js"></script>
        <script src="<?= base_url().'/'; ?>js/md5.min.js"></script>
    </head>
    
    <?php $data = $this->data; ?>
    <body style="padding-top:40px;">
        <div class="navbar navbar-fixed-top">
            <div class="navbar-inner">
                <div class="container-fluid">
                    <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse"> <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </a>
                    <a class="brand" href="#" onclick="gotoHome()">设备管理系统</a>
                    <div class="nav-collapse collapse">
                        <?php if($data["userInfo"] != []){ ?>
                        <ul class="nav pull-right">
                            <a href="#"><span class="badge badge-important pull-right" style="position: absolute;left: 25px;top: 1px;padding: 1px 5px;z-index:100;" onclick="alertMes()">10</span></a>
                            <li class="dropdown">
                                <a href="#" role="button" class="dropdown-toggle" data-toggle="dropdown"> <i class="icon-user"></i> <?= $data["userInfo"]["nick"] ?>，你好！ <i class="caret"></i>

                                </a>
                                <ul class="dropdown-menu">
                                    <li>
                                        <a tabindex="-1" href="#">个人主页</a>
                                    </li>
                                    <li class="divider"></li>
                                    <li>
                                        <a tabindex="-1" onclick="logout()" >退出登录</a>

                                    </li>
                                </ul>
                            </li>
                        </ul>
                        <?php }else{ ?>
                            <ul class="nav" style="float:right;">
                            <li>
                                <a href="<?= base_url().'/'; ?>sign/loginPage" role="button" class="dropdown-toggle"> <i class="icon-user"></i> 登录 </a>
                            </li>
                        </ul>
                        <?php } ?>
                        <ul class="nav">
                            <li class="active" style="padding:6px 0px;margin-top:4px;background:lightgray;border-radius:8px;">
                                <i class="hide-sidebar" style="padding:10px 20px;display:none;"><a class="icon-chevron-left" href='#' title="Hide Sidebar" rel='tooltip'>&nbsp;</a></i>
                                <i class="show-sidebar" style="display:none;padding:10px 20px;display:inline;"><a class="icon-chevron-right" href='#' title="Show Sidebar" rel='tooltip'>&nbsp;</a></i>
                            </li>
                            <li class="dropdown" style="margin-left:10px;">
                                <a href="#" role="button" class="dropdown-toggle" data-toggle="dropdown">功能 <i class="caret"></i>

                                </a>
                                <ul class="dropdown-menu">
                                    <li onclick="funcSwich(this)" id="switch_home" <?php if($data["uri"]["seg"][0] == "/" || $data["uri"]["seg"][0] == "home"){echo "class='active'";} ?>>
                                        <a tabindex="-1" href="#">首页</a>
                                    </li>
                                    <li onclick="funcSwich(this)" id="switch_devman" <?php if($data["uri"]["seg"][0] == "devManage"){echo "class='active'";} ?> >
                                        <a tabindex="-1" href="#">设备管理</a>
                                    </li>
                                    <li onclick="funcSwich(this)" id="switch_userman" <?php if($data["uri"]["seg"][0] == "userManage"){echo "class='active'";} ?>>
                                        <a tabindex="-1" href="#">用户管理</a>
                                    </li>
                                    <li onclick="funcSwich(this)" id="switch_orgman" <?php if($data["uri"]["seg"][0] == "orgManage"){echo "class='active'";} ?>>
                                        <a tabindex="-1" href="#">组织管理</a>
                                    </li>
                                    <li class="divider"></li>
                                    <li onclick="funcSwich(this)" id="switch_sysman" <?php if($data["uri"]["seg"][0] == "sysManage"){echo "class='active'";} ?>>
                                        <a tabindex="-1" href="#">系统设置</a>
                                    </li>
                                </ul>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>
        </div>

<script>
/*******************************************
 *     头部功能页面切换
 /******************************************/
function funcSwich(e){
    var id = $(e).attr("id");
    var host = window.location.host;
    var username = $.cookie('username');
    var token = $.cookie('token');
    if(username == undefined){
        username = "";
    }
    if(token == undefined){
        token = "";
    }
    if(id == "switch_home"){
        window.location.href = "http://" + host + "?username=" + username + "&token=" + token ;
    }else if(id == "switch_devman"){
        window.location.href = "http://" + host + "/devManage" + "?username=" + username + "&token=" + token ;
    }else if(id == "switch_userman"){
        window.location.href = "http://" + host + "/userManage" + "?username=" + username + "&token=" + token ;
    }else if(id == "switch_orgman"){
        window.location.href = "http://" + host + "/orgManage" + "?username=" + username + "&token=" + token ;
    }else if(id == "switch_sysman"){
        window.location.href = "http://" + host + "/sysManage" + "?username=" + username + "&token=" + token ;
    }
}

/* *************************************
 *       退出登录
************************************** */
function logout(){
    var username = $.cookie('username');
    var host = window.location.host;
    var url = "http://" + host + "/signCtr/logout"
    var postData = {};
    postData["username"] = username;
    $.ajax({
        url: url,
        data: JSON.stringify(postData),
        type: "POST",
        dataType: "json",
        contentType:"application/json",
        success: function(data) {
            if(data.status == "200"){
                $.removeCookie('username');
                $.removeCookie('token');
                window.location.href = "http://" + host + "/sign/loginPage";
            }else{
                alert(data.message);
            }
        }
    });
}

/* *************************************
 *       进入首页
************************************** */
function gotoHome(){
    var host = window.location.host;
    var username = $.cookie('username');
    var token = $.cookie('token');
    if(username == undefined){
        username = "";
    }
    if(token == undefined){
        token = "";
    }
    window.location.href = "http://" + host + "?username=" + username + "&token=" + token ;
}


function alertMes(){
    alert("你有10新消息！");
}

</script>
