phpgroupware-cvs
[Top][All Lists]
Advanced

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

[Phpgroupware-cvs] CVS: cdb/inc class.cdb_contact.inc.php,1.1,1.2


From: Patrick Walsh <address@hidden>
Subject: [Phpgroupware-cvs] CVS: cdb/inc class.cdb_contact.inc.php,1.1,1.2
Date: Mon, 28 Jan 2002 04:50:11 -0500

Update of /cvsroot/phpgroupware/cdb/inc
In directory subversions:/tmp/cvs-serv11720

Modified Files:
        class.cdb_contact.inc.php 
Log Message:
fleshed out all the functions

Index: class.cdb_contact.inc.php
===================================================================
RCS file: /cvsroot/phpgroupware/cdb/inc/class.cdb_contact.inc.php,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** class.cdb_contact.inc.php   11 Nov 2001 15:43:42 -0000      1.1
--- class.cdb_contact.inc.php   28 Jan 2002 09:50:08 -0000      1.2
***************
*** 3,7 ****
        * phpGroupWare                                                          
   *
        * http://www.phpgroupware.org/                                          
   *
!       * This file written by Patrick Walsh <address@hidden>            *
        * with some part done by Mathieu van Loon <address@hidden>         *
        * 
------------------------------------------------------------------------ *
--- 3,7 ----
        * phpGroupWare                                                          
   *
        * http://www.phpgroupware.org/                                          
   *
!       * This file written by Patrick Walsh <address@hidden>               *
        * with some part done by Mathieu van Loon <address@hidden>         *
        * 
------------------------------------------------------------------------ *
***************
*** 17,37 ****
        /* $Id$ */
  
!       
/**************************************************************************\
!       * Developers: please execute a search on TODO for things to be done     
   *
!       * Also, execute a search on NOTE for stuff I wasn't sure about, or      
   *
!       * might require attention some other way                                
   *
!       * mathieu                                                               
   *
!       
\**************************************************************************/
  
        class cdb_contact extends cdb_generic
        {
                var $_client; /* my subclass client */
                var $_meta; /* my subclass meta */
! 
                function cdb_contact()
                {
                        $this->_ = array(
!                               /* TODO */
!                               /* add vars that have get/let interface to this 
array. */
                                'main_organization_location_selector' => 0,
                                'first_name'       => '',
--- 17,49 ----
        /* $Id$ */
  
! /*!
!         @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
        {
+           /////////////////////////////////////////////////
+          ////////////// Public Functions /////////////////
+         /////////////////////////////////////////////////
                var $_client; /* my subclass client */
                var $_meta; /* my subclass 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'       => '',
***************
*** 59,166 ****
                }
  
!               /* NOTE: I removed function id() because it is
!                        called directly from the inherited class
!                        -Patrick
                */
!               function create($strName)
                {
!                       /* TODO */
!                       return int $id || 0;
                }
  
                function save()
                {
!                       /* TODO: for now, we don't check for dirty flags. will 
add later */
! 
!                       /* NOTE: $this->_note is not stored in the contact_main 
class, */
!                       /* but stored in contact_notes. It will be stored by 
this function */
!                       /* though */
!                       $mySuccess = False;
!                               
!                       // Check to make sure we have been loaded or created 
prior to this save
!                       if($this->id() && $this->exists($this->id()))
                        {
                                // Build query
!                               $query = "UPDATE phpgw_cdb_contact_main SET ".
!                                       
//"main_organization_location_selector=0". WHAT IS IT FOR?
!                                       "first_name='" . 
$this->get('first_name')."', ".
!                                       "middle_name='". 
$this->get('middle_name')."', ".
!                                       "last_name='"  . 
$this->get('last_name')."', ".
!                                       "last_name_prefix='" . 
$this->get('last_name_prefix')."', ".
!                                       "initials='" . 
$this->get('initials')."', ".
!                                       "location='" . 
$this->get('location')."', ".
!                                       "nickname='" . 
$this->get('nickname')."', ".
!                                       "profession='" . 
$this->get('profession')."', ".
!                                       "suffix='"   . $this->get('suffix')."', 
".
!                                       "title='"    . $this->get('title')."', 
".
!                                       "email_selector=" . 
$this->get('email_selector').", ".
!                                       "web_selector='" . 
$this->get('web_selector')." ".
!                                       "WHERE contact_id=" . $this->id();
! 
!                               // Execute query
!                               $GLOBALS['phpgw']->db->query($query);
! 
!                               // the note field is stored in a different 
table.
!                               // We don't know whether an actual record 
exists for this note
!                               // So we check first
!                               $query = "SELECT contact_id FROM 
phpgw_cdb_contact_notes ".
!                                        "WHERE contact_id=".$this->id());
!                               $GLOBALS['phpgw']->db->query($query);
!                               if($GLOBALS['phpgw']->db->num_rows() == 1) // 
we'll have to update
                                {
!                                       $query = "UPDATE 
phpgw_cdb_contact_notes SET note='".$this->get(note)."' ".
!                                                "WHERE 
contact_id=".$this->id());
!                                       $GLOBALS['phpgw']->db->query($query);
                                }
!                               else // we'll have to insert
!                               {
!                                       $query = "INSERT INTO 
phpgw_cdb_contact_notes (contact_id, note) ".
!                                                "VALUES 
(".$this->id().",'".$this->get('note')."')";
!                                       $GLOBALS['phpgw']->db->query($query);
!                               }
! 
!                               // Done
!                               $mySuccess = True;
                        }
-                       return $mySuccess;
                }
  
!               function load($intID)
!               {
!                       /* TODO */
!                       $mySuccess = False;
!                       return $mySuccess;
                }
  
!               /* Function exists is in generic.class.php, which is inherited
!               function exists($intID)
                {
!                       $mySuccess = FALSE;
!                       if(is_int($intID)
                        {
!       
!                                // do stuff
                        }
!                       return $mySuccess;
                }
!               */
!               function delete()
                {
!                       /* NOTE: I assume someone with write access 
(can_write($intID) evaluates */
!                       /* to TRUE, has delete access as well */
!                       $mySuccess = False;
!                       if($this->can_write($this->_id)) // check for write 
permission
!                       {
!                               if($this->meta->let_status('delete')) // try to 
set status to 'delete'
!                               {
!                                       $mySuccess = True; // report TRUE on 
success
!                               }
!                       }
!                       return $mySuccess;
                }
  
                function get_client_data()
                {
!                       /* TODO */
                        return $this->_client;
                }
--- 71,276 ----
                }
  
!               /*!
!               @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 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 cdb_entity_id ("contact_id") VALUES 
("' .
+                                       $contact_id . '")';
+                       $this->_db->query($sql,__LINE__,__FILE__);
+                       $this->_id = 
$this->_db->get_last_insert_id('cdb_entity_id',
+                                       'entity_id');
+                       // Create entry in entity_meta
+                       $status = "active";
+                       $sql = 'INSERT INTO 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 cdb_entity_notes 
("entity_id","note") VALUES ' .
+                                       '("'.$this->id().'","")';
+                       $this->_db->query($sql,__LINE__,__FILE__);
+                       
+                       return $this->id();
+               }
+ 
+       function exists($contact_id)
+       {
+               if (!is_int($contact_id))
+               {
+               $contact_id = $this->_get('contact_id');
+               }
+               $sql='SELECT * FROM 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 
on
+               success and false on failure.
+         @example1 $x->save();
+         */  
                function save()
                {
!                       //TODO need to save the children if they are loaded
!                       if($this->id() && $this->exists($this->id()) && 
$this->can_write())
                        {
                                // Build query
!                               $sqlp = "UPDATE cdb_contact_main SET ";
!                               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 
cdb_entity_notes SET note="'.
!                                                                       
$this->get_note().'" WHERE entity_id="'.
!                                                                       
$this->id().'"';
!                                                       
$this->_db->query($sql2,__LINE__,__FILE__);
!                                                       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__);
                                }
!                               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...
!                       
!                       if (! $entity_id = $this->exists($contact_id))
!                       {
!                               return FALSE;
!                       }
!                       $this->_id = $entity_id;
! 
!                       // Now lookup the main contact info
!                       $sql = 'SELECT * FROM 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 cdb_entity_notes WHERE 
entity_id="' .
!                                       $this->id() . '"';
!                       $this->_db->query($sql,__LINE__,__FILE__);
!                       $this->_let('note',$this->_db->f('note'));
! 
                }
  
!               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;
                }
***************
*** 202,206 ****
                function get_first_name()
                {
!                       return $this->get('first_name');
                }
                function let_first_name($inStr)
--- 312,316 ----
                function get_first_name()
                {
!                       return $this->_get('first_name');
                }
                function let_first_name($inStr)
***************
*** 211,215 ****
                        if(strlen($inStr)<=255)
                        {
!                               $mySuccess = $this->let('first_name',$inStr);
                        }
                        return $mySuccess;
--- 321,325 ----
                        if(strlen($inStr)<=255)
                        {
!                               $mySuccess = $this->_let('first_name',$inStr);
                        }
                        return $mySuccess;
***************
*** 217,221 ****
                function get_middle_name()
                {
!                       return $this->get('middle_name');
                }
                function let_middle_name($inStr)
--- 327,331 ----
                function get_middle_name()
                {
!                       return $this->_get('middle_name');
                }
                function let_middle_name($inStr)
***************
*** 226,230 ****
                        if(strlen($inStr)<=255)
                        {
!                               $mySuccess = $this->let('middle_name',$inStr);
                        }
                        return $mySuccess;
--- 336,340 ----
                        if(strlen($inStr)<=255)
                        {
!                               $mySuccess = $this->_let('middle_name',$inStr);
                        }
                        return $mySuccess;
***************
*** 232,236 ****
                function get_last_name()
                {
!                       return $this->get('last_name');
                }
                function let_last_name($inStr)
--- 342,346 ----
                function get_last_name()
                {
!                       return $this->_get('last_name');
                }
                function let_last_name($inStr)
***************
*** 241,245 ****
                        if(strlen($inStr)<=255)
                        {
!                               $mySuccess = $this->let('last_name',$inStr);
                        }
                        return $mySuccess;
--- 351,355 ----
                        if(strlen($inStr)<=255)
                        {
!                               $mySuccess = $this->_let('last_name',$inStr);
                        }
                        return $mySuccess;
***************
*** 247,251 ****
                function get_last_name_prefix()
                {
!                       return $this->get('last_name_prefix');
                }
                function let_last_name_prefix($inStr)
--- 357,361 ----
                function get_last_name_prefix()
                {
!                       return $this->_get('last_name_prefix');
                }
                function let_last_name_prefix($inStr)
***************
*** 256,260 ****
                        if(strlen($inStr)<=10)
                        {
!                               $mySuccess = 
$this->let('last_name_prefix',$inStr);
                        }
                        return $mySuccess;
--- 366,370 ----
                        if(strlen($inStr)<=10)
                        {
!                               $mySuccess = 
$this->_let('last_name_prefix',$inStr);
                        }
                        return $mySuccess;
***************
*** 262,266 ****
                function get_initials()
                {
!                       return $this->get('initials');
                }
                function let_initials($inStr)
--- 372,376 ----
                function get_initials()
                {
!                       return $this->_get('initials');
                }
                function let_initials($inStr)
***************
*** 271,275 ****
                        if(strlen($inStr)<=6)
                        {
!                               $mySuccess = $this->let('initials',$inStr);
                        }
                        return $mySuccess;
--- 381,385 ----
                        if(strlen($inStr)<=6)
                        {
!                               $mySuccess = $this->_let('initials',$inStr);
                        }
                        return $mySuccess;
***************
*** 277,281 ****
                function get_location()
                {
!                       return $this->get('location');
                }
                function let_location($inStr)
--- 387,391 ----
                function get_location()
                {
!                       return $this->_get('location');
                }
                function let_location($inStr)
***************
*** 286,290 ****
                        if(strlen($inStr)<=255)
                        {
!                               $mySuccess = $this->let('location',$inStr);
                        }
                        return $mySuccess;
--- 396,400 ----
                        if(strlen($inStr)<=255)
                        {
!                               $mySuccess = $this->_let('location',$inStr);
                        }
                        return $mySuccess;
***************
*** 292,296 ****
                function get_nickname()
                {
!                       return $this->get('nickname');
                }
                function let_nickname($inStr)
--- 402,406 ----
                function get_nickname()
                {
!                       return $this->_get('nickname');
                }
                function let_nickname($inStr)
***************
*** 301,305 ****
                        if(strlen($inStr)<=255)
                        {
!                               $mySuccess = $this->let('nickname',$inStr);
                        }
                        return $mySuccess;
--- 411,415 ----
                        if(strlen($inStr)<=255)
                        {
!                               $mySuccess = $this->_let('nickname',$inStr);
                        }
                        return $mySuccess;
***************
*** 307,311 ****
                function get_profession()
                {
!                       return $this->get('profession');
                }
                function let_profession($inStr)
--- 417,421 ----
                function get_profession()
                {
!                       return $this->_get('profession');
                }
                function let_profession($inStr)
***************
*** 316,320 ****
                        if(strlen($inStr)<=255)
                        {
!                               $mySuccess = $this->let('profession',$inStr);
                        }
                        return $mySuccess;
--- 426,430 ----
                        if(strlen($inStr)<=255)
                        {
!                               $mySuccess = $this->_let('profession',$inStr);
                        }
                        return $mySuccess;
***************
*** 322,326 ****
                function get_suffix()
                {
!                       return $this->get('suffix');
                }
                function let_suffix($inStr)
--- 432,436 ----
                function get_suffix()
                {
!                       return $this->_get('suffix');
                }
                function let_suffix($inStr)
***************
*** 331,335 ****
                        if(strlen($inStr)<=20)
                        {
!                               $mySuccess = $this->let('suffix',$inStr);
                        }
                        return $mySuccess;
--- 441,445 ----
                        if(strlen($inStr)<=20)
                        {
!                               $mySuccess = $this->_let('suffix',$inStr);
                        }
                        return $mySuccess;
***************
*** 337,341 ****
                function get_title()
                {
!                       return $this->get('title');
                }
                function let_title($inStr)
--- 447,451 ----
                function get_title()
                {
!                       return $this->_get('title');
                }
                function let_title($inStr)
***************
*** 346,350 ****
                        if(strlen($inStr)<=20)
                        {
!                               $mySuccess = $this->let('title',$inStr);
                        }
                        return $mySuccess;
--- 456,460 ----
                        if(strlen($inStr)<=20)
                        {
!                               $mySuccess = $this->_let('title',$inStr);
                        }
                        return $mySuccess;
***************
*** 357,361 ****
                function get_mailing_address_selector()
                {
!                       return $this->get('mailing_address_selector');
                }
                function let_mailing_address_selector($inID)
--- 467,471 ----
                function get_mailing_address_selector()
                {
!                       return $this->_get('mailing_address_selector');
                }
                function let_mailing_address_selector($inID)
***************
*** 364,368 ****
                        if(is_int($inID))
                        {
!                               $mySuccess = 
$this->let('mailing_address_selector',$inID);
                        }
                        return $mySuccess;
--- 474,478 ----
                        if(is_int($inID))
                        {
!                               $mySuccess = 
$this->_let('mailing_address_selector',$inID);
                        }
                        return $mySuccess;
***************
*** 376,380 ****
                function get_web_selector()
                {
!                       return $this->get('web_selector');
                }
                function let_web_selector($inID)
--- 486,490 ----
                function get_web_selector()
                {
!                       return $this->_get('web_selector');
                }
                function let_web_selector($inID)
***************
*** 383,387 ****
                        if(is_int($inID))
                        {
!                               $mySuccess = $this->let('web_selector',$inID);
                        }
                        return $mySuccess;
--- 493,497 ----
                        if(is_int($inID))
                        {
!                               $mySuccess = $this->_let('web_selector',$inID);
                        }
                        return $mySuccess;
***************
*** 392,399 ****
                        return string;
                }
                function get_email_selector()
                {
!                       return $this->get('email_selector');
                }
                function let_email_selector($inID)
                {
--- 502,511 ----
                        return string;
                }
+ 
                function get_email_selector()
                {
!                       return $this->_get('email_selector');
                }
+ 
                function let_email_selector($inID)
                {
***************
*** 401,408 ****
                        if(is_int($inID))
                        {
!                               $mySuccess = $this->let('email_selector',$inID);
                        }
                        return $mySuccess;
                }
                function get_phonex($inID)
                {
--- 513,521 ----
                        if(is_int($inID))
                        {
!                               $mySuccess = 
$this->_let('email_selector',$inID);
                        }
                        return $mySuccess;
                }
+ 
                function get_phonex($inID)
                {
***************
*** 414,417 ****
--- 527,531 ----
                        return string;
                }
+ 
                function get_phonex_selector($inID)
                {
***************
*** 420,427 ****
                        {
                                $phonex_selector_varname = 
'phone'.$inID.'_selector';
!                               $myReply = $this->get($phonex_selector_varname);
                        }
                        return $myReply;
                }
                function let_phonex_selector($inID, $inNewVal)
                {
--- 534,542 ----
                        {
                                $phonex_selector_varname = 
'phone'.$inID.'_selector';
!                               $myReply = 
$this->_get($phonex_selector_varname);
                        }
                        return $myReply;
                }
+ 
                function let_phonex_selector($inID, $inNewVal)
                {
***************
*** 430,451 ****
                        {
                                $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($inStr)
                {
                        /* NOTE Due to database restrictions the note */
                        /* can be no longer than 65535 characters */
!                       $mySuccess = False;
!                       if(strlen($inStr)<=65535)
                        {
!                               $mySuccess = $this->let('note', $inStr);
                        }
!                       return $mySuccess;
                }
        }
--- 545,654 ----
                        {
                                $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;
                }
        }




reply via email to

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