addressbook.class.inc
来自「groupoffice」· INC 代码 · 共 1,110 行 · 第 1/3 页
INC
1,110 行
function delete_contact($contact_id) { global $GO_CONFIG; 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'"; $sql2 = "DELETE FROM ab_custom_contact_fields WHERE id='$contact_id'"; if ($this->query($sql1) && $this->query($sql2)) { 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 get_groups($addressbook_id) { $sql = "SELECT * FROM ab_groups WHERE addressbook_id='$addressbook_id'"; $this->query($sql); return $this->num_rows(); } function add_group($addressbook_id, $name) { $name = htmlspecialchars($name); $group_id = $this->nextid("ab_groups"); if ($group_id > 0) { $sql = "INSERT INTO ab_groups (id, addressbook_id, name) VALUES "."('$group_id', '$addressbook_id', '$name')"; $this->query($sql); return $group_id; } else { return false; } } function delete_group($group_id) { $sql = "UPDATE ab_contacts SET group_id='0' WHERE group_id='$group_id'"; if ($this->query($sql)) { $sql = "DELETE FROM ab_groups WHERE id='$group_id'"; $this->query($sql); return true; } 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 move_contact_to_group($contact_id, $group_id) { $sql = "UPDATE ab_contacts SET group_id='$group_id' WHERE id='$contact_id'"; $this->query($sql); } function clear_group($group_id) { $sql = "UPDATE ab_contacts SET group_id='0' WHERE group_id='$group_id'"; $this->query($sql); } function change_group_name($group_id, $name) { $sql = "UPDATE ab_groups SET name='$name' WHERE id='$group_id'"; $this->query($sql); } function get_group($group_id) { $sql = "SELECT * FROM ab_groups WHERE id='$group_id'"; $this->query($sql); if ($this->next_record()) { return $this->Record; } return false; } function get_group_by_name($addressbook_id, $name) { $sql = "SELECT * FROM ab_groups WHERE addressbook_id='$addressbook_id' AND name='$name'"; $this->query($sql); if ($this->next_record()) { return $this->Record; } return false; } 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']; } $company['id'] = $this->nextid("ab_companies"); if ($company['id'] > 0) { if ($this->insert_row('ab_companies', $company)) { $this->query("INSERT INTO ab_custom_company_fields(id) VALUES ('".$company['id']."')"); 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, ab_custom_company_fields.* FROM ab_companies "."INNER JOIN ab_addressbooks ON "."(ab_addressbooks.id=ab_companies.addressbook_id) "."LEFT JOIN ab_custom_company_fields ON ab_custom_company_fields.id=ab_companies.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; 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 $this->query("DELETE FROM ab_custom_company_fields WHERE id='$company_id'"); } } function delete_user($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); } } 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_custom_company_fields_cats</h2>"; $sql = "SELECT * FROM ab_custom_company_fields_cats"; $this->query($sql); while ($this->next_record()) { if (!($GO_SECURITY->acl_exists($this->f('acl_id')))) { echo "aclid ".$this->f('acl_id')." of ".$this->f('id')." does not exist<br>"; } } echo "<h2>checking ab_custom_contact_fields_cats</h2>"; $sql = "SELECT * FROM ab_custom_contact_fields_cats"; $this->query($sql); while ($this->next_record()) { if (!($GO_SECURITY->acl_exists($this->f('acl_id')))) { echo "aclid ".$this->f('acl_id')." of ".$this->f('id')." does not exist<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>"; } } }}?>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?