<?php
session_start();
if ($_SESSION['login']!="ok") {
	echo "<script language='javascript'>";
	echo " location='./';";
	echo "</script>";
}
?>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>后台管理</title>
        <link rel="stylesheet" type="text/css" href="lib/ext/resources/css/ext-all.css"/>
        <link rel="stylesheet" type="text/css" href="css/main.css"/>
        <script type="text/javascript" src="lib/ext/adapter/ext/ext-base.js">
        </script>
        <script type="text/javascript" src="lib/ext/ext-all.js">
        </script>
        <script type="text/javascript">
            Ext.BLANK_IMAGE_URL = 'img/s.gif';
        </script>
        <style type="text/css">
         <!--
        
        .STYLE1 {
            font-size: 12px
        }
        -->
        </style>
    </head>
    <body>
        <div id="loading-mask" style="">
        </div>
        <div id="loading">
            <div class="loading-indicator">
                <img src="img/extanim32.gif" width="32" height="32" style="margin-right:8px;" align="absmiddle"/>Loading...
            </div>
        </div>
        <script>
            //设置超链接渲染方式
            function showUrl(value){
                return "<a href='" + value + "' target='_blank'>" + value + "</a>";
            }
            Ext.onReady(function(){
                //创建tab                
                var tabpanel = new Ext.TabPanel({
                    region: 'center',
                    deferredRender: false,
                    activeTab: 0,
                    resizeTabs: true, // turn on tab resizing
                    minTabWidth: 115,
                    tabWidth: 135,
                    activeTab: 0,
                    enableTabScroll: true
                });
                tabpanel.add(new Ext.Panel({
                    title: "说明",
                    el: 'shuoming'
                }));
                //创建body渲染
                new Ext.Viewport({
                    layout: "border",
                    items: [new Ext.BoxComponent({
                        region: 'north',
                        el: 'north',
                        height: 30
                    }), new Ext.BoxComponent({
                        region: 'south',
                        el: 'south',
                        height: 25
                    }), {
                        region: 'west',
                        id: 'west-panel',
                        split: true,
                        width: 200,
                        minSize: 175,
                        maxSize: 400,
                        margins: '0 0 0 0',
                        layout: 'accordion',
                        title: '系统菜单',
                        collapseMode: 'mini',
                        collapsible: true,
                        layoutConfig: {
                            animate: true
                        },
                        items: [{
                            title: '网站管理',
                            border: false,
                            html: '<div id="tree-div" style="overflow:auto;width:100%;height:100%"></div>'
                            //iconCls:'nav',
                            //icon:'date_next.png'
                        }]
                    }, tabpanel]
                });
                //树菜单开始
                var Tree = Ext.tree;
                // set the root node
                var root = new Tree.AsyncTreeNode({
                    text: 'Ext JS',
                    draggable: false,
                    id: 'root'
                });
                
                var tree = new Tree.TreePanel({
                    el: 'tree-div',
                    autoScroll: true,
                    root: root,
                    animate: true,
                    enableDD: false,
                    border: false,
                    rootVisible: false,
                    containerScroll: true,
                    loader: new Tree.TreeLoader({
                        dataUrl: 'treedata.php'
                    })
                });
                tree.setRootNode(root);
                // render the tree
                tree.render();
                root.expand();
                tree.on('click', treeClick);
                //设置树的点击事件
                function treeClick(node, e){
                    if (node.isLeaf()) {
                        e.stopEvent();
                        var n = tabpanel.getComponent(node.id);
                        var k = tabpanel.find('title', node.text);
                        if (!n && node.id == "webmag" && k == '') {
                            //创建grid                            
                            var store = new Ext.data.JsonStore({
                                url: "_grid_json.php",
                                root: "results",
                                totalProperty: 'total',//这里从url返回结果中读取记录总数
                                fields: ["urlid", "webname", "weburl", "states", "key", "hot", "kind"]
                            });
                            var sm = new Ext.grid.CheckboxSelectionModel({//复选框申明
                                header: " ",
                                sortable: true,
                                width: 20
                            });
                            var colM = new Ext.grid.ColumnModel([sm, {
                                header: "ID",
                                dataIndex: "urlid",
                                sortable: true,
                                width: 40
                            }, {
                                header: "网站名称",
                                dataIndex: "webname",
                                sortable: true,
                                width: 150
                            }, {
                                header: "网址",
                                dataIndex: "weburl",
                                sortable: true,
                                renderer: showUrl,
                                width: 250
                            }, {
                                header: "状态",
                                dataIndex: "states",
                                sortable: true,
                                width: 60
                            }, {
                                header: "关键字",
                                dataIndex: "key",
                                sortable: true
                            }, {
                                header: "热度",
                                dataIndex: "hot",
                                sortable: true
                            }, {
                                header: "分类",
                                dataIndex: "kind",
                                sortable: true
                            }]);
                            
                            var tb_text = new Ext.Toolbar.TextItem("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");//创建一个空白区域
                            Ext.QuickTips.init();//开启表单提示
                            Ext.form.Field.prototype.msgTarget = 'side';//设置提示信息位置为边上                
                            var s_pannel = new Ext.FormPanel({
                                height: 20,
                                labelWidth: 50,
                                baseCls: 'x-plain',
                                defaults: {
                                    width: 150,
                                    height: 10
                                },
                                defaultType: 'textfield',
                                items: [{
                                    fieldLabel: '网站名称或关键字',
                                    id: 'title',
                                    name: 'title'
                                }]
                            });
                            //按分类收缩绑定数据源
                            var select_kind_count = new Ext.data.JsonStore({
                                url: "_select_kind.php?k=count",
                                fields: ['name', 'value'],
                                totalProperty: "total",
                                root: "results",
                                id: "name"
                            });
                            var select_kind = new Ext.data.JsonStore({
                                url: "_select_kind.php",
                                fields: ['name', 'value'],
                                totalProperty: "total",
                                root: "results",
                                id: "name"
                            });
                            var select_states = new Ext.data.JsonStore({
                                url: "_states.js",
                                fields: ['name', 'value'],
                                totalProperty: "total",
                                root: "result",
                                id: "name"
                            });
                            
                            function web_add(){//显示选择行   
                                Ext.form.Field.prototype.msgTarget = 'side';//设置提示信息位置为边上
                                var window_form_add = new Ext.FormPanel({//初始化表单面板
                                    id: 'window_form_add',
                                    name: 'window_form_add',
                                    labelWidth: 60, // 默认标签宽度板
                                    labelAlign: 'right',
                                    baseCls: 'x-plain',//不设置该值，表单将保持原样，设置后表单与窗体完全融合（-_-!!，说不清了，大家可以去掉运行下看看）
                                    bodyStyle: 'padding:5px 5px 0',
                                    width: 400,
                                    frame: true,
                                    //border: false,
                                    defaults: {
                                        width: 370,
                                        height: 150
                                    },
                                    defaultType: 'textfield',//默认字段类型
                                    items: [{
                                        xtype: 'fieldset',
                                        title: '网站基本信息',
                                        //checkboxToggle: true,
                                        defaults: {
                                            xtype: 'textfield',
                                            width: 200
                                        },
                                        items: [{
                                            name: 'webname',
                                            fieldLabel: '网站名称',
                                            allowBlank: false,
                                            blankText: '网站名称不能为空'
                                        
                                        }, {
                                            name: 'weburl',
                                            fieldLabel: '网站地址',
                                            allowBlank: false,
                                            blankText: '网站地址不能为空'
                                        }, {
                                            name: "key",
                                            fieldLabel: '关键字'
                                        }, {
                                            xtype: 'combo',
                                            name: 'kind',
                                            fieldLabel: '网站分类',
                                            displayField: 'name',
                                            valueField: 'value',
                                            store: select_kind,
                                            triggerAction: 'all',
                                            emptyText: '请选择分类...',
                                            selectOnFocus: true
                                        }, {
                                            xtype: 'combo',
                                            name: 'states',
                                            fieldLabel: '网站状态',
                                            displayField: 'name',
                                            valueField: 'value',
                                            store: select_states,
                                            triggerAction: 'all',
                                            emptyText: '请选择状态...',
                                            selectOnFocus: true
                                        }]
                                    }],
                                    buttons: [{
                                        text: '确定',
                                        handler: function(){//添加网站
                                            if (edit_widow.getComponent('window_form_add').form.isValid()) {
                                                edit_widow.getComponent('window_form_add').form.submit({
                                                    waitTitle: '请稍候',
                                                    waitMsg: '正在提交数据,请稍候....',
                                                    url: '_grid_web_submit.php?action=webadd',
                                                    method: 'POST',
                                                    success: function(form, action){
                                                        var Result = action.result.success;
                                                        if (Result == false) {
                                                            Ext.MessageBox.alert('提示', action.result.message);
                                                        }
                                                        else 
                                                            if (Result == true) {
                                                                Ext.MessageBox.alert('提示', action.result.message);
                                                                window_form_add.form.reset();
                                                                store.load({
                                                                    params: {
                                                                        start: 0,
                                                                        limit: 30
                                                                    }
                                                                });
                                                            }
                                                    },
                                                    failure: function(form, action){
                                                        Ext.MessageBox.alert('提示', action.result.message);
                                                        window_form_add.form.reset();
                                                    }
                                                    
                                                })
                                            }
                                        }
                                    }, {
                                        text: '取消',
                                        handler: function(){
                                            window_form_add.form.reset();
                                        }
                                    }]
                                });
                                var edit_widow = new Ext.Window({
                                    title: "添加记录",
                                    width: 400,
                                    height: 250,
                                    modal: true,
                                    maximizable: true,
                                    //minimizable: true,
                                    items: window_form_add
                                });
                                edit_widow.show();
                            }
                            
                            
                            function web_del(){//删除网站
                                var rows = grid.getSelectionModel().getSelections();
                                if (rows) {
                                    Ext.Msg.confirm("请确认", "是否真的删除这些记录吗?", function(butten, text){
                                        if (butten == "yes") {
                                            for (var i = 0; i < rows.length; i++) {
                                                Ext.Ajax.request({
                                                    url: '_grid_web_submit.php?action=webdel',
                                                    params: 'id=' + rows[i].get("urlid")
                                                });
                                            }
                                            store.load({
                                                params: {
                                                    start: 0,
                                                    limit: 30
                                                }
                                            });
                                        }
                                    });
                                    
                                }
                            }
                            store.load({
                                params: {
                                    start: 0,
                                    limit: 30
                                }
                            });
                            //这里设定每次加载前把搜索条件加上
                            store.on('beforeload', function(){
                                Ext.apply(this.baseParams, {
                                    title: Ext.get('title').dom.value
                                });
                            });
                            
                            function web_edit(){//修改网站记录
                                var rows = grid.getSelectionModel().getSelections();
                                if (rows) {
                                    //alert(rows.length);                        
                                    for (var i = 0; i < rows.length; i++) {
                                        Ext.form.Field.prototype.msgTarget = 'side';//设置提示信息位置为边上
                                        var window_form_edit = new Ext.FormPanel({//初始化表单面板
                                            id: 'window_form_edit',
                                            name: 'window_form_edit',
                                            labelWidth: 60, // 默认标签宽度板
                                            labelAlign: 'right',
                                            baseCls: 'x-plain',//不设置该值，表单将保持原样，设置后表单与窗体完全融合（-_-!!，说不清了，大家可以去掉运行下看看）
                                            bodyStyle: 'padding:5px 5px 0',
                                            width: 400,
                                            frame: true,
                                            //border: false,
                                            defaults: {
                                                width: 370,
                                                height: 150
                                            },
                                            defaultType: 'textfield',//默认字段类型
                                            items: [{
                                                xtype: 'fieldset',
                                                title: '网站基本信息',
                                                //checkboxToggle: true,
                                                defaults: {
                                                    xtype: 'textfield',
                                                    width: 200
                                                },
                                                items: [{
                                                    name: 'webid',
                                                    fieldLabel: 'ID',
                                                    xtype: 'hidden',
                                                    value: rows[i].get("urlid")
                                                }, {
                                                    name: 'webname',
                                                    fieldLabel: '网站名称',
                                                    allowBlank: false,
                                                    blankText: '网站名称不能为空',
                                                    value: rows[i].get("webname")
                                                }, {
                                                    name: 'weburl',
                                                    fieldLabel: '网站地址',
                                                    allowBlank: false,
                                                    blankText: '网站地址不能为空',
                                                    value: rows[i].get("weburl")
                                                }, {
                                                    name: "key",
                                                    fieldLabel: '关键字',
                                                    value: rows[i].get("key")
                                                }, {
                                                    xtype: 'combo',
                                                    name: 'kind',
                                                    fieldLabel: '网站分类',
                                                    displayField: 'name',
                                                    valueField: 'value',
                                                    store: select_kind,
                                                    triggerAction: 'all',
                                                    emptyText: '请选择分类...',
                                                    selectOnFocus: true,
                                                    value: rows[i].get("kind")
                                                }, {
                                                    xtype: 'combo',
                                                    name: 'states',
                                                    fieldLabel: '网站状态',
                                                    displayField: 'name',
                                                    valueField: 'value',
                                                    store: select_states,
                                                    triggerAction: 'all',
                                                    emptyText: '请选择状态...',
                                                    selectOnFocus: true,
                                                    value: rows[i].get("states")
                                                }]
                                            }],
                                            buttons: [{
                                                text: '确定',
                                                handler: function(){//修改表单提交函数
                                                    if (edit_widow.getComponent('window_form_edit').form.isValid()) {
                                                        edit_widow.getComponent('window_form_edit').form.submit({
                                                            url: '_grid_web_submit.php?action=webedit',
                                                            waitTitle: '提示',
                                                            method: 'POST',
                                                            waitMsg: '正在更新数据,请稍候...',
                                                            success: function(form, action){
                                                                var Result = action.result.success;
                                                                if (Result == false) {
                                                                    Ext.MessageBox.alert('提示', action.result.message);
                                                                }
                                                                else 
                                                                    if (Result == true) {
                                                                        Ext.MessageBox.alert('提示', action.result.message);
                                                                        window_form_edit.form.reset();
                                                                        function getCookie(objName){//获取指定名称的cookie的值
                                                                            var arrStr = document.cookie.split("; ");
                                                                            for (var i = 0; i < arrStr.length; i++) {
                                                                                var temp = arrStr[i].split("=");
                                                                                if (temp[0] == objName) 
                                                                                    return unescape(temp[1]);
                                                                            }
                                                                        }
                                                                        var _start = getCookie('_start');
                                                                        //var _start=Ext.state.CookieProvider();
                                                                        store.load({
                                                                            params: {
                                                                                start: _start,
                                                                                limit: 30
                                                                            }
                                                                        });
                                                                        edit_widow.close();
                                                                    }
                                                            },
                                                            failure: function(form, action){
                                                                Ext.MessageBox.alert('提示', action.result.message);
                                                                window_form_edit.form.reset();
                                                                
                                                                
                                                            }
                                                        });
                                                    }
                                                }
                                            }, {
                                                text: '取消',
                                                handler: function(){
                                                    edit_widow.close();
                                                }
                                            }]
                                        });
                                        var edit_widow = new Ext.Window({
                                            title: "修改记录--" + rows[i].get("webname") + "--网址--" + rows[i].get("weburl"),
                                            width: 400,
                                            height: 250,
                                            modal: true,
                                            maximizable: true,
                                            minimizable: true,
                                            items: window_form_edit
                                        });
                                        edit_widow.show();
                                    }
                                }
                            }
                            function web_pass(){
                                var rows = grid.getSelectionModel().getSelections();
                                if (rows) {
                                    Ext.Msg.confirm("请确认", "是否真的审核通过这些网站吗?", function(butten, text){
                                        if (butten == "yes") {
                                            for (var i = 0; i < rows.length; i++) {
                                                Ext.Ajax.request({
                                                    url: '_grid_web_submit.php?action=webpass',
                                                    params: 'id=' + rows[i].get("urlid")
                                                });
                                            }
                                            function getCookie(objName){//获取指定名称的cookie的值
                                                var arrStr = document.cookie.split("; ");
                                                for (var i = 0; i < arrStr.length; i++) {
                                                    var temp = arrStr[i].split("=");
                                                    if (temp[0] == objName) 
                                                        return unescape(temp[1]);
                                                }
                                            }
                                            var _start = getCookie('_start');
                                            store.load({
                                                params: {
                                                    start: _start,
                                                    limit: 30
                                                }
                                            });
                                        }
                                        
                                    })
                                    
                                }
                            }
                            var s_kind = new Ext.form.ComboBox({
                                xtype: 'combo',
                                name: 'kind',
                                id: 'kind_name',
                                fieldLabel: '网站分类',
                                displayField: 'name',
                                valueField: 'value',
                                store: select_kind_count,
                                triggerAction: 'all',
                                emptyText: '请选择分类...',
                                selectOnFocus: true,
                                editable: false
                            
                            });
                            var grid = new Ext.grid.GridPanel({
                                //renderTo: "web_list",//这里指定渲染到层的id
                                title: "网站列表",
                                id: 'webmag',
                                height: 680,
                                //width: 1200,
                                closable: true,
                                //icon:'img/chart_pie_link.png',
                                cm: colM,
                                loadMask: true,
                                store: store,
                                autoExpandColumn: 7,//这里指定扩充
                                tbar: [s_pannel,//搜索表单
                                {
                                    xtype: "tbseparator"
                                }, s_kind, {
                                    xtype: "tbseparator"
                                }, {
                                    text: '&nbsp;搜索',
                                    icon: "img/page_find.png",
                                    cls: "x-btn-text-icon",
                                    handler: function(){
                                        // if (s_pannel.form.isValid()) {
                                        //alert(s_kind.getValue());
                                        store.load({
                                            params: {
                                                start: 0,
                                                limit: 30,
                                                title: Ext.get('title').dom.value,//取得搜索表单文本域的值，发送到服务端
                                                kind: s_kind.getValue()
                                            }
                                        })
                                        //}
                                    }
                                }, {
                                    xtype: "tbseparator"
                                }, {
                                    text: "添加",
                                    icon: "img/chart_pie_add.png",
                                    cls: "x-btn-text-icon",
                                    handler: web_add
                                }, {
                                    xtype: "tbseparator"
                                }, {
                                    text: "修改",
                                    icon: "img/chart_pie_edit.png",
                                    cls: "x-btn-text-icon",
                                    handler: web_edit
                                }, {
                                    xtype: "tbseparator"
                                }, {
                                    text: "审核",
                                    icon: "img/chart_pie.png",
                                    cls: "x-btn-text-icon",
                                    handler: web_pass
                                }, {
                                    xtype: "tbseparator"
                                }, {
                                    text: "删除",
                                    icon: "img/chart_pie_delete.png",
                                    cls: "x-btn-text-icon",
                                    handler: web_del
                                }],
                                
                                bbar: new Ext.PagingToolbar({
                                    pageSize: 30,
                                    store: store,
                                    displayInfo: true,
                                    displayMsg: '当前 {0} 到 {1} 共 {2}',
                                    emptyMsg: "没有数据返回",
                                    items: null
                                })
                            });
                            function toggleDetails(btn, pressed){
                                var view = grid.getView();
                                view.showPreview = pressed;
                                view.refresh();
                            }
                            var n = tabpanel.add(grid);
                            
                            tabpanel.setActiveTab(n);
                        }
                        if (!n && node.id == "star" && k == '') {//星座管理tabpanel
                            //创建星座grid                            
                            var star_store = new Ext.data.JsonStore({
                                url: "_star_grid_json.php",
                                root: "results",
                                totalProperty: 'total',//这里从url返回结果中读取记录总数
                                fields: ["id", "value", "starshow", "time", "kind"]
                            });
                            var star_sm = new Ext.grid.CheckboxSelectionModel({//复选框申明
                                header: " ",
                                sortable: true,
                                width: 20
                            });
                            var star_colM = new Ext.grid.ColumnModel([star_sm, {
                                header: "ID",
                                dataIndex: "id",
                                sortable: true,
                                width: 40
                            }, {
                                header: "星座介绍",
                                dataIndex: "value",
                                sortable: true,
                                width: 300
                            }, {
                                header: "每日寄语",
                                dataIndex: "starshow",
                                sortable: true,
                                width: 400
                            }, {
                                header: "时间",
                                dataIndex: "time",
                                sortable: true,
                                width: 100
                            }, {
                                header: "星座",
                                dataIndex: "kind",
                                sortable: true
                            }]);
                            //创建搜索框
                            var d_pannel = new Ext.FormPanel({
                                height: 20,
                                labelWidth: 30,
                                baseCls: 'x-plain',
                                defaults: {
                                    width: 150,
                                    height: 10
                                },
                                defaultType: 'textfield',
                                items: [{
                                    fieldLabel: '日期',
                                    id: 'time',
                                    name: 'time'
                                    //allowBlank: false,//禁止为空
                                    //blankText: '搜索日期不能为空'
                                }]
                            });
                            //绑定分类数据源
                            var select_star_kind = new Ext.data.JsonStore({
                                url: "_select_star_kind.js",
                                fields: ['name', 'value'],
                                totalProperty: "total",
                                root: "result",
                                id: "name"
                            });
                            //创建分类下拉选项框
                            var k_kind = new Ext.form.ComboBox({
                                xtype: 'combo',
                                name: 'kind',
                                id: 'star_kind_name',
                                fieldLabel: '星座分类',
                                displayField: 'name',
                                valueField: 'value',
                                store: select_star_kind,
                                triggerAction: 'all',
                                emptyText: '请选择分类...',
                                selectOnFocus: true,
                                editable: false
                            
                            });
                            //创建tab内容
                            var star_grid = new Ext.grid.GridPanel({
                                title: "星座管理",
                                id: 'star',
                                cm: star_colM,
                                loadMask: true,
                                closable: true,
                                store: star_store,
                                tbar: [d_pannel, {
                                    xtype: "tbseparator"
                                }, k_kind, {
                                    xtype: "tbseparator"
                                }, {
                                    text: '&nbsp;搜索',
                                    icon: "img/page_find.png",
                                    cls: "x-btn-text-icon",
                                    handler: function(){
                                        star_store.load({
                                            params: {
                                                start: 0,
                                                limit: 30,
                                                time: Ext.get('time').dom.value,//取得搜索表单文本域的值，发送到服务端
                                                kind: k_kind.getValue()
                                            }
                                        })
                                    }
                                    
                                }, {
                                    xtype: "tbseparator"
                                }, {
                                    text: '添加',
                                    icon: "img/chart_pie_add.png",
                                    cls: "x-btn-text-icon",
                                    handler: function(){
                                        Ext.QuickTips.init();//开启表单提示
                                        var star_form = new Ext.FormPanel({
                                            id: 'star_form',
                                            name: 'star_form',
                                            labelWidth: 60, // 默认标签宽度板
                                            labelAlign: 'right',
                                            baseCls: 'x-plain',//不设置该值，表单将保持原样，设置后表单与窗体完全融合（-_-!!，说不清了，大家可以去掉运行下看看）
                                            bodyStyle: 'padding:5px 5px 0',
                                            width: 600,
                                            frame: true,
                                            //border: false,
                                            defaults: {
                                                width: 575,
                                                height: 150
                                            },
                                            defaultType: 'textfield',//默认字段类型
                                            items: [{
                                                xtype: 'fieldset',
                                                title: '网站基本信息',
                                                width: 575,
                                                height: 100,//区域高度
                                                //checkboxToggle: true,
                                                defaults: {
                                                    xtype: 'textfield',
                                                    width: 150
                                                },
                                                items: [{
                                                    name: 'star_time',
                                                    fieldLabel: '显示日期',
                                                    allowBlank: false,
                                                    blankText: '显示日期不能为空'
                                                
                                                }, {
                                                    xtype: 'combo',
                                                    name: 'star_kind',
                                                    fieldLabel: '星座分类',
                                                    displayField: 'name',
                                                    valueField: 'value',
                                                    store: select_star_kind,
                                                    triggerAction: 'all',
                                                    emptyText: '请选择分类...',
                                                    selectOnFocus: true
                                                }]
                                            }, {
                                                xtype: 'fieldset',
                                                title: '星座简介',
                                                height: 160,
                                                items: {
                                                    xtype: 'htmleditor',
                                                    name: 'star_info',
                                                    hideLabel: true,
                                                    width: 550,
                                                    height: 150
                                                }
                                            }, {
                                                xtype: 'fieldset',
                                                title: '每日寄语',
                                                height: 160,
                                                items: {
                                                    xtype: 'htmleditor',
                                                    name: 'star_show',
                                                    hideLabel: true,
                                                    width: 550,
                                                    height: 150
                                                }
                                            }],
                                            buttons: [{
                                                text: '确定',
                                                handler: function(){//添加网站
                                                    if (star_add_win.getComponent('star_form').form.isValid()) {
                                                        star_add_win.getComponent('star_form').form.submit({
                                                            waitTitle: '请稍候',
                                                            waitMsg: '正在提交数据,请稍候....',
                                                            url: '_grid_web_submit.php?action=staradd',
                                                            method: 'POST',
                                                            success: function(form, action){
                                                                var Result = action.result.success;
                                                                if (Result == true) {
                                                                    Ext.MessageBox.alert('提示', action.result.message);
                                                                    window_form_add.form.reset();
                                                                    star_store.load({
                                                                        params: {
                                                                            start: 0,
                                                                            limit: 30
                                                                        }
                                                                    });
                                                                }
                                                                else {
                                                                    Ext.MessageBox.alert('提示', action.result.message);
                                                                }
                                                            },
                                                            failure: function(form, action){
                                                                Ext.MessageBox.alert('提示', action.result.message);
                                                                window_form_add.form.reset();
                                                            }
                                                            
                                                        })
                                                    }
                                                }
                                            }, {
                                                text: '取消',
                                                handler: function(){
                                                    star_form.form.reset();
                                                }
                                            }]
                                        });
                                        var star_add_win = new Ext.Window({
                                            title: "添加记录",
                                            width: 600,
                                            height: 580,
                                            modal: true,
                                            maximizable: true,
                                            items: star_form
                                        });
                                        star_add_win.show();
                                    }
                                }, {
                                    xtype: "tbseparator"
                                }, {
                                    text: '修改',
                                    icon: "img/chart_pie_add.png",
                                    cls: "x-btn-text-icon",
                                    handler: function(){
                                        Ext.QuickTips.init();//开启表单提示
                                        var row = star_grid.getSelectionModel().getSelections();
                                        if (row) {
                                            for (var i = 0; i < row.length; i++) {
                                                Ext.form.Field.prototype.msgTarget = 'side';//设置提示信息位置为边上
                                                var star_edit_form = new Ext.FormPanel({
                                                    id: 'star_edit_form',
                                                    name: 'star_edit_form',
                                                    labelWidth: 60, // 默认标签宽度板
                                                    labelAlign: 'right',
                                                    baseCls: 'x-plain',
                                                    bodyStyle: 'padding:5px 5px 0',
                                                    width: 600,
                                                    frame: true,
                                                    //border: false,
                                                    defaults: {
                                                        width: 575,
                                                        height: 150
                                                    },
                                                    defaultType: 'textfield',//默认字段类型
                                                    items: [{
                                                        xtype: 'fieldset',
                                                        title: '网站基本信息',
                                                        width: 575,
                                                        height: 100,//区域高度
                                                        //checkboxToggle: true,
                                                        defaults: {
                                                            xtype: 'textfield',
                                                            width: 150
                                                        },
                                                        items: [{
                                                            xtype: 'hidden',
                                                            name: 'id',
                                                            value: row[i].get("id")
                                                        }, {
                                                            name: 'star_time',
                                                            fieldLabel: '显示日期',
                                                            allowBlank: false,
                                                            blankText: '显示日期不能为空',
                                                            value: row[i].get("time")
                                                        }, {
                                                            xtype: 'combo',
                                                            name: 'star_kind',
                                                            fieldLabel: '星座分类',
                                                            displayField: 'name',
                                                            valueField: 'value',
                                                            store: select_star_kind,
                                                            triggerAction: 'all',
                                                            emptyText: '请选择分类...',
                                                            selectOnFocus: true,
                                                            value: row[i].get("kind")
                                                        }]
                                                    }, {
                                                        xtype: 'fieldset',
                                                        title: '星座简介',
                                                        height: 160,
                                                        items: {
                                                            xtype: 'htmleditor',
                                                            name: 'star_info',
                                                            hideLabel: true,
                                                            width: 550,
                                                            height: 150,
                                                            value: row[i].get("value")
                                                        }
                                                    }, {
                                                        xtype: 'fieldset',
                                                        title: '每日寄语',
                                                        height: 160,
                                                        items: {
                                                            xtype: 'htmleditor',
                                                            name: 'star_show',
                                                            hideLabel: true,
                                                            width: 550,
                                                            height: 150,
                                                            value: row[i].get("starshow")
                                                        }
                                                    }],
                                                    buttons: [{
                                                        text: '确定',
                                                        handler: function(){//添加网站
                                                            if (star_edit_win.getComponent('star_edit_form').form.isValid()) {
                                                                star_edit_win.getComponent('star_edit_form').form.submit({
                                                                    waitTitle: '请稍候',
                                                                    waitMsg: '正在提交数据,请稍候....',
                                                                    url: '_grid_web_submit.php?action=staredit',
                                                                    method: 'POST',
                                                                    success: function(form, action){
                                                                        var Result = action.result.success;
                                                                        if (Result == true) {
                                                                            Ext.MessageBox.alert('提示', action.result.message);
                                                                            star_edit_form.form.reset();
                                                                            star_edit_win.close();
                                                                            star_store.load({
                                                                                params: {
                                                                                    start: 0,
                                                                                    limit: 30
                                                                                }
                                                                            });
                                                                        }
                                                                        else {
                                                                            Ext.MessageBox.alert('提示', action.result.message);
                                                                        }
                                                                    },
                                                                    failure: function(form, action){
                                                                        Ext.MessageBox.alert('提示', action.result.message);
                                                                        star_edit_form.form.reset();
                                                                    }
                                                                })
                                                            }
                                                        }
                                                    }, {
                                                        text: '取消',
                                                        handler: function(){
                                                            star_edit_form.form.reset();
                                                        }
                                                    }]
                                                });
                                                var star_edit_win = new Ext.Window({
                                                    title: "添加记录",
                                                    width: 600,
                                                    height: 580,
                                                    modal: true,
                                                    maximizable: true,
                                                    items: star_edit_form
                                                });
                                                star_edit_win.show();
                                            }
                                        }
                                    }
                                    
                                }, {
                                    xtype: "tbseparator"
                                }, {
                                    text: '删除',
                                    icon: "img/chart_pie_delete.png",
                                    cls: "x-btn-text-icon",
                                    handler: function(){
                                        var row = star_grid.getSelectionModel().getSelections();
                                        if (row) {
                                            Ext.Msg.confirm("请确认", "是否真的删除这些记录吗?", function(butten, text){
                                                if (butten == "yes") {
                                                    for (var i = 0; i < row.length; i++) {
                                                        Ext.Ajax.request({
                                                            url: '_grid_web_submit.php?action=stardel',
                                                            params: 'id=' + row[i].get("id")
                                                        });
                                                    }
                                                    star_store.load({
                                                        params: {
                                                            start: 0,
                                                            limit: 30
                                                        }
                                                    });
                                                }
                                            })
                                            
                                        }
                                    }
                                }],
                                bbar: new Ext.PagingToolbar({
                                    pageSize: 30,
                                    store: star_store,
                                    displayInfo: true,
                                    displayMsg: '当前 {0} 到 {1} 共 {2}',
                                    emptyMsg: "没有数据返回",
                                    items: null
                                })
                            });
                            star_store.load({
                                params: {
                                    start: 0,
                                    limit: 25
                                }
                            });
                            var star_grid_n = tabpanel.add(star_grid);
                            tabpanel.setActiveTab(star_grid_n);
                        }
                        if (!n && node.id == "webkind" && k == '') {
                            var kind_root = new Ext.tree.AsyncTreeNode({
                                id: '0',
                                text: '所有分类'
                            });
                            var data = new Ext.tree.TreeLoader({
                                url: '_tree_json.php'
                            });
                            var k_add_pannel = new Ext.FormPanel({//定义添加分类文本框
                                height: 20,
                                labelWidth: 50,
                                baseCls: 'x-plain',
                                defaults: {
                                    width: 150,
                                    height: 10
                                },
                                defaultType: 'textfield',
                                items: [{
                                    fieldLabel: '分类名称',
                                    id: 'kind',
                                    name: 'kind',
                                    allowBlank: false,//禁止为空
                                    blankText: '分类名称不能为空'
                                }]
                            });
                            var select_kind_add_count = new Ext.data.JsonStore({
                                url: "_select_kind.php?k=count",
                                fields: ['name', 'value'],
                                totalProperty: "total",
                                root: "results",
                                id: "name"
                            });
                            var s_add_kind = new Ext.form.ComboBox({
                                xtype: 'combo',
                                name: 'kind_add_name',
                                id: 'kind_add_name',
                                fieldLabel: '网站分类',
                                displayField: 'name',
                                valueField: 'value',
                                store: select_kind_add_count,
                                triggerAction: 'all',
                                emptyText: '请选择分类...',
                                selectOnFocus: true,
                                editable: false
                            
                            });
                            var kind_tree = new Ext.tree.TreePanel({
                                title: '网站分类树',
                                root: kind_root,
                                id: 'webkind',
                                closable: true,
                                enableDD: true,
                                ddScroll: true,
                                singleExpand: true,
                                loader: data,
                                tbar: [k_add_pannel, {
                                    xtype: 'tbseparator'
                                }, new Ext.Toolbar.TextItem("添加到"),{
                                    xtype: 'tbseparator'
                                },s_add_kind, {
                                    xtype: 'tbseparator'
                                }, {
                                    text: "添加",
                                    icon: "img/chart_pie_add.png",
                                    cls: "x-btn-text-icon",
                                    selModel: new Ext.tree.MultiSelectionModel(),
                                    handler: function(){
                                        if (k_add_pannel.form.isValid()) {
                                            Ext.Ajax.request({
                                                url: '_grid_web_submit.php?action=webkindadd',
                                                method: 'POST',
                                                params: 'kind_add_name=' + Ext.get('kind').dom.value + '&kind_name=' + s_add_kind.getValue(),
                                                success: function(response, options){
                                                    Ext.Msg.alert('提示', '添加成功!');
                                                    kind_tree.getRootNode().reload();
                                                    select_kind_add_count.load();
                                                    k_add_pannel.form.reset();
                                                },
                                                failure: function(response, options){
                                                    Ext.Msg.alert('提示', '添加失败!');
                                                }
                                            });
                                        }
                                    }
                                }, {
                                    xtype: 'tbseparator'
                                }, {
                                    text: "删除",
                                    icon: "img/chart_pie_delete.png",
                                    cls: "x-btn-text-icon",
                                    handler: function(){
										Ext.Msg.alert("警告","首先请确认你已经选了一个分类,如果没有选择默认为所有分类,将会删除所有记录!!!");
                                        var node_kind = kind_tree.getSelectionModel().getSelectedNode();
                                        if (node_kind) {
                                            Ext.Msg.confirm("请确认", "删除分类会将该分类的子类以及属于该类的网站一起删除,确定要删除吗?", function(butten, text){
                                                if (butten == "yes") {
                                                    Ext.Ajax.request({
                                                        url: '_grid_web_submit.php?action=kinddel',
                                                        params: 'id=' + node_kind.id,
                                                        success: function(response, options){
                                                            kind_tree.getRootNode().reload();
                                                            select_kind_add_count.load();
                                                        },
                                                        failure: function(){
                                                            Ext.Msg.alert("删除失败");
                                                        }
                                                    });
                                                }
                                            });
                                        }
                                    }
                                }],
                                width: 300
                            });
                            data.on('beforeload', function(treeLoader, node){
                                this.baseParams.id = node.attributes.id;
                            }, data);
                            tabpanel.add(kind_tree);
                            tabpanel.setActiveTab(kind_tree);
                        }
                        if (!n && node.id == "user_edit" && k == '') {//修改密码
                            Ext.QuickTips.init();//开启表单提示
                            Ext.form.Field.prototype.msgTarget = 'side';
                            var user_form = new Ext.form.FormPanel({
                                height: 20,
                                labelWidth: 80,
                                labelAlign: 'right',
                                baseCls: 'x-plain',
                                labelAlign: 'right',
                                baseCls: 'x-plain',
                                bodyStyle: 'padding:5px 3px 0',
                                defaultType: 'textfield',
                                items: [{
                                    xtype: 'fieldset',
                                    title: '以下内容要正确填写',
                                    defaults: {
                                        xtype: 'textfield',
                                        width: 200,
										height:20
                                    },
                                    items: [{
                                        fieldLabel: '原始用户名',
                                        id: 'user_name',
                                        name: 'user_name',
                                        allowBlank: false,
                                        blankText: '用户名不能为空'
                                    }, {
                                        fieldLabel: '用户名',
                                        id: 'new_user_name',
                                        name: 'new_user_name',
                                        allowBlank: false,
                                        blankText: '用户名不能为空'
                                    }, {
                                        fieldLabel: '原始密码',
                                        id: 'or_pass',
                                        name: 'or_pass',
                                        inputType: 'password',
										minLength:6,
										minLengthText:'密码不能小于6位',
                                        allowBlank: false,
                                        blankText: '原始密码不能为空'
                                    
                                    }, {
                                        fieldLabel: '密码',
                                        id: 'new_pass',
                                        name: 'new_pass',
                                        inputType: 'password',
										minLength:6,
										minLengthText:'密码不能小于6位',
                                        allowBlank: false,
                                        blankText: '密码不能为空'
                                    
                                    }, {
                                        fieldLabel: '重复密码',
                                        id: 'new_pass_rp',
                                        name: 'new_pass_rp',
                                        inputType: 'password',
										minLength:6,
										minLengthText:'密码不能小于6位',
                                        allowBlank: false,
                                        validator: function(){
                                            if (user_form.form.findField("new_pass").getValue() == user_form.form.findField("new_pass_rp").getValue()) 
                                                return true;
                                            else 
                                                return false;
                                        },
										invalidText :'密码不一致',
                                        blankText: '密码不能为空'
                                    
                                    }]
                                }],
                                buttons: [{
                                    text: '确定',
                                    handler: function(){
                                         if (user_form.form.isValid()){
										 	user_form.form.submit({
												waitTitle: '请稍候',
                                                waitMsg: '正在提交数据,请稍候....',
                                                url: '_grid_web_submit.php?action=user_edit',
                                                method: 'POST',
												success:function(form, action){
													var Result = action.result.success;
													if(Result==true){
														Ext.MessageBox.alert('提示', action.result.message);
														user_win.close();
													}else{
														Ext.MessageBox.alert('提示', action.result.message);
														user_form.form.reset();
													}
												},
												failure: function(form, action){
                                                     Ext.MessageBox.alert('提示', action.result.message);
                                                     user_form.form.reset();
                                                }
											});
										 }
                                    }
                                }, {
                                    text: '取消',
                                    handler: function(){
										user_win.close();
                                    }
                                }]
                            
                            });
                            var user_win = new Ext.Window({
                                title: '修改管理员资料',
                                width: 350,
                                height: 250,
                                modal: true,
                                items: user_form
                            });
                            user_win.show();
                        }
                        else {
                            tabpanel.setActiveTab(node.id);
                        }
                    }
                }
            });
            setTimeout(function(){
                Ext.get('loading').remove();
                Ext.get('loading-mask').fadeOut({
                    remove: true
                });
            }, 250);
        </script>
        <div id="shuoming">
            <p class="STYLE1">
                制作:<a href="http://www.jayboy.cn" target="_blank">脚本王子</a>
            </p>
        </div>
        <div id="north">
            <p class="api-title" align="center">
            <b>ee23.cn后台管理</b>
        </div>
        <div id="west">
        </div>
        <div id="south">
            <div style="float:left;margin:5px;font:normal 12px tahoma, arial, sans-serif, 宋体;">
                Power By: <span style="color:blue"><a href="http://www.jayboy.cn" target="_blank">脚本王子</a></span>
                &nbsp;
            </div>
            <div style="float:right;margin:5px;font:normal 12px tahoma, arial, sans-serif, 宋体;">
                版权所有：<a href="http://ee23.cn">ee23.cn</a>
            </div>
        </div>
    </body>
</html>
