addressbook.class.inc

来自「groupoffice」· INC 代码 · 共 1,110 行 · 第 1/3 页

INC
1,110 行
字号
			return $this->f('id');		}		return false;	}	function search_contacts($user_id, $query, $field = 'last_name', $addressbook_id = 0, $mtime = 0, $start=0, $offset=0, $require_email=false) {		$query = str_replace('*', '%', $query);		if ($_SESSION['GO_SESSION']['sort_name'] == 'first_name') {			$sort = 'ab_contacts.first_name ASC, ab_contacts.last_name ASC';		} else {			$sort = 'ab_contacts.last_name ASC, ab_contacts.first_name ASC';		}		$sql = "SELECT ab_contacts.* FROM ab_contacts ";		if (strpos($field, 'ab_custom_contact_fields') !== false) {			$sql .= "INNER JOIN ab_custom_contact_fields ON ab_custom_contact_fields.id=ab_contacts.id ";		}		if ($addressbook_id > 0) {			$sql .= "WHERE ab_contacts.addressbook_id='$addressbook_id' AND ";		} else {						$count = $this->get_user_addressbooks($user_id);						if($count > 1)			{				while($this->next_record())				{					$user_ab[] = $this->f('id');									}				$sql .= "WHERE ab_contacts.addressbook_id IN (".implode(",",$user_ab).") AND ";			}elseif(	$this->next_record())			{				$sql .= "WHERE ab_contacts.addressbook_id=".$this->f('id')." AND ";			}else			{				return false;			}		}		if ($field == '') {			$fields_sql = "SHOW FIELDS FROM ab_contacts";			$this->query($fields_sql);			while ($this->next_record()) {				if (eregi('varchar', $this->f('Type'))) {					if (isset ($first)) {						$sql .= ' OR ';					} else {						$first = true;						$sql .= '(';					}					$sql .= "ab_contacts.".$this->f('Field')." LIKE '$query'";				}			}			$sql .= ')';		} else {			$sql .= "$field LIKE '$query' ";		}				if($require_email)		{			$sql .= " AND ab_contacts.email != ''";		}		$sql .= " ORDER BY $sort";		$this->query($sql);		$count = $this->num_rows();		if($offset > 0)		{				$sql .= " LIMIT $start, $offset";					$this->query($sql);			return $count;			}else		{			return $count;		}	}	function get_contacts_by_birthday($interval_start, $interval_end) {	}	function search_companies($user_id, $query, $field = 'name', $addressbook_id = 0, $start=0, $offset=0, $require_email=false) {		$query = str_replace('*', '%', $query);		$sql = "SELECT ab_companies.* FROM ab_companies ";		if (strpos($field, 'ab_custom_company_fields') !== false) {			$sql .= "INNER JOIN ab_custom_company_fields ON ab_custom_company_fields.id=ab_companies.id ";		}		if ($addressbook_id > 0) {			$sql .= "WHERE ab_companies.addressbook_id='$addressbook_id' AND ";		} else {						$count = $this->get_user_addressbooks($user_id);						if($count > 1)			{				while($this->next_record())				{					$user_ab[] = $this->f('id');									}				$sql .= "WHERE ab_companies.addressbook_id IN (".implode(",",$user_ab).") AND ";			}elseif(	$this->next_record())			{				$sql .= "WHERE ab_companies.addressbook_id=".$this->f('id')." AND ";			}else			{				return false;			}		}		if ($field == '') {			$fields_sql = "SHOW FIELDS FROM ab_companies";			$this->query($fields_sql);			while ($this->next_record()) {				if (eregi('varchar', $this->f('Type'))) {					if (isset ($first)) {						$sql .= ' OR ';					} else {						$first = true;						$sql .= '(';					}					$sql .= "ab_companies.".$this->f('Field')." LIKE '$query'";				}			}			$sql .= ')';		} else {			$sql .= "$field LIKE '$query' ";		}				if($require_email)		{			$sql .= " AND ab_companies.email != ''";		}		$sql .= "ORDER BY ab_companies.name ASC";				$this->query($sql);		$count = $this->num_rows();		if($offset > 0 )		{				$sql .= " LIMIT $start, $offset";					$this->query($sql);			return $count;			}else		{			return $count;		}	}	function get_contacts($addressbook_id=0, $sort = "name", $direction = "ASC", $start=0, $offset=0, $links=false) {		global $GO_SECURITY;		if ($sort == 'name') {			if ($_SESSION['GO_SESSION']['sort_name'] == 'first_name') {				$sort = 'first_name '.$direction.', last_name';			} else {				$sort = 'last_name '.$direction.', first_name';			}		}		$sql = "SELECT * FROM ab_contacts ";		if($addressbook_id>0)		{			$sql .= " WHERE ab_contacts.addressbook_id='$addressbook_id'";		}				if(is_array($links))		{			if(!count($links))			{				return 0;			}			if($addressbook_id>0)			{				$sql .= " AND ";			}else			{				$sql .= " WHERE ";			}			$sql .= "link_id IN (".implode(',', $links).")";		}		$sql .= 	" ORDER BY $sort $direction";				$this->query($sql);		$count =  $this->num_rows();		if ($offset != 0 && $count > $offset) {			$sql .= " LIMIT $start, $offset";			$this->query($sql);		} 		return $count;	}	function get_user_contacts($user_id, $addressbook_id) {		$this->query("SELECT * FROM ab_contacts WHERE addressbook_id='$addressbook_id' AND user_id='$user_id'");		return $this->num_rows();	}	function get_user_companies($user_id, $addressbook_id) {		$this->query("SELECT * FROM ab_companies WHERE addressbook_id='$addressbook_id' AND user_id='$user_id'");		return $this->num_rows();	}	function get_company_contacts($company_id, $sort = "name", $direction = "ASC", $start, $offset) {		if ($sort == 'name') {			if ($_SESSION['GO_SESSION']['sort_name'] == 'first_name') {				$sort = 'first_name '.$direction.', last_name';			} else {				$sort = 'last_name '.$direction.', first_name';			}			//	  $sort = 'first_name '.$direction.', last_name';		}		$sql = "SELECT * FROM ab_contacts WHERE company_id='$company_id' ORDER BY $sort $direction";		if ($offset != 0) {			$sql .= " LIMIT $start, $offset";			$sql2 = "SELECT * FROM ab_contacts WHERE company_id='$company_id'";			$this->query($sql2);			$count = $this->num_rows();			if ($count > 0) {				$this->query($sql);				return $count;			}			return 0;		} else {			$this->query($sql);			return $this->num_rows();		}	}	function get_contacts_for_export($addressbook_id, $user_id = 0) {		global $GO_SECURITY;		if ($user_id == 0) {			$user_id = $GO_SECURITY->user_id;		}		$sql = "SELECT ab_contacts.*, ab_groups.name AS group_name,"."ab_companies.name AS company FROM ab_contacts "."LEFT JOIN ab_groups ON (ab_contacts.group_id=ab_groups.id) "."LEFT JOIN ab_companies ON (ab_contacts.company_id=ab_companies.id) "." WHERE ab_contacts.addressbook_id='$addressbook_id' "."ORDER BY ab_contacts.first_name, ab_contacts.last_name ASC";		$this->query($sql);		return $this->num_rows();	}	function get_contacts_group($addressbook_id, $group_id, $sort = "name", $direction = "ASC", $user_id = 0) {		global $GO_SECURITY;		if ($user_id == 0) {			$user_id = $GO_SECURITY->user_id;		}		if ($sort == 'name') {			if ($_SESSION['GO_SESSION']['sort_name'] == 'first_name') {				$sort = 'first_name '.$direction.', middle_name, last_name';			} else {				$sort = 'last_name '.$direction.', first_name, middle_name';			}			//      $sort = 'first_name '.$direction.', last_name';		}		$sql = "SELECT ab_contacts.* FROM ab_contacts "."WHERE ab_contacts.addressbook_id='$addressbook_id' "."AND ab_contacts.group_id='$group_id' "."ORDER BY $sort $direction";		$this->query($sql);		return $this->num_rows();	}	function get_contact_by_name($addressbook_id, $name) {		$sql = "SELECT * FROM ab_contacts WHERE addressbook_id='$addressbook_id' AND name='$name'";		$this->query($sql);		if ($this->next_record()) {			return $this->Record;		}		return false;	}	function get_contact($contact_id) {		$this->query("SELECT ab_addressbooks.acl_read, ab_addressbooks.acl_write, ab_contacts.*, "."ab_companies.address AS work_address, ab_companies.address_no AS "."work_address_no, ab_companies.zip AS work_zip, "."ab_companies.city AS work_city, ab_companies.state AS work_state, "."ab_companies.country AS work_country, ab_companies.homepage, "."ab_companies.bank_no, ab_companies.email AS company_email, "."ab_companies.phone AS company_phone, ab_companies.fax AS company_fax, "."ab_companies.name AS company_name, "."ab_companies.post_address AS work_post_address, ab_companies.post_address_no AS work_post_address_no, "."ab_companies.post_zip AS work_post_zip, ab_companies.post_city AS work_post_city, ab_companies.post_state AS work_post_state, "."ab_companies.post_country AS work_post_country, ab_custom_contact_fields.* "."FROM ab_contacts LEFT JOIN ab_companies ON (ab_contacts.company_id=ab_companies.id) "."INNER JOIN ab_addressbooks ON (ab_contacts.addressbook_id=ab_addressbooks.id) "."LEFT JOIN ab_custom_contact_fields ON ab_custom_contact_fields.id=ab_contacts.id "."WHERE ab_contacts.id='$contact_id'");		if ($this->next_record(MYSQL_ASSOC)) {			return $this->Record;		}		return false;	}		function get_empty_contact()	{		$sql = "SHOW FIELDS FROM ab_contacts";		$this->query($sql);		while($this->next_record())		{			$contact[$this->Field] = '';		}		return $contact;	}		function get_empty_company()	{		$sql = "SHOW FIELDS FROM ab_companies";		$this->query($sql);		while($this->next_record())		{			$company[$this->Field] = '';		}		return $company;	}	function add_contact($contact) {				if (!isset($contact['user_id']) || $contact['user_id'] == 0) {			global $GO_SECURITY;			$contact['user_id'] = $GO_SECURITY->user_id;		}					if (!isset($contact['ctime']) || $contact['ctime'] == 0) {			$contact['ctime'] = get_gmt_time();		}		if (!isset($contact['mtime']) || $contact['mtime'] == 0) {			$contact['mtime'] = $contact['ctime'];		}		if (isset($contact['sex']) && $contact['sex'] == '') {			$contact['sex'] = 'M';		}		$contact['id'] = $this->nextid("ab_contacts");				go_log(LOG_DEBUG, 'NEW CONTACT: '.$contact['id']);		if ($contact['id']  > 0) {						if ($this->insert_row('ab_contacts', $contact)) {				$this->query("INSERT INTO ab_custom_contact_fields (id) VALUES ('".$contact['id']."')");				return $contact['id'];			} else {				return false;			}		} else {			return false;		}	}	function update_contact($contact)	{		if (!isset($contact['mtime']) || $contact['mtime'] == 0) {			$contact['mtime'] = get_gmt_time();		}		if (isset($contact['sex']) && $contact['sex'] == '') {			$contact['sex'] = 'M';		}		return $this->update_row('ab_contacts', 'id', $contact);	}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?