phpgroupware-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Phpgroupware-cvs] phpgwapi/inc class.sql_mssql.inc.php, NONE, 1.1.2.1 c


From: Dave Hall <address@hidden>
Subject: [Phpgroupware-cvs] phpgwapi/inc class.sql_mssql.inc.php, NONE, 1.1.2.1 class.contact_addr.inc.php, 1.1.2.1, 1.1.2.2 class.contact_central.inc.php, 1.1.2.1, 1.1.2.2 class.contact_comm.inc.php, 1.1.2.1, 1.1.2.2 class.contact_person.inc.php, 1.1.2.1, 1.1.2.2 class.contacts_sql.inc.php, 1.17.2.2.2.6, 1.17.2.2.2.7 class.sql.inc.php, 1.1.2.2, 1.1.2.3 class.sql_builder.inc.php, 1.1.2.2, 1.1.2.3 class.sql_criteria.inc.php, 1.1.2.1, 1.1.2.2 class.sql_entity.inc.php, 1.1.2.4, 1.1.2.5 class.sql_mysql.inc.php, 1.1.2.1, 1.1.2.2 class.sql_pgsql.inc.php, 1.1.2.1, 1.1.2.2
Date: Fri, 26 Sep 2003 00:03:10 +0000

Update of /cvsroot/phpgroupware/phpgwapi/inc
In directory subversions:/tmp/cvs-serv6407/inc

Modified Files:
      Tag: Version-0_9_16-branch
        class.contact_addr.inc.php class.contact_central.inc.php 
        class.contact_comm.inc.php class.contact_person.inc.php 
        class.contacts_sql.inc.php class.sql.inc.php 
        class.sql_builder.inc.php class.sql_criteria.inc.php 
        class.sql_entity.inc.php class.sql_mysql.inc.php 
        class.sql_pgsql.inc.php 
Added Files:
      Tag: Version-0_9_16-branch
        class.sql_mssql.inc.php 
Log Message:
Fixes for bugs 5144, 5148, 5518 - from eald


Index: class.sql_mysql.inc.php
===================================================================
RCS file: /cvsroot/phpgroupware/phpgwapi/inc/Attic/class.sql_mysql.inc.php,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -C2 -d -r1.1.2.1 -r1.1.2.2
*** class.sql_mysql.inc.php     8 Sep 2003 13:26:38 -0000       1.1.2.1
--- class.sql_mysql.inc.php     26 Sep 2003 00:03:08 -0000      1.1.2.2
***************
*** 33,40 ****
                }
  
!               function concatenate($elements)
                {
                        $str =  implode(', ', $elements);
                        return ($str) ? 'concat('.$str.')' : '';
                }
        }
--- 33,47 ----
                }
  
!               function concat($elements)
                {
                        $str =  implode(', ', $elements);
                        return ($str) ? 'concat('.$str.')' : '';
+ 
+               }
+ 
+               function concat_null($elements)
+               {
+                       $str =  implode(', ', $elements);
+                       return ($str) ? 'concat('.sql::safe_null($str).')' : '';
                }
        }

Index: class.contact_central.inc.php
===================================================================
RCS file: 
/cvsroot/phpgroupware/phpgwapi/inc/Attic/class.contact_central.inc.php,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -C2 -d -r1.1.2.1 -r1.1.2.2
*** class.contact_central.inc.php       8 Sep 2003 13:26:38 -0000       1.1.2.1
--- class.contact_central.inc.php       26 Sep 2003 00:03:08 -0000      1.1.2.2
***************
*** 22,26 ****
                                                         'delete'       => '',
                                                         'sort'         => '',
!                                                        'field'        => ''),
                                 'cat_id'       => array('select'       => '',
                                                         'criteria'     => '',
--- 22,27 ----
                                                         'delete'       => '',
                                                         'sort'         => '',
!                                                        'field'        => '',
!                                                        'type'         => 
'string'),
                                 'cat_id'       => array('select'       => '',
                                                         'criteria'     => '',
***************
*** 95,99 ****
                function criteria_owner($element)
                {
!                       $this->_add_criteria($this->index_criteria($element)); 
                }
  
--- 96,100 ----
                function criteria_owner($element)
                {
!                       $this->_add_criteria($this->index_criteria($element));
                }
  

Index: class.sql.inc.php
===================================================================
RCS file: /cvsroot/phpgroupware/phpgwapi/inc/Attic/class.sql.inc.php,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -C2 -d -r1.1.2.2 -r1.1.2.3
*** class.sql.inc.php   10 Sep 2003 23:58:01 -0000      1.1.2.2
--- class.sql.inc.php   26 Sep 2003 00:03:08 -0000      1.1.2.3
***************
*** 165,169 ****
                function and_($left, $right)
                {
!                       return ' (('.$left.') AND ('.$right.')) ';
                }
  
--- 165,169 ----
                function and_($left, $right)
                {
!                       return '('.$left.' AND '.$right.')';
                }
  
***************
*** 177,181 ****
                function or_($left, $right)
                {
!                       return ' (('.$left.') OR ('.$right.')) ';
                }
  
--- 177,181 ----
                function or_($left, $right)
                {
!                       return ' ('.$left.' OR '.$right.') ';
                }
  
***************
*** 209,213 ****
                function lower($value)
                {
!                       return 'LOWER('.$vaule.')';
                }
  
--- 209,213 ----
                function lower($value)
                {
!                       return 'LOWER('.$value.')';
                }
  
***************
*** 219,229 ****
                * @return string with criteria.
                */
!               function in($field, $values)
                {
!                       return $field.' IN ('.implode(",",$values).')';
                }
  
                /**
!               * Act like a lisp and(one, two, three,...infinity)
                *
                * All and's are in same level, (without parenethesis).
--- 219,252 ----
                * @return string with criteria.
                */
!               function in($field, $values, $type='integer')
                {
!                       // This must be changed by anything
!                       if(count($values) > 1)
!                       {
!                               if($type != 'integer' && $type != '')
!                               {
!                                       return str_replace(',\'', '\',\'', 
$field.' IN (\''.implode(",'",$values)."')");
!                               }
!                               else 
!                               {
!                                       return $field.' IN ('.implode(",", 
$values) .')';
!                               }
!                       }
!                       else
!                       {
!                               $type = $type ? $type : 'integer';
!                               if (is_array($values))
!                               {
!                                       return sql::equal($field, 
sql::$type(current($values)));
!                               }
!                               else
!                               {
!                                       return sql::equal($field, 
sql::$type($values));
!                               }       
!                       }
                }
  
                /**
!               * Act like a lisp and(one, two, three,...infinity) adding 
clause with and.
                *
                * All and's are in same level, (without parenethesis).
***************
*** 363,375 ****
                \*************************************************************/
                /**
!               * Return the function that concatenate two fields
                *
                * @param array $elements array with the elemnts that want to 
concatenate
                * @return string with $elements concatenated
                */
!               function concatenate($elements)
                {
!                       $str = implode(' || ', $elements);
!                       return ($str)? '('.$str.')' : '';
                }
        }
--- 386,427 ----
                \*************************************************************/
                /**
!               * Return the function that concatenate fields on $elements
                *
                * @param array $elements array with the elemnts that want to 
concatenate
                * @return string with $elements concatenated
                */
!               function concat($elements)
                {
!               }
! 
!               /**
!               * Return the function that concatenate fields, when any 
returned value<br />
!               * is null, it changet it for empty string.
!               *
!               * @param array $elements array with the elemnts that want to 
concatenate
!               * @return string with $elements concatenated
!               */
!               function concat_null($elements)
!               {
!               }
! 
!               /**
!               * This function change to empty string, a NULL value for select.
!               *
!               * When data retrieved from database is NULL it allow change it 
to empty<br />
!               * string. use it in SELECT development.
!               * @param string $value Field or expresion to make safe.
!               */
!               function safe_null($value)
!               {
!                       if(empty($value))
!                       {
!                               return ;
!                       }
!                       foreach($value as $data)
!                       {
!                               $return_value[] = 'CASE '.$data.' WHEN NULL 
THEN \'\' ELSE '.$data;
!                       }
!                       return $return_value;
                }
        }

Index: class.contact_addr.inc.php
===================================================================
RCS file: /cvsroot/phpgroupware/phpgwapi/inc/Attic/class.contact_addr.inc.php,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -C2 -d -r1.1.2.1 -r1.1.2.2
*** class.contact_addr.inc.php  8 Sep 2003 13:26:38 -0000       1.1.2.1
--- class.contact_addr.inc.php  26 Sep 2003 00:03:08 -0000      1.1.2.2
***************
*** 336,339 ****
--- 336,340 ----
                                                      
sql_criteria::is_null($field));
                        $this->_add_criteria($criteria);
+                       return $criteria;
                }
  

Index: class.contact_comm.inc.php
===================================================================
RCS file: /cvsroot/phpgroupware/phpgwapi/inc/Attic/class.contact_comm.inc.php,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -C2 -d -r1.1.2.1 -r1.1.2.2
*** class.contact_comm.inc.php  8 Sep 2003 13:26:38 -0000       1.1.2.1
--- class.contact_comm.inc.php  26 Sep 2003 00:03:08 -0000      1.1.2.2
***************
*** 8,11 ****
--- 8,12 ----
                                                                 'delete'       
=> '',
                                                                 'sort'         
=> '',
+                                                                'type'         
=> 'integer',
                                                                 'field'        
=> 'comm_id'),
                                 'comm_contact_id'      => array('select'       
=> '',
***************
*** 15,18 ****
--- 16,20 ----
                                                                 'delete'       
=> '',
                                                                 'sort'         
=> '',
+                                                                'type'         
=> 'integer',
                                                                 'field'        
=> 'contact_id'),
                                 'comm_descr'           => array('select'       
=> '',

--- NEW FILE: class.sql_mssql.inc.php ---
<?php
  /**************************************************************************\
  * phpGroupWare API - SQL Generator for MS SQL Server                       *
  * http://www.phpgroupware.org                                              *
  * This program is part of the GNU project, see http://www.gnu.org/         *
  *                                                                          *
  * Copyright 2003 Free Software Foundation, Inc.                            *
  *                                                                          *
  * Originally Written by Edgar Antonio Luna Diaz - eald at co.com.mx        *
  * Contributions from Alejadro Borges, Jonathan Alberto Rivera Gomez        *
  * Current Maintained by Edgar Antonio Luna Diaz - eald at co.com.mx        *
  * --------------------------------------------                             *
  * Development of this application was funded by http://www.sogrp.com       *
  * --------------------------------------------                             *
  *  This program is Free Software; you can redistribute it and/or modify it *
  *  under the terms of the GNU General Public License as published by the   *
  *  Free Software Foundation; either version 2 of the License, or (at your  *
  *  option) any later version.                                              *
  \**************************************************************************/

/* $Id: class.sql_mssql.inc.php,v 1.1.2.1 2003/09/26 00:03:08 skwashd Exp $ */

        /**
        * Class that help to create criterias for common queries
        *
        * This class provide common methods to set, mantain, an retrive the 
queries to use in a query (for the where clausule).
        * @package sql
        */
        class sql extends sql_
        {
                function sql_()
                {
                }

                function concat($elements)
                {
                        $str = implode(' + ', $elements);
                        return ($str)? '('.$str.')' : '';
                }

                function concat_null($elements)
                {
                        $str = implode(' + ', $elements);
                        return ($str)? '('.sql::safe_null($str).')' : '';
                }
        }
?>

Index: class.contact_person.inc.php
===================================================================
RCS file: 
/cvsroot/phpgroupware/phpgwapi/inc/Attic/class.contact_person.inc.php,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -C2 -d -r1.1.2.1 -r1.1.2.2
*** class.contact_person.inc.php        8 Sep 2003 13:26:38 -0000       1.1.2.1
--- class.contact_person.inc.php        26 Sep 2003 00:03:08 -0000      1.1.2.2
***************
*** 240,244 ****
                        $this->set_elinks('person_id', 
'phpgwapi.contact_accounts', 'account_person_id');
                        $this->set_elinks('person_id', 
'phpgwapi.contact_org_person', 'my_person_id');
!                       $this->set_ilinks('person_id', 
'phpgwapi.contact_central','contact_id', REQUIRED_KEY);
                }
  
--- 240,244 ----
                        $this->set_elinks('person_id', 
'phpgwapi.contact_accounts', 'account_person_id');
                        $this->set_elinks('person_id', 
'phpgwapi.contact_org_person', 'my_person_id');
!                       $this->set_ilinks('person_id', 
'phpgwapi.contact_central','contact_id', PHPGW_SQL_REQUIRED_KEY);
                }
  

Index: class.sql_builder.inc.php
===================================================================
RCS file: /cvsroot/phpgroupware/phpgwapi/inc/Attic/class.sql_builder.inc.php,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -C2 -d -r1.1.2.2 -r1.1.2.3
*** class.sql_builder.inc.php   10 Sep 2003 23:58:01 -0000      1.1.2.2
--- class.sql_builder.inc.php   26 Sep 2003 00:03:08 -0000      1.1.2.3
***************
*** 51,55 ****
                var $external_from_value;
                var $external_criteria_value;
- 
                /*************************************************************\
                * Entity, class and general section                           *
--- 51,54 ----
***************
*** 134,142 ****
                function instance_entity_by_field($field)
                {
!                       $entity_name = $ent_name($field);
!                       $entity = CreateObject($entity);
!                       return array($entity_name => $entity);
                }
!               
                function instance_entity($entity_name)
                {
--- 133,141 ----
                function instance_entity_by_field($field)
                {
!                       $entity_name = $this->ent_name($field);
!                       $entity = CreateObject($entity_name);
!                       return array($entity_name, &$entity);
                }
! 
                function instance_entity($entity_name)
                {
***************
*** 148,154 ****
                        else
                        {
-                               // FIX: Broken to make a favor to jarg
-                               //$appname = 
$GLOBALS['phpgw_info']['flags']['currentapp'];
-                               //$this->entities[$ent] = 
CreateObject($appname.$ent);
                                $this->entities[$entity_name] = 
CreateObject($entity_name);
                                $this->ldebug('instance_entity',
--- 147,150 ----
***************
*** 324,368 ****
                                      'dump');
                        $this->sort_by_distances();
!                       switch($this->operation)
                        {
!                       case 'select':
!                               foreach ($this->entities as $name => $class)
                                {
!                                       list($fields, $from, $alias, 
$lcriteria) = $class->get_select();
!                                       if ($fields)
!                                       {
!                                               $this->select_fields[] = 
$fields;
!                                       }
!                                       $fields = '';
!                                       if ($lcriteria)
!                                       {
!                                               $this->all_criteria = 
sql_criteria::append_and(array($lcriteria,
!                                                                               
        $this->all_criteria));
!                                       }
                                }
-                               $from = $this->get_join();
-                               $this->fields = implode(', ', 
$this->select_fields);
-                               // hooks for add external things in my queries
-                               $this->fields = 
$this->external_select($this->fields);
-                               $from = $this->external_from ($from);
-                               $this->all_criteria = 
$this->external_criteria($this->all_criteria);
-                               $sql  = 'SELECT '.$this->fields.' FROM '.$from;
-                               $sql .= (empty($this->all_criteria))?'':' WHERE 
'.
-                                       $this->all_criteria;
-                               $this->select_fields = NULL;
-                               $this->all_criteria = NULL;
-                               $this->entities = NULL;
-                               $this->path = NULL;
-                               $this->distance = NULL;
-                               $this->false_path = NULL;
-                               $this->ldebug('get_sql', array('Entities' => 
$this->entities,
-                                                              'Path' => 
$this->path,
-                                                              'Distances' => 
$this->distance,),
-                                             'dump');
-                               $sql = $this->set_order($sql);
-                               unset($this->order_string);
-                               $this->ldebug('SQL', array('SQL String' => 
$sql));
-                               return $sql;
                        }
                }
  
--- 320,359 ----
                                      'dump');
                        $this->sort_by_distances();
!                       // var_dump($this->all_criteria);
!                       foreach ($this->entities as $name => $class)
                        {
!                               list($fields, $from, $alias, $lcriteria) = 
$class->get_select();
!                               if ($fields)
                                {
!                                       $this->select_fields[] = $fields;
!                               }
!                               $fields = '';
!                               if ($lcriteria && empty($this->all_criteria))
!                               {
!                                       $this->all_criteria = 
sql_criteria::append_and(array($lcriteria, $this->all_criteria));
                                }
                        }
+                       $from = $this->get_join();
+                       $this->fields = implode(', ', $this->select_fields);
+                       // hooks for add external things in my queries
+                       $this->fields = $this->external_select($this->fields);
+                       $from = $this->external_from ($from);
+                       $this->all_criteria = 
$this->external_criteria($this->all_criteria);
+                       $sql  = 'SELECT '.$this->fields.' FROM '.$from;
+                       $sql .= (empty($this->all_criteria))?'':' WHERE '. 
$this->all_criteria;
+                       $this->select_fields = NULL;
+                       $this->all_criteria = NULL;
+                       $this->entities = NULL;
+                       $this->path = NULL;
+                       $this->distance = NULL;
+                       $this->false_path = NULL;
+                       $this->ldebug('get_sql', array('Entities' => 
$this->entities,
+                                               'Path' => $this->path,
+                                               'Distances' => 
$this->distance,),
+                               'dump');
+                       $sql = $this->set_order($sql);
+                       unset($this->order_string);
+                       $this->ldebug('SQL', array('SQL String' => $sql));
+                       return $sql;
                }
  
***************
*** 586,593 ****
                * @param string $field false field name
                */
!               function real_name($field)
                {
!                       list($entity, $instance) = 
$this->instance_entity_by_field($field); 
!                       return $instance->real_field($field);
                }
  
--- 577,645 ----
                * @param string $field false field name
                */
!               function real_name($field, $operation='insert')
                {
!                       list($entity_name, $entity) = 
$this->instance_entity_by_field($field);
! //                    echo "<br>field is ";
! //                    var_dump($field);
!                       $entity->set_operation($operation);
!                       return 
$entity->real_field($entity->put_real_alias($field));
!               }
! 
!               /**
!               * Get the real name for $field based on the map and instantiate 
the entity
!               *
!               * @param string $field false field name
!               */
!               function real_field_entity($field, $operation='')
!               {
!                       list($entity, $instance) = 
$this->instance_entity_by_field($field);
!                       $instance->set_opertation($operation);
!                       $this->entities[$entity] = $entity;
!                       return 
$instance->real_field($instance->put_real_alias($field));
!               }
! 
!               /**
!               * Cast value for datatype
!               * 
!               * @param mixed $value Which we go to cast
!               * @param string $field field name to know the datatype
!               * @param boolean $permanent decide if we want to preserv the 
instance of the entity in $entities array
!               */
!               function cast($value, $field, $permanent=True)
!               {
!                       $entity = $this->ent_name($field);
!                       $instance = $this->instance_volatile($entity, 
$permanent);
!                       return $instance->cast($value, $field);
!               }
! 
! 
!               /**
!               * Instance an entity for permant usage of for remove at instant
!               * 
!               * $permanent don't have any effect if entity already exist in 
$entities array.
!               * @param mixed $value Which we go to cast
!               * @param string $field field name to know the datatype
!               * @param boolean $permanent decide if we want to preserv the 
instance of the entity in $entities array
!               */
!               function instance_volatile($entity, $permanent=True)
!               {
!                       if(is_object($this->entities[$entity]))
!                       {
!                               $entity =& $this->entities[$entity];
!                               return $entity;
!                       }
!                       else
!                       {
!                               $instance = CreateObject($entity);
!                               if($permanent)
!                               {
!                                       $this->entities[$entity] = $instance;
!                                       return $this->entities[$entity];
!                               }
!                               else
!                               {
!                                       return $instance = 
CreateObject($entity);
!                               }
!                       }
                }
  
***************
*** 625,681 ****
                # Third operator IS_ a operator name that send to 
sql::operate();
                * @param array $data Genertaded by calls of sql class.
                */
!               function _criteria($data)
                {
!                       $num_elements = count($data);
                        switch($num_elements)
                        {
                        case 0:
                        case 1:
!                               $local_criteria = $data;
                                break;
                        case 2:
                        case 3:
!                               $operator = array_pop($data);
!                               $left = first($data);
!                               $right = next($data);
!                               if(is_array($left) && $operator != '_in')
                                {
!                                       $left = $this->criteria($left);
                                }
                                else
                                {
!                                       $entity = $this->get_entity($field);
!                                       $left = 
$this->entities[$entity]->alias_field($field);
                                }
                                if(is_array($right))
                                {
!                                       $right = $this->criteria($right);
                                }
!                               if ($operator == '_match')
                                {
!                                       
$this->entities[$entity]->add_criteria($left,$right);
                                }
                                else
                                {
!                                       $local_criteria = 
sql::operate($operator,$left,right);
                                }
                                break;
                        default:
!                               foreach($data as $element)
                                {
!                                       if (is_array($element))
!                                       {
!                                               $this->criteria($element);
!                                       }
!                                       elseif ($element == '_append_and' || 
$element == '_append_or')
!                                       {
!                                               $local_criteria = 
sql::$operator($element, $stack);
!                                       }
!                                       else
!                                       {
!                                               $stack[] = 
$this->criteria($element);
!                                       }
                                }
                        }
                        return $local_criteria;
--- 677,739 ----
                # Third operator IS_ a operator name that send to 
sql::operate();
                * @param array $data Genertaded by calls of sql class.
+               * @param string $operation Is one of: insert, select, delete, 
update, if is diferent to select, then the result will not include the alias 
for table.
+               * @return Criteria for any sql query.
                */
!               function builder_criteria($token_criteria, $operation='insert')
                {
!                       $num_elements = count($token_criteria);
                        switch($num_elements)
                        {
                        case 0:
                        case 1:
!                               $local_criteria = $token_criteria;
                                break;
                        case 2:
                        case 3:
!                               $operator = array_pop($token_criteria);
!                               $left = array_shift($token_criteria);
!                               $right = array_shift($token_criteria);
!                               if(is_array($left) && $operator != 'in')
                                {
!                                       $left = $this->builder_criteria($left, 
$operation);
                                }
                                else
                                {
!                                       $entity = $this->get_entity($left);
!                                       
$this->entities[$entity]->set_operation($operation);
!                                       $field = $left;
!                                       $left = 
$this->entities[$entity]->put_real_alias($this->real_field($entity, $left));
                                }
                                if(is_array($right))
                                {
!                                       if ($operator != 'in') 
!                                       {
!                                               $right = 
$this->builder_criteria($right, $operation);
!                                       }
                                }
!                               else
                                {
!                                       if($field && !($operator == 'has' || 
$operator == 'begin_with' || $operator == 'end_with'))
!                                       {
!                                               $right = 
$this->entities[$entity]->cast($right, $field);
!                                       }
!                               }
!                               if ($operator == 'append_and' || $operator == 
'append_or')
!                               {
!                                       $param = array($left, $right);
!                                       $local_criteria = 
sql_criteria::operate($operator,$param);                                      
                                }
                                else
                                {
!                                       $local_criteria = 
sql_criteria::operate($operator,$left,$right);
                                }
                                break;
                        default:
!                               $operator = array_pop($token_criteria);
!                               foreach($token_criteria as $criteria)
                                {
!                                       $criterias[] = 
$this->builder_criteria($criteria, $operation);
                                }
+                               $local_criteria = 
sql_criteria::operate($operator,$criterias);
                        }
                        return $local_criteria;
***************
*** 683,686 ****
--- 741,752 ----
  
                /**
+               * This is an optional criteria generator, powerfull because use 
sql_criteria and sql_entity
+               */
+               function criteria_token($criteria, $operation='select')
+               {
+                       $this->all_criteria = 
$this->builder_criteria($criteria, $operation);
+               }
+ 
+               /**
                * Set the criteria to correspoding class
                * 
***************
*** 970,974 ****
                        $entity = $this->get_entity($field);
                        $real_name = 
$this->entities[$entity]->real_field($field);
!                       $criteria = 
$this->entities[$entity]->index_criteria(array('real_field' => $real_name, 
'value' => $value));
                        return $this->entities[$entity]->delete($criteria, 
$action);
                        unset($this->entities[$entity]);
--- 1036,1040 ----
                        $entity = $this->get_entity($field);
                        $real_name = 
$this->entities[$entity]->real_field($field);
!                       $criteria = 
$this->entities[$entity]->index_criteria(array('real_field' => $real_name, 
'value' => $value, 'field' => $field));
                        return $this->entities[$entity]->delete($criteria, 
$action);
                        unset($this->entities[$entity]);
***************
*** 1098,1103 ****
                function ldebug($myfoo, $data, $type = 'string', $err = '')
                {
! //                    if (!((($myfoo != '_add') xor
! //                           ($myfoo != '')) xor
  //                          ($myfoo == '')) xor
  //                        ($myfoo == ''))
--- 1164,1169 ----
                function ldebug($myfoo, $data, $type = 'string', $err = '')
                {
! //                    if (!((($myfoo != 'SQL') xor
! //                           ($myfoo != 'criteria')) xor
  //                          ($myfoo == '')) xor
  //                        ($myfoo == ''))

Index: class.sql_entity.inc.php
===================================================================
RCS file: /cvsroot/phpgroupware/phpgwapi/inc/Attic/class.sql_entity.inc.php,v
retrieving revision 1.1.2.4
retrieving revision 1.1.2.5
diff -C2 -d -r1.1.2.4 -r1.1.2.5
*** class.sql_entity.inc.php    16 Sep 2003 23:28:05 -0000      1.1.2.4
--- class.sql_entity.inc.php    26 Sep 2003 00:03:08 -0000      1.1.2.5
***************
*** 117,127 ****
                * Determines whether if operation must be changed or not.
                *
!               * @param string $action Actual action that is proposed to be 
the operation.
                */
!               function set_operation($action)
                {
!                       if (empty($this->operation) && $action != 'criteria')
                        {
!                               $this->operation = $action;
                        }
                }
--- 117,142 ----
                * Determines whether if operation must be changed or not.
                *
!               * Operation is used to decide if alias is attached to fields 
names or not
!               * @param string $opertation Actual action that is proposed to 
be the operation.
                */
!               function set_operation($operation)
                {
!                       if (empty($this->operation) && $operation != 'criteria' 
&& !empty($operation))
                        {
!                               $this->operation = $operation;
!                       }
!               }
! 
!               /**
!               * Forced change of actual operation
!               *
!               * Operation is used to decide if alias is attached to fields 
names or not
!               * @param string $operation action to be set.
!               */
!               function change_operation($operation)
!               {
!                       if (!empty($operation) && $operation != 'criteria')
!                       {
!                               $this->operation = $operation;
                        }
                }
***************
*** 176,179 ****
--- 191,203 ----
                }
  
+               /**
+               * Set the alias to a any field
+               * @param string $field Name of the field.
+               * @return the string ready for replace s/EASS/alias/
+               */
+               function put_real_alias($field)
+               {
+                       return ($this->operation == 'select')? 
$this->alias.'.'.$field : $field;
+               }
                /*************************************************************\
                * Select section                                              *
***************
*** 335,339 ****
                                elseif(count($element['value']) > 1)
                                {
!                                       return sql_criteria::in($field, 
$element['value']);
                                }
                        }
--- 359,363 ----
                                elseif(count($element['value']) > 1)
                                {
!                                       return sql_criteria::in($field, 
$element['value'], $this->get_datatype($field));
                                }
                        }
***************
*** 360,364 ****
                        - `in' is a three element: 1. field name, 2. array with 
values, 3. token
                        */
!                       
                        $num_elements = count($token_criteria);
                        switch($num_elements)
--- 384,388 ----
                        - `in' is a three element: 1. field name, 2. array with 
values, 3. token
                        */
! 
                        $num_elements = count($token_criteria);
                        switch($num_elements)
***************
*** 508,517 ****
                }
  
                function cast($data, $false_field)
                {
                        $type = $this->get_datatype($false_field);
                        return ($data == sql::null())? sql::null() : 
sql::$type($data);
!               }               
!               
                /**
                * Genarete the insert string
--- 532,553 ----
                }
  
+               /**
+               * Get the right value for the datatype of the false field
+               * 
+               * @param mixed $data value that want to cast.
+               * @param string $false_field Field for search datatype
+               * @return string Corresponding string with sql for datatype
+               */
                function cast($data, $false_field)
                {
+                       if(is_array($data))
+                       {
+                               return $this->index_criteria($data);
+                       
+                       }
                        $type = $this->get_datatype($false_field);
                        return ($data == sql::null())? sql::null() : 
sql::$type($data);
!               }
! 
                /**
                * Genarete the insert string

Index: class.sql_pgsql.inc.php
===================================================================
RCS file: /cvsroot/phpgroupware/phpgwapi/inc/Attic/class.sql_pgsql.inc.php,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -C2 -d -r1.1.2.1 -r1.1.2.2
*** class.sql_pgsql.inc.php     8 Sep 2003 13:26:38 -0000       1.1.2.1
--- class.sql_pgsql.inc.php     26 Sep 2003 00:03:08 -0000      1.1.2.2
***************
*** 21,26 ****
  /* $Id$ */
  
- 
- 
        /**
        * Class that help to create criterias for common queries
--- 21,24 ----
***************
*** 35,38 ****
--- 33,51 ----
                }
  
+               function concat($elements)
+               {
+                       $str = implode(' || ', $elements);
+                       return ($str)? '('.$str.')' : '';
+               }
+ 
+               function concat_null($elements)
+               {
+                       $str = implode(' || ', $elements);
+                       return ($str)? '('.sql::safe_null($str).')' : '';
+               }
+               function has($field, $value)
+               {
+                       return sql_criteria::upper($field).' ILIKE 
'."'%$value%'";
+               }
        }
  ?>

Index: class.contacts_sql.inc.php
===================================================================
RCS file: /cvsroot/phpgroupware/phpgwapi/inc/class.contacts_sql.inc.php,v
retrieving revision 1.17.2.2.2.6
retrieving revision 1.17.2.2.2.7
diff -C2 -d -r1.17.2.2.2.6 -r1.17.2.2.2.7
*** class.contacts_sql.inc.php  16 Sep 2003 23:28:04 -0000      1.17.2.2.2.6
--- class.contacts_sql.inc.php  26 Sep 2003 00:03:08 -0000      1.17.2.2.2.7
***************
*** 23,30 ****
        include(PHPGW_API_INC . '/class.sql_entity.inc.php');
  
        /**
        * Contact Management System
!       * This class provides a contact database scheme.
!       * It attempts to be based on the vcard 2.1 standard, with mods as 
needed to make for more reasonable sql storage.
        * Note that changes here must also work in the LDAP version.
        * @package contacts
--- 23,36 ----
        include(PHPGW_API_INC . '/class.sql_entity.inc.php');
  
+       define(PHPGW_CONTACTS_CATEGORIES_ALL, -3);
+       define(PHPGW_CONTACTS_ALL, 1);
+       define(PHPGW_CONTACTS_MINE, 2);
+       define(PHPGW_CONTACTS_PRIVATE, 3);
+ 
        /**
        * Contact Management System
!       *
!       * This class provides a contact database scheme. <br>
!       * It attempts to be based on the vcard 2.1 standard, <br>  with mods as 
needed to make for more reasonable sql storage. <br>
        * Note that changes here must also work in the LDAP version.
        * @package contacts
***************
*** 39,43 ****
                var $account_id = 0;
                var $total_records = 0;
!               var $grants = '';
                /**
                * All exporteds fields
--- 45,49 ----
                var $account_id = 0;
                var $total_records = 0;
!               var $grants;
                /**
                * All exporteds fields
***************
*** 468,471 ****
--- 474,482 ----
                                  'email'       => array('Bussiness', 'email'),
                                  'email_home'  => array('Home', 'email'));
+               /**
+               * Describe the type of contact, this var know the type of 
contact.
+               */
+               var $_contact_person;
+               var $_contact_org;
  
                function contacts_($session=True)
***************
*** 529,534 ****
                                $this->contact_type = 
$this->get_contact_types();
                        }
!                       $this->tab_main_persons = 'Persons';
!                       $this->tab_main_organizations = 'Organizations';
                }
  
--- 540,545 ----
                                $this->contact_type = 
$this->get_contact_types();
                        }
!                       $this->_contact_person = 'Persons';
!                       $this->_contact_org = 'Organizations';
                }
  
***************
*** 545,548 ****
--- 556,579 ----
                }
  
+               /**
+               * Get the information about contact of type `person'
+               *
+               * @return string
+               */
+               function get_person_name()
+               {
+                       return $this->_contact_person;
+               }
+ 
+               /**
+               * Get the information about contact of type `Organization'
+               *
+               * @return string
+               */
+               function get_org_name()
+               {
+                       return $this->_contact_org;
+               }
+               
                /*************************************************************\
                * Deprecated functions section                                *
***************
*** 558,564 ****
                        $this->db->query($sql_select,__LINE__,__FILE__);
                        $this->db->next_record();
!                       
                        $return_fields = &$this->db->Record;
!                       
                        $return_extra_fields = 
read_extra_fields($return_fields['contact_id']);
  
--- 589,595 ----
                        $this->db->query($sql_select,__LINE__,__FILE__);
                        $this->db->next_record();
! 
                        $return_fields = &$this->db->Record;
! 
                        $return_extra_fields = 
read_extra_fields($return_fields['contact_id']);
  
***************
*** 566,569 ****
--- 597,624 ----
                }
  
+               /* This function get all the Communication media from one 
contact.
+               *
+               * Or the first if there is no one marked as preferred.
+               * @param integer $contact_id id to locate the contact
+               * return array Form: (description => value, description => 
value, ...)
+               */
+               function get_all_comms($contact_id)
+               {
+                       if (intval($contact_id) != 0)
+                       {
+                               // get all comm_descriptions from api function
+                               $this->request(array('comm_data', 
'comm_descr'));
+                               $this->criteria(array('comm_contact_id' => 
$contact_id));
+                               // get all comms from db
+                               $records = $this->get_query(PHPGW_SQL_RUN_SQL, 
__LINE__, __FILE__);
+                               foreach ($records as $comm)
+                               {
+                                       $descr = 
$this->search_comm_descr_id($comm['comm_descr']);
+                                       $comms[$descr] = $comm['comm_data'];    
+                               }
+                       }
+                       return $comms;
+               }
+ 
                function read_last_entry($fields='')
                {
***************
*** 621,625 ****
                        list($data['comms'], $data['locations'], 
$data['others']) = $this->slice_old_fields($fields);
                        $catogeries = array($fields['cat_id']);
!                       $this->add_contact($this->tab_main_persons, $principal, 
$data['comms'], $data['locations'], categories, $data['others']);
                }
  
--- 676,680 ----
                        list($data['comms'], $data['locations'], 
$data['others']) = $this->slice_old_fields($fields);
                        $catogeries = array($fields['cat_id']);
!                       $this->add_contact($this->_contact_person, $principal, 
$data['comms'], $data['locations'], categories, $data['others']);
                }
  
***************
*** 724,731 ****
                * @param string $orderby The field which you want order
                * @param string $sort ASC | DESC depending what you want
!               * @param array $criteria All criterias what you want
                * @return array with records
                */
!               function get_persons($fields, $limit='', $ofset='', 
$orderby='', $sort='', $criteria='')
                {
                        $this->request($fields);
--- 779,787 ----
                * @param string $orderby The field which you want order
                * @param string $sort ASC | DESC depending what you want
!               * @param mixed $criteria All criterias what you want
!               * @param mixed $criteria_token same like $criteria but 
builded<br>with sql_criteria class, more powerfull
                * @return array with records
                */
!               function get_persons($fields, $limit='', $ofset='', 
$orderby='', $sort='', $criteria='', $criteria_token='')
                {
                        $this->request($fields);
***************
*** 733,738 ****
                        {
                                $this->criteria($criteria);
                        }
-                       $this->criteria(array('contact_type' => 
$this->search_contact_type($this->tab_main_persons)));
  
                        if($orderby)
--- 789,800 ----
                        {
                                $this->criteria($criteria);
+                               $this->criteria(array('contact_type' => 
$this->search_contact_type($this->_contact_person)));
+ 
+                       }
+                       else
+                       {
+                               $criteria_token = 
sql_criteria::token_and(sql_criteria::_equal('contact_type', 
$this->search_contact_type($this->_contact_person)), $criteria_token);
+                               $this->criteria_token($criteria_token);
                        }
  
                        if($orderby)
***************
*** 740,746 ****
                                $this->order(array($orderby), $sort);
                        }
-                       
                        $sql = $this->get_sql();
- 
                        if ($limit)
                        {
--- 802,806 ----
***************
*** 818,824 ****
                * @param string $sort ASC | DESC depending what you want
                * @param array $criteria All criterias what you want
                * @return array with records
                */
!               function get_orgs($fields, $limit='', $ofset='', $orderby='', 
$sort='', $criteria='')
                {
                        $this->request($fields);
--- 878,885 ----
                * @param string $sort ASC | DESC depending what you want
                * @param array $criteria All criterias what you want
+               * @param mixed $criteria_token same like $criteria but 
builded<br>with sql_criteria class, more powerfull
                * @return array with records
                */
!               function get_orgs($fields, $limit='', $ofset='', $orderby='', 
$sort='', $criteria='', $criteria_token='')
                {
                        $this->request($fields);
***************
*** 826,831 ****
                        {
                                $this->criteria($criteria);
                        }
-                       $this->criteria(array('contact_type' => 
$this->search_contact_type($this->tab_main_organizations)));
                        
                        if($orderby)
--- 887,897 ----
                        {
                                $this->criteria($criteria);
+                               $this->criteria(array('contact_type' => 
$this->search_contact_type($this->_contact_org)));
+                       }
+                       else
+                       {
+                               $criteria_token = 
sql_criteria::token_and(sql_criteria::_equal('contact_type', 
$this->search_contact_type($this->_contact_org)), $criteria_token);
+                               $this->criteria_token($criteria_token);
                        }
                        
                        if($orderby)
***************
*** 912,921 ****
                        $this->request($data);
                        $this->criteria(array('comm_contact_id' => 
$contact_id));
! 
!                       if($fields_to_search!='')
                        {
                                $this->criteria(array('comm_find_descr' => 
$fields_to_search));
                        }
!                       
                        $entry =  $this->get_records(__LINE__, __FILE__);
                        if($entry)
--- 978,986 ----
                        $this->request($data);
                        $this->criteria(array('comm_contact_id' => 
$contact_id));
!                       if(!empty($fields_to_search))
                        {
                                $this->criteria(array('comm_find_descr' => 
$fields_to_search));
                        }
! 
                        $entry =  $this->get_records(__LINE__, __FILE__);
                        if($entry)
***************
*** 1074,1078 ****
                        if($criteria!='')
                        {
!                               $this->criteria($criteria);
                        }
                        $count =  $this->get_query($action, __LINE__, __FILE__);
--- 1139,1143 ----
                        if($criteria!='')
                        {
!                               $this->criteria_token($criteria);
                        }
                        $count =  $this->get_query($action, __LINE__, __FILE__);
***************
*** 1092,1096 ****
                        if($criteria!='')
                        {
!                               $this->criteria($criteria);
                        }
                        $count =  $this->get_query($action, __LINE__, __FILE__);
--- 1157,1161 ----
                        if($criteria!='')
                        {
!                               $this->criteria_token($criteria);
                        }
                        $count =  $this->get_query($action, __LINE__, __FILE__);
***************
*** 1239,1243 ****
                        $sql = 'SELECT cat2.cat_id FROM phpgw_categories as cat 
'
                                .'INNER JOIN phpgw_categories as cat2 ON 
cat.cat_id=cat2.cat_parent '
!                               .'WHERE cat.cat_id in (' . implode(",", 
$cat_id) . ')';
                        
                        $this->db->query($sql, __LINE__, __FILE__);
--- 1304,1308 ----
                        $sql = 'SELECT cat2.cat_id FROM phpgw_categories as cat 
'
                                .'INNER JOIN phpgw_categories as cat2 ON 
cat.cat_id=cat2.cat_parent '
!                               .'WHERE '.sql::in('cat.cat_id', $cat_id);
                        
                        $this->db->query($sql, __LINE__, __FILE__);
***************
*** 1249,1253 ****
                        if(is_array($cats))
                        {
!                               return array_merge($cats,  
$this->get_sub_cats($cats));
                        }
                }
--- 1314,1318 ----
                        if(is_array($cats))
                        {
!                               return array_merge($cats, 
$this->get_sub_cats($cats));
                        }
                }
***************
*** 1464,1472 ****
                        switch($add_type)
                        {
!                       case $this->tab_main_persons:
                                $this->add_person($principal, $cid, 
PHPGW_SQL_RUN_SQL);
                                $this->add_orgs_for_person($contact_relations, 
$principal['preferred_org'], $principal['preferred_address'], $cid, 
PHPGW_SQL_RUN_SQL);
                                break;
!                       case $this->tab_main_organizations:
                                $this->add_org($principal, $cid, 
PHPGW_SQL_RUN_SQL);
                                
$this->add_people_for_organzation($contact_relations, $cid, PHPGW_SQL_RUN_SQL);
--- 1529,1537 ----
                        switch($add_type)
                        {
!                       case $this->_contact_person:
                                $this->add_person($principal, $cid, 
PHPGW_SQL_RUN_SQL);
                                $this->add_orgs_for_person($contact_relations, 
$principal['preferred_org'], $principal['preferred_address'], $cid, 
PHPGW_SQL_RUN_SQL);
                                break;
!                       case $this->_contact_org:
                                $this->add_org($principal, $cid, 
PHPGW_SQL_RUN_SQL);
                                
$this->add_people_for_organzation($contact_relations, $cid, PHPGW_SQL_RUN_SQL);
***************
*** 1552,1556 ****
                function add_people_for_organzation($people, $cid, 
$action=PHPGW_SQL_RETURN_SQL)
                {
!                       if(is_array($people))
                        {
                                foreach($people as $person)
--- 1617,1629 ----
                function add_people_for_organzation($people, $cid, 
$action=PHPGW_SQL_RETURN_SQL)
                {
!                       if(!is_array($people))
!                       {
! //                            echo "There is no any person to add in your 
array";
! //                            This must be a critical error to stop 
everything?
! //                            $GLOBALS['phpgw']->exit();
!                               return;
!                       }
! 
!                       foreach($people as $person)
                        {
                                foreach($people as $person)
***************
*** 1614,1618 ****
                {
                        $this->location = CreateObject('phpgwapi.contact_addr');
!                       $this->lock_table($this->location->table);
  
                        $location['addr_creatby']=1;
--- 1687,1694 ----
                {
                        $this->location = CreateObject('phpgwapi.contact_addr');
!                       if ($action == PHPGW_SQL_RUN_SQL)
!                       {
!                               $this->lock_table($this->location->table);
!                       }
  
                        $location['addr_creatby']=1;
***************
*** 1636,1640 ****
                {       
                        $this->comm = CreateObject('phpgwapi.contact_comm');
!                       $this->lock_table($this->comm->table);
  
                        $comm['comm_creatby']=1;
--- 1712,1719 ----
                {       
                        $this->comm = CreateObject('phpgwapi.contact_comm');
!                       if ($action == PHPGW_SQL_RUN_SQL)
!                       {
!                               $this->lock_table($this->comm->table);
!                       }
  
                        $comm['comm_creatby']=1;
***************
*** 1658,1662 ****
                {
                        $this->others = CreateObject('phpgwapi.contact_others');
!                       $this->lock_table($this->others->table);
                        unset($others['key_other_id']);
  
--- 1737,1745 ----
                {
                        $this->others = CreateObject('phpgwapi.contact_others');
!                       if ($action == PHPGW_SQL_RUN_SQL)
!                       {
!                               $this->lock_table($this->others->table);
!                       }
! 
                        unset($others['key_other_id']);
  
***************
*** 1678,1682 ****
                        $type = ($type)? $type : $this->get_type_contact($cid);
  
!                       $type = ($type == $this->tab_main_persons)? 'person' : 
'org';
  
                        if(empty($entity_keys))
--- 1761,1765 ----
                        $type = ($type)? $type : $this->get_type_contact($cid);
  
!                       $type = ($type == $this->_contact_person)? 'person' : 
'org';
  
                        if(empty($entity_keys))
***************
*** 1860,1865 ****
                                        $row['contact_id'];
                                }
-                               //var_export($contacts);
-                               //$this->delete_($contacts);
                        }
                        return;
--- 1943,1946 ----
***************
*** 1867,1871 ****
  
                /*************************************************************\
!               * Misela functions section                                    *
                \*************************************************************/
  
--- 1948,1952 ----
  
                /*************************************************************\
!               * Misc functions section                                     *
                \*************************************************************/
  
***************
*** 1909,1913 ****
                }
                
!               function get_records_by_field($field, $line, $file)
                {
                        $this->execute_query($this->get_sql(),$line,$file);
--- 1990,1994 ----
                }
                
!               function get_records_by_field($field, $line=__LINE__, 
$file=__FILE__)
                {
                        $this->execute_query($this->get_sql(),$line,$file);
***************
*** 2039,2042 ****
--- 2120,2195 ----
                }
  
+               /*************************************************************\
+               * Filters section                                            *
+               \*************************************************************/
+ 
+               /**
+               * Create a criteria with or and like operators for all the 
fields
+               */
+               function search_by_any($fields)
+               {
+                       foreach($fields as $field => $value)
+                       {
+                               if ($value == NULL)
+                               {
+                                       continue;
+                               }
+                               if (is_array($value))
+                               {
+                                       if(in_array('append_or', $value) || 
in_array('append_and', $value))
+                                       {
+                                               $elements[] = $value;
+                                       }
+                                       else
+                                       {
+                                               $elements[] = 
sql_criteria::in($field, $value);
+                                       }
+                               }
+                               else
+                               {
+                                       $elements[] = 
sql_criteria::token_has($field, $value);
+                               }
+                       }
+                       return sql_criteria::_append_or($elements);
+               }
+               
+               /**
+               * Create a criteria with `and' and the corresponding operator 
of each field.
+               */
+               function search_by_all($fields)
+               {
+                       foreach($fields as $field => $value)
+                       {
+                               if ($value == NULL)
+                               {
+                                       continue;
+                               }
+ 
+                               if (is_array($value))
+                               {
+                                       if(in_array('append_or', $value) || 
in_array('append_and', $value))
+                                       {
+                                               $elements[] = $value;
+                                       }
+                                       else
+                                       {
+                                               if (count($value) == 1)
+                                               {
+                                                       $elements[] = 
sql_criteria::_equal($field, current($value));
+                                               }
+                                               else
+                                               {
+                                                       $elements[] = 
sql_criteria::_in($field, $value);
+                                               }
+                                       }
+                               }
+                               else
+                               {
+                                       $elements[] = 
sql_criteria::_equal($field, $value);
+                               }
+                       }
+                       return sql_criteria::_append_and($elements);
+               }
+ 
                /**
                * Get the all contacts which are from specified owner
***************
*** 2233,2236 ****
--- 2386,2485 ----
  
                /**
+               * Retrieve the criteria for index addressbook implementation.
+               *
+               * Could be used in others parts but thinks that it was 
created<br />
+               * with that propouse.
+               * This looks for the categories and for the acl perms.
+               *
+               * @param integer $owner this is the actual user of phpgroupware
+               *
+               * @param mixed $access This is limit the search for private 
only<br />
+               * (with PHPGW_CONTACTS_PRIVATE), all my 
contacts(PHPGW_CONTACTS_MINE)<br />
+               * or all the records I have access (PHPGW_CONTACTS_ALL).
+               *
+               * @param integer $categories if have any value then limit the 
result<br />
+               * to contacts that belongs to this categories (and childs) <br 
/>PHPGW_CONTACTS_CATEGORIES_ALL if want not use categories criterias.
+               *
+               * @param array $search_fields this is used in search, is the<br 
/>
+               * list of fields to search. Also this list is used to know if 
we<br />
+               * need to set the criteria for search the prefered addresses 
for contacts.
+               *
+               * @param string $pattern Is the string that will be used to 
search in<br />
+               * all fields of $search_fields, set value to this param 
without<br />
+               * setting $search_field is useless.
+               */
+               function criteria_for_index($owner, $access=PHPGW_CONTACTS_ALL, 
$categories=PHPGW_CONTACTS_CATEGORIES_ALL, $search_fields=array(), $pattern='')
+               {
+                       if(!is_numeric($owner) || intval($owner) == 0)
+                       {
+                               return ;
+                       }
+                       switch($access)
+                       {
+                       case PHPGW_CONTACTS_MINE:
+                               $criteria = sql_criteria::_equal('owner', 
$owner);
+                               break;
+                       case PHPGW_CONTACTS_PRIVATE:
+                               $criteria = 
sql_criteria::token_and(sql_criteria::_equal('access', 'private'),
+                                                               
sql_criteria::_equal('owner', $owner));
+                               break;
+                       case PHPGW_CONTACTS_ALL:
+                       default:
+                               $criteria = 
sql_criteria::token_or(sql_criteria::token_and(sql_criteria::_equal('access', 
'public'),
+                                                                               
sql_criteria::_in('owner', $this->get_contacts_shared($owner, PHPGW_ACL_READ))),
+                                                                  
sql_criteria::_equal('owner', $owner));
+                               break;
+                       }
+                       if($categories != PHPGW_CONTACTS_CATEGORIES_ALL)
+                       {
+                               $categories_array = 
array_merge(array($categories), $this->get_sub_cats($categories));
+                               if(count($categories_array) > 0)
+                               {
+                                       foreach($categories_array as $cat_id)
+                                       {
+                                               $search_categories[] = 
sql_criteria::token_or(sql_criteria::_equal('sel_cat_id', $cat_id),
+                                                                               
        sql_criteria::token_has('sel_cat_id', ','.$cat_id.','));
+                                       }
+                                       $categories_criteria = 
sql_criteria::_append_or($search_categories);
+                                       $criteria = 
sql_criteria::token_and($criteria, $categories_criteria);
+                               }
+                       }
+                       if(count($search_fields) > 0 && $pattern)
+                       {
+                               foreach($search_fields as $field)
+                               {
+                                       $search_array[] = 
sql_criteria::token_has($field, $pattern);
+                               }
+                               $search_criteria = 
sql_criteria::_append_or($search_array);
+                               $location = 
CreateObject('phpgwapi.contact_addr');
+                               
if(count(array_intersect($location->get_false_fields(), $search_fields)) > 0)
+                               {
+                                       $addr_preferred_criteria = 
sql_criteria::token_or(sql_criteria::_equal('addr_pref_val', 'Y'),
+                                                                               
        sql_criteria::_is_null('key_addr_id'));
+                                       $search_criteria = 
sql_criteria::token_and($search_criteria, $addr_preferred_criteria);
+                               }
+                               $criteria = sql_criteria::token_and($criteria, 
$search_criteria);
+                       }
+                       return $criteria;
+               }
+ 
+               function get_contacts_shared($owner_id, 
$acl_type=PHPGW_ACL_READ)
+               {
+                       $this->grants = 
$GLOBALS['phpgw']->acl->get_grants('addressbook');
+                       foreach($this->grants as $owner => $perm)
+                       {
+                               if($this->check_perms($perm, $acl_type))
+                               {
+                                       $required_grants[] = $owner;
+                               }
+                       }
+                       return $required_grants;
+               }
+ 
+               function check_perms($has, $needed)
+               {
+                       return (!!($has & $needed) == True);
+               }
+               /**
                * Copy all contact data to new contact
                *
***************
*** 2408,2414 ****
                function slice_old_fields($fields, $data_type)
                {
- //                                              'email_home_type'     => 
'email_home_type');
- //                                      'email_type'  => array('email_type',
- 
                        foreach ($comm_old as $old_field => $value)
                        {
--- 2657,2660 ----
***************
*** 2453,2457 ****
                }
  
- 
                function update_single_extra_field($id, $name, $value)
                {
--- 2699,2702 ----
***************
*** 2467,2471 ****
                        $this->request('account_person_id');
                        $this->criteria(array('account_id' => $account_id));
!                       $person_id = 
$this->get_records_by_field('account_person_id');
                        if(!$person_id)
                        {
--- 2712,2716 ----
                        $this->request('account_person_id');
                        $this->criteria(array('account_id' => $account_id));
!                       $person_id = 
$this->get_records_by_field('account_person_id', __LINE__, __FILE__);
                        if(!$person_id)
                        {

Index: class.sql_criteria.inc.php
===================================================================
RCS file: /cvsroot/phpgroupware/phpgwapi/inc/Attic/class.sql_criteria.inc.php,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -C2 -d -r1.1.2.1 -r1.1.2.2
*** class.sql_criteria.inc.php  8 Sep 2003 13:26:38 -0000       1.1.2.1
--- class.sql_criteria.inc.php  26 Sep 2003 00:03:08 -0000      1.1.2.2
***************
*** 118,122 ****
                * @return array token list of has criteria
                */
!               function _has($field,$value)
                {
                        return array($field,$value,'has');
--- 118,122 ----
                * @return array token list of has criteria
                */
!               function token_has($field,$value)
                {
                        return array($field,$value,'has');
***************
*** 133,137 ****
                * @see _has
                */
!               function _begin($field,$value)
                {
                        return array($field,$value,'begin_with');
--- 133,137 ----
                * @see _has
                */
!               function token_begin($field,$value)
                {
                        return array($field,$value,'begin_with');
***************
*** 148,152 ****
                * @see _has
                */
!               function _end($field,$value) 
                {
                        return array($field,$value,'end_with');
--- 148,152 ----
                * @see _has
                */
!               function token_end($field,$value) 
                {
                        return array($field,$value,'end_with');
***************
*** 244,248 ****
                function _append_and($clause)
                {
!                       return array_push($clause, 'append_and');
                }
  
--- 244,249 ----
                function _append_and($clause)
                {
!                       array_push($clause, 'append_and');
!                       return $clause;
                }
  
***************
*** 256,260 ****
                function _append_or($clause)
                {
!                       return array_push($clause, 'append_or');
                }
  
--- 257,262 ----
                function _append_or($clause)
                {
!                       array_push($clause, 'append_or');
!                       return $clause;
                }
  





reply via email to

[Prev in Thread] Current Thread [Next in Thread]