This repository has been archived on 2026-06-20. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
EDT/admin/include/function.php
T
wsh5485 7e47ce238b chore: 添加多个图片和资源文件
添加了管理后台所需的图片资源、Excel文件、安装程序以及设计相关的图片文件
2025-06-15 13:04:37 +08:00

3963 lines
108 KiB
PHP
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
//记录订单操作日志
function update_order_state($uid,$cid,$action,$attachments){
global $db,$table_pre,$s_brand;
$add_date=date("Y-m-d H:i:s");
$db->query("insert into ".$table_pre."order_state (uid,cid,brand,action,attachments,add_date) values ('".$uid."','".$cid."','".$s_brand."','".$action."','".$attachments."','".$add_date."')");
}
//记录订单表sql日志
function update_order_log($uid,$sql){
global $db,$table_pre;
$add_date=date("Y-m-d H:i:s");
$db->query("insert into ".$table_pre."order_log (uid,sql_value,add_date) values ('".$uid."','".mysql_escape_string($sql)."','".$add_date."')");
}
////////////检查session
function check_session(){
global $db,$table_pre;
//$check_time=2*60*60;
$check_time=30*60;
$now1=time()-$check_time;
$db->query("delete from ".$table_pre."session where lastactivity<".$now1);
}
////////////解析session动作
function parse_session_action($action){
global $db,$table_pre;
$arr_module=array("admin"=>"管理员","bb"=>"标准报表","plugin"=>"插件报表","boss_gl"=>"概览","dk"=>"单款","dk_single"=>"单款详情","dp"=>"搭配","dp_single"=>"搭配详情","cl"=>"陈列","cl_single"=>"陈列详情","cc_single"=>"橱窗详情","cc"=>"橱窗","ts"=>"推送","ty"=>"推演","msg"=>"消息","my_client"=>"我的客户","ph"=>"全国排行","detail"=>"订单明细","ph_my"=>"我的排行","sjs"=>"设计师","ts_zj"=>"推送主讲","xw"=>"行为分析","zycl"=>"自由陈列","zydp"=>"自由搭配","login"=>"登录");
$arr_cate_title=array("client"=>"客户","ks"=>"款式","kh"=>"款式","ms"=>"订货模式","size"=>"尺码","color"=>"颜色","ks_size"=>"款色深度");
//
$q="select no,title from ".$table_pre."keyword where cate='arr_select'";
$r=$db->query($q);
while($m=$db->fetch_array($r)){
$arr_cate_title[$m["no"]]=$m["title"];
}
$tmp=explode("|",$action);
$_m=$tmp[0];
$_a=$tmp[1];
$cate=$tmp[2];
$r="";
$r.=get_main_value($arr_module,$_m);
if($_m=="plugin"){
//取得插件名称
$m=get_db_msg("select title from ".$table_pre."plugin where file_name='".$_a."' and cate='".$cate."'");
$r.="-".$m["title"];
}else{
if($cate){
$arr_cate=explode("&",$cate);
if($arr_cate[0])
$r.="-".get_main_value($arr_cate_title,$arr_cate[0]);
if($arr_cate[1])
$r.="-".get_main_value($arr_cate_title,$arr_cate[1]);
}
}
return $r;
}
///////////////////////////////////////////////////////字符串
function deel_end($str,$len=1){
$r="";
if($str)
$r=substr($str,0,-$len);
return $r;
}
function ifor_edt_str2num($str){
$key="background";
$num="";
for($i=0;$i<strlen($str);$i++){
for($k=0;$k<strlen($key);$k++){
if(substr($key,$k,1)==substr($str,$i,1))
$num.=$k;
}
}
return $num;
}
//
function deel_text_html($text){
$text=StripSlashes($text);
$text=str_replace("\"","'",$text);
return $text;
}
//
function get_editor($text,$id='content1',$w='100%',$h='450px'){
$text=deel_text_html($text);
$r="<textarea id=\"".$id."\" name=\"".$id."\" style=\"width:".$w.";height:".$h.";visibility:hidden;\">".$text."</textarea>";
//$r="<INPUT type=\"hidden\" name=\"".$id."\" value=\"".$text."\"><IFRAME ID=\"".$text1."\" src=\"editor/ewebeditor.htm?id=".$id."&style=mini\" frameborder=\"0\" scrolling=\"no\" width=\"".$w."\" height=\"".$h."\"></IFRAME>";
return $r;
}
//取得唯一标识
function gsession(){
$r=date("YmdHis").substr(microtime(),2,6);
return $r;
}
//daddslashes
function daddslashes($string) {
if(!get_magic_quotes_gpc()) {
if(is_array($string)) {
foreach($string as $key => $val) {
$string[$key] = daddslashes($val, $force);
}
} else {
$string = addslashes($string);
}
}
return $string;
}
//dstripslashes
function dstripslashes($string) {
if(is_array($string)) {
foreach($string as $key => $val) {
$string[$key] = dstripslashes($val, $force);
}
} else {
$string = stripslashes($string);
}
return $string;
}
//取得随机字母
function get_rand($num){
$choper="123456789abcdefghijklmnpqrstuvwxyz";
for($i=0;$i<$num;$i++){
$r_str.=substr($choper,rand(0,strlen($choper)-1),1);
}
return $r_str;
}
//取得随机数字
function get_rand_num($num){
$choper="0123456789";
for($i=0;$i<$num;$i++){
$r_str.=substr($choper,rand(0,strlen($choper)-1),1);
}
return $r_str;
}
//转换成html
function dhtmlchars($str){
$str=str_replace("<","&lt;",$str);
$str=str_replace(">","&gt;",$str);
$str=str_replace("\n","<br>",$str);
$str=str_replace("\r","",$str);
$str=str_replace(" ","&nbsp;",$str);
return $str;
}
//dhtmlspecialchars
function dhtmlspecialchars($string) {
if(is_array($string)) {
foreach($string as $key => $val) {
$string[$key] = dhtmlspecialchars($val);
}
} else {
$string = preg_replace('/&amp;((#(\d{3,5}|x[a-fA-F0-9]{4})|[a-zA-Z][a-z0-9]{2,5});)/', '&\\1',
str_replace(array('&', '"', '<', '>'), array('&amp;', '&quot;', '&lt;', '&gt;'), $string));
}
return $string;
}
//去除html标记
function no_html($content){
$search=array("'<script[^>]*?>.*?</script>'si",
"'<[\/\!]*?[^<>]*?>'si",
"'([\r\n])[\s]+'",
"'&(quot|#34);'i",
"'&(amp|#38);'i",
"'&(lt|#60);'i",
"'&(gt|#62);'i",
"'&(nbsp|#160);'i",
"'&(iexcl|#161);'i",
"'&(cent|#162);'i",
"'&(pound|#163);'i",
"'&(copy|#169);'i",
"'&#(\d+);'e");
$replace=array("",
"",
"\\1",
"\"",
"&",
"<",
">",
" ",
chr(161),
chr(162),
chr(163),
chr(169),
"chr(\\1)");
$content=preg_replace($search,$replace,$content);
return $content;
}
/////显示短标题
//不带省略号
function substrgb($str,$len){
if(strlen($str)<$len+1){
return $str;
}else{
$start=0;
for($i=0;$i<$start+$len;$i++){
$tmpstr=(ord($str[$i])>=161 && ord($str[$i])<=247 && ord($str[$i+1])>=161 && ord($str[$i+1])<=254)?$str[$i].$str[++$i]:$tmpstr=$str[$i];
if ($i>=$start&&$i<($start+$len))
$tmp.=$tmpstr;
}
return $tmp;
}
}
//带省略号
function substrgb1($str,$len){
if(strlen($str)<$len+1){
return $str;
}else{
$start=0;
for($i=0;$i<$start+$len;$i++){
$tmpstr=(ord($str[$i])>=161 && ord($str[$i])<=247 && ord($str[$i+1])>=161 && ord($str[$i+1])<=254)?$str[$i].$str[++$i]:$tmpstr=$str[$i];
if ($i>=$start&&$i<($start+$len))
$tmp.=$tmpstr;
}
return $tmp."...";
}
}
//截取字符
function sub_start_end($str,$start,$end){
$tmp=explode($start,$str);
$tmp=explode($end,$tmp[1]);
return $tmp[0];
}
//
function check_td($str){
return trim($str)?$str:"&nbsp;";
}
///////////////////////////////////////////////////////url相关
//重定向
function url_redirect($url=''){
$url=$url?$url:$_SERVER["HTTP_REFERER"];
//echo $url;
echo "<script> window.location.href='".$url."'; </script>";
//echo "<meta http-equiv=\"rsefresh\" content=\"1;url=".$url."\">";
echo "<body><a href=\"".$url."\">Success!</a></body>";
exit();
}
//输出js代码并且重定向
function jscode_and_redirect($url='',$jscode=''){
$url=$url?$url:$_SERVER["HTTP_REFERER"];
echo "<html><head><meta http-equiv=\"refresh\" content=\"1;url=".$url."\"></head><body>".$jscode."</body></html>";
exit();
}
//输出js错误提示
function alert($msg){
echo "<script> alert('".$msg."'); </script>";
exit();
}
//输出js错误提示并返回
function alert_and_back($msg){
echo "<html><head><meta http-equiv=\"content-type\" content=\"text/html;charset=utf-8\"></head><body><script> alert('".$msg."');\n history.back(); </script></body></html>";
exit();
}
//输出js错误提示并关闭窗口
function alert_and_close($msg){
echo "<html><head><meta http-equiv=\"content-type\" content=\"text/html;charset=utf-8\"></head><body><script> alert('".$msg."');\n window.close(); </script></body></html>";
exit();
}
//输出js错误提示并重定向
function alert_and_redirect($msg,$url){
echo "<html><head><meta http-equiv=\"refresh\" content=\"0;url=".$url."\"><meta http-equiv=\"content-type\" content=\"text/html;charset=utf-8\"><script> alert('".$msg."'); </script></body></html>";
exit();
}
//输出js错误提示并关闭窗口
function alert_and_reload_opener($msg){
echo "<html><head><meta http-equiv=\"content-type\" content=\"text/html;charset=utf-8\"></head><body><script> alert('".$msg."');\n window.opener.location.reload();\n window.close();\n </script></body></html>";
exit();
}
//重定向并post变量
function redirect_and_post($url,$var){
$html="<body onload='document.form1.submit();'><form name=form1 method='post' action=\"".$url."\">";
if(is_array($var)){
foreach($var as $key => $value){
$html.="<input type=hidden name=\"".$key."\" value=\"".urlencode($value)."\">\n";
}
}
$html.="</form></body>";
echo $html;
}
//处理url
function url_add_getvar($url,$arr){
$tmp=str_replace("?","#",$url);
if(ereg("#",$tmp))
$url.="&";
else
$url.="?";
foreach($arr as $key => $value){
$url.=$key."=".$value."&";
}
$url=substr($url,0,-1);
return $url;
}
//=====================================================phpexcel
//处理回车
function deel_tmp_td($str){
$str=str_replace("\r\n","",$str);
$str=str_replace("\n","",$str);
$str=str_replace("\r","",$str);
return trim($str);
}
//把上传的excel文件转换成文本文件
function save_tmp_file($file){
require_once THIS_FILE_ROOT."/include/phpexcel/PHPExcel/IOFactory.php";
$file_name=gsession();
$file_ext=get_file_ext($file["name"]);
$xls_file_name=$file_name.".".$file_ext;
//$xls_file_name="../kh1.xls";
upload_file($file["tmp_name"],THIS_FILE_ROOT."/cache",$xls_file_name);
$inputFileName=THIS_FILE_ROOT."/cache/".$xls_file_name;
try {
$inputFileType = PHPExcel_IOFactory::identify($inputFileName);
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$objPHPExcel = $objReader->load($inputFileName);
} catch(Exception $e) {
die("加载文件发生错误:".pathinfo($inputFileName,PATHINFO_BASENAME).": ".$e->getMessage());
}
$sheet=$objPHPExcel->getSheet(0);
$highestRow=$sheet->getHighestRow();
$highestColumn=$sheet->getHighestColumn();
//获取一行的数据
$content="";
for($row=1;$row<=$highestRow;$row++){
$rowData = $sheet->rangeToArray("A".$row.":". $highestColumn.$row, NULL,TRUE,FALSE);
if($rowData){
$line="";
for($i=0;$i<count($rowData[0]);$i++){
$line.=deel_tmp_td($rowData[0][$i])."|^_^|";
}
if($line){
$line=substr($line,0,-5);
$content.=$line."\n";
}
}
//print_r($rowData);
//echo "<Br>";
}
if($content){
$content=substr($content,0,-1);
write_file(THIS_FILE_ROOT."/cache",$file_name,$content);
}
//del_file(THIS_FILE_ROOT."/cache/".$xls_file_name);
return $file_name;
}
//取得临时文件内容
function get_tmp_content($file){
$content=read_file(THIS_FILE_ROOT."/cache/".$file);
return $content;
}
//删除临时文件
function del_tmp_file($file){
del_file(THIS_FILE_ROOT."/cache/".$file);
del_file(THIS_FILE_ROOT."/cache/".$file.".xls");
del_file(THIS_FILE_ROOT."/cache/".$file.".xlsx");
}
//取得表头内容
function get_table_thead($content){
$arr=explode("\n",$content);
$arr=explode("|^_^|",$arr[0]);
return $arr;
}
//检查表头是否对应
function check_table_thead($arr_head,$arr_head_global){
global $arr_column_client_pinpai;
$arr1=$arr2=array();
$arr3=$arr_column_client_pinpai;
for($i=0;$i<count($arr_head);$i++){
if(in_array($arr_head[$i],$arr_head_global)){
$arr1[]=$i;
$arr2[]=get_main_key($arr_head_global,$arr_head[$i]);
}
}
return array($arr1,$arr2);
}
//处理表头格式
function push_array_header($data_col,$data,$hang,$lie,$val){
$lie_max=count($data_col);
$hang_max=count($data);
$r=array();
for($i=0;$i<$hang_max;$i++){
if($hang==$i){
for($j=0;$j<$lie_max;$j++){
if($j==$lie){
$r[$i][$j]=$val;
}else if($j<$lie){
$r[$i][$j]=$data[$i][$j];
}else{
if(isset($data[$i][$j-1])==true)
$r[$i][$j]=$data[$i][$j-1];
}
}
}else{
if(isset($data[$i])==true)
$r[$i]=$data[$i];
}
}
return $r;
}
//自动计算合并行,合并列
function deel_data_cs_rs($data,$data_col){
//
$hang_max=count($data);
$lie_max=count($data_col);
for($i=0;$i<$hang_max;$i++){
for($j=0;$j<$lie_max;$j++){
$val=$data[$i][$j];
if($val){
$arr_tmp=explode("|",$data[$i][$j]);
if($arr_tmp[1]){
$arr_tmp1=explode(":",$arr_tmp[1]);
if($arr_tmp1[0]=="rs"){
for($i1=1;$i1<$arr_tmp1[1];$i1++){
$data=push_array_header($data_col,$data,($i+$i1),($j),"^_^");
}
}else if($arr_tmp1[0]=="cs"){
for($i1=1;$i1<$arr_tmp1[1];$i1++){
$data=push_array_header($data_col,$data,($i),($j+$i1),"^_^");
}
}
}
}
}
}
return $data;
}
function output_excel($file_name='',$data=array(),$download='y'){
require_once THIS_FILE_ROOT."/include/phpexcel/PHPExcel.php";
$file_name=$file_name?$file_name:date("Ymd-Hi");
/*数据格式说明
$file_name="test";//不需要后缀
$data=array();
$data["col"]=array('img','str','str','num','num','num','num','num','num','num');//定义列的数据类型
//表头,支持合并单元格
$data["header"][0]=array('图片|rs:3','款号|rs:3','颜色|rs:3','尺码|cs:3', '数量|rs:3', '金额|rs:3');//名称|合并单元
$data["header"][1]=array('S','M','L');
$data["header"][2]=array('35','36','37');
//数据
$data["body"][0]=array('../attachments/design/mini/12W0101_82.jpg','12W0101','02','1','1','1','3','300');
$data["body"][1]=array('../attachments/design/mini/12W1105_91.jpg|rs:3','12W0102|rs:3','51','2','2','0','4','400');
$data["body"][2]=array('52','2','2','1','5','500');
$data["body"][3]=array('53','3','3','0','6','600');
*/
$excel = new PHPExcel();
$objDrawing = new PHPExcel_Worksheet_Drawing();
$excel->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$excel->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
$objActSheet = $excel->getActiveSheet();
$letter=array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','AA','AB','AC','AD','AE','AF','AG','AH','AI','AJ','AK','AL','AM','AN','AO','AP','AQ','AR','AS','AT','AU','AV','AW','AX','AY','AZ');
$defaultFont = $excel->getDefaultStyle()->getFont();
//-------------------------------填充表格表头
$data_header=$data["header"];
$hang_max=count($data_header);
$lie_max=count($data["col"]);
$data_header=$data["header"];
$data_header=deel_data_cs_rs($data_header,$data["col"]);
//print_r($data_header);
//echo "<br>";
//填充
$thead_rows=0;
for($row=0;$row<count($data_header);$row++){
$row1=$row+1;
for($lie=0;$lie<count($data_header[$row]);$lie++){
$arr_tmp=explode("|",$data_header[$row][$lie]);
if($arr_tmp[1]){
$arr_tmp1=explode(":",$arr_tmp[1]);
if($arr_tmp1[0]=="rs"){
$excel->getActiveSheet()->mergeCells($letter[$lie].$row1.':'.$letter[$lie].($row1+$arr_tmp1[1]-1));
}else if($arr_tmp1[0]=="cs"){
$excel->getActiveSheet()->mergeCells($letter[$lie].$row1.':'.$letter[$lie+$arr_tmp1[1]-1].$row1);
}
}
$str1=$arr_tmp[0];
if($arr_tmp[0]!="^_^")
$excel->getActiveSheet()->setCellValue($letter[$lie].$row1,$str1);
}
$thead_rows++;
}
$data["header"]=$data_header;
//设置宽度
for($lie=0;$lie<count($data["col"]);$lie++){
if($data["col"][$lie]=="img"){
$excel->getActiveSheet()->getColumnDimension($letter[$lie])->setWidth(40);
}
}
//-------------------------------填充表格内容
$data_body=$data["body"];
$data_body=deel_data_cs_rs($data_body,$data["col"]);
for($row=0;$row<count($data_body);$row++) {
//判断本行是否有图片
$is_img="n";
$imgh=0;
for($lie=0;$lie<count($data_body[$row]);$lie++){
$arr_tmp=explode("|",$data_body[$row][$lie]);
$arr_tmp1=explode(":",$arr_tmp[1]);
if($data["col"][$lie]=="img" && is_file($arr_tmp[0])){
$image_size=getimagesize($arr_tmp[0]);
$imgh=$image_size[1];
//echo $arr_tmp[0]."|".$imgh."<br>";
if($arr_tmp1[0]=="rs"){
$imgh=$imgh-$arr_tmp1[1]*(19*4/3);
}
$is_img="y";
}
}
$j=$row+1+$thead_rows;
//设置表格高度
if($is_img=="y"){
$excel->getActiveSheet()->getRowDimension($j)->setRowHeight($imgh);
}else{
$excel->getActiveSheet()->getRowDimension($j)->setRowHeight(20);
}
//向每行单元格插入数据
for($lie=0;$lie<count($data_body[$row]);$lie++){
$arr_tmp=explode("|",$data_body[$row][$lie]);
if($arr_tmp[1]){
$arr_tmp1=explode(":",$arr_tmp[1]);
if($arr_tmp1[0]=="rs"){
$excel->getActiveSheet()->mergeCells($letter[$lie].$j.':'.$letter[$lie].($j+$arr_tmp1[1]-1));
}else if($arr_tmp1[0]=="cs"){
$excel->getActiveSheet()->mergeCells($letter[$lie].$j.':'.$letter[$lie+$arr_tmp1[1]-1].$j);
}
}
$str1=$arr_tmp[0];
if($str1!="^_^"){
if($data["col"][$lie]=="img"){
//实例化插入图片类
if(is_file($str1)){
//$image_size=getimagesize($data_body[$row][$lie]);
$objDrawing = new PHPExcel_Worksheet_Drawing();
$objDrawing->setResizeProportional(false);
$objDrawing->setPath($str1);
//$objDrawing->setWidth($image_size[0]); //照片宽度
//$objDrawing->setHeight($image_size[1]);//照片高度
$objDrawing->setCoordinates($letter[$lie].$j);
$objDrawing->setOffsetX(1);
$objDrawing->setOffsetY(1);
$objDrawing->getShadow()->setVisible(true);
//$objDrawing->getShadow()->setDirection(50);
$objDrawing->setWorksheet($excel->getActiveSheet());
}else{
//$excel->getActiveSheet()->setCellValue($letter[$lie].$j," ");
}
}else if($data["col"][$lie]=="str"){
$excel->getActiveSheet()->setCellValueExplicit($letter[$lie].$j,$str1,PHPExcel_Cell_DataType::TYPE_STRING);
}else{
$excel->getActiveSheet()->setCellValue($letter[$lie].$j,$str1);
}
}
}
}
if($download=="y"){
ob_end_clean();
//直接下载
$write = new PHPExcel_Writer_Excel5($excel);
header("Pragma: public");
header("Expires: 0");
header("Cache-Control:must-revalidate, post-check=0, pre-check=0");
header("Content-Type:application/force-download");
header("Content-Type:application/vnd.ms-execl");
header("Content-Type:application/octet-stream");
header("Content-Type:application/download");;
header("Content-Disposition:attachment;filename=".$file_name.".xls");
header("Content-Transfer-Encoding:binary");
$write->save('php://output');
}else{
//保存成文件
$write = new PHPExcel_Writer_Excel5($excel);
$write->save($file_name);
}
}
///////////////////////////////////////////////////////文件操作
//上传文件
function upload_file($original_file,$path,$new_file_name){
make_dir($path);
return copy($original_file,$path."/".$new_file_name);
}
//修改文件名
function modify_file_name($original_file,$new_file_name){
if(is_file($original_file)){
copy($original_file,$new_file_name);
unlink($original_file);
}
}
//创建目录
function make_dir($dir){
if(!is_dir($dir))
mkdir($dir,0777);
}
///删除文件
function del_file($file){
if(is_file($file))
return @unlink($file);
}
//写入文件
function write_file($dir,$file_name,$content){
make_dir($dir);
$file=$dir."/".$file_name;
$fp=fopen($file,"w");
if(fwrite($fp,$content))
return true;
else
return false;
}
//写入并覆盖文件
function write_file1($dir,$file_name,$content){
make_dir($dir);
$file=$dir."/".$file_name;
$fp=fopen($file,"w+");
if(fwrite($fp,$content))
return true;
else
return false;
}
//取得上级路径
function get_last_path($p){
if(strpos($p,"\\")){
$arr1=explode("\\",$p);
$str_split="\\";
}else if(strstr($p,"/")){
$arr1=explode("/",$p);
$str_split="/";
}
$p1="";
for($i=0;$i<count($arr1)-1;$i++){
$p1.=$arr1[$i].$str_split;
}
if($p1)
$p1=substr($p1,0,-strlen($str_split));
return $p1;
}
//读取文件内容
function read_file($file){
if(is_file($file)){
$fp=fopen($file,"r");
while($buffer=fread($fp,1024)){
$content.=$buffer;
}
fclose($fp);
}
return $content;
}
//取得文件的后缀名
function get_file_name($file_name){
$arr_tmp=explode(".",$file_name);
$num=count($arr_tmp)-1;
$r="";
for($i=0;$i<$num;$i++){
$r.=$arr_tmp[$i].".";
}
if($r)
$r=substr($r,0,-1);
return $r;
}
//取得文件的后缀名
function get_file_ext($file_name){
$arr_tmp=explode(".",$file_name);
$num=count($arr_tmp)-1;
return strtolower($arr_tmp[$num]);
}
//取得文件的图标
function get_file_ext_icon($file_ext,$property){
$ft="";
switch($file_ext){
case "rm":
case "swf":
$ft=$file_ext;
break;
default:
$ft="avi";
break;
}
return "<img src=\"images/f_".$ft.".gif\" border=\"0\"".$property.">";
}
//检查类型
function check_file_type($str,$type){
$r=false;
$tmp=explode("|",$str);
for($i=0;$i<count($tmp);$i++){
if(strtolower($tmp[$i])==strtolower($type)){
$r=true;
break;
}
}
return $r;
}
//检查文件大小
function check_file_size($f_size,$c_size){
$r=false;
if($f_size/1024<$c_size)
$r=true;
return $r;
}
//制作缩略图
function make_mini_picture($srcFile,$dstFile,$size=200){
$data=GetImageSize($srcFile);
switch($data[2]){
case 1:
$im=@ImageCreateFromGIF($srcFile);
break;
case 2:
$im=@ImageCreateFromJPEG($srcFile);
break;
case 3:
$im=@ImageCreateFromPNG($srcFile);
break;
}
$srcW=ImageSX($im);
$srcH=ImageSY($im);
if($srcW<$size && $srcH<$size){
$dstW=$srcW;
$dstH=$srcH;
}else if($srcW>$srcH){
$dstW=$size;
$dstH=intval($srcH*$size/$srcW);
}else{
$dstH=$size;
$dstW=intval($srcW*$size/$srcH);
}
$ni=imagecreatetruecolor($dstW,$dstH);
imagecopyresampled($ni,$im,0,0,0,0,$dstW,$dstH,$srcW,$srcH);
ImageJpeg($ni,$dstFile);
}
///////////////////////////////////////////////////////数据库操作
function _mysql_connect($t=''){
global $dbhost,$dbuser,$dbpw,$dbname;
switch($t){
case "1":
//
break;
default:
$db=new DB_Sql;
$db->connect($dbhost,$dbuser,$dbpw,$dbname);
break;
}
return $db;
}
//取得结果
function get_db_msg($query){
global $db;
$res=$db->query($query);
$msg=$db->fetch_array($res);
return $msg;
}
///////////////////////////////////////////////////////分页相关函数
//
function get_order_reverse_url($tran_var,$order,$value,$url=''){
$url=$url?$url:$_SERVER[PHP_SELF];
foreach($tran_var as $key1=>$value1){
$other_var.="&".$key1."=".urlencode($value1);
}
if($value==str_replace("!","",$order) && !ereg("!",$order))
$other_var="?order=!".$value.$other_var;
else
$other_var="?order=".$value.$other_var;
$r=$url.$other_var;
return $r;
}
//
function get_order_sql($order){
global $arr_order,$arr_order_d;
$arr=ereg("!",$order)?$arr_order_d:$arr_order;
$order=ereg("!",$order)?str_replace("!","",$order):$order;
foreach($arr as $key => $value){
if($key==$order)
$r=$value;
}
return $r;
}
//
function get_pagesize_option($arr){
global $page_size;
for($i=0;$i<count($arr);$i++){
$r.="<option value='".$arr[$i]."'";
if($page_size==$arr[$i])
$r.=" selected";
$r.=">".$arr[$i]."</option>";
}
return $r;
}
//
function get_order_action($self,$order,$url,$tran_var){
$url=$url?$url:$_SERVER[PHP_SELF];
if(is_array($tran_var)){
foreach($tran_var as $key => $value){
$query.=$key."=".urlencode($value)."&";
}
if(str_replace("!","",$order)==$self){
if(substr($order,strlen($order)-1,1)=="!"){
$query.="order=".$self;
$img="order2h.gif";
}else{
$query.="order=".$self."!";
$img="order1h.gif";
}
}else{
$query.="order=".$self;
$img="order1.gif";
}
return "<a href=\"".$url."?".$query."\"><img src=\"images/".$img."\" border=0></a>";
}else{
return ;
}
}
//
///////////////////////////////////////////////////////目录操作
//
function path_cut0($path){
$tmp=explode("-",$path);
for($i=0;$i<count($tmp);$i++){
if($tmp[$i]>0)
$r.=$tmp[$i]."-";
}
$r=substr($r,0,-1);
return $r;
}
///截去前$num层目录
function path_cut($path,$num){
$tmp=explode("-",$path);
for($i=$num;$i<count($tmp);$i++){
$r.=$tmp[$i]."-";
}
$r=substr($r,0,-1);
return $r;
}
//截去后$num层目录
function path_cutb($path,$num){
$tmp=explode("-",$path);
for($i=0;$i<count($tmp)-$num;$i++){
$r.=$tmp[$i]."-";
}
$r=substr($r,0,-1);
return $r;
}
//截去后$num层目录
function dir_cutb($path,$num){
if(ereg("/",$path)){
$flag="/";
}else{
$flag="\\";
}
$tmp=explode($flag,$path);
$r="";
for($i=0;$i<count($tmp)-$num;$i++){
$r.=$tmp[$i].$flag;
}
$r=substr($r,0,-1);
return $r;
}
//去除目录
function dir_cutc($path){
if(ereg("/",$path)){
$flag="/";
}else{
$flag="\\";
}
$tmp=explode($flag,$path);
$r=$tmp[count($tmp)-1];
return $r;
}
//缩进
function indent($deep){
if($deep>0){
for($i=0;$i<$deep-1;$i++){
$r.="  ";
}
$r.="";
}
return $r;
}
//取得父目录
function get_parent_id($path){
$tmp=explode("-",$path);
$r=$tmp[count($tmp)-1];
$r=$r?$r:"0";
return $r;
}
//取得最后路径
function get_last_id($path){
$tmp=explode("-",$path);
$r=$tmp[count($tmp)];
$r=$r?$r:"0";
return $r;
}
//取得最后路径
function get_last_id1($path){
$tmp=explode("-",$path);
$r=$tmp[count($tmp)-1];
$r=$r?$r:"0";
return $r;
}
//检测是否存在下级目录
function check_subpath($path){
global $db,$table_pre,$_m;
$check=false;
$tmp=get_db_msg("select count(*) 'num' from ".$table_pre."path where module='".$_m."' and path='".$path."'");
if($tmp[num]>0)
$check=true;
return $check;
}
//
function get_deep($path){
$arr=explode("-",$path);
return count($arr);
}
//根据charge_uid,计算charge_path,charge_real_path,
function get_qj_charge($arr_charge_uid){
global $db,$table_pre;
$arr_upath=array();
for($i=0;$i<count($arr_charge_uid);$i++){
$m1=get_db_msg("select id,path from ".$table_pre."client where id='".$arr_charge_uid[$i]."'");
$arr_upath[$i]=$m1["path"]."-".$m1["id"];
}
sort($arr_upath);
//补全代理、区域的路径
$arr_path=array();
for($i=0;$i<count($arr_upath);$i++){
$arr1=explode("-",$arr_upath[$i]);
$tmp="0";
for($j=1;$j<count($arr1);$j++){
$tmp.="-".$arr1[$j];
if(!in_array($tmp,$arr_path))
$arr_path[]=$tmp;
}
}
$str_path=arr_to_str($arr_path);
//
$str_path_real="";
//去掉半选状态
$arr_charge_path_real=array();
for($i=0;$i<count($arr_path);$i++){
$check=get_db_msg("select count(*) 'num' from ".$table_pre."client where (path='".$arr_path[$i]."' or path like '".$arr_path[$i]."-%') and (face='3' or face='4' or face='9')");
$check1=get_charge_path_xj_num($arr_path[$i],$arr_path);
if($check["num"]==$check1){
$arr_charge_path_real[]=$arr_path[$i];
}
//echo $arr_path[$i].":".$check["num"]."|".$check1."<br>";
}
//去掉多余
$arr_charge_path_real1=array();
for($i=0;$i<count($arr_charge_path_real);$i++){
if(get_charge_path_is_sj($arr_charge_path_real[$i],$arr_charge_path_real)=="n"){
$arr_charge_path_real1[]=$arr_charge_path_real[$i];
}
}
$str_path_real=arr_to_str($arr_charge_path_real1);
return array($str_path,$str_path_real);
}
//计算下级客户数
function get_charge_path_xj_num($p,$arr_path){
$r=0;
for($i=0;$i<count($arr_path);$i++){
$tmp=explode($p."-",$arr_path[$i]);
if($tmp[1])
$r++;
}
return $r;
}
//计算是否存在上级
function get_charge_path_is_sj($p,$arr_path){
$r="n";
$path_sj=path_cutb($p,1);
for($i=0;$i<count($arr_path);$i++){
if($path_sj==$arr_path[$i])
$r="y";
}
return $r;
}
//检查区经是否有cid下的所有店铺权限
function check_qj_priv_all($cid){
global $db,$table_pre,$arr_upath;
$m1=get_db_msg("select id,path from ".$table_pre."client where id='".$cid."'");
$this_p=$m1["path"]."-".$cid;
$num1=0;
for($i=0;$i<count($arr_upath);$i++){
if(@ereg($this_p."-",$arr_upath[$i]))
$num1++;
}
$m2=get_db_msg("select count(*) 'num' from ".$table_pre."client where path='".$this_p."' or path like '".$this_p."-%'");
$r="n";
if($m2["num"]==$num1)
$r="y";
return $r;
}
//
function op_path($path,$mod){
global $db,$table_pre;
$op_path="";
$res=$db->query("select * from ".$table_pre."path where module='".$mod."' and deep='1' order by ord");
while($msg=$db->fetch_array($res)){
$op_path.="<option value='".$msg["path"]."-".$msg["id"]."'";
if($path==$msg["path"]."-".$msg["id"])
$op_path.=" selected";
$op_path.=">".$msg[title]."</option>";
}
return $op_path;
}
//
function op_path_two($path,$mod){
global $db,$table_pre;
$op_path="";
$res=$db->query("select * from ".$table_pre."path where module='".$mod."' and deep='1' order by ord");
while($msg=$db->fetch_array($res)){
$check=get_db_msg("select count(*) 'num' from ".$table_pre."path where module='".$mod."' and path='".$msg["path"]."-".$msg["id"]."'");
if($check[num]==0){
$op_path.="<option value='".$msg["path"]."-".$msg["id"]."'";
if($path==$msg["path"]."-".$msg["id"])
$op_path.=" selected";
$op_path.=">".$msg[title]."</option>";
}
$r=$db->query("select * from ".$table_pre."path where module='".$mod."' and path='0-".$msg["id"]."' order by ord");
while($m=$db->fetch_array($r)){
$op_path.="<option value='".$m["path"]."-".$m["id"]."'";
if($path==$m["path"]."-".$m["id"])
$op_path.=" selected";
$op_path.=">".$msg[title]." -> ".$m[title]."</option>";
}
}
return $op_path;
}
//
function op_path_two1($path,$mod){
global $db,$table_pre;
$op_path="";
$res=$db->query("select * from ".$table_pre."path where module='".$mod."' and deep='1' order by ord");
while($msg=$db->fetch_array($res)){
$check=get_db_msg("select count(*) 'num' from ".$table_pre."path where module='".$mod."' and path='".$msg["path"]."-".$msg["id"]."'");
$op_path.="<option value='".$msg["path"]."-".$msg["id"]."'";
if($path==$msg["path"]."-".$msg["id"])
$op_path.=" selected";
$op_path.=">".$msg[title]."</option>";
$r=$db->query("select * from ".$table_pre."path where module='".$mod."' and path='0-".$msg["id"]."' order by ord");
while($m=$db->fetch_array($r)){
$op_path.="<option value='".$m["path"]."-".$m["id"]."'";
if($path==$m["path"]."-".$m["id"])
$op_path.=" selected";
$op_path.=">  ".$m[title]."</option>";
}
}
return $op_path;
}
//
function op_course_chapter($cid,$cpath=''){
global $db,$table_pre;
$op_path="";
$q="select * from ".$table_pre."course_chapter where iid='".$cid."' and deep=1 order by ord";
$r=$db->query($q);
while($m=$db->fetch_array($r)){
//$check=get_db_msg("select count(*) 'num' from ".$table_pre."course_chapter where iid='".$cid."' and path='".$m["path"]."-".$m["id"]."'");
$op_path.="<option value='".$m["path"]."-".$m["id"]."'";
if($cpath==$m["path"]."-".$m["id"])
$op_path.=" selected";
$op_path.=">".$m["title"]."</option>";
$q1="select * from ".$table_pre."course_chapter where deep=2 and path='".$m["path"]."-".$m["id"]."' order by ord";
$r1=$db->query($q1);
while($m1=$db->fetch_array($r1)){
$op_path.="<option value='".$m1["path"]."-".$m1["id"]."'";
if($cpath==$m1["path"]."-".$m1["id"])
$op_path.=" selected";
$op_path.=">  ".$m1["title"]."</option>";
}
}
return $op_path;
}
//
function op_path_two_pid($pid,$mod){
global $db,$table_pre;
$op_path="";
$res=$db->query("select * from ".$table_pre."path where module='".$mod."' and deep='1' order by ord");
while($msg=$db->fetch_array($res)){
$check=get_db_msg("select count(*) 'num' from ".$table_pre."path where module='".$mod."' and path='".$msg["path"]."-".$msg["id"]."'");
$op_path.="<option value='".$msg["id"]."'";
if($pid==$msg["id"])
$op_path.=" selected";
$op_path.=">".$msg["title"]."</option>";
$r=$db->query("select * from ".$table_pre."path where module='".$mod."' and path='0-".$msg["id"]."' order by ord");
while($m=$db->fetch_array($r)){
$op_path.="<option value='".$m["id"]."'";
if($pid==$m["id"])
$op_path.=" selected";
$op_path.=">  ".$m["title"]."</option>";
}
}
return $op_path;
}
//
function op_path_three($path,$mod){
global $db,$table_pre;
$op_path="";
$res=$db->query("select * from ".$table_pre."path where module='".$mod."' and deep='1' order by ord");
while($msg=$db->fetch_array($res)){
$check=get_db_msg("select count(*) 'num' from ".$table_pre."path where module='".$mod."' and path='".$msg["path"]."-".$msg["id"]."'");
if($check[num]==0){
$op_path.="<option value='".$msg["path"]."-".$msg["id"]."'";
if($path==$msg["path"]."-".$msg["id"])
$op_path.=" selected";
$op_path.=">".$msg[title]."</option>";
}
$r=$db->query("select * from ".$table_pre."path where module='".$mod."' and path='0-".$msg["id"]."' order by ord");
while($m=$db->fetch_array($r)){
$check=get_db_msg("select count(*) 'num' from ".$table_pre."path where module='".$mod."' and path='".$m["path"]."-".$m["id"]."'");
if($check[num]==0){
$op_path.="<option value='".$m["path"]."-".$m["id"]."'";
if($path==$m["path"]."-".$m["id"])
$op_path.=" selected";
$op_path.=">".$msg[title]." -> ".$m[title]."</option>";
}
$r1=$db->query("select * from ".$table_pre."path where module='".$mod."' and path='".$m["path"]."-".$m["id"]."' order by ord");
while($m1=$db->fetch_array($r1)){
$op_path.="<option value='".$m1["path"]."-".$m1["id"]."'";
if($path==$m1["path"]."-".$m1["id"])
$op_path.=" selected";
$op_path.=">".$msg[title]." -> ".$m[title]." -> ".$m1[title]."</option>";
}
}
}
return $op_path;
}
//
function op_client_dp($path=''){
global $db,$table_pre;
$op_path="";
$res=$db->query("select * from ".$table_pre."client where face='4' order by path, ord");
while($msg=$db->fetch_array($res)){
$op_path.="<option value='".$msg["id"]."'";
if($path==$msg["id"])
$op_path.=" selected";
$op_path.=">".$msg["title"]."(".$msg["username"].")</option>";
}
return $op_path;
}
//
function op_client_dp1($username){
global $db,$table_pre;
$op_path="";
$res=$db->query("select * from ".$table_pre."client where face='4' order by path, ord");
while($msg=$db->fetch_array($res)){
$op_path.="<option value='".$msg["username"]."'";
if($username==$msg["username"])
$op_path.=" selected";
$op_path.=">".$msg["title"]."(".$msg["username"].")</option>";
}
return $op_path;
}
//
function op_client_all_id($cid=''){
global $db,$table_pre;
$op_path="";
$res=$db->query("select * from ".$table_pre."client order by path,ord");
while($msg=$db->fetch_array($res)){
$op_path.="<option value='".$msg["id"]."'";
if($cid==$msg["id"])
$op_path.=" selected";
$op_path.=">".$msg["title"]."(".$msg["username"].")</option>";
}
return $op_path;
}
//
function op_client($path=''){
global $db,$table_pre;
$op_path="";
$res=$db->query("select * from ".$table_pre."client where face=3 or face=9 order by concat(path,'-',id),ord");
while($msg=$db->fetch_array($res)){
$op_path.="<option value='".$msg["path"]."-".$msg["id"]."'";
if($path==$msg["path"]."-".$msg["id"])
$op_path.=" selected";
$op_path.=">".indent($msg["deep"]).$msg["title"]."(".$msg["username"].")</option>";
}
return $op_path;
}
//
function op_client1($path){
global $db,$table_pre;
$op_path="";
$res=$db->query("select * from ".$table_pre."client where deep='1' order by ord");
while($msg=$db->fetch_array($res)){
$check=get_db_msg("select count(*) 'num' from ".$table_pre."client where path='".$msg["path"]."-".$msg["id"]."'");
if($check["num"]==0){
$op_path.="<option value='".$msg["path"]."-".$msg["id"]."'";
if($path==$msg["path"]."-".$msg["id"])
$op_path.=" selected";
$op_path.=">".$msg["title"]."(".$msg["username"].")</option>";
}
$r=$db->query("select * from ".$table_pre."client where path='".$msg["path"]."-".$msg["id"]."' order by ord");
while($m=$db->fetch_array($r)){
$check=get_db_msg("select count(*) 'num' from ".$table_pre."client where path='".$m["path"]."-".$m["id"]."'");
if($check[num]==0){
$op_path.="<option value='".$m["path"]."-".$m["id"]."'";
if($path==$m["path"]."-".$m["id"])
$op_path.=" selected";
$op_path.=">".$msg["title"]."(".$msg["username"].") -> ".$m["title"]."(".$m["username"].")</option>";
}
$r1=$db->query("select * from ".$table_pre."client where path='".$m["path"]."-".$m["id"]."' order by ord");
while($m1=$db->fetch_array($r1)){
$check=get_db_msg("select count(*) 'num' from ".$table_pre."client where path='".$m1["path"]."-".$m1["id"]."'");
if($check[num]==0){
$op_path.="<option value='".$m1["path"]."-".$m1["id"]."'";
if($path==$m1["path"]."-".$m1["id"])
$op_path.=" selected";
$op_path.=">".$msg["title"]."(".$msg["username"].") -> ".$m["title"]."(".$m["username"].") -> ".$m1["title"]."(".$m1["username"].")</option>";
}
$r2=$db->query("select * from ".$table_pre."client where path='".$m1["path"]."-".$m1["id"]."' order by ord");
while($m2=$db->fetch_array($r2)){
$check=get_db_msg("select count(*) 'num' from ".$table_pre."client where path='".$m2["path"]."-".$m2["id"]."'");
if($check[num]==0){
$op_path.="<option value='".$m2["path"]."-".$m2["id"]."'";
if($path==$m2["path"]."-".$m2["id"])
$op_path.=" selected";
$op_path.=">".$msg["title"]."(".$msg["username"].") -> ".$m["title"]."(".$m["username"].") -> ".$m1["title"]."(".$m1["username"].") -> ".$m2["title"]."(".$m2["username"].")</option>";
}
}
}
}
}
return $op_path;
}
//
function get_client_path_title($path,$split='-'){
global $db,$table_pre;
$table=$table_pre."client";
$tmp=explode("-",$path);
$r="";
for($i=0;$i<count($tmp);$i++){
if($tmp[$i]>0){
$t=get_db_msg("select * from ".$table." where id='".$tmp[$i]."'");
$r.=$t["title"].$split;
}
}
$r=substr($r,0,0-strlen($split));
return $r?$r:$path;
}
//
function get_path_title($path,$split='-',$table=''){
global $db,$table_pre;
$table=$table?$table:$table_pre."path";
$tmp=explode("-",$path);
$r="";
for($i=0;$i<count($tmp);$i++){
if($tmp[$i]>0){
$t=get_db_msg("select * from ".$table." where id='".$tmp[$i]."'");
$r.=$t["title"].$split;
}
}
$r=substr($r,0,0-strlen($split));
return $r;
}
//
function get_column_name($table,$id,$column){
global $db;
$msg=get_db_msg("select * from ".$table." where id='".$id."'");
return $msg[$column];
}
//
function parse_deep($deep){
$r="";
for($i=1;$i<$deep;$i++){
$r.="&nbsp;&nbsp;&nbsp;&nbsp;";
}
return $r;
}
///////////////////////////////////////////////////////数学和日期
//
function sizecount($filesize) {
if($filesize >= 1073741824) {
$filesize = round($filesize / 1073741824 * 100) / 100 . ' G';
} elseif($filesize >= 1048576) {
$filesize = round($filesize / 1048576 * 100) / 100 . ' M';
} elseif($filesize >= 1024) {
$filesize = round($filesize / 1024 * 100) / 100 . ' K';
} else {
$filesize = $filesize . ' bytes';
}
return $filesize;
}
//保留小数
function keep_float($f,$num,$thousands_sep=''){
$r=number_format($f,$num,".",$thousands_sep);
return $r;
}
//计算百分比
function deel_bfb($n1,$n2){
if($n2>0 && $n1>0){
$r=round(($n1/$n2)*100);
$r=$r."%";
}else{
$r="0%";
}
return $r;
}
//计算百分比
function deel_bfb1($n1,$n2,$num=2){
if($n2>0 && $n1>0){
$r=keep_float(($n1/$n2)*100,$num);
$r=$r."%";
//$r=$n1.",".$n2;
}else{
$r="0%";
}
return $r;
}
//计算百分比
function deel_bfb3($n1,$num=0){
if($n1>0){
$r=keep_float($n1*100,$num);
$r=$r."%";
//$r=$n1.",".$n2;
}else{
$r="0%";
}
return $r;
}
//
function deel_date1($format,$time){
if($time>0)
return date($format,$time);
else
return "";
}
//处理数字
function deel_num($num){
return $num+1-1;
}
//
function deel_price($price){
if($price==0)
return "";
else
return $price;
}
//
function deel_date_null($date){
$date=str_replace("0000-00-00","",$date);
return $date;
}
//
function format_my_date($date){
$date=str_replace("/","-",$date);
$date=deel_full_date($date);
return $date;
}
//
function get_min_in_array($arr){
if(is_array($arr)){
sort($arr);
return $arr[0];
}else{
return 0;
}
}
//
function check_datetime($datetime){
$datetime=str_replace("-","",$datetime);
$datetime=str_replace(":","",$datetime);
$datetime=str_replace(" ","",$datetime);
$datetime=$datetime+1-1;
return $datetime;
}
//
function day_add($date,$adder){
$tmp=explode("-",$date);
$t=mktime(0,0,0,$tmp[1],$tmp[2]+$adder,$tmp[0]);
return date("Y-n-j",$t);
}
//
function day_add1($date,$adder){
$tmp=explode("-",$date);
$t=mktime(0,0,0,$tmp[1],$tmp[2]+$adder,$tmp[0]);
return date("Y-m-d",$t);
}
//
function day_to_ymd($date){
if(!$date)
return;
$tmp=explode("-",$date);
$t=mktime(0,0,0,$tmp[1],$tmp[2]+$adder,$tmp[0]);
return date("Y-m-d",$t);
}
//日期转化为time()格式
function day_to_time($date){
if(!$date)
return;
$tmp=explode(" ",$date);
$date=explode("-",$tmp[0]);
$time=explode(":",$tmp[1]);
return mktime($time[0],$time[1],$time[2],$date[1],$date[2],$date[0]);
}
//日期转化为time()格式,时间为0:0:0
function day_to_time1($date){
if(!$date)
return;
$date=explode("-",$date);
return mktime(0,0,0,$date[1],$date[2],$date[0]);
}
//日期转化为time()格式,时间为23:59:59
function day_to_time2($date){
$date=explode("-",$date);
return mktime(23,59,59,$date[1],$date[2],$date[0]);
}
//计算天数
function count_day($date1,$date2){
if(!$date2)
return 0;
$Date_List_1=explode("-",$date1);
$Date_List_2=explode("-",$date2);
$d1=mktime(0,0,0,$Date_List_1[1],$Date_List_1[2],$Date_List_1[0]);
$d2=mktime(0,0,0,$Date_List_2[1],$Date_List_2[2],$Date_List_2[0]);
$days=round(($d2-$d1)/3600/24);
return $days;
}
//日期转成yyyy-dd-mm格式
function deel_full_date($date){
$arr=explode("-",$date);
$m=strlen($arr[1])>1?$arr[1]:"0".$arr[1];
$d=strlen($arr[2])>1?$arr[2]:"0".$arr[2];
return $arr[0]."-".$m."-".$d;
}
//
function hb_date($date1,$date2){
$a1=explode("-",$date1);
$a2=explode("-",$date2);
if($date1==$date2){
$r=$a1[0]."".$a1[1]."".$a1[2]."";
}else if($a1[0]==$a2[0]){
if($a1[1]==$a2[1]){
$r=$a1[0]."".$a1[1]."".$a1[2]."日-".$a2[2]."";
}else{
$r=$a1[0]."".$a1[1]."".$a1[2]."日-".$a2[1]."".$a2[2]."";
}
}else{
$r=$a1[0]."".$a1[1]."".$a1[2]."日-".$a2[0]."".$a2[1]."".$a2[2]."";
}
return $r;
}
//
function deel_add_date($add_date){
$arr1=explode(" ",$add_date);
$arr_d=explode("-",$arr1[0]);
$arr_t=explode(":",$arr1[1]);
return $arr_d[2]."".$arr_t[0]."".$arr_t[1]."".$arr_t[2]."";
}
///////////////////////////////////////////////////////权限相关
//
function count_priv_channel($cid,$priv){
$p=explode(",",$priv);
$count=0;
for($i=0;$i<count($p);$i++){
$t1=explode("-",$p[$i]);
if($t1[0]==$cid)
$count++;
}
return $count;
}
//
function print_form_priv($priv=''){
global $db,$table_pre,$arr_priv_tran;
$check=split_priv_str($priv);
$r="<table cellpadding=0 cellspacing=1 width=100% border=0 bgcolor=#ffffff>";
$query="select * from ".$table_pre."channel where deep=1 order by ord";
$res=$db->query($query);
$i=0;
while($msg=$db->fetch_array($res)){
$query1="select * from ".$table_pre."channel where path='0-".$msg["id"]."' order by ord";
$t=get_db_msg("select count(*) 'num' from ".$table_pre."channel where path='0-".$msg["id"]."'");
$t=$t["num"];
$r.="<tr><td style='background-color:#f5f5f5;height:18px'><input type=checkbox id='".$i."_main' onclick=\"check_multi(".$t.",'".$i."')\"";
if(count_priv_channel($msg["id"],$priv)==$t)
$r.=" checked";
$r.="><label for=\"".$i."_main\">".$msg[title]."</label></td></tr><tr><td>";
$res1=$db->query($query1);
$j=0;
while($msg1=$db->fetch_array($res1)){
if(trim($msg1["priv"])!=""){
$r.="&nbsp;&nbsp;<input type=hidden name=priv_id[] value=\"".$msg["id"]."-".$msg1["id"]."\">".$msg1["title"].":";
$a=explode(",",$msg1["priv"]);
for($k=0;$k<count($a);$k++){
$r.="<input type=\"radio\" name=\"priv_".$msg["id"]."_".$msg1["id"]."\" id=\"priv_".$msg["id"]."_".$msg1["id"]."_".$a[$k]."\" value=\"".$a[$k]."\"";
if($k==0)
$r.=" checked";
else if(in_array($msg["id"]."-".$msg1["id"]."|".$a[$k],$check[1]))
$r.=" checked";
$r.="><label style=\"line-height:25px;\" for=\"priv_".$msg["id"]."_".$msg1["id"]."_".$a[$k]."\">".get_main_value($arr_priv_tran,$a[$k])."</label>";
}
$r.="<br>";
}else{
$r.="&nbsp;&nbsp;<input type=checkbox name=priv_id[] id=\"".$i."_".$j."\" value=\"".$msg["id"]."-".$msg1["id"]."\"";
if(in_array($msg["id"]."-".$msg1["id"],$check[0]))
$r.=" checked";
$r.="><label style=\"line-height:25px;\" for=\"".$i."_".$j."\">".$msg1[title]."</label><br>";
}
$j++;
}
$r.="</td></tr>";
$i++;
}
$r.="</table>";
return $r;
}
//
function print_form_priv1($priv=''){
global $arr_priv1;
$check=explode(",",$priv);
$r="";
$i=0;
foreach($arr_priv1 as $k1 => $v1){
$r.="<input type=checkbox id='p1_".$i."' name=\"priv1_".$i."\" value=\"".$k1."\"";
if(in_array($k1,$check))
$r.=" checked";
$r.="><label for=\"p1_".$i."\">".$v1."</label> ";
$i++;
}
return $r;
}
//检查权限
function check_priv1($p,$priv){
$c=explode(",",$priv);
if(in_array($p,$c))
return true;
else
return false;
}
//
function deel_gang($str){
$str=str_replace("-","_",$str);
return $str;
}
//
function deel_0($str){
if($str==0)
$str="";
return $str;
}
//
function add_0($str){
if($str>0)
$str=$str;
else
$str="0";
return $str;
}
//
function deel_01($str){
$str=$str==""?"0":$str;
return $str;
}
//
function deel_td($str){
return $str?$str:"&nbsp;";
}
function deel_td_zz($str){
return $str?$str:"";
}
//
function split_priv_str($priv){
$tmp=explode(",",$priv);
$r=array();
for($i=0;$i<count($tmp);$i++){
$tmp1=explode('|',$tmp[$i]);
$r[0][$i]=$tmp1[0];
$r[1][$i]=$tmp[$i];
}
return $r;
}
//=====================================输出权限字串
function print_priv_str($priv){
global $db,$table_pre,$arr_priv_tran;
$col_priv="";
$priv1=explode(",",$priv);
for($i=0;$i<count($priv1);$i++){
if($priv1[$i]){
$priv3=explode("-",$priv1[$i]);
//$msg1=get_db_msg("select title from ".$table_pre."channel where id='".$priv3[0]."'");
$msg2=get_db_msg("select title from ".$table_pre."channel where id='".$priv3[1]."'");
//$col_priv.=$msg1["title"]."->".$msg2["title"];
$col_priv.=$msg2["title"];
$col_priv.=", ";
}
}
if($col_priv)
$col_priv=substr($col_priv,0,-2);
return $col_priv;
}
//=====================================判断权限
function return_priv($m,$priv){
global $db,$table_pre;
$mc=get_db_msg("select id,path from ".$table_pre."channel where module='".$m."'");
$check=path_cut0($mc["path"]."-".$mc["id"]);
$arr=explode(",",$priv);
$r=array("n","");
for($i=0;$i<count($arr);$i++){
$arr1=explode("|",$arr[$i]);
if($check==$arr1[0]){
$r[0]="y";
$r[1]=$arr1[1];
}
}
return $r;
}
//=====================================写入日志
function set_log($action='',$remark=''){
global $db,$table_pre,$query,$uid;
$ip=$_SERVER["REMOTE_ADDR"];
$db->query("insert into ".$table_pre."log (uid,ip,action,remark,sql_value,add_date) values ('".$uid."','".$ip."','".$action."','".$remark."','".mysql_escape_string($query)."','".time()."')");
}
///////////////////////////////////////////////////////可选类别
////////////输出cate
//
function out_select_cate($form,$name,$width,$cate,$value=''){
global $db,$table_pre;
$width1=$width+18;
$width2=$width+2;
$d_value=$value;
$r="<DIV style=\"POSITION: relative\"><SPAN style=\"MARGIN-LEFT: ".$width."px; OVERFLOW: hidden; WIDTH: 18px\"> <SELECT style=\"MARGIN-LEFT: -".$width."px; WIDTH: ".$width1."px\" onchange=".$form.".".$name.".value=this.value>";
$query="select * from ".$table_pre."keyword where cate='".$cate."' order by no";
$res=$db->query($query);
$count=0;
$r.="<option value=''></option>";
while($msg=$db->fetch_array($res)){
$r.="<option value=\"".$msg[title]."\"";
if($msg[title]==$d_value)
$r.=" selected";
$r.=">".$msg[title]."</option>";
$count++;
}
$r.="</SELECT></SPAN><INPUT style=\"LEFT: 0px; WIDTH: ".$width2."px; POSITION: absolute;z-index:10000\" value=\"".$d_value."\" name=\"".$name."\"></DIV>";
return $r;
}
//
function out_select_cate1($form,$name,$width,$cate,$value=''){
global $db,$table_pre;
$width1=$width+18;
$d_value=$value;
$r="<input id=\"".$name."\" name=\"".$name."\" value=\"".$d_value."\" type=\"text\" style=\"width:".$width."px;POSITION: absolute\">
<select name=\"".$name."_s_cate\" id=\"".$name."_s_cate\" onchange=\"document.getElementById('".$name."').value=this.options[this.selectedIndex].value\" style=\"width:".$width1."px;CLIP: rect(auto auto auto ".$width."px);\">";
$query="select * from ".$table_pre."keyword where cate='".$cate."' order by no";
$res=$db->query($query);
$count=0;
$r.="<option value=''></option>";
while($msg=$db->fetch_array($res)){
$r.="<option value=\"".$msg[title]."\"";
if($msg[title]==$d_value)
$r.=" selected";
$r.=">".$msg[title]."</option>";
$count++;
}
$r.="</SELECT>";
return $r;
}
////////////更新
function update_cate($cate,$value){
global $db,$table_pre;
if(trim($value)){
$msg=get_db_msg("select count(*) 'num' from ".$table_pre."keyword where title='".$value."' and cate='".$cate."'");
if($msg[num]==0){
$tmp=get_db_msg("select max(ord) 'ord' from ".$table_pre."keyword where cate='".$cate."'");
$ord=$tmp[ord]+1;
$db->query("insert into ".$table_pre."keyword (ord,cate,title) values ('".$ord."','".$cate."','".$value."')");
}
}
}
//
function update_keyword($cate,$value){
global $db,$table_pre;
$value=trim($value);
if(trim($value)){
$msg=get_db_msg("select count(*) 'num' from ".$table_pre."keyword where title='".$value."' and cate='".$cate."'");
if($msg["num"]==0){
$tmp=get_db_msg("select max(ord) 'ord' from ".$table_pre."keyword where cate='".$cate."'");
if($tmp["ord"]>10)
$ord=$tmp[ord]+1;
else
$ord=11;
$db->query("insert into ".$table_pre."keyword (ord,cate,no,title) values ('".$ord."','".$cate."','".$ord."','".$value."')");
}
}
}
//
function update_keyword_color($code,$title){
global $db,$table_pre;
$title=trim($title);
$code=trim($code);
if($title && $code){
$msg=get_db_msg("select count(*) 'num' from ".$table_pre."keyword where title='".$title."' and no='".$code."' and cate='color'");
if($msg["num"]==0){
$tmp=get_db_msg("select max(ord) 'ord' from ".$table_pre."keyword where cate='color'");
if($tmp["ord"]>0)
$ord=$tmp[ord]+1;
else
$ord=1;
$db->query("insert into ".$table_pre."keyword (ord,cate,no,title) values ('".$ord."','color','".$code."','".$title."')");
}
}
}
////////////op
//
function op_select_cate($cate,$value=""){
global $db,$table_pre;
$r=$db->query("select * from ".$table_pre."keyword where cate='".$cate."' order by no");
$op="";
while($m=$db->fetch_array($r)){
$op.="<option value=\"".$m[title]."\"";
if($value==$m[title])
$op.=" selected";
$op.=">".$m[title]."</option>";
}
return $op;
}
//
function op_select_cate1($cate,$value=""){
global $db,$table_pre;
$r=$db->query("select * from ".$table_pre."keyword where cate='".$cate."' order by no");
$op="";
while($m=$db->fetch_array($r)){
$op.="<option class='option_list' value=\"".$m["no"]."\"";
if($value==$m["no"])
$op.=" selected";
$op.=">".$m["no"]."(".$m["title"].")</option>";
}
return $op;
}
//
function op_select_cate2($cate,$value=""){
global $db,$table_pre;
$r=$db->query("select * from ".$table_pre."keyword where cate='".$cate."' order by no");
$op="";
while($m=$db->fetch_array($r)){
$op.="<option value=\"".$m["no"]."\"";
if($value==$m["no"])
$op.=" selected";
$op.=">".$m["title"]."</option>";
}
return $op;
}
//
function op_select_cate3($cate,$value=""){
global $db,$table_pre;
$r=$db->query("select * from ".$table_pre."keyword where cate='".$cate."' order by no");
$op="";
while($m=$db->fetch_array($r)){
$op.="<option value=\"".$m["no"]."\"";
if($value==$m["no"])
$op.=" selected";
$op.=">".$m["title"]."(".$m["no"].")</option>";
}
return $op;
}
//
function get_cate_title_no($cate,$value){
global $db,$table_pre;
$m=get_db_msg("select * from ".$table_pre."keyword where cate='".$cate."' and no='".$value."' limit 0,1");
$r=trim($m["title"])?trim($m["title"]):$value;
return $r;
}
//
function arr_select($cate,$col1="no",$col2="title"){
global $db,$table_pre;
$r=$db->query("select * from ".$table_pre."keyword where cate='".$cate."' order by no");
$arr=array();
while($m=$db->fetch_array($r)){
$arr[$m[$col1]]=$m[$col2];
}
return $arr;
}
///////////////////////////////////////////////////////编辑器分页
//
function get_text_content($text,$page){
$arr=explode("<P>{:newpage:}</P>",$text);
return $arr[$page];
}
//
function get_text_page($text,$page){
global $id;
$arr=explode("<P>{:newpage:}</P>",$text);
$total=count($arr);
$r="";
if($total>1){
if($page>0)
$r.=" <a href=\"".$_SERVER[PHP_SELF]."?id=".$id."&page=".($page-1)."\">上一页</a> ";
for($i=0;$i<$total;$i++){
$list=$i+1;
if($i==$page){
$r.=" [".$list."] ";
}else{
$r.=" <a href=\"".$_SERVER[PHP_SELF]."?id=".$id."&page=".$i."\">[".$list."]</a> ";
}
}
if($page!=$total-1)
$r.=" <a href=\"".$_SERVER[PHP_SELF]."?id=".$id."&page=".($page+1)."\">下一页</a> ";
}
return $r;
}
///////////////////////////////////////////////////////模板相关
//取得tmpl模板
function template($tpl){
$tpl=THIS_FILE_ROOT."/template/".$tpl.".php";
if(is_file($tpl)){
return $tpl;
}else{
exit("找不到相关模板(".$tpl.")!");
}
}
//
function tmpl($tpl){
$tpl=THIS_FILE_ROOT."/tmpl/".$tpl.".php";
if(is_file($tpl)){
return $tpl;
}else{
exit("找不到相关模板(".$tpl.")!");
}
}
//
function _include($inc){
$inc=THIS_FILE_ROOT."/inc/".$inc.".php";
if(is_file($inc)){
return $inc;
}else{
exit("找不到相关模块(".$inc.")!");
}
}
///////////////////////////////////////////////////////数组
//插入值到最后第二个
function insert_last_2($arr,$v){
$arr1=array();
for($i=0;$i<count($arr);$i++){
if($i<count($arr)-1){
$arr1[]=$arr[$i];
}else{
$arr1[]=$v;
$arr1[]=$arr[$i];
}
}
return $arr1;
}
//找出数组中的重复数据
function find_repeat_data($arr){
$r=array();
$r1=array();
foreach($arr as $k1 => $v1){
if(!in_array($v1,$r)){
$r[$k1]=$v1;
}else{
$r1[$k1]=$v1;
}
}
return array($r,$r1);
}
//累计数组指定索引前面的值的和
function count_arr_num_before($arr,$i){
$r=0;
if($i>0){
for($k=0;$k<$i;$k++){
$r+=$arr[$k];
}
}
return $r;
}
function arr_push($arr,$num){
$r=array();
$i=0;
if($num>0){
foreach($arr as $k => $v){
if($i<=$num){
$r[$k]=$v;
}
$i++;
}
}else{
foreach($arr as $k => $v){
if($i>=abs($num)){
$r[$k]=$v;
}
$i++;
}
}
return $r;
}
//
function arr_minus($arr,$v){
$r=array();
for($i=0,$j=0;$i<count($arr);$i++){
if($arr[$i]!=$v){
$r[$j]=$arr[$i];
$j++;
}
}
return $r;
}
//
function arr_part($arr,$arr_ind){
$r=array();
foreach($arr as $key => $value){
if(in_array($key,$arr_ind))
$r[$key]=$value;
}
return $r;
}
//
function arr_str_minus($str,$v){
$r="";
$arr=explode(",",$str);
for($i=0;$i<count($arr);$i++){
if($arr[$i]!=$v){
$r.=$arr[$i].",";
}
}
if($r)
$r=substr($r,0,-1);
return $r;
}
//
function arr_to_str($arr){
$r="";
for($i=0;$i<count($arr);$i++){
$r.=$arr[$i].",";
}
$r=substr($r,0,-1);
return $r;
}
//
function arr_last_key($arr){
$r="";
if(!is_array($arr))
return;
$i=0;
$len=count($arr);
foreach($arr as $key => $value){
if($i==$len-1)
$r=$key;
$i++;
}
return $r;
}
//
function get_main_radio($arr,$name,$v='',$fuc=''){
$op="";
if(!is_array($arr))
return;
$i=1;
foreach($arr as $key => $value){
$op.="<input type='radio' name='".$name."' id='".$name."_".$i."' value='".$key."'".$fuc."";
if($v==$key)
$op.=" checked";
$op.="><label for='".$name."_".$i."'>".$value."</label> ";
$i++;
}
return $op;
}
//
function get_main_radio2($arr,$num,$name,$v='',$fuc=''){
$op="";
if(!is_array($arr))
return;
if($num>0){
$i=1;
foreach($arr as $key => $value){
if($i<=$num){
$op.="<input type='radio' name='".$name."' id='".$name."_".$i."' value='".$key."'".$fuc."";
if($v==$key)
$op.=" checked";
$op.="><label for='".$name."_".$i."'>".$value."</label> ";
}
$i++;
}
}else{
$i=1;
foreach($arr as $key => $value){
if($i>=abs($num)){
$op.="<input type='radio' name='".$name."' id='".$name."_".$i."' value='".$key."'".$fuc."";
if($v==$key)
$op.=" checked";
$op.="><label for='".$name."_".$i."'>".$value."</label> ";
}
$i++;
}
}
return $op;
}
//
function get_main_checkbox($arr,$name,$v='',$fuc=''){
$op="";
if(!is_array($arr))
return;
$i=1;
if($v)
$check=explode(",",$v);
foreach($arr as $key => $value){
$op.="<input type=\"checkbox\" name=\"".$name."[]\" id=\"".$name."_".$i."\" value=\"".$key."\"".$fuc."";
if(is_array($check)){
if(in_array($key,$check))
$op.=" checked";
}
$op.="><label for='".$name."_".$i."'>".$value."</label> ";
$i++;
}
return $op;
}
//
function get_main_radio1($arr,$name,$v='',$fuc=''){
$op="";
if(!is_array($arr))
return;
$i=1;
foreach($arr as $key => $value){
$op.="<input type='radio' name='".$name."' id='".$name."_".$i."' value='".$value."'".$fuc."";
if($v==$key)
$op.=" checked";
$op.="><label for='".$name."_".$i."'>".$value."</label> ";
$i++;
}
return $op;
}
//
function get_main_op($arr,$v=''){
$op="";
if(!is_array($arr))
return;
foreach($arr as $key => $value){
$op.="<option class='option_list' value='".$key."'";
if($v==$key)
$op.=" selected";
$op.=">".$value."</option>";
}
return $op;
}
//
function get_main_op_arr($arr,$arr_v){
$op="";
if(!is_array($arr))
return;
foreach($arr as $key => $value){
$op.="<option value='".$key."'";
if(is_array($arr_v) && in_array($key,$arr_v))
$op.=" selected";
$op.=">".$value."</option>";
}
return $op;
}
//
function get_main_op1($arr,$v=''){
$op="";
if(!is_array($arr))
return;
foreach($arr as $key => $value){
$op.="<option value='".$key."'";
if($v==$key)
$op.=" selected";
$op.=">".$key."(".$value.")</option>";
}
return $op;
}
//
function get_main_op2($arr,$v,$v1='',$v2=''){
$op="";
if(!is_array($arr))
return;
foreach($arr as $key => $value){
$op.="<option value='".$key."'";
if($v==$key)
$op.=" selected";
$op.=">".$v1.$value.$v2."</option>";
}
return $op;
}
//
function get_op_num($num1,$num2,$v=''){
$op="";
for($i=$num1;$i<=$num2;$i++){
$op.="<option value='".$i."'";
if($v==$i)
$op.=" selected";
$op.=">".$i."</option>";
}
return $op;
}
//
function reverse_array($arr){
if(!is_array($arr))
return;
$r=array();
foreach($arr as $key => $value){
$r[$value]=$key;
}
return $r;
}
//
function get_main_value_num($arr,$k){
if(!is_array($arr))
return;
foreach($arr as $key => $value){
if($key==$k)
return $value;
}
return 0;
}
//
function get_main_value($arr,$k){
if(!is_array($arr))
return;
foreach($arr as $key => $value){
if($key==$k)
return $value;
}
return $k;
}
//
function get_main_value_arr($arr,$str){
if(!is_array($arr))
return;
$tmp=explode(",",$str);
$r="";
for($i=0;$i<count($tmp);$i++){
$r.=get_main_value($arr,$tmp[$i]).",";
}
if($r)
$r=substr($r,0,-1);
return $r;
}
//
function get_main_key($arr,$v){
if(!is_array($arr))
return;
foreach($arr as $key => $value){
if($value==$v)
return $key;
}
return $v;
}
//
function get_main_key1($arr,$v){
for($i=0;$i<count($arr);$i++){
if($arr[$i]==$v)
return $i;
}
return 0;
}
//
function get_key($arr){
if(!is_array($arr))
return;
$arr1=array();
foreach($arr as $key => $value){
$arr1[]=$key;
}
return $arr1;
}
///////////////////////////////////////////////////////远程操作
function get_from_url($url){
$fp=@fopen($url,"r");
if($fp){
while($buffer=fread($fp,1024)){
$content.=$buffer;
}
return $content;
}else{
return false;
}
}
///////////////////////////////////////////////////////ajax
//执行
function ajax_do($url,$method='GET',$arr_success_js=''){
$str="<script>
var xmlhttp=ajaxinit();
var url=\"".$url."\";
xmlhttp.open(\"".$method."\",url,true);
xmlhttp.setRequestHeader(\"Cache-Control\",\"no-cache\");
xmlhttp.onreadystatechange=function(){
if(xmlhttp.readyState==4 && xmlhttp.status==200){
//alert(xmlhttp.responseText);
".$arr_success_js."
}
}
xmlhttp.send(null);
</script>";
return $str;
}
///////////////////////////////////////////////////////其他
//
function get_sex_op($value=1){
global $arr_gender;
$r="";
foreach($arr_gender as $k => $v){
$r.=" <input type=radio name=gender value=\"".$k."\"";
if($k==$value)
$r.=" checked";
$r.=">".$v;
}
return $r;
}
//输出比例图片
function out_good_pic($pic,$width,$height,$property=''){
if(is_file($pic))
$wh=GetImageSize($pic);
else
return "<img src=\"images/blank.gif\" border=\"0\" width=\"".$width."\" height=\"".$height."\" ".$property.">";
$tmp="";
if($width<$wh[0] || $height<$wh[1]){
if(($wh[0]/$width)>($wh[1]/$height))
$tmp=" width=\"".$width."\"";
else
$tmp=" height=\"".$height."\"";
}
return "<img src=\"".$pic."\"".$tmp." border=\"0\" ".$property.">";
}
//输出图片实际高度
function get_good_pic_height($pic,$width,$height){
if(is_file($pic)){
$wh=GetImageSize($pic);
}else{
$pic1=str_replace("content://com.muchuang.edt/","../",$pic).".jpg";
if(is_file($pic1))
$wh=GetImageSize($pic1);
}
$h=0;
if($width<$wh[0] || $height<$wh[1]){
if(($wh[0]/$width)>($wh[1]/$height)){
$h=round($wh[1]*$width/$wh[0]);
}else{
$h=$height;
}
}else{
$h=$wh[1];
}
return $h;
}
//给出按比例图片的参数
function out_good_pic_set($pic,$width,$height){
if(is_file($pic)){
$wh=GetImageSize($pic);
}else{
$pic1=str_replace("content://com.muchuang.edt/","../",$pic).".jpg";
if(is_file($pic1))
$wh=GetImageSize($pic1);
}
$tmp="";
if($width<$wh[0] || $height<$wh[1]){
if(($wh[0]/$width)>($wh[1]/$height)){
$tmp=" width='".$width."' height='".round($wh[1]*$width/$wh[0])."'";
}else{
$tmp=" width='".round($wh[0]*$height/$wh[1])."' height='".$height."'";
}
}else{
$tmp=" width='".$wh[0]."' height='".$wh[1]."'";
}
return $tmp;
}
//=======================================================给出按比例图片的参数
function out_good_pic_set_arr($pic,$width,$height){
$w1=$h1=0;
if(is_file($pic)){
$wh=GetImageSize($pic);
}else{
$pic1=str_replace("content://com.muchuang.edt/","../",$pic).".jpg";
if(is_file($pic1))
$wh=GetImageSize($pic1);
}
$tmp="";
if($width<$wh[0] || $height<$wh[1]){
if(($wh[0]/$width)>($wh[1]/$height)){
$w1=$width;
$h1=round($wh[1]*$width/$wh[0]);
}else{
$w1=round($wh[0]*$height/$wh[1]);
$h1=$height;
}
}else{
$w1=$wh[0];
$h1=$wh[1];
}
return array($w1,$h1);
}
//
function check_cookie(){
$login_uid=$_COOKIE[THIS_COOKIE];
if($login_uid>0){
return $login_uid;
}else{
url_redirect("./?manage=y");
exit();
}
}
//
function check_cookie_jxs(){
$login_uid=$_COOKIE["izzen_2011w_jxs"];
if($login_uid>0){
return $login_uid;
}else{
url_redirect("./");
exit();
}
}
//
function get_video_url($v){
$max_video_link=200;
$v=explode("\n",$v);
return $v[0];
}
//
function out_answer($type,$answer){
$arr_new_answer=array("y"=>"","n"=>"");
if($type=="1")
$r=get_main_value($arr_new_answer,$answer);
else
$r=$answer;
return $r;
}
//
function format_time_minute($t){
$r=$t?$t."分钟":"--";
return $r;
}
//
function format_num($num){
$num=$num+1-1;
return $num;
}
//取得订单数量
function get_order_num($id,$color,$bx,$size){
global $uid,$db,$table_pre,$_key;
$tmp1=get_db_msg("select * from ".$table_pre."order where _key='".$_key."' and uid='".$uid."' and iid='".$id."' and color='".$color."' and bx='".$bx."'");
$r=$tmp1["num_".strtolower($size)];
$r=$r>0?$r:"";
return $r;
}
//尺码sql脚本
function get_size_sql($t){
global $sys_size_num;
$r="";
switch($t){
case "sum";
for($s1=1;$s1<=$sys_size_num;$s1++){
$r.="num_".$s1."+";
}
if($r)
$r=substr($r,0,-1);
break;
case "suma";
for($s1=1;$s1<=$sys_size_num;$s1++){
$r.="a.num_".$s1."+";
}
if($r)
$r=substr($r,0,-1);
break;
case "sum1";
for($s1=1;$s1<=$sys_size_num;$s1++){
$r.="sum(num_".$s1.") 'num_".$s1."',";
}
if($r)
$r=substr($r,0,-1);
break;
case "sum_size_je";
for($s1=1;$s1<=$sys_size_num;$s1++){
$r.="sum(num_".$s1."*price) 'je_".$s1."',";
}
if($r)
$r=substr($r,0,-1);
break;
case "update":
for($s1=1;$s1<=$sys_size_num;$s1++){
$v1="num_".$s1;
global $$v1;
$r.=$v1."='".$$v1."',";
}
if($r)
$r=substr($r,0,-1);
break;
case "insert1":
for($s1=1;$s1<=$sys_size_num;$s1++){
$r.="num_".$s1.",";
}
if($r)
$r=substr($r,0,-1);
break;
case "inserta":
for($s1=1;$s1<=$sys_size_num;$s1++){
$r.="a.num_".$s1.",";
}
if($r)
$r=substr($r,0,-1);
break;
case "insert2":
for($s1=1;$s1<=$sys_size_num;$s1++){
$v1="num_".$s1;
global $$v1;
$r.="'".$$v1."',";
}
if($r)
$r=substr($r,0,-1);
break;
case "count_total":
$r=0;
for($s1=1;$s1<=$sys_size_num;$s1++){
$v1="num_".$s1;
global $$v1;
$r+=$$v1;
}
break;
}
return $r;
}
//取得款号订单数量
function get_order_num_kh($id){
global $uid,$db,$table_pre,$_key;
$r=0;
$tmp1=get_db_msg("select sum(".get_size_sql("sum").") 'num' from ".$table_pre."order where uid='".$uid."' and iid='".$id."' and _key='".$_key."'");
$r=$tmp1["num"];
if($r>0)
return $r;
else
return ;
}
//
function get_set($k){
global $db,$table_pre;
$m=get_db_msg("select * from ".$table_pre."set where _k='".$k."'");
if($m["id"]>0)
return $m["_v"];
else
return "";
}
//
function get_set_title($k,$v){
global $db,$table_pre;
$r="";
$m=get_db_msg("select * from ".$table_pre."set where _k='".$k."'");
$tmp=explode(",",$m["_t1"]);
for($i=0;$i<count($tmp);$i++){
$tmp1=explode("|",$tmp[$i]);
if($tmp1[0]==$v)
$r=$tmp1[1];
}
return $r;
}
//
function deel_color($c){
if($c){
$arr=explode(",",$c);
$b="";
for($i=0;$i<count($arr);$i++){
$arr1=explode("-",$arr[$i]);
$b.=$arr1[0].",";
}
if($b)
$b=substr($b,0,-1);
return $b;
}else{
return;
}
}
//格式化规格
function deel_gg($gg){
$gg=str_replace("",",",$gg);
return $gg;
}
//
function show_color($c){
global $table_pre,$db;
if($c){
$arr=explode(",",$c);
$b="";
for($i=0;$i<count($arr);$i++){
$arr1=get_cate_title_no("color",$arr[$i]);
$b.=$arr[$i]."-".$arr1.",";
}
if($b)
$b=substr($b,0,-1);
return $b;
}else{
return;
}
}
//
function get_num_je_size($s,$s_group_id){
global $table_pre,$db,$con,$s_key;
$s=strtolower($s);
$m1=get_db_msg("select sum(num_".$s.") 'num',sum(num_".$s."*price) 'je' from ".$table_pre."order where _key='".$s_key."' and size_group_id='".$s_group_id."' ".$con);
return array($m1["num"],$m1["je"]);
}
//
function get_num_je_size_category($s,$cate,$no){
global $table_pre,$db,$con,$s_key;
$s=strtolower($s);
$m1=get_db_msg("select sum(num_".$s.") 'num',sum(num_".$s."*price) 'je' from ".$table_pre."order where _key='".$s_key."' and ".$cate."='".$no."' ".$con);
return array($m1["num"],$m1["je"]);
}
//
function get_num_size($s){
global $table_pre,$db,$uid,$s_key;
$je=0;
$s=strtolower($s);
$m1=get_db_msg("select sum(num_".$s.") 'num' from ".$table_pre."order where uid='".$uid."' and ka<>'y' and _key='".$s_key."'");
return $m1["num"];
}
//
function get_num_color($iid,$color){
global $table_pre,$db,$_key;
$je=0;
$s=strtolower($s);
$m1=get_db_msg("select sum(".get_size_sql("sum").") 'num' from ".$table_pre."order where iid='".$iid."' and color='".$color."' and _key='".$_key."'");
return $m1["num"]>0?$m1["num"]:"0";
}
//
function get_num_client($iid,$uid){
global $table_pre,$db,$_key;
$m1=get_db_msg("select count(distinct uid) 'num' from ".$table_pre."order where iid='".$iid."' and _key='".$_key."'");
return $m1["num"]>0?$m1["num"]:"0";
}
function get_num_client_color($iid,$color,$uid){
global $table_pre,$db,$_key;
$m1=get_db_msg("select count(distinct uid) 'num' from ".$table_pre."order where iid='".$iid."' and color='".$color."'");
return $m1["num"]>0?$m1["num"]:"0";
}
//取得自搭配图片
function get_zydp_pic($pic,$t='mini'){
global $sys_zydp_pic_path_mini,$sys_zydp_pic_path_big;
$v1="sys_zydp_pic_path_".$t;
$hz=($t=="mini")?"jpg":"png";
$pic="../attachments/zydp/".$$v1."/".$pic.".".$hz;
if(!is_file($pic)){
$pic="images/no_pic_80.gif";
}
return $pic;
}
//取得自由陈列图片
function get_zycl_pic($pic,$t='mini'){
global $sys_zycl_pic_path_mini,$sys_zycl_pic_path_gan,$sys_zydp_pic_path_zen1,$sys_zydp_pic_path_zen2;
$v1="sys_zycl_pic_path_".$t;
$hz=($t=="mini")?"jpg":"png";
$pic="../attachments/zycl/".$$v1."/".$pic.".".$hz;
if(!is_file($pic)){
$pic="images/no_pic_80.gif";
}
return $pic;
}
//
function get_kh_picture($no,$main_pic,$color){
$pic="";
if(trim($main_pic)){
$pic="../attachments/design/mini/".$no."_".$main_pic.".jpg";
}
if(!is_file($pic)){
$pic="../attachments/design/mini/".$no.".jpg";
}
if(!is_file($pic)){
$tmp=explode(",",$color);
for($j=0;$j<count($tmp);$j++){
$pic="../attachments/design/mini/".$no."_".$tmp[$j].".jpg";
if(is_file($pic))
break;
}
}
if(!is_file($pic)){
$pic="images/no_pic_80.gif";
}
return $pic;
}
//
function get_kh_color_picture($no,$c){
$pic="../attachments/design/mini/".$no."_".$c.".jpg";
if(!is_file($pic))
$pic="../attachments/design/mini/".$no.".jpg";
if(!is_file($pic))
$pic="images/no_pic_80.gif";
return $pic;
}
//
function get_kh_color_picture_big($no,$c){
$pic="../attachments/design/big/".$no."_".$c.".jpg";
if(!is_file($pic))
$pic="../attachments/design/big/".$no.".jpg";
if(!is_file($pic))
$pic="images/no_pic_big.gif";
return $pic;
}
//
function get_kh_picture_big($no,$main_pic,$color){
$pic="";
if(trim($main_pic)){
$pic="../attachments/design/big/".$no."_".$main_pic.".jpg";
}
if(!is_file($pic)){
$pic="../attachments/design/big/".$no.".jpg";
}
if(!is_file($pic)){
$tmp=explode(",",$color);
for($j=0;$j<count($tmp);$j++){
$pic="../attachments/design/big/".$no."_".$tmp[$j].".jpg";
if(is_file($pic))
break;
}
}
if(!is_file($pic)){
$pic="images/no_pic_big.gif";
}
return $pic;
}
//
function get_kh_dp_big($dph){
global $order_session;
$s_dir=$order_session?$order_session."/":"";
$pic="../attachments/dp/".$s_dir."big/".$dph.".jpg";
if(!is_file($pic)){
$pic="images/no_pic_big.gif";
}
return $pic;
}
//
function get_kh_dp_mini($dph){
global $order_session;
$s_dir=$order_session?$order_session."/":"";
$pic="../attachments/dp/".$s_dir."mini/".$dph.".jpg";
if(!is_file($pic)){
$pic="images/no_pic_80.gif";
}
return $pic;
}
//
function get_kh_cc_big($cch){
global $order_session;
$s_dir=$order_session?$order_session."/":"";
$pic="../attachments/cc/".$s_dir."big/".$cch.".jpg";
if(!is_file($pic)){
$pic="images/no_pic_big.gif";
}
return $pic;
}
//
function get_kh_cc_mini($cch){
global $order_session;
$s_dir=$order_session?$order_session."/":"";
$pic="../attachments/cc/".$s_dir."mini/".$cch.".jpg";
if(!is_file($pic)){
$pic="images/no_pic_80.gif";
}
return $pic;
}
//
function get_kh_cl_big($clh){
global $order_session;
$s_dir=$order_session?$order_session."/":"";
$pic="../attachments/cl/".$s_dir."big/".$clh.".jpg";
if(!is_file($pic)){
$pic="images/no_pic_big.gif";
}
return $pic;
}
//
function get_kh_cl_mini($clh){
global $order_session;
$s_dir=$order_session?$order_session."/":"";
$pic="../attachments/cl/".$s_dir."mini/".$clh.".jpg";
if(!is_file($pic)){
$pic="images/no_pic_80.gif";
}
return $pic;
}
//
function get_size_merged(){
global $table_pre,$db;
$arr_size_merged=array();
$r1=$db->query("select no from ".$table_pre."size group by no order by no");
while($m1=$db->fetch_array($r1)){
$arr_size_merged[]=$m1["no"];
}
return $arr_size_merged;
}
//
//判断是否买断
function check_md($kh,$color,$bx,$size,$dj=''){
global $db,$table_pre;
if($dj)
$sql_dj=" (dj='".$dj."' or dj='') and ";
else
$sql_dj="";
$r="n";
$check=get_db_msg("select count(*) 'num' from ".$table_pre."kh_md where".$sql_dj." kh='".$kh."'");
if($check["num"]>0){
//买断款
$check=get_db_msg("select id,price from ".$table_pre."kh_md where".$sql_dj." kh='".$kh."' and color='' and bx='' and size=''");
if($check["id"]>0)
return $check["price"];
//买断颜色
$check=get_db_msg("select id,price from ".$table_pre."kh_md where".$sql_dj." kh='".$kh."' and color='".$color."' and bx='' and size=''");
if($check["id"]>0)
return $check["price"];
//买断杯型
$check=get_db_msg("select id,price from ".$table_pre."kh_md where".$sql_dj." kh='".$kh."' and color='".$color."' and bx='".$bx."' and size=''");
if($check["id"]>0)
return $check["price"];
//买断尺码
$check=get_db_msg("select id,price,size from ".$table_pre."kh_md where".$sql_dj." kh='".$kh."' and color='".$color."' and bx='".$bx."'");
if($check["id"]>0){
$arr1=explode(",",$check["size"]);
if(in_array($size,$arr1))
return $check["price"];
}
}
return $r;
}
//判断是否不予下单尺码
function check_size_not($kh,$color,$bx,$size){
global $db,$table_pre;
$r="n";
$check=get_db_msg("select count(*) 'num' from ".$table_pre."size_not");
if($check["num"]>0){
//款
$check=get_db_msg("select id from ".$table_pre."size_not where kh='".$kh."' and color='' and bx='' and size=''");
if($check["id"]>0)
return "y";
//颜色
$check=get_db_msg("select id from ".$table_pre."size_not where kh='".$kh."' and color='".$color."' and bx='' and size=''");
if($check["id"]>0)
return "y";
//杯型
$check=get_db_msg("select id from ".$table_pre."size_not where kh='".$kh."' and color='".$color."' and bx='".$bx."' and size=''");
if($check["id"]>0)
return "y";
//尺码
$check=get_db_msg("select id,size from ".$table_pre."size_not where kh='".$kh."' and color='".$color."' and bx='".$bx."'");
if($check["id"]>0){
$arr1=explode(",",$check["size"]);
if(in_array($size,$arr1))
return "y";
}
}
return $r;
}
//取得吊牌价格
function get_price_dp($cid,$khid,$color='',$bx=''){
global $db,$table_pre,$is_multi_price,$child_sizegroup_title;
$is_ggk=is_ggk($khid);
if($is_ggk=="y"){
//有规格
$con1="";
if($color)
$con1.=" and color='".$color."'";
if($bx)
$con1.=" and gg='".$bx."'";
$m1=get_db_msg("select sum(price)/count(*) 'price' from ".$table_pre."kh_gg where iid='".$khid."'".$con1);
$price=$m1["price"];
}else{
//无规格
$tmp=get_db_msg("select b.id 'id',a.no 'no' from ".$table_pre."kh a,".$table_pre."keyword b where a.id='".$khid."' and b.id=a.size_group and b.cate='size' and b.title='".$child_sizegroup_title."'");
if($tmp["id"]>0){
//童装尺码异价
$tmp1=get_db_msg("select price from ".$table_pre."size_bx where no='".$tmp["no"]."' and bx='".$bx."'");
$price=$tmp1["price"];
}else{
if($is_multi_price=="y"){
$m1=get_db_msg("select dp_price from ".$table_pre."client where id='".$cid."'");
$zd_price=$m1["dp_price"]?$m1["dp_price"]:"price1";
}else{
$zd_price="price";
}
$m_kh=get_db_msg("select ".$zd_price." from ".$table_pre."kh where id='".$khid."'");
$price=$m_kh[$zd_price];
}
}
return deel_num($price);
}
//取得结算价
function get_price_zk($cid,$khid,$color='',$bx=''){
global $db,$table_pre,$zk_type;
if($zk_type=="client"){
//折扣到客户
$m1=get_db_msg("select id,zk from ".$table_pre."client where id='".$cid."'");
$zk=$m1["zk"]>0?$m1["zk"]:1;
$price_dp=get_price_dp($cid,$khid,$color,$bx);
$price_zk=$price_dp*$zk;
}else{
if($zk_type!=""){
$price_zk=0;
$m1=get_db_msg("select * from ".$table_pre."zk where cid='".$cid."' and iid='".$khid."'");
if($zk_type=="kl"){
//扣率
$price_dp=get_price_dp($cid,$khid,$color,$bx);
$zk=($m1["id"]>0)?$m1["zk"]:1;
$price_zk=$price_dp*$zk;
}else{
//金额
if($m1["price"]>0){
$price_zk=$m1["price"];
}else{
$price_zk=get_price_dp($cid,$khid,$color,$bx);
}
}
}else{
$price_zk=get_price_dp($cid,$khid,$color,$bx);
}
}
return $price_zk;
}
//是否设置了折扣
function is_set_zk($cid,$khid){
global $db,$table_pre,$zk_type;
$r="n";
if($zk_type=="client"){
$m1=get_db_msg("select id,zk from ".$table_pre."client where id='".$cid."'");
if($m1["zk"]<1){
$r="y";
}
}else{
$m1=get_db_msg("select id from ".$table_pre."zk where cid='".$cid."' and iid='".$khid."'");
if($m1["id"]>0)
$r="y";
}
return $r;
}
function cache_order($uid,$khid,$color,$bx){
global $db,$table_pre,$zk_type,$bx_sizegroup_title,$child_sizegroup_title,$is_multi_price,$_key;
$price_zk_dl=$price_md=0;
//文胸
if($bx_sizegroup_title){
$tmp=get_db_msg("select id from ".$table_pre."keyword where cate='size' and title='".$bx_sizegroup_title."' limit 0,1");
$bx_sizegroup_id=$tmp["id"];
}else{
$bx_sizegroup_id=0;
}
//童装
if($child_sizegroup_title){
$tmp=get_db_msg("select id from ".$table_pre."keyword where cate='size' and title='".$child_sizegroup_title."' limit 0,1");
$child_sizegroup_id=$tmp["id"];
}else{
$child_sizegroup_id=0;
}
$m=get_db_msg("select * from ".$table_pre."order where uid='".$uid."' and iid='".$khid."' and color='".$color."' and bx='".$bx."' and _key='".$_key."'");
if($m["id"]>0){
//
//------计算结算金额
$jsje=$jsje_dl=$mdje=0;
$m_kh=get_db_msg("select no,size_group,size from ".$table_pre."kh where id='".$khid."'");
$m_client=get_db_msg("select id,path from ".$table_pre."client where id='".$uid."'");
$upath=$m_client["path"]."-".$m_client["id"];
//取得杯型
if($m_kh["size_group"]==$bx_sizegroup_id){
//文胸
$tmp=get_db_msg("select size from ".$table_pre."size_bx where no='".$m_kh["no"]."' and bx='".$bx."'");
$arr_size=explode(",",$tmp["size"]);
}else if($m_kh["size_group"]==$child_sizegroup_id){
//童装
$tmp=get_db_msg("select size from ".$table_pre."size_bx where no='".$m_kh["no"]."' and bx='".$bx."'");
$arr_size=explode(",",$tmp["size"]);
}else{
$arr_size=explode(",",$m_kh["size"]);
}
//
$dl_uid=get_dl_id($upath);
$qy_uid=get_qy_id($upath);
//
$price_zk=get_price_zk($uid,$khid,$color,$bx);
if($dl_uid>0 && is_set_zk($dl_uid,$khid)=="y"){
$price_zk_dl=get_price_zk($dl_uid,$khid,$color,$bx);
}else{
$price_zk_dl=$price_zk;
}
$price_dp=get_price_dp($uid,$khid,$color,$bx);
$num=0;
for($i=0;$i<count($arr_size);$i++){
$num_tmp=$m["num_".$arr_size[$i]];
if($num_tmp>0){
$price_md=check_md($m_kh["no"],$m["color"],$bx,$arr_size[$i]);
//代理商结算金额
if($price_md!="n"){
$price_zk1=$price_md>0?$price_md:$price_zk;
$price_zk1_dl=$price_md>0?$price_md:$price_zk_dl;
$mdje+=$num_tmp*$price_zk1;
}else{
$price_zk1=$price_zk;
$price_zk1_dl=$price_zk_dl;
}
$jsje+=$num_tmp*$price_zk1;
$jsje_dl+=$num_tmp*$price_zk1_dl;
$num+=$num_tmp;
}
}
$je=$num*$price_dp;
$q1="update ".$table_pre."order set price='".deel_num($price_dp)."',price_zk='".deel_num($price_zk)."',num='".$num."',je='".deel_num($je)."',jsje='".deel_num($jsje)."',jsje_dl='".deel_num($jsje_dl)."',mdje='".deel_num($mdje)."',qy='".$qy_uid."',dl='".$dl_uid."',upath='".$upath."' where id='".$m["id"]."'";
$db->query($q1);
}
}
//
function set_order_total($uid){
global $db,$table_pre,$_key;
$order_num=$order_num1=0;
$order_money=$order_money_zk=$order_money1=$order_money1_zk=$order_money_md=0;
$m1=get_db_msg("select id,path,face from ".$table_pre."client where id='".$uid."'");
if($m1["face"]=="4"){
$jsje_title="jsje";
$con_uid="uid='".$uid."'";
}else{
$jsje_title="jsje_dl";
$con_uid="upath like '".$m1["path"]."-".$m1["id"]."-%'";
}
//所有
$tmp=get_db_msg("select sum(num) 'num',sum(je) 'je',sum(".$jsje_title.") 'jsje',sum(mdje) 'mdje' from ".$table_pre."order where ka<>'y' and _key='".$_key."' and ".$con_uid);
$order_num=$tmp["num"];
$order_money=$tmp["je"];
$order_money_zk=$tmp["jsje"];
$order_money_md=$tmp["mdje"];
//成衣
$tmp=get_db_msg("select sum(num) 'num',sum(je) 'je',sum(".$jsje_title.") 'jsje' from ".$table_pre."order where ka<>'y' and ".$con_uid." and is_sp<>'y' and _key='".$_key."'");
$order_num1=$tmp["num"];
$order_money1=$tmp["je"];
$order_money1_zk=$tmp["jsje"];
$db->query("update ".$table_pre."client set order_num='".$order_num."',order_num1='".$order_num1."',order_money='".$order_money."',order_money_zk='".$order_money_zk."',order_money1='".$order_money1."',order_money1_zk='".$order_money1_zk."',order_money_md='".$order_money_md."' where id='".$uid."'");
}
//
function set_order_total_all(){
global $db,$table_pre,$_key;
$q="select * from ".$table_pre."client where face='4'";
$r=$db->query($q);
while($m=$db->fetch_array($r)){
set_order_total($m["id"]);
}
}
//
function get_jgd($price){
global $db,$table_pre;
$re="";
$q="select * from ".$table_pre."keyword where cate='jgd' order by no";
$r=$db->query($q);
while($m=$db->fetch_array($r)){
if(check_jgd($price,$m["title"])){
$re=$m["no"];
}
}
return $re;
}
//
function check_jgd($price,$jgd){
$r=false;
if(strpos($jgd,"以下")){
$p=str_replace("以下","",$jgd);
if($price<$p)
$r=true;
}else if(strpos($jgd,"以上")){
$p=str_replace("以上","",$jgd);
if($price>$p)
$r=true;
}else if(strpos($jgd,"-")){
$p=explode("-",$jgd);
if($price>=$p[0] && $price<=$p[1])
$r=true;
}
return $r;
}
//
function get_client_autocompelete($face='',$show_all='y',$all_title=''){
global $db,$table_pre;
$all_title=$all_title?$all_title:"所有客户";
$str="var clients = [\n";
if($show_all=="y")
$str.="{id:\"all\",t:\"-".$all_title."-\",u:\"_all_\",p:\"0\"},\n";
$con=$face?" where face='".$face."'":"";
$q="select id,title,username,path,CONCAT(path,'-',id) 'abs_path' from ".$table_pre."client ".$con." order by abs_path";
$r=$db->query($q);
$i=0;
while($m=$db->fetch_array($r)){
$str.="{id:\"".$m["id"]."\",t:\"".$m["title"]."\",u:\"".$m["username"]."\",p:\"".$m["path"]."-".$m["id"]."\"},\n";
$i++;
}
if($i>0)
$str=substr($str,0,-2);
$str.="];\n";
return $str;
}
//
function get_client_autocompelete_face($arr_face){
global $db,$table_pre;
$str="var clients = [\n";
$con="";
for($i=0;$i<count($arr_face);$i++){
$con.="face='".$arr_face[$i]."' or ";
}
if($con)
$con=" where ".substr($con,0,-4);
$q="select id,title,username,path,CONCAT(path,'-',id) 'abs_path' from ".$table_pre."client ".$con." order by abs_path";
$r=$db->query($q);
$i=0;
while($m=$db->fetch_array($r)){
$str.="{id:\"".$m["id"]."\",t:\"".$m["title"]."\",u:\"".$m["username"]."\",p:\"".$m["path"]."-".$m["id"]."\"},\n";
$i++;
}
if($i>0)
$str=substr($str,0,-2);
$str.="];\n";
return $str;
}
//取得总指标单位
function get_zb_dw($zb_type){
if($zb_type=="js"){
$dw="";
}else{
$dw="";
}
return $dw;
}
//更新指标
function update_zb($cid,$season,$bc,$series,$category,$category1,$num){
global $db,$table_pre,$zbxf;
switch($zbxf){
case "category":
case "category1":
case "season":
case "bc":
$c=get_db_msg("select * from ".$table_pre."client_zb where cid='".$cid."' and ".$zbxf."='".$$zbxf."' limit 0,1");
if($c["id"]>0){
$q1="update ".$table_pre."client_zb set num='".$num."' where id='".$c["id"]."'";
$db->query($q1);
//删除多余记录
$db->query("delete from ".$table_pre."client_zb where id<>'".$c["id"]."' and cid='".$cid."' and ".$zbxf."='".$$zbxf."'");
}else{
$q1="insert into ".$table_pre."client_zb (cid,".$zbxf.",num) values ('".$cid."','".$$zbxf."','".$num."')";
$db->query($q1);
}
//echo $q1."<br>";
break;
case "season_category1":
case "season_category":
case "bc_category1":
case "bc_category":
case "series_category":
case "series_category":
$tmp=explode("_",$zbxf);
$xfzb1=$tmp[0];
$xfzb2=$tmp[1];
$c=get_db_msg("select * from ".$table_pre."client_zb where cid='".$cid."' and ".$xfzb2."='".$$xfzb2."' and ".$xfzb1."='".$$xfzb1."' limit 0,1");
if($c["id"]>0){
$q1="update ".$table_pre."client_zb set num='".$num."' where id='".$c["id"]."'";
$db->query($q1);
//删除多余记录
$db->query("delete from ".$table_pre."client_zb where id<>'".$c["id"]."' and cid='".$cid."' and ".$xfzb2."='".$$xfzb2."' and ".$xfzb1."='".$$xfzb1."'");
}else{
$q1="insert into ".$table_pre."client_zb (cid,".$xfzb1.",".$xfzb2.",num) values ('".$cid."','".$$xfzb1."','".$$xfzb2."','".$num."')";
$db->query($q1);
}
break;
}
}
//取得指标
function get_zb($cid,$season,$bc,$series,$category,$category1){
global $db,$table_pre,$zbxf;
$con="";
if($season)
$con.=" and season='".$season."'";
if($bc)
$con.=" and bc='".$bc."'";
if($series)
$con.=" and series='".$series."'";
if($category)
$con.=" and category='".$category."'";
if($category1)
$con.=" and category1='".$category1."'";
$m=get_db_msg("select * from ".$table_pre."client_zb where cid='".$cid."'".$con."order by id limit 0,1");
$r=$m["num"];
return $r;
}
//取得折扣
function get_zk($cid,$category){
global $db,$table_pre;
$zk=100;
$tmp=get_db_msg("select zk from ".$table_pre."client_zk where cid='".$cid."' and category='".$category."'");
if($tmp["zk"]>0)
$zk=$tmp["zk"];
return $zk;
}
//更新折扣
function update_zk($cid,$no,$num){
global $db,$table_pre,$zkxf;
switch($zkxf){
case "category":
$c=get_db_msg("select * from ".$table_pre."client_zk where cid='".$cid."' and ".$zkxf."='".$no."' limit 0,1");
if($c["id"]>0){
$q1="update ".$table_pre."client_zk set zk='".$num."' where id='".$c["id"]."'";
$db->query($q1);
//删除多余记录
$db->query("delete from ".$table_pre."client_zk where id<>'".$c["id"]."' and cid='".$cid."' and ".$zkxf."='".$no."'");
}else{
$q1="insert into ".$table_pre."client_zk (cid,".$zkxf.",zk) values ('".$cid."','".$no."','".$num."')";
$db->query($q1);
}
//echo $q1."<br>";
break;
}
}
//
function edt_licence_decode($string,$key) {
$expiry=0;
$ckey_length=4;
$key=md5($key?$key:"ifor");
$keya=md5(substr($key,0,16));
$keyb=md5(substr($key,16,16));
$keyc=$ckey_length?(substr($string,0,$ckey_length)):'';
$cryptkey=$keya.md5($keya.$keyc);
$key_length=strlen($cryptkey);
$string=base64_decode(substr($string, $ckey_length));
$string_length=strlen($string);
$result='';
$box=range(0,255);
$rndkey=array();
for($i=0;$i<= 255;$i++) {
$rndkey[$i]=ord($cryptkey[$i % $key_length]);
}
for($j=$i=0;$i<256;$i++) {
$j=($j+$box[$i]+$rndkey[$i]) % 256;
$tmp=$box[$i];
$box[$i]=$box[$j];
$box[$j]=$tmp;
}
for($a=$j=$i=0; $i < $string_length; $i++) {
$a=($a + 1) % 256;
$j=($j + $box[$a]) % 256;
$tmp=$box[$a];
$box[$a]=$box[$j];
$box[$j]=$tmp;
$result .= chr(ord($string[$i]) ^ ($box[($box[$a] + $box[$j]) % 256]));
}
if((substr($result,0,10)==0 || substr($result,0,10)-time()>0) && substr($result,10,16) == substr(md5(substr($result,26).$keyb),0,16)) {
return substr($result, 26);
} else {
return '';
}
}
//
function check_arr_select_show($no){
global $db,$table_pre;
$check=get_db_msg("select * from ".$table_pre."keyword where cate='arr_select' and no='".$no."'");
if($check["flag_ka"]=="y")
return true;
else
return false;
}
function set_client_licence($arr_lic){
/*
global $db,$table_pre;
$num=$arr_lic[2];
if($arr_lic[4]!="ifor_edt"){
alert_and_back(base64_decode("bGljZW5zZc7EvP6yu8alxeSjoQ=="));
}
if($num>0){
if($arr_lic[6]!="9"){
$c=get_db_msg("select count(*) 'num' from ".$table_pre."client where face='4'");
if($c["num"]>$num){
alert_and_back(base64_decode("ttSyu8bwo6y16sbMyv2zrLn9TGljZW5zZcrayKijrM7et6i9+MjruMOyy7Wlo6E="));
}
}
}else{
alert_and_back(base64_decode("bGljZW5zZc7EvP7Iscqno6E="));
}
*/
}
//更新服务器的连接数
function cache_servers_num(){
global $db,$table_pre;
$q="select * from ".$table_pre."servers";
$r=$db->query($q);
while($m=$db->fetch_array($r)){
$tmp=get_db_msg("select count(*) 'num' from ".$table_pre."servers_online where server_ip='".$m["ip"]."'");
$db->query("update ".$table_pre."servers set num='".$tmp["num"]."' where id='".$m["id"]."'");
}
}
//取得款号的序号,当序号到色或者到款都支持
function get_kh_xh($msg,$color=''){
global $db,$table_pre,$xh_ms;
if($xh_ms=="2"){
//
if(trim($color))
$m1=get_db_msg("select * from ".$table_pre."kh_xh where kh='".$msg["no"]."' and color='".$color."' limit 0,1");
if($m1["id"]>0){
$xh=$m1["xh"];
}else{
$m1=get_db_msg("select * from ".$table_pre."kh_xh where kh='".$msg["no"]."' limit 0,1");
if($m1["id"]>0)
$xh=$m1["xh"];
else
$xh=$msg["xh"];
}
}else{
//到款
$xh=$msg["xh"];
}
return $xh;
}
//处理杯型
function deel_bx($bx){
global $arr_bx;
$bx=strtoupper(trim($bx));
if(in_array($bx,$arr_bx)){
$r=$bx;
}else{
$r="";
}
return $r;
}
//处理款型,童装
function deel_bx_zt($bx){
global $arr_child_bx;
$arr_bx1=array();
foreach($arr_child_bx as $bx1 =>$arr_size1){
$arr_bx1[]=$bx1;
}
if(in_array($bx,$arr_bx1)){
$r=$bx;
}else{
$r="";
}
return $r;
}
//取得上级区域
function get_qy_id($path){
global $db,$table_pre;
$arr_path=explode("-",$path);
for($i=count($arr_path)-1;$i>=0;$i--){
if($arr_path[$i]>0){
$m1=get_db_msg("select id,face from ".$table_pre."client where id='".$arr_path[$i]."'");
if($m1["face"]=="9"){
return $m1["id"];
}
}
}
return "";
}
//取得上级代理
function get_dl_id($path){
global $db,$table_pre;
$arr_path=explode("-",$path);
for($i=count($arr_path)-1;$i>=0;$i--){
if($arr_path[$i]>0){
$m1=get_db_msg("select id,face from ".$table_pre."client where id='".$arr_path[$i]."'");
if($m1["face"]=="3"){
return $m1["id"];
}
}
}
return "";
}
//取得上级代理名称
function get_dl_title($path){
global $db,$table_pre;
$arr_path=explode("-",$path);
for($i=count($arr_path)-1;$i>=0;$i--){
if($arr_path[$i]>0){
$m1=get_db_msg("select id,face,title from ".$table_pre."client where id='".$arr_path[$i]."'");
if($m1["face"]=="3"){
return $m1["title"];
}
}
}
return "";
}
//-------------------------------------------------------------------------计算排行表
//到色计算
function count_ph($uid,$iid,$color){
global $db,$table_pre,$_key;
$c1=get_db_msg("select count(*) 'num' from ".$table_pre."ph");
if($c1["num"]==0)
cache_ph_first();
$m_kh=get_db_msg("select * from ".$table_pre."kh where id='".$iid."'");
$m_client=get_db_msg("select path,username,in_ph from ".$table_pre."client where id='".$uid."'");
if($m_kh["in_ph"]=="y" && $m_client["in_ph"]=="y"){
$qy_id=get_qy_id($m_client["path"]);
//取得选项
$arr_select_no=array();
$sql1=$sql2="";
$q1="select no from ".$table_pre."keyword where cate='arr_select' and flag_ka='y' and no<>'sx' and no<>'sx' and no<>'zd1' and no<>'zd2' and no<>'zd3' order by ord";
$r1=$db->query($q1);
while($m1=$db->fetch_array($r1)){
$sql1.=$m1["no"].",";
$sql2.="'".$m_kh[$m1["no"]]."',";
}
//饰品款
$sql1.="is_sp,";
$sql2.="'".$m_kh["is_sp"]."',";
//
$check=get_db_msg("select * from ".$table_pre."ph where qy='".$qy_id."' and iid='".$iid."' and color='".$color."'");
//
$m1=get_db_msg("select sum(num) 'num',sum(je) 'je' from ".$table_pre."order where qy='".$qy_id."' and iid='".$iid."' and color='".$color."' and ka<>'y' and _key='".$_key."' group by qy,iid,color");
//
if($check["id"]>0){
if($m1["num"]==0)
$q="delete from ".$table_pre."ph where id='".$check["id"]."'";
else
$q="update ".$table_pre."ph set num='".$m1["num"]."',je='".$m1["je"]."' where id='".$check["id"]."'";
}else{
if($m1["num"]>0)
$q="insert into ".$table_pre."ph (iid,qy,no,color,".$sql1."num,je) values ('".$iid."','".$qy_id."','".$m_kh["no"]."','".$color."',".$sql2."'".$m1["num"]."','".$m1["je"]."')";
}
if($q)
$db->query($q);
}
}
//到款计算
function count_ph_uid_kh($uid,$iid){
global $db,$table_pre,$_key;
$c1=get_db_msg("select count(*) 'num' from ".$table_pre."ph");
if($c1["num"]==0)
cache_ph_first();
$m_client=get_db_msg("select path,in_ph from ".$table_pre."client where id='".$uid."'");
$m_kh=get_db_msg("select * from ".$table_pre."kh where id='".$iid."'");
if($m_kh["in_ph"]=="y" && $m_client["in_ph"]=="y"){
$qy_id=get_qy_id($m_client["path"]);
//删除相关数据
$db->query("delete from ".$table_pre."ph where qy='".$qy_id."' and iid='".$iid."'");
//取得选项
$arr_select_no=array();
$sql1="";
$q1="select no from ".$table_pre."keyword where cate='arr_select' and flag_ka='y' and no<>'sx' and no<>'sx' and no<>'zd1' and no<>'zd2' and no<>'zd3' order by ord";
$r1=$db->query($q1);
while($m1=$db->fetch_array($r1)){
$arr_select_no[]=$m1["no"];
$sql1.=$m1["no"].",";
}
//饰品款
$sql1.="is_sp,";
//
$q1="select sum(num) 'num',sum(je) 'je',color from ".$table_pre."order where qy='".$qy_id."' and iid='".$iid."' and _key='".$_key."' and ka<>'y' group by qy,iid,color";
$r1=$db->query($q1);
while($m1=$db->fetch_array($r1)){
//取得选项
$sql2="";
for($i1=0;$i1<count($arr_select_no);$i1++){
$sql2.="'".$m_kh[$arr_select_no[$i1]]."',";
}
$sql2.="'".$m_kh["is_sp"]."',";
if($m1["num"]>0){
$q="insert into ".$table_pre."ph (iid,qy,no,color,".$sql1."num,je) values ('".$iid."','".$qy_id."','".$m_kh["no"]."','".$m1["color"]."',".$sql2."'".$m1["num"]."','".$m1["je"]."')";
//echo $q."<br>";
$db->query($q);
}
}
}
}
//初次读入排行数据
function cache_ph_first(){
global $db,$table_pre;
//取得选项
$arr_select_no=array();
$sql1="";
$q1="select no from ".$table_pre."keyword where cate='arr_select' and flag_ka='y' and no<>'sx' and no<>'sx' and no<>'zd1' and no<>'zd2' and no<>'zd3' order by ord";
$r1=$db->query($q1);
while($m1=$db->fetch_array($r1)){
$arr_select_no[]=$m1["no"];
$sql1.=$m1["no"].",";
}
//饰品款
$sql1.="is_sp,";
$q="select * from ".$table_pre."kh where ka<>'y' and in_ph='y'";
$r=$db->query($q);
while($m=$db->fetch_array($r)){
$arr_color=explode(",",$m["color"]);
$arr_color_ka=explode(",",$m["color_ka"]);
for($k=0;$k<count($arr_color);$k++){
if(!in_array($arr_color[$k],$arr_color_ka)){
//取得选项
$sql2="";
for($i1=0;$i1<count($arr_select_no);$i1++){
$sql2.="'".$m[$arr_select_no[$i1]]."',";
}
$sql2.="'".$m_kh["is_sp"]."',";
$q1="insert into ".$table_pre."ph (iid,qy,no,color,".$sql1."num,je) values ('".$m["id"]."','','".$m["no"]."','".$arr_color[$k]."',".$sql2."'0','0')";
//echo $q1."<br>";
$db->query($q1);
}
}
}
}
//重新缓存排行表
function cache_ph(){
global $db,$table_pre,$_key;
//取得选项
$arr_select_no=array();
$sql1="";
$sql11="";
$q1="select no from ".$table_pre."keyword where cate='arr_select' and flag_ka='y' and no<>'sx' and no<>'sx' and no<>'zd1' and no<>'zd2' and no<>'zd3' order by ord";
$r1=$db->query($q1);
while($m1=$db->fetch_array($r1)){
$arr_select_no[]=$m1["no"];
$sql1.=$m1["no"].",";
$sql11.="o.".$m1["no"].",";
}
//饰品款
$sql1.="is_sp,";
$sql11.="o.is_sp,";
//重新读入数据
$db->query("truncate table ".$table_pre."ph");
//读入订单数据
$q="select o.iid 'iid',o.no 'no',o.color 'color',".$sql11."sum(o.num) 'num',sum(o.je) 'je',o.qy 'qy' from ".$table_pre."order o,".$table_pre."kh k,".$table_pre."client c where o.iid=k.id and o.uid=c.id and o.ka<>'y' and k.in_ph='y' and c.in_ph='y' and o.ka<>'y' and o._key='".$_key."' group by o.qy,o.no,o.color";
$r=$db->query($q);
while($m=$db->fetch_array($r)){
//取得选项
$sql2="";
for($i1=0;$i1<count($arr_select_no);$i1++){
$sql2.="'".$m[$arr_select_no[$i1]]."',";
}
$sql2.="'".$m["is_sp"]."',";
$q1="insert into ".$table_pre."ph (iid,qy,no,color,".$sql1."num,je) values ('".$m["iid"]."','".$m["qy"]."','".$m["no"]."','".$m["color"]."',".$sql2."'".$m["num"]."','".$m["je"]."')";
//echo $q1."<br>";
$db->query($q1);
}
//读入未定款色
$q="select * from ".$table_pre."kh where ka<>'y' and in_ph='y'";
$r=$db->query($q);
while($m=$db->fetch_array($r)){
$arr_color=explode(",",$m["color"]);
$arr_color_ka=explode(",",$m["color_ka"]);
for($k=0;$k<count($arr_color);$k++){
if(!in_array($arr_color[$k],$arr_color_ka)){
$tmp=get_db_msg("select count(*) 'num' from ".$table_pre."ph where iid='".$m["id"]."' and color='".$arr_color[$k]."'");
if($tmp["num"]>0){
//已存在,则不读入
}else{
//不存在,则读入
//取得选项
$sql2="";
for($i1=0;$i1<count($arr_select_no);$i1++){
$sql2.="'".$m[$arr_select_no[$i1]]."',";
}
$sql2.="'".$m["is_sp"]."',";
$q1="insert into ".$table_pre."ph (iid,qy,no,color,".$sql1."num,je) values ('".$m["id"]."','','".$m["no"]."','".$arr_color[$k]."',".$sql2."'0','0')";
//echo $q1."<br>";
$db->query($q1);
}
}
}
}
}
//读取可支持的最大尺码
function get_max_size_num(){
global $db,$table_pre;
$q="show columns from ".$table_pre."order";
$r=$db->query($q);
$max=0;
while($m=$db->fetch_array($r)){
if(substr($m["Field"],0,4)=="num_"){
$arr=explode("_",$m["Field"]);
$max=$arr[1]>$max?$arr[1]:$max;
}
}
return $max;
}
//规范配码规则
function deel_pm_gz($gz){
$gz=str_replace("",":",$gz);
$gz=str_replace("",":",$gz);
$gz=str_replace(";",":",$gz);
$arr1=explode(":",$gz);
$r="";
for($i=0;$i<count($arr1);$i++){
$num=$arr1[$i]+1-1;
$r.=$num.":";
}
if($r)
$r=substr($r,0,-1);
return $r;
}
//检查配码
function check_pm_gz($gz){
$gz=str_replace("",":",$gz);
$gz=str_replace("",":",$gz);
$gz=str_replace(";",":",$gz);
$arr1=explode(":",$gz);
$r="";
$msg="";
for($i=0;$i<count($arr1);$i++){
$num=$arr1[$i]+1-1;
if(!(floor($num)==$num) || $num<0){
$msg="配码不得包含负数或小数!";
return $msg;
}
}
}
//处理显示的金额方式
function deel_je_show($je){
if($je>=100000000){
$je=keep_float(($je/100000000),2)."亿";
}else if($je>=10000){
$je=keep_float(($je/10000),1)."";
}else{
$je=$je;
}
return $je;
}
//单独计算代理商金额
function cache_je_dl($id){
global $db,$table_pre,$_key;
$m=get_db_msg("select path from ".$table_pre."client where id='".$id."'");
$tmp=get_db_msg("select sum(jsje_dl) 'money' from ".$table_pre."order where upath like '".$m["path"]."-".$id."-%' and is_sp<>'y' and _key='".$_key."'");
$order_money_zk=$tmp["money"];
$tmp=get_db_msg("select sum(jsje_dl) 'money' from ".$table_pre."order where upath like '".$m["path"]."-".$id."-%' and is_sp='y' and _key='".$_key."'");
$order_money1_zk=$tmp["money"];
$db->query("update ".$table_pre."client set order_money_zk='".$order_money_zk."',order_money1_zk='".$order_money1_zk."' where id='".$id."'");
}
//
function is_brand(){
global $db,$table_pre;
$r=get_set("is_brand");
$r=$r?$r:"n";
return $r;
}
//取得订单状态
function get_client_state($is_jd,$is_checked){
global $show_jd;
$r="";
if($show_jd=="y"){
if($is_checked=="y"){
$r="已确认";
}else{
if($is_jd=="y"){
$r="已交单";
}else{
$r="未交单";
}
}
}else{
if($is_checked=="y")
$r="已确认";
else
$r="未确认";
}
return $r;
}
//取得订单打印状态
function get_client_print_state($uid){
global $db,$table_pre;
$m1=get_db_msg("select id from ".$table_pre."order_state where cid='".$uid."' and action='打印订单'");
$r="n";
if($m1["id"]>0)
$r="y";
return $r;
}
function get_client_state_all_brand($id){
global $db,$table_pre,$show_jd;
$client_state="";
if($show_jd=="y"){
$c1=get_db_msg("select count(*) 'num' from ".$table_pre."client_brand where cid='".$id."' and is_checked='y'");
$c2=get_db_msg("select count(*) 'num' from ".$table_pre."client_brand where cid='".$id."'");
if($c1["num"]==$c2["num"]){
$client_state="已确认";
}else{
$c1=get_db_msg("select count(*) 'num' from ".$table_pre."client_brand where cid='".$id."' and is_jd='y'");
$c2=get_db_msg("select count(*) 'num' from ".$table_pre."client_brand where cid='".$id."'");
if($c1["num"]==$c2["num"])
$client_state="已交单";
else
$client_state="未交单";
}
}else{
$c1=get_db_msg("select count(*) 'num' from ".$table_pre."client_brand where cid='".$id."' and is_checked='y'");
$c2=get_db_msg("select count(*) 'num' from ".$table_pre."client_brand where cid='".$id."'");
if($c1["num"]==$c2["num"])
$client_state="已确认";
else
$client_state="未确认";
}
return $client_state;
}
//合并尺码
function size_hb($size1,$size2){
$arr1=explode(",",$size1);
$arr2=explode(",",$size2);
$r="";
$arr=array_merge($arr1,$arr2);
$arr1=array();
for($i=0;$i<count($arr);$i++){
$arr1[$i]=$arr[$i];
}
$arr3=array_unique($arr1);
asort($arr3);
$r="";
foreach($arr3 as $j => $s){
$r.=$s.",";
}
if($r)
$r=substr($r,0,-1);
return $r;
}
//翻译词汇
function d_translate($k){
global $arr_sys_lang;
foreach($arr_sys_lang as $k1 => $v1){
if($k==$k1)
return $v1;
}
return $k;
}
//行为分析时间段显示格式化
function deel_date_format($con,$d){
$r1=$r2="";
$d=trim($d);
if($con=="hour"){
$r1=substr($d,8,2)."";
$r2=substr($d,11,2)."";
}else if($con=="minute"){
$r1=substr($d,8,2)."";
$r2=substr($d,11,2)."".substr($d,14,1)."0分";
}else if($con=="half_day"){
$r1=substr($d,8,2)."";
if(substr($d,12,1)=="1")
$r2="上午";
else if(substr($d,12,1)=="2")
$r2="下午";
else
$r2="晚上";
}else{
$r1=substr($d,8,2)."";
}
return $r1.$r2;
}
//
function deel_sql_con_kh($con_kh){
global $db,$table_pre;
$arr1=explode(",",$con_kh);
$r="";
for($i=0;$i<count($arr1);$i++){
$arr2=explode(":",$arr1[$i]);
if($arr2[0] && $arr2[1]){
$m1=get_db_msg("select no from ".$table_pre."keyword where cate='arr_select' and title='".$arr2[0]."' limit 0,1");
$m2=get_db_msg("select no from ".$table_pre."keyword where cate='".$m1["no"]."' and title='".$arr2[1]."' limit 0,1");
$r.=$m1["no"]."<>'".$m2["no"]."' and ";
}
}
if($r)
$r=" and (".substr($r,0,-4).")";
return $r;
}
//检查表是否存在
function check_table_exist($t){
global $db,$table_pre,$dbname;
$check=get_db_msg("select count(*) 'num' from information_schema.TABLES where TABLE_SCHEMA='".$dbname."' and TABLE_NAME='".$t."'");
if($check["num"]>0)
return "y";
else
return "n";
}
//更新规格名称
function insert_gg($gg){
global $db,$table_pre;
if(trim($gg)){
$c=get_db_msg("select id from ".$table_pre."kh_gg_title where title='".$gg."'");
if($c["id"]>0){
//已经有数据
}else{
$db->query("insert ".$table_pre."kh_gg_title (title) values ('".$gg."')");
}
}
}
//取得规格名称
function get_gg_title($gg){
global $db,$table_pre;
$gg_title="";
if(trim($gg)){
$c=get_db_msg("select title from ".$table_pre."kh_gg_title where id='".$gg."'");
$gg_title=$c["title"];
}
return $gg_title;
}
//取得规格编号
function get_gg_id($gg){
global $db,$table_pre;
$ggid="";
if(trim($gg)){
$c=get_db_msg("select id from ".$table_pre."kh_gg_title where title='".$gg."'");
$ggid=$c["id"];
}
return $ggid;
}
//
function is_ggk($khid){
global $db,$table_pre,$is_gg;
$r="n";
if($is_gg){
if(check_table_exist($table_pre."kh_gg")=="y"){
$check_gg=get_db_msg("select count(*) 'num' from ".$table_pre."kh_gg where iid='".$khid."'");
if($check_gg["num"]>0){
$r=$is_gg;
}
}
}
return $r;
}
//
function is_gg_ks($khid,$color){
global $db,$table_pre,$is_gg;
$r="n";
if($is_gg!="n"){
if(check_table_exist($table_pre."kh_gg")=="y"){
$check_gg=get_db_msg("select count(*) 'num' from ".$table_pre."kh_gg where iid='".$khid."' and color='".$color."'");
if($check_gg["num"]>0){
$r=$is_gg;
}
}
}
return $r;
}
//取得跨列值
function get_colspan($i,$total,$var,$js){
$r=$js;
for($j=$i;$j<$total;$j++){
$v1=$var.$j;
global $$v1;
$r=$r*count($$v1);
}
return $r;
}
//
function get_colspan1($i,$var,$js){
$r=$js;
for($j=0;$j<$i;$j++){
$v1=$var.$j;
global $$v1;
$r=$r*count($$v1);
}
return $r;
}
//
function get_sx($color){
global $table_pre,$db;
$q="select * from ".$table_pre."sx";
$r=$db->query($q);
while($m=$db->fetch_array($r)){
$arr=explode(",",$m["_v"]);
for($i=0;$i<count($arr);$i++){
if($arr[$i]==$color)
return $m["no"];
}
}
return "";
}
//给区经增加新增店铺的权限
function add_qj_priv_by_dp($qjid,$dpid){
global $table_pre,$db;
$m_qj=get_db_msg("select id,charge_uid,charge_path,charge_path_real from ".$table_pre."client where id='".$qjid."'");
$m_dp=get_db_msg("select id,path from ".$table_pre."client where id='".$dpid."'");
$dp_sjid=get_last_id1($m_dp["path"]);
if($dp_sjid>0){
//计算str_path;
$arr_path=explode(",",$m_qj["charge_path"]);
$str_path="";
for($i=0;$i<count($arr_path);$i++){
$lid=get_last_id1($arr_path[$i]);
if($lid==$dp_sjid){
$str_path.=$arr_path[$i].",";
$str_path.=$m_dp["path"]."-".$m_dp["id"].",";
}else{
$str_path.=$arr_path[$i].",";
}
}
if($str_path)
$str_path=substr($str_path,0,-1);
//计算str_uid;
$arr_uid=explode(",",$m_qj["charge_uid"]);
if(count($arr_uid)>0)
$str_uid=$m_qj["charge_uid"].",".$dpid;
else
$str_uid=$dpid;
$q2="update ".$table_pre."client set charge_uid='".$str_uid."',charge_path='".$str_path."' where id='".$qjid."'";
$db->query($q2);
return "y";
}else{
return "n";
}
}
//取得订单概览的报名名称
function get_bb_title($bb){
global $table_pre,$db,$sys_bb_cate;
$arr_group_by_title=array();
$r1=$db->query("select no,title from ".$table_pre."keyword where cate='arr_select'");
while($m1=$db->fetch_array($r1)){
$arr_group_by_title[$m1["no"]]=$m1["title"];
}
$arr_group_by_title["size"]="尺码";
$arr_group_by_title["color"]="颜色";
$arr_group_by_title["ks_size"]="款色深度";
if(is_array($sys_bb_cate)){
//------定制报表显示
for($i=0;$i<count($sys_bb_cate);$i++){
$arr1=explode("|",$sys_bb_cate[$i]);
if(count($arr1)>1){
$arr_group_by_title[$sys_bb_cate[$i]]=get_main_value($arr_group_by_title,$arr1[0])."-".get_main_value($arr_group_by_title,$arr1[1]);
}else{
$arr_group_by_title[$sys_bb_cate[$i]]=get_main_value($arr_group_by_title,$arr1[0]);
}
}
}
//------插件报表读取
if(check_table_exist($table_pre."plugin")=="y"){
$q1="select * from ".$table_pre."plugin where cate='client_bb'";
$r1=$db->query($q1);
while($m1=$db->fetch_array($r1)){
$arr_group_by_title["plugin_".$m1["file_name"]]=$m1["title"];
}
}
return get_main_value($arr_group_by_title,$bb)."分析";
}
//计算数组的离散程度
function get_pc($list){
if(count($list)>0){
$avg=array_sum($list)/count($list);
$total_var=0;
foreach ($list as $lv){
if(($lv-$avg)>0)
$total_var+=pow(($lv-$avg),2);
}
return sqrt($total_var/count($list));
}
}
//读取插件名称
function read_plugin_title($content){
$tmp=explode("\n",$content);
$tmp=trim($tmp[1]);
$tmp=str_replace("-","",$tmp);
$tmp=str_replace("//","",$tmp);
$tmp=str_replace("","",$tmp);
$tmp=str_replace("插件名称","",$tmp);
return $tmp;
}
//读取插件参数配置
function read_plugin_param($content){
$tmp=explode("\n",$content);
$tmp=trim($tmp[2]);
$tmp=str_replace("//","",$tmp);
$tmp=str_replace("","",$tmp);
$tmp=str_replace(":","",$tmp);
$arr1=explode("可配置参数",$tmp);
$str1=trim($arr1[1]);
$arr_param=array();
return $str1;
}
//读取插件参数值
function get_plugin_set($zd,$val){
global $table_pre,$db,$cate,$file_name,$id;
$m1=get_db_msg("select id,param from ".$table_pre."plugin where id='".$id."'");
if($m1["id"]>0){
$param=$m1["param"];
$arr1=explode(",",$param);
for($i=0;$i<count($arr1);$i++){
$arr2=explode("|",$arr1[$i]);
if($arr2[0]==$zd){
$v=$arr2[1];
return $v;
}
}
}
return $val;
}
//只适用于童装尺码异价类型
//根据索引值,取得款型名称
function get_child_bx_title($ind){
global $arr_child_bx;
$r=$ind;
$i=0;
foreach($arr_child_bx as $bx1 => $arr_bx_size1){
if($i==$ind){
$r=$bx1;
break;
}
$i++;
}
return $r;
}
//根据款型名称,取得索引值
function get_child_bx_ind($title){
global $arr_child_bx;
$r=false;
$i=0;
foreach($arr_child_bx as $bx1 => $arr_bx_size1){
if($title==$bx1){
$r=$i;
break;
}
$i++;
}
return $r;
}
//
function recount_pm($tmp_khid,$tmp_bx,$tmp_pm){
global $child_sizegroup_id,$table_pre,$db;
$check=get_db_msg("select no,size,size_group from ".$table_pre."kh where id='".$tmp_khid."'");
$arr2=explode(":",$tmp_pm);
$r=$tmp_pm;
if($child_sizegroup_id==$check["size_group"]){
//童装
$check1=get_db_msg("select size from ".$table_pre."size_bx where no='".$check["no"]."' and bx='".$tmp_bx."'");
$arr1=explode(",",$check1["size"]);
}else{
//非童装
$arr1=explode(",",$check["size"]);
}
if(count($arr2)==1 && count($arr1)!=count($arr2)){
$r="";
for($i=0;$i<count($arr1);$i++){
$r.=$arr2[0].":";
}
if($r)
$r=substr($r,0,-1);
}
return $r;
}
//检查目录权限
function new_is_writeable($path){
$file=$path."/test.txt";
if($fp=@fopen($file, 'w')) {
@fclose($fp);
@unlink($file);
$writeable=1;
}else{
$writeable=0;
}
return $writeable;
}
//计算配码数字之和
function count_pm_num($gz){
$arr1=explode(":",$gz);
$r=0;
for($i=0;$i<count($arr1);$i++){
$num=$arr1[$i]+1-1;
$r+=$num;
}
return $r;
}
//调整配码
function tz_pm($arr_kh_size,$arr_pm){
$arr_pm1=array();
for($i=0;$i<count($arr_kh_size);$i++){
$arr_pm1[$arr_kh_size[$i]]=$arr_pm[$i];
}
return $arr_pm1;
}
//根据尺码,自动处理配码
function deel_pm_by_size($arr_old_pm,$arr_old_size,$arr_new_size){
//print_r($arr_new_size);
$arr_new_pm=array();
//先处理是否少了尺码
foreach($arr_old_pm as $s1 => $pm1){
if(in_array($s1,$arr_new_size))
$arr_new_pm[$s1]=$pm1;
}
//再处理新增的尺码
for($i=0;$i<count($arr_new_size);$i++){
if(!in_array($arr_new_size[$i],$arr_old_size))
$arr_new_pm[$arr_new_size[$i]]=0;
}
//排序并保持索引
ksort($arr_new_pm);
$new_pm="";
foreach($arr_new_pm as $s1 => $pm1){
if($pm1){
$new_pm.=$pm1.":";
}else{
$new_pm.="0:";
}
}
if($new_pm)
$new_pm=substr($new_pm,0,-1);
return $new_pm;
}
function create_guid() {
$charid = strtoupper(md5(uniqid(mt_rand(), true)));
$hyphen = chr(45);// "-"
$uuid = chr(123)// "{"
.substr($charid, 0, 8).$hyphen
.substr($charid, 8, 4).$hyphen
.substr($charid,12, 4).$hyphen
.substr($charid,16, 4).$hyphen
.substr($charid,20,12)
.chr(125);// "}"
return $uuid;
}