<?php
if (!defined('ROOT')) exit('Can\'t Access !'); 
class mod_company extends module_class{
	function main(){
       $typeid = $_GET['typeid'];
	   $s_province = $_POST['s_province'];
	   $s_city = $_POST['s_city'];
	   $s_county = $_POST['s_county'];
	   $wd = $_POST['wd']; 
	   $where = "where checked='1' ";
	   if($typeid) $where .= "and typeid='{$typeid}'";
	   if($s_province&&$s_province!='省份') $where .= "and s_province='{$s_province}'";
	   if($s_city&&$s_city!='地级市') $where .= "and s_city='{$s_city}'";
	   if($s_county&&$s_county!='市、县级市') $where .= "and s_county='{$s_county}'";
	   if($wd&&$wd!='请输入关键词') $where .= "and name like '%{$wd}%'";
	   $pagetotal = $this->pagetotal = $this->mysql->counts("select * from {$this->pre}company $where");
	   $this->pageclass($pagetotal,6);
	   $this->company = $this->mysql->getarr("select * from {$this->pre}company $where order by addtime desc,id desc limit ".$this->page->start.",".$this->page->size); 
	   $this->hotcompany = $this->mysql->getarr("select * from {$this->pre}company where checked='1' and ishot='1'  order by checked desc,id desc limit 0,5");  
	   $this->type = $this->mysql->getarr("select * from {$this->pre}companytype order by `typeorder` asc");
    }
	
 	function show(){
	   $this->company = $this->mysql->select_one("select * from {$this->pre}company where id='{$_GET[id]}' ");  
	   if(!is_array($this->company))  $this->message('go_back','对不起，该信息不存在');
	   $this->pics = array_filter(explode('|',$this->company['pics']));
	   $this->hotcompany = $this->mysql->getarr("select * from {$this->pre}company where checked='1' and ishot='1' order by checked desc,id desc limit 0,5");  
	   $this->type = $this->mysql->getarr("select * from {$this->pre}companytype order by `typeorder` asc");
	}
	
 	function add(){
	   $typequery = $this->mysql->query("select * from {$this->pre}companytype order by `typeorder` asc");
	   while($typers=$this->mysql->assoc($typequery)){
		 $this->typelist .= "[<$typers[id]><$typers[typename]>]";;
	   }
	   $this->hotcompany = $this->mysql->getarr("select * from {$this->pre}company where checked='1' and ishot='1' order by checked desc,id desc limit 0,5");   
	   $this->type = $this->mysql->getarr("select * from {$this->pre}companytype order by `typeorder` asc");
       if(submit()){
		  $arr['name'] = sintrim($_POST['name']);
		  $arr['address'] = $_POST['address'];
		  $arr['person'] = $_POST['person'];
		  $arr['telphone'] = $_POST['telphone'];
		  $arr['qq'] = $_POST['qq'];
		  $arr['website'] = $_POST['website'];
		  $arr['typeid'] = $_POST['typeid'];
		  $arr['addtime'] = time();
		  $arr['content'] = $_POST['content'];
		  $arr['checked'] = 0; 
		  $arr['ishot'] = 0; 
		  $arr['s_province'] = $_POST['s_province'];
		  $arr['s_city'] = $_POST['s_city']; 
		  $arr['s_county'] = $_POST['s_county']; 
		  $message = '申请已提交，请等待审核';
          $this->mysql->insert("{$this->pre}company",$arr); 
		  $this->message('company_main',$message);
	    }
	   
	}
}
?>