<?php
/*
	[Office 515158] (C) 2009-2014 天生创想 Inc.
	$Id: mod_communication mobile $
*/
(!defined('IN_TOA') || !defined('IN_ADMIN')) && exit('Access Denied!');
empty($do) && $do = 'list';
if ($do == 'list') {
	$type=getGP('type','G');
	if($type==''){
		$type=1;
	}
	if($type=='1'){
		$wheresql = " where type=1 and  uid='".$_USER->id."'";
	}else{
		$wheresql = " where type=2";
	}
	$num = $db->result("SELECT COUNT(*) AS num FROM ".DB_TABLEPRE."communication ".$wheresql." order by id desc");
    $sql = "SELECT * FROM ".DB_TABLEPRE."communication ".$wheresql." ORDER BY id desc LIMIT 0,100";
	$result = $db->fetch_all($sql);
	include_once('template/communication.php');

}elseif ($do == 'views') {
	$id = getGP('id','G','int');
	$type = getGP('type','G','int');
	if($id!=''){
		$row = $db->fetch_one_array("SELECT * FROM ".DB_TABLEPRE."communication  WHERE id = '".$id."'");
	}
	include_once('template/communication_view.php');
}elseif ($do == 'add') {
	if($_POST['view']!=''){
			$id = getGP('id','P','int');
			$com = array();
			$com['company'] = getGP('company','P');
			$com['person'] = getGP('person','P');
			$com['tel'] = getGP('tel','P');
			$com['phone'] = getGP('phone','P');
			$com['fax'] = getGP('fax','P');
			$com['mail'] = getGP('mail','P');
			$com['zipcode'] = getGP('zipcode','P');
			$com['address'] = getGP('address','P');
			$com['position'] = getGP('position','P');
			$com['sex'] = getGP('sex','P');
			$com['msn'] = getGP('msn','P');
			$com['type'] = getGP('type','P');
		if($id!=''){
			update_db('communication',$com, array('id' => $id));
			$content='';
			$id=$db->insert_id();
			$content=serialize($com);
			$title='编辑通迅录';
			get_logadd($id,$content,$title,9,$_USER->id);
			
		}else{
			$com['date'] = get_date('Y-m-d H:i:s',PHP_TIME);
			$com['uid'] = $_USER->id;
			insert_db('communication',$com);
			$content='';
			$id=$db->insert_id();
			$content=serialize($com);
			$title='添加通迅录';
			get_logadd($id,$content,$title,9,$_USER->id);
		}
		$formlist='true';
	}else{
		$id = getGP('id','G','int');
		$type = getGP('type','G','int');
		if($id!=''){
			$row = $db->fetch_one_array("SELECT * FROM ".DB_TABLEPRE."communication  WHERE id = '".$id."'");
			$_title['name']='编辑';
		}else{ 
			$_title['name']='新增';
			$row['sex']='男';
		}
		
	}
	include_once('template/communication_add.php');

}
?>