"编号","title"=>"名称");
$arr_column_keyword_sx=array("no"=>"编号","title"=>"名称","color"=>"颜色名称");
if($s_cate=="color")
$s_cate_title="颜色";
else
$s_cate_title=get_cate_title_no("arr_select",$s_cate);
//
$check=get_db_msg("select count(*) 'num' from ".$table_pre."keyword where cate='arr_select'");
if($check["num"]==0){
//写入默认数据
foreach($arr_global_select as $no => $title){
$q="insert into ".$table_pre."keyword (ord,title,cate,no) values ('1','".$title."','arr_select','".$no."')";
$db->query($q);
}
}
switch($_a){
case "set_color" :
//--------------------------设置颜色
//取得默认值
$m1=get_db_msg("select * from ".$table_pre."sx where no='".$no."' limit 0,1");
$json_data.="\"value\":\"".$m1["_v"]."\",";
//取得已经被设置过的值
$q="select * from ".$table_pre."sx where no<>'".$no."'";
$r=$db->query($q);
$str_color="";
while($m=$db->fetch_array($r)){
$t1=explode(",",$m["_v"]);
if($m["_v"])
$str_color.=$m["_v"].",";
}
$str_color=deel_end($str_color);
$json_data.="\"color_picked\":\"".$str_color."\",";
//取得所有颜色
$q0="select no,title from ".$table_pre."keyword where cate='color' order by no";
$r0=$db->query($q0);
$str_color="";
while($m0=$db->fetch_array($r0)){
$str_color.="{\"no\":\"".$m0["no"]."\",\"title\":\"".$m0["title"]."\"},";
}
$str_color=deel_end($str_color);
$json_data.="\"color\":[".$str_color."],";
break;
case "save_set_color" :
//--------------------------保存颜色设置
$tmp=get_db_msg("select id from ".$table_pre."keyword where cate='sx' and no='".$no."'");
if($tmp["id"]>0){
$_v=$color;
$check=get_db_msg("select * from ".$table_pre."sx where no='".$no."'");
if($check["id"]>0){
$q="update ".$table_pre."sx set _v='".$_v."' where no='".$no."'";
}else{
$q="insert into ".$table_pre."sx (no,_v) values ('".$no."','".$_v."')";
}
//echo $q."
";
$db->query($q);
//设置订单表
for($i=0;$i";
$db->query($q1);
}
$json_data.="\"code\":1,";
}else{
$json_data.="\"code\":0,\"msg\":\"色系不存在(".$no.")\",";
}
break;
case "add" :
if($id){
$msg=get_db_msg("select * from ".$table_pre."keyword where id='".$id."'");
$no=$msg["no"];
$title=$msg["title"];
}else{
$tmp=get_db_msg("select max(no) 'no' from ".$table_pre."keyword where cate='".$s_cate."'");
$no=($tmp["no"]>0)?($tmp["no"]+1):"";
$title="";
}
$json_data.="\"no\":\"".$no."\",\"title\":\"".$title."\",";
break;
case "save_add" :
//验证
$c=get_db_msg("select count(*) 'num' from ".$table_pre."keyword where (no='".$no."') and id<>'".$id."' and cate='".$s_cate."'");
if($c["num"]>0){
$msg_error="该编号已经存在,请检查";
$json_data.="\"code\":\"0\",\"msg\":\"".$msg_error."\",";
}else{
if($id){
$msg=get_db_msg("select * from ".$table_pre."keyword where id='".$id."'");
if($msg["no"]!=$no){
//更新订单表
$q1="update ".$table_pre."order set ".$s_cate."='".$no."' where ".$s_cate."='".$msg["no"]."' and _key='".$_key."'";
$db->query($q1);
//更新款号表
if($s_cate=="color"){
//颜色例外
$q="select * from ".$table_pre."kh";
$r=$db->query($q);
while($m=$db->fetch_array($r)){
$c=$m["color"];
$tmp=explode(",",$c);
$c_good="";
$is_up="n";
for($i=0;$iquery("update ".$table_pre."kh set color='".$c_good."' where id='".$m["id"]."'");
//更改图片
$i="../attachments/design/mini/".$m["no"]."_".$msg["no"].".jpg";
if(is_file($i)){
//
copy($i,"../attachments/design/mini/".$m["no"]."_".$no.".jpg");
del_file($i);
//
copy("../attachments/design/big/".$m["no"]."_".$msg["no"].".jpg","../attachments/design/big/".$m["no"]."_".$no.".jpg");
del_file("../attachments/design/big/".$m["no"]."_".$msg["no"].".jpg");
}
}
}
}else{
if($s_cate=="sx"){
$db->query("update ".$table_pre."sx set no='".$no."' where no='".$msg["no"]."'");
}else{
$db->query("update ".$table_pre."kh set ".$s_cate."='".$no."' where ".$s_cate."='".$msg["no"]."'");
}
}
}
$query="update ".$table_pre."keyword set no='".$no."',title='".$title."' where id='".$id."'";
$db->query($query);
$log_action="修改";
}else{
$query="insert ".$table_pre."keyword (no,title,cate) values ('".$no."','".$title."','".$s_cate."')";
$db->query($query);
$iid=$db->insert_id();
$log_action="新增";
}
$lid=$id?$id:$iid;
set_log($log_action."选项",$title."|".$lid);
$json_data.="\"code\":\"1\",";
}
break;
case "del" :
$id=(is_array($id))?$id:array($id);
$num=count($id);
for($i=0;$i<$num;$i++){
$tmp=get_db_msg("select * from ".$table_pre."keyword where id='".$id[$i]."'");
if($tmp["cate"]=="sx"){
$db->query("delete from ".$table_pre."sx where no='".$tmp["no"]."'");
}
$lid.=$tmp["title"]."|".$id[$i].", ";
$db->query("delete from ".$table_pre."keyword where id='".$id[$i]."'");
}
$lid=substr($lid,0,-2);
set_log("删除".$_title_,$lid);
$json_data.="\"code\":1,";
break;
//------------------------------------------------------------------------------------选项设置
case "save_select" :
$query="select * from ".$table_pre."keyword where cate='arr_select' order by ord";
$res=$db->query($query);
while($msg=$db->fetch_array($res)){
$var_title="title_".$msg["id"];
$var_flag_ka="is_show_".$msg["id"];
$var_flag_bd="is_bd_".$msg["id"];
//
$tmp_flag_ka=($$var_flag_ka=="on")?"y":"n";
$tmp_flag_bd=($$var_flag_bd=="on")?"y":"n";
$q="update ".$table_pre."keyword set title='".$$var_title."',flag_ka='".$tmp_flag_ka."',flag_bd='".$tmp_flag_bd."' where id='".$msg["id"]."'";
//$query.=$q.";";
$db->query($q);
}
set_log("修改字段设置");
$json_data.="\"code\":1,";
break;
case "set_select":
$query="select * from ".$table_pre."keyword where cate='arr_select' order by ord";
//echo $query."
";
$res=$db->query($query);
$str="";
while($msg=$db->fetch_array($res)){
$str.="{\"id\":\"".$msg["id"]."\",\"no\":\"".$msg["no"]."\",\"title\":\"".$msg["title"]."\",\"flag_ka\":\"".$msg["flag_ka"]."\",\"flag_bd\":\"".$msg["flag_bd"]."\"},";
}
$json_data.="\"data\":[".deel_end($str)."],";
break;
//------------------------------------------------------------------------------------/选项设置
//----------------------------------------------------------------------导入EXCEL
case "import":
//目录权限
$arr_path=array(
"cache"=>"admin/cache"
);
$json_data.="\"path_priv\":[";
$tmp="";
foreach($arr_path as $path_real => $path_title){
$tmp.="{\"title\":\"".$path_title."\",\"priv\":";
if(new_is_writeable($path_real)==1){
$tmp.="\"y\"";
}else{
$tmp.="\"n\"";
}
$tmp.="},";
}
$json_data.=substr($tmp,0,-1)."],";
break;
case "import_check":
$s_cate=$cate;
if($s_cate=="sx")
$arr_column1=$arr_column_keyword_sx;
else
$arr_column1=$arr_column_keyword;
$file1=$_FILES["up_file"];
//echo $file1["name"]."--";
$tmp_file_name=save_tmp_file($file1);
$tmp_content=get_tmp_content($tmp_file_name);
$arr_content=explode("\n",$tmp_content);
$arr_thead=get_table_thead($tmp_content);
$arr_column=check_table_thead($arr_thead,$arr_column1);
$msg="";
if(count($arr_column[0])==0){
$msg.="未检测到可导入字段,请返回检查EXCEL文件!";
//del_tmp_file($tmp_file_name);
$json_data.="\"code\":0,\"msg\":\"".$msg."\",";
}else{
$errmsg="";
$arr_init=array();
//新增导入时检查是否编号已存在
for($i=1;$i0 && count($arr_init)!=count($arr_result)){
$errmsg.="编号存在重复值,请返回检查EXCEL文件!";
}
if($errmsg){
$json_data.="\"code\":0,\"msg\":\"".$errmsg."\",";
}else{
//
$column="";
foreach($arr_column1 as $k => $v){
$column.=$v.",";
}
if($column)
$column=substr($column,0,-1);
$msg1=array();
$msg1[0]=array("可导入正确字段",$column);
//
$column="";
for($i=0;$i".$arr_thead[$i].",";
}
if($column)
$column=substr($column,0,-1);
//
$msg1[1]=array("检测到的有效字段",$column);
//
$total=count($arr_content)-1;
$msg1[2]=array("记录条数",$total);
$m1="";
for($i=0;$iquery("delete from ".$table_pre."keyword where cate='".$s_cate."'");
}else{
$error_str="";
//新增导入时检查是否编号已存在
for($i=1;$i";
$db->query($q);
}
if($s_cate=="sx"){
//处理颜色
for($i=1;$i0){
$q="update ".$table_pre."sx set _v='".$color."' where id='".$check["id"]."'";
$db->query($q);
//设置订单表
$arr_color=explode(",",$color);
for($k=0;$kquery($q1);
}
}else{
$q="insert into ".$table_pre."sx (no,_v) values ('".$no."','".$color."')";
$db->query($q);
//设置订单表
$arr_color=explode(",",$color);
for($k=0;$kquery($q1);
}
}
//echo $i.".".$q."
";
}
}
del_tmp_file($tmp_file_name);
$log_remark=$import_flag;
set_log("导入 ".get_cate_title_no("arr_select",$s_cate),$log_remark);
$json_data.="\"code\":1,\"reload_type\":\"table\",";
break;
//----------------------------------------------------------------------/导入EXCEL
//----------------------------------------------------------------------导出数据
case "export":
if($s_cate=="sx")
$arr_column=$arr_column_keyword_sx;
else
$arr_column=$arr_column_keyword;
$column="";
foreach($arr_column as $k => $v){
$column.="{\"k\":\"".$k."\",\"t\":\"".$v."\"},";
}
$column=deel_end($column);
$json_data.="\"col\":[".$column."],";
break;
case "export_do":
if($s_cate=="sx")
$arr_column=$arr_column_keyword_sx;
else
$arr_column=$arr_column_keyword;
foreach($arr_column as $k => $v){
$var="col_".$k;
if($$var=="on"){
$ex_col[]=$k;
}
}
$num=count($ex_col);
if($num==0)
alert_and_back("请至少选择一个要导出的字段!");
$data=array();
//设置表头数据类型
for($i=0;$i<$num;$i++){
$data["col"][]="str";
}
//设置表头
for($i=0;$i<$num;$i++){
$data["header"][0][]=get_main_value($arr_column,$ex_col[$i]);
}
$query="select * from ".$table_pre."keyword where cate='".$s_cate."' order by no";
$r=$db->query($query);
$row=0;
while($m=$db->fetch_array($r)){
for($i=0;$i<$num;$i++){
$k=$ex_col[$i];
if($k=="color"){
//取得颜色
$tmp=get_db_msg("select _v from ".$table_pre."sx where no='".$m["no"]."'");
$tmp=explode(",",$tmp["_v"]);
$str_color="";
for($i1=0;$i1query($q);
while($m=$db->fetch_array($r)){
$str_tab.="{\"no\":\"".$m["no"]."\",\"title\":\"".$m["title"]."\"},";
}
$str_tab=deel_end($str_tab);
$json_data.="\"tab\":[".$str_tab."],";
//-----------------------/tab
//
$query="select * from ".$table_pre."keyword ".$sql_con." order by no";
//echo $query."
";
$res=$db->query($query);
$count=0;
$json_data.="\"code\":0,\"msg\":\"\",\"count\":".$total_num.",\"data\":[";
$str_tmp="";
while($msg=$db->fetch_array($res)){
$list=$count_first+$count+1;
$str_tmp.="{";
$str_tmp.="\"id\":\"".$msg["id"]."\",";
$str_tmp.="\"no\":\"".$msg["no"]."\",";
$str_tmp.="\"title\":\"".$msg["title"]."\",";
if($s_cate=="sx"){
$b1="";
//取得色系
$tmp=get_db_msg("select * from ".$table_pre."sx where no='".$msg["no"]."'");
$sx=show_color($tmp["_v"]);
}else{
$sx="";
}
$str_tmp.="\"sx\":\"".$sx."\"";
$str_tmp.="},";
$count++;
}
$json_data.=substr($str_tmp,0,-1)."],";
break;
}
}
$json_data=substr($json_data,0,-1)."}";
echo $json_data;
?>