Exemple #1
0
/**
 * 填写时所需的HTML控件
 */
function ctl_fill($act)
{
    global $_PRIV, $_LANG, $tpl;
    /* 小于当前管理员角色的角色下拉框 */
    $sub_role = sub_role(array('info' => $_PRIV['role']), false);
    if (empty($sub_role)) {
        $tpl['formc_role'] = '<span style="color:#ff0000">&nbsp;' . $_LANG['fill_admin_role'] . '</span>';
    } else {
        $tpl['formc_role'] = ddl_role_custom($sub_role, 'role_id', $tpl['admin']['role_id'], array(), array('style' => 'width:153px'));
    }
    /* 辅助权限表 */
    $privilege_ids = $act == 'add' ? array() : privilege_ids(array('admin_id' => $_GET['admin_id']));
    //提交的管理员的细粒度权限IDS
    $tpl['html_privilege_table'] = html_privilege_table('privilege_ids', $privilege_ids, admin_privilege_ids());
}
/**
 * 删除权限
 *
 * @params arr  $filter  过滤条件
 */
function del_privilege($filter)
{
    global $_LANG;
    /* 根据权限ID删除 */
    if (is_numeric($filter['privilege_id']) && intval($filter['privilege_id']) > 0) {
        /* 删除管理员权限和角色权限 */
        del_admin_privilege(array('privilege_id' => $filter['privilege_id']));
        del_role_privilege(array('privilege_id' => $filter['privilege_id']));
        /* 删除权限 */
        $GLOBALS['db']->delete(tname('privilege'), 'privilege_id=' . intval($filter['privilege_id']));
        return array('error' => 0, 'message' => $_LANG['del_ok']);
    }
    /* 根据模块ID删除 */
    if (is_numeric($filter['module_id']) && intval($filter['module_id']) > 0) {
        /* 取得模块的所有权限 */
        $priv_ids = privilege_ids(array('module_id' => $filter['module_id']));
        /* 删除管理员权限和角色权限 */
        del_admin_privilege(array('privilege_ids' => $priv_ids));
        del_role_privilege(array('privilege_ids' => $priv_ids));
        /* 删除权限 */
        $GLOBALS['db']->delete(tname('privilege'), 'module_id=' . intval($filter['module_id']));
        return array('error' => 0, 'message' => $_LANG['del_ok']);
    }
    return array('error' => 1, 'message' => $_LANG['fail_del']);
}