mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-10-06 02:02:24 +02:00
Massive change to read function to help ordering and filtering
This commit is contained in:
parent
7cead125e0
commit
a0f49c6a3e
@ -63,8 +63,11 @@
|
|||||||
$fields["d_emailtype"] = $email_type;
|
$fields["d_emailtype"] = $email_type;
|
||||||
$fields["title"] = $title;
|
$fields["title"] = $title;
|
||||||
$fields["a_tel"] = $wphone;
|
$fields["a_tel"] = $wphone;
|
||||||
|
$fields["a_tel_work"] = "y";
|
||||||
$fields["b_tel"] = $hphone;
|
$fields["b_tel"] = $hphone;
|
||||||
|
$fields["b_tel_home"] = "y";
|
||||||
$fields["c_tel"] = $fax;
|
$fields["c_tel"] = $fax;
|
||||||
|
$fields["c_tel_fax"] = "y";
|
||||||
$fields["pager"] = $pager;
|
$fields["pager"] = $pager;
|
||||||
$fields["mphone"] = $mphone;
|
$fields["mphone"] = $mphone;
|
||||||
$fields["ophone"] = $ophone;
|
$fields["ophone"] = $ophone;
|
||||||
|
@ -1,4 +0,0 @@
|
|||||||
<?php
|
|
||||||
include($phpgw_info["server"]["include_root"]."/addressbook/inc/class.addressbook_".$phpgw_info["server"]["account_repository"].".inc.php");
|
|
||||||
include($phpgw_info["server"]["include_root"]."/addressbook/inc/class.addressbook_shared.inc.php");
|
|
||||||
?>
|
|
@ -1,44 +1,39 @@
|
|||||||
<?php
|
<?php
|
||||||
/**************************************************************************\
|
/**************************************************************************\
|
||||||
* phpGroupWare API - Accounts manager for SQL *
|
* phpGroupWare API - Contacts manager for SQL *
|
||||||
* This file written by Joseph Engo <jengo@phpgroupware.org> *
|
* This file written by Joseph Engo <jengo@phpgroupware.org> *
|
||||||
* View and manipulate contact records using SQL *
|
* View and manipulate contact records using SQL *
|
||||||
* Copyright (C) 2001 Joseph Engo *
|
* Copyright (C) 2001 Joseph Engo *
|
||||||
* -------------------------------------------------------------------------*
|
* -------------------------------------------------------------------------*
|
||||||
* This library is part of the phpGroupWare API *
|
* This library is part of the phpGroupWare API *
|
||||||
* http://www.phpgroupware.org/api *
|
* http://www.phpgroupware.org/api *
|
||||||
* ------------------------------------------------------------------------ *
|
* ------------------------------------------------------------------------ *
|
||||||
* This library is free software; you can redistribute it and/or modify it *
|
* 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 *
|
* under the terms of the GNU Lesser General Public License as published by *
|
||||||
* the Free Software Foundation; either version 2.1 of the License, *
|
* the Free Software Foundation; either version 2.1 of the License, *
|
||||||
* or any later version. *
|
* or any later version. *
|
||||||
* This library is distributed in the hope that it will be useful, but *
|
* This library is distributed in the hope that it will be useful, but *
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of *
|
* WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
|
||||||
* See the GNU Lesser General Public License for more details. *
|
* See the GNU Lesser General Public License for more details. *
|
||||||
* You should have received a copy of the GNU Lesser General Public License *
|
* 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, *
|
* along with this library; if not, write to the Free Software Foundation, *
|
||||||
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
|
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
|
||||||
\**************************************************************************/
|
\**************************************************************************/
|
||||||
|
|
||||||
/* $Id$ */
|
/* $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 */
|
/* ldap is a copy of sql for now */
|
||||||
|
|
||||||
class contacts_
|
class contacts_
|
||||||
{
|
{
|
||||||
var $db;
|
var $db;
|
||||||
|
var $std_table="phpgw_addressbook";
|
||||||
|
var $ext_table="phpgw_addressbook_extra";
|
||||||
var $account_id;
|
var $account_id;
|
||||||
var $stock_addressbook_fields; // This is an array of all the fields in the addressbook
|
var $stock_contact_fields; // This is an array of almost the fields in the
|
||||||
|
// phpgw_addressbook table, except id,owner,lid,tid
|
||||||
|
var $email_types; // VCard email type array
|
||||||
var $total_records; // This will contain numrows for data retrieved
|
var $total_records; // This will contain numrows for data retrieved
|
||||||
|
|
||||||
function contacts_()
|
function contacts_()
|
||||||
@ -46,55 +41,104 @@
|
|||||||
global $phpgw, $phpgw_info;
|
global $phpgw, $phpgw_info;
|
||||||
|
|
||||||
$this->db = $phpgw->db;
|
$this->db = $phpgw->db;
|
||||||
|
|
||||||
$this->account_id = $phpgw_info["user"]["account_id"];
|
$this->account_id = $phpgw_info["user"]["account_id"];
|
||||||
$this->stock_addressbook_fields = array("firstname" => "firstname",
|
|
||||||
"lastname" => "lastname",
|
$this->stock_contact_fields = array(
|
||||||
"email" => "email",
|
"fn" => "fn", //'firstname lastname'
|
||||||
"hphone" => "hphone",
|
"sound" => "sound",
|
||||||
"wphone" => "wphone",
|
"org_name" => "org_name", //company
|
||||||
"fax" => "fax",
|
"org_unit" => "org_unit", //division
|
||||||
"pager" => "pager",
|
|
||||||
"mphone" => "mphone",
|
|
||||||
"ophone" => "ophone",
|
|
||||||
"street" => "street",
|
|
||||||
"city" => "city",
|
|
||||||
"state" => "state",
|
|
||||||
"zip" => "zip",
|
|
||||||
"bday" => "bday",
|
|
||||||
"notes" => "notes",
|
|
||||||
"company" => "company",
|
|
||||||
"title" => "title",
|
"title" => "title",
|
||||||
"address2" => "address2",
|
"n_given" => "n_given", //firstname
|
||||||
"url" => "url"
|
"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
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->email_types = array(
|
||||||
|
"INTERNET" => "INTERNET",
|
||||||
|
"CompuServe" => "CompuServe",
|
||||||
|
"AOL" => "AOL",
|
||||||
|
"Prodigy" => "Prodigy",
|
||||||
|
"eWorld" => "eWorld",
|
||||||
|
"AppleLink" => "AppleLink",
|
||||||
|
"AppleTalk" => "AppleTalk",
|
||||||
|
"PowerShare" => "PowerShare",
|
||||||
|
"IBMMail" => "IBMMail",
|
||||||
|
"ATTMail" => "ATTMail",
|
||||||
|
"MCIMail" => "MCIMail",
|
||||||
|
"X.400" => "X.400",
|
||||||
|
"TLX" => "TLX"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function read_single_entry($id,$fields)
|
// send this the id and whatever fields you want to see
|
||||||
|
function read_single_entry($id,$fields="")
|
||||||
{
|
{
|
||||||
list($ab_fields,$ab_fieldnames,$extra_fields) = $this->split_ab_and_extras($fields);
|
if (!$fields || empty($fields)) { $fields = $this->stock_contact_fields; }
|
||||||
if (count($ab_fieldnames)) {
|
list($stock_fields,$stock_fieldnames,$extra_fields) =
|
||||||
$t_fields = ",ab_" . implode(",ab_",$ab_fieldnames);
|
$this->split_stock_and_extras($fields);
|
||||||
if ($t_fields == ",ab_") {
|
|
||||||
|
if (count($stock_fieldnames)) {
|
||||||
|
$t_fields = "," . implode(",",$stock_fieldnames);
|
||||||
|
if ($t_fields == ",") {
|
||||||
unset($t_fields);
|
unset($t_fields);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->db2 = $this->db;
|
$this->db2 = $this->db;
|
||||||
|
|
||||||
$this->db->query("select ab_id,ab_owner,ab_access $t_fields from addressbook WHERE ab_id='$id'");
|
$this->db->query("select id,lid,tid,owner $t_fields from $this->std_table WHERE id='$id'");
|
||||||
$this->db->next_record();
|
$this->db->next_record();
|
||||||
|
|
||||||
$return_fields[0]["id"] = $this->db->f("ab_id");
|
$return_fields[0]["id"] = $this->db->f("id"); // unique id
|
||||||
$return_fields[0]["owner"] = $this->db->f("ab_owner");
|
$return_fields[0]["lid"] = $this->db->f("lid"); // lid for group/account records
|
||||||
$return_fields[0]["access"] = $this->db->f("ab_access");
|
$return_fields[0]["tid"] = $this->db->f("tid"); // type id (g/u) for groups/accounts
|
||||||
if (gettype($ab_fieldnames) == "array") {
|
$return_fields[0]["owner"] = $this->db->f("owner"); // id of owner/parent for the record
|
||||||
while (list($f_name) = each($ab_fieldnames)) {
|
if (gettype($stock_fieldnames) == "array") {
|
||||||
$return_fields[0][$f_name] = $this->db->f("ab_" . $f_name);
|
while (list($f_name) = each($stock_fieldnames)) {
|
||||||
|
$return_fields[0][$f_name] = $this->db->f($f_name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->db2->query("select contact_name,contact_value from phpgw_contacts where contact_id='"
|
$this->db2->query("select contact_name,contact_value from $this->ext_table where contact_id='" . $this->db->f("id") . "'",__LINE__,__FILE__);
|
||||||
. $this->db->f("ab_id") . "'",__LINE__,__FILE__);
|
|
||||||
while ($this->db2->next_record()) {
|
while ($this->db2->next_record()) {
|
||||||
// If its not in the list to be returned, don't return it.
|
// If its not in the list to be returned, don't return it.
|
||||||
// This is still quicker then 5(+) separate queries
|
// This is still quicker then 5(+) separate queries
|
||||||
@ -102,81 +146,170 @@
|
|||||||
$return_fields[0][$this->db2->f("contact_name")] = $this->db2->f("contact_value");
|
$return_fields[0][$this->db2->f("contact_name")] = $this->db2->f("contact_value");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $return_fields;
|
return $return_fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
function read($start,$offset,$access,$fields,$query="",$filter="",$sort="",$order="")
|
function read_last_entry($fields="")
|
||||||
|
{
|
||||||
|
if (!$fields || empty($fields)) { $fields = $this->stock_contact_fields; }
|
||||||
|
list($stock_fields,$stock_fieldnames,$extra_fields) =
|
||||||
|
$this->split_stock_and_extras($fields);
|
||||||
|
|
||||||
|
if (count($stock_fieldnames)) {
|
||||||
|
$t_fields = "," . implode(",",$stock_fieldnames);
|
||||||
|
if ($t_fields == ",") {
|
||||||
|
unset($t_fields);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->db2 = $this->db;
|
||||||
|
|
||||||
|
$this->db->query("select max(id) from $this->std_table");
|
||||||
|
$this->db->next_record();
|
||||||
|
|
||||||
|
$id = $this->db->f("max(id)");
|
||||||
|
|
||||||
|
$this->db->query("select id,lid,tid,owner $t_fields from $this->std_table WHERE id='$id'");
|
||||||
|
$this->db->next_record();
|
||||||
|
|
||||||
|
$return_fields[0]["id"] = $this->db->f("id"); // unique id
|
||||||
|
$return_fields[0]["lid"] = $this->db->f("lid"); // lid for group/account records
|
||||||
|
$return_fields[0]["tid"] = $this->db->f("tid"); // type id (g/u) for groups/accounts
|
||||||
|
$return_fields[0]["owner"] = $this->db->f("owner"); // id of owner/parent for the record
|
||||||
|
if (gettype($stock_fieldnames) == "array") {
|
||||||
|
while (list($f_name) = each($stock_fieldnames)) {
|
||||||
|
$return_fields[0][$f_name] = $this->db->f($f_name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->db2->query("select contact_name,contact_value from $this->ext_table 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// send this the range, query, sort, order and whatever fields you want to see
|
||||||
|
// 'rights' is unused at this time
|
||||||
|
function read($start,$offset,$fields="",$query="",$filter="",$sort="",$order="",$rights="")
|
||||||
{
|
{
|
||||||
global $phpgw,$phpgw_info;
|
global $phpgw,$phpgw_info;
|
||||||
|
if (!$fields || empty($fields)) { $fields = $this->stock_contact_fields; }
|
||||||
|
$DEBUG = 1;
|
||||||
|
|
||||||
|
list($stock_fields,$stock_fieldnames,$extra_fields) = $this->split_stock_and_extras($fields);
|
||||||
|
if (count($stock_fieldnames)) {
|
||||||
|
$t_fields = "," . implode(",",$stock_fieldnames);
|
||||||
|
if ($t_fields == ",") {
|
||||||
|
unset($t_fields);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($filter) {
|
||||||
|
if ($DEBUG) { echo "DEBUG - Inbound filter is: #".$filter."#"; }
|
||||||
|
$filterarray = split(',',$filter);
|
||||||
|
if ($filterarray[1]) {
|
||||||
|
$i=0;
|
||||||
|
while (list($name,$value) = split('=',$filterarray[$i])) {
|
||||||
|
$filterfields[$i] .= array($name => $value);
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
list($name,$value) = split('=',$filter);
|
||||||
|
if ($DEBUG) {
|
||||||
|
echo "<br>DEBUG - Filter intermediate strings 1: #".$name."# => #".$value."#";
|
||||||
|
}
|
||||||
|
$filterfields = array($name => $value);
|
||||||
|
}
|
||||||
|
|
||||||
|
$i=0;
|
||||||
|
while (list($name,$value) = each($filterfields)) {
|
||||||
|
if ($DEBUG) { echo "<br>DEBUG - Filter intermediate strings 2: #".$name."# => #".$value."#"; }
|
||||||
|
$filterlist .= $name."='".$value."',";
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
|
$filterlist = substr($filterlist,0,-1);
|
||||||
|
|
||||||
|
if ($DEBUG) {
|
||||||
|
echo "<br>DEBUG - Filter output string: #".$filterlist."#";
|
||||||
|
}
|
||||||
|
|
||||||
|
list($fields,$fieldnames,$extra) = $this->split_stock_and_extras($filterfields);
|
||||||
|
|
||||||
|
if ($extra) {
|
||||||
|
while (list($name,$value) = each($extra)) {
|
||||||
|
$value = "%," . $value . ",%";
|
||||||
|
$filterextra .= " AND contact_name='".$name."' AND contact_value like '".$value."',";
|
||||||
|
}
|
||||||
|
$filterextra = substr($filterextra,0,-1);
|
||||||
|
} else {
|
||||||
|
$filterstock = " AND ($filterlist) ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($DEBUG && ($filterextra || $filterstock)) {
|
||||||
|
if ($filterextra) {
|
||||||
|
echo "<br>DEBUG - Filtering on extra fields with: #" . $filterextra . "#";
|
||||||
|
}
|
||||||
|
if ($filterstock) {
|
||||||
|
echo "<br>DEBUG - Filtering on standard fields with: #" . $filterstock . "#";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!$sort) { $sort = "ASC"; }
|
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) {
|
if ($order) {
|
||||||
$ordermethod = "order by $order $sort ";
|
$ordermethod = "order by $order $sort ";
|
||||||
} else {
|
} else {
|
||||||
$ordermethod = "order by ab_lastname,ab_firstname,ab_email $sort";
|
$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 = ",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
|
$this->db3 = $this->db2 = $this->db; // Create new result objects before our queries
|
||||||
|
|
||||||
if ($query) {
|
if ($query) {
|
||||||
$this->db3->query("SELECT * from addressbook $filtermethod AND (ab_lastname like '"
|
$this->db3->query("SELECT * from $this->std_table WHERE (n_family like '"
|
||||||
. "%$query%' OR ab_firstname like '%$query%' OR ab_email like '%$query%' OR "
|
. "%$query%' OR n_given like '%$query%' OR d_email like '%$query%' OR "
|
||||||
. "ab_street like '%$query%' OR ab_city like '%$query%' OR ab_state "
|
. "adr_street like '%$query%' OR adr_locality like '%$query%' OR adr_region "
|
||||||
. "like '%$query%' OR ab_zip like '%$query%' OR ab_notes like "
|
. "like '%$query%' OR adr_postalcode like '%$query%' OR org_unit like "
|
||||||
. "'%$query%' OR ab_company like '%$query%') " . $ordermethod,__LINE__,__FILE__);
|
. "'%$query%' OR org_name like '%$query%') " . $filterstock . $ordermethod,__LINE__,__FILE__);
|
||||||
$this->total_records = $this->db3->num_rows();
|
$this->total_records = $this->db3->num_rows();
|
||||||
|
|
||||||
$this->db->query("SELECT * from addressbook $filtermethod AND (ab_lastname like '"
|
$this->db->query("SELECT * from $this->std_table WHERE (n_family like '"
|
||||||
. "%$query%' OR ab_firstname like '%$query%' OR ab_email like '%$query%' OR "
|
. "%$query%' OR n_given like '%$query%' OR d_email like '%$query%' OR "
|
||||||
. "ab_street like '%$query%' OR ab_city like '%$query%' OR ab_state "
|
. "adr_street like '%$query%' OR adr_locality like '%$query%' OR adr_region "
|
||||||
. "like '%$query%' OR ab_zip like '%$query%' OR ab_notes like "
|
. "like '%$query%' OR adr_postalcode like '%$query%' OR org_unit like "
|
||||||
. "'%$query%' OR ab_company like '%$query%') " . $ordermethod . " "
|
. "'%$query%' OR ORG_Name like '%$query%') " . $filterstock . $ordermethod . " "
|
||||||
. $this->db->limit($start,$offset),__LINE__,__FILE__);
|
. $this->db->limit($start,$offset),__LINE__,__FILE__);
|
||||||
} else {
|
} else {
|
||||||
$this->db3->query("select ab_id,ab_owner,ab_access $t_fields from addressbook "
|
$this->db3->query("select id,lid,tid,owner $t_fields from $this->std_table "
|
||||||
. $filtermethod,__LINE__,__FILE__);
|
. $filterstock,__LINE__,__FILE__);
|
||||||
$this->total_records = $this->db3->num_rows();
|
$this->total_records = $this->db3->num_rows();
|
||||||
|
|
||||||
$this->db->query("select ab_id,ab_owner,ab_access $t_fields from addressbook "
|
$this->db->query("select id,lid,tid,owner $t_fields from $this->std_table "
|
||||||
. $filtermethod . " " . $ordermethod . " " . $this->db->limit($start,$offset),__LINE__,__FILE__);
|
. $filterstock . " " . $ordermethod . " " . $this->db->limit($start,$offset),__LINE__,__FILE__);
|
||||||
}
|
}
|
||||||
|
|
||||||
$i=0;
|
$i=0;
|
||||||
while ($this->db->next_record()) {
|
while ($this->db->next_record()) {
|
||||||
$return_fields[$i]["id"] = $this->db->f("ab_id");
|
// unique id, lid for group/account records,
|
||||||
$return_fields[$i]["owner"] = $this->db->f("ab_owner");
|
// type id (g/u) for groups/accounts, and
|
||||||
$return_fields[$i]["access"] = $this->db->f("ab_access");
|
// id of owner/parent for the record
|
||||||
if (gettype($ab_fieldnames) == "array") {
|
$return_fields[$i]["id"] = $this->db->f("id");
|
||||||
while (list($f_name) = each($ab_fieldnames)) {
|
$return_fields[$i]["lid"] = $this->db->f("lid");
|
||||||
$return_fields[$i][$f_name] = $this->db->f("ab_" . $f_name);
|
$return_fields[$i]["tid"] = $this->db->f("tid");
|
||||||
}
|
$return_fields[$i]["owner"] = $this->db->f("owner");
|
||||||
reset($ab_fieldnames);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->db2->query("select contact_name,contact_value from phpgw_contacts where contact_id='"
|
if (gettype($stock_fieldnames) == "array") {
|
||||||
. $this->db->f("ab_id") . "'",__LINE__,__FILE__);
|
while (list($f_name) = each($stock_fieldnames)) {
|
||||||
|
$return_fields[$i][$f_name] = $this->db->f($f_name);
|
||||||
|
}
|
||||||
|
reset($stock_fieldnames);
|
||||||
|
}
|
||||||
|
$this->db2->query("select contact_name,contact_value from $this->ext_table where contact_id='"
|
||||||
|
. $this->db->f("id") . "'" .$filterextra,__LINE__,__FILE__);
|
||||||
while ($this->db2->next_record()) {
|
while ($this->db2->next_record()) {
|
||||||
// If its not in the list to be returned, don't return it.
|
// If its not in the list to be returned, don't return it.
|
||||||
// This is still quicker then 5(+) separate queries
|
// This is still quicker then 5(+) separate queries
|
||||||
@ -190,24 +323,23 @@
|
|||||||
return $return_fields;
|
return $return_fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
function add($owner,$access,$fields)
|
function add($owner,$fields)
|
||||||
{
|
{
|
||||||
list($ab_fields,$ab_fieldnames,$extra_fields) = $this->split_ab_and_extras($fields);
|
list($stock_fields,$stock_fieldnames,$extra_fields) = $this->split_stock_and_extras($fields);
|
||||||
|
|
||||||
//$this->db->lock(array("phpgw_addressbook"));
|
//$this->db->lock(array("contacts"));
|
||||||
$this->db->query("insert into addressbook (ab_owner,ab_access,ab_"
|
$this->db->query("insert into $this->std_table (owner,"
|
||||||
. implode(",ab_",$this->stock_addressbook_fields)
|
. implode(",",$this->stock_contact_fields)
|
||||||
. ") values ('$owner','$access','"
|
. ") values ('$owner','"
|
||||||
. implode("','",$this->loop_addslashes($ab_fields)) . "')",__LINE__,__FILE__);
|
. implode("','",$this->loop_addslashes($stock_fields)) . "')",__LINE__,__FILE__);
|
||||||
|
|
||||||
$this->db->query("select max(ab_id) from addressbook",__LINE__,__FILE__);
|
$this->db->query("select max(id) from $this->std_table ",__LINE__,__FILE__);
|
||||||
$this->db->next_record();
|
$this->db->next_record();
|
||||||
$ab_id = $this->db->f(0);
|
$id = $this->db->f(0);
|
||||||
//$this->db->unlock();
|
//$this->db->unlock();
|
||||||
|
|
||||||
if (count($extra_fields)) {
|
if (count($extra_fields)) {
|
||||||
while (list($name,$value) = each($extra_fields)) {
|
while (list($name,$value) = each($extra_fields)) {
|
||||||
$this->db->query("insert into phpgw_contacts values ('$ab_id','" . $this->account_id . "','"
|
$this->db->query("insert into $this->ext_table values ('$id','" . $this->account_id . "','"
|
||||||
. addslashes($name) . "','" . addslashes($value) . "')",__LINE__,__FILE__);
|
. addslashes($name) . "','" . addslashes($value) . "')",__LINE__,__FILE__);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -215,7 +347,7 @@
|
|||||||
|
|
||||||
function field_exists($id,$field_name)
|
function field_exists($id,$field_name)
|
||||||
{
|
{
|
||||||
$this->db->query("select count(*) from phpgw_contacts where contact_id='$id' and contact_name='"
|
$this->db->query("select count(*) from $this->ext_table where contact_id='$id' and contact_name='"
|
||||||
. addslashes($field_name) . "'",__LINE__,__FILE__);
|
. addslashes($field_name) . "'",__LINE__,__FILE__);
|
||||||
$this->db->next_record();
|
$this->db->next_record();
|
||||||
return $this->db->f(0);
|
return $this->db->f(0);
|
||||||
@ -223,36 +355,36 @@
|
|||||||
|
|
||||||
function add_single_extra_field($id,$owner,$field_name,$field_value)
|
function add_single_extra_field($id,$owner,$field_name,$field_value)
|
||||||
{
|
{
|
||||||
$this->db->query("insert into phpgw_contacts values ($id,'$owner','" . addslashes($field_name)
|
$this->db->query("insert into $this->ext_table values ($id,'$owner','" . addslashes($field_name)
|
||||||
. "','" . addslashes($field_value) . "')",__LINE__,__FILE__);
|
. "','" . addslashes($field_value) . "')",__LINE__,__FILE__);
|
||||||
}
|
}
|
||||||
|
|
||||||
function delete_single_extra_field($id,$field_name)
|
function delete_single_extra_field($id,$field_name)
|
||||||
{
|
{
|
||||||
$this->db->query("delete from phpgw_contacts where contact_id='$id' and contact_name='"
|
$this->db->query("delete from $this->ext_table where contact_id='$id' and contact_name='"
|
||||||
. addslashes($field_name) . "'",__LINE__,__FILE__);
|
. addslashes($field_name) . "'",__LINE__,__FILE__);
|
||||||
}
|
}
|
||||||
|
|
||||||
function update($id,$owner,$access,$fields)
|
function update($id,$owner,$fields)
|
||||||
{
|
{
|
||||||
// First make sure that id number exists
|
// First make sure that id number exists
|
||||||
$this->db->query("select count(*) from addressbook where ab_id='$id'",__LINE__,__FILE__);
|
$this->db->query("select count(*) from $this->std_table where id='$id'",__LINE__,__FILE__);
|
||||||
$this->db->next_record();
|
$this->db->next_record();
|
||||||
if (! $this->db->f(0)) {
|
if (! $this->db->f(0)) {
|
||||||
return False;
|
return False;
|
||||||
}
|
}
|
||||||
|
|
||||||
list($ab_fields,$ab_fieldnames,$extra_fields) = $this->split_ab_and_extras($fields);
|
list($stock_fields,$stock_fieldnames,$extra_fields) = $this->split_stock_and_extras($fields);
|
||||||
if (count($ab_fields)) {
|
if (count($stock_fields)) {
|
||||||
while (list($ab_fieldname) = each($ab_fieldnames)) {
|
while (list($stock_fieldname) = each($stock_fieldnames)) {
|
||||||
$ta[] = $ab_fieldname . "='" . addslashes($ab_fields[$ab_fieldname]) . "'";
|
$ta[] = $stock_fieldname . "='" . addslashes($stock_fields[$stock_fieldname]) . "'";
|
||||||
}
|
}
|
||||||
$fields_s = ",ab_" . implode(",ab_",$ta);
|
$fields_s = "," . implode(",",$ta);
|
||||||
if ($field_s == ",") {
|
if ($field_s == ",") {
|
||||||
unset($field_s);
|
unset($field_s);
|
||||||
}
|
}
|
||||||
$this->db->query("update addressbook set ab_owner='$owner',ab_access='$access' $fields_s where "
|
$this->db->query("update $this->std_table set owner='$owner' $fields_s where "
|
||||||
. "ab_id='$id'",__LINE__,__FILE__);
|
. "id='$id'",__LINE__,__FILE__);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (list($x_name,$x_value) = each($extra_fields)) {
|
while (list($x_name,$x_value) = each($extra_fields)) {
|
||||||
@ -260,7 +392,7 @@
|
|||||||
if (! $x_value) {
|
if (! $x_value) {
|
||||||
$this->delete_single_extra_field($id,$x_name);
|
$this->delete_single_extra_field($id,$x_name);
|
||||||
} else {
|
} else {
|
||||||
$this->db->query("update phpgw_contacts set contact_value='" . addslashes($x_value)
|
$this->db->query("update $this->ext_table set contact_value='" . addslashes($x_value)
|
||||||
. "',contact_owner='$owner' where contact_name='" . addslashes($x_name)
|
. "',contact_owner='$owner' where contact_name='" . addslashes($x_name)
|
||||||
. "' and contact_id='$id'",__LINE__,__FILE__);
|
. "' and contact_id='$id'",__LINE__,__FILE__);
|
||||||
}
|
}
|
||||||
@ -273,9 +405,9 @@
|
|||||||
// This is where the real work of delete() is done
|
// This is where the real work of delete() is done
|
||||||
function delete_($id)
|
function delete_($id)
|
||||||
{
|
{
|
||||||
$this->db->query("delete from addressbook where ab_owner='" . $this->account_id . "' and "
|
$this->db->query("delete from $this->std_table where owner='" . $this->account_id . "' and "
|
||||||
. "ab_id='$id'",__LINE__,__FILE__);
|
. "id='$id'",__LINE__,__FILE__);
|
||||||
$this->db->query("delete from phpgw_contacts where contact_id='$id' and contact_owner='"
|
$this->db->query("delete from $this->ext_table where contact_id='$id' and contact_owner='"
|
||||||
. $this->account_id . "'",__LINE__,__FILE__);
|
. $this->account_id . "'",__LINE__,__FILE__);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,16 +23,6 @@
|
|||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
addressbook_extra (
|
|
||||||
contact_id int,
|
|
||||||
contact_owner int,
|
|
||||||
contact_name varchar(255),
|
|
||||||
contact_value varchar(255)
|
|
||||||
);
|
|
||||||
*/
|
|
||||||
|
|
||||||
class contacts extends contacts_
|
class contacts extends contacts_
|
||||||
{
|
{
|
||||||
var $db;
|
var $db;
|
||||||
@ -46,7 +36,7 @@
|
|||||||
while (list($field,$value) = each($fields)) {
|
while (list($field,$value) = each($fields)) {
|
||||||
// Depending on how the array was build, this is needed.
|
// Depending on how the array was build, this is needed.
|
||||||
// Yet, I can't figure out why ....
|
// Yet, I can't figure out why ....
|
||||||
if (gettype($field) == "integer") {
|
if (gettype($value) == "integer") {
|
||||||
$field = $value;
|
$field = $value;
|
||||||
}
|
}
|
||||||
if ($this->stock_contact_fields[$field]) {
|
if ($this->stock_contact_fields[$field]) {
|
||||||
@ -81,5 +71,56 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// sort a multi-dimensional array on an array element
|
||||||
|
// using the named element
|
||||||
|
// This is neither used (yet) or guaranteed to work
|
||||||
|
function qsort_multiarray($array,$column,$order = "ASC",$left = 0,$right = -1,$num=0)
|
||||||
|
{
|
||||||
|
if($right == -1)
|
||||||
|
{ $right = count($array) - 1; }
|
||||||
|
|
||||||
|
$i=0;
|
||||||
|
|
||||||
|
if (!$num) {
|
||||||
|
$num=0;
|
||||||
|
echo "nonum";
|
||||||
|
if ($column && !empty($column)) {
|
||||||
|
while (list($name,$value) = each($array[0])) {
|
||||||
|
if ($column == $name) {
|
||||||
|
$num = $i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
echo "<br>". $num ." - name='".$name."', value='". $value . "'";
|
||||||
|
|
||||||
|
$lefts = $left;
|
||||||
|
$rights = $right;
|
||||||
|
$middle = $array[($left + $right) / 2][$num];
|
||||||
|
|
||||||
|
if($rights > $lefts) {
|
||||||
|
do {
|
||||||
|
if($order == "ASC") {
|
||||||
|
while($array[$lefts][$num]<$middle) $lefts++;
|
||||||
|
while($array[$rights][$num]>$middle) $rights--;
|
||||||
|
} else {
|
||||||
|
while($array[$lefts][$num]>$middle) $lefts++;
|
||||||
|
while($array[$rights][$num]<$middle) $rights--;
|
||||||
|
}
|
||||||
|
|
||||||
|
if($lefts <= $rights) {
|
||||||
|
$tmp = $array[$lefts];
|
||||||
|
$array[$lefts++] = $array[$rights];
|
||||||
|
$array[$rights--] = $tmp;
|
||||||
|
}
|
||||||
|
} while($lefts <= $rights);
|
||||||
|
|
||||||
|
$array = $this->qsort_multiarray($array,"",$order,$left,$rights,$num);
|
||||||
|
$array = $this->qsort_multiarray($array,"",$order,$lefts,$right,$num);
|
||||||
|
}
|
||||||
|
return $array;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
@ -39,6 +39,8 @@
|
|||||||
var $db;
|
var $db;
|
||||||
var $std_table="phpgw_addressbook";
|
var $std_table="phpgw_addressbook";
|
||||||
var $ext_table="phpgw_addressbook_extra";
|
var $ext_table="phpgw_addressbook_extra";
|
||||||
|
// temp table definition for listings is in read function
|
||||||
|
|
||||||
var $account_id;
|
var $account_id;
|
||||||
var $stock_contact_fields; // This is an array of almost the fields in the phpgw_addressbook table, except id,owner,lid,tid
|
var $stock_contact_fields; // This is an array of almost the fields in the phpgw_addressbook table, except id,owner,lid,tid
|
||||||
var $email_types; // VCard email type array
|
var $email_types; // VCard email type array
|
||||||
@ -202,12 +204,15 @@
|
|||||||
|
|
||||||
|
|
||||||
// send this the range, query, sort, order and whatever fields you want to see
|
// send this the range, query, sort, order and whatever fields you want to see
|
||||||
// 'rights' is unused at this time
|
// 'rights' and 'query' are unused at this time
|
||||||
function read($start,$offset,$fields="",$query="",$filter="",$sort="",$order="",$rights="")
|
function read($start,$offset,$fields="",$query="",$filter="",$sort="",$order="",$rights="")
|
||||||
{
|
{
|
||||||
global $phpgw,$phpgw_info;
|
global $phpgw,$phpgw_info;
|
||||||
|
|
||||||
|
$tmp_table="phpgw_addressbook_user".$phpgw_info["user"]["account_id"]."_cache";
|
||||||
|
|
||||||
if (!$fields || empty($fields)) { $fields = $this->stock_contact_fields; }
|
if (!$fields || empty($fields)) { $fields = $this->stock_contact_fields; }
|
||||||
$DEBUG = 1;
|
$DEBUG = 0;
|
||||||
|
|
||||||
list($stock_fields,$stock_fieldnames,$extra_fields) = $this->split_stock_and_extras($fields);
|
list($stock_fields,$stock_fieldnames,$extra_fields) = $this->split_stock_and_extras($fields);
|
||||||
if (count($stock_fieldnames)) {
|
if (count($stock_fieldnames)) {
|
||||||
@ -217,14 +222,20 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($query) { echo "DEBUG: Queries temporarily unavailable"; }
|
||||||
|
|
||||||
|
// turn filter's a=b,c=d OR a=b into an array
|
||||||
if ($filter) {
|
if ($filter) {
|
||||||
if ($DEBUG) { echo "DEBUG - Inbound filter is: #".$filter."#"; }
|
if ($DEBUG) { echo "DEBUG - Inbound filter is: #".$filter."#"; }
|
||||||
$filterarray = split(',',$filter);
|
$filterarray = split(',',$filter);
|
||||||
if ($filterarray[1]) {
|
if ($filterarray[1]) {
|
||||||
$i=0;
|
$i=0;
|
||||||
while (list($name,$value) = split('=',$filterarray[$i])) {
|
for ($i=0;$i<count($filterarray);$i++) {
|
||||||
$filterfields[$i] .= array($name => $value);
|
list($name,$value) = split("=",$filterarray[$i]);
|
||||||
$i++;
|
if ($name) {
|
||||||
|
if ($DEBUG) { echo "<br>DEBUG - Filter intermediate strings 1: #".$name."# => #".$value."#"; }
|
||||||
|
$filterfields[$name] = $value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
list($name,$value) = split('=',$filter);
|
list($name,$value) = split('=',$filter);
|
||||||
@ -234,76 +245,158 @@
|
|||||||
$filterfields = array($name => $value);
|
$filterfields = array($name => $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// now check each element of the array and convert into SQL for queries
|
||||||
|
// below
|
||||||
$i=0;
|
$i=0;
|
||||||
while (list($name,$value) = each($filterfields)) {
|
while (list($name,$value) = each($filterfields)) {
|
||||||
if ($DEBUG) { echo "<br>DEBUG - Filter intermediate strings 2: #".$name."# => #".$value."#"; }
|
if ($DEBUG) { echo "<br>DEBUG - Filter intermediate strings 2: #".$name."# => #".$value."#"; }
|
||||||
$filterlist .= $name."='".$value."',";
|
$isstd=0;
|
||||||
|
if ($name && empty($value)) {
|
||||||
|
reset($stock_fields);
|
||||||
|
while (list($fname,$fvalue)=each($stock_fields)) {
|
||||||
|
if ($fvalue==$name) {
|
||||||
|
$filterlist .= $name.' is NULL,';
|
||||||
|
$isstd=1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!$isstd) {
|
||||||
|
$filterlist2 .= 'b.'.$name.' is NULL,';
|
||||||
|
$fieldlist2 .= 'b.'.$name.',';
|
||||||
|
}
|
||||||
|
} elseif($name && $value) {
|
||||||
|
reset($stock_fields);
|
||||||
|
while (list($fname,$fvalue)=each($stock_fields)) {
|
||||||
|
if ($fvalue==$name) {
|
||||||
|
$filterlist .= $name.'="'.$value.'",';
|
||||||
|
$isstd=1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!$isstd) {
|
||||||
|
$filterlist2 .= 'b.'.$name.'="'.$value.'",';
|
||||||
|
$fieldlist2 .= 'b.'.$name.',';
|
||||||
|
}
|
||||||
|
}
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
$filterlist = substr($filterlist,0,-1);
|
$filterlist = substr($filterlist,0,-1);
|
||||||
|
$filterlist = ereg_replace(","," AND ",$filterlist);
|
||||||
|
$filterlist2 = substr($filterlist2,0,-1);
|
||||||
|
$fieldlist2 = substr($fieldlist2,0,-1);
|
||||||
|
|
||||||
if ($DEBUG) {
|
if ($DEBUG) {
|
||||||
echo "<br>DEBUG - Filter output string: #".$filterlist."#";
|
echo "<br>DEBUG - Filter output string1: #".$filterlist."#";
|
||||||
|
echo "<br>DEBUG - Filter output string2: #".$filterlist2."#";
|
||||||
}
|
}
|
||||||
|
|
||||||
list($fields,$fieldnames,$extra) = $this->split_stock_and_extras($filterfields);
|
if ($filterlist) {
|
||||||
|
$filtermethod = ' WHERE ('.$filterlist.') ';
|
||||||
if ($extra) {
|
|
||||||
while (list($name,$value) = each($extra)) {
|
|
||||||
$value = "%," . $value . ",%";
|
|
||||||
$filterextra .= " AND contact_name='".$name."' AND contact_value like '".$value."',";
|
|
||||||
}
|
|
||||||
$filterextra = substr($filterextra,0,-1);
|
|
||||||
} else {
|
|
||||||
$filterstock = " AND ($filterlist) ";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($DEBUG && ($filterextra || $filterstock)) {
|
if ($DEBUG && $filtermethod) {
|
||||||
if ($filterextra) {
|
echo "<br>DEBUG - Filtering with: #" . $filtermethod . "#";
|
||||||
echo "<br>DEBUG - Filtering on extra fields with: #" . $filterextra . "#";
|
|
||||||
}
|
|
||||||
if ($filterstock) {
|
|
||||||
echo "<br>DEBUG - Filtering on standard fields with: #" . $filterstock . "#";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$sort) { $sort = "ASC"; }
|
if (!$sort) { $sort = "ASC"; }
|
||||||
|
|
||||||
if ($order) {
|
if ($order) {
|
||||||
$ordermethod = "order by $order $sort ";
|
while (list($name,$value)=each($stock_fields)) {
|
||||||
|
if ($name == $order) {
|
||||||
|
$ordermethod = "order by a.$order $sort ";
|
||||||
|
break;
|
||||||
} else {
|
} else {
|
||||||
$ordermethod = "order by n_family,n_given,d_email $sort";
|
$ordermethod = "order by b.$order $sort ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$ordermethod = "order by a.n_family,a.n_given,a.d_email $sort";
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($DEBUG && $ordermethod) {
|
||||||
|
echo "<br>DEBUG - $ordermethod";
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->db3 = $this->db2 = $this->db; // Create new result objects before our queries
|
$this->db3 = $this->db2 = $this->db; // Create new result objects before our queries
|
||||||
|
|
||||||
if ($query) {
|
// start create sql for temp table
|
||||||
$this->db3->query("SELECT * from $this->std_table WHERE (n_family like '"
|
$tempcreate = "CREATE TABLE ".$tmp_table." (id int(11),";
|
||||||
. "%$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%') " . $filterstock . $ordermethod,__LINE__,__FILE__);
|
|
||||||
$this->total_records = $this->db3->num_rows();
|
|
||||||
|
|
||||||
$this->db->query("SELECT * from $this->std_table WHERE (n_family like '"
|
// construct query and count rows based on filter sent to function
|
||||||
. "%$query%' OR n_given like '%$query%' OR d_email like '%$query%' OR "
|
$this->db->query("select id from $this->std_table ".$filtermethod,__LINE__,__FILE__);
|
||||||
. "adr_street like '%$query%' OR adr_locality like '%$query%' OR adr_region "
|
$this->total_records = $this->db->num_rows();
|
||||||
. "like '%$query%' OR adr_postalcode like '%$query%' OR org_unit like "
|
|
||||||
. "'%$query%' OR ORG_Name like '%$query%') " . $filterstock . $ordermethod . " "
|
|
||||||
. $this->db->limit($start,$offset),__LINE__,__FILE__);
|
|
||||||
} else {
|
|
||||||
$this->db3->query("select id,lid,tid,owner $t_fields from $this->std_table "
|
|
||||||
. $filterstock,__LINE__,__FILE__);
|
|
||||||
$this->total_records = $this->db3->num_rows();
|
|
||||||
|
|
||||||
$this->db->query("select id,lid,tid,owner $t_fields from $this->std_table "
|
$i=0;
|
||||||
. $filterstock . " " . $ordermethod . " " . $this->db->limit($start,$offset),__LINE__,__FILE__);
|
while ($this->db->next_record()) {
|
||||||
|
$this->db2->query("select contact_name,contact_value from $this->ext_table where contact_id='"
|
||||||
|
. $this->db->f("id") . "'",__LINE__,__FILE__);
|
||||||
|
|
||||||
|
$tempinsert[$i] = "INSERT INTO " . $tmp_table . " (id,";
|
||||||
|
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")]) {
|
||||||
|
if (!strstr($tempcreate,$this->db2->f("contact_name"))) {
|
||||||
|
$tempcreate .= $this->db2->f("contact_name") ." TEXT,";
|
||||||
}
|
}
|
||||||
|
$tempinsert[$i] .= $this->db2->f("contact_name").",";
|
||||||
|
$tempvalues[$i] .= '"'.$this->db2->f("contact_value").'",';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$tempinsert[$i] = substr($tempinsert[$i],0,-1);
|
||||||
|
$tempvalues[$i] = substr($tempvalues[$i],0,-1);
|
||||||
|
if ($tempvalues[$i]) {
|
||||||
|
$tempval = $this->db->f("id").','.$tempvalues[$i].',';
|
||||||
|
} else {
|
||||||
|
$tempval = $this->db->f("id").',';
|
||||||
|
}
|
||||||
|
$tempinsert[$i] .= ') VALUES ('.$tempval;
|
||||||
|
$tempinsert[$i] = substr($tempinsert[$i],0,-1).")";
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// fixup strings, create and populate temp table of extra fields
|
||||||
|
$tempcreate = substr($tempcreate,0,-1) . ")";
|
||||||
|
$this->db->query("DROP TABLE IF EXISTS $tmp_table");
|
||||||
|
$this->db->query($tempcreate);
|
||||||
|
|
||||||
|
for ($i=0;$i<count($tempinsert);$i++) {
|
||||||
|
$this->db->query($tempinsert[$i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
reset($stock_fields);
|
||||||
|
reset($extra_fields);
|
||||||
|
// create strings for insertion into crosstable query below
|
||||||
|
while(list($name,$value)=each($stock_fields)) {
|
||||||
|
$std .= "a.".$name.",";
|
||||||
|
}
|
||||||
|
$std = substr($std,0,-1);
|
||||||
|
while(list($name,$value)=each($extra_fields)) {
|
||||||
|
$ext .= "b.".$name.",";
|
||||||
|
}
|
||||||
|
$ext = substr($ext,0,-1);
|
||||||
|
if (!empty($fieldlist2)) {
|
||||||
|
$filtertemp = " AND " . $filterlist2 . " ";
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($DEBUG && $filtertemp) {
|
||||||
|
echo "<br>DEBUG - Filtering with: #" . $filtertemp . "#";
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql = 'SELECT a.id,a.tid,a.lid,a.owner,b.id,'. $std . ','
|
||||||
|
. $ext . ' FROM '.$this->std_table.' AS a, '
|
||||||
|
. $tmp_table .' AS b WHERE a.id=b.id ' . $filtertemp
|
||||||
|
. $ordermethod;
|
||||||
|
|
||||||
|
$this->db3->query($sql,__LINE__,__FILE__);
|
||||||
|
$this->total_records = $this->db3->num_rows();
|
||||||
|
|
||||||
|
$this->db->query($sql. " " . $this->db->limit($start,$offset),__LINE__,__FILE__);
|
||||||
|
|
||||||
$i=0;
|
$i=0;
|
||||||
while ($this->db->next_record()) {
|
while ($this->db->next_record()) {
|
||||||
// unique id, lid for group/account records,
|
// unique id, lid for group/account records,
|
||||||
// type id (g/u) for groups/accounts, and
|
// type id (g/u) for groups/accounts/inv records, and
|
||||||
// id of owner/parent for the record
|
// id of owner/parent for the record
|
||||||
$return_fields[$i]["id"] = $this->db->f("id");
|
$return_fields[$i]["id"] = $this->db->f("id");
|
||||||
$return_fields[$i]["lid"] = $this->db->f("lid");
|
$return_fields[$i]["lid"] = $this->db->f("lid");
|
||||||
@ -311,23 +404,14 @@
|
|||||||
$return_fields[$i]["owner"] = $this->db->f("owner");
|
$return_fields[$i]["owner"] = $this->db->f("owner");
|
||||||
|
|
||||||
if (gettype($stock_fieldnames) == "array") {
|
if (gettype($stock_fieldnames) == "array") {
|
||||||
while (list($f_name) = each($stock_fieldnames)) {
|
while (list($f_name) = each($fields)) {
|
||||||
$return_fields[$i][$f_name] = $this->db->f($f_name);
|
$return_fields[$i][$f_name] = $this->db->f($f_name);
|
||||||
}
|
}
|
||||||
reset($stock_fieldnames);
|
reset($fields);
|
||||||
}
|
|
||||||
$this->db2->query("select contact_name,contact_value from $this->ext_table where contact_id='"
|
|
||||||
. $this->db->f("id") . "'" .$filterextra,__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++;
|
$i++;
|
||||||
}
|
}
|
||||||
|
$this->db->query("DROP TABLE IF EXISTS $tmp_table");
|
||||||
return $return_fields;
|
return $return_fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,9 +80,14 @@
|
|||||||
"d_emailtype" => "email type", //'INTERNET','CompuServe',etc...
|
"d_emailtype" => "email type", //'INTERNET','CompuServe',etc...
|
||||||
"d_email_work" => "", //yn
|
"d_email_work" => "", //yn
|
||||||
"d_email_home" => "", //yn
|
"d_email_home" => "", //yn
|
||||||
|
//"access" => "access"
|
||||||
|
"pager" => "Pager",
|
||||||
|
"mphone" => "mobile phone",
|
||||||
|
"ophone" => "other phone",
|
||||||
|
"address2" => "address2",
|
||||||
"bday" => "birthday",
|
"bday" => "birthday",
|
||||||
"url" => "url",
|
"url" => "url",
|
||||||
//"access" => "access"
|
"notes" => "notes"
|
||||||
);
|
);
|
||||||
|
|
||||||
while($name = each($abc) ) {
|
while($name = each($abc) ) {
|
||||||
|
@ -64,25 +64,28 @@
|
|||||||
$offset = 30;
|
$offset = 30;
|
||||||
}
|
}
|
||||||
|
|
||||||
// following sets up the filter for read, then restores the filter string for later checking
|
// Set filter to display entries where tid is blank,
|
||||||
if ($filter == "none") { $filter = ""; }
|
// else they may be accounts, etc.
|
||||||
$savefilter = $filter;
|
$savefilter = $filter;
|
||||||
// Set filter to display entries where tid is blank, else they may be accounts, etc.
|
if ($filter == "none") {
|
||||||
if ($filter != "" ) { $filter = "tid="; }
|
$filter = 'tid=';
|
||||||
//if ($filter != "" ) { $filter = "access=$filter"; }
|
} elseif($filter == "private") {
|
||||||
|
$filter = 'owner='.$phpgw_info["user"]["account_id"].',tid=';
|
||||||
$qfilter = $filter;
|
} else {
|
||||||
$filter = $savefilter;
|
$filter .= ',tid=';
|
||||||
|
}
|
||||||
|
|
||||||
if (!$columns_to_display ) {
|
if (!$columns_to_display ) {
|
||||||
$columns_to_display = array("n_given","n_family","org_name");
|
$columns_to_display = array("n_given","n_family","org_name");
|
||||||
$noprefs=lang("Please set your preferences for this app");
|
$noprefs=lang("Please set your preferences for this app");
|
||||||
}
|
}
|
||||||
$qcols = $columns_to_display + array("access");
|
$qcols = $columns_to_display;# + array("access");
|
||||||
|
|
||||||
// read the entry list
|
// read the entry list
|
||||||
if (!$userid) { $userid = $phpgw_info["user"]["account_id"]; }
|
if (!$userid) { $userid = $phpgw_info["user"]["account_id"]; }
|
||||||
$entries = addressbook_read_entries($start,$offset,$qcols,$query,$qfilter,$sort,$order,$userid);
|
$entries = addressbook_read_entries($start,$offset,$qcols,$query,$filter,$sort,$order,$userid);
|
||||||
|
// now that the query is done, reset filter, since nextmatchs grabs it globally
|
||||||
|
$filter=$savefilter;
|
||||||
|
|
||||||
$search_filter = $phpgw->nextmatchs->show_tpl("index.php",$start, $this->total_records,"&order=$order&filter=$filter&sort=$sort&query=$query","75%", $phpgw_info["theme"]["th_bg"]);
|
$search_filter = $phpgw->nextmatchs->show_tpl("index.php",$start, $this->total_records,"&order=$order&filter=$filter&sort=$sort&query=$query","75%", $phpgw_info["theme"]["th_bg"]);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user