<?php
class companyfen
{
    var $db;
	var $tpl;
	var $page;
	
	function companyfen()
	{
		global $db;
		global $tpl;		
		$this -> db     = & $db;
		$this -> tpl    = & $tpl;
	}
	
	//个人信息 
	function get_pon($cid=0)
	{
		$this -> db->query("select * from ".COMPANY." where company_id='$cid'");
		$info=$this -> db->fetchRow();
		if(empty($info))
		     return 0; 
		$ar=array('name','sex','position','email','province','city');//必填项
	   	foreach($ar as $val)
		{
			if(empty($info[$val])&&$info[$val]!=0)
				return 0;//有必填项未填写
		}
		return 20; //获得10分  
	}
	
	//企业信息
	function get_com($userid=0) 
	{
		$this->db->query("select * from ".ALLUSER." where userid='$userid'");
		$info=$this->db->fetchRow();
		if(empty($info))
			return 0; 
		$ar=array('company','contact','tel','zip','addr','province','city','ctype','main_pro','purch_pro','staff_num');//必填项
	   	foreach($ar as $val)
		{
			if(empty($info[$val])&&$info[$val]!=0)
				return 0;//有必填项未填写
		}
		return 20; //获得20分  
	}
	
	//工商信息
	function get_gs($userid=0) 
	{
		$this->db->query("select * from ".CERTIFICATION." where company_id='$userid' limit 1");
		$num=$this->db->num_rows();
		if(empty($num))
			return 0;
		else
			return 10;
	}
	
	//产品信息  //小于5条20分
	function get_offer($userid=0)
	{
		$this->db->query("select * from ".INFO." where company_id='$userid' ");
		$num=$this->db->num_rows();
		if(empty($num))
			return 0;
		else if($num<5)
			return 20;
		else
			return 45;
	}
	
	//新闻信息  //小于5分
	function get_news($userid=0) 
	{
		$this->db->query("select * from ".NEWSD." where uid='$userid' limit 1");
		$num=$this->db->num_rows();
		if(empty($num))
			return 0; 
		else
		    return 5; 
	}
	//最终得分
    function get_all($userid)
	{
		$fen=$this->get_news($userid)*1+$this->get_pon($userid)*1+$this->get_com($userid)*1+$this->get_gs($userid)*1+$this->get_offer($userid)*1;
		return $fen;
	}
}
?>