7e47ce238b
添加了管理后台所需的图片资源、Excel文件、安装程序以及设计相关的图片文件
333 lines
9.9 KiB
PHP
333 lines
9.9 KiB
PHP
<?php
|
|
//-------------------------------
|
|
header("Content-type: text/html; charset=utf-8");
|
|
if(THIS_IN!="edt_admin")
|
|
exit("错误的访问!");
|
|
//-------------------------------execute action
|
|
$db=_mysql_connect();
|
|
$msg_login_user=get_db_msg("select * from ".$table_pre."user where id='".$uid."'");
|
|
//权限判断
|
|
$priv=return_priv($_m,$msg_login_user["priv"]);
|
|
$arr_column_kh_xh=array("xh"=>d_translate("xh"),"kh"=>"款号","color"=>"色号");
|
|
$json_data="{";
|
|
if($priv[0]=="n"){
|
|
//没有操作权限
|
|
$json_data.="\"error\":\"没有操作权限\",\"code\":0,\"msg\":\"\",\"count\":0,\"data\":[],";
|
|
}else{
|
|
$json_data.="\"uid\":".$uid.",";
|
|
switch($_a){
|
|
case "check_kh":
|
|
$str="";
|
|
$tmp="";
|
|
$q="select kh from web_kh_xh group by kh";
|
|
$r=$db->query($q);
|
|
$i=0;
|
|
while($m=$db->fetch_array($r)){
|
|
$check=get_db_msg("select id from web_kh where no='".$m["kh"]."'");
|
|
if(!$check["id"]){
|
|
$tmp.="{\"kh\":\"".$m["kh"]."\",\"v\":\"".$m["kh"]."\"},";
|
|
$i++;
|
|
}
|
|
}
|
|
if($i>0){
|
|
$str.="{\"cate\":\"款号有误\",\"data\":[".deel_end($tmp)."]},";
|
|
}else{
|
|
$str.="{\"cate\":\"款号无误\",\"data\":[]},";
|
|
}
|
|
$json_data.="\"error\":[".deel_end($str)."],";
|
|
break;
|
|
case "check_color":
|
|
$str="";
|
|
$tmp="";
|
|
$q="select * from web_kh_xh";
|
|
$r=$db->query($q);
|
|
$i=0;
|
|
while($m=$db->fetch_array($r)){
|
|
$tmparr=get_db_msg("select * from web_kh where no='".$m["kh"]."'");
|
|
$arr_color=explode(",",$tmparr["color"]);
|
|
if(!in_array($m["color"],$arr_color)){
|
|
$tmp.="{\"xh\":\"".$m["xh"]."\",\"v\":\"".$m["kh"].",".$m["color"]."\"},";
|
|
$i++;
|
|
}
|
|
}
|
|
if($i>0){
|
|
$str.="{\"cate\":\"颜色有误\",\"data\":[".deel_end($tmp)."]},";
|
|
}else{
|
|
$str.="{\"cate\":\"颜色无误\",\"data\":[]},";
|
|
}
|
|
$json_data.="\"error\":[".deel_end($str)."],";
|
|
break;
|
|
case "check_xh":
|
|
$str="";
|
|
$tmp="";
|
|
$q="select xh from web_kh_xh group by xh";
|
|
$r=$db->query($q);
|
|
$i=0;
|
|
while($m=$db->fetch_array($r)){
|
|
$check=get_db_msg("select count(*) 'num' from web_kh_xh where xh='".$m["xh"]."'");
|
|
if($check["num"]>1){
|
|
$tmp.="{\"xh\":\"".$m["xh"]."\",\"v\":\"".$m["xh"]."\"},";
|
|
$i++;
|
|
}
|
|
}
|
|
if($i>0){
|
|
$str.="{\"cate\":\"".d_translate("xh")."有误\",\"data\":[".deel_end($tmp)."]},";
|
|
}else{
|
|
$str.="{\"cate\":\"".d_translate("xh")."无误\",\"data\":[]},";
|
|
}
|
|
$json_data.="\"error\":[".deel_end($str)."],";
|
|
break;
|
|
case "check_xh_null":
|
|
$str="";
|
|
$tmp="";
|
|
$q="select * from ".$table_pre."kh";
|
|
$r=$db->query($q);
|
|
$i=0;
|
|
while($m=$db->fetch_array($r)){
|
|
$arr_color=explode(",",$m["color"]);
|
|
for($j=0;$j<count($arr_color);$j++){
|
|
$check=get_db_msg("select id from ".$table_pre."kh_xh where kh='".$m["no"]."' and color='".$arr_color[$j]."'");
|
|
if(!$check["id"]){
|
|
$tmp.="{\"kh\":\"".$m["no"]."\",\"v\":\"".$m["no"]."-".$arr_color[$j]."\"},";
|
|
$i++;
|
|
}
|
|
}
|
|
}
|
|
if($i>0){
|
|
$str.="{\"cate\":\"款色缺".d_translate("xh")."\",\"data\":[".deel_end($tmp)."]},";
|
|
}else{
|
|
$str.="{\"cate\":\"".d_translate("xh")."无缺少\",\"data\":[]},";
|
|
}
|
|
$json_data.="\"error\":[".deel_end($str)."],";
|
|
break;
|
|
case "add":
|
|
if($id){
|
|
$msg=get_db_msg("select * from ".$table_pre."kh_xh where id='".$id."'");
|
|
$xh=$msg["xh"];
|
|
$kh=$msg["kh"]."|".get_cate_title_no("color",$msg["color"])."|".$msg["color"];
|
|
}else{
|
|
$tmp=get_db_msg("select max(xh) 'xh' from ".$table_pre."kh_xh");
|
|
$xh=$tmp["xh"]>0?($tmp["xh"]+1):1;
|
|
$kh="";
|
|
}
|
|
$json_data.="\"xh\":\"".$xh."\",";
|
|
$json_data.="\"kh\":\"".$kh."\",";
|
|
break;
|
|
case "save_add":
|
|
$arr1=explode("|",$kh);
|
|
$kh=$arr1[0];
|
|
$color=$arr1["2"];
|
|
if($id>0){
|
|
$q="update web_kh_xh set xh='".$xh."',kh='".$kh."',color='".$color."' where id='".$id."'";
|
|
}else{
|
|
$q="insert into web_kh_xh (xh,kh,color) values ('".$xh."','".$kh."','".$color."')";
|
|
}
|
|
$db->query($q);
|
|
$json_data.="\"code\":1,";
|
|
break;
|
|
//删除
|
|
case "del" :
|
|
$id=(is_array($id))?$id:array($id);
|
|
$num=count($id);
|
|
for($i=0;$i<$num;$i++){
|
|
$q="delete from web_kh_xh where id='".$id[$i]."'";
|
|
$db->query($q);
|
|
$lid.=$id[$i].", ";
|
|
}
|
|
$lid=substr($lid,0,-2);
|
|
set_log("删除款号".d_translate("xh"),$lid);
|
|
$json_data.="\"code\":1,";
|
|
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":
|
|
$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_column_kh_xh);
|
|
$msg="";
|
|
if(count($arr_column[0])==0){
|
|
$msg.="未检测到可导入字段,请返回检查EXCEL文件!";
|
|
del_tmp_file($tmp_file_name);
|
|
$json_data.="\"code\":0,\"msg\":\"".$msg."\",";
|
|
}else{
|
|
//
|
|
$column="";
|
|
foreach($arr_column_kh_xh as $k => $v){
|
|
$column.=$v.",";
|
|
}
|
|
if($column)
|
|
$column=substr($column,0,-1);
|
|
$msg1=array();
|
|
$msg1[0]=array("可导入正确字段",$column);
|
|
//
|
|
$column="";
|
|
for($i=0;$i<count($arr_thead);$i++){
|
|
if(in_array(get_main_key($arr_column_kh_xh,$arr_thead[$i]),$arr_column[1])){
|
|
$style=" style='font-weight:bold;color:#0000ff'";
|
|
}else{
|
|
$style=" style='color:#cccccc'";
|
|
}
|
|
$column.="<span".$style.">".$arr_thead[$i]."</span>,";
|
|
}
|
|
if($column)
|
|
$column=substr($column,0,-1);
|
|
//
|
|
$msg1[1]=array("检测到的有效字段",$column);
|
|
//
|
|
$total=count($arr_content)-1;
|
|
$msg1[2]=array("记录条数",$total);
|
|
$m1="";
|
|
for($i=0;$i<count($msg1);$i++){
|
|
$m1.="{\"col1\":\"".$msg1[$i][0]."\",\"col2\":\"".$msg1[$i][1]."\"},";
|
|
}
|
|
if($m1)
|
|
$m1=substr($m1,0,-1);
|
|
$json_data.="\"code\":1,\"tmp_file_name\":\"".$tmp_file_name."\",\"msg\":[".$m1."],";
|
|
$json_data.="\"input\":[{\"type\":\"radio\",\"title\":\"导入方式\",\"name\":\"import_type\",\"op\":\"清空导入|新增导入\",\"value\":\"清空导入\"}],";
|
|
}
|
|
break;
|
|
case "import_do":
|
|
$import_type=($import_type=="清空导入")?"y":"n";
|
|
if($import_type=="y"){
|
|
$db->query("TRUNCATE TABLE ".$table_pre."kh_xh;");
|
|
}
|
|
$json_data.="\"code\":1,\"reload_type\":\"1\",";
|
|
//-------------------------------------------导入数据
|
|
$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_column_kh_xh);
|
|
$insert_column="";
|
|
for($i=0;$i<count($arr_column[1]);$i++){
|
|
$insert_column.=$arr_column[1][$i].",";
|
|
}
|
|
$insert_column=substr($insert_column,0,-1);
|
|
for($i=1;$i<count($arr_content);$i++){
|
|
$tmp_arr=explode("|^_^|",$arr_content[$i]);
|
|
$insert_value="";
|
|
for($k=0;$k<count($arr_column[0]);$k++){
|
|
$ind=$arr_column[0][$k];
|
|
$ititle=$arr_column[1][$k];
|
|
$insert_value.="'".mysql_escape_string(trim($tmp_arr[$ind]))."',";
|
|
}
|
|
$insert_value=substr($insert_value,0,-1);
|
|
$q="insert into ".$table_pre."kh_xh (".$insert_column.") values (".$insert_value.")";
|
|
//echo $q."<br>";
|
|
$db->query($q);
|
|
}
|
|
del_tmp_file($tmp_file_name);
|
|
$log_remark=$import_flag;
|
|
set_log("导入 款号".d_translate("xh")."数据",$log_remark);
|
|
break;
|
|
//----------------------------------------------------------------------导出数据
|
|
case "export":
|
|
$column="";
|
|
foreach($arr_column_kh_xh as $k => $v){
|
|
$column.="{\"k\":\"".$k."\",\"t\":\"".$v."\"},";
|
|
}
|
|
if($column)
|
|
$column=substr($column,0,-1);
|
|
$json_data.="\"col\":[".$column."],";
|
|
break;
|
|
case "export_do":
|
|
//取得字段选择的值
|
|
foreach($arr_column_kh_xh as $k => $v){
|
|
$var="col_".$k;
|
|
if($$var=="on"){
|
|
$ex_col[]=$k;
|
|
}
|
|
}
|
|
$num=count($ex_col);
|
|
if($num==0)
|
|
alert_and_back("请至少选择一个要导出的字段");
|
|
|
|
for($i=0;$i<$num;$i++){
|
|
$data["col"][]='str';
|
|
$data["header"][0][]=get_main_value($arr_column_kh_xh,$ex_col[$i]);
|
|
}
|
|
|
|
$query="select * from web_kh_xh order by kh,xh";
|
|
$r=$db->query($query);
|
|
$row=0;
|
|
while($m=$db->fetch_array($r)){
|
|
for($i=0;$i<$num;$i++){
|
|
$k=$ex_col[$i];
|
|
$data["body"][$row][]=$m[$k];
|
|
}
|
|
$row++;
|
|
}
|
|
$file_name="kh_xh_".date("Y-m-d-H-i");
|
|
output_excel($file_name,$data);
|
|
set_log("导出 款号信息");
|
|
exit;
|
|
break;
|
|
//-------------主界面
|
|
default:
|
|
$json_data.="\"lang_xh\":\"原牌号\",";
|
|
$json_data.="\"lang_kh\":\"款号\",";
|
|
|
|
//
|
|
$page=$page>0?$page:1;
|
|
$limit=$limit>0?$limit:10;
|
|
$start=($page-1)*$limit;
|
|
$end=$limit;
|
|
|
|
//条件
|
|
$sql_con="";
|
|
if($s_kh || $s_xh){
|
|
if($s_xh)
|
|
$sql_con.="xh='".$s_xh."' and ";
|
|
if($s_kh)
|
|
$sql_con.="kh like '%".$s_kh."%' and ";
|
|
}
|
|
if($sql_con)
|
|
$sql_con="where ".substr($sql_con,0,-4);
|
|
|
|
//取得总条数
|
|
$tmp=get_db_msg("select count(*) 'num' from web_kh_xh ".$sql_con);
|
|
$total_num=$tmp["num"];
|
|
|
|
$json_data.="\"code\":0,\"msg\":\"\",\"count\":".$total_num.",\"data\":[";
|
|
$count=1;
|
|
$str_tmp="";
|
|
$sql="select * from web_kh_xh ".$sql_con." order by kh,xh limit ".$start.",".$end;
|
|
$res=$db->query($sql);
|
|
while($msg=$db->fetch_array($res)){
|
|
$list=$count+$start;
|
|
$str_tmp.="{";
|
|
$str_tmp.="\"ct\":\"".$list."\",";
|
|
$str_tmp.="\"id\":\"".$msg["id"]."\",";
|
|
$str_tmp.="\"yph\":\"".$msg["xh"]."\",";
|
|
$str_tmp.="\"kh\":\"".$msg["kh"]."\",";
|
|
$str_tmp.="\"color\":\"".$msg["color"]."-".get_cate_title_no("color",$msg["color"])."\"";
|
|
$str_tmp.="},";
|
|
$count++;
|
|
}
|
|
$json_data.=substr($str_tmp,0,-1)."],";
|
|
break;
|
|
}
|
|
}
|
|
$json_data=substr($json_data,0,-1)."}";
|
|
echo $json_data;
|
|
?>
|