phpgroupware-cvs
[Top][All Lists]
Advanced

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

[Phpgroupware-cvs] phpgwapi/inc class.accounts_ldap.inc.php, 1.101.2.13.


From: Alejandro Borges (lex) <address@hidden>
Subject: [Phpgroupware-cvs] phpgwapi/inc class.accounts_ldap.inc.php, 1.101.2.13.2.5, 1.101.2.13.2.6 class.accounts_sql.inc.php, 1.80.2.8.2.16, 1.80.2.8.2.17 class.contacts_sql.inc.php, 1.17.2.2.2.28, 1.17.2.2.2.29 class.sql_builder.inc.php, 1.1.2.14, 1.1.2.15 class.sql_entity.inc.php, 1.1.2.9, 1.1.2.10
Date: Tue, 28 Oct 2003 06:46:21 +0000

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

Modified Files:
      Tag: Version-0_9_16-branch
        class.accounts_ldap.inc.php class.accounts_sql.inc.php 
        class.contacts_sql.inc.php class.sql_builder.inc.php 
        class.sql_entity.inc.php 
Log Message:
DEEP, COMPLEX, WORRYSOME, LARGE, ERRORPRONE patch from eald to give propper 
support to person_id in ldap plus other fixups in sql_builder also of the same
eerie nature


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.28
retrieving revision 1.17.2.2.2.29
diff -C2 -d -r1.17.2.2.2.28 -r1.17.2.2.2.29
*** class.contacts_sql.inc.php  28 Oct 2003 01:23:31 -0000      1.17.2.2.2.28
--- class.contacts_sql.inc.php  28 Oct 2003 06:46:18 -0000      1.17.2.2.2.29
***************
*** 171,175 ****
                                                        'org_modby'             
=> 'modified by',
                                                        'count_orgs'            
=> 'number of organizations',
!                                                       'account_id'            
=> 'account id',
                                                        'count_persons'         
=> 'number of persons',
  
--- 171,175 ----
                                                        'org_modby'             
=> 'modified by',
                                                        'count_orgs'            
=> 'number of organizations',
!                                                       //'account_id'          
=> 'account id',
                                                        'count_persons'         
=> 'number of persons',
  
***************
*** 196,201 ****
                                                        'other_contact_id'      
=> 'custom contact id',
                                                        'addr_type_id'          
=> 'address type id',
!                                                       'account_id'            
=> 'account id',
!                                                       'account_person_id'     
=> 'account person id',
                                                        'person_only'           
=> 'only persons',
                                                        'per_active'            
=> 'active person', 
--- 196,201 ----
                                                        'other_contact_id'      
=> 'custom contact id',
                                                        'addr_type_id'          
=> 'address type id',
! //                                                    'account_id'            
=> 'account id',
! //                                                    'account_person_id'     
=> 'account person id',
                                                        'person_only'           
=> 'only persons',
                                                        'per_active'            
=> 'active person', 
***************
*** 303,307 ****
                                 'per_modby'            => 
array('phpgwapi.contact_person', '1'),
                                 'per_name'             => 
array('phpgwapi.contact_person', '1'),
!                                'account_id'           => 
array('phpgwapi.contact_person', '1'),
                                 'count_persons'        => 
array('phpgwapi.contact_person', '1'),
                                 'people'               => 
array('phpgwapi.contact_person', '1', array('people_org', 'people_org_person', 
'people_contact')),
--- 303,307 ----
                                 'per_modby'            => 
array('phpgwapi.contact_person', '1'),
                                 'per_name'             => 
array('phpgwapi.contact_person', '1'),
!                                //'account_id'         => 
array('phpgwapi.contact_person', '1'),
                                 'count_persons'        => 
array('phpgwapi.contact_person', '1'),
                                 'people'               => 
array('phpgwapi.contact_person', '1', array('people_org', 'people_org_person', 
'people_contact')),
***************
*** 467,471 ****
                                                'per_modby',
                                                'per_modon',
-                                               'account_id',
                                                'key_addr_id',
                                                'addr_descritpion',
--- 467,470 ----
***************
*** 701,704 ****
--- 700,731 ----
                }
  
+               /* 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__);
+                               if(count($records) == 0)
+                               {
+                                       return;
+                               }
+                               foreach ($records as $comm)
+                               {
+                                       $descr = 
$this->search_comm_descr_id($comm['comm_descr']);
+                                       $comms[$descr] = $comm['comm_data'];    
+                               }
+                       }
+                       return $comms;
+               }
+ 
                /* @deprecated */
                function read_last_entry($fields='')
***************
*** 751,763 ****
                }
  
                /* @deprecated */
                function add($owner,$fields,$access='',$cat_id='',$tid='n')
                {
!                       $principal['acesss'] = $access;
!                       $principal['owner'] = $owner;
!                       $principal['contact_type'] = $type;
!                       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']);
                }
  
--- 778,1079 ----
                }
  
+               /**
+               * Get all the data for any contact or contacts that are part of 
$optional_criteria.
+               *
+               * This function try to be a comprensive way to get data from 
contacts<br /> convert the contacts database output on a multidimensional 
array<br />
+               * @param int|array $contact_id
+               * @param mixed $optional_criteria criteria built with 
sql_criteria
+               * @param integer $line where this function is called, usefull 
for debug
+               * @param integer $file where this function is called, usefull 
for debug
+               * @return mixed array with all the data of contact (contacts).
+               */
+               function person_complete_data($contact_id, $optional_criteria = 
'', $line=__LINE__, $file=__FILE__)
+               {
+                       $this->request($this->import_export_fields);
+                       if (empty($optional_criteria))
+                       {
+                               if (intval($contact_id) == 0)
+                               {
+                                       // this is an error
+                                       return ;
+                               }
+                               
$this->criteria_token(sql_criteria::_equal('contact_id', $contact_id));
+                       }
+                       else
+                       {
+                               $this->criteria_token($optional_criteria);
+                       }
+ 
+                       $sql = $this->get_sql();
+ 
+                       $this->execute_query($sql, $line, $file);
+ 
+                       while ($this->db->next_record())
+                       {
+                               $record = $this->db->Record;
+                               $contact['contact_id']          = 
$record['contact_id'];
+                               $contact['per_full_name']       = 
$record['per_full_name'];
+                               $contact['per_first_name']      = 
$record['per_first_name'];
+                               $contact['per_last_name']       = 
$record['per_full_name'];
+                               $contact['per_middle_name']     = 
$record['per_middle_name'];
+                               $contact['per_suffix']          = 
$record['per_suffix'];
+                               $contact['per_prefix']          = 
$record['per_prefix'];
+                               $contact['per_birthday']        = 
$record['per_birthday'];
+                               $contact['per_pubkey']          = 
$record['per_pubkey'];
+                               $contact['per_title']           = 
$record['per_title'];
+                               $contact['per_departament']     = 
$record['per_departamet'];
+                               $contact['per_initials']        = 
$record['per_initials'];
+                               $contact['per_sound']           = 
$record['per_sound'];
+                               $contact['per_active']          = 
$record['per_active'];
+                               $contact['per_createon']        = 
$record['per_createon'];
+                               $contact['per_createby']        = 
$record['per_createby'];
+                               $contact['per_modby']           = 
$record['per_modby'];
+                               $contact['per_modon']           = 
$record['per_modon'];
+                               //$contact['account_id']                = 
$record['account_id'];
+                               // Locations info
+                               $loc_id                                         
= $record['key_addr_id'];
+                               if($loc_id)
+                               {
+                                       $contact['locations'][$loc_id]['type']  
        = $record['addr_description'];
+                                       $contact['locations'][$loc_id]['add1']  
        = $record['addr_add1'];
+                                       $contact['locations'][$loc_id]['add2']  
        = $record['addr_add2'];
+                                       $contact['locations'][$loc_id]['add3']  
        = $record['addr_add3'];
+                                       
$contact['locations'][$loc_id]['address']       = $record['addr_address'];
+                                       $contact['locations'][$loc_id]['city']  
        = $record['addr_city'];
+                                       $contact['locations'][$loc_id]['state'] 
        = $record['addr_state'];
+                                       
$contact['locations'][$loc_id]['postal_code']   = $record['addr_postal_code'];
+                                       
$contact['locations'][$loc_id]['country']       = $record['addr_country'];
+                                       
$contact['locations'][$loc_id]['preferred']     = $record['addr_preferred'];
+                               }
+                               // Notes
+                               $note_id                                        
= $record['key_note_id'];
+                               if($note_id)
+                               {
+                                       $contact['notes'][$note_id]['text']     
        = $record['note_text'];
+                                       $contact['notes'][$note_id]['type']     
        = $record['note_description'];
+                               }
+                               // Communcation media fields
+                               if($record['comm_data'])
+                               {
+                                       $comm_descr                             
= $record['comm_description'];
+                                       $contact[$comm_descr]                   
= $record['comm_data'];
+                                       $contact['comm_type'][$comm_descr]      
= $record['comm_type_description'];
+                               }
+                               // Other fields
+                               if($record['other_value'])
+                               {
+                                       $contact[$record['other_name']]         
= $record['other_value'];
+                               }
+                       }
+                       return $contact;
+               }
+ 
+               function comms_fixed($comm_type, $comm_description)
+               {
+                       // In this array add all the label that you have on an 
import method, an make the
+                       // association with the corresponding description on 
database
+                       if(!$this->hash_comms_import)
+                       {
+                               $this->hash_comms_import = 
+                                       array('email'  => array('home'          
=> 'home email',
+                                                               'work'          
=> 'work email',
+                                                               'other'         
=> 'other email'),
+                                             'phone'  => array('home'          
=> 'home phone',
+                                                               'work'          
=> 'work phone',
+                                                               'other'         
=> 'other phone',
+                                                               'msg'           
=> 'msg phone',
+                                                               'home_two'      
=> 'second home phone',
+                                                               'work_two'      
=> 'second work phone',
+                                                               'isdn'          
=> 'isdn',
+                                                               'other_two'     
=> 'second other phone',
+                                                               'pager'         
=> 'pager'),
+                                             'fax'    => array('work'          
=> 'work fax',
+                                                               'home'          
=> 'home fax',
+                                                               'other'         
=> 'other fax'),
+                                             'mobile' => array('car'           
=> 'car phone',
+                                                               'cell'          
=> 'mobile (cell) phone'));
+                       }
+ 
+                       return 
$this->search_comm_descr($hash_comms_import[$comm_type][$comm_description]);
+               }
+ 
+               /**
+               * explode a field name by `_' so parts of the field name have a 
meaning, not only the whole name
+               * 
+               * @param string $field meta-field name, with form: 
{kind}_{key_{real_field_name}
+               * @param value $value to assing to field
+               * @param mixed &$field_list reference to the list that contain 
$field
+               */
+               function explode_field_name($field, $value, &$fields_list)
+               {
+                       // ugly hack
+                       $addr_keys = array('work', 'home', 'other', 'other', 
'other', 'other');
+ 
+                       list($kind, $key, $name) = explode('_', $field, 3);
+                       switch ($kind)
+                       {
+                       case 'addr':
+                               // Code for locations
+                               $fields_list['location'][$key][$name] = $value;
+                               unset($fields_list[$field]);
+                               $fields_list['location'][$key]['type'] = 
$addr_keys[$key];
+                               break;
+                       case 'comm':
+                               // Code for comms
+                               
$fields_list['comm_media'][$this->comms_fixed($key, $name)] = $value;
+                               unset($fields_list[$field]);
+                               break;
+                       case 'org':
+                               list($org_key, $name) = explode('_', $name, 2);
+                               switch($key)
+                               {
+                               case 'addr':
+                                       // Code for locations
+                                       
$fields_list['org_data']['location'][$org_key][$name] = $value;
+                                       unset($fields_list[$field]);
+                                       
$fields_list['org_data']['location'][$org_key]['type'] = $addr_keys[$org_key];
+                                       break;
+                               case 'comm':
+                                       // Code for comms
+                                       
$fields_list['org_data']['comm_media'][$this->comms_fixed($org_key, $name)] = 
$value;
+                                       unset($fields_list[$field]);
+                                       break;
+                               default:
+                                       // code for default (principal/others)
+                                       $fields_list['org_data'][$field] = 
$value;
+                                       unset($fields_list[$field]);
+                               }
+                       }
+               }
+ 
+               /**
+               * Get all the data for any contact or contacts that are part of 
$optional_criteria.
+               *
+               * This function try to be a comprensive way to get data from 
contacts<br /> convert the contacts database output on a multidimensional 
array<br />
+               * @param int|array $contact_id
+               * @param mixed $optional_criteria criteria built with 
sql_criteria
+               * @param integer $line where this function is called, usefull 
for debug
+               * @param integer $file where this function is called, usefull 
for debug
+               * @return mixed array with all the data of contact (contacts).
+               */
+               function person_complete_data($contact_id, $optional_criteria = 
'', $line=__LINE__, $file=__FILE__)
+               {
+                       $this->request($this->import_export_fields);
+                       if (empty($optional_criteria))
+                       {
+                               if (intval($contact_id) == 0)
+                               {
+                                       // this is an error
+                                       return ;
+                               }
+                               
$this->criteria_token(sql_criteria::_equal('contact_id', $contact_id));
+                       }
+                       else
+                       {
+                               $this->criteria_token($optional_criteria);
+                       }
+ 
+                       $sql = $this->get_sql();
+ 
+                       $this->execute_query($sql, $line, $file);
+ 
+                       while ($this->db->next_record())
+                       {
+                               $record = $this->db->Record;
+                               $contact['contact_id']          = 
$record['contact_id'];
+                               $contact['per_full_name']       = 
$record['per_full_name'];
+                               $contact['per_first_name']      = 
$record['per_first_name'];
+                               $contact['per_last_name']       = 
$record['per_full_name'];
+                               $contact['per_middle_name']     = 
$record['per_middle_name'];
+                               $contact['per_suffix']          = 
$record['per_suffix'];
+                               $contact['per_prefix']          = 
$record['per_prefix'];
+                               $contact['per_birthday']        = 
$record['per_birthday'];
+                               $contact['per_pubkey']          = 
$record['per_pubkey'];
+                               $contact['per_title']           = 
$record['per_title'];
+                               $contact['per_departament']     = 
$record['per_departamet'];
+                               $contact['per_initials']        = 
$record['per_initials'];
+                               $contact['per_sound']           = 
$record['per_sound'];
+                               $contact['per_active']          = 
$record['per_active'];
+                               $contact['per_createon']        = 
$record['per_createon'];
+                               $contact['per_createby']        = 
$record['per_createby'];
+                               $contact['per_modby']           = 
$record['per_modby'];
+                               $contact['per_modon']           = 
$record['per_modon'];
+                               $contact['account_id']          = 
$record['account_id'];
+                               // Locations info
+                               $loc_id                                         
= $record['key_addr_id'];
+                               if($loc_id)
+                               {
+                                       $contact['locations'][$loc_id]['type']  
        = $record['addr_description'];
+                                       $contact['locations'][$loc_id]['add1']  
        = $record['addr_add1'];
+                                       $contact['locations'][$loc_id]['add2']  
        = $record['addr_add2'];
+                                       $contact['locations'][$loc_id]['add3']  
        = $record['addr_add3'];
+                                       
$contact['locations'][$loc_id]['address']       = $record['addr_address'];
+                                       $contact['locations'][$loc_id]['city']  
        = $record['addr_city'];
+                                       $contact['locations'][$loc_id]['state'] 
        = $record['addr_state'];
+                                       
$contact['locations'][$loc_id]['postal_code']   = $record['addr_postal_code'];
+                                       
$contact['locations'][$loc_id]['country']       = $record['addr_country'];
+                                       
$contact['locations'][$loc_id]['preferred']     = $record['addr_preferred'];
+                               }
+                               // Notes
+                               $note_id                                        
= $record['key_note_id'];
+                               if($note_id)
+                               {
+                                       $contact['notes'][$note_id]['text']     
        = $record['note_text'];
+                                       $contact['notes'][$note_id]['type']     
        = $record['note_description'];
+                               }
+                               // Communcation media fields
+                               if($record['comm_data'])
+                               {
+                                       $comm_descr                             
= $record['comm_description'];
+                                       $contact[$comm_descr]                   
= $record['comm_data'];
+                                       $contact['comm_type'][$comm_descr]      
= $record['comm_type_description'];
+                               }
+                               // Other fields
+                               if($record['other_value'])
+                               {
+                                       $contact[$record['other_name']]         
= $record['other_value'];
+                               }
+                       }
+                       return $contact;
+               }
+ 
+               // Deprecated, this method is for old import only, I ask help 
to code a new one
                /* @deprecated */
                function add($owner,$fields,$access='',$cat_id='',$tid='n')
                {
!                       foreach($fields as $field => $value)
!                       {
!                               $this->explode_field_name($field, $value, 
$fields);
!                       }
!                       if(in_array($fields['note']))
!                       {
!                               $note['type'] = 'general';
!                               $note['note'] = $fields['note'];
!                               unset($fields['note']);
!                       }
! 
!                       if($fields['organization'])
!                       {
!                               $criteria = 
$this->criteria_for_index($GLOBALS['phpgw_info']['user']['account_id'], 
PHPGW_CONTACTS_CATEGORIES_ALL, array('org_name'), $fields['organization']);
!                               $records = $this->get_orgs(array('contact_id'));
!                               if(is_array($records))
!                               {
!                                       foreach($record as $org)
!                                       {
!                                               $orgs[] = $org['contact_id'];
!                                       }
!                               }
!                               else
!                               {
!                                       $this->add_org(array('org_name' => 
$fields['organization']));
!                                       $orgs = array($this->last_id('contact', 
'contact_id'));
!                               }
!                       }
! 
!                       $fields['notes']                = $note;
!                       $fields['organizations']        = $orgs;
!                       $fields['categories']           = $cat_id;
!                       $fields['access']               = $access;
!                       $this->contact_import($fields);
                }
  
***************
*** 1068,1072 ****
  
                /**
!               * Retrieve communicatins data for contact id.
                *
                * @param integer $contact_id  Id which want information.
--- 1384,1388 ----
  
                /**
!               * Retrieve communications data for contact id.
                *
                * @param integer $contact_id  Id which want information.
***************
*** 1085,1090 ****
                                      'comm_data',
                                      'comm_descr',
!                                     'comm_description',
!                                     'comm_type_id');
                        $this->request($data);
                        $this->criteria(array('comm_contact_id' => 
$contact_id));
--- 1401,1405 ----
                                      'comm_data',
                                      'comm_descr',
!                                     'comm_description');
                        $this->request($data);
                        $this->criteria(array('comm_contact_id' => 
$contact_id));
***************
*** 1391,1408 ****
                function get_system_contacts($data, $action=PHPGW_SQL_RUN_SQL)
                {
!                       $this->request($data);
!                       $this->request('account_person_id');
!                       $this->criteria(array('person_only' => TRUE));
!                       $sql = $this->get_sql();
!                       if($action == PHPGW_SQL_RUN_SQL)
                        {
!                               return $sql;
                        }
!                       $this->db->query($sql, __LINE__, __FILE__);
!                       while ($this->db->next_record())
                        {
!                               $persons[] = $this->db->f('account_person_id');
                        }
!                       return $persons;
                }
  
--- 1706,1728 ----
                function get_system_contacts($data, $action=PHPGW_SQL_RUN_SQL)
                {
! 
!                       $accounts = $GLOBALS['phpgw']->accounts->get_list();
!                       foreach($accounts as $account_data)
                        {
!                               if($account_data['person_id'])
!                               {
!                                       $people[] = $account_data['person_id'];
!                               }
                        }
! 
!                       if(is_array($data))
                        {
!                               $this->request($data);
                        }
! 
!                       $this->request('person_id');
!                       // sql::in() is better than make a select by each 
account
!                       $this->criteria(array('person_id' => $people));
!                       return $this->get_query($action, __LINE__, __FILE__);
                }
  
***************
*** 1819,1826 ****
                 * @param array $comms Information relative to communication 
media
                 * @param array $location Information relative to locations.
!                * @param array $categeries Catagories in which contact must be 
added..
                 * @return Array With person_id, account_person_id and all data 
of contacts that we wanted.
                 */
!               function add_contact($type, $principal=array(), $comms=array(), 
$locations=array(), $categories=array(), $others=array(), 
$contact_relations=array())
                {
                        $this->contact = 
CreateObject('phpgwapi.contact_central');
--- 2139,2149 ----
                 * @param array $comms Information relative to communication 
media
                 * @param array $location Information relative to locations.
!                * @param array $categeries Catagories in which contact must be 
added.
!                * @param array $others Others fields to be added.
!                * @param array $contact_relations the org_id or the person_id 
for this person or organzation
!                * @param array $notes Notes to be added. 
                 * @return Array With person_id, account_person_id and all data 
of contacts that we wanted.
                 */
!               function add_contact($type, $principal=array(), $comms=array(), 
$locations=array(), $categories=array(), $others=array(), 
$contact_relations=array(), $notes=array())
                {
                        $this->contact = 
CreateObject('phpgwapi.contact_central');
***************
*** 1872,1875 ****
--- 2195,2207 ----
                                $this->unlock_table();
                        }
+                       if(is_array($notes))
+                       {
+                               foreach($notes as $note)
+                               {
+                                       $this->add_notes($notes, $cid, 
PHPGW_SQL_RUN_SQL);
+                               }
+                               $this->unlock_table();
+                       }
+ 
                        return $cid;
                }
***************
*** 1947,1954 ****
                                $orgs = $this->has_preferred_org($person);
                                $this->relations = 
CreateObject('phpgwapi.contact_org_person');
-                               if ($action == PHPGW_SQL_RUN_SQL)
-                               {
-                                       
$this->lock_table($this->relations->table);
-                               }
                                $data['my_person_id'] = $person;
                                $data['my_creaton'] = $this->get_mkdate();
--- 2279,2282 ----
***************
*** 1963,1967 ****
                                }
                                
! 
                                $sql[] = $this->_add($data,'relations', 
'my_org_id', $cid, $action);
                                $this->unlock_table();
--- 2291,2298 ----
                                }
                                
!                               if ($action == PHPGW_SQL_RUN_SQL)
!                               {
!                                       
$this->lock_table($this->relations->table);
!                               }
                                $sql[] = $this->_add($data,'relations', 
'my_org_id', $cid, $action);
                                $this->unlock_table();
***************
*** 1986,1993 ****
                                {
                                        $this->relations = 
CreateObject('phpgwapi.contact_org_person');
-                                       if ($action == PHPGW_SQL_RUN_SQL)
-                                       {
-                                               
$this->lock_table($this->relations->table);
-                                       }
                                        $data['my_org_id'] = $org;
                                        $data['my_addr_id'] = $addr_id;
--- 2317,2320 ----
***************
*** 2002,2005 ****
--- 2329,2336 ----
                                        $data['my_creaton'] = 
$this->get_mkdate();
                                        $data['my_creatby'] = 
$this->get_user_id();
+                                       if ($action == PHPGW_SQL_RUN_SQL)
+                                       {
+                                               
$this->lock_table($this->relations->table);
+                                       }
                                        $sql[] = $this->_add($data,'relations', 
'my_person_id', $cid, $action);
                                        $this->unlock_table();
***************
*** 2068,2071 ****
--- 2399,2427 ----
  
                /**
+                * Add a note for a contact
+                * 
+                * @param array $note Communications information for contact
+                * @param integer $cid  contact id
+                * @param integer $action PHPGW_SQL_RETURN_SQL | 
PHPGW_SQL_RUN_SQL depending what we want
+                */
+               function add_note($note, $cid = '', 
$action=PHPGW_SQL_RETURN_SQL)
+               {       
+                       $this->comm = CreateObject('phpgwapi.contact_comm');
+                       if ($action == PHPGW_SQL_RUN_SQL)
+                       {
+                               $this->lock_table($this->comm->table);
+                       }
+ 
+                       $comm['note_creatby'] = $this->get_user_id();
+                       $comm['note_modby'] = $this->get_user_id();
+                       $comm['note_creaton'] = $this->get_mkdate();
+                       $comm['note_modon'] = $this->get_mkdate();
+ 
+                       unset($comm['key_note_id']);
+ 
+                       return 
$this->_add($note,'note','note_contact_id',$cid,$action);
+               }
+ 
+               /**
                 * Add a others for a contact
                 * 
***************
*** 2604,2611 ****
                function is_user($contact_id)
                {
!                       $this->request('account_person_id');
!                       $this->criteria(array('person_only' => TRUE));
!                       $user = $this->get_records(__LINE__, __FILE__);
!                       if($user[0]['is_account'] == 0)
                        {
                                return FALSE;
--- 2960,2965 ----
                function is_user($contact_id)
                {
!                       $account_id = 
$this->$GLOBALS['phpgw']->accounts->search_person($contact['person_id']);
!                       if($account_id == 0)
                        {
                                return FALSE;
***************
*** 2613,2617 ****
                        else
                        {
!                               return TRUE;
                        }
                }
--- 2967,2971 ----
                        else
                        {
!                               return $account_id;
                        }
                }
***************
*** 2619,2626 ****
                function get_account_id($contact_id)
                {
!                       $this->request('account_id');
!                       $this->criteria(array('account_person_id' => 
$contact_id));
!                       $user = $this->get_records(__LINE__, __FILE__);
!                       return $user[0]['account_id'];
                }
                
--- 2973,2987 ----
                function get_account_id($contact_id)
                {
!                       $accounts = $GLOBALS['phpgw']->accounts->get_list();
!                       foreach($accounts as $account_data)
!                       {
!                               if($account_data['person_id'] == $contact_id)
!                               {
!                                       $account_id = 
$account_data['account_id'];
!                                       break;
!                               }
!                       }
! 
!                       return $account_id;
                }
                
***************
*** 2687,2699 ****
                * @param mixed $preson_id  Person id which want to check.
                * @param Array $data the info that you want of this contact
-               * @param integer $action PHPGW_SQL_RETURN_SQL | 
PHPGW_SQL_RUN_SQL depending what we want
                * @return Array With person_id, account_person_id and all data 
of contacts that we wanted.
                */
!               function are_users($person_id, $data, $action=PHPGW_SQL_RUN_SQL)
                {
                        $this->request($data);
!                       $this->request('account_person_id');
                        $this->criteria(array('person_id' => $person_id));
!                       return $this->get_query($action, __LINE__, __FILE__);
                }
  
--- 3048,3067 ----
                * @param mixed $preson_id  Person id which want to check.
                * @param Array $data the info that you want of this contact
                * @return Array With person_id, account_person_id and all data 
of contacts that we wanted.
                */
!               function are_users($person_id, $data)
                {
                        $this->request($data);
!                       $this->request(array('person_id'));
                        $this->criteria(array('person_id' => $person_id));
!                       $query = $this->get_query(PHPGW_SQL_RETURN_SQL);
!                       $this->db->query($query,__LINE__, __FILE__);
!                       while($this->db->next_record())
!                       {
!                               $contact = $this->db->Record;
!                               $contact['account_id'] = 
$this->$GLOBALS['phpgw']->accounts->search_person($contact['person_id']);
!                               $contacts[] = $contact;
!                       }
!                       return $contacts;
                }
  
***************
*** 2715,2728 ****
                function get_contacts_which_are_users()
                {
!                       $this->request('person_id');
!                       $this->request('account_id');
!                       $this->request('per_name');
!                       $sql = $this->get_sql();
!                       $this->db->query($sql, __LINE__, __FILE__);             
        
!                       while ($this->db->next_record())
!                       {
!                               $contacts = &$this->db->Record;
!                       }
!                       return $contacts;
                }
  
--- 3083,3087 ----
                function get_contacts_which_are_users()
                {
!                       return $this->get_system_contacts();
                }
  
***************
*** 3125,3145 ****
                function update_single_extra_field($id, $name, $value)
                {
!                       $this->update('other_value', $value);
!                       $this->criteria(array('other_contact_id' => $id));
!                       $this->criteria(array('other_name' => $name));
!                       $sql_update = $this->map['other_contact_id']->update();
!                       $this->db->query($sql_update,__LINE__,__FILE__);
                }
  
                function is_contact($account_id)
                {
!                       $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)
                        {
                                return False;
                        }
!                       return $person_id;
                }
  
--- 3484,3500 ----
                function update_single_extra_field($id, $name, $value)
                {
!                       $other = CreateObject('phpgwapi.contact_others');
!                       $criteria = 
sql_criteria::token_and(sql_criteria::_equal('other_name', $name), 
sql_criteria::_equal('contact_id', $id));
!                       $other->update($id, array('other_value' => $value), 
$criteria);
                }
  
                function is_contact($account_id)
                {
!                       $account = 
$GLOBALS['phpgw']->accounts->get_account_data($account_id);
!                       if(empty($account[$account_id]['person_id']))
                        {
                                return False;
                        }
!                       return $account[$account_id]['person_id'];
                }
  
***************
*** 3377,3381 ****
                        //die('debug');
                }
! 
                function contact_import($fields, $type = '')
                {
--- 3732,3741 ----
                        //die('debug');
                }
!               /**
!               * Method that could be used to import field, from an array with 
the specified form.
!               * 
!               * This is the only one method that provide the fullfill fields 
for contact.
!               * 
!               */
                function contact_import($fields, $type = '')
                {
***************
*** 3385,3389 ****
                                $contact['contact_id']          = 
$fields['contact_id'];
                                $contact['access']              = 
$fields['access'];
!                               $contact['owner']               = 
$fields['owner'];
                                $contact['per_first_name']      = 
$fields['first_name'];
                                $contact['per_last_name']       = 
$fields['last_name'];
--- 3745,3749 ----
                                $contact['contact_id']          = 
$fields['contact_id'];
                                $contact['access']              = 
$fields['access'];
!                               $contact['owner']               = 
$fields['owner'] ? $principal['owner'] : 
$GLOBALS['phpgw_info']['user']['account_id'];
                                $contact['per_first_name']      = 
$fields['first_name'];
                                $contact['per_last_name']       = 
$fields['last_name'];
***************
*** 3432,3436 ****
                        }
                        $contact['categories']  = $fields['categories'];
!                       unset($fields['categories']);
  
                        // Locations info
--- 3792,3797 ----
                        }
                        $contact['categories']  = $fields['categories'];
!                       $contact['access']      = $fields['access'];
!                       unset($fields['categories'], $fields['access']);
  
                        // Locations info
***************
*** 3484,3488 ****
                                        {
                                                // FIXME: what is the default 
value for note_type?
!                                               $note_type = 
$this->search_location_type('default');
                                                if(!empty($note_type))
                                                {
--- 3845,3849 ----
                                        {
                                                // FIXME: what is the default 
value for note_type?
!                                               $note_type = 
$this->search_note_type('general');
                                                if(!empty($note_type))
                                                {
***************
*** 3534,3541 ****
                                }
                        }
!                       
!                       // FIXME: Jarg needs to check this
!                       $this->add_contact($type, $contact, $comm_media, 
$locations, $contact['categories'], $others, $contact['relations']);
!                       return $contact;
                }
        }
--- 3895,3899 ----
                                }
                        }
!                       return $this->add_contact($type, $contact, $comm_media, 
$locations, $contact['categories'], $others, $contact['relations'], $notes);
                }
        }

Index: class.accounts_ldap.inc.php
===================================================================
RCS file: /cvsroot/phpgroupware/phpgwapi/inc/class.accounts_ldap.inc.php,v
retrieving revision 1.101.2.13.2.5
retrieving revision 1.101.2.13.2.6
diff -C2 -d -r1.101.2.13.2.5 -r1.101.2.13.2.6
*** class.accounts_ldap.inc.php 26 Oct 2003 06:12:57 -0000      1.101.2.13.2.5
--- class.accounts_ldap.inc.php 28 Oct 2003 06:46:18 -0000      1.101.2.13.2.6
***************
*** 524,527 ****
--- 524,565 ----
                }
  
+               /**
+               * Search by the person_id attribute on accounte entry
+               *
+               * based on id2name
+               * @param integer $person_id The person_id to search
+               */
+               function search_person($person_id)
+               {
+                       static $person_list;
+                       if(isset($person_list[$person_id]))
+                       {
+                               return intval($person_list[$person_id]);
+                       }
+ 
+                       $allValues = array();
+                       // Groups are person? are you sure?
+                       $sri = ldap_search($this->ds, $this->group_context, 
"(&(person_id=$person_id)(phpgwaccounttype=g))");
+                       $allValues = ldap_get_entries($this->ds, $sri);
+ 
+                       if (@$allValues[0]['gidnumber'][0])
+                       {
+                               $person_list[$person_id] = 
intval($allValues[0]['gidnumber'][0]);
+                               return $person_list[$person_id];
+                       }
+ 
+                       $allValues = array();
+                       $sri = ldap_search($this->ds, $this->user_context, 
"(&(person_id=$person_id)(phpgwaccounttype=u))");
+                       $allValues = ldap_get_entries($this->ds, $sri);
+ 
+                       if (@$allValues[0]['uidnumber'][0])
+                       {
+                               $id_list[$person_id] = 
intval($allValues[0]['uidnumber'][0]);
+                               return $person_list[$person_id];
+                       }
+ 
+                       return $person_list[$person_id];
+               }
+ 
                function get_type($accountid = '')
                {

Index: class.sql_builder.inc.php
===================================================================
RCS file: /cvsroot/phpgroupware/phpgwapi/inc/Attic/class.sql_builder.inc.php,v
retrieving revision 1.1.2.14
retrieving revision 1.1.2.15
diff -C2 -d -r1.1.2.14 -r1.1.2.15
*** class.sql_builder.inc.php   21 Oct 2003 01:08:15 -0000      1.1.2.14
--- class.sql_builder.inc.php   28 Oct 2003 06:46:18 -0000      1.1.2.15
***************
*** 263,266 ****
--- 263,273 ----
  
                        $this->instance_entity($near_entity);
+                       if(is_array($this->distance))
+                       {
+                               if(array_key_exists($near_entity, 
$this->distance))
+                               {
+                                       unset($this->distance[$near_entity]);
+                               }
+                       }
                        $this->add_path($near_entity, $reverse);
                        if ($min_distance == 0)
***************
*** 276,280 ****
                function last_distance()
                {
!                       $curr = current($this->distance);
                        @$this->ldebug('last_distance', array('Before Current' 
=> $curr), 'dump');
                        next($this->distance);
--- 283,287 ----
                function last_distance()
                {
!                       $curr = key($this->distance);
                        @$this->ldebug('last_distance', array('Before Current' 
=> $curr), 'dump');
                        next($this->distance);
***************
*** 282,289 ****
                        {
                                $curr = key($this->distance);
!                               $this->ldebug('last_distance', array('Middle 
Current No last' => $curr), 'dump');
                                prev($this->distance);
                                $curr = key($this->distance);
!                               $this->ldebug('last_distance', array('After 
Current No last' => $curr), 'dump');
                                return FALSE;
                        }
--- 289,296 ----
                        {
                                $curr = key($this->distance);
!                               $this->ldebug('last_distance', array('Next' => 
$curr), 'dump');
                                prev($this->distance);
                                $curr = key($this->distance);
!                               $this->ldebug('last_distance', array('Current 
No last' => $curr), 'dump');
                                return FALSE;
                        }
***************
*** 291,298 ****
                        {
                                $curr = key($this->distance);
!                               $this->ldebug('last_distance', array('Middle 
Current last' => $curr), 'dump');
                                prev($this->distance);
                                $curr = key($this->distance);
!                               $this->ldebug('last_distance', array('After 
Current last' => $curr), 'dump');
                                return TRUE;
                        }
--- 298,305 ----
                        {
                                $curr = key($this->distance);
!                               $this->ldebug('last_distance', array('Next' => 
$curr), 'dump');
                                prev($this->distance);
                                $curr = key($this->distance);
!                               $this->ldebug('last_distance', array('Current 
LAST' => $curr), 'dump');
                                return TRUE;
                        }
***************
*** 312,318 ****
                                $this->path[$ent]['identity'] = 
$this->entities[$ent]->get_identity();
                                $this->path[$ent]['alias'] = 
$this->entities[$ent]->get_alias();
!                       }                       
                }
!               
                function merge_paths()
                {
--- 319,330 ----
                                $this->path[$ent]['identity'] = 
$this->entities[$ent]->get_identity();
                                $this->path[$ent]['alias'] = 
$this->entities[$ent]->get_alias();
!                       }
                }
! 
!               function get_path()
!               {
!                       return is_array($this->path) ? $this->path : array();
!               }
! 
                function merge_paths()
                {
***************
*** 321,328 ****
                }
  
-               function get_path()
-               {
-                       return is_array($this->path) ? $this->path : array();
-               }
                /**
                * Return the SQL select correct for all the entity map.
--- 333,336 ----
***************
*** 338,342 ****
                        }
                        $this->ldebug('get_sql',
!                                     array('Entities' => 
array_keys($this->entities)),
                                      'dump');
                        $this->sort_by_distances();
--- 346,351 ----
                        }
                        $this->ldebug('get_sql',
!                                     array('Entities' => 
array_keys($this->entities),
!                                           'Path' => $this->distance),
                                      'dump');
                        $this->sort_by_distances();
***************
*** 369,376 ****
                        $this->false_path = NULL;
                        $this->_criteria_built = False;
!                       $this->ldebug('get_sql', array('Entities' => 
$this->entities,
!                                               'Path' => $this->path,
!                                               'Distances' => 
$this->distance,),
!                               'dump');
                        $sql = $this->set_order($sql);
                        unset($this->order_string);
--- 378,382 ----
                        $this->false_path = NULL;
                        $this->_criteria_built = False;
! 
                        $sql = $this->set_order($sql);
                        unset($this->order_string);
***************
*** 482,486 ****
                        // table as alias (1)
                        $this->ldebug('get_join',
!                                                 array('Path' => $this->path),
                                                  'dump');
                        $prev_entity = key($path);
--- 488,492 ----
                        // table as alias (1)
                        $this->ldebug('get_join',
!                                                 array('Path' => $path),
                                                  'dump');
                        $prev_entity = key($path);
***************
*** 653,657 ****
                                else
                                {
!                                       return $instance = 
CreateObject($entity);
                                }
                        }
--- 659,663 ----
                                else
                                {
!                                       return $instance;
                                }
                        }
***************
*** 1048,1056 ****
                                $value = array_shift($criteria);
                        }
!                       $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]);
                }
  
--- 1054,1061 ----
                                $value = array_shift($criteria);
                        }
!                       $entity = 
$this->instance_volatile($this->ent_name($field), False);
!                       $real_name = $entity->real_field($field);
!                       $criteria = $entity->index_criteria(array('real_field' 
=> $real_name, 'value' => $value, 'field' => $field));
!                       return $entity->delete($criteria, $action);
                }
  
***************
*** 1096,1103 ****
                {
                        /**
!                       * This the NEW parent/child fields
                        * implementation, I hope this solve my
!                       * problems, but this don't remove that exist
!                       * a design problem with the n-n relations and
                        * 1-1.
                        */
--- 1101,1108 ----
                {
                        /**
!                       * This is the NEW parent/child fields
                        * implementation, I hope this solve my
!                       * problems, but this don't remove that exist a
!                       * design problem with the n-n relations and
                        * 1-1.
                        */
***************
*** 1197,1205 ****
                function ldebug($myfoo, $data, $type = 'string', $err = '')
                {
! //                    if (!((($myfoo != 'get_join') xor
  //                           ($myfoo != '')) xor
! //                          ($myfoo == 'add_path')) xor
! //                        ($myfoo == ''))
! //                    if ($myfoo != 'get_sql')
  //                    {
                        return;
--- 1202,1210 ----
                function ldebug($myfoo, $data, $type = 'string', $err = '')
                {
! //                    if (!((($myfoo != '') xor
  //                           ($myfoo != '')) xor
! //                          ($myfoo == '')) xor
! //                        ($myfoo == 'get_sql'))
! //                    if ($myfoo != 'SQL')
  //                    {
                        return;

Index: class.accounts_sql.inc.php
===================================================================
RCS file: /cvsroot/phpgroupware/phpgwapi/inc/class.accounts_sql.inc.php,v
retrieving revision 1.80.2.8.2.16
retrieving revision 1.80.2.8.2.17
diff -C2 -d -r1.80.2.8.2.16 -r1.80.2.8.2.17
*** class.accounts_sql.inc.php  26 Oct 2003 06:12:58 -0000      1.80.2.8.2.16
--- class.accounts_sql.inc.php  28 Oct 2003 06:46:18 -0000      1.80.2.8.2.17
***************
*** 178,182 ****
  
                                $whereclause .= " account_firstname LIKE 
'%$query%' OR account_lastname LIKE "
!                                       . "'%$query%' OR account_lid LIKE 
'%$query%' )";
                        }
  
--- 178,182 ----
  
                                $whereclause .= " account_firstname LIKE 
'%$query%' OR account_lastname LIKE "
!                                       . "'%$query%' OR account_lid LIKE 
'%$query%' OR person_id LIKE '%$query%')";
                        }
  
***************
*** 267,270 ****
--- 267,297 ----
                        }
                        return $id_list[$account_id];
+               }
+ 
+               function search_person($person_id)
+               {
+                       static $person_list;
+ 
+                       if (! $person_id)
+                       {
+                               return False;
+                       }
+ 
+                       if($person_list[$person_id])
+                       {
+                               return $person_list[$person_id];
+                       }
+ 
+                       $this->db->query('SELECT account_id FROM phpgw_accounts 
WHERE person_id=' . $person_id,__LINE__,__FILE__);
+                       if($this->db->num_rows())
+                       {
+                               $this->db->next_record();
+                               $person_list[$person_id] = 
$this->db->f('account_id');
+                       }
+                       else
+                       {
+                               $person_list[$person_id] = False;
+                       }
+                       return $person_list[$person_id];
                }
  

Index: class.sql_entity.inc.php
===================================================================
RCS file: /cvsroot/phpgroupware/phpgwapi/inc/Attic/class.sql_entity.inc.php,v
retrieving revision 1.1.2.9
retrieving revision 1.1.2.10
diff -C2 -d -r1.1.2.9 -r1.1.2.10
*** class.sql_entity.inc.php    9 Oct 2003 00:25:21 -0000       1.1.2.9
--- class.sql_entity.inc.php    28 Oct 2003 06:46:18 -0000      1.1.2.10
***************
*** 668,672 ****
                function set_update_data($element)
                {
!                       $value = ($element['value']) ? 
$this->cast($element['value'], $element['field']) : sql::null();
                        $this->values .= (($this->values)?', 
':'').$element['real_field'].' = '.$value;
                }
--- 668,672 ----
                function set_update_data($element)
                {
!                       $value = ($element['value'] || $element['value'] == 0) 
? $this->cast($element['value'], $element['field']) : sql::null();
                        $this->values .= (($this->values)?', 
':'').$element['real_field'].' = '.$value;
                }





reply via email to

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