phpgroupware-cvs
[Top][All Lists]
Advanced

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

[Phpgroupware-cvs] CVS: sync/inc class.common_base.inc.php,1.1.1.1,1.2 c


From: Dave Hall <address@hidden>
Subject: [Phpgroupware-cvs] CVS: sync/inc class.common_base.inc.php,1.1.1.1,1.2 class.contacts_base.inc.php,1.1.1.1,1.2
Date: Wed, 30 Apr 2003 01:20:41 -0400

Update of /cvsroot/phpgroupware/sync/inc
In directory subversions:/tmp/cvs-serv8607

Modified Files:
        class.common_base.inc.php class.contacts_base.inc.php 
Log Message:
contacts should now be complete

Index: class.common_base.inc.php
===================================================================
RCS file: /cvsroot/phpgroupware/sync/inc/class.common_base.inc.php,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -r1.1.1.1 -r1.2
*** class.common_base.inc.php   28 Apr 2003 21:13:44 -0000      1.1.1.1
--- class.common_base.inc.php   30 Apr 2003 05:20:38 -0000      1.2
***************
*** 1,131 ****
! <?php
!     
/**************************************************************************\
!     * phpGroupWare - Sync                                                     
           *
!     * http://www.phpgroupware.org                                             
 *
!     * Written by Dave Hall [skwashd AT phpgroupware.org]                      
           *
!     * 
------------------------------------------------------------------------ *
!     *  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.                                             
 *
!     
\**************************************************************************/
!               
!     /*!
!     @class_start common_base
!     @abstract Abstract helper class for syncing phpgw data with other 
systems/devices 
!     */
!               class common_base
!               {
!                       var $db;
!                       var $type;
!                       var $user_id = 
$GLOBALS['phpgw_info']['user']['account_id'];
!                       
!                       /*!
!                       * @function get_map_default
!                       * @abstract constructor
!                       * @param $type - app/api class 
!                       */
!                       function common_base($type='')
!                       {
!                               if(strlen($type)>1)
!                               {
!                                       trigger_error("Type must be 
specified!", E_USER_ERROR);
!                                       return NULL;
!                               }
!                               /* This will be uncommented soon 
!                               else if(strcasecmp(get_class($this), 
'common_base') == 0)
!                               {
!                                       trigger_error('Cannot instantiate 
abstract class ' . get_class($this), E_USER_ERROR);
!                                       return NULL; 
!                               }*/
!                               $this->type=$type;
! 
!                               $this->db = createObject('phpgwapi.db');
!                       }
!                       
!                       /*!
!                       * @function add_match
!                       * @abstract add a new record match record in matching 
table
!                       * @param $phpgw_id - the record id in phpgw
!                       * @param $remote_id - the record id in other 
system/device
!                       * @param $staus(optional) - the status of the record - 
-1 deleted, 0 archived, 1 active
!                       */
!                       function add_match($phpgw_id, $remote_id, $staus_id=1)
!                       {
!                               /*security checks*/
!                               $phpgw_id       = (int) $phpgw_id;
!                               $remote_id      = (int) $remote_id;
!                               $staus_id       = (int) $staus_id;
! 
!                               $sql  = "INSERT INTO phpgw_sync_match(app_name, 
phpgw_id, remote_id, user_id, $status_id) ";
!                               $sql .= "VALUES('$this->type', $phpgw_id, 
$remote_id, $this->user_id, $staus_id)";
!                               $this->db->query($sql);
!                       }
!                       
!                       /*!
!                       * @function find_match
!                       * @abstract finds record matches
!                       * @param $phpgw_id - the record id in phpgw - set to 
false if unknown
!                       * @param $remote_id - the record id in other 
system/device
!                       */
!                       function find_match($phpgw_id = false, $remote_id = 
false)
!                       {
!                               var $return = false;
! 
!                               /*security checks*/
!                               $phpgw_id       = (int) $phpgw_id;
!                               $remote_id      = (int) $remote_id;
!                               
!                               if($phpgw_id || $remote_id)
!                               {
!                               $sql  = "SELECT * FROM phpgw_sync_match ";
!                               $sql .= "WHERE app_name = '$this->type' ";
!                               $sql .= ($phpgw_id ? "AND phpgw_id = $phpgw_id 
" : '';
!                               $sql .= ($remote_id ? "AND remote_id = 
$remote_id " : '';
!                               $sql .= "AND user_id = $this->user_id ";
!                               $this->db->query($sql);
!                               if($this->db->next_record())
!                               {
!                                       $return = array('phpgw_id'      => 
$this->db->f('phpgw_id'),
!                                                                       
'remote_id'     => $this->db->f('remote_id'),
!                                                                       
'status_id'     => $this->db->f('status_id')
!                                                                       );
!                               }
!                               }
!                               return $return;
!                       }
!                       
!                       function match
! 
!                       /*!
!                       * @function update_match
!                       * @abstract update a record in the match table
!                       * @param $phpgw_id - the record id in phpgw
!                       * @param $remote_id - the record id in other 
system/device
!                       * @param $staus_id - the status of the record - 1 
active, 2 readonly, 3 deleted, 4 archived  
!                       */
!                       function update_match($phpgw_id, $remote_id, $staus_id)
!                       {
!                               /*security checks*/
!                               $phpgw_id       = (int) $phpgw_id;
!                               $remote_id      = (int) $remote_id;
!                               $staus_id       = (int) $staus_id;
!                               
!                               $sql  = "UPDATE phpgw_sync_match ";
!                               $sql .= "SET satus_id = $status_id "
!                               $sql .= "WHERE app_name = '$this->type' ";
!                               $sql .= "AND phpgw_id = $phpgw_id ";
!                               $sql .= "AND remote_id = $remote_id "
!                               $sql .= "AND user_id = $this->user_id ";
!                               $this->db->query($sql);
!                       }
!               }
! 
!     /*!
!     @class_end common_base
!     */
!               define('PHPGW_SYNC_STATUS_ACTIVE', 1);
!               define('PHPGW_SYNC_STATUS_READONLY', 2);
!               define('PHPGW_SYNC_STATUS_DELETED', 3);
!               define('PHPGW_SYNC_STATUS_ARCHIVED', 4);
! ?>
--- 1,131 ----
! <?php
!     
/**************************************************************************\
!     * phpGroupWare - Sync                                                     
           *
!     * http://www.phpgroupware.org                                             
 *
!     * Written by Dave Hall [skwashd AT phpgroupware.org]                      
           *
!     * 
------------------------------------------------------------------------ *
!     *  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.                                             
 *
!     
\**************************************************************************/
!               
!     /*!
!     @class_start common_base
!     @abstract Abstract helper class for syncing phpgw data with other 
systems/devices 
!     */
!               class common_base
!               {
!                       var $db;
!                       var $type;
!                       var $user_id = 
$GLOBALS['phpgw_info']['user']['account_id'];
!                       
!                       /*!
!                       * @function get_map_default
!                       * @abstract constructor
!                       * @param $type - app/api class 
!                       */
!                       function common_base($type='')
!                       {
!                               if(strlen($type)<1)
!                               {
!                                       trigger_error("Type must be 
specified!", E_USER_ERROR);
!                                       return NULL;
!                               }
!                               /* This will be uncommented soon 
!                               else if(strcasecmp(get_class($this), 
'common_base') == 0)
!                               {
!                                       trigger_error('Cannot instantiate 
abstract class ' . get_class($this), E_USER_ERROR);
!                                       return NULL; 
!                               }*/
!                               $this->type=$type;
! 
!                               $this->db = createObject('phpgwapi.db');
!                       }
!                       
!                       /*!
!                       * @function add_match
!                       * @abstract add a new record match record in matching 
table
!                       * @param $phpgw_id - the record id in phpgw
!                       * @param $remote_id - the record id in other 
system/device
!                       * @param $staus(optional) - the status of the record - 
-1 deleted, 0 archived, 1 active
!                       */
!                       function add_match($phpgw_id, $remote_id, $staus_id=1)
!                       {
!                               /*security checks*/
!                               $phpgw_id       = (int) $phpgw_id;
!                               $remote_id      = (int) $remote_id;
!                               $staus_id       = (int) $staus_id;
! 
!                               $sql  = "INSERT INTO phpgw_sync_match(app_name, 
phpgw_id, remote_id, user_id, $status_id) ";
!                               $sql .= "VALUES('$this->type', $phpgw_id, 
$remote_id, $this->user_id, $staus_id)";
!                               $this->db->query($sql);
!                       }
!                       
!                       /*!
!                       * @function find_match
!                       * @abstract finds record matches
!                       * @param $phpgw_id - the record id in phpgw - set to 
false if unknown
!                       * @param $remote_id - the record id in other 
system/device
!                       */
!                       function find_match($phpgw_id = false, $remote_id = 
false)
!                       {
!                               var $return = false;
! 
!                               /*security checks*/
!                               $phpgw_id       = (int) $phpgw_id;
!                               $remote_id      = (int) $remote_id;
!                               
!                               if($phpgw_id || $remote_id)
!                               {
!                               $sql  = "SELECT * FROM phpgw_sync_match ";
!                               $sql .= "WHERE app_name = '$this->type' ";
!                               $sql .= ($phpgw_id ? "AND phpgw_id = $phpgw_id 
" : '';
!                               $sql .= ($remote_id ? "AND remote_id = 
$remote_id " : '';
!                               $sql .= "AND user_id = $this->user_id ";
!                               $this->db->query($sql);
!                               if($this->db->next_record())
!                               {
!                                       $return = array('phpgw_id'      => 
$this->db->f('phpgw_id'),
!                                                                       
'remote_id'     => $this->db->f('remote_id'),
!                                                                       
'status_id'     => $this->db->f('status_id')
!                                                                       );
!                               }
!                               }
!                               return $return;
!                       }
!                       
!                       function match
! 
!                       /*!
!                       * @function update_match
!                       * @abstract update a record in the match table
!                       * @param $phpgw_id - the record id in phpgw
!                       * @param $remote_id - the record id in other 
system/device
!                       * @param $staus_id - the status of the record - 1 
active, 2 readonly, 3 deleted, 4 archived  
!                       */
!                       function update_match($phpgw_id, $remote_id, $staus_id)
!                       {
!                               /*security checks*/
!                               $phpgw_id       = (int) $phpgw_id;
!                               $remote_id      = (int) $remote_id;
!                               $staus_id       = (int) $staus_id;
!                               
!                               $sql  = "UPDATE phpgw_sync_match ";
!                               $sql .= "SET satus_id = $status_id "
!                               $sql .= "WHERE app_name = '$this->type' ";
!                               $sql .= "AND phpgw_id = $phpgw_id ";
!                               $sql .= "AND remote_id = $remote_id "
!                               $sql .= "AND user_id = $this->user_id ";
!                               $this->db->query($sql);
!                       }
!               }
! 
!     /*!
!     @class_end common_base
!     */
!               define('PHPGW_SYNC_STATUS_ACTIVE', 1);
!               define('PHPGW_SYNC_STATUS_READONLY', 2);
!               define('PHPGW_SYNC_STATUS_DELETED', 3);
!               define('PHPGW_SYNC_STATUS_ARCHIVED', 4);
! ?>

Index: class.contacts_base.inc.php
===================================================================
RCS file: /cvsroot/phpgroupware/sync/inc/class.contacts_base.inc.php,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -r1.1.1.1 -r1.2
*** class.contacts_base.inc.php 28 Apr 2003 21:13:45 -0000      1.1.1.1
--- class.contacts_base.inc.php 30 Apr 2003 05:20:39 -0000      1.2
***************
*** 1,344 ****
! <?php
!     
/**************************************************************************\
!     * phpGroupWare - Sync                                                     
           *
!     * http://www.phpgroupware.org                                             
 *
!     * Written by Dave Hall [skwashd AT phpgroupware.org]                      
           *
!     * 
------------------------------------------------------------------------ *
!     *  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.                                             
 *
!     
\**************************************************************************/
!               
!     /*!
!     @class_start contacts_base
!     @abstract Abstract Class for syncing contacts data 
!     */
! 
!               class contacts_base
!               {
!                       var $implementation; //type of implementation in non 
abstract class
!                       var $implemented_methods = null;
!                       
!                       //class containters
!                       var $common;  //container for common object
!                       var $contacts;  //container for contacts object
! 
!                       function contacts_base()
!                       {
!                               /* This will be uncommented soon 
!                               if(strcasecmp(get_class($this), 
'contacts_base') == 0)
!                               {
!                                       trigger_error('Cannot instantiate 
abstract class ' . get_class($this), E_USER_ERROR);
!                                       return NULL; 
!                               }*/
!                               $this->common = createObject('sync.common_' . 
$this->implementation);
!                               $this->contacts = 
createObject('phpgwapi.contacts');
!                       }
!                       
!                       /*!
!                       * @function get_map_default
!                       * @abstract maps contact class fieldnames to stock 
mappings
!                       */
!                       function get_map_default()
!                       {
!                               //unused fields should be removed in concrete 
version
!                               return array('fn'                               
        => 'fn',
!                               'n_given'                               => 
'n_given',
!                               'n_family'                              => 
'n_family',
!                                                       'n_middle'              
                => 'n_middle',
!                                               'n_prefix'                      
        => 'n_prefix',
!                                               'n_suffix'                      
        => 'n_suffix',
!                                               'sound'                         
        => 'sound',
!                                               'bday'                          
        => 'bday',
!                                               'note'                          
        => 'note',
!                                               'tz'                            
        => 'tz',
!                                               'geo'                           
        => 'geo',
!                                               'url'                           
        => 'url',
!                                               'pubkey'                        
        => 'pubkey',
!                                               'org_name'                      
        => 'org_name',
!                                               'org_unit'                      
        => 'org_unit',
!                                               'title'                         
        => 'title',
!                                               'adr_one_street'                
=> 'adr_one_street',
!                                               'adr_one_locality'              
=> 'adr_one_locality', 
!                                               'adr_one_region'                
=> 'adr_one_region', 
!                                               'adr_one_postalcode'    => 
'adr_one_postalcode',
!                                               'adr_one_countryname'   => 
'adr_one_countryname',
!                                               'adr_one_type'                  
=> 'adr_one_type',
!                                               'label'                         
        => 'label',
!                                               'adr_two_street'                
=> 'adr_two_street',
!                                               'adr_two_locality'              
=> 'adr_two_locality', 
!                                               'adr_two_region'                
=> 'adr_two_region', 
!                                               'adr_two_postalcode'    => 
'adr_two_postalcode',
!                                               'adr_two_countryname'   => 
'adr_two_countryname',
!                                               'adr_two_type'                  
=> 'adr_two_type',
!                                               'tel_work'                      
        => 'tel_work',
!                                               'tel_home'                      
        => 'tel_home',
!                                               'tel_voice'                     
        => 'tel_voice',
!                                               'tel_fax'                       
        => 'tel_fax', 
!                                               'tel_msg'                       
        => 'tel_msg',
!                                               'tel_cell'                      
        => 'tel_cell',
!                                               'tel_pager'                     
        => 'tel_pager',
!                                               'tel_bbs'                       
        => 'tel_bbs',
!                                               'tel_modem'                     
        => 'tel_modem',
!                                               'tel_car'                       
        => 'tel_car',
!                                               'tel_isdn'                      
        => 'tel_isdn',
!                                               'tel_video'                     
        => 'tel_video',
!                                               'tel_prefer'                    
=> 'tel_prefer',
!                                               'email'                         
        => 'email',
!                                               'email_type'                    
=> 'email_type',
!                                               'email_home'                    
=> 'email_home',
!                                               'email_home_type'               
=> 'email_home_type'
!               );
! 
!                       }
! 
!                       /*!
!                       * @function get_map_from
!                       * @abstract maps contact class fieldnames custom 
mappings for exporting records
!                       */
!                       function get_map_from()
!                       {
!                               //unused fields should be removed in concrete 
version
!                               return array('fn'                               
        => 'fn',
!                               'n_given'                               => 
'n_given',
!                               'n_family'                              => 
'n_family',
!                                                       'n_middle'              
                => 'n_middle',
!                                               'n_prefix'                      
        => 'n_prefix',
!                                               'n_suffix'                      
        => 'n_suffix',
!                                               'sound'                         
        => 'sound',
!                                               'bday'                          
        => 'bday',
!                                               'note'                          
        => 'note',
!                                               'tz'                            
        => 'tz',
!                                               'geo'                           
        => 'geo',
!                                               'url'                           
        => 'url',
!                                               'pubkey'                        
        => 'pubkey',
!                                               'org_name'                      
        => 'org_name',
!                                               'org_unit'                      
        => 'org_unit',
!                                               'title'                         
        => 'title',
!                                               'adr_one_street'                
=> 'adr_one_street',
!                                               'adr_one_locality'              
=> 'adr_one_locality', 
!                                               'adr_one_region'                
=> 'adr_one_region', 
!                                               'adr_one_postalcode'    => 
'adr_one_postalcode',
!                                               'adr_one_countryname'   => 
'adr_one_countryname',
!                                               'adr_one_type'                  
=> 'adr_one_type',
!                                               'label'                         
        => 'label',
!                                               'adr_two_street'                
=> 'adr_two_street',
!                                               'adr_two_locality'              
=> 'adr_two_locality', 
!                                               'adr_two_region'                
=> 'adr_two_region', 
!                                               'adr_two_postalcode'    => 
'adr_two_postalcode',
!                                               'adr_two_countryname'   => 
'adr_two_countryname',
!                                               'adr_two_type'                  
=> 'adr_two_type',
!                                               'tel_work'                      
        => 'tel_work',
!                                               'tel_home'                      
        => 'tel_home',
!                                               'tel_voice'                     
        => 'tel_voice',
!                                               'tel_fax'                       
        => 'tel_fax', 
!                                               'tel_msg'                       
        => 'tel_msg',
!                                               'tel_cell'                      
        => 'tel_cell',
!                                               'tel_pager'                     
        => 'tel_pager',
!                                               'tel_bbs'                       
        => 'tel_bbs',
!                                               'tel_modem'                     
        => 'tel_modem',
!                                               'tel_car'                       
        => 'tel_car',
!                                               'tel_isdn'                      
        => 'tel_isdn',
!                                               'tel_video'                     
        => 'tel_video',
!                                               'tel_prefer'                    
=> 'tel_prefer',
!                                               'email'                         
        => 'email',
!                                               'email_type'                    
=> 'email_type',
!                                               'email_home'                    
=> 'email_home',
!                                               'email_home_type'               
=> 'email_home_type'
!               );
! 
!                       }
! 
!                       /*!
!                       * @function get_map_to
!                       * @abstract maps contact class fieldnames custom 
mappings for importing records
!                       */
!                       function get_map_to()
!                       {
!                               //unused fields should be removed in concrete 
version
!                               return array('fn'                               
        => 'fn',
!                               'n_given'                               => 
'n_given',
!                               'n_family'                              => 
'n_family',
!                                                       'n_middle'              
                => 'n_middle',
!                                               'n_prefix'                      
        => 'n_prefix',
!                                               'n_suffix'                      
        => 'n_suffix',
!                                               'sound'                         
        => 'sound',
!                                               'bday'                          
        => 'bday',
!                                               'note'                          
        => 'note',
!                                               'tz'                            
        => 'tz',
!                                               'geo'                           
        => 'geo',
!                                               'url'                           
        => 'url',
!                                               'pubkey'                        
        => 'pubkey',
!                                               'org_name'                      
        => 'org_name',
!                                               'org_unit'                      
        => 'org_unit',
!                                               'title'                         
        => 'title',
!                                               'adr_one_street'                
=> 'adr_one_street',
!                                               'adr_one_locality'              
=> 'adr_one_locality', 
!                                               'adr_one_region'                
=> 'adr_one_region', 
!                                               'adr_one_postalcode'    => 
'adr_one_postalcode',
!                                               'adr_one_countryname'   => 
'adr_one_countryname',
!                                               'adr_one_type'                  
=> 'adr_one_type',
!                                               'label'                         
        => 'label',
!                                               'adr_two_street'                
=> 'adr_two_street',
!                                               'adr_two_locality'              
=> 'adr_two_locality', 
!                                               'adr_two_region'                
=> 'adr_two_region', 
!                                               'adr_two_postalcode'    => 
'adr_two_postalcode',
!                                               'adr_two_countryname'   => 
'adr_two_countryname',
!                                               'adr_two_type'                  
=> 'adr_two_type',
!                                               'tel_work'                      
        => 'tel_work',
!                                               'tel_home'                      
        => 'tel_home',
!                                               'tel_voice'                     
        => 'tel_voice',
!                                               'tel_fax'                       
        => 'tel_fax', 
!                                               'tel_msg'                       
        => 'tel_msg',
!                                               'tel_cell'                      
        => 'tel_cell',
!                                               'tel_pager'                     
        => 'tel_pager',
!                                               'tel_bbs'                       
        => 'tel_bbs',
!                                               'tel_modem'                     
        => 'tel_modem',
!                                               'tel_car'                       
        => 'tel_car',
!                                               'tel_isdn'                      
        => 'tel_isdn',
!                                               'tel_video'                     
        => 'tel_video',
!                                               'tel_prefer'                    
=> 'tel_prefer',
!                                               'email'                         
        => 'email',
!                                               'email_type'                    
=> 'email_type',
!                                               'email_home'                    
=> 'email_home',
!                                               'email_home_type'               
=> 'email_home_type'
!               );
! 
!                       }
!                       
!                       /*!
!                       * @function map_record
!                       * @abstract ABSTRACT METHOD additional field 
manipulation before export/import
!                       * @param $record - the record to be manipulated
!                       * @param $to_phpgw - is record going to phpgw? (import 
- true/ export - false)
!                       */
!                       function map_record($record, $to_phpgw=true)
!                       {
!                               return $record;
!                       }
! 
!                       /*!
!                       * @function phpgw_add
!                       * @abstract add a new record to the phpgw contacts 
repository
!                       * @param $record - array of field/value pairs - 
$record['id'] is remote_id
!                       * @param $public - boolean - is record public?
!                       * @param $cat - mapped category_id to be used 
!                       */
!                       function phpgw_add($record, $public=true, 
$category_id='')
!                       {
!                               if(@$this->implemented_methods['map_record'])
!                               {
!                                       $record = $this->map_record($record, 
true);
!                               }
! 
!                               $remote_id = (int) $record['id'];
!                               unset($record['id']);
! 
!                               $this->update_map(2);
!                               
!                               $cat_id = (int) (strlen($cat)>1 && 
isset($GLOBALS['phpgw_info']['user']['preferences']['default_category'])
!                                                               ? 
$GLOBALS['phpgw_info']['user']['preferences']['default_category']
!                                                               : $category_id);
! 
!                               $access = ($public ? 'public' : 'private'); 
!                               
!                               $phpgw_id = 
$this->contacts->add($owner,$fields,$access,$cat_id);
!                               $this->common->update_match($phpgw_id, 
$remote_id, PHPGW_SYNC_STATUS_ACTIVE);
!                       }
! 
!                       /*!
!                       * @function phpgw_delete
!                       * @abstract archive a record in the phpgw contacts 
repository - record remains in phpgw but is no longer sync'd 
!                       * @param $phpgw_id - record_id in phpgw contacts 
repsository 
!                       * @param $remote_id - record_id in remote system/device 
contacts system
!                       */
!                       function phpgw_archive($phpgw_id, $remote_id)
!                       {
!                               $phpgw_id = (int) $phpgw_id;
!                               $remote_id = (int) $remote_id;
!                               $this->common->update_match($phpgw_id, 
$remote_id, PHPGW_SYNC_STATUS_ARCHIVED);
!                       }
!                       
!                       /*!
!                       * @function phpgw_delete
!                       * @abstract delete a record from the phpgw contacts 
repository 
!                       * @param $phpgw_id - record_id in phpgw contacts 
repsository 
!                       * @param $remote_id - record_id in remote system/device 
contacts system
!                       */
!                       function phpgw_delete($phpgw_id, $remote_id)
!                       {
!                               $phpgw_id = (int) $phpgw_id;
!                               $remote_id = (int) $remote_id;
!                               $this->contacts->delete($phpgw_id);
!                               $this->common->update_match($phpgw_id, 
$remote_id, PHPGW_SYNC_STATUS_DELETED);
!                       }
!                       
!                       /*!
!                       * @function phpgw_update
!                       * @abstract update an exiting record in the phpgw 
contacts repository - it will add it if it doesn't exist
!                       * @param $record - array of field/value pairs - 
$record['id'] is remote_id
!                       * @param $public - boolean - is record public?
!                       * @param $cat - mapped category_id to be used 
!                       */
!                       function phpgw_update($record, $public=true, 
$category_id='')
!                       {
!                               $status = $this->common->find_match((int) 
$record['id']);
!                               if($status === false)//must be new
!                               {
!                                       $this->phpgw_add($record, $public, 
$category_id)
!                               }
! 
!                               if($status == PHPGW_SYNC_STATUS_ACTIVE)//all 
others are irrelevant
!                               {
!                               if(@$this->implemented_methods['map_record'])
!                               {
!                                       $record = $this->map_record($record, 
true);
!                               }
!                               
!                               $remote_id = (int) $record['id'];
!                               unset($record['id']);
!   
!                               $this->update_map(2);
!                               
!                               $cat_id = (int) (strlen($cat)>1 && 
isset($GLOBALS['phpgw_info']['user']['preferences']['default_category'])
!                                                               ? 
$GLOBALS['phpgw_info']['user']['preferences']['default_category']
!                                                               : $category_id);
!   
!                               $access = ($public ? 'public' : 'private'); 
!                               
!                               $phpgw_id = 
$this->contacts->add($owner,$fields,$access,$cat_id);
!                               $this->common->update_match($phpgw_id, 
$remote_id, PHPGW_SYNC_STATUS_ACTIVE);
!                               }
!                       }
! 
!                       /*!
!                       * @function update_map
!                       * @abstract updates field mappings in contacts class
!                       * @param $map - 0=default, 1=from phpgw, 2=to phpgw 
!                       */
!                       function update_map($type=0)
!                       {
!                               switch $type
!                               {
!                                       case 1:
!                                               
$contacts->$stock_contact_fields = $this->get_map_from();
!                                               break;
! 
!                                       case 2:
!                                               
$contacts->$stock_contact_fields = $this->get_map_to();
!                                               break;
! 
!                                       case 0:
!                                       case default:
!                                               
$contacts->$stock_contact_fields = $this->get_map_default();
!                                               break;
!                               }
!                       }
! 
!               }
!     /*!
!     @class_end contacts_base
!     */
! 
! ?>
--- 1,360 ----
! <?php
!     
/**************************************************************************\
!     * phpGroupWare - Sync                                                     
           *
!     * http://www.phpgroupware.org                                             
 *
!     * Written by Dave Hall [skwashd AT phpgroupware.org]                      
           *
!     * 
------------------------------------------------------------------------ *
!     *  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.                                             
 *
!     
\**************************************************************************/
!               
!     /*!
!     @class_start contacts_base
!     @abstract Abstract Class for syncing contacts data 
!     */
! 
!               class contacts_base
!               {
!                       var $implementation; //type of implementation in non 
abstract class
!                       var $implemented_methods = null;
!                       
!                       //class containters
!                       var $common;  //container for common object
!                       var $contacts;  //container for contacts object
! 
!                       function contacts_base()
!                       {
!                               /* This will be uncommented soon 
!                               if(strcasecmp(get_class($this), 
'contacts_base') == 0)
!                               {
!                                       trigger_error('Cannot instantiate 
abstract class ' . get_class($this), E_USER_ERROR);
!                                       return NULL; 
!                               }*/
!                               $this->common = createObject('sync.common_' . 
$this->implementation);
!                               $this->contacts = 
createObject('phpgwapi.contacts');
!                       }
!                       
!                       /*!
!                       * @function get_dirty_recs
!                       * @abstract returns a list of records which were 
editted/created since last sync
!                       * @param $get_all - boolean - get all records - ignore 
the last sync timestamp
!                       */
!                       function get_dirty_recs($get_all = false)
!                       {
!                               $lastmod = (int) ( (bool) $get_all ? 0 : 
$this->common->lastsync); 
!                               $dirty_recs = $this->contacts->read( 0, 0, '', 
'', '', 'id', 'ASC', $lastmod);
!                               foreach($dirty_recs as $rec_id => $rec_vals)
!                               {
!                                       $mapped_recs[$rec_id] = 
$this->map_record($record, false); 
!                               }
!                               return $mapped_recs;
!                       }
! 
!                       /*!
!                       * @function get_map_default
!                       * @abstract maps contact class fieldnames to stock 
mappings
!                       */
!                       function get_map_default()
!                       {
!                               //unused fields should be removed in concrete 
version
!                               return array('fn'                               
        => 'fn',
!                               'n_given'                               => 
'n_given',
!                               'n_family'                              => 
'n_family',
!                                                       'n_middle'              
                => 'n_middle',
!                                               'n_prefix'                      
        => 'n_prefix',
!                                               'n_suffix'                      
        => 'n_suffix',
!                                               'sound'                         
        => 'sound',
!                                               'bday'                          
        => 'bday',
!                                               'note'                          
        => 'note',
!                                               'tz'                            
        => 'tz',
!                                               'geo'                           
        => 'geo',
!                                               'url'                           
        => 'url',
!                                               'pubkey'                        
        => 'pubkey',
!                                               'org_name'                      
        => 'org_name',
!                                               'org_unit'                      
        => 'org_unit',
!                                               'title'                         
        => 'title',
!                                               'adr_one_street'                
=> 'adr_one_street',
!                                               'adr_one_locality'              
=> 'adr_one_locality', 
!                                               'adr_one_region'                
=> 'adr_one_region', 
!                                               'adr_one_postalcode'    => 
'adr_one_postalcode',
!                                               'adr_one_countryname'   => 
'adr_one_countryname',
!                                               'adr_one_type'                  
=> 'adr_one_type',
!                                               'label'                         
        => 'label',
!                                               'adr_two_street'                
=> 'adr_two_street',
!                                               'adr_two_locality'              
=> 'adr_two_locality', 
!                                               'adr_two_region'                
=> 'adr_two_region', 
!                                               'adr_two_postalcode'    => 
'adr_two_postalcode',
!                                               'adr_two_countryname'   => 
'adr_two_countryname',
!                                               'adr_two_type'                  
=> 'adr_two_type',
!                                               'tel_work'                      
        => 'tel_work',
!                                               'tel_home'                      
        => 'tel_home',
!                                               'tel_voice'                     
        => 'tel_voice',
!                                               'tel_fax'                       
        => 'tel_fax', 
!                                               'tel_msg'                       
        => 'tel_msg',
!                                               'tel_cell'                      
        => 'tel_cell',
!                                               'tel_pager'                     
        => 'tel_pager',
!                                               'tel_bbs'                       
        => 'tel_bbs',
!                                               'tel_modem'                     
        => 'tel_modem',
!                                               'tel_car'                       
        => 'tel_car',
!                                               'tel_isdn'                      
        => 'tel_isdn',
!                                               'tel_video'                     
        => 'tel_video',
!                                               'tel_prefer'                    
=> 'tel_prefer',
!                                               'email'                         
        => 'email',
!                                               'email_type'                    
=> 'email_type',
!                                               'email_home'                    
=> 'email_home',
!                                               'email_home_type'               
=> 'email_home_type'
!               );
! 
!                       }
! 
!                       /*!
!                       * @function get_map_from
!                       * @abstract maps contact class fieldnames custom 
mappings for exporting records
!                       */
!                       function get_map_from()
!                       {
!                               //unused fields should be removed in concrete 
version
!                               return array('fn'                               
        => 'fn',
!                               'n_given'                               => 
'n_given',
!                               'n_family'                              => 
'n_family',
!                                                       'n_middle'              
                => 'n_middle',
!                                               'n_prefix'                      
        => 'n_prefix',
!                                               'n_suffix'                      
        => 'n_suffix',
!                                               'sound'                         
        => 'sound',
!                                               'bday'                          
        => 'bday',
!                                               'note'                          
        => 'note',
!                                               'tz'                            
        => 'tz',
!                                               'geo'                           
        => 'geo',
!                                               'url'                           
        => 'url',
!                                               'pubkey'                        
        => 'pubkey',
!                                               'org_name'                      
        => 'org_name',
!                                               'org_unit'                      
        => 'org_unit',
!                                               'title'                         
        => 'title',
!                                               'adr_one_street'                
=> 'adr_one_street',
!                                               'adr_one_locality'              
=> 'adr_one_locality', 
!                                               'adr_one_region'                
=> 'adr_one_region', 
!                                               'adr_one_postalcode'    => 
'adr_one_postalcode',
!                                               'adr_one_countryname'   => 
'adr_one_countryname',
!                                               'adr_one_type'                  
=> 'adr_one_type',
!                                               'label'                         
        => 'label',
!                                               'adr_two_street'                
=> 'adr_two_street',
!                                               'adr_two_locality'              
=> 'adr_two_locality', 
!                                               'adr_two_region'                
=> 'adr_two_region', 
!                                               'adr_two_postalcode'    => 
'adr_two_postalcode',
!                                               'adr_two_countryname'   => 
'adr_two_countryname',
!                                               'adr_two_type'                  
=> 'adr_two_type',
!                                               'tel_work'                      
        => 'tel_work',
!                                               'tel_home'                      
        => 'tel_home',
!                                               'tel_voice'                     
        => 'tel_voice',
!                                               'tel_fax'                       
        => 'tel_fax', 
!                                               'tel_msg'                       
        => 'tel_msg',
!                                               'tel_cell'                      
        => 'tel_cell',
!                                               'tel_pager'                     
        => 'tel_pager',
!                                               'tel_bbs'                       
        => 'tel_bbs',
!                                               'tel_modem'                     
        => 'tel_modem',
!                                               'tel_car'                       
        => 'tel_car',
!                                               'tel_isdn'                      
        => 'tel_isdn',
!                                               'tel_video'                     
        => 'tel_video',
!                                               'tel_prefer'                    
=> 'tel_prefer',
!                                               'email'                         
        => 'email',
!                                               'email_type'                    
=> 'email_type',
!                                               'email_home'                    
=> 'email_home',
!                                               'email_home_type'               
=> 'email_home_type'
!               );
! 
!                       }
! 
!                       /*!
!                       * @function get_map_to
!                       * @abstract maps contact class fieldnames custom 
mappings for importing records
!                       */
!                       function get_map_to()
!                       {
!                               //unused fields should be removed in concrete 
version
!                               return array('fn'                               
        => 'fn',
!                               'n_given'                               => 
'n_given',
!                               'n_family'                              => 
'n_family',
!                                                       'n_middle'              
                => 'n_middle',
!                                               'n_prefix'                      
        => 'n_prefix',
!                                               'n_suffix'                      
        => 'n_suffix',
!                                               'sound'                         
        => 'sound',
!                                               'bday'                          
        => 'bday',
!                                               'note'                          
        => 'note',
!                                               'tz'                            
        => 'tz',
!                                               'geo'                           
        => 'geo',
!                                               'url'                           
        => 'url',
!                                               'pubkey'                        
        => 'pubkey',
!                                               'org_name'                      
        => 'org_name',
!                                               'org_unit'                      
        => 'org_unit',
!                                               'title'                         
        => 'title',
!                                               'adr_one_street'                
=> 'adr_one_street',
!                                               'adr_one_locality'              
=> 'adr_one_locality', 
!                                               'adr_one_region'                
=> 'adr_one_region', 
!                                               'adr_one_postalcode'    => 
'adr_one_postalcode',
!                                               'adr_one_countryname'   => 
'adr_one_countryname',
!                                               'adr_one_type'                  
=> 'adr_one_type',
!                                               'label'                         
        => 'label',
!                                               'adr_two_street'                
=> 'adr_two_street',
!                                               'adr_two_locality'              
=> 'adr_two_locality', 
!                                               'adr_two_region'                
=> 'adr_two_region', 
!                                               'adr_two_postalcode'    => 
'adr_two_postalcode',
!                                               'adr_two_countryname'   => 
'adr_two_countryname',
!                                               'adr_two_type'                  
=> 'adr_two_type',
!                                               'tel_work'                      
        => 'tel_work',
!                                               'tel_home'                      
        => 'tel_home',
!                                               'tel_voice'                     
        => 'tel_voice',
!                                               'tel_fax'                       
        => 'tel_fax', 
!                                               'tel_msg'                       
        => 'tel_msg',
!                                               'tel_cell'                      
        => 'tel_cell',
!                                               'tel_pager'                     
        => 'tel_pager',
!                                               'tel_bbs'                       
        => 'tel_bbs',
!                                               'tel_modem'                     
        => 'tel_modem',
!                                               'tel_car'                       
        => 'tel_car',
!                                               'tel_isdn'                      
        => 'tel_isdn',
!                                               'tel_video'                     
        => 'tel_video',
!                                               'tel_prefer'                    
=> 'tel_prefer',
!                                               'email'                         
        => 'email',
!                                               'email_type'                    
=> 'email_type',
!                                               'email_home'                    
=> 'email_home',
!                                               'email_home_type'               
=> 'email_home_type'
!               );
! 
!                       }
!                       
!                       /*!
!                       * @function map_record
!                       * @abstract ABSTRACT METHOD additional field 
manipulation before export/import
!                       * @param $record - the record to be manipulated
!                       * @param $to_phpgw - is record going to phpgw? (import 
- true/ export - false)
!                       */
!                       function map_record($record, $to_phpgw=true)
!                       {
!                               return $record;
!                       }
! 
!                       /*!
!                       * @function phpgw_add
!                       * @abstract add a new record to the phpgw contacts 
repository
!                       * @param $record - array of field/value pairs - 
$record['id'] is remote_id
!                       * @param $public - boolean - is record public?
!                       * @param $cat - mapped category_id to be used 
!                       */
!                       function phpgw_add($record, $public=true, 
$category_id='')
!                       {
!                               if(@$this->implemented_methods['map_record'])
!                               {
!                                       $record = $this->map_record($record, 
true);
!                               }
! 
!                               $remote_id = (int) $record['id'];
!                               unset($record['id']);
! 
!                               $this->update_map(2);
!                               
!                               $cat_id = (int) (strlen($cat)>1 && 
isset($GLOBALS['phpgw_info']['user']['preferences']['default_category'])
!                                                               ? 
$GLOBALS['phpgw_info']['user']['preferences']['default_category']
!                                                               : $category_id);
! 
!                               $access = ($public ? 'public' : 'private'); 
!                               
!                               $phpgw_id = 
$this->contacts->add($owner,$fields,$access,$cat_id);
!                               $this->common->update_match($phpgw_id, 
$remote_id, PHPGW_SYNC_STATUS_ACTIVE);
!                       }
! 
!                       /*!
!                       * @function phpgw_delete
!                       * @abstract archive a record in the phpgw contacts 
repository - record remains in phpgw but is no longer sync'd 
!                       * @param $phpgw_id - record_id in phpgw contacts 
repsository 
!                       * @param $remote_id - record_id in remote system/device 
contacts system
!                       */
!                       function phpgw_archive($phpgw_id, $remote_id)
!                       {
!                               $phpgw_id = (int) $phpgw_id;
!                               $remote_id = (int) $remote_id;
!                               $this->common->update_match($phpgw_id, 
$remote_id, PHPGW_SYNC_STATUS_ARCHIVED);
!                       }
!                       
!                       /*!
!                       * @function phpgw_delete
!                       * @abstract delete a record from the phpgw contacts 
repository 
!                       * @param $phpgw_id - record_id in phpgw contacts 
repsository 
!                       * @param $remote_id - record_id in remote system/device 
contacts system
!                       */
!                       function phpgw_delete($phpgw_id, $remote_id)
!                       {
!                               $phpgw_id = (int) $phpgw_id;
!                               $remote_id = (int) $remote_id;
!                               $this->contacts->delete($phpgw_id);
!                               $this->common->update_match($phpgw_id, 
$remote_id, PHPGW_SYNC_STATUS_DELETED);
!                       }
!                       
!                       /*!
!                       * @function phpgw_update
!                       * @abstract update an exiting record in the phpgw 
contacts repository - it will add it if it doesn't exist
!                       * @param $record - array of field/value pairs - 
$record['id'] is remote_id
!                       * @param $public - boolean - is record public?
!                       * @param $cat - mapped category_id to be used 
!                       */
!                       function phpgw_update($record, $public=true, 
$category_id='')
!                       {
!                               $status = $this->common->find_match((int) 
$record['id']);
!                               if($status === false)//must be new
!                               {
!                                       $this->phpgw_add($record, $public, 
$category_id)
!                               }
! 
!                               if($status == PHPGW_SYNC_STATUS_ACTIVE)//all 
others are irrelevant
!                               {
!                               if(@$this->implemented_methods['map_record'])
!                               {
!                                       $record = $this->map_record($record, 
true);
!                               }
!                               
!                               $remote_id = (int) $record['id'];
!                               unset($record['id']);
!   
!                               $this->update_map(2);
!                               
!                               $cat_id = (int) (strlen($cat)>1 && 
isset($GLOBALS['phpgw_info']['user']['preferences']['default_category'])
!                                                               ? 
$GLOBALS['phpgw_info']['user']['preferences']['default_category']
!                                                               : $category_id);
!   
!                               $access = ($public ? 'public' : 'private'); 
!                               
!                               $phpgw_id = 
$this->contacts->add($owner,$fields,$access,$cat_id);
!                               $this->common->update_match($phpgw_id, 
$remote_id, PHPGW_SYNC_STATUS_ACTIVE);
!                               }
!                       }
! 
!                       /*!
!                       * @function update_map
!                       * @abstract updates field mappings in contacts class
!                       * @param $map - 0=default, 1=from phpgw, 2=to phpgw 
!                       */
!                       function update_map($type=0)
!                       {
!                               switch $type
!                               {
!                                       case 1:
!                                               
$contacts->$stock_contact_fields = $this->get_map_from();
!                                               break;
! 
!                                       case 2:
!                                               
$contacts->$stock_contact_fields = $this->get_map_to();
!                                               break;
! 
!                                       case 0:
!                                       case default:
!                                               
$contacts->$stock_contact_fields = $this->get_map_default();
!                                               break;
!                               }
!                       }
! 
!               }
!     /*!
!     @class_end contacts_base
!     */
! 
! ?>





reply via email to

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