[21195] Improvement: add organisation as datatype 4746:5203

Sigurd Nes <[email protected]> Wed, 14 Apr 2010 19:26:00 +0000
Newsgroups gmane.comp.web.phpgroupware.cvs
Message-ID <[email protected]>
Revision: 21195
          http://svn.sv.gnu.org/viewvc/?view=rev&root=phpgroupware&revision=21195
Author:   sigurdne
Date:     2010-04-14 19:26:00 +0000 (Wed, 14 Apr 2010)
Log Message:
-----------
Improvement: add organisation as datatype 4746:5203

Modified Paths:
--------------
    people/sigurdne/modules/phpgwapi/trunk/inc/class.custom_fields.inc.php

Modified: people/sigurdne/modules/phpgwapi/trunk/inc/class.custom_fields.inc.php
===================================================================
--- people/sigurdne/modules/phpgwapi/trunk/inc/class.custom_fields.inc.php	2010-04-14 19:23:52 UTC (rev 21194)
+++ people/sigurdne/modules/phpgwapi/trunk/inc/class.custom_fields.inc.php	2010-04-14 19:26:00 UTC (rev 21195)
@@ -1,16 +1,16 @@
 <?php
 	/**
-	* phpGroupWare custom fields
-	*
-	* @author Sigurd Nes <[email protected]>
-	* @author Dave Hall dave.hall at skwashd.com
-	* @copyright Copyright (C) 2003-2006 Free Software Foundation http://www.fsf.org/
+	 * phpGroupWare custom fields
+	 *
+	 * @author Sigurd Nes <[email protected]>
+	 * @author Dave Hall dave.hall at skwashd.com
+	 * @copyright Copyright (C) 2003-2006 Free Software Foundation http://www.fsf.org/
 	 * @license http://www.gnu.org/licenses/gpl.html GNU General Public License v2 or later
-	* @internal Development of this application was funded by http://www.bergen.kommune.no/bbb_/ekstern/
+	 * @internal Development of this application was funded by http://www.bergen.kommune.no/bbb_/ekstern/
 	 * @package phpgroupware
 	 * @subpackage phpgwapi
 	 * @version $Id$
-	*/
+	 */
 
 	/*
 	   This program is free software: you can redistribute it and/or modify
@@ -43,14 +43,14 @@
 		
 		/**
 		* @var array $receipt messages from the prosessing of functions
-		 */
+		*/
 		public $receipt = array();
 		
 		/**
 		* @var array $datatype_text the translated end user field types
-		 */
+		*/
 		public $datatype_text = array();
-		
+
 		/**
 		 * @var string $_appname the name of the current application
 		 */
@@ -63,7 +63,7 @@
 
 		/**
 		 * @var string $_join SQL JOIN statement
-		*/
+		 */
 		protected $_join;
 
 		/**
@@ -109,7 +109,8 @@
 				'R'		=> lang('Muliple radio'),
 				'CH'	=> lang('Muliple checkbox'),
 				'LB'	=> lang('Listbox'),
-				'AB'	=> lang('Contact'),
+				'AB'	=> lang('Contact'),// Addressbook person
+				'ABO'	=> lang('Organisation'),// Addressbook organisation
 				'VENDOR'=> lang('Vendor'),
 				'email'	=> lang('Email'),
 				'link'	=> lang('Link'),
@@ -174,7 +175,7 @@
 			unset($group);
 
 			$this->_db->transaction_begin();
-			
+
 			$sql = "SELECT id FROM phpgw_cust_attribute_group"
 				. " WHERE location_id = {$values['location_id']}"
 					. " AND name = '{$values['name']}'";
@@ -203,9 +204,9 @@
 			$receipt['id'] = $values['id'];
 
 			if ( $this->_db->transaction_commit() )
-				{
+			{
 				return $values['id'];
-				}
+			}
 
 			return 0;
 		}
@@ -301,12 +302,13 @@
 				case 'CH':
 				case 'LB':
 				case 'AB':
+				case 'ABO':
 				case 'VENDOR':
 				case 'event':
 					if ( $attrib['history'] )
-				{
+					{
 						$receipt['error'][] = array('msg' => lang('History not allowed for this datatype'));
-				}
+					}
 					$values['history'] = false;
 					break;
 
@@ -353,15 +355,15 @@
 			unset($cols, $vals);
 
 			$receipt['id'] = $values['id'];
-			
+
 			if ( !$values['precision_'] > 0)
 			{
 				$precision = $this->_translate_datatype_precision($values['datatype']);
 				if ( $precision )
-			{
+				{
 					$values['precision_'] = $precision;
+				}
 			}
-			}
 
 			$col_info = array
 			(
@@ -378,7 +380,7 @@
 				{
 					unset($col_info['default']);
 				}
-				}
+			}
 
 			$this->_oProc->AddColumn($attrib_table, $values['column_name'], $col_info);
 
@@ -392,7 +394,7 @@
 
 		/**
 		 * Prepare an attribute value so it can be saved in the database
-		 * 
+		 *
 		 * @param array $values_attribute an attribute structure
 		 *
 		 * @return array the structure with the value prepared
@@ -411,7 +413,7 @@
 				if ( !$attrib['value'] )
 				{
 					continue;
-			}
+				}
 
 				switch ( $attrib['datatype'] )
 				{
@@ -484,7 +486,7 @@
 		 * @param string $appname where to delete the attrib
 		 * @param integer $attrib_id id of attrib to delete
 		 * @param bool $doubled sometimes the attribute fits into a history-table as a double
-		 * 
+		 *
 		 * @return boolean was the record deleted?
 		 */
 		public function delete($appname, $location, $attrib_id, $table = '',$doubled = false )
@@ -493,7 +495,7 @@
 			$attrib_id	= (int) $attrib_id;
 
 			if(!$table)
-		{
+			{
 				$table	= $GLOBALS['phpgw']->locations->get_attrib_table($appname, $location);
 			}
 
@@ -533,7 +535,7 @@
 				$max_sort	= $this->_db->f('max_sort');
 			
 				if ( $max_sort > $attrib_sort )
-			{
+				{
 					$sql = "UPDATE phpgw_cust_attribute SET attrib_sort = attrib_sort - 1"
 						. " WHERE location_id = {$loc_id} AND attrib_sort > {$attrib_sort} AND group_id = {$group_id}";
 					$this->_db->query($sql, __LINE__, __FILE__);
@@ -541,7 +543,7 @@
 				$sql = "DELETE FROM phpgw_cust_attribute"
 						. " WHERE location_id = {$loc_id} AND id = {$attrib_id}";
 				$this->_db->query($sql, __LINE__,__FILE__);
-			}
+			}	
 			return $this->_db->transaction_commit();
 		}
 
@@ -574,14 +576,14 @@
 			if ( $this->_db->transaction_commit() )
 			{
 				return $group_id;
-		}
-		
+			}
+
 			return false;
 		}
 		/**
 		 * Edit a custom field
 		 * 
-		 * @param array $attrib the field data
+		 * @param array  $attrib       the field data
 		 * @param string $attrib_table which table the attribute is part of
 		 * @param bool $doubled sometimes the attribute fits into a history-table as a double
 		 *
@@ -595,7 +597,7 @@
 			$attrib['history'] = isset($attrib['history']) ? !!$attrib['history'] : false;
 			$attrib['lookup_form'] = isset($attrib['lookup_form']) ? !!$attrib['lookup_form'] : false;
 			$attrib['group_id']		= (int) $attrib['group_id'];
-			
+
 			if(!$attrib_table)
 			{
 				$attrib_table = $GLOBALS['phpgw']->locations->get_attrib_table($attrib['appname'],$attrib['location']);
@@ -616,13 +618,14 @@
 				case 'CH':
 				case 'LB':
 				case 'AB':
+				case 'ABO':
 				case 'VENDOR':
 				case 'event':
 					if ( $attrib['history'] )
-				{
+					{
 						$this->receipt['error'][] = array('msg'	=> lang('History not allowed for this datatype'));
-				}
-				$attrib['history'] = false;
+					}
+					$attrib['history'] = false;
 					break;
 
 				default: // all is good
@@ -641,26 +644,26 @@
 			$OldDataType		= $this->_db->f('datatype');
 			$OldPrecision		= $this->_db->f('precision_');
 			$OldGroup			= (int) $this->_db->f('group_id');			
-			
+
 			$table_def = $this->get_table_def($attrib_table);	
 
 			$this->_db->transaction_begin();
 
 			if( !$doubled )
 			{
-			$value_set = array
-			(
-				'input_text'	=> $attrib['input_text'],
-				'statustext'	=> $attrib['statustext'],
-				'search'		=> isset($attrib['search']) ? $attrib['search'] : '',
-				'list'			=> isset($attrib['list']) ? $attrib['list'] : '',
-				'history'		=> isset($attrib['history']) ? $attrib['history'] : '',
-				'nullable'		=> $attrib['column_info']['nullable'] == 'False' ? 'False' : 'True',
-				'disabled'		=> isset($attrib['disabled']) ? $attrib['disabled'] : '',
-				'helpmsg'		=> $attrib['helpmsg'],
+				$value_set = array
+				(
+					'input_text'	=> $attrib['input_text'],
+					'statustext'	=> $attrib['statustext'],
+					'search'		=> isset($attrib['search']) ? $attrib['search'] : '',
+					'list'			=> isset($attrib['list']) ? $attrib['list'] : '',
+					'history'		=> isset($attrib['history']) ? $attrib['history'] : '',
+					'nullable'		=> $attrib['column_info']['nullable'] == 'False' ? 'False' : 'True',
+					'disabled'		=> isset($attrib['disabled']) ? $attrib['disabled'] : '',
+					'helpmsg'		=> $attrib['helpmsg'],
 					'lookup_form'	=> isset($attrib['lookup_form']) ? $attrib['lookup_form'] : '',
 					'group_id'		=> $attrib['group_id']
-			);
+				);
 
 				if($OldGroup != $attrib['group_id'])
 				{
@@ -684,7 +687,7 @@
 					$this->_db->query($sql, __LINE__, __FILE__);
 					$this->_db->next_record();
 					$max_sort	= $this->_db->f('max_sort');
-
+			
 					if ( $max_sort > $attrib_sort )
 					{
 						$sql = "UPDATE phpgw_cust_attribute SET attrib_sort = attrib_sort - 1"
@@ -774,20 +777,51 @@
 			if(isset($attrib['new_choice']) && $attrib['new_choice'] && !$doubled )
 			{
 				$choice_id = $this->_next_id('phpgw_cust_choice' ,array('location_id'=> $location_id, 'attrib_id'=>$attrib_id));
+				$choice_sort = $choice_id;
 
 				$values= array(
 					$location_id,
 					$attrib_id,
 					$choice_id,
+					$choice_sort,
 					$attrib['new_choice']
 					);
 
 				$values	= $this->_db->validate_insert($values);
 
-				$this->_db->query("INSERT INTO phpgw_cust_choice (location_id, attrib_id, id, value) "
+				$this->_db->query("INSERT INTO phpgw_cust_choice (location_id, attrib_id, id,choice_sort, value) "
 				. "VALUES ($values)",__LINE__,__FILE__);
 			}
 
+
+			if ( count($attrib['edit_choice'])  && !$doubled )
+			{
+				foreach ($attrib['edit_choice'] as $choice_id => $value)
+				{
+					$choice_id = (int) $choice_id;
+					$value = $this->_db->db_addslashes($value);
+					$sql = "UPDATE phpgw_cust_choice SET value = '{$value}'"
+						. " WHERE location_id = {$location_id}"
+							. " AND attrib_id = {$attrib_id}"
+							. " AND id = {$choice_id}";
+					$this->_db->query($sql, __LINE__, __FILE__);
+				}
+			}
+
+			if ( count($attrib['order_choice'])  && !$doubled )
+			{
+				foreach ($attrib['order_choice'] as $choice_id => $order)
+				{
+					$choice_id = (int) $choice_id;
+					$order = (int) $order;
+					$sql = "UPDATE phpgw_cust_choice SET choice_sort = {$order}"
+						. " WHERE location_id = {$location_id}"
+							. " AND attrib_id = {$attrib_id}"
+							. " AND id = {$choice_id}";
+					$this->_db->query($sql, __LINE__, __FILE__);
+				}
+			}
+
 			if ( count($attrib['delete_choice'])  && !$doubled )
 			{
 				foreach ($attrib['delete_choice'] as $choice_id)
@@ -813,8 +847,8 @@
 		/**
 		 * Get a list of attributes
 		 * 
-		 * @param string $appname the name of the application
-		 * @param string $location the name of the location
+		 * @param string $appname      the name of the application
+		 * @param string $location     the name of the location
 		 * @param integer $start
 		 * @param string query         
 		 * @param string $sort         
@@ -829,10 +863,10 @@
 				$order = 'attrib_sort', $allrows = false, $inc_choices = false, $filter = array())
 		{
 			$location_id	= $GLOBALS['phpgw']->locations->get_id($appname, $location);
-			$start		= (int) $start;
+			$start			= (int) $start;
 			$query			= $this->_db->db_addslashes($query);
 			$order			= $this->_db->db_addslashes($order);
-			$allrows	= !!$allrows;
+			$allrows		= !!$allrows;
 
 			
 			$filtermethod	= '';
@@ -840,7 +874,7 @@
 			{
 				$condition = array();
 				foreach ($filter as $column => $value)
-			{
+				{
 					if($value)
 					{
 						$condition[] = "$column = '{$value}'";
@@ -849,10 +883,10 @@
 					{
 						$condition[] = "$column IS NULL";					
 					}
-			}
+				}
 
 				if( $condition )
-			{
+				{
 					$filtermethod = 'AND ' . implode(" AND ", $condition);
 				}
 
@@ -862,7 +896,7 @@
 			if ( $order )
 			{
 				if ( $sort == 'DESC')
-			{
+				{
 					$sort = 'DESC';
 				}
 
@@ -953,7 +987,7 @@
 		}
 		/**
 		 * Get a list of groups availlable for attributes within a location
-		*
+		 * 
 		 * @param string $appname      the name of the application
 		 * @param string $location     the name of the location
 		 * @param ?????? $start        ask sigurd
@@ -961,12 +995,12 @@
 		 * @param ?????? $sort         ask sigurd
 		 * @param ?????? $order        ask sigurd
 		 * @param ?????? $allrows      ask sigurd
-		*
+		 *
 		 * @return ???? something
-		*/
+		 */
 		public function find_group($appname, $location, $start = 0, $query = '', $sort = 'ASC', 
 				$order = 'group_sort', $allrows = false)
-			{
+		{
 			$location_id	= $GLOBALS['phpgw']->locations->get_id($appname, $location);
 			$start			= (int) $start;
 			$query			= $this->_db->db_addslashes($query);
@@ -977,9 +1011,9 @@
 			if ( $order )
 			{
 				if ( $sort == 'DESC')
-			{
+				{
 					$sort = 'DESC';
-			}
+				}
 
 				$ordermethod = "ORDER BY {$order} {$sort}";
 			}
@@ -1028,7 +1062,7 @@
 
 			return $attrib_groups;
 		}
-		
+
 		/**
 		* Read a single attribute group record
 		*
@@ -1042,7 +1076,7 @@
 		{
 			$location_id = $GLOBALS['phpgw']->locations->get_id($appname, $location);
 			$id = (int) $id;
-			
+
 			$sql = "SELECT * FROM phpgw_cust_attribute_group "
 				. " WHERE location_id = {$location_id} AND id = {$id}";
 			$this->_db->query($sql, __LINE__, __FILE__);
@@ -1053,30 +1087,30 @@
 			}
 
 			$group = array
-				(
+			(
 				'id'			=> $this->_db->f('id'),
 				'group_name'	=> $this->_db->f('name', true),
 				'descr'			=> $this->_db->f('descr', true),
 				'remark'		=> $this->_db->f('remark', true),
 				'group_sort'	=> $this->_db->f('group_sort')
-				);
+			);
 
 			return $group;
 		}
 		/**
 		* Read a single attribute record
-		 * 
+		*
 		* @param string  $appname     the name of the module for the attribute
 		* @param string  $location    the name of the location of the attribute
 		* @param integer $id          the id of the attribute
 		* @param boolean $inc_choices include choices if a lookup field
 		*
 		* @return array the attribute record
-		 */
+		*/
 		public function get($appname, $location, $id, $inc_choices = true)
 		{
 			$location_id = $GLOBALS['phpgw']->locations->get_id($appname, $location);
-			$id			= (int) $id;
+			$id = (int) $id;
 
 			$sql = "SELECT phpgw_cust_attribute.* FROM phpgw_cust_attribute " 
 				. " WHERE location_id = {$location_id}"
@@ -1122,19 +1156,19 @@
 			if ( $inc_choices )
 			{
 				switch ( $this->_db->f('datatype') )
-					{
-				default:
+				{
+					default:
 						// bail out quickly
 						break;
 					case 'R':
 					case 'CH':
 					case 'LB':
 						$attrib['choice'] = $this->_get_choices($location_id, $id);
-					break;
-					}
+						break;
 				}
+			}
 			return $attrib;
-			}
+		}
 
 		/**
 		* Arrange attributes within groups
@@ -1156,26 +1190,26 @@
 					'name'	=> lang('attributes'),
 					'descr' => lang('attributes')
 				)
-				);
+			);
 			$groups = $this->find_group($appname, $location, 0, '', 'ASC', 'group_sort', true);
 			$groups = array_merge($no_group, $groups);
-
+		
 			foreach ($groups as &$group)
+			{
+				foreach ($attributes as $attribute)
 				{
-				foreach ($attributes as $attribute)
-		{
 					if($attribute['group_id'] == $group['id'])
-			{
+					{
 						$group['attributes'][] = $attribute;
+					}
+				}
 			}
-		}
-		}
 			return $groups;
 		}
 
 		/**
 		 * Get the definition of a table
-		 * 
+		 *
 		 * @param string $table     the name of the table to look up
 		 * @param array  $table_def ask sigurd
 		 *
@@ -1202,22 +1236,22 @@
 			$table_def[$table]['fk'] = isset($table_def[$table]['fk']) && $table_def[$table]['fk'] ? $table_def[$table]['fk'] : $tableinfo[2];		
 			$table_def[$table]['ix'] = isset($table_def[$table]['ix']) && $table_def[$table]['ix'] ? $table_def[$table]['ix'] : $tableinfo[3];
 			$table_def[$table]['uc'] = isset($table_def[$table]['uc']) && $table_def[$table]['uc'] ? $table_def[$table]['uc'] : $tableinfo[4];
-			
+
 			return $table_def;
 		}
-		
+
 		/**
 		* Preserve attribute values from post in case of an error
-		 * 
+		*
 		* @param array $values value set with
 		* @param array $values_attributes attribute definitions and values from posting
 		*
 		* @return array attribute definitions and values
-		 */
+		*/
 		public function preserve_attribute_values($values, $values_attributes)
-				{
+		{
 			if ( !is_array($values_attributes ) )
-					{
+			{
 				return array();
 			}
 
@@ -1228,45 +1262,45 @@
 					if ( $val_attrib['id'] != $attribute['attrib_id'] )
 					{
 						continue;
-		}
+					}
 
 					if( !isset($attribute['value']) )
-		{
+					{
 						continue;
 					}
 
 					if ( is_array($attribute['value']) )
-			{
+					{
 						foreach ( $val_attrib['choice'] as &$choice )
-				{
+						{
 							foreach ( $attribute['value'] as $selected )
-					{
+							{
 								if ( $selected == $choice['id'] )
-					{
+								{
 									$choice['checked'] = 'checked';
+								}
+							}
+						}
 					}
-					}
-					}
-				}
 					else if ( isset($val_attrib['choice'])
 						&& is_array($val_attrib['choice']) )
-				{
+					{
 						foreach ( $val_attrib['choice'] as &$choice)
-					{
+						{
 							if ( $choice['id'] == $attribute['value'] )
 							{
 								$choice['checked'] = 'checked';
+							}
+						}
 					}
-				}
-					}
 					else
-							{
+					{
 						$val_attrib['value'] = $attribute['value'];
 					}
-							}
-						}
+				}
+			}
 			return $values;
-					}
+		}
 
 
 
@@ -1281,13 +1315,13 @@
 			$id		= (int) $id;
 
 			if ( $resort == 'down' )
-				{
+			{
 				$resort = 'down';
 			}
 			else
-					{
+			{
 				$resort	= 'up';
-					}
+			}
 
 			$location_id = $GLOBALS['phpgw']->locations->get_id($appname, $location);
 
@@ -1307,13 +1341,13 @@
 
 			$update = false;
 			switch($resort)
-									{
+			{
 				case 'down':
 					if($max_sort > $attrib_sort)
-										{
+					{
 						$new_sort = $attrib_sort + 1;
 						$update = true;
-										}
+					}
 					break;
 
 				case 'up':
@@ -1322,15 +1356,15 @@
 					{
 						$new_sort = $attrib_sort - 1;
 						$update = true;
-									}
+					}
 					break;
-								}
+			}
 
 			if ( !$update )
 			{
 				// nothing to do
 				return true;
-							}
+			}
 
 			$sql = "UPDATE phpgw_cust_attribute_group SET group_sort = {$attrib_sort}"
 				. " WHERE location_id = {$location_id} AND group_sort = {$new_sort}";
@@ -1341,7 +1375,7 @@
 			$this->_db->query($sql, __LINE__, __FILE__);
 
 			return $this->_db->transaction_commit();
-						}
+		}
 
 		/**
 		 * Resort an attribute's position in relation to other attributes
@@ -1356,9 +1390,9 @@
 			if ( $resort == 'down' )
 			{
 				$resort = 'down';
-					}
-					else
-					{
+			}
+			else
+			{
 				$resort	= 'up';
 			}
 
@@ -1386,13 +1420,13 @@
 
 			$update = false;
 			switch($resort)
-						{
+			{
 				case 'down':
 					if($max_sort > $attrib_sort)
-							{
+					{
 						$new_sort = $attrib_sort + 1;
 						$update = true;
-						}
+					}
 					break;
 
 				case 'up':
@@ -1403,13 +1437,13 @@
 						$update = true;
 					}
 					break;
-				}
+			}
 
 			if ( !$update )
-				{
+			{
 				// nothing to do
 				return true;
-				}
+			}
 
 			$sql = "UPDATE phpgw_cust_attribute SET attrib_sort = {$attrib_sort}"
 				. " WHERE location_id = {$location_id} AND attrib_sort = {$new_sort} AND group_id = {$group_id}";
@@ -1420,7 +1454,7 @@
 			$this->_db->query($sql, __LINE__, __FILE__);
 
 			return $this->_db->transaction_commit();
-			}
+		}
 
 		/**
 		 * Convert a datatype to a human readable label
@@ -1430,13 +1464,13 @@
 		 * @return string the user readable string
 		 */
 		public function translate_datatype($datatype)
-			{ 
+		{
 			if ( isset($this->datatype_text[$datatype]) )
-				{
+			{
 				return $this->datatype_text[$datatype];
-				}
+			}
 			return '';
-			}
+		}
 
 		/**
 		 * Get the list of available choices for a lookup field
@@ -1445,14 +1479,14 @@
 		 * @param integer $attrib_id   the field being looked up
 		 */
 		protected function _get_choices($location_id, $attrib_id)
-			{
+		{
 			$location_id	= (int) $location_id;
 			$attrib_id		= (int) $attrib_id;
-
+			
 			$sql = "SELECT * FROM phpgw_cust_choice " 
 				. " WHERE location_id = {$location_id}"
 					. " AND attrib_id = {$attrib_id}"
-				. " ORDER BY value";
+				. " ORDER BY choice_sort ASC, value";
 			$this->_db->query($sql,__LINE__,__FILE__);
 
 			$choices = array();
@@ -1463,7 +1497,8 @@
 				$choices[] = array
 				(
 					'id'	=> $this->_db->f('id'),
-					'value'	=> $this->_db->f('value', true)
+					'value'	=> $this->_db->f('value', true),
+					'order'	=> $this->_db->f('choice_sort')
 				);
 			}
 			return $choices;
@@ -1471,47 +1506,47 @@
 
 		/**
 		 * Finds the next ID for a record at a table
-		*
+		 * 
 		 * @param string $table tablename in question
 		 * @param array  $key   conditions for finding the next id
 		 *
 		 * @return int the next id
-		*/
+		 */
 		protected function _next_id($table = null, $key = null)
-							{
+		{
 			if ( !$table )
-								{
+			{
 				return 0;
-							}
+			}
 
 			$next_id = 0;
 
 			$where = '';
 			if ( is_array($key) )
-						{
+			{
 				foreach ( $key as $col => $val )
-							{
+				{
 					if ( $val )
-								{
+					{
 						$val = $this->_db->db_addslashes($val);
 						$condition[] = "{$col} = '{$val}";
-							}
-						}
+					}
+				}
 
 				$where='WHERE ' . implode("' AND ", $condition) . "'";
-					}
+			}
 
 			$sql = "SELECT max(id) as maximum FROM {$table} {$where}";
 			$this->_db->query($sql, __LINE__, __FILE__);
 			if ( $this->_db->next_record() )
 			{
 				$next_id = $this->_db->f('maximum');
-				}
+			}
 
 			++$next_id;
 			return $next_id;
-			}
-			
+		}
+
 		/**
 		 * Preapre a datatype for insert
 		 *
@@ -1520,7 +1555,7 @@
 		 * @return string the converted datatype or empty string is invalid
 		 */
 		protected function _translate_datatype_insert($datatype)
-				{
+		{
 			$datatype_text = array
 			(
 				'V'			=> 'varchar',
@@ -1532,7 +1567,8 @@
 				'R'			=> 'int',
 				'CH'		=> 'text',
 				'LB'		=> 'int',
-				'AB'		=> 'int',
+				'AB'		=> 'int',// Addressbook person
+				'ABO'		=> 'int',// Addressbook organisation
 				'VENDOR'	=> 'int',
 				'email'		=> 'varchar',
 				'link'		=> 'varchar',
@@ -1542,12 +1578,12 @@
 			);
 
 			if ( !isset($datatype_text[$datatype]) )
-					{
+			{
 				return '';
-					}
+			}
 
 			return $datatype_text[$datatype];
-					}
+		}
 
 		/**
 		 * Get the precision for a datatype
@@ -1557,13 +1593,14 @@
 		 * @return integer the precision - 0 for n/a or invalid
 		 */
 		protected function _translate_datatype_precision($datatype)
-					{
+		{
 			$datatype_precision = array
 			(
 				'I'			=> 4,
 				'R'			=> 4,
 				'LB'		=> 4,
 				'AB'		=> 4,
+				'ABO'		=> 4,
 				'VENDOR'	=> 4,
 				'email'		=> 64,
 				'link'		=> 255,
@@ -1571,11 +1608,11 @@
 				'user' 		=> 4,
 				'event'		=> 4
 			);
-	
+
 			if ( !isset($datatype_precision[$datatype]) )
-					{
+			{
 				return 0;
-					}
+			}
 			return $datatype_precision[$datatype];
-				}
-			}
+		}
+	}