<?php if (!defined('ROOT')){ echo 'Deny ...'; exit; } extract($data); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>MAIN</title>
        <link href="<?php echo $base_url; ?>static/css/style.css" rel="stylesheet" type="text/css" />
        <link href="<?php echo $base_url; ?>static/css/select.css" rel="stylesheet" type="text/css" />
        <script type="text/javascript" src="<?php echo $base_url; ?>static/js/jquery.js"></script>
        <script type="text/javascript" src="<?php echo $base_url; ?>static/js/select-ui.min.js"></script>
        <script type="text/javascript" src="<?php echo $base_url; ?>static/js/common.js"></script>
    </head>
    <body>
        <div class="place">
            <span>位置：</span>
            <ul class="placeul">
                <li><a href="<?php echo $base->get_url(array('c' => 'frame', 'm' => 'main')); ?>">首页</a></li>
                <li>数据模型</li>
            </ul>
        </div>
        <div class="formbody">
            <div class="usual">
                <div class="itab" style="margin: 12px 0px;">
                    <ul>
                        <?php                        
                        foreach ($channels as $c) {                            
                        ?>
                        <li><a href="<?php echo $base->get_url(array('c' => 'database', 'cid' => $c['id'])); ?>" class="<?php if ($c['id'] == $cid) { ?>selected<?php } ?>"><?php echo $c['name']; ?></a></li> 
                        <?php } ?>
                    </ul>
                </div>
                <ul class="seachform">
                    <?php
                        echo form::start('form1');
                        echo form::nonce($admin['id'], 'createTable');
                        echo form::input_hidden('cid', $cid);
                        echo form::input(array(
                            'title' => '数据表名',
                            'name' => 'table_name',
                            'must' => 1,
                            'placeholder' => '请输入字母',
                            'style' => 'width: 120px;',
                            'value' => '',
                            'readonly' => 0
                        ));
                        echo form::input(array(
                            'title' => '数据表简称',
                            'name' => 'table_tag',
                            'must' => 1,
                            'placeholder' => '请输入汉字',
                            'style' => 'width: 120px;',
                            'value' => '',
                            'readonly' => 0
                        ));                        
                        echo form::submit('新建数据表', 'btn88');
                        echo form::onclick('form1', 'btn88', '新建数据表', $base->get_url(array('c' => 'database', 'm' => 'createAJAX')), $base->get_url(array('c' => 'database', 'cid' => $cid)));
                    ?>
                    <li><input type="button" class="btn" value="生成模型" style="background-image: none;background-color: darkcyan;border-radius: 4px;" onclick="location.href = '<?php echo $base->get_url(array('c' => 'database', 'm' => 'createModels', 'cid' => $cid)); ?>';"/></li>
                </ul>
                <table class="tablelist">
                    <thead>
                        <tr>
                            <th>ID</th>
                            <th>表的简称</th>
                            <th>表名</th>
                            <th>管理</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php
                        if ($result['lists']) {
                            foreach ($result['lists'] as $item) {
                        ?>
                        <tr>
                            <td><?php echo $item['id'];?></td>
                            <td><?php echo $item['tag'];?></td>
                            <td><?php echo $item['full_name'];?></td>
                            <td><a class="tablelink" href="<?php echo $base->get_url(array('c' => 'database', 'm' => 'fields', 'cid' => $cid, 'id' => $item['id']));?>">[字段]</a></td>
                            <td>
                                <a href="javascript:;" class="tablelink" onclick="_delete(<?php echo $item['id'];?>, '<?php echo $item['full_name'];?>');">[删除]</a>
                            </td>
                        </tr>
                        <?php }}?>
                    </tbody>
                </table>
                <div style="margin-top: 12px;"><?php echo $result['pager']; ?><br style="clear: both;"/></div>
            </div>
        </div>
        <?php echo form::alert('deleteTable', $base_url);?>
        <?php echo form::alert_confirm('deleteTable', $base->get_url(array('c' => 'database', 'm' => 'deleteTable')), form::create_nonce($admin['id'], 'deleteTable'));?>
        <script>
            function _delete(id, name){
                $('.deleteTable .tipright p').html('确认要删除 <font color="red">' + name + '</font> 吗?');
                $(".deleteTable").fadeIn(200);
                $('#_id').val(id);                
            } 
            $(function(){
                $('.tablelist tbody tr:odd').addClass('odd');
            });
        </script>
    </body>
</html>
