phpgroupware-cvs
[Top][All Lists]
Advanced

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

[Phpgroupware-cvs] phpgroupware/ipc_test_suite/sources/app/class.ipc_ad


From: nomail
Subject: [Phpgroupware-cvs] phpgroupware/ipc_test_suite/sources/app/class.ipc_addressbook.inc.php, 1.1.2.2
Date: Fri, 14 May 2004 20:39:44 +0200

Update of /phpgroupware/ipc_test_suite/sources/app
Modified Files:
        Branch: Version-0_9_16-branch
          class.ipc_addressbook.inc.php

date: 2004/05/14 18:39:44;  author: mkaemmerer;  state: Exp;  lines: +246 -84

Log Message:
- new version from DS
=====================================================================
Index: phpgroupware/ipc_test_suite/sources/app/class.ipc_addressbook.inc.php
diff -u 
phpgroupware/ipc_test_suite/sources/app/class.ipc_addressbook.inc.php:1.1.2.1 
phpgroupware/ipc_test_suite/sources/app/class.ipc_addressbook.inc.php:1.1.2.2
--- 
phpgroupware/ipc_test_suite/sources/app/class.ipc_addressbook.inc.php:1.1.2.1   
    Mon Apr  5 19:42:00 2004
+++ phpgroupware/ipc_test_suite/sources/app/class.ipc_addressbook.inc.php       
Fri May 14 18:39:44 2004
@@ -98,44 +98,124 @@
                {
                        $owner = $GLOBALS['phpgw_info']['user']['account_id'];
 
+                       // First, make sure they have permission to this entry
                        if(!$this->contacts->check_read($id, $owner))
                        {
                                return false;
                        }
 
-                       // First, make sure they have permission to this entry
-                       $fieldlist = $this->contacts->person_complete_data($id);
+                       $contact_type = 
$this->contacts->search_contact_type_id($this->contacts->get_type_contact($id));
                        
+
+                       $fields['type']            = $contact_type;
+                       $fields['id']              = $id;
+                       $fields['adr_one_type']    = 'WORK';
+                       $fields['adr_two_type']    = 'HOME';
+                       $fields['email_type']      = 'INTERNET';
+                       $fields['email_home_type'] = 'INTERNET';
+
+                       if($contact_type == $this->contacts->get_person_name())
+                       { // person
+                               $fieldlist = 
$this->contacts->person_complete_data($id);
+
+                               $fields['owner']    = $fieldlist['owner'];
+                               $fields['access']   = $fieldlist['access'];
+                               $fields['createon'] = $fieldlist['createon'];
+                               $fields['modon']    = $fieldlist['modon'];
+       
+                               /*
+                               $fields['full_name'] = $fieldlist['full_name'];
+                               bug: $fieldlist['full_name'] contains two 
spaces between first and last name, when middle name is empty
+                               workaround: calculate the fullname like shown 
below
+                               */
+                               $fields['first_name']   = 
$fieldlist['first_name'];
+                               $fields['last_name']    = 
$fieldlist['last_name'];
+                               $fields['middle_name']  = 
$fieldlist['middle_name'];
+       
+                               $fields['full_name']    = $fields['first_name'] 
. ' ';
+                               $fields['full_name']   .= 
($fields['middle_name'] != '') ? $fields['middle_name'] . ' ' : '';
+                               $fields['full_name']   .= $fields['last_name'];
+       
+                               $fields['prefix']       = $fieldlist['prefix'];
+                               $fields['suffix']       = $fieldlist['suffix'];
+                               $fields['sound']        = $fieldlist['sound'];
+                               $fields['birthday']     = 
$fieldlist['birthday'];
+                               //$fields['note']       = $fieldlist[''];
+                               //$fields['tz']         = 
$fieldlist['locations'][$type_work][''];
+                               //$fields['geo']        = $fieldlist[''];
+                               $fields['pubkey']       = $fieldlist['pubkey'];
+                               $fields['org_name']     = 
$fieldlist['org_name'];
+                               $fields['org_unit']     = 
$fieldlist['department'];
+                               $fields['title']        = $fieldlist['title'];
+                               //$fields['tel_prefer'] = $fieldlist[''];
+
+                               $cats = 
$this->contacts->get_cats_by_person($id);
+                               $fields['cat_id'] = implode(",", $cats);
+                       }
+                       elseif($contact_type == $this->contacts->get_org_name())
+                       { // organization
+                               $fieldlist = array();
+
+                               $data = 
array('contact_id','owner','access','cat_id','org_name','org_creaton','org_modon');
+                               $org_data = $this->contacts->get_orgs($data, 
null, null, null, 'ASC', array('contact_id' => $id), null);
+
+                               if(!isset($org_data[0]))
+                               {
+                                       return false;
+                               }
+
+                               $fields['owner']          = 
$org_data[0]['owner'];
+                               $fields['access']         = 
$org_data[0]['access']?$org_data[0]['access']:'';
+                               $fields['createon']     = 
$org_data[0]['org_creaton']?$org_data[0]['org_creaton']:'';
+                               $fields['modon']          = 
$org_data[0]['org_modon']?$org_data[0]['org_modon']:'';
+                               $fields['org_name']     = 
$org_data[0]['org_name'];
+                               $fields['cat_id']         = 
$org_data[0]['cat_id']?$org_data[0]['cat_id']:'';
+                               
+                               $loclist = 
$this->contacts->get_addr_contact_data($id);
+                               if(is_array($loclist))
+                               {
+                                       $fieldlist['locations'] = array();
+                                       while(list($no_use, $loc) = 
each($loclist))
+                                       {
+                                               $addr_id = $loc['key_addr_id'];
+                                               
$fieldlist['locations'][$addr_id] = array(
+                                                       'type'        => 
$loc['addr_description'],
+                                                       'add1'        => 
$loc['addr_add1'],
+                                                       'add2'        => 
$loc['addr_add2'],
+                                                       'city'        => 
$loc['addr_city'],
+                                                       'state'       => 
$loc['addr_state'],
+                                                       'postal_code' => 
$loc['addr_postal_code'],
+                                                       'country'     => 
$loc['addr_country']
+                                               );
+                                       }
+                               }
+
+                               $commlist = 
$this->contacts->get_comm_contact_data($id);
+                               if(is_array($commlist))
+                               {
+                                       $fieldlist['comm_media'] = array();
+                                       while(list($no_use, $comm) = 
each($commlist))
+                                       {
+                                               $comm_type = 
$comm['comm_description'];
+                                               
$fieldlist['comm_media'][$comm_type] = $comm['comm_data'];
+                                       }
+                               }
+
+                               $cats = $this->contacts->get_cats_by_org($id);
+                               while(list($no_use, $cat_id) = each($cats))
+                               {
+                                       if($cat_id)
+                                               $cat_id_list[] = $cat_id;
+                               }
+                               $cats = $cat_id_list;
+                               $fields['cat_id'] = implode(",", $cats);
+                       }
+                       else
+                       {
+                               return false;
+                       }
+
                        $type_work = 
$this->contacts->search_location_type('work');
                        $type_home = 
$this->contacts->search_location_type('home');
-                       /*
-                       $fields['full_name']            = 
$fieldlist['full_name'];
-                       bug: $fieldlist['full_name'] contains two spaces 
between first and last name, when middle name is empty
-                       workaround: calculate the fullname like shown below
-                       */
-                       $fields['first_name']           = 
$fieldlist['first_name'];
-                       $fields['last_name']            = 
$fieldlist['last_name'];
-                       $fields['middle_name']          = 
$fieldlist['middle_name'];
-
-                       $fields['full_name']            = $fields['first_name'] 
. ' ';
-                       $fields['full_name']           .= 
($fields['middle_name'] != '') ? $fields['middle_name'] . ' ' : '';
-                       $fields['full_name']           .= $fields['last_name'];
-
-                       $fields['prefix']               = $fieldlist['prefix'];
-                       $fields['suffix']               = $fieldlist['suffix'];
-                       $fields['sound']                = $fieldlist['sound'];
-                       $fields['birthday']             = 
$fieldlist['birthday'];
-                       //$fields['note']               = $fieldlist[''];
-                       //$fields['tz']                 = 
$fieldlist['locations'][$type_work][''];
-                       //$fields['geo']                = $fieldlist[''];
-                       $fields['pubkey']               = $fieldlist['pubkey'];
-                       $fields['org_name']             = 
$fieldlist['org_name'];
-                       $fields['org_unit']             = 
$fieldlist['department'];
-                       $fields['title']                = $fieldlist['title'];
-                       $fields['adr_one_type']         = 'WORK';
-                       $fields['adr_two_type']         = 'HOME';
-                       //$fields['tel_prefer']         = $fieldlist[''];
-                       $fields['email_type']           = 'INTERNET';
-                       $fields['email_home_type']      = 'INTERNET';
 
                        // locations contains a list of loc_id and its date
                        if (isset($fieldlist['locations']) && 
is_array($fieldlist['locations']))
@@ -166,34 +246,37 @@
                                }
                        }
 
-                       $fields['tel_work']             = 
$fieldlist['comm_media']['work phone'];
-                       $fields['tel_home']             = 
$fieldlist['comm_media']['home phone'];
-                       $fields['tel_voice']            = 
$fieldlist['comm_media']['voice phone'];
-                       $fields['tel_work_fax']         = 
$fieldlist['comm_media']['work fax'];
-                       $fields['tel_home_fax']         = 
$fieldlist['comm_media']['home fax'];
-                       $fields['tel_msg']              = 
$fieldlist['comm_media']['msg phone'];
-                       $fields['tel_cell']             = 
$fieldlist['comm_media']['mobile (cell) phone'];
-                       $fields['tel_pager']            = 
$fieldlist['comm_media']['pager'];
-                       $fields['tel_bbs']              = 
$fieldlist['comm_media']['bbs'];
-                       $fields['tel_modem']            = 
$fieldlist['comm_media']['modem'];
-                       $fields['tel_car']              = 
$fieldlist['comm_media']['car phone'];
-                       $fields['tel_isdn']             = 
$fieldlist['comm_media']['isdn'];
-                       $fields['tel_video']            = 
$fieldlist['comm_media']['video'];
-                       $fields['email']                = 
$fieldlist['comm_media']['work email'];
-                       $fields['email_home']           = 
$fieldlist['comm_media']['home email'];
-                       $fields['url']                  = 
$fieldlist['comm_media']['website'];
-
-                       $email = $fields['email'];
-                       $emailtype = $fields['email_type'];
-                       if (!$emailtype)
-                       {
-                               $fields['email_type'] = 'INTERNET';
-                       }
-                       $hemail       = $fields['email_home'];
-                       $hemailtype   = $fields['email_home_type'];
-                       if (!$hemailtype)
+                       if (isset($fieldlist['comm_media']) && 
is_array($fieldlist['comm_media']))
                        {
-                               $fields['email_home_type'] = 'INTERNET';
+                               $fields['tel_work']             = 
$fieldlist['comm_media']['work phone'];
+                               $fields['tel_home']             = 
$fieldlist['comm_media']['home phone'];
+                               $fields['tel_voice']            = 
$fieldlist['comm_media']['voice phone'];
+                               $fields['tel_work_fax']         = 
$fieldlist['comm_media']['work fax'];
+                               $fields['tel_home_fax']         = 
$fieldlist['comm_media']['home fax'];
+                               $fields['tel_msg']              = 
$fieldlist['comm_media']['msg phone'];
+                               $fields['tel_cell']             = 
$fieldlist['comm_media']['mobile (cell) phone'];
+                               $fields['tel_pager']            = 
$fieldlist['comm_media']['pager'];
+                               $fields['tel_bbs']              = 
$fieldlist['comm_media']['bbs'];
+                               $fields['tel_modem']            = 
$fieldlist['comm_media']['modem'];
+                               $fields['tel_car']              = 
$fieldlist['comm_media']['car phone'];
+                               $fields['tel_isdn']             = 
$fieldlist['comm_media']['isdn'];
+                               $fields['tel_video']            = 
$fieldlist['comm_media']['video'];
+                               $fields['email']                = 
$fieldlist['comm_media']['work email'];
+                               $fields['email_home']           = 
$fieldlist['comm_media']['home email'];
+                               $fields['url']                  = 
$fieldlist['comm_media']['website'];
+                               
+                               $email = $fields['email'];
+                               $emailtype = $fields['email_type'];
+                               if (!$emailtype)
+                               {
+                                       $fields['email_type'] = 'INTERNET';
+                               }
+                               $hemail       = $fields['email_home'];
+                               $hemailtype   = $fields['email_home_type'];
+                               if (!$hemailtype)
+                               {
+                                       $fields['email_home_type'] = 'INTERNET';
+                               }
                        }
 
                        // convert fields to mime type format
@@ -206,9 +289,11 @@
                                case 'text/xml':
                                        return $this->_export_xml($fields);
                                break;
+                               case 'x-phpgroupware/search-index-data-item':
+                                       return 
$this->_export_index_data_item($fields);
+                               break;
                                default:
                                        return false;
-                               break;
                        }
 
                }
@@ -218,10 +303,11 @@
                * Return a list with the available id's in the application.
                * The optional lastmod parameter allows a limitations of the 
data id list.
                * The list contains all the id's of the modified data since the 
passed lastmod timestamp.
-               * @param integer $lastmod last modification time, default is -1 
and means return all data id's
+               * @param integer $lastmod last modification time, default is -1 
and means return all data id's.
+               * @param string $restriction restrict the result for a special 
use of the id list. The possible restrictions are 'syncable' or 'searchable'. 
When using 'syncable' only person ids will be returned in the result. 
'searchable' returns all ids for both persons and orgs without check the owner. 
Otherwise no restriction will be used and the result contains all ids for both 
persons and orgs from the owner.
                * @return array list of data id's
                */
-               function getIdList($lastmod=-1)
+               function getIdList($lastmod=-1, $restriction='')
                {
                        $idList = array();
                        $lastmod = intval($lastmod);
@@ -230,31 +316,63 @@
                        //$this->contacts->read(null, false, null, null, null, 
null, null, $lastmod);
                        // read_contacts doesnt allow lastmod time -> 
workaround:
 
-                       if($lastmod >= 0)
+                       if($lastmod > 0)
                        {
-                               $sql = 'SELECT DISTINCT c.contact_id AS 
contact_id '.
-                                       'FROM phpgw_contact c '.
-                                       'LEFT JOIN phpgw_contact_addr ca ON 
(c.contact_id=ca.contact_id) '.
-                                       'LEFT JOIN phpgw_contact_comm cc ON 
(c.contact_id=cc.contact_id) '.
-                                       'LEFT JOIN phpgw_contact_note cn ON 
(c.contact_id=cn.contact_id) '.
-                                       'LEFT JOIN phpgw_contact_person cp ON 
(c.contact_id=cp.person_id) '.
-                                       'WHERE '.
-                                       ' (c.owner = '.$owner.')'.
-                                       ' AND'.
-                                       ' ('.
-                                       '  (ca.modified_on > '.$lastmod.') OR '.
-                                       '  (cc.modified_on > '.$lastmod.') OR '.
-                                       '  (cn.modified_on > '.$lastmod.') OR '.
-                                       '  (cp.modified_on > '.$lastmod.') '.
-                                       ' ) '.
-                                       'ORDER BY c.contact_id';
+                               $sql  = 'SELECT DISTINCT c.contact_id AS 
contact_id ';
+                               $sql .= 'FROM phpgw_contact c ';
+                               $sql .= 'JOIN phpgw_contact_addr ca ON 
(c.contact_id=ca.contact_id) ';
+                               $sql .= 'JOIN phpgw_contact_comm cc ON 
(c.contact_id=cc.contact_id) ';
+                               $sql .= 'JOIN phpgw_contact_note cn ON 
(c.contact_id=cn.contact_id) ';
+                               if($restriction == 'syncable')
+                               { // only persons - no organizations
+                                       $sql .= 'JOIN phpgw_contact_person cp 
ON (c.contact_id=cp.person_id) ';                         
+                               }
+                               else
+                               { // persons and organizations
+                                       $sql .= 'JOIN phpgw_contact_person cp 
ON (c.contact_id=cp.person_id) ';
+                                       $sql .= 'JOIN phpgw_contact_org co ON 
(c.contact_id=co.org_id) ';
+                               }
+                               $sql .= 'WHERE ';
+                               if($restriction != 'searchable')
+                               { // only owners data
+                                       $sql .= ' (c.owner = '.$owner.')';
+                                       $sql .= ' AND';
+                               }
+
+                               $sql .= ' (';
+                               $sql .= '  (ca.modified_on > '.$lastmod.') OR ';
+                               $sql .= '  (cc.modified_on > '.$lastmod.') OR ';
+                               $sql .= '  (cn.modified_on > '.$lastmod.') OR ';
+
+                               if($restriction == 'syncable')
+                               { // only persons - no organizations
+                                       $sql .= '  (cp.modified_on > 
'.$lastmod.') ';
+                               }
+                               else
+                               { // persons and organizations
+                                       $sql .= '  (cp.modified_on > 
'.$lastmod.') OR ';
+                                       $sql .= '  (co.modified_on > 
'.$lastmod.') ';
+                               }
+
+                               $sql .= ' ) ';
+                               $sql .= 'ORDER BY c.contact_id';
                        }
                        else
                        {
-                               $sql = 'SELECT DISTINCT contact_id '.
-                                       'FROM phpgw_contact '.
-                                       'WHERE owner = '.$owner.' '.
-                                       'ORDER BY contact_id';
+                               $sql  = 'SELECT DISTINCT c.contact_id AS 
contact_id ';
+                               $sql .= 'FROM phpgw_contact c ';
+
+                               if($restriction == 'syncable')
+                               { // only persons - no organizations
+                                       $sql .= 'JOIN phpgw_contact_person cp 
ON (c.contact_id=cp.person_id) ';
+                               }
+
+                               if($restriction != 'searchable')
+                               { // only owners data
+                                       $sql .= 'WHERE c.owner = '.$owner.' ';
+                               }
+
+                               $sql .=         'ORDER BY c.contact_id';
                        }
                        $contacts = 
$this->contacts->db->query($sql,__LINE__,__FILE__);
                        while ($this->contacts->db->next_record())
@@ -736,9 +854,53 @@
                */
                function _export_xml($fields)
                {
-                       $xml = CreateObject('phpgwapi.xmltool', 'root','','');
-                       return $xml->import_var('contact',$fields,True,True);
+                       $dom_doc = domxml_new_doc("1.0");
+
+                       // contact/
+                       $elem_contact = $dom_doc->create_element('contact');
+                       $node_contact = $dom_doc->append_child($elem_contact);
+                       
+                       while(list($element, $value) = each($fields))
+                       {
+                               // contact/<element>
+                               $xmlElement = 
$dom_doc->create_element($element);
+                               $xmlNode = 
$node_contact->append_child($xmlElement);
+                               // contact/<element> text string
+                               $xmlNode->set_content($value);
+                       }
+                       
+                       $xml_string = $dom_doc->dump_mem(true);
+                       return $xml_string;
                }
 
+               function &_export_index_data_item($fields)
+               {
+                       $index_xml_item = CreateObject('search.index_xml_item', 
'addressbook', $fields['id']);
+
+                       if($fields['type'] == 'Persons')
+                               
$index_xml_item->setDisplayName($fields['full_name']);
+                       elseif($fields['type'] == 'Organizations')
+                               
$index_xml_item->setDisplayName($fields['org_name']);
+
+                       $content = $this->_export_xml($fields);
+                       $index_xml_item->setContent($content, 'text/xml', 
'1.0');
+                       $index_xml_item->setContentTransferEncoding('base64');
+
+                       $catId   = $fields['cat_id']?$fields['cat_id']:'';
+                       $catName = $fields['cat']?$fields['cat']:'';
+                       $index_xml_item->setCategory($catId, $catName);
+
+                       $ownerId = $fields['owner'];
+                       $groupId = '';
+                       $visibilty = $fields['access'];
+                       $index_xml_item->setAccess($ownerId, $groupId, 
$visibilty);
+
+                       $created    = $fields['createon'];
+                       $modified   = $fields['modon'];
+                       $lastAccess = '';
+                       $index_xml_item->setTimestamp($created, $modified, 
$lastAccess);
+
+                       return $index_xml_item;
+               }
        }
 ?>




reply via email to

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