<?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><a href="<?php echo $base->get_url(array('c' => 'database', 'cid' => $cid)); ?>">数据模型</a></li>
                <?php if ($up){?>
                <li><a href="<?php echo $base->get_url(array('c' => 'database', 'm' => 'fields', 'cid' => $cid, 'id' => $up['id'])); ?>">【<?php echo $up['mode'];?>】字段管理</a></li>
                <?php }?>
                <li>【<?php echo $db['mode'];?>】字段管理</li>
            </ul>
        </div>
        <div class="formbody">
            <div class="usual">
                <div class="tabson">
                    <div class="tools">
                        <ul class="toolbar">
                            <li class="click" onclick="location.href = '<?php echo $base->get_url(array('c' => 'database', 'm' => 'createField', 'cid' => $cid, 'tid' => $db['id'])); ?>';"><span><img src="<?php echo $base_url; ?>static/images/t01.png"></span>新增字段</li>
                            <li onclick="location.href = '<?php echo $base->get_url(array('c' => 'database', 'm' => 'childTable', 'cid' => $cid, 'tid' => $db['id'])); ?>';"><span><img src="<?php echo $base_url; ?>static/images/t05.png"></span>下级模型 (<?php echo $count;?>)</li>
                            <li onclick="location.href = '<?php echo $base->get_url(array('c' => 'database', 'm' => 'search', 'cid' => $cid, 'tid' => $db['id'])); ?>';"><span><img src="<?php echo $base_url; ?>static/images/t05.png"></span>筛选设置</li>
                        </ul>
                    </div>
                    <?php echo form::start('form1');?>
                    <?php echo form::nonce($admin['id'], 'sortField');?>
                    <?php echo form::input_hidden('tid', $db['id']);?>
                    <table class="tablelist">
                        <thead>
                            <tr>
                                <th width="100">ID</th>
                                <th>顺序</th>
                                <th>字段名</th>
                                <th width="40">必填</th>
                                <th width="40">列表</th>
                                <th width="40">筛选</th>
                                <th>简称</th>
                                <th>类型</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php
                            if ($fields){
                                foreach ($fields as $field){
                            ?>
                            <tr>
                                <td><?php echo $field['id'];?></td>
                                <td><input type="text" class="dfinput" name="sort[<?php echo $field['id'];?>]" style="width: 40px; height: 20px; line-height: 20px;" value="<?php echo $field['_orderby'];?>" /></td>
                                <td><?php echo $field['name'];?></td>
                                <td><?php echo $field['_must'] ? '√' : '';?></td>
                                <td><a class="tablelink" href="javascript:;" onclick="_view(<?php echo $field['id'];?>, $(this));"><?php echo $field['_view'] ? '√' : '&nbsp;&nbsp;&nbsp;&nbsp;';?></a></td>
                                <td><a class="tablelink" href="javascript:;" onclick="_soso(<?php echo $field['id'];?>, $(this));"><?php echo $field['_soso'] ? '√' : '&nbsp;&nbsp;&nbsp;&nbsp;';?></a></td>
                                <td><?php echo $field['tag'];?></td>
                                <td><?php echo $field['_form'];?></td>
                                <td>
                                    <a href="<?php echo $base->get_url(array('c' => 'database', 'm' => 'editField', 'cid' => $cid, 'tid' => $db['id'], 'id' => $field['id']));?>" class="tablelink">[编辑]</a>
                                    <a class="tablelink" href="javascript:;" onclick="_delete('<?php echo $field['name'];?>', '<?php echo $field['id'];?>');">[删除]</a>
                                </td>
                            </tr>
                            <?php
                                }
                            }
                            ?>
                        </tbody>
                    </table>
                    <?php if ($fields){?>                    
                    <div style="margin-top: 6px;"><input name="btn88" type="button" class="btn btn88" value="排序" style="background-image: none;background-color: #eee; border: 1px solid #ccc;border-radius: 4px; color: #555; width: 100px;"/></div>
                    <?php }?>
                    <?php echo form::end();?>
                    <?php echo form::onclick('form1', 'btn88', '排序', $base->get_url(array('c' => 'database', 'm' => 'sortField')), $base->get_url(array('c' => 'database', 'm' => 'fields', 'cid' => $cid, 'id' => $db['id'])));?>
                </div>
            </div>
        </div>
        <?php echo form::alert('deleteField', $base_url);?> 
        <?php echo form::alert_confirm('deleteField', $base->get_url(array('c' => 'database', 'm' => 'deleteField', 'cid' => $cid, 'id' => $db['id'])), form::create_nonce($admin['id'], 'deleteField'));?>
        <script>
            function _delete(name, id){
                $('.deleteField .tipright p').html('确认要删除 <font color="red">' + name + '</font> 吗?');
                $(".deleteField").fadeIn(200);
                $('#_id').val(id);
            }
            function _view(id, e){
                var that = e;
                $.post('<?php echo $base->get_url(array('c' => 'database', 'm' => 'changeView'));?>', {id: id}, function (_view){
                    var msg = _view == 1 ? '√' : '&nbsp;&nbsp;&nbsp;&nbsp;';
                    console.log(msg);
                    that.html(msg);
                });
            }
            function _soso(id, e){
                var that = e;
                $.post('<?php echo $base->get_url(array('c' => 'database', 'm' => 'changeSoso'));?>', {id: id}, function (_soso){
                    var msg = _soso == 1 ? '√' : '&nbsp;&nbsp;&nbsp;&nbsp;';
                    console.log(msg);
                    that.html(msg);
                });
            }
            $(function(){
                $('.tablelist tbody tr:odd').addClass('odd');                
            });
        </script>
    </body>
</html>
