phpgroupware-cvs
[Top][All Lists]
Advanced

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

[Phpgroupware-cvs] phpgwapi/inc/class.contacts_sql.inc.php, 1.17.2.2.2.7


From: nomail
Subject: [Phpgroupware-cvs] phpgwapi/inc/class.contacts_sql.inc.php, 1.17.2.2.2.71
Date: Tue, 16 Nov 2004 22:35:21 +0100

Update of /phpgwapi/inc
Modified Files:
        Branch: Version-0_9_16-branch
          class.contacts_sql.inc.php

date: 2004/11/16 21:35:21;  author: alexbsa;  state: Exp;  lines: +155 -46

Log Message:
AHA! Finally!
Fixes 10371 - 10766
=====================================================================
Index: phpgwapi/inc/class.contacts_sql.inc.php
diff -u phpgwapi/inc/class.contacts_sql.inc.php:1.17.2.2.2.70 
phpgwapi/inc/class.contacts_sql.inc.php:1.17.2.2.2.71
--- phpgwapi/inc/class.contacts_sql.inc.php:1.17.2.2.2.70       Sat Nov  6 
15:34:26 2004
+++ phpgwapi/inc/class.contacts_sql.inc.php     Tue Nov 16 21:35:21 2004
@@ -474,8 +474,8 @@
                                                'per_initials',
                                                'per_sound',
                                                'per_active',
-                                               'per_createon',
-                                               'per_createby',
+                                               'per_creaton',
+                                               'per_creatby',
                                                'per_modby',
                                                'per_modon',
                                                'key_addr_id',
@@ -964,7 +964,7 @@
                */
                function delete_single_extra_field($id,$field_name)
                {
-                       $this->delete_others($cid);
+                       $this->delete_others($cid, PHPGW_SQL_RUN_SQL);
                        return array();
                }
 
@@ -1774,7 +1774,7 @@
                        $addr_keys = array('work', 'home', 'other', 'other', 
'other', 'other');
 
                        list($kind, $key, $name) = explode('_', $field, 3);
-                       echo "$kind : $key : $name<br />\n";
+                       //echo "$kind : $key : $name<br />\n";
                        switch ($kind)
                        {
                        case 'addr':
@@ -1862,8 +1862,8 @@
                                $contact['initials']            = 
$record['per_initials'];
                                $contact['sound']               = 
$record['per_sound'];
                                $contact['active']              = 
$record['per_active'];
-                               $contact['createon']            = 
$record['per_createon'];
-                               $contact['createby']            = 
$record['per_createby'];
+                               $contact['createon']            = 
$record['per_creaton'];
+                               $contact['createby']            = 
$record['per_creatby'];
                                $contact['modby']               = 
$record['per_modby'];
                                $contact['modon']               = 
$record['per_modon'];
                                $contact['account_id']          = 
$record['account_id'];
@@ -2110,6 +2110,28 @@
                }
 
                /**
+               * Allow edit all location information of an contact
+               * 
+               * @param integer $contact_id Contact Id that want to be edited.
+               * @param array $data Information for contact
+               * @param integer $action PHPGW_SQL_RETURN_SQL | 
PHPGW_SQL_RUN_SQL depending what we want
+               * @return string SQL update string
+               */
+               function edit_location_by_contact($contact_id, $data, 
$action=PHPGW_SQL_RETURN_SQL)
+               {
+                       $loc = CreateObject('phpgwapi.contact_addr');
+                       if(!isset($data['addr_modon']))
+                       {
+                               $data['addr_modon'] = $this->get_mkdate();
+                       }
+                       if(!isset($data['addr_modby']))
+                       {
+                               $data['addr_modby'] = $this->get_user_id();
+                       }
+                       return $loc->update($data, 
sql_criteria::_equal('contact_id',sql::integer($contact_id)), $action);
+               }
+
+               /**
                * Allow edit communication information of an contact
                * 
                * @param integer $id Contact comm Id that want to be edited.
@@ -2141,8 +2163,16 @@
                */
                function edit_other($id, $data, $action=PHPGW_SQL_RETURN_SQL)
                {
-                       $comm = CreateObject('phpgwapi.contact_others');
-                       return $comm->update($data, 
sql_criteria::_equal('other_id',sql::integer($id)), $action);
+                       $other = CreateObject('phpgwapi.contact_others');
+                       if(!isset($data['other_modon']))
+                       {
+                               $data['other_modon'] = $this->get_mkdate();
+                       }
+                       if(!isset($data['other_modby']))
+                       {
+                               $data['other_modby'] = $this->get_user_id();
+                       }
+                       return $other->update($data, 
sql_criteria::_equal('other_id',sql::integer($id)), $action);
                }
 
                /**
@@ -2156,6 +2186,14 @@
                function edit_comms_by_contact($id, $data, 
$action=PHPGW_SQL_RETURN_SQL)
                {
                        $comm = CreateObject('phpgwapi.contact_comm');
+                       if(!isset($data['comm_modon']))
+                       {
+                               $data['comm_modon'] = $this->get_mkdate();
+                       }
+                       if(!isset($data['comm_modby']))
+                       {
+                               $data['comm_modby'] = $this->get_user_id();
+                       }
                        return $comm->update($data, 
sql_criteria::_equal('contact_id',sql::integer($id)), $action);
                }
 
@@ -2356,9 +2394,9 @@
                                $this->lock_table($this->org->table);
                        }
                        $this->lock_table($this->org->table);
-                       $principal['org_creaton'] = $this->get_mkdate();
+                       $principal['org_creaton'] = 
(isset($principal['org_creaton'])?$principal['org_creaton']:$this->get_mkdate());
                        $principal['org_creatby'] = $this->get_user_id();
-                       $principal['org_modon'] = $this->get_mkdate();
+                       $principal['org_modon'] = 
(isset($principal['org_modon'])?$principal['org_modon']:$this->get_mkdate());
                        $principal['org_modby'] = $this->get_user_id();
 
                        $execute = $this->_add($principal,'org','org_id',$cid, 
$action);
@@ -2382,9 +2420,9 @@
                                $this->lock_table($this->person->table);
                        }
                        $this->lock_table($this->person->table);
-                       $principal['per_creaton'] = $this->get_mkdate();
+                       $principal['per_creaton'] = 
(isset($principal['per_creaton'])?$principal['per_creaton']:$this->get_mkdate());
                        $principal['per_creatby'] = $this->get_user_id();
-                       $principal['per_modon'] = $this->get_mkdate();
+                       $principal['per_modon'] = 
(isset($principal['per_modon'])?$principal['per_modon']:$this->get_mkdate());;
                        $principal['per_modby'] = $this->get_user_id();
 
                        $execute = 
$this->_add($principal,'person','person_id',$cid, $action);
@@ -2501,10 +2539,11 @@
                        {
                                $location['addr_preferred'] = 'N';
                        }
+
+                       $location['addr_creaton'] = 
(isset($location['addr_creaton'])?$location['addr_creaton']:$this->get_mkdate());
                        $location['addr_creatby'] = $this->get_user_id();
+                       $location['addr_modon'] = 
(isset($location['addr_modon'])?$location['addr_modon']:$this->get_mkdate());;
                        $location['addr_modby'] = $this->get_user_id();
-                       $location['addr_creaton'] = $this->get_mkdate();
-                       $location['addr_modon'] = $this->get_mkdate();
 
                        unset($location['key_addr_id']);
 
@@ -2527,10 +2566,10 @@
                                $this->lock_table($this->comm->table);
                        }
 
+                       $comm['comm_creaton'] = 
(isset($comm['comm_creaton'])?$comm['comm_creaton']:$this->get_mkdate());
                        $comm['comm_creatby'] = $this->get_user_id();
+                       $comm['comm_modon'] = 
(isset($comm['comm_modon'])?$comm['comm_modon']:$this->get_mkdate());;
                        $comm['comm_modby'] = $this->get_user_id();
-                       $comm['comm_creaton'] = $this->get_mkdate();
-                       $comm['comm_modon'] = $this->get_mkdate();
 
                        unset($comm['key_comm_id']);
 
@@ -2553,10 +2592,10 @@
                                $this->lock_table($this->note->table);
                        }
 
+                       $note['note_creaton'] = 
(isset($note['note_creaton'])?$note['note_creaton']:$this->get_mkdate());
                        $note['note_creatby'] = $this->get_user_id();
+                       $note['note_modon'] = 
(isset($note['note_modon'])?$note['note_modon']:$this->get_mkdate());;
                        $note['note_modby'] = $this->get_user_id();
-                       $note['note_creaton'] = $this->get_mkdate();
-                       $note['note_modon'] = $this->get_mkdate();
 
                        unset($comm['key_note_id']);
 
@@ -3790,18 +3829,22 @@
                */
                function display_name($field)
                {
-                       if($this->contact_fields['showable'])
+                       if($this->contact_fields['showable'][$field])
                        {
                                return 
$GLOBALS['phpgw']->lang($this->contact_fields['showable'][$field]);
                        }
-                       if($this->contact_fields['retreivable'])
+                       if($this->contact_fields['retreivable'][$field])
                        {
                                return 
$GLOBALS['phpgw']->lang($this->contact_fields['retrievable'][$field]);
                        }
-                       if($this->contact_fields['catalogs'])
+                       if($this->contact_fields['catalogs'][$field])
                        {
                                return 
$GLOBALS['phpgw']->lang($this->contact_fields['catalogs'][$field]);
                        }
+                       else
+                       {
+                               return $field;
+                       }
                }
 
                /**
@@ -4018,6 +4061,7 @@
                        $attributes['objectClass'][] = 'inetOrgPerson';
                        $attributes['cn'][]          = 
utf8_encode($person[0]['per_full_name']) ? 
utf8_encode($person[0]['per_full_name']) : ' ';
                        $attributes['sn'][]          = 
utf8_encode($person[0]['per_last_name']) ? 
utf8_encode($person[0]['per_last_name']) : ' ';
+
                        /* Optional attributes */
                        $attributes['uid'][]         = utf8_encode($uid);
                        if($person[0]['org_name'])
@@ -4144,7 +4188,7 @@
                        if((isset($fields['first_name']) && 
!isset($fields['org_name'])) || $type)
                        {
                                $contact['contact_id']        = 
isset($fields['contact_id'])        ? $fields['contact_id']        : '';
-                               $contact['access']            = 
isset($fields['access'])            ? $fields['access']            : '';
+                               $contact['access']            = 
isset($fields['access'])            ? $fields['access']            : 'private';
                                $contact['owner']             = 
isset($fields['owner'])             ? $fields['owner']             : 
$GLOBALS['phpgw_info']['user']['account_id'];
                                $contact['per_first_name']    = 
isset($fields['first_name'])        ? $fields['first_name']        : '';
                                $contact['per_last_name']     = 
isset($fields['last_name'])         ? $fields['last_name']         : '';
@@ -4161,17 +4205,8 @@
                                $contact['preferred_org']     = 
isset($fields['preferred_org'])     ? $fields['preferred_org']     : '';
                                $contact['preferred_address'] = 
isset($fields['preferred_address']) ? $fields['preferred_address'] : '';
                                $contact['relations']         = 
isset($fields['organizations'])     ? $fields['organizations']     : array();
-
-                               if ($contact['preferred_org'] != '')
-                               {
-                                       $this->request(array('contact_id'));
-                                       $this->criteria(array('org_name' => 
$contact['preferred_org']));
-                                       $result = 
$this->get_query(PHPGW_SQL_RUN_SQL, __LINE__, __FILE__);
-                                       if ($result && isset($result[0]))
-                                       {
-                                               $contact['relations'][] = 
$result[0]['contact_id'];
-                                       }
-                               }
+                               $contact['per_creaton']       = 
isset($fields['createon'])          ? $fields['createon']          : null;
+                               $contact['per_modon']         = 
isset($fields['modon'])             ? $fields['modon']             : null;
 
                                unset(  $fields['contact_id'],
                                        $fields['first_name'],
@@ -4192,27 +4227,30 @@
                                        $fields['access'],
                                        $fields['full_name'],
                                        $fields['owner'],
-                                       $fields['createon'],
-                                       $fields['createby'],
-                                       $fields['modon'],
-                                       $fields['modby'],
                                        $fields['account_id'],
                                        $fields['org_name']);
                        }
                        else
                        {
+                               $contact['access']     = 
isset($fields['access'])   ? $fields['access']   : 'private';
+                               $contact['owner']      = 
isset($fields['owner'])    ? $fields['owner']    : 
$GLOBALS['phpgw_info']['user']['account_id'];
                                $contact['org_name']   = 
isset($fields['org_name']) ? $fields['org_name'] : '';
                                $contact['org_active'] = 
isset($fields['active'])   ? $fields['active']   : '';
                                $contact['org_parent'] = 
isset($fields['parent'])   ? $fields['parent']   : '';
                                $contact['relations']  = 
isset($fields['people'])   ? $fields['people']   : '';
+                               $contact['org_creaton']= 
isset($fields['createon']) ? $fields['createon'] : null;
+                               $contact['org_creatby']= 
isset($fields['createby']) ? $fields['createby'] : null;
+                               $contact['org_modon']  = 
isset($fields['modon'])    ? $fields['modon']    : null;
+                               $contact['org_modby']  = 
isset($fields['modby'])    ? $fields['modby']    : null;
 
                                unset(  $fields['org_name'],
                                        $fields['active'],
                                        $fields['parent'],
-                                       $fields['people']);
+                                       $fields['people']
+                               );
                        }
 
-                       $contact['categories'] = isset($fields['categories']) ? 
$fields['categories'] : '';
+                       $contact['cat_id'] = isset($fields['categories']) ? 
$fields['categories'] : '';
                        unset($fields['categories'], $fields['access']);
 
                        // Locations info
@@ -4248,6 +4286,10 @@
                                        $location['addr_postal_code'] = 
isset($location_input['postal_code']) ? $location_input['postal_code'] : '';
                                        $location['addr_country']     = 
isset($location_input['country'])     ? $location_input['country']     : '';
                                        $location['addr_preferred']   = 
isset($location_input['preferred'])   ? $location_input['preferred']   : '';
+                                       $location['addr_createon']   = 
isset($fields['createon'])   ? $fields['createon']   : '';
+                                       $location['addr_createby']   = 
isset($fields['createby'])   ? $fields['createby']   : '';
+                                       $location['addr_modon']      = 
isset($fields['modon'])      ? $fields['modon']      : '';
+                                       $location['addr_modby']      = 
isset($fields['modby'])      ? $fields['modby']      : '';
                                        $locations[] = $location;
                                }
                        }
@@ -4284,6 +4326,11 @@
                                                }
                                        }
                                        $note['note_text'] = 
$note_input['note'];
+                                       $note['note_createon'] = 
isset($fields['createon'])   ? $fields['createon']   : '';
+                                       $note['note_createby'] = 
isset($fields['createby'])   ? $fields['createby']   : '';
+                                       $note['note_modon']    = 
isset($fields['modon'])      ? $fields['modon']      : '';
+                                       $note['note_modby']    = 
isset($fields['modby'])      ? $fields['modby']      : '';
+
                                        $notes[] = $note;
                                }
                        }
@@ -4300,6 +4347,10 @@
                                        {
                                                $comm['comm_descr']     = 
$description_id;
                                                $comm['comm_data']      = 
$comm_input;
+                                               $comm['comm_createon'] = 
isset($fields['createon'])   ? $fields['createon']   : '';
+                                               $comm['comm_createby'] = 
isset($fields['createby'])   ? $fields['createby']   : '';
+                                               $comm['comm_modon']    = 
isset($fields['modon'])      ? $fields['modon']      : '';
+                                               $comm['comm_modby']    = 
isset($fields['modby'])      ? $fields['modby']      : '';
                                                $comm_media[]           = $comm;
                                        }
                                        else
@@ -4320,10 +4371,48 @@
                                        $other['other_name']    = $field_name;
                                        $other['other_value']   = $field_value;
                                        $other['other_owner']   = 
$GLOBALS['phpgw_info']['user']['account_id'];
+                                       $other['other_createon'] = 
isset($fields['createon'])   ? $fields['createon']   : '';
+                                       $other['other_createby'] = 
isset($fields['createby'])   ? $fields['createby']   : '';
+                                       $other['other_modon']    = 
isset($fields['modon'])      ? $fields['modon']      : '';
+                                       $other['other_modby']    = 
isset($fields['modby'])      ? $fields['modby']      : '';
                                        $others[]               = $other;
                                }
                        }
 
+
+                       if($contact['preferred_org'] != '')
+                       {
+                               $this->criteria(array('org_name' => 
$contact['preferred_org'],
+                                                     'owner' => 
$GLOBALS['phpgw_info']['user']['account_id']));
+                               $records = $this->get_orgs(array('contact_id'));
+
+                               if(is_array($records))
+                               {
+                                       foreach($records as $org)
+                                       {
+                                               $contact['relations'][] = 
$org['contact_id'];
+                                       }
+                               }
+                               else
+                               {
+                                       $principal['access']   = 
$contact['access'];
+                                       $principal['owner']    = 
$contact['owner'];
+                                       $principal['org_name'] = 
$contact['preferred_org'];
+
+                                       $principal['org_creaton'] = 
isset($fields['createon'])   ? $fields['createon']   : '';
+                                       $principal['org_creatby'] = 
isset($fields['createby'])   ? $fields['createby']   : '';
+                                       $principal['org_modon']   = 
isset($fields['modon'])      ? $fields['modon']      : '';
+                                       $principal['org_modby']   = 
isset($fields['modby'])      ? $fields['modby']      : '';
+                               }
+                       }
+
+                       unset(
+                               $fields['createon'],
+                               $fields['createby'],
+                               $fields['modon'],
+                               $fields['modby']
+                       );
+
                        if (($update == true) && (isset($contact['contact_id']) 
== true))
                        {
                                $cid = $contact['contact_id'];
@@ -4407,7 +4496,7 @@
                                if(is_array($old_locations) && 
(count($old_locations) > 0))
                                {
                                        // 1. delete old locs
-                                       $this->delete_locations($cid);
+                                       $this->delete_locations($cid, 
PHPGW_SQL_RUN_SQL);
                                        if ($GLOBALS['phpgw']->db->Error)
                                                $ret_loc['delete_locations'] = 
false;
                                        else
@@ -4427,8 +4516,21 @@
                                        }
                                }                                       
 
-                               // todo: updare $contact['relations'] ???
-
+                               // update organizations data (delete old and 
add new org)
+                               $this->delete_orgs_by_person($cid, 
PHPGW_SQL_RUN_SQL);
+                               if($contact['preferred_org'])
+                               {
+                                       if(isset($principal))
+                                       { // new org
+                                               $type_org = 
$this->search_contact_type($this->_contact_org);
+                                               $contact_relations[] = $cid;
+                                               $this->add_contact($type_org, 
$principal, array(), array(), $contact['cat_id'], array(), $contact_relations, 
array());
+                                       }
+                                       else
+                                       {
+                                               
$this->add_orgs_for_person($contact['relations'], $contact['preferred_org'], 
$contact['preferred_address'], $cid, PHPGW_SQL_RUN_SQL);
+                                       }
+                               }
 
                                // update other data (delete old and add new 
others)
                                $ret_other = array();
@@ -4438,7 +4540,7 @@
                                {
                                        $ret['other'] = $old_others;
                                        // 1. delete old others
-                                       $this->delete_others($cid);
+                                       $this->delete_others($cid, 
PHPGW_SQL_RUN_SQL);
                                        if ($GLOBALS['phpgw']->db->Error)
                                                $ret_other['delete_others'] = 
false;
                                        else
@@ -4458,11 +4560,18 @@
                                        }
                                }                                       
 
-                               return $ret;
+                               return true; //$ret;
                        }
                        else
                        {
-                               return $this->add_contact($type, $contact, 
$comm_media, $locations, $contact['categories'], $others, 
$contact['relations'], $notes);
+                               $cid = $this->add_contact($type, $contact, 
$comm_media, $locations, $contact['cat_id'], $others, $contact['relations'], 
$notes);
+                               if(isset($principal))
+                               {
+                                       $type_org = 
$this->search_contact_type($this->_contact_org);
+                                       $contact_relations[] = $cid;
+                                       $this->add_contact($type_org, 
$principal, array(), array(), $contact['cat_id'], array(), $contact_relations, 
array());
+                               }
+                               return $cid;
                        }
                }
        }




reply via email to

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