<?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" />
        <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/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' => 'group')); ?>">用户组</a></li>
                <li>【<?php echo $db['name']; ?>】权限设置</li>
            </ul>
        </div>
        <div class="formbody">
            <div class="usual">
                <div class="itab" style="margin: 12px 0px;">
                    <ul>
                        <?php
                        $channels = service::channels();
                        ksort($channels);
                        foreach ($channels as $c) {
                            ?>
                            <li><a href="<?php echo $base->get_url(array('c' => 'group', 'm' => 'perm', 'id' => $db['id'], 'cid' => $c['id'])); ?>" class="<?php if ($c['id'] == $cid) { ?>selected<?php } ?>"><?php echo $c['name']; ?></a></li> 
                        <?php } ?>
                    </ul>
                </div>
                <form method="post" action="" onsubmit="return false;" id="form1">
                    <?php
                    echo form::input_hidden('gid', $db['id']); # 用户组ID
                    echo form::input_hidden('cid', $cid); # 模块ID
                    echo form::nonce($admin['id'], 'permSet');
                    $node = service::common_index_by_id('AdminNode', array(
                        'where' => 'pid=0 and model_id=?', 
                        'param' => array($cid)
                    ));
                    if ($node){
                    ?>
                    <table class="tablelist" style="margin-bottom: 5px; border-top: 0;">
                    <?php
                        $access = service::common_index_by_id('AdminAccess', array(
                            'where' => 'level = ? and model_id = ?',
                            'param' => array($db['id'], $cid)
                        ));
                        $access_nodes = array();
                        if ($access){
                            foreach ($access as $item){
                                $access_nodes[] = $item['node_id'];
                            }
                        }
                        foreach ($node as $item){
                    ?>                    
                        <thead>
                            <tr>
                                <th colspan="20" style="border-top: 1px solid #cbcbcb; border-bottom: 1px solid #cbcbcb;">
                                    <?php echo $item['name'];?>
                                </th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <?php
                                $list = service::common_index_by_id('AdminNode', array(
                                    'where' => 'pid = ?', 'param' => array($item['id'])
                                ));
                                $count = 0;
                                if ($list){
                                    $i = 0;
                                    $count = count($list);
                                    foreach ($list as $perm){
                                        $i++;
                                ?>
                                <td>
                                    <input <?php if (in_array($perm['id'], $access_nodes)){?>checked<?php }?> type="checkbox" name="perm[<?php echo $perm['controller'];?>][<?php echo $perm['method'];?>]" value="<?php echo $perm['id'];?>"/> <?php echo $perm['name'];?>
                                </td>
                                <?php
                                        if ($i % 5 == 0 && $i != $count){
                                            echo '</tr><tr>';
                                        }
                                    }
                                }
                                $td = $count % 5;
                                if ($td > 0){
                                    $loop = 5 - $td;
                                    for ($j = 0; $j < $loop; $j++){
                                        echo "<td>&nbsp;</td>";
                                    }
                                }
                                ?>
                            </tr>
                        </tbody>                    
                    <?php
                        }
                    ?>
                    </table>
                    <?php
                    }
                    ?>
                    <input name="btn88" type="button" class="btn btn88" value="保存" />
                </form>
                <?php echo form::onclick('form1', 'btn88', '保存', $base->get_url(array('c' => 'group', 'm' => 'permAJAX')), $base->get_url(array('c' => 'group', 'm' => 'perm', 'id' => $db['id'])));?>
            </div> 
        </div>
    </body>
</html>
