Index: inc/class.contacts_sql.inc.php
===================================================================
RCS file: /cvsroot/phpgwapi/phpgwapi/inc/class.contacts_sql.inc.php,v
retrieving revision 1.17.2.2.2.69
diff -u -r1.17.2.2.2.69 class.contacts_sql.inc.php
--- inc/class.contacts_sql.inc.php	1 Sep 2004 13:06:08 -0000	1.17.2.2.2.69
+++ inc/class.contacts_sql.inc.php	26 Nov 2004 13:06:51 -0000
@@ -6,7 +6,7 @@
 	* @license http://www.gnu.org/licenses/gpl.html GNU General Public License
 	* @package phpgwapi
 	* @subpackage contacts
-	* @version $Id: class.contacts_sql.inc.php,v 1.17.2.2.2.69 2004/09/01 13:06:08 fipsfuchs Exp $
+	* @version $Id: class.contacts_sql.inc.php,v 1.17.2.2.2.61.50.22 2004/11/10 14:08:12 aschiller Exp $
 	* @internal Development of this application was funded by http://www.sogrp.com
 	*/
 
@@ -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'];
@@ -2141,8 +2141,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 +2164,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 +2372,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 +2398,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 +2517,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 +2544,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 +2570,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,15 +3807,15 @@
 		*/
 		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]);
 			}
@@ -4127,6 +4144,7 @@
 				echo "</pre>";
 				echo "<br />";
 			}
+			
 		}
 
 		/**
@@ -4144,7 +4162,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 +4179,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 +4201,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 +4260,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 +4300,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;
 				}
 			}
@@ -4298,8 +4319,12 @@
 					$description_id = $this->search_comm_descr($description_input);
 					if(!empty($description_id))
 					{
-						$comm['comm_descr']	= $description_id;
-						$comm['comm_data']	= $comm_input;
+						$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
@@ -4317,13 +4342,51 @@
 			{
 				foreach($fields as $field_name => $field_value)
 				{
-					$other['other_name']	= $field_name;
-					$other['other_value']	= $field_value;
-					$other['other_owner']	= $GLOBALS['phpgw_info']['user']['account_id'];
+					$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 +4470,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
@@ -4425,10 +4488,23 @@
 						else
 							$ret_loc['add_location'][] = true;
 					}
-				}					
-
-				// 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 +4514,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 +4534,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;
 			}
 		}
 	}
Index: inc/class.ipc_.inc.php
===================================================================
RCS file: /cvsroot/phpgwapi/phpgwapi/inc/class.ipc_.inc.php,v
retrieving revision 1.2.2.2
diff -u -r1.2.2.2 class.ipc_.inc.php
--- inc/class.ipc_.inc.php	27 Feb 2004 23:02:05 -0000	1.2.2.2
+++ inc/class.ipc_.inc.php	26 Nov 2004 13:06:51 -0000
@@ -6,7 +6,7 @@
 	* @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License
 	* @package phpgwapi
 	* @subpackage communication
-	* @version $Id: class.ipc_.inc.php,v 1.2.2.2 2004/02/27 23:02:05 ceb Exp $
+	* @version $Id: class.ipc_.inc.php,v 1.2.2.2.52.5 2004/11/24 17:11:07 pkamps Exp $
 	*/
 
 
@@ -18,108 +18,105 @@
 	*/
 	class ipc_
 	{
+		var $debugLevel = 2;
+		
 		/**
 		* Constructor
-		*
 		* @abstract
-		* @access public
 		*/
 		function ipc_()
 		{
 			die('call abstract method: '.__class__.'::'.__function__);
 		}
 
+
 		/**
 		* Add data in a certain mime type format to the application.
-		*
 		* @abstract
-		* @param   mixed    $data  data for adding to the application, the datatype depends on the mime type
-		* @param   string   $type  specifies the mime type of the passed data
-		* @return  integer         id of the added data
+		* @param mixed $data data for adding to the application, the datatype depends on the mime type
+		* @param string $type specifies the mime type of the passed data
+		* @param string $version specifies the mime type version of the passed data
+		* @return integer id of the added data
 		*/
-		function addData($data, $type)
+		function addData($data, $type, $version='')
 		{
 			die('call abstract method: '.__class__.'::'.__function__);
 		}
 
-		/**
-		* Convert data from a mime type to another.
-		*
-		* @abstract
-		* @access  public
-		* @param   mixed    $data     data for converting, the datatype depends on the input mime type
-		* @param   string   $typeIn   specifies the input mime type of the passed data
-		* @param   string   $typeOut  specifies the output mime type of the passed data
-		* @return  mixed              converted data from application, the datatype depends on the passed output mime type
-		*/
-		function convertData($data, $typeIn, $typeOut)
-		{
-			die('call abstract method: '.__class__.'::'.__function__);
-		}
 
 		/**
 		* Checks if data for the passed id exists.
-		*
 		* @abstract
-		* @param   integer  $id  id to check
-		* @return  boolean       true if the data with id exist, otherwise false
+		* @param integer $id id to check
+		* @return boolean true if the data with id exist, otherwise false
 		*/
 		function existData($id)
 		{
 			die('call abstract method: '.__class__.'::'.__function__);
 		}
 
+
 		/**
 		* Get data from the application in a certain mime type format.
-		*
 		* @abstract
-		* @param   integer  $id    id of data to get from the application
-		* @param   string   $type  specifies the mime type of the returned data
-		* @return  mixed           data from application, the datatype depends on the passed mime type, false if no data exists for the passed id
+		* @param integer $id id of data to get from the application
+		* @param string $type specifies the mime type of the returned data
+		* @param string $version specifies the mime type version of the returned data
+		* @return mixed data from application, the datatype depends on the passed mime type, false if no data exists for the passed id
 		*/
-		function getData($id, $type)
+		function getData($id, $type, $version='')
 		{
 			die('call abstract method: '.__class__.'::'.__function__);
 		}
 
+
 		/**
 		* 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.
-		*
 		* @abstract
-		* @param   integer  $lastmod  last modification time, default is -1 and means return all data id's
-		* @return  array              list of 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($time=-1)
+		function getIdList($lastmod=-1, $restriction='')
 		{
 			die('call abstract method: '.__class__.'::'.__function__);
 		}
 
+
 		/**
 		* Remove data of the passed id.
-		*
 		* @abstract
-		* @param   integer  $id  id of data to remove from the application
-		* @return  boolean       true if the data is removed, otherwise false
+		* @param integer $id id of data to remove from the application
+		* @return boolean true if the data is removed, otherwise false
 		*/
 		function removeData($id)
 		{
 			die('call abstract method: '.__class__.'::'.__function__);
 		}
 
+
 		/**
 		* Replace the existing data of the passed id with the passed data in a certain mime type format.
-		*
 		* @abstract
-		* @param   integer  $id    id of data to replace
-		* @param   mixed    $data  the new data, the datatype depends on the passed mime type
-		* @param   string   $type  specifies the mime type of the passed data
-		* @return  boolean         true if the data is replaced, otherwise false
+		* @param integer $id id of data to replace
+		* @param mixed $data the new data, the datatype depends on the passed mime type
+		* @param string $type specifies the mime type of the passed data
+		* @param string $version specifies the mime type version of the passed data (still not supported)
+		* @return boolean true if the data is replaced, otherwise false
 		*/
-		function replaceData($id, $data, $type)
+		function replaceData($id, $data, $type, $version='')
 		{
 			die('call abstract method: '.__class__.'::'.__function__);
 		}
+		
+		function debugLog($string, $level = 0)
+		{
+			if($level <= $this->debugLevel)
+			{
+				error_log($string);
+			}	
+		}
 	}
 ?>
\ No newline at end of file
Index: inc/class.ipc_manager.inc.php
===================================================================
RCS file: /cvsroot/phpgwapi/phpgwapi/inc/class.ipc_manager.inc.php,v
retrieving revision 1.2.2.2
diff -u -r1.2.2.2 class.ipc_manager.inc.php
--- inc/class.ipc_manager.inc.php	27 Feb 2004 23:02:05 -0000	1.2.2.2
+++ inc/class.ipc_manager.inc.php	26 Nov 2004 13:06:51 -0000
@@ -6,191 +6,240 @@
 	* @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License
 	* @package phpgwapi
 	* @subpackage communication
-	* @version $Id: class.ipc_manager.inc.php,v 1.2.2.2 2004/02/27 23:02:05 ceb Exp $
+	* @version $Id: class.ipc_manager.inc.php,v 1.2.2.2.52.6 2004/09/13 09:35:16 dschaller Exp $
 	*/
 
 	/**
 	* Abstract IPC Application class for the IPC Layer
 	*/
-include_class('ipc_');
+	include_class('ipc_');
 
 	/**
 	* Manager of the IPC Layer
 	* @package phpgwapi
 	* @subpackage communication
 	*/
-class ipc_manager
-{
-	/**
-	 * @var array $_ipcObjectList  contains the created ipc application objects
-	 * @access private
-	 */
-	var $_ipcObjectList;
-
-
-  var $xmlrpc_methods;
-  
-	/**
-	 * constructor
-	 */
-	function ipc_manager()
+	class ipc_manager
 	{
-		$this->_ipcObjectList = array();
-		$this->xmlrpc_methods = array();
-		$this->xmlrpc_methods[] = array(
-			'name'        => 'execIPC',
-			'description' => 'Execute an ipc application methode'
-		);
-	}
+		/**
+		* @var array $_ipcObjectList  contains the created ipc application objects
+		* @access private
+		*/
+		var $_ipcObjectList;
+	
+	
+		/**
+		* @var array $xmlrpc_methods  contains information for xmlrpc methods
+		* @access public
+		*/
+	  var $xmlrpc_methods;
+	  
+		/**
+		* constructor
+		*/
+		function ipc_manager()
+		{
+			$this->_ipcObjectList = array();
+			$this->xmlrpc_methods = array();
+			$this->xmlrpc_methods[] = array(
+				'name'        => 'execIPC',
+				'description' => 'Execute an ipc application methode'
+			);
+		}
 
 
-	/**
-	 * Get the ipc application object
-	 *
-	 * @access  public
-	 * @param   string  $appName  name of the application
-	 * @return  object            ipc object of application 
-	 */
-	function &getIPC($appName)
-	{
-		// check if app is available amd the acl run app right
-  	if ($this->_checkIPCApp($appName) == false)
-      return false;
-
-		// create ipc class name
-		$className = $this->_createIPCAppClassName($appName);
-		
-		// check if ipc app object exists
-		if (isset($this->_ipcObjectList[$className]) && is_object($this->_ipcObjectList[$className]))
-		{ // return the existing ipc app object
-			return $this->_ipcObjectList[$className];
-		}
-		else
-		{
-			$obj =& CreateObject($className);
-			if (is_object($obj) == true)
-			{ // save and return the created ipc app object
-				$this->_ipcObjectList[$className] =& $obj;
-				return $this->_ipcObjectList[$className];
+		/**
+		* Get the ipc application object
+		* @param string $appName name of the application
+		* @param bool $checkRun if true check if application is running
+		* @return object ipc object of application 
+		*/
+		function &getIPC($appName, $checkRun=true)
+		{
+			// check if app is available amd the acl run app right
+	  	if ($this->_checkIPCApp($appName, $checkRun) == false)
+	      return false;
+
+			// create ipc class name
+			$className = $this->_createIPCAppClassName($appName);
+
+			// check if ipc app object exists
+			if (isset($this->_ipcObjectList[$className]) && is_object($this->_ipcObjectList[$className]))
+			{ // return the existing ipc app object
+				if(!$this->_setApplicationEnvironment($appName))
+					return false;
+				else
+					return $this->_ipcObjectList[$className];
 			}
 			else
 			{
-			  return false;
+				$obj =& CreateObject($className);
+				if (is_object($obj) == true)
+				{ // save and return the created ipc app object
+					$this->_ipcObjectList[$className] =& $obj;
+					if(!$this->_setApplicationEnvironment($appName))
+						return false;
+					else
+						return $this->_ipcObjectList[$className];
+				}
+				else
+				{
+				  return false;
+				}
 			}
 		}
-	}
 
 
-  /**
-   * Destroy the ipc application object.
-   *
-   * @access  public
-   * @param   string   $appName  name of application
-   * @return  boolean            true when object was destroyed, otherwise false
-   */
-  function destroyIPC($appName)
-  {
-		// create ipc class name
-		$className = $this->_createIPCAppClassName($appName);
-		
-		// check if ipc app object exists
-		if (isset($this->_ipcObjectList[$className]) == true)
-		{ // destroy the ipc app object
-			unset($this->_ipcObjectList[$className]);
-			return true;
-		}
-		else
+		/**
+		* Destroy the ipc application object.
+		* @param string $appName name of application
+		* @return boolean true when object was destroyed, otherwise false
+		*/
+		function destroyIPC($appName)
 		{
-		  return false;
+			// create ipc class name
+			$className = $this->_createIPCAppClassName($appName);
+
+			// check if ipc app object exists
+			if (isset($this->_ipcObjectList[$className]) == true)
+			{ // destroy the ipc app object
+				unset($this->_ipcObjectList[$className]);
+				if(!$this->_setApplicationEnvironment('phpgwapi'))
+					return false;
+				else
+					return true;
+			}
+			else
+			{
+			  return false;
+			}
 		}
-	}
 
 
-  /**
-   * Executes a ipc method.
-   *
-   * @access  public
-   * @param   string  $ipcAppMethod        name of the application and mathod to execute as '<appName>.<methodName>'
-   * @param   array   $ipcAppMethodParams  array with parameters for passing to the called method
-   * @return  mixed                        result of execution
-   */
-	function execIPC($ipcAppMethod, $ipcAppMethodParams=null)
-	{
-		list($ipcApp, $ipcMethod) = explode('.', $ipcAppMethod);
-		$ipc =& $this->getIPC($ipcApp);
-		
-		if (is_object($ipc) == false)
-			return false;
-		
-		if (method_exists($ipc, $ipcMethod) == false)
-			return false;
-
-		$ipcParams = '';
-		for($i=0; $i<count($ipcAppMethodParams); $i++)
-		{
-			if ($i>0)
-				$ipcParams .= ', ';
-			if(is_string($ipcAppMethodParams[$i]) == true)
-				$ipcParams .= '\''.$ipcAppMethodParams[$i].'\'';
-			else {
-				if (is_array($ipcAppMethodParams[$i])) {
-					$arrayconstructor = 'array(';
-					$firstentry = true;
-					foreach($ipcAppMethodParams[$i] as $key => $value) {
-						if ($firstentry) 
-							$firstentry = false;
-						else
-							$arrayconstructor .= ', ';
-						$arrayconstructor .= "$key => $value";
+		/**
+		* Executes a ipc method.
+		* @param string $ipcAppMethod name of the application and mathod to execute as '<appName>.<methodName>'
+		* @param array $ipcAppMethodParams array with parameters for passing to the called method
+		* @return mixed result of execution
+		*/
+		function execIPC($ipcAppMethod, $ipcAppMethodParams=null)
+		{
+			list($ipcApp, $ipcMethod) = explode('.', $ipcAppMethod);
+			$ipc =& $this->getIPC($ipcApp);
+			
+			if (is_object($ipc) == false)
+				return false;
+			
+			if (method_exists($ipc, $ipcMethod) == false)
+				return false;
+	
+			$ipcParams = '';
+			for($i=0; $i<count($ipcAppMethodParams); $i++)
+			{
+				if ($i>0)
+					$ipcParams .= ', ';
+				if(is_string($ipcAppMethodParams[$i]) == true)
+					$ipcParams .= '\''.$ipcAppMethodParams[$i].'\'';
+				else {
+					if (is_array($ipcAppMethodParams[$i])) {
+						$arrayconstructor = 'array(';
+						$firstentry = true;
+						foreach($ipcAppMethodParams[$i] as $key => $value) {
+							if ($firstentry) 
+								$firstentry = false;
+							else
+								$arrayconstructor .= ', ';
+							$arrayconstructor .= "'$key' => '$value'";
+						}
+						$ipcParams .= $arrayconstructor . ')';
 					}
-					$ipcParams .= $arrayconstructor . ')';
+					else
+						$ipcParams .= $ipcAppMethodParams[$i];
 				}
-				else
-					$ipcParams .= $ipcAppMethodParams[$i];
 			}
-		}
-
-		$ipc_cmd = '$ret = $ipc->'.$ipcMethod.'('.$ipcParams.');';
-		eval($ipc_cmd);
-		return $ret;
-	}
+	
+			$ipc_cmd = '$ret = $ipc->'.$ipcMethod.'('.$ipcParams.');';
 
-	/**
-	 * Check if application is available and the acl run application right for the current user.
-	 *
-	 * @access  private
-	 * @param   string   $appName  name of application
-	 * @return  boolean            true if application is available and user has acl run right, otherwise false
-	 */
-	function _checkIPCApp($appName)
-	{
-		// 1: check if app is available
-		if (isset($GLOBALS['phpgw']->applications->data[$appName]) == false)
+      // disabled next line because passwds are submittet as plaintext
+      //error_log("$ipc_cmd");
+      
+			eval($ipc_cmd);
+			return $ret;
+		}
+
+		/**
+		* Check if application is available and the acl run application right for the current user.
+		* @access private
+		* @param string $appName name of application
+		* @return boolean true if application is available and user has acl run right, otherwise false
+		*/
+		function _checkIPCApp($appName, $checkRun=true)
 		{
-			return false;
+			if($appName == 'phpgwapi')
+				return true;
+
+			if($checkRun)
+			{
+				// 1: check if app is available
+				if (isset($GLOBALS['phpgw']->applications->data[$appName]) == false)
+				{
+					return false;
+				}
+
+				// 2: check the acl run app right
+				if ($GLOBALS['phpgw']->acl->check('run', 1, $appName) == false)
+				{
+					return false;
+				}
+			}
+	
+			return true;
 		}
 
-		// 2: check the acl run app right
-		if ($GLOBALS['phpgw']->acl->check('run', 1, $appName) == false)
+
+		/**
+		* Create the name of the ipc application class for the passed application name.
+		* @access private
+		* @param string $appName name of application
+		* @return string name of tne ipc application class
+		*/
+		function _createIPCAppClassName($appName)
 		{
-			return false;
+			return $appName.'.ipc_'.$appName;
 		}
 
-		return true;
-	}
+		/**
+		* Set application environment.
+		* @access private
+		* @param string $appName name of application
+		* @return boolean true if environment set, otherwise false
+		*/
+		function _setApplicationEnvironment($appName)
+		{
+			// current app
+			$GLOBALS['phpgw_info']['flags']['currentapp'] = $appName;
 
+			// app lang data
+			$GLOBALS['phpgw']->translation->add_app($appName);			
+			
+			// app template dir
+			$tpl_root_dir = $GLOBALS['phpgw']->common->get_tpl_dir($appName);
+			if(!$tpl_root_dir)
+			{
+				return false;
+			}
+			else
+			{
+				if(is_object($GLOBALS['phpgw']->template))
+				{
+					if(!$GLOBALS['phpgw']->template->set_root($tpl_root_dir))
+					{
+						return false;
+					}
+				}
+			}
 
-	/**
-	 * Create the name of the ipc application class for the passed application name.
-	 *
-	 * @access  private
-	 * @param   string   $appName  name of application
-	 * @return  string             name of tne ipc application class
-	 */
-	function _createIPCAppClassName($appName)
-	{
-		return $appName.'.ipc_'.$appName;
+			return true;
+		}
 	}
-
-}
 ?>
\ No newline at end of file
Index: inc/class.ipc_phpgwapi.inc.php
===================================================================
RCS file: inc/class.ipc_phpgwapi.inc.php
diff -N inc/class.ipc_phpgwapi.inc.php
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ inc/class.ipc_phpgwapi.inc.php	26 Nov 2004 13:06:51 -0000
@@ -0,0 +1,113 @@
+<?php
+	/**
+	* IPC Layer
+	* @author Dirk Schaller <dschaller@probusiness.de>
+	* @copyright Copyright (C) 2003-2004, Free Software Foundation, Inc. http://www.fsf.org/
+	* @license http://www.fsf.org/licenses/gpl.html GNU General Public License
+	* @package phpgwapi
+	* @subpackage ipc
+	* @version $Id: class.ipc_phpgwapi.inc.php,v 1.1.50.3 2004/05/26 12:31:02 dschaller Exp $
+	*/
+
+	/**
+	* Fassade of phpgwapi.
+	* @package phpgwapi
+	*/
+	class ipc_phpgwapi extends ipc_
+	{
+		var $db;
+
+		function ipc_phpgwapi()
+		{
+			$this->db =& $GLOBALS['phpgw']->db;
+		}
+		
+		function getTableData($tableName, $type, $version='1.0', $fields=array(), $whereclause='')
+		{
+			if($type != 'x-phpgroupware/phpgw-db-dump-array')
+				return false;
+			
+			if(is_array($fields) && (count($fields) > 0))
+				$select = impolode(', ', fields);
+			else
+				$select = '*';
+			
+			$query = 'SELECT '.$select.' FROM '.$tableName;
+
+			if($whereclause != '')
+			{
+				$query .= ' '.$whereclause;
+			}
+			
+			$this->db->query($query, __LINE__, __FILE__);
+			while ($this->db->next_record())
+			{
+				$data = $this->db->Record;
+				if(!$data || (count($data) == 0))
+					continue;
+
+				$tabData = array();
+				while(list($key, $val) = each($data))
+				{
+					if(!is_int($key))
+						$tabData[$key] = $val;
+				}
+
+				if(count($data) == 0)
+					continue;
+				else
+					$tableData[] = $tabData;
+			}
+			return $tableData;
+		}
+		
+		function setTableData($tableName, $data, $type, $version='', $fields=array())
+		{
+			if($type != 'x-phpgroupware/phpgw-db-dump-array')
+				return false;
+
+			$truncate_table = 'TRUNCATE TABLE '.$tableName;
+			$this->db->query($truncate_table, __LINE__, __FILE__);
+			if($GLOBALS['phpgw']->db->Error)
+				return false;
+
+			while(list($no_use, $record) = each($data))
+			{
+				$insert_cols = array();
+				$insert_vals = array();
+
+				if(is_array($fields) && (count($fields) > 0))
+				{
+					while(list($no_use, $col) = each($fields))
+					{
+						if(array_key_exists($col, $record))
+						{
+							$insert_cols[] = ''.$col.'';
+							$insert_vals[] = '\''.$record[$col].'\'';
+						}
+					}
+				}
+				else
+				{
+					while(list($col, $val) = each($record))
+					{
+						$insert_cols[] = ''.$col.'';
+						$insert_vals[] = '\''.$val.'\'';
+					}
+				}
+
+				$insert_col_str = '('.implode(', ', $insert_cols).')';
+				$insert_val_str = '('.implode(', ', $insert_vals).')';
+
+				$insert = 'INSERT INTO '.$tableName.' '.$insert_col_str.' VALUES '.$insert_val_str;
+				$this->db->query($insert, __LINE__, __FILE__);
+
+				if($GLOBALS['phpgw']->db->Error)
+					return false;
+			}
+
+			return true;
+		}
+
+	}
+?>
