<?php if (!defined('ROOT')){ echo 'Deny ...'; exit; } extract($data); ?>
<div class="place">
    <span>选择【<?php echo $table['tag'];?>】数据</span>
    <ul class="placeul" style="float:right;">
        <li onclick="_connect_window_close();" style="cursor: pointer; color: red; font-weight: bold;">[关闭]</li>
    </ul>
</div>
<div class="formbody" style="margin-top:10px;">
    <div class="usual">
        <input type="text" class="dfinput" id="find_the_key" value="<?php echo $key;?>" style="width: 180px;"/>
        <input type="button" class="btn" value="搜索" onclick="_connect_find('<?php echo $url;?>');"/>
        <input type="button" class="btn" value="确认选择" onclick="_connect_select(<?php echo $table['id'];?>, '<?php echo $base->get_url(array('c' => 'database', 'm' => 'ajaxFetch'));?>');" id="connect_select_btn" style="background-image: linear-gradient(to bottom,#fff 0,#e0e0e0 100%);border:1px solid #ccc;color: #333; display: none;"/>
        <a href="javascript:;" class="tablelink" onclick="_connect_clear();">[清除]</a>
        <table class="tablelist" style="margin-top: 10px;">
            <thead>
                <tr>
                    <th><input type="checkbox" onclick="_connect_checked($(this));"/></th>
                    <th>ID</th>
                    <?php foreach ($shows as $show){?>
                    <th><?php echo $show['tag'];?></th>
                    <?php }?>
                    <th>更新时间</th>
                </tr>
            </thead>
            <tbody>
                <?php
                if ($lists) {
                    foreach ($lists as $item) {
                ?>
                <tr>
                    <td><input type="checkbox" class="_connect_checkbox" value="<?php echo $item['id'];?>" onclick="_connect_sigle_checked();"/></td>
                    <td><?php echo $item['id'];?></td>
                    <?php foreach ($shows as $show){?>
                    <td>
                        <?php
                        switch ($show['_form']){
                            case 'select':
                            case 'radio':
                            case 'radio_int':
                            case 'select_int':
                                if ($fields[$show['name']]['content']){
                                    echo $fields[$show['name']]['content'][$item[$show['name']]]['name'];
                                }else{
                                    if ($fields[$show['name']]['connect_id']){
                                        echo $item[$show['name'].'_value'];
                                    }else{
                                        echo $item[$show['name']];
                                    }
                                }                     
                                break;
                            case 'checkbox':
                                if ($item[$show['name']]){
                                    $exItem = explode(',', $item[$show['name']]);
                                    $exValue = array();
                                    foreach ($exItem as $id){
                                        $exValue[] = $fields[$show['name']]['content'][$id]['name'];
                                    }
                                    echo implode(', ', $exValue);
                                }else{
                                    echo '--';
                                }
                                break;
                            case 'singleImage':
                                echo '<img src="'.$item[$show['name']].'?imageView/1/w/24/h/24" width="24" height="24"/>';
                                break;
                            case 'timepicker':
                                echo $item[$show['name']] ? date('Y-m-d H:i', $item[$show['name']]) : '--';
                                break;
                            default:
                                if ($fields[$show['name']]['connect_id']){
                                    echo $item[$show['name'].'_value'];
                                }else{
                                    echo $item[$show['name']];
                                }
                                break;
                        }
                        ?>
                    </td>
                    <?php }?>
                    <td><?php echo date('Y-m-d H:i', $item['dateline']);?></td>
                </tr>
                <?php
                    }
                }
                ?>
            </tbody>
        </table>        
        <div style="margin-top: 12px;"><?php echo $pager; ?><br style="clear: both;"/></div>
    </div>
</div>
<script>
    $(function(){
        $('.tablelist tbody tr:odd').addClass('odd');
    });
</script>