mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-11-07 16:44:20 +01:00
moving the files to where they belong
This commit is contained in:
parent
d25b5bd3a7
commit
a31ba57a86
4
addressbook/inc/class.contacts.inc.php
Normal file
4
addressbook/inc/class.contacts.inc.php
Normal file
@ -0,0 +1,4 @@
|
||||
<?php
|
||||
include($phpgw_info["server"]["include_root"]."/addressbook/inc/class.contacts_".$phpgw_info["server"]["contacts_repository"].".inc.php");
|
||||
include($phpgw_info["server"]["include_root"]."/addressbook/inc/class.contacts_shared.inc.php");
|
||||
?>
|
284
addressbook/inc/class.contacts_ldap.inc.php
Normal file
284
addressbook/inc/class.contacts_ldap.inc.php
Normal file
@ -0,0 +1,284 @@
|
||||
<?php
|
||||
/**************************************************************************\
|
||||
* phpGroupWare API - Accounts manager for SQL *
|
||||
* This file written by Joseph Engo <jengo@phpgroupware.org> *
|
||||
* View and manipulate contact records using SQL *
|
||||
* Copyright (C) 2001 Joseph Engo *
|
||||
* -------------------------------------------------------------------------*
|
||||
* This library is part of the phpGroupWare API *
|
||||
* http://www.phpgroupware.org/api *
|
||||
* ------------------------------------------------------------------------ *
|
||||
* This library is free software; you can redistribute it and/or modify it *
|
||||
* under the terms of the GNU Lesser General Public License as published by *
|
||||
* the Free Software Foundation; either version 2.1 of the License, *
|
||||
* or any later version. *
|
||||
* This library is distributed in the hope that it will be useful, but *
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
|
||||
* See the GNU Lesser General Public License for more details. *
|
||||
* You should have received a copy of the GNU Lesser General Public License *
|
||||
* along with this library; if not, write to the Free Software Foundation, *
|
||||
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
|
||||
\**************************************************************************/
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
phpgw_contacts (
|
||||
contact_id int,
|
||||
contact_owner int,
|
||||
contact_name varchar(255),
|
||||
contact_value varchar(255)
|
||||
);
|
||||
*/
|
||||
|
||||
/* ldap is a copy of sql for now */
|
||||
|
||||
class contacts_
|
||||
{
|
||||
var $db;
|
||||
var $account_id;
|
||||
var $stock_addressbook_fields; // This is an array of all the fields in the addressbook
|
||||
var $total_records; // This will contain numrows for data retrieved
|
||||
|
||||
function contacts_()
|
||||
{
|
||||
global $phpgw, $phpgw_info;
|
||||
|
||||
$this->db = $phpgw->db;
|
||||
|
||||
$this->account_id = $phpgw_info["user"]["account_id"];
|
||||
$this->stock_addressbook_fields = array("firstname" => "firstname",
|
||||
"lastname" => "lastname",
|
||||
"email" => "email",
|
||||
"hphone" => "hphone",
|
||||
"wphone" => "wphone",
|
||||
"fax" => "fax",
|
||||
"pager" => "pager",
|
||||
"mphone" => "mphone",
|
||||
"ophone" => "ophone",
|
||||
"street" => "street",
|
||||
"city" => "city",
|
||||
"state" => "state",
|
||||
"zip" => "zip",
|
||||
"bday" => "bday",
|
||||
"notes" => "notes",
|
||||
"company" => "company",
|
||||
"title" => "title",
|
||||
"address2" => "address2",
|
||||
"url" => "url"
|
||||
);
|
||||
}
|
||||
|
||||
function read_single_entry($id,$fields)
|
||||
{
|
||||
list($ab_fields,$ab_fieldnames,$extra_fields) = $this->split_ab_and_extras($fields);
|
||||
if (count($ab_fieldnames)) {
|
||||
$t_fields = ",ab_" . implode(",ab_",$ab_fieldnames);
|
||||
if ($t_fields == ",ab_") {
|
||||
unset($t_fields);
|
||||
}
|
||||
}
|
||||
|
||||
$this->db2 = $this->db;
|
||||
|
||||
$this->db->query("select ab_id,ab_owner,ab_access $t_fields from addressbook WHERE ab_id='$id'");
|
||||
$this->db->next_record();
|
||||
|
||||
$return_fields[0]["id"] = $this->db->f("ab_id");
|
||||
$return_fields[0]["owner"] = $this->db->f("ab_owner");
|
||||
$return_fields[0]["access"] = $this->db->f("ab_access");
|
||||
if (gettype($ab_fieldnames) == "array") {
|
||||
while (list($f_name) = each($ab_fieldnames)) {
|
||||
$return_fields[0][$f_name] = $this->db->f("ab_" . $f_name);
|
||||
}
|
||||
}
|
||||
$this->db2->query("select contact_name,contact_value from phpgw_contacts where contact_id='"
|
||||
. $this->db->f("ab_id") . "'",__LINE__,__FILE__);
|
||||
while ($this->db2->next_record()) {
|
||||
// If its not in the list to be returned, don't return it.
|
||||
// This is still quicker then 5(+) separate queries
|
||||
if ($extra_fields[$this->db2->f("contact_name")]) {
|
||||
$return_fields[0][$this->db2->f("contact_name")] = $this->db2->f("contact_value");
|
||||
}
|
||||
}
|
||||
|
||||
return $return_fields;
|
||||
}
|
||||
|
||||
function read($start,$offset,$access,$fields,$query="",$filter="",$sort="",$order="")
|
||||
{
|
||||
global $phpgw,$phpgw_info;
|
||||
|
||||
if (!$sort) { $sort = "ASC"; }
|
||||
if (!$filter) { $filter = "none"; }
|
||||
|
||||
if ($filter != "private") {
|
||||
if ($filter != "none") {
|
||||
$filtermethod = "WHERE ab_access like '%,$filter,%' ";
|
||||
} else {
|
||||
$filtermethod = "WHERE (ab_owner='" . $phpgw_info["user"]["account_id"] ."' OR ab_access='public' "
|
||||
. $phpgw->accounts->sql_search("ab_access") . " ) ";
|
||||
}
|
||||
} else {
|
||||
$filtermethod = "WHERE ab_owner='" . $phpgw_info["user"]["account_id"] . "' ";
|
||||
}
|
||||
|
||||
if ($order) {
|
||||
$ordermethod = "order by $order $sort ";
|
||||
} else {
|
||||
$ordermethod = "order by ab_lastname,ab_firstname,ab_email $sort";
|
||||
}
|
||||
|
||||
list($ab_fields,$ab_fieldnames,$extra_fields) = $this->split_ab_and_extras($fields);
|
||||
if (count($ab_fieldnames)) {
|
||||
$t_fields = ",ab_" . implode(",ab_",$ab_fieldnames);
|
||||
if ($t_fields == ",ab_") {
|
||||
unset($t_fields);
|
||||
}
|
||||
}
|
||||
|
||||
$this->db3 = $this->db2 = $this->db; // Create new result objects before our queries
|
||||
|
||||
if ($query) {
|
||||
$this->db3->query("SELECT * from addressbook $filtermethod AND (ab_lastname like '"
|
||||
. "%$query%' OR ab_firstname like '%$query%' OR ab_email like '%$query%' OR "
|
||||
. "ab_street like '%$query%' OR ab_city like '%$query%' OR ab_state "
|
||||
. "like '%$query%' OR ab_zip like '%$query%' OR ab_notes like "
|
||||
. "'%$query%' OR ab_company like '%$query%') " . $ordermethod,__LINE__,__FILE__);
|
||||
$this->total_records = $this->db3->num_rows();
|
||||
|
||||
$this->db->query("SELECT * from addressbook $filtermethod AND (ab_lastname like '"
|
||||
. "%$query%' OR ab_firstname like '%$query%' OR ab_email like '%$query%' OR "
|
||||
. "ab_street like '%$query%' OR ab_city like '%$query%' OR ab_state "
|
||||
. "like '%$query%' OR ab_zip like '%$query%' OR ab_notes like "
|
||||
. "'%$query%' OR ab_company like '%$query%') " . $ordermethod . " "
|
||||
. $this->db->limit($start,$offset),__LINE__,__FILE__);
|
||||
} else {
|
||||
$this->db3->query("select ab_id,ab_owner,ab_access $t_fields from addressbook "
|
||||
. $filtermethod,__LINE__,__FILE__);
|
||||
$this->total_records = $this->db3->num_rows();
|
||||
|
||||
$this->db->query("select ab_id,ab_owner,ab_access $t_fields from addressbook "
|
||||
. $filtermethod . " " . $ordermethod . " " . $this->db->limit($start,$offset),__LINE__,__FILE__);
|
||||
}
|
||||
|
||||
$i=0;
|
||||
while ($this->db->next_record()) {
|
||||
$return_fields[$i]["id"] = $this->db->f("ab_id");
|
||||
$return_fields[$i]["owner"] = $this->db->f("ab_owner");
|
||||
$return_fields[$i]["access"] = $this->db->f("ab_access");
|
||||
if (gettype($ab_fieldnames) == "array") {
|
||||
while (list($f_name) = each($ab_fieldnames)) {
|
||||
$return_fields[$i][$f_name] = $this->db->f("ab_" . $f_name);
|
||||
}
|
||||
reset($ab_fieldnames);
|
||||
}
|
||||
|
||||
$this->db2->query("select contact_name,contact_value from phpgw_contacts where contact_id='"
|
||||
. $this->db->f("ab_id") . "'",__LINE__,__FILE__);
|
||||
while ($this->db2->next_record()) {
|
||||
// If its not in the list to be returned, don't return it.
|
||||
// This is still quicker then 5(+) separate queries
|
||||
if ($extra_fields[$this->db2->f("contact_name")]) {
|
||||
$return_fields[$i][$this->db2->f("contact_name")] = $this->db2->f("contact_value");
|
||||
}
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
|
||||
return $return_fields;
|
||||
}
|
||||
|
||||
function add($owner,$access,$fields)
|
||||
{
|
||||
list($ab_fields,$ab_fieldnames,$extra_fields) = $this->split_ab_and_extras($fields);
|
||||
|
||||
//$this->db->lock(array("phpgw_addressbook"));
|
||||
$this->db->query("insert into addressbook (ab_owner,ab_access,ab_"
|
||||
. implode(",ab_",$this->stock_addressbook_fields)
|
||||
. ") values ('$owner','$access','"
|
||||
. implode("','",$this->loop_addslashes($ab_fields)) . "')",__LINE__,__FILE__);
|
||||
|
||||
$this->db->query("select max(ab_id) from addressbook",__LINE__,__FILE__);
|
||||
$this->db->next_record();
|
||||
$ab_id = $this->db->f(0);
|
||||
//$this->db->unlock();
|
||||
|
||||
if (count($extra_fields)) {
|
||||
while (list($name,$value) = each($extra_fields)) {
|
||||
$this->db->query("insert into phpgw_contacts values ('$ab_id','" . $this->account_id . "','"
|
||||
. addslashes($name) . "','" . addslashes($value) . "')",__LINE__,__FILE__);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function field_exists($id,$field_name)
|
||||
{
|
||||
$this->db->query("select count(*) from phpgw_contacts where contact_id='$id' and contact_name='"
|
||||
. addslashes($field_name) . "'",__LINE__,__FILE__);
|
||||
$this->db->next_record();
|
||||
return $this->db->f(0);
|
||||
}
|
||||
|
||||
function add_single_extra_field($id,$owner,$field_name,$field_value)
|
||||
{
|
||||
$this->db->query("insert into phpgw_contacts values ($id,'$owner','" . addslashes($field_name)
|
||||
. "','" . addslashes($field_value) . "')",__LINE__,__FILE__);
|
||||
}
|
||||
|
||||
function delete_single_extra_field($id,$field_name)
|
||||
{
|
||||
$this->db->query("delete from phpgw_contacts where contact_id='$id' and contact_name='"
|
||||
. addslashes($field_name) . "'",__LINE__,__FILE__);
|
||||
}
|
||||
|
||||
function update($id,$owner,$access,$fields)
|
||||
{
|
||||
// First make sure that id number exists
|
||||
$this->db->query("select count(*) from addressbook where ab_id='$id'",__LINE__,__FILE__);
|
||||
$this->db->next_record();
|
||||
if (! $this->db->f(0)) {
|
||||
return False;
|
||||
}
|
||||
|
||||
list($ab_fields,$ab_fieldnames,$extra_fields) = $this->split_ab_and_extras($fields);
|
||||
if (count($ab_fields)) {
|
||||
while (list($ab_fieldname) = each($ab_fieldnames)) {
|
||||
$ta[] = $ab_fieldname . "='" . addslashes($ab_fields[$ab_fieldname]) . "'";
|
||||
}
|
||||
$fields_s = ",ab_" . implode(",ab_",$ta);
|
||||
if ($field_s == ",") {
|
||||
unset($field_s);
|
||||
}
|
||||
$this->db->query("update addressbook set ab_owner='$owner',ab_access='$access' $fields_s where "
|
||||
. "ab_id='$id'",__LINE__,__FILE__);
|
||||
}
|
||||
|
||||
while (list($x_name,$x_value) = each($extra_fields)) {
|
||||
if ($this->field_exists($id,$x_name)) {
|
||||
if (! $x_value) {
|
||||
$this->delete_single_extra_field($id,$x_name);
|
||||
} else {
|
||||
$this->db->query("update phpgw_contacts set contact_value='" . addslashes($x_value)
|
||||
. "',contact_owner='$owner' where contact_name='" . addslashes($x_name)
|
||||
. "' and contact_id='$id'",__LINE__,__FILE__);
|
||||
}
|
||||
} else {
|
||||
$this->add_single_extra_field($id,$owner,$x_name,$x_value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// This is where the real work of delete() is done
|
||||
function delete_($id)
|
||||
{
|
||||
$this->db->query("delete from addressbook where ab_owner='" . $this->account_id . "' and "
|
||||
. "ab_id='$id'",__LINE__,__FILE__);
|
||||
$this->db->query("delete from phpgw_contacts where contact_id='$id' and contact_owner='"
|
||||
. $this->account_id . "'",__LINE__,__FILE__);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
84
addressbook/inc/class.contacts_shared.inc.php
Normal file
84
addressbook/inc/class.contacts_shared.inc.php
Normal file
@ -0,0 +1,84 @@
|
||||
<?php
|
||||
/**************************************************************************\
|
||||
* phpGroupWare API - Accounts manager for SQL *
|
||||
* This file written by Joseph Engo <jengo@phpgroupware.org> *
|
||||
* View and manipulate contact records *
|
||||
* Copyright (C) 2001 Joseph Engo *
|
||||
* -------------------------------------------------------------------------*
|
||||
* This library is part of the phpGroupWare API *
|
||||
* http://www.phpgroupware.org/api *
|
||||
* ------------------------------------------------------------------------ *
|
||||
* This library is free software; you can redistribute it and/or modify it *
|
||||
* under the terms of the GNU Lesser General Public License as published by *
|
||||
* the Free Software Foundation; either version 2.1 of the License, *
|
||||
* or any later version. *
|
||||
* This library is distributed in the hope that it will be useful, but *
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
|
||||
* See the GNU Lesser General Public License for more details. *
|
||||
* You should have received a copy of the GNU Lesser General Public License *
|
||||
* along with this library; if not, write to the Free Software Foundation, *
|
||||
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
|
||||
\**************************************************************************/
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
|
||||
/*
|
||||
phpgw_contacts (
|
||||
contact_id int,
|
||||
contact_owner int,
|
||||
contact_name varchar(255),
|
||||
contact_value varchar(255)
|
||||
);
|
||||
*/
|
||||
|
||||
class contacts extends contacts_
|
||||
{
|
||||
var $db;
|
||||
var $account_id;
|
||||
var $stock_contact_fields; // This is an array of all the fields in the addressbook
|
||||
var $total_records;
|
||||
|
||||
function split_ab_and_extras($fields)
|
||||
{
|
||||
while (list($field,$value) = each($fields)) {
|
||||
// Depending on how the array was build, this is needed.
|
||||
// Yet, I can't figure out why ....
|
||||
if (gettype($field) == "integer") {
|
||||
$field = $value;
|
||||
}
|
||||
if ($this->stock_contact_fields[$field]) {
|
||||
$ab_fields[$field] = $value;
|
||||
$ab_fieldnames[$field] = $field;
|
||||
} else {
|
||||
$extra_fields[$field] = $value;
|
||||
}
|
||||
}
|
||||
return array($ab_fields,$ab_fieldnames,$extra_fields);
|
||||
}
|
||||
|
||||
function loop_addslashes($fields)
|
||||
{
|
||||
$absf = $this->stock_contact_fields;
|
||||
while ($t = each($absf)) {
|
||||
$ta[] = addslashes($fields[$t[0]]);
|
||||
}
|
||||
reset($absf); // Is this needed ?
|
||||
return $ta;
|
||||
}
|
||||
|
||||
// This will take an array or integer
|
||||
function delete($id)
|
||||
{
|
||||
if (gettype($id) == "array") {
|
||||
while (list($null,$t_id) = each($id)) {
|
||||
$this->delete_($t_id);
|
||||
}
|
||||
} else {
|
||||
$this->delete_($id);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
301
addressbook/inc/class.contacts_sql.inc.php
Normal file
301
addressbook/inc/class.contacts_sql.inc.php
Normal file
@ -0,0 +1,301 @@
|
||||
<?php
|
||||
/**************************************************************************\
|
||||
* phpGroupWare API - Accounts manager for SQL *
|
||||
* This file written by Joseph Engo <jengo@phpgroupware.org> *
|
||||
* View and manipulate contact records using SQL *
|
||||
* Copyright (C) 2001 Joseph Engo *
|
||||
* -------------------------------------------------------------------------*
|
||||
* This library is part of the phpGroupWare API *
|
||||
* http://www.phpgroupware.org/api *
|
||||
* ------------------------------------------------------------------------ *
|
||||
* This library is free software; you can redistribute it and/or modify it *
|
||||
* under the terms of the GNU Lesser General Public License as published by *
|
||||
* the Free Software Foundation; either version 2.1 of the License, *
|
||||
* or any later version. *
|
||||
* This library is distributed in the hope that it will be useful, but *
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
|
||||
* See the GNU Lesser General Public License for more details. *
|
||||
* You should have received a copy of the GNU Lesser General Public License *
|
||||
* along with this library; if not, write to the Free Software Foundation, *
|
||||
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
|
||||
\**************************************************************************/
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
contacts_extra (
|
||||
contact_id int,
|
||||
contact_owner int,
|
||||
contact_name varchar(255),
|
||||
contact_value varchar(255)
|
||||
);
|
||||
*/
|
||||
|
||||
/* ldap is a copy of sql for now */
|
||||
|
||||
class contacts_
|
||||
{
|
||||
var $db;
|
||||
var $account_id;
|
||||
var $stock_contact_fields; // This is an array of all the fields in the contacts table
|
||||
var $total_records; // This will contain numrows for data retrieved
|
||||
|
||||
function contacts_()
|
||||
{
|
||||
global $phpgw, $phpgw_info;
|
||||
|
||||
$this->db = $phpgw->db;
|
||||
|
||||
$this->account_id = $phpgw_info["user"]["account_id"];
|
||||
// rework the following to be a simple sed style creation
|
||||
$this->stock_contact_fields = array("FN" => "FN", //'firstname lastname'
|
||||
"SOUND" => "SOUND",
|
||||
"ORG.Name" => "ORG.Name", //company
|
||||
"ORG_Unit" => "ORG.Unit", //division
|
||||
"TITLE" => "TITLE",
|
||||
"N_Given" => "N.Given", //firstname
|
||||
"N_Family" => "N.Family", //lastname
|
||||
"N_Middle" => "N.Middle",
|
||||
"N_Prefix" => "N.Prefix",
|
||||
"N_Suffix" => "N.Suffix",
|
||||
"LABEL" => "LABEL",
|
||||
"ADR_Street" => "ADR.Street",
|
||||
"ADR_Locality" => "ADR.Locality", //city
|
||||
"ADR_Region" => "ADR.Region", //state
|
||||
"ADR_PostalCode" => "ADR.PostalCode", //zip
|
||||
"ADR_CountryName" => "ADR.CountryName",
|
||||
"ADR_Work" => "ADR.Work", //yn
|
||||
"ADR_Home" => "ADR.Home", //yn
|
||||
"ADR_Parcel" => "ADR.Parcel", //yn
|
||||
"ADR_Postal" => "ADR.Postal", //yn
|
||||
"TZ" => "TZ",
|
||||
"GEO" => "GEO",
|
||||
"A_TEL" => "A.TEL",
|
||||
"A_TEL_Work" => "A.TEL.Work", //yn
|
||||
"A_TEL_Home" => "A.TEL.Home", //yn
|
||||
"A_TEL_Voice" => "A.TEL.Voice", //yn
|
||||
"A_TEL_Msg" => "A.TEL.Msg", //yn
|
||||
"A_TEL_Fax" => "A.TEL.Fax", //yn
|
||||
"A_TEL_Prefer" => "A.TEL.Prefer", //yn
|
||||
"B_TEL" => "B.TEL",
|
||||
"B_TEL_Work" => "B.TEL.Work", //yn
|
||||
"B_TEL_Home" => "B.TEL.Home", //yn
|
||||
"B_TEL_Voice" => "B.TEL.Voice", //yn
|
||||
"B_TEL_Msg" => "B.TEL.Msg", //yn
|
||||
"B_TEL_Fax" => "B.TEL.Fax", //yn
|
||||
"B_TEL_Prefer" => "B.TEL.Prefer", //yn
|
||||
"C_TEL" => "C.TEL",
|
||||
"C_TEL_Work" => "C.TEL.Work", //yn
|
||||
"C_TEL_Home" => "C.TEL.Home", //yn
|
||||
"C_TEL_Voice" => "C.TEL.Voice", //yn
|
||||
"C_TEL_Msg" => "C.TEL.Msg", //yn
|
||||
"C_TEL_Fax" => "C.TEL.Fax", //yn
|
||||
"C_TEL_Prefer" => "C.TEL.Prefer", //yn
|
||||
"D_EMAIL" => "D.EMAIL",
|
||||
"D_EMAILTYPE" => "D.EMAILTYPE", //'INTERNET','CompuServe',etc...
|
||||
"D_EMAIL_Work" => "D.EMAIL.Work", //yn
|
||||
"D_EMAIL_Home" => "D.EMAIL.Home", //yn
|
||||
);
|
||||
}
|
||||
|
||||
function read_single_entry($id,$fields)
|
||||
{
|
||||
list($ab_fields,$ab_fieldnames,$extra_fields) = $this->split_ab_and_extras($fields);
|
||||
if (count($ab_fieldnames)) {
|
||||
$t_fields = "," . implode(",",$ab_fieldnames);
|
||||
if ($t_fields == ",") {
|
||||
unset($t_fields);
|
||||
}
|
||||
}
|
||||
|
||||
$this->db2 = $this->db;
|
||||
|
||||
$this->db->query("select id,lid,owner $t_fields from addressbook WHERE id='$id'");
|
||||
$this->db->next_record();
|
||||
|
||||
$return_fields[0]["id"] = $this->db->f("id");
|
||||
$return_fields[0]["lid"] = $this->db->f("lid");
|
||||
$return_fields[0]["owner"] = $this->db->f("owner");
|
||||
if (gettype($ab_fieldnames) == "array") {
|
||||
while (list($f_name) = each($ab_fieldnames)) {
|
||||
$return_fields[0][$f_name] = $this->db->f($f_name);
|
||||
}
|
||||
}
|
||||
$this->db2->query("select contact_name,contact_value from addressbook_extra where contact_id='"
|
||||
. $this->db->f("id") . "'",__LINE__,__FILE__);
|
||||
while ($this->db2->next_record()) {
|
||||
// If its not in the list to be returned, don't return it.
|
||||
// This is still quicker then 5(+) separate queries
|
||||
if ($extra_fields[$this->db2->f("contact_name")]) {
|
||||
$return_fields[0][$this->db2->f("contact_name")] = $this->db2->f("contact_value");
|
||||
}
|
||||
}
|
||||
|
||||
return $return_fields;
|
||||
}
|
||||
|
||||
function read($start,$offset,$fields,$query="",$sort="",$order="")
|
||||
{
|
||||
global $phpgw,$phpgw_info;
|
||||
|
||||
if (!$sort) { $sort = "ASC"; }
|
||||
|
||||
if ($order) {
|
||||
$ordermethod = "order by $order $sort ";
|
||||
} else {
|
||||
$ordermethod = "order by N_Family,N_Given,D_EMAIL $sort";
|
||||
}
|
||||
|
||||
list($ab_fields,$ab_fieldnames,$extra_fields) = $this->split_ab_and_extras($fields);
|
||||
if (count($ab_fieldnames)) {
|
||||
$t_fields = "," . implode(",",$ab_fieldnames);
|
||||
if ($t_fields == ",") {
|
||||
unset($t_fields);
|
||||
}
|
||||
}
|
||||
|
||||
$this->db3 = $this->db2 = $this->db; // Create new result objects before our queries
|
||||
|
||||
if ($query) {
|
||||
$this->db3->query("SELECT * from addressbook WHERE (N_Family like '"
|
||||
. "%$query%' OR N_Given like '%$query%' OR D_EMAIL like '%$query%' OR "
|
||||
. "ADR_Street like '%$query%' OR ADR_Locality like '%$query%' OR ADR_Region "
|
||||
. "like '%$query%' OR ADR_PostalCode like '%$query%' OR ORG_Unit like "
|
||||
. "'%$query%' OR ORG_Name like '%$query%') " . $ordermethod,__LINE__,__FILE__);
|
||||
$this->total_records = $this->db3->num_rows();
|
||||
|
||||
$this->db->query("SELECT * from addressbook WHERE (N_Family like '"
|
||||
. "%$query%' OR N_Given like '%$query%' OR D_EMAIL like '%$query%' OR "
|
||||
. "ADR_Street like '%$query%' OR ADR_Locality like '%$query%' OR ADR_Region "
|
||||
. "like '%$query%' OR ADR_PostalCode like '%$query%' OR ORG_Unit like "
|
||||
. "'%$query%' OR ORG_Name like '%$query%') " . $ordermethod . " "
|
||||
. $this->db->limit($start,$offset),__LINE__,__FILE__);
|
||||
} else {
|
||||
$this->db3->query("select id,lid,owner $t_fields from addressbook "
|
||||
. $filtermethod,__LINE__,__FILE__);
|
||||
$this->total_records = $this->db3->num_rows();
|
||||
|
||||
$this->db->query("select id,lid,owner $t_fields from addressbook "
|
||||
. $filtermethod . " " . $ordermethod . " " . $this->db->limit($start,$offset),__LINE__,__FILE__);
|
||||
}
|
||||
|
||||
$i=0;
|
||||
while ($this->db->next_record()) {
|
||||
$return_fields[$i]["id"] = $this->db->f("id");
|
||||
$return_fields[$i]["lid"] = $this->db->f("lid");
|
||||
$return_fields[$i]["owner"] = $this->db->f("owner");
|
||||
if (gettype($ab_fieldnames) == "array") {
|
||||
while (list($f_name) = each($ab_fieldnames)) {
|
||||
$return_fields[$i][$f_name] = $this->db->f($f_name);
|
||||
}
|
||||
reset($ab_fieldnames);
|
||||
}
|
||||
|
||||
$this->db2->query("select contact_name,contact_value from addressbook_extra where contact_id='"
|
||||
. $this->db->f("id") . "'",__LINE__,__FILE__);
|
||||
while ($this->db2->next_record()) {
|
||||
// If its not in the list to be returned, don't return it.
|
||||
// This is still quicker then 5(+) separate queries
|
||||
if ($extra_fields[$this->db2->f("contact_name")]) {
|
||||
$return_fields[$i][$this->db2->f("contact_name")] = $this->db2->f("contact_value");
|
||||
}
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
|
||||
return $return_fields;
|
||||
}
|
||||
|
||||
function add($owner,$fields)
|
||||
{
|
||||
list($ab_fields,$ab_fieldnames,$extra_fields) = $this->split_ab_and_extras($fields);
|
||||
|
||||
//$this->db->lock(array("contacts"));
|
||||
$this->db->query("insert into contacts (owner,"
|
||||
. implode(",",$this->stock_contact_fields)
|
||||
. ") values ('$owner','"
|
||||
. implode("','",$this->loop_addslashes($ab_fields)) . "')",__LINE__,__FILE__);
|
||||
|
||||
$this->db->query("select max(id) from addressbook",__LINE__,__FILE__);
|
||||
$this->db->next_record();
|
||||
$id = $this->db->f(0);
|
||||
//$this->db->unlock();
|
||||
|
||||
if (count($extra_fields)) {
|
||||
while (list($name,$value) = each($extra_fields)) {
|
||||
$this->db->query("insert into contacts_extra values ('$id','" . $this->account_id . "','"
|
||||
. addslashes($name) . "','" . addslashes($value) . "')",__LINE__,__FILE__);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function field_exists($id,$field_name)
|
||||
{
|
||||
$this->db->query("select count(*) from addressbook_extra where contact_id='$id' and contact_name='"
|
||||
. addslashes($field_name) . "'",__LINE__,__FILE__);
|
||||
$this->db->next_record();
|
||||
return $this->db->f(0);
|
||||
}
|
||||
|
||||
function add_single_extra_field($id,$owner,$field_name,$field_value)
|
||||
{
|
||||
$this->db->query("insert into contacts_extra values ($id,'$owner','" . addslashes($field_name)
|
||||
. "','" . addslashes($field_value) . "')",__LINE__,__FILE__);
|
||||
}
|
||||
|
||||
function delete_single_extra_field($id,$field_name)
|
||||
{
|
||||
$this->db->query("delete from addressbook_extra where contact_id='$id' and contact_name='"
|
||||
. addslashes($field_name) . "'",__LINE__,__FILE__);
|
||||
}
|
||||
|
||||
function update($id,$owner,$fields)
|
||||
{
|
||||
// First make sure that id number exists
|
||||
$this->db->query("select count(*) from addressbook where id='$id'",__LINE__,__FILE__);
|
||||
$this->db->next_record();
|
||||
if (! $this->db->f(0)) {
|
||||
return False;
|
||||
}
|
||||
|
||||
list($ab_fields,$ab_fieldnames,$extra_fields) = $this->split_ab_and_extras($fields);
|
||||
if (count($ab_fields)) {
|
||||
while (list($ab_fieldname) = each($ab_fieldnames)) {
|
||||
$ta[] = $ab_fieldname . "='" . addslashes($ab_fields[$ab_fieldname]) . "'";
|
||||
}
|
||||
$fields_s = "," . implode(",",$ta);
|
||||
if ($field_s == ",") {
|
||||
unset($field_s);
|
||||
}
|
||||
$this->db->query("update contacts set owner='$owner', $fields_s where "
|
||||
. "id='$id'",__LINE__,__FILE__);
|
||||
}
|
||||
|
||||
while (list($x_name,$x_value) = each($extra_fields)) {
|
||||
if ($this->field_exists($id,$x_name)) {
|
||||
if (! $x_value) {
|
||||
$this->delete_single_extra_field($id,$x_name);
|
||||
} else {
|
||||
$this->db->query("update contacts_extra set contact_value='" . addslashes($x_value)
|
||||
. "',contact_owner='$owner' where contact_name='" . addslashes($x_name)
|
||||
. "' and contact_id='$id'",__LINE__,__FILE__);
|
||||
}
|
||||
} else {
|
||||
$this->add_single_extra_field($id,$owner,$x_name,$x_value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// This is where the real work of delete() is done
|
||||
function delete_($id)
|
||||
{
|
||||
$this->db->query("delete from addressbook where owner='" . $this->account_id . "' and "
|
||||
. "id='$id'",__LINE__,__FILE__);
|
||||
$this->db->query("delete from addressbook_extra where contact_id='$id' and contact_owner='"
|
||||
. $this->account_id . "'",__LINE__,__FILE__);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
Loading…
Reference in New Issue
Block a user