📄 addressbook.class.inc
字号:
if ($company['email'] != '') { $sql .= " OR email='".$company['email']."' "; } if ($company['zip'] != '' && $company['address_no'] != '') { $sql .= " OR (zip='".$company['zip']."' AND address_no='".$company['address_no']."')"; } $sql .= ");"; $this->query($sql); if ($this->next_record()) { return $this->f('id'); } return false; } function search_email($user_id, $query) { $query = str_replace(' ','%', $query); $sql = "SELECT DISTINCT ab_contacts.first_name, ab_contacts.middle_name, ab_contacts.last_name, ab_contacts.email, ab_contacts.email2, ab_contacts.email3 FROM ab_contacts WHERE "; $user_ab = $this->get_user_addressbook_ids($user_id); if(count($user_ab) > 1) { $sql .= "ab_contacts.addressbook_id IN (".implode(",",$user_ab).") AND "; }elseif(count($user_ab)==1) { $sql .= "ab_contacts.addressbook_id=".$user_ab[0]." AND "; }else { return false; } $sql .= "(CONCAT(first_name,middle_name,last_name) LIKE '".$query."' OR email LIKE '$query' OR email2 LIKE '$query' OR email3 LIKE '$query')"; if ($_SESSION['GO_SESSION']['sort_name'] == 'first_name') { $sort_index = 'ab_contacts.first_name ASC, ab_contacts.last_name'; } else { $sort_index = 'ab_contacts.last_name ASC, ab_contacts.first_name'; } $sql .= " ORDER BY $sort_index ASC LIMIT 0,10"; $this->query($sql); } function search_contacts($user_id, $query, $field = 'last_name', $addressbook_id = 0, $mtime = 0, $start=0, $offset=0, $require_email=false, $sort_index='name', $sort_order='ASC', $writable_only=false) { global $GO_MODULES; $query = str_replace('*', '%', $query); if($sort_index=='name') { if ($_SESSION['GO_SESSION']['sort_name'] == 'first_name') { $sort_index = 'ab_contacts.first_name ASC, ab_contacts.last_name'; } else { $sort_index = 'ab_contacts.last_name ASC, ab_contacts.first_name'; } } $sql = "SELECT ab_contacts.*, ab_companies.name AS company_name FROM ab_contacts ". "LEFT JOIN ab_companies ON ab_contacts.company_id=ab_companies.id "; if(isset($GO_MODULES->modules['custom_fields']) && $GO_MODULES->modules['custom_fields']['read_permission']) { $sql .= "LEFT JOIN cf_2 ON cf_2.link_id=ab_contacts.link_id "; } if ($addressbook_id > 0) { $sql .= "WHERE ab_contacts.addressbook_id='$addressbook_id' AND "; } else { if($writable_only) { $user_ab = $this->get_writable_addressbook_ids($user_id); }else { $user_ab = $this->get_user_addressbook_ids($user_id); } if(count($user_ab) > 1) { $sql .= "WHERE ab_contacts.addressbook_id IN (".implode(",",$user_ab).") AND "; }elseif(count($user_ab)==1) { $sql .= "WHERE ab_contacts.addressbook_id=".$user_ab[0]." AND "; }else { return false; } } if($query!='') { if(!is_array($field)) { $fields=array(); if($field == '') { $fields_sql = "SHOW FIELDS FROM ab_contacts"; $this->query($fields_sql); while($this->next_record()) { if(eregi('varchar', $this->f('Type'))) { $fields[]='ab_contacts.'.$this->f('Field'); } } if(isset($GO_MODULES->modules['custom_fields']) && $GO_MODULES->modules['custom_fields']['read_permission']) { $fields_sql = "SHOW FIELDS FROM cf_2"; $this->query($fields_sql); while ($this->next_record()) { $fields[]='cf_2.'.$this->f('Field'); } } }else { $fields[]=$field; } }else { $fields=$field; } foreach($fields as $field) { if(count($fields)>1) { if(isset($first)) { $sql .= ' OR '; }else { $first = true; $sql .= '('; } } if($field=='name') { $sql .= "CONCAT(first_name,middle_name,last_name) LIKE '".str_replace(' ','%', $query)."' "; }else { $sql .= "$field LIKE '$query' "; } } if(count($fields)>1) { $sql .= ')'; } } if($require_email) { $sql .= " AND ab_contacts.email != ''"; } $sql .= " ORDER BY $sort_index $sort_order"; $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, $sort_index='name', $sort_order='ASC') { global $GO_MODULES; $query = str_replace('*', '%', $query); if(isset($GO_MODULES->modules['custom_fields'])) { $sql = "SELECT ab_companies.*, cf_3.* FROM ab_companies ". "LEFT JOIN cf_3 ON cf_3.link_id=ab_companies.link_id "; }else { $sql = "SELECT ab_companies.* FROM ab_companies "; } if ($addressbook_id > 0) { $sql .= "WHERE ab_companies.addressbook_id='$addressbook_id' AND "; } else { $user_ab = $this->get_user_addressbook_ids($user_id); if(count($user_ab) > 1) { $sql .= "WHERE ab_companies.addressbook_id IN (".implode(",",$user_ab).") AND "; }elseif(count($user_ab)==1) { $sql .= "WHERE ab_companies.addressbook_id=".$user_ab[0]." 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'"; } } if(isset($GO_MODULES->modules['custom_fields']) && $GO_MODULES->modules['custom_fields']['read_permission']) { $fields_sql = "SHOW FIELDS FROM cf_3"; $this->query($fields_sql); while ($this->next_record()) { if (eregi('varchar', $this->f('Type')) || $this->f('Field')=='id') { if (isset ($first)) { $sql .= ' OR '; } else { $first = true; $sql .= '('; } $sql .= "cf_3.".$this->f('Field')." LIKE '$query'"; } } } $sql .= ')'; } else { $sql .= "$field LIKE '$query' "; } if($require_email) { $sql .= " AND ab_companies.email != ''"; } $sql .= "ORDER BY $sort_index $sort_order"; $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_companies.name AS company FROM ab_contacts ". "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 ". "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) ". "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; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -