<?php
$conf_basedir = "../../";	//相对主目录的位置
$conf_where = "admin"; //选择调用相应模块
include_once($conf_basedir . "/base.inc.php");
error_reporting(7);
ini_set("display_errors",true);
checkAuth('19');	//判断登录和权限
$title = "经纪人权限组";

if($conf_cityflag == 'nj'){
    $tbl ="broker_package";
     /*修改信息*/
    if ($action == "modify") {
        $q = "SELECT * FROM $tbl WHERE package_id = $id";
        if ($q_ext != "")
            $q.=" AND " . $q_ext;
        $data_info = $db->GetRow($q);
        if (count($data_info) == 0)
           echo "<script>alert('没有发现您查询的记录');location.href = 'broker_group_manage_new.php';</script>";
    }

    $referer = $_SERVER['HTTP_REFERER'];
    if ($action == 'insert') {
        $sql ="select package_id from $tbl where package_name = '".$package_name."'";
        $isSameName = $dbback->getOne($sql);
        if($isSameName){
            echo "<script>alert('权限组命名冲突，请重新命名!');location.href='broker_group_manage_new.php';</script>";
            exit();
        }
        $tt = array();

             $tt[package_name]					= $package_name;
            $tt[package_valid_num]				= $package_valid_num;
            $tt[package_stock_num]				= $package_stock_num;
            $tt[package_refresh_num]				= $package_refresh_num;           
            $tt[package_sell_purview]				= $package_sell_purview;
            $tt[package_rent_purview]				= $package_rent_purview;
            $tt[package_tag_num]				= $package_tag_num;
            $tt[isstar_credit_upper_limit]	                = $isstar_credit_upper_limit;
            $tt[credit_upper_limit]	                        = $credit_upper_limit;
            $tt[exp_status]			                = $exp_status;
            $tt[credit_status]		                        = $credit_status;
      

        //写入数据库
        $q = insert_sql($tbl, $tt);
        $db->Execute($q);
        echo "<script>alert('提交成功!'); location.href = 'broker_group_manage_new.php';</script>";
    }

    if ($action == 'update') {
         $sql ="select package_id from $tbl where package_name = '".$package_name."' and package_id !=" . intval($id) . "";
        $isSameName = $dbback->getOne($sql);
        if($isSameName){
            echo "<script>alert('权限组命名冲突，请重新命名!');location.href='broker_group_manage_new.php';</script>";
            exit();
        }
        $tt = array();
           
             $tt[package_name]					= $package_name;
            $tt[package_valid_num]				= $package_valid_num;
            $tt[package_stock_num]				= $package_stock_num;
            $tt[package_refresh_num]				= $package_refresh_num;           
            $tt[package_sell_purview]				= $package_sell_purview;
            $tt[package_rent_purview]				= $package_rent_purview;
            $tt[package_tag_num]				= $package_tag_num;
            $tt[isstar_credit_upper_limit]	                = $isstar_credit_upper_limit;
            $tt[credit_upper_limit]	                        = $credit_upper_limit;
            $tt[exp_status]			                = $exp_status;
            $tt[credit_status]		                        = $credit_status;

        //写入数据库
        $q = update_sql($tbl, $tt, " where package_id=" . intval($id) . ""); 
        $db->Execute($q);

        echo "<script>alert('提交成功!'); location.href='broker_group_manage_new.php';</script>";
    }
    if($action == 'delete'){        
        //删除记录
        $q="delete from $tbl where id=".intval($id);
        $msg=$db->Execute($q);
        if($msg){
            echo "<script>alert('删除成功');location.href='broker_group_manage_new.php';</script>";
        }else{       
            echo "<script>alert('删除失败');location.href='broker_group_manage_new.php';</script>";
        }
        
    }
     $tpl = "broker/broker_group_modify_new_nj";
    
}else{
    $tbl = "broker_group";
    //include_once(CORE_CONF . "/conf_page_broker.php"); //经纪人权限表文件
  //  $css = "<link href='" . $conf_default_tplpath . "/css/cp.css' rel='stylesheet' type='text/css' />";
   // $js	 = "<script src='script/cp.js' type='text/javascript' ></script><script type='text/javascript' src='script/formValidator.js'></script>";

    /*修改信息*/
    if ($action == "modify") {
        $q = "SELECT * FROM $tbl WHERE id = $id";
        if ($q_ext != "")
            $q.=" AND " . $q_ext;
        $data_info = $db->GetRow($q);
        if (count($data_info) == 0)
           echo "<script>alert('没有发现您查询的记录');location.href= 'broker_group_manage_new.php';</script>";
    }

    $referer = $_SERVER['HTTP_REFERER'];
    if ($action == 'insert') {
        $sql ="select id from $tbl where groupname = '".$groupname."'";
        $isSameName = $dbback->getOne($sql);
        if($isSameName){
            echo "<script>alert('权限组命名冲突，请重新命名!');location.href='broker_group_manage_new.php';</script>";
            exit();
        }
        $tt = array();
            $tt[groupname]					= $groupname;          
            $tt[post]						= $post;
            $tt[inventory]					= $inventory;
            $tt[is_pay]                                         = $is_pay;
            $tt[refresh]					= $refresh;
            $tt[total_refresh]					= $total_refresh;
            $tt[tag_num]					= $tag_num;
            $tt[plus_open]					= $plus_open;
            $tt[isstar_credit_limit_day]	= $isstar_credit_limit_day;
            $tt[isstar_credit_upper_limit]	= $isstar_credit_upper_limit;
            $tt[credit_upper_limit]			= $credit_upper_limit;
            $tt[package_level]				= $package_level;
            $tt[exp_status]			                = $exp_status;
            $tt[credit_status]		                        = $credit_status;

        //写入数据库
        $q = insert_sql($tbl, $tt);
        $db->Execute($q);
        echo "<script>alert('提交成功!');location.href='broker_group_manage_new.php';</script>";
    }

    if ($action == 'update') {
        $sql ="select id from $tbl where groupname = '".$groupname."' and id != " . intval($id) . "";     
        $isSameName = $dbback->getOne($sql);
        if($isSameName){
            echo "<script>alert('权限组命名冲突，请重新命名!');location.href='broker_group_manage_new.php';</script>";
            exit();
        }
        $tt = array();
    
            $tt[groupname]					= $groupname;          
            $tt[post]						= $post;
            $tt[inventory]					= $inventory;
            $tt[is_pay]                                         = $is_pay;
            $tt[refresh]					= $refresh;
            $tt[total_refresh]					= $total_refresh;
            $tt[tag_num]					= $tag_num;
            $tt[plus_open]					= $plus_open;
            $tt[isstar_credit_limit_day]	= $isstar_credit_limit_day;
            $tt[isstar_credit_upper_limit]	= $isstar_credit_upper_limit;
            $tt[credit_upper_limit]			= $credit_upper_limit;
            $tt[package_level]				= $package_level;
            $tt[exp_status]			                = $exp_status;
            $tt[credit_status]		                        = $credit_status;
      

        //写入数据库
        $q = update_sql($tbl, $tt, " where id=" . intval($id) . "");
    
        $db->Execute($q);

        echo "<script>alert('提交成功!');location.href='broker_group_manage_new.php';</script>";
    }
    if($action == 'delete'){        
        //删除记录
        $q="delete from $tbl where id=".intval($id);
        $msg=$db->Execute($q);
        if($msg){
            echo "<script>alert('删除成功');location.href='broker_group_manage_new.php';</script>";
        }else{       
            echo "<script>alert('删除失败');location.href='broker_group_manage_new.php';</script>";
        }
        
    }
    $tpl = "broker/broker_group_modify_new";
}


include_once(Template("header"));
include_once(Template($tpl));
include_once(Template("footer"));
?>