<?php
 /*
 * 74cms 管理中心 通讯录相关函数
 * ============================================================================
 * 版权所有: 骑士网络，并保留所有权利。
 * 网站地址: http://www.74cms.com；
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和
 * 使用；不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
*/
 if(!defined('IN_QISHI'))
 {
die('Access Denied!');
 }
//获取职位信息列表
function get_list($offset,$perpage,$get_sql= '')
{
	global $db,$timestamp;
	$row_arr = array();
	$limit=" LIMIT ".$offset.','.$perpage;
	$result =  $db->query("SELECT *  FROM ".table('list')." AS l ".$get_sql);
	while($row = $db->fetch_array($result))
	{
		$row['title_']=$row['title'];
		$row['title']=cut_str($row['title'],18,0,"...");
		$row['trade_cn_']=$row['trade_cn'];
		$row['trade_cn']=cut_str($row['trade_cn'],16,0,"...");
		if(intval($row['utype'])==1)
		{
			$sql = "select * from ".table('company_profile')." where uid=".intval($row['uid'])." LIMIT 1 ";
			$belong_info = $db->getone($sql);
			$row['belong_people_'] = $belong_info['companyname'];
			$row['belong_people'] = cut_str($row['belong_people_'],11,0,"...");
			//$row['belong_url'] = url_rewrite('QS_companyshow',array('id'=>$belong_info['id']));
		}
		elseif(intval($row['utype'])==3)
		{
			$sql = "select * from ".table('hunter_profile')." where uid=".intval($row['uid'])." LIMIT 1 ";
			$belong_info = $db->getone($sql);
			$row['belong_people_'] = $belong_info['fullname'];
			$row['belong_people'] = cut_str($row['belong_people_'],11,0,"...");
			//$row['belong_url'] = url_rewrite('QS_hunter_show',array('id'=>$belong_info['id']));
		}
		$row['list_url'] = url_rewrite('QS_list_show',array('id'=>$row['id']));
		$row_arr[] = $row;
	}
	return $row_arr;
}
//修改list审核状态
function edit_list_audit($id,$audit)
{
	global $db,$_CFG;
	$audit=intval($audit);
	if (!is_array($id))$id=array($id);
	$sqlin=implode(",",$id);
	$return=0;
	if (preg_match("/^(\d{1,10},)*(\d{1,10})$/",$sqlin))
	{
		$listarry = $db->getall("SELECT * FROM ".table('list')." WHERE id IN ({$sqlin}) ");
		foreach ($listarry as $key => $list)
		{
			if(updatetable(table('list') , array('audit'=>$audit) , " id={$list['id']}"))
			{
				$return++;
			}
		}
	}
	return $return;
}
//删除list
function del_list($id)
{
	global $db,$_CFG;
	if (!is_array($id))$id=array($id);
	$sqlin=implode(",",$id);
	$return=0;
	if (preg_match("/^(\d{1,10},)*(\d{1,10})$/",$sqlin))
	{
		//先循环的删掉文件
		$result = $db->query("select * from ".table('list')." WHERE id IN ({$sqlin})");
		while($row = $db->fetch_array($result))
		{
			$path = QISHI_ROOT_PATH."data/list/".$row['file'];
			if(unlink($path))
			{
				if (!$db->query("Delete from ".table('list')." WHERE id = ({$row['id']})")) return false;
				$return=$return+$db->affected_rows();
			}
		}
		return $return;
	}
	else
	{
		return false;
	}
}
//得到单条list通讯录
function get_list_one($id)
{
	global $db;
	$id=intval($id);
	$val=$db->getone("select * from ".table('list')." where id='{$id}' LIMIT 1");
	$members=get_user($val['uid']);
	$val['down'] = $db->get_total("select count(*) as num from ".table('down_list')." where  id =".$id);
	if(intval($val['utype'])==1)
	{
		$com=$db->getone("select * from ".table('company_profile')." where uid='{$val['uid']}' LIMIT 1");
		$val['belong_url']=url_rewrite('QS_companyshow',array('id'=>$com['id']));
		//所属会员
		$val['belong']=$members['username'];
		//上传者
		$val['belong_name']=$com['companyname'];
		//联系人
		$val['contact']=$members['fullname'];
		$val['contact_email']=$members['email'];
		$val['contact_mobile']=$members['mobile'];
	}
	else
	{
		$hun=$db->getone("select * from ".table('hunter_profile')." where uid='{$val['uid']}' LIMIT 1");
		$val['belong_url']=url_rewrite('QS_hunter_show',array('id'=>$hun['id']));
		//所属会员
		$val['belong']=$members['username'];
		//上传者
		$val['belong_name']=$hun['fullname'];
		//联系人
		$val['contact']=$hun['fullname'];
		$val['contact_email']=$members['email'];
		$val['contact_mobile']=$members['mobile'];
	}
	return $val;
}
function get_user($uid)
{
	global $db;
	$sql = "select * from ".table('members')." where uid=".intval($uid)." LIMIT 1";
	return $db->getone($sql);
}
//得到下载list通讯录信息
function get_down_info($offset,$perpage,$id)
{
	global $db,$_CFG;
	$id = intval($id);
	$limit=" LIMIT ".$offset.','.$perpage;
	$list_info = $db->getone("select * from ".table('list')." where id =".$id." limit 1");
	//下载list会员信息
	$row_arr = array();
	$result = $db->query("select * from ".table('down_list')." WHERE list_id = {$id}".$limit);
	while($row = $db->fetch_array($result))
	{
		$members = $db->getone("select * from ".table('members')." WHERE uid = {$row['uid']} limit 1");
		//会员名称
		$row['username'] = $members['username'];
		if(intval($row['utype'])==1)
		{
			$info = $db->getone("select * from ".table('company_profile')." where uid=".intval($row['uid'])." LIMIT 1 ");
			$row['down_people'] = $info['companyname'];
		}
		else
		{
			$info = $db->getone("select * from ".table('hunter_profile')." where uid=".intval($row['uid'])." LIMIT 1 ");
			$row['down_people'] = $info['fullname'];
		}
		$row['down_num'] = $db->get_total("select count(*) as num from ".table('down_list')." where uid=".$row['uid']." and id =".$id);
		$row['cost'] = intval($list_info['price'])*round(intval($_CFG['charge_ratio'])/100,2);
		$is_report = $db->getone("select * from ".table('report_list')." where uid=".intval($row['uid'])." and list_id=".$id." LIMIT 1 ");
		//未举报
		if(empty($is_report))
		{
			$row['is_report']='未投诉';
		}
		else
		{
			$row['is_report']='已投诉';
		}
		$row_arr[] = $row;
	}
	return $row_arr;
}




?>