📄 addressbook.class.inc
字号:
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'; } if(empty($contact['link_id'])) { $contact['link_id']=$GLOBALS['GO_LINKS']->get_link_id(); } $contact['id'] = $this->nextid("ab_contacts"); if ($contact['id'] > 0) { if ($this->insert_row('ab_contacts', $contact)) { 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); } function delete_contact($contact_id) { global $GO_CONFIG,$GO_LINKS; $contact=$this->get_contact($contact_id); $GO_LINKS->delete_link($contact['link_id']); require_once($GO_CONFIG->class_path.'filesystem.class.inc'); $fs = new filesystem(true); $fs->delete($GO_CONFIG->file_storage_path.'contacts/'.$contact_id.'/'); $sql1 = "DELETE FROM tp_mailing_contacts WHERE contact_id='$contact_id'"; if ($this->query($sql1)) { return $this->query("DELETE FROM ab_contacts WHERE id='$contact_id'"); } } function user_is_contact($user_id, $id) { $sql = "SELECT ab_contacts.* FROM ab_contacts "; $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; } $sql .= "ab_contacts.source_id='$id'"; $this->query($sql); if ($this->next_record()) { return $this->Record; } else { return false; } } function user_is_in_addressbook($user_id, $addressbook_id) { $sql = "SELECT id FROM ab_contacts WHERE source_id='$user_id' AND addressbook_id='$addressbook_id'"; $this->query($sql); return $this->next_record(); } function get_contact_by_email($email, $user_id) { $email = get_email_from_string($email); $sql = "SELECT ab_contacts.*, ab_addressbooks.acl_read, ab_addressbooks.acl_write FROM ab_contacts ". "INNER JOIN ab_addressbooks ON (ab_addressbooks.id=ab_contacts.addressbook_id) "; $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; } $sql .= " (ab_contacts.email='$email' OR ab_contacts.email2='$email' OR ab_contacts.email3='$email')"; $this->query($sql); if ($this->next_record()) return $this->Record; else return false; } function move_company_to_addressbook($company_id, $addressbook_id) { $sql = "UPDATE ab_companies SET mtime='".get_gmt_time()."', addressbook_id='$addressbook_id' WHERE id='$company_id'"; $this->query($sql); } function move_contact_to_addressbook($contact_id, $addressbook_id) { $sql = "UPDATE ab_contacts SET mtime='".get_gmt_time()."', addressbook_id='$addressbook_id' WHERE id='$contact_id'"; $this->query($sql); } function add_contact_to_company($contact_id, $company_id) { return $this->query("UPDATE ab_contacts SET company_id='$company_id' WHERE id='$contact_id'"); } function add_company($company) { if (!isset($company['user_id']) || $company['user_id'] == 0) { global $GO_SECURITY; $company['user_id'] = $GO_SECURITY->user_id; } if (!isset($company['ctime']) || $company['ctime'] == 0) { $company['ctime'] = get_gmt_time(); } if (!isset($company['mtime']) || $company['mtime'] == 0) { $company['mtime'] = $company['ctime']; } if(!isset($company['link_id'])) { global $GO_LINKS; $company['link_id']=$GO_LINKS->get_link_id(); } $company['id'] = $this->nextid("ab_companies"); if ($company['id'] > 0) { if ($this->insert_row('ab_companies', $company)) { return $company['id']; } else { return false; } } else { return false; } } function update_company($company) { if (!isset($company['mtime']) || $company['mtime'] == 0) { $company['mtime'] = get_gmt_time(); } return $this->update_row('ab_companies', 'id', $company); } function get_company_by_name($addressbook_id, $name) { $sql = "SELECT * FROM ab_companies WHERE addressbook_id='$addressbook_id' AND name='$name'"; $this->query($sql); if ($this->next_record()) { return $this->Record; } return false; } function get_company($company_id) { $sql = "SELECT ab_companies.*, ab_addressbooks.acl_read, ". "ab_addressbooks.acl_write FROM ab_companies ". "INNER JOIN ab_addressbooks ON ". "(ab_addressbooks.id=ab_companies.addressbook_id) ". "WHERE ab_companies.id='$company_id'"; $this->query($sql); if ($this->next_record()) { return $this->Record; } return false; } function get_companies($addressbook_id=0, $sort = 'name', $direction = 'ASC', $start = 0, $offset = 0, $links=false) { global $GO_SECURITY; $sql = "SELECT ab_companies.* FROM ab_companies"; if($addressbook_id > 0) { $sql .= " WHERE 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 search_company($name, $addressbook_id) { $sql = "SELECT * FROM ab_companies WHERE addressbook_id='$addressbook_id' AND name LIKE '%$name%'"; $this->query($sql); return $this->num_rows(); } function get_company_id_by_name($name, $addressbook_id) { $sql = "SELECT id FROM ab_companies WHERE addressbook_id='$addressbook_id' AND name='$name'"; $this->query($sql); if ($this->next_record()) { return $this->f('id'); } return false; } function delete_company($company_id) { global $GO_CONFIG, $GO_LINKS; $company=$this->get_contact($company_id); $GO_LINKS->delete_link($company['link_id']); require_once($GO_CONFIG->class_path.'filesystem.class.inc'); $fs = new filesystem(true); $fs->delete($GO_CONFIG->file_storage_path.'companies/'.$company_id.'/'); $sql = "DELETE FROM ab_companies WHERE id='$company_id'"; if ($this->query($sql)) { return true; } } function consistencycheck($fixit = false) { global $GO_USERS, $GO_SECURITY; echo "<h2>checking ab_addressbooks</h2>"; $sql = "SELECT * FROM ab_addressbooks"; $this->query($sql); while ($this->next_record()) { if (!($GO_USERS->get_user($this->f('user_id')))) { echo "owner of ".$this->f('id')." does not exist (".$this->f('user_id').")<br>"; } if (!($GO_SECURITY->acl_exists($this->f('acl_read')))) { echo "aclid(read) ".$this->f('acl_read')." of ".$this->f('id')." does not exist<br>"; } if (!($GO_SECURITY->acl_exists($this->f('acl_write')))) { echo "aclid(write) ".$this->f('acl_write')." of ".$this->f('id')." does not exist<br>"; } } echo "<h2>checking ab_companies</h2>"; $sql = "SELECT * FROM ab_companies"; $this->query($sql); while ($this->next_record()) { if (!($GO_USERS->get_user($this->f('user_id')))) { echo "owner of ".$this->f('id')."does not exist (".$this->f('user_id').")<br>"; } } echo "<h2>checking ab_contacts</h2>"; $sql = "SELECT * FROM ab_contacts"; $this->query($sql); while ($this->next_record()) { if (!($GO_USERS->get_user($this->f('user_id')))) { echo "owner of ".$this->f('id')."does not exist (".$this->f('user_id').")<br>"; } } echo "<h2>checking ab_settings</h2>"; $sql = "SELECT * FROM ab_settings"; $this->query($sql); while ($this->next_record()) { if (!($GO_USERS->get_user($this->f('user_id')))) { echo "owner of ".$this->f('id')."does not exist (".$this->f('user_id').")<br>"; } } } function __on_search($user_id,$last_sync_time=0) { global $GO_MODULES, $GO_LANGUAGE; require($GO_LANGUAGE->get_language_file('addressbook')); $sql = "SELECT * FROM ab_contacts "; $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; } $sql .= "mtime>$last_sync_time"; $this->query($sql); $search = new search(); $db = new db(); while($this->next_record()) { $cache['table']='ab_contacts'; $cache['id']=$this->f('id'); $cache['user_id']=$user_id; $cache['name'] = addslashes(format_name($this->f('last_name'),$this->f('first_name'),$this->f('middle_name'))); $cache['link_id'] = $this->f('link_id'); $cache['link_type']=2; $cache['description']=''; $cache['url']=$GO_MODULES->modules['addressbook']['url'].'contact.php?contact_id='.$this->f('id'); $cache['type']=$ab_contact; $cache['keywords']=addslashes(record_to_keywords($this->Record)).','.$ab_contact; $cache['mtime']=$this->f('mtime'); if($search->get_search_result($user_id, $this->f('link_id'))) { $db->update_row('se_cache',array('user_id','link_id'), $cache); }else { $db->insert_row('se_cache',$cache); } } $sql = "SELECT * FROM ab_companies "; 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; } $sql .= "mtime>$last_sync_time"; $this->query($sql); $db = new db(); while($this->next_record()) { $cache['table']='ab_companies'; $cache['id']=$this->f('id'); $cache['user_id']=$user_id; $cache['name'] = addslashes($this->f('name')); $cache['link_id'] = $this->f('link_id'); $cache['link_type']=3; $cache['description']=''; $cache['url']=$GO_MODULES->modules['addressbook']['url'].'company.php?company_id='.$this->f('id'); $cache['type']=$ab_company; $cache['keywords']=addslashes(record_to_keywords($this->Record)).','.$cache['type']; $cache['mtime']=$this->f('mtime'); if($search->get_search_result($user_id, $this->f('link_id'))) { $db->update_row('se_cache',array('user_id','link_id'), $cache); }else { $db->insert_row('se_cache',$cache); } } } function __on_user_delete($user_id) { $sql = "UPDATE ab_contacts SET source_id='0' WHERE source_id='$user_id'"; $this->query($sql); $ab = new addressbook(); $sql = "SELECT id FROM ab_addressbooks WHERE user_id='$user_id'"; $this->query($sql); while ($this->next_record()) { $ab->delete_addressbook($this->f('id')); } $this->query("DELETE FROM ab_settings WHERE user_id='$user_id'"); global $GO_MODULES; if($plugin = $GO_MODULES->get_plugin('templates','addressbook')) { require_once($plugin['class_path'].'templates.class.inc'); $tp = new templates(); $tp->delete_user($user_id); } } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -