query("insert into ".$table_pre."order_state (uid,cid,brand,action,attachments,add_date) values ('".$uid."','".$cid."','".$arr_s_brand[$i]."','".$action."','".$attachments."','".$add_date."')"); } }else{ $db->query("insert into ".$table_pre."order_state (uid,cid,brand,action,attachments,add_date) values ('".$uid."','".$cid."','','".$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."')"); } //记录客户操作日志 function update_log_hd(){ global $db,$table_pre,$hd_face,$arr_log_hd_action_in,$_m,$_a,$uid,$s_tab,$id,$khid,$khid,$log_hd_old_num,$log_hd_num,$s_is_ordered,$is_hd_log; $hd_face=$last_path; // if($is_hd_log=="n") return false; //取得订货模式 $m1=get_db_msg("select _t1 from ".$table_pre."set where _k='sys_ms'"); $sys_ms1=$m1["_t1"]; $arr_ms1=explode(",",$sys_ms1); $arr_ms2=array(); $default_ms=""; for($i=0;$i0){ if($log_hd_old_num>0) $action=23; else $action=21; }else if($log_hd_num<0){ $action=22; } } }else if($_a=="del"){ $num=$log_hd_num; $action=24; } }else if($_m=="dp"){ global $log_hd_old_num_kh; $log_hd_ms=get_main_value($arr_ms2,2); //搭配订单界面 $iid=$khid; if($_a=="save"){ $num=abs($log_hd_num); if($log_hd_num>0){ //21下单,23加量 if($log_hd_old_num_kh==0) $action=21; else $action=23; }else if($log_hd_num<0){ //22减量,24删单 if($log_hd_old_num_kh==$num) $action=24; else $action=22; } } }else if($_m=="ty"){ global $log_hd_old_num_kh; $log_hd_ms=get_main_value($arr_ms2,6); //搭配订单界面 $iid=$khid; if($_a=="save"){ $num=abs($log_hd_num); if($log_hd_num>0){ //21下单,23加量 if($log_hd_old_num_kh==0) $action=21; else $action=23; }else if($log_hd_num<0){ //22减量,24删单 if($log_hd_old_num_kh==$num) $action=24; else $action=22; } } }else if($_m=="cc"){ global $flag_action; $log_hd_ms=get_main_value($arr_ms2,4); //橱窗订单界面 $num=abs($log_hd_num); $iid=$khid; $action=$flag_action; }else if($_m=="login"){ //登陆 $action=11; }else if($_m=="client_pj"){ //评款 $num=$log_hd_num; $iid=$khid; if($_a=="save_pj") $action=61; else $action=62; }else if($_m=="logout"){ //注销 $action=12; }else if($_m=="main_8"){ //管理员界面 $action=0; } if(in_array($action,$arr_log_hd_action_in) && $uid>0){ if($num==0 && ($action!=11 && $action!=12)){ $q=""; }else{ $q="insert into ".$table_pre."log_hd (uid,iid,num,ip,action,ms,hd_type,add_date) values ('".$uid."','".$iid."','".$num."','".$ip."','".$action."','".$log_hd_ms."','".$hd_face."','".$add_date."')"; $db->query($q); } } } ////////////更新session function update_session($uid,$ip){ global $db,$table_pre,$_m,$_a,$cate,$file_name,$last_path; $hd_face=$last_path; $server_ip=$_SERVER['HTTP_HOST']; if($_m=="plugin"){ $action=$_m."|".$file_name."|".$cate; }else{ if($_m=="tanmu"){ $action="zbuser|".$_a."|".$cate; }else{ $action=$_m."|".$_a."|".$cate; } } if($_m!="load_pic" && $_m!="ajax_msg"){ $ip=$_SERVER["REMOTE_ADDR"]; $sid=$_COOKIE["client_sid"]; $msg=get_db_msg("select id from ".$table_pre."session where uid='".$uid."' and sid='".$sid."' limit 0,1"); if($msg["id"]>0) $db->query("update ".$table_pre."session set action='".$action."',remark='".$hd_face."',server_ip='".$server_ip."',lastactivity='".time()."' where id='".$msg["id"]."'"); else $db->query("insert into ".$table_pre."session (uid,ip,server_ip,action,remark,lastactivity,sid) values ('".$uid."','".$ip."','".$server_ip."','".$action."','".$hd_face."','".time()."','".$sid."')"); //$msg=get_db_msg("select * from ".$table_pre."session where uid='".$uid."' and ip='".$ip."' limit 0,1"); //if($msg["id"]>0) //$db->query("update ".$table_pre."session set action='".$action."',remark='".$hd_face."',server_ip='".$server_ip."',lastactivity='".time()."' where id='".$msg["id"]."'"); //else //$db->query("insert into ".$table_pre."session (uid,ip,server_ip,action,remark,lastactivity) values ('".$uid."','".$ip."','".$server_ip."','".$action."','".$hd_face."','".time()."')"); } } ////////////检查session function check_session(){ global $db,$table_pre; //$check_time=2*60*60; $check_time=30*60;//30分钟没操作自动退出 $now1=time()-$check_time; $db->query("delete from ".$table_pre."session where lastactivity<".$now1); $db->query("delete from ".$table_pre."session where uid=0"); } ////////////删除session function delete_session($uid){ global $db,$table_pre; $q="delete from ".$table_pre."session where uid='".$uid."'"; $db->query($q); } //更新服务器的连接数 function cache_servers_num(){ global $db,$table_pre; $q="select id,ip 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 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".$text.""; //$r=""; 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("<","<",$str); $str=str_replace(">",">",$str); $str=str_replace("\n","
",$str); $str=str_replace("\r","",$str); $str=str_replace(" "," ",$str); return $str; } //dhtmlspecialchars function dhtmlspecialchars($string) { if(is_array($string)) { foreach($string as $key => $val) { $string[$key] = dhtmlspecialchars($val); } } else { $string = preg_replace('/&((#(\d{3,5}|x[a-fA-F0-9]{4})|[a-zA-Z][a-z0-9]{2,5});)/', '&\\1', str_replace(array('&', '"', '<', '>'), array('&', '"', '<', '>'), $string)); } return $string; } //去除html标记 function no_html($content){ $search=array("']*?>.*?'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]; } ///////////////////////////////////////////////////////url相关 //重定向 function url_redirect($url=''){ $url=$url?$url:$_SERVER["HTTP_REFERER"]; echo ""; exit(); } //输出js代码并且重定向 function jscode_and_redirect($url='',$jscode=''){ $url=$url?$url:$_SERVER["HTTP_REFERER"]; echo "".$jscode.""; exit(); } //输出js错误提示 function alert($msg){ echo ""; exit(); } //输出js错误提示并返回 function alert_and_back($msg){ echo ""; exit(); } //返回错误提示 function alert_and_back1($msg){ return $msg; } //输出js错误提示并关闭窗口 function alert_and_close($msg){ echo ""; exit(); } //输出js错误提示并重定向 function alert_and_redirect($msg,$url){ echo ""; echo ""; exit(); } //输出js错误提示并关闭窗口 function alert_and_reload_opener($msg){ echo ""; exit(); } //重定向并post变量 function redirect_and_post($url,$var){ $html="
"; if(is_array($var)){ foreach($var as $key => $value){ $html.="\n"; } } $html.="
"; echo $html; } //输出错误结果 function echo_wrong($msg){ echo ""; echo "



".$msg."!

"; exit; } //处理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; } // function get_this_url(){ $this_url=""; if(is_array($_GET)){ foreach($_GET as $k => $v){ $this_url.=$k."=".urlencode($v)."&"; } } if(is_array($_POST)){ foreach($_POST as $k => $v){ $this_url.=$k."=".urlencode($v)."&"; } } if($this_url) $this_url="?".substr($this_url,0,-1); return $this_url; } // function del_url_para($url,$arr){ $arr1=explode("?",$url); $arr2=explode("&",$arr1[1]); $str1=""; for($i=0;$i"; } //检查类型 function check_file_type($str,$type){ $r=false; $tmp=explode("|",$str); for($i=0;$i$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,$quality); } } ///////////////////////////////////////////////////////数据库操作 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"; } 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 ""; }else{ return ; } } // ///////////////////////////////////////////////////////目录操作 // function path_cut0($path){ $tmp=explode("-",$path); for($i=0;$i0) $r.=$tmp[$i]."-"; } $r=substr($r,0,-1); return $r; } ///截去前$num层目录 function path_cut($path,$num){ $tmp=explode("-",$path); for($i=$num;$i0){ for($i=0;$i<$deep-1;$i++){ $r.="  "; } $r.="└ "; } return $r; } function indent_dote($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 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); } // function op_path($path,$mod){ global $db,$table_pre; $op_path=""; $res=$db->query("select id,path,title from ".$table_pre."path where module='".$mod."' and deep='1' order by ord"); while($msg=$db->fetch_array($res)){ $op_path.=""; } } return $op_path; } // function op_path_two1($path,$mod){ global $db,$table_pre; $op_path=""; $res=$db->query("select id,path,title 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.=""; } $r1=$db->query("select id,path,title from ".$table_pre."path where module='".$mod."' and path='".$m[path]."-".$m[id]."' order by ord"); while($m1=$db->fetch_array($r1)){ $op_path.=""; } } } return $op_path; } // function get_jxs_path_title($path,$split='-'){ global $db,$table_pre; $table=$table_pre."jxs"; $tmp=explode("-",$path); $r=""; for($i=0;$i0){ $t=get_db_msg("select username from ".$table." where id='".$tmp[$i]."'"); $r.=$t["username"].$split; } } $r=substr($r,0,0-strlen($split)); return $r; } // function get_path_title($path,$split='-',$table=''){ global $db,$table_pre; $table=$table?$table:$table_pre."path"; $tmp=explode("-",$path); $r=""; for($i=0;$i0){ $t=get_db_msg("select title from ".$table." where id='".$tmp[$i]."'"); $r.=$t["title"].$split; } } $r=substr($r,0,0-strlen($split)); return $r; } // function get_path_title_web($path,$cate,$split='-',$var='pid',$prop=''){ global $db,$table_pre; $table=$table_pre."path"; $tmp=explode("-",$path); $r=""; for($i=0;$i0){ $t=get_db_msg("select id,title 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 ".$column." from ".$table." where id='".$id."'"); return $msg[$column]; } ///////////////////////////////////////////////////////数学和日期 // 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 deel_cf($n1,$n2){ if($n2>0 && $n1>0){ $r=$n1/$n2; }else{ $r="0"; } return $r; } //保留小数 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_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 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 get_op_month($month){ $op=""; $arr=array(); for($i=1;$i<13;$i++){ $op.="