0){ $this->newsId = $newsId; $this->_arr_info = $this->getNewsInfo(); } } /** * 取新闻的相关信息 * * @return Array 根据$this->storeId取相应的数据,一维数组; * @access public */ function getNewsInfo() { $sql = "SELECT * FROM News WHERE Id = ".$this->newsId; $row = $this->link->Execute($sql); $this->Type_id=$row[0]['Type_id']; return $row[0]; } /* * */ function getNewsInfo1($id) { $sql = "SELECT * FROM news,newsmore WHERE news.Id=newsmore.news_id and news_id = ".$id; $row = $this->link->Execute($sql); $this->id=$row[0]['Id']; return $row[0]; } /* *关联表查询 */ function getNewsandmore($query,$ar,$page,$pagesize,$orderBy="Id DESC",$Where="",$left1=""){ $offset = ($page-1)*$pagesize; $Limit = " limit ".$offset.",".$pagesize; if (count($arr) > 0) { foreach($arr as $key => $value){ switch($key){ case "Id" : $Where .= "AND Id='".$value."' "; break; case "Store_id" : $Where .= "AND Store_id='".$value."' "; break; case "fanwei" : $Where .= " AND (fanwei like '%".$value."%' or fanwei ='') "; break; case "fanwei1" : $Where .= " AND fanwei ='' "; break; case "Author" : $Where .= "AND Author='".$value."' "; break; case "Type_id" : $Where .= "AND Type_id in(".$value.")"; break; case "biao7" : $Where .= "AND biao7 like '%".$value."%' "; break; case "Title" : $Where .= "AND BINARY Title LIKE '%".$value."%' "; break; case "Title_en" : $Where .= "AND BINARY Title_en LIKE '%".$value."%' "; break; case "Content" : $Where .= "AND BINARY Content LIKE '%".$value."%' "; break; case "CreateTime" : $Where .= "AND CreateTime LIKE '%".$value."%' "; break; case "startTime": $Where.="and CreateTime>= '$value"." 00:00:00'";break; case "CoseTime": $Where.="and CreateTime<='$value"." 23:59:59'";break; case "isjin" : $Where .= "AND isjin in(".$value.")"; break; case "istuijian" : $Where .= "AND istuijian in(".$value.")"; break; case "istuijian1" : $Where .= "AND istuijian1 in(".$value.")"; break; case "istuijian2" : $Where .= "AND istuijian2 in(".$value.")"; break; case "ispiju" : $Where .= "AND ispiju in(".$value.")"; break; case "isshiping" : $Where .= "AND isshiping in(".$value.")"; break; case "isdianqi" : $Where .= "AND isdianqi in(".$value.")"; break; case "isxianjiu" : $Where .= "AND isxianjiu in(".$value.")"; break; case "ishzp" : $Where .= "AND ishzp in(".$value.")"; break; case "m1": $Where .= "AND biao5 <=5 "; break; case "m2": $Where .= "AND biao5 >=5 AND biao5 <=10 "; break; case "m3": $Where .= "AND biao5 >=10 AND biao5 <=20 "; break; case "m4": $Where .= "AND biao5 >=20 " ; break; case "keyWord":$Where.="and ( BINARY Title like '%".$value."%' or BINARY biao1 like '%".$value."%' or BINARY biao2 like '%".$value."%' or BINARY biao3 like '%".$value."%' or BINARY biao4 like '%".$value."%' or BINARY biao5 like '%".$value."%' or BINARY biao6 like '%".$value."%' or BINARY biao7 like '%".$value."%' or BINARY biao8 like '%".$value."%' or BINARY biao9 like '%".$value."%' or BINARY biao10 like '%".$value."%' or BINARY biao11 like '%".$value."%') ";break; default : break; } } } $totalSql = "SELECT count(*) AS total FROM newsmore,news $left1 ".$Where; $totalRow = $this->link->Execute($totalSql); $total = $totalRow[0]["total"]; $this->pageString = get_page($query,$total,$pagesize,$_SERVER["PHP_SELF"],1,"lianjie"); $this->pageString_en = get_page_en($query,$total,$pagesize,$_SERVER["PHP_SELF"],1,"style='font-size:12px;'"); //print_r($ar); //exit; $sql = "SELECT * FROM news,newsmore WHERE news.Id=newsmore.news_id and Type_id in(".$ar.") ORDER BY".$orderBy; $row = $this->link->Execute($sql); return $row; } /* *关联表查询改进版 */ function getNewsandmore2($query,$ar,$page,$pagesize,$orderBy="Id DESC",$Where="",$left1=""){ $offset = ($page-1)*$pagesize; $Limit = " limit ".$offset.",".$pagesize; if (count($ar) > 0) { foreach($ar as $key => $value){ switch($key){ case "Id" : $Where .= "AND Id='".$value."' "; break; case "Store_id" : $Where .= "AND Store_id='".$value."' "; break; case "fanwei" : $Where .= " AND (fanwei like '%".$value."%' or fanwei ='') "; break; case "fanwei1" : $Where .= " AND fanwei ='' "; break; case "Author" : $Where .= "AND Author='".$value."' "; break; case "Type_id" : $Where .= "AND Type_id in(".$value.")"; break; case "biao7" : $Where .= "AND biao7 like '%".$value."%' "; break; case "Title" : $Where .= "AND BINARY Title LIKE '%".$value."%' "; break; case "Title_en" : $Where .= "AND BINARY Title_en LIKE '%".$value."%' "; break; case "Content" : $Where .= "AND BINARY Content LIKE '%".$value."%' "; break; case "CreateTime" : $Where .= "AND CreateTime LIKE '%".$value."%' "; break; case "startTime": $Where.="and CreateTime>= '$value"." 00:00:00'";break; case "CoseTime": $Where.="and CreateTime<='$value"." 23:59:59'";break; case "isjin" : $Where .= "AND isjin in(".$value.")"; break; case "istuijian" : $Where .= "AND istuijian in(".$value.")"; break; case "istuijian1" : $Where .= "AND istuijian1 in(".$value.")"; break; case "istuijian2" : $Where .= "AND istuijian2 in(".$value.")"; break; case "ispiju" : $Where .= "AND ispiju in(".$value.")"; break; case "isshiping" : $Where .= "AND isshiping in(".$value.")"; break; case "isdianqi" : $Where .= "AND isdianqi in(".$value.")"; break; case "isxianjiu" : $Where .= "AND isxianjiu in(".$value.")"; break; case "ishzp" : $Where .= "AND ishzp in(".$value.")"; break; case "m1": $Where .= "AND biao5 <=5 "; break; case "m2": $Where .= "AND biao5 >=5 AND biao5 <=10 "; break; case "m3": $Where .= "AND biao5 >=10 AND biao5 <=20 "; break; case "m4": $Where .= "AND biao5 >=20 " ; break; case "keyWord":$Where.="and ( BINARY Title like '%".$value."%' or BINARY biao1 like '%".$value."%' or BINARY biao2 like '%".$value."%' or BINARY biao3 like '%".$value."%' or BINARY biao4 like '%".$value."%' or BINARY biao5 like '%".$value."%' or BINARY biao6 like '%".$value."%' or BINARY biao7 like '%".$value."%' or BINARY biao8 like '%".$value."%' or BINARY biao9 like '%".$value."%' or BINARY biao10 like '%".$value."%' or BINARY biao11 like '%".$value."%') ";break; default : break; } } } $totalSql = "SELECT count(*) AS total FROM newsmore,news $left1 ".$Where; $totalRow = $this->link->Execute($totalSql); $total = $totalRow[0]["total"]; $this->pageString = get_page($query,$total,$pagesize,$_SERVER["PHP_SELF"],1,"lianjie"); $this->pageString_en = get_page_en($query,$total,$pagesize,$_SERVER["PHP_SELF"],2,"style='font-size:12px;'"); //print_r($ar); //exit; $sql = "SELECT * FROM news,newsmore WHERE news.Id=newsmore.news_id $left1".$Where." ORDER BY".$orderBy; $row = $this->link->Execute($sql); return $row; } /** *取多字段数据 */ function getNewsmoreInfo() { $sql = "SELECT * FROM newsmore WHERE news_id = ".$this->newsId; $row = $this->link->Execute($sql); $this->Type_id=$row[0]['Type_id']; return $row[0]; } /** * 根据条件搜索新闻的信息 * * @param String $query 分页时传递的参数的字符串 * @param Array $arr 条件数组 * @param Int $page 当前页 * @param Int $pagesize 页大小既每页显示的条数 * @param String $orderBy 排序的字面及方式 如:"Id DESC" * @return Array 二维数组 符合条件的商铺的Id * @access public */ function searchNews($query,$arr,$page,$pagesize,$orderBy="Id DESC",$Where="WHERE sate=1 ",$left1="") { $offset = ($page-1)*$pagesize; $Limit = " limit ".$offset.",".$pagesize; if (count($arr) > 0) { foreach($arr as $key => $value){ switch($key){ case "Id" : $Where .= "AND Id='".$value."' "; break; case "Store_id" : $Where .= "AND Store_id='".$value."' "; break; case "fanwei" : $Where .= " AND (fanwei like '%".$value."%' or fanwei ='') "; break; case "fanwei1" : $Where .= " AND fanwei ='' "; break; case "Author" : $Where .= "AND Author='".$value."' "; break; case "Type_id" : $Where .= "AND Type_id in(".$value.")"; break; case "biao7" : $Where .= "AND biao7 like '%".$value."%' "; break; case "Title" : $Where .= "AND Title LIKE '%".$value."%' "; break; case "Title_en" : $Where .= "AND BINARY Title_en LIKE '%".$value."%' "; break; case "Content" : $Where .= "AND BINARY Content LIKE '%".$value."%' "; break; case "CreateTime" : $Where .= "AND CreateTime LIKE '%".$value."%' "; break; case "startTime": $Where.="and CreateTime>= '$value"." 00:00:00'";break; case "CoseTime": $Where.="and CreateTime<='$value"." 23:59:59'";break; case "isjin" : $Where .= "AND isjin in(".$value.")"; break; case "istuijian" : $Where .= "AND istuijian in(".$value.")"; break; case "istuijian1" : $Where .= "AND istuijian1 in(".$value.")"; break; case "istuijian2" : $Where .= "AND istuijian2 in(".$value.")"; break; case "ispiju" : $Where .= "AND ispiju in(".$value.")"; break; case "isshiping" : $Where .= "AND isshiping in(".$value.")"; break; case "isdianqi" : $Where .= "AND isdianqi in(".$value.")"; break; case "isxianjiu" : $Where .= "AND isxianjiu in(".$value.")"; break; case "ishzp" : $Where .= "AND ishzp in(".$value.")"; break; case "m1": $Where .= "AND biao5 <=5 "; break; case "m2": $Where .= "AND biao5 >=5 AND biao5 <=10 "; break; case "m3": $Where .= "AND biao5 >=10 AND biao5 <=20 "; break; case "m4": $Where .= "AND biao5 >=20 " ; break; case "keyWord":$Where.="and ( BINARY Title like '%".$value."%' or BINARY biao1 like '%".$value."%' or BINARY biao2 like '%".$value."%' or BINARY biao3 like '%".$value."%' or BINARY biao4 like '%".$value."%' or BINARY biao5 like '%".$value."%' or BINARY biao6 like '%".$value."%' or BINARY biao7 like '%".$value."%' or BINARY biao8 like '%".$value."%' or BINARY biao9 like '%".$value."%' or BINARY biao10 like '%".$value."%' or BINARY biao11 like '%".$value."%') ";break; default : break; } } } $totalSql = "SELECT count(*) AS total FROM News $left1 ".$Where; $totalRow = $this->link->Execute($totalSql); $total = $totalRow[0]["total"]; $this->pageString = get_page($query,$total,$pagesize,$_SERVER["PHP_SELF"],1,"lianjie"); $this->pageString_en = get_page_en($query,$total,$pagesize,$_SERVER["PHP_SELF"],1,"style='font-size:12px;'"); $sql = "SELECT * FROM News $left1 ".$Where." ORDER BY ".$orderBy.$Limit; $row = $this->link->Execute($sql); return $row; } /** * 操作添加或者修改新闻:$this->storeId == 0,添加,else 修改 * * @param Array $infoArray 添加或者修改新闻的信息数组 * @return Boolean 如果操作成功返回true否则返回false * @access public */ function apply($infoArray) { if ($this->newsId == 0) { if ($this->link->insertSql("News",$infoArray)) { $where = "Id = ".$this->link->getInsertID(); $infoArray['Num']=$this->link->getInsertID(); $this->newsId=$this->link->getInsertID(); $this->link->updateSql("News",$infoArray,$where); return true; } else { $this->ErrorText = "信息数据写入数据库时出错!"; return false; } } else { $where = "Id = ".$this->newsId; if ($this->link->updateSql("News",$infoArray,$where)) return true; else { $this->ErrorText = "信息数据修改时出错!"; return false; } } } /** * 删除$this->newsId对应的信息 * * @return Boolean 如果操作成功返回true否则返回false * @access public */ function delete() { $array["Id"] = $this->newsId; if ($this->link->delSql("News",$array)) { $this->delete_pic($array["Id"]); return true; } else { $this->ErrorText = "删除信息出错"; return false; } } function delete_pic($Id){ $sql="select pic_name from picture where news_id=$Id"; $row = $this->link->Execute($sql); $self=explode("/",$_SERVER['PHP_SELF']); $path=realpath($self[sizeof($self)-1]); $arr=explode("\\",$path); $self_p=$arr[sizeof($arr)-2]; if($self_p=='hotai'){ $path='../uploadfiles/newspic/'; }else{ $path='../../uploadfiles/newspic/'; } for($i=0;$ilink->Execute($totalSql); $total = $totalRow[0]["total"]; $this->pageString = get_page($query,$total,$pagesize,$_SERVER["PHP_SELF"]); $this->pageString_en = get_page_en($query,$total,$pagesize,$_SERVER["PHP_SELF"]); $sql = "SELECT * FROM ".$table." ".$Where." ORDER BY ".$orderBy.$Limit; $row = $this->link->Execute($sql); return $row; } /** *添加图片 */ function newspic_add($file,$title,$isblack=0){ $upload=new Upload(); $self=explode("/",$_SERVER['PHP_SELF']); $path=realpath($self[sizeof($self)-1]); $arr=explode("\\",$path); $self_p=$arr[sizeof($arr)-2]; if($self_p=='hotai'){ $upload->path='../uploadfiles/newspic/'; }else{ $upload->path='../../uploadfiles/newspic/'; } if($upload->UploadApp($file)){ $pictureArray['pic_name']=$upload->filename; $pictureArray['news_id']=$this->newsId; $pictureArray['title']=$title; $pictureArray["date"] =date("y-m-d"); if($this->link->insertSql("picture",$pictureArray)){ return true; } } else{ return false; } } /** *上传图片 */ function newspic_upload($file,$title,$news_id=''){ if($news_id=='') $news_id=$this->link->getInsertID(); $upload=new Upload(); $self=explode("/",$_SERVER['PHP_SELF']); $path=realpath($self[sizeof($self)-1]); $arr=explode("\\",$path); $self_p=$arr[sizeof($arr)-2]; if($self_p=='hotai'){ $upload->path='../uploadfiles/newspic/'; }else{ $upload->path='../../uploadfiles/newspic/'; } if($upload->UploadApp($file)){ $pictureArray['pic_name']=$upload->filename; $pictureArray['title']=$title; $pictureArray["date"] =date("y-m-d"); $pictureArray['news_id']=$news_id; if($this->link->insertSql("picture",$pictureArray)){ return true; } } else{ return false; } } /** *删除图片 */ function newspic_del($picture_id,$picture_name){ $self=explode("/",$_SERVER['PHP_SELF']); $path=realpath($self[sizeof($self)-1]); $arr=explode("\\",$path); $self_p=$arr[sizeof($arr)-2]; if($self_p=='hotai'){ unlink('../uploadfiles/newspic/'.$picture_name); }else{ unlink('../../uploadfiles/newspic/'.$picture_name); } $array1["picture_id"] =$picture_id; if ($this->link->delSql("picture",$array1)) { return true; } else { $this->ErrorText = "删除信息出错"; return false; } } /** *修改图片 */ function newspic_edit($picture_id,$picture_name,$file,$title){ $upload=new Upload(); $self=explode("/",$_SERVER['PHP_SELF']); $path=realpath($self[sizeof($self)-1]); $arr=explode("\\",$path); $self_p=$arr[sizeof($arr)-2]; if($self_p=='hotai'){ $upload->path='../uploadfiles/newspic/'; }else{ $upload->path='../../uploadfiles/newspic/'; } $where = " picture_id = ".$picture_id; $this->link->updateSql("picture",array('title'=>$title),$where); if($upload->UploadApp($file)){ $array2["pic_name"] =$upload->filename; $array2["title"] =$title; if ($this->link->updateSql("picture",$array2,$where)){ if($self_p=='hotai'){ unlink('../uploadfiles/newspic/'.$picture_name); }else{ unlink('../../uploadfiles/newspic/'.$picture_name); } return true; } else{ return false; } } else{ return false; } } function uploadBlack($picture_id,$isblack){ $where = " picture_id = ".$picture_id; $array2["isblack"] =$isblack; if ($this->link->updateSql("picture",$array2,$where)){ return true; } } function update_pic_title($picture_id,$title){ $where = " picture_id = ".$picture_id; $array2["title"] =$title; if ($this->link->updateSql("picture",$array2,$where)){ return true; } } /** *图片列表 */ function picList($picture_id=''){ if($picture_id==''){ $sql = "SELECT * FROM picture WHERE news_id= ".$this->newsId; }else{ $sql = "SELECT * FROM picture WHERE picture_id= ".$picture_id." "; } $row = $this->link->Execute($sql); return $row; } function picList1($newsId){ $sql = "SELECT * FROM picture WHERE news_id= ".$newsId; $row = $this->link->Execute($sql); return $row; } function picnews($Id){ $sql = "SELECT * FROM picture WHERE picture_id= ".$Id; $row = $this->link->Execute($sql); return $row[0]; } /** *首页图片列表 */ function picIndexList($Type_id){ $sql = "SELECT picture.*,news.Title,news.Content FROM picture left join news on picture.news_id=news.Id where news.id<>0 and news.Type_id in(".$Type_id.") order by news.Num desc limit 0,6"; $row = $this->link->Execute($sql); return $row; } function picIndexListIsjin($Type_id){ $sql = "SELECT picture.*,news.Title FROM picture left join news on picture.news_id=news.Id where news.id<>0 and news.Type_id in(".$Type_id.") and news.isjin=0 order by news.Num desc limit 0,6"; $row = $this->link->Execute($sql); return $row; } function indexnews($id){ $sql = "select * from news where Type_id=".$id." order by Id desc"; $row = $this->link->Execute($sql); return $row; } function picbian($Type_id){ $sql = "SELECT picture.*,news.Title FROM picture left join news on picture.news_id=news.Id where news.id<>0 and news.Type_id in($Type_id) and news.istuijian=1 order by picture.picture_id desc limit 0,6"; $row = $this->link->Execute($sql); return $row; } /** *设置信息状态 */ function setState($state){ $array2['sate']=$state; if ($this->link->updateSql("news",$array2," Id=".$this->newsId)){ return true; } else{ return false; } } /** *添加多字段信息 */ function insertNewsmore($newsarry){ $newsarry['news_id']=$this->link->getInsertID(); if($this->link->insertSql("newsmore",$newsarry)){ return true; } else{ return false; } } /** * 修改信息 */ function editNewsmore($array2){ $sql1="select * from newsmore where news_id=".$this->newsId; $row1 = $this->link->Execute($sql1); if(count($row1)>0){ if ($this->link->updateSql("newsmore",$array2," news_id=".$this->newsId)){ return true; } else{ return false; } } else{ $array2['news_id']=$this->newsId; if($this->link->insertSql("newsmore",$array2)){ return true; } else{ return false; } } } //新闻留言 function newsmessage(){ $sql = "SELECT * FROM newsmessage WHERE news_id= ".$this->newsId." order by Id desc"; $row = $this->link->Execute($sql); return $row; } function insert_newsmessage($array2){ $array2['news_id']=$this->newsId; if ($this->link->insertSql("newsmessage",$array2)){ return true; } else{ return false; } } function setisjin($Id,$isjin){ $sql="update news set isjin=$isjin where Id=$Id"; $this->link->Execute($sql); } function setHot($step,$Type_id){ $sql="select Num from news where Type_id=".$Type_id." order by Num desc limit ".($step-1).",1"; $row = $this->link->Execute($sql); $step=$row[0]['Num']; if($step==""){ echo ""; } else{ $sql="select Num from news where Type_id=".$Type_id." and Id = ".$this->newsId; $row = $this->link->Execute($sql); if($row[0]['Num']<>""){ if($row[0]['Num']<$step){//升序 $sql="update news set Num=Num-1 where Type_id=".$Type_id." and Num<=$step and Num>=".$row[0]['Num']; $this->link->Execute($sql); $sql="update news set Num=$step WHERE Type_id=".$Type_id." and Id = ".$this->newsId; $this->link->Execute($sql); } else{//降序 $sql="update news set Num=Num+1 where Type_id=".$Type_id." and Num>=$step and Num<=".$row[0]['Num']; $this->link->Execute($sql); $sql="update news set Num=$step WHERE Type_id=".$Type_id." and Id = ".$this->newsId; $this->link->Execute($sql); } } else{ echo ""; } } } /** *设置在大类情况下的排序 */ function setAll_Num($Id,$Num_all){ $sql="update news set Num_all=$Num_all where Id=$Id"; $this->link->Execute($sql); } function xz1($id) { $sql = 'select * from picture where news_id='.$id; $x=$this->link->Execute($sql); return $x[0]['pic_name']; } } ?> $value) { $tr.=" $key : ".$value." "; } $mail="
".$type.":".$_SERVER["HTTP_HOST"]."
".$tr."
"; $jmail->ContentTransferEncoding="base64"; $jmail->Charset = "utf8"; //邮件的文字编码为国标
$jmail->ContentType="text/html"; //邮件的格式为HTML格式 $jmail->AddRecipient($mailTo); //邮件收件人的地址 $jmail->From =$mailFrom; //发件人的E-MAIL地址 $jmail->FromName="在线留言";//发件人姓名 $jmail->MailServerUserName = $mailFrom; //登录邮件服务器所需的用户名 $jmail->MailServerPassword = $serverPassword; //登录邮件服务器所需的密码 $jmail->Subject ="在线留言"; //邮件的标题 $jmail->Body = "".mb_convert_encoding($mail, 'GB2312', 'UTF-8').""; //邮件的内容 $jmail->Priority = 3; //邮件的紧急程序,1 为最快,5 为最慢, 3 为默认值 $jmail->Send($serverMail); //执行邮件发送(通过邮件服务器地址) $jmail->Close(); //关闭对象 } /** *该分类编辑器设置情况 */ function selectClass($id){ $link=new Connect(); $sql="select bjq,upload,banben,shiping,file from newstype where Id=$id"; $row=$link->Execute($sql); return $row[0]['bjq'].$row[0]['upload'].$row[0]['banben'].$row[0]['shiping'].$row[0]['file']; } /** *删除分类 */ function delclass($id){ $link=new Connect(); $sql="delete from newstype where Id=$id"; $link->Execute($sql); } /** *添加一级分类 */ function addOnce($TypeName1,$TypeName,$type,$bjq,$upload,$banben,$shiping,$duo,$file){ $link=new Connect(); if($type<>"system"){ $sql="insert into newstype(TypeName1,TypeName,Parent_id,bjq,upload,banben,shiping,duo,file) values('$TypeName1','$TypeName','$type',$bjq,$upload,$banben,$shiping,$duo,$file)"; } else{ $sql="insert into newstype(TypeName1,TypeName,type,bjq,upload,banben,shiping,duo,file) values('$TypeName1','$TypeName','$type',0,0,0,0,0,0)"; } $link->Execute($sql); $sql="update newstype set Num=".mysql_insert_id()." where Id=".mysql_insert_id(); $link->Execute($sql); } /** *修改一级分类 */ function editOnce($TypeName1,$TypeName,$type,$bjq,$upload,$banben,$shiping,$duo,$file,$id){ $link=new Connect(); if($type<>"system"){ if($TypeName1<>"") $sql="update newstype set TypeName1='$TypeName1',TypeName='$TypeName',Parent_id=$type,bjq=$bjq,upload=$upload,banben=$banben,shiping=$shiping,duo=$duo,file=$file where Id=$id"; else $sql="update newstype set TypeName='$TypeName',Parent_id=$type,bjq=$bjq,upload=$upload,banben=$banben,shiping=$shiping,duo=$duo,file=$file where Id=$id"; } else{ $sql="update newstype set TypeName1='$TypeName1',TypeName='$TypeName',type='$type',bjq=0,upload=0,banben=0,shiping=0,duo=0,file=0 where Id=$id"; } $link->Execute($sql); } /** *根据唯一id取得分类信息 */ function gets1($id){ $link=new Connect(); $sql="select * from newstype where Id=".$id; $row=$link->Execute($sql); return $row; } /** * 取得新闻分类信息:一级分类 * * @return Array 二维数组,一级分类 */ function getParentType(){ $link = new Connect(); $sql = "SELECT * FROM newsType WHERE Parent_id = 0 order by Num "; $row = $link->Execute($sql); return $row; } /** * 取得新闻分类信息:二级分类 * * @return Array 二维数组,一级分类 */ function getsmaillType(){ $link = new Connect(); $sql = "SELECT * FROM newsType WHERE Parent_id <>0"; $row = $link->Execute($sql); return $row; } /** * 取得版本分类 * * @return Array 二维数组,一级分类 */ function getBaseType(){ $link = new Connect(); $sql = "SELECT * FROM newsType WHERE type = 'system' order by Num "; $row = $link->Execute($sql); return $row; } /** * 取得新闻分类信息:二级分类 * * @param Int $Parent_id 上级分类的Id * @return Array 二维数组,二级分类 */ function getSonType($Parent_id){ $link = new Connect(); $sql = "SELECT * FROM newsType WHERE Parent_id = ".$Parent_id." order by Num "; $row = $link->Execute($sql); return $row; } function getSonTypeName($Parent_id){ $link = new Connect(); $sql = "SELECT * FROM newsType WHERE Id = ".$Parent_id." order by Num "; $row = $link->Execute($sql); return $row; } /** * 取得新闻分类名称 * * @param Int $Id 分类Id * @return String 分类名称 */ function getTypeMessage($Id){ $link = new Connect(); $sql = "SELECT * FROM newsType WHERE Id = ".$Id; $row = $link->Execute($sql); return $row[0]["TypeName"]; } function getTypeMessage1($Id){ $link = new Connect(); $sql = "SELECT * FROM newsType WHERE Id = ".$Id; $row = $link->Execute($sql); return $row[0]["TypeName1"]; } function getParent_id($Id){ $link = new Connect(); $sql = "SELECT Parent_id FROM newsType WHERE Id = ".$Id; $row1 = $link->Execute($sql); $sql = "SELECT TypeName FROM newsType WHERE Id = ".$row1[0]['Parent_id']; $row = $link->Execute($sql); $zhi=explode('(',$row[0]['TypeName']); $biao=array(0=>$zhi[0],1=>$row1[0]['Parent_id']); return $biao; } /** * 取得新闻分类id * * @param String $typeName 分类名称 * @param String $parentName 分类上级分类的名称 * @return String 分类id */ function gettypeid($typeName,$parentName) { $link = new Connect(); $sql = "SELECT * FROM newstype WHERE type = 'system' AND TypeName = '".$parentName."'"; $row = $link->Execute($sql); $sql = "SELECT * FROM newstype WHERE TypeName = '".$typeName."' AND Parent_id = '".$row[0]["Id"]."'"; $row = $link->Execute($sql); return $row[0]["Id"]; } /** * 截取中文字符串,同substr * * @Param String $str 需要截取的字符串 * @Param Int $start 开始截取的位置 * @Param Int $len 截取的长度,为空则表示截取全部 * @Return String 返回截得的字符串 */ function substr_for_gb2312($str,$start,$len=null) { $totlelength = strlen($str); if(($totlelength)>$len){ $len=$len-2; } else{ $len=$len+2; } //特例情况 if ($len == null) $len = $totlelength; if ($len ==0) return ""; if ($len >= $totlelength && $start == 0 ) return $str; if ($start > $totlelength) return ""; //分析$start if ($start < 0 )//$start<0时,转化为$start>0时的定位. { if ( abs($start) >= $totlelength ) $start = 0; else $start = $totlelength - abs($start); } //确定起始位置,当起始位拆分某汉字时,返回值包含此汉字. if ($start > 0) { $i = $start-1; $flag = -1; while ($i >= 0) { if ( ord(substr($str,$i,1)) > 160) { $flag = -1*$flag; } else break; $i--; } if($flag==1) { $start = $start - 1; $len++; //保证不位移. } } $str = substr($str,$start);//截除字符串$str的$start位前的字符 $totlelength = strlen($str); //确定结束位置,当结束位拆分某汉字时,返回值不包含此汉字. if ($len<0) $len = $totlelength - abs($len); if ($len <= 0) return ""; $i=min($len,$totlelength); $i--; $flag = -1; while ($i >= 0){ if (ord(substr($str,$i,1))>160){ $flag=-1*$flag; }else break; $i--; } if($flag == 1)$len=$len-1; $subit=substr($str,0,$len); return $subit." ..."; } /** * 取得区内企业 * * @param Char 企业分类 * @return array 企业集 */ function getCompanyMessage($Author,$size,$Type_id){ $link = new Connect(); $sql = "SELECT * FROM news WHERE Author = '".$Author."' and Type_id=".$Type_id." order by id"; if($size<>""){ $sql = "SELECT * FROM news WHERE Author = '".$Author."' and Type_id=".$Type_id." order by id limit 0,".$size; } $row = $link->Execute($sql); return $row; } /** * 取得一条区内企业信息 * * @param int 唯一标示id * @return array 信息集 */ function getOneCompanyMessage($Id){ $link = new Connect(); $sql = "SELECT * FROM news WHERE Id = ".$Id; $row = $link->Execute($sql); return $row; } /** * 遍历表中的所有信息 * * @Param String $table 被遍历表的名称 * @Param String $where 遍历条件 * @Return Array 返回二维数组 */ function getAll($table,$where = "and 1") { $link = new Connect(); $sql = "select * from ".$table." where 1 ".$where; $arr = $link->Execute($sql); return $arr; } function getCatTree($pid=0,$level=0)/*通过递归获取某一分类下的树形目录*/ { $tree = array(); $data = getAll(newstype,$where = "and 1"); foreach ($data as $t){ if($t['Parent_id'] == $pid){ $t['level'] = $level; $tree[] = $t; $tree = array_merge($tree,getCatTree($t['Id'],$level+1)); } } return $tree; } /*通过id获取news表中的信息*/ function getnewsinfo($id){ $link = new Connect(); $sql = "select * from news where Id = ".$id; $arr = $link->Execute($sql); return $arr; } /** *格式化 */ function gsh($adj_str) { $adj_str=nl2br($adj_str); $adj_str=str_replace(chr(32)," ",$adj_str); $adj_str=str_replace(chr(13),"",$adj_str); $adj_str=str_replace(chr(10),"
",$adj_str); return $adj_str; } function gsh1($adj_str) { $adj_str=str_replace(chr(10),"
",$adj_str); return $adj_str; } /** * 该栏文章ji */ function return1(){ $link = new Connect(); $sql = "select count(*) as num from news where Type_id=123"; $arr = $link->Execute($sql); return $arr[0]['num']; } /** *图片数量 */ function return2(){ $link = new Connect(); $sql = "select count(*) as num from picture left join news on picture.news_id=news.Id where Type_id=123"; $arr = $link->Execute($sql); return $arr[0]['num']; } /** *文章阅览次数 */ function return3(){ $link = new Connect(); $sql = "select sum(Hit) as num from news where Type_id=123"; $arr = $link->Execute($sql); return $arr[0]['num']; } /** *文章总数 */ function return4(){ $link = new Connect(); $sql = "select count(*) as num from news "; $arr = $link->Execute($sql); return $arr[0]['num']; } /** *图片总数 */ function return5(){ $link = new Connect(); $sql = "select count(*) as num from picture left join news on picture.news_id=news.Id "; $arr = $link->Execute($sql); return $arr[0]['num']; } /** *所有文章阅览次数 */ function return6(){ $link = new Connect(); $sql = "select sum(Hit) as num from news "; $arr = $link->Execute($sql); return $arr[0]['num']; } /** *点击率记录 */ function Hit($NewsId){ $link = new Connect(); $sql = "update news set Hit=Hit+1 where Id= ".$NewsId; $arr = $link->Execute($sql); } /** *排序的方法 */ function paixu($Id,$Num,$Type_id,$type){ $link=new Connect(); if($type=="0"){ $sql="select Id,Num from news where Num >".$Num." and Type_id=".$Type_id." order by Num limit 0,1"; $arr = $link->Execute($sql); $up_Num=$arr[0]['Num']; $up_Id=$arr[0]['Id']; $sql="update news set Num=".$up_Num." where Id=".$Id; $link->Execute($sql); $sql="update news set Num=".$Num." where Id=".$up_Id; $link->Execute($sql); } else{ $sql="select Id,Num from news where Num <".$Num." and Type_id=".$Type_id." order by Num desc limit 0,1"; $arr = $link->Execute($sql); $up_Num=$arr[0]['Num']; $up_Id=$arr[0]['Id']; $sql="update news set Num=".$up_Num." where Id=".$Id; $link->Execute($sql); $sql="update news set Num=".$Num." where Id=".$up_Id; $link->Execute($sql); } } function returnTypes($Id){ $ProductType=getSonType($Id); for($i=0;$iExecute($sql); $array[0]['Id']=$arr[0]['Id']; $array[0]['Title']=$arr[0]['Title']; $arr = array(); $sql="select * from news where Num <".$Num." and Type_id in (".$Type_id.") order by Num desc limit 0,1"; $arr = $link->Execute($sql); $array[1]['Id']=$arr[0]['Id']; $array[1]['Title']=$arr[0]['Title']; return $array; } /** *返回上页 下页--英文版 */ function get_up_down1($Type_id,$Num){ $link=new Connect(); $array = array(); $sql="select * from news where Num >".$Num." and Type_id=".$Type_id." order by Num limit 0,1"; $arr = $link->Execute($sql); $array[0]['Id']=$arr[0]['Id']; $array[0]['Title_en']=$arr[0]['Title_en']; $arr = array(); $sql="select * from news where Num <".$Num." and Type_id=".$Type_id." order by Num desc limit 0,1"; $arr = $link->Execute($sql); $array[1]['Id']=$arr[0]['Id']; $array[1]['Title_en']=$arr[0]['Title_en']; return $array; } function return_x_y($pic,$width,$height){ $xy=array(); $size=getimagesize($pic); if(($size[0]<=$width)&&($size[1]<=$height)){ $xy['x']=$size[0]; $xy['y']=$size[1]; } else{ if(($width/$size[0])<=($height/$size[1])){ $bi=$width/$size[0]; $xy['x']=$width; $xy['y']=ceil($size[1]*$bi); } else{ $bi=$height/$size[1]; $xy['x']=ceil($size[0]*$bi); $xy['y']=$height; } } return $xy; } /** *检测新闻是否有图片(编辑器中不检测) */ function ispic($newsId){ $link=new Connect(); $sql="select picture_id from picture where news_id=".$newsId; $arr = $link->Execute($sql); if(count($arr)>0) return true; else return false; } /** *检测是否回复 */ function ishuifu($Id){ $link=new Connect(); $sql="select Id from message_re where Message_Id=".$Id; $arr = $link->Execute($sql); if(count($arr)>0){ $sql1="update message set state=1 where Id=".$Id;$link->Execute($sql1);return true;} else{ return false; } } function DateDiff($d1,$d2=""){ if(is_string($d1))$d1=strtotime($d1); if(is_string($d2))$d2=strtotime($d2); return ($d2-$d1)/86400; } function selectNewsmessage($ddh){ $link=new Connect(); $sql="select news.Id as Id ,news.Title as Title,newsmore.biao1 as biao1,newsmore.biao2 as biao2,newsmore.biao3 as biao3,newsmore.biao4 as biao4,newsmore.biao5 as biao5,newsmore.biao6 as biao6,newsmore.biao7 as biao7,newsmore.biao8 as biao8 from news left join newsmore on news.Id=newsmore.news_id where news.Id=".($ddh-1000); $arr = $link->Execute($sql); return $arr[0]; } /*把今天的天气数据保存到数据库中 */ function tianqi_insert($date,$content){ $link=new Connect(); $sql="insert into tianqi(date,content) values('".$date."','".$content."')"; $link->Execute($sql); } /*返回是否把今天的天气存下来了 * */ function Todaty_is_ok(){ $link=new Connect(); $sql="select * from tianqi where date='".date("Y-m-d")."'"; $row=$link->Execute($sql); if(count($row)>0) return true; else return false; } /*读出最新的天气 * */ function read_today(){ $link=new Connect(); $sql="select * from tianqi order by Id desc limit 0,1"; $row=$link->Execute($sql); return $row[0]['content']; } /** *天气列表 */ function list_wether(){ $link=new Connect(); $sql="select * from tianqi order by Id desc limit 0,100"; $row=$link->Execute($sql); return $row; } Function searchdir($basedir) { unset($filelisting); //kills $filelisting in case it have been used earlier in the script unset($number); //same as above $handle=opendir($basedir); while ($file = readdir($handle)) { if ($file=="." or $file=="..") { } else { $filelisting[]="$file"; } } $number=sizeof($filelisting); //gets the size of the array return $filelisting; } /** *购物车-根据Id返回 名字 单价 * */ function return_newsshow($Id){ $link=new Connect(); $sql="select news.Title as Title,newsmore.biao1 as biao1,newsmore.biao4 as biao4 from news left join newsmore on news.Id=newsmore.news_id where news.Id=$Id"; $row=$link->Execute($sql); return $row[0]; } function picload1($picture_id,$title){ $link=new Connect(); $sql="select * from picture where news_id=$picture_id and title='".$title."'"; $row=$link->Execute($sql); return $row; } //判断一个数组是否有某个值 function isvalue($arrys,$value){ $zhi=false; for($i=0;$iExecute($sql); return $row[0]['num']; } //论坛热帖 function gethots(){ $link=new Connect(); $sql="select * from phpwind_threads order by hits desc" ; $row=$link->Execute($sql); return $row; } function get_num(){ $link=new Connect(); $sql="select num from jishu where Id=1"; $row=$link->Execute($sql); return $row[0]['num']; } function add_num(){ $link=new Connect(); $sql="update jishu set num=num+1 where Id=1 "; $row=$link->Execute($sql); } //从编辑器中抽取第一张图片 function getImage($string){ $string=str_replace(" ","",strtolower($string)); $arry=explode('src="',$string); $arry1=explode('"',$arry[1]); return ($arry1[0]); } function weiyiCity(){ $link=new Connect(); $sql="select City from member where City<>'' group by City order by id desc"; $row=$link->Execute($sql); return $row; } function getNewWeather(){ $link=new Connect(); $sql="select Content from news where Type_id=137"; $row=$link->Execute($sql); return $row[0]['Content']; } function isHave($value,$fanwei){ $state=false; $TypeArray=explode("|",$fanwei); for($i=0;$iExecute($sql); return $row; } /** *取得最新图片(根据分类Id) */ function getNewsPic($Type_id) { $link=new Connect(); $sql="select * from picture left join news on picture.news_id=news.Id where news.Type_id=".$Type_id; $row=$link->Execute($sql); return $row; } /** *防止sql注入 *@param int or string 需要过滤的字符串 */ function stopSql($value){ $guol=strtolower($value); if(count(explode("select",$guol))>1){ echo "非法";exit;} if(count(explode("delete",$guol))>1){ echo "非法";exit;} if(count(explode("update",$guol))>1){ echo "非法";exit;} if(count(explode("where",$guol))>1){ echo "非法";exit;} if(count(explode("and",$guol))>1){ echo "非法";exit;} if(count(explode("show",$guol))>1){ echo "非法";exit;} } foreach($_GET as $key=>$value){ stopSql($value); } foreach($_POST as $key=>$value){ // stopSql($value); } function substr_table($string,$star,$end){ return substr_for_gb2312(str_replace(" ","",strip_tags($string)),$star,$end); } function get_up_down_new($Type_id,$Num){ $link=new Connect(); $array = array(); $sql="select * from news where Num >".$Num." and Type_id=".$Type_id." order by Num limit 0,1"; $arr = $link->Execute($sql); $array[0]['Id']=$arr[0]['Id']; $array[0]['Title']=$arr[0]['Title']; $arr = array(); $sql="select * from news where Num <".$Num." and Type_id=".$Type_id." order by Num desc limit 0,1"; $arr = $link->Execute($sql); $array[1]['Id']=$arr[0]['Id']; $array[1]['Title']=$arr[0]['Title']; return $array; } /** *根据产品分类id返回他上级所有的id+产品分类id */ function getup($Id,$s1=''){ if($s1=="") $s1=$Id; $s=$s1; $link=new Connect(); $sql="select Id,Parent_id from newstype where Id=".$Id; $row=$link->Execute($sql); if($row[0]['Parent_id']<>0){ $s1=$s.",".$row[0]['Parent_id']; $s=getup($row[0]['Parent_id'],$s1); } return $s; } /** *根据产品分类id返回他下级所有的id */ function getdown($Id,$s=''){ if($s=="") $s=$Id; $link=new Connect(); $sql="select * from newstype where Parent_id=".$Id; $row=$link->Execute($sql); for($i=0;$iExecute($sql); $up_Num=$arr[0]['Num']; $up_Id=$arr[0]['Id']; $sql="update newstype set Num=".$up_Num." where Id=".$Id; $link->Execute($sql); $sql="update newstype set Num=".$Num." where Id=".$up_Id; $link->Execute($sql); } else{ $sql="select Id,Num from newstype where Num >".$Num." and Parent_id=".$Parent_id." order by Num limit 0,1"; $arr = $link->Execute($sql); $up_Num=$arr[0]['Num']; $up_Id=$arr[0]['Id']; $sql="update newstype set Num=".$up_Num." where Id=".$Id; $link->Execute($sql); $sql="update newstype set Num=".$Num." where Id=".$up_Id; $link->Execute($sql); } } function getFileSize($filename){ $size1=filesize($filename); //获知文件字节数 if($size1>=1024*1024*1024){ return round($size1/1024/1024/1024,2)."GB"; } else if($size1>=1024*1024){ return round($size1/1024/1024,1)."MB"; } else if($size1>=1024){ return round($size1/1024,0)."KB"; } else { return $size1."Byte";} } function getFileGeshi($filename){ $array=explode('.',$filename); return $array[count($array)-1]; } function insert_tj($web,$date){ $link=new Connect(); $link->Execute("INSERT INTO `tj` (`web`,`create`) VALUES ('".$web."','".$date."')"); } function get_tj(){ $link=new Connect(); $arr = $link->Execute("select count(*) as num from tj"); return $arr['0']['num']; } //读取数据 function getVote($Id,$ip=""){ $link = new Connect(); if($ip=="") $sql = "SELECT * FROM vote WHERE news_id = ".$Id; else $sql = "SELECT * FROM vote WHERE news_id = ".$Id." and ip = '".$ip."'"; $row = $link->Execute($sql); return $row; } //存入数据 function setVote($data) { $link = new Connect(); if($link->insertSql("vote",$data)) return true; else return false; } //获取ip算法 function getIp() { if ($HTTP_SERVER_VARS["HTTP_X_FORWARDED_FOR"]) { $ip = $HTTP_SERVER_VARS["HTTP_X_FORWARDED_FOR"]; } elseif ($HTTP_SERVER_VARS["HTTP_CLIENT_IP"]) { $ip = $HTTP_SERVER_VARS["HTTP_CLIENT_IP"]; } elseif ($HTTP_SERVER_VARS["REMOTE_ADDR"]) { $ip = $HTTP_SERVER_VARS["REMOTE_ADDR"]; } elseif (getenv("HTTP_X_FORWARDED_FOR")) { $ip = getenv("HTTP_X_FORWARDED_FOR"); } elseif (getenv("HTTP_CLIENT_IP")) { $ip = getenv("HTTP_CLIENT_IP"); } elseif (getenv("REMOTE_ADDR")) { $ip = getenv("REMOTE_ADDR"); } else { $ip = false; } return $ip; } // function pShowMessage($str_message = null,$str_type = 'Back',$str_url = '../', $is_exit = true) { echo ''; if ($is_exit){ exit(); } } /** * 检测邮箱 * * @param sting $email * @return boolean */ function checkEmail($email){ $exp = "^[a-z'0-9]+([._-][a-z'0-9]+)*@([a-z0-9]+([._-][a-z0-9]+))+$"; if(eregi($exp,$email)){ return true; }else{ return false; } } /** * 检测手机号码 * * @param string $string * @return boolean */ function checkMobile($string){ if(preg_match("/^13[0-9]{1}[0-9]{8}$|15[0-9]{1}[0-9]{8}$|18[0-9]{9}$/",$string)){ return true; }else{ return false; } } function sGetFiltrateStr($str) { $tmpstr = trim($str); $tmpstr = strip_tags($tmpstr); $tmpstr = htmlspecialchars($tmpstr); $tmpstr = addslashes($tmpstr); $tmpstr = str_replace(" ","", $tmpstr); $tmpstr = trim($tmpstr); $tmpstr = str_replace("&nbsp;","", $tmpstr); return $tmpstr; } function substr_for_utf($string,$start,$length) { //by aiou $chars = $string; //echo $string[0].$string[1].$string[2]; $i=0; do{ if (preg_match ("/[0-9a-zA-Z]/", $chars[$i])){//纯英文 $m++; } else {$n++; }//非英文字节, $k = $n/3+$m/2; $l = $n/3+$m;//最终截取长度;$l = $n/3+$m*2? $i++; } while($k < $length); $str1 = mb_substr($string,$start,$l,'utf-8');//保证不会出现乱码 if(($string)<>$str1){$str1=$str1."...";} return $str1; } function i_array_column($input, $columnKey, $indexKey=null){ if(!function_exists('array_column')){ $columnKeyIsNumber = (is_numeric($columnKey))?true:false; $indexKeyIsNull = (is_null($indexKey))?true :false; $indexKeyIsNumber = (is_numeric($indexKey))?true:false; $result = array(); foreach((array)$input as $key=>$row){ if($columnKeyIsNumber){ $tmp= array_slice($row, $columnKey, 1); $tmp= (is_array($tmp) && !empty($tmp))?current($tmp):null; }else{ $tmp= isset($row[$columnKey])?$row[$columnKey]:null; } if(!$indexKeyIsNull){ if($indexKeyIsNumber){ $key = array_slice($row, $indexKey, 1); $key = (is_array($key) && !empty($key))?current($key):null; $key = is_null($key)?0:$key; }else{ $key = isset($row[$indexKey])?$row[$indexKey]:0; } } $result[$key] = $tmp; } return $result; }else{ return array_column($input, $columnKey, $indexKey); } } ?>