phpgroupware-cvs
[Top][All Lists]
Advanced

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

[Phpgroupware-cvs] old/cdb/inc class.cdb_contact_phone.inc.php, 1.1 clas


From: skwashd
Subject: [Phpgroupware-cvs] old/cdb/inc class.cdb_contact_phone.inc.php, 1.1 class.cdb_contact_personal.inc.php, 1.1 class.cdb_contact_internet.inc.php, 1.1 class.cdb_entity.inc.php, 1.1 class.cdb_entity_meta.inc.php, 1.1 class.cdb_organization_client.inc.php, 1.1 class.cdb_organization.inc.php, 1.1 class.cdb_generic.inc.php, 1.1 class.cdb_contact_client.inc.php, 1.1 class.cdb_contact_address.inc.php, 1.1 class.bo.inc.php, 1.1 class.cdb_contact.inc.php, 1.1 class.cdb_address.inc.php, 1.1 class.bo_filter.inc.php, 1.1 class.cdb_organization_location.inc.php, 1.1 class.cdb_phone.inc.php, 1.1 class.ui.inc.php, 1.1 class.so.inc.php, 1.1 class.cdb_template.inc.php, 1.1 class.ui_generic.inc.php, 1.1 class.ui_overview.inc.php, 1.1
Date: Thu, 5 May 2005 02:56:00 +0200

Update of old/cdb/inc

Added Files:
     Branch: MAIN
            class.cdb_contact_phone.inc.php 
            class.cdb_contact_personal.inc.php 
            class.cdb_contact_internet.inc.php 
            class.cdb_entity.inc.php 
            class.cdb_entity_meta.inc.php 
            class.cdb_organization_client.inc.php 
            class.cdb_organization.inc.php 
            class.cdb_generic.inc.php 
            class.cdb_contact_client.inc.php 
            class.cdb_contact_address.inc.php 
            class.bo.inc.php 
            class.cdb_contact.inc.php 
            class.cdb_address.inc.php 
            class.bo_filter.inc.php 
            class.cdb_organization_location.inc.php 
            class.cdb_phone.inc.php 
            class.ui.inc.php 
            class.so.inc.php 
            class.cdb_template.inc.php 
            class.ui_generic.inc.php 
            class.ui_overview.inc.php 

Log Message:
cvs clean up

====================================================
Index: class.cdb_contact_phone.inc.php
<?php
  /**************************************************************************\
  * phpGroupWare                                                             *
  * http://www.phpgroupware.org/                                             *
  * This file written by Patrick Walsh <address@hidden>            *
  * ------------------------------------------------------------------------ *
  * Please see the documentation for these classes in the README file in     *
  * this directory.                                                          *
  * ------------------------------------------------------------------------ *
  *  This program is free software; you can redistribute it and/or modify it *
  *  under the terms of the GNU General Public License as published by the   *
  *  Free Software Foundation; either version 2 of the License, or (at your  *
  *  option) any later version.                                              *
  \**************************************************************************/

  /* $Id: class.cdb_contact_phone.inc.php,v 1.1 2005/05/05 00:56:39 skwashd Exp 
$ */

        class cdb_contact_phone extends cdb_generic
        {
                var $_phone_list;
                var $_db;

                function cdb_contact_phone()
                {
                        $this->_db = $GLOBALS['phpgw']->db;
                        /* add vars that have get/let interface to this array. 
*/
                        $this->_ = array(
                        );
                }

                function save()
                {
                        reset($this->_phone_list);
                        $retval = FALSE;
                        while (list($key,$value) = $this->_phone_list)
                        {
                                if ($value->save())
                                {
                                        $retval = TRUE;
                                }
                        }
                        return $retval;
                }

                function load($entity_id)
                {
                        $this->_phone_list = array();
                        $this->_id = $entity_id;
                        $this->_loaded = TRUE;
                        $sql = 'SELECT contact_phone_id FROM 
phpgw_cdb_contact_phone WHERE ' .
                                'entity_id="' . $entity_id . '"';
                        $this->_db->query($sql,__LINE__,__FILE__);
            while ($this->_db->next_record())
            {
                                $this->_phone_list[] = 
CreateObject('cdb.cdb_phone');
                                $x = $this->_db->f('contact_phone_id');
                                $this->_phone_list[$x]->load($x);
                        }
                        return TRUE;
                }

                function get_phone_list()
                {
                        return $this->_phone_list;
                }
        }
?>

====================================================
Index: class.cdb_contact_personal.inc.php
<?php
  /**************************************************************************\
  * phpGroupWare                                                             *
  * http://www.phpgroupware.org/                                             *
  * This file written by Miles Lott <address@hidden>                        *
  * With contributions from mr_e and bjmorel                                 *
  * ------------------------------------------------------------------------ *
  * Please see the documentation for these classes in the README file in     *
  * this directory.                                                          *
  * ------------------------------------------------------------------------ *
  *  This program is free software; you can redistribute it and/or modify it *
  *  under the terms of the GNU General Public License as published by the   *
  *  Free Software Foundation; either version 2 of the License, or (at your  *
  *  option) any later version.                                              *
  \**************************************************************************/

  /* $Id: class.cdb_contact_personal.inc.php,v 1.1 2005/05/05 00:56:39 skwashd 
Exp $ */

  /* This file is to be considered broken and wip */

        class cdb_contact_personal extends cdb_generic_class
        {
                function cdb_contact_personal()
                {
                        /* add vars that have get/let interface to this array. 
*/
                        $this->_db = $GLOBALS['phpgw']->db;
                        $this->_ = array(
                                'contact_id'    => 0,
                                'birthday'      => 0,
                                'children'      => '',
                                // one of "unspecified", "male", or "female"
                                'gender'        => 'unspecified',
                                'gov_id_num'    => '',
                                'hobbies'       => '',
                                'language'      => 0,
                                'spouse'        => '',
                                'anniversary'   => 0
                        );
                }

                function get_birthday()
                {
                        return $this->_get('birthday');
                }

                function let_birthday($new_birthday)
                {
                        return $this->_let('birthday', $new_birthday);
                }

                function get_children()
                {
                        return $this->_get('children');
                }

                function let_children($new_children)
                {
                        return $this->_let('children', $new_children);
                }

                function get_gender()
                {
                        return $this->_get('gender');
                        #returns 'unspecified'|'male'|'female'
                }

                function let_gender($new_gender)
                {
                        switch($new_gender)
                        {
                                case 'unspecified':
                                case 'male':
                                case 'female':
                                        return $this->_let('gender', 
$new_gender);
                                default:
                                        return FALSE;
                        }
                }

                function get_gov_id()
                {
                        return $this->_get('gov_id_num');
                }

                function let_gov_id($new_gov_id)
                {
                        return $this->_let('gov_id_num', $new_gov_id);
                }

                function get_hobbies()
                {
                        return $this->_get('hobbies');
                }

                function let_hobbies($new_hobbies)
                {
                        return $this->_let('hobbies', $new_hobbies);
                }

                function get_language()
                {
                        return $this->_get('language');
                }

                function let_language($new_language)
                {
                        return $this->_let('language', $new_language);
                }

                function get_spouse()
                {
                        return $this->_get('spouse');
                }

                function let_spouse($new_spouse)
                {
                        return $this->_let('spouse', $new_spouse);
                }

                function get_anniversary()
                {
                        return $this->_get('anniversary');
                }

                function let_anniversary($new_anniversary)
                {
                        return $this->_let('anniversary', $new_anniversary);
                }

                function save()
                {
                        if($this->id() && $this->contact_exists($this->id()) && 
$this->can_write())
                        {
                                $sqlp = "UPDATE phpgw_cdb_contact_personal SET 
";
                                if ($this->_dirty_vars())
                                {
                                reset($this->_dirty);
                                        do
                                        {
                                                $key = key($this->_dirty);
                                                $sql.=$key.'="';
                                                $sql .= $this->_get($key) . '", 
';
                                        }
                                        while (next($this->_dirty));
                                        if ($sql)
                                        {
                                                $sql .= 'contact_id="' . 
$this->get_contact_id().'"'.
                                                        ' WHERE 
contact_id="'.$this->get_contact_id().'"';
                                                
$this->_db->query($sqlp.$sql,__LINE__,__FILE__);
                                        }
                                }

                        $this->_dirty = array();

                                return TRUE;
                        }
                        else
                        {
                                //TODO: raise a major error!
                                return FALSE;
                        }
                }

                function load($contact_id)
                {
                        if (!$this->contact_exists($contact_id))
                        {
                                $this->_create($contact_id);
                        }
                        $this->_loaded = FALSE;

                        $sql = 'SELECT * FROM phpgw_cdb_contact_personal WHERE 
contact_id="' .
                        $contact_id.'"';
                        $this->_db->query($sql,__LINE__,__FILE__);

                        reset($this->_);
                        do
                        {
                        $key = key($this->_);
                        $this->_let($key,$this->_db->f($key));
                        }
                        while(next($this->_));

                        $this->_dirty = array();
                        $this->_loaded = TRUE;
                        return TRUE;

                }

                /*!
                @function contact_exists
                @abstract Checks the existence of contact_id
                @discussion Checks for the existence of contact_id
                */
                function contact_exists($contact_id)
                {
                        if (!is_int($contact_id))
                        {
                                $contact_id = $this->_get('contact_id');
                        }
                        $sql='SELECT * FROM phpgw_cdb_contact_personal WHERE 
contact_id="' .
                                $contact_id.'"';
                        $this->_db->query($sql,__LINE__,__FILE__);
                        if ($this->_db->num_rows() > 0)
                        {
                                return TRUE;
                        }
                        else
                        {
                                return FALSE;
                        }
                }

                /*!
                @function _create
                @abstract Creates a new record in the cdb_contact_personal DB
                @discussion New with default values
                */
                function _create($contact_id)
                {
                        if (!is_int($contact_id))
                        {
                                $contact_id = $this->_get('contact_id');
                        }

                        $sql='INSERT INTO phpgw_cdb_contact_personal 
("contact_id", ' .
                                '"birthday", "children", "gender", 
"gov_id_num", ' .
                                '"hobbies", "language", "spouse", "anniversary" 
) ' .
                                'VALUES ("' . $contact_id . '", "0", "", 
"unspecified", ' .
                                '"", "", "0", "", "0")';
                        $this->_db->query($sql,__LINE__,__FILE__);

                }

        }

?>

====================================================
Index: class.cdb_contact_internet.inc.php
<?php
  /**************************************************************************\
  * phpGroupWare                                                             *
  * http://www.phpgroupware.org/                                             *
  * This file written by Brian Morel <brianmorel AT yahoo DOT com>           *
  * ------------------------------------------------------------------------ *
  * Please see the documentation for these classes in the README file in     *
  * this directory.                                                          *
  * ------------------------------------------------------------------------ *
  *  This program is free software; you can redistribute it and/or modify it *
  *  under the terms of the GNU General Public License as published by the   *
  *  Free Software Foundation; either version 2 of the License, or (at your  *
  *  option) any later version.                                              *
  \**************************************************************************/

  /* $Id: class.cdb_contact_internet.inc.php,v 1.1 2005/05/05 00:56:39 skwashd 
Exp $ */

  /* This file is to be should work, but needs to be tested*/

        class cdb_contact_internet extends cdb_generic_class
        {
                function cdb_contact_internet()
                {
                        /* add vars that have get/let interface to this array. 
*/
                        $this->_db = $GLOBALS['phpgw']->db;
                        $this->_ = array(
                                'contact_id'                 => 0,
                                'email_home'                 => '',
                                'email_home_display'         => '',
                                'email_business'             => '',
                                'email_business_display'     => '',
                                'email_other'                => '',
                                'email_other_display'        => '',
                                'ftp'                        => '',
                                'free_busy_address'          => '',
                                'personal_home_page'         => '',
                                'business_home_page'         => '',
                                'other_home_page'            => '',
                                'send_as_plain_text'         => 1,
                                'icq'                        => ''
                        );
                }

                function get_email_home()
                {
                        return $this->_get('email_home');
                }

                function let_email_home($new_email_home)
                {
                        return $this->_let('email_home', $new_email_home);
                }

                function get_email_home_display()
                {
                        return $this->_get('email_home_display');
                }

                function let_email_home_display($new_email_home_display)
                {
                        return $this->_let('email_home_display', 
$new_email_home_display);
                }

                function get_email_business()
                {
                        return $this->_get('email_business');
                }

                function let_email_business($new_email_business)
                {
                        return $this->_let('email_business', 
$new_email_business);
                }

                function get_email_business_display()
                {
                        return $this->_get('email_business_display');
                }

                function let_email_business_display($new_email_business_display)
                {
                        return $this->_let('email_business_display', 
$new_email_business_display);
                }

                function get_email_other()
                {
                        return $this->_get('email_other');
                }

                function let_email_other($new_email_other)
                {
                        return $this->_let('email_other', $new_email_other);
                }

                function get_email_other_display()
                {
                        return $this->_get('email_other_display');
                }

                function let_email_other_display($new_email_other_display)
                {
                        return $this->_let('email_other_display', 
$new_email_other_display);
                }

                function get_ftp()
                {
                        return $this->_get('ftp');
                }

                function let_ftp($new_ftp)
                {
                        return $this->_let('ftp', $new_ftp);
                }

                function get_free_busy_address()
                {
                        return $this->_get('free_busy_address');
                }

                function let_free_busy_address($new_free_busy_address)
                {
                        return $this->_let('free_busy_address', 
$new_free_busy_address);
                }

                function get_personal_home_page()
                {
                        return $this->_get('personal_home_page');
                }

                function let_personal_home_page($new_personal_home_page)
                {
                        return $this->_let('personal_home_page', 
$new_personal_home_page);
                }

                function get_business_home_page()
                {
                        return $this->_get('business_home_page');
                }

                function let_business_home_page($new_business_home_page)
                {
                        return $this->_let('business_home_page', 
$new_business_home_page);
                }

                function get_other_home_page()
                {
                        return $this->_get('other_home_page');
                }

                function let_other_home_page($new_other_home_page)
                {
                        return $this->_let('other_home_page', 
$new_other_home_page);
                }

                function get_send_as_plain_text()
                {
                        return $this->_get('send_as_plain_text');
                }

                function let_send_as_plain_text($new_send_as_plain_text)
                {
                        return $this->_let('send_as_plain_text', 
$new_send_as_plain_text);
                }

                function get_icq()
                {
                        return $this->_get('icq');
                }

                function let_icq($new_icq)
                {
                        return $this->_let('icq', $new_icq);
                }

                function save()
                {
                        if($this->id() && $this->contact_exists($this->id()) && 
$this->can_write())
                        {
                                $sqlp = "UPDATE phpgw_cdb_contact_internet SET 
";
                                if ($this->_dirty_vars())
                                {
                                reset($this->_dirty);
                                        do
                                        {
                                                $key = key($this->_dirty);
                                                $sql.=$key.'="';
                                                $sql .= $this->_get($key) . '", 
';
                                        }
                                        while (next($this->_dirty));
                                        if ($sql)
                                        {
                                                $sql .= 'contact_id="' . 
$this->get_contact_id().'"'.
                                                        ' WHERE 
contact_id="'.$this->get_contact_id().'"';
                                                
$this->_db->query($sqlp.$sql,__LINE__,__FILE__);
                                        }
                                }

                                $this->_dirty = array();

                                return TRUE;
                        }
                        else
                        {
                                //TODO: raise a major error!
                                return FALSE;
                        }
                }

                function load($contact_id)
                {
                        if (!$this->contact_exists($contact_id))
                        {
                                $this->_create($contact_id);
                        }

                        $this->_loaded = FALSE;
                        $this->_dirty = array();

                        $sql = 'SELECT * FROM phpgw_cdb_contact_internet WHERE 
contact_id="' .
                                $contact_id.'"';
                        $this->_db->query($sql,__LINE__,__FILE__);

                        reset($this->_);
                        do
                        {
                                $key = key($this->_);
                                $this->_let($key,$this->_db->f($key));
                        }
                        while(next($this->_));

                        $this->_loaded = TRUE;
                        return TRUE;

                }

                /*!
                @function contact_exists
                @abstract Checks the existence of contact_id
                @discussion Checks for the existence of contact_id
                */
                function contact_exists($contact_id)
                {
                        if (!is_int($contact_id))
                        {
                                $contact_id = $this->_get('contact_id');
                        }

                        $sql='SELECT * FROM phpgw_cdb_contact_internet WHERE 
contact_id="' .
                                $contact_id.'"';
                        $this->_db->query($sql,__LINE__,__FILE__);
                        if ($this->_db->num_rows() > 0)
                        {
                                return TRUE;
                        }
                        else
                        {
                                return FALSE;
                        }
                }

                /*!
                @function _create
                @abstract Creates a new record in the cdb_contact_internet DB
                @discussion New with default values
                */
                function _create($contact_id)
                {
                        if (!is_int($contact_id))
                        {
                                $contact_id = $this->_get('contact_id');
                        }

                        $sql='INSERT INTO phpgw_cdb_contact_internet 
("contact_id", ' .
                                '"email_home", ' .
                                '"email_home_display", ' .
                                '"email_business", ' .
                                '"email_business_display", ' .
                                '"email_other", ' .
                                '"email_other_display", ' .
                                '"ftp", ' .
                                '"free_busy_address", ' .
                                '"personal_home_page", ' .
                                '"business_home_page", ' .
                                '"other_home_page", ' .
                                '"send_as_plain_text", ' .
                                '"icq" ' .
                                ') ' .
                                'VALUES ("' .
                                $contact_id .
                                '", ' .
                                '"", "", "", "", "", "", "", "", "", "", "", 
"1", "")';

                                $this->_db->query($sql,__LINE__,__FILE__);

                }

        }
?>

====================================================
Index: class.cdb_entity.inc.php
<?php
  /**************************************************************************\
  * phpGroupWare                                                             *
  * http://www.phpgroupware.org/                                             *
  * This file written by Patrick Walsh <address@hidden>            *
  * ------------------------------------------------------------------------ *
  * Please see the documentation for these classes in the README file in     *
  * this directory.                                                          *
  * ------------------------------------------------------------------------ *
  *  This program is free software; you can redistribute it and/or modify it *
  *  under the terms of the GNU General Public License as published by the   *
  *  Free Software Foundation; either version 2 of the License, or (at your  *
  *  option) any later version.                                              *
  \**************************************************************************/

  /* $Id: class.cdb_entity.inc.php,v 1.1 2005/05/05 00:56:39 skwashd Exp $ */

/*!
                @class cdb_entity
                @abstract Root Entity Class
                @discussion This class is a container that holds either an 
organization
                class object or a contact class object.
                @syntax CreateObject('cdb.cdb_entity');
                @example $x = CreateObject('cdb.cdb_entity');
                @example x->let_type("contact");
                @example x->get_contact_data();
                @author mr_e
                @copyright GPL
                @package cdb
                @access public
*/
        class cdb_entity extends cdb_generic
        {
        /***************************\
                *      Local Variables      *
        \***************************/

                /* PHP does not support local vars.  Use
                   'var $_varname;' to signify local vars.       */
                var $_contact;  // my contact subclass
                var $_org;              // my org subclass

                function cdb_entity()
                {
                        $this->_db = $GLOBALS['phpgw']->db;
                        $this->_ = array(
                                //Either 'contact' or 'organization'
                                'entity_type' => 'contact',
                                //if entity_type='organization' and loaded=true 
then this
                                //contains the loaded org data
                                'organization_obj' => '',
                                //if entity_type='contact' and loaded==true 
then this contains
                                //the loaded contact data
                                'contact_obj' => ''
                        );
                }

                /*!
                @function load
                @abstract Loads an entity into the entity object
                @discussion Loads an entity into the entity object
                @syntax int load(int entity_id)
                @example1 $x->load($entity_id)
                @param entity_id int-the global entity id (not org id or 
contact id)
                */
                function load($entity_id)
                {
                        // Unload everything first
                        unset($this->_org);
                        unset($this->_contact);
                        $this->_loaded = FALSE;
                        $this->_id = 0;

                        $sql = 'SELECT * FROM phpgw_cdb_entity_id WHERE ' .
                                'entity_id="'.$entity_id.'"';
                        $this->_db->query($sql,__LINE__,__FILE__);
                        if ($this->_db->next_record())
                        {
                                $contact_id = $this->_db->f('contact_id');
                                $org_id = $this->_db->f('organization_id');
                                $this->_id = $entity_id;
                                if ($contact_id)
                                {
                                        $this->_let('entity_type','contact');
                                        $this->_contact = 
CreateObject('cdb.cdb_contact');
                                        if ($this->_contact->load($contact_id))
                                        {
                                                $this->_loaded = TRUE;
                                                return $this->id();
                                        }
                                        else
                                        {
                                                return FALSE;
                                        }
                                }
                                else if ($org_id)
                                {
                                        
$this->_let('entity_type','organization');
                                        $this->_org = 
CreateObject('cdb.cdb_organization');
                                        if ($this->_org->load($org_id))
                                        {
                                                $this->_loaded = TRUE;
                                                return $this->id();
                                        }
                                        else
                                        {
                                                return FALSE;
                                        }
                                }
                                else
                                {
                                        return FALSE;
                                }
                        }
                        else
                        {
                                return FALSE;
                        }
                }

                /*!
                @function create
                @abstract Creates a new entity
                @discussion Creates a new entity of type specified
                @syntax int create(str entity_type)
                @example1 $x->create('organization')
                @param entity_type str-either "contact" or "organization"
                */
                function create($entity_type)
                {
                        unset($this->_org);
                        unset($this->_contact);
                        $this->_loaded = FALSE;
                        $this->_id = 0;

                        if ($entity_type == 'contact')
                        {
                                $this->_let('entity_type','contact');
                                $this->_contact = 
CreateObject('cdb.cdb_contact');
                                if ($this->_contact->create(''))
                                {
                                        $this->_id = $this->_contact->id();
                                        $this->_loaded = TRUE;
                                        return $this->id();
                                }
                                else
                                {
                                        // TODO: raise phpgw error
                                        return FALSE;
                                }
                        }
                        else if ($entity_type == 'organization')
                        {
                                $this->_let('entity_type','organization');
                                $this->_org = 
CreateObject('cdb.cdb_organization');
                                if ($org_id = $this->_org->create(''))
                                {
                                        $sql = 'INSERT INTO phpgw_cdb_entity_id 
("organization_id") VALUES ("' . $org_id . '")';
                                        
$this->_db->query($sql,__LINE__,__FILE__);
                                        $this->_id = 
$this->_db->get_last_insert_id('phpgw_cdb_entity_id','entity_id');
                                        $this->_loaded = TRUE;
                                        return $this->id();
                                }
                                else
                                {
                                        return FALSE;
                                }
                        }
                        else
                        {
                                //TODO raise a phpgw error
                                return FALSE;
                        }
                }

                /*!function delete
                @abstract Move the entity to the trashcan
                @discussion Mark the entity as deleted
                */
                function delete()
                {
                        //TODO: call contact.delete or org.delete
                }
                /*!
                @function exists
                @abstract See if entity exists
                */
            function exists($entity_id='')
        {
                if (!is_int($entity_id))
                {
                $entity_id = $this->id();
                }
                $sql='SELECT * FROM phpgw_cdb_entity_id WHERE 
entity_id="'.$entity_id.'"';
                $this->_db->query($sql,__LINE__,__FILE__);
                if ($this->_db->num_rows() > 0)
                {
                return TRUE;
                }
                else
                {
                return FALSE;
                }
        }

                /*!
                @function get_type
                @abstract Get's the entity type
                @discussion Returns either "contact" or "organization" -- gets 
the
                        type of the currently loaded id or if entity_id is 
passed,
                        checks that id instead.
                @example1 $x->get_type();
                @example2 $x->get_type(123);
                */
                function get_type($entity_id='')
                {
                        if (is_int($entity_id))
                        {
                                $sql = 'SELECT * FROM phpgw_cdb_entity_id WHERE 
' .
                                        'entity_id="'.$entity_id.'"';
                                $this->_db->query($sql,__LINE__,__FILE__);
                                $contact_id = $this->_db->f('contact_id');
                                $org_id = $this->_db->f('organization_id');
                                if ($contact_id)
                                {
                                        return 'contact';
                                }
                                else if ($org_id)
                                {
                                        return 'organization';
                                }
                                else
                                {
                                        return FALSE;
                                }
                        }
                        else
                        {
                                return $this->_get('entity_type');
                        }
                }

                /*!
                @function get_organization_data
                @abstract Returns the loaded org class, if one exists
                @discussion This is an alias of get_org_data
                */
                function get_organization_data()
                {
                        return get_org_data();
                }

                /*!
                @function get_org_data
                @abstract Returns the loaded org class, if one exists
                */
                function get_org_data()
                {
                        if ($this->loaded() && 
$this->get_type()=='organization')
                        {
                                return $_org;
                        }
                        else
                        {
                                return FALSE;
                        }
                }

                /*!
                @function get_contact_data
                @abstract Returns the loaded contact class, if one exists
                */
                function get_contact_data()
                {
                        if ($this->loaded() && $this->get_type()=='contact')
                        {
                                return $_contact;
                        }
                        else
                        {
                                return FALSE;
                        }
                }

                /*!
                @function get_data
                @abstract Returns whichever class is loaded or null if neither
                */
                function get_data()
                {
                        if ($this->get_type() == "contact")
                        {
                                return get_contact_data();
                        }
                        else
                        {
                                return get_org_data();
                        }
                }
        } // end class
?>

====================================================
Index: class.cdb_entity_meta.inc.php
<?php
  /**************************************************************************\
  * phpGroupWare                                                             *
  * http://www.phpgroupware.org/                                             *
  * This file written by Patrick Walsh <address@hidden>            *
  * ------------------------------------------------------------------------ *
  * Please see the documentation for these classes in the README file in     *
  * this directory.                                                          *
  * ------------------------------------------------------------------------ *
  *  This program is free software; you can redistribute it and/or modify it *
  *  under the terms of the GNU General Public License as published by the   *
  *  Free Software Foundation; either version 2 of the License, or (at your  *
  *  option) any later version.                                              *
  \**************************************************************************/

  /* $Id: class.cdb_entity_meta.inc.php,v 1.1 2005/05/05 00:56:39 skwashd Exp $ 
*/

        /*!
        @class cdb_entity_meta
        @abstract Meta data for entities
        @syntax CreateObject('cdb.cdb_entity_meta');
        @example $x = CreateObject('cdb.cdb_entity_meta');
        @author mr_e
        @copyright GPL
        @package cdb
        @access public
        */

        class cdb_entity_meta extends cdb_generic
        {
                var $_modified;

                function cdb_entity_meta()
                {
                        $this->_db = $GLOBALS['phpgw']->db;
                        $this->_ = array(
                                //'contact' or 'organization'
                                'entity_type'           => 'contact',
                                //'pending','active',or'deleted'
                                'status'                => 'pending',
                                'created'               => 0,
                                'modified'              => 0,
                                'file_as'               => '',
                                'followup_status'       => 0,
                                'created_by'            => 0,
                                'keywords'              => '',
                                'group_access'          => 0,
                                'version'               => $GLOBALS['cdb_ver'],
                                'ldap_sync'             => 0,
                                'ldap_dn'               => ''
                        );
                }

                /*!
                @function get_type
                @abstract Returns the entity type
                @discussion Returns either 'contact' or 'organization'
                */
                function get_type()
                {
                        return $this->_get('entity_type');
                }

                /*!
                @function let_type
                @abstract Sets the entity type
                @discussion Returns either 'contact' or 'organization'
                */
                function let_type($new_type)
                {
                        if (strtolower($new_type) == 'contact')
                        {
                                $this->_let('entity_type', 'contact');
                        }
                        elseif(strtolower(substr($new_type,0,3)) == 'org')
                        {
                                $this->_let('entity_type', 'organization');
                        }
                }

                /*!
                @function save
                @abstract Saves any changed meta data
                @discussion Returns true if any data has changed and false if 
nothing
                                has changed.
                */
                function save()
                {
                        if($this->id() && $this->exists($this->id()) && 
$this->can_write()
                                && $this->loaded())
                        {
                                // Build query
                                $sqlp = "UPDATE phpgw_cdb_entity_meta SET ";
                                reset($this->_dirty);
                                do
                                {
                                        $key = key($this->_dirty);
                                        switch($key)
                                        {
                                                default:
                                                        $sql.=$key.'="';
                                        }
                                        $sql .= $this->_get($key) . '", ';
                                }
                                while (next($this->_dirty));
                                if ($sql || $this->_modified)
                                {
                                        //There was dirty data, so update the 
modified date
                                        $sql .= 'modified="' . time() . '"' .
                                                ' WHERE entity_id="' . 
$this->id() . '"';
                                        
$this->_db->query($sqlp.$sql,__LINE__,__FILE__);
                                        $this->_modified = FALSE;
                                        $this->_dirty = array();
                                        return TRUE;
                                }
                                else
                                {
                                        return FALSE;
                                }
                        }
                        else
                        {
                                //TODO: raise a major error!  Can't save an 
unloaded class
                                return FALSE;
                        }
                }

                function load($entity_id)
                {
                        $this->_loaded = FALSE;
                        $this->_modified = FALSE;
                        $this->_id = 0;

                        // Retrieve the type of entity.  If the entity doesn't 
exist,
                        // FALSE will be returned and we should return false as 
well.
                        $entity = CreateObject('cdb.cdb_entity');
                        if (! $type = $entity->get_type($entity_id))
                        {
                                return FALSE;
                        }

                        $this->_id = $entity_id;

                        $sql = 'SELECT * FROM phpgw_cdb_entity_meta WHERE 
entity_id="'.
                                        $entity_id . '"';
                        $this->_db->query($sql,__LINE__,__FILE__);

                        reset($this->_);
                        do
                        {
                                $key = key($this->_);
                                switch($key)
                                {
                                        case 'entity_type':
                                                $this->_let($key,$type);
                                                break;
                                        default:
                                                
$this->_let($key,$this->_db->f($key));
                                }
                        }
                        while(next($this->_));
                        $this->_loaded = TRUE;
                }

                function create($entity_id)
                {
                        $status = "active";
                        $sql = 'INSERT INTO phpgw_cdb_entity_meta 
("entity_id","status",' .
                                
'"created","modified","file_as","created_by","version") ' .
                                'VALUES 
("'.$this->id().'","'.$status.'","'.time().'","' .
                                time().'","'.$file_as.'","' .
                                
$GLOBALS['phpgw_info']['user']['account_id'].'","' .
                                $cdb_ver.'")';
                                $this->_db->query($sql,__LINE__,__FILE__);
                }

                function date_created()
                {
                        return $this->_get('created');
                }

                function set_modified()
                {
                        $this->_modified=TRUE;
                }

                function date_modified()
                {
                        return $this->_get('modified');
                }

                function created_by()
                {
                        return $this->_get('created_by');
                }

                function version()
                {
                        return $this->_get('version');
                }

                function get_status()
                {
                        /* Can be either 'active', 'pending', 'deleted' */
                        return $this->_get('status');
                }

                function let_status($status)
                {
                        switch ($status)
                        {
                                case 'active':
                                case 'pending':
                                case 'deleted':
                                        return $this->_let('status', $status);
                                        break;
                                default:
                                        return FALSE;
                        }
                }

                function get_file_as()
                {
                        return $this->_get('file_as');
                }

                function let_file_as($file_as)
                {
                        return $this->_let('file_as', $file_as);
                }

                function get_followup_status()
                {
                        return $this->_get('followup_status');
                }

                function let_followup_status($followup)
                {
                        if(is_int($intStatus))
                        {
                                //TODO: Check for valid followup status
                                return $this->_let('followup_status', 
$intStatus);
                        }
                        else
                        {
                                return FALSE;
                        }
                }

                function get_keywords()
                {
                        return $this->_get('keywords');
                }

                function let_keywords($keywords)
                {
                        /* keywords should either be an array or a comma 
separated list */
                        if(is_array($keywords))
                        {
                                return $this->_let('keywords', 
implode(',',$keywords));
                        }
                        else if (is_string($keywords))
                        {
                                return $this->_let('keywords',$keywords);
                        }
                        else
                        {
                                return FALSE;
                        }
                }

                function get_group_access()
                {
                        return $this->_get('group_access');
                }

                function let_group_access($groupaccess)
                {
                        if(is_int($groupaccess))
                        {
                                return $this->_let('group_access', 
$groupaccess);
                        }
                        else
                        {
                                return FALSE;
                        }
                }

                function get_ldap_sync()
                {
                        return $this->_get('ldap_sync');
                }

                function let_ldap_sync($ldap_sync)
                {
                        return $this->_let(intval($ldap_sync));
                }

                function get_ldap_dn()
                {
                        /*  if ldap_sync is true, and this record has already 
been
                        propogated, then this will return the dn which can 
directly
                        reference the ldap entry.
                        */
                        $this->_get('ldap_dn');
                }

                function let_ldap_dn($ldap_dn)
                {
                        return $this->_let('ldap_dn');
                }
        }
?>

====================================================
Index: class.cdb_organization_client.inc.php
<?php
  /**************************************************************************\
  * phpGroupWare                                                             *
  * http://www.phpgroupware.org/                                             *
  * This file written by Brian Morel < brianmorel AT yahoo DOT com >         *
  * ------------------------------------------------------------------------ *
  * Please see the documentation for these classes in the README file in     *
  * this directory.                                                          *
  * ------------------------------------------------------------------------ *
  *  This program is free software; you can redistribute it and/or modify it *
  *  under the terms of the GNU General Public License as published by the   *
  *  Free Software Foundation; either version 2 of the License, or (at your  *
  *  option) any later version.                                              *
  \**************************************************************************/

  /* $Id: class.cdb_organization_client.inc.php,v 1.1 2005/05/05 00:56:39 
skwashd Exp $ */

        class cdb_organization_client extends cdb_generic
        {
                function cdb_organization_client()
                {
                        $this->_ = array(
                                'organization_id'       => 0,
                                'account'               => '',
                                'billing_info'          => '',
                                'customer_id'           => '',
                                'referred_by'           => ''
                                );
                }

                function get_organization_id()
                {
                        return $this->_get('organization_id');
                }

                function get_account()
                {
                        return $this->_get('account');
                }

                function let_account($new_account)
                {
                        return $this->_let('account', $new_account);
                }

                function get_billing_info()
                {
                        return $this->_get('billing_info');
                }

                function let_billing_info($new_billing_info)
                {
                        return $this->_let('billing_info', $new_billing_info);
                }

                function get_customer_id()
                {
                        return $this->_get('customer_id');
                }

                function let_customer_id($new_customer_id)
                {
                        return $this->_let('customer_id', $new_customer_id);
                }

                function get_referred_by()
                {
                        return $this->_get('referred_by');
                }

                function let_referred_by($new_referred_by)
                {
                        return $this->_let('referred_by', $new_referred_by);
                }

                function save()
                {
                        if($this->id() && 
$this->client_exists($this->get_organization_id()) && $this->can_write())
                        {
                                $sqlp = "UPDATE phpgw_cdb_org_client SET ";
                                if ($this->_dirty_vars())
                                {
                                reset($this->_dirty);
                                        do
                                        {
                                                $key = key($this->_dirty);
                                                switch($key)
                                                {
                                                        case 'organization_id' :
                                                                break;
                                                        default:
                                                                $sql.=$key.'="';
                                                                $sql .= 
$this->_get($key) . '", ';
                                                }
                                        }
                                        while (next($this->_dirty));

                                        if ($sql)
                                        {
                                                $sql .= 'organization_id="' . 
$this->get_organization_id().'"'.
                                                        ' WHERE 
organization_id="'.$this->get_organization_id().'"';
                                                
$this->_db->query($sqlp.$sql,__LINE__,__FILE__);
                                        }
                                }

                        $this->_dirty = array();

                                return TRUE;
                        }
                        else
                        {
                                //TODO: raise a major error!
                                return FALSE;
                        }
                }

                function load($organization_id)
                {
                        $this->_loaded = FALSE;

                        $sql = 'SELECT * FROM phpgw_cdb_org_client WHERE 
organization_id="' .
                        $organization . '"';
                        $this->_db->query($sql,__LINE__,__FILE__);

                        reset($this->_);
                        do
                        {
                                $key = key($this->_);
                                $this->_let($key,$this->_db->f($key));
                        }
                        while(next($this->_));

                        $this->_dirty = array();
                        $this->_loaded = TRUE;
                        return TRUE;

                }

                function create()
                {
                        $sql='INSERT INTO phpgw_cdb_org_client( ' .
                                '"account", ' .
                                '"billing_info", ' .
                                '"customer_id", ' .
                                '"referred_by" ) ' .
                                'VALUES ("", "", "", "")';
                        $this->_db->query($sql,__LINE__,__FILE__);
                        return 
$this->_db->get_last_insert_id('phpgw_cdb_org_client',
                                'organization_id');

                }

                function client_exists($organization_id)
                {
                        if (!is_int($organization_id))
                        {
                                $organization_id = 
$this->_get('organization_id');
                        }
                        $sql='SELECT * FROM phpgw_cdb_org_client WHERE 
organization_id="' .
                                $organization_id.'"';
                        $this->_db->query($sql,__LINE__,__FILE__);
                        if ($this->_db->num_rows() > 0)
                        {
                                return TRUE;
                        }
                        else
                        {
                                return FALSE;
                        }
                }
        }
?>

====================================================
Index: class.cdb_organization.inc.php
<?php
        
/**************************************************************************\
        * phpGroupWare                                                          
   *
        * http://www.phpgroupware.org/                                          
   *
        * This file written by Brian Morel < brianmorel AT yahoo DOT com >      
   *
        * 
------------------------------------------------------------------------ *
        * Please see the documentation for these classes in the README file in  
   *
        * this directory.                                                       
   *
        * 
------------------------------------------------------------------------ *
        * This program is free software; you can redistribute it and/or modify 
it  *
        * under the terms of the GNU General Public License as published by the 
   *
        * Free Software Foundation; either version 2 of the License, or (at 
your   *
        * option) any later version.                                            
   *
        
\**************************************************************************/

        /* $Id: class.cdb_organization.inc.php,v 1.1 2005/05/05 00:56:39 
skwashd Exp $ */

/*!
        @class cdb_organization
        @abstract Root Organization Class
        @syntax CreateObject('cdb.cdb_organization');
        @example $x = CreateObject('cdb.cdb_organization');
        @author bjmorel
        @copyright GPL
        @package cdb
        @access public
*/
        class cdb_organization extends cdb_generic
        {
                var $_meta;
                var $_location;
                var $_client;

                function cdb_organization()
                {
                        $this->_db = $GLOBALS['phpgw']->db;
                        $this->_ = array(
                                'organization_id'               => 0,
                                'organization_name'             => '',
                                'organization_home_page'        => '',
                                'organization_network_name'     => '',
                                'organization_org_id_num'       => '',
                                'main_location'                 => 0,
                                'note'                          => ''
                        );
                }

         /************************\
         *    Public Functions    *
         \************************/
                /*!
                @function organization_id
                @abstract Returns the organization id
                @discussion Returns the organization id or zero if no contact 
loaded
                */
                function organization_id()
                {
                        return $this->_get('organization_id');
                }

                /*!
                @function create
                @abstract Create a new organization
                @syntax int create(str name)
                @discussion This adds an entry to the cdb_organization,
                cdb_entity_id, cdb_entity_notes and cdb_entity_meta.
                Returns true on success and false on failure.
                @example1 $organization_id = $x->create("Org Inc.");
                @example2 $organization_id = $x->create();
                @param name str-the optional name of the organization
                */
                function create($name)
                {
                        global $cdb_ver;
                        unset($this->_meta);
                        unset($this->_client);
                        $this->_id = 0;
                        $this->_let('organization_id',0);

                        // Create entry in organization
                        $sql = 'INSERT INTO phpgw_cdb_org ("organization_name") 
' .
                                        'VALUES ("'.$name.'")';
                        $this->_db->query($sql,__LINE__,__FILE__);
                        $this->_let('organization_id',
                                        
$this->_db->get_last_insert_id('phpgw_cdb_org',
                                        'organization_id'));

                        // Create entity_id entry
                        $sql = 'INSERT INTO phpgw_cdb_entity_id 
("organization_id") VALUES ("' .
                                        $organization_id . '")';
                        $this->_db->query($sql,__LINE__,__FILE__);
                        $this->_id = 
$this->_db->get_last_insert_id('phpgw_cdb_entity_id',
                                        'entity_id');

                        // Create entry in entity_meta
                        $status = "active";
                        $sql = 'INSERT INTO phpgw_cdb_entity_meta ("entity_id", 
' .
                                        '"status", ' .
                                        '"created", ' .
                                        '"modified", ' .
                                        '"file_as", ' .
                                        '"created_by", ' .
                                        '"version") ' .
                                        'VALUES ("' .
                                        $this->id() . '","' .
                                        $status . '","' .
                                        time() . '","' .
                                        time() . '","' .
                                        $name . '","' .
                                        
$GLOBALS['phpgw_info']['user']['account_id'] . '","' .
                                        $cdb_ver . '")';
                        $this->_db->query($sql,__LINE__,__FILE__);

                        // Create enry in entity_note
                        $sql = 'INSERT INTO phpgw_cdb_entity_notes 
("entity_id","note") VALUES ' .
                                        '("' . $this->id() . '","")';
                        $this->_db->query($sql,__LINE__,__FILE__);

                        $this->_meta = CreateObject('cdb.cdb_entity_meta');
                        $this->_meta->load($this->id());

                        return $this->id();
                }

                /*!
                @function organization_exists
                @abstract Checks the existence of organization_id
                @discussion Checks for the existence of organization_id
                */
                function organization_exists($organization_id)
                {
                        if (!is_int($organization_id))
                        {
                                $organization_id = 
$this->_get('organization_id');
                        }
                        $sql='SELECT * FROM phpgw_cdb_entity_id WHERE 
organization_id="' .
                                $organization_id . '"';
                        $this->_db->query($sql,__LINE__,__FILE__);
                        if ($this->_db->num_rows() > 0)
                        {
                                return $this->_db->f('entity_id');
                        }
                        else
                        {
                                return FALSE;
                        }
                }

                /*!
                @function save
                @abstract Save recent changes
                @syntax int save()
                @discussion This will use the _dirty array to determine what 
needs
                        to be written to the database and then write it.  
Returns true when
                        changes have been made and false if none have been made.
                @example1 if ($x->save())
                        {
                                print lang('Changes saved.');
                        }
                        else
                        {
                                print lang('No changes saved.');
                        }
                */
                function save()
                {
                        if($this->id() && $this->exists($this->id()) && 
$this->can_write()
                                && $this->get_loaded())
                        {
                                //TODO need to save the children if they are 
loaded
                                if (isset($this->_client))
                                {
                                        if ($this->_client->save())
                                        {
                                                $this->_meta->set_modified();
                                        }
                                }
                                if (isset($this->_location))
                                {
                                        if ($this->_location->save())
                                        {
                                                $this->_meta->set_modified();
                                        }
                                }


                                // Build update query
                                $sqlp = "UPDATE phpgw_cdb_org SET ";
                                if ($this->_dirty_vars())
                                {
                                        $this->_meta->set_modified();

                                        reset($this->_dirty);
                                        do
                                        {
                                                $key = key($this->_dirty);
                                                switch($key)
                                                {
                                                        case 'note' :
                                                                // the note is 
in a diff table
                                                                // sine it's by 
itself, just do db now
                                                                $sql2.='UPDATE 
phpgw_cdb_entity_notes SET note="'.
                                                                                
$this->get_note().'" WHERE entity_id="'.
                                                                                
$this->id().'"';
                                                                
$this->_db->query($sql2,__LINE__,__FILE__);
                                                                
$this->_meta->set_modified();
                                                                break;
                                                        case 'organization_id':
                                                                break;
                                                        default:
                                                                $sql.=$key.'="';
                                                                $sql .= 
$this->_get($key) . '", ';
                                                }
                                        }
                                        while (next($this->_dirty));
                                        if ($sql)
                                        {
                                                $sql .= 'organization_id="' . 
$this->get_organization_id().'"'.
                                                        ' WHERE 
organization_id="'.$this->get_organization_id().'"';
                                                
$this->_db->query($sqlp.$sql,__LINE__,__FILE__);
                                        }
                                }

                                $this->_meta->save();
                                $this->_dirty = array();

                                return TRUE;
                        }
                        else
                        {
                                //TODO: raise a major error!
                                return FALSE;
                        }
                }

                /*!
                @function load
                @abstract Load a organization
                @syntax int load(int contact_id)
                @discussion Populate the data with data from the database.  
Returns
                        true on success and false on failure.  The important 
thing is that
                        this function takes the organization_id and not the 
entity_id.  If you
                        want to use the entity id, create an entity object and 
use that
                        load function instead.
                @example1 $x->load(234);
                */
                function load($organization_id)
                {
                        // Don't worry about the status (deleted vs. active) 
here...

                        // Simultaneously check existence of contact_id and get 
entity_id
                        if (! $entity_id = $this->exists($organization_id))
                        {
                                return FALSE;
                        }
                        $this->_id = $entity_id;
                        $this->_loaded = FALSE;
                        $this->_dirty = array();

                        // Now lookup the main contact info
                        $sql = 'SELECT * FROM phpgw_cdb_org WHERE 
organization_id="' .
                                        $organization_id.'"';
                        $this->_db->query($sql,__LINE__,__FILE__);

                        reset($this->_);
                        do
                        {
                                $key = key($this->_);
                                switch($key)
                                {
                                        case 'note':
                                                // the note is in a diff table
                                                // just ignore it for now and 
we'll load it in a min
                                                break;
                                        case 'organization_id':
                                                
$this->_let('organization_id',$organization_id);
                                                break;
                                        default:
                                                
$this->_let($key,$this->_db->f($key));
                                }
                        }
                        while(next($this->_));

                        // Now take care of the note
                        $sql = 'SELECT note FROM phpgw_cdb_entity_notes WHERE 
entity_id="' .
                                        $this->id() . '"';
                        $this->_db->query($sql,__LINE__,__FILE__);
                        $this->_let('note',$this->_db->f('note'));

                        //TODO: Now load the meta object
                        $this->_meta = CreateObject('cdb.cdb_entity_meta');
                        $this->_meta->load($this->id());

                        $this->_loaded = TRUE;
                        $this->_dirty = array();
                        return TRUE;

                }

                function delete()
                {
                        if($this->can_write()) // check for write permission
                        {
                                $this->get_meta->let_status('delete');
                                return TRUE;
                        }
                        return FALSE;
                }

                function empty_trash()
                {
                        //TODO: delete where status=deleted
                }

                function get_client_data()
                {
                        /* TODO: need to check to be sure client has been 
loaded */
                        return $this->_client;
                }
                function get_meta_data()
                {
                        /* TODO */
                        return $this->_meta;
                }
                function get_location_data( $location )
                {
                        /* TODO */
                        // return contact.location.class; // This is a syntax 
error
                }

                function get_name()
                {
                        return $this->_get('organization_name');
                }
                function let_name($new_name)
                {
                        $mySuccess = False;
                        if(strlen($new_name)<=100)
                        {
                                $mySuccess = 
$this->_let('organization_name',$new_name);
                        }
                        return $mySuccess;
                }

                function get_home_page()
                {
                        return $this->_get('organization_home_page');
                }
                function let_home_page($new_home_page)
                {
                        $mySuccess = False;
                        if(strlen($new_home_page)<=65535)
                        {
                                $mySuccess = 
$this->_let('organization_home_page', $new_home_page);
                        }
                        return $mySuccess;
                }
                function get_network_name()
                {
                        return $this->_get('organization_network_name');
                }
                function let_network_name($new_network_name)
                {
                        /* NOTE Due to database restrictions the network_name */
                        /* can be no longer than 20 characters */
                        $mySuccess = False;
                        if(strlen($new_network_name)<=100)
                        {
                                $mySuccess = 
$this->_let('organization_network_name', $new_network_name);
                        }
                        return $mySuccess;
                }
                function get_gov_id_num()
                {
                        return $this->_get('organization_gov_id_num');
                }
                function let_gov_if_num($new_gov_id_num)
                {
                        /* NOTE Due to database restrictions the gov_id_num */
                        /* can be no longer than 20 characters */
                        $mySuccess = False;
                        if(strlen($new_gov_id_num)<=20)
                        {
                                $mySuccess = 
$this->_let('organization_gov_id_num', $new_gov_id_num);
                        }
                        return $mySuccess;
                }

                function get_main_location()
                {
                        return $this->_get('main_location');
                }

                function let_main_location( $new_main_location )
                {
                        $this->_let('main_location', $new_main_location);
                }

                function get_note()
                {
                        return $this->_get('note');
                }

                function let_note($note)
                {
                        /* NOTE Due to database restrictions the note */
                        /* can be no longer than 65535 characters */
                        if(strlen($note)<=65535)
                        {
                                return $this->_let('note', $note);
                        }
                        return FALSE;
                }

                function get_locations()
                {
                        $_location_list = array();

                        $sql = 'SELECT location_id, location FROM ' .
                                'cdb_org_locations WHERE organization_id="' .
                                get_organization_id() . '"';

                        $this->_db->query($sql,__LINE__,__FILE__);

                        $_location_list[$this->_db->f('location_id')] = 
$this->_db->f('location');

                        for ( $i = 0; $i < $this->_db->num_rows(); ++$i )
                        {
                                $this->_db->next_record();
                                $_location_list[$this->_db->f('location_id')] = 
$this->_db->f('location');
                        }

                        return $_location_list;
                }

        }
?>

====================================================
Index: class.cdb_generic.inc.php
<?php
  /**************************************************************************\
  * phpGroupWare                                                             *
  * http://www.phpgroupware.org/                                             *
  * This file written by Patrick Walsh <address@hidden>            *
  * ------------------------------------------------------------------------ *
  * Please see the documentation for these classes in the README file in     *
  * this directory.                                                          *
  * ------------------------------------------------------------------------ *
  *  This program is free software; you can redistribute it and/or modify it *
  *  under the terms of the GNU General Public License as published by the   *
  *  Free Software Foundation; either version 2 of the License, or (at your  *
  *  option) any later version.                                              *
  \**************************************************************************/

  /* $Id: class.cdb_generic.inc.php,v 1.1 2005/05/05 00:56:39 skwashd Exp $ */


        /* This class is extended by all cdb classes */
        class cdb_generic {

         /**************************\
         *     Public Variables     *
         \**************************/

         /**************************\
         *      Local Variables     *
         \**************************/

         /******************************************\
         * PHP does not support local vars.  Use    *
         * 'var $_varname;' to signify local vars.  *
         \******************************************/

        var $_ = array();
        var $_dirty = array();
        var $_id = 0;
        var $_db;
        var $_loaded;

         /**************************\
         *    Private Functions     *
         \**************************/
        function _var_valid($var)
        {
                if (! $this->_loaded)
                {
                        //TODO raise an error
                        print ('Class not loaded');
                        return FALSE;
                }
                if (isset($this->_[$var]))
                {
                        return TRUE;
                }
                else
                {
                        //TODO Raise a phpgw error and make a stink
                        // but for now, just write a message:
                        print ('Bad variable '.$var);
                        return FALSE;
                }
        }

        function _let($var, $val)
        {
                if ($this->_var_valid($var) && $this->can_write()) {
                        if ($this->_get($var) != $val)
                        {
                                // new value, so make it dirty
                                $this->_dirty[$var] = 1;
                                $this->_[$var] = $val;

                                return TRUE; //signal that a change was made
                        }
                }
                return FALSE; //signal that no change was made
        }

        function _get($var)
        {
                if ($this->_var_valid($var) && $this->can_read())
                {
                        return $this->_[$var];
                }
                else
                {
                        return FALSE;
                }
        }

        function _dirty_vars()
        {
                if (is_array($this->_dirty) && count($this->_dirty)>0)
                {
                        return TRUE;
                }
                else
                {
                        return FALSE;
                }
        }

        function dirty($dirty_prop)
        {
                if ($this->_var_exists($var))
                {
                        $this->_dirty[$dirty_prop]=1;
                        return TRUE;
                }
                else
                {
                        return FALSE;
                }
        }

         /**************************\
         *     Public Functions     *
         \**************************/
        function id()
        {
                return (int)$this->_id;
        }

        function get_entity_id_from_contact($contact_id)
        {
                $tmpdb = $GLOBALS['phpgw']->db;
                $sql = 'SELECT * FROM phpgw_cdb_entity_id WHERE contact_id="' .
                        $contact_id . '"';
                $tmpdb->query($sql,__LINE__,__FILE__);
                return $tmpdb->f('entity_id');
        }

        function get_entity_id_from_org($org_id)
        {
                $tmpdb = $GLOBALS['phpgw']->db;
                $sql = 'SELECT * FROM phpgw_cdb_entity_id WHERE 
organization_id="' .
                        $org_id . '"';
                $tmpdb->query($sql,__LINE__,__FILE__);
                return $tmpdb->f('entity_id');
        }

        /*!
        @function loaded
        @abstract Returns true if a entity is loaded in memory
        */
        function loaded()
        {
                return $this->_loaded;
        }

        function can_read($entity_id)
        {
                //TODO: check for read permissions
                $retval = TRUE;
                if(is_int($entity_id))
                {
                        // do stuff
                }
                else
                {
                        $entity_id = $this->id();
                }
                return $retval;
        }

        function can_write($entity_id)
        {
                //TODO: check for write permissions
                $retval = TRUE;
                if(is_int($entity_id))
                {
                        // do stuff
                }
                else
                {
                        $entity_id = $this->id();
                }
                return $retval;
        }

}
?>

====================================================
Index: class.cdb_contact_client.inc.php
<?php
  /**************************************************************************\
  * phpGroupWare                                                             *
  * http://www.phpgroupware.org/                                             *
  * This file written by Brian Morel < brianmorel AT yahoo DOT com >         *
  * ------------------------------------------------------------------------ *
  * Please see the documentation for these classes in the README file in     *
  * this directory.                                                          *
  * ------------------------------------------------------------------------ *
  *  This program is free software; you can redistribute it and/or modify it *
  *  under the terms of the GNU General Public License as published by the   *
  *  Free Software Foundation; either version 2 of the License, or (at your  *
  *  option) any later version.                                              *
  \**************************************************************************/

  /* $Id: class.cdb_contact_client.inc.php,v 1.1 2005/05/05 00:56:39 skwashd 
Exp $ */

  /* This file needs testing */

        class cdb_contact_client extends cdb_generic_class
        {
                function cdb_contact_client()
                {
                        /* add vars that have get/let interface to this array. 
*/
                        $this->_db = $GLOBALS['phpgw']->db;
                        $this->_ = array(
                                'contact_id'    => 0,
                                'account'       => '',
                                'billing_info'  => '',
                                'customer_id'   => '',
                                'referred_by'   => ''
                                );
                }

                function get_contact_id()
                {
                        return $this->_get('contact_id');
                }

                function get_account()
                {
                        return $this->_get('account');
                }

                function let_account($new_account)
                {
                        return $this->_let('account', $new_account);
                }

                function get_billing_info()
                {
                        return $this->_get('billing_info');
                }

                function let_billing_info($new_billing_info)
                {
                        return $this->_let('billing_info', $new_billing_info);
                }

                function get_cutomer_id()
                {
                        return $this->_get('customer_id');
                }

                function let_customer_id($new_customer_id)
                {
                        return $this->_let('customer_id', $new_customer_id);
                }

                function get_referred_by()
                {
                        return $this->_get('referred_by');
                }

                function let_referred_by($new_referred_by)
                {
                        return $this->_let('referred_by', $new_referred_by);
                }

                /*!
                @function save
                @abstract Saves a record in the cdb_contact_client DB
                @discussion checks for existence and writeing
                */
                function save()
                {
                        if($this->id() && $this->contact_exists($this->id()) && 
$this->can_write())
                        {
                                $sqlp = "UPDATE phpgw_cdb_contact_client SET ";
                                if ($this->_dirty_vars())
                                {
                                        reset($this->_dirty);
                                        do
                                        {
                                                $key = key($this->_dirty);
                                                switch($key)
                                                {
                                                        case 'contact_id':
                                                                break;
                                                        default:
                                                                $sql.=$key.'="';
                                                                $sql .= 
$this->_get($key) . '", ';
                                                }
                                        }
                                        while (next($this->_dirty));
                                        if ($sql)
                                        {
                                                $sql .= 'contact_id="' . 
$this->get_contact_id().'"'.
                                                        ' WHERE 
contact_id="'.$this->get_contact_id().'"';
                                                
$this->_db->query($sqlp.$sql,__LINE__,__FILE__);
                                        }
                                }

                        $this->_dirty = array();

                                return TRUE;
                        }
                        else
                        {
                                //TODO: raise a major error!
                                return FALSE;
                        }
                }

                /*!
                @function load
                @abstract Loads a record from the cdb_contact_clent DB
                @discussion Takes contact_id to load
                */
                function load($contact_id)
                {
                        if (!$this->contact_exists($contact_id))
                        {
                                $this->_create($contact_id);
                        }
                        $this->_loaded = FALSE;

                        $sql = 'SELECT * FROM phpgw_cdb_contact_client WHERE 
contact_id="' .
                        $contact_id.'"';
                        $this->_db->query($sql,__LINE__,__FILE__);

                        reset($this->_);
                        do
                        {
                                $key = key($this->_);
                                $this->_let($key,$this->_db->f($key));
                        }
                        while(next($this->_));

                        $this->_id = $contact_id;
                        $this->_dirty = array();
                        $this->_loaded = TRUE;
                        return TRUE;

                }

                /*!
                @function contact_exists
                @abstract Checks the existence of contact_id
                @discussion Checks for the existence of contact_id
                */
                function contact_exists($contact_id)
                {
                        if (!is_int($contact_id))
                        {
                                $contact_id = $this->_get('contact_id');
                        }
                        $sql='SELECT * FROM phpgw_cdb_contact_client WHERE 
contact_id="' .
                                $contact_id.'"';
                        $this->_db->query($sql,__LINE__,__FILE__);
                        if ($this->_db->num_rows() > 0)
                        {
                                return TRUE;
                        }
                        else
                        {
                                return FALSE;
                        }
                }

                /*!
                @function _create
                @abstract Creates a new record in the cdb_contact_client DB
                @discussion New with default values
                */
                function _create($contact_id)
                {
                        if (!is_int($contact_id))
                        {
                                $contact_id = $this->_get('contact_id');
                        }

                        $sql='INSERT INTO phpgw_cdb_contact_client 
("contact_id", ' .
                                '"account", "billing_info", "customer_id", 
"referred_by" ) ' .
                                'VALUES ("' . $contact_id . '", "", "", "", "") 
';
                        $this->_db->query($sql,__LINE__,__FILE__);

                }

        }

?>

====================================================
Index: class.cdb_contact_address.inc.php
<?php
  /**************************************************************************\
  * phpGroupWare                                                             *
  * http://www.phpgroupware.org/                                             *
  * This file written by Brian Morel  < brianmorel AT yahoo DOT com >        *
  * ------------------------------------------------------------------------ *
  * Please see the documentation for these classes in the README file in     *
  * this directory.                                                          *
  * ------------------------------------------------------------------------ *
  *  This program is free software; you can redistribute it and/or modify it *
  *  under the terms of the GNU General Public License as published by the   *
  *  Free Software Foundation; either version 2 of the License, or (at your  *
  *  option) any later version.                                              *
  \**************************************************************************/

  /* $Id: class.cdb_contact_address.inc.php,v 1.1 2005/05/05 00:56:39 skwashd 
Exp $ */

        class cdb_contact_address extends cdb_generic
        {
                var $_address_list;
                var $_db;

                function cdb_contact_address()
                {
                        $this->_db = $GLOBALS['phpgw']->db;
                        /* add vars that have get/let interface to this array. 
*/
                        $this->_ = array(
                        );
                }

                function save()
                {
                        reset($this->_address_list);
                        $retval = FALSE;
                        while (list($key,$value) = $this->_address_list)
                        {
                                if ($value->save())
                                {
                                        $retval = TRUE;
                                }
                        }
                        return $retval;
                }

                function load($entity_id)
                {
                        $this->_address_list = array();
                        $this->_id = $entity_id;
                        $this->_loaded = TRUE;
                        $sql = 'SELECT contact_address_id FROM 
phpgw_cdb_contact_addr WHERE ' .
                                'entity_id="' . $entity_id . '"';
                        $this->_db->query($sql,__LINE__,__FILE__);
                        while ($this->_db->next_record())
                        {
                                $this->_address_list[] = 
CreateObject('cdb.cdb_address');
                                $x = $this->_db->f('contact_address_id');
                                $this->_address_list[$x]->load($x);
                        }
                        return TRUE;
                }

                function get_address_list()
                {
                        return $this->_address_list;
                }
        }
?>

====================================================
Index: class.bo.inc.php
//business objects

====================================================
Index: class.cdb_contact.inc.php
<?php
        
/**************************************************************************\
        * phpGroupWare                                                          
   *
        * http://www.phpgroupware.org/                                          
   *
        * This file written by Patrick Walsh <address@hidden>               *
        * with some part done by Mathieu van Loon <address@hidden>         *
        * 
------------------------------------------------------------------------ *
        * Please see the documentation for these classes in the README file in  
   *
        * this directory.                                                       
   *
        * 
------------------------------------------------------------------------ *
        * This program is free software; you can redistribute it and/or modify 
it  *
        * under the terms of the GNU General Public License as published by the 
   *
        * Free Software Foundation; either version 2 of the License, or (at 
your   *
        * option) any later version.                                            
   *
        
\**************************************************************************/

        /* $Id: class.cdb_contact.inc.php,v 1.1 2005/05/05 00:56:39 skwashd Exp 
$ */

/*!
        @class cdb_contact
        @abstract Root Contact Class
        @syntax CreateObject('cdb.cdb_contact');
        @example $x = CreateObject('cdb.cdb_contact');
        @author mr_e
        @copyright GPL
        @package cdb
        @access public
*/
        class cdb_contact extends cdb_generic
        {
                var $_client;
                var $_meta;
                var $_personal;
                var $_internet;
                var $_phone;
                var $_address;
                var $_note;

                function cdb_contact()
                {
                        $this->_db = $GLOBALS['phpgw']->db;
                        $this->_ = array(
                                'contact_id'       => 0,
                                'main_organization_location_selector' => 0,
                                'first_name'       => '',
                                'middle_name'      => '',
                                'last_name_prefix' => '',
                                'last_name'        => '',
                                'initials'         => '',
                                'location'         => '',
                                'nickname'         => '',
                                'profession'       => '',
                                'suffix'           => '',
                                'title'            => '',
                                'email_selector'   => 0,
                                'web_selector'     => 0,
                                'mailing_address_selector' => 0,
                                'phone1_selector'  => 0,
                                'phone2_selector'  => 0,
                                'phone3_selector'  => 0,
                                'phone4_selector'  => 0,
                                'phone5_selector'  => 0,
                                'phone7_selector'  => 0,
                                'phone8_selector'  => 0,
                                'note'             => ''
                        );
                }

 /************************\
 *    Public Functions    *
 \************************/
                /*!
                @function contact_id
                @abstract Returns the contact id
                @discussion Returns the contact id or zero if no contact loaded
                */
                function contact_id()
                {
                        return $this->_get('contact_id');
                }

                /*!
                @function create
                @abstract Create a new contact
                @syntax int create(str name)
                @discussion This adds an entry to the cdb_contact_main,
                cdb_entity_id, cdb_entity_notes and cdb_entity_meta.
                Returns true on success and false on failure.
                @example1 $contact_id = $x->create("Joe Schmoe");
                @example2 $contact_id = $x->create();
                @param name str-the optional name of the contact
                */
                function create($name)
                {
                        global $cdb_ver;
                        unset($this->_meta);
                        unset($this->_client);
                        $this->_id = 0;
                        $this->_let('contact_id',0);

                        $lname = $this->_extract_last_name($name);
                        $fname = $this->_extract_first_name($name);
                        $file_as = _make_file_as($fname,$lname);

                        // Create entry in contact_main
                        $sql = 'INSERT INTO phpgw_cdb_contact_main 
("first_name","last_name") ' .
                                        'VALUES ("'.$fname.'","'.$lname.'")';
                        $this->_db->query($sql,__LINE__,__FILE__);
                        $this->_let('contact_id',
                                        
$this->_db->get_last_insert_id('cdb_contact_main',
                                        'contact_id'));

                        // Create entity_id entry
                        $sql = 'INSERT INTO phpgw_cdb_entity_id ("contact_id") 
VALUES ("' .
                                        $contact_id . '")';
                        $this->_db->query($sql,__LINE__,__FILE__);
                        $this->_id = 
$this->_db->get_last_insert_id('phpgw_cdb_entity_id',
                                        'entity_id');

                        // Create entry in entity_meta
                        $status = "active";
                        $sql = 'INSERT INTO phpgw_cdb_entity_meta 
("entity_id","status",' .
                                        
'"created","modified","file_as","created_by","version") ' .
                                        'VALUES 
("'.$this->id().'","'.$status.'","'.time().'","' .
                                        time().'","'.$file_as.'","' .
                                        
$GLOBALS['phpgw_info']['user']['account_id'].'","' .
                                        $cdb_ver.'")';
                        $this->_db->query($sql,__LINE__,__FILE__);

                        // Create enry in entity_note
                        $sql = 'INSERT INTO phpgw_cdb_entity_notes 
("entity_id","note") VALUES ' .
                                        '("'.$this->id().'","")';
                        $this->_db->query($sql,__LINE__,__FILE__);

                        $this->_meta = CreateObject('cdb.cdb_entity_meta');
                        $this->_meta->load($this->id());

                        return $this->id();
                }

        /*!
        @function exists
        @abstract Checks the existence of contact_id
        @discussion Checks for the existence of contact_id
        */
        function exists($contact_id)
        {
                if (!is_int($contact_id))
                {
                $contact_id = $this->_get('contact_id');
                }
                $sql='SELECT * FROM phpgw_cdb_entity_id WHERE contact_id="' .
                                        $contact_id.'"';
                $this->_db->query($sql,__LINE__,__FILE__);
                if ($this->_db->num_rows() > 0)
                {
                return $this->_db->f('entity_id');
                }
                else
                {
                return FALSE;
                }
        }

        /*!
        @function save
        @abstract Save recent changes
        @syntax int save()
        @discussion This will use the _dirty array to determine what needs
                to be written to the database and then write it.  Returns true 
when
                changes have been made and false if none have been made.
        @example1 if ($x->save())
                                {
                                        print lang('Changes saved.');
                                }
                                else
                                {
                                        print lang('No changes saved.');
                                }
        */
                function save()
                {
                        if($this->id() && $this->exists($this->id()) && 
$this->can_write()
                                && $this->get_loaded())
                        {
                                //TODO need to save the children if they are 
loaded
                                if (isset($this->_client))
                                {
                                        if ($this->_client->save())
                                        {
                                                $this->_meta->set_modified();
                                        }
                                }
                                if (isset($this->_personal))
                                {
                                        if ($this->_personal->save())
                                        {
                                                $this->_meta->set_modified();
                                        }
                                }
                                if (isset($this->_internet))
                                {
                                        if ($this->_internet->save())
                                        {
                                                $this->_meta->set_modified();
                                        }
                                }
                                if (isset($this->_phone))
                                {
                                        if ($this->_phone->save())
                                        {
                                                $this->_meta->set_modified();
                                        }
                                }
                                if (isset($this->_address))
                                {
                                        if ($this->_address->save())
                                        {
                                                $this->_meta->set_modified();
                                        }
                                }

                                // Build update query
                                $sqlp = "UPDATE phpgw_cdb_contact_main SET ";
                                if ($this->_dirty_vars())
                                {
                                        $this->_meta->set_modified();

                                        reset($this->_dirty);
                                        do
                                        {
                                                $key = key($this->_dirty);
                                                switch($key)
                                                {
                                                        case 'note':
                                                                // the note is 
in a diff table
                                                                // sine it's by 
itself, just do db now
                                                                $sql2.='UPDATE 
phpgw_cdb_entity_notes SET note="'.
                                                                                
$this->get_note().'" WHERE entity_id="'.
                                                                                
$this->id().'"';
                                                                
$this->_db->query($sql2,__LINE__,__FILE__);
                                                                
$this->_meta->set_modified();
                                                                break;
                                                        default:
                                                                $sql.=$key.'="';
                                                }
                                                $sql .= $this->_get($key) . '", 
';
                                        }
                                        while (next($this->_dirty));
                                        if ($sql)
                                        {
                                                $sql .= 'contact_id="' . 
$this->get_contact_id().'"'.
                                                        ' WHERE 
contact_id="'.$this->get_contact_id().'"';
                                                
$this->_db->query($sqlp.$sql,__LINE__,__FILE__);
                                        }
                                }

                                $this->_meta->save();
                                $this->_dirty = array();

                                return TRUE;
                        }
                        else
                        {
                                //TODO: raise a major error!
                                return FALSE;
                        }
                }

        /*!
        @function load
        @abstract Load a contact
        @syntax int load(int contact_id)
                @discussion Populate the data with data from the database.  
Returns
                true on success and false on failure.  The important thing is 
that
                this function takes the contact_id and not the entity_id.  If 
you
                want to use the entity id, create an entity object and use that
                load function instead.
        @example1 $x->load(234);
        */
                function load($contact_id)
                {
                        // Don't worry about the status (deleted vs. active) 
here...

                        // Simultaneously check existence of contact_id and get 
entity_id
                        if (! $entity_id = $this->exists($contact_id))
                        {
                                return FALSE;
                        }
                        $this->_id = $entity_id;
                        $this->_loaded = FALSE;
                        $this->_dirty = array();

                        // Now lookup the main contact info
                        $sql = 'SELECT * FROM phpgw_cdb_contact_main WHERE 
contact_id="' .
                                        $contact_id.'"';
                        $this->_db->query($sql,__LINE__,__FILE__);

                        reset($this->_);
                        do
                        {
                                $key = key($this->_);
                                switch($key)
                                {
                                        case 'note':
                                                // the note is in a diff table
                                                // just ignore it for now and 
we'll load it in a min
                                                break;
                                        case 'contact_id':
                                                
$this->_let('contact_id',$contact_id);
                                                break;
                                        default:
                                                
$this->_let($key,$this->_db->f($key));
                                }
                        }
                        while(next($this->_));

                        // Now take care of the note
                        $sql = 'SELECT note FROM phpgw_cdb_entity_notes WHERE 
entity_id="' .
                                        $this->id() . '"';
                        $this->_db->query($sql,__LINE__,__FILE__);
                        $this->_let('note',$this->_db->f('note'));

                        //TODO: Now load the meta object
                        $this->_meta = CreateObject('cdb.cdb_entity_meta');
                        $this->_meta->load($this->id());

                        $this->_loaded = TRUE;
                        $this->_dirty = array();
                        return TRUE;

                }

                function delete()
                {
                        if($this->can_write()) // check for write permission
                        {
                                $this->get_meta->let_status('delete');
                                return TRUE;
                        }
                        return FALSE;
                }

                function empty_trash()
                {
                        //TODO: delete where status=deleted
                }

                function get_client_data()
                {
                        /* TODO: need to check to be sure client has been 
loaded */
                        return $this->_client;
                }
                function get_meta_data()
                {
                        /* TODO */
                        return $this->_meta;
                }
                function get_personal_data()
                {
                        /* TODO */
                        // return contact.personal.class; // Syntax error
                }
                function get_internet_data()
                {
                        /* TODO */
                        // return contact.internet.class; // Syntax error
                }
                function get_phone_data()
                {
                        /* TODO */
                        // return contact.phone.class; // Syntax error
                }
                function get_address_data()
                {
                        /* TODO */
                        // return contact.address.class; // Syntax error
                }
                function get_main_organization()
                {
                        /* TODO */
                        // return organization.class; // Syntax error
                }
                function let_main_organization(/* organization.class */) // 
Syntax error
                {
                        /* TODO */
                        return;
                }
                function get_first_name()
                {
                        return $this->_get('first_name');
                }
                function let_first_name($inStr)
                {
                        /* NOTE due to database restrictions, the first_name 
can */
                        /* be no longer than 255 characters */
                        $mySuccess = False;
                        if(strlen($inStr)<=255)
                        {
                                $mySuccess = $this->_let('first_name',$inStr);
                        }
                        return $mySuccess;
                }
                function get_middle_name()
                {
                        return $this->_get('middle_name');
                }
                function let_middle_name($inStr)
                {
                        /* NOTE due to database restrictions, the middle_name 
can */
                        /* be no longer than 255 characters */
                        $mySuccess = False;
                        if(strlen($inStr)<=255)
                        {
                                $mySuccess = $this->_let('middle_name',$inStr);
                        }
                        return $mySuccess;
                }
                function get_last_name()
                {
                        return $this->_get('last_name');
                }
                function let_last_name($inStr)
                {
                        /* NOTE due to database restrictions, the last_name can 
*/
                        /* be no longer than 255 characters */
                        $mySuccess = False;
                        if(strlen($inStr)<=255)
                        {
                                $mySuccess = $this->_let('last_name',$inStr);
                        }
                        return $mySuccess;
                }
                function get_last_name_prefix()
                {
                        return $this->_get('last_name_prefix');
                }
                function let_last_name_prefix($inStr)
                {
                        /* NOTE due to database restrictions, the 
last_name_prefix can */
                        /* be no longer than 10 characters */
                        $mySuccess = False;
                        if(strlen($inStr)<=10)
                        {
                                $mySuccess = 
$this->_let('last_name_prefix',$inStr);
                        }
                        return $mySuccess;
                }
                function get_initials()
                {
                        return $this->_get('initials');
                }
                function let_initials($inStr)
                {
                        /* NOTE due to database restrictions, the initials can 
be no */
                        /* longer than 6 characters */
                        $mySuccess = False;
                        if(strlen($inStr)<=6)
                        {
                                $mySuccess = $this->_let('initials',$inStr);
                        }
                        return $mySuccess;
                }
                function get_location()
                {
                        return $this->_get('location');
                }
                function let_location($inStr)
                {
                        /* NOTE due to database restrictions, the location can 
*/
                        /* be no longer than 255 characters */
                        $mySuccess = False;
                        if(strlen($inStr)<=255)
                        {
                                $mySuccess = $this->_let('location',$inStr);
                        }
                        return $mySuccess;
                }
                function get_nickname()
                {
                        return $this->_get('nickname');
                }
                function let_nickname($inStr)
                {
                        /* NOTE due to database restrictions, the nickname can 
*/
                        /* be no longer than 255 characters */
                        $mySuccess = False;
                        if(strlen($inStr)<=255)
                        {
                                $mySuccess = $this->_let('nickname',$inStr);
                        }
                        return $mySuccess;
                }
                function get_profession()
                {
                        return $this->_get('profession');
                }
                function let_profession($inStr)
                {
                        /* NOTE due to database restrictions, the profession 
can */
                        /* be no longer than 255 characters */
                        $mySuccess = False;
                        if(strlen($inStr)<=255)
                        {
                                $mySuccess = $this->_let('profession',$inStr);
                        }
                        return $mySuccess;
                }
                function get_suffix()
                {
                        return $this->_get('suffix');
                }
                function let_suffix($inStr)
                {
                        /* NOTE Due to database restrictions the suffix */
                        /* can be no longer than 20 characters */
                        $mySuccess = False;
                        if(strlen($inStr)<=20)
                        {
                                $mySuccess = $this->_let('suffix',$inStr);
                        }
                        return $mySuccess;
                }
                function get_title()
                {
                        return $this->_get('title');
                }
                function let_title($inStr)
                {
                        /* NOTE Due to database restrictions the title */
                        /* can be no longer than 20 characters */
                        $mySuccess = False;
                        if(strlen($inStr)<=20)
                        {
                                $mySuccess = $this->_let('title',$inStr);
                        }
                        return $mySuccess;
                }
                function get_mailing_address()
                {
                        /* TODO */
                        return string;
                }
                function get_mailing_address_selector()
                {
                        return $this->_get('mailing_address_selector');
                }
                function let_mailing_address_selector($inID)
                {
                        $mySuccess = False;
                        if(is_int($inID))
                        {
                                $mySuccess = 
$this->_let('mailing_address_selector',$inID);
                        }
                        return $mySuccess;
                }
                function get_web()
                {
                         /* TODO */
                        return string;
                }
                function get_web_selector()
                {
                        return $this->_get('web_selector');
                }
                function let_web_selector($inID)
                {
                        $mySuccess = False;
                        if(is_int($inID))
                        {
                                $mySuccess = $this->_let('web_selector',$inID);
                        }
                        return $mySuccess;
                }
                function get_email()
                {
                        /* TODO */
                        return string;
                }

                function get_email_selector()
                {
                        return $this->_get('email_selector');
                }

                function let_email_selector($inID)
                {
                        $mySuccess = False;
                        if(is_int($inID))
                        {
                                $mySuccess = 
$this->_let('email_selector',$inID);
                        }
                        return $mySuccess;
                }

                function get_phonex($inID)
                {
                        /* TODO */
                        if(is_int($inID) && 0 < $inID && $inID < 9)
                        {
                                // do stuff
                        }
                        return string;
                }

                function get_phonex_selector($inID)
                {
                        $myReply = 0;
                        if(is_int($inID) && 0 < $inID && $inID < 9)
                        {
                                $phonex_selector_varname = 
'phone'.$inID.'_selector';
                                $myReply = 
$this->_get($phonex_selector_varname);
                        }
                        return $myReply;
                }

                function let_phonex_selector($inID, $inNewVal)
                {
                        $mySuccess = False;
                        if(is_int($inID) /*&*/) // Syntax error
                        {
                                $phonex_selector_varname = 
'phone'.$inID.'_selector';
                                $mySuccess = 
$this->_let($phonex_selector_varname,$inNewVal);
                        }
                        return $mySuccess;
                }

                function get_note()
                {
                        return $this->_get('note');
                }

                function let_note($note)
                {
                        /* NOTE Due to database restrictions the note */
                        /* can be no longer than 65535 characters */
                        if(strlen($note)<=65535)
                        {
                                return $this->_let('note', $note);
                        }
                        return FALSE;
                }

 /*************************\
 *    Private Functions    *
 \*************************/
                function _extract_first_name($name)
                {
                        if ($name)
                        {
                                // First check for format "Lastname, Firstname 
Middle"
                                // $fname = "Firstname Middle"
                                if (strstr($name, ', '))
                                {
                                        $fname = substr($name, (strrpos($name, 
', ')+2));
                                }
                                // No comma, separate out "Firstname Middle 
Lastname"
                                else
                                {
                                        $pos = strrpos($name, " ");
                                        if (is_string($pos) && !$pos)
                                        {
                                                //no spaces, assume only last 
name
                                                $fname = '';
                                        }
                                        else
                                        {
                                                $fname = substr($name, 0, $pos 
-1);
                                        }
                                }
                        }
                        else
                        {
                                $fname='';
                        }
                        return $fname;
                }

                function _extract_last_name($name)
                {
                        if ($name)
                        {
                                // First check for format "Lastname, Firstname 
Middle"
                                // $fname = "Firstname Middle"
                                if (strstr($name, ', '))
                                {
                                        $lname = substr($name, 0, 
strrpos($name, ', '));
                                }
                                // No comma, separate out "Firstname Middle 
Lastname"
                                else
                                {
                                        $pos = strrpos($name, " ");
                                        if (is_string($pos) && !$pos)
                                        {
                                                //no spaces, assume only last 
name
                                                $lname = $name;
                                        }
                                        else
                                        {
                                                $lname = substr($name, $pos + 
1);
                                        }
                                }
                        }
                        else
                        {
                                $lname='';
                        }
                        return $lname;
                }

                function _make_file_as($fname, $lname)
                {
                        if ($lname && $fname) {
                                $file_as = $lname . ', ' . $fname;
                        }
                        else if ($lname)
                        {
                                $file_as = $lname;
                        }
                        else if ($fname)
                        {
                                $file_as = $fname;
                        }
                        else
                        {
                                $file_as = '';
                        }
                        return $file_as;
                }
        }
?>

====================================================
Index: class.cdb_address.inc.php
<?php
  /**************************************************************************\
  * phpGroupWare                                                             *
  * http://www.phpgroupware.org/                                             *
  * This file written by Patrick Walsh <address@hidden>            *
  * ------------------------------------------------------------------------ *
  * Please see the documentation for these classes in the README file in     *
  * this directory.                                                          *
  * ------------------------------------------------------------------------ *
  *  This program is free software; you can redistribute it and/or modify it *
  *  under the terms of the GNU General Public License as published by the   *
  *  Free Software Foundation; either version 2 of the License, or (at your  *
  *  option) any later version.                                              *
  \**************************************************************************/

  /* $Id: class.cdb_address.inc.php,v 1.1 2005/05/05 00:56:39 skwashd Exp $ */

        class cdb_address extends cdb_generic
        {
                function cdb_address()
                {
                        $this->_db = $GLOBALS['phpgw']->db;
                        /* add vars that have get/let interface to this array. 
*/
                        $this->_ = array(
                                'contact_address_id'       => 0,
                                'entity_id'                => 0,
                                'address_category_id'      => 0,
                                'address_city'             => '',
                                'address_country'          => '',
                                'postal_code'              => '',
                                'address_street'           => ''
                        );
                }

                function get_address_id()
                {
                        return $this->_get('contact_address_id');
                }

                function get_type_name()
                {
                        $sql = 'SELECT address_category_name FROM 
phpgw_cdb_contact_addr_cat'.
                                'WHERE 
address_category_id="'.$this->_get('address_category_id').
                                '"';
                        $this->_db->query($sql,__LINE__,__FILE__);
                        return $this->_db->f('address_category_name');
                }

                function get_type()
                {
                        return (int)$this->_get('address_category_id');
                }

                function let_type($new_type)
                {
                        return $this->_let('address_category_id', 
(int)$new_type);
                }

                function get_city()
                {
                        return $this->_get('address_city');
                }

                function let_city($new_city)
                {
                        return $this->_let('address_city', $new_city);
                }

                function get_street()
                {
                        return $this->_get('address_street');
                }

                function let_street($new_street)
                {
                        return $this->_let('address_street', $new_street);
                }

                function get_country()
                {
                        return $this->_get('address_country');
                }

                function let_country($new_country)
                {
                        return $this->_let('address_country', $new_country);
                }

                function get_postalcode()
                {
                        return $this->_get('postal_code');
                }

                function let_postalcode($new_postalcode)
                {
                        return $this->_let('postal_code', $new_postalcode);
                }

                function save()
                {
                        // Build update query
                        $sqlp = "UPDATE phpgw_cdb_contact_addr SET ";
                        if ($this->_dirty_vars())
                        {
                                reset($this->_dirty);
                                do
                                {
                                        $key = key($this->_dirty);
                                        switch($key)
                                        {
                                                case 'contact_address_id' :
                                                        break;
                                                default:
                                                        $sql.=$key.'="';
                                                        $sql .= 
$this->_get($key) . '", ';
                                        }
                                }
                                while (next($this->_dirty));

                                if ($sql)
                                {
                                        $sql .= 'entity_id="' . $this->id().'"'.
                                                ' WHERE 
contact_address_id="'.$this->get_address_id().'"';
                                        
$this->_db->query($sqlp.$sql,__LINE__,__FILE__);
                                }
                                return TRUE;
                        }
                        else
                        {
                                return FALSE;
                        }
                }

                function load($address_id)
                {
                        $sql = 'SELECT * FROM phpgw_cdb_contact_addr WHERE 
contact_address_id="' .
                                $address_id . '"';
                        $this->_db->query($sql,__LINE__,__FILE__);

                        reset($this->_);
                        do
                        {
                                $key = key($this->_);
                                $this->_let($key,$this->_db->f($key));
                        }
                        while(next($this->_));

                        $this->_id = (int)$this->_db->f('entity_id');

                        $this->_loaded = TRUE;
                        $this->_dirty = array();

                        return (int)$this->id();
                }

                function create($entity_id, $type_id, $street, $city,
                                $country, $postal_code )
                {
                        $this->_loaded = TRUE;
                        $this->_dirty = array();
                        $sql = 'INSERT INTO phpgw_cdb_contact_addr ( ' .
                                '"entity_id",' .
                                '"address_category_id", ' .
                                '"address_street", ' .
                                '"address_city", ' .
                                '"address_country", ' .
                                '"postal_code" ' .
                                ') VALUES ("' .
                                $entity_id . '", "' .
                                $type_id . '", "' .
                                $street . '", "' .
                                $city . '", "' .
                                $country . '", "' .
                                $postal_code . '" )';
                        $to_be_returned = 
$this->_db->query($sql,__LINE__,__FILE__);
                        $this->_id = $entity_id;
                        $this->_let('contact_address_id',
                        
$this->_db->get_last_insert_id('phpgw_cdb_contact_address',
                                'contact_address_id'));

                        return $to_be_returned;
                }
        }
?>

====================================================
Index: class.bo_filter.inc.php
<?php
  /**************************************************************************\
  * phpGroupWare                                                             *
  * http://www.phpgroupware.org/                                             *
  * This file written by Patrick Walsh <address@hidden>            *
  * ------------------------------------------------------------------------ *
  * Please see the documentation for these classes in the README file in     *
  * this directory.                                                          *
  * ------------------------------------------------------------------------ *
  *  This program is free software; you can redistribute it and/or modify it *
  *  under the terms of the GNU General Public License as published by the   *
  *  Free Software Foundation; either version 2 of the License, or (at your  *
  *  option) any later version.                                              *
  \**************************************************************************/

  /* $Id: class.bo_filter.inc.php,v 1.1 2005/05/05 00:56:39 skwashd Exp $ */

/*!
        @class bo_filter
        @abstract Used to filter records for views, filters, other apps, etc.
        @syntax CreateObject('cdb.bo_filter');
        @author Patrick Walsh (mr_e)
        @copyright GPL
        @package cdb
        @access public
*/
        class bo_filter
        {
                var $_fields;
                var $_criteria;
                var $_groupby;
                var $_sortby;
                var $_db;
                var $_view_id;
                var $_limit;
                var $_joins;

        var $public_functions = array
        (
            'filter'  => False
        );

                function bo_filter()
                {
                        $this->_db = $GLOBALS['phpgw']->db;
                        $this->_fields = '*';
                        $this->_criteria = '1=1';
                        $this->_groupby = '';
                        $this->_sortby = '';
                        $this->_limit = 0;
                        $this->_view_id = 0;
                        $this->_joins = array();
                }

                function filter($filter_name, $fields, $criteria, $sorting, 
$grouping, $limit)
                {
                        if (!isset($filter_name))
                        {
                                // TODO: Raise error: no filter name set
                                return FALSE;
                        }

                        //Error check: is this a valid view name?
                        $sql = 'SELECT view_id FROM phpgw_cdb_views WHERE 
name="'.
                                $filter_name . '"';
                        $this->_db->query($sql,__LINE__,__FILE__);
                        if ($this->_db->nf() > 0)
                        {
                                $this->_view_id = $this->_db->f('view_id');
                        }
                        else
                        {
                                //TODO: Raise error: no such filter name
                                return FALSE;
                        }

                        
/*************************************************************\
                        * If something isn't passed, use the previous value 
stored in *
                        * this class or the defaults (eg, fields='*').  If it 
is      *
                        * passed, allow for an array or comma separated list.   
      *
                        
\*************************************************************/

                        if (isset($fields))
                        {
                                // Store as array
                                if (is_array($fields))
                                {
                                        $this->_fields = $fields;
                                }
                                else
                                {
                                        $this->_fields = explode(',',$fields);
                                }
                        }
                        if (isset($criteria))
                        {
                                // Store as array
                                if (is_array($criteria))
                                {
                                        $this->_criteria = $criteria;
                                }
                                else
                                {
                                        $this->_criteria = explode(',', 
$criteria);
                                }
                        }
                        if (isset($sorting))
                        {
                                // Store as array
                                if (is_array($sorting))
                                {
                                        $this->_sortby = $sorting;
                                }
                                else
                                {
                                        $this->_sortby = explode(',',$sorting);
                                }
                        }
                        if (isset($grouping))
                        {
                                // Store as array
                                if (is_array($grouping))
                                {
                                        $this->_groupby = $grouping;
                                }
                                else
                                {
                                        $this->_groupby = explode(',', 
$grouping);
                                }
                        }
                        if (!isset($limit))
                        {
                                $this->_limit = 0;
                        }

                        
/*************************************************************\
                        * Now check for or create a cached table to operate on. 
      *
                        
\*************************************************************/

                        $cache_exists = FALSE;
                        $cache_isvalid = FALSE;
                        $sql = 'SELECT cache_date FROM phpgw_cdb_views WHERE ' .
                                'view_id="' . $this->_view_id . '"';
                        if ($this->_db->f('cache_date') > 
$this->get_cache_expiration())
                        {
                                $cache_isvalid = TRUE;
                        }
                        $sql = 'SELECT COUNT(*) FROM phpgw_cdb_cache_' . 
$filter_name;
                        $this->_db->query($sql,__LINE__,__FILE__);
                        if ($this->_db->nf() >0)
                        {
                                $cache_exists = TRUE;
                        }

                        if ($cache_exists && ! $cache_isvalid)
                        {
                                //TODO: Does this work in mysql AND pgsql??
                                $sql = 'DROP TABLE IF EXISTS 
phpgw_cdb_cache_'.$filter_name;
                                $this->_db->query($sql,__LINE__,__FILE__);
                                $cache_exists = FALSE;
                        }

                        if (!$cache_exists)
                        {
                                $fields = $this->eval_fields();
                                $criteria = $this->eval_criteria();
                                $sql = 'CREATE TEMPORARY TABLE 
phpgw_cdb_cache_' . $filter_name;
                                //TODO: if mysql:
                                        $sql .= ' SELECT ' . $fields . ' WHERE 
' . $criteria;

                                /*TODO: if pgsql:
                                        $sql .= ' AS (SELECT '.$fields.' WHERE 
'.$criteria.')';*/

                                
/*****************************************************\
                                * In the special case where 
contact_main.categories   *
                                * is being requested, due to no sub-selects in 
mysql  *
                                * we have to create a temporary table that we 
join    *
                                * to the main temporary table.  This must be 
done b4  *
                                * the above sql is executed.  -mr_e             
      *
                                * PS - this is mysql only for now.  will worry 
about  *
                                *      pgsql and others later.                  
      *
                                
\*****************************************************/
                                if (strstr($fields,'categories'))
                                {
                                        $sql_cat='DROP TABLE IF EXISTS 
phpgw_cdb_cache__categories';
                                        
$this->_db->query($sql_cat,__LINE__,__FILE__);
                                        
/*************************************************\
                                        * OK, I created the mysql only way of 
doing this, *
                                        * but it requires more rows than 
desired.  So I'm *
                                        * going to leave the below sql 
statement in the   *
                                        * code simply because it was such hell 
to design  *
                                        * it.  And then I'm going to do the 
same thing    *
                                        * client side that this did db side. 
-mr_e        *
                                        
\*************************************************/
                                /*      $sql_cat = 'CREATE TEMPORARY TABLE ' .
                                                'phpgw_cdb_cache__categories ' .
                                                'SELECT ' .
                                                        '@old:address@hidden,' .
                                                        
'@b:=phpgw_cdb_category.name AS category,' .
                                                        
'@a:=if(@address@hidden,' .
                                                                
'concat(@a,',',phpgw_cdb_category.name),' .
                                                                
'phpgw_cdb_category.name' .
                                                        ') AS categories ' .
                                                'FROM ' .
                                                        'phpgw_cdb_entity_id, 
phpgw_cdb_category_link, '.
                                                        'phpgw_cdb_category ' .
                                                'WHERE ' .
                                                        
'phpgw_cdb_entity_id.entity_id='.
                                                                
'phpgw_cdb_category_link.entity_id '.
                                                        'AND 
phpgw_cdb_category_link.category_id='.
                                                                
'phpgw_cdb_category.category_id';
                                */
                                        $sql_cat = 'CREATE TEMPORARY TABLE ' .
                                                'phpgw_cdb_cache__categories '.
                                                '(' .
                                                        "entity_id int(11) 
unsigned DEFAULT '0' NOT NULL, ".
                                                        'categories text, '.
                                                        'PRIMARY KEY 
(entity_id)'.
                                                ')';
                                        
$this->_db->query($sql_cat,__LINE__,__FILE__);
                                        $sql_cat = 'SELECT '.
                                                
'phpgw_cdb_category_link.entity_id AS entity_id,'.
                                                'phpgw_cdb_category.name AS 
name '.
                                                'FROM phpgw_cdb_category_link, 
phpgw_cdb_category '.
                                                'WHERE 
phpgw_cdb_category_link.category_id='.
                                                        
'phpgw_cdb_category.category_id '.
                                                'ORDER BY entity_id,name';
                                        
$this->_db->query($sql_cat,__LINE__,__FILE__);
                                        $entity_id=0;
                                        $cat_str='';
                                        
/*************************************************\
                                        * Every row has one entity id and one 
category.   *
                                        * We need to concat all the categories 
for each   *
                                        * entity into a comma separated list.   
          *
                                        
\*************************************************/
                                        while ($this->_db->next_record())
                                        {
                                                if 
($this->_db->f('entity_id')==$entity_id)
                                                {
                                                        if ($cat_str=='')
                                                        {
                                                                $cat_str = 
$this->_db->f('name');
                                                        }
                                                        else
                                                        {
                                                                $cat_str .= 
','.$this->_db->f('name');
                                                        }
                                                }
                                                else
                                                {
                                                        $sql_cat='INSERT INTO 
phpgw_cdb_cache__categories'.
                                                                " 
('entity_id','name')" .
                                                                "VALUES 
('".$entity_id."','".$cat_str."')";
                                                        
$this->_db->query($sql_cat,__LINE__,__FILE__);
                                                        $entity_id = 
$this->_db->f('entity_id');
                                                        $cat_str = 
$this->_db->f('name');
                                                }
                                        }
                                } // endif categories
                        } // endif !cache_exists

                        
/*************************************************************\
                        * Make our query on the cached table taking into 
account      *
                        * permissions, sorting, limits and grouping.            
      *
                        
\*************************************************************/

                        //TODO: create limit query from cached table based on 
which
                        //records desired (1-10, 11-20, etc.) and permissions 
using
                        //the sorting as necessary

                        //finally, take resultant array and group as desired
                }


        /*!
        @function get_cache_expiration
        @abstract Returns the good-cache cutoff time
        @discussion This returns the point at which all previously created
                                caches are invalid and all subsequently created 
caches are
                                valid.  The cutoff time, if you will.
        */
                function get_cache_expiration()
                {
                        //TODO: Look up preference, put number of seconds
                        // the cache is valid for into $valid_secs
                        $valid_secs = 60 * 60;
                        return now() - $valid_secs;
                }

                /*!
                @function eval_fields
                */
                function eval_fields()
                {
                        $select = 'phpgw_cdb_entity_id.entity_id AS entity_id';
                        $from = 'phpgw_cdb_entity_id';
                        $this->_joins = array();
                        reset($this->_fields);
                        while (list($key,$value) = $this->_fields)
                        {
                                $result = FALSE;
                                $field = explode('.',$value);
                                switch($field[0])
                                {
                                        case 'contact_main':
                                                $result = 
join_contact_main($field);
                                                break;
                                        case 'contact_phone':
                                        case 'contact_address':
                                        case 'contact_client':
                                        case 'contact_personal':
                                        case 'contact_internet':
                                        case 'organization':
                                        case 'organization_client':
                                        case 'contact_organization':
                                        case 'meta':
                                        default:
                                                //TODO: Raise error: bad input
                                }
                                if (is_array($result))
                                {
                                        $select .= $result['select'];
                                        $from .= $result['from'];
                                }
                                else
                                {
                                        //TODO: Raise error: should be 
impossible to get here
                                }
                        }
                        return $select . ' FROM ' . $from;
                }

                /*!
                @function eval_criteria
                */
                function eval_criteria()
                {
                        /****************************************************\
                        * Some notes: First, most criteria depends upon the  *
                        * proper tables being joined together.  This is the  *
                        * same process as eval_fields, so we'll reuse the    *
                        * same routines for some things.                     *
                        * To clarify: a person might want to select three    *
                        * fields, a, b and c, where d=e.  If this is the     *
                        * case, we need to be sure we've joined d and e even *
                        * though we don't select those fields.               *
                        \****************************************************/

                }

                /*!
                @function inner_join
                @discussion Allows us to return different syntaxes for diff dbs.
                                        This join is functionally equivalent to 
a comma
                                        separated list of tables and a joining 
where clause.
                */
                function inner_join($right_table, $join_key)
                {
                        //TODO: if mysql
                        return ' INNER JOIN ' . $right_table . ' ON 
phpgw_cdb_entity_id.' .
                                $join_key . '=' . $right_table . '.' . 
$join_key;

                        //TODO: elseif pgsql
                }

                /*!
                @function left_join
                @discussion Allows for different syntax for making joins with 
diff dbs.
                                        This assumes a join against the 
entity_id table.
                */
                function left_join($right_table, $join_key)
                {
                        //TODO: if mysql
                        return ' LEFT JOIN ' . $right_table . ' ON 
phpgw_cdb_entity_id.' .
                                $join_key . '=' . $right_table . '.' . 
$join_key;
                        //TODO: elseif pgsql
                        // actually, above syntax may work.  or, may break on 
both dbs.
                }

                /*!
                @function left_join_ex
                @discussion Same as left_join, but does not assume left table.
                */
                function left_join_ex($ltable, $rtable, $ljoin_key, $rjoin_key)
                {
                        if (! isset($rjoin_key))
                        {
                                $rjoin_key = $ljoin_key;
                        }
                        //TODO: if mysql
                        return ' LEFT JOIN ' . $right_table . ' ON ' . $ltable 
. '.' .
                                $ljoin_key . '=' . $rtable . '.' . $rjoin_key;
                        //TODO: elseif pgsql
                }

                /*!
                @function join_contact_main
                */
                function join_contact_main($field)
                {
                        $retval = array(
                                        'select' => '',
                                        'from' => ''
                        );
                        switch($field[1])
                        {
                                case 'first_name':
                                case 'middle_name':
                                case 'last_name':
                                case 'last_name_prefix':
                                case 'initials':
                                case 'location':
                                case 'nickname':
                                case 'profession':
                                case 'suffix':
                                case 'title':
                                        
/*********************************************\
                                        * Above cases all handled the same way  
      *
                                        
\*********************************************/
                                        if (! $this->_joined('contact_main'))
                                        {
                                                $retval['from'] = 
$this->left_join(
                                                        
'phpgw_cdb_contact_main', 'contact_id');
                                        }
                                        $retval['select'] = 
',phpgw_cdb_contact_main.' .
                                                $field[1] . ' AS ' . $field[1];
                                        break;

                                case 'organization':
                                        
/*********************************************\
                                        * OK, organization is obtained by 
joining     *
                                        * contact_main to org_location to org.  
The   *
                                        * contact_main references a main 
location,    *
                                        * but the name is in the org table.  So 
we    *
                                        * need three tables to be joined for 
this     *
                                        * sucker.  -mr_e                        
      *
                                        
\*********************************************/
                                        $retval['from'] = '';
                                        if (! $this->_joined('contact_main'))
                                        {
                                                $retval['from'] .= 
$this->left_join(
                                                        
'phpgw_cdb_contact_main', 'contact_id'
                                                );
                                        }
                                        if (! $this->_joined('org_location'))
                                        {
                                                $retval['from'] .= 
$this->left_join_ex(
                                                        
'phpgw_cdb_contact_main',
                                                        
'phpgw_cdb_org_location',
                                                        
'main_organization_location_selector',
                                                        'location_id'
                                                );
                                        }
                                        if (! $this->_joined('org'))
                                        {
                                                $retval['from'] .= 
$this->left_join_ex(
                                                        
'phpgw_cdb_org_location',
                                                        'phpgw_cdb_org',
                                                        'organization_id'
                                                );
                                        }
                                        $retval['select'] = 
',phpgw_cdb_org.organization_name ' .
                                                'AS organization';
                                        break;
                                case 'organization_location':
                                        
/********************************************\
                                        * Requires contact_main and 
org_location     *
                                        * which join on location_id and         
     *
                    * main_organization_location_selector        *
                    \********************************************/
                                        $retval['from'] = '';
                                        if (! $this->_joined('contact_main'))
                                        {
                                                $retval['from'] .= 
$this->left_join(
                                                        
'phpgw_cdb_contact_main', 'contact_id'
                                                );
                                        }
                                        if (! $this->_joined('org_location'))
                                        {
                                                $retval['from'] .= 
$this->left_join_ex(
                                                        
'phpgw_cdb_contact_main',
                                                        
'phpgw_cdb_org_location',
                                                        
'main_organization_location_selector',
                                                        'location_id'
                                                );
                                        }
                                        $retval['select'] = 
',phpgw_cdb_org_location.location ' .
                                                'AS organization_location';
                                        break;
                                case 'mailing_address':
                                        break;
                                case 'note':
                                        
/****************************************\
                                        * Join entity_id's... that's it. :-)    
 *
                                        
\****************************************/
                                        if (! $this->_joined('entity_notes'))
                                        {
                                                $retval['from'] = 
$this->left_join(
                                                        
'phpgw_cdb_entity_notes', 'entity_id'
                                                );
                                        }
                                        $retval['select'] = 
',phpgw_cdb_entity_notes.note AS note';
                                        break;
                                case 'category':
                                        
/*****************************************\
                                        * Gotta have this field for grouping by 
  *
                                        * categories.  This makes duplicate     
  *
                                        * db rows for each category a contact   
  *
                                        * belongs to.                           
  *
                                        
\*****************************************/
                                        if (! $this->_joined('category_link'))
                                        {
                                                $reval['from'] = 
$this->inner_join(
                                                        
'phpgw_cdb_category_link', 'entity_id'
                                                );
                                        }
                                        if (! $this->_joined('category'))
                                        {
                                                $retval['from'] = 
$this->left_join_ex(
                                                        
'phpgw_cdb_category_link',
                                                        'phpgw_cdb_category',
                                                        'category_id'
                                                );
                                        }
                                        $retval['select'] = 
',phpgw_cdb_category.name AS name';
                                        break;
                                case 'categories':
                                        
/*****************************************\
                                        * This cannot be done in a single query 
  *
                                        * in mysql 3.x due to lack of 
subselects  *
                                        * and functions for concat'ing rows.    
  *
                                        * So this depends on having a temporary 
  *
                                        * categories table created that can be  
  *
                                        * joined easily.                        
  *
                                        
\*****************************************/
                                        if (! 
$this->_joined('cache__categories'))
                                        {
                                                $retval['from'] = 
$this->left_join(
                                                        
'phpgw_cdb_entity_cache__categories', 'entity_id'
                                                );
                                        }
                                        $retval['select'] = 
',phpgw_cdb_entity_cache__categories'.
                                                '.categories AS categories';
                                        break;
                                default:
                                        //TODO: Raise error
                                        return FALSE;
                        }
                }

                /*!
                @function _joined
                @discussion Checks to see if this table has already been joined
                */
                function _joined($db_name)
                {
                        if ($this->_joins[$db_name])
                        {
                                return TRUE;
                        }
                        else
                        {
                                $this->_joins[$db_name] = 1;
                                return FALSE;
                        }
                }



        }
?>

====================================================
Index: class.cdb_organization_location.inc.php
<?php
  /**************************************************************************\
  * phpGroupWare                                                             *
  * http://www.phpgroupware.org/                                             *
  * This file written by Brian Morel < brianmorel AT yahoo DOT com >         *
  * ------------------------------------------------------------------------ *
  * Please see the documentation for these classes in the README file in     *
  * this directory.                                                          *
  * ------------------------------------------------------------------------ *
  *  This program is free software; you can redistribute it and/or modify it *
  *  under the terms of the GNU General Public License as published by the   *
  *  Free Software Foundation; either version 2 of the License, or (at your  *
  *  option) any later version.                                              *
  \**************************************************************************/

  /* $Id: class.cdb_organization_location.inc.php,v 1.1 2005/05/05 00:56:39 
skwashd Exp $ */

        class cdb_organization_location extends cdb_generic
        {
                function cdb_organization_location()
                {
                        $this->_ = array(
                                'location_id'           => 0,
                                'organization_id'       => 0,
                                'location'              => '',
                                'address_street'        => '',
                                'address_city'          => '',
                                'address_country'       => '',
                                'postal_code'           => '',
                                'number'                => ''
                                );
                }

                function get_location_id()
                {
                        return $this->_get('location_id');
                }

                function get_organization_id()
                {
                        return $this->_get('organization_id');
                }

                function let_organization_id($new_organization_id)
                {
                        return $this->_let('location', $new_organization_id);
                }

                function get_location()
                {
                        return $this->_get('location');
                }

                function let_location($new_location)
                {
                        return $this->_let('location', $new_location);
                }

                function get_street()
                {
                        return $this->_get('address_street');
                }

                function let_street($new_street)
                {
                        return $this->_let('address_street', $new_street);
                }

                function get_city()
                {
                        return $this->_get('address_city');
                }

                function let_city($new_city)
                {
                        return $this->_let('address_city', $new_city);
                }

                function get_country()
                {
                        return $this->_get('address_country');
                }

                function let_country($new_country)
                {
                        return $this->_let('address_country', $new_country);
                }

                function get_postal_code()
                {
                        return $this->_get('postal_code');
                }

                function let_postal_code($new_postal_code)
                {
                        return $this->_let('postal_code', $new_postal_code);
                }

                function get_number()
                {
                        return $this->_get('number');
                }

                function let_number($new_number)
                {
                        return $this->_let('number', $new_number);
                }

                function save()
                {
                        if($this->id() && 
$this->location_exists($this->get_organization_id()) && $this->can_write())
                        {
                                $sqlp = "UPDATE phpgw_cdb_org_location SET ";
                                if ($this->_dirty_vars())
                                {
                                reset($this->_dirty);
                                        do
                                        {
                                                $key = key($this->_dirty);
                                                switch($key)
                                                {
                                                        case 'location_id' :
                                                                break;
                                                        default:
                                                                $sql.=$key.'="';
                                                                $sql .= 
$this->_get($key) . '", ';
                                                }
                                        }
                                        while (next($this->_dirty));

                                        if ($sql)
                                        {
                                                $sql .= 'location_id="' . 
$this->get_location_id().'"'.
                                                        ' WHERE 
location_id="'.$this->get_location_id().'"';
                                                
$this->_db->query($sqlp.$sql,__LINE__,__FILE__);
                                        }
                                }

                        $this->_dirty = array();

                                return TRUE;
                        }
                        else
                        {
                                //TODO: raise a major error!
                                return FALSE;
                        }
                }

                function load($location_id)
                {
                        $this->_loaded = FALSE;

                        $sql = 'SELECT * FROM phpgw_cdb_org_location WHERE 
location_id="' .
                        $location_id.'"';
                        $this->_db->query($sql,__LINE__,__FILE__);

                        reset($this->_);
                        do
                        {
                                $key = key($this->_);
                                $this->_let($key,$this->_db->f($key));
                        }
                        while(next($this->_));

                        $this->_dirty = array();
                        $this->_loaded = TRUE;
                        return TRUE;

                }

                function create()
                {
                        $sql='INSERT INTO phpgw_cdb_org_location( ' .
                                '"organization_id", ' .
                                '"location", ' .
                                '"address_street", ' .
                                '"address_city", ' .
                                '"address_country", ' .
                                '"postal_code", ' .
                                '"number" ) ' .
                                'VALUES ("0", "", "", "", "", "", "", "")';
                        $this->_db->query($sql,__LINE__,__FILE__);
                        return 
$this->_db->get_last_insert_id('phpgw_cdb_org_location',
                                'location_id');

                }

                function location_exists($location_id)
                {
                        if (!is_int($location_id))
                        {
                                $location_id = $this->_get('location_id');
                        }
                        $sql='SELECT * FROM phpgw_cdb_org_location WHERE 
location_id="' .
                                $location_id.'"';
                        $this->_db->query($sql,__LINE__,__FILE__);
                        if ($this->_db->num_rows() > 0)
                        {
                                return TRUE;
                        }
                        else
                        {
                                return FALSE;
                        }
                }
        }
?>

====================================================
Index: class.cdb_phone.inc.php
<?php
  /**************************************************************************\
  * phpGroupWare                                                             *
  * http://www.phpgroupware.org/                                             *
  * This file written by Patrick Walsh <address@hidden>            *
  * ------------------------------------------------------------------------ *
  * Please see the documentation for these classes in the README file in     *
  * this directory.                                                          *
  * ------------------------------------------------------------------------ *
  *  This program is free software; you can redistribute it and/or modify it *
  *  under the terms of the GNU General Public License as published by the   *
  *  Free Software Foundation; either version 2 of the License, or (at your  *
  *  option) any later version.                                              *
  \**************************************************************************/

  /* $Id: class.cdb_phone.inc.php,v 1.1 2005/05/05 00:56:39 skwashd Exp $ */

        class cdb_phone extends cdb_generic
        {
                function cdb_phone()
                {
                        $this->_db = $GLOBALS['phpgw']->db;
                        /* add vars that have get/let interface to this array. 
*/
                        $this->_ = array(
                                'contact_phone_id'      => '',
                                'phone_category_id'     => 0,
                                'number'                        => ''
                        );
                }

                function save()
                {
                        // Build update query
                        $sqlp = "UPDATE phpgw_cdb_contact_phone SET ";
                        if ($this->_dirty_vars())
                        {
                                reset($this->_dirty);
                                do
                                {
                                        $key = key($this->_dirty);
                                        $sql.=$key.'="';
                                }
                                while (next($this->_dirty));
                                $sql .= $this->_get($key) . '", ';
                                if ($sql)
                                {
                                        $sql .= 'entity_id="' . $this->id().'"'.
                                                ' WHERE 
contact_phone_id="'.$this->get_phone_id().'"';
                                        
$this->_db->query($sqlp.$sql,__LINE__,__FILE__);
                                }
                                return TRUE;
                        }
                        else
                        {
                                return FALSE;
                        }
                }

                function load($phone_id)
                {
                        $sql = 'SELECT * FROM phpgw_cdb_contact_phone WHERE 
contact_phone_id="' .
                                $phone_id . '"';
                        $this->_db->query($sql,__LINE__,__FILE__);

                        reset($this->_);
                        do
                        {
                                $key = key($this->_);
                                $this->_let($key,$this->_db->f($key));
                        }
            while(next($this->_));

                        $this->_id = (int)$this->_db->f('entity_id');

                        $this->_loaded = TRUE;
                        $this->_dirty = array();

                        return (int)$this->id();
                }

                function create($entity_id, $type_id, $number)
                {
                        $this->_loaded = TRUE;
                        $this->_dirty = array();
            $sql = 'INSERT INTO phpgw_cdb_contact_phone ("entity_id",' .
                                        '"phone_category_id", "number") VALUES 
' .
                    '("'.$entity_id.'","'.$type_id.'","'.$number.'")';
            $this->_db->query($sql,__LINE__,__FILE__);
                        $this->_id = $entity_id;
            $this->_let('contact_phone_id',
                    $this->_db->get_last_insert_id('phpgw_cdb_contact_phone',
                    'contact_phone_id'));

                        return $this->_db->query($sql,__LINE__,__FILE__);
                }

                function get_phone_id()
                {
                        return (int)$this->_get('contact_phone_id');
                }

                function get_type_name()
                {
                        $sql = 'SELECT phone_category_name FROM 
phpgw_cdb_contact_phone_cat'.
                                ' WHERE 
phone_category_id="'.$this->_get('phone_category_id').
                                '"';
                        $this->_db->query($sql,__LINE__,__FILE__);
                        return $this->_db->f('phone_category_name');
                }

                function get_type()
                {
                        return (int)$this->_get('phone_category_id');
                }

                function let_type($new_type)
                {
                        return $this->_let('phone_category_id', (int)$new_type);
                }

                function get_number()
                {
                        return $this->_get('number');
                }

                function let_number($new_number)
                {
                        return $this->_let('number', $new_number);
                }
        }
?>

====================================================
Index: class.ui.inc.php
//user interface

====================================================
Index: class.so.inc.php
// Storage Objects

====================================================
Index: class.cdb_template.inc.php
<?php
  /**************************************************************************\
  * phpGroupWare                                                             *
  * http://www.phpgroupware.org/                                             *
  * This file written by Patrick Walsh <address@hidden>            *
  * ------------------------------------------------------------------------ *
  * Please see the documentation for these classes in the README file in     *
  * this directory.                                                          *
  * ------------------------------------------------------------------------ *
  *  This program is free software; you can redistribute it and/or modify it *
  *  under the terms of the GNU General Public License as published by the   *
  *  Free Software Foundation; either version 2 of the License, or (at your  *
  *  option) any later version.                                              *
  \**************************************************************************/

  /* $Id: class.cdb_template.inc.php,v 1.1 2005/05/05 00:56:39 skwashd Exp $ */

/*      This file is here merely to serve as an EXAMPLE of how to create
        a class in cdb.
*/

/*!
        @class cdb_xxx
        @abstract This class does xxx
        @syntax CreateObject('cdb.cdb_xxx');
        @example $x = CreateObject('cdb.cdb_xxx');
        @author your_name_here
        @copyright GPL
        @package cdb
        @access public
*/
        class cdb_xxx extends cdb_generic
        {
                function cdb_xxx()
                {
                        // var $_privatevarshere; // This is an syntax error 
and seems also to be useless
                        $this->_db = $GLOBALS['phpgw']->db;

                        /* add vars that have get/let interface to this array. 
*/
                        $this->_ = array(
                                'zzz' => '',
                                'yyy' => 0,
                                'xxx' => ''
                        );
                }

                /*!
                @function get_zzz
                @abstract Get's the zzz property
                @discussion Returns either x or y
                @example1 $x->get_zzz();
                */
                function get_zzz()
                {
                        return $this->_get('zzz');
                }

                function let_zzz($new_zzz)
                {
                        // Check for sane data here before calling _let
                        return $this->_let('zzz', $new_zzz);
                }

                function get_xxx()
                {
                        return $this->_get('xxx');
                }

                function let_xxx($new_xxx)
                {
                        return $this->_let('xxx', $new_xxx);
                }
        }
?>

====================================================
Index: class.ui_generic.inc.php
<?php
  /**************************************************************************\
  * phpGroupWare                                                             *
  * http://www.phpgroupware.org/                                             *
  * This file written by Patrick Walsh <address@hidden>               *
  * ------------------------------------------------------------------------ *
  * Please see the documentation for these classes in the README file in     *
  * this directory.                                                          *
  * ------------------------------------------------------------------------ *
  *  This program is free software; you can redistribute it and/or modify it *
  *  under the terms of the GNU General Public License as published by the   *
  *  Free Software Foundation; either version 2 of the License, or (at your  *
  *  option) any later version.                                              *
  \**************************************************************************/

  /* $Id: class.ui_generic.inc.php,v 1.1 2005/05/05 00:56:39 skwashd Exp $ */

/*!
        @class ui_generic
        @abstract This class will be the parent of the view classes
        @author Patrick Walsh (mr_e)
        @copyright GPL
        @package cdb
        @access public
*/
        class ui_generic
        {
                function ui_generic()
                {
                }

        }
?>

====================================================
Index: class.ui_overview.inc.php
<?php
  /**************************************************************************\
  * phpGroupWare                                                             *
  * http://www.phpgroupware.org/                                             *
  * This file written by Patrick Walsh <address@hidden>               *
  * ------------------------------------------------------------------------ *
  * Please see the documentation for these classes in the README file in     *
  * this directory.                                                          *
  * ------------------------------------------------------------------------ *
  *  This program is free software; you can redistribute it and/or modify it *
  *  under the terms of the GNU General Public License as published by the   *
  *  Free Software Foundation; either version 2 of the License, or (at your  *
  *  option) any later version.                                              *
  \**************************************************************************/

  /* $Id: class.ui_overview.inc.php,v 1.1 2005/05/05 00:56:39 skwashd Exp $ */

/*!
        @class ui_overview
        @abstract This class spits out the overview screen
        @author Patrick Walsh (mr_e)
        @copyright GPL
        @package cdb
        @access public
*/
        class ui_overview
        {
                function ui_overview()
                {
                }

        }
?>






reply via email to

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