<?php
/* *
* $Author ：PHPYUN开发团队
*
* 官网: http://www.phpyun.com
*
* 版权所有 2009-2018 宿迁鑫潮信息技术有限公司，并保留所有权利。
*
* 软件声明：未经授权前提下，不得用于商业运营、二次开发以及任何形式的再次发布。
*/
class info_controller extends company{
	function index_action(){
		 
		$row=$this->obj->DB_select_once("company","`uid`='".$this->uid."'");
		if ($row['comqcode']){
		    $row['comqcode']=str_replace('./', $this->config['sy_weburl'].'/', $row['comqcode']);
		}
		$save=$this->obj->DB_select_once("lssave","`uid`='".$this->uid."'and `savetype`='3'");
		$save=unserialize($save['save']);
		if($save['lastupdate']){
			$save['time']=date('H:i',ceil(($save['lastupdate'])));
		} 
		if($row['linkphone']){
			$linkphone=@explode('-',$row['linkphone']);
			$row['phoneone']=$linkphone[0];
			$row['phonetwo']=$linkphone[1];
			$row['phonethree']=$linkphone[2]; 
		}
		if (($row['x']==''||$row['y']=='')&&$row['address']!=''){
		    $row['setmap']=1;
		}elseif ($row['x']!=''&&$row['y']!=''){
		    $row['setmap']=2;
		}else{
		    $row['setmap']=3;
		}
		if ($row['welfare']){
			$row['arraywelfare']=explode(',', $row['welfare']);
		}

		if($row['logo'] && $row['logo_status']!='0'){
			$row['logo']=null;
		}

		$row['content']=str_replace(array("ti<x>tle","“","”"),array("title"," "," "),$row['content']);
		
		$tel=$this->obj->DB_select_once("company_cert","`uid`='".$this->uid."' and `type`='2'");
		$this->yunset("save",$save);
		$this->yunset("tel",$tel);
		$this->yunset("row",$row);
		$this->public_action();
		$this->company_satic();
		$this->yunset($this->MODEL('cache')->GetCache(array('com','city','job','hy')));
		$cert=$this->obj->DB_select_once("company_cert","`uid`='".$this->uid."' and type='3'");
		$this->yunset("cert",$cert);
		$this->yunset("js_def",2);
		$this->com_tpl('info');
	}
	function save_action(){
		$UploadM=$this->MODEL('upload');
		$IntegralM=$this->MODEL('integral');
		$_POST=$this->post_trim($_POST);
 		if(trim($_POST['linktel'])){
		    $t_exist=$this->obj->DB_select_once("member","`uid`<>'".$this->uid."' and `moblie`='".$_POST['linktel']."'","`uid`");
		}else if($_POST['linkmail']){
		    $e_exist=$this->obj->DB_select_once("member","`uid`<>'".$this->uid."' and `email`='".$_POST['linkmail']."'","`uid`");
		}
		if($t_exist['uid']){
		    $this->ACT_layer_msg("手机已存在！",8);
		}elseif ($e_exist['uid']){
		    $this->ACT_layer_msg("邮箱已存在！",8);
		}
		$company=$this->obj->DB_select_once("company","`uid`='".$this->uid."'");
		$comname=$this->obj->DB_select_all('company',"`uid`<>'".$this->uid."' and `name`='".$_POST['name']."'","`uid`");
		if($_POST['name']==""){
		    $this->ACT_layer_msg("企业全称不能为空！",8);
		}
		if($comname){
		    $this->ACT_layer_msg("企业全称已存在！",8);
		}
		if($_POST['hy']==""){
		    $this->ACT_layer_msg("从事行业不能为空！",8);
		}
		if($_POST['pr']==""){
		    $this->ACT_layer_msg("企业性质不能为空！",8);
		}
		if($_POST['mun']==""){
		    $this->ACT_layer_msg("企业规模不能为空！",8);
		}
		if($_POST['provinceid']==""){
		    $this->ACT_layer_msg("所在地不能为空！",8);
		}
		if($_POST['address']==""){
		    $this->ACT_layer_msg("公司地址不能为空！",8);
		}
		if($_POST['linkman']==""){
		    $this->ACT_layer_msg("联系人不能为空！",8);
		}
		$linkphone=array();
		if($_POST['phonetwo']&&$_POST['phonetwo']!='座机号'){
		    if($_POST['phoneone']==''||$_POST['phoneone']=='区号'){
		        $this->ACT_layer_msg("请填写区号！",8);
		    }else{
		        $linkphone[]=$_POST['phoneone'];
		    }
		    if($_POST['phonetwo']&&$_POST['phonetwo']!='座机号'){
		        $linkphone[]=$_POST['phonetwo'];
		    }
		    if($_POST['phonethree']&&$_POST['phonetwo']!='分机号'){
		        $linkphone[]=$_POST['phonethree'];
		    }
		}
		$_POST['linkphone']=@implode('-',$linkphone);
		if($_POST['linktel']==""){
		    if($_POST['linkphone']==""){
		        $this->ACT_layer_msg("联系手机和固定电话任填一项！",8);
		    }else if($_POST['phoneone']==""){
		        $this->ACT_layer_msg("请填写区号！",8);
		    }
		}
		if($_POST['content']==""){
		    $this->ACT_layer_msg("企业简介不能为空！",8);
		}
		
		delfiledir("../data/upload/tel/".$this->uid);
		unset($_POST['submitbtn']);
		if($_FILES['firmpic']['tmp_name']){
		    $upload=$UploadM->Upload_pic("../data/upload/company/",false);
		    $firmpic=$upload->picture($_FILES['firmpic']);
		    $picmsg = $UploadM->picmsg($firmpic,$_SERVER['HTTP_REFERER']);
		    if($picmsg['status'] == $firmpic){
		        $this->ACT_layer_msg($picmsg['msg'],8);
		    }
		    $_POST['firmpic'] = str_replace("../data/upload/company","./data/upload/company",$firmpic);
		    if($company['firmpic']){
		        unlink_pic(".".$company['firmpic']);
		    }
		}
		$Member=$this->MODEL("userinfo");
		if($_POST['linktel']!=""){
		    if($company['moblie_status']==1){
		        unset($_POST['linktel']);
		    }else{
		        $moblieNum = $Member->GetMemberNum(array("moblie"=>$_POST['linktel'],"`uid`<>'".$this->uid."'"));
		        if($_POST['linktel']==''){
		            $this->ACT_layer_msg("手机号码不能为空！",8);
		        }elseif(!CheckMoblie($_POST['linktel'])){
		            $this->ACT_layer_msg("手机号码格式错误！",8);
		        }elseif($moblieNum>0){
		            $this->ACT_layer_msg("手机号码已存在！",8);
		        }else{
		            $mvalue['moblie']=$_POST['linktel'];
		        }
		    }
		}
		if($company['email_status']==1){
		    unset($_POST['linkmail']);
		}elseif($_POST['linkmail']){
		    $emailNum = $Member->GetMemberNum(array("email"=>$_POST['linkmail'],"`uid`<>'".$this->uid."'"));


			if(CheckRegEmail($_POST['linkmail'])==false){

		        $this->ACT_layer_msg("联系邮箱格式错误！",8);
		    }elseif($emailNum>0){

		        $this->ACT_layer_msg("联系邮箱已存在！",8);
		    }else{
		        $mvalue['email']=$_POST['linkmail'];
		    }
		}

		$where['uid']=$this->uid;
		$_POST['content']=str_replace(array("&amp;","background-color:#ffffff","background-color:#fff","white-space:nowrap;"),array("&",'background-color:','background-color:','white-space:'),$_POST['content']);
		$_POST['lastupdate']=mktime();
		if($company['yyzz_status']=='1'){
		    unset($_POST['name']);
		}else{
		    $data['com_name']=$_POST['name'];
		}
		$_POST['welfare']=@implode(',',$_POST['welfare']);
		$nid=$this->obj->update_once("company",$_POST,$where);
		$this->cookie->SetCookie("delay", "", time() - 60);
		if($nid){
		    $this->obj->DB_delete_all("lssave","`uid`='".$this->uid."'and `savetype`='3'");
		    $this->obj->member_log("修改企业信息",7);
		    
		    if($company['lastupdate']==""){
		        if($this->config['integral_userinfo_type']=="1"){
		            $auto=true;
		        }else{
		            $auto=false;
		        }
		        
		        $IntegralM->company_invtal($this->uid,$this->config['integral_userinfo'],$auto,"首次填写基本资料",true,2,'integral',25);
		    }
		    $data['pr']=$_POST['pr'];
		    $data['mun']=$_POST['mun'];
		    $data['com_provinceid']=$_POST['provinceid'];
		    $data['welfare']=$_POST['welfare'];
		    $this->obj->update_once("company_job",$data,array("uid"=>$this->uid));
			$member_status = $this->obj->DB_select_once("member","`uid`='".$this->uid."'","`status`");
			if($member_status && $member_status['status']=='3'){
				$mvalue['status']='0';
			}
		    if(!empty($mvalue)){

		        $this->obj->update_once('member',$mvalue,array("uid"=>$this->uid));
		    }
		    if($_POST['name']!=$company['name']&&$_POST['name']){
		        $this->obj->update_once("hotjob",array("username"=>$_POST['name']),array("uid"=>$this->uid));
		        $this->obj->update_once("partjob",array("com_name"=>$_POST['name']),array("uid"=>$this->uid));
		        $this->obj->update_once("userid_job",array("com_name"=>$_POST['name']),array("com_id"=>$this->uid));
		        $this->obj->update_once("fav_job",array("com_name"=>$_POST['name']),array("com_id"=>$this->uid));
		        $this->obj->update_once("report",array("r_name"=>$_POST['name']),array("c_uid"=>$this->uid));
		        $this->obj->update_once("blacklist",array("com_name"=>$_POST['name']),array("c_uid"=>$this->uid));
		        $this->obj->update_once("msg",array("com_name"=>$_POST['name']),array("job_uid"=>$this->uid));
		    }
			$this->obj->DB_update_all("user_log","`status`='1'","`id`='".$_POST['logid']."'");
		    $this->ACT_layer_msg("更新成功！",9,"index.php?c=info");
		}else{
			$this->obj->DB_update_all("user_log","`status`='2'","`id`='".$_POST['logid']."'");
		    $this->ACT_layer_msg("更新失败！",8,"index.php?c=info");
		}
	}
}
?>