phpgroupware-cvs
[Top][All Lists]
Advanced

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

[Phpgroupware-cvs] property inc/class.boXport.inc.php inc/class.bo...


From: Sigurd Nes
Subject: [Phpgroupware-cvs] property inc/class.boXport.inc.php inc/class.bo...
Date: Fri, 03 Feb 2006 12:05:50 +0000

CVSROOT:        /sources/phpgroupware
Module name:    property
Branch:         
Changes by:     Sigurd Nes <address@hidden>     06/02/03 12:05:49

Modified files:
        inc            : class.boXport.inc.php class.boactor.inc.php 
                         class.boadmin.inc.php 
                         class.boadmin_location.inc.php 
                         class.boagreement.inc.php class.boalarm.inc.php 
                         class.boasync.inc.php class.bob_account.inc.php 
                         class.bocategory.inc.php class.bocommon.inc.php 
                         class.bocustom.inc.php class.bodocument.inc.php 
                         class.boentity.inc.php class.bogab.inc.php 
                         class.boinvestment.inc.php 
                         class.boinvoice.inc.php 
                         class.bolocation.inc.php class.bolookup.inc.php 
                         class.bometer.inc.php class.bop_of_town.inc.php 
                         class.bopricebook.inc.php 
                         class.boproject.inc.php class.borequest.inc.php 
                         class.bos_agreement.inc.php 
                         class.bostandard_2.inc.php 
                         class.bostandard_3.inc.php 
                         class.bostandard_entity.inc.php 
                         class.botemplate.inc.php 
                         class.botenant_claim.inc.php 
                         class.botts.inc.php class.bowo_hour.inc.php 
                         class.boworkorder.inc.php 
                         class.custom_functions.inc.php 
                         class.excel.inc.php class.historylog.inc.php 
                         class.menu.inc.php class.pdf.inc.php 
                         class.soXport.inc.php class.sogab.inc.php 
                         class.uiXport.inc.php class.uiactor.inc.php 
                         class.uiadmin.inc.php 
                         class.uiadmin_entity.inc.php 
                         class.uiadmin_location.inc.php 
                         class.uiagreement.inc.php class.uialarm.inc.php 
                         class.uiasync.inc.php class.uib_account.inc.php 
                         class.uicategory.inc.php class.uicustom.inc.php 
                         class.uidocument.inc.php class.uientity.inc.php 
                         class.uigab.inc.php class.uiinvestment.inc.php 
                         class.uilocation.inc.php class.uilookup.inc.php 
                         class.uimeter.inc.php class.uip_of_town.inc.php 
                         class.uipricebook.inc.php 
                         class.uiproject.inc.php class.uirequest.inc.php 
                         class.uis_agreement.inc.php 
                         class.uistandard_2.inc.php 
                         class.uistandard_3.inc.php 
                         class.uistandard_entity.inc.php 
                         class.uitemplate.inc.php 
                         class.uitenant_claim.inc.php 
                         class.uitts.inc.php class.uiwo_hour.inc.php 
                         class.uiworkorder.inc.php hook_admin.inc.php 
                         hook_help.inc.php hook_home.inc.php 
                         hook_manual.inc.php hook_preferences.inc.php 
                         hook_settings.inc.php 
        inc/custom     : cron.php 
        inc/export     : Agresso 
        setup          : setup.inc.php 
        templates/base : admin_entity.xsl invoice.xsl 
        templates/default: admin_entity.xsl invoice.xsl 

Log message:
        dos2unix

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/inc/class.boXport.inc.php.diff?tr1=1.11&tr2=1.12&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/inc/class.boactor.inc.php.diff?tr1=1.7&tr2=1.8&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/inc/class.boadmin.inc.php.diff?tr1=1.7&tr2=1.8&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/inc/class.boadmin_location.inc.php.diff?tr1=1.8&tr2=1.9&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/inc/class.boagreement.inc.php.diff?tr1=1.7&tr2=1.8&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/inc/class.boalarm.inc.php.diff?tr1=1.11&tr2=1.12&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/inc/class.boasync.inc.php.diff?tr1=1.5&tr2=1.6&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/inc/class.bob_account.inc.php.diff?tr1=1.6&tr2=1.7&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/inc/class.bocategory.inc.php.diff?tr1=1.6&tr2=1.7&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/inc/class.bocommon.inc.php.diff?tr1=1.20&tr2=1.21&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/inc/class.bocustom.inc.php.diff?tr1=1.6&tr2=1.7&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/inc/class.bodocument.inc.php.diff?tr1=1.6&tr2=1.7&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/inc/class.boentity.inc.php.diff?tr1=1.14&tr2=1.15&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/inc/class.bogab.inc.php.diff?tr1=1.7&tr2=1.8&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/inc/class.boinvestment.inc.php.diff?tr1=1.6&tr2=1.7&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/inc/class.boinvoice.inc.php.diff?tr1=1.16&tr2=1.17&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/inc/class.bolocation.inc.php.diff?tr1=1.9&tr2=1.10&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/inc/class.bolookup.inc.php.diff?tr1=1.7&tr2=1.8&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/inc/class.bometer.inc.php.diff?tr1=1.6&tr2=1.7&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/inc/class.bop_of_town.inc.php.diff?tr1=1.6&tr2=1.7&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/inc/class.bopricebook.inc.php.diff?tr1=1.7&tr2=1.8&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/inc/class.boproject.inc.php.diff?tr1=1.13&tr2=1.14&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/inc/class.borequest.inc.php.diff?tr1=1.9&tr2=1.10&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/inc/class.bos_agreement.inc.php.diff?tr1=1.11&tr2=1.12&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/inc/class.bostandard_2.inc.php.diff?tr1=1.6&tr2=1.7&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/inc/class.bostandard_3.inc.php.diff?tr1=1.6&tr2=1.7&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/inc/class.bostandard_entity.inc.php.diff?tr1=1.6&tr2=1.7&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/inc/class.botemplate.inc.php.diff?tr1=1.6&tr2=1.7&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/inc/class.botenant_claim.inc.php.diff?tr1=1.6&tr2=1.7&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/inc/class.botts.inc.php.diff?tr1=1.15&tr2=1.16&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/inc/class.bowo_hour.inc.php.diff?tr1=1.8&tr2=1.9&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/inc/class.boworkorder.inc.php.diff?tr1=1.9&tr2=1.10&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/inc/class.custom_functions.inc.php.diff?tr1=1.5&tr2=1.6&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/inc/class.excel.inc.php.diff?tr1=1.6&tr2=1.7&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/inc/class.historylog.inc.php.diff?tr1=1.7&tr2=1.8&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/inc/class.menu.inc.php.diff?tr1=1.16&tr2=1.17&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/inc/class.pdf.inc.php.diff?tr1=1.6&tr2=1.7&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/inc/class.soXport.inc.php.diff?tr1=1.21&tr2=1.22&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/inc/class.sogab.inc.php.diff?tr1=1.13&tr2=1.14&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/inc/class.uiXport.inc.php.diff?tr1=1.15&tr2=1.16&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/inc/class.uiactor.inc.php.diff?tr1=1.12&tr2=1.13&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/inc/class.uiadmin.inc.php.diff?tr1=1.10&tr2=1.11&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/inc/class.uiadmin_entity.inc.php.diff?tr1=1.13&tr2=1.14&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/inc/class.uiadmin_location.inc.php.diff?tr1=1.10&tr2=1.11&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/inc/class.uiagreement.inc.php.diff?tr1=1.17&tr2=1.18&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/inc/class.uialarm.inc.php.diff?tr1=1.10&tr2=1.11&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/inc/class.uiasync.inc.php.diff?tr1=1.10&tr2=1.11&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/inc/class.uib_account.inc.php.diff?tr1=1.10&tr2=1.11&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/inc/class.uicategory.inc.php.diff?tr1=1.9&tr2=1.10&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/inc/class.uicustom.inc.php.diff?tr1=1.12&tr2=1.13&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/inc/class.uidocument.inc.php.diff?tr1=1.11&tr2=1.12&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/inc/class.uientity.inc.php.diff?tr1=1.16&tr2=1.17&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/inc/class.uigab.inc.php.diff?tr1=1.12&tr2=1.13&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/inc/class.uiinvestment.inc.php.diff?tr1=1.9&tr2=1.10&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/inc/class.uilocation.inc.php.diff?tr1=1.17&tr2=1.18&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/inc/class.uilookup.inc.php.diff?tr1=1.12&tr2=1.13&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/inc/class.uimeter.inc.php.diff?tr1=1.9&tr2=1.10&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/inc/class.uip_of_town.inc.php.diff?tr1=1.9&tr2=1.10&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/inc/class.uipricebook.inc.php.diff?tr1=1.13&tr2=1.14&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/inc/class.uiproject.inc.php.diff?tr1=1.23&tr2=1.24&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/inc/class.uirequest.inc.php.diff?tr1=1.18&tr2=1.19&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/inc/class.uis_agreement.inc.php.diff?tr1=1.23&tr2=1.24&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/inc/class.uistandard_2.inc.php.diff?tr1=1.9&tr2=1.10&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/inc/class.uistandard_3.inc.php.diff?tr1=1.9&tr2=1.10&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/inc/class.uistandard_entity.inc.php.diff?tr1=1.9&tr2=1.10&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/inc/class.uitemplate.inc.php.diff?tr1=1.9&tr2=1.10&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/inc/class.uitenant_claim.inc.php.diff?tr1=1.9&tr2=1.10&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/inc/class.uitts.inc.php.diff?tr1=1.28&tr2=1.29&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/inc/class.uiwo_hour.inc.php.diff?tr1=1.17&tr2=1.18&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/inc/class.uiworkorder.inc.php.diff?tr1=1.17&tr2=1.18&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/inc/hook_admin.inc.php.diff?tr1=1.18&tr2=1.19&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/inc/hook_help.inc.php.diff?tr1=1.6&tr2=1.7&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/inc/hook_home.inc.php.diff?tr1=1.6&tr2=1.7&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/inc/hook_manual.inc.php.diff?tr1=1.7&tr2=1.8&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/inc/hook_preferences.inc.php.diff?tr1=1.6&tr2=1.7&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/inc/hook_settings.inc.php.diff?tr1=1.12&tr2=1.13&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/inc/custom/cron.php.diff?tr1=1.6&tr2=1.7&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/inc/export/Agresso.diff?tr1=1.29&tr2=1.30&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/setup/setup.inc.php.diff?tr1=1.25&tr2=1.26&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/templates/base/admin_entity.xsl.diff?tr1=1.3&tr2=1.4&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/templates/base/invoice.xsl.diff?tr1=1.6&tr2=1.7&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/templates/default/admin_entity.xsl.diff?tr1=1.5&tr2=1.6&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/templates/default/invoice.xsl.diff?tr1=1.13&tr2=1.14&r1=text&r2=text

Patches:
Index: property/inc/class.boXport.inc.php
diff -u property/inc/class.boXport.inc.php:1.11 
property/inc/class.boXport.inc.php:1.12
--- property/inc/class.boXport.inc.php:1.11     Fri Jan 27 14:05:42 2006
+++ property/inc/class.boXport.inc.php  Fri Feb  3 12:05:49 2006
@@ -1,282 +1,282 @@
-<?php
-       /**
-       * phpGroupWare - property: a Facilities Management System.
-       *
-       * @author Sigurd Nes <address@hidden>
-       * @copyright Copyright (C) 2003-2005 Free Software Foundation, Inc. 
http://www.fsf.org/
-       * @license http://www.gnu.org/licenses/gpl.html GNU General Public 
License
-       * @internal Development of this application was funded by 
http://www.bergen.kommune.no/bbb_/ekstern/
-       * @package property
-       * @subpackage admin
-       * @version $Id: class.boXport.inc.php,v 1.11 2006/01/27 14:05:42 
sigurdne Exp $
-       */
-
-       /**
-        * Description
-        * @package property
-        */
-
-       class boXport
-       {
-               var $public_functions = array(
-                       'import' => True,
-                       'export' => True
-               );
-
-               var $start;
-               var $query;
-               var $sort;
-               var $order;
-               var $filter;
-               var $cat_id;
-
-               var $use_session = False;
-
-               function boXport ($session=False)
-               {
-
-                       $GLOBALS['phpgw_info']['flags']['currentapp']   =       
'property';
-                       $this->currentapp               = 
$GLOBALS['phpgw_info']['flags']['currentapp'];
-
-                       $this->config           = 
CreateObject('phpgwapi.config',$this->currentapp);
-
-                       if($session)
-                       {
-                               $this->read_sessiondata();
-                               $this->use_session = True;
-                       }
-
-                       $start  = get_var('start',array('POST','GET'));
-                       $query  = get_var('query',array('POST','GET'));
-                       $sort   = get_var('sort',array('POST','GET'));
-                       $order  = get_var('order',array('POST','GET'));
-                       $filter = get_var('filter',array('POST','GET'));
-                       $cat_id = get_var('cat_id',array('POST','GET'));
-
-                       if($start || $start == 0)  { $this->start = $start; }
-                       if($query)  { $this->query  = $query;  }
-                       if($sort)   { $this->sort   = $sort;   }
-                       if($order)  { $this->order  = $order;  }
-                       if($filter) { $this->filter = $filter; }
-                       $this->cat_id = $cat_id;
-               }
-
-               function save_sessiondata()
-               {
-
-                       if ($this->use_session)
-                       {
-                               $data = array(
-                                       'start'  => $this->start,
-                                       'query'  => $this->query,
-                                       'sort'   => $this->sort,
-                                       'order'  => $this->order,
-                                       'filter' => $this->filter,
-                                       'cat_id' => $this->cat_id
-                               );
-                               if($this->debug) { echo '<br>Save:'; 
_debug_array($data); }
-                               
$GLOBALS['phpgw']->session->appsession('session_data','export',$data);
-                       }
-               }
-
-               function read_sessiondata()
-               {
-                       $data = 
$GLOBALS['phpgw']->session->appsession('session_data','export');
-                       if($this->debug) { echo '<br>Read:'; 
_debug_array($data); }
-
-                       $this->start  = $data['start'];
-                       $this->query  = $data['query'];
-                       $this->sort   = $data['sort'];
-                       $this->order  = $data['order'];
-                       $this->filter = $data['filter'];
-                       $this->cat_id = $data['cat_id'];
-               }
-
-               function select_import_conv($selected='')
-               {
-                       $dir_handle = @opendir(PHPGW_APP_INC . SEP . 'import');
-                       $i=0; $myfilearray = '';
-                       while ($file = readdir($dir_handle))
-                       {
-                               if ((substr($file, 0, 1) != '.') && 
is_file(PHPGW_APP_INC . SEP . 'import' . SEP . $file) )
-                               {
-                                       $myfilearray[$i] = $file;
-                                       $i++;
-                               }
-                       }
-                       closedir($dir_handle);
-                       sort($myfilearray);
-
-                       for ($i=0;$i<count($myfilearray);$i++)
-                       {
-                               $fname = ereg_replace('_',' ',$myfilearray[$i]);
-                               $sel_file = '';
-                               if ($myfilearray[$i]==$selected)
-                               {
-                                       $sel_file = 'selected';
-                               }
-
-                               $conv_list[] = array
-                               (
-                                       'id'            => $myfilearray[$i],
-                                       'name'          => $fname,
-                                       'selected'      => $sel_file
-                               );
-                       }
-
-                       for ($i=0;$i<count($conv_list);$i++)
-                       {
-                               if ($conv_list[$i]['selected'] != 'selected')
-                               {
-                                       unset($conv_list[$i]['selected']);
-                               }
-                       }
-
-                       return $conv_list;
-
-               }
-
-               function select_export_conv($selected='')
-               {
-                       $dir_handle = @opendir(PHPGW_APP_INC . SEP . 'export');
-                       $i=0; $myfilearray = '';
-                       while ($file = readdir($dir_handle))
-                       {
-                               if ((substr($file, 0, 1) != '.') && 
is_file(PHPGW_APP_INC . SEP . 'export' . SEP . $file) )
-                               {
-                                       $myfilearray[$i] = $file;
-                                       $i++;
-                               }
-                       }
-                       closedir($dir_handle);
-                       sort($myfilearray);
-
-                       for ($i=0;$i<count($myfilearray);$i++)
-                       {
-                               $fname = ereg_replace('_',' ',$myfilearray[$i]);
-                               $sel_file = '';
-                               if ($myfilearray[$i]==$selected)
-                               {
-                                       $sel_file = 'selected';
-                               }
-
-                               $conv_list[] = array
-                               (
-                                       'id'            => $myfilearray[$i],
-                                       'name'          => $fname,
-                                       'selected'      => $sel_file
-                               );
-                       }
-
-                       for ($i=0;$i<count($conv_list);$i++)
-                       {
-                               if ($conv_list[$i]['selected'] != 'selected')
-                               {
-                                       unset($conv_list[$i]['selected']);
-                               }
-                       }
-
-                       return $conv_list;
-
-               }
-
-               function select_rollback_file($selected='')
-               {
-                       $this->config->read_repository();
-                       $file_catalog = 
$this->config->config_data['export_path'];
-
-                       $dir_handle = @opendir($file_catalog);
-                       $i=0; $myfilearray = '';
-                       while ($file = readdir($dir_handle))
-                       {
-                               if ((substr($file, 0, 1) != '.') && 
is_file($file_catalog . SEP . $file) )
-                               {
-                                       $myfilearray[$i] = $file;
-                                       $i++;
-                               }
-                       }
-                       closedir($dir_handle);
-                       @sort($myfilearray);
-
-                       for ($i=0;$i<count($myfilearray);$i++)
-                       {
-                               $fname = ereg_replace('_',' ',$myfilearray[$i]);
-                               $sel_file = '';
-                               if ($myfilearray[$i]==$selected)
-                               {
-                                       $sel_file = 'selected';
-                               }
-
-                               $rollback_list[] = array
-                               (
-                                       'id'            => $myfilearray[$i],
-                                       'name'          => $fname,
-                                       'selected'      => $sel_file
-                               );
-                       }
-
-                       for ($i=0;$i<count($rollback_list);$i++)
-                       {
-                               if ($rollback_list[$i]['selected'] != 
'selected')
-                               {
-                                       unset($rollback_list[$i]['selected']);
-                               }
-                       }
-
-                       return $rollback_list;
-
-               }
-
-               function import($invoice_common,$download)
-               {
-                       include (PHPGW_APP_INC . '/import/' . 
$invoice_common['conv_type']);
-                       $invoice = new import_conv;
-
-                       $buffer = $invoice->import($invoice_common,$download);
-                       if ($download)
-                       {
-                               $header = $invoice->header;
-                               $import = $invoice->import;
-                               $buffer= array(
-                                               'table'         => $buffer,
-                                               'header'        => $header,
-                                               'import'        => $import
-                                       );
-                       }
-                       return $buffer;
-               }
-
-               function export($data)
-               {
-                       $conv_type = $data['conv_type'];
-                       $download = $data['download'];
-                       $pre_transfer = $data['pre_transfer'];
-                       $force_period_year = $data['force_period_year'];
-
-                       include(PHPGW_SERVER_ROOT.'/'.'property'.'/inc/export/' 
. $conv_type);
-                       $invoice = new export_conv;
-
-                       $buffer = 
$invoice->overfor($download,$pre_transfer,$force_period_year);
-
-                       return $buffer;
-               }
-
-               function rollback($conv_type,$role_back_date,$rollback_file)
-               {
-                       include (PHPGW_APP_INC . '/export/' . $conv_type);
-                       $invoice = new export_conv;
-                       $buffer = 
$invoice->RullTilbake($role_back_date,$rollback_file);
-                       return $buffer;
-
-               }
-
-               function export_cron($data)
-               {
-                       if($data['enabled']==1)
-                       {
-                               $this->export($data);
-                       }
-               }
-
-       }
-?>
+<?php
+       /**
+       * phpGroupWare - property: a Facilities Management System.
+       *
+       * @author Sigurd Nes <address@hidden>
+       * @copyright Copyright (C) 2003-2005 Free Software Foundation, Inc. 
http://www.fsf.org/
+       * @license http://www.gnu.org/licenses/gpl.html GNU General Public 
License
+       * @internal Development of this application was funded by 
http://www.bergen.kommune.no/bbb_/ekstern/
+       * @package property
+       * @subpackage admin
+       * @version $Id: class.boXport.inc.php,v 1.12 2006/02/03 12:05:49 
sigurdne Exp $
+       */
+
+       /**
+        * Description
+        * @package property
+        */
+
+       class boXport
+       {
+               var $public_functions = array(
+                       'import' => True,
+                       'export' => True
+               );
+
+               var $start;
+               var $query;
+               var $sort;
+               var $order;
+               var $filter;
+               var $cat_id;
+
+               var $use_session = False;
+
+               function boXport ($session=False)
+               {
+
+                       $GLOBALS['phpgw_info']['flags']['currentapp']   =       
'property';
+                       $this->currentapp               = 
$GLOBALS['phpgw_info']['flags']['currentapp'];
+
+                       $this->config           = 
CreateObject('phpgwapi.config',$this->currentapp);
+
+                       if($session)
+                       {
+                               $this->read_sessiondata();
+                               $this->use_session = True;
+                       }
+
+                       $start  = get_var('start',array('POST','GET'));
+                       $query  = get_var('query',array('POST','GET'));
+                       $sort   = get_var('sort',array('POST','GET'));
+                       $order  = get_var('order',array('POST','GET'));
+                       $filter = get_var('filter',array('POST','GET'));
+                       $cat_id = get_var('cat_id',array('POST','GET'));
+
+                       if($start || $start == 0)  { $this->start = $start; }
+                       if($query)  { $this->query  = $query;  }
+                       if($sort)   { $this->sort   = $sort;   }
+                       if($order)  { $this->order  = $order;  }
+                       if($filter) { $this->filter = $filter; }
+                       $this->cat_id = $cat_id;
+               }
+
+               function save_sessiondata()
+               {
+
+                       if ($this->use_session)
+                       {
+                               $data = array(
+                                       'start'  => $this->start,
+                                       'query'  => $this->query,
+                                       'sort'   => $this->sort,
+                                       'order'  => $this->order,
+                                       'filter' => $this->filter,
+                                       'cat_id' => $this->cat_id
+                               );
+                               if($this->debug) { echo '<br>Save:'; 
_debug_array($data); }
+                               
$GLOBALS['phpgw']->session->appsession('session_data','export',$data);
+                       }
+               }
+
+               function read_sessiondata()
+               {
+                       $data = 
$GLOBALS['phpgw']->session->appsession('session_data','export');
+                       if($this->debug) { echo '<br>Read:'; 
_debug_array($data); }
+
+                       $this->start  = $data['start'];
+                       $this->query  = $data['query'];
+                       $this->sort   = $data['sort'];
+                       $this->order  = $data['order'];
+                       $this->filter = $data['filter'];
+                       $this->cat_id = $data['cat_id'];
+               }
+
+               function select_import_conv($selected='')
+               {
+                       $dir_handle = @opendir(PHPGW_APP_INC . SEP . 'import');
+                       $i=0; $myfilearray = '';
+                       while ($file = readdir($dir_handle))
+                       {
+                               if ((substr($file, 0, 1) != '.') && 
is_file(PHPGW_APP_INC . SEP . 'import' . SEP . $file) )
+                               {
+                                       $myfilearray[$i] = $file;
+                                       $i++;
+                               }
+                       }
+                       closedir($dir_handle);
+                       sort($myfilearray);
+
+                       for ($i=0;$i<count($myfilearray);$i++)
+                       {
+                               $fname = ereg_replace('_',' ',$myfilearray[$i]);
+                               $sel_file = '';
+                               if ($myfilearray[$i]==$selected)
+                               {
+                                       $sel_file = 'selected';
+                               }
+
+                               $conv_list[] = array
+                               (
+                                       'id'            => $myfilearray[$i],
+                                       'name'          => $fname,
+                                       'selected'      => $sel_file
+                               );
+                       }
+
+                       for ($i=0;$i<count($conv_list);$i++)
+                       {
+                               if ($conv_list[$i]['selected'] != 'selected')
+                               {
+                                       unset($conv_list[$i]['selected']);
+                               }
+                       }
+
+                       return $conv_list;
+
+               }
+
+               function select_export_conv($selected='')
+               {
+                       $dir_handle = @opendir(PHPGW_APP_INC . SEP . 'export');
+                       $i=0; $myfilearray = '';
+                       while ($file = readdir($dir_handle))
+                       {
+                               if ((substr($file, 0, 1) != '.') && 
is_file(PHPGW_APP_INC . SEP . 'export' . SEP . $file) )
+                               {
+                                       $myfilearray[$i] = $file;
+                                       $i++;
+                               }
+                       }
+                       closedir($dir_handle);
+                       sort($myfilearray);
+
+                       for ($i=0;$i<count($myfilearray);$i++)
+                       {
+                               $fname = ereg_replace('_',' ',$myfilearray[$i]);
+                               $sel_file = '';
+                               if ($myfilearray[$i]==$selected)
+                               {
+                                       $sel_file = 'selected';
+                               }
+
+                               $conv_list[] = array
+                               (
+                                       'id'            => $myfilearray[$i],
+                                       'name'          => $fname,
+                                       'selected'      => $sel_file
+                               );
+                       }
+
+                       for ($i=0;$i<count($conv_list);$i++)
+                       {
+                               if ($conv_list[$i]['selected'] != 'selected')
+                               {
+                                       unset($conv_list[$i]['selected']);
+                               }
+                       }
+
+                       return $conv_list;
+
+               }
+
+               function select_rollback_file($selected='')
+               {
+                       $this->config->read_repository();
+                       $file_catalog = 
$this->config->config_data['export_path'];
+
+                       $dir_handle = @opendir($file_catalog);
+                       $i=0; $myfilearray = '';
+                       while ($file = readdir($dir_handle))
+                       {
+                               if ((substr($file, 0, 1) != '.') && 
is_file($file_catalog . SEP . $file) )
+                               {
+                                       $myfilearray[$i] = $file;
+                                       $i++;
+                               }
+                       }
+                       closedir($dir_handle);
+                       @sort($myfilearray);
+
+                       for ($i=0;$i<count($myfilearray);$i++)
+                       {
+                               $fname = ereg_replace('_',' ',$myfilearray[$i]);
+                               $sel_file = '';
+                               if ($myfilearray[$i]==$selected)
+                               {
+                                       $sel_file = 'selected';
+                               }
+
+                               $rollback_list[] = array
+                               (
+                                       'id'            => $myfilearray[$i],
+                                       'name'          => $fname,
+                                       'selected'      => $sel_file
+                               );
+                       }
+
+                       for ($i=0;$i<count($rollback_list);$i++)
+                       {
+                               if ($rollback_list[$i]['selected'] != 
'selected')
+                               {
+                                       unset($rollback_list[$i]['selected']);
+                               }
+                       }
+
+                       return $rollback_list;
+
+               }
+
+               function import($invoice_common,$download)
+               {
+                       include (PHPGW_APP_INC . '/import/' . 
$invoice_common['conv_type']);
+                       $invoice = new import_conv;
+
+                       $buffer = $invoice->import($invoice_common,$download);
+                       if ($download)
+                       {
+                               $header = $invoice->header;
+                               $import = $invoice->import;
+                               $buffer= array(
+                                               'table'         => $buffer,
+                                               'header'        => $header,
+                                               'import'        => $import
+                                       );
+                       }
+                       return $buffer;
+               }
+
+               function export($data)
+               {
+                       $conv_type = $data['conv_type'];
+                       $download = $data['download'];
+                       $pre_transfer = $data['pre_transfer'];
+                       $force_period_year = $data['force_period_year'];
+
+                       include(PHPGW_SERVER_ROOT.'/'.'property'.'/inc/export/' 
. $conv_type);
+                       $invoice = new export_conv;
+
+                       $buffer = 
$invoice->overfor($download,$pre_transfer,$force_period_year);
+
+                       return $buffer;
+               }
+
+               function rollback($conv_type,$role_back_date,$rollback_file)
+               {
+                       include (PHPGW_APP_INC . '/export/' . $conv_type);
+                       $invoice = new export_conv;
+                       $buffer = 
$invoice->RullTilbake($role_back_date,$rollback_file);
+                       return $buffer;
+
+               }
+
+               function export_cron($data)
+               {
+                       if($data['enabled']==1)
+                       {
+                               $this->export($data);
+                       }
+               }
+
+       }
+?>
Index: property/inc/class.boactor.inc.php
diff -u property/inc/class.boactor.inc.php:1.7 
property/inc/class.boactor.inc.php:1.8
--- property/inc/class.boactor.inc.php:1.7      Fri Jan 27 14:05:42 2006
+++ property/inc/class.boactor.inc.php  Fri Feb  3 12:05:49 2006
@@ -1,416 +1,416 @@
-<?php
-       /**
-       * phpGroupWare - property: a Facilities Management System.
-       *
-       * @author Sigurd Nes <address@hidden>
-       * @copyright Copyright (C) 2003-2005 Free Software Foundation, Inc. 
http://www.fsf.org/
-       * @license http://www.gnu.org/licenses/gpl.html GNU General Public 
License
-       * @internal Development of this application was funded by 
http://www.bergen.kommune.no/bbb_/ekstern/
-       * @package property
-       * @subpackage admin
-       * @version $Id: class.boactor.inc.php,v 1.7 2006/01/27 14:05:42 
sigurdne Exp $
-       */
-
-       /**
-        * Description
-        * @package property
-        */
-
-       class boactor
-       {
-               var $start;
-               var $query;
-               var $filter;
-               var $sort;
-               var $order;
-               var $cat_id;
-               var $role;
-               var $member_id;
-
-               var $public_functions = array
-               (
-                       'read'                          => True,
-                       'read_single'           => True,
-                       'save'                          => True,
-                       'delete'                        => True,
-                       'check_perms'           => True
-               );
-
-               function boactor($session=False)
-               {
-                       $this->currentapp               = 
$GLOBALS['phpgw_info']['flags']['currentapp'];
-                       $this->so = CreateObject($this->currentapp.'.soactor');
-                       $this->bocommon = 
CreateObject($this->currentapp.'.bocommon');
-
-                       if ($session)
-                       {
-                               $this->read_sessiondata();
-                               $this->use_session = True;
-                       }
-
-                       $start  = get_var('start',array('POST','GET'));
-                       $query  = get_var('query',array('POST','GET'));
-                       $sort   = get_var('sort',array('POST','GET'));
-                       $order  = get_var('order',array('POST','GET'));
-                       $filter = get_var('filter',array('POST','GET'));
-                       $cat_id = get_var('cat_id',array('POST','GET'));
-                       $allrows        = 
get_var('allrows',array('POST','GET'));
-                       $role   = get_var('role',array('POST','GET'));
-                       $member_id      = 
get_var('member_id',array('POST','GET'));
-
-
-                       $this->role     = $role;
-                       $this->so->role = $role;
-
-                       if ($start)
-                       {
-                               $this->start=$start;
-                       }
-                       else
-                       {
-                               $this->start=0;
-                       }
-
-                       if(isset($query))
-                       {
-                               $this->query = $query;
-                       }
-                       if(!empty($filter))
-                       {
-                               $this->filter = $filter;
-                       }
-                       if(isset($sort))
-                       {
-                               $this->sort = $sort;
-                       }
-                       if(isset($order))
-                       {
-                               $this->order = $order;
-                       }
-                       if(isset($cat_id) && !empty($cat_id))
-                       {
-                               $this->cat_id = $cat_id;
-                       }
-                       else
-                       {
-                               unset($this->cat_id);
-                       }
-                       if(isset($allrows))
-                       {
-                               $this->allrows = $allrows;
-                       }
-                       if(isset($member_id))
-                       {
-                               $this->member_id = $member_id;
-                       }
-               }
-
-               function save_sessiondata($data)
-               {
-                       if ($this->use_session)
-                       {
-                               
$GLOBALS['phpgw']->session->appsession('session_data','actor_' . 
$this->role,$data);
-                       }
-               }
-
-               function read_sessiondata()
-               {
-                       $data = 
$GLOBALS['phpgw']->session->appsession('session_data','actor_' . $this->role);
-
-                       //_debug_array($data);
-
-                       $this->start    = $data['start'];
-                       $this->query    = $data['query'];
-                       $this->filter   = $data['filter'];
-                       $this->sort             = $data['sort'];
-                       $this->order    = $data['order'];
-                       $this->cat_id   = $data['cat_id'];
-                       $this->member_id= $data['member_id'];
-                       $this->allrows  = $data['allrows'];
-               }
-
-               function check_perms($has, $needed)
-               {
-                       return (!!($has & $needed) == True);
-               }
-
-
-               function select_category_list($format='',$selected='')
-               {
-                       switch($format)
-                       {
-                               case 'select':
-                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('cat_select'));
-                                       break;
-                               case 'filter':
-                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('cat_filter'));
-                                       break;
-                       }
-
-                       $categories= $this->so->select_category_list();
-
-                       while (is_array($categories) && list(,$category) = 
each($categories))
-                       {
-                               $sel_category = '';
-                               if ($category['id']==$selected)
-                               {
-                                       $sel_category = 'selected';
-                               }
-
-                               $category_list[] = array
-                               (
-                                       'cat_id'        => $category['id'],
-                                       'name'          => $category['name'],
-                                       'selected'      => $sel_category
-                               );
-                       }
-
-                       for ($i=0;$i<count($category_list);$i++)
-                       {
-                               if ($category_list[$i]['selected'] != 
'selected')
-                               {
-                                       unset($category_list[$i]['selected']);
-                               }
-                       }
-
-                       return $category_list;
-               }
-
-               function read()
-               {
-                       $actor = $this->so->read(array('start' => 
$this->start,'query' => $this->query,'sort' => $this->sort,'order' => 
$this->order,
-                                                                               
        'filter' => $this->filter,'cat_id' => 
$this->cat_id,'allrows'=>$this->allrows,'member_id'=>$this->member_id));
-                       $this->total_records = $this->so->total_records;
-
-                       $this->uicols   = $this->so->uicols;
-
-                       for ($i=0; $i<count($actor); $i++)
-                       {
-                               $actor[$i]['entry_date']  = 
$GLOBALS['phpgw']->common->show_date($actor[$i]['date'],$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']);
-                       }
-                       return $actor;
-               }
-
-               function read_single($data)
-               {
-                       $contacts                       = 
CreateObject('phpgwapi.contacts');
-
-                       $vendor = CreateObject($this->currentapp.'.soactor');
-                       $vendor->role = 'vendor';
-
-
-                       $actor  = $this->so->read_single($data);
-                       $dateformat = 
$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
-
-                       $input_type_array = array(
-                               'R' => 'radio',
-                               'CH' => 'checkbox',
-                               'LB' => 'listbox'
-                       );
-
-                       $sep = '/';
-                       $dlarr[strpos($dateformat,'Y')] = 'Y';
-                       $dlarr[strpos($dateformat,'m')] = 'm';
-                       $dlarr[strpos($dateformat,'d')] = 'd';
-                       ksort($dlarr);
-
-                       $dateformat= (implode($sep,$dlarr));
-
-                       $m=0;
-                       for ($i=0;$i<count($actor['attributes']);$i++)
-                       {
-                               if($actor['attributes'][$i]['datatype']=='D' && 
$actor['attributes'][$i]['value'])
-                               {
-                                       $timestamp_date= 
mktime(0,0,0,date(m,strtotime($actor['attributes'][$i]['value'])),date(d,strtotime($actor['attributes'][$i]['value'])),date(y,strtotime($actor['attributes'][$i]['value'])));
-                                       $actor['attributes'][$i]['value']       
= $GLOBALS['phpgw']->common->show_date($timestamp_date,$dateformat);
-                               }
-                               if($actor['attributes'][$i]['datatype']=='AB')
-                               {
-                                       if($actor['attributes'][$i]['value'])
-                                       {
-                                               $contact_data   = 
$contacts->read_single_entry($actor['attributes'][$i]['value'],array('n_given'=>'n_given','n_family'=>'n_family','email'=>'email'));
-                                               
$actor['attributes'][$i]['contact_name']        = $contact_data[0]['n_family'] 
. ', ' . $contact_data[0]['n_given'];
-                                       }
-
-                                       $insert_record_actor[]  = 
$actor['attributes'][$i]['name'];
-                                       $lookup_link            = 
$GLOBALS['phpgw']->link('/index.php','menuaction='.$this->currentapp.'.uilookup.addressbook&column='
 . $actor['attributes'][$i]['name']);
-
-                                       $lookup_functions[$m]['name'] = 
'lookup_'. $actor['attributes'][$i]['name'] .'()';
-                                       $lookup_functions[$m]['action'] = 
'Window1=window.open('."'" . $lookup_link ."'" 
.',"Search","width=800,height=700,toolbar=no,scrollbars=yes,resizable=yes");';
-                                       $m++;
-                               }
-                               
if($actor['attributes'][$i]['datatype']=='VENDOR')
-                               {
-                                       if($actor['attributes'][$i]['value'])
-                                       {
-                                               $vendor_data    = 
$vendor->read_single(array('actor_id'=>$actor['attributes'][$i]['value']));
-
-                                               for 
($n=0;$n<count($vendor_data['attributes']);$n++)
-                                               {
-                                                       
if($vendor_data['attributes'][$n]['name'] == 'org_name')
-                                                       {
-                                                               
$actor['attributes'][$i]['vendor_name']= 
$vendor_data['attributes'][$n]['value'];
-                                                               $n 
=count($vendor_data['attributes']);
-                                                       }
-                                               }
-                                       }
-
-                                       $insert_record_actor[]  = 
$actor['attributes'][$i]['name'];
-                                       $lookup_link            = 
$GLOBALS['phpgw']->link('/index.php','menuaction='.$this->currentapp.'.uilookup.vendor&column='
 . $actor['attributes'][$i]['name']);
-
-                                       $lookup_functions[$m]['name'] = 
'lookup_'. $actor['attributes'][$i]['name'] .'()';
-                                       $lookup_functions[$m]['action'] = 
'Window1=window.open('."'" . $lookup_link ."'" 
.',"Search","width=800,height=700,toolbar=no,scrollbars=yes,resizable=yes");';
-                                       $m++;
-                               }
-                               if($actor['attributes'][$i]['datatype']=='R' || 
$actor['attributes'][$i]['datatype']=='CH' || 
$actor['attributes'][$i]['datatype']=='LB')
-                               {
-                                       $actor['attributes'][$i]['choice']      
= $this->so->read_attrib_choice($actor['attributes'][$i]['attrib_id']);
-                                       
$input_type=$input_type_array[$actor['attributes'][$i]['datatype']];
-
-                                       
if($actor['attributes'][$i]['datatype']=='CH')
-                                       {
-                                               
$actor['attributes'][$i]['value']=unserialize($actor['attributes'][$i]['value']);
-                                               
$actor['attributes'][$i]['choice'] = 
$this->bocommon->select_multi_list_2($actor['attributes'][$i]['value'],$actor['attributes'][$i]['choice'],$input_type);
-
-                                       }
-                                       else
-                                       {
-                                               for 
($j=0;$j<count($actor['attributes'][$i]['choice']);$j++)
-                                               {
-                                                       
$actor['attributes'][$i]['choice'][$j]['input_type']=$input_type;
-                                                       
if($actor['attributes'][$i]['choice'][$j]['id']==$actor['attributes'][$i]['value'])
-                                                       {
-                                                               
$actor['attributes'][$i]['choice'][$j]['checked']='checked';
-                                                       }
-                                               }
-                                       }
-                               }
-
-                               $actor['attributes'][$i]['datatype_text'] = 
$this->bocommon->translate_datatype($actor['attributes'][$i]['datatype']);
-                               $actor['attributes'][$i]['counter']     = $i;
-                               $actor['attributes'][$i]['type_id']     = 
$data['type_id'];
-                       }
-
-                       for ($j=0;$j<count($lookup_functions);$j++)
-                       {
-                               $actor['lookup_functions'] .= 'function ' . 
$lookup_functions[$j]['name'] ."\r\n";
-                               $actor['lookup_functions'] .= '{'."\r\n";
-                               $actor['lookup_functions'] .= 
$lookup_functions[$j]['action'] ."\r\n";
-                               $actor['lookup_functions'] .= '}'."\r\n";
-                       }
-
-                       
$GLOBALS['phpgw']->session->appsession('insert_record_actor',$this->currentapp,$insert_record_actor);
-
-//html_print_r($actor);
-                       return $actor;
-               }
-
-               function save($actor,$values_attribute='')
-               {
-
-                       for ($i=0;$i<count($values_attribute);$i++)
-                       {
-                               if($values_attribute[$i]['datatype']=='CH' && 
$values_attribute[$i]['value'])
-                               {
-                                       $values_attribute[$i]['value'] = 
serialize($values_attribute[$i]['value']);
-                               }
-                               if($values_attribute[$i]['datatype']=='R' && 
$values_attribute[$i]['value'])
-                               {
-                                       $values_attribute[$i]['value'] = 
$values_attribute[$i]['value'][0];
-                               }
-
-                               if($values_attribute[$i]['datatype']=='N' && 
$values_attribute[$i]['value'])
-                               {
-                                       $values_attribute[$i]['value'] = 
str_replace(",",".",$values_attribute[$i]['value']);
-                               }
-
-                               if($values_attribute[$i]['datatype']=='D' && 
$values_attribute[$i]['value'])
-                               {
-                                       $values_attribute[$i]['value'] = 
date($this->bocommon->dateformat,$this->bocommon->date_to_timestamp($values_attribute[$i]['value']));
-                               }
-                       }
-
-                       if ($actor['actor_id'])
-                       {
-                               if ($actor['actor_id'] != 0)
-                               {
-                                       $actor_id = $actor['actor_id'];
-                                       
$receipt=$this->so->edit($actor,$values_attribute);
-                               }
-                       }
-                       else
-                       {
-                               $receipt = 
$this->so->add($actor,$values_attribute);
-                       }
-                       return $receipt;
-               }
-
-               function delete($actor_id='',$id='',$attrib='')
-               {
-                       if ($attrib)
-                       {
-                               $this->so->delete_attrib($id);
-                       }
-                       else
-                       {
-                               $this->so->delete($actor_id);
-                       }
-               }
-
-               function read_attrib($type_id='')
-               {
-                       $attrib = $this->so->read_attrib(array('start' => 
$this->start,'query' => $this->query,'sort' => $this->sort,'order' => 
$this->order,
-                                                                               
        'allrows'=>$this->allrows));
-
-                       for ($i=0; $i<count($attrib); $i++)
-                       {
-                               $attrib[$i]['datatype'] = 
$this->bocommon->translate_datatype($attrib[$i]['datatype']);
-                       }
-
-                       $this->total_records = $this->so->total_records;
-
-                       return $attrib;
-               }
-
-               function read_single_attrib($id)
-               {
-                       return $this->so->read_single_attrib($id);
-               }
-
-               function resort_attrib($data)
-               {
-                       $this->so->resort_attrib($data);
-               }
-
-               function save_attrib($attrib,$action='')
-               {
-                       if ($action=='edit')
-                       {
-                               if ($attrib['id'] != '')
-                               {
-
-                                       $receipt = 
$this->so->edit_attrib($attrib);
-                               }
-                       }
-                       else
-                       {
-                               $receipt = $this->so->add_attrib($attrib);
-                       }
-                       return $receipt;
-               }
-
-               function column_list($selected='',$allrows='')
-               {
-                       if(!$selected)
-                       {
-                               
$selected=$GLOBALS['phpgw_info']['user']['preferences'][$this->currentapp]["actor_columns_"
 . $this->role];
-                       }
-
-                       $columns = 
$this->so->read_attrib(array('allrows'=>$allrows,'column_list'=>True));
-
-                       
$column_list=$this->bocommon->select_multi_list($selected,$columns);
-
-                       return $column_list;
-               }
-       }
-?>
+<?php
+       /**
+       * phpGroupWare - property: a Facilities Management System.
+       *
+       * @author Sigurd Nes <address@hidden>
+       * @copyright Copyright (C) 2003-2005 Free Software Foundation, Inc. 
http://www.fsf.org/
+       * @license http://www.gnu.org/licenses/gpl.html GNU General Public 
License
+       * @internal Development of this application was funded by 
http://www.bergen.kommune.no/bbb_/ekstern/
+       * @package property
+       * @subpackage admin
+       * @version $Id: class.boactor.inc.php,v 1.8 2006/02/03 12:05:49 
sigurdne Exp $
+       */
+
+       /**
+        * Description
+        * @package property
+        */
+
+       class boactor
+       {
+               var $start;
+               var $query;
+               var $filter;
+               var $sort;
+               var $order;
+               var $cat_id;
+               var $role;
+               var $member_id;
+
+               var $public_functions = array
+               (
+                       'read'                          => True,
+                       'read_single'           => True,
+                       'save'                          => True,
+                       'delete'                        => True,
+                       'check_perms'           => True
+               );
+
+               function boactor($session=False)
+               {
+                       $this->currentapp               = 
$GLOBALS['phpgw_info']['flags']['currentapp'];
+                       $this->so = CreateObject($this->currentapp.'.soactor');
+                       $this->bocommon = 
CreateObject($this->currentapp.'.bocommon');
+
+                       if ($session)
+                       {
+                               $this->read_sessiondata();
+                               $this->use_session = True;
+                       }
+
+                       $start  = get_var('start',array('POST','GET'));
+                       $query  = get_var('query',array('POST','GET'));
+                       $sort   = get_var('sort',array('POST','GET'));
+                       $order  = get_var('order',array('POST','GET'));
+                       $filter = get_var('filter',array('POST','GET'));
+                       $cat_id = get_var('cat_id',array('POST','GET'));
+                       $allrows        = 
get_var('allrows',array('POST','GET'));
+                       $role   = get_var('role',array('POST','GET'));
+                       $member_id      = 
get_var('member_id',array('POST','GET'));
+
+
+                       $this->role     = $role;
+                       $this->so->role = $role;
+
+                       if ($start)
+                       {
+                               $this->start=$start;
+                       }
+                       else
+                       {
+                               $this->start=0;
+                       }
+
+                       if(isset($query))
+                       {
+                               $this->query = $query;
+                       }
+                       if(!empty($filter))
+                       {
+                               $this->filter = $filter;
+                       }
+                       if(isset($sort))
+                       {
+                               $this->sort = $sort;
+                       }
+                       if(isset($order))
+                       {
+                               $this->order = $order;
+                       }
+                       if(isset($cat_id) && !empty($cat_id))
+                       {
+                               $this->cat_id = $cat_id;
+                       }
+                       else
+                       {
+                               unset($this->cat_id);
+                       }
+                       if(isset($allrows))
+                       {
+                               $this->allrows = $allrows;
+                       }
+                       if(isset($member_id))
+                       {
+                               $this->member_id = $member_id;
+                       }
+               }
+
+               function save_sessiondata($data)
+               {
+                       if ($this->use_session)
+                       {
+                               
$GLOBALS['phpgw']->session->appsession('session_data','actor_' . 
$this->role,$data);
+                       }
+               }
+
+               function read_sessiondata()
+               {
+                       $data = 
$GLOBALS['phpgw']->session->appsession('session_data','actor_' . $this->role);
+
+                       //_debug_array($data);
+
+                       $this->start    = $data['start'];
+                       $this->query    = $data['query'];
+                       $this->filter   = $data['filter'];
+                       $this->sort             = $data['sort'];
+                       $this->order    = $data['order'];
+                       $this->cat_id   = $data['cat_id'];
+                       $this->member_id= $data['member_id'];
+                       $this->allrows  = $data['allrows'];
+               }
+
+               function check_perms($has, $needed)
+               {
+                       return (!!($has & $needed) == True);
+               }
+
+
+               function select_category_list($format='',$selected='')
+               {
+                       switch($format)
+                       {
+                               case 'select':
+                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('cat_select'));
+                                       break;
+                               case 'filter':
+                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('cat_filter'));
+                                       break;
+                       }
+
+                       $categories= $this->so->select_category_list();
+
+                       while (is_array($categories) && list(,$category) = 
each($categories))
+                       {
+                               $sel_category = '';
+                               if ($category['id']==$selected)
+                               {
+                                       $sel_category = 'selected';
+                               }
+
+                               $category_list[] = array
+                               (
+                                       'cat_id'        => $category['id'],
+                                       'name'          => $category['name'],
+                                       'selected'      => $sel_category
+                               );
+                       }
+
+                       for ($i=0;$i<count($category_list);$i++)
+                       {
+                               if ($category_list[$i]['selected'] != 
'selected')
+                               {
+                                       unset($category_list[$i]['selected']);
+                               }
+                       }
+
+                       return $category_list;
+               }
+
+               function read()
+               {
+                       $actor = $this->so->read(array('start' => 
$this->start,'query' => $this->query,'sort' => $this->sort,'order' => 
$this->order,
+                                                                               
        'filter' => $this->filter,'cat_id' => 
$this->cat_id,'allrows'=>$this->allrows,'member_id'=>$this->member_id));
+                       $this->total_records = $this->so->total_records;
+
+                       $this->uicols   = $this->so->uicols;
+
+                       for ($i=0; $i<count($actor); $i++)
+                       {
+                               $actor[$i]['entry_date']  = 
$GLOBALS['phpgw']->common->show_date($actor[$i]['date'],$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']);
+                       }
+                       return $actor;
+               }
+
+               function read_single($data)
+               {
+                       $contacts                       = 
CreateObject('phpgwapi.contacts');
+
+                       $vendor = CreateObject($this->currentapp.'.soactor');
+                       $vendor->role = 'vendor';
+
+
+                       $actor  = $this->so->read_single($data);
+                       $dateformat = 
$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
+
+                       $input_type_array = array(
+                               'R' => 'radio',
+                               'CH' => 'checkbox',
+                               'LB' => 'listbox'
+                       );
+
+                       $sep = '/';
+                       $dlarr[strpos($dateformat,'Y')] = 'Y';
+                       $dlarr[strpos($dateformat,'m')] = 'm';
+                       $dlarr[strpos($dateformat,'d')] = 'd';
+                       ksort($dlarr);
+
+                       $dateformat= (implode($sep,$dlarr));
+
+                       $m=0;
+                       for ($i=0;$i<count($actor['attributes']);$i++)
+                       {
+                               if($actor['attributes'][$i]['datatype']=='D' && 
$actor['attributes'][$i]['value'])
+                               {
+                                       $timestamp_date= 
mktime(0,0,0,date(m,strtotime($actor['attributes'][$i]['value'])),date(d,strtotime($actor['attributes'][$i]['value'])),date(y,strtotime($actor['attributes'][$i]['value'])));
+                                       $actor['attributes'][$i]['value']       
= $GLOBALS['phpgw']->common->show_date($timestamp_date,$dateformat);
+                               }
+                               if($actor['attributes'][$i]['datatype']=='AB')
+                               {
+                                       if($actor['attributes'][$i]['value'])
+                                       {
+                                               $contact_data   = 
$contacts->read_single_entry($actor['attributes'][$i]['value'],array('n_given'=>'n_given','n_family'=>'n_family','email'=>'email'));
+                                               
$actor['attributes'][$i]['contact_name']        = $contact_data[0]['n_family'] 
. ', ' . $contact_data[0]['n_given'];
+                                       }
+
+                                       $insert_record_actor[]  = 
$actor['attributes'][$i]['name'];
+                                       $lookup_link            = 
$GLOBALS['phpgw']->link('/index.php','menuaction='.$this->currentapp.'.uilookup.addressbook&column='
 . $actor['attributes'][$i]['name']);
+
+                                       $lookup_functions[$m]['name'] = 
'lookup_'. $actor['attributes'][$i]['name'] .'()';
+                                       $lookup_functions[$m]['action'] = 
'Window1=window.open('."'" . $lookup_link ."'" 
.',"Search","width=800,height=700,toolbar=no,scrollbars=yes,resizable=yes");';
+                                       $m++;
+                               }
+                               
if($actor['attributes'][$i]['datatype']=='VENDOR')
+                               {
+                                       if($actor['attributes'][$i]['value'])
+                                       {
+                                               $vendor_data    = 
$vendor->read_single(array('actor_id'=>$actor['attributes'][$i]['value']));
+
+                                               for 
($n=0;$n<count($vendor_data['attributes']);$n++)
+                                               {
+                                                       
if($vendor_data['attributes'][$n]['name'] == 'org_name')
+                                                       {
+                                                               
$actor['attributes'][$i]['vendor_name']= 
$vendor_data['attributes'][$n]['value'];
+                                                               $n 
=count($vendor_data['attributes']);
+                                                       }
+                                               }
+                                       }
+
+                                       $insert_record_actor[]  = 
$actor['attributes'][$i]['name'];
+                                       $lookup_link            = 
$GLOBALS['phpgw']->link('/index.php','menuaction='.$this->currentapp.'.uilookup.vendor&column='
 . $actor['attributes'][$i]['name']);
+
+                                       $lookup_functions[$m]['name'] = 
'lookup_'. $actor['attributes'][$i]['name'] .'()';
+                                       $lookup_functions[$m]['action'] = 
'Window1=window.open('."'" . $lookup_link ."'" 
.',"Search","width=800,height=700,toolbar=no,scrollbars=yes,resizable=yes");';
+                                       $m++;
+                               }
+                               if($actor['attributes'][$i]['datatype']=='R' || 
$actor['attributes'][$i]['datatype']=='CH' || 
$actor['attributes'][$i]['datatype']=='LB')
+                               {
+                                       $actor['attributes'][$i]['choice']      
= $this->so->read_attrib_choice($actor['attributes'][$i]['attrib_id']);
+                                       
$input_type=$input_type_array[$actor['attributes'][$i]['datatype']];
+
+                                       
if($actor['attributes'][$i]['datatype']=='CH')
+                                       {
+                                               
$actor['attributes'][$i]['value']=unserialize($actor['attributes'][$i]['value']);
+                                               
$actor['attributes'][$i]['choice'] = 
$this->bocommon->select_multi_list_2($actor['attributes'][$i]['value'],$actor['attributes'][$i]['choice'],$input_type);
+
+                                       }
+                                       else
+                                       {
+                                               for 
($j=0;$j<count($actor['attributes'][$i]['choice']);$j++)
+                                               {
+                                                       
$actor['attributes'][$i]['choice'][$j]['input_type']=$input_type;
+                                                       
if($actor['attributes'][$i]['choice'][$j]['id']==$actor['attributes'][$i]['value'])
+                                                       {
+                                                               
$actor['attributes'][$i]['choice'][$j]['checked']='checked';
+                                                       }
+                                               }
+                                       }
+                               }
+
+                               $actor['attributes'][$i]['datatype_text'] = 
$this->bocommon->translate_datatype($actor['attributes'][$i]['datatype']);
+                               $actor['attributes'][$i]['counter']     = $i;
+                               $actor['attributes'][$i]['type_id']     = 
$data['type_id'];
+                       }
+
+                       for ($j=0;$j<count($lookup_functions);$j++)
+                       {
+                               $actor['lookup_functions'] .= 'function ' . 
$lookup_functions[$j]['name'] ."\r\n";
+                               $actor['lookup_functions'] .= '{'."\r\n";
+                               $actor['lookup_functions'] .= 
$lookup_functions[$j]['action'] ."\r\n";
+                               $actor['lookup_functions'] .= '}'."\r\n";
+                       }
+
+                       
$GLOBALS['phpgw']->session->appsession('insert_record_actor',$this->currentapp,$insert_record_actor);
+
+//html_print_r($actor);
+                       return $actor;
+               }
+
+               function save($actor,$values_attribute='')
+               {
+
+                       for ($i=0;$i<count($values_attribute);$i++)
+                       {
+                               if($values_attribute[$i]['datatype']=='CH' && 
$values_attribute[$i]['value'])
+                               {
+                                       $values_attribute[$i]['value'] = 
serialize($values_attribute[$i]['value']);
+                               }
+                               if($values_attribute[$i]['datatype']=='R' && 
$values_attribute[$i]['value'])
+                               {
+                                       $values_attribute[$i]['value'] = 
$values_attribute[$i]['value'][0];
+                               }
+
+                               if($values_attribute[$i]['datatype']=='N' && 
$values_attribute[$i]['value'])
+                               {
+                                       $values_attribute[$i]['value'] = 
str_replace(",",".",$values_attribute[$i]['value']);
+                               }
+
+                               if($values_attribute[$i]['datatype']=='D' && 
$values_attribute[$i]['value'])
+                               {
+                                       $values_attribute[$i]['value'] = 
date($this->bocommon->dateformat,$this->bocommon->date_to_timestamp($values_attribute[$i]['value']));
+                               }
+                       }
+
+                       if ($actor['actor_id'])
+                       {
+                               if ($actor['actor_id'] != 0)
+                               {
+                                       $actor_id = $actor['actor_id'];
+                                       
$receipt=$this->so->edit($actor,$values_attribute);
+                               }
+                       }
+                       else
+                       {
+                               $receipt = 
$this->so->add($actor,$values_attribute);
+                       }
+                       return $receipt;
+               }
+
+               function delete($actor_id='',$id='',$attrib='')
+               {
+                       if ($attrib)
+                       {
+                               $this->so->delete_attrib($id);
+                       }
+                       else
+                       {
+                               $this->so->delete($actor_id);
+                       }
+               }
+
+               function read_attrib($type_id='')
+               {
+                       $attrib = $this->so->read_attrib(array('start' => 
$this->start,'query' => $this->query,'sort' => $this->sort,'order' => 
$this->order,
+                                                                               
        'allrows'=>$this->allrows));
+
+                       for ($i=0; $i<count($attrib); $i++)
+                       {
+                               $attrib[$i]['datatype'] = 
$this->bocommon->translate_datatype($attrib[$i]['datatype']);
+                       }
+
+                       $this->total_records = $this->so->total_records;
+
+                       return $attrib;
+               }
+
+               function read_single_attrib($id)
+               {
+                       return $this->so->read_single_attrib($id);
+               }
+
+               function resort_attrib($data)
+               {
+                       $this->so->resort_attrib($data);
+               }
+
+               function save_attrib($attrib,$action='')
+               {
+                       if ($action=='edit')
+                       {
+                               if ($attrib['id'] != '')
+                               {
+
+                                       $receipt = 
$this->so->edit_attrib($attrib);
+                               }
+                       }
+                       else
+                       {
+                               $receipt = $this->so->add_attrib($attrib);
+                       }
+                       return $receipt;
+               }
+
+               function column_list($selected='',$allrows='')
+               {
+                       if(!$selected)
+                       {
+                               
$selected=$GLOBALS['phpgw_info']['user']['preferences'][$this->currentapp]["actor_columns_"
 . $this->role];
+                       }
+
+                       $columns = 
$this->so->read_attrib(array('allrows'=>$allrows,'column_list'=>True));
+
+                       
$column_list=$this->bocommon->select_multi_list($selected,$columns);
+
+                       return $column_list;
+               }
+       }
+?>
Index: property/inc/class.boadmin.inc.php
diff -u property/inc/class.boadmin.inc.php:1.7 
property/inc/class.boadmin.inc.php:1.8
--- property/inc/class.boadmin.inc.php:1.7      Fri Jan 27 14:05:43 2006
+++ property/inc/class.boadmin.inc.php  Fri Feb  3 12:05:49 2006
@@ -1,508 +1,508 @@
-<?php
-       /**
-       * phpGroupWare - property: a Facilities Management System.
-       *
-       * @author Sigurd Nes <address@hidden>
-       * @copyright Copyright (C) 2003-2005 Free Software Foundation, Inc. 
http://www.fsf.org/
-       * @license http://www.gnu.org/licenses/gpl.html GNU General Public 
License
-       * @internal Development of this application was funded by 
http://www.bergen.kommune.no/bbb_/ekstern/
-       * @package property
-       * @subpackage admin
-       * @version $Id: class.boadmin.inc.php,v 1.7 2006/01/27 14:05:43 
sigurdne Exp $
-       */
-
-       /**
-        * Description
-        * @package property
-        */
-
-       class boadmin
-       {
-               var $start;
-               var $query;
-               var $filter;
-               var $sort;
-               var $order;
-               var $cat_id;
-
-               function boadmin($session='')
-               {
-                       $this->currentapp       = 
$GLOBALS['phpgw_info']['flags']['currentapp'];
-                       $this->so                       = 
CreateObject($this->currentapp.'.soadmin');
-                       $this->acl2             = 
CreateObject($this->currentapp.'.acl2','##DEFAULT##','##DEFAULT##');
-                       $this->right            = array(1,2,4,8,16,32,64,128);
-                       $this->app_id           
=$GLOBALS['phpgw']->applications->data[$GLOBALS['phpgw_info']['flags']['currentapp']]['id'];
-
-                       if ($session)
-                       {
-                               $this->read_sessiondata();
-                               $this->use_session = True;
-                       }
-
-
-                       $start  = get_var('start',array('POST','GET'));
-                       $query  = get_var('query',array('POST','GET'));
-                       $sort   = get_var('sort',array('POST','GET'));
-                       $order  = get_var('order',array('POST','GET'));
-                       $filter = get_var('filter',array('POST','GET'));
-                       $cat_id = get_var('cat_id',array('POST','GET'));
-                       $permission     = 
get_var('permission',array('POST','GET'));
-       //              $location       = 
get_var('location',array('POST','GET')); // don't work for some reason...
-                       $module = get_var('module',array('POST','GET'));
-                       $granting_group = 
get_var('granting_group',array('POST','GET'));
-                       $allrows        = 
get_var('allrows',array('POST','GET'));
-
-                       if ($start)
-                       {
-                               $this->start=$start;
-                       }
-                       else
-                       {
-                               $this->start=0;
-                       }
-
-                       if(isset($query))
-                       {
-                               $this->query = $query;
-                       }
-                       if(isset($filter))
-                       {
-                               $this->filter = $filter;
-                       }
-                       if(isset($sort))
-                       {
-                               $this->sort = $sort;
-                       }
-                       if(isset($order))
-                       {
-                               $this->order = $order;
-                       }
-                       if(isset($cat_id))
-                       {
-                               $this->cat_id = $cat_id;
-                       }
-                       if(isset($module))
-                       {
-                               $this->location = $module;
-                       }
-                       if(isset($granting_group))
-                       {
-                               $this->granting_group = $granting_group;
-                       }
-                       if(isset($allrows))
-                       {
-                               $this->allrows = $allrows;
-                       }
-
-                       if ($this->allrows)
-                       {
-                               $this->start = -1;
-                               $this->offset = -1;
-                       }
-               }
-
-
-               function read_sessiondata()
-               {
-                       $data = 
$GLOBALS['phpgw']->session->appsession('session_data','fm_admin');
-
-                       $this->start            = $data['start'];
-                       $this->query            = $data['query'];
-                       $this->filter           = $data['filter'];
-                       $this->sort                     = $data['sort'];
-                       $this->order            = $data['order'];
-                       $this->cat_id           = $data['cat_id'];
-                       $this->location         = $data['location'];
-                       $this->granting_group   = $data['granting_group'];
-                       $this->allrows  = $data['allrows'];
-               }
-
-               function save_sessiondata($data)
-               {
-                       if ($this->use_session)
-                       {
-                               
$GLOBALS['phpgw']->session->appsession('session_data','fm_admin',$data);
-                       }
-               }
-
-
-
-               function select_location($format='',$selected='',$grant='')
-               {
-
-                       switch($format)
-                       {
-                               case 'select':
-                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('select_location'));
-                                       break;
-                               case 'filter':
-                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('filter_location'));
-                                       break;
-                       }
-
-                       $locations= $this->so->select_location($grant);
-
-                       while (is_array($locations) && list(,$loc) = 
each($locations))
-                       {
-                               $sel_loc = '';
-                               if ($loc['id']==$selected)
-                               {
-                                       $sel_loc = 'selected';
-                               }
-
-                               $location_list[] = array
-                               (
-                                       'id'            => $loc['id'],
-                                       'descr'         => $loc['id'] . ' [' . 
$loc['descr'] . ']',
-                                       'selected'      => $sel_loc
-                               );
-                       }
-
-                       for ($i=0;$i<count($location_list);$i++)
-                       {
-                               if ($location_list[$i]['selected'] != 
'selected')
-                               {
-                                       unset($location_list[$i]['selected']);
-                               }
-                       }
-
-                       return $location_list;
-               }
-
-               function select_category_list($format='',$selected='')
-               {
-                       switch($format)
-                       {
-                               case 'select':
-                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('cat_select'));
-                                       break;
-                               case 'filter':
-                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('cat_filter'));
-                                       break;
-                       }
-
-
-                       $categories[0]['id']    = 'groups';
-                       $categories[0]['name']  = lang('Groups');
-                       $categories[1]['id']    = 'accounts';
-                       $categories[1]['name']  = lang('Users');
-
-                       while (is_array($categories) && list(,$category) = 
each($categories))
-                       {
-                               $sel_category = '';
-                               if ($category['id']==$selected)
-                               {
-                                       $sel_category = 'selected';
-                               }
-
-                               $category_list[] = array
-                               (
-                                       'cat_id'        => $category['id'],
-                                       'name'          => $category['name'],
-                                       'selected'      => $sel_category
-                               );
-                       }
-
-                       for ($i=0;$i<count($category_list);$i++)
-                       {
-                               if ($category_list[$i]['selected'] != 
'selected')
-                               {
-                                       unset($category_list[$i]['selected']);
-                               }
-                       }
-
-                       return $category_list;
-               }
-
-               function set_permission2($values,$r_processed,$type)
-               {
-                       @reset($values);
-                       $totalacl = array();
-                       while(list($rowinfo,$perm) = each($values))
-                       {
-                               list($user_id,$rights) = split('_',$rowinfo);
-                               $totalacl[$user_id] += $rights;
-                       }
-                       @reset($totalacl);
-                       while(list($user_id,$rights) = @each($totalacl))
-                       {
-                               $user_checked[]=$user_id;
-
-                               
$this->acl2->set($this->location,$rights,$user_id,$type);
-                       }
-
-                       if(is_array($r_processed) && is_array($user_checked))
-                       {
-                               $user_delete    = array_diff($r_processed, 
$user_checked);
-                       }
-                       else
-                       {
-                               $user_delete    = $r_processed;
-                       }
-                       if(is_array($user_delete) && count($user_delete)>0)
-                       {
-                               $user_delete= explode("_",implode("_", 
$user_delete));
-
-                               $this->remove_permission($user_delete,$type);
-                       }
-               }
-
-               function set_permission($values,$r_processed,$initials)
-               {
-                       if($initials)
-                       {
-                               $this->so->set_initials($initials);
-                       }
-
-                       $r_processed=explode("_",$r_processed);
-
-                       if(!$values['right'])
-                       {
-                               $values['right'] = array();
-                       }
-                       if(!$values['mask'])
-                       {
-                               $values['mask'] = array();
-                       }
-
-                       $this->set_permission2($values['right'],$r_processed,0);
-                       $this->set_permission2($values['mask'],$r_processed,1);
-
-//     $this->acl2->check('.invoice.test', $rights,$user_id);
-//     echo 'rights_cache:<pre>'; print_r($this->acl2->rights_cache); echo 
'</pre>';
-
-                       $receipt['message'][] = array('msg' => 
lang('permissions are updated!'));
-                       return $receipt;
-               }
-
-               function set_grant2($values,$r_processed,$type)
-               {
-                       @reset($values);
-                       $totalacl = array();
-                       while(list($rowinfo,$perm) = each($values))
-                       {
-                               list($user_id,$rights) = split('_',$rowinfo);
-                               $totalacl[$user_id] += $rights;
-                       }
-                       @reset($totalacl);
-                       while(list($user_id,$rights) = @each($totalacl))
-                       {
-                               $user_checked[]=$user_id;
-
-                               
$this->acl2->set_grant($this->location,$rights,$user_id,$type,$this->granting_group);
-                       }
-
-                       if(is_array($r_processed) && is_array($user_checked))
-                       {
-                               $user_delete    = array_diff($r_processed, 
$user_checked);
-                       }
-                       else
-                       {
-                               $user_delete    = $r_processed;
-                       }
-                       if(is_array($user_delete) && count($user_delete)>0)
-                       {
-                               $user_delete= explode("_",implode("_", 
$user_delete));
-
-                               $this->remove_grant($user_delete,$type);
-                       }
-
-               }
-
-               function set_grant($values,$r_processed)
-               {
-                       $r_processed=explode("_",$r_processed);
-
-                       if(!$values['right'])
-                       {
-                               $values['right'] = array();
-                       }
-                       if(!$values['mask'])
-                       {
-                               $values['mask'] = array();
-                       }
-
-                       $this->set_grant2($values['right'],$r_processed,0);
-                       $this->set_grant2($values['mask'],$r_processed,1);
-
-                       $receipt['message'][] = array('msg' => 
lang('permissions are updated!'));
-                       return $receipt;
-               }
-
-               function remove_permission($user_delete,$type)
-               {
-
-                       $right=$this->right;
-
-                       for ($i=0;$i<count($user_delete);$i++)
-                       {
-                               for ($j=0;$j<count($right);$j++)
-                               {
-                                       
$this->acl2->remove($this->location,$right[$j],$user_delete[$i],$type);
-                               }
-                       }
-               }
-
-               function remove_grant($user_delete,$type)
-               {
-
-                       $right=$this->right;
-
-                       for ($i=0;$i<count($user_delete);$i++)
-                       {
-                               for ($j=0;$j<count($right);$j++)
-                               {
-                                       
$this->acl2->remove_grant($this->location,$right[$j],$user_delete[$i],$type,$this->granting_group);
-                               }
-                       }
-               }
-
-               function get_user_list($type='',$app_id='')
-               {
-                       if($this->granting_group)
-                       {
-                               $owner = $this->granting_group;
-                       }
-                       else
-                       {
-                               $owner = 
$GLOBALS['phpgw_info']['user']['account_id'];
-                       }
-
-                       $right=$this->right;
-
-                       $GLOBALS['phpgw']->accounts->account_id = $owner;
-
-                       $allusers = 
$GLOBALS['phpgw']->accounts->get_list($type, $this->start,$this->sort, 
$this->order, $this->query, $this->offset);
-
-                       if (isSet($allusers) AND is_array($allusers))
-                       {
-                               $j=0;
-                               foreach($allusers as $account)
-                               {
-                                       
if($account['account_id']!=$GLOBALS['phpgw_info']['user']['account_id'] || 
$this->granting_group)
-                                       {
-                                               $user_list[$j]['account_id']    
        = $account['account_id'];
-                                               $user_list[$j]['account_lid']   
        = $account['account_lid'];
-                                               
$user_list[$j]['account_firstname'] = $account['account_firstname'];
-                                               
$user_list[$j]['account_lastname']      = $account['account_lastname'];
-                                               $user_list[$j]['initials']      
                = $this->so->get_initials($account['account_id']);
-
-                                               $count_right=count($right);
-                                               for ($i=0;$i<$count_right;$i++)
-                                               {
-                                                       
if($this->acl2->check_grant($owner,$this->location, 
$right[$i],$account['account_id'],$app_id,True,0,True))
-                                                       {
-                                                               
$user_list[$j]['right'][$right[$i]] = 'checked';
-                                                       }
-                                                       
if($this->acl2->check_grant($owner,$this->location, 
$right[$i],$account['account_id'],$this->app_id,True,1,True))
-                                                       {
-                                                               
$user_list[$j]['mask'][$right[$i]] = 'checked';
-                                                       }
-                                               }
-
-                                               if 
(isSet($user_list[$j]['mask']) AND is_array($user_list[$j]['mask']))
-                                               {
-                                                       $result_temp    = 
@array_diff(array_keys($user_list[$j]['right']), 
array_keys($user_list[$j]['mask']));
-                                                       if (isSet($result_temp) 
AND is_array($result_temp))
-                                                       {
-                                                               
foreach($result_temp as $temp)
-                                                               {
-                                                                       
$user_list[$j]['result'][$temp] = 'checked';
-                                                               }
-                                                       }
-                                               }
-                                               else
-                                               {
-                                                       
$user_list[$j]['result'] = $user_list[$j]['right'];
-                                               }
-
-                                               $user_list[$j]['right']['type'] 
= 'right';
-                                               $user_list[$j]['mask']['type'] 
= 'mask';
-                                               
$user_list[$j]['result']['type'] = 'result';
-
-                                               $j++;
-                                       }
-                               }
-                       }
-
-                       $this->total_records = 
$GLOBALS['phpgw']->accounts->total;
-
-//_debug_array($user_list);
-
-                       return $user_list;
-               }
-
-
-               function get_user_list2($type='',$app_id='')
-               {
-                       $right=$this->right;
-
-                       $allusers = 
$GLOBALS['phpgw']->accounts->get_list($type, $this->start,$this->sort, 
$this->order, $this->query, $this->offset);
-
-                       if (isSet($allusers) AND is_array($allusers))
-                       {
-                               $j=0;
-                               foreach($allusers as $account)
-                               {
-                                       $user_list[$j]['account_id']            
= $account['account_id'];
-                                       $user_list[$j]['account_lid']           
= $account['account_lid'];
-                                       $user_list[$j]['account_firstname'] = 
$account['account_firstname'];
-                                       $user_list[$j]['account_lastname']      
= $account['account_lastname'];
-                                       $user_list[$j]['initials']              
        = $this->so->get_initials($account['account_id']);
-
-                                       $count_right=count($right);
-                                       for ($i=0;$i<$count_right;$i++)
-                                       {
-                                               
if($this->acl2->check($this->location, 
$right[$i],$account['account_id'],$this->app_id,True,0,True))
-                                               {
-                                                       
$user_list[$j]['right'][$right[$i]] = 'checked';
-                                               }
-                                               
if($this->acl2->check($this->location, 
$right[$i],$account['account_id'],$this->app_id,True,1,True))
-                                               {
-                                                       
$user_list[$j]['mask'][$right[$i]] = 'checked';
-                                               }
-                                       }
-
-                                       if (isSet($user_list[$j]['mask']) AND 
is_array($user_list[$j]['mask']))
-                                       {
-                                               $result_temp    = 
@array_diff(array_keys($user_list[$j]['right']), 
array_keys($user_list[$j]['mask']));
-                                               if (isSet($result_temp) AND 
is_array($result_temp))
-                                               {
-                                                       foreach($result_temp as 
$temp)
-                                                       {
-                                                               
$user_list[$j]['result'][$temp] = 'checked';
-                                                       }
-                                               }
-                                       }
-                                       else
-                                       {
-                                               $user_list[$j]['result'] = 
$user_list[$j]['right'];
-                                       }
-
-                                       $user_list[$j]['right']['type'] = 
'right';
-                                       $user_list[$j]['mask']['type'] = 'mask';
-                                       $user_list[$j]['result']['type'] = 
'result';
-
-                                       $j++;
-                               }
-                       }
-
-                       $this->total_records = 
$GLOBALS['phpgw']->accounts->total;
-
-                       return $user_list;
-               }
-
-               function read_fm_id()
-               {
-
-                       $fm_ids = $this->so->read_fm_id();
-                       return $fm_ids;
-
-               }
-               function edit_id($values='')
-               {
-                       return $this->so->edit_id($values);
-
-               }
-       }
-?>
+<?php
+       /**
+       * phpGroupWare - property: a Facilities Management System.
+       *
+       * @author Sigurd Nes <address@hidden>
+       * @copyright Copyright (C) 2003-2005 Free Software Foundation, Inc. 
http://www.fsf.org/
+       * @license http://www.gnu.org/licenses/gpl.html GNU General Public 
License
+       * @internal Development of this application was funded by 
http://www.bergen.kommune.no/bbb_/ekstern/
+       * @package property
+       * @subpackage admin
+       * @version $Id: class.boadmin.inc.php,v 1.8 2006/02/03 12:05:49 
sigurdne Exp $
+       */
+
+       /**
+        * Description
+        * @package property
+        */
+
+       class boadmin
+       {
+               var $start;
+               var $query;
+               var $filter;
+               var $sort;
+               var $order;
+               var $cat_id;
+
+               function boadmin($session='')
+               {
+                       $this->currentapp       = 
$GLOBALS['phpgw_info']['flags']['currentapp'];
+                       $this->so                       = 
CreateObject($this->currentapp.'.soadmin');
+                       $this->acl2             = 
CreateObject($this->currentapp.'.acl2','##DEFAULT##','##DEFAULT##');
+                       $this->right            = array(1,2,4,8,16,32,64,128);
+                       $this->app_id           
=$GLOBALS['phpgw']->applications->data[$GLOBALS['phpgw_info']['flags']['currentapp']]['id'];
+
+                       if ($session)
+                       {
+                               $this->read_sessiondata();
+                               $this->use_session = True;
+                       }
+
+
+                       $start  = get_var('start',array('POST','GET'));
+                       $query  = get_var('query',array('POST','GET'));
+                       $sort   = get_var('sort',array('POST','GET'));
+                       $order  = get_var('order',array('POST','GET'));
+                       $filter = get_var('filter',array('POST','GET'));
+                       $cat_id = get_var('cat_id',array('POST','GET'));
+                       $permission     = 
get_var('permission',array('POST','GET'));
+       //              $location       = 
get_var('location',array('POST','GET')); // don't work for some reason...
+                       $module = get_var('module',array('POST','GET'));
+                       $granting_group = 
get_var('granting_group',array('POST','GET'));
+                       $allrows        = 
get_var('allrows',array('POST','GET'));
+
+                       if ($start)
+                       {
+                               $this->start=$start;
+                       }
+                       else
+                       {
+                               $this->start=0;
+                       }
+
+                       if(isset($query))
+                       {
+                               $this->query = $query;
+                       }
+                       if(isset($filter))
+                       {
+                               $this->filter = $filter;
+                       }
+                       if(isset($sort))
+                       {
+                               $this->sort = $sort;
+                       }
+                       if(isset($order))
+                       {
+                               $this->order = $order;
+                       }
+                       if(isset($cat_id))
+                       {
+                               $this->cat_id = $cat_id;
+                       }
+                       if(isset($module))
+                       {
+                               $this->location = $module;
+                       }
+                       if(isset($granting_group))
+                       {
+                               $this->granting_group = $granting_group;
+                       }
+                       if(isset($allrows))
+                       {
+                               $this->allrows = $allrows;
+                       }
+
+                       if ($this->allrows)
+                       {
+                               $this->start = -1;
+                               $this->offset = -1;
+                       }
+               }
+
+
+               function read_sessiondata()
+               {
+                       $data = 
$GLOBALS['phpgw']->session->appsession('session_data','fm_admin');
+
+                       $this->start            = $data['start'];
+                       $this->query            = $data['query'];
+                       $this->filter           = $data['filter'];
+                       $this->sort                     = $data['sort'];
+                       $this->order            = $data['order'];
+                       $this->cat_id           = $data['cat_id'];
+                       $this->location         = $data['location'];
+                       $this->granting_group   = $data['granting_group'];
+                       $this->allrows  = $data['allrows'];
+               }
+
+               function save_sessiondata($data)
+               {
+                       if ($this->use_session)
+                       {
+                               
$GLOBALS['phpgw']->session->appsession('session_data','fm_admin',$data);
+                       }
+               }
+
+
+
+               function select_location($format='',$selected='',$grant='')
+               {
+
+                       switch($format)
+                       {
+                               case 'select':
+                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('select_location'));
+                                       break;
+                               case 'filter':
+                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('filter_location'));
+                                       break;
+                       }
+
+                       $locations= $this->so->select_location($grant);
+
+                       while (is_array($locations) && list(,$loc) = 
each($locations))
+                       {
+                               $sel_loc = '';
+                               if ($loc['id']==$selected)
+                               {
+                                       $sel_loc = 'selected';
+                               }
+
+                               $location_list[] = array
+                               (
+                                       'id'            => $loc['id'],
+                                       'descr'         => $loc['id'] . ' [' . 
$loc['descr'] . ']',
+                                       'selected'      => $sel_loc
+                               );
+                       }
+
+                       for ($i=0;$i<count($location_list);$i++)
+                       {
+                               if ($location_list[$i]['selected'] != 
'selected')
+                               {
+                                       unset($location_list[$i]['selected']);
+                               }
+                       }
+
+                       return $location_list;
+               }
+
+               function select_category_list($format='',$selected='')
+               {
+                       switch($format)
+                       {
+                               case 'select':
+                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('cat_select'));
+                                       break;
+                               case 'filter':
+                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('cat_filter'));
+                                       break;
+                       }
+
+
+                       $categories[0]['id']    = 'groups';
+                       $categories[0]['name']  = lang('Groups');
+                       $categories[1]['id']    = 'accounts';
+                       $categories[1]['name']  = lang('Users');
+
+                       while (is_array($categories) && list(,$category) = 
each($categories))
+                       {
+                               $sel_category = '';
+                               if ($category['id']==$selected)
+                               {
+                                       $sel_category = 'selected';
+                               }
+
+                               $category_list[] = array
+                               (
+                                       'cat_id'        => $category['id'],
+                                       'name'          => $category['name'],
+                                       'selected'      => $sel_category
+                               );
+                       }
+
+                       for ($i=0;$i<count($category_list);$i++)
+                       {
+                               if ($category_list[$i]['selected'] != 
'selected')
+                               {
+                                       unset($category_list[$i]['selected']);
+                               }
+                       }
+
+                       return $category_list;
+               }
+
+               function set_permission2($values,$r_processed,$type)
+               {
+                       @reset($values);
+                       $totalacl = array();
+                       while(list($rowinfo,$perm) = each($values))
+                       {
+                               list($user_id,$rights) = split('_',$rowinfo);
+                               $totalacl[$user_id] += $rights;
+                       }
+                       @reset($totalacl);
+                       while(list($user_id,$rights) = @each($totalacl))
+                       {
+                               $user_checked[]=$user_id;
+
+                               
$this->acl2->set($this->location,$rights,$user_id,$type);
+                       }
+
+                       if(is_array($r_processed) && is_array($user_checked))
+                       {
+                               $user_delete    = array_diff($r_processed, 
$user_checked);
+                       }
+                       else
+                       {
+                               $user_delete    = $r_processed;
+                       }
+                       if(is_array($user_delete) && count($user_delete)>0)
+                       {
+                               $user_delete= explode("_",implode("_", 
$user_delete));
+
+                               $this->remove_permission($user_delete,$type);
+                       }
+               }
+
+               function set_permission($values,$r_processed,$initials)
+               {
+                       if($initials)
+                       {
+                               $this->so->set_initials($initials);
+                       }
+
+                       $r_processed=explode("_",$r_processed);
+
+                       if(!$values['right'])
+                       {
+                               $values['right'] = array();
+                       }
+                       if(!$values['mask'])
+                       {
+                               $values['mask'] = array();
+                       }
+
+                       $this->set_permission2($values['right'],$r_processed,0);
+                       $this->set_permission2($values['mask'],$r_processed,1);
+
+//     $this->acl2->check('.invoice.test', $rights,$user_id);
+//     echo 'rights_cache:<pre>'; print_r($this->acl2->rights_cache); echo 
'</pre>';
+
+                       $receipt['message'][] = array('msg' => 
lang('permissions are updated!'));
+                       return $receipt;
+               }
+
+               function set_grant2($values,$r_processed,$type)
+               {
+                       @reset($values);
+                       $totalacl = array();
+                       while(list($rowinfo,$perm) = each($values))
+                       {
+                               list($user_id,$rights) = split('_',$rowinfo);
+                               $totalacl[$user_id] += $rights;
+                       }
+                       @reset($totalacl);
+                       while(list($user_id,$rights) = @each($totalacl))
+                       {
+                               $user_checked[]=$user_id;
+
+                               
$this->acl2->set_grant($this->location,$rights,$user_id,$type,$this->granting_group);
+                       }
+
+                       if(is_array($r_processed) && is_array($user_checked))
+                       {
+                               $user_delete    = array_diff($r_processed, 
$user_checked);
+                       }
+                       else
+                       {
+                               $user_delete    = $r_processed;
+                       }
+                       if(is_array($user_delete) && count($user_delete)>0)
+                       {
+                               $user_delete= explode("_",implode("_", 
$user_delete));
+
+                               $this->remove_grant($user_delete,$type);
+                       }
+
+               }
+
+               function set_grant($values,$r_processed)
+               {
+                       $r_processed=explode("_",$r_processed);
+
+                       if(!$values['right'])
+                       {
+                               $values['right'] = array();
+                       }
+                       if(!$values['mask'])
+                       {
+                               $values['mask'] = array();
+                       }
+
+                       $this->set_grant2($values['right'],$r_processed,0);
+                       $this->set_grant2($values['mask'],$r_processed,1);
+
+                       $receipt['message'][] = array('msg' => 
lang('permissions are updated!'));
+                       return $receipt;
+               }
+
+               function remove_permission($user_delete,$type)
+               {
+
+                       $right=$this->right;
+
+                       for ($i=0;$i<count($user_delete);$i++)
+                       {
+                               for ($j=0;$j<count($right);$j++)
+                               {
+                                       
$this->acl2->remove($this->location,$right[$j],$user_delete[$i],$type);
+                               }
+                       }
+               }
+
+               function remove_grant($user_delete,$type)
+               {
+
+                       $right=$this->right;
+
+                       for ($i=0;$i<count($user_delete);$i++)
+                       {
+                               for ($j=0;$j<count($right);$j++)
+                               {
+                                       
$this->acl2->remove_grant($this->location,$right[$j],$user_delete[$i],$type,$this->granting_group);
+                               }
+                       }
+               }
+
+               function get_user_list($type='',$app_id='')
+               {
+                       if($this->granting_group)
+                       {
+                               $owner = $this->granting_group;
+                       }
+                       else
+                       {
+                               $owner = 
$GLOBALS['phpgw_info']['user']['account_id'];
+                       }
+
+                       $right=$this->right;
+
+                       $GLOBALS['phpgw']->accounts->account_id = $owner;
+
+                       $allusers = 
$GLOBALS['phpgw']->accounts->get_list($type, $this->start,$this->sort, 
$this->order, $this->query, $this->offset);
+
+                       if (isSet($allusers) AND is_array($allusers))
+                       {
+                               $j=0;
+                               foreach($allusers as $account)
+                               {
+                                       
if($account['account_id']!=$GLOBALS['phpgw_info']['user']['account_id'] || 
$this->granting_group)
+                                       {
+                                               $user_list[$j]['account_id']    
        = $account['account_id'];
+                                               $user_list[$j]['account_lid']   
        = $account['account_lid'];
+                                               
$user_list[$j]['account_firstname'] = $account['account_firstname'];
+                                               
$user_list[$j]['account_lastname']      = $account['account_lastname'];
+                                               $user_list[$j]['initials']      
                = $this->so->get_initials($account['account_id']);
+
+                                               $count_right=count($right);
+                                               for ($i=0;$i<$count_right;$i++)
+                                               {
+                                                       
if($this->acl2->check_grant($owner,$this->location, 
$right[$i],$account['account_id'],$app_id,True,0,True))
+                                                       {
+                                                               
$user_list[$j]['right'][$right[$i]] = 'checked';
+                                                       }
+                                                       
if($this->acl2->check_grant($owner,$this->location, 
$right[$i],$account['account_id'],$this->app_id,True,1,True))
+                                                       {
+                                                               
$user_list[$j]['mask'][$right[$i]] = 'checked';
+                                                       }
+                                               }
+
+                                               if 
(isSet($user_list[$j]['mask']) AND is_array($user_list[$j]['mask']))
+                                               {
+                                                       $result_temp    = 
@array_diff(array_keys($user_list[$j]['right']), 
array_keys($user_list[$j]['mask']));
+                                                       if (isSet($result_temp) 
AND is_array($result_temp))
+                                                       {
+                                                               
foreach($result_temp as $temp)
+                                                               {
+                                                                       
$user_list[$j]['result'][$temp] = 'checked';
+                                                               }
+                                                       }
+                                               }
+                                               else
+                                               {
+                                                       
$user_list[$j]['result'] = $user_list[$j]['right'];
+                                               }
+
+                                               $user_list[$j]['right']['type'] 
= 'right';
+                                               $user_list[$j]['mask']['type'] 
= 'mask';
+                                               
$user_list[$j]['result']['type'] = 'result';
+
+                                               $j++;
+                                       }
+                               }
+                       }
+
+                       $this->total_records = 
$GLOBALS['phpgw']->accounts->total;
+
+//_debug_array($user_list);
+
+                       return $user_list;
+               }
+
+
+               function get_user_list2($type='',$app_id='')
+               {
+                       $right=$this->right;
+
+                       $allusers = 
$GLOBALS['phpgw']->accounts->get_list($type, $this->start,$this->sort, 
$this->order, $this->query, $this->offset);
+
+                       if (isSet($allusers) AND is_array($allusers))
+                       {
+                               $j=0;
+                               foreach($allusers as $account)
+                               {
+                                       $user_list[$j]['account_id']            
= $account['account_id'];
+                                       $user_list[$j]['account_lid']           
= $account['account_lid'];
+                                       $user_list[$j]['account_firstname'] = 
$account['account_firstname'];
+                                       $user_list[$j]['account_lastname']      
= $account['account_lastname'];
+                                       $user_list[$j]['initials']              
        = $this->so->get_initials($account['account_id']);
+
+                                       $count_right=count($right);
+                                       for ($i=0;$i<$count_right;$i++)
+                                       {
+                                               
if($this->acl2->check($this->location, 
$right[$i],$account['account_id'],$this->app_id,True,0,True))
+                                               {
+                                                       
$user_list[$j]['right'][$right[$i]] = 'checked';
+                                               }
+                                               
if($this->acl2->check($this->location, 
$right[$i],$account['account_id'],$this->app_id,True,1,True))
+                                               {
+                                                       
$user_list[$j]['mask'][$right[$i]] = 'checked';
+                                               }
+                                       }
+
+                                       if (isSet($user_list[$j]['mask']) AND 
is_array($user_list[$j]['mask']))
+                                       {
+                                               $result_temp    = 
@array_diff(array_keys($user_list[$j]['right']), 
array_keys($user_list[$j]['mask']));
+                                               if (isSet($result_temp) AND 
is_array($result_temp))
+                                               {
+                                                       foreach($result_temp as 
$temp)
+                                                       {
+                                                               
$user_list[$j]['result'][$temp] = 'checked';
+                                                       }
+                                               }
+                                       }
+                                       else
+                                       {
+                                               $user_list[$j]['result'] = 
$user_list[$j]['right'];
+                                       }
+
+                                       $user_list[$j]['right']['type'] = 
'right';
+                                       $user_list[$j]['mask']['type'] = 'mask';
+                                       $user_list[$j]['result']['type'] = 
'result';
+
+                                       $j++;
+                               }
+                       }
+
+                       $this->total_records = 
$GLOBALS['phpgw']->accounts->total;
+
+                       return $user_list;
+               }
+
+               function read_fm_id()
+               {
+
+                       $fm_ids = $this->so->read_fm_id();
+                       return $fm_ids;
+
+               }
+               function edit_id($values='')
+               {
+                       return $this->so->edit_id($values);
+
+               }
+       }
+?>
Index: property/inc/class.boadmin_location.inc.php
diff -u property/inc/class.boadmin_location.inc.php:1.8 
property/inc/class.boadmin_location.inc.php:1.9
--- property/inc/class.boadmin_location.inc.php:1.8     Mon Jan 30 22:14:19 2006
+++ property/inc/class.boadmin_location.inc.php Fri Feb  3 12:05:49 2006
@@ -1,304 +1,304 @@
-<?php
-       /**
-       * phpGroupWare - property: a Facilities Management System.
-       *
-       * @author Sigurd Nes <address@hidden>
-       * @copyright Copyright (C) 2003-2005 Free Software Foundation, Inc. 
http://www.fsf.org/
-       * @license http://www.gnu.org/licenses/gpl.html GNU General Public 
License
-       * @internal Development of this application was funded by 
http://www.bergen.kommune.no/bbb_/ekstern/
-       * @package property
-       * @subpackage admin
-       * @version $Id: class.boadmin_location.inc.php,v 1.8 2006/01/30 
22:14:19 sigurdne Exp $
-       */
-
-       /**
-        * Description
-        * @package property
-        */
-
-       class boadmin_location
-       {
-               var $start;
-               var $query;
-               var $filter;
-               var $sort;
-               var $order;
-               var $cat_id;
-
-               var $public_functions = array
-               (
-                       'read'                          => True,
-                       'read_single'           => True,
-                       'save'                          => True,
-                       'delete'                        => True,
-                       'check_perms'           => True
-               );
-
-               var $soap_functions = array(
-                       'list' => array(
-                               'in'  => 
array('int','int','struct','string','int'),
-                               'out' => array('array')
-                       ),
-                       'read' => array(
-                               'in'  => array('int','struct'),
-                               'out' => array('array')
-                       ),
-                       'save' => array(
-                               'in'  => array('int','struct'),
-                               'out' => array()
-                       ),
-                       'delete' => array(
-                               'in'  => array('int','struct'),
-                               'out' => array()
-                       )
-               );
-
-               function boadmin_location($session=False)
-               {
-                       $this->currentapp       = 
$GLOBALS['phpgw_info']['flags']['currentapp'];
-                       $this->so               = 
CreateObject($this->currentapp.'.soadmin_location');
-                       $this->bocommon = 
CreateObject($this->currentapp.'.bocommon');
-
-                       if ($session)
-                       {
-                               $this->read_sessiondata();
-                               $this->use_session = True;
-                       }
-
-                       $start  = get_var('start',array('POST','GET'));
-                       $query  = get_var('query',array('POST','GET'));
-                       $sort   = get_var('sort',array('POST','GET'));
-                       $order  = get_var('order',array('POST','GET'));
-                       $filter = get_var('filter',array('POST','GET'));
-                       $cat_id = get_var('cat_id',array('POST','GET'));
-                       $allrows        = 
get_var('allrows',array('POST','GET'));
-
-                       if ($start)
-                       {
-                               $this->start=$start;
-                       }
-                       else
-                       {
-                               $this->start=0;
-                       }
-
-                       if(isset($query))
-                       {
-                               $this->query = $query;
-                       }
-                       if(!empty($filter))
-                       {
-                               $this->filter = $filter;
-                       }
-                       if(isset($sort))
-                       {
-                               $this->sort = $sort;
-                       }
-                       if(isset($order))
-                       {
-                               $this->order = $order;
-                       }
-                       if(isset($cat_id))
-                       {
-                               $this->cat_id = $cat_id;
-                       }
-                       if(isset($allrows))
-                       {
-                               $this->allrows = $allrows;
-                       }
-               }
-
-
-               function save_sessiondata($data)
-               {
-                       if ($this->use_session)
-                       {
-                               
$GLOBALS['phpgw']->session->appsession('session_data','standard_e',$data);
-                       }
-               }
-
-               function read_sessiondata()
-               {
-                       $data = 
$GLOBALS['phpgw']->session->appsession('session_data','standard_e');
-
-
-                       $this->start    = $data['start'];
-                       $this->query    = $data['query'];
-                       $this->filter   = $data['filter'];
-                       $this->sort             = $data['sort'];
-                       $this->order    = $data['order'];
-                       $this->cat_id   = $data['cat_id'];
-               }
-
-               function reset_fm_cache()
-               {
-                       $this->so->reset_fm_cache();
-               }
-
-
-               function read()
-               {
-                       $standard = $this->so->read(array('start' => 
$this->start,'query' => $this->query,'sort' => $this->sort,'order' => 
$this->order));
-
-                       $this->total_records = $this->so->total_records;
-
-
-                       return $standard;
-               }
-
-               function read_config()
-               {
-                       $standard = $this->so->read_config(array('start' => 
$this->start,'query' => $this->query,'sort' => $this->sort,'order' => 
$this->order));
-
-                       $this->total_records = $this->so->total_records;
-
-
-                       return $standard;
-               }
-
-               function read_config_single($column_name)
-               {
-                       return $this->so->read_config_single($column_name);
-               }
-
-               function read_single($id)
-               {
-                       return $this->so->read_single($id);
-               }
-
-               function save($standard,$action='')
-               {
-                       if ($action=='edit')
-                       {
-                               if ($standard['id'] != '')
-                               {
-
-                                       $receipt = $this->so->edit($standard);
-                               }
-                       }
-                       else
-                       {
-                               $receipt = $this->so->add($standard);
-                       }
-                       return $receipt;
-
-               }
-
-               function delete($type_id,$id,$attrib)
-               {
-                       $this->so->delete($type_id,$id,$attrib);
-               }
-
-               function read_attrib($type_id='')
-               {
-                       $attrib = $this->so->read_attrib(array('start' => 
$this->start,'query' => $this->query,'sort' => $this->sort,'order' => 
$this->order,
-                                                                               
        'type_id' => $type_id,'allrows'=>$this->allrows));
-
-                       for ($i=0; $i<count($attrib); $i++)
-                       {
-                               $attrib[$i]['datatype'] = 
$this->bocommon->translate_datatype($attrib[$i]['datatype']);
-                       }
-
-                       $this->total_records = $this->so->total_records;
-
-                       return $attrib;
-               }
-
-               function read_single_attrib($type_id,$id)
-               {
-                       return $this->so->read_single_attrib($type_id,$id);
-               }
-
-               function resort_attrib($data)
-               {
-                       $this->so->resort_attrib($data);
-               }
-
-               function save_attrib($attrib,$action='')
-               {
-                       if ($action=='edit')
-                       {
-                               if ($attrib['id'] != '')
-                               {
-
-                                       $receipt = 
$this->so->edit_attrib($attrib);
-                               }
-                       }
-                       else
-                       {
-                               $receipt = $this->so->add_attrib($attrib);
-                       }
-                       return $receipt;
-               }
-
-               function save_config($values='',$column_name='')
-               {
-                               return 
$this->so->save_config($values,$column_name);
-               }
-
-               function select_location_type($selected='')
-               {
-                       $location_types= $this->so->select_location_type();
-
-                       while (is_array($location_types) && list(,$type) = 
each($location_types))
-                       {
-                               $sel_type = '';
-                               if ($type['id']==$selected)
-                               {
-                                       $sel_type = 'selected';
-                               }
-
-                               $location_type_list[] = array
-                               (
-                                       'id'    => $type['id'],
-                                       'name'          => $type['name'],
-                                       'selected'      => $sel_type
-                               );
-                       }
-
-                       for ($i=0;$i<count($location_type_list);$i++)
-                       {
-                               if ($location_type_list[$i]['selected'] != 
'selected')
-                               {
-                                       
unset($location_type_list[$i]['selected']);
-                               }
-                       }
-
-//_debug_array($location_type_list);
-                       return $location_type_list;
-               }
-
-               function select_nullable($selected='')
-               {
-                       $nullable[0]['id']= 'True';
-                       $nullable[0]['name']= lang('True');
-                       $nullable[1]['id']= 'False';
-                       $nullable[1]['name']= lang('False');
-
-                       while (is_array($nullable) && list(,$type) = 
each($nullable))
-                       {
-                               $sel_type = '';
-                               if ($type['id']==$selected)
-                               {
-                                       $sel_type = 'selected';
-                               }
-
-                               $nullable_list[] = array
-                               (
-                                       'id'    => $type['id'],
-                                       'name'          => $type['name'],
-                                       'selected'      => $sel_type
-                               );
-                       }
-
-                       for ($i=0;$i<count($nullable_list);$i++)
-                       {
-                               if ($nullable_list[$i]['selected'] != 
'selected')
-                               {
-                                       unset($nullable_list[$i]['selected']);
-                               }
-                       }
-                       return $nullable_list;
-               }
-       }
-?>
+<?php
+       /**
+       * phpGroupWare - property: a Facilities Management System.
+       *
+       * @author Sigurd Nes <address@hidden>
+       * @copyright Copyright (C) 2003-2005 Free Software Foundation, Inc. 
http://www.fsf.org/
+       * @license http://www.gnu.org/licenses/gpl.html GNU General Public 
License
+       * @internal Development of this application was funded by 
http://www.bergen.kommune.no/bbb_/ekstern/
+       * @package property
+       * @subpackage admin
+       * @version $Id: class.boadmin_location.inc.php,v 1.9 2006/02/03 
12:05:49 sigurdne Exp $
+       */
+
+       /**
+        * Description
+        * @package property
+        */
+
+       class boadmin_location
+       {
+               var $start;
+               var $query;
+               var $filter;
+               var $sort;
+               var $order;
+               var $cat_id;
+
+               var $public_functions = array
+               (
+                       'read'                          => True,
+                       'read_single'           => True,
+                       'save'                          => True,
+                       'delete'                        => True,
+                       'check_perms'           => True
+               );
+
+               var $soap_functions = array(
+                       'list' => array(
+                               'in'  => 
array('int','int','struct','string','int'),
+                               'out' => array('array')
+                       ),
+                       'read' => array(
+                               'in'  => array('int','struct'),
+                               'out' => array('array')
+                       ),
+                       'save' => array(
+                               'in'  => array('int','struct'),
+                               'out' => array()
+                       ),
+                       'delete' => array(
+                               'in'  => array('int','struct'),
+                               'out' => array()
+                       )
+               );
+
+               function boadmin_location($session=False)
+               {
+                       $this->currentapp       = 
$GLOBALS['phpgw_info']['flags']['currentapp'];
+                       $this->so               = 
CreateObject($this->currentapp.'.soadmin_location');
+                       $this->bocommon = 
CreateObject($this->currentapp.'.bocommon');
+
+                       if ($session)
+                       {
+                               $this->read_sessiondata();
+                               $this->use_session = True;
+                       }
+
+                       $start  = get_var('start',array('POST','GET'));
+                       $query  = get_var('query',array('POST','GET'));
+                       $sort   = get_var('sort',array('POST','GET'));
+                       $order  = get_var('order',array('POST','GET'));
+                       $filter = get_var('filter',array('POST','GET'));
+                       $cat_id = get_var('cat_id',array('POST','GET'));
+                       $allrows        = 
get_var('allrows',array('POST','GET'));
+
+                       if ($start)
+                       {
+                               $this->start=$start;
+                       }
+                       else
+                       {
+                               $this->start=0;
+                       }
+
+                       if(isset($query))
+                       {
+                               $this->query = $query;
+                       }
+                       if(!empty($filter))
+                       {
+                               $this->filter = $filter;
+                       }
+                       if(isset($sort))
+                       {
+                               $this->sort = $sort;
+                       }
+                       if(isset($order))
+                       {
+                               $this->order = $order;
+                       }
+                       if(isset($cat_id))
+                       {
+                               $this->cat_id = $cat_id;
+                       }
+                       if(isset($allrows))
+                       {
+                               $this->allrows = $allrows;
+                       }
+               }
+
+
+               function save_sessiondata($data)
+               {
+                       if ($this->use_session)
+                       {
+                               
$GLOBALS['phpgw']->session->appsession('session_data','standard_e',$data);
+                       }
+               }
+
+               function read_sessiondata()
+               {
+                       $data = 
$GLOBALS['phpgw']->session->appsession('session_data','standard_e');
+
+
+                       $this->start    = $data['start'];
+                       $this->query    = $data['query'];
+                       $this->filter   = $data['filter'];
+                       $this->sort             = $data['sort'];
+                       $this->order    = $data['order'];
+                       $this->cat_id   = $data['cat_id'];
+               }
+
+               function reset_fm_cache()
+               {
+                       $this->so->reset_fm_cache();
+               }
+
+
+               function read()
+               {
+                       $standard = $this->so->read(array('start' => 
$this->start,'query' => $this->query,'sort' => $this->sort,'order' => 
$this->order));
+
+                       $this->total_records = $this->so->total_records;
+
+
+                       return $standard;
+               }
+
+               function read_config()
+               {
+                       $standard = $this->so->read_config(array('start' => 
$this->start,'query' => $this->query,'sort' => $this->sort,'order' => 
$this->order));
+
+                       $this->total_records = $this->so->total_records;
+
+
+                       return $standard;
+               }
+
+               function read_config_single($column_name)
+               {
+                       return $this->so->read_config_single($column_name);
+               }
+
+               function read_single($id)
+               {
+                       return $this->so->read_single($id);
+               }
+
+               function save($standard,$action='')
+               {
+                       if ($action=='edit')
+                       {
+                               if ($standard['id'] != '')
+                               {
+
+                                       $receipt = $this->so->edit($standard);
+                               }
+                       }
+                       else
+                       {
+                               $receipt = $this->so->add($standard);
+                       }
+                       return $receipt;
+
+               }
+
+               function delete($type_id,$id,$attrib)
+               {
+                       $this->so->delete($type_id,$id,$attrib);
+               }
+
+               function read_attrib($type_id='')
+               {
+                       $attrib = $this->so->read_attrib(array('start' => 
$this->start,'query' => $this->query,'sort' => $this->sort,'order' => 
$this->order,
+                                                                               
        'type_id' => $type_id,'allrows'=>$this->allrows));
+
+                       for ($i=0; $i<count($attrib); $i++)
+                       {
+                               $attrib[$i]['datatype'] = 
$this->bocommon->translate_datatype($attrib[$i]['datatype']);
+                       }
+
+                       $this->total_records = $this->so->total_records;
+
+                       return $attrib;
+               }
+
+               function read_single_attrib($type_id,$id)
+               {
+                       return $this->so->read_single_attrib($type_id,$id);
+               }
+
+               function resort_attrib($data)
+               {
+                       $this->so->resort_attrib($data);
+               }
+
+               function save_attrib($attrib,$action='')
+               {
+                       if ($action=='edit')
+                       {
+                               if ($attrib['id'] != '')
+                               {
+
+                                       $receipt = 
$this->so->edit_attrib($attrib);
+                               }
+                       }
+                       else
+                       {
+                               $receipt = $this->so->add_attrib($attrib);
+                       }
+                       return $receipt;
+               }
+
+               function save_config($values='',$column_name='')
+               {
+                               return 
$this->so->save_config($values,$column_name);
+               }
+
+               function select_location_type($selected='')
+               {
+                       $location_types= $this->so->select_location_type();
+
+                       while (is_array($location_types) && list(,$type) = 
each($location_types))
+                       {
+                               $sel_type = '';
+                               if ($type['id']==$selected)
+                               {
+                                       $sel_type = 'selected';
+                               }
+
+                               $location_type_list[] = array
+                               (
+                                       'id'    => $type['id'],
+                                       'name'          => $type['name'],
+                                       'selected'      => $sel_type
+                               );
+                       }
+
+                       for ($i=0;$i<count($location_type_list);$i++)
+                       {
+                               if ($location_type_list[$i]['selected'] != 
'selected')
+                               {
+                                       
unset($location_type_list[$i]['selected']);
+                               }
+                       }
+
+//_debug_array($location_type_list);
+                       return $location_type_list;
+               }
+
+               function select_nullable($selected='')
+               {
+                       $nullable[0]['id']= 'True';
+                       $nullable[0]['name']= lang('True');
+                       $nullable[1]['id']= 'False';
+                       $nullable[1]['name']= lang('False');
+
+                       while (is_array($nullable) && list(,$type) = 
each($nullable))
+                       {
+                               $sel_type = '';
+                               if ($type['id']==$selected)
+                               {
+                                       $sel_type = 'selected';
+                               }
+
+                               $nullable_list[] = array
+                               (
+                                       'id'    => $type['id'],
+                                       'name'          => $type['name'],
+                                       'selected'      => $sel_type
+                               );
+                       }
+
+                       for ($i=0;$i<count($nullable_list);$i++)
+                       {
+                               if ($nullable_list[$i]['selected'] != 
'selected')
+                               {
+                                       unset($nullable_list[$i]['selected']);
+                               }
+                       }
+                       return $nullable_list;
+               }
+       }
+?>
Index: property/inc/class.boagreement.inc.php
diff -u property/inc/class.boagreement.inc.php:1.7 
property/inc/class.boagreement.inc.php:1.8
--- property/inc/class.boagreement.inc.php:1.7  Fri Jan 27 14:05:43 2006
+++ property/inc/class.boagreement.inc.php      Fri Feb  3 12:05:49 2006
@@ -1,767 +1,767 @@
-<?php
-       /**
-       * phpGroupWare - property: a Facilities Management System.
-       *
-       * @author Sigurd Nes <address@hidden>
-       * @copyright Copyright (C) 2003-2005 Free Software Foundation, Inc. 
http://www.fsf.org/
-       * @license http://www.gnu.org/licenses/gpl.html GNU General Public 
License
-       * @internal Development of this application was funded by 
http://www.bergen.kommune.no/bbb_/ekstern/
-       * @package property
-       * @subpackage agreement
-       * @version $Id: class.boagreement.inc.php,v 1.7 2006/01/27 14:05:43 
sigurdne Exp $
-       */
-
-       /**
-        * Description
-        * @package property
-        */
-
-       class boagreement
-       {
-               var $start;
-               var $query;
-               var $filter;
-               var $sort;
-               var $order;
-               var $cat_id;
-               var $role;
-               var $member_id;
-
-               var $public_functions = array
-               (
-                       'read'                          => True,
-                       'read_single'           => True,
-                       'save'                          => True,
-                       'delete'                        => True,
-                       'check_perms'           => True
-               );
-
-               function boagreement($session=False)
-               {
-                       $this->currentapp               = 
$GLOBALS['phpgw_info']['flags']['currentapp'];
-                       $this->so = 
CreateObject($this->currentapp.'.soagreement');
-                       $this->bocommon = 
CreateObject($this->currentapp.'.bocommon');
-                       $this->vfs                      = 
CreateObject('phpgwapi.vfs');
-                       $this->rootdir          = $this->vfs->basedir;
-                       $this->fakebase         = $this->vfs->fakebase;
-
-                       if ($session)
-                       {
-                               $this->read_sessiondata();
-                               $this->use_session = True;
-                       }
-
-                       $start  = get_var('start',array('POST','GET'));
-                       $query  = get_var('query',array('POST','GET'));
-                       $sort   = get_var('sort',array('POST','GET'));
-                       $order  = get_var('order',array('POST','GET'));
-                       $filter = get_var('filter',array('POST','GET'));
-                       $cat_id = get_var('cat_id',array('POST','GET'));
-                       $vendor_id      = 
get_var('vendor_id',array('POST','GET'));
-                       $allrows        = 
get_var('allrows',array('POST','GET'));
-                       $role   = get_var('role',array('POST','GET'));
-                       $member_id      = 
get_var('member_id',array('POST','GET'));
-
-
-                       $this->role     = $role;
-                       $this->so->role = $role;
-
-                       if ($start)
-                       {
-                               $this->start=$start;
-                       }
-                       else
-                       {
-                               $this->start=0;
-                       }
-
-                       if(isset($query))
-                       {
-                               $this->query = $query;
-                       }
-                       if(!empty($filter))
-                       {
-                               $this->filter = $filter;
-                       }
-                       if(isset($sort))
-                       {
-                               $this->sort = $sort;
-                       }
-                       if(isset($order))
-                       {
-                               $this->order = $order;
-                       }
-                       if(isset($cat_id) && !empty($cat_id))
-                       {
-                               $this->cat_id = $cat_id;
-                       }
-                       else
-                       {
-                               unset($this->cat_id);
-                       }
-                       if(isset($allrows))
-                       {
-                               $this->allrows = $allrows;
-                       }
-                       if(isset($member_id))
-                       {
-                               $this->member_id = $member_id;
-                       }
-                       if(isset($vendor_id))
-                       {
-                               $this->vendor_id = $vendor_id;
-                       }
-               }
-
-               function save_sessiondata($data)
-               {
-                       if ($this->use_session)
-                       {
-                               
$GLOBALS['phpgw']->session->appsession('session_data','agreement',$data);
-                       }
-               }
-
-               function read_sessiondata()
-               {
-                       $data = 
$GLOBALS['phpgw']->session->appsession('session_data','agreement');
-
-                       //_debug_array($data);
-
-                       $this->start    = $data['start'];
-                       $this->query    = $data['query'];
-                       $this->filter   = $data['filter'];
-                       $this->sort             = $data['sort'];
-                       $this->order    = $data['order'];
-                       $this->cat_id   = $data['cat_id'];
-                       $this->vendor_id= $data['vendor_id'];
-                       $this->member_id= $data['member_id'];
-                       $this->allrows  = $data['allrows'];
-               }
-
-               function check_perms($has, $needed)
-               {
-                       return (!!($has & $needed) == True);
-               }
-
-
-               function select_category_list($format='',$selected='')
-               {
-                       switch($format)
-                       {
-                               case 'select':
-                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('cat_select'));
-                                       break;
-                               case 'filter':
-                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('cat_filter'));
-                                       break;
-                       }
-
-                       $categories= $this->so->select_category_list();
-
-                       while (is_array($categories) && list(,$category) = 
each($categories))
-                       {
-                               $sel_category = '';
-                               if ($category['id']==$selected)
-                               {
-                                       $sel_category = 'selected';
-                               }
-
-                               $category_list[] = array
-                               (
-                                       'cat_id'        => $category['id'],
-                                       'name'          => $category['name'],
-                                       'selected'      => $sel_category
-                               );
-                       }
-
-                       for ($i=0;$i<count($category_list);$i++)
-                       {
-                               if ($category_list[$i]['selected'] != 
'selected')
-                               {
-                                       unset($category_list[$i]['selected']);
-                               }
-                       }
-
-                       return $category_list;
-               }
-
-               function select_vendor_list($format='',$selected='')
-               {
-                       switch($format)
-                       {
-                               case 'select':
-                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('select_vendor'));
-                                       break;
-                               case 'filter':
-                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('filter_vendor'));
-                                       break;
-                       }
-
-                       $input_list= $this->so->select_vendor_list();
-                       $vendor_list= 
$this->bocommon->select_list($selected,$input_list);
-
-                       return $vendor_list;
-               }
-
-               function read()
-               {
-                       $agreement = $this->so->read(array('start' => 
$this->start,'query' => $this->query,'sort' => $this->sort,'order' => 
$this->order,
-                                                                               
        'filter' => $this->filter,'cat_id' => 
$this->cat_id,'allrows'=>$this->allrows,'member_id'=>$this->member_id,
-                                                                               
        'vendor_id'=>$this->vendor_id));
-                       $this->total_records = $this->so->total_records;
-
-                       $this->uicols   = $this->so->uicols;
-
-                       for ($i=0; $i<count($agreement); $i++)
-                       {
-                               if($agreement[$i]['start_date'])
-                               {
-                                       $agreement[$i]['start_date']  = 
$GLOBALS['phpgw']->common->show_date($agreement[$i]['start_date'],$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']);
-                               }
-                               if($agreement[$i]['end_date'])
-                               {
-                                       $agreement[$i]['end_date']  = 
$GLOBALS['phpgw']->common->show_date($agreement[$i]['end_date'],$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']);
-                               }
-
-                               $agreement[$i]['status']  = 
lang($agreement[$i]['status']);
-
-                       }
-                       return $agreement;
-               }
-
-               function read_details($id)
-               {
-                       $list = $this->so->read_details(array('start' => 
$this->start,'query' => $this->query,'sort' => $this->sort,'order' => 
$this->order,
-                                                                               
        'filter' => $this->filter,'cat_id' => 
$this->cat_id,'allrows'=>$this->allrows,'member_id'=>$this->member_id,
-                                                                               
        'agreement_id'=>$id));
-                       $this->total_records = $this->so->total_records;
-
-                       $this->uicols   = $this->so->uicols;
-
-                       return $list;
-               }
-
-               function read_prizing($data)
-               {
-                       $list = $this->so->read_prizing($data);
-                       $this->total_records = $this->so->total_records;
-
-                       $this->uicols   = $this->so->uicols;
-
-                       for ($i=0; $i<count($list); $i++)
-                       {
-                               $list[$i]['index_date']  = 
$GLOBALS['phpgw']->common->show_date($list[$i]['index_date'],$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']);
-                       }
-
-                       return $list;
-               }
-
-               function read_event($data)
-               {
-                       $boalarm                = 
CreateObject($this->currentapp.'.boalarm');
-                       $event  = $this->so->read_single($data);
-                       $event['alarm_date']=$event['termination_date'];
-                       $event['alarm'] = 
$boalarm->read_alarms($type='agreement',$data['agreement_id']);
-                       return $event;
-               }
-
-               function read_single($data)
-               {
-                       $agreement      = $this->so->read_single($data);
-                       $dateformat = 
$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
-                       $agreement['start_date']                = 
$GLOBALS['phpgw']->common->show_date($agreement['start_date'],$dateformat);
-                       $agreement['end_date']          = 
$GLOBALS['phpgw']->common->show_date($agreement['end_date'],$dateformat);
-                       if($agreement['termination_date'])
-                       {
-                               $agreement['termination_date']= 
$GLOBALS['phpgw']->common->show_date($agreement['termination_date'],$dateformat);
-                       }
-
-                       $agreement = $this->convert_attribute($agreement);
-
-                       $this->vfs->override_acl = 1;
-
-                       $agreement['files'] = $this->vfs->ls (array(
-                            'string' => $this->fakebase. '/' . 'agreement' .  
'/' . $data['agreement_id'],
-                            'relatives' => array(RELATIVE_NONE)));
-
-                       $this->vfs->override_acl = 0;
-
-                       if(!$agreement['files'][0]['file_id'])
-                       {
-                               unset($agreement['files']);
-                       }
-
-                       return $agreement;
-
-               }
-
-               function read_single_item($data)
-               {
-                       $item   = $this->so->read_single_item($data);
-//_debug_array($item);
-                       $item   = $this->convert_attribute($item,True);
-                       return $item;
-               }
-
-               function convert_attribute($list,$detail='')
-               {
-                       if($detail)
-                       {
-                               $this->so->role = 'detail';
-                       }
-                       $contacts                       = 
CreateObject('phpgwapi.contacts');
-
-                       $vendor = CreateObject($this->currentapp.'.soactor');
-                       $vendor->role = 'vendor';
-
-                       $dateformat = 
$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
-
-                       $input_type_array = array(
-                               'R' => 'radio',
-                               'CH' => 'checkbox',
-                               'LB' => 'listbox'
-                       );
-
-                       $sep = '/';
-                       $dlarr[strpos($dateformat,'Y')] = 'Y';
-                       $dlarr[strpos($dateformat,'m')] = 'm';
-                       $dlarr[strpos($dateformat,'d')] = 'd';
-                       ksort($dlarr);
-
-                       $dateformat= (implode($sep,$dlarr));
-
-//html_print_r($list);
-                       $m=0;
-                       for ($i=0;$i<count($list['attributes']);$i++)
-                       {
-                               if($list['attributes'][$i]['datatype']=='D' && 
$list['attributes'][$i]['value'])
-                               {
-                                       $timestamp_date= 
mktime(0,0,0,date(m,strtotime($list['attributes'][$i]['value'])),date(d,strtotime($list['attributes'][$i]['value'])),date(y,strtotime($list['attributes'][$i]['value'])));
-                                       $list['attributes'][$i]['value']        
= $GLOBALS['phpgw']->common->show_date($timestamp_date,$dateformat);
-                               }
-                               if($list['attributes'][$i]['datatype']=='AB')
-                               {
-                                       if($list['attributes'][$i]['value'])
-                                       {
-                                               $contact_data   = 
$contacts->read_single_entry($list['attributes'][$i]['value'],array('n_given'=>'n_given','n_family'=>'n_family','email'=>'email'));
-                                               
$list['attributes'][$i]['contact_name'] = $contact_data[0]['n_family'] . ', ' . 
$contact_data[0]['n_given'];
-                                       }
-
-                                       $insert_record_list[]   = 
$list['attributes'][$i]['name'];
-                                       $lookup_link            = 
$GLOBALS['phpgw']->link('/index.php','menuaction='.$this->currentapp.'.uilookup.addressbook&column='
 . $list['attributes'][$i]['name']);
-
-                                       $lookup_functions[$m]['name'] = 
'lookup_'. $list['attributes'][$i]['name'] .'()';
-                                       $lookup_functions[$m]['action'] = 
'Window1=window.open('."'" . $lookup_link ."'" 
.',"Search","width=800,height=700,toolbar=no,scrollbars=yes,resizable=yes");';
-                                       $m++;
-                               }
-                               
if($list['attributes'][$i]['datatype']=='VENDOR')
-                               {
-                                       if($list['attributes'][$i]['value'])
-                                       {
-                                               $vendor_data    = 
$vendor->read_single(array('actor_id'=>$list['attributes'][$i]['value']));
-
-                                               for 
($n=0;$n<count($vendor_data['attributes']);$n++)
-                                               {
-                                                       
if($vendor_data['attributes'][$n]['name'] == 'org_name')
-                                                       {
-                                                               
$list['attributes'][$i]['vendor_name']= $vendor_data['attributes'][$n]['value'];
-                                                               $n 
=count($vendor_data['attributes']);
-                                                       }
-                                               }
-                                       }
-
-                                       $insert_record_list[]   = 
$list['attributes'][$i]['name'];
-                                       $lookup_link            = 
$GLOBALS['phpgw']->link('/index.php','menuaction='.$this->currentapp.'.uilookup.vendor&column='
 . $list['attributes'][$i]['name']);
-
-                                       $lookup_functions[$m]['name'] = 
'lookup_'. $list['attributes'][$i]['name'] .'()';
-                                       $lookup_functions[$m]['action'] = 
'Window1=window.open('."'" . $lookup_link ."'" 
.',"Search","width=800,height=700,toolbar=no,scrollbars=yes,resizable=yes");';
-                                       $m++;
-                               }
-
-                               if($list['attributes'][$i]['datatype']=='R' || 
$list['attributes'][$i]['datatype']=='CH' || 
$list['attributes'][$i]['datatype']=='LB')
-                               {
-                                       $list['attributes'][$i]['choice']       
= $this->so->read_attrib_choice($list['attributes'][$i]['attrib_id']);
-                                       
$input_type=$input_type_array[$list['attributes'][$i]['datatype']];
-
-                                       
if($list['attributes'][$i]['datatype']=='CH')
-                                       {
-                                               
$list['attributes'][$i]['value']=unserialize($list['attributes'][$i]['value']);
-                                               
$list['attributes'][$i]['choice'] = 
$this->bocommon->select_multi_list_2($list['attributes'][$i]['value'],$list['attributes'][$i]['choice'],$input_type);
-
-                                       }
-                                       else
-                                       {
-                                               for 
($j=0;$j<count($list['attributes'][$i]['choice']);$j++)
-                                               {
-                                                       
$list['attributes'][$i]['choice'][$j]['input_type']=$input_type;
-                                                       
if($list['attributes'][$i]['choice'][$j]['id']==$list['attributes'][$i]['value'])
-                                                       {
-                                                               
$list['attributes'][$i]['choice'][$j]['checked']='checked';
-                                                       }
-                                               }
-                                       }
-                               }
-
-                               $list['attributes'][$i]['datatype_text'] = 
$this->bocommon->translate_datatype($list['attributes'][$i]['datatype']);
-                               $list['attributes'][$i]['counter']      = $i;
-                               $list['attributes'][$i]['type_id']      = 
$data['type_id'];
-                       }
-
-                       for ($j=0;$j<count($lookup_functions);$j++)
-                       {
-                               $list['lookup_functions'] .= 'function ' . 
$lookup_functions[$j]['name'] ."\r\n";
-                               $list['lookup_functions'] .= '{'."\r\n";
-                               $list['lookup_functions'] .= 
$lookup_functions[$j]['action'] ."\r\n";
-                               $list['lookup_functions'] .= '}'."\r\n";
-                       }
-
-                       
$GLOBALS['phpgw']->session->appsession('insert_record_agreement' . 
!!$detail,$this->currentapp,$insert_record_list);
-
-//html_print_r($list);
-                       return $list;
-
-               }
-
-               function convert_attribute_save($values_attribute='')
-               {
-
-                       for ($i=0;$i<count($values_attribute);$i++)
-                       {
-                               if($values_attribute[$i]['datatype']=='CH' && 
$values_attribute[$i]['value'])
-                               {
-                                       $values_attribute[$i]['value'] = 
serialize($values_attribute[$i]['value']);
-                               }
-                               if($values_attribute[$i]['datatype']=='R' && 
$values_attribute[$i]['value'])
-                               {
-                                       $values_attribute[$i]['value'] = 
$values_attribute[$i]['value'][0];
-                               }
-
-                               if($values_attribute[$i]['datatype']=='N' && 
$values_attribute[$i]['value'])
-                               {
-                                       $values_attribute[$i]['value'] = 
str_replace(",",".",$values_attribute[$i]['value']);
-                               }
-
-                               if($values_attribute[$i]['datatype']=='D' && 
$values_attribute[$i]['value'])
-                               {
-                                       $values_attribute[$i]['value'] = 
date($this->bocommon->dateformat,$this->bocommon->date_to_timestamp($values_attribute[$i]['value']));
-                               }
-                       }
-
-                       return $values_attribute;
-               }
-
-               function save($values,$values_attribute='',$action='')
-               {
-
-                       $values['start_date']   = 
$this->bocommon->date_to_timestamp($values['start_date']);
-                       $values['end_date']     = 
$this->bocommon->date_to_timestamp($values['end_date']);
-                       $values['termination_date']     = 
$this->bocommon->date_to_timestamp($values['termination_date']);
-
-                       $values_attribute = 
$this->convert_attribute_save($values_attribute);
-
-                       if ($action=='edit')
-//                     if ($values['agreement_id'])
-                       {
-                               if ($values['agreement_id'] != 0)
-                               {
-                                       
$receipt=$this->so->edit($values,$values_attribute);
-
-                                       if($values['delete_file'])
-                                       {
-                                               for 
($i=0;$i<count($values['delete_file']);$i++)
-                                               {
-                                                       $file = 
$this->fakebase. SEP . 'agreement' . SEP . $values['agreement_id'] . SEP . 
$values['delete_file'][$i];
-
-                                                       
if($this->vfs->file_exists(array(
-                                                                       
'string' => $file,
-                                                                       
'relatives' => Array(RELATIVE_NONE)
-                                                               )))
-                                                       {
-                                                               
$this->vfs->override_acl = 1;
-
-                                                               
if(!$this->vfs->rm (array(
-                                                                       
'string' => $file,
-                                                                    
'relatives' => array(
-                                                                         
RELATIVE_NONE
-                                                                    )
-                                                               )))
-                                                               {
-                                                                       
$receipt['error'][]=array('msg'=>lang('failed to delete file') . ' :'. 
$this->fakebase. SEP . 'agreement'. SEP . $values['agreement_id'] . SEP 
.$values['delete_file'][$i]);
-                                                               }
-                                                               else
-                                                               {
-                                                                       
$receipt['message'][]=array('msg'=>lang('file deleted') . ' :'. 
$this->fakebase. SEP . 'agreement'. SEP . $values['id'] . SEP . 
$values['delete_file'][$i]);
-                                                               }
-                                                               
$this->vfs->override_acl = 0;
-                                                       }
-                                               }
-                                       }
-                               }
-                       }
-                       else
-                       {
-                               $receipt = 
$this->so->add($values,$values_attribute);
-                       }
-                       return $receipt;
-               }
-
-               function save_item($values,$values_attribute='')
-               {
-//_debug_array($values);
-                       $values['m_cost']       = 
str_replace(",",".",$values['m_cost']);
-                       $values['w_cost']       = 
str_replace(",",".",$values['w_cost']);
-                       $values['total_cost']           = $values['m_cost'] + 
$values['w_cost'];
-
-                       if ($values['index_count'] > 0)
-                       {
-                               if ($values['id'] != 0)
-                               {
-                                       $receipt=$this->so->edit_item($values);
-                               }
-                       }
-                       else
-                       {
-                               $receipt = $this->so->add_item($values);
-                       }
-                       return $receipt;
-               }
-
-
-               function update($values)
-               {
-                       $values['date'] = 
$this->bocommon->date_to_timestamp($values['date']);
-
-                       return $this->so->update($values);
-               }
-
-               function delete_last_index($agreement_id,$id)
-               {
-                       $this->so->delete_last_index($agreement_id,$id);
-               }
-
-
-               function delete_item($agreement_id,$activity_id)
-               {
-                       $this->so->delete_item($agreement_id,$activity_id);
-               }
-
-               function delete($agreement_id='',$id='',$attrib='')
-               {
-                       if ($attrib)
-                       {
-                               $this->so->delete_attrib($id);
-                       }
-                       else
-                       {
-                               $this->so->delete($agreement_id);
-                       }
-               }
-
-               function read_attrib($type_id='')
-               {
-                       $attrib = $this->so->read_attrib(array('start' => 
$this->start,'query' => $this->query,'sort' => $this->sort,'order' => 
$this->order,
-                                                                               
        'allrows'=>$this->allrows));
-
-                       for ($i=0; $i<count($attrib); $i++)
-                       {
-                               $attrib[$i]['datatype'] = 
$this->bocommon->translate_datatype($attrib[$i]['datatype']);
-                       }
-
-                       $this->total_records = $this->so->total_records;
-
-                       return $attrib;
-               }
-
-               function read_single_attrib($id)
-               {
-                       return $this->so->read_single_attrib($id);
-               }
-
-               function resort_attrib($data)
-               {
-                       $this->so->resort_attrib($data);
-               }
-
-               function save_attrib($attrib,$action='')
-               {
-                       if ($action=='edit')
-                       {
-                               if ($attrib['id'] != '')
-                               {
-
-                                       $receipt = 
$this->so->edit_attrib($attrib);
-                               }
-                       }
-                       else
-                       {
-                               $receipt = $this->so->add_attrib($attrib);
-                       }
-                       return $receipt;
-               }
-
-               function column_list($selected='',$allrows='')
-               {
-                       if(!$selected)
-                       {
-                               
$selected=$GLOBALS['phpgw_info']['user']['preferences'][$this->currentapp]["agreement_columns"];
-                       }
-
-                       $columns = 
$this->so->read_attrib(array('allrows'=>$allrows,'column_list'=>True));
-
-                       
$column_list=$this->bocommon->select_multi_list($selected,$columns);
-
-                       return $column_list;
-               }
-
-               function request_next_id()
-               {
-                               return $this->so->request_next_id();
-               }
-
-               function create_home_dir($receipt='')
-               {
-                       if(!$this->vfs->file_exists(array(
-                                       'string' => $this->fakebase. SEP . 
'agreement',
-                                       'relatives' => Array(RELATIVE_NONE)
-                               )))
-                       {
-                               $this->vfs->override_acl = 1;
-
-                               if(!$this->vfs->mkdir (array(
-                                    'string' => $this->fakebase. SEP . 
'agreement',
-                                    'relatives' => array(
-                                         RELATIVE_NONE
-                                    )
-                               )))
-                               {
-                                       
$receipt['error'][]=array('msg'=>lang('failed to create directory') . ' :'. 
$this->fakebase. SEP . 'agreement');
-                               }
-                               else
-                               {
-                                       
$receipt['message'][]=array('msg'=>lang('directory created') . ' :'. 
$this->fakebase. SEP . 'agreement');
-                               }
-                               $this->vfs->override_acl = 0;
-                       }
-
-                       return $receipt;
-               }
-
-               function create_document_dir($id='')
-               {
-
-                       if(!$this->vfs->file_exists(array(
-                                       'string' => $this->fakebase. SEP . 
'agreement' .  SEP . $id,
-                                       'relatives' => Array(RELATIVE_NONE)
-                               )))
-                       {
-                               $this->vfs->override_acl = 1;
-                               if(!$this->vfs->mkdir (array(
-                                    'string' => $this->fakebase. SEP . 
'agreement' .  SEP . $id,
-                                    'relatives' => array(
-                                         RELATIVE_NONE
-                                    )
-                               )))
-                               {
-                                       
$receipt['error'][]=array('msg'=>lang('failed to create directory') . ' :'. 
$this->fakebase. SEP  . 'agreement' .  SEP . $id);
-                               }
-                               else
-                               {
-                                       
$receipt['message'][]=array('msg'=>lang('directory created') . ' :'. 
$this->fakebase. SEP . 'agreement' .  SEP . $id);
-                               }
-                               $this->vfs->override_acl = 0;
-                       }
-
-//_debug_array($receipt);
-                       return $receipt;
-               }
-
-               function get_agreement_group_list($selected='')
-               {
-                       $agreement_groups= 
$this->so->get_agreement_group_list();
-
-                       while (is_array($agreement_groups) && 
list(,$agreement_group_entry) = each($agreement_groups))
-                       {
-                               $sel_agreement_group_entry = '';
-                               if ($agreement_group_entry['id']==$selected)
-                               {
-                                       $sel_agreement_group_entry = 'selected';
-                               }
-
-                               $agreement_group_list[] = array
-                               (
-                                       'id'    => $agreement_group_entry['id'],
-                                       'name'          => 
$agreement_group_entry['name'],
-                                       'selected'      => 
$sel_agreement_group_entry
-                               );
-                       }
-
-                       for ($i=0;$i<count($agreement_group_list);$i++)
-                       {
-                               if ($agreement_group_list[$i]['selected'] != 
'selected')
-                               {
-                                       
unset($agreement_group_list[$i]['selected']);
-                               }
-                       }
-
-                       return $agreement_group_list;
-               }
-
-               function read_group_activity($group_id='',$agreement_id='')
-               {
-                       $activity_list = 
$this->so->read_group_activity($group_id,$agreement_id);
-                       $this->uicols   = $this->so->uicols;
-                       return $activity_list;
-               }
-
-               function add_activity($values='',$agreement_id='')
-               {
-                       return $this->so->add_activity($values,$agreement_id);
-               }
-
-               function select_status_list($format='',$selected='')
-               {
-                       switch($format)
-                       {
-                               case 'select':
-                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('status_select'));
-                                       break;
-                               case 'filter':
-                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('status_filter'));
-                                       break;
-                       }
-
-                       $status_entries= $this->so->select_status_list();
-
-                       while (is_array($status_entries) && list(,$status) = 
each($status_entries))
-                       {
-                               $sel_status = '';
-                               if ($status['id']==$selected)
-                               {
-                                       $sel_status = 'selected';
-                               }
-
-                               $status_list[] = array
-                               (
-                                       'id'            => $status['id'],
-                                       'name'          => $status['name'],
-                                       'selected'      => $sel_status
-                               );
-                       }
-
-                       for ($i=0;$i<count($status_list);$i++)
-                       {
-                               if ($status_list[$i]['selected'] != 'selected')
-                               {
-                                       unset($status_list[$i]['selected']);
-                               }
-                       }
-
-                       return $status_list;
-               }
-               
-               function get_activity_descr($id)
-               {
-                       return $this->so->get_activity_descr($id);
-               }
-       }
-?>
+<?php
+       /**
+       * phpGroupWare - property: a Facilities Management System.
+       *
+       * @author Sigurd Nes <address@hidden>
+       * @copyright Copyright (C) 2003-2005 Free Software Foundation, Inc. 
http://www.fsf.org/
+       * @license http://www.gnu.org/licenses/gpl.html GNU General Public 
License
+       * @internal Development of this application was funded by 
http://www.bergen.kommune.no/bbb_/ekstern/
+       * @package property
+       * @subpackage agreement
+       * @version $Id: class.boagreement.inc.php,v 1.8 2006/02/03 12:05:49 
sigurdne Exp $
+       */
+
+       /**
+        * Description
+        * @package property
+        */
+
+       class boagreement
+       {
+               var $start;
+               var $query;
+               var $filter;
+               var $sort;
+               var $order;
+               var $cat_id;
+               var $role;
+               var $member_id;
+
+               var $public_functions = array
+               (
+                       'read'                          => True,
+                       'read_single'           => True,
+                       'save'                          => True,
+                       'delete'                        => True,
+                       'check_perms'           => True
+               );
+
+               function boagreement($session=False)
+               {
+                       $this->currentapp               = 
$GLOBALS['phpgw_info']['flags']['currentapp'];
+                       $this->so = 
CreateObject($this->currentapp.'.soagreement');
+                       $this->bocommon = 
CreateObject($this->currentapp.'.bocommon');
+                       $this->vfs                      = 
CreateObject('phpgwapi.vfs');
+                       $this->rootdir          = $this->vfs->basedir;
+                       $this->fakebase         = $this->vfs->fakebase;
+
+                       if ($session)
+                       {
+                               $this->read_sessiondata();
+                               $this->use_session = True;
+                       }
+
+                       $start  = get_var('start',array('POST','GET'));
+                       $query  = get_var('query',array('POST','GET'));
+                       $sort   = get_var('sort',array('POST','GET'));
+                       $order  = get_var('order',array('POST','GET'));
+                       $filter = get_var('filter',array('POST','GET'));
+                       $cat_id = get_var('cat_id',array('POST','GET'));
+                       $vendor_id      = 
get_var('vendor_id',array('POST','GET'));
+                       $allrows        = 
get_var('allrows',array('POST','GET'));
+                       $role   = get_var('role',array('POST','GET'));
+                       $member_id      = 
get_var('member_id',array('POST','GET'));
+
+
+                       $this->role     = $role;
+                       $this->so->role = $role;
+
+                       if ($start)
+                       {
+                               $this->start=$start;
+                       }
+                       else
+                       {
+                               $this->start=0;
+                       }
+
+                       if(isset($query))
+                       {
+                               $this->query = $query;
+                       }
+                       if(!empty($filter))
+                       {
+                               $this->filter = $filter;
+                       }
+                       if(isset($sort))
+                       {
+                               $this->sort = $sort;
+                       }
+                       if(isset($order))
+                       {
+                               $this->order = $order;
+                       }
+                       if(isset($cat_id) && !empty($cat_id))
+                       {
+                               $this->cat_id = $cat_id;
+                       }
+                       else
+                       {
+                               unset($this->cat_id);
+                       }
+                       if(isset($allrows))
+                       {
+                               $this->allrows = $allrows;
+                       }
+                       if(isset($member_id))
+                       {
+                               $this->member_id = $member_id;
+                       }
+                       if(isset($vendor_id))
+                       {
+                               $this->vendor_id = $vendor_id;
+                       }
+               }
+
+               function save_sessiondata($data)
+               {
+                       if ($this->use_session)
+                       {
+                               
$GLOBALS['phpgw']->session->appsession('session_data','agreement',$data);
+                       }
+               }
+
+               function read_sessiondata()
+               {
+                       $data = 
$GLOBALS['phpgw']->session->appsession('session_data','agreement');
+
+                       //_debug_array($data);
+
+                       $this->start    = $data['start'];
+                       $this->query    = $data['query'];
+                       $this->filter   = $data['filter'];
+                       $this->sort             = $data['sort'];
+                       $this->order    = $data['order'];
+                       $this->cat_id   = $data['cat_id'];
+                       $this->vendor_id= $data['vendor_id'];
+                       $this->member_id= $data['member_id'];
+                       $this->allrows  = $data['allrows'];
+               }
+
+               function check_perms($has, $needed)
+               {
+                       return (!!($has & $needed) == True);
+               }
+
+
+               function select_category_list($format='',$selected='')
+               {
+                       switch($format)
+                       {
+                               case 'select':
+                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('cat_select'));
+                                       break;
+                               case 'filter':
+                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('cat_filter'));
+                                       break;
+                       }
+
+                       $categories= $this->so->select_category_list();
+
+                       while (is_array($categories) && list(,$category) = 
each($categories))
+                       {
+                               $sel_category = '';
+                               if ($category['id']==$selected)
+                               {
+                                       $sel_category = 'selected';
+                               }
+
+                               $category_list[] = array
+                               (
+                                       'cat_id'        => $category['id'],
+                                       'name'          => $category['name'],
+                                       'selected'      => $sel_category
+                               );
+                       }
+
+                       for ($i=0;$i<count($category_list);$i++)
+                       {
+                               if ($category_list[$i]['selected'] != 
'selected')
+                               {
+                                       unset($category_list[$i]['selected']);
+                               }
+                       }
+
+                       return $category_list;
+               }
+
+               function select_vendor_list($format='',$selected='')
+               {
+                       switch($format)
+                       {
+                               case 'select':
+                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('select_vendor'));
+                                       break;
+                               case 'filter':
+                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('filter_vendor'));
+                                       break;
+                       }
+
+                       $input_list= $this->so->select_vendor_list();
+                       $vendor_list= 
$this->bocommon->select_list($selected,$input_list);
+
+                       return $vendor_list;
+               }
+
+               function read()
+               {
+                       $agreement = $this->so->read(array('start' => 
$this->start,'query' => $this->query,'sort' => $this->sort,'order' => 
$this->order,
+                                                                               
        'filter' => $this->filter,'cat_id' => 
$this->cat_id,'allrows'=>$this->allrows,'member_id'=>$this->member_id,
+                                                                               
        'vendor_id'=>$this->vendor_id));
+                       $this->total_records = $this->so->total_records;
+
+                       $this->uicols   = $this->so->uicols;
+
+                       for ($i=0; $i<count($agreement); $i++)
+                       {
+                               if($agreement[$i]['start_date'])
+                               {
+                                       $agreement[$i]['start_date']  = 
$GLOBALS['phpgw']->common->show_date($agreement[$i]['start_date'],$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']);
+                               }
+                               if($agreement[$i]['end_date'])
+                               {
+                                       $agreement[$i]['end_date']  = 
$GLOBALS['phpgw']->common->show_date($agreement[$i]['end_date'],$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']);
+                               }
+
+                               $agreement[$i]['status']  = 
lang($agreement[$i]['status']);
+
+                       }
+                       return $agreement;
+               }
+
+               function read_details($id)
+               {
+                       $list = $this->so->read_details(array('start' => 
$this->start,'query' => $this->query,'sort' => $this->sort,'order' => 
$this->order,
+                                                                               
        'filter' => $this->filter,'cat_id' => 
$this->cat_id,'allrows'=>$this->allrows,'member_id'=>$this->member_id,
+                                                                               
        'agreement_id'=>$id));
+                       $this->total_records = $this->so->total_records;
+
+                       $this->uicols   = $this->so->uicols;
+
+                       return $list;
+               }
+
+               function read_prizing($data)
+               {
+                       $list = $this->so->read_prizing($data);
+                       $this->total_records = $this->so->total_records;
+
+                       $this->uicols   = $this->so->uicols;
+
+                       for ($i=0; $i<count($list); $i++)
+                       {
+                               $list[$i]['index_date']  = 
$GLOBALS['phpgw']->common->show_date($list[$i]['index_date'],$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']);
+                       }
+
+                       return $list;
+               }
+
+               function read_event($data)
+               {
+                       $boalarm                = 
CreateObject($this->currentapp.'.boalarm');
+                       $event  = $this->so->read_single($data);
+                       $event['alarm_date']=$event['termination_date'];
+                       $event['alarm'] = 
$boalarm->read_alarms($type='agreement',$data['agreement_id']);
+                       return $event;
+               }
+
+               function read_single($data)
+               {
+                       $agreement      = $this->so->read_single($data);
+                       $dateformat = 
$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
+                       $agreement['start_date']                = 
$GLOBALS['phpgw']->common->show_date($agreement['start_date'],$dateformat);
+                       $agreement['end_date']          = 
$GLOBALS['phpgw']->common->show_date($agreement['end_date'],$dateformat);
+                       if($agreement['termination_date'])
+                       {
+                               $agreement['termination_date']= 
$GLOBALS['phpgw']->common->show_date($agreement['termination_date'],$dateformat);
+                       }
+
+                       $agreement = $this->convert_attribute($agreement);
+
+                       $this->vfs->override_acl = 1;
+
+                       $agreement['files'] = $this->vfs->ls (array(
+                            'string' => $this->fakebase. '/' . 'agreement' .  
'/' . $data['agreement_id'],
+                            'relatives' => array(RELATIVE_NONE)));
+
+                       $this->vfs->override_acl = 0;
+
+                       if(!$agreement['files'][0]['file_id'])
+                       {
+                               unset($agreement['files']);
+                       }
+
+                       return $agreement;
+
+               }
+
+               function read_single_item($data)
+               {
+                       $item   = $this->so->read_single_item($data);
+//_debug_array($item);
+                       $item   = $this->convert_attribute($item,True);
+                       return $item;
+               }
+
+               function convert_attribute($list,$detail='')
+               {
+                       if($detail)
+                       {
+                               $this->so->role = 'detail';
+                       }
+                       $contacts                       = 
CreateObject('phpgwapi.contacts');
+
+                       $vendor = CreateObject($this->currentapp.'.soactor');
+                       $vendor->role = 'vendor';
+
+                       $dateformat = 
$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
+
+                       $input_type_array = array(
+                               'R' => 'radio',
+                               'CH' => 'checkbox',
+                               'LB' => 'listbox'
+                       );
+
+                       $sep = '/';
+                       $dlarr[strpos($dateformat,'Y')] = 'Y';
+                       $dlarr[strpos($dateformat,'m')] = 'm';
+                       $dlarr[strpos($dateformat,'d')] = 'd';
+                       ksort($dlarr);
+
+                       $dateformat= (implode($sep,$dlarr));
+
+//html_print_r($list);
+                       $m=0;
+                       for ($i=0;$i<count($list['attributes']);$i++)
+                       {
+                               if($list['attributes'][$i]['datatype']=='D' && 
$list['attributes'][$i]['value'])
+                               {
+                                       $timestamp_date= 
mktime(0,0,0,date(m,strtotime($list['attributes'][$i]['value'])),date(d,strtotime($list['attributes'][$i]['value'])),date(y,strtotime($list['attributes'][$i]['value'])));
+                                       $list['attributes'][$i]['value']        
= $GLOBALS['phpgw']->common->show_date($timestamp_date,$dateformat);
+                               }
+                               if($list['attributes'][$i]['datatype']=='AB')
+                               {
+                                       if($list['attributes'][$i]['value'])
+                                       {
+                                               $contact_data   = 
$contacts->read_single_entry($list['attributes'][$i]['value'],array('n_given'=>'n_given','n_family'=>'n_family','email'=>'email'));
+                                               
$list['attributes'][$i]['contact_name'] = $contact_data[0]['n_family'] . ', ' . 
$contact_data[0]['n_given'];
+                                       }
+
+                                       $insert_record_list[]   = 
$list['attributes'][$i]['name'];
+                                       $lookup_link            = 
$GLOBALS['phpgw']->link('/index.php','menuaction='.$this->currentapp.'.uilookup.addressbook&column='
 . $list['attributes'][$i]['name']);
+
+                                       $lookup_functions[$m]['name'] = 
'lookup_'. $list['attributes'][$i]['name'] .'()';
+                                       $lookup_functions[$m]['action'] = 
'Window1=window.open('."'" . $lookup_link ."'" 
.',"Search","width=800,height=700,toolbar=no,scrollbars=yes,resizable=yes");';
+                                       $m++;
+                               }
+                               
if($list['attributes'][$i]['datatype']=='VENDOR')
+                               {
+                                       if($list['attributes'][$i]['value'])
+                                       {
+                                               $vendor_data    = 
$vendor->read_single(array('actor_id'=>$list['attributes'][$i]['value']));
+
+                                               for 
($n=0;$n<count($vendor_data['attributes']);$n++)
+                                               {
+                                                       
if($vendor_data['attributes'][$n]['name'] == 'org_name')
+                                                       {
+                                                               
$list['attributes'][$i]['vendor_name']= $vendor_data['attributes'][$n]['value'];
+                                                               $n 
=count($vendor_data['attributes']);
+                                                       }
+                                               }
+                                       }
+
+                                       $insert_record_list[]   = 
$list['attributes'][$i]['name'];
+                                       $lookup_link            = 
$GLOBALS['phpgw']->link('/index.php','menuaction='.$this->currentapp.'.uilookup.vendor&column='
 . $list['attributes'][$i]['name']);
+
+                                       $lookup_functions[$m]['name'] = 
'lookup_'. $list['attributes'][$i]['name'] .'()';
+                                       $lookup_functions[$m]['action'] = 
'Window1=window.open('."'" . $lookup_link ."'" 
.',"Search","width=800,height=700,toolbar=no,scrollbars=yes,resizable=yes");';
+                                       $m++;
+                               }
+
+                               if($list['attributes'][$i]['datatype']=='R' || 
$list['attributes'][$i]['datatype']=='CH' || 
$list['attributes'][$i]['datatype']=='LB')
+                               {
+                                       $list['attributes'][$i]['choice']       
= $this->so->read_attrib_choice($list['attributes'][$i]['attrib_id']);
+                                       
$input_type=$input_type_array[$list['attributes'][$i]['datatype']];
+
+                                       
if($list['attributes'][$i]['datatype']=='CH')
+                                       {
+                                               
$list['attributes'][$i]['value']=unserialize($list['attributes'][$i]['value']);
+                                               
$list['attributes'][$i]['choice'] = 
$this->bocommon->select_multi_list_2($list['attributes'][$i]['value'],$list['attributes'][$i]['choice'],$input_type);
+
+                                       }
+                                       else
+                                       {
+                                               for 
($j=0;$j<count($list['attributes'][$i]['choice']);$j++)
+                                               {
+                                                       
$list['attributes'][$i]['choice'][$j]['input_type']=$input_type;
+                                                       
if($list['attributes'][$i]['choice'][$j]['id']==$list['attributes'][$i]['value'])
+                                                       {
+                                                               
$list['attributes'][$i]['choice'][$j]['checked']='checked';
+                                                       }
+                                               }
+                                       }
+                               }
+
+                               $list['attributes'][$i]['datatype_text'] = 
$this->bocommon->translate_datatype($list['attributes'][$i]['datatype']);
+                               $list['attributes'][$i]['counter']      = $i;
+                               $list['attributes'][$i]['type_id']      = 
$data['type_id'];
+                       }
+
+                       for ($j=0;$j<count($lookup_functions);$j++)
+                       {
+                               $list['lookup_functions'] .= 'function ' . 
$lookup_functions[$j]['name'] ."\r\n";
+                               $list['lookup_functions'] .= '{'."\r\n";
+                               $list['lookup_functions'] .= 
$lookup_functions[$j]['action'] ."\r\n";
+                               $list['lookup_functions'] .= '}'."\r\n";
+                       }
+
+                       
$GLOBALS['phpgw']->session->appsession('insert_record_agreement' . 
!!$detail,$this->currentapp,$insert_record_list);
+
+//html_print_r($list);
+                       return $list;
+
+               }
+
+               function convert_attribute_save($values_attribute='')
+               {
+
+                       for ($i=0;$i<count($values_attribute);$i++)
+                       {
+                               if($values_attribute[$i]['datatype']=='CH' && 
$values_attribute[$i]['value'])
+                               {
+                                       $values_attribute[$i]['value'] = 
serialize($values_attribute[$i]['value']);
+                               }
+                               if($values_attribute[$i]['datatype']=='R' && 
$values_attribute[$i]['value'])
+                               {
+                                       $values_attribute[$i]['value'] = 
$values_attribute[$i]['value'][0];
+                               }
+
+                               if($values_attribute[$i]['datatype']=='N' && 
$values_attribute[$i]['value'])
+                               {
+                                       $values_attribute[$i]['value'] = 
str_replace(",",".",$values_attribute[$i]['value']);
+                               }
+
+                               if($values_attribute[$i]['datatype']=='D' && 
$values_attribute[$i]['value'])
+                               {
+                                       $values_attribute[$i]['value'] = 
date($this->bocommon->dateformat,$this->bocommon->date_to_timestamp($values_attribute[$i]['value']));
+                               }
+                       }
+
+                       return $values_attribute;
+               }
+
+               function save($values,$values_attribute='',$action='')
+               {
+
+                       $values['start_date']   = 
$this->bocommon->date_to_timestamp($values['start_date']);
+                       $values['end_date']     = 
$this->bocommon->date_to_timestamp($values['end_date']);
+                       $values['termination_date']     = 
$this->bocommon->date_to_timestamp($values['termination_date']);
+
+                       $values_attribute = 
$this->convert_attribute_save($values_attribute);
+
+                       if ($action=='edit')
+//                     if ($values['agreement_id'])
+                       {
+                               if ($values['agreement_id'] != 0)
+                               {
+                                       
$receipt=$this->so->edit($values,$values_attribute);
+
+                                       if($values['delete_file'])
+                                       {
+                                               for 
($i=0;$i<count($values['delete_file']);$i++)
+                                               {
+                                                       $file = 
$this->fakebase. SEP . 'agreement' . SEP . $values['agreement_id'] . SEP . 
$values['delete_file'][$i];
+
+                                                       
if($this->vfs->file_exists(array(
+                                                                       
'string' => $file,
+                                                                       
'relatives' => Array(RELATIVE_NONE)
+                                                               )))
+                                                       {
+                                                               
$this->vfs->override_acl = 1;
+
+                                                               
if(!$this->vfs->rm (array(
+                                                                       
'string' => $file,
+                                                                    
'relatives' => array(
+                                                                         
RELATIVE_NONE
+                                                                    )
+                                                               )))
+                                                               {
+                                                                       
$receipt['error'][]=array('msg'=>lang('failed to delete file') . ' :'. 
$this->fakebase. SEP . 'agreement'. SEP . $values['agreement_id'] . SEP 
.$values['delete_file'][$i]);
+                                                               }
+                                                               else
+                                                               {
+                                                                       
$receipt['message'][]=array('msg'=>lang('file deleted') . ' :'. 
$this->fakebase. SEP . 'agreement'. SEP . $values['id'] . SEP . 
$values['delete_file'][$i]);
+                                                               }
+                                                               
$this->vfs->override_acl = 0;
+                                                       }
+                                               }
+                                       }
+                               }
+                       }
+                       else
+                       {
+                               $receipt = 
$this->so->add($values,$values_attribute);
+                       }
+                       return $receipt;
+               }
+
+               function save_item($values,$values_attribute='')
+               {
+//_debug_array($values);
+                       $values['m_cost']       = 
str_replace(",",".",$values['m_cost']);
+                       $values['w_cost']       = 
str_replace(",",".",$values['w_cost']);
+                       $values['total_cost']           = $values['m_cost'] + 
$values['w_cost'];
+
+                       if ($values['index_count'] > 0)
+                       {
+                               if ($values['id'] != 0)
+                               {
+                                       $receipt=$this->so->edit_item($values);
+                               }
+                       }
+                       else
+                       {
+                               $receipt = $this->so->add_item($values);
+                       }
+                       return $receipt;
+               }
+
+
+               function update($values)
+               {
+                       $values['date'] = 
$this->bocommon->date_to_timestamp($values['date']);
+
+                       return $this->so->update($values);
+               }
+
+               function delete_last_index($agreement_id,$id)
+               {
+                       $this->so->delete_last_index($agreement_id,$id);
+               }
+
+
+               function delete_item($agreement_id,$activity_id)
+               {
+                       $this->so->delete_item($agreement_id,$activity_id);
+               }
+
+               function delete($agreement_id='',$id='',$attrib='')
+               {
+                       if ($attrib)
+                       {
+                               $this->so->delete_attrib($id);
+                       }
+                       else
+                       {
+                               $this->so->delete($agreement_id);
+                       }
+               }
+
+               function read_attrib($type_id='')
+               {
+                       $attrib = $this->so->read_attrib(array('start' => 
$this->start,'query' => $this->query,'sort' => $this->sort,'order' => 
$this->order,
+                                                                               
        'allrows'=>$this->allrows));
+
+                       for ($i=0; $i<count($attrib); $i++)
+                       {
+                               $attrib[$i]['datatype'] = 
$this->bocommon->translate_datatype($attrib[$i]['datatype']);
+                       }
+
+                       $this->total_records = $this->so->total_records;
+
+                       return $attrib;
+               }
+
+               function read_single_attrib($id)
+               {
+                       return $this->so->read_single_attrib($id);
+               }
+
+               function resort_attrib($data)
+               {
+                       $this->so->resort_attrib($data);
+               }
+
+               function save_attrib($attrib,$action='')
+               {
+                       if ($action=='edit')
+                       {
+                               if ($attrib['id'] != '')
+                               {
+
+                                       $receipt = 
$this->so->edit_attrib($attrib);
+                               }
+                       }
+                       else
+                       {
+                               $receipt = $this->so->add_attrib($attrib);
+                       }
+                       return $receipt;
+               }
+
+               function column_list($selected='',$allrows='')
+               {
+                       if(!$selected)
+                       {
+                               
$selected=$GLOBALS['phpgw_info']['user']['preferences'][$this->currentapp]["agreement_columns"];
+                       }
+
+                       $columns = 
$this->so->read_attrib(array('allrows'=>$allrows,'column_list'=>True));
+
+                       
$column_list=$this->bocommon->select_multi_list($selected,$columns);
+
+                       return $column_list;
+               }
+
+               function request_next_id()
+               {
+                               return $this->so->request_next_id();
+               }
+
+               function create_home_dir($receipt='')
+               {
+                       if(!$this->vfs->file_exists(array(
+                                       'string' => $this->fakebase. SEP . 
'agreement',
+                                       'relatives' => Array(RELATIVE_NONE)
+                               )))
+                       {
+                               $this->vfs->override_acl = 1;
+
+                               if(!$this->vfs->mkdir (array(
+                                    'string' => $this->fakebase. SEP . 
'agreement',
+                                    'relatives' => array(
+                                         RELATIVE_NONE
+                                    )
+                               )))
+                               {
+                                       
$receipt['error'][]=array('msg'=>lang('failed to create directory') . ' :'. 
$this->fakebase. SEP . 'agreement');
+                               }
+                               else
+                               {
+                                       
$receipt['message'][]=array('msg'=>lang('directory created') . ' :'. 
$this->fakebase. SEP . 'agreement');
+                               }
+                               $this->vfs->override_acl = 0;
+                       }
+
+                       return $receipt;
+               }
+
+               function create_document_dir($id='')
+               {
+
+                       if(!$this->vfs->file_exists(array(
+                                       'string' => $this->fakebase. SEP . 
'agreement' .  SEP . $id,
+                                       'relatives' => Array(RELATIVE_NONE)
+                               )))
+                       {
+                               $this->vfs->override_acl = 1;
+                               if(!$this->vfs->mkdir (array(
+                                    'string' => $this->fakebase. SEP . 
'agreement' .  SEP . $id,
+                                    'relatives' => array(
+                                         RELATIVE_NONE
+                                    )
+                               )))
+                               {
+                                       
$receipt['error'][]=array('msg'=>lang('failed to create directory') . ' :'. 
$this->fakebase. SEP  . 'agreement' .  SEP . $id);
+                               }
+                               else
+                               {
+                                       
$receipt['message'][]=array('msg'=>lang('directory created') . ' :'. 
$this->fakebase. SEP . 'agreement' .  SEP . $id);
+                               }
+                               $this->vfs->override_acl = 0;
+                       }
+
+//_debug_array($receipt);
+                       return $receipt;
+               }
+
+               function get_agreement_group_list($selected='')
+               {
+                       $agreement_groups= 
$this->so->get_agreement_group_list();
+
+                       while (is_array($agreement_groups) && 
list(,$agreement_group_entry) = each($agreement_groups))
+                       {
+                               $sel_agreement_group_entry = '';
+                               if ($agreement_group_entry['id']==$selected)
+                               {
+                                       $sel_agreement_group_entry = 'selected';
+                               }
+
+                               $agreement_group_list[] = array
+                               (
+                                       'id'    => $agreement_group_entry['id'],
+                                       'name'          => 
$agreement_group_entry['name'],
+                                       'selected'      => 
$sel_agreement_group_entry
+                               );
+                       }
+
+                       for ($i=0;$i<count($agreement_group_list);$i++)
+                       {
+                               if ($agreement_group_list[$i]['selected'] != 
'selected')
+                               {
+                                       
unset($agreement_group_list[$i]['selected']);
+                               }
+                       }
+
+                       return $agreement_group_list;
+               }
+
+               function read_group_activity($group_id='',$agreement_id='')
+               {
+                       $activity_list = 
$this->so->read_group_activity($group_id,$agreement_id);
+                       $this->uicols   = $this->so->uicols;
+                       return $activity_list;
+               }
+
+               function add_activity($values='',$agreement_id='')
+               {
+                       return $this->so->add_activity($values,$agreement_id);
+               }
+
+               function select_status_list($format='',$selected='')
+               {
+                       switch($format)
+                       {
+                               case 'select':
+                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('status_select'));
+                                       break;
+                               case 'filter':
+                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('status_filter'));
+                                       break;
+                       }
+
+                       $status_entries= $this->so->select_status_list();
+
+                       while (is_array($status_entries) && list(,$status) = 
each($status_entries))
+                       {
+                               $sel_status = '';
+                               if ($status['id']==$selected)
+                               {
+                                       $sel_status = 'selected';
+                               }
+
+                               $status_list[] = array
+                               (
+                                       'id'            => $status['id'],
+                                       'name'          => $status['name'],
+                                       'selected'      => $sel_status
+                               );
+                       }
+
+                       for ($i=0;$i<count($status_list);$i++)
+                       {
+                               if ($status_list[$i]['selected'] != 'selected')
+                               {
+                                       unset($status_list[$i]['selected']);
+                               }
+                       }
+
+                       return $status_list;
+               }
+               
+               function get_activity_descr($id)
+               {
+                       return $this->so->get_activity_descr($id);
+               }
+       }
+?>
Index: property/inc/class.boalarm.inc.php
diff -u property/inc/class.boalarm.inc.php:1.11 
property/inc/class.boalarm.inc.php:1.12
--- property/inc/class.boalarm.inc.php:1.11     Fri Jan 27 14:05:43 2006
+++ property/inc/class.boalarm.inc.php  Fri Feb  3 12:05:49 2006
@@ -1,481 +1,481 @@
-<?php
-       /**
-       * phpGroupWare - property: a Facilities Management System.
-       *
-       * @author Sigurd Nes <address@hidden>
-       * @copyright Copyright (C) 2003-2005 Free Software Foundation, Inc. 
http://www.fsf.org/
-       * @license http://www.gnu.org/licenses/gpl.html GNU General Public 
License
-       * @internal Development of this application was funded by 
http://www.bergen.kommune.no/bbb_/ekstern/
-       * @package property
-       * @subpackage admin
-       * @version $Id: class.boalarm.inc.php,v 1.11 2006/01/27 14:05:43 
sigurdne Exp $
-       */
-
-       /**
-        * Description
-        * @package property
-        */
-
-       class boalarm
-       {
-
-               var $public_functions = array
-               (
-                       'send_alarm' => True
-               );
-
-               function boalarm()
-               {
-
-                       $GLOBALS['phpgw_info']['flags']['currentapp']   =       
'property';
-                       $this->currentapp               = 
$GLOBALS['phpgw_info']['flags']['currentapp'];
-                       if (!is_object($GLOBALS['phpgw']->asyncservice))
-                       {
-                               $GLOBALS['phpgw']->asyncservice = 
CreateObject('phpgwapi.asyncservice');
-                       }
-                       $this->async = &$GLOBALS['phpgw']->asyncservice;
-                       $this->so                               = 
CreateObject($this->currentapp.'.soalarm');
-                       $this->bocommon                         = 
CreateObject($this->currentapp.'.bocommon');
-                       if ($session)
-                       {
-                               $this->read_sessiondata();
-                               $this->use_session = True;
-                       }
-
-                       $start  = get_var('start',array('POST','GET'));
-                       $query  = get_var('query',array('POST','GET'));
-                       $sort   = get_var('sort',array('POST','GET'));
-                       $order  = get_var('order',array('POST','GET'));
-                       $filter = get_var('filter',array('POST','GET'));
-                       $cat_id = get_var('cat_id',array('POST','GET'));
-                       $method_id      = 
get_var('method_id',array('POST','GET'));
-                       $allrows                        = 
get_var('allrows',array('POST','GET'));
-
-                       if ($start)
-                       {
-                               $this->start=$start;
-                       }
-                       else
-                       {
-                               $this->start=0;
-                       }
-
-                       if(isset($query))
-                       {
-                               $this->query = $query;
-                       }
-                       if(!empty($filter))
-                       {
-                               $this->filter = $filter;
-                       }
-                       if(isset($sort))
-                       {
-                               $this->sort = $sort;
-                       }
-                       if(isset($order))
-                       {
-                               $this->order = $order;
-                       }
-                       if(isset($cat_id) && !empty($cat_id))
-                       {
-                               $this->cat_id = $cat_id;
-                       }
-                       else
-                       {
-                               unset($this->cat_id);
-                       }
-                       if(isset($method_id) && !empty($method_id))
-                       {
-                               $this->method_id = $method_id;
-                       }
-                       else
-                       {
-                               unset($this->method_id);
-                       }
-                       if(isset($allrows))
-                       {
-                               $this->allrows = $allrows;
-                       }
-               }
-
-               function save_sessiondata($data)
-               {
-                       if ($this->use_session)
-                       {
-                               
$GLOBALS['phpgw']->session->appsession('session_data','owner',$data);
-                       }
-               }
-
-               function read_sessiondata()
-               {
-                       $data = 
$GLOBALS['phpgw']->session->appsession('session_data','owner');
-
-                       $this->start    = $data['start'];
-                       $this->query    = $data['query'];
-                       $this->filter   = $data['filter'];
-                       $this->sort             = $data['sort'];
-                       $this->order    = $data['order'];
-                       $this->cat_id   = $data['cat_id'];
-                       $this->method_id        = $data['method_id'];
-               }
-
-
-               function select_method_list($selected='')
-               {
-                       $list = $this->so->select_method_list();
-                       $list = $this->bocommon->select_list($selected,$list);
-                       return $list;
-               }
-
-               function read_single_method($id)
-               {
-                       return $this->so->read_single_method($id);
-               }
-
-               function read()
-               {
-                       $jobs = $this->so->read(array(id=>'%','start' => 
$this->start,'query' => $this->query,'sort' => $this->sort,'order' => 
$this->order,
-                                                                               
        'filter' => $this->filter,'allrows'=>$this->allrows));
-                       $this->total_records    = $this->so->total_records;
-                       return $jobs;
-               }
-
-               /*!
-               @function read_alarms
-               @abstract read the alarms of a calendar-event specified by 
$cal_id
-               @returns array of alarms with alarm-id as key
-               @note the alarm-id is a string of 'cal:'.$cal_id.':'.$alarm_nr, 
it is used as the job-id too
-               */
-               function read_alarms($type='',$input_id,$text='')
-               {
-                       $alarms = array();
-
-                       if ($jobs = $this->async->read($type . 
':'.intval($input_id).':%'))
-                       {
-                               foreach($jobs as $id => $job)
-                               {
-                                       $alarm                          = 
$job['data']; // text, enabled
-                                       $alarm['alarm_id']      = $id;
-                                       $alarm['time']          = 
$GLOBALS['phpgw']->common->show_date($job['next']);
-                                       $alarm['user']          = 
$GLOBALS['phpgw']->accounts->id2name($alarm['owner']);
-                                       $alarm['text']          = $text;
-
-                                       $alarms[] = $alarm;
-                               }
-                       }
-                       return $alarms;
-               }
-
-               /*!
-               @function read_alarm
-               @abstract read a single alarm specified by it's $id
-               @returns array with data of the alarm
-               @note the alarm-id is a string of 'cal:'.$cal_id.':'.$alarm_nr, 
it is used as the job-id too
-               */
-               function read_alarm($alarm_type,$id)
-               {
-                       if (!($jobs = $this->async->read($id)))
-                       {
-                               return False;
-                       }
-
-                       $alarm         = $jobs[$id]['data'];    // text, enabled
-                       $alarm['id']   = $id;
-                       $alarm['time'] = $jobs[$id]['next'];
-                       $alarm['times'] = $jobs[$id]['times'];
-
-//                     echo "<p>read_alarm('$id')="; print_r($alarm); echo 
"</p>\n";
-                       return $alarm;
-               }
-
-
-
-               /*!
-               @function enable
-               @abstract enable or disable one or more alarms identified by 
its ids
-               @syntax enable($ids,$enable=True)
-               @param $ids array with alarm ids as keys (!)
-               @returns the number of alarms enabled or -1 for insuficent 
permission to do so
-               @note Not found alarms or insuficent perms stop the enableing 
of multiple alarms
-               */
-               function enable_alarm($alarm_type,$alarms,$enable=True)
-               {
-                       $enabled = 0;
-                       foreach ($alarms as $id => $field)
-                       {
-                               $temp = explode(':',$id);
-                               $alarm_type = $temp[0];
-
-                               if (!($alarm = 
$this->read_alarm($alarm_type,$id)))
-                               {
-                                       return 0;       // alarm not found
-                               }
-                               if (!$alarm['enabled'] == !$enable)
-                               {
-                                       continue;       // nothing to do
-                               }
-/*                             if ($enable && 
!$this->check_perms(PHPGW_ACL_SETALARM,$alarm['owner']) ||
-                                       !$enable && 
!$this->check_perms(PHPGW_ACL_DELETEALARM,$alarm['owner']))
-                               {
-                                       return -1;
-                               }
-*/
-                               $alarm['enabled'] = intval(!$alarm['enabled']);
-
-                               if 
($this->save_alarm($alarm_type,$alarm['event_id'],$alarm))
-                               {
-                                       ++$enabled;
-                               }
-                       }
-                       return $enabled;
-               }
-
-
-               /*!
-               @function save_alarm
-               @abstract saves a new or updated alarm
-               @syntax save_alarm($cal_id,$alarm,$id=False)
-               @param $cal_id Id of the calendar-entry
-               @param $alarm array with fields: text, owner, enabled, ..
-               */
-               function save_alarm($alarm_type,$event_id,$alarm,$method='')
-               {
-                       if(!$method)
-                       {
-                               $method = $this->currentapp 
.'.boalarm.send_alarm';
-                       }
-//                     echo "<p>save_alarm(event_id=$event_id, alarm="; 
print_r($alarm); echo ")</p>\n";
-
-                       if (!$alarm['id'])
-                       {
-                               $alarms = 
$this->read_alarms($alarm_type,$event_id);    // find a free alarm#
-                               $n = count($alarms);
-                               do
-                               {
-                                       $id = $alarm_type 
.':'.intval($event_id).':'.$n;
-                                       ++$n;
-                               }
-                               while (@isset($alarms[$id]));
-
-                               $alarm[$alarm_type.'_id'] = $event_id;          
// we need the back-reference
-
-                               $alarm['id'] = $id;
-
-                               if 
(!$this->async->set_timer($alarm['times'],$id,$method,$alarm))
-                               {
-                                       return False;
-                               }
-                               return $id;
-                       }
-                       else
-                       {
-                               $this->async->cancel_timer($alarm['id']);
-                               
$this->async->set_timer($alarm['times'],$alarm['id'],$method,$alarm);
-                               return $alarm['id'];
-                       }
-               }
-
-               /*!
-               @function add_alarm
-               @abstract adds a new alarm to an event
-               @syntax add(&$event,$time,$login_id)
-               @param &$event event to add the alarm too
-               @param $time for the alarm in sec before the starttime of the 
event
-               @param $login_id user to alarm
-               @returns the alarm or False
-               */
-               function add_alarm($alarm_type,&$event,$time,$owner)
-               {
-/*                     if (!$this->check_perms(PHPGW_ACL_SETALARM,$owner) || 
!($cal_id = $event['id']))
-                       {
-                               return False;
-                       }
-*/
-                       if(!$owner>0)
-                       {
-                               $receipt['error'][]=array('msg'=>lang('No user 
selected'));
-                               return  $receipt;
-                       }
-
-                       $alarm = Array(
-                               'time'    => ($event['alarm_date'] - $time), 
//($etime=$this->bo->maketime($event['start'])) - $time,
-                               'offset'  => $time,
-                               'owner'   => $owner,
-                               'enabled' => 1,
-                               'event_id' => $event['id'],
-                               'event_name' => $event['name']
-                       );
-
-                       $alarm['times'] = $alarm['time'];
-                       $alarm['id'] = 
$this->save_alarm($alarm_type,$event['id'],$alarm);
-
-                       $event['alarm'][$alarm['id']] = $alarm;
-
-                       return $alarm;
-               }
-
-
-               /*!
-               @function delete
-               @abstract delete one or more alarms identified by its ids
-               @syntax delete($ids)
-               @param $ids array with alarm ids as keys (!)
-               @returns the number of alarms deleted or -1 for insuficent 
permission to do so
-               @note Not found alarms or insuficent perms stop the deleting of 
multiple alarms
-               */
-               function delete_alarm($alarm_type,$alarms)
-               {
-                       $deleted = 0;
-                       foreach ($alarms as $id => $field)
-                       {
-                               if (!($alarm = 
$this->read_alarm($alarm_type,$id)))
-                               {
-                                       return 0;       // alarm not found
-                               }
-/*                             if 
(!$this->check_perms(PHPGW_ACL_DELETEALARM,$alarm['owner']))
-                               {
-                                       return -1;
-                               }
-*/
-                               if ($this->async->cancel_timer($id))
-                               {
-                                       ++$deleted;
-                               }
-                       }
-                       return $deleted;
-               }
-
-
-               function test_cron()
-               {
-                       $this->async->check_run('crontab');
-               }
-
-
-               function send_alarm($alarm)
-               {
-
-       //              echo "<p>boalarm::send_alarm("; print_r($alarm); echo 
")</p>\n";
-                       $GLOBALS['phpgw_info']['user']['account_id'] = 
$this->owner = $alarm['owner'];
-
-                       if (!$alarm['enabled'] || !$alarm['owner'])
-                       {
-                               return False;   // event not found
-                       }
-
-                       $this->config           = 
CreateObject('phpgwapi.config');
-                       $this->config->read_repository();
-                       $this->send                     = 
CreateObject('phpgwapi.send');
-
-                       $members = array();
-
-                       // build subject
-                       $subject = lang('Alarm').': '.$alarm['event_name'];
-
-                       $prefs_user = 
$this->bocommon->create_preferences($this->currentapp,$alarm['owner']);
-
-                       $from_address=$prefs_user['email'];
-
-       //-----------from--------
-
-
-                       
$current_user_id=$GLOBALS['phpgw_info']['user']['account_id'];
-
-                       $current_user_firstname = 'FM';
-
-                       $current_user_lastname  = 'System';
-
-                       $current_user_name= $user_firstname . " " 
.$user_lastname ;
-
-                       $current_prefs_user = 
$this->bocommon->create_preferences($this->currentapp,$alarm['owner']);
-                       $current_user_address=$current_prefs_user['email'];
-
-                       $headers = "Return-Path: <". $current_user_address 
.">\r\n";
-                       $headers .= "From: " . $current_user_name . "<" . 
$current_user_address .">\r\n";
-//                     $headers .= "Bcc: " . $current_user_name . "<" . 
$current_user_address .">\r\n";
-                       $headers .= "Content-type: text/html; 
charset=iso-8859-1\r\n";
-                       $headers .= "MIME-Version: 1.0\r\n";
-
-       //-----------from--------
-               // build body
-                       $body  = '';
-                       $body .= lang('Alarm').' #'.$alarm['event_id']."\n";
-                       $body .= lang('Name').': '.$alarm['event_name']."\n";
-                       if(!is_array($alarm['time']))
-                       {
-                               $body .= lang('Deadline').': '. 
$GLOBALS['phpgw']->common->show_date(($alarm['time']+$alarm['offset'])) ."\n";
-                       }
-                       $body .= lang('Assigned To').': 
'.$GLOBALS['phpgw']->accounts->id2name($alarm['owner'])."\n";
-
-                       // add assigned to recipients
-                       $members[] = array('account_id' => $alarm['owner'], 
'account_name' => $GLOBALS['phpgw']->accounts->id2name($alarm['owner']));
-
-                       $error = Array();
-                       $toarray = Array();
-                       $i=0;
-                       for ($i=0;$i<count($members);$i++)
-                       {
-                               if ($members[$i]['account_id'])
-                               {
-                                       $prefs = 
$this->bocommon->create_preferences($this->currentapp,$members[$i]['account_id']);
-                                       if (strlen($prefs['email'])> 
(strlen($members[$i]['account_name'])+1))
-                                       {
-                                               $toarray[$prefs['email']] = 
$prefs['email'];
-                                       }
-                                       else
-                                       {
-                                               $receipt['error'][] = 
array('msg'=> lang('Your message could not be sent!'));
-                                               $receipt['error'][] = 
array('msg'=>lang('This user has not defined an email address !') . ' : ' . 
$members[$i]['account_name']);
-                                       }
-                               }
-                       }
-
-                       if(count($toarray) > 1)
-                       {
-                               $to = implode(',',$toarray);
-                       }
-                       else
-                       {
-                               $to = current($toarray);
-                       }
-
-                       $mail_method= 
$this->config->config_data['fmwrkorder_mail'];
-//                     echo 'mail_method: '.$mail_method .'<BR>';
-
-                       if ($mail_method=='smtp'):
-                       {
-                               $rc = $this->send->msg('email', $to, $subject, 
stripslashes($body), '', $cc, 
$bcc,$current_user_address,$current_user_name,'txt');
-                       }
-                       elseif ($mail_method=='sendmail'):
-                       {
-                               $rc=    @mail($to,$subject,stripslashes($body), 
$headers);
-                       }
-                       else:
-                       {
-                               $receipt['error'][] = array('msg'=> 
lang('Mailing method is not chosen! (admin section)'));
-                       }
-                       endif;
-
-               //      $rc=1;
-                       if (!$rc)
-                       {
-                               $receipt['error'][] = array('msg'=> lang('Your 
message could not be sent by mail!'));
-                               $receipt['error'][] = array('msg'=> lang('The 
mail server returned'));
-                               $receipt['error'][] = array('msg'=> 'From :' . 
$current_user_name . '<' . $current_user_address .'>');
-                               $receipt['error'][] = array('msg'=> 'to: '.$to);
-                               $receipt['error'][] = array('msg'=> 'subject: 
'.$subject);
-                               $receipt['error'][] = array('msg'=> $body );
-       //                      $receipt['error'][] = array('msg'=> 'cc: ' . 
$cc);
-       //                      $receipt['error'][] = array('msg'=> 'bcc: 
'.$bcc);
-                               $receipt['error'][] = array('msg'=> 'group: 
'.$group_name);
-                               $receipt['error'][] = array('msg'=> 'err_code: 
'.$this->send->err['code']);
-                               $receipt['error'][] = array('msg'=> 'err_msg: 
'. htmlspecialchars($this->send->err['msg']));
-                               $receipt['error'][] = array('msg'=> 'err_desc: 
'. $GLOBALS['phpgw']->err['desc']);
-                       }
-
-//_debug_array($receipt);
-//                     return $receipt;
-               }
-
-       }
-?>
+<?php
+       /**
+       * phpGroupWare - property: a Facilities Management System.
+       *
+       * @author Sigurd Nes <address@hidden>
+       * @copyright Copyright (C) 2003-2005 Free Software Foundation, Inc. 
http://www.fsf.org/
+       * @license http://www.gnu.org/licenses/gpl.html GNU General Public 
License
+       * @internal Development of this application was funded by 
http://www.bergen.kommune.no/bbb_/ekstern/
+       * @package property
+       * @subpackage admin
+       * @version $Id: class.boalarm.inc.php,v 1.12 2006/02/03 12:05:49 
sigurdne Exp $
+       */
+
+       /**
+        * Description
+        * @package property
+        */
+
+       class boalarm
+       {
+
+               var $public_functions = array
+               (
+                       'send_alarm' => True
+               );
+
+               function boalarm()
+               {
+
+                       $GLOBALS['phpgw_info']['flags']['currentapp']   =       
'property';
+                       $this->currentapp               = 
$GLOBALS['phpgw_info']['flags']['currentapp'];
+                       if (!is_object($GLOBALS['phpgw']->asyncservice))
+                       {
+                               $GLOBALS['phpgw']->asyncservice = 
CreateObject('phpgwapi.asyncservice');
+                       }
+                       $this->async = &$GLOBALS['phpgw']->asyncservice;
+                       $this->so                               = 
CreateObject($this->currentapp.'.soalarm');
+                       $this->bocommon                         = 
CreateObject($this->currentapp.'.bocommon');
+                       if ($session)
+                       {
+                               $this->read_sessiondata();
+                               $this->use_session = True;
+                       }
+
+                       $start  = get_var('start',array('POST','GET'));
+                       $query  = get_var('query',array('POST','GET'));
+                       $sort   = get_var('sort',array('POST','GET'));
+                       $order  = get_var('order',array('POST','GET'));
+                       $filter = get_var('filter',array('POST','GET'));
+                       $cat_id = get_var('cat_id',array('POST','GET'));
+                       $method_id      = 
get_var('method_id',array('POST','GET'));
+                       $allrows                        = 
get_var('allrows',array('POST','GET'));
+
+                       if ($start)
+                       {
+                               $this->start=$start;
+                       }
+                       else
+                       {
+                               $this->start=0;
+                       }
+
+                       if(isset($query))
+                       {
+                               $this->query = $query;
+                       }
+                       if(!empty($filter))
+                       {
+                               $this->filter = $filter;
+                       }
+                       if(isset($sort))
+                       {
+                               $this->sort = $sort;
+                       }
+                       if(isset($order))
+                       {
+                               $this->order = $order;
+                       }
+                       if(isset($cat_id) && !empty($cat_id))
+                       {
+                               $this->cat_id = $cat_id;
+                       }
+                       else
+                       {
+                               unset($this->cat_id);
+                       }
+                       if(isset($method_id) && !empty($method_id))
+                       {
+                               $this->method_id = $method_id;
+                       }
+                       else
+                       {
+                               unset($this->method_id);
+                       }
+                       if(isset($allrows))
+                       {
+                               $this->allrows = $allrows;
+                       }
+               }
+
+               function save_sessiondata($data)
+               {
+                       if ($this->use_session)
+                       {
+                               
$GLOBALS['phpgw']->session->appsession('session_data','owner',$data);
+                       }
+               }
+
+               function read_sessiondata()
+               {
+                       $data = 
$GLOBALS['phpgw']->session->appsession('session_data','owner');
+
+                       $this->start    = $data['start'];
+                       $this->query    = $data['query'];
+                       $this->filter   = $data['filter'];
+                       $this->sort             = $data['sort'];
+                       $this->order    = $data['order'];
+                       $this->cat_id   = $data['cat_id'];
+                       $this->method_id        = $data['method_id'];
+               }
+
+
+               function select_method_list($selected='')
+               {
+                       $list = $this->so->select_method_list();
+                       $list = $this->bocommon->select_list($selected,$list);
+                       return $list;
+               }
+
+               function read_single_method($id)
+               {
+                       return $this->so->read_single_method($id);
+               }
+
+               function read()
+               {
+                       $jobs = $this->so->read(array(id=>'%','start' => 
$this->start,'query' => $this->query,'sort' => $this->sort,'order' => 
$this->order,
+                                                                               
        'filter' => $this->filter,'allrows'=>$this->allrows));
+                       $this->total_records    = $this->so->total_records;
+                       return $jobs;
+               }
+
+               /*!
+               @function read_alarms
+               @abstract read the alarms of a calendar-event specified by 
$cal_id
+               @returns array of alarms with alarm-id as key
+               @note the alarm-id is a string of 'cal:'.$cal_id.':'.$alarm_nr, 
it is used as the job-id too
+               */
+               function read_alarms($type='',$input_id,$text='')
+               {
+                       $alarms = array();
+
+                       if ($jobs = $this->async->read($type . 
':'.intval($input_id).':%'))
+                       {
+                               foreach($jobs as $id => $job)
+                               {
+                                       $alarm                          = 
$job['data']; // text, enabled
+                                       $alarm['alarm_id']      = $id;
+                                       $alarm['time']          = 
$GLOBALS['phpgw']->common->show_date($job['next']);
+                                       $alarm['user']          = 
$GLOBALS['phpgw']->accounts->id2name($alarm['owner']);
+                                       $alarm['text']          = $text;
+
+                                       $alarms[] = $alarm;
+                               }
+                       }
+                       return $alarms;
+               }
+
+               /*!
+               @function read_alarm
+               @abstract read a single alarm specified by it's $id
+               @returns array with data of the alarm
+               @note the alarm-id is a string of 'cal:'.$cal_id.':'.$alarm_nr, 
it is used as the job-id too
+               */
+               function read_alarm($alarm_type,$id)
+               {
+                       if (!($jobs = $this->async->read($id)))
+                       {
+                               return False;
+                       }
+
+                       $alarm         = $jobs[$id]['data'];    // text, enabled
+                       $alarm['id']   = $id;
+                       $alarm['time'] = $jobs[$id]['next'];
+                       $alarm['times'] = $jobs[$id]['times'];
+
+//                     echo "<p>read_alarm('$id')="; print_r($alarm); echo 
"</p>\n";
+                       return $alarm;
+               }
+
+
+
+               /*!
+               @function enable
+               @abstract enable or disable one or more alarms identified by 
its ids
+               @syntax enable($ids,$enable=True)
+               @param $ids array with alarm ids as keys (!)
+               @returns the number of alarms enabled or -1 for insuficent 
permission to do so
+               @note Not found alarms or insuficent perms stop the enableing 
of multiple alarms
+               */
+               function enable_alarm($alarm_type,$alarms,$enable=True)
+               {
+                       $enabled = 0;
+                       foreach ($alarms as $id => $field)
+                       {
+                               $temp = explode(':',$id);
+                               $alarm_type = $temp[0];
+
+                               if (!($alarm = 
$this->read_alarm($alarm_type,$id)))
+                               {
+                                       return 0;       // alarm not found
+                               }
+                               if (!$alarm['enabled'] == !$enable)
+                               {
+                                       continue;       // nothing to do
+                               }
+/*                             if ($enable && 
!$this->check_perms(PHPGW_ACL_SETALARM,$alarm['owner']) ||
+                                       !$enable && 
!$this->check_perms(PHPGW_ACL_DELETEALARM,$alarm['owner']))
+                               {
+                                       return -1;
+                               }
+*/
+                               $alarm['enabled'] = intval(!$alarm['enabled']);
+
+                               if 
($this->save_alarm($alarm_type,$alarm['event_id'],$alarm))
+                               {
+                                       ++$enabled;
+                               }
+                       }
+                       return $enabled;
+               }
+
+
+               /*!
+               @function save_alarm
+               @abstract saves a new or updated alarm
+               @syntax save_alarm($cal_id,$alarm,$id=False)
+               @param $cal_id Id of the calendar-entry
+               @param $alarm array with fields: text, owner, enabled, ..
+               */
+               function save_alarm($alarm_type,$event_id,$alarm,$method='')
+               {
+                       if(!$method)
+                       {
+                               $method = $this->currentapp 
.'.boalarm.send_alarm';
+                       }
+//                     echo "<p>save_alarm(event_id=$event_id, alarm="; 
print_r($alarm); echo ")</p>\n";
+
+                       if (!$alarm['id'])
+                       {
+                               $alarms = 
$this->read_alarms($alarm_type,$event_id);    // find a free alarm#
+                               $n = count($alarms);
+                               do
+                               {
+                                       $id = $alarm_type 
.':'.intval($event_id).':'.$n;
+                                       ++$n;
+                               }
+                               while (@isset($alarms[$id]));
+
+                               $alarm[$alarm_type.'_id'] = $event_id;          
// we need the back-reference
+
+                               $alarm['id'] = $id;
+
+                               if 
(!$this->async->set_timer($alarm['times'],$id,$method,$alarm))
+                               {
+                                       return False;
+                               }
+                               return $id;
+                       }
+                       else
+                       {
+                               $this->async->cancel_timer($alarm['id']);
+                               
$this->async->set_timer($alarm['times'],$alarm['id'],$method,$alarm);
+                               return $alarm['id'];
+                       }
+               }
+
+               /*!
+               @function add_alarm
+               @abstract adds a new alarm to an event
+               @syntax add(&$event,$time,$login_id)
+               @param &$event event to add the alarm too
+               @param $time for the alarm in sec before the starttime of the 
event
+               @param $login_id user to alarm
+               @returns the alarm or False
+               */
+               function add_alarm($alarm_type,&$event,$time,$owner)
+               {
+/*                     if (!$this->check_perms(PHPGW_ACL_SETALARM,$owner) || 
!($cal_id = $event['id']))
+                       {
+                               return False;
+                       }
+*/
+                       if(!$owner>0)
+                       {
+                               $receipt['error'][]=array('msg'=>lang('No user 
selected'));
+                               return  $receipt;
+                       }
+
+                       $alarm = Array(
+                               'time'    => ($event['alarm_date'] - $time), 
//($etime=$this->bo->maketime($event['start'])) - $time,
+                               'offset'  => $time,
+                               'owner'   => $owner,
+                               'enabled' => 1,
+                               'event_id' => $event['id'],
+                               'event_name' => $event['name']
+                       );
+
+                       $alarm['times'] = $alarm['time'];
+                       $alarm['id'] = 
$this->save_alarm($alarm_type,$event['id'],$alarm);
+
+                       $event['alarm'][$alarm['id']] = $alarm;
+
+                       return $alarm;
+               }
+
+
+               /*!
+               @function delete
+               @abstract delete one or more alarms identified by its ids
+               @syntax delete($ids)
+               @param $ids array with alarm ids as keys (!)
+               @returns the number of alarms deleted or -1 for insuficent 
permission to do so
+               @note Not found alarms or insuficent perms stop the deleting of 
multiple alarms
+               */
+               function delete_alarm($alarm_type,$alarms)
+               {
+                       $deleted = 0;
+                       foreach ($alarms as $id => $field)
+                       {
+                               if (!($alarm = 
$this->read_alarm($alarm_type,$id)))
+                               {
+                                       return 0;       // alarm not found
+                               }
+/*                             if 
(!$this->check_perms(PHPGW_ACL_DELETEALARM,$alarm['owner']))
+                               {
+                                       return -1;
+                               }
+*/
+                               if ($this->async->cancel_timer($id))
+                               {
+                                       ++$deleted;
+                               }
+                       }
+                       return $deleted;
+               }
+
+
+               function test_cron()
+               {
+                       $this->async->check_run('crontab');
+               }
+
+
+               function send_alarm($alarm)
+               {
+
+       //              echo "<p>boalarm::send_alarm("; print_r($alarm); echo 
")</p>\n";
+                       $GLOBALS['phpgw_info']['user']['account_id'] = 
$this->owner = $alarm['owner'];
+
+                       if (!$alarm['enabled'] || !$alarm['owner'])
+                       {
+                               return False;   // event not found
+                       }
+
+                       $this->config           = 
CreateObject('phpgwapi.config');
+                       $this->config->read_repository();
+                       $this->send                     = 
CreateObject('phpgwapi.send');
+
+                       $members = array();
+
+                       // build subject
+                       $subject = lang('Alarm').': '.$alarm['event_name'];
+
+                       $prefs_user = 
$this->bocommon->create_preferences($this->currentapp,$alarm['owner']);
+
+                       $from_address=$prefs_user['email'];
+
+       //-----------from--------
+
+
+                       
$current_user_id=$GLOBALS['phpgw_info']['user']['account_id'];
+
+                       $current_user_firstname = 'FM';
+
+                       $current_user_lastname  = 'System';
+
+                       $current_user_name= $user_firstname . " " 
.$user_lastname ;
+
+                       $current_prefs_user = 
$this->bocommon->create_preferences($this->currentapp,$alarm['owner']);
+                       $current_user_address=$current_prefs_user['email'];
+
+                       $headers = "Return-Path: <". $current_user_address 
.">\r\n";
+                       $headers .= "From: " . $current_user_name . "<" . 
$current_user_address .">\r\n";
+//                     $headers .= "Bcc: " . $current_user_name . "<" . 
$current_user_address .">\r\n";
+                       $headers .= "Content-type: text/html; 
charset=iso-8859-1\r\n";
+                       $headers .= "MIME-Version: 1.0\r\n";
+
+       //-----------from--------
+               // build body
+                       $body  = '';
+                       $body .= lang('Alarm').' #'.$alarm['event_id']."\n";
+                       $body .= lang('Name').': '.$alarm['event_name']."\n";
+                       if(!is_array($alarm['time']))
+                       {
+                               $body .= lang('Deadline').': '. 
$GLOBALS['phpgw']->common->show_date(($alarm['time']+$alarm['offset'])) ."\n";
+                       }
+                       $body .= lang('Assigned To').': 
'.$GLOBALS['phpgw']->accounts->id2name($alarm['owner'])."\n";
+
+                       // add assigned to recipients
+                       $members[] = array('account_id' => $alarm['owner'], 
'account_name' => $GLOBALS['phpgw']->accounts->id2name($alarm['owner']));
+
+                       $error = Array();
+                       $toarray = Array();
+                       $i=0;
+                       for ($i=0;$i<count($members);$i++)
+                       {
+                               if ($members[$i]['account_id'])
+                               {
+                                       $prefs = 
$this->bocommon->create_preferences($this->currentapp,$members[$i]['account_id']);
+                                       if (strlen($prefs['email'])> 
(strlen($members[$i]['account_name'])+1))
+                                       {
+                                               $toarray[$prefs['email']] = 
$prefs['email'];
+                                       }
+                                       else
+                                       {
+                                               $receipt['error'][] = 
array('msg'=> lang('Your message could not be sent!'));
+                                               $receipt['error'][] = 
array('msg'=>lang('This user has not defined an email address !') . ' : ' . 
$members[$i]['account_name']);
+                                       }
+                               }
+                       }
+
+                       if(count($toarray) > 1)
+                       {
+                               $to = implode(',',$toarray);
+                       }
+                       else
+                       {
+                               $to = current($toarray);
+                       }
+
+                       $mail_method= 
$this->config->config_data['fmwrkorder_mail'];
+//                     echo 'mail_method: '.$mail_method .'<BR>';
+
+                       if ($mail_method=='smtp'):
+                       {
+                               $rc = $this->send->msg('email', $to, $subject, 
stripslashes($body), '', $cc, 
$bcc,$current_user_address,$current_user_name,'txt');
+                       }
+                       elseif ($mail_method=='sendmail'):
+                       {
+                               $rc=    @mail($to,$subject,stripslashes($body), 
$headers);
+                       }
+                       else:
+                       {
+                               $receipt['error'][] = array('msg'=> 
lang('Mailing method is not chosen! (admin section)'));
+                       }
+                       endif;
+
+               //      $rc=1;
+                       if (!$rc)
+                       {
+                               $receipt['error'][] = array('msg'=> lang('Your 
message could not be sent by mail!'));
+                               $receipt['error'][] = array('msg'=> lang('The 
mail server returned'));
+                               $receipt['error'][] = array('msg'=> 'From :' . 
$current_user_name . '<' . $current_user_address .'>');
+                               $receipt['error'][] = array('msg'=> 'to: '.$to);
+                               $receipt['error'][] = array('msg'=> 'subject: 
'.$subject);
+                               $receipt['error'][] = array('msg'=> $body );
+       //                      $receipt['error'][] = array('msg'=> 'cc: ' . 
$cc);
+       //                      $receipt['error'][] = array('msg'=> 'bcc: 
'.$bcc);
+                               $receipt['error'][] = array('msg'=> 'group: 
'.$group_name);
+                               $receipt['error'][] = array('msg'=> 'err_code: 
'.$this->send->err['code']);
+                               $receipt['error'][] = array('msg'=> 'err_msg: 
'. htmlspecialchars($this->send->err['msg']));
+                               $receipt['error'][] = array('msg'=> 'err_desc: 
'. $GLOBALS['phpgw']->err['desc']);
+                       }
+
+//_debug_array($receipt);
+//                     return $receipt;
+               }
+
+       }
+?>
Index: property/inc/class.boasync.inc.php
diff -u property/inc/class.boasync.inc.php:1.5 
property/inc/class.boasync.inc.php:1.6
--- property/inc/class.boasync.inc.php:1.5      Fri Jan 27 14:05:43 2006
+++ property/inc/class.boasync.inc.php  Fri Feb  3 12:05:49 2006
@@ -1,164 +1,164 @@
-<?php
-       /**
-       * phpGroupWare - property: a Facilities Management System.
-       *
-       * @author Sigurd Nes <address@hidden>
-       * @copyright Copyright (C) 2003-2005 Free Software Foundation, Inc. 
http://www.fsf.org/
-       * @license http://www.gnu.org/licenses/gpl.html GNU General Public 
License
-       * @internal Development of this application was funded by 
http://www.bergen.kommune.no/bbb_/ekstern/
-       * @package property
-       * @subpackage admin
-       * @version $Id: class.boasync.inc.php,v 1.5 2006/01/27 14:05:43 
sigurdne Exp $
-       */
-
-       /**
-        * Description
-        * @package property
-        */
-
-       class boasync
-       {
-               var $start;
-               var $query;
-               var $filter;
-               var $sort;
-               var $order;
-               var $cat_id;
-
-               var $public_functions = array
-               (
-                       'read'                          => True,
-                       'read_single'           => True,
-                       'save'                          => True,
-                       'delete'                        => True,
-                       'check_perms'           => True
-               );
-
-               var $soap_functions = array(
-                       'list' => array(
-                               'in'  => 
array('int','int','struct','string','int'),
-                               'out' => array('array')
-                       ),
-                       'read' => array(
-                               'in'  => array('int','struct'),
-                               'out' => array('array')
-                       ),
-                       'save' => array(
-                               'in'  => array('int','struct'),
-                               'out' => array()
-                       ),
-                       'delete' => array(
-                               'in'  => array('int','struct'),
-                               'out' => array()
-                       )
-               );
-
-               function boasync($session=False)
-               {
-                       $this->currentapp       = 
$GLOBALS['phpgw_info']['flags']['currentapp'];
-                       $this->so               = 
CreateObject($this->currentapp.'.soasync');
-                       $this->socommon = 
CreateObject($this->currentapp.'.socommon');
-
-                       if ($session)
-                       {
-                               $this->read_sessiondata();
-                               $this->use_session = True;
-                       }
-
-                       $start  = get_var('start',array('POST','GET'));
-                       $query  = get_var('query',array('POST','GET'));
-                       $sort   = get_var('sort',array('POST','GET'));
-                       $order  = get_var('order',array('POST','GET'));
-                       $filter = get_var('filter',array('POST','GET'));
-                       $cat_id = get_var('cat_id',array('POST','GET'));
-
-                       if ($start)
-                       {
-                               $this->start=$start;
-                       }
-                       else
-                       {
-                               $this->start=0;
-                       }
-
-                       if(isset($query))
-                       {
-                               $this->query = $query;
-                       }
-                       if(!empty($filter))
-                       {
-                               $this->filter = $filter;
-                       }
-                       if(isset($sort))
-                       {
-                               $this->sort = $sort;
-                       }
-                       if(isset($order))
-                       {
-                               $this->order = $order;
-                       }
-                       if(isset($cat_id))
-                       {
-                               $this->cat_id = $cat_id;
-                       }
-               }
-
-               function save_sessiondata($data)
-               {
-                       if ($this->use_session)
-                       {
-                               
$GLOBALS['phpgw']->session->appsession('session_data','async',$data);
-                       }
-               }
-
-               function read_sessiondata()
-               {
-                       $data = 
$GLOBALS['phpgw']->session->appsession('session_data','async');
-
-                       $this->start    = $data['start'];
-                       $this->query    = $data['query'];
-                       $this->filter   = $data['filter'];
-                       $this->sort             = $data['sort'];
-                       $this->order    = $data['order'];
-                       $this->cat_id   = $data['cat_id'];
-               }
-
-
-               function read()
-               {
-                       $method = $this->so->read(array('start' => 
$this->start,'query' => $this->query,'sort' => $this->sort,'order' => 
$this->order));
-
-                       $this->total_records = $this->so->total_records;
-
-                       return $method;
-               }
-
-               function read_single($id)
-               {
-                       return $this->so->read_single($id);
-               }
-
-               function save($method,$action='')
-               {
-                       if ($action=='edit')
-                       {
-                               if ($method['id'] != '')
-                               {
-
-                                       $receipt = $this->so->edit($method);
-                               }
-                       }
-                       else
-                       {
-                               $receipt = $this->so->add($method);
-                       }
-                       return $receipt;
-
-               }
-
-               function delete($id)
-               {
-                       $this->so->delete($id);
-               }
-       }
-?>
+<?php
+       /**
+       * phpGroupWare - property: a Facilities Management System.
+       *
+       * @author Sigurd Nes <address@hidden>
+       * @copyright Copyright (C) 2003-2005 Free Software Foundation, Inc. 
http://www.fsf.org/
+       * @license http://www.gnu.org/licenses/gpl.html GNU General Public 
License
+       * @internal Development of this application was funded by 
http://www.bergen.kommune.no/bbb_/ekstern/
+       * @package property
+       * @subpackage admin
+       * @version $Id: class.boasync.inc.php,v 1.6 2006/02/03 12:05:49 
sigurdne Exp $
+       */
+
+       /**
+        * Description
+        * @package property
+        */
+
+       class boasync
+       {
+               var $start;
+               var $query;
+               var $filter;
+               var $sort;
+               var $order;
+               var $cat_id;
+
+               var $public_functions = array
+               (
+                       'read'                          => True,
+                       'read_single'           => True,
+                       'save'                          => True,
+                       'delete'                        => True,
+                       'check_perms'           => True
+               );
+
+               var $soap_functions = array(
+                       'list' => array(
+                               'in'  => 
array('int','int','struct','string','int'),
+                               'out' => array('array')
+                       ),
+                       'read' => array(
+                               'in'  => array('int','struct'),
+                               'out' => array('array')
+                       ),
+                       'save' => array(
+                               'in'  => array('int','struct'),
+                               'out' => array()
+                       ),
+                       'delete' => array(
+                               'in'  => array('int','struct'),
+                               'out' => array()
+                       )
+               );
+
+               function boasync($session=False)
+               {
+                       $this->currentapp       = 
$GLOBALS['phpgw_info']['flags']['currentapp'];
+                       $this->so               = 
CreateObject($this->currentapp.'.soasync');
+                       $this->socommon = 
CreateObject($this->currentapp.'.socommon');
+
+                       if ($session)
+                       {
+                               $this->read_sessiondata();
+                               $this->use_session = True;
+                       }
+
+                       $start  = get_var('start',array('POST','GET'));
+                       $query  = get_var('query',array('POST','GET'));
+                       $sort   = get_var('sort',array('POST','GET'));
+                       $order  = get_var('order',array('POST','GET'));
+                       $filter = get_var('filter',array('POST','GET'));
+                       $cat_id = get_var('cat_id',array('POST','GET'));
+
+                       if ($start)
+                       {
+                               $this->start=$start;
+                       }
+                       else
+                       {
+                               $this->start=0;
+                       }
+
+                       if(isset($query))
+                       {
+                               $this->query = $query;
+                       }
+                       if(!empty($filter))
+                       {
+                               $this->filter = $filter;
+                       }
+                       if(isset($sort))
+                       {
+                               $this->sort = $sort;
+                       }
+                       if(isset($order))
+                       {
+                               $this->order = $order;
+                       }
+                       if(isset($cat_id))
+                       {
+                               $this->cat_id = $cat_id;
+                       }
+               }
+
+               function save_sessiondata($data)
+               {
+                       if ($this->use_session)
+                       {
+                               
$GLOBALS['phpgw']->session->appsession('session_data','async',$data);
+                       }
+               }
+
+               function read_sessiondata()
+               {
+                       $data = 
$GLOBALS['phpgw']->session->appsession('session_data','async');
+
+                       $this->start    = $data['start'];
+                       $this->query    = $data['query'];
+                       $this->filter   = $data['filter'];
+                       $this->sort             = $data['sort'];
+                       $this->order    = $data['order'];
+                       $this->cat_id   = $data['cat_id'];
+               }
+
+
+               function read()
+               {
+                       $method = $this->so->read(array('start' => 
$this->start,'query' => $this->query,'sort' => $this->sort,'order' => 
$this->order));
+
+                       $this->total_records = $this->so->total_records;
+
+                       return $method;
+               }
+
+               function read_single($id)
+               {
+                       return $this->so->read_single($id);
+               }
+
+               function save($method,$action='')
+               {
+                       if ($action=='edit')
+                       {
+                               if ($method['id'] != '')
+                               {
+
+                                       $receipt = $this->so->edit($method);
+                               }
+                       }
+                       else
+                       {
+                               $receipt = $this->so->add($method);
+                       }
+                       return $receipt;
+
+               }
+
+               function delete($id)
+               {
+                       $this->so->delete($id);
+               }
+       }
+?>
Index: property/inc/class.bob_account.inc.php
diff -u property/inc/class.bob_account.inc.php:1.6 
property/inc/class.bob_account.inc.php:1.7
--- property/inc/class.bob_account.inc.php:1.6  Fri Jan 27 14:05:43 2006
+++ property/inc/class.bob_account.inc.php      Fri Feb  3 12:05:49 2006
@@ -1,179 +1,179 @@
-<?php
-       /**
-       * phpGroupWare - property: a Facilities Management System.
-       *
-       * @author Sigurd Nes <address@hidden>
-       * @copyright Copyright (C) 2003-2005 Free Software Foundation, Inc. 
http://www.fsf.org/
-       * @license http://www.gnu.org/licenses/gpl.html GNU General Public 
License
-       * @internal Development of this application was funded by 
http://www.bergen.kommune.no/bbb_/ekstern/
-       * @package property
-       * @subpackage admin
-       * @version $Id: class.bob_account.inc.php,v 1.6 2006/01/27 14:05:43 
sigurdne Exp $
-       */
-
-       /**
-        * Description
-        * @package property
-        */
-
-       class bob_account
-       {
-               var $start;
-               var $query;
-               var $filter;
-               var $sort;
-               var $order;
-               var $cat_id;
-
-               var $public_functions = array
-               (
-                       'read'                          => True,
-                       'read_single'           => True,
-                       'save'                          => True,
-                       'delete'                        => True,
-                       'check_perms'           => True
-               );
-
-               var $soap_functions = array(
-                       'list' => array(
-                               'in'  => 
array('int','int','struct','string','int'),
-                               'out' => array('array')
-                       ),
-                       'read' => array(
-                               'in'  => array('int','struct'),
-                               'out' => array('array')
-                       ),
-                       'save' => array(
-                               'in'  => array('int','struct'),
-                               'out' => array()
-                       ),
-                       'delete' => array(
-                               'in'  => array('int','struct'),
-                               'out' => array()
-                       )
-               );
-
-               function bob_account($session=False)
-               {
-                       $this->currentapp       = 
$GLOBALS['phpgw_info']['flags']['currentapp'];
-                       $this->so               = 
CreateObject($this->currentapp.'.sob_account');
-                       $this->socommon = 
CreateObject($this->currentapp.'.socommon');
-
-                       if ($session)
-                       {
-                               $this->read_sessiondata();
-                               $this->use_session = True;
-                       }
-
-                       $start  = get_var('start',array('POST','GET'));
-                       $query  = get_var('query',array('POST','GET'));
-                       $sort   = get_var('sort',array('POST','GET'));
-                       $order  = get_var('order',array('POST','GET'));
-                       $filter = get_var('filter',array('POST','GET'));
-                       $cat_id = get_var('cat_id',array('POST','GET'));
-                       $allrows= get_var('allrows',array('POST','GET'));
-
-                       if ($start)
-                       {
-                               $this->start=$start;
-                       }
-                       else
-                       {
-                               $this->start=0;
-                       }
-
-                       if(isset($query))
-                       {
-                               $this->query = $query;
-                       }
-                       if(!empty($filter))
-                       {
-                               $this->filter = $filter;
-                       }
-                       if(isset($sort))
-                       {
-                               $this->sort = $sort;
-                       }
-                       if(isset($order))
-                       {
-                               $this->order = $order;
-                       }
-                       if(isset($cat_id))
-                       {
-                               $this->cat_id = $cat_id;
-                       }
-                       if(isset($allrows))
-                       {
-                               $this->allrows = $allrows;
-                       }
-               }
-
-
-               function save_sessiondata($data)
-               {
-                       if ($this->use_session)
-                       {
-                               
$GLOBALS['phpgw']->session->appsession('session_data','b_account',$data);
-                       }
-               }
-
-               function read_sessiondata()
-               {
-                       $data = 
$GLOBALS['phpgw']->session->appsession('session_data','b_account');
-
-                       //_debug_array($data);
-
-                       $this->start    = $data['start'];
-                       $this->query    = $data['query'];
-                       $this->filter   = $data['filter'];
-                       $this->sort             = $data['sort'];
-                       $this->order    = $data['order'];
-                       $this->cat_id   = $data['cat_id'];
-                       $this->allrows  = $data['allrows'];
-               }
-
-
-               function read()
-               {
-                       $b_account = $this->so->read(array('start' => 
$this->start,'query' => $this->query,'sort' => $this->sort,'order' => 
$this->order,
-                                                                               
        'allrows'=>$this->allrows));
-
-                       $this->total_records = $this->so->total_records;
-
-                       return $b_account;
-               }
-
-               function read_single($id)
-               {
-                       return $this->so->read_single($id);
-               }
-
-               function select_part_of_town($part_of_town_id)
-               {
-                       return 
$this->socommon->select_part_of_town($part_of_town_id);
-               }
-
-               function save($b_account,$action='')
-               {
-                       if ($action=='edit')
-                       {
-                               if ($b_account['id'] != '')
-                               {
-
-                                       $receipt = $this->so->edit($b_account);
-                               }
-                       }
-                       else
-                       {
-                               $receipt = $this->so->add($b_account);
-                       }
-
-                       return $receipt;
-               }
-
-               function delete($id)
-               {
-                       $this->so->delete($id);
-               }
-       }
-?>
+<?php
+       /**
+       * phpGroupWare - property: a Facilities Management System.
+       *
+       * @author Sigurd Nes <address@hidden>
+       * @copyright Copyright (C) 2003-2005 Free Software Foundation, Inc. 
http://www.fsf.org/
+       * @license http://www.gnu.org/licenses/gpl.html GNU General Public 
License
+       * @internal Development of this application was funded by 
http://www.bergen.kommune.no/bbb_/ekstern/
+       * @package property
+       * @subpackage admin
+       * @version $Id: class.bob_account.inc.php,v 1.7 2006/02/03 12:05:49 
sigurdne Exp $
+       */
+
+       /**
+        * Description
+        * @package property
+        */
+
+       class bob_account
+       {
+               var $start;
+               var $query;
+               var $filter;
+               var $sort;
+               var $order;
+               var $cat_id;
+
+               var $public_functions = array
+               (
+                       'read'                          => True,
+                       'read_single'           => True,
+                       'save'                          => True,
+                       'delete'                        => True,
+                       'check_perms'           => True
+               );
+
+               var $soap_functions = array(
+                       'list' => array(
+                               'in'  => 
array('int','int','struct','string','int'),
+                               'out' => array('array')
+                       ),
+                       'read' => array(
+                               'in'  => array('int','struct'),
+                               'out' => array('array')
+                       ),
+                       'save' => array(
+                               'in'  => array('int','struct'),
+                               'out' => array()
+                       ),
+                       'delete' => array(
+                               'in'  => array('int','struct'),
+                               'out' => array()
+                       )
+               );
+
+               function bob_account($session=False)
+               {
+                       $this->currentapp       = 
$GLOBALS['phpgw_info']['flags']['currentapp'];
+                       $this->so               = 
CreateObject($this->currentapp.'.sob_account');
+                       $this->socommon = 
CreateObject($this->currentapp.'.socommon');
+
+                       if ($session)
+                       {
+                               $this->read_sessiondata();
+                               $this->use_session = True;
+                       }
+
+                       $start  = get_var('start',array('POST','GET'));
+                       $query  = get_var('query',array('POST','GET'));
+                       $sort   = get_var('sort',array('POST','GET'));
+                       $order  = get_var('order',array('POST','GET'));
+                       $filter = get_var('filter',array('POST','GET'));
+                       $cat_id = get_var('cat_id',array('POST','GET'));
+                       $allrows= get_var('allrows',array('POST','GET'));
+
+                       if ($start)
+                       {
+                               $this->start=$start;
+                       }
+                       else
+                       {
+                               $this->start=0;
+                       }
+
+                       if(isset($query))
+                       {
+                               $this->query = $query;
+                       }
+                       if(!empty($filter))
+                       {
+                               $this->filter = $filter;
+                       }
+                       if(isset($sort))
+                       {
+                               $this->sort = $sort;
+                       }
+                       if(isset($order))
+                       {
+                               $this->order = $order;
+                       }
+                       if(isset($cat_id))
+                       {
+                               $this->cat_id = $cat_id;
+                       }
+                       if(isset($allrows))
+                       {
+                               $this->allrows = $allrows;
+                       }
+               }
+
+
+               function save_sessiondata($data)
+               {
+                       if ($this->use_session)
+                       {
+                               
$GLOBALS['phpgw']->session->appsession('session_data','b_account',$data);
+                       }
+               }
+
+               function read_sessiondata()
+               {
+                       $data = 
$GLOBALS['phpgw']->session->appsession('session_data','b_account');
+
+                       //_debug_array($data);
+
+                       $this->start    = $data['start'];
+                       $this->query    = $data['query'];
+                       $this->filter   = $data['filter'];
+                       $this->sort             = $data['sort'];
+                       $this->order    = $data['order'];
+                       $this->cat_id   = $data['cat_id'];
+                       $this->allrows  = $data['allrows'];
+               }
+
+
+               function read()
+               {
+                       $b_account = $this->so->read(array('start' => 
$this->start,'query' => $this->query,'sort' => $this->sort,'order' => 
$this->order,
+                                                                               
        'allrows'=>$this->allrows));
+
+                       $this->total_records = $this->so->total_records;
+
+                       return $b_account;
+               }
+
+               function read_single($id)
+               {
+                       return $this->so->read_single($id);
+               }
+
+               function select_part_of_town($part_of_town_id)
+               {
+                       return 
$this->socommon->select_part_of_town($part_of_town_id);
+               }
+
+               function save($b_account,$action='')
+               {
+                       if ($action=='edit')
+                       {
+                               if ($b_account['id'] != '')
+                               {
+
+                                       $receipt = $this->so->edit($b_account);
+                               }
+                       }
+                       else
+                       {
+                               $receipt = $this->so->add($b_account);
+                       }
+
+                       return $receipt;
+               }
+
+               function delete($id)
+               {
+                       $this->so->delete($id);
+               }
+       }
+?>
Index: property/inc/class.bocategory.inc.php
diff -u property/inc/class.bocategory.inc.php:1.6 
property/inc/class.bocategory.inc.php:1.7
--- property/inc/class.bocategory.inc.php:1.6   Fri Jan 27 14:05:43 2006
+++ property/inc/class.bocategory.inc.php       Fri Feb  3 12:05:49 2006
@@ -1,179 +1,179 @@
-<?php
-       /**
-       * phpGroupWare - property: a Facilities Management System.
-       *
-       * @author Sigurd Nes <address@hidden>
-       * @copyright Copyright (C) 2003-2005 Free Software Foundation, Inc. 
http://www.fsf.org/
-       * @license http://www.gnu.org/licenses/gpl.html GNU General Public 
License
-       * @internal Development of this application was funded by 
http://www.bergen.kommune.no/bbb_/ekstern/
-       * @package property
-       * @subpackage admin
-       * @version $Id: class.bocategory.inc.php,v 1.6 2006/01/27 14:05:43 
sigurdne Exp $
-       */
-
-       /**
-        * Description
-        * @package property
-        */
-
-       class bocategory
-       {
-               var $start;
-               var $query;
-               var $filter;
-               var $sort;
-               var $order;
-               var $cat_id;
-
-               var $public_functions = array
-               (
-                       'read'                          => True,
-                       'read_single'           => True,
-                       'save'                          => True,
-                       'delete'                        => True,
-                       'check_perms'           => True
-               );
-
-               var $soap_functions = array(
-                       'list' => array(
-                               'in'  => 
array('int','int','struct','string','int'),
-                               'out' => array('array')
-                       ),
-                       'read' => array(
-                               'in'  => array('int','struct'),
-                               'out' => array('array')
-                       ),
-                       'save' => array(
-                               'in'  => array('int','struct'),
-                               'out' => array()
-                       ),
-                       'delete' => array(
-                               'in'  => array('int','struct'),
-                               'out' => array()
-                       )
-               );
-
-               function bocategory($session=False)
-               {
-                       $this->currentapp       = 
$GLOBALS['phpgw_info']['flags']['currentapp'];
-                       $this->so               = 
CreateObject($this->currentapp.'.socategory');
-                       $this->socommon = 
CreateObject($this->currentapp.'.socommon');
-
-                       if ($session)
-                       {
-                               $this->read_sessiondata();
-                               $this->use_session = True;
-                       }
-
-                       $start  = get_var('start',array('POST','GET'));
-                       $query  = get_var('query',array('POST','GET'));
-                       $sort   = get_var('sort',array('POST','GET'));
-                       $order  = get_var('order',array('POST','GET'));
-                       $filter = get_var('filter',array('POST','GET'));
-                       $cat_id = get_var('cat_id',array('POST','GET'));
-                       $allrows= get_var('allrows',array('POST','GET'));
-
-                       if ($start)
-                       {
-                               $this->start=$start;
-                       }
-                       else
-                       {
-                               $this->start=0;
-                       }
-
-                       if(isset($query))
-                       {
-                               $this->query = $query;
-                       }
-                       if(!empty($filter))
-                       {
-                               $this->filter = $filter;
-                       }
-                       if(isset($sort))
-                       {
-                               $this->sort = $sort;
-                       }
-                       if(isset($order))
-                       {
-                               $this->order = $order;
-                       }
-                       if(isset($cat_id))
-                       {
-                               $this->cat_id = $cat_id;
-                       }
-                       if(isset($allrows))
-                       {
-                               $this->allrows = $allrows;
-                       }
-               }
-
-
-               function save_sessiondata($data)
-               {
-                       if ($this->use_session)
-                       {
-                               
$GLOBALS['phpgw']->session->appsession('session_data','category',$data);
-                       }
-               }
-
-               function read_sessiondata()
-               {
-                       $data = 
$GLOBALS['phpgw']->session->appsession('session_data','category');
-
-                       //_debug_array($data);
-
-                       $this->start    = $data['start'];
-                       $this->query    = $data['query'];
-                       $this->filter   = $data['filter'];
-                       $this->sort             = $data['sort'];
-                       $this->order    = $data['order'];
-                       $this->cat_id   = $data['cat_id'];
-                       $this->allrows  = $data['allrows'];
-               }
-
-
-               function read($type='',$type_id='')
-               {
-                       $category = $this->so->read(array('start' => 
$this->start,'query' => $this->query,'sort' => $this->sort,'order' => 
$this->order,
-                                                                               
        'type' => $type,type_id=>$type_id,'allrows'=>$this->allrows));
-
-                       $this->total_records = $this->so->total_records;
-
-                       return $category;
-               }
-
-               function read_single($id,$type,$type_id)
-               {
-                       return $this->so->read_single($id,$type,$type_id);
-               }
-
-               function select_part_of_town($part_of_town_id)
-               {
-                       return 
$this->socommon->select_part_of_town($part_of_town_id);
-               }
-
-               function save($category,$action='',$type ='',$type_id)
-               {
-                       if ($action=='edit')
-                       {
-                               if ($category['id'] != '')
-                               {
-
-                                       $receipt = 
$this->so->edit($category,$type,$type_id);
-                               }
-                       }
-                       else
-                       {
-                               $receipt = 
$this->so->add($category,$type,$type_id);
-                       }
-
-                       return $receipt;
-               }
-
-               function delete($id,$type,$type_id)
-               {
-                       $this->so->delete($id,$type,$type_id);
-               }
-       }
-?>
+<?php
+       /**
+       * phpGroupWare - property: a Facilities Management System.
+       *
+       * @author Sigurd Nes <address@hidden>
+       * @copyright Copyright (C) 2003-2005 Free Software Foundation, Inc. 
http://www.fsf.org/
+       * @license http://www.gnu.org/licenses/gpl.html GNU General Public 
License
+       * @internal Development of this application was funded by 
http://www.bergen.kommune.no/bbb_/ekstern/
+       * @package property
+       * @subpackage admin
+       * @version $Id: class.bocategory.inc.php,v 1.7 2006/02/03 12:05:49 
sigurdne Exp $
+       */
+
+       /**
+        * Description
+        * @package property
+        */
+
+       class bocategory
+       {
+               var $start;
+               var $query;
+               var $filter;
+               var $sort;
+               var $order;
+               var $cat_id;
+
+               var $public_functions = array
+               (
+                       'read'                          => True,
+                       'read_single'           => True,
+                       'save'                          => True,
+                       'delete'                        => True,
+                       'check_perms'           => True
+               );
+
+               var $soap_functions = array(
+                       'list' => array(
+                               'in'  => 
array('int','int','struct','string','int'),
+                               'out' => array('array')
+                       ),
+                       'read' => array(
+                               'in'  => array('int','struct'),
+                               'out' => array('array')
+                       ),
+                       'save' => array(
+                               'in'  => array('int','struct'),
+                               'out' => array()
+                       ),
+                       'delete' => array(
+                               'in'  => array('int','struct'),
+                               'out' => array()
+                       )
+               );
+
+               function bocategory($session=False)
+               {
+                       $this->currentapp       = 
$GLOBALS['phpgw_info']['flags']['currentapp'];
+                       $this->so               = 
CreateObject($this->currentapp.'.socategory');
+                       $this->socommon = 
CreateObject($this->currentapp.'.socommon');
+
+                       if ($session)
+                       {
+                               $this->read_sessiondata();
+                               $this->use_session = True;
+                       }
+
+                       $start  = get_var('start',array('POST','GET'));
+                       $query  = get_var('query',array('POST','GET'));
+                       $sort   = get_var('sort',array('POST','GET'));
+                       $order  = get_var('order',array('POST','GET'));
+                       $filter = get_var('filter',array('POST','GET'));
+                       $cat_id = get_var('cat_id',array('POST','GET'));
+                       $allrows= get_var('allrows',array('POST','GET'));
+
+                       if ($start)
+                       {
+                               $this->start=$start;
+                       }
+                       else
+                       {
+                               $this->start=0;
+                       }
+
+                       if(isset($query))
+                       {
+                               $this->query = $query;
+                       }
+                       if(!empty($filter))
+                       {
+                               $this->filter = $filter;
+                       }
+                       if(isset($sort))
+                       {
+                               $this->sort = $sort;
+                       }
+                       if(isset($order))
+                       {
+                               $this->order = $order;
+                       }
+                       if(isset($cat_id))
+                       {
+                               $this->cat_id = $cat_id;
+                       }
+                       if(isset($allrows))
+                       {
+                               $this->allrows = $allrows;
+                       }
+               }
+
+
+               function save_sessiondata($data)
+               {
+                       if ($this->use_session)
+                       {
+                               
$GLOBALS['phpgw']->session->appsession('session_data','category',$data);
+                       }
+               }
+
+               function read_sessiondata()
+               {
+                       $data = 
$GLOBALS['phpgw']->session->appsession('session_data','category');
+
+                       //_debug_array($data);
+
+                       $this->start    = $data['start'];
+                       $this->query    = $data['query'];
+                       $this->filter   = $data['filter'];
+                       $this->sort             = $data['sort'];
+                       $this->order    = $data['order'];
+                       $this->cat_id   = $data['cat_id'];
+                       $this->allrows  = $data['allrows'];
+               }
+
+
+               function read($type='',$type_id='')
+               {
+                       $category = $this->so->read(array('start' => 
$this->start,'query' => $this->query,'sort' => $this->sort,'order' => 
$this->order,
+                                                                               
        'type' => $type,type_id=>$type_id,'allrows'=>$this->allrows));
+
+                       $this->total_records = $this->so->total_records;
+
+                       return $category;
+               }
+
+               function read_single($id,$type,$type_id)
+               {
+                       return $this->so->read_single($id,$type,$type_id);
+               }
+
+               function select_part_of_town($part_of_town_id)
+               {
+                       return 
$this->socommon->select_part_of_town($part_of_town_id);
+               }
+
+               function save($category,$action='',$type ='',$type_id)
+               {
+                       if ($action=='edit')
+                       {
+                               if ($category['id'] != '')
+                               {
+
+                                       $receipt = 
$this->so->edit($category,$type,$type_id);
+                               }
+                       }
+                       else
+                       {
+                               $receipt = 
$this->so->add($category,$type,$type_id);
+                       }
+
+                       return $receipt;
+               }
+
+               function delete($id,$type,$type_id)
+               {
+                       $this->so->delete($id,$type,$type_id);
+               }
+       }
+?>
Index: property/inc/class.bocommon.inc.php
diff -u property/inc/class.bocommon.inc.php:1.20 
property/inc/class.bocommon.inc.php:1.21
--- property/inc/class.bocommon.inc.php:1.20    Fri Jan 27 14:05:43 2006
+++ property/inc/class.bocommon.inc.php Fri Feb  3 12:05:49 2006
@@ -1,1384 +1,1384 @@
-<?php
-       /**
-       * phpGroupWare - property: a Facilities Management System.
-       *
-       * @author Sigurd Nes <address@hidden>
-       * @copyright Copyright (C) 2003-2005 Free Software Foundation, Inc. 
http://www.fsf.org/
-       * @license http://www.gnu.org/licenses/gpl.html GNU General Public 
License
-       * @internal Development of this application was funded by 
http://www.bergen.kommune.no/bbb_/ekstern/
-       * @package property
-       * @subpackage core
-       * @version $Id: class.bocommon.inc.php,v 1.20 2006/01/27 14:05:43 
sigurdne Exp $
-       */
-
-       /**
-        * Description
-        * @package property
-        */
-
-       class bocommon
-       {
-               var $start;
-               var $query;
-               var $filter;
-               var $sort;
-               var $order;
-               var $cat_id;
-               var $district_id;
-
-
-               var $public_functions = array
-               (
-                       'select_part_of_town'   => True,
-                       'menu'                                  => True,
-               );
-
-               var $soap_functions = array(
-                       'list' => array(
-                               'in'  => 
array('int','int','struct','string','int'),
-                               'out' => array('array')
-                       ),
-                       'read' => array(
-                               'in'  => array('int','struct'),
-                               'out' => array('array')
-                       ),
-                       'save' => array(
-                               'in'  => array('int','struct'),
-                               'out' => array()
-                       ),
-                       'delete' => array(
-                               'in'  => array('int','struct'),
-                               'out' => array()
-                       )
-               );
-
-               function bocommon()
-               {
-
-                       $GLOBALS['phpgw_info']['flags']['currentapp']   =       
'property';
-                       $this->currentapp               = 
$GLOBALS['phpgw_info']['flags']['currentapp'];
-                       $this->socommon                 = 
CreateObject($this->currentapp.'.socommon');
-                       $this->account          = 
$GLOBALS['phpgw_info']['user']['account_id'];
-
-                       if (!is_object($GLOBALS['phpgw']->asyncservice))
-                       {
-                               $GLOBALS['phpgw']->asyncservice = 
CreateObject('phpgwapi.asyncservice');
-                       }
-                       $this->async = &$GLOBALS['phpgw']->asyncservice;
-
-                       $this->join                     = $this->socommon->join;
-                       $this->left_join        = $this->socommon->left_join;
-                       $this->like                     = $this->socommon->like;
-
-                       switch($GLOBALS['phpgw_info']['server']['db_type'])
-                       {
-                               case 'mssql':
-                                       $this->dateformat               = "M d 
Y";
-                                       $this->datetimeformat   = "M d Y g:iA";
-                                       break;
-                               case 'mysql':
-                                       $this->dateformat               = 
"Y-m-d";
-                                       $this->datetimeformat   = "Y-m-d G:i:s";
-                                       break;
-                               case 'pgsql':
-                                       $this->dateformat               = 
"Y-m-d";
-                                       $this->datetimeformat   = "Y-m-d G:i:s";
-//                                     $this->dateformat               = "F j, 
Y";
-//                                     $this->datetimeformat   = "F j, Y g:iA";
-                                       break;
-                       }
-
-       /*              if 
($GLOBALS['phpgw_info']['server']['db_type']=='mssql')
-                       {
-                               $this->dateformat               = "M d Y";
-                               $this->datetimeformat   = "M d Y g:iA";
-                       }
-                       else
-                       {
-                               $this->dateformat               = "Y-m-d";
-                               $this->datetimeformat   = "Y-m-d G:i:s";
-                       }
-
-
-                       if(!$GLOBALS['phpgw_info']['flags']['css'])
-                       {
-                               $GLOBALS['phpgw_info']['flags']['css'] .= 
"-->\n</style>\n"
-                                       . '<link rel="stylesheet" 
type="text/css" media="all" href="'
-                                       . 
$GLOBALS['phpgw_info']['server']['webserver_url'].'/' . $this->currentapp . 
'/templates/'
-                                       . 
$GLOBALS['phpgw_info']['server']['template_set']
-                                       . 
'/css/'.$GLOBALS['phpgw_info']['server']['template_set'].'.css" 
title="'.$GLOBALS['phpgw_info']['server']['template_set'].'" />'
-                                       . "\n<style type=\"text/css\">\n<!--\n";
-                       }
-*/
-               }
-
-               function jscalendar()
-               {
-                       $phpgw_js_url = 
$GLOBALS['phpgw_info']['server']['webserver_url'].'/phpgwapi/js';
-//                     $img = 
$GLOBALS['phpgw']->common->get_image_path('phpgwapi','default').'/cal.png';
-                       $img    = 
$GLOBALS['phpgw_info']['server']['webserver_url'] . 
'/phpgwapi/templates/default/images/cal.png';
-
-//                     $img = $phpgw_js_url.'/jscalendar/img.gif';
-                       $dateformat = 
$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
-                       $jsDateFormat = str_replace(array('d', 'm', 'M', 'Y'), 
array('%d', '%m', '%b', '%Y'), $dateformat);
-
-                       $GLOBALS['phpgw_info']['flags']['java_script'] 
.='</script>
-                       <link rel="stylesheet" type="text/css" media="all" 
href="'.$phpgw_js_url.'/jscalendar/calendar-win2k-cold-1.css" 
title="win2k-cold-1" >
-                       <script type="text/javascript" 
src="'.$phpgw_js_url.'/jscalendar/calendar.js"></script>
-                       <script type="text/javascript" 
src="'.$phpgw_js_url.'/jscalendar/calendar-setup.js"></script>
-                       <script type="text/javascript" 
src="'.$phpgw_js_url.'/jscalendar/lang/calendar-'.substr($GLOBALS['phpgw_info']['user']['preferences']['common']['lang'],0,2)
 .'.js"></script>
-                       ';
-
-
-//                     <script type="text/javascript" 
src="'.ereg_replace('[?&]*click_history=[0-9a-f]*','',$GLOBALS['phpgw']->link('/phpgwapi/js/jscalendar/jscalendar-setup.php')).'"></script>
-
-                       $cal_info=array(
-//                             'stylesheet'                                    
=> $phpgw_js_url.'/jscalendar/calendar-win2k-cold-1.css',
-//                             'calendar_source'                               
=> $phpgw_js_url.'/jscalendar/calendar.js',
-//                             'calendar_setup_source'                 => 
$phpgw_js_url.'/jscalendar/calendar-setup.js',
-//                             'calendar_lang'                                 
=> 
$phpgw_js_url.'/jscalendar/lang/calendar-'.substr($GLOBALS['phpgw_info']['user']['preferences']['common']['lang'],0,2)
 .'.js',
-                               'jsDateFormat'                                  
=> $jsDateFormat,
-                               'img'                                           
        => $img,
-                               );
-                       return $cal_info;
-               }
-
-               function check_perms($rights, $required)
-               {
-       //              return (!!($rights & $required) == True);
-                       return ($rights & $required);
-               }
-
-               function create_preferences($app='',$user_id='')
-               {
-                       return 
$this->socommon->create_preferences($app,$user_id);
-               }
-
-               function get_lookup_entity($location='')
-               {
-                       return $this->socommon->get_lookup_entity($location);
-               }
-
-               function get_start_entity($location='')
-               {
-                       return $this->socommon->get_start_entity($location);
-               }
-
-               function msgbox_data($receipt)
-               {
-                       $msgbox_data_error=array();
-                       if (isSet($receipt['error']) AND 
is_array($receipt['error']))
-                       {
-                               foreach($receipt['error'] as $errors)
-                               {
-                                       $msgbox_data_error += 
array($errors['msg']=> False);
-                               }
-                       }
-
-                       $msgbox_data_message=array();
-
-                       if (isSet($receipt['message']) AND 
is_array($receipt['message']))
-                       {
-                               foreach($receipt['message'] as $messages)
-                               {
-                                       $msgbox_data_message += 
array($messages['msg']=> True);
-                               }
-                       }
-
-                       $msgbox_data = $msgbox_data_error + 
$msgbox_data_message;
-
-                       return $msgbox_data;
-               }
-
-               function moneyformat($amount)
-               {
-                       if 
($GLOBALS['phpgw_info']['server']['db_type']=='mssql')
-                       {
-                               $moneyformat    = 
"CONVERT(MONEY,"."'$amount'".",0)";
-                       }
-                       else
-                       {
-                               $moneyformat    = "'" . $amount . "'";
-                       }
-
-                       return $moneyformat;
-               }
-
-
-               function date_array($date)
-               {
-                       $dateformat = 
strtolower($GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']);
-                       $dateformat = str_replace(".","",$dateformat);
-                       $dateformat = str_replace("-","",$dateformat);
-                       $dateformat = str_replace("/","",$dateformat);
-                       $y=strpos($dateformat,'y');
-                       $d=strpos($dateformat,'d');
-                       $m=strpos($dateformat,'m');
-
-                       $dateparts = explode('/', $date);
-                       $date_array['day']              = $dateparts[$d];
-                       $date_array['month']    = $dateparts[$m];
-                       $date_array['year']             = $dateparts[$y];
-
-                       return $date_array;
-               }
-
-               function date_to_timestamp($date)
-               {
-                       if($date)
-                       {
-                               $date_array     = $this->date_array($date);
-                               $date   = mktime 
(8,0,0,$date_array['month'],$date_array['day'],$date_array['year']);
-                       }
-                       return $date;
-               }
-
-
-               function 
column_list($selected='',$entity_type='',$cat_id,$allrows='')
-               {
-                       $bostandard_entity      = 
CreateObject($this->currentapp.'.bostandard_entity',True);
-
-                       if(!$selected)
-                       {
-                               
$selected=$GLOBALS['phpgw_info']['user']['preferences'][$this->currentapp][$entity_type.'_columns_'.$cat_id];
-                       }
-
-                       $columns = 
$bostandard_entity->read_attrib($entity_type,$cat_id,$allrows);
-//_debug_array($columns);
-
-                       
$column_list=$this->select_multi_list($selected,$columns);
-
-                       return $column_list;
-
-               }
-
-               function select_multi_list($selected='',$input_list)
-               {
-                       $j=0;
-                       if (isset($input_list) AND is_array($input_list))
-                       {
-                               foreach($input_list as $entry)
-                               {
-                                       $output_list[$j]['id'] = $entry['id'];
-                                       $output_list[$j]['name'] = 
$entry['name'];
-
-                                       for ($i=0;$i<count($selected);$i++)
-                                       {
-                                               if($selected[$i] == 
$entry['id'])
-                                               {
-                                                       
$output_list[$j]['selected'] = 'selected';
-                                               }
-                                       }
-                                       $j++;
-                               }
-                       }
-
-                       for ($i=0;$i<count($output_list);$i++)
-                       {
-                               if ($output_list[$i]['selected'] != 'selected')
-                               {
-                                       unset($output_list[$i]['selected']);
-                               }
-                       }
-
-                       return $output_list;
-               }
-
-
-
-               function select_list($selected='',$input_list='')
-               {
-                       if (isset($input_list) AND is_array($input_list))
-                       {
-                               foreach($input_list as $entry)
-                               {
-                                       $sel_entry = '';
-                                       if ($entry['id']==$selected)
-                                       {
-                                               $sel_entry = 'selected';
-                                       }
-                                       $entry_list[] = array
-                                       (
-                                               'id'            => $entry['id'],
-                                               'name'          => 
$entry['name'],
-                                               'selected'      => $sel_entry
-                                       );
-                               }
-                               for ($i=0;$i<count($entry_list);$i++)
-                               {
-                                       if ($entry_list[$i]['selected'] != 
'selected')
-                                       {
-                                               
unset($entry_list[$i]['selected']);
-                                       }
-                               }
-                       }
-                       return $entry_list;
-               }
-
-
-               function 
get_user_list($format='',$selected='',$extra='',$default='',$start='', 
$sort='', $order='', $query='',$offset='')
-               {
-                       switch($format)
-                       {
-                               case 'select':
-                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('user_id_select'));
-                                       break;
-                               case 'filter':
-                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('user_id_filter'));
-                                       break;
-                       }
-
-                       if(!$selected && $default)
-                       {
-                               $selected = $default;
-                       }
-
-                       if (is_array($extra))
-                       {
-                               foreach($extra as $extra_user)
-                               {
-                                       $users_extra[]=array
-                                       (
-                                               'account_id' => $extra_user,
-                                               'account_firstname' => 
lang($extra_user)
-                                       );
-                               }
-                       }
-
-                       $accounts       = CreateObject('phpgwapi.accounts');
-                       $users = $accounts->get_list('accounts', $start, $sort, 
$order, $query,$offset);
-                       unset($accounts);
-                       if (is_array($users_extra) && is_array($users))
-                       {
-                               $users = $users_extra + $users;
-                       }
-
-                       if (isSet($users) AND is_array($users))
-                       {
-                               foreach($users as $user)
-                               {
-                                       $sel_user = '';
-                                       if ($user['account_id']==$selected)
-                                       {
-                                               $sel_user = 'selected';
-                                       }
-
-                                       $user_list[] = array
-                                       (
-                                               'user_id'       => 
$user['account_id'],
-                                               'name'          => 
$user['account_lastname'].' '.$user['account_firstname'],
-                                               'selected'      => $sel_user
-                                       );
-                               }
-                       }
-
-                       $user_count= count($user_list);
-                       for ($i=0;$i<$user_count;$i++)
-                       {
-                               if ($user_list[$i]['selected'] != 'selected')
-                               {
-                                       unset($user_list[$i]['selected']);
-                               }
-                       }
-
-//_debug_array($user_list);
-                       return $user_list;
-               }
-
-               function get_group_list($format='',$selected='',$start='', 
$sort='', $order='', $query='',$offset='')
-               {
-                       switch($format)
-                       {
-                               case 'select':
-                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('group_select'));
-                                       break;
-                               case 'filter':
-                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('group_filter'));
-                                       break;
-                       }
-
-                       $accounts       = CreateObject('phpgwapi.accounts');
-                       $users = $accounts->get_list('groups', $start, $sort, 
$order, $query,$offset);
-                       unset($accounts);
-                       if (isSet($users) AND is_array($users))
-                       {
-                               foreach($users as $user)
-                               {
-                                       $sel_user = '';
-                                       if ($user['account_id']==$selected)
-                                       {
-                                               $sel_user = 'selected';
-                                       }
-
-                                       $user_list[] = array
-                                       (
-                                               'id'    => $user['account_id'],
-                                               'name'          => 
$user['account_firstname'],
-                                               'selected'      => $sel_user
-                                       );
-                               }
-                       }
-
-                       $user_count= count($user_list);
-                       for ($i=0;$i<$user_count;$i++)
-                       {
-                               if ($user_list[$i]['selected'] != 'selected')
-                               {
-                                       unset($user_list[$i]['selected']);
-                               }
-                       }
-
-//_debug_array($user_list);
-                       return $user_list;
-               }
-
-
-               function 
get_user_list_right($right='',$selected='',$acl_location='')
-               {
-                       
$employees=$this->socommon->get_user_list_right($right,$acl_location);
-                       while (is_array($employees) && list(,$user) = 
each($employees))
-                       {
-                               $sel_user = '';
-                               if ($user['account_lid']==$selected)
-                               {
-                                       $sel_user = 'selected';
-                               }
-
-                               $user_list[] = array
-                               (
-                                       'lid'                   => 
$user['account_lid'],
-                                       'firstname'             => 
$user['account_firstname'],
-                                       'lastname'              => 
$user['account_lastname'],
-                                       'selected'              => $sel_user
-                               );
-                       }
-
-                       for ($i=0;$i<count($user_list);$i++)
-                       {
-                               if ($user_list[$i]['selected'] != 'selected')
-                               {
-                                       unset($user_list[$i]['selected']);
-                               }
-                       }
-
-                       return $user_list;
-               }
-
-               function 
get_user_list_right2($format='',$right='',$selected='',$acl_location='',$extra='',$default='')
-               {
-                       switch($format)
-                       {
-                               case 'select':
-                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('user_id_select'));
-                                       break;
-                               case 'filter':
-                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('user_id_filter'));
-                                       break;
-                       }
-
-                       if(!$selected && $default)
-                       {
-                               $selected = $default;
-                       }
-
-                       if (isset($extra) AND is_array($extra))
-                       {
-                               foreach($extra as $extra_user)
-                               {
-                                       $users_extra[]=array
-                                       (
-                                               'account_id' => $extra_user,
-                                               'account_firstname' => 
lang($extra_user)
-                                       );
-                               }
-                       }
-
-                       
$users=$this->socommon->get_user_list_right($right,$acl_location);
-
-                       if (is_array($users_extra) && is_array($users))
-                       {
-                               foreach($users as $users_entry)
-                               {
-                                       array_push($users_extra,$users_entry);
-                               }
-                               $users=$users_extra;
-                       }
-
-                       while (is_array($users) && list(,$user) = each($users))
-                       {
-                               $sel_user = '';
-                               if ($user['account_id']==$selected)
-                               {
-                                       $sel_user = 'selected';
-                               }
-
-                               $user_list[] = array
-                               (
-                                       'user_id'               => 
$user['account_id'],
-                                       'name'          => 
$user['account_lastname'].' '.$user['account_firstname'],
-                                       'selected'      => $sel_user
-                               );
-                       }
-
-                       for ($i=0;$i<count($user_list);$i++)
-                       {
-                               if ($user_list[$i]['selected'] != 'selected')
-                               {
-                                       unset($user_list[$i]['selected']);
-                               }
-                       }
-
-                       return $user_list;
-               }
-
-
-               function initiate_ui_vendorlookup($data)
-               {
-//_debug_array($data);
-
-                       $contacts       = 
CreateObject($this->currentapp.'.soactor');
-                       $contacts->role='vendor';
-
-                       if($data['type']=='view')
-                       {
-                               
$GLOBALS['phpgw']->xslttpl->add_file(array('vendor_view'));
-                       }
-                       else
-                       {
-                               
$GLOBALS['phpgw']->xslttpl->add_file(array('vendor_form'));
-                       }
-
-                       $vendor['value_vendor_id']                              
= $data['vendor_id'];
-                       $vendor['value_vendor_name']                    = 
$data['vendor_name'];
-
-                       if($data['vendor_id'] && !$data['vendor_name'])
-                       {
-                               $vendor_data                                    
        = $contacts->read_single(array('actor_id'=>$data['vendor_id']));
-                               if(is_array($vendor_data))
-                               {
-                                       foreach($vendor_data['attributes'] as 
$attribute)
-                                       {
-                                               
if($attribute['name']=='org_name')
-                                               {
-                                                       
$vendor['value_vendor_name']=$attribute['value'];
-                                                       break;
-                                               }
-                                       }
-                               }
-                       }
-
-                       $vendor['vendor_link']                                  
= 
$GLOBALS['phpgw']->link('/index.php','menuaction='.$this->currentapp.'.uilookup.vendor');
-                       $vendor['lang_vendor']                                  
= lang('Vendor');
-                       $vendor['lang_select_vendor_help']              = 
lang('Klick this link to select vendor');
-                       $vendor['lang_vendor_name']                             
= lang('Vendor Name');
-
-                       unset($contacts);
-//_debug_array($vendor);
-                       return $vendor;
-               }
-
-
-               function initiate_ui_budget_account_lookup($data)
-               {
-                       if($data['type']=='view')
-                       {
-                               
$GLOBALS['phpgw']->xslttpl->add_file(array('b_account_view'));
-                       }
-                       else
-                       {
-                               
$GLOBALS['phpgw']->xslttpl->add_file(array('b_account_form'));
-                       }
-
-                       $b_account['value_b_account_id']                        
= $data['b_account_id'];
-                       $b_account['value_b_account_name']                      
= $data['b_account_name'];
-                       $b_account['b_account_link']                            
= 
$GLOBALS['phpgw']->link('/index.php','menuaction='.$this->currentapp.'.uilookup.b_account');
-                       $b_account['lang_b_account']                            
= lang('b_account');
-                       $b_account['lang_select_b_account_help']        = 
lang('Klick this link to select budget account');
-                       $b_account['lang_b_account']                            
= lang('Budget account');
-                       if($data['b_account_id'] && !$data['b_account_name'])
-                       {
-                               $b_account_object       = 
CreateObject($this->currentapp.'.sob_account');
-                               $b_account_data = 
$b_account_object->read_single($data['b_account_id']);
-                               $b_account['value_b_account_name']      = 
$b_account_data['descr'];
-                       }
-
-//_debug_array($b_account);
-                       return $b_account;
-               }
-
-
-               function initiate_ui_alarm($data)
-               {
-                       $boalarm                = 
CreateObject($this->currentapp.'.boalarm');
-
-                       if($data['type']=='view')
-                       {
-                               
$GLOBALS['phpgw']->xslttpl->add_file(array('alarm_view'));
-                       }
-                       else
-                       {
-                               
$GLOBALS['phpgw']->xslttpl->add_file(array('alarm_form'));
-                       }
-
-                       $alarm['header'][] = array
-                       (
-                               'lang_time'             => lang('Time'),
-                               'lang_text'     => lang('Text'),
-                               'lang_user'                     => lang('User'),
-                               'lang_enabled'          => lang('Enabled'),
-                               'lang_select'           => lang('Select')
-                               );
-
-                       $alarm['values'] = 
$boalarm->read_alarms($data['alarm_type'],$data['id'],$data['text']);
-                       if(!count($alarm['values'])>0)
-                       {
-                               unset($alarm['values']);
-                       }
-
-                       if($data['type']=='form')
-                       {
-                               $alarm['alter_alarm'][] = array
-                               (
-                                       'lang_enable'           => 
lang('Enable'),
-                                       'lang_disable'          => 
lang('Disable'),
-                                       'lang_delete'           => 
lang('Delete')
-                                       );
-
-                               for ($i=1; $i<=31; $i++)
-                               {
-                                       
$alarm['add_alarm']['day_list'][($i-1)][id] = $i;
-                               }
-                               $alarm['add_alarm']['lang_day']                 
                = lang('Day');
-                               $alarm['add_alarm']['lang_day_statustext']      
        = lang('Day');
-
-                               for ($i=1; $i<=24; $i++)
-                               {
-                                       
$alarm['add_alarm']['hour_list'][($i-1)][id] = $i;
-                               }
-                               $alarm['add_alarm']['lang_hour']                
                        = lang('Hour');
-                               $alarm['add_alarm']['lang_hour_statustext']     
                = lang('Hour');
-
-                               for ($i=1; $i<=60; $i++)
-                               {
-                                       
$alarm['add_alarm']['minute_list'][($i-1)][id] = $i;
-                               }
-                               $alarm['add_alarm']['lang_minute']              
                        = lang('Minutes before the event');
-                               $alarm['add_alarm']['lang_minute_statustext']   
        = lang('Minutes before the event');
-
-                               $alarm['add_alarm']['user_list'] = 
$this->get_user_list_right2('select',4,False,$data['acl_location'],False,$default=$this->account);
-
-                               $alarm['add_alarm']['lang_user']                
                        = lang('User');
-                               $alarm['add_alarm']['lang_user_statustext']     
                = lang('Select the user the alarm belongs to.');
-                               $alarm['add_alarm']['lang_no_user']             
                        = lang('No user');
-                               $alarm['add_alarm']['lang_add']                 
                        = lang('Add');
-                               $alarm['add_alarm']['lang_add_alarm']           
                                = lang('Add alarm');
-                               $alarm['add_alarm']['lang_add_statustext']      
                = lang('Add alarm for selected user');
-
-                       }
-
-//_debug_array($alarm['values']);
-                       return $alarm;
-               }
-
-
-               function 
select_multi_list_2($selected='',$input_list,$input_type='')
-               {
-                       $j=0;
-                       if (isset($input_list) AND is_array($input_list))
-                       {
-                               foreach($input_list as $entry)
-                               {
-                                       $output_list[$j]['id'] = $entry['id'];
-                                       $output_list[$j]['value'] = 
$entry['value'];
-                                       $output_list[$j]['input_type'] = 
$input_type;
-
-                                       for ($i=0;$i<count($selected);$i++)
-                                       {
-                                               if($selected[$i] == 
$entry['id'])
-                                               {
-                                                       
$output_list[$j]['checked'] = 'checked';
-                                               }
-                                       }
-                                       $j++;
-                               }
-                       }
-
-                       for ($i=0;$i<count($output_list);$i++)
-                       {
-                               if ($output_list[$i]['checked'] != 'checked')
-                               {
-                                       unset($output_list[$i]['checked']);
-                               }
-                       }
-
-                       return $output_list;
-               }
-
-               function translate_datatype($datatype)
-               {
-                       $datatype_text = array(
-                               'V' => 'Varchar',
-                               'I' => 'Integer',
-                               'C' => 'char',
-                               'N' => 'Float',
-                               'D' => 'Date',
-                               'T' => 'Memo',
-                               'R' => 'Muliple radio',
-                               'CH' => 'Muliple checkbox',
-                               'LB' => 'Listbox',
-                               'AB' => 'Contact',
-                               'VENDOR' => 'Vendor',
-                               'email' => 'Email'
-                       );
-
-                       $datatype  = lang($datatype_text[$datatype]);
-
-                       return $datatype;
-               }
-
-               function translate_datatype_insert($datatype)
-               {
-                       $datatype_text = array(
-                               'V' => 'varchar',
-                               'I' => 'int',
-                               'C' => 'char',
-                               'N' => 'decimal',
-                               'D' => 'timestamp',
-                               'T' => 'text',
-                               'R' => 'int',
-                               'CH' => 'text',
-                               'LB' => 'int',
-                               'AB' => 'int',
-                               'VENDOR' => 'int',
-                               'email' => 'varchar'
-                       );
-
-                       return $datatype_text[$datatype];
-               }
-
-               function translate_datatype_precision($datatype)
-               {
-                       $datatype_precision = array(
-                               'R' => 4,
-                               'LB' => 4,
-                               'AB' => 4,
-                               'VENDOR' => 4,
-                               'email' => 64
-                       );
-
-                       return $datatype_precision[$datatype];
-               }
-
-               function save_attributes($values_attribute,$type)
-               {
-
-                       for ($i=0;$i<count($values_attribute);$i++)
-                       {
-                               if($values_attribute[$i]['datatype']=='CH' && 
$values_attribute[$i]['value'])
-                               {
-                                       $values_attribute[$i]['value'] = 
serialize($values_attribute[$i]['value']);
-                               }
-                               if($values_attribute[$i]['datatype']=='R' && 
$values_attribute[$i]['value'])
-                               {
-                                       $values_attribute[$i]['value'] = 
$values_attribute[$i]['value'][0];
-                               }
-
-                               if($values_attribute[$i]['datatype']=='N' && 
$values_attribute[$i]['value'])
-                               {
-                                       $values_attribute[$i]['value'] = 
str_replace(",",".",$values_attribute[$i]['value']);
-                               }
-
-                               if($values_attribute[$i]['datatype']=='D' && 
$values_attribute[$i]['value'])
-                               {
-                                       $dateformat= 
$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
-                                       $dateformat = 
str_replace(".","",$dateformat);
-                                       $dateformat = 
str_replace("-","",$dateformat);
-                                       $dateformat = 
str_replace("/","",$dateformat);
-                                       $y=strpos($dateformat,'Y');
-                                       $d=strpos($dateformat,'d');
-                                       $m=strpos($dateformat,'m');
-
-                                       $dateparts = explode('/', 
$values_attribute[$i]['value']);
-                                       $day            = $dateparts[$d];
-                                       $month          = $dateparts[$m];
-                                       $year           = $dateparts[$y];
-                                       $values_attribute[$i]['value'] = 
date($this->dateformat,mktime(2,0,0,$month,$day,$year));
-                               }
-                       }
-
-                       
$this->socommon->save_attributes($values_attribute,$type);
-               }
-
-               function list_methods($_type='xmlrpc')
-               {
-                       /*
-                         This handles introspection or discovery by the logged 
in client,
-                         in which case the input might be an array.  The 
server always calls
-                         this function to fill the server dispatch map using a 
string.
-                       */
-                       if (is_array($_type))
-                       {
-                               $_type = $_type['type'] ? $_type['type'] : 
$_type[0];
-                       }
-                       switch($_type)
-                       {
-                               case 'xmlrpc':
-                                       $xml_functions = array(
-                                               'read' => array(
-                                                       'function'  => 'read',
-                                                       'signature' => 
array(array(xmlrpcInt,xmlrpcStruct)),
-                                                       'docstring' => 
lang('Read a single entry by passing the id and fieldlist.')
-                                               ),
-                                               'save' => array(
-                                                       'function'  => 'save',
-                                                       'signature' => 
array(array(xmlrpcStruct,xmlrpcStruct)),
-                                                       'docstring' => 
lang('Update a single entry by passing the fields.')
-                                               ),
-                                               'delete' => array(
-                                                       'function'  => 'delete',
-                                                       'signature' => 
array(array(xmlrpcBoolean,xmlrpcInt)),
-                                                       'docstring' => 
lang('Delete a single entry by passing the id.')
-                                               ),
-                                               'list' => array(
-                                                       'function'  => '_list',
-                                                       'signature' => 
array(array(xmlrpcStruct,xmlrpcStruct)),
-                                                       'docstring' => 
lang('Read a list of entries.')
-                                               ),
-                                               'list_methods' => array(
-                                                       'function'  => 
'list_methods',
-                                                       'signature' => 
array(array(xmlrpcStruct,xmlrpcString)),
-                                                       'docstring' => 
lang('Read this list of methods.')
-                                               )
-                                       );
-                                       return $xml_functions;
-                                       break;
-                               case 'soap':
-                                       return $this->soap_functions;
-                                       break;
-                               default:
-                                       return array();
-                                       break;
-                       }
-               }
-
-               function add_leading_zero($num)
-               {
-
-                       if ($id_type == "hex")
-                       {
-                               $num = hexdec($num);
-                               $num++;
-                               $num = dechex($num);
-                       }
-                       else
-                       {
-                               $num++;
-                       }
-
-                       if (strlen($num) == 4)
-                               $return = $num;
-                       if (strlen($num) == 3)
-                               $return = "0$num";
-                       if (strlen($num) == 2)
-                               $return = "00$num";
-                       if (strlen($num) == 1)
-                               $return = "000$num";
-                       if (strlen($num) == 0)
-                               $return = "0001";
-
-                       return strtoupper($return);
-               }
-
-
-               function read_location_data($location_code)
-               {
-                       $soadmin_location       = 
CreateObject($this->currentapp.'.soadmin_location');
-
-                       $location_types = 
$soadmin_location->select_location_type();
-                       unset($soadmin_location);
-
-                       return 
$this->socommon->read_location_data($location_code,$location_types);
-               }
-
-               function read_single_tenant($tenant_id)
-               {
-                       return $this->socommon->read_single_tenant($tenant_id);
-               }
-
-               function check_location($location_code='',$type_id='')
-               {
-                       return 
$this->socommon->check_location($location_code,$type_id);
-               }
-
-               function generate_sql($data)
-               {
-//_debug_array($data);
-
-                       $cols                           = 
(isset($data['cols'])?$data['cols']:'');
-                       $entity_table           = 
(isset($data['entity_table'])?$data['entity_table']:'');
-                       $cols_return            = 
(isset($data['cols_return'])?$data['cols_return']:'');
-                       $uicols                         = 
(isset($data['uicols'])?$data['uicols']:'');
-                       $joinmethod             = 
(isset($data['joinmethod'])?$data['joinmethod']:'');
-                       $paranthesis            = 
(isset($data['paranthesis'])?$data['paranthesis']:'');
-                       $lookup                         = 
(isset($data['lookup'])?$data['lookup']:'');
-                       $location_level         = 
(isset($data['location_level'])?$data['location_level']:'');
-                       $no_address     = 
(isset($data['no_address'])?$data['no_address']:'');
-
-                       $this->join = $this->socommon->join;
-
-                       $joinmethod .= " $this->join  fm_location1 ON 
($entity_table.loc1 = fm_location1.loc1))";
-                       $paranthesis .='(';
-                       $joinmethod .= " $this->join  fm_part_of_town ON 
(fm_location1.part_of_town_id = fm_part_of_town.part_of_town_id))";
-                       $paranthesis .='(';
-                       $joinmethod .= " $this->join  fm_owner ON 
(fm_location1.owner_id = fm_owner.id))";
-                       $paranthesis .='(';
-
-                       $soadmin_location       = 
CreateObject($this->currentapp.'.soadmin_location');
-                       $location_types = 
$soadmin_location->select_location_type();
-                       $config = $soadmin_location->read_config('');
-
-                       if($location_level)
-                       {
-                               $type_id=$location_level;
-                       }
-                       else
-                       {
-                               $type_id        = count($location_types);
-                       }
-                       $this->type_id  = $type_id;
-
-                       for ($i=0; $i<$type_id; $i++)
-                       {
-
-                               $uicols['input_type'][]         = 'text';
-                               $uicols['name'][]                       = 'loc' 
. $location_types[$i]['id'];
-                               $uicols['descr'][]                      = 
$location_types[$i]['name'];
-                               $uicols['statustext'][]         = 
$location_types[$i]['descr'];
-                       }
-/*
-                       $fm_location_cols = 
$soadmin_location->read_attrib(array('type_id'=>$type_id,'lookup_type'=>$type_id));
-                       $location_cols_count    = count($fm_location_cols);
-
-                       for ($i=0;$i<$location_cols_count;$i++)
-                       {
-                               if($fm_location_cols[$i]['list']==1)
-                               {
-                                       $cols_extra[]                           
= $fm_location_cols[$i]['column_name']; // only for lookup
-                                       $cols_return[]                          
= $fm_location_cols[$i]['column_name'];
-                                       $uicols['input_type'][]         = 
'text';
-                                       $uicols['name'][]                       
= $fm_location_cols[$i]['column_name'];
-                                       $uicols['descr'][]                      
= $fm_location_cols[$i]['input_text'];
-                                       $uicols['statustext'][]         = 
$fm_location_cols[$i]['statustext'];
-                               }
-                       }
-
-*/
-                       unset($soadmin_location);
-
-                       for ($i=0; $i< $this->type_id; $i++)
-                       {
-                               $cols_return[] = 'loc' . 
$location_types[$i]['id'];
-                       }
-
-                       if($lookup)
-                       {
-                               $cols_return[]                          = 
'loc1_name';
-                               $cols_extra[]                           = 
'loc1_name';
-                               $uicols['input_type'][]         = 'text';
-                               $uicols['name'][]                       = 
'loc1_name';
-                               $uicols['descr'][]                      = 
lang('Property Name');
-                               $uicols['statustext'][]         = 
lang('Property Name');
-
-                               for ($i=2;$i<($type_id+1);$i++)
-                               {
-                                       $cols_return_lookup[]           = 'loc' 
. $i . '_name';
-                                       $uicols['input_type'][]         = 
'hidden';
-                                       $uicols['name'][]                       
= 'loc' . $i . '_name';
-                                       $uicols['descr'][]                      
= '';
-                                       $uicols['statustext'][]         = '';
-                               }
-                       }
-
-                       if(!$no_address)
-                       {
-                               $cols.= ",$entity_table.address";
-                               $cols_return[]                          = 
'address';
-                               $uicols['input_type'][]         = 'text';
-                               $uicols['name'][]                       = 
'address';
-                               $uicols['descr'][]                      = 
lang('address');
-                               $uicols['statustext'][]         = 
lang('address');
-                       }
-
-
-                       $config_count   = count($config);
-                       for ($i=0;$i<$config_count;$i++)
-                       {
-
-                               if (($config[$i]['location_type'] <= $type_id) 
&& ($config[$i]['query_value'] ==1))
-                               {
-
-                                       
if($config[$i]['column_name']=='street_id')
-                                       {
-
-                                               $cols_return[]                  
        = 'street_name';
-                                               $uicols['input_type'][]         
= 'hidden';
-                                               $uicols['name'][]               
        = 'street_name';
-                                               $uicols['descr'][]              
        = lang('street name');
-                                               $uicols['statustext'][]         
= lang('street name');
-
-                                               $cols_return[]                  
        = 'street_number';
-                                               $uicols['input_type'][]         
= 'hidden';
-                                               $uicols['name'][]               
        = 'street_number';
-                                               $uicols['descr'][]              
        = lang('street number');
-                                               $uicols['statustext'][]         
= lang('street number');
-
-                                               $cols_return[]                  
        = $config[$i]['column_name'];
-                                               $uicols['input_type'][]         
= 'hidden';
-                                               $uicols['name'][]               
        = $config[$i]['column_name'];
-                                               $uicols['descr'][]              
        = lang($config[$i]['input_text']);
-                                               $uicols['statustext'][]         
= lang($config[$i]['input_text']);
-                                               if($lookup)
-                                               {
-                                                       $cols_extra[]           
                = 'street_name';
-                                                       $cols_extra[]           
                = 'street_number';
-                                                       $cols_extra[]           
                = $config[$i]['column_name'];
-                                               }
-
-                                       }
-                                       else
-                                       {
-                                               $cols_return[]                  
        = $config[$i]['column_name'];
-                                               $uicols['input_type'][]         
= 'text';
-                                               $uicols['name'][]               
        = $config[$i]['column_name'];
-                                               $uicols['descr'][]              
        = $config[$i]['input_text'];
-                                               $uicols['statustext'][]         
= $config[$i]['input_text'];
-
-                                               if($lookup)
-                                               {
-                                                       $cols_extra[]           
                = $config[$i]['column_name'];
-                                               }
-                                       }
-                               }
-                       }
-
-                       $this->uicols           = $uicols;
-                       $this->cols_return      = $cols_return;
-                       $this->cols_extra       = $cols_extra;
-                       $this->cols_return_lookup       = $cols_return_lookup;
-
-                       $from .= " FROM $paranthesis $entity_table ";
-
-                       $sql = "SELECT $cols $from $joinmethod";
-
-                       return $sql;
-
-               }
-
-               function select_part_of_town($format='',$selected='')
-               {
-                       switch($format)
-                       {
-                               case 'select':
-                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('select_part_of_town'));
-                                       break;
-                               case 'filter':
-                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('filter_part_of_town'));
-                                       break;
-                       }
-
-                       $parts= $this->socommon->select_part_of_town();
-
-                       while (is_array($parts) && list(,$part) = each($parts))
-                       {
-                               $sel_part = '';
-                               if ($part['id']==$selected)
-                               {
-                                       $sel_part = 'selected';
-                               }
-
-                               $part_of_town_list[] = array
-                               (
-                                       'id'    => $part['id'],
-                                       'name'          => $part['name'],
-                                       'selected'      => $sel_part
-                               );
-                       }
-
-                       for ($i=0;$i<count($part_of_town_list);$i++)
-                       {
-                               if ($part_of_town_list[$i]['selected'] != 
'selected')
-                               {
-                                       
unset($part_of_town_list[$i]['selected']);
-                               }
-                       }
-
-                       return $part_of_town_list;
-               }
-
-               function select_category_property_list($format='',$selected='')
-               {
-                       switch($format)
-                       {
-                               case 'select':
-                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('cat_select'));
-                                       break;
-                               case 'filter':
-                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('cat_filter'));
-                                       break;
-                       }
-
-                       $categories= 
$this->socommon->select_category_property_list();
-
-                       while (is_array($categories) && list(,$category) = 
each($categories))
-                       {
-                               $sel_category = '';
-                               if ($category['id']==$selected)
-                               {
-                                       $sel_category = 'selected';
-                               }
-
-                               $category_list[] = array
-                               (
-                                       'cat_id'        => $category['id'],
-                                       'name'          => $category['name'],
-                                       'selected'      => $sel_category
-                               );
-                       }
-
-                       for ($i=0;$i<count($category_list);$i++)
-                       {
-                               if ($category_list[$i]['selected'] != 
'selected')
-                               {
-                                       unset($category_list[$i]['selected']);
-                               }
-                       }
-
-                       return $category_list;
-               }
-
-               function select_district_list($format='',$selected='')
-               {
-                       switch($format)
-                       {
-                               case 'select':
-                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('select_district'));
-                                       break;
-                               case 'filter':
-                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('filter_district'));
-                                       break;
-                       }
-
-                       $districts= $this->socommon->select_district_list();
-
-                       while (is_array($districts) && list(,$district) = 
each($districts))
-                       {
-                               $sel_district = '';
-                               if ($district['id']==$selected)
-                               {
-                                       $sel_district = 'selected';
-                               }
-
-                               $district_list[] = array
-                               (
-                                       'id'    => $district['id'],
-                                       'name'          => $district['name'],
-                                       'selected'      => $sel_district
-                               );
-                       }
-
-                       for ($i=0;$i<count($district_list);$i++)
-                       {
-                               if ($district_list[$i]['selected'] != 
'selected')
-                               {
-                                       unset($district_list[$i]['selected']);
-                               }
-                       }
-
-                       return $district_list;
-               }
-
-
-               function validate_db_insert($values)
-               {
-                       foreach($values as $value)
-                       {
-                               if($value || $value === 0)
-                               {
-                                       $insert_value[] = "'".$value."'";
-                               }
-                               else
-                               {
-                                       $insert_value[] = 'NULL';
-                               }
-                       }
-
-                       $values = implode(",", $insert_value);
-                       return $values;
-               }
-
-               function validate_db_update($value_set)
-               {
-                       while (is_array($value_set) && list($field,$value) = 
each($value_set))
-                       {
-                               if($value || $value === 0)
-                               {
-                                       $value_entry[]= "$field='$value'";
-                               }
-                               else
-                               {
-                                       $value_entry[]= "$field=NULL";
-                               }
-                       }
-
-                       $value_set      = implode(",", $value_entry);
-                       return $value_set;
-               }
-
-               function fm_cache($name='',$value='')
-               {
-                       return $this->socommon->fm_cache($name,$value);
-               }
-
-               function next_id($table,$key='')
-               {
-                       return $this->socommon->next_id($table,$key);
-               }
-
-               function select_datatype($selected='')
-               {
-                       $datatypes[0]['id']= 'V';
-                       $datatypes[0]['name']= lang('varchar');
-                       $datatypes[1]['id']= 'C';
-                       $datatypes[1]['name']= lang('Character');
-                       $datatypes[2]['id']= 'I';
-                       $datatypes[2]['name']= lang('Integer');
-                       $datatypes[3]['id']= 'N';
-                       $datatypes[3]['name']= lang('Decimal');
-                       $datatypes[4]['id']= 'D';
-                       $datatypes[4]['name']= lang('Date');
-                       $datatypes[5]['id']= 'T';
-                       $datatypes[5]['name']= lang('Memo');
-                       $datatypes[6]['id']= 'R';
-                       $datatypes[6]['name']= lang('Multiple radio');
-                       $datatypes[7]['id']= 'CH';
-                       $datatypes[7]['name']= lang('Multiple Checkbox');
-                       $datatypes[8]['id']= 'LB';
-                       $datatypes[8]['name']= lang('ListBox');
-                       $datatypes[9]['id']= 'AB';
-                       $datatypes[9]['name']= lang('Contact');
-                       $datatypes[10]['id']= 'VENDOR';
-                       $datatypes[10]['name']= lang('Vendor');
-                       $datatypes[11]['id']= 'email';
-                       $datatypes[11]['name']= lang('Email');
-
-                       return $this->select_list($selected,$datatypes);
-
-               }
-
-               function select_nullable($selected='')
-               {
-                       $nullable[0]['id']= 'True';
-                       $nullable[0]['name']= lang('True');
-                       $nullable[1]['id']= 'False';
-                       $nullable[1]['name']= lang('False');
-
-                       return $this->select_list($selected,$nullable);
-               }
-
-
-               function excel($list,$name,$descr,$input_type='')
-               {
-                       $GLOBALS['phpgw_info']['flags'][noheader] = True;
-                       $GLOBALS['phpgw_info']['flags'][nofooter] = True;
-                       $GLOBALS['phpgw_info']['flags']['xslt_app'] = False;
-
-                       $filename= 
$GLOBALS['phpgw_info']['user']['account_lid'].'.xls';
-
-                       $workbook       = 
CreateObject($this->currentapp.'.excel',"-");
-                       $browser = CreateObject('phpgwapi.browser');
-                       
$browser->content_header($filename,'application/vnd.ms-excel');
-
-                       $count_uicols_name=count($name);
-
-                       $worksheet1 =& $workbook->add_worksheet('First One');
-
-                       $j=0;
-                       if (isset($list) AND is_array($list))
-                       {
-                               foreach($list as $entry)
-                               {
-                                       $m=0;
-                                       for ($k=0;$k<$count_uicols_name;$k++)
-                                       {
-                                               if($input_type[$k]!='hidden')
-                                               {
-                                                       $content[$j][$m]        
= str_replace("\r\n"," ",$entry[$name[$k]]);
-                                                       
$worksheet1->write_string(0, $m, $descr[$k]);
-                                                       $m++;
-                                               }
-                                       }
-                                       $j++;
-                               }
-
-                               foreach($content as $row)
-                               {
-                                       $line++;
-                                       for ($i=0; $i<count($row); $i++)
-                                       {
-                                               
$worksheet1->write($line,$i,$row[$i]);
-                                       }
-                               }
-                       }
-                       $workbook->close();
-
-               }
-
-               function increment_id($name)
-               {
-                       return $this->socommon->increment_id($name);
-               }
-
-               function get_origin_link($type)
-               {
-                       if($type=='tts'):
-                       {
-                               $link = '.uitts.view';
-                       }
-                       elseif($type=='request'):
-                       {
-                               $link = '.uirequest.view';
-                       }
-                       elseif($type=='project'):
-                       {
-                               $link = '.uiproject.view';
-                       }
-                       elseif(substr($type,0,6)=='entity'):
-                       {
-
-                               $type           = explode("_",$type);
-                               $entity_id      = $type[1];
-                               $cat_id         = $type[2];
-                               $link = 
".uientity.view&entity_id=$entity_id&cat_id=$cat_id";
-                       }
-                       endif;
-
-                       return $link;
-               }
-
-               function select_wo_hours_category_list($selected='')
-               {
-                       $category_list= 
$this->socommon->select_wo_hours_category_list();
-                       if($selected)
-                       {
-                               $category_list = 
$this->select_list($selected,$category_list);
-                       }
-
-                       return $category_list;
-               }
-
-               function new_db()
-               {
                        return $this->socommon->new_db();
-               }
-
-       }
-?>
+<?php
+       /**
+       * phpGroupWare - property: a Facilities Management System.
+       *
+       * @author Sigurd Nes <address@hidden>
+       * @copyright Copyright (C) 2003-2005 Free Software Foundation, Inc. 
http://www.fsf.org/
+       * @license http://www.gnu.org/licenses/gpl.html GNU General Public 
License
+       * @internal Development of this application was funded by 
http://www.bergen.kommune.no/bbb_/ekstern/
+       * @package property
+       * @subpackage core
+       * @version $Id: class.bocommon.inc.php,v 1.21 2006/02/03 12:05:49 
sigurdne Exp $
+       */
+
+       /**
+        * Description
+        * @package property
+        */
+
+       class bocommon
+       {
+               var $start;
+               var $query;
+               var $filter;
+               var $sort;
+               var $order;
+               var $cat_id;
+               var $district_id;
+
+
+               var $public_functions = array
+               (
+                       'select_part_of_town'   => True,
+                       'menu'                                  => True,
+               );
+
+               var $soap_functions = array(
+                       'list' => array(
+                               'in'  => 
array('int','int','struct','string','int'),
+                               'out' => array('array')
+                       ),
+                       'read' => array(
+                               'in'  => array('int','struct'),
+                               'out' => array('array')
+                       ),
+                       'save' => array(
+                               'in'  => array('int','struct'),
+                               'out' => array()
+                       ),
+                       'delete' => array(
+                               'in'  => array('int','struct'),
+                               'out' => array()
+                       )
+               );
+
+               function bocommon()
+               {
+
+                       $GLOBALS['phpgw_info']['flags']['currentapp']   =       
'property';
+                       $this->currentapp               = 
$GLOBALS['phpgw_info']['flags']['currentapp'];
+                       $this->socommon                 = 
CreateObject($this->currentapp.'.socommon');
+                       $this->account          = 
$GLOBALS['phpgw_info']['user']['account_id'];
+
+                       if (!is_object($GLOBALS['phpgw']->asyncservice))
+                       {
+                               $GLOBALS['phpgw']->asyncservice = 
CreateObject('phpgwapi.asyncservice');
+                       }
+                       $this->async = &$GLOBALS['phpgw']->asyncservice;
+
+                       $this->join                     = $this->socommon->join;
+                       $this->left_join        = $this->socommon->left_join;
+                       $this->like                     = $this->socommon->like;
+
+                       switch($GLOBALS['phpgw_info']['server']['db_type'])
+                       {
+                               case 'mssql':
+                                       $this->dateformat               = "M d 
Y";
+                                       $this->datetimeformat   = "M d Y g:iA";
+                                       break;
+                               case 'mysql':
+                                       $this->dateformat               = 
"Y-m-d";
+                                       $this->datetimeformat   = "Y-m-d G:i:s";
+                                       break;
+                               case 'pgsql':
+                                       $this->dateformat               = 
"Y-m-d";
+                                       $this->datetimeformat   = "Y-m-d G:i:s";
+//                                     $this->dateformat               = "F j, 
Y";
+//                                     $this->datetimeformat   = "F j, Y g:iA";
+                                       break;
+                       }
+
+       /*              if 
($GLOBALS['phpgw_info']['server']['db_type']=='mssql')
+                       {
+                               $this->dateformat               = "M d Y";
+                               $this->datetimeformat   = "M d Y g:iA";
+                       }
+                       else
+                       {
+                               $this->dateformat               = "Y-m-d";
+                               $this->datetimeformat   = "Y-m-d G:i:s";
+                       }
+
+
+                       if(!$GLOBALS['phpgw_info']['flags']['css'])
+                       {
+                               $GLOBALS['phpgw_info']['flags']['css'] .= 
"-->\n</style>\n"
+                                       . '<link rel="stylesheet" 
type="text/css" media="all" href="'
+                                       . 
$GLOBALS['phpgw_info']['server']['webserver_url'].'/' . $this->currentapp . 
'/templates/'
+                                       . 
$GLOBALS['phpgw_info']['server']['template_set']
+                                       . 
'/css/'.$GLOBALS['phpgw_info']['server']['template_set'].'.css" 
title="'.$GLOBALS['phpgw_info']['server']['template_set'].'" />'
+                                       . "\n<style type=\"text/css\">\n<!--\n";
+                       }
+*/
+               }
+
+               function jscalendar()
+               {
+                       $phpgw_js_url = 
$GLOBALS['phpgw_info']['server']['webserver_url'].'/phpgwapi/js';
+//                     $img = 
$GLOBALS['phpgw']->common->get_image_path('phpgwapi','default').'/cal.png';
+                       $img    = 
$GLOBALS['phpgw_info']['server']['webserver_url'] . 
'/phpgwapi/templates/default/images/cal.png';
+
+//                     $img = $phpgw_js_url.'/jscalendar/img.gif';
+                       $dateformat = 
$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
+                       $jsDateFormat = str_replace(array('d', 'm', 'M', 'Y'), 
array('%d', '%m', '%b', '%Y'), $dateformat);
+
+                       $GLOBALS['phpgw_info']['flags']['java_script'] 
.='</script>
+                       <link rel="stylesheet" type="text/css" media="all" 
href="'.$phpgw_js_url.'/jscalendar/calendar-win2k-cold-1.css" 
title="win2k-cold-1" >
+                       <script type="text/javascript" 
src="'.$phpgw_js_url.'/jscalendar/calendar.js"></script>
+                       <script type="text/javascript" 
src="'.$phpgw_js_url.'/jscalendar/calendar-setup.js"></script>
+                       <script type="text/javascript" 
src="'.$phpgw_js_url.'/jscalendar/lang/calendar-'.substr($GLOBALS['phpgw_info']['user']['preferences']['common']['lang'],0,2)
 .'.js"></script>
+                       ';
+
+
+//                     <script type="text/javascript" 
src="'.ereg_replace('[?&]*click_history=[0-9a-f]*','',$GLOBALS['phpgw']->link('/phpgwapi/js/jscalendar/jscalendar-setup.php')).'"></script>
+
+                       $cal_info=array(
+//                             'stylesheet'                                    
=> $phpgw_js_url.'/jscalendar/calendar-win2k-cold-1.css',
+//                             'calendar_source'                               
=> $phpgw_js_url.'/jscalendar/calendar.js',
+//                             'calendar_setup_source'                 => 
$phpgw_js_url.'/jscalendar/calendar-setup.js',
+//                             'calendar_lang'                                 
=> 
$phpgw_js_url.'/jscalendar/lang/calendar-'.substr($GLOBALS['phpgw_info']['user']['preferences']['common']['lang'],0,2)
 .'.js',
+                               'jsDateFormat'                                  
=> $jsDateFormat,
+                               'img'                                           
        => $img,
+                               );
+                       return $cal_info;
+               }
+
+               function check_perms($rights, $required)
+               {
+       //              return (!!($rights & $required) == True);
+                       return ($rights & $required);
+               }
+
+               function create_preferences($app='',$user_id='')
+               {
+                       return 
$this->socommon->create_preferences($app,$user_id);
+               }
+
+               function get_lookup_entity($location='')
+               {
+                       return $this->socommon->get_lookup_entity($location);
+               }
+
+               function get_start_entity($location='')
+               {
+                       return $this->socommon->get_start_entity($location);
+               }
+
+               function msgbox_data($receipt)
+               {
+                       $msgbox_data_error=array();
+                       if (isSet($receipt['error']) AND 
is_array($receipt['error']))
+                       {
+                               foreach($receipt['error'] as $errors)
+                               {
+                                       $msgbox_data_error += 
array($errors['msg']=> False);
+                               }
+                       }
+
+                       $msgbox_data_message=array();
+
+                       if (isSet($receipt['message']) AND 
is_array($receipt['message']))
+                       {
+                               foreach($receipt['message'] as $messages)
+                               {
+                                       $msgbox_data_message += 
array($messages['msg']=> True);
+                               }
+                       }
+
+                       $msgbox_data = $msgbox_data_error + 
$msgbox_data_message;
+
+                       return $msgbox_data;
+               }
+
+               function moneyformat($amount)
+               {
+                       if 
($GLOBALS['phpgw_info']['server']['db_type']=='mssql')
+                       {
+                               $moneyformat    = 
"CONVERT(MONEY,"."'$amount'".",0)";
+                       }
+                       else
+                       {
+                               $moneyformat    = "'" . $amount . "'";
+                       }
+
+                       return $moneyformat;
+               }
+
+
+               function date_array($date)
+               {
+                       $dateformat = 
strtolower($GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']);
+                       $dateformat = str_replace(".","",$dateformat);
+                       $dateformat = str_replace("-","",$dateformat);
+                       $dateformat = str_replace("/","",$dateformat);
+                       $y=strpos($dateformat,'y');
+                       $d=strpos($dateformat,'d');
+                       $m=strpos($dateformat,'m');
+
+                       $dateparts = explode('/', $date);
+                       $date_array['day']              = $dateparts[$d];
+                       $date_array['month']    = $dateparts[$m];
+                       $date_array['year']             = $dateparts[$y];
+
+                       return $date_array;
+               }
+
+               function date_to_timestamp($date)
+               {
+                       if($date)
+                       {
+                               $date_array     = $this->date_array($date);
+                               $date   = mktime 
(8,0,0,$date_array['month'],$date_array['day'],$date_array['year']);
+                       }
+                       return $date;
+               }
+
+
+               function 
column_list($selected='',$entity_type='',$cat_id,$allrows='')
+               {
+                       $bostandard_entity      = 
CreateObject($this->currentapp.'.bostandard_entity',True);
+
+                       if(!$selected)
+                       {
+                               
$selected=$GLOBALS['phpgw_info']['user']['preferences'][$this->currentapp][$entity_type.'_columns_'.$cat_id];
+                       }
+
+                       $columns = 
$bostandard_entity->read_attrib($entity_type,$cat_id,$allrows);
+//_debug_array($columns);
+
+                       
$column_list=$this->select_multi_list($selected,$columns);
+
+                       return $column_list;
+
+               }
+
+               function select_multi_list($selected='',$input_list)
+               {
+                       $j=0;
+                       if (isset($input_list) AND is_array($input_list))
+                       {
+                               foreach($input_list as $entry)
+                               {
+                                       $output_list[$j]['id'] = $entry['id'];
+                                       $output_list[$j]['name'] = 
$entry['name'];
+
+                                       for ($i=0;$i<count($selected);$i++)
+                                       {
+                                               if($selected[$i] == 
$entry['id'])
+                                               {
+                                                       
$output_list[$j]['selected'] = 'selected';
+                                               }
+                                       }
+                                       $j++;
+                               }
+                       }
+
+                       for ($i=0;$i<count($output_list);$i++)
+                       {
+                               if ($output_list[$i]['selected'] != 'selected')
+                               {
+                                       unset($output_list[$i]['selected']);
+                               }
+                       }
+
+                       return $output_list;
+               }
+
+
+
+               function select_list($selected='',$input_list='')
+               {
+                       if (isset($input_list) AND is_array($input_list))
+                       {
+                               foreach($input_list as $entry)
+                               {
+                                       $sel_entry = '';
+                                       if ($entry['id']==$selected)
+                                       {
+                                               $sel_entry = 'selected';
+                                       }
+                                       $entry_list[] = array
+                                       (
+                                               'id'            => $entry['id'],
+                                               'name'          => 
$entry['name'],
+                                               'selected'      => $sel_entry
+                                       );
+                               }
+                               for ($i=0;$i<count($entry_list);$i++)
+                               {
+                                       if ($entry_list[$i]['selected'] != 
'selected')
+                                       {
+                                               
unset($entry_list[$i]['selected']);
+                                       }
+                               }
+                       }
+                       return $entry_list;
+               }
+
+
+               function 
get_user_list($format='',$selected='',$extra='',$default='',$start='', 
$sort='', $order='', $query='',$offset='')
+               {
+                       switch($format)
+                       {
+                               case 'select':
+                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('user_id_select'));
+                                       break;
+                               case 'filter':
+                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('user_id_filter'));
+                                       break;
+                       }
+
+                       if(!$selected && $default)
+                       {
+                               $selected = $default;
+                       }
+
+                       if (is_array($extra))
+                       {
+                               foreach($extra as $extra_user)
+                               {
+                                       $users_extra[]=array
+                                       (
+                                               'account_id' => $extra_user,
+                                               'account_firstname' => 
lang($extra_user)
+                                       );
+                               }
+                       }
+
+                       $accounts       = CreateObject('phpgwapi.accounts');
+                       $users = $accounts->get_list('accounts', $start, $sort, 
$order, $query,$offset);
+                       unset($accounts);
+                       if (is_array($users_extra) && is_array($users))
+                       {
+                               $users = $users_extra + $users;
+                       }
+
+                       if (isSet($users) AND is_array($users))
+                       {
+                               foreach($users as $user)
+                               {
+                                       $sel_user = '';
+                                       if ($user['account_id']==$selected)
+                                       {
+                                               $sel_user = 'selected';
+                                       }
+
+                                       $user_list[] = array
+                                       (
+                                               'user_id'       => 
$user['account_id'],
+                                               'name'          => 
$user['account_lastname'].' '.$user['account_firstname'],
+                                               'selected'      => $sel_user
+                                       );
+                               }
+                       }
+
+                       $user_count= count($user_list);
+                       for ($i=0;$i<$user_count;$i++)
+                       {
+                               if ($user_list[$i]['selected'] != 'selected')
+                               {
+                                       unset($user_list[$i]['selected']);
+                               }
+                       }
+
+//_debug_array($user_list);
+                       return $user_list;
+               }
+
+               function get_group_list($format='',$selected='',$start='', 
$sort='', $order='', $query='',$offset='')
+               {
+                       switch($format)
+                       {
+                               case 'select':
+                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('group_select'));
+                                       break;
+                               case 'filter':
+                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('group_filter'));
+                                       break;
+                       }
+
+                       $accounts       = CreateObject('phpgwapi.accounts');
+                       $users = $accounts->get_list('groups', $start, $sort, 
$order, $query,$offset);
+                       unset($accounts);
+                       if (isSet($users) AND is_array($users))
+                       {
+                               foreach($users as $user)
+                               {
+                                       $sel_user = '';
+                                       if ($user['account_id']==$selected)
+                                       {
+                                               $sel_user = 'selected';
+                                       }
+
+                                       $user_list[] = array
+                                       (
+                                               'id'    => $user['account_id'],
+                                               'name'          => 
$user['account_firstname'],
+                                               'selected'      => $sel_user
+                                       );
+                               }
+                       }
+
+                       $user_count= count($user_list);
+                       for ($i=0;$i<$user_count;$i++)
+                       {
+                               if ($user_list[$i]['selected'] != 'selected')
+                               {
+                                       unset($user_list[$i]['selected']);
+                               }
+                       }
+
+//_debug_array($user_list);
+                       return $user_list;
+               }
+
+
+               function 
get_user_list_right($right='',$selected='',$acl_location='')
+               {
+                       
$employees=$this->socommon->get_user_list_right($right,$acl_location);
+                       while (is_array($employees) && list(,$user) = 
each($employees))
+                       {
+                               $sel_user = '';
+                               if ($user['account_lid']==$selected)
+                               {
+                                       $sel_user = 'selected';
+                               }
+
+                               $user_list[] = array
+                               (
+                                       'lid'                   => 
$user['account_lid'],
+                                       'firstname'             => 
$user['account_firstname'],
+                                       'lastname'              => 
$user['account_lastname'],
+                                       'selected'              => $sel_user
+                               );
+                       }
+
+                       for ($i=0;$i<count($user_list);$i++)
+                       {
+                               if ($user_list[$i]['selected'] != 'selected')
+                               {
+                                       unset($user_list[$i]['selected']);
+                               }
+                       }
+
+                       return $user_list;
+               }
+
+               function 
get_user_list_right2($format='',$right='',$selected='',$acl_location='',$extra='',$default='')
+               {
+                       switch($format)
+                       {
+                               case 'select':
+                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('user_id_select'));
+                                       break;
+                               case 'filter':
+                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('user_id_filter'));
+                                       break;
+                       }
+
+                       if(!$selected && $default)
+                       {
+                               $selected = $default;
+                       }
+
+                       if (isset($extra) AND is_array($extra))
+                       {
+                               foreach($extra as $extra_user)
+                               {
+                                       $users_extra[]=array
+                                       (
+                                               'account_id' => $extra_user,
+                                               'account_firstname' => 
lang($extra_user)
+                                       );
+                               }
+                       }
+
+                       
$users=$this->socommon->get_user_list_right($right,$acl_location);
+
+                       if (is_array($users_extra) && is_array($users))
+                       {
+                               foreach($users as $users_entry)
+                               {
+                                       array_push($users_extra,$users_entry);
+                               }
+                               $users=$users_extra;
+                       }
+
+                       while (is_array($users) && list(,$user) = each($users))
+                       {
+                               $sel_user = '';
+                               if ($user['account_id']==$selected)
+                               {
+                                       $sel_user = 'selected';
+                               }
+
+                               $user_list[] = array
+                               (
+                                       'user_id'               => 
$user['account_id'],
+                                       'name'          => 
$user['account_lastname'].' '.$user['account_firstname'],
+                                       'selected'      => $sel_user
+                               );
+                       }
+
+                       for ($i=0;$i<count($user_list);$i++)
+                       {
+                               if ($user_list[$i]['selected'] != 'selected')
+                               {
+                                       unset($user_list[$i]['selected']);
+                               }
+                       }
+
+                       return $user_list;
+               }
+
+
+               function initiate_ui_vendorlookup($data)
+               {
+//_debug_array($data);
+
+                       $contacts       = 
CreateObject($this->currentapp.'.soactor');
+                       $contacts->role='vendor';
+
+                       if($data['type']=='view')
+                       {
+                               
$GLOBALS['phpgw']->xslttpl->add_file(array('vendor_view'));
+                       }
+                       else
+                       {
+                               
$GLOBALS['phpgw']->xslttpl->add_file(array('vendor_form'));
+                       }
+
+                       $vendor['value_vendor_id']                              
= $data['vendor_id'];
+                       $vendor['value_vendor_name']                    = 
$data['vendor_name'];
+
+                       if($data['vendor_id'] && !$data['vendor_name'])
+                       {
+                               $vendor_data                                    
        = $contacts->read_single(array('actor_id'=>$data['vendor_id']));
+                               if(is_array($vendor_data))
+                               {
+                                       foreach($vendor_data['attributes'] as 
$attribute)
+                                       {
+                                               
if($attribute['name']=='org_name')
+                                               {
+                                                       
$vendor['value_vendor_name']=$attribute['value'];
+                                                       break;
+                                               }
+                                       }
+                               }
+                       }
+
+                       $vendor['vendor_link']                                  
= 
$GLOBALS['phpgw']->link('/index.php','menuaction='.$this->currentapp.'.uilookup.vendor');
+                       $vendor['lang_vendor']                                  
= lang('Vendor');
+                       $vendor['lang_select_vendor_help']              = 
lang('Klick this link to select vendor');
+                       $vendor['lang_vendor_name']                             
= lang('Vendor Name');
+
+                       unset($contacts);
+//_debug_array($vendor);
+                       return $vendor;
+               }
+
+
+               function initiate_ui_budget_account_lookup($data)
+               {
+                       if($data['type']=='view')
+                       {
+                               
$GLOBALS['phpgw']->xslttpl->add_file(array('b_account_view'));
+                       }
+                       else
+                       {
+                               
$GLOBALS['phpgw']->xslttpl->add_file(array('b_account_form'));
+                       }
+
+                       $b_account['value_b_account_id']                        
= $data['b_account_id'];
+                       $b_account['value_b_account_name']                      
= $data['b_account_name'];
+                       $b_account['b_account_link']                            
= 
$GLOBALS['phpgw']->link('/index.php','menuaction='.$this->currentapp.'.uilookup.b_account');
+                       $b_account['lang_b_account']                            
= lang('b_account');
+                       $b_account['lang_select_b_account_help']        = 
lang('Klick this link to select budget account');
+                       $b_account['lang_b_account']                            
= lang('Budget account');
+                       if($data['b_account_id'] && !$data['b_account_name'])
+                       {
+                               $b_account_object       = 
CreateObject($this->currentapp.'.sob_account');
+                               $b_account_data = 
$b_account_object->read_single($data['b_account_id']);
+                               $b_account['value_b_account_name']      = 
$b_account_data['descr'];
+                       }
+
+//_debug_array($b_account);
+                       return $b_account;
+               }
+
+
+               function initiate_ui_alarm($data)
+               {
+                       $boalarm                = 
CreateObject($this->currentapp.'.boalarm');
+
+                       if($data['type']=='view')
+                       {
+                               
$GLOBALS['phpgw']->xslttpl->add_file(array('alarm_view'));
+                       }
+                       else
+                       {
+                               
$GLOBALS['phpgw']->xslttpl->add_file(array('alarm_form'));
+                       }
+
+                       $alarm['header'][] = array
+                       (
+                               'lang_time'             => lang('Time'),
+                               'lang_text'     => lang('Text'),
+                               'lang_user'                     => lang('User'),
+                               'lang_enabled'          => lang('Enabled'),
+                               'lang_select'           => lang('Select')
+                               );
+
+                       $alarm['values'] = 
$boalarm->read_alarms($data['alarm_type'],$data['id'],$data['text']);
+                       if(!count($alarm['values'])>0)
+                       {
+                               unset($alarm['values']);
+                       }
+
+                       if($data['type']=='form')
+                       {
+                               $alarm['alter_alarm'][] = array
+                               (
+                                       'lang_enable'           => 
lang('Enable'),
+                                       'lang_disable'          => 
lang('Disable'),
+                                       'lang_delete'           => 
lang('Delete')
+                                       );
+
+                               for ($i=1; $i<=31; $i++)
+                               {
+                                       
$alarm['add_alarm']['day_list'][($i-1)][id] = $i;
+                               }
+                               $alarm['add_alarm']['lang_day']                 
                = lang('Day');
+                               $alarm['add_alarm']['lang_day_statustext']      
        = lang('Day');
+
+                               for ($i=1; $i<=24; $i++)
+                               {
+                                       
$alarm['add_alarm']['hour_list'][($i-1)][id] = $i;
+                               }
+                               $alarm['add_alarm']['lang_hour']                
                        = lang('Hour');
+                               $alarm['add_alarm']['lang_hour_statustext']     
                = lang('Hour');
+
+                               for ($i=1; $i<=60; $i++)
+                               {
+                                       
$alarm['add_alarm']['minute_list'][($i-1)][id] = $i;
+                               }
+                               $alarm['add_alarm']['lang_minute']              
                        = lang('Minutes before the event');
+                               $alarm['add_alarm']['lang_minute_statustext']   
        = lang('Minutes before the event');
+
+                               $alarm['add_alarm']['user_list'] = 
$this->get_user_list_right2('select',4,False,$data['acl_location'],False,$default=$this->account);
+
+                               $alarm['add_alarm']['lang_user']                
                        = lang('User');
+                               $alarm['add_alarm']['lang_user_statustext']     
                = lang('Select the user the alarm belongs to.');
+                               $alarm['add_alarm']['lang_no_user']             
                        = lang('No user');
+                               $alarm['add_alarm']['lang_add']                 
                        = lang('Add');
+                               $alarm['add_alarm']['lang_add_alarm']           
                                = lang('Add alarm');
+                               $alarm['add_alarm']['lang_add_statustext']      
                = lang('Add alarm for selected user');
+
+                       }
+
+//_debug_array($alarm['values']);
+                       return $alarm;
+               }
+
+
+               function 
select_multi_list_2($selected='',$input_list,$input_type='')
+               {
+                       $j=0;
+                       if (isset($input_list) AND is_array($input_list))
+                       {
+                               foreach($input_list as $entry)
+                               {
+                                       $output_list[$j]['id'] = $entry['id'];
+                                       $output_list[$j]['value'] = 
$entry['value'];
+                                       $output_list[$j]['input_type'] = 
$input_type;
+
+                                       for ($i=0;$i<count($selected);$i++)
+                                       {
+                                               if($selected[$i] == 
$entry['id'])
+                                               {
+                                                       
$output_list[$j]['checked'] = 'checked';
+                                               }
+                                       }
+                                       $j++;
+                               }
+                       }
+
+                       for ($i=0;$i<count($output_list);$i++)
+                       {
+                               if ($output_list[$i]['checked'] != 'checked')
+                               {
+                                       unset($output_list[$i]['checked']);
+                               }
+                       }
+
+                       return $output_list;
+               }
+
+               function translate_datatype($datatype)
+               {
+                       $datatype_text = array(
+                               'V' => 'Varchar',
+                               'I' => 'Integer',
+                               'C' => 'char',
+                               'N' => 'Float',
+                               'D' => 'Date',
+                               'T' => 'Memo',
+                               'R' => 'Muliple radio',
+                               'CH' => 'Muliple checkbox',
+                               'LB' => 'Listbox',
+                               'AB' => 'Contact',
+                               'VENDOR' => 'Vendor',
+                               'email' => 'Email'
+                       );
+
+                       $datatype  = lang($datatype_text[$datatype]);
+
+                       return $datatype;
+               }
+
+               function translate_datatype_insert($datatype)
+               {
+                       $datatype_text = array(
+                               'V' => 'varchar',
+                               'I' => 'int',
+                               'C' => 'char',
+                               'N' => 'decimal',
+                               'D' => 'timestamp',
+                               'T' => 'text',
+                               'R' => 'int',
+                               'CH' => 'text',
+                               'LB' => 'int',
+                               'AB' => 'int',
+                               'VENDOR' => 'int',
+                               'email' => 'varchar'
+                       );
+
+                       return $datatype_text[$datatype];
+               }
+
+               function translate_datatype_precision($datatype)
+               {
+                       $datatype_precision = array(
+                               'R' => 4,
+                               'LB' => 4,
+                               'AB' => 4,
+                               'VENDOR' => 4,
+                               'email' => 64
+                       );
+
+                       return $datatype_precision[$datatype];
+               }
+
+               function save_attributes($values_attribute,$type)
+               {
+
+                       for ($i=0;$i<count($values_attribute);$i++)
+                       {
+                               if($values_attribute[$i]['datatype']=='CH' && 
$values_attribute[$i]['value'])
+                               {
+                                       $values_attribute[$i]['value'] = 
serialize($values_attribute[$i]['value']);
+                               }
+                               if($values_attribute[$i]['datatype']=='R' && 
$values_attribute[$i]['value'])
+                               {
+                                       $values_attribute[$i]['value'] = 
$values_attribute[$i]['value'][0];
+                               }
+
+                               if($values_attribute[$i]['datatype']=='N' && 
$values_attribute[$i]['value'])
+                               {
+                                       $values_attribute[$i]['value'] = 
str_replace(",",".",$values_attribute[$i]['value']);
+                               }
+
+                               if($values_attribute[$i]['datatype']=='D' && 
$values_attribute[$i]['value'])
+                               {
+                                       $dateformat= 
$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
+                                       $dateformat = 
str_replace(".","",$dateformat);
+                                       $dateformat = 
str_replace("-","",$dateformat);
+                                       $dateformat = 
str_replace("/","",$dateformat);
+                                       $y=strpos($dateformat,'Y');
+                                       $d=strpos($dateformat,'d');
+                                       $m=strpos($dateformat,'m');
+
+                                       $dateparts = explode('/', 
$values_attribute[$i]['value']);
+                                       $day            = $dateparts[$d];
+                                       $month          = $dateparts[$m];
+                                       $year           = $dateparts[$y];
+                                       $values_attribute[$i]['value'] = 
date($this->dateformat,mktime(2,0,0,$month,$day,$year));
+                               }
+                       }
+
+                       
$this->socommon->save_attributes($values_attribute,$type);
+               }
+
+               function list_methods($_type='xmlrpc')
+               {
+                       /*
+                         This handles introspection or discovery by the logged 
in client,
+                         in which case the input might be an array.  The 
server always calls
+                         this function to fill the server dispatch map using a 
string.
+                       */
+                       if (is_array($_type))
+                       {
+                               $_type = $_type['type'] ? $_type['type'] : 
$_type[0];
+                       }
+                       switch($_type)
+                       {
+                               case 'xmlrpc':
+                                       $xml_functions = array(
+                                               'read' => array(
+                                                       'function'  => 'read',
+                                                       'signature' => 
array(array(xmlrpcInt,xmlrpcStruct)),
+                                                       'docstring' => 
lang('Read a single entry by passing the id and fieldlist.')
+                                               ),
+                                               'save' => array(
+                                                       'function'  => 'save',
+                                                       'signature' => 
array(array(xmlrpcStruct,xmlrpcStruct)),
+                                                       'docstring' => 
lang('Update a single entry by passing the fields.')
+                                               ),
+                                               'delete' => array(
+                                                       'function'  => 'delete',
+                                                       'signature' => 
array(array(xmlrpcBoolean,xmlrpcInt)),
+                                                       'docstring' => 
lang('Delete a single entry by passing the id.')
+                                               ),
+                                               'list' => array(
+                                                       'function'  => '_list',
+                                                       'signature' => 
array(array(xmlrpcStruct,xmlrpcStruct)),
+                                                       'docstring' => 
lang('Read a list of entries.')
+                                               ),
+                                               'list_methods' => array(
+                                                       'function'  => 
'list_methods',
+                                                       'signature' => 
array(array(xmlrpcStruct,xmlrpcString)),
+                                                       'docstring' => 
lang('Read this list of methods.')
+                                               )
+                                       );
+                                       return $xml_functions;
+                                       break;
+                               case 'soap':
+                                       return $this->soap_functions;
+                                       break;
+                               default:
+                                       return array();
+                                       break;
+                       }
+               }
+
+               function add_leading_zero($num)
+               {
+
+                       if ($id_type == "hex")
+                       {
+                               $num = hexdec($num);
+                               $num++;
+                               $num = dechex($num);
+                       }
+                       else
+                       {
+                               $num++;
+                       }
+
+                       if (strlen($num) == 4)
+                               $return = $num;
+                       if (strlen($num) == 3)
+                               $return = "0$num";
+                       if (strlen($num) == 2)
+                               $return = "00$num";
+                       if (strlen($num) == 1)
+                               $return = "000$num";
+                       if (strlen($num) == 0)
+                               $return = "0001";
+
+                       return strtoupper($return);
+               }
+
+
+               function read_location_data($location_code)
+               {
+                       $soadmin_location       = 
CreateObject($this->currentapp.'.soadmin_location');
+
+                       $location_types = 
$soadmin_location->select_location_type();
+                       unset($soadmin_location);
+
+                       return 
$this->socommon->read_location_data($location_code,$location_types);
+               }
+
+               function read_single_tenant($tenant_id)
+               {
+                       return $this->socommon->read_single_tenant($tenant_id);
+               }
+
+               function check_location($location_code='',$type_id='')
+               {
+                       return 
$this->socommon->check_location($location_code,$type_id);
+               }
+
+               function generate_sql($data)
+               {
+//_debug_array($data);
+
+                       $cols                           = 
(isset($data['cols'])?$data['cols']:'');
+                       $entity_table           = 
(isset($data['entity_table'])?$data['entity_table']:'');
+                       $cols_return            = 
(isset($data['cols_return'])?$data['cols_return']:'');
+                       $uicols                         = 
(isset($data['uicols'])?$data['uicols']:'');
+                       $joinmethod             = 
(isset($data['joinmethod'])?$data['joinmethod']:'');
+                       $paranthesis            = 
(isset($data['paranthesis'])?$data['paranthesis']:'');
+                       $lookup                         = 
(isset($data['lookup'])?$data['lookup']:'');
+                       $location_level         = 
(isset($data['location_level'])?$data['location_level']:'');
+                       $no_address     = 
(isset($data['no_address'])?$data['no_address']:'');
+
+                       $this->join = $this->socommon->join;
+
+                       $joinmethod .= " $this->join  fm_location1 ON 
($entity_table.loc1 = fm_location1.loc1))";
+                       $paranthesis .='(';
+                       $joinmethod .= " $this->join  fm_part_of_town ON 
(fm_location1.part_of_town_id = fm_part_of_town.part_of_town_id))";
+                       $paranthesis .='(';
+                       $joinmethod .= " $this->join  fm_owner ON 
(fm_location1.owner_id = fm_owner.id))";
+                       $paranthesis .='(';
+
+                       $soadmin_location       = 
CreateObject($this->currentapp.'.soadmin_location');
+                       $location_types = 
$soadmin_location->select_location_type();
+                       $config = $soadmin_location->read_config('');
+
+                       if($location_level)
+                       {
+                               $type_id=$location_level;
+                       }
+                       else
+                       {
+                               $type_id        = count($location_types);
+                       }
+                       $this->type_id  = $type_id;
+
+                       for ($i=0; $i<$type_id; $i++)
+                       {
+
+                               $uicols['input_type'][]         = 'text';
+                               $uicols['name'][]                       = 'loc' 
. $location_types[$i]['id'];
+                               $uicols['descr'][]                      = 
$location_types[$i]['name'];
+                               $uicols['statustext'][]         = 
$location_types[$i]['descr'];
+                       }
+/*
+                       $fm_location_cols = 
$soadmin_location->read_attrib(array('type_id'=>$type_id,'lookup_type'=>$type_id));
+                       $location_cols_count    = count($fm_location_cols);
+
+                       for ($i=0;$i<$location_cols_count;$i++)
+                       {
+                               if($fm_location_cols[$i]['list']==1)
+                               {
+                                       $cols_extra[]                           
= $fm_location_cols[$i]['column_name']; // only for lookup
+                                       $cols_return[]                          
= $fm_location_cols[$i]['column_name'];
+                                       $uicols['input_type'][]         = 
'text';
+                                       $uicols['name'][]                       
= $fm_location_cols[$i]['column_name'];
+                                       $uicols['descr'][]                      
= $fm_location_cols[$i]['input_text'];
+                                       $uicols['statustext'][]         = 
$fm_location_cols[$i]['statustext'];
+                               }
+                       }
+
+*/
+                       unset($soadmin_location);
+
+                       for ($i=0; $i< $this->type_id; $i++)
+                       {
+                               $cols_return[] = 'loc' . 
$location_types[$i]['id'];
+                       }
+
+                       if($lookup)
+                       {
+                               $cols_return[]                          = 
'loc1_name';
+                               $cols_extra[]                           = 
'loc1_name';
+                               $uicols['input_type'][]         = 'text';
+                               $uicols['name'][]                       = 
'loc1_name';
+                               $uicols['descr'][]                      = 
lang('Property Name');
+                               $uicols['statustext'][]         = 
lang('Property Name');
+
+                               for ($i=2;$i<($type_id+1);$i++)
+                               {
+                                       $cols_return_lookup[]           = 'loc' 
. $i . '_name';
+                                       $uicols['input_type'][]         = 
'hidden';
+                                       $uicols['name'][]                       
= 'loc' . $i . '_name';
+                                       $uicols['descr'][]                      
= '';
+                                       $uicols['statustext'][]         = '';
+                               }
+                       }
+
+                       if(!$no_address)
+                       {
+                               $cols.= ",$entity_table.address";
+                               $cols_return[]                          = 
'address';
+                               $uicols['input_type'][]         = 'text';
+                               $uicols['name'][]                       = 
'address';
+                               $uicols['descr'][]                      = 
lang('address');
+                               $uicols['statustext'][]         = 
lang('address');
+                       }
+
+
+                       $config_count   = count($config);
+                       for ($i=0;$i<$config_count;$i++)
+                       {
+
+                               if (($config[$i]['location_type'] <= $type_id) 
&& ($config[$i]['query_value'] ==1))
+                               {
+
+                                       
if($config[$i]['column_name']=='street_id')
+                                       {
+
+                                               $cols_return[]                  
        = 'street_name';
+                                               $uicols['input_type'][]         
= 'hidden';
+                                               $uicols['name'][]               
        = 'street_name';
+                                               $uicols['descr'][]              
        = lang('street name');
+                                               $uicols['statustext'][]         
= lang('street name');
+
+                                               $cols_return[]                  
        = 'street_number';
+                                               $uicols['input_type'][]         
= 'hidden';
+                                               $uicols['name'][]               
        = 'street_number';
+                                               $uicols['descr'][]              
        = lang('street number');
+                                               $uicols['statustext'][]         
= lang('street number');
+
+                                               $cols_return[]                  
        = $config[$i]['column_name'];
+                                               $uicols['input_type'][]         
= 'hidden';
+                                               $uicols['name'][]               
        = $config[$i]['column_name'];
+                                               $uicols['descr'][]              
        = lang($config[$i]['input_text']);
+                                               $uicols['statustext'][]         
= lang($config[$i]['input_text']);
+                                               if($lookup)
+                                               {
+                                                       $cols_extra[]           
                = 'street_name';
+                                                       $cols_extra[]           
                = 'street_number';
+                                                       $cols_extra[]           
                = $config[$i]['column_name'];
+                                               }
+
+                                       }
+                                       else
+                                       {
+                                               $cols_return[]                  
        = $config[$i]['column_name'];
+                                               $uicols['input_type'][]         
= 'text';
+                                               $uicols['name'][]               
        = $config[$i]['column_name'];
+                                               $uicols['descr'][]              
        = $config[$i]['input_text'];
+                                               $uicols['statustext'][]         
= $config[$i]['input_text'];
+
+                                               if($lookup)
+                                               {
+                                                       $cols_extra[]           
                = $config[$i]['column_name'];
+                                               }
+                                       }
+                               }
+                       }
+
+                       $this->uicols           = $uicols;
+                       $this->cols_return      = $cols_return;
+                       $this->cols_extra       = $cols_extra;
+                       $this->cols_return_lookup       = $cols_return_lookup;
+
+                       $from .= " FROM $paranthesis $entity_table ";
+
+                       $sql = "SELECT $cols $from $joinmethod";
+
+                       return $sql;
+
+               }
+
+               function select_part_of_town($format='',$selected='')
+               {
+                       switch($format)
+                       {
+                               case 'select':
+                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('select_part_of_town'));
+                                       break;
+                               case 'filter':
+                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('filter_part_of_town'));
+                                       break;
+                       }
+
+                       $parts= $this->socommon->select_part_of_town();
+
+                       while (is_array($parts) && list(,$part) = each($parts))
+                       {
+                               $sel_part = '';
+                               if ($part['id']==$selected)
+                               {
+                                       $sel_part = 'selected';
+                               }
+
+                               $part_of_town_list[] = array
+                               (
+                                       'id'    => $part['id'],
+                                       'name'          => $part['name'],
+                                       'selected'      => $sel_part
+                               );
+                       }
+
+                       for ($i=0;$i<count($part_of_town_list);$i++)
+                       {
+                               if ($part_of_town_list[$i]['selected'] != 
'selected')
+                               {
+                                       
unset($part_of_town_list[$i]['selected']);
+                               }
+                       }
+
+                       return $part_of_town_list;
+               }
+
+               function select_category_property_list($format='',$selected='')
+               {
+                       switch($format)
+                       {
+                               case 'select':
+                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('cat_select'));
+                                       break;
+                               case 'filter':
+                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('cat_filter'));
+                                       break;
+                       }
+
+                       $categories= 
$this->socommon->select_category_property_list();
+
+                       while (is_array($categories) && list(,$category) = 
each($categories))
+                       {
+                               $sel_category = '';
+                               if ($category['id']==$selected)
+                               {
+                                       $sel_category = 'selected';
+                               }
+
+                               $category_list[] = array
+                               (
+                                       'cat_id'        => $category['id'],
+                                       'name'          => $category['name'],
+                                       'selected'      => $sel_category
+                               );
+                       }
+
+                       for ($i=0;$i<count($category_list);$i++)
+                       {
+                               if ($category_list[$i]['selected'] != 
'selected')
+                               {
+                                       unset($category_list[$i]['selected']);
+                               }
+                       }
+
+                       return $category_list;
+               }
+
+               function select_district_list($format='',$selected='')
+               {
+                       switch($format)
+                       {
+                               case 'select':
+                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('select_district'));
+                                       break;
+                               case 'filter':
+                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('filter_district'));
+                                       break;
+                       }
+
+                       $districts= $this->socommon->select_district_list();
+
+                       while (is_array($districts) && list(,$district) = 
each($districts))
+                       {
+                               $sel_district = '';
+                               if ($district['id']==$selected)
+                               {
+                                       $sel_district = 'selected';
+                               }
+
+                               $district_list[] = array
+                               (
+                                       'id'    => $district['id'],
+                                       'name'          => $district['name'],
+                                       'selected'      => $sel_district
+                               );
+                       }
+
+                       for ($i=0;$i<count($district_list);$i++)
+                       {
+                               if ($district_list[$i]['selected'] != 
'selected')
+                               {
+                                       unset($district_list[$i]['selected']);
+                               }
+                       }
+
+                       return $district_list;
+               }
+
+
+               function validate_db_insert($values)
+               {
+                       foreach($values as $value)
+                       {
+                               if($value || $value === 0)
+                               {
+                                       $insert_value[] = "'".$value."'";
+                               }
+                               else
+                               {
+                                       $insert_value[] = 'NULL';
+                               }
+                       }
+
+                       $values = implode(",", $insert_value);
+                       return $values;
+               }
+
+               function validate_db_update($value_set)
+               {
+                       while (is_array($value_set) && list($field,$value) = 
each($value_set))
+                       {
+                               if($value || $value === 0)
+                               {
+                                       $value_entry[]= "$field='$value'";
+                               }
+                               else
+                               {
+                                       $value_entry[]= "$field=NULL";
+                               }
+                       }
+
+                       $value_set      = implode(",", $value_entry);
+                       return $value_set;
+               }
+
+               function fm_cache($name='',$value='')
+               {
+                       return $this->socommon->fm_cache($name,$value);
+               }
+
+               function next_id($table,$key='')
+               {
+                       return $this->socommon->next_id($table,$key);
+               }
+
+               function select_datatype($selected='')
+               {
+                       $datatypes[0]['id']= 'V';
+                       $datatypes[0]['name']= lang('varchar');
+                       $datatypes[1]['id']= 'C';
+                       $datatypes[1]['name']= lang('Character');
+                       $datatypes[2]['id']= 'I';
+                       $datatypes[2]['name']= lang('Integer');
+                       $datatypes[3]['id']= 'N';
+                       $datatypes[3]['name']= lang('Decimal');
+                       $datatypes[4]['id']= 'D';
+                       $datatypes[4]['name']= lang('Date');
+                       $datatypes[5]['id']= 'T';
+                       $datatypes[5]['name']= lang('Memo');
+                       $datatypes[6]['id']= 'R';
+                       $datatypes[6]['name']= lang('Multiple radio');
+                       $datatypes[7]['id']= 'CH';
+                       $datatypes[7]['name']= lang('Multiple Checkbox');
+                       $datatypes[8]['id']= 'LB';
+                       $datatypes[8]['name']= lang('ListBox');
+                       $datatypes[9]['id']= 'AB';
+                       $datatypes[9]['name']= lang('Contact');
+                       $datatypes[10]['id']= 'VENDOR';
+                       $datatypes[10]['name']= lang('Vendor');
+                       $datatypes[11]['id']= 'email';
+                       $datatypes[11]['name']= lang('Email');
+
+                       return $this->select_list($selected,$datatypes);
+
+               }
+
+               function select_nullable($selected='')
+               {
+                       $nullable[0]['id']= 'True';
+                       $nullable[0]['name']= lang('True');
+                       $nullable[1]['id']= 'False';
+                       $nullable[1]['name']= lang('False');
+
+                       return $this->select_list($selected,$nullable);
+               }
+
+
+               function excel($list,$name,$descr,$input_type='')
+               {
+                       $GLOBALS['phpgw_info']['flags'][noheader] = True;
+                       $GLOBALS['phpgw_info']['flags'][nofooter] = True;
+                       $GLOBALS['phpgw_info']['flags']['xslt_app'] = False;
+
+                       $filename= 
$GLOBALS['phpgw_info']['user']['account_lid'].'.xls';
+
+                       $workbook       = 
CreateObject($this->currentapp.'.excel',"-");
+                       $browser = CreateObject('phpgwapi.browser');
+                       
$browser->content_header($filename,'application/vnd.ms-excel');
+
+                       $count_uicols_name=count($name);
+
+                       $worksheet1 =& $workbook->add_worksheet('First One');
+
+                       $j=0;
+                       if (isset($list) AND is_array($list))
+                       {
+                               foreach($list as $entry)
+                               {
+                                       $m=0;
+                                       for ($k=0;$k<$count_uicols_name;$k++)
+                                       {
+                                               if($input_type[$k]!='hidden')
+                                               {
+                                                       $content[$j][$m]        
= str_replace("\r\n"," ",$entry[$name[$k]]);
+                                                       
$worksheet1->write_string(0, $m, $descr[$k]);
+                                                       $m++;
+                                               }
+                                       }
+                                       $j++;
+                               }
+
+                               foreach($content as $row)
+                               {
+                                       $line++;
+                                       for ($i=0; $i<count($row); $i++)
+                                       {
+                                               
$worksheet1->write($line,$i,$row[$i]);
+                                       }
+                               }
+                       }
+                       $workbook->close();
+
+               }
+
+               function increment_id($name)
+               {
+                       return $this->socommon->increment_id($name);
+               }
+
+               function get_origin_link($type)
+               {
+                       if($type=='tts'):
+                       {
+                               $link = '.uitts.view';
+                       }
+                       elseif($type=='request'):
+                       {
+                               $link = '.uirequest.view';
+                       }
+                       elseif($type=='project'):
+                       {
+                               $link = '.uiproject.view';
+                       }
+                       elseif(substr($type,0,6)=='entity'):
+                       {
+
+                               $type           = explode("_",$type);
+                               $entity_id      = $type[1];
+                               $cat_id         = $type[2];
+                               $link = 
".uientity.view&entity_id=$entity_id&cat_id=$cat_id";
+                       }
+                       endif;
+
+                       return $link;
+               }
+
+               function select_wo_hours_category_list($selected='')
+               {
+                       $category_list= 
$this->socommon->select_wo_hours_category_list();
+                       if($selected)
+                       {
+                               $category_list = 
$this->select_list($selected,$category_list);
+                       }
+
+                       return $category_list;
+               }
+
+               function new_db()
+               {                       return $this->socommon->new_db();
+               }
+
+       }
+?>
Index: property/inc/class.bocustom.inc.php
diff -u property/inc/class.bocustom.inc.php:1.6 
property/inc/class.bocustom.inc.php:1.7
--- property/inc/class.bocustom.inc.php:1.6     Fri Jan 27 14:05:43 2006
+++ property/inc/class.bocustom.inc.php Fri Feb  3 12:05:49 2006
@@ -1,195 +1,195 @@
-<?php
-       /**
-       * phpGroupWare - property: a Facilities Management System.
-       *
-       * @author Sigurd Nes <address@hidden>
-       * @copyright Copyright (C) 2003-2005 Free Software Foundation, Inc. 
http://www.fsf.org/
-       * @license http://www.gnu.org/licenses/gpl.html GNU General Public 
License
-       * @internal Development of this application was funded by 
http://www.bergen.kommune.no/bbb_/ekstern/
-       * @package property
-       * @subpackage custom
-       * @version $Id: class.bocustom.inc.php,v 1.6 2006/01/27 14:05:43 
sigurdne Exp $
-       */
-
-       /**
-        * Description
-        * @package property
-        */
-
-       class bocustom
-       {
-               var $start;
-               var $query;
-               var $filter;
-               var $sort;
-               var $order;
-               var $cat_id;
-
-               var $public_functions = array
-               (
-                       'read'                          => True,
-                       'read_single'           => True,
-                       'save'                          => True,
-                       'delete'                        => True,
-                       'check_perms'           => True
-               );
-
-               function bocustom($session=False)
-               {
-                       $this->currentapp               = 
$GLOBALS['phpgw_info']['flags']['currentapp'];
-                       $this->so = CreateObject($this->currentapp.'.socustom');
-
-                       if ($session)
-                       {
-                               $this->read_sessiondata();
-                               $this->use_session = True;
-                       }
-
-                       $start  = get_var('start',array('POST','GET'));
-                       $query  = get_var('query',array('POST','GET'));
-                       $sort   = get_var('sort',array('POST','GET'));
-                       $order  = get_var('order',array('POST','GET'));
-                       $filter = get_var('filter',array('POST','GET'));
-                       $cat_id = get_var('cat_id',array('POST','GET'));
-                       $allrows                        = 
get_var('allrows',array('POST','GET'));
-
-                       if ($start)
-                       {
-                               $this->start=$start;
-                       }
-                       else
-                       {
-                               $this->start=0;
-                       }
-
-                       if(isset($query))
-                       {
-                               $this->query = $query;
-                       }
-                       if(!empty($filter))
-                       {
-                               $this->filter = $filter;
-                       }
-                       if(isset($sort))
-                       {
-                               $this->sort = $sort;
-                       }
-                       if(isset($order))
-                       {
-                               $this->order = $order;
-                       }
-                       if(isset($cat_id) && !empty($cat_id))
-                       {
-                               $this->cat_id = $cat_id;
-                       }
-                       else
-                       {
-                               unset($this->cat_id);
-                       }
-                       if(isset($allrows))
-                       {
-                               $this->allrows = $allrows;
-                       }
-               }
-
-
-               function save_sessiondata($data)
-               {
-                       if ($this->use_session)
-                       {
-                               
$GLOBALS['phpgw']->session->appsession('session_data','custom',$data);
-                       }
-               }
-
-               function read_sessiondata()
-               {
-                       $data = 
$GLOBALS['phpgw']->session->appsession('session_data','custom');
-
-                       $this->start    = $data['start'];
-                       $this->query    = $data['query'];
-                       $this->filter   = $data['filter'];
-                       $this->sort             = $data['sort'];
-                       $this->order    = $data['order'];
-                       $this->cat_id   = $data['cat_id'];
-               }
-
-               function check_perms($has, $needed)
-               {
-                       return (!!($has & $needed) == True);
-               }
-
-
-               function read()
-               {
-                       $custom = $this->so->read(array('start' => 
$this->start,'query' => $this->query,'sort' => $this->sort,'order' => 
$this->order,
-                                                                               
        'filter' => $this->filter,'cat_id' => 
$this->cat_id,'allrows'=>$this->allrows));
-                       $this->total_records = $this->so->total_records;
-
-                       for ($i=0; $i<count($custom); $i++)
-                       {
-                               $custom[$i]['entry_date']  = 
$GLOBALS['phpgw']->common->show_date($custom[$i]['entry_date'],$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']);
-                       }
-                       return $custom;
-               }
-
-               function read_single($custom_id)
-               {
-                       return $this->so->read_single($custom_id);
-               }
-
-               function read_custom_name($custom_id)
-               {
-                       return $this->so->read_custom_name($custom_id);
-               }
-
-               function save($custom)
-               {
-
-                       if ($custom['custom_id'])
-                       {
-                               if ($custom['custom_id'] != 0)
-                               {
-                                       $custom_id = $custom['custom_id'];
-                                       $receipt=$this->so->edit($custom);
-                               }
-                       }
-                       else
-                       {
-                               $receipt = $this->so->add($custom);
-                       }
-                       return $receipt;
-               }
-
-               function delete($params)
-               {
-                       if (is_array($params))
-                       {
-                               $this->so->delete($params[0]);
-                       }
-                       else
-                       {
-                               $this->so->delete($params);
-                       }
-               }
-
-               function resort($data)
-               {
-                       $this->so->resort($data);
-               }
-
-
-               function read_custom($custom_id,$allrows='')
-               {
-                       if($allrows)
-                       {
-                               $this->allrows=$allrows;
-                       }
-                       $custom = $this->so->read_custom(array('start' => 
$this->start,'query' => $this->query,'sort' => $this->sort,'order' => 
$this->order,
-                                                                               
        'filter' => $this->filter,'custom_id' => 
$custom_id,'allrows'=>$this->allrows));
-                       $this->uicols = $this->so->uicols;
-                       $this->total_records = $this->so->total_records;
-                       return $custom;
-               }
-
-       }
-?>
+<?php
+       /**
+       * phpGroupWare - property: a Facilities Management System.
+       *
+       * @author Sigurd Nes <address@hidden>
+       * @copyright Copyright (C) 2003-2005 Free Software Foundation, Inc. 
http://www.fsf.org/
+       * @license http://www.gnu.org/licenses/gpl.html GNU General Public 
License
+       * @internal Development of this application was funded by 
http://www.bergen.kommune.no/bbb_/ekstern/
+       * @package property
+       * @subpackage custom
+       * @version $Id: class.bocustom.inc.php,v 1.7 2006/02/03 12:05:49 
sigurdne Exp $
+       */
+
+       /**
+        * Description
+        * @package property
+        */
+
+       class bocustom
+       {
+               var $start;
+               var $query;
+               var $filter;
+               var $sort;
+               var $order;
+               var $cat_id;
+
+               var $public_functions = array
+               (
+                       'read'                          => True,
+                       'read_single'           => True,
+                       'save'                          => True,
+                       'delete'                        => True,
+                       'check_perms'           => True
+               );
+
+               function bocustom($session=False)
+               {
+                       $this->currentapp               = 
$GLOBALS['phpgw_info']['flags']['currentapp'];
+                       $this->so = CreateObject($this->currentapp.'.socustom');
+
+                       if ($session)
+                       {
+                               $this->read_sessiondata();
+                               $this->use_session = True;
+                       }
+
+                       $start  = get_var('start',array('POST','GET'));
+                       $query  = get_var('query',array('POST','GET'));
+                       $sort   = get_var('sort',array('POST','GET'));
+                       $order  = get_var('order',array('POST','GET'));
+                       $filter = get_var('filter',array('POST','GET'));
+                       $cat_id = get_var('cat_id',array('POST','GET'));
+                       $allrows                        = 
get_var('allrows',array('POST','GET'));
+
+                       if ($start)
+                       {
+                               $this->start=$start;
+                       }
+                       else
+                       {
+                               $this->start=0;
+                       }
+
+                       if(isset($query))
+                       {
+                               $this->query = $query;
+                       }
+                       if(!empty($filter))
+                       {
+                               $this->filter = $filter;
+                       }
+                       if(isset($sort))
+                       {
+                               $this->sort = $sort;
+                       }
+                       if(isset($order))
+                       {
+                               $this->order = $order;
+                       }
+                       if(isset($cat_id) && !empty($cat_id))
+                       {
+                               $this->cat_id = $cat_id;
+                       }
+                       else
+                       {
+                               unset($this->cat_id);
+                       }
+                       if(isset($allrows))
+                       {
+                               $this->allrows = $allrows;
+                       }
+               }
+
+
+               function save_sessiondata($data)
+               {
+                       if ($this->use_session)
+                       {
+                               
$GLOBALS['phpgw']->session->appsession('session_data','custom',$data);
+                       }
+               }
+
+               function read_sessiondata()
+               {
+                       $data = 
$GLOBALS['phpgw']->session->appsession('session_data','custom');
+
+                       $this->start    = $data['start'];
+                       $this->query    = $data['query'];
+                       $this->filter   = $data['filter'];
+                       $this->sort             = $data['sort'];
+                       $this->order    = $data['order'];
+                       $this->cat_id   = $data['cat_id'];
+               }
+
+               function check_perms($has, $needed)
+               {
+                       return (!!($has & $needed) == True);
+               }
+
+
+               function read()
+               {
+                       $custom = $this->so->read(array('start' => 
$this->start,'query' => $this->query,'sort' => $this->sort,'order' => 
$this->order,
+                                                                               
        'filter' => $this->filter,'cat_id' => 
$this->cat_id,'allrows'=>$this->allrows));
+                       $this->total_records = $this->so->total_records;
+
+                       for ($i=0; $i<count($custom); $i++)
+                       {
+                               $custom[$i]['entry_date']  = 
$GLOBALS['phpgw']->common->show_date($custom[$i]['entry_date'],$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']);
+                       }
+                       return $custom;
+               }
+
+               function read_single($custom_id)
+               {
+                       return $this->so->read_single($custom_id);
+               }
+
+               function read_custom_name($custom_id)
+               {
+                       return $this->so->read_custom_name($custom_id);
+               }
+
+               function save($custom)
+               {
+
+                       if ($custom['custom_id'])
+                       {
+                               if ($custom['custom_id'] != 0)
+                               {
+                                       $custom_id = $custom['custom_id'];
+                                       $receipt=$this->so->edit($custom);
+                               }
+                       }
+                       else
+                       {
+                               $receipt = $this->so->add($custom);
+                       }
+                       return $receipt;
+               }
+
+               function delete($params)
+               {
+                       if (is_array($params))
+                       {
+                               $this->so->delete($params[0]);
+                       }
+                       else
+                       {
+                               $this->so->delete($params);
+                       }
+               }
+
+               function resort($data)
+               {
+                       $this->so->resort($data);
+               }
+
+
+               function read_custom($custom_id,$allrows='')
+               {
+                       if($allrows)
+                       {
+                               $this->allrows=$allrows;
+                       }
+                       $custom = $this->so->read_custom(array('start' => 
$this->start,'query' => $this->query,'sort' => $this->sort,'order' => 
$this->order,
+                                                                               
        'filter' => $this->filter,'custom_id' => 
$custom_id,'allrows'=>$this->allrows));
+                       $this->uicols = $this->so->uicols;
+                       $this->total_records = $this->so->total_records;
+                       return $custom;
+               }
+
+       }
+?>
Index: property/inc/class.bodocument.inc.php
diff -u property/inc/class.bodocument.inc.php:1.6 
property/inc/class.bodocument.inc.php:1.7
--- property/inc/class.bodocument.inc.php:1.6   Fri Jan 27 14:05:43 2006
+++ property/inc/class.bodocument.inc.php       Fri Feb  3 12:05:49 2006
@@ -1,640 +1,640 @@
-<?php
-       /**
-       * phpGroupWare - property: a Facilities Management System.
-       *
-       * @author Sigurd Nes <address@hidden>
-       * @copyright Copyright (C) 2003-2005 Free Software Foundation, Inc. 
http://www.fsf.org/
-       * @license http://www.gnu.org/licenses/gpl.html GNU General Public 
License
-       * @internal Development of this application was funded by 
http://www.bergen.kommune.no/bbb_/ekstern/
-       * @package property
-       * @subpackage document
-       * @version $Id: class.bodocument.inc.php,v 1.6 2006/01/27 14:05:43 
sigurdne Exp $
-       */
-
-       /**
-        * Description
-        * @package property
-        */
-
-       class bodocument
-       {
-               var $start;
-               var $query;
-               var $filter;
-               var $sort;
-               var $order;
-               var $cat_id;
-
-               var $public_functions = array
-               (
-                       'read'                          => True,
-                       'read_single'           => True,
-                       'save'                          => True,
-                       'delete'                        => True,
-                       'check_perms'           => True
-               );
-
-               function bodocument($session=False)
-               {
-                       $this->currentapp       = 
$GLOBALS['phpgw_info']['flags']['currentapp'];
-                       $this->so                       = 
CreateObject($this->currentapp.'.sodocument');
-                       $this->bocommon         = 
CreateObject($this->currentapp.'.bocommon');
-                       $this->solocation       = 
CreateObject($this->currentapp.'.solocation');
-                       $this->historylog       = 
CreateObject($this->currentapp.'.historylog','document');
-                       $this->contacts         = 
CreateObject($this->currentapp.'.soactor');
-                       $this->contacts->role='vendor';
-
-                       $this->vfs                      = 
CreateObject('phpgwapi.vfs');
-                       $this->rootdir          = $this->vfs->basedir;
-                       $this->fakebase         = $this->vfs->fakebase;
-
-                       if ($session)
-                       {
-                               $this->read_sessiondata();
-                               $this->use_session = True;
-                       }
-
-                       $start  = get_var('start',array('POST','GET'));
-                       $query  = get_var('query',array('POST','GET'));
-                       $sort   = get_var('sort',array('POST','GET'));
-                       $order  = get_var('order',array('POST','GET'));
-                       $filter = get_var('filter',array('POST','GET'));
-                       $cat_id = get_var('cat_id',array('POST','GET'));
-                       $status_id      = 
get_var('status_id',array('POST','GET'));
-                       $entity_id      = 
get_var('entity_id',array('POST','GET'));
-                       $doc_type       = 
get_var('doc_type',array('POST','GET'));
-                       $query_location = 
get_var('query_location',array('POST','GET'));
-
-
-                       if ($start)
-                       {
-                               $this->start=$start;
-                       }
-                       else
-                       {
-                               $this->start=0;
-                       }
-
-                       if(isset($query))
-                       {
-                               $this->query = $query;
-                       }
-                       if(isset($filter))
-                       {
-                               $this->filter = $filter;
-                       }
-                       if(isset($sort))
-                       {
-                               $this->sort = $sort;
-                       }
-                       if(isset($order))
-                       {
-                               $this->order = $order;
-                       }
-                       if(isset($cat_id))
-                       {
-                               $this->cat_id = $cat_id;
-                       }
-                       if(isset($status_id))
-                       {
-                               $this->status_id = $status_id;
-                       }
-                       if(isset($entity_id))
-                       {
-                               $this->entity_id = $entity_id;
-                       }
-                       if(isset($doc_type))
-                       {
-                               $this->doc_type = $doc_type;
-                       }
-                       if(isset($query_location))
-                       {
-                               $this->query_location = $query_location;
-                       }
-
-               }
-
-               function save_sessiondata($data)
-               {
-                       if ($this->use_session)
-                       {
-                               
$GLOBALS['phpgw']->session->appsession('session_data','document',$data);
-                       }
-               }
-
-               function read_sessiondata()
-               {
-                       $data = 
$GLOBALS['phpgw']->session->appsession('session_data','document');
-
-                       //_debug_array($data);
-
-                       $this->start    = $data['start'];
-                       $this->query    = $data['query'];
-                       $this->filter   = $data['filter'];
-                       $this->sort             = $data['sort'];
-                       $this->order    = $data['order'];
-                       $this->cat_id   = $data['cat_id'];
-                       $this->entity_id        = $data['entity_id'];
-                       $this->doc_type = $data['doc_type'];
-                       $this->query_location   = $data['query_location'];
-               }
-
-               function select_status_list($format='',$selected='')
-               {
-                       switch($format)
-                       {
-                               case 'select':
-                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('status_select'));
-                                       break;
-                               case 'filter':
-                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('status_filter'));
-                                       break;
-                       }
-
-                       $status_entries= $this->so->select_status_list();
-
-                       while (is_array($status_entries) && list(,$status) = 
each($status_entries))
-                       {
-                               $sel_status = '';
-                               if ($status['id']==$selected)
-                               {
-                                       $sel_status = 'selected';
-                               }
-
-                               $status_list[] = array
-                               (
-                                       'id'            => $status['id'],
-                                       'name'          => $status['name'],
-                                       'selected'      => $sel_status
-                               );
-                       }
-
-                       for ($i=0;$i<count($status_list);$i++)
-                       {
-                               if ($status_list[$i]['selected'] != 'selected')
-                               {
-                                       unset($status_list[$i]['selected']);
-                               }
-                       }
-
-                       return $status_list;
-               }
-
-               function select_branch_list($selected='')
-               {
-
-                       $branch_entries= $this->so->select_branch_list();
-
-                       while (is_array($branch_entries) && list(,$branch) = 
each($branch_entries))
-                       {
-                               $sel_branch = '';
-                               if ($branch['id']==$selected)
-                               {
-                                       $sel_branch = 'selected';
-                               }
-
-                               $branch_list[] = array
-                               (
-                                       'id'            => $branch['id'],
-                                       'name'          => $branch['name'],
-                                       'selected'      => $sel_branch
-                               );
-                       }
-
-                       for ($i=0;$i<count($branch_list);$i++)
-                       {
-                               if ($branch_list[$i]['selected'] != 'selected')
-                               {
-                                       unset($branch_list[$i]['selected']);
-                               }
-                       }
-
-                       return $branch_list;
-               }
-
-
-               function select_doc_type_list($format='',$selected='')
-               {
-                       switch($format)
-                       {
-                               case 'select':
-                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('cat_select'));
-                                       break;
-                               case 'filter':
-                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('cat_filter'));
-                                       break;
-                       }
-
-                       $categories= $this->so->select_doc_type_list();
-
-                       while (is_array($categories) && list(,$category) = 
each($categories))
-                       {
-                               $sel_category = '';
-                               if ($category['id']==$selected)
-                               {
-                                       $sel_category = 'selected';
-                               }
-
-                               $category_list[] = array
-                               (
-                                       'cat_id'        => $category['id'],
-                                       'name'          => $category['name'],
-                                       'selected'      => $sel_category
-                               );
-                       }
-
-                       for ($i=0;$i<count($category_list);$i++)
-                       {
-                               if ($category_list[$i]['selected'] != 
'selected')
-                               {
-                                       unset($category_list[$i]['selected']);
-                               }
-                       }
-
-                       return $category_list;
-               }
-
-
-               function read()
-               {
-                       $document = $this->so->read(array('start' => 
$this->start,'query' => $this->query,'sort' => $this->sort,'order' => 
$this->order,
-                                                                               
        'filter' => $this->filter,'cat_id' => $this->cat_id,'entity_id' => 
$this->entity_id,'doc_type'=>$this->doc_type));
-                       $this->total_records = $this->so->total_records;
-
-                       $this->uicols   = $this->so->uicols;
-                       $cols_extra             = $this->so->cols_extra;
-
-                       $dateformat = 
$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
-                       for ($i=0; $i<count($document); $i++)
-                       {
-                               
$location_data=$this->solocation->read_single($document[$i]['location_code']);
-
-                               for ($j=0;$j<count($cols_extra);$j++)
-                               {
-                                       $document[$i][$cols_extra[$j]] = 
$location_data[$cols_extra[$j]];
-                               }
-                       }
-
-                       return $document;
-               }
-
-               function read_at_location($location_code='')
-               {
-                       $document = $this->so->read_at_location(array('start' 
=> $this->start,'query' => $this->query,'sort' => $this->sort,'order' => 
$this->order,
-                                                                               
        'filter' => $this->filter,'cat_id' => $this->cat_id,'entity_id' => 
$this->entity_id,
-                                                                               
        'location_code' => $location_code,'doc_type'=>$this->doc_type));
-                       $this->total_records = $this->so->total_records;
-
-                       $dateformat = 
$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
-
-                       for ($i=0; $i<count($document); $i++)
-                       {
-                               $document[$i]['user'] = 
$GLOBALS['phpgw']->accounts->id2name($document[$i]['user_id']);
-                               $document[$i]['document_date'] = 
$GLOBALS['phpgw']->common->show_date($document[$i]['start_date'],$dateformat);
-                               $document[$i]['entry_date'] = 
$GLOBALS['phpgw']->common->show_date($document[$i]['entry_date'],$dateformat);
-                       }
-
-                       return $document;
-               }
-
-               function read_single($document_id)
-               {
-                       $document                                               
= $this->so->read_single($document_id);
-                       $dateformat                                             
= $GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
-                       $document['document_date']              = 
$GLOBALS['phpgw']->common->show_date($document['document_date'],$dateformat);
-                       $vendor                                                 
= $this->contacts->read_single(array('actor_id'=>$document['vendor_id']));
-
-                       if(is_array($vendor))
-                       {
-                               foreach($vendor['attributes'] as $attribute)
-                               {
-                                       if($attribute['name']=='org_name')
-                                       {
-                                               
$document['vendor_name']=$attribute['value'];
-                                               break;
-                                       }
-                               }
-                       }
-
-                       if($document['location_code'])
-                       {
-                               $document['location_data'] 
=$this->solocation->read_single($document['location_code']);
-                       }
-
-                       if($document['p_num'])
-                       {
-                               $soadmin_entity = 
CreateObject($this->currentapp.'.soadmin_entity');
-                               $category = 
$soadmin_entity->read_single_category($document['p_entity_id'],$document['p_cat_id']);
-
-                               
$document['p'][$document['p_entity_id']]['p_num']=$document['p_num'];
-                               
$document['p'][$document['p_entity_id']]['p_entity_id']=$document['p_entity_id'];
-                               
$document['p'][$document['p_entity_id']]['p_cat_id']=$document['p_cat_id'];
-                               
$document['p'][$document['p_entity_id']]['p_cat_name'] = $category['name'];
-                       }
-
-                       return $document;
-               }
-
-               function read_location_data($location_code)
-               {
-                       $location_data=         
$this->solocation->read_single($location_code);
-
-                       return $location_data;
-               }
-
-               function select_category_list($format='',$selected='')
-               {
-/*                     switch($format)
-                       {
-                               case 'select':
-                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('cat_select'));
-                                       break;
-                               case 'filter':
-                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('cat_filter'));
-                                       break;
-                       }
-
-
-*/
-
-                       $soadmin_entity         = 
CreateObject($this->currentapp.'.soadmin_entity');
-                       $categories                     = 
$soadmin_entity->read_category(array('allrows'=>True,'entity_id'=>$this->entity_id));
-
-                       $category_list  = 
$this->bocommon->select_multi_list($selected,$categories);
-
-/*                     while (is_array($categories) && list(,$category) = 
each($categories))
-                       {
-                               $sel_category = '';
-                               if ($category['id']==$selected)
-                               {
-                                       $sel_category = 'selected';
-                               }
-
-                               $category_list[] = array
-                               (
-                                       'cat_id'        => $category['id'],
-                                       'name'          => $category['name'],
-                                       'selected'      => $sel_category
-                               );
-                       }
-
-                       for ($i=0;$i<count($category_list);$i++)
-                       {
-                               if ($category_list[$i]['selected'] != 
'selected')
-                               {
-                                       unset($category_list[$i]['selected']);
-                               }
-                       }
-*/
-                       return $category_list;
-               }
-
-
-
-               function read_record_history($id)
-               {
-                       $history_array = 
$this->historylog->return_array(array('O'),array(),'','',$id);
-                       $i=0;
-                       while (is_array($history_array) && list(,$value) = 
each($history_array))
-                       {
-
-                               $record_history[$i]['value_date']       = 
$GLOBALS['phpgw']->common->show_date($value['datetime']);
-                               $record_history[$i]['value_user']       = 
$value['owner'];
-
-                               switch ($value['status'])
-                               {
-                                       case 'R': $type = lang('Re-opened'); 
break;
-                                       case 'X': $type = lang('Closed');    
break;
-                                       case 'O': $type = lang('Opened');    
break;
-                                       case 'A': $type = lang('Re-assigned'); 
break;
-                                       case 'P': $type = lang('Priority 
changed'); break;
-                                       case 'CO': $type = lang('Initial 
Coordinator'); break;
-                                       case 'C': $type = lang('Coordinator 
changed'); break;
-                                       case 'TO': $type = lang('Initial 
Category'); break;
-                                       case 'T': $type = lang('Category 
changed'); break;
-                                       case 'SO': $type = lang('Initial 
Status'); break;
-                                       case 'S': $type = lang('Status 
changed'); break;
-                                       case 'FO': $type = lang('Initial 
File'); break;
-                                       case 'F': $type = lang('File changed'); 
break;
-                                       case 'LO': $type = lang('Initial 
Link'); break;
-                                       case 'L': $type = lang('Link changed'); 
break;
-                                       default: break;
-                               }
-
-                               
if($value['new_value']=='O'){$value['new_value']=lang('Opened');}
-                               
if($value['new_value']=='X'){$value['new_value']=lang('Closed');}
-
-
-                               $record_history[$i]['value_action']     = 
$type?$type:'';
-                               unset($type);
-
-                               if ($value['status'] == 'A')
-                               {
-                                       if (! $value['new_value'])
-                                       {
-                                               
$record_history[$i]['value_new_value']  = lang('None');
-                                       }
-                                       else
-                                       {
-                                               
$record_history[$i]['value_new_value']  = 
$GLOBALS['phpgw']->accounts->id2name($value['new_value']);
-                                       }
-                               }
-                               else if ($value['status'] == 'C' || 
$value['status'] == 'CO')
-                               {
-                                       $record_history[$i]['value_new_value']  
= $GLOBALS['phpgw']->accounts->id2name($value['new_value']);
-                               }
-                               else if ($value['status'] == 'T' || 
$value['status'] == 'TO')
-                               {
-                                       $record_history[$i]['value_new_value']  
= $this->so->read_single_category($value['new_value']);
-                               }
-                               else if ($value['status'] != 'O' && 
$value['new_value'])
-                               {
-                                       $record_history[$i]['value_new_value']  
= $value['new_value'];
-                               }
-                               else
-                               {
-                                       $record_history[$i]['value_new_value']  
= '';
-                               }
-
-                               $i++;
-                       }
-
-                       return $record_history;
-               }
-
-
-               function create_home_dir()
-               {
-                       if(!$this->vfs->file_exists(array(
-                                       'string' => $this->fakebase. SEP . 
'document',
-                                       'relatives' => Array(RELATIVE_NONE)
-                               )))
-                       {
-                               $this->vfs->override_acl = 1;
-
-                               if(!$this->vfs->mkdir (array(
-                                    'string' => $this->fakebase. SEP . 
'document',
-                                    'relatives' => array(
-                                         RELATIVE_NONE
-                                    )
-                               )))
-                               {
-                                       
$receipt['error'][]=array('msg'=>lang('failed to create directory') . ' :'. 
$this->fakebase. SEP . 'document');
-                               }
-                               else
-                               {
-                                       
$receipt['message'][]=array('msg'=>lang('directory created') . ' :'. 
$this->fakebase. SEP . 'document');
-                               }
-                               $this->vfs->override_acl = 0;
-                       }
-                       return $receipt;
-               }
-
-
-               function create_document_dir($data,$receipt)
-               {
-                       if(is_array($data))
-                       {
-                               $loc1                   = 
(isset($data['loc1'])?$data['loc1']:'');
-                               $entity_name    = 
(isset($data['entity_name'])?$data['entity_name']:'');
-                               $category_name  = 
(isset($data['category_name'])?$data['category_name']:'');
-                               $p_num = 
(isset($data['p_num'])?$data['p_num']:'');
-                       }
-
-                       $this->vfs->override_acl = 1;
-//_debug_array($data);
-                       if(!$this->vfs->file_exists(array(
-                                       'string' => $this->fakebase. SEP . 
'document' .  SEP . $loc1,
-                                       'relatives' => Array(RELATIVE_NONE)
-                               )))
-                       {
-                               if(!$this->vfs->mkdir (array(
-                                    'string' => $this->fakebase. SEP . 
'document' .  SEP . $loc1,
-                                    'relatives' => array(
-                                         RELATIVE_NONE
-                                    )
-                               )))
-                               {
-                                       
$receipt['error'][]=array('msg'=>lang('failed to create directory') . ' :'. 
$this->fakebase. SEP . 'document' .  SEP . $loc1);
-                               }
-                               else
-                               {
-                                       
$receipt['message'][]=array('msg'=>lang('directory created') . ' :'. 
$this->fakebase. SEP . 'document' .  SEP . $loc1);
-                               }
-                               $this->vfs->override_acl = 0;
-                       }
-
-                       if($entity_name)
-                       {
-                               if(!$this->vfs->file_exists(array(
-                                               'string' => $this->fakebase. 
SEP . 'document' .  SEP . $loc1 .  SEP . $entity_name,
-                                               'relatives' => 
Array(RELATIVE_NONE)
-                                       )))
-                               {
-
-                                       if(!$this->vfs->mkdir (array(
-                                                'string' => $this->fakebase. 
SEP . 'document' .  SEP . $loc1 .  SEP . $entity_name,
-                                            'relatives' => array(
-                                                 RELATIVE_NONE
-                                            )
-                                       )))
-                                       {
-                                               
$receipt['error'][]=array('msg'=>lang('failed to create directory') . ' :'. 
$this->fakebase. SEP . 'document'  .  SEP . $loc1 .  SEP . $entity_name);
-                                       }
-                                       else
-                                       {
-                                               
$receipt['message'][]=array('msg'=>lang('directory created') . ' :'. 
$this->fakebase. SEP . 'document'  .  SEP . $loc1 .  SEP . $entity_name);
-                                       }
-                               }
-                       }
-                       if($category_name)
-                       {
-                               if(!$this->vfs->file_exists(array(
-                                               'string' => $this->fakebase. 
SEP . 'document' .  SEP . $loc1 .  SEP . $entity_name .  SEP . $category_name,
-                                               'relatives' => 
Array(RELATIVE_NONE)
-                                       )))
-                               {
-
-                                       if(!$this->vfs->mkdir (array(
-                                                'string' => $this->fakebase. 
SEP . 'document' .  SEP . $loc1 .  SEP . $entity_name .  SEP . $category_name,
-                                            'relatives' => array(
-                                                 RELATIVE_NONE
-                                            )
-                                       )))
-                                       {
-                                               
$receipt['error'][]=array('msg'=>lang('failed to create directory') . ' :'. 
$this->fakebase. SEP . 'document'  .  SEP . $loc1 .  SEP . $entity_name .  SEP 
. $category_name);
-                                       }
-                                       else
-                                       {
-                                               
$receipt['message'][]=array('msg'=>lang('directory created') . ' :'. 
$this->fakebase. SEP . 'document'  .  SEP . $loc1 .  SEP . $entity_name .  SEP 
. $category_name);
-                                       }
-                               }
-                       }
-                       if($p_num)
-                       {
-                               if(!$this->vfs->file_exists(array(
-                                               'string' => $this->fakebase. 
SEP . 'document' .  SEP . $loc1 .  SEP . $entity_name .  SEP . $category_name . 
 SEP . $p_num,
-                                               'relatives' => 
Array(RELATIVE_NONE)
-                                       )))
-                               {
-
-                                       if(!$this->vfs->mkdir (array(
-                                                'string' => $this->fakebase. 
SEP . 'document' .  SEP . $loc1 .  SEP . $entity_name .  SEP . $category_name . 
 SEP . $p_num,
-                                            'relatives' => array(
-                                                 RELATIVE_NONE
-                                            )
-                                       )))
-                                       {
-                                               
$receipt['error'][]=array('msg'=>lang('failed to create directory') . ' :'. 
$this->fakebase. SEP . 'document'  .  SEP . $loc1 .  SEP . $entity_name .  SEP 
. $category_name .  SEP . $p_num);
-                                       }
-                                       else
-                                       {
-                                               
$receipt['message'][]=array('msg'=>lang('directory created') . ' :'. 
$this->fakebase. SEP . 'document'  .  SEP . $loc1 .  SEP . $entity_name .  SEP 
. $category_name .  SEP . $p_num);
-                                       }
-                               }
-                       }
-
-                       $this->vfs->override_acl = 0;
-
-//_debug_array($receipt);
-                       return $receipt;
-               }
-
-
-               function save($values)
-               {
-
-                       $document_date  = 
$this->bocommon->date_array($values['document_date']);
-                       $values['document_date']        = mktime 
(2,0,0,$document_date['month'],$document_date['day'],$document_date['year']);
-
-                       while (is_array($values['location']) && list(,$value) = 
each($values['location']))
-                       {
-                               if($value)
-                               {
-                                       $location[] = $value;
-                               }
-                       }
-
-                       $values['location_code']=implode("-", $location);
-
-//_debug_array($values);
-                       if ($values['document_id'])
-                       {
-                               if ($values['document_id'] != 0)
-                               {
-                                       $receipt = $this->so->edit($values);
-                               }
-                       }
-                       else
-                       {
-                               $receipt = $this->so->add($values);
-                       }
-                       return $receipt;
-               }
-
-               function delete($document_id)
-               {
-                       $this->so->delete($document_id);
-               }
-       }
-?>
+<?php
+       /**
+       * phpGroupWare - property: a Facilities Management System.
+       *
+       * @author Sigurd Nes <address@hidden>
+       * @copyright Copyright (C) 2003-2005 Free Software Foundation, Inc. 
http://www.fsf.org/
+       * @license http://www.gnu.org/licenses/gpl.html GNU General Public 
License
+       * @internal Development of this application was funded by 
http://www.bergen.kommune.no/bbb_/ekstern/
+       * @package property
+       * @subpackage document
+       * @version $Id: class.bodocument.inc.php,v 1.7 2006/02/03 12:05:49 
sigurdne Exp $
+       */
+
+       /**
+        * Description
+        * @package property
+        */
+
+       class bodocument
+       {
+               var $start;
+               var $query;
+               var $filter;
+               var $sort;
+               var $order;
+               var $cat_id;
+
+               var $public_functions = array
+               (
+                       'read'                          => True,
+                       'read_single'           => True,
+                       'save'                          => True,
+                       'delete'                        => True,
+                       'check_perms'           => True
+               );
+
+               function bodocument($session=False)
+               {
+                       $this->currentapp       = 
$GLOBALS['phpgw_info']['flags']['currentapp'];
+                       $this->so                       = 
CreateObject($this->currentapp.'.sodocument');
+                       $this->bocommon         = 
CreateObject($this->currentapp.'.bocommon');
+                       $this->solocation       = 
CreateObject($this->currentapp.'.solocation');
+                       $this->historylog       = 
CreateObject($this->currentapp.'.historylog','document');
+                       $this->contacts         = 
CreateObject($this->currentapp.'.soactor');
+                       $this->contacts->role='vendor';
+
+                       $this->vfs                      = 
CreateObject('phpgwapi.vfs');
+                       $this->rootdir          = $this->vfs->basedir;
+                       $this->fakebase         = $this->vfs->fakebase;
+
+                       if ($session)
+                       {
+                               $this->read_sessiondata();
+                               $this->use_session = True;
+                       }
+
+                       $start  = get_var('start',array('POST','GET'));
+                       $query  = get_var('query',array('POST','GET'));
+                       $sort   = get_var('sort',array('POST','GET'));
+                       $order  = get_var('order',array('POST','GET'));
+                       $filter = get_var('filter',array('POST','GET'));
+                       $cat_id = get_var('cat_id',array('POST','GET'));
+                       $status_id      = 
get_var('status_id',array('POST','GET'));
+                       $entity_id      = 
get_var('entity_id',array('POST','GET'));
+                       $doc_type       = 
get_var('doc_type',array('POST','GET'));
+                       $query_location = 
get_var('query_location',array('POST','GET'));
+
+
+                       if ($start)
+                       {
+                               $this->start=$start;
+                       }
+                       else
+                       {
+                               $this->start=0;
+                       }
+
+                       if(isset($query))
+                       {
+                               $this->query = $query;
+                       }
+                       if(isset($filter))
+                       {
+                               $this->filter = $filter;
+                       }
+                       if(isset($sort))
+                       {
+                               $this->sort = $sort;
+                       }
+                       if(isset($order))
+                       {
+                               $this->order = $order;
+                       }
+                       if(isset($cat_id))
+                       {
+                               $this->cat_id = $cat_id;
+                       }
+                       if(isset($status_id))
+                       {
+                               $this->status_id = $status_id;
+                       }
+                       if(isset($entity_id))
+                       {
+                               $this->entity_id = $entity_id;
+                       }
+                       if(isset($doc_type))
+                       {
+                               $this->doc_type = $doc_type;
+                       }
+                       if(isset($query_location))
+                       {
+                               $this->query_location = $query_location;
+                       }
+
+               }
+
+               function save_sessiondata($data)
+               {
+                       if ($this->use_session)
+                       {
+                               
$GLOBALS['phpgw']->session->appsession('session_data','document',$data);
+                       }
+               }
+
+               function read_sessiondata()
+               {
+                       $data = 
$GLOBALS['phpgw']->session->appsession('session_data','document');
+
+                       //_debug_array($data);
+
+                       $this->start    = $data['start'];
+                       $this->query    = $data['query'];
+                       $this->filter   = $data['filter'];
+                       $this->sort             = $data['sort'];
+                       $this->order    = $data['order'];
+                       $this->cat_id   = $data['cat_id'];
+                       $this->entity_id        = $data['entity_id'];
+                       $this->doc_type = $data['doc_type'];
+                       $this->query_location   = $data['query_location'];
+               }
+
+               function select_status_list($format='',$selected='')
+               {
+                       switch($format)
+                       {
+                               case 'select':
+                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('status_select'));
+                                       break;
+                               case 'filter':
+                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('status_filter'));
+                                       break;
+                       }
+
+                       $status_entries= $this->so->select_status_list();
+
+                       while (is_array($status_entries) && list(,$status) = 
each($status_entries))
+                       {
+                               $sel_status = '';
+                               if ($status['id']==$selected)
+                               {
+                                       $sel_status = 'selected';
+                               }
+
+                               $status_list[] = array
+                               (
+                                       'id'            => $status['id'],
+                                       'name'          => $status['name'],
+                                       'selected'      => $sel_status
+                               );
+                       }
+
+                       for ($i=0;$i<count($status_list);$i++)
+                       {
+                               if ($status_list[$i]['selected'] != 'selected')
+                               {
+                                       unset($status_list[$i]['selected']);
+                               }
+                       }
+
+                       return $status_list;
+               }
+
+               function select_branch_list($selected='')
+               {
+
+                       $branch_entries= $this->so->select_branch_list();
+
+                       while (is_array($branch_entries) && list(,$branch) = 
each($branch_entries))
+                       {
+                               $sel_branch = '';
+                               if ($branch['id']==$selected)
+                               {
+                                       $sel_branch = 'selected';
+                               }
+
+                               $branch_list[] = array
+                               (
+                                       'id'            => $branch['id'],
+                                       'name'          => $branch['name'],
+                                       'selected'      => $sel_branch
+                               );
+                       }
+
+                       for ($i=0;$i<count($branch_list);$i++)
+                       {
+                               if ($branch_list[$i]['selected'] != 'selected')
+                               {
+                                       unset($branch_list[$i]['selected']);
+                               }
+                       }
+
+                       return $branch_list;
+               }
+
+
+               function select_doc_type_list($format='',$selected='')
+               {
+                       switch($format)
+                       {
+                               case 'select':
+                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('cat_select'));
+                                       break;
+                               case 'filter':
+                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('cat_filter'));
+                                       break;
+                       }
+
+                       $categories= $this->so->select_doc_type_list();
+
+                       while (is_array($categories) && list(,$category) = 
each($categories))
+                       {
+                               $sel_category = '';
+                               if ($category['id']==$selected)
+                               {
+                                       $sel_category = 'selected';
+                               }
+
+                               $category_list[] = array
+                               (
+                                       'cat_id'        => $category['id'],
+                                       'name'          => $category['name'],
+                                       'selected'      => $sel_category
+                               );
+                       }
+
+                       for ($i=0;$i<count($category_list);$i++)
+                       {
+                               if ($category_list[$i]['selected'] != 
'selected')
+                               {
+                                       unset($category_list[$i]['selected']);
+                               }
+                       }
+
+                       return $category_list;
+               }
+
+
+               function read()
+               {
+                       $document = $this->so->read(array('start' => 
$this->start,'query' => $this->query,'sort' => $this->sort,'order' => 
$this->order,
+                                                                               
        'filter' => $this->filter,'cat_id' => $this->cat_id,'entity_id' => 
$this->entity_id,'doc_type'=>$this->doc_type));
+                       $this->total_records = $this->so->total_records;
+
+                       $this->uicols   = $this->so->uicols;
+                       $cols_extra             = $this->so->cols_extra;
+
+                       $dateformat = 
$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
+                       for ($i=0; $i<count($document); $i++)
+                       {
+                               
$location_data=$this->solocation->read_single($document[$i]['location_code']);
+
+                               for ($j=0;$j<count($cols_extra);$j++)
+                               {
+                                       $document[$i][$cols_extra[$j]] = 
$location_data[$cols_extra[$j]];
+                               }
+                       }
+
+                       return $document;
+               }
+
+               function read_at_location($location_code='')
+               {
+                       $document = $this->so->read_at_location(array('start' 
=> $this->start,'query' => $this->query,'sort' => $this->sort,'order' => 
$this->order,
+                                                                               
        'filter' => $this->filter,'cat_id' => $this->cat_id,'entity_id' => 
$this->entity_id,
+                                                                               
        'location_code' => $location_code,'doc_type'=>$this->doc_type));
+                       $this->total_records = $this->so->total_records;
+
+                       $dateformat = 
$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
+
+                       for ($i=0; $i<count($document); $i++)
+                       {
+                               $document[$i]['user'] = 
$GLOBALS['phpgw']->accounts->id2name($document[$i]['user_id']);
+                               $document[$i]['document_date'] = 
$GLOBALS['phpgw']->common->show_date($document[$i]['start_date'],$dateformat);
+                               $document[$i]['entry_date'] = 
$GLOBALS['phpgw']->common->show_date($document[$i]['entry_date'],$dateformat);
+                       }
+
+                       return $document;
+               }
+
+               function read_single($document_id)
+               {
+                       $document                                               
= $this->so->read_single($document_id);
+                       $dateformat                                             
= $GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
+                       $document['document_date']              = 
$GLOBALS['phpgw']->common->show_date($document['document_date'],$dateformat);
+                       $vendor                                                 
= $this->contacts->read_single(array('actor_id'=>$document['vendor_id']));
+
+                       if(is_array($vendor))
+                       {
+                               foreach($vendor['attributes'] as $attribute)
+                               {
+                                       if($attribute['name']=='org_name')
+                                       {
+                                               
$document['vendor_name']=$attribute['value'];
+                                               break;
+                                       }
+                               }
+                       }
+
+                       if($document['location_code'])
+                       {
+                               $document['location_data'] 
=$this->solocation->read_single($document['location_code']);
+                       }
+
+                       if($document['p_num'])
+                       {
+                               $soadmin_entity = 
CreateObject($this->currentapp.'.soadmin_entity');
+                               $category = 
$soadmin_entity->read_single_category($document['p_entity_id'],$document['p_cat_id']);
+
+                               
$document['p'][$document['p_entity_id']]['p_num']=$document['p_num'];
+                               
$document['p'][$document['p_entity_id']]['p_entity_id']=$document['p_entity_id'];
+                               
$document['p'][$document['p_entity_id']]['p_cat_id']=$document['p_cat_id'];
+                               
$document['p'][$document['p_entity_id']]['p_cat_name'] = $category['name'];
+                       }
+
+                       return $document;
+               }
+
+               function read_location_data($location_code)
+               {
+                       $location_data=         
$this->solocation->read_single($location_code);
+
+                       return $location_data;
+               }
+
+               function select_category_list($format='',$selected='')
+               {
+/*                     switch($format)
+                       {
+                               case 'select':
+                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('cat_select'));
+                                       break;
+                               case 'filter':
+                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('cat_filter'));
+                                       break;
+                       }
+
+
+*/
+
+                       $soadmin_entity         = 
CreateObject($this->currentapp.'.soadmin_entity');
+                       $categories                     = 
$soadmin_entity->read_category(array('allrows'=>True,'entity_id'=>$this->entity_id));
+
+                       $category_list  = 
$this->bocommon->select_multi_list($selected,$categories);
+
+/*                     while (is_array($categories) && list(,$category) = 
each($categories))
+                       {
+                               $sel_category = '';
+                               if ($category['id']==$selected)
+                               {
+                                       $sel_category = 'selected';
+                               }
+
+                               $category_list[] = array
+                               (
+                                       'cat_id'        => $category['id'],
+                                       'name'          => $category['name'],
+                                       'selected'      => $sel_category
+                               );
+                       }
+
+                       for ($i=0;$i<count($category_list);$i++)
+                       {
+                               if ($category_list[$i]['selected'] != 
'selected')
+                               {
+                                       unset($category_list[$i]['selected']);
+                               }
+                       }
+*/
+                       return $category_list;
+               }
+
+
+
+               function read_record_history($id)
+               {
+                       $history_array = 
$this->historylog->return_array(array('O'),array(),'','',$id);
+                       $i=0;
+                       while (is_array($history_array) && list(,$value) = 
each($history_array))
+                       {
+
+                               $record_history[$i]['value_date']       = 
$GLOBALS['phpgw']->common->show_date($value['datetime']);
+                               $record_history[$i]['value_user']       = 
$value['owner'];
+
+                               switch ($value['status'])
+                               {
+                                       case 'R': $type = lang('Re-opened'); 
break;
+                                       case 'X': $type = lang('Closed');    
break;
+                                       case 'O': $type = lang('Opened');    
break;
+                                       case 'A': $type = lang('Re-assigned'); 
break;
+                                       case 'P': $type = lang('Priority 
changed'); break;
+                                       case 'CO': $type = lang('Initial 
Coordinator'); break;
+                                       case 'C': $type = lang('Coordinator 
changed'); break;
+                                       case 'TO': $type = lang('Initial 
Category'); break;
+                                       case 'T': $type = lang('Category 
changed'); break;
+                                       case 'SO': $type = lang('Initial 
Status'); break;
+                                       case 'S': $type = lang('Status 
changed'); break;
+                                       case 'FO': $type = lang('Initial 
File'); break;
+                                       case 'F': $type = lang('File changed'); 
break;
+                                       case 'LO': $type = lang('Initial 
Link'); break;
+                                       case 'L': $type = lang('Link changed'); 
break;
+                                       default: break;
+                               }
+
+                               
if($value['new_value']=='O'){$value['new_value']=lang('Opened');}
+                               
if($value['new_value']=='X'){$value['new_value']=lang('Closed');}
+
+
+                               $record_history[$i]['value_action']     = 
$type?$type:'';
+                               unset($type);
+
+                               if ($value['status'] == 'A')
+                               {
+                                       if (! $value['new_value'])
+                                       {
+                                               
$record_history[$i]['value_new_value']  = lang('None');
+                                       }
+                                       else
+                                       {
+                                               
$record_history[$i]['value_new_value']  = 
$GLOBALS['phpgw']->accounts->id2name($value['new_value']);
+                                       }
+                               }
+                               else if ($value['status'] == 'C' || 
$value['status'] == 'CO')
+                               {
+                                       $record_history[$i]['value_new_value']  
= $GLOBALS['phpgw']->accounts->id2name($value['new_value']);
+                               }
+                               else if ($value['status'] == 'T' || 
$value['status'] == 'TO')
+                               {
+                                       $record_history[$i]['value_new_value']  
= $this->so->read_single_category($value['new_value']);
+                               }
+                               else if ($value['status'] != 'O' && 
$value['new_value'])
+                               {
+                                       $record_history[$i]['value_new_value']  
= $value['new_value'];
+                               }
+                               else
+                               {
+                                       $record_history[$i]['value_new_value']  
= '';
+                               }
+
+                               $i++;
+                       }
+
+                       return $record_history;
+               }
+
+
+               function create_home_dir()
+               {
+                       if(!$this->vfs->file_exists(array(
+                                       'string' => $this->fakebase. SEP . 
'document',
+                                       'relatives' => Array(RELATIVE_NONE)
+                               )))
+                       {
+                               $this->vfs->override_acl = 1;
+
+                               if(!$this->vfs->mkdir (array(
+                                    'string' => $this->fakebase. SEP . 
'document',
+                                    'relatives' => array(
+                                         RELATIVE_NONE
+                                    )
+                               )))
+                               {
+                                       
$receipt['error'][]=array('msg'=>lang('failed to create directory') . ' :'. 
$this->fakebase. SEP . 'document');
+                               }
+                               else
+                               {
+                                       
$receipt['message'][]=array('msg'=>lang('directory created') . ' :'. 
$this->fakebase. SEP . 'document');
+                               }
+                               $this->vfs->override_acl = 0;
+                       }
+                       return $receipt;
+               }
+
+
+               function create_document_dir($data,$receipt)
+               {
+                       if(is_array($data))
+                       {
+                               $loc1                   = 
(isset($data['loc1'])?$data['loc1']:'');
+                               $entity_name    = 
(isset($data['entity_name'])?$data['entity_name']:'');
+                               $category_name  = 
(isset($data['category_name'])?$data['category_name']:'');
+                               $p_num = 
(isset($data['p_num'])?$data['p_num']:'');
+                       }
+
+                       $this->vfs->override_acl = 1;
+//_debug_array($data);
+                       if(!$this->vfs->file_exists(array(
+                                       'string' => $this->fakebase. SEP . 
'document' .  SEP . $loc1,
+                                       'relatives' => Array(RELATIVE_NONE)
+                               )))
+                       {
+                               if(!$this->vfs->mkdir (array(
+                                    'string' => $this->fakebase. SEP . 
'document' .  SEP . $loc1,
+                                    'relatives' => array(
+                                         RELATIVE_NONE
+                                    )
+                               )))
+                               {
+                                       
$receipt['error'][]=array('msg'=>lang('failed to create directory') . ' :'. 
$this->fakebase. SEP . 'document' .  SEP . $loc1);
+                               }
+                               else
+                               {
+                                       
$receipt['message'][]=array('msg'=>lang('directory created') . ' :'. 
$this->fakebase. SEP . 'document' .  SEP . $loc1);
+                               }
+                               $this->vfs->override_acl = 0;
+                       }
+
+                       if($entity_name)
+                       {
+                               if(!$this->vfs->file_exists(array(
+                                               'string' => $this->fakebase. 
SEP . 'document' .  SEP . $loc1 .  SEP . $entity_name,
+                                               'relatives' => 
Array(RELATIVE_NONE)
+                                       )))
+                               {
+
+                                       if(!$this->vfs->mkdir (array(
+                                                'string' => $this->fakebase. 
SEP . 'document' .  SEP . $loc1 .  SEP . $entity_name,
+                                            'relatives' => array(
+                                                 RELATIVE_NONE
+                                            )
+                                       )))
+                                       {
+                                               
$receipt['error'][]=array('msg'=>lang('failed to create directory') . ' :'. 
$this->fakebase. SEP . 'document'  .  SEP . $loc1 .  SEP . $entity_name);
+                                       }
+                                       else
+                                       {
+                                               
$receipt['message'][]=array('msg'=>lang('directory created') . ' :'. 
$this->fakebase. SEP . 'document'  .  SEP . $loc1 .  SEP . $entity_name);
+                                       }
+                               }
+                       }
+                       if($category_name)
+                       {
+                               if(!$this->vfs->file_exists(array(
+                                               'string' => $this->fakebase. 
SEP . 'document' .  SEP . $loc1 .  SEP . $entity_name .  SEP . $category_name,
+                                               'relatives' => 
Array(RELATIVE_NONE)
+                                       )))
+                               {
+
+                                       if(!$this->vfs->mkdir (array(
+                                                'string' => $this->fakebase. 
SEP . 'document' .  SEP . $loc1 .  SEP . $entity_name .  SEP . $category_name,
+                                            'relatives' => array(
+                                                 RELATIVE_NONE
+                                            )
+                                       )))
+                                       {
+                                               
$receipt['error'][]=array('msg'=>lang('failed to create directory') . ' :'. 
$this->fakebase. SEP . 'document'  .  SEP . $loc1 .  SEP . $entity_name .  SEP 
. $category_name);
+                                       }
+                                       else
+                                       {
+                                               
$receipt['message'][]=array('msg'=>lang('directory created') . ' :'. 
$this->fakebase. SEP . 'document'  .  SEP . $loc1 .  SEP . $entity_name .  SEP 
. $category_name);
+                                       }
+                               }
+                       }
+                       if($p_num)
+                       {
+                               if(!$this->vfs->file_exists(array(
+                                               'string' => $this->fakebase. 
SEP . 'document' .  SEP . $loc1 .  SEP . $entity_name .  SEP . $category_name . 
 SEP . $p_num,
+                                               'relatives' => 
Array(RELATIVE_NONE)
+                                       )))
+                               {
+
+                                       if(!$this->vfs->mkdir (array(
+                                                'string' => $this->fakebase. 
SEP . 'document' .  SEP . $loc1 .  SEP . $entity_name .  SEP . $category_name . 
 SEP . $p_num,
+                                            'relatives' => array(
+                                                 RELATIVE_NONE
+                                            )
+                                       )))
+                                       {
+                                               
$receipt['error'][]=array('msg'=>lang('failed to create directory') . ' :'. 
$this->fakebase. SEP . 'document'  .  SEP . $loc1 .  SEP . $entity_name .  SEP 
. $category_name .  SEP . $p_num);
+                                       }
+                                       else
+                                       {
+                                               
$receipt['message'][]=array('msg'=>lang('directory created') . ' :'. 
$this->fakebase. SEP . 'document'  .  SEP . $loc1 .  SEP . $entity_name .  SEP 
. $category_name .  SEP . $p_num);
+                                       }
+                               }
+                       }
+
+                       $this->vfs->override_acl = 0;
+
+//_debug_array($receipt);
+                       return $receipt;
+               }
+
+
+               function save($values)
+               {
+
+                       $document_date  = 
$this->bocommon->date_array($values['document_date']);
+                       $values['document_date']        = mktime 
(2,0,0,$document_date['month'],$document_date['day'],$document_date['year']);
+
+                       while (is_array($values['location']) && list(,$value) = 
each($values['location']))
+                       {
+                               if($value)
+                               {
+                                       $location[] = $value;
+                               }
+                       }
+
+                       $values['location_code']=implode("-", $location);
+
+//_debug_array($values);
+                       if ($values['document_id'])
+                       {
+                               if ($values['document_id'] != 0)
+                               {
+                                       $receipt = $this->so->edit($values);
+                               }
+                       }
+                       else
+                       {
+                               $receipt = $this->so->add($values);
+                       }
+                       return $receipt;
+               }
+
+               function delete($document_id)
+               {
+                       $this->so->delete($document_id);
+               }
+       }
+?>
Index: property/inc/class.boentity.inc.php
diff -u property/inc/class.boentity.inc.php:1.14 
property/inc/class.boentity.inc.php:1.15
--- property/inc/class.boentity.inc.php:1.14    Fri Jan 27 14:05:43 2006
+++ property/inc/class.boentity.inc.php Fri Feb  3 12:05:49 2006
@@ -1,636 +1,636 @@
-<?php
-       /**
-       * phpGroupWare - property: a Facilities Management System.
-       *
-       * @author Sigurd Nes <address@hidden>
-       * @copyright Copyright (C) 2003-2005 Free Software Foundation, Inc. 
http://www.fsf.org/
-       * @license http://www.gnu.org/licenses/gpl.html GNU General Public 
License
-       * @internal Development of this application was funded by 
http://www.bergen.kommune.no/bbb_/ekstern/
-       * @package property
-       * @subpackage entity
-       * @version $Id: class.boentity.inc.php,v 1.14 2006/01/27 14:05:43 
sigurdne Exp $
-       */
-
-       /**
-        * Description
-        * @package property
-        */
-
-       class boentity
-       {
-               var $start;
-               var $query;
-               var $filter;
-               var $sort;
-               var $order;
-               var $cat_id;
-
-               var $public_functions = array
-               (
-                       'read'                          => True,
-                       'read_single'           => True,
-                       'save'                          => True,
-                       'delete'                        => True,
-                       'check_perms'           => True
-               );
-
-               var $soap_functions = array(
-                       'list' => array(
-                               'in'  => 
array('int','int','struct','string','int'),
-                               'out' => array('array')
-                       ),
-                       'read' => array(
-                               'in'  => array('int','struct'),
-                               'out' => array('array')
-                       ),
-                       'save' => array(
-                               'in'  => array('int','struct'),
-                               'out' => array()
-                       ),
-                       'delete' => array(
-                               'in'  => array('int','struct'),
-                               'out' => array()
-                       )
-               );
-
-               function boentity($session=False)
-               {
-                       $this->currentapp       = 
$GLOBALS['phpgw_info']['flags']['currentapp'];
-                       $this->so                       = 
CreateObject($this->currentapp.'.soentity');
-
-                       $this->solocation       = 
CreateObject($this->currentapp.'.solocation');
-                       $this->bocommon         = 
CreateObject($this->currentapp.'.bocommon');
-                       $this->vfs                      = 
CreateObject('phpgwapi.vfs');
-                       $this->rootdir          = $this->vfs->basedir;
-                       $this->fakebase         = $this->vfs->fakebase;
-
-                       if ($session)
-                       {
-                               $this->read_sessiondata();
-                               $this->use_session = True;
-                       }
-
-                       $start  = get_var('start',array('POST','GET'));
-                       $query  = get_var('query',array('POST','GET'));
-                       $sort   = get_var('sort',array('POST','GET'));
-                       $order  = get_var('order',array('POST','GET'));
-                       $filter = get_var('filter',array('POST','GET'));
-                       $cat_id = get_var('cat_id',array('POST','GET'));
-                       $district_id    = 
get_var('district_id',array('POST','GET'));
-                       $entity_id      = 
get_var('entity_id',array('POST','GET'));
-                       $status = get_var('status',array('POST','GET'));
-                       $start_date     = 
get_var('start_date',array('POST','GET'));
-                       $end_date       = 
get_var('end_date',array('POST','GET'));
-
-                       $this->soadmin_entity           = 
CreateObject($this->currentapp.'.soadmin_entity',$entity_id,$cat_id);
-
-                       $this->category_name    = 
$this->soadmin_entity->category_name;
-
-                       if ($start)
-                       {
-                               $this->start=$start;
-                       }
-                       else
-                       {
-                               $this->start=0;
-                       }
-                       if(array_key_exists('query',$_POST) || 
array_key_exists('query',$_GET) )
-                       {
-                               $this->query = $query;
-                       }
-                       if(array_key_exists('filter',$_POST))
-                       {
-                               $this->filter = $filter;
-                       }
-                       if(array_key_exists('sort',$_POST))
-                       {
-                               $this->sort = $sort;
-                       }
-                       if(array_key_exists('order',$_POST))
-                       {
-                               $this->order = $order;
-                       }
-       //              if(array_key_exists('cat_id',$_POST) || 
array_key_exists('cat_id',$_GET) )
-                       if($cat_id)
-                       {
-                               $this->cat_id = $cat_id;
-                       }
-                       if(array_key_exists('district_id',$_POST))
-                       {
-                               $this->district_id = $district_id;
-                       }
-                       if($entity_id)
-                       {
-                               $this->entity_id = $entity_id;
-                       }
-                       if(array_key_exists('status',$_POST))
-                       {
-                               $this->status = $status;
-                       }
-                       if(array_key_exists('start_date',$_POST))
-                       {
-                               $this->start_date = $start_date;
-                       }
-                       if(array_key_exists('end_date',$_POST))
-                       {
-                               $this->end_date = $end_date;
-                       }
-               }
-
-               function save_sessiondata($data)
-               {
-                       if ($this->use_session)
-                       {
-                               
$GLOBALS['phpgw']->session->appsession('session_data','entity',$data);
-                       }
-               }
-
-               function read_sessiondata()
-               {
-                       $data = 
$GLOBALS['phpgw']->session->appsession('session_data','entity');
-                       //_debug_array($data);
-                       $this->start    = $data['start'];
-                       $this->query    = $data['query'];
-                       $this->filter   = $data['filter'];
-                       $this->sort             = $data['sort'];
-                       $this->order    = $data['order'];
-               //      $this->cat_id   = $data['cat_id'];
-                       $this->district_id      = $data['district_id'];
-               //      $this->entity_id        = $data['entity_id'];
-                       $this->status           = $data['status'];
-                       $this->start_date       = $data['start_date'];
-                       $this->end_date         = $data['end_date'];
-               }
-
-               function 
column_list($selected='',$entity_id='',$cat_id,$allrows='')
-               {
-                       $soadmin_entity = 
CreateObject($this->currentapp.'.soadmin_entity');
-
-                       if(!$selected)
-                       {
-                               
$selected=$GLOBALS['phpgw_info']['user']['preferences'][$this->currentapp]["entity_columns_"
 . $this->entity_id . '_' . $this->cat_id];
-                       }
-
-                       $columns = 
$soadmin_entity->read_attrib(array('entity_id'=>$entity_id,'cat_id'=>$cat_id,'allrows'=>$allrows));
-                       
$column_list=$this->bocommon->select_multi_list($selected,$columns);
-
-                       return $column_list;
-               }
-
-               function select_category_list($format='',$selected='')
-               {
-                       switch($format)
-                       {
-                               case 'select':
-                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('cat_select'));
-                                       break;
-                               case 'filter':
-                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('cat_filter'));
-                                       break;
-                       }
-
-                       $categories= 
$this->soadmin_entity->read_category(array('allrows'=>True,'entity_id'=>$this->entity_id));
-
-                       while (is_array($categories) && list(,$category) = 
each($categories))
-                       {
-                               $sel_category = '';
-                               if ($category['id']==$selected)
-                               {
-                                       $sel_category = 'selected';
-                               }
-
-                               $category_list[] = array
-                               (
-                                       'cat_id'        => $category['id'],
-                                       'name'          => $category['name'],
-                                       'selected'      => $sel_category
-                               );
-                       }
-
-                       for ($i=0;$i<count($category_list);$i++)
-                       {
-                               if ($category_list[$i]['selected'] != 
'selected')
-                               {
-                                       unset($category_list[$i]['selected']);
-                               }
-                       }
-
-                       return $category_list;
-               }
-
-
-               function select_status_list($format='',$selected='')
-               {
-                       switch($format)
-                       {
-                               case 'select':
-                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('status_select'));
-                                       break;
-                               case 'filter':
-                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('status_filter'));
-                                       break;
-                       }
-
-                       $status_entries= 
$this->so->select_status_list($this->entity_id,$this->cat_id);
-
-                       while (is_array($status_entries) && list(,$status) = 
each($status_entries))
-                       {
-                               $sel_status = '';
-                               if ($status['id']==$selected)
-                               {
-                                       $sel_status = 'selected';
-                               }
-
-                               $status_list[] = array
-                               (
-                                       'id'            => $status['id'],
-                                       'name'          => $status['name'],
-                                       'selected'      => $sel_status
-                               );
-                       }
-
-                       for ($i=0;$i<count($status_list);$i++)
-                       {
-                               if ($status_list[$i]['selected'] != 'selected')
-                               {
-                                       unset($status_list[$i]['selected']);
-                               }
-                       }
-
-                       return $status_list;
-               }
-
-               function read($data='')
-               {
-                       $entity = $this->so->read(array('start' => 
$this->start,'query' => $this->query,'sort' => $this->sort,'order' => 
$this->order,
-                                                                               
        'filter' => $this->filter,'cat_id' => $this->cat_id,'district_id' => 
$this->district_id,
-                                                                               
        
'lookup'=>$data['lookup'],'allrows'=>$data['allrows'],'entity_id'=>$this->entity_id,'cat_id'=>$this->cat_id,'status'=>$this->status,
-                                                                               
        
'start_date'=>$this->bocommon->date_to_timestamp($data['start_date']),'end_date'=>$this->bocommon->date_to_timestamp($data['end_date']),
-                                                                               
        'allrows'=>$data['allrows']));
-
-                       $this->total_records = $this->so->total_records;
-                       $this->uicols   = $this->so->uicols;
-                       $cols_extra             = $this->so->cols_extra;
-                       $cols_return_lookup             = 
$this->so->cols_return_lookup;
-//_debug_array($entity);
-//_debug_array($cols_extra);
-//_debug_array($cols_return_lookup);
-
-                       if($data['lookup'])
-                       {
-                               for ($i=0;$i<count($entity);$i++)
-                               {
-                                       
$location_data=$this->solocation->read_single($entity[$i]['location_code']);
-                                       for ($j=0;$j<count($cols_extra);$j++)
-                                       {
-                                               $entity[$i][$cols_extra[$j]] = 
$location_data[$cols_extra[$j]];
-                                       }
-
-                                       if($cols_return_lookup)
-                                       {
-                                               for 
($k=0;$k<count($cols_return_lookup);$k++)
-                                               {
-                                                       
$entity[$i][$cols_return_lookup[$k]] = $location_data[$cols_return_lookup[$k]];
-                                               }
-                                       }
-                               }
-                       }
-
-                       return $entity;
-               }
-
-               function read_single($data)
-               {
-                       $soadmin_entity = 
CreateObject($this->currentapp.'.soadmin_entity');
-                       $contacts                       = 
CreateObject('phpgwapi.contacts');
-                       $vendor = CreateObject($this->currentapp.'.soactor');
-                       $vendor->role = 'vendor';
-
-                       $entity = $this->so->read_single($data);
-                       $dateformat = 
$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
-                       $entity['date']  = 
$GLOBALS['phpgw']->common->show_date($entity['date'],$dateformat);
-
-                       if($entity['location_code'])
-                       {
-                               
$entity['location_data']=$this->solocation->read_single($entity['location_code']);
-                               if($entity['tenant_id'])
-                               {
-                                       
$tenant_data=$this->bocommon->read_single_tenant($entity['tenant_id']);
-                                       $entity['location_data']['tenant_id']   
= $entity['tenant_id'];
-                                       
$entity['location_data']['contact_phone']= $entity['contact_phone'];
-                                       $entity['location_data']['last_name']   
= $tenant_data['last_name'];
-                                       $entity['location_data']['first_name']  
= $tenant_data['first_name'];
-                               }
-                       }
-
-                       if($entity['p_num'])
-                       {
-                               $category = 
$soadmin_entity->read_single_category($entity['p_entity_id'],$entity['p_cat_id']);
-                               
$entity['p'][$entity['p_entity_id']]['p_num']=$entity['p_num'];
-                               
$entity['p'][$entity['p_entity_id']]['p_entity_id']=$entity['p_entity_id'];
-                               
$entity['p'][$entity['p_entity_id']]['p_cat_id']=$entity['p_cat_id'];
-                               
$entity['p'][$entity['p_entity_id']]['p_cat_name'] = $category['name'];
-                       }
-
-                       $input_type_array = array(
-                               'R' => 'radio',
-                               'CH' => 'checkbox',
-                               'LB' => 'listbox'
-                       );
-
-                       $sep = '/';
-
-                       $dlarr[strpos($dateformat,'Y')] = 'Y';
-                       $dlarr[strpos($dateformat,'m')] = 'm';
-                       $dlarr[strpos($dateformat,'d')] = 'd';
-                       ksort($dlarr);
-                       $dateformat= (implode($sep,$dlarr));
-                       $m=0;
-
-                       for ($i=0;$i<count($entity['attributes']);$i++)
-                       {
-                               if($entity['attributes'][$i]['datatype']=='D' 
&& $entity['attributes'][$i]['value'])
-                               {
-                                       $timestamp_date= 
mktime(0,0,0,date(m,strtotime($entity['attributes'][$i]['value'])),date(d,strtotime($entity['attributes'][$i]['value'])),date(y,strtotime($entity['attributes'][$i]['value'])));
-                                       $entity['attributes'][$i]['value']      
= $GLOBALS['phpgw']->common->show_date($timestamp_date,$dateformat);
-                               }
-
-                               if($entity['attributes'][$i]['datatype']=='AB')
-                               {
-                                       if($entity['attributes'][$i]['value'])
-                                       {
-                                               $contact_data                   
        = 
$contacts->read_single_entry($entity['attributes'][$i]['value'],array('n_given'=>'n_given','n_family'=>'n_family','email'=>'email'));
-                                               
$entity['attributes'][$i]['contact_name']       = $contact_data[0]['n_family'] 
. ', ' . $contact_data[0]['n_given'];
-                                       }
-
-                                       $insert_record_entity[] = 
$entity['attributes'][$i]['name'];
-                                       $lookup_link            = 
$GLOBALS['phpgw']->link('/index.php','menuaction='.$this->currentapp.'.uilookup.addressbook&column='
 . $entity['attributes'][$i]['name']);
-                                       $lookup_functions[$m]['name'] = 
'lookup_'. $entity['attributes'][$i]['name'] .'()';
-                                       $lookup_functions[$m]['action'] = 
'Window1=window.open('."'" . $lookup_link ."'" 
.',"Search","width=800,height=700,toolbar=no,scrollbars=yes,resizable=yes");';
-                                       $m++;
-                               }
-
-                               
if($entity['attributes'][$i]['datatype']=='VENDOR')
-                               {
-                                       if($entity['attributes'][$i]['value'])
-                                       {
-                                               $vendor_data    = 
$vendor->read_single(array('actor_id'=>$entity['attributes'][$i]['value']));
-                                               for 
($n=0;$n<count($vendor_data['attributes']);$n++)
-                                               {
-                                                       
if($vendor_data['attributes'][$n]['name'] == 'org_name')
-                                                       {
-                                                               
$entity['attributes'][$i]['vendor_name']= 
$vendor_data['attributes'][$n]['value'];
-                                                               $n 
=count($vendor_data['attributes']);
-                                                       }
-                                               }
-                                       }
-
-                                       $insert_record_entity[] = 
$entity['attributes'][$i]['name'];
-                                       $lookup_link            = 
$GLOBALS['phpgw']->link('/index.php','menuaction='.$this->currentapp.'.uilookup.vendor&column='
 . $entity['attributes'][$i]['name']);
-                                       $lookup_functions[$m]['name'] = 
'lookup_'. $entity['attributes'][$i]['name'] .'()';
-                                       $lookup_functions[$m]['action'] = 
'Window1=window.open('."'" . $lookup_link ."'" 
.',"Search","width=800,height=700,toolbar=no,scrollbars=yes,resizable=yes");';
-                                       $m++;
-                               }
-
-                               if($entity['attributes'][$i]['datatype']=='R' 
|| $entity['attributes'][$i]['datatype']=='CH' || 
$entity['attributes'][$i]['datatype']=='LB')
-                               {
-                                       $entity['attributes'][$i]['choice']     
= 
$soadmin_entity->read_attrib_choice($data['entity_id'],$data['cat_id'],$entity['attributes'][$i]['attrib_id']);
-                                       
$input_type=$input_type_array[$entity['attributes'][$i]['datatype']];
-
-                                       
if($entity['attributes'][$i]['datatype']=='CH')
-                                       {
-                                               
$entity['attributes'][$i]['value']=unserialize($entity['attributes'][$i]['value']);
-                                               
$entity['attributes'][$i]['choice'] = 
$this->bocommon->select_multi_list_2($entity['attributes'][$i]['value'],$entity['attributes'][$i]['choice'],$input_type);
-                                       }
-                                       else
-                                       {
-                                               for 
($j=0;$j<count($entity['attributes'][$i]['choice']);$j++)
-                                               {
-                                                       
$entity['attributes'][$i]['choice'][$j]['input_type']=$input_type;
-                                                       
if($entity['attributes'][$i]['choice'][$j]['id']==$entity['attributes'][$i]['value'])
-                                                       {
-                                                               
$entity['attributes'][$i]['choice'][$j]['checked']='checked';
-                                                       }
-                                               }
-                                       }
-                               }
-
-                               $entity['attributes'][$i]['datatype_text'] = 
$this->bocommon->translate_datatype($entity['attributes'][$i]['datatype']);
-                               $entity['attributes'][$i]['counter']    = $i;
-                               $entity['attributes'][$i]['type_id']    = 
$data['type_id'];
-                       }
-
-                       for ($j=0;$j<count($lookup_functions);$j++)
-                       {
-                               $entity['lookup_functions'] .= 'function ' . 
$lookup_functions[$j]['name'] ."\r\n";
-                               $entity['lookup_functions'] .= '{'."\r\n";
-                               $entity['lookup_functions'] .= 
$lookup_functions[$j]['action'] ."\r\n";
-                               $entity['lookup_functions'] .= '}'."\r\n";
-                       }
-
-                       $this->vfs->override_acl = 1;
-
-                       $entity['files'] = $this->vfs->ls (array(
-                            'string' => $this->fakebase. '/' . 
$this->category_name . '/' . $entity['location_data']['loc1'] .  '/' . 
$data['id'],
-                            'relatives' => array(RELATIVE_NONE)));
-
-                       $this->vfs->override_acl = 0;
-
-                       if(!$entity['files'][0]['file_id'])
-                       {
-                               unset($entity['files']);
-                       }
-
-
-                       
$GLOBALS['phpgw']->session->appsession('insert_record_entity',$this->currentapp,$insert_record_entity);
-
-//_debug_array($insert_record_entity);
-                       return $entity;
-               }
-
-
-               function create_home_dir($receipt='')
-               {
-                       if(!$this->vfs->file_exists(array(
-                                       'string' => $this->fakebase. SEP . 
$this->category_name,
-                                       'relatives' => Array(RELATIVE_NONE)
-                               )))
-                       {
-                               $this->vfs->override_acl = 1;
-
-                               if(!$this->vfs->mkdir (array(
-                                    'string' => $this->fakebase. SEP . 
$this->category_name,
-                                    'relatives' => array(
-                                         RELATIVE_NONE
-                                    )
-                               )))
-                               {
-                                       
$receipt['error'][]=array('msg'=>lang('failed to create directory') . ' :'. 
$this->fakebase. SEP . $this->category_name);
-                               }
-                               else
-                               {
-                                       
$receipt['message'][]=array('msg'=>lang('directory created') . ' :'. 
$this->fakebase. SEP . $this->category_name);
-                               }
-                               $this->vfs->override_acl = 0;
-                       }
-
-                       return $receipt;
-               }
-
-               function create_document_dir($loc1='',$id='')
-               {
-                       if(!$this->vfs->file_exists(array(
-                                       'string' => $this->fakebase. SEP . 
$this->category_name .  SEP . $loc1,
-                                       'relatives' => Array(RELATIVE_NONE)
-                               )))
-                       {
-                               $this->vfs->override_acl = 1;
-                               if(!$this->vfs->mkdir (array(
-                                    'string' => $this->fakebase. SEP . 
$this->category_name .  SEP . $loc1,
-                                    'relatives' => array(
-                                         RELATIVE_NONE
-                                    )
-                               )))
-                               {
-                                       
$receipt['error'][]=array('msg'=>lang('failed to create directory') . ' :'. 
$this->fakebase. SEP . $this->category_name .  SEP . $loc1);
-                               }
-                               else
-                               {
-                                       
$receipt['message'][]=array('msg'=>lang('directory created') . ' :'. 
$this->fakebase. SEP . $this->category_name .  SEP . $loc1);
-                               }
-                               $this->vfs->override_acl = 0;
-                       }
-
-
-                       if(!$this->vfs->file_exists(array(
-                                       'string' => $this->fakebase. SEP . 
$this->category_name .  SEP . $loc1 .  SEP . $id,
-                                       'relatives' => Array(RELATIVE_NONE)
-                               )))
-                       {
-                               $this->vfs->override_acl = 1;
-                               if(!$this->vfs->mkdir (array(
-                                    'string' => $this->fakebase. SEP . 
$this->category_name .  SEP . $loc1 .  SEP . $id,
-                                    'relatives' => array(
-                                         RELATIVE_NONE
-                                    )
-                               )))
-                               {
-                                       
$receipt['error'][]=array('msg'=>lang('failed to create directory') . ' :'. 
$this->fakebase. SEP  . $this->category_name  .  SEP . $loc1 .  SEP . $id);
-                               }
-                               else
-                               {
-                                       
$receipt['message'][]=array('msg'=>lang('directory created') . ' :'. 
$this->fakebase. SEP . $this->category_name .  SEP . $loc1 .  SEP . $id);
-                               }
-                               $this->vfs->override_acl = 0;
-                       }
-
-//_debug_array($receipt);
-                       return $receipt;
-               }
-
-               function 
save($values,$values_attribute,$action='',$entity_id,$cat_id)
-               {
-                       while (is_array($values['location']) && list(,$value) = 
each($values['location']))
-                       {
-                               if($value)
-                               {
-                                       $location[] = $value;
-                               }
-                       }
-
-                       $values['location_code']=implode("-", $location);
-
-                       $values['date'] = 
$this->bocommon->date_to_timestamp($values['date']);
-
-                       for ($i=0;$i<count($values_attribute);$i++)
-                       {
-                               if($values_attribute[$i]['datatype']=='CH' && 
$values_attribute[$i]['value'])
-                               {
-                                       $values_attribute[$i]['value'] = 
serialize($values_attribute[$i]['value']);
-                               }
-                               if($values_attribute[$i]['datatype']=='R' && 
$values_attribute[$i]['value'])
-                               {
-                                       $values_attribute[$i]['value'] = 
$values_attribute[$i]['value'][0];
-                               }
-
-                               if($values_attribute[$i]['datatype']=='N' && 
$values_attribute[$i]['value'])
-                               {
-                                       $values_attribute[$i]['value'] = 
str_replace(",",".",$values_attribute[$i]['value']);
-                               }
-
-                               if($values_attribute[$i]['datatype']=='D' && 
$values_attribute[$i]['value'])
-                               {
-
-                                       $values_attribute[$i]['value'] = 
date($this->bocommon->dateformat,$this->bocommon->date_to_timestamp($values_attribute[$i]['value']));
-                               }
-                       }
-
-                       if ($action=='edit')
-                       {
-                               $receipt = 
$this->so->edit($values,$values_attribute,$entity_id,$cat_id);
-
-                               if($values['delete_file'])
-                               {
-                                       for 
($i=0;$i<count($values['delete_file']);$i++)
-                                       {
-                                               $file = $this->fakebase. SEP . 
$this->category_name . SEP . $location[0] . SEP . $values['id'] . SEP . 
$values['delete_file'][$i];
-
-                                               
if($this->vfs->file_exists(array(
-                                                               'string' => 
$file,
-                                                               'relatives' => 
Array(RELATIVE_NONE)
-                                                       )))
-                                               {
-                                                       
$this->vfs->override_acl = 1;
-
-                                                       if(!$this->vfs->rm 
(array(
-                                                               'string' => 
$file,
-                                                            'relatives' => 
array(
-                                                                 RELATIVE_NONE
-                                                            )
-                                                       )))
-                                                       {
-                                                               
$receipt['error'][]=array('msg'=>lang('failed to delete file') . ' :'. 
$this->fakebase. SEP . $this->category_name . SEP . $location[0]. SEP . 
$values['id'] . SEP .$values['delete_file'][$i]);
-                                                       }
-                                                       else
-                                                       {
-                                                               
$receipt['message'][]=array('msg'=>lang('file deleted') . ' :'. 
$this->fakebase. SEP . $this->category_name . SEP . $location[0]. SEP . 
$values['id'] . SEP . $values['delete_file'][$i]);
-                                                       }
-                                                       
$this->vfs->override_acl = 0;
-                                               }
-                                       }
-                               }
-                       }
-                       else
-                       {
-                               $receipt = 
$this->so->add($values,$values_attribute,$entity_id,$cat_id);
-                       }
-
-                       $acl_location = '.entity.' . $entity_id . '.' . $cat_id;
-                       $custom_functions = 
$this->soadmin_entity->read_custom_function(array('acl_location' => 
$acl_location,'allrows'=>True));
-
-                       if (isSet($custom_functions) AND 
is_array($custom_functions))
-                       {
-                               foreach($custom_functions as $entry)
-                               {
-                                       if (is_file(PHPGW_APP_INC . SEP . 
'custom' . SEP . $entry['file_name']) && $entry['active'])
-                                       include (PHPGW_APP_INC . SEP . 'custom' 
. SEP . $entry['file_name']);
-                               }
-                       }
-                       return receipt;
-               }
-
-
-               function delete($id )
-               {
-                       $this->so->delete($this->entity_id,$this->cat_id,$id);
-               }
-
-               function generate_id($data )
-               {
-                       if($data['cat_id'])
-                       {
-                               return $this->so->generate_id($data);
-                       }
-               }
-       }
+<?php
+       /**
+       * phpGroupWare - property: a Facilities Management System.
+       *
+       * @author Sigurd Nes <address@hidden>
+       * @copyright Copyright (C) 2003-2005 Free Software Foundation, Inc. 
http://www.fsf.org/
+       * @license http://www.gnu.org/licenses/gpl.html GNU General Public 
License
+       * @internal Development of this application was funded by 
http://www.bergen.kommune.no/bbb_/ekstern/
+       * @package property
+       * @subpackage entity
+       * @version $Id: class.boentity.inc.php,v 1.15 2006/02/03 12:05:49 
sigurdne Exp $
+       */
+
+       /**
+        * Description
+        * @package property
+        */
+
+       class boentity
+       {
+               var $start;
+               var $query;
+               var $filter;
+               var $sort;
+               var $order;
+               var $cat_id;
+
+               var $public_functions = array
+               (
+                       'read'                          => True,
+                       'read_single'           => True,
+                       'save'                          => True,
+                       'delete'                        => True,
+                       'check_perms'           => True
+               );
+
+               var $soap_functions = array(
+                       'list' => array(
+                               'in'  => 
array('int','int','struct','string','int'),
+                               'out' => array('array')
+                       ),
+                       'read' => array(
+                               'in'  => array('int','struct'),
+                               'out' => array('array')
+                       ),
+                       'save' => array(
+                               'in'  => array('int','struct'),
+                               'out' => array()
+                       ),
+                       'delete' => array(
+                               'in'  => array('int','struct'),
+                               'out' => array()
+                       )
+               );
+
+               function boentity($session=False)
+               {
+                       $this->currentapp       = 
$GLOBALS['phpgw_info']['flags']['currentapp'];
+                       $this->so                       = 
CreateObject($this->currentapp.'.soentity');
+
+                       $this->solocation       = 
CreateObject($this->currentapp.'.solocation');
+                       $this->bocommon         = 
CreateObject($this->currentapp.'.bocommon');
+                       $this->vfs                      = 
CreateObject('phpgwapi.vfs');
+                       $this->rootdir          = $this->vfs->basedir;
+                       $this->fakebase         = $this->vfs->fakebase;
+
+                       if ($session)
+                       {
+                               $this->read_sessiondata();
+                               $this->use_session = True;
+                       }
+
+                       $start  = get_var('start',array('POST','GET'));
+                       $query  = get_var('query',array('POST','GET'));
+                       $sort   = get_var('sort',array('POST','GET'));
+                       $order  = get_var('order',array('POST','GET'));
+                       $filter = get_var('filter',array('POST','GET'));
+                       $cat_id = get_var('cat_id',array('POST','GET'));
+                       $district_id    = 
get_var('district_id',array('POST','GET'));
+                       $entity_id      = 
get_var('entity_id',array('POST','GET'));
+                       $status = get_var('status',array('POST','GET'));
+                       $start_date     = 
get_var('start_date',array('POST','GET'));
+                       $end_date       = 
get_var('end_date',array('POST','GET'));
+
+                       $this->soadmin_entity           = 
CreateObject($this->currentapp.'.soadmin_entity',$entity_id,$cat_id);
+
+                       $this->category_name    = 
$this->soadmin_entity->category_name;
+
+                       if ($start)
+                       {
+                               $this->start=$start;
+                       }
+                       else
+                       {
+                               $this->start=0;
+                       }
+                       if(array_key_exists('query',$_POST) || 
array_key_exists('query',$_GET) )
+                       {
+                               $this->query = $query;
+                       }
+                       if(array_key_exists('filter',$_POST))
+                       {
+                               $this->filter = $filter;
+                       }
+                       if(array_key_exists('sort',$_POST))
+                       {
+                               $this->sort = $sort;
+                       }
+                       if(array_key_exists('order',$_POST))
+                       {
+                               $this->order = $order;
+                       }
+       //              if(array_key_exists('cat_id',$_POST) || 
array_key_exists('cat_id',$_GET) )
+                       if($cat_id)
+                       {
+                               $this->cat_id = $cat_id;
+                       }
+                       if(array_key_exists('district_id',$_POST))
+                       {
+                               $this->district_id = $district_id;
+                       }
+                       if($entity_id)
+                       {
+                               $this->entity_id = $entity_id;
+                       }
+                       if(array_key_exists('status',$_POST))
+                       {
+                               $this->status = $status;
+                       }
+                       if(array_key_exists('start_date',$_POST))
+                       {
+                               $this->start_date = $start_date;
+                       }
+                       if(array_key_exists('end_date',$_POST))
+                       {
+                               $this->end_date = $end_date;
+                       }
+               }
+
+               function save_sessiondata($data)
+               {
+                       if ($this->use_session)
+                       {
+                               
$GLOBALS['phpgw']->session->appsession('session_data','entity',$data);
+                       }
+               }
+
+               function read_sessiondata()
+               {
+                       $data = 
$GLOBALS['phpgw']->session->appsession('session_data','entity');
+                       //_debug_array($data);
+                       $this->start    = $data['start'];
+                       $this->query    = $data['query'];
+                       $this->filter   = $data['filter'];
+                       $this->sort             = $data['sort'];
+                       $this->order    = $data['order'];
+               //      $this->cat_id   = $data['cat_id'];
+                       $this->district_id      = $data['district_id'];
+               //      $this->entity_id        = $data['entity_id'];
+                       $this->status           = $data['status'];
+                       $this->start_date       = $data['start_date'];
+                       $this->end_date         = $data['end_date'];
+               }
+
+               function 
column_list($selected='',$entity_id='',$cat_id,$allrows='')
+               {
+                       $soadmin_entity = 
CreateObject($this->currentapp.'.soadmin_entity');
+
+                       if(!$selected)
+                       {
+                               
$selected=$GLOBALS['phpgw_info']['user']['preferences'][$this->currentapp]["entity_columns_"
 . $this->entity_id . '_' . $this->cat_id];
+                       }
+
+                       $columns = 
$soadmin_entity->read_attrib(array('entity_id'=>$entity_id,'cat_id'=>$cat_id,'allrows'=>$allrows));
+                       
$column_list=$this->bocommon->select_multi_list($selected,$columns);
+
+                       return $column_list;
+               }
+
+               function select_category_list($format='',$selected='')
+               {
+                       switch($format)
+                       {
+                               case 'select':
+                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('cat_select'));
+                                       break;
+                               case 'filter':
+                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('cat_filter'));
+                                       break;
+                       }
+
+                       $categories= 
$this->soadmin_entity->read_category(array('allrows'=>True,'entity_id'=>$this->entity_id));
+
+                       while (is_array($categories) && list(,$category) = 
each($categories))
+                       {
+                               $sel_category = '';
+                               if ($category['id']==$selected)
+                               {
+                                       $sel_category = 'selected';
+                               }
+
+                               $category_list[] = array
+                               (
+                                       'cat_id'        => $category['id'],
+                                       'name'          => $category['name'],
+                                       'selected'      => $sel_category
+                               );
+                       }
+
+                       for ($i=0;$i<count($category_list);$i++)
+                       {
+                               if ($category_list[$i]['selected'] != 
'selected')
+                               {
+                                       unset($category_list[$i]['selected']);
+                               }
+                       }
+
+                       return $category_list;
+               }
+
+
+               function select_status_list($format='',$selected='')
+               {
+                       switch($format)
+                       {
+                               case 'select':
+                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('status_select'));
+                                       break;
+                               case 'filter':
+                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('status_filter'));
+                                       break;
+                       }
+
+                       $status_entries= 
$this->so->select_status_list($this->entity_id,$this->cat_id);
+
+                       while (is_array($status_entries) && list(,$status) = 
each($status_entries))
+                       {
+                               $sel_status = '';
+                               if ($status['id']==$selected)
+                               {
+                                       $sel_status = 'selected';
+                               }
+
+                               $status_list[] = array
+                               (
+                                       'id'            => $status['id'],
+                                       'name'          => $status['name'],
+                                       'selected'      => $sel_status
+                               );
+                       }
+
+                       for ($i=0;$i<count($status_list);$i++)
+                       {
+                               if ($status_list[$i]['selected'] != 'selected')
+                               {
+                                       unset($status_list[$i]['selected']);
+                               }
+                       }
+
+                       return $status_list;
+               }
+
+               function read($data='')
+               {
+                       $entity = $this->so->read(array('start' => 
$this->start,'query' => $this->query,'sort' => $this->sort,'order' => 
$this->order,
+                                                                               
        'filter' => $this->filter,'cat_id' => $this->cat_id,'district_id' => 
$this->district_id,
+                                                                               
        
'lookup'=>$data['lookup'],'allrows'=>$data['allrows'],'entity_id'=>$this->entity_id,'cat_id'=>$this->cat_id,'status'=>$this->status,
+                                                                               
        
'start_date'=>$this->bocommon->date_to_timestamp($data['start_date']),'end_date'=>$this->bocommon->date_to_timestamp($data['end_date']),
+                                                                               
        'allrows'=>$data['allrows']));
+
+                       $this->total_records = $this->so->total_records;
+                       $this->uicols   = $this->so->uicols;
+                       $cols_extra             = $this->so->cols_extra;
+                       $cols_return_lookup             = 
$this->so->cols_return_lookup;
+//_debug_array($entity);
+//_debug_array($cols_extra);
+//_debug_array($cols_return_lookup);
+
+                       if($data['lookup'])
+                       {
+                               for ($i=0;$i<count($entity);$i++)
+                               {
+                                       
$location_data=$this->solocation->read_single($entity[$i]['location_code']);
+                                       for ($j=0;$j<count($cols_extra);$j++)
+                                       {
+                                               $entity[$i][$cols_extra[$j]] = 
$location_data[$cols_extra[$j]];
+                                       }
+
+                                       if($cols_return_lookup)
+                                       {
+                                               for 
($k=0;$k<count($cols_return_lookup);$k++)
+                                               {
+                                                       
$entity[$i][$cols_return_lookup[$k]] = $location_data[$cols_return_lookup[$k]];
+                                               }
+                                       }
+                               }
+                       }
+
+                       return $entity;
+               }
+
+               function read_single($data)
+               {
+                       $soadmin_entity = 
CreateObject($this->currentapp.'.soadmin_entity');
+                       $contacts                       = 
CreateObject('phpgwapi.contacts');
+                       $vendor = CreateObject($this->currentapp.'.soactor');
+                       $vendor->role = 'vendor';
+
+                       $entity = $this->so->read_single($data);
+                       $dateformat = 
$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
+                       $entity['date']  = 
$GLOBALS['phpgw']->common->show_date($entity['date'],$dateformat);
+
+                       if($entity['location_code'])
+                       {
+                               
$entity['location_data']=$this->solocation->read_single($entity['location_code']);
+                               if($entity['tenant_id'])
+                               {
+                                       
$tenant_data=$this->bocommon->read_single_tenant($entity['tenant_id']);
+                                       $entity['location_data']['tenant_id']   
= $entity['tenant_id'];
+                                       
$entity['location_data']['contact_phone']= $entity['contact_phone'];
+                                       $entity['location_data']['last_name']   
= $tenant_data['last_name'];
+                                       $entity['location_data']['first_name']  
= $tenant_data['first_name'];
+                               }
+                       }
+
+                       if($entity['p_num'])
+                       {
+                               $category = 
$soadmin_entity->read_single_category($entity['p_entity_id'],$entity['p_cat_id']);
+                               
$entity['p'][$entity['p_entity_id']]['p_num']=$entity['p_num'];
+                               
$entity['p'][$entity['p_entity_id']]['p_entity_id']=$entity['p_entity_id'];
+                               
$entity['p'][$entity['p_entity_id']]['p_cat_id']=$entity['p_cat_id'];
+                               
$entity['p'][$entity['p_entity_id']]['p_cat_name'] = $category['name'];
+                       }
+
+                       $input_type_array = array(
+                               'R' => 'radio',
+                               'CH' => 'checkbox',
+                               'LB' => 'listbox'
+                       );
+
+                       $sep = '/';
+
+                       $dlarr[strpos($dateformat,'Y')] = 'Y';
+                       $dlarr[strpos($dateformat,'m')] = 'm';
+                       $dlarr[strpos($dateformat,'d')] = 'd';
+                       ksort($dlarr);
+                       $dateformat= (implode($sep,$dlarr));
+                       $m=0;
+
+                       for ($i=0;$i<count($entity['attributes']);$i++)
+                       {
+                               if($entity['attributes'][$i]['datatype']=='D' 
&& $entity['attributes'][$i]['value'])
+                               {
+                                       $timestamp_date= 
mktime(0,0,0,date(m,strtotime($entity['attributes'][$i]['value'])),date(d,strtotime($entity['attributes'][$i]['value'])),date(y,strtotime($entity['attributes'][$i]['value'])));
+                                       $entity['attributes'][$i]['value']      
= $GLOBALS['phpgw']->common->show_date($timestamp_date,$dateformat);
+                               }
+
+                               if($entity['attributes'][$i]['datatype']=='AB')
+                               {
+                                       if($entity['attributes'][$i]['value'])
+                                       {
+                                               $contact_data                   
        = 
$contacts->read_single_entry($entity['attributes'][$i]['value'],array('n_given'=>'n_given','n_family'=>'n_family','email'=>'email'));
+                                               
$entity['attributes'][$i]['contact_name']       = $contact_data[0]['n_family'] 
. ', ' . $contact_data[0]['n_given'];
+                                       }
+
+                                       $insert_record_entity[] = 
$entity['attributes'][$i]['name'];
+                                       $lookup_link            = 
$GLOBALS['phpgw']->link('/index.php','menuaction='.$this->currentapp.'.uilookup.addressbook&column='
 . $entity['attributes'][$i]['name']);
+                                       $lookup_functions[$m]['name'] = 
'lookup_'. $entity['attributes'][$i]['name'] .'()';
+                                       $lookup_functions[$m]['action'] = 
'Window1=window.open('."'" . $lookup_link ."'" 
.',"Search","width=800,height=700,toolbar=no,scrollbars=yes,resizable=yes");';
+                                       $m++;
+                               }
+
+                               
if($entity['attributes'][$i]['datatype']=='VENDOR')
+                               {
+                                       if($entity['attributes'][$i]['value'])
+                                       {
+                                               $vendor_data    = 
$vendor->read_single(array('actor_id'=>$entity['attributes'][$i]['value']));
+                                               for 
($n=0;$n<count($vendor_data['attributes']);$n++)
+                                               {
+                                                       
if($vendor_data['attributes'][$n]['name'] == 'org_name')
+                                                       {
+                                                               
$entity['attributes'][$i]['vendor_name']= 
$vendor_data['attributes'][$n]['value'];
+                                                               $n 
=count($vendor_data['attributes']);
+                                                       }
+                                               }
+                                       }
+
+                                       $insert_record_entity[] = 
$entity['attributes'][$i]['name'];
+                                       $lookup_link            = 
$GLOBALS['phpgw']->link('/index.php','menuaction='.$this->currentapp.'.uilookup.vendor&column='
 . $entity['attributes'][$i]['name']);
+                                       $lookup_functions[$m]['name'] = 
'lookup_'. $entity['attributes'][$i]['name'] .'()';
+                                       $lookup_functions[$m]['action'] = 
'Window1=window.open('."'" . $lookup_link ."'" 
.',"Search","width=800,height=700,toolbar=no,scrollbars=yes,resizable=yes");';
+                                       $m++;
+                               }
+
+                               if($entity['attributes'][$i]['datatype']=='R' 
|| $entity['attributes'][$i]['datatype']=='CH' || 
$entity['attributes'][$i]['datatype']=='LB')
+                               {
+                                       $entity['attributes'][$i]['choice']     
= 
$soadmin_entity->read_attrib_choice($data['entity_id'],$data['cat_id'],$entity['attributes'][$i]['attrib_id']);
+                                       
$input_type=$input_type_array[$entity['attributes'][$i]['datatype']];
+
+                                       
if($entity['attributes'][$i]['datatype']=='CH')
+                                       {
+                                               
$entity['attributes'][$i]['value']=unserialize($entity['attributes'][$i]['value']);
+                                               
$entity['attributes'][$i]['choice'] = 
$this->bocommon->select_multi_list_2($entity['attributes'][$i]['value'],$entity['attributes'][$i]['choice'],$input_type);
+                                       }
+                                       else
+                                       {
+                                               for 
($j=0;$j<count($entity['attributes'][$i]['choice']);$j++)
+                                               {
+                                                       
$entity['attributes'][$i]['choice'][$j]['input_type']=$input_type;
+                                                       
if($entity['attributes'][$i]['choice'][$j]['id']==$entity['attributes'][$i]['value'])
+                                                       {
+                                                               
$entity['attributes'][$i]['choice'][$j]['checked']='checked';
+                                                       }
+                                               }
+                                       }
+                               }
+
+                               $entity['attributes'][$i]['datatype_text'] = 
$this->bocommon->translate_datatype($entity['attributes'][$i]['datatype']);
+                               $entity['attributes'][$i]['counter']    = $i;
+                               $entity['attributes'][$i]['type_id']    = 
$data['type_id'];
+                       }
+
+                       for ($j=0;$j<count($lookup_functions);$j++)
+                       {
+                               $entity['lookup_functions'] .= 'function ' . 
$lookup_functions[$j]['name'] ."\r\n";
+                               $entity['lookup_functions'] .= '{'."\r\n";
+                               $entity['lookup_functions'] .= 
$lookup_functions[$j]['action'] ."\r\n";
+                               $entity['lookup_functions'] .= '}'."\r\n";
+                       }
+
+                       $this->vfs->override_acl = 1;
+
+                       $entity['files'] = $this->vfs->ls (array(
+                            'string' => $this->fakebase. '/' . 
$this->category_name . '/' . $entity['location_data']['loc1'] .  '/' . 
$data['id'],
+                            'relatives' => array(RELATIVE_NONE)));
+
+                       $this->vfs->override_acl = 0;
+
+                       if(!$entity['files'][0]['file_id'])
+                       {
+                               unset($entity['files']);
+                       }
+
+
+                       
$GLOBALS['phpgw']->session->appsession('insert_record_entity',$this->currentapp,$insert_record_entity);
+
+//_debug_array($insert_record_entity);
+                       return $entity;
+               }
+
+
+               function create_home_dir($receipt='')
+               {
+                       if(!$this->vfs->file_exists(array(
+                                       'string' => $this->fakebase. SEP . 
$this->category_name,
+                                       'relatives' => Array(RELATIVE_NONE)
+                               )))
+                       {
+                               $this->vfs->override_acl = 1;
+
+                               if(!$this->vfs->mkdir (array(
+                                    'string' => $this->fakebase. SEP . 
$this->category_name,
+                                    'relatives' => array(
+                                         RELATIVE_NONE
+                                    )
+                               )))
+                               {
+                                       
$receipt['error'][]=array('msg'=>lang('failed to create directory') . ' :'. 
$this->fakebase. SEP . $this->category_name);
+                               }
+                               else
+                               {
+                                       
$receipt['message'][]=array('msg'=>lang('directory created') . ' :'. 
$this->fakebase. SEP . $this->category_name);
+                               }
+                               $this->vfs->override_acl = 0;
+                       }
+
+                       return $receipt;
+               }
+
+               function create_document_dir($loc1='',$id='')
+               {
+                       if(!$this->vfs->file_exists(array(
+                                       'string' => $this->fakebase. SEP . 
$this->category_name .  SEP . $loc1,
+                                       'relatives' => Array(RELATIVE_NONE)
+                               )))
+                       {
+                               $this->vfs->override_acl = 1;
+                               if(!$this->vfs->mkdir (array(
+                                    'string' => $this->fakebase. SEP . 
$this->category_name .  SEP . $loc1,
+                                    'relatives' => array(
+                                         RELATIVE_NONE
+                                    )
+                               )))
+                               {
+                                       
$receipt['error'][]=array('msg'=>lang('failed to create directory') . ' :'. 
$this->fakebase. SEP . $this->category_name .  SEP . $loc1);
+                               }
+                               else
+                               {
+                                       
$receipt['message'][]=array('msg'=>lang('directory created') . ' :'. 
$this->fakebase. SEP . $this->category_name .  SEP . $loc1);
+                               }
+                               $this->vfs->override_acl = 0;
+                       }
+
+
+                       if(!$this->vfs->file_exists(array(
+                                       'string' => $this->fakebase. SEP . 
$this->category_name .  SEP . $loc1 .  SEP . $id,
+                                       'relatives' => Array(RELATIVE_NONE)
+                               )))
+                       {
+                               $this->vfs->override_acl = 1;
+                               if(!$this->vfs->mkdir (array(
+                                    'string' => $this->fakebase. SEP . 
$this->category_name .  SEP . $loc1 .  SEP . $id,
+                                    'relatives' => array(
+                                         RELATIVE_NONE
+                                    )
+                               )))
+                               {
+                                       
$receipt['error'][]=array('msg'=>lang('failed to create directory') . ' :'. 
$this->fakebase. SEP  . $this->category_name  .  SEP . $loc1 .  SEP . $id);
+                               }
+                               else
+                               {
+                                       
$receipt['message'][]=array('msg'=>lang('directory created') . ' :'. 
$this->fakebase. SEP . $this->category_name .  SEP . $loc1 .  SEP . $id);
+                               }
+                               $this->vfs->override_acl = 0;
+                       }
+
+//_debug_array($receipt);
+                       return $receipt;
+               }
+
+               function 
save($values,$values_attribute,$action='',$entity_id,$cat_id)
+               {
+                       while (is_array($values['location']) && list(,$value) = 
each($values['location']))
+                       {
+                               if($value)
+                               {
+                                       $location[] = $value;
+                               }
+                       }
+
+                       $values['location_code']=implode("-", $location);
+
+                       $values['date'] = 
$this->bocommon->date_to_timestamp($values['date']);
+
+                       for ($i=0;$i<count($values_attribute);$i++)
+                       {
+                               if($values_attribute[$i]['datatype']=='CH' && 
$values_attribute[$i]['value'])
+                               {
+                                       $values_attribute[$i]['value'] = 
serialize($values_attribute[$i]['value']);
+                               }
+                               if($values_attribute[$i]['datatype']=='R' && 
$values_attribute[$i]['value'])
+                               {
+                                       $values_attribute[$i]['value'] = 
$values_attribute[$i]['value'][0];
+                               }
+
+                               if($values_attribute[$i]['datatype']=='N' && 
$values_attribute[$i]['value'])
+                               {
+                                       $values_attribute[$i]['value'] = 
str_replace(",",".",$values_attribute[$i]['value']);
+                               }
+
+                               if($values_attribute[$i]['datatype']=='D' && 
$values_attribute[$i]['value'])
+                               {
+
+                                       $values_attribute[$i]['value'] = 
date($this->bocommon->dateformat,$this->bocommon->date_to_timestamp($values_attribute[$i]['value']));
+                               }
+                       }
+
+                       if ($action=='edit')
+                       {
+                               $receipt = 
$this->so->edit($values,$values_attribute,$entity_id,$cat_id);
+
+                               if($values['delete_file'])
+                               {
+                                       for 
($i=0;$i<count($values['delete_file']);$i++)
+                                       {
+                                               $file = $this->fakebase. SEP . 
$this->category_name . SEP . $location[0] . SEP . $values['id'] . SEP . 
$values['delete_file'][$i];
+
+                                               
if($this->vfs->file_exists(array(
+                                                               'string' => 
$file,
+                                                               'relatives' => 
Array(RELATIVE_NONE)
+                                                       )))
+                                               {
+                                                       
$this->vfs->override_acl = 1;
+
+                                                       if(!$this->vfs->rm 
(array(
+                                                               'string' => 
$file,
+                                                            'relatives' => 
array(
+                                                                 RELATIVE_NONE
+                                                            )
+                                                       )))
+                                                       {
+                                                               
$receipt['error'][]=array('msg'=>lang('failed to delete file') . ' :'. 
$this->fakebase. SEP . $this->category_name . SEP . $location[0]. SEP . 
$values['id'] . SEP .$values['delete_file'][$i]);
+                                                       }
+                                                       else
+                                                       {
+                                                               
$receipt['message'][]=array('msg'=>lang('file deleted') . ' :'. 
$this->fakebase. SEP . $this->category_name . SEP . $location[0]. SEP . 
$values['id'] . SEP . $values['delete_file'][$i]);
+                                                       }
+                                                       
$this->vfs->override_acl = 0;
+                                               }
+                                       }
+                               }
+                       }
+                       else
+                       {
+                               $receipt = 
$this->so->add($values,$values_attribute,$entity_id,$cat_id);
+                       }
+
+                       $acl_location = '.entity.' . $entity_id . '.' . $cat_id;
+                       $custom_functions = 
$this->soadmin_entity->read_custom_function(array('acl_location' => 
$acl_location,'allrows'=>True));
+
+                       if (isSet($custom_functions) AND 
is_array($custom_functions))
+                       {
+                               foreach($custom_functions as $entry)
+                               {
+                                       if (is_file(PHPGW_APP_INC . SEP . 
'custom' . SEP . $entry['file_name']) && $entry['active'])
+                                       include (PHPGW_APP_INC . SEP . 'custom' 
. SEP . $entry['file_name']);
+                               }
+                       }
+                       return receipt;
+               }
+
+
+               function delete($id )
+               {
+                       $this->so->delete($this->entity_id,$this->cat_id,$id);
+               }
+
+               function generate_id($data )
+               {
+                       if($data['cat_id'])
+                       {
+                               return $this->so->generate_id($data);
+                       }
+               }
+       }
 ?>
\ No newline at end of file
Index: property/inc/class.bogab.inc.php
diff -u property/inc/class.bogab.inc.php:1.7 
property/inc/class.bogab.inc.php:1.8
--- property/inc/class.bogab.inc.php:1.7        Fri Jan 27 14:05:43 2006
+++ property/inc/class.bogab.inc.php    Fri Feb  3 12:05:49 2006
@@ -1,208 +1,208 @@
-<?php
-       /**
-       * phpGroupWare - property: a Facilities Management System.
-       *
-       * @author Sigurd Nes <address@hidden>
-       * @copyright Copyright (C) 2003-2005 Free Software Foundation, Inc. 
http://www.fsf.org/
-       * @license http://www.gnu.org/licenses/gpl.html GNU General Public 
License
-       * @internal Development of this application was funded by 
http://www.bergen.kommune.no/bbb_/ekstern/
-       * @package property
-       * @subpackage location
-       * @version $Id: class.bogab.inc.php,v 1.7 2006/01/27 14:05:43 sigurdne 
Exp $
-       */
-
-       /**
-        * Description
-        * @package property
-        */
-
-       class bogab
-       {
-               var $start;
-               var $query;
-               var $filter;
-               var $sort;
-               var $order;
-               var $cat_id;
-
-               var $public_functions = array
-               (
-                       'read'                          => True,
-                       'read_single'           => True,
-                       'save'                          => True,
-                       'delete'                        => True,
-                       'check_perms'           => True
-               );
-
-               function bogab($session=False)
-               {
-                       $this->currentapp       = 
$GLOBALS['phpgw_info']['flags']['currentapp'];
-                       $this->bocommon         = 
CreateObject($this->currentapp.'.bocommon');
-                       $this->solocation       = 
CreateObject($this->currentapp.'.solocation');
-                       $this->config                           = 
CreateObject('phpgwapi.config');
-                       $this->config->read_repository();
-                       $gab_insert_level = 
$this->config->config_data['gab_insert_level'];
-
-                       if (! $gab_insert_level)
-                       {
-                               $gab_insert_level = 3;
-                       }
-
-                       $this->gab_insert_level = $gab_insert_level;
-
-                       $this->so                       = 
CreateObject($this->currentapp.'.sogab',$this->gab_insert_level);
-
-                       if ($session)
-                       {
-                               $this->read_sessiondata();
-                               $this->use_session = True;
-                       }
-
-                       $start  = get_var('start',array('POST','GET'));
-                       $query  = get_var('query',array('POST','GET'));
-                       $sort   = get_var('sort',array('POST','GET'));
-                       $order  = get_var('order',array('POST','GET'));
-                       $filter = get_var('filter',array('POST','GET'));
-                       $cat_id = get_var('cat_id',array('POST','GET'));
-                       $allrows        = 
get_var('allrows',array('POST','GET'));
-
-                       if ($start)
-                       {
-                               $this->start=$start;
-                       }
-                       else
-                       {
-                               $this->start=0;
-                       }
-
-                       if(isset($query))
-                       {
-                               $this->query = $query;
-                       }
-                       if(!empty($filter))
-                       {
-                               $this->filter = $filter;
-                       }
-                       if(isset($sort))
-                       {
-                               $this->sort = $sort;
-                       }
-                       if(isset($order))
-                       {
-                               $this->order = $order;
-                       }
-                       if(isset($cat_id))
-                       {
-                               $this->cat_id = $cat_id;
-                       }
-                       if(isset($allrows))
-                       {
-                               $this->allrows = $allrows;
-                       }
-               }
-
-
-               function save_sessiondata($data)
-               {
-                       if ($this->use_session)
-                       {
-                               
$GLOBALS['phpgw']->session->appsession('session_data','gab',$data);
-                       }
-               }
-
-               function read_sessiondata()
-               {
-                       $data = 
$GLOBALS['phpgw']->session->appsession('session_data','gab');
-
-                       //_debug_array($data);
-
-                       $this->start    = $data['start'];
-                       $this->query    = $data['query'];
-                       $this->filter   = $data['filter'];
-                       $this->sort             = $data['sort'];
-                       $this->order    = $data['order'];
-                       $this->cat_id   = $data['cat_id'];
-                       $this->allrows  = $data['allrows'];
-               }
-
-
-               function 
read($loc1='',$gaards_nr='',$bruksnr='',$feste_nr='',$seksjons_nr='',$address='')
-               {
-                       $gab = $this->so->read(array('start' => 
$this->start,'sort' => $this->sort,'order' => 
$this->order,'allrows'=>$this->allrows,
-                                                                               
        'cat_id' => $this->cat_id,'loc1' => $loc1,
-                                                                               
        'gaards_nr' => $gaards_nr,'bruksnr' => $bruksnr,'feste_nr' => $feste_nr,
-                                                                               
        'seksjons_nr' => $seksjons_nr,'address' => $address));
-                       $this->total_records = $this->so->total_records;
-                       return $gab;
-               }
-
-               function read_detail($gab_id='')
-               {
-                       $gab = $this->so->read_detail(array('start' => 
$this->start,'sort' => $this->sort,'order' => $this->order,
-                                                                               
        'cat_id' => $this->cat_id,'gab_id' => 
$gab_id,'allrows'=>$this->allrows));
-                       $this->total_records = $this->so->total_records;
-
-                       $this->uicols   = $this->so->uicols;
-                       $cols_extra             = $this->so->cols_extra;
-
-
-                       for ($i=0; $i<count($gab); $i++)
-                       {
-                               
$location_data=$this->solocation->read_single($gab[$i]['location_code']);
-
-                               for ($j=0;$j<count($cols_extra);$j++)
-                               {
-                                       $gab[$i][$cols_extra[$j]] = 
$location_data[$cols_extra[$j]];
-                               }
-                       }
-
-                       return $gab;
-               }
-
-               function read_single($gab_id='',$location_code='')
-               {
-                       $gab = $this->so->read_single($gab_id,$location_code);
-
-                       if($gab['location_code'])
-                       {
-                               $gab['location_data'] 
=$this->solocation->read_single($gab['location_code']);
-                       }
-
-                       return $gab;
-               }
-
-
-               function save($values)
-               {
-                       if(!$values['location_code'])
-                       {
-                               while (is_array($values['location']) && 
list(,$value) = each($values['location']))
-                               {
-                                       if($value)
-                                       {
-                                               $location[] = $value;
-                                       }
-                               }
-
-                               $values['location_code']=implode("-", 
$location);
-                       }
-
-                       if ($values['action']=='edit')
-                       {
-                               $receipt = $this->so->edit($values);
-                       }
-                       else
-                       {
-                               $receipt = $this->so->add($values);
-                       }
-
-                       $receipt['location_code']=$values['location_code'];
-                       return $receipt;
-               }
-
-               function delete($gab_id='',$location_code='')
-               {
-                       $this->so->delete($gab_id,$location_code);
-               }
-       }
-?>
+<?php
+       /**
+       * phpGroupWare - property: a Facilities Management System.
+       *
+       * @author Sigurd Nes <address@hidden>
+       * @copyright Copyright (C) 2003-2005 Free Software Foundation, Inc. 
http://www.fsf.org/
+       * @license http://www.gnu.org/licenses/gpl.html GNU General Public 
License
+       * @internal Development of this application was funded by 
http://www.bergen.kommune.no/bbb_/ekstern/
+       * @package property
+       * @subpackage location
+       * @version $Id: class.bogab.inc.php,v 1.8 2006/02/03 12:05:49 sigurdne 
Exp $
+       */
+
+       /**
+        * Description
+        * @package property
+        */
+
+       class bogab
+       {
+               var $start;
+               var $query;
+               var $filter;
+               var $sort;
+               var $order;
+               var $cat_id;
+
+               var $public_functions = array
+               (
+                       'read'                          => True,
+                       'read_single'           => True,
+                       'save'                          => True,
+                       'delete'                        => True,
+                       'check_perms'           => True
+               );
+
+               function bogab($session=False)
+               {
+                       $this->currentapp       = 
$GLOBALS['phpgw_info']['flags']['currentapp'];
+                       $this->bocommon         = 
CreateObject($this->currentapp.'.bocommon');
+                       $this->solocation       = 
CreateObject($this->currentapp.'.solocation');
+                       $this->config                           = 
CreateObject('phpgwapi.config');
+                       $this->config->read_repository();
+                       $gab_insert_level = 
$this->config->config_data['gab_insert_level'];
+
+                       if (! $gab_insert_level)
+                       {
+                               $gab_insert_level = 3;
+                       }
+
+                       $this->gab_insert_level = $gab_insert_level;
+
+                       $this->so                       = 
CreateObject($this->currentapp.'.sogab',$this->gab_insert_level);
+
+                       if ($session)
+                       {
+                               $this->read_sessiondata();
+                               $this->use_session = True;
+                       }
+
+                       $start  = get_var('start',array('POST','GET'));
+                       $query  = get_var('query',array('POST','GET'));
+                       $sort   = get_var('sort',array('POST','GET'));
+                       $order  = get_var('order',array('POST','GET'));
+                       $filter = get_var('filter',array('POST','GET'));
+                       $cat_id = get_var('cat_id',array('POST','GET'));
+                       $allrows        = 
get_var('allrows',array('POST','GET'));
+
+                       if ($start)
+                       {
+                               $this->start=$start;
+                       }
+                       else
+                       {
+                               $this->start=0;
+                       }
+
+                       if(isset($query))
+                       {
+                               $this->query = $query;
+                       }
+                       if(!empty($filter))
+                       {
+                               $this->filter = $filter;
+                       }
+                       if(isset($sort))
+                       {
+                               $this->sort = $sort;
+                       }
+                       if(isset($order))
+                       {
+                               $this->order = $order;
+                       }
+                       if(isset($cat_id))
+                       {
+                               $this->cat_id = $cat_id;
+                       }
+                       if(isset($allrows))
+                       {
+                               $this->allrows = $allrows;
+                       }
+               }
+
+
+               function save_sessiondata($data)
+               {
+                       if ($this->use_session)
+                       {
+                               
$GLOBALS['phpgw']->session->appsession('session_data','gab',$data);
+                       }
+               }
+
+               function read_sessiondata()
+               {
+                       $data = 
$GLOBALS['phpgw']->session->appsession('session_data','gab');
+
+                       //_debug_array($data);
+
+                       $this->start    = $data['start'];
+                       $this->query    = $data['query'];
+                       $this->filter   = $data['filter'];
+                       $this->sort             = $data['sort'];
+                       $this->order    = $data['order'];
+                       $this->cat_id   = $data['cat_id'];
+                       $this->allrows  = $data['allrows'];
+               }
+
+
+               function 
read($loc1='',$gaards_nr='',$bruksnr='',$feste_nr='',$seksjons_nr='',$address='')
+               {
+                       $gab = $this->so->read(array('start' => 
$this->start,'sort' => $this->sort,'order' => 
$this->order,'allrows'=>$this->allrows,
+                                                                               
        'cat_id' => $this->cat_id,'loc1' => $loc1,
+                                                                               
        'gaards_nr' => $gaards_nr,'bruksnr' => $bruksnr,'feste_nr' => $feste_nr,
+                                                                               
        'seksjons_nr' => $seksjons_nr,'address' => $address));
+                       $this->total_records = $this->so->total_records;
+                       return $gab;
+               }
+
+               function read_detail($gab_id='')
+               {
+                       $gab = $this->so->read_detail(array('start' => 
$this->start,'sort' => $this->sort,'order' => $this->order,
+                                                                               
        'cat_id' => $this->cat_id,'gab_id' => 
$gab_id,'allrows'=>$this->allrows));
+                       $this->total_records = $this->so->total_records;
+
+                       $this->uicols   = $this->so->uicols;
+                       $cols_extra             = $this->so->cols_extra;
+
+
+                       for ($i=0; $i<count($gab); $i++)
+                       {
+                               
$location_data=$this->solocation->read_single($gab[$i]['location_code']);
+
+                               for ($j=0;$j<count($cols_extra);$j++)
+                               {
+                                       $gab[$i][$cols_extra[$j]] = 
$location_data[$cols_extra[$j]];
+                               }
+                       }
+
+                       return $gab;
+               }
+
+               function read_single($gab_id='',$location_code='')
+               {
+                       $gab = $this->so->read_single($gab_id,$location_code);
+
+                       if($gab['location_code'])
+                       {
+                               $gab['location_data'] 
=$this->solocation->read_single($gab['location_code']);
+                       }
+
+                       return $gab;
+               }
+
+
+               function save($values)
+               {
+                       if(!$values['location_code'])
+                       {
+                               while (is_array($values['location']) && 
list(,$value) = each($values['location']))
+                               {
+                                       if($value)
+                                       {
+                                               $location[] = $value;
+                                       }
+                               }
+
+                               $values['location_code']=implode("-", 
$location);
+                       }
+
+                       if ($values['action']=='edit')
+                       {
+                               $receipt = $this->so->edit($values);
+                       }
+                       else
+                       {
+                               $receipt = $this->so->add($values);
+                       }
+
+                       $receipt['location_code']=$values['location_code'];
+                       return $receipt;
+               }
+
+               function delete($gab_id='',$location_code='')
+               {
+                       $this->so->delete($gab_id,$location_code);
+               }
+       }
+?>
Index: property/inc/class.boinvestment.inc.php
diff -u property/inc/class.boinvestment.inc.php:1.6 
property/inc/class.boinvestment.inc.php:1.7
--- property/inc/class.boinvestment.inc.php:1.6 Fri Jan 27 14:05:43 2006
+++ property/inc/class.boinvestment.inc.php     Fri Feb  3 12:05:49 2006
@@ -1,393 +1,393 @@
-<?php
-       /**
-       * phpGroupWare - property: a Facilities Management System.
-       *
-       * @author Sigurd Nes <address@hidden>
-       * @copyright Copyright (C) 2003-2005 Free Software Foundation, Inc. 
http://www.fsf.org/
-       * @license http://www.gnu.org/licenses/gpl.html GNU General Public 
License
-       * @internal Development of this application was funded by 
http://www.bergen.kommune.no/bbb_/ekstern/
-       * @package property
-       * @subpackage eco
-       * @version $Id: class.boinvestment.inc.php,v 1.6 2006/01/27 14:05:43 
sigurdne Exp $
-       */
-
-       /**
-        * Description
-        * @package property
-        */
-
-       class boinvestment
-       {
-               var $start;
-               var $query;
-               var $filter;
-               var $sort;
-               var $order;
-               var $cat_id;
-//             var $part_of_town_id;
-
-               var $public_functions = array
-               (
-                       'read'                          => True,
-                       'read_single'           => True,
-                       'save'                          => True,
-                       'delete'                        => True,
-                       'check_perms'           => True
-               );
-
-               var $soap_functions = array(
-                       'list' => array(
-                               'in'  => 
array('int','int','struct','string','int'),
-                               'out' => array('array')
-                       ),
-                       'read' => array(
-                               'in'  => array('int','struct'),
-                               'out' => array('array')
-                       ),
-                       'save' => array(
-                               'in'  => array('int','struct'),
-                               'out' => array()
-                       ),
-                       'delete' => array(
-                               'in'  => array('int','struct'),
-                               'out' => array()
-                       )
-               );
-
-               function boinvestment($session=False)
-               {
-                       $this->currentapp       = 
$GLOBALS['phpgw_info']['flags']['currentapp'];
-                       $this->so               = 
CreateObject($this->currentapp.'.soinvestment');
-                       $this->bocommon = 
CreateObject($this->currentapp.'.bocommon');
-                       $this->socommon = 
CreateObject($this->currentapp.'.socommon');
-
-                       if ($session)
-                       {
-                               $this->read_sessiondata();
-                               $this->use_session = True;
-                       }
-
-                       $start                          = 
get_var('start',array('POST','GET'));
-                       $query                          = 
get_var('query',array('POST','GET'));
-                       $sort                           = 
get_var('sort',array('POST','GET'));
-                       $order                          = 
get_var('order',array('POST','GET'));
-                       $filter                         = 
get_var('filter',array('POST','GET'));
-                       $cat_id                         = 
get_var('cat_id',array('POST','GET'));
-                       $part_of_town_id        = 
get_var('part_of_town_id',array('POST','GET'));
-                       $allrows                        = 
get_var('allrows',array('POST','GET'));
-
-                       if ($start)
-                       {
-                               $this->start=$start;
-                       }
-                       else
-                       {
-                               $this->start=0;
-                       }
-
-                       if(isset($query))
-                       {
-                               $this->query = $query;
-                       }
-                       if(isset($filter))
-                       {
-                               $this->filter = $filter;
-                       }
-                       if(isset($sort))
-                       {
-                               $this->sort = $sort;
-                       }
-                       if(isset($order))
-                       {
-                               $this->order = $order;
-                       }
-                       if(isset($cat_id))
-                       {
-                               $this->cat_id = $cat_id;
-                       }
-                       if(isset($part_of_town_id))
-                       {
-                               $this->part_of_town_id = $part_of_town_id;
-                       }
-                       if(isset($allrows))
-                       {
-                               $this->allrows = $allrows;
-                       }
-
-               }
-
-               function read_sessiondata()
-               {
-                       $data = 
$GLOBALS['phpgw']->session->appsession('session_data','investment');
-                       $this->start    = $data['start'];
-                       $this->query    = $data['query'];
-                       $this->filter   = $data['filter'];
-                       $this->sort             = $data['sort'];
-                       $this->order    = $data['order'];
-                       $this->cat_id   = $data['cat_id'];
-                       $this->part_of_town_id  = $data['part_of_town_id'];
-                       $this->allrows  = $data['allrows'];
-               }
-
-               function save_sessiondata($data)
-               {
-                       if ($this->use_session)
-                       {
-                               
$GLOBALS['phpgw']->session->appsession('session_data','investment',$data);
-                       }
-               }
-
-               function read()
-               {
-
-                       $investment = $this->so->read(array('start' => 
$this->start,'query' => $this->query,'sort' => $this->sort,'order' => 
$this->order,
-                                                                               
        'filter' => $this->filter,'cat_id' => $this->cat_id,'part_of_town_id' 
=> $this->part_of_town_id,'allrows'=>$this->allrows));
-                       $this->total_records = $this->so->total_records;
-
-       /*              for ($i=0; $i<count($investment); $i++)
-                       {
-                               $investment[$i]['date']  = 
$GLOBALS['phpgw']->common->show_date($investment[$i]['date']);
-                       }
-       */
-                       return $investment;
-               }
-
-
-               function select_category($format='',$selected='')
-               {
-                       switch($format)
-                       {
-                               case 'select':
-                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('cat_select'));
-                                       break;
-                               case 'filter':
-                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('cat_filter'));
-                                       break;
-                       }
-
-                       $categories= $this->so->get_type_list();
-
-                       while (is_array($categories) && list(,$category) = 
each($categories))
-                       {
-                               $sel_category = '';
-                               if ($category['id']==$selected)
-                               {
-                                       $sel_category = 'selected';
-                               }
-
-                               $category_list[] = array
-                               (
-                                       'cat_id'        => $category['id'],
-                                       'name'          => $category['num'],
-                                       'selected'      => $sel_category
-                               );
-                       }
-
-                       for ($i=0;$i<count($category_list);$i++)
-                       {
-                               if ($category_list[$i]['selected'] != 
'selected')
-                               {
-                                       unset($category_list[$i]['selected']);
-                               }
-                       }
-
-                       return $category_list;
-               }
-
-               function write_off_period_list($selected='')
-               {
-
-                       
$GLOBALS['phpgw']->xslttpl->add_file(array('cat_select'));
-
-
-                       $categories= $this->so->write_off_period_list();
-
-                       while (is_array($categories) && list(,$category) = 
each($categories))
-                       {
-                               $sel_category = '';
-                               if ($category['period']==$selected)
-                               {
-                                       $sel_category = 'selected';
-                               }
-
-                               $category_list[] = array
-                               (
-                                       'cat_id'        => $category['period'],
-                                       'name'          => $category['period'],
-                                       'selected'      => $sel_category
-                               );
-                       }
-
-                       for ($i=0;$i<count($category_list);$i++)
-                       {
-                               if ($category_list[$i]['selected'] != 
'selected')
-                               {
-                                       unset($category_list[$i]['selected']);
-                               }
-                       }
-
-                       return $category_list;
-               }
-
-
-
-
-               function save_investment($values)
-               {
-                       while (is_array($values['location']) && list(,$value) = 
each($values['location']))
-                       {
-                               if($value)
-                               {
-                                       $location[] = $value;
-                               }
-                       }
-
-                       $values['location_code']=implode("-", $location);
-
-//_debug_array($values);
-
-                       $values['date'] = 
$this->bocommon->date_to_timestamp($values['date']);
-                       $values['date']= 
date($this->bocommon->dateformat,$values['date']);
-
-                       $values['initial_value']        = 
abs($values['initial_value']);
-
-                       if($values['type']=='funding')
-                       {
-                               $values['initial_value'] = 
-$values['initial_value'];
-                       }
-
-                       if($values['new_period'])
-                       {
-                               $values['period'] = $values['new_period'];
-                               unset($values['new_period']);
-                       }
-
-                       if($values['extra']['p_num'])
-                       {
-                               $boadmin_entity         = 
CreateObject($this->currentapp.'.boadmin_entity');
-                               $category = 
$boadmin_entity->read_single_category($values['extra']['p_entity_id'],$values['extra']['p_cat_id']);
-                               $values['entity_id']    = 
$values['extra']['p_num'];
-                               $values['entity_type']  =$category['name'];
-
-                       }
-                       else
-                       {
-                               $values['entity_id']    = 
$values['location_code'];
-                               $values['entity_type']  ='property';
-                       }
-
-
-                       $receipt=$this->so->save_investment($values);
-
-                       return $receipt;
-               }
-
-
-               function update_investment($values)
-               {
-
-                       
$date_array=$this->bocommon->date_array($values['date']);
-
-                       $date = mktime 
(2,0,0,$date_array['month'],$date_array['day'],$date_array['year']);
-                       $date= date($this->bocommon->dateformat,$date);
-
-                       $new_index=str_replace(",",".",$values['new_index']);
-
-                       while($entry=each($values['update']))
-                       {
-                               $local_error='';
-                               $n=$entry[0];
-
-                               if ($values['value'][$n])
-                               {
-                                       if ((abs($values['value'][$n])- 
abs(($values['initial_value'][$n]*$new_index)))<0)
-                                       {
-                                               $new_value=0;
-                                               
$new_index=$values['value'][$n]/$values['initial_value'][$n];
-                                       }
-                                       else
-                                       {
-                                               
$new_value=$values['value'][$n]-($values['initial_value'][$n]*$new_index);
-                                       }
-
-                                       $update[]=array(
-                                               'entity_id'             
=>$values['entity_id'][$n],
-                                               'invest_id'             
=>$values['investment_id'][$n],
-                                               'new_index'             
=>$new_index,
-                                               'new_value'             
=>$new_value,
-                                               'initial_value' 
=>$values['initial_value'][$n],
-                                               'date'                  =>$date
-                                               );
-                               }
-                       }
-                       $this->so->update_investment($update);
-               }
-
-
-               function filter($format='',$selected='')
-               {
-                       switch($format)
-                       {
-                               case 'select':
-                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('filter_select'));
-                                       break;
-                               case 'filter':
-                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('filter_filter'));
-                                       break;
-                       }
-
-                       $filters[0][id]='investment';
-                       $filters[0][name]=lang('Investment');
-                       $filters[1][id]='funding';
-                       $filters[1][name]=lang('Funding');
-
-                       while (is_array($filters) && list(,$filter) = 
each($filters))
-                       {
-                               $sel_filter = '';
-                               if ($filter['id']==$selected)
-                               {
-                                       $sel_filter = 'selected';
-                               }
-
-                               $filter_list[] = array
-                               (
-                                       'id'    => $filter['id'],
-                                       'name'          => $filter['name'],
-                                       'selected'      => $sel_filter
-                               );
-                       }
-
-                       for ($i=0;$i<count($filter_list);$i++)
-                       {
-                               if ($filter_list[$i]['selected'] != 'selected')
-                               {
-                                       unset($filter_list[$i]['selected']);
-                               }
-                       }
-
-                       return $filter_list;
-               }
-
-
-               function read_single($entity_id,$investment_id)
-               {
-                       $history        = 
$this->so->read_single($entity_id,$investment_id,$this->start,$this->allrows);
-
-                       $this->total_records = $this->so->total_records;
-
-                       return $history;
-               }
-
-
-               function select_part_of_town($part_of_town_id)
-               {
-                       return 
$this->socommon->select_part_of_town($part_of_town_id);
-               }
-
-
-               function delete($entity_id,$investment_id,$index_count)
-               {
-                       
$this->so->delete($entity_id,$investment_id,$index_count);
-               }
-       }
-?>
+<?php
+       /**
+       * phpGroupWare - property: a Facilities Management System.
+       *
+       * @author Sigurd Nes <address@hidden>
+       * @copyright Copyright (C) 2003-2005 Free Software Foundation, Inc. 
http://www.fsf.org/
+       * @license http://www.gnu.org/licenses/gpl.html GNU General Public 
License
+       * @internal Development of this application was funded by 
http://www.bergen.kommune.no/bbb_/ekstern/
+       * @package property
+       * @subpackage eco
+       * @version $Id: class.boinvestment.inc.php,v 1.7 2006/02/03 12:05:49 
sigurdne Exp $
+       */
+
+       /**
+        * Description
+        * @package property
+        */
+
+       class boinvestment
+       {
+               var $start;
+               var $query;
+               var $filter;
+               var $sort;
+               var $order;
+               var $cat_id;
+//             var $part_of_town_id;
+
+               var $public_functions = array
+               (
+                       'read'                          => True,
+                       'read_single'           => True,
+                       'save'                          => True,
+                       'delete'                        => True,
+                       'check_perms'           => True
+               );
+
+               var $soap_functions = array(
+                       'list' => array(
+                               'in'  => 
array('int','int','struct','string','int'),
+                               'out' => array('array')
+                       ),
+                       'read' => array(
+                               'in'  => array('int','struct'),
+                               'out' => array('array')
+                       ),
+                       'save' => array(
+                               'in'  => array('int','struct'),
+                               'out' => array()
+                       ),
+                       'delete' => array(
+                               'in'  => array('int','struct'),
+                               'out' => array()
+                       )
+               );
+
+               function boinvestment($session=False)
+               {
+                       $this->currentapp       = 
$GLOBALS['phpgw_info']['flags']['currentapp'];
+                       $this->so               = 
CreateObject($this->currentapp.'.soinvestment');
+                       $this->bocommon = 
CreateObject($this->currentapp.'.bocommon');
+                       $this->socommon = 
CreateObject($this->currentapp.'.socommon');
+
+                       if ($session)
+                       {
+                               $this->read_sessiondata();
+                               $this->use_session = True;
+                       }
+
+                       $start                          = 
get_var('start',array('POST','GET'));
+                       $query                          = 
get_var('query',array('POST','GET'));
+                       $sort                           = 
get_var('sort',array('POST','GET'));
+                       $order                          = 
get_var('order',array('POST','GET'));
+                       $filter                         = 
get_var('filter',array('POST','GET'));
+                       $cat_id                         = 
get_var('cat_id',array('POST','GET'));
+                       $part_of_town_id        = 
get_var('part_of_town_id',array('POST','GET'));
+                       $allrows                        = 
get_var('allrows',array('POST','GET'));
+
+                       if ($start)
+                       {
+                               $this->start=$start;
+                       }
+                       else
+                       {
+                               $this->start=0;
+                       }
+
+                       if(isset($query))
+                       {
+                               $this->query = $query;
+                       }
+                       if(isset($filter))
+                       {
+                               $this->filter = $filter;
+                       }
+                       if(isset($sort))
+                       {
+                               $this->sort = $sort;
+                       }
+                       if(isset($order))
+                       {
+                               $this->order = $order;
+                       }
+                       if(isset($cat_id))
+                       {
+                               $this->cat_id = $cat_id;
+                       }
+                       if(isset($part_of_town_id))
+                       {
+                               $this->part_of_town_id = $part_of_town_id;
+                       }
+                       if(isset($allrows))
+                       {
+                               $this->allrows = $allrows;
+                       }
+
+               }
+
+               function read_sessiondata()
+               {
+                       $data = 
$GLOBALS['phpgw']->session->appsession('session_data','investment');
+                       $this->start    = $data['start'];
+                       $this->query    = $data['query'];
+                       $this->filter   = $data['filter'];
+                       $this->sort             = $data['sort'];
+                       $this->order    = $data['order'];
+                       $this->cat_id   = $data['cat_id'];
+                       $this->part_of_town_id  = $data['part_of_town_id'];
+                       $this->allrows  = $data['allrows'];
+               }
+
+               function save_sessiondata($data)
+               {
+                       if ($this->use_session)
+                       {
+                               
$GLOBALS['phpgw']->session->appsession('session_data','investment',$data);
+                       }
+               }
+
+               function read()
+               {
+
+                       $investment = $this->so->read(array('start' => 
$this->start,'query' => $this->query,'sort' => $this->sort,'order' => 
$this->order,
+                                                                               
        'filter' => $this->filter,'cat_id' => $this->cat_id,'part_of_town_id' 
=> $this->part_of_town_id,'allrows'=>$this->allrows));
+                       $this->total_records = $this->so->total_records;
+
+       /*              for ($i=0; $i<count($investment); $i++)
+                       {
+                               $investment[$i]['date']  = 
$GLOBALS['phpgw']->common->show_date($investment[$i]['date']);
+                       }
+       */
+                       return $investment;
+               }
+
+
+               function select_category($format='',$selected='')
+               {
+                       switch($format)
+                       {
+                               case 'select':
+                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('cat_select'));
+                                       break;
+                               case 'filter':
+                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('cat_filter'));
+                                       break;
+                       }
+
+                       $categories= $this->so->get_type_list();
+
+                       while (is_array($categories) && list(,$category) = 
each($categories))
+                       {
+                               $sel_category = '';
+                               if ($category['id']==$selected)
+                               {
+                                       $sel_category = 'selected';
+                               }
+
+                               $category_list[] = array
+                               (
+                                       'cat_id'        => $category['id'],
+                                       'name'          => $category['num'],
+                                       'selected'      => $sel_category
+                               );
+                       }
+
+                       for ($i=0;$i<count($category_list);$i++)
+                       {
+                               if ($category_list[$i]['selected'] != 
'selected')
+                               {
+                                       unset($category_list[$i]['selected']);
+                               }
+                       }
+
+                       return $category_list;
+               }
+
+               function write_off_period_list($selected='')
+               {
+
+                       
$GLOBALS['phpgw']->xslttpl->add_file(array('cat_select'));
+
+
+                       $categories= $this->so->write_off_period_list();
+
+                       while (is_array($categories) && list(,$category) = 
each($categories))
+                       {
+                               $sel_category = '';
+                               if ($category['period']==$selected)
+                               {
+                                       $sel_category = 'selected';
+                               }
+
+                               $category_list[] = array
+                               (
+                                       'cat_id'        => $category['period'],
+                                       'name'          => $category['period'],
+                                       'selected'      => $sel_category
+                               );
+                       }
+
+                       for ($i=0;$i<count($category_list);$i++)
+                       {
+                               if ($category_list[$i]['selected'] != 
'selected')
+                               {
+                                       unset($category_list[$i]['selected']);
+                               }
+                       }
+
+                       return $category_list;
+               }
+
+
+
+
+               function save_investment($values)
+               {
+                       while (is_array($values['location']) && list(,$value) = 
each($values['location']))
+                       {
+                               if($value)
+                               {
+                                       $location[] = $value;
+                               }
+                       }
+
+                       $values['location_code']=implode("-", $location);
+
+//_debug_array($values);
+
+                       $values['date'] = 
$this->bocommon->date_to_timestamp($values['date']);
+                       $values['date']= 
date($this->bocommon->dateformat,$values['date']);
+
+                       $values['initial_value']        = 
abs($values['initial_value']);
+
+                       if($values['type']=='funding')
+                       {
+                               $values['initial_value'] = 
-$values['initial_value'];
+                       }
+
+                       if($values['new_period'])
+                       {
+                               $values['period'] = $values['new_period'];
+                               unset($values['new_period']);
+                       }
+
+                       if($values['extra']['p_num'])
+                       {
+                               $boadmin_entity         = 
CreateObject($this->currentapp.'.boadmin_entity');
+                               $category = 
$boadmin_entity->read_single_category($values['extra']['p_entity_id'],$values['extra']['p_cat_id']);
+                               $values['entity_id']    = 
$values['extra']['p_num'];
+                               $values['entity_type']  =$category['name'];
+
+                       }
+                       else
+                       {
+                               $values['entity_id']    = 
$values['location_code'];
+                               $values['entity_type']  ='property';
+                       }
+
+
+                       $receipt=$this->so->save_investment($values);
+
+                       return $receipt;
+               }
+
+
+               function update_investment($values)
+               {
+
+                       
$date_array=$this->bocommon->date_array($values['date']);
+
+                       $date = mktime 
(2,0,0,$date_array['month'],$date_array['day'],$date_array['year']);
+                       $date= date($this->bocommon->dateformat,$date);
+
+                       $new_index=str_replace(",",".",$values['new_index']);
+
+                       while($entry=each($values['update']))
+                       {
+                               $local_error='';
+                               $n=$entry[0];
+
+                               if ($values['value'][$n])
+                               {
+                                       if ((abs($values['value'][$n])- 
abs(($values['initial_value'][$n]*$new_index)))<0)
+                                       {
+                                               $new_value=0;
+                                               
$new_index=$values['value'][$n]/$values['initial_value'][$n];
+                                       }
+                                       else
+                                       {
+                                               
$new_value=$values['value'][$n]-($values['initial_value'][$n]*$new_index);
+                                       }
+
+                                       $update[]=array(
+                                               'entity_id'             
=>$values['entity_id'][$n],
+                                               'invest_id'             
=>$values['investment_id'][$n],
+                                               'new_index'             
=>$new_index,
+                                               'new_value'             
=>$new_value,
+                                               'initial_value' 
=>$values['initial_value'][$n],
+                                               'date'                  =>$date
+                                               );
+                               }
+                       }
+                       $this->so->update_investment($update);
+               }
+
+
+               function filter($format='',$selected='')
+               {
+                       switch($format)
+                       {
+                               case 'select':
+                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('filter_select'));
+                                       break;
+                               case 'filter':
+                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('filter_filter'));
+                                       break;
+                       }
+
+                       $filters[0][id]='investment';
+                       $filters[0][name]=lang('Investment');
+                       $filters[1][id]='funding';
+                       $filters[1][name]=lang('Funding');
+
+                       while (is_array($filters) && list(,$filter) = 
each($filters))
+                       {
+                               $sel_filter = '';
+                               if ($filter['id']==$selected)
+                               {
+                                       $sel_filter = 'selected';
+                               }
+
+                               $filter_list[] = array
+                               (
+                                       'id'    => $filter['id'],
+                                       'name'          => $filter['name'],
+                                       'selected'      => $sel_filter
+                               );
+                       }
+
+                       for ($i=0;$i<count($filter_list);$i++)
+                       {
+                               if ($filter_list[$i]['selected'] != 'selected')
+                               {
+                                       unset($filter_list[$i]['selected']);
+                               }
+                       }
+
+                       return $filter_list;
+               }
+
+
+               function read_single($entity_id,$investment_id)
+               {
+                       $history        = 
$this->so->read_single($entity_id,$investment_id,$this->start,$this->allrows);
+
+                       $this->total_records = $this->so->total_records;
+
+                       return $history;
+               }
+
+
+               function select_part_of_town($part_of_town_id)
+               {
+                       return 
$this->socommon->select_part_of_town($part_of_town_id);
+               }
+
+
+               function delete($entity_id,$investment_id,$index_count)
+               {
+                       
$this->so->delete($entity_id,$investment_id,$index_count);
+               }
+       }
+?>
Index: property/inc/class.boinvoice.inc.php
diff -u property/inc/class.boinvoice.inc.php:1.16 
property/inc/class.boinvoice.inc.php:1.17
--- property/inc/class.boinvoice.inc.php:1.16   Fri Jan 27 14:05:43 2006
+++ property/inc/class.boinvoice.inc.php        Fri Feb  3 12:05:49 2006
@@ -1,725 +1,725 @@
-<?php
-       /**
-       * phpGroupWare - property: a Facilities Management System.
-       *
-       * @author Sigurd Nes <address@hidden>
-       * @copyright Copyright (C) 2003-2005 Free Software Foundation, Inc. 
http://www.fsf.org/
-       * @license http://www.gnu.org/licenses/gpl.html GNU General Public 
License
-       * @internal Development of this application was funded by 
http://www.bergen.kommune.no/bbb_/ekstern/
-       * @package property
-       * @subpackage eco
-       * @version $Id: class.boinvoice.inc.php,v 1.16 2006/01/27 14:05:43 
sigurdne Exp $
-       */
-
-       /**
-        * Description
-        * @package property
-        */
-
-       class boinvoice
-       {
-               var $db = '';
-
-               function boinvoice($session=False)
-               {
-                       $this->db                       = $GLOBALS['phpgw']->db;
-                       $this->currentapp       = 
$GLOBALS['phpgw_info']['flags']['currentapp'];
-                       $this->so              = 
CreateObject($this->currentapp.'.soinvoice',True);
-                       $this->bocommon    = 
CreateObject($this->currentapp.'.bocommon');
-                       $this->account_id = 
$GLOBALS['phpgw_info']['user']['account_id'];
-
-                       if ($session)
-                       {
-                               $this->read_sessiondata();
-                               $this->use_session = True;
-                       }
-
-                       $start                  = 
get_var('start',array('POST','GET'));
-                       $query                  = 
get_var('query',array('POST','GET'));
-                       $sort                   = 
get_var('sort',array('POST','GET'));
-                       $order                  = 
get_var('order',array('POST','GET'));
-                       $filter                 = 
get_var('filter',array('POST','GET'));
-                       $cat_id                 = 
get_var('cat_id',array('POST','GET'));
-                       $user_lid               = 
get_var('user_lid',array('POST','GET'));
-                       $allrows                = 
get_var('allrows',array('POST','GET'));
-
-                       if ($start)
-                       {
-                               $this->start=$start;
-                       }
-                       else
-                       {
-                               $this->start=0;
-                       }
-
-                       if(isset($query))
-                       {
-                               $this->query = $query;
-                       }
-                       if(!empty($filter))
-                       {
-                               $this->filter = $filter;
-                       }
-                       if(isset($sort))
-                       {
-                               $this->sort = $sort;
-                       }
-                       if(isset($order))
-                       {
-                               $this->order = $order;
-                       }
-                       if(isset($cat_id))
-                       {
-                               $this->cat_id = $cat_id;
-                       }
-                       if(isset($user_lid))
-                       {
-                               $this->user_lid = $user_lid;
-                       }
-                       if(isset($allrows))
-                       {
-                               $this->allrows = $allrows;
-                       }
-               }
-
-
-               function save_sessiondata($data)
-               {
-                       if ($this->use_session)
-                       {
-                               
$GLOBALS['phpgw']->session->appsession('session_data','invoice',$data);
-                       }
-               }
-
-               function read_sessiondata()
-               {
-                       $data = 
$GLOBALS['phpgw']->session->appsession('session_data',invoice);
-
-//     _debug_array($data);
-
-                       $this->start            = $data['start'];
-                       $this->query            = $data['query'];
-                       $this->filter           = $data['filter'];
-                       $this->sort                     = $data['sort'];
-                       $this->order            = $data['order'];
-                       $this->cat_id           = $data['cat_id'];
-                       $this->user_lid         = $data['user_lid'];
-                       $this->sub                      = $data['sub'];
-                       $this->allrows          = $data['allrows'];
-               }
-
-               function 
read_invoice($paid='',$start_date='',$end_date='',$vendor_id='',$loc1='',$workorder_id='',$voucher_id='')
-               {
-                       $invoice = $this->so->read_invoice(array('start' => 
$this->start,'query' => $this->query,'sort' => $this->sort,'order' => 
$this->order,
-                                                                               
        'user_lid' => $this->user_lid,'cat_id' => $this->cat_id, 'paid' => 
$paid,
-                                                                               
        'start_date'=>$start_date,'end_date'=>$end_date,'vendor_id'=>$vendor_id,
-                                                                               
        'loc1'=>$loc1,'workorder_id'=>$workorder_id,'allrows'=>$this->allrows,
-                                                                               
        'voucher_id'=>$voucher_id));
-
-                       $this->total_records = $this->so->total_records;
-                       $this->end_time = $this->so->end_time;
-
-                       return $invoice;
-               }
-
-               function read_invoice_sub($voucher_id='',$paid='')
-               {
-                       $invoice = $this->so->read_invoice_sub(array('start' => 
$this->start,'query' => $this->query,'sort' => $this->sort,'order' => 
$this->order,
-                                                                               
        'user_lid' => $this->user_lid,'cat_id' => 
$this->cat_id,'voucher_id'=>$voucher_id,'paid' => $paid));
-                       $this->total_records = $this->so->total_records;
-                       return $invoice;
-               }
-
-               function read_remark($id='',$paid='')
-               {
-                       return $remark = $this->so->read_remark($id,$paid);
-               }
-
-
-               function 
read_consume($start_date='',$end_date='',$vendor_id='',$loc1='',$workorder_id='',$b_account_class='',$district_id='')
-               {
-                       $invoice = $this->so->read_consume(array('start' => 
$this->start,'query' => $this->query,'sort' => $this->sort,'order' => 
$this->order,
-                                                                               
        'user_lid' => $this->user_lid,'cat_id' => $this->cat_id,
-                                                                               
        'start_date'=>$start_date,'end_date'=>$end_date,'vendor_id'=>$vendor_id,
-                                                                               
        'loc1'=>$loc1,'workorder_id'=>$workorder_id,'b_account_class' 
=>$b_account_class,
-                                                                               
        'district_id' => $district_id ));
-
-                       $this->total_records = $this->so->total_records;
-
-                       return $invoice;
-               }
-
-
-               function update_invoice($values)
-               {
-
-                       return $this->so->update_invoice($values);
-
-               }
-
-
-               function update_invoice_sub($values)
-               {
-                       return $this->so->update_invoice_sub($values);
-               }
-
-               function select_account_class($selected='')
-               {
-
-                       $b_account_class_list= 
$this->so->select_account_class();
-
-                       while (is_array($b_account_class_list) && list(,$class) 
= each($b_account_class_list))
-                       {
-                               $sel_class = '';
-                               if ($class['id']==$selected)
-                               {
-                                       $sel_class = 'selected';
-                               }
-
-                               $class_list[] = array
-                               (
-                                       'id'    => $class['id'],
-                                       'name'          => $class['name'],
-                                       'selected'      => $sel_class
-                               );
-                       }
-
-                       for ($i=0;$i<count($class_list);$i++)
-                       {
-                               if ($class_list[$i]['selected'] != 'selected')
-                               {
-                                       unset($class_list[$i]['selected']);
-                               }
-                       }
-
-                       return $class_list;
-               }
-
-
-
-               function period_list($selected='')
-               {
-                       for ($i=1; $i<=12; $i++)
-                       {
-                               $period_list[$i]['id'] = $i;
-                               $period_list[$i]['name'] = $i;
-                               if($i==$selected)
-                               {
-                                       $period_list[$i]['selected'] = 
'selected';
-                               }
-                       }
-                       return $period_list;
-               }
-
-               function tax_code_list($selected='')
-               {
-                       $tax_codes=$this->so->tax_code_list();
-
-                       while (is_array($tax_codes) && list(,$code) = 
each($tax_codes))
-                       {
-                               $sel_code = '';
-                               if ($code['id']==$selected)
-                               {
-                                       $sel_code = 'selected';
-                               }
-
-                               $tax_code_list[] = array
-                               (
-                                       'id'                    => $code['id'],
-                                       'selected'              => $sel_code
-                               );
-                       }
-
-                       for ($i=0;$i<count($tax_code_list);$i++)
-                       {
-                               if ($tax_code_list[$i]['selected'] != 
'selected')
-                               {
-                                       unset($tax_code_list[$i]['selected']);
-                               }
-                       }
-
-                       return $tax_code_list;
-               }
-
-               function update_period($voucher_id='',$period='')
-               {
-                       return $this->so->update_period($voucher_id,$period);
-               }
-
-               function increment_bilagsnr()
-               {
-
-                       return $this->so->increment_bilagsnr();
-
-               }
-
-               function next_bilagsnr()
-               {
-                       return $this->so->next_bilagsnr();
-               }
-
-               function check_vendor($vendor_id)
-               {
-
-                       return $this->so->check_vendor($vendor_id);
-               }
-
-
-               function get_lisfm_ecoart($selected='')
-               {
-                       $arts=$this->so->get_lisfm_ecoart();
-
-                       while (is_array($arts) && list(,$art) = each($arts))
-                       {
-                               $sel_art = '';
-                               if ($art['id']==$selected)
-                               {
-                                       $sel_art = 'selected';
-                               }
-
-                               $art_list[] = array
-                               (
-                                       'id'            => $art['id'],
-                                       'num'           => $art['num'],
-                                       'selected'      => $sel_art
-                               );
-                       }
-
-                       for ($i=0;$i<count($art_list);$i++)
-                       {
-                               if ($art_list[$i]['selected'] != 'selected')
-                               {
-                                       unset($art_list[$i]['selected']);
-                               }
-                       }
-
-                       return $art_list;
-               }
-       //----------
-
-               function select_category($format='',$selected='')
-               {
-                       switch($format)
-                       {
-                               case 'select':
-                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('cat_select'));
-                                       break;
-                               case 'filter':
-                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('cat_filter'));
-                                       break;
-                       }
-
-                       $categories= $this->so->get_type_list();
-
-                       while (is_array($categories) && list(,$category) = 
each($categories))
-                       {
-                               $sel_category = '';
-                               if ($category['id']==$selected)
-                               {
-                                       $sel_category = 'selected';
-                               }
-
-                               $category_list[] = array
-                               (
-                                       'cat_id'        => $category['id'],
-                                       'name'          => $category['num'],
-                                       'selected'      => $sel_category
-                               );
-                       }
-
-                       for ($i=0;$i<count($category_list);$i++)
-                       {
-                               if ($category_list[$i]['selected'] != 
'selected')
-                               {
-                                       unset($category_list[$i]['selected']);
-                               }
-                       }
-
-                       return $category_list;
-               }
-
-
-               function 
get_invoice_user_list($format='',$selected='',$extra='',$default='')
-               {
-                       if(!$selected && $default)
-                       {
-                               $selected = $default;
-                       }
-
-                       switch($format)
-                       {
-                               case 'select':
-                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('user_lid_select'));
-                                       break;
-                               case 'filter':
-                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('user_lid_filter'));
-                                       break;
-                       }
-
-                       if (is_array($extra))
-                       {
-                               foreach($extra as $extra_user)
-                               {
-                                       $users_extra[]=array
-                                       (
-                                               'account_lid' => $extra_user,
-                                               'account_firstname' => 
lang($extra_user)
-                                       );
-                               }
-                       }
-
-                       $users= $this->so->get_invoice_user_list();
-                       if (is_array($users_extra) && is_array($users))
-                       {
-                               $users = $users_extra + $users;
-                       }
-
-                       while (is_array($users) && list(,$user) = each($users))
-                       {
-                               $sel_user = '';
-                               if ($user['account_lid']==$selected)
-                               {
-                                       $sel_user = 'selected';
-                               }
-
-                               $user_list[] = array
-                               (
-                                       'user_lid'      => $user['account_lid'],
-                                       'name'          => 
$user['account_lastname'].' '.$user['account_firstname'],
-                                       'selected'      => $sel_user
-                               );
-                       }
-
-                       for ($i=0;$i<count($user_list);$i++)
-                       {
-                               if ($user_list[$i]['selected'] != 'selected')
-                               {
-                                       unset($user_list[$i]['selected']);
-                               }
-                       }
-
-//_debug_array($user_list);
-                       return $user_list;
-               }
-
-
-
-               function get_type_list($selected='')
-               {
-                       $types=$this->so->get_type_list();
-
-                       while (is_array($types) && list(,$type) = each($types))
-                       {
-                               $sel_type = '';
-                               if ($type['id']==$selected)
-                               {
-                                       $sel_type = 'selected';
-                               }
-
-                               $type_list[] = array
-                               (
-                                       'id'            => $type['id'],
-                                       'num'           => $type['num'],
-                                       'selected'      => $sel_type
-                               );
-                       }
-
-                       for ($i=0;$i<count($type_list);$i++)
-                       {
-                               if ($type_list[$i]['selected'] != 'selected')
-                               {
-                                       unset($type_list[$i]['selected']);
-                               }
-                       }
-
-                       return $type_list;
-               }
-
-       //----------
-               function select_dimb_list($selected='')
-               {
-                       $dimbs=$this->so->select_dimb_list();
-
-                       while (is_array($dimbs) && list(,$dimb) = each($dimbs))
-                       {
-                               $sel_dimb = '';
-                               if ($dimb['id']==$selected)
-                               {
-                                       $sel_dimb = 'selected';
-                               }
-
-                               $dimb_list[] = array
-                               (
-                                       'id'            => $dimb['id'],
-                                       'num'           => $dimb['num'],
-                                       'selected'      => $sel_dimb
-                               );
-                       }
-
-                       for ($i=0;$i<count($dimb_list);$i++)
-                       {
-                               if ($dimb_list[$i]['selected'] != 'selected')
-                               {
-                                       unset($dimb_list[$i]['selected']);
-                               }
-                       }
-
-                       return $dimb_list;
-               }
-
-       //-------------------
-               function select_dimd_list($selected='')
-               {
-                       $dimds=$this->so->select_dimd_list();
-
-                       while (is_array($dimds) && list(,$dimd) = each($dimds))
-                       {
-                               $sel_dimd = '';
-                               if ($dimd['id']==$selected)
-                               {
-                                       $sel_dimd = 'selected';
-                               }
-
-                               $dimd_list[] = array
-                               (
-                                       'id'            => $dimd['id'],
-                                       'num'           => $dimd['num'],
-                                       'selected'      => $sel_dimd
-                               );
-                       }
-
-                       for ($i=0;$i<count($dimd_list);$i++)
-                       {
-                               if ($dimd_list[$i]['selected'] != 'selected')
-                               {
-                                       unset($dimd_list[$i]['selected']);
-                               }
-                       }
-
-                       return $dimd_list;
-               }
-
-               function select_tax_code_list($selected='')
-               {
-                       $tax_codes=$this->so->select_tax_code_list();
-
-                       while (is_array($tax_codes) && list(,$tax_code) = 
each($tax_codes))
-                       {
-                               $sel_tax_code = '';
-                               if ($tax_code['id']==$selected)
-                               {
-                                       $sel_tax_code = 'selected';
-                               }
-
-                               $tax_code_list[] = array
-                               (
-                                       'id'            => $tax_code['id'],
-                                       'num'           => $tax_code['num'],
-                                       'selected'      => $sel_tax_code
-                               );
-                       }
-
-                       for ($i=0;$i<count($tax_code_list);$i++)
-                       {
-                               if ($tax_code_list[$i]['selected'] != 
'selected')
-                               {
-                                       unset($tax_code_list[$i]['selected']);
-                               }
-                       }
-                       return $tax_code_list;
-               }
-
-               function delete($params)
-               {
-                       if (is_array($params))
-                       {
-                               $this->so->delete($params[0]);
-                       }
-                       else
-                       {
-                               $this->so->delete($params);
-                       }
-               }
-
-               function add($values,$debug='')
-               {
-                       $this->soXport    = 
CreateObject($this->currentapp.'.soXport');
-                       if($values['loc1']=$values['location']['loc1'])
-                       {
-                               $values['dima']=implode('',$values['location']);
-                       }
-
-                       $values['spbudact_code']=$values['b_account_id'];
-                       $values['fakturanr']=$values['invoice_num'];
-                       $values['spvend_code']=$values['vendor_id'];
-
-                       $values['belop'] = 
str_replace('kr','',$values['amount']);
-                       $values['belop'] = str_replace(' ','',$values['belop']);
-                       $values['belop'] = 
str_replace(',','.',$values['belop']);
-                       $values['godkjentbelop']=$values['belop'];
-
-                       $values['fakturadato'] = 
date($this->bocommon->dateformat,mktime(2,0,0,$values['smonth'],$values['sday'],$values['syear']));
-
-                       if($values['num_days'])
-                       {
-                               $values['forfallsdato'] = 
date($this->bocommon->dateformat,mktime(2,0,0,$values['smonth'],$values['sday'],$values['syear'])+(86400*$values['num_days']));
-                       }
-                       else
-                       {
-                               $values['forfallsdato'] = 
date($this->bocommon->dateformat,mktime(2,0,0,$values['emonth'],$values['eday'],$values['eyear']));
-                       }
-
-                       $values['artid']                        = 
$values['art'];
-                       $values['periode']                      = 
$values['smonth'];
-                       $values['dimb']                         = 
$values['dim_b'];
-                       $values['oppsynsmannid']        = $values['janitor'];
-                       $values['saksbehandlerid']      = $values['supervisor'];
-                       $values['budsjettansvarligid'] = 
$values['budget_responsible'];
-                       $values['kildeid']                      = 1;
-                       $values['kidnr']                        = 
$values['kid_nr'];
-                       $values['typeid']                       = 
$values['type'];
-                       if($order_type = 
$this->soXport->check_order(intval($values['order'])))
-                       {
-                               if($order_type=='workorder')
-                               {
-                                       $soworkorder = 
CreateObject($this->currentapp.'.soworkorder');
-                                       $soproject = 
CreateObject($this->currentapp.'.soproject');
-                                       $workorder      = 
$soworkorder->read_single($values['order']);
-                                       $project        = 
$soproject->read_single($workorder['project_id']);
-
-                                       $values['spvend_code']  = 
$workorder['vendor_id'];
-                                       $values['spbudact_code']        = 
$workorder['b_account_id'];
-                                       $values['location_code']        
=$project['location_code'];
-                                       $values['dima']                         
=str_replace('-','',$project['location_code']);
-                                       $values['vendor_name']          = 
$this->get_vendor_name($workorder['vendor_id']);
-                                       $values['pmwrkord_code']        = 
$values['order'];
-                                       $values['project_id']                   
= $workorder['project_id'];
-
-                                       $values = 
$this->set_responsible($values,$workorder['user_id'],$workorder['b_account_id']);
-
-                                       if($values['auto_tax'])
-                                       {
-                                               $values['mvakode'] = 
$this->soXport->auto_tax($values['dima']);
-                                               $values['mvakode'] = 
$this->soXport->tax_b_account_override($values['mvakode'],$values['spbudact_code']);
-                                               $values['mvakode'] = 
$this->soXport->tax_vendor_override($values['mvakode'],$values['spvend_code']);
-                                               $values['kostra_id'] = 
$this->soXport->get_kostra_id($values['dima']);
-                                       }
-
-                                       $buffer[0]=$values;
-                               }
-
-                               if($order_type=='s_agreement')
-                               {
-                                       $sos_agreement = 
CreateObject($this->currentapp.'.sos_agreement');
-                                       $s_agreement = 
$sos_agreement->read_single(array('s_agreement_id'=>$values['order']));
-
-                                       $values['spvend_code']          = 
$s_agreement['vendor_id'];
-                                       $values['spbudact_code']        = 
$s_agreement['b_account_id'];
-                                       $values['vendor_name']          = 
$this->get_vendor_name($s_agreement['vendor_id']);
-                                       $values['pmwrkord_code']        = 
intval($values['order']);
-                                       $values = 
$this->set_responsible($values,$s_agreement['user_id'],$s_agreement['b_account_id']);
-
-
-                                       $s_agreement_detail = 
$sos_agreement->read(array('allrows'=>True,'s_agreement_id'=>$values['order'],'detail'=>True));
-
-                                       $sum_agreement=0;
-                                       for 
($i=0;$i<count($s_agreement_detail);$i++)
-                                       {
-                                               $sum_agreement = $sum_agreement 
+ $s_agreement_detail[$i]['cost'];
-                                       }
-
-
-                                       for 
($i=0;$i<count($s_agreement_detail);$i++)
-                                       {
-                                               $buffer[$i]=$values;
-
-                                               $buffer[$i]['location_code']    
=$s_agreement_detail[$i]['location_code'];
-                                               $buffer[$i]['dima']             
                =str_replace('-','',$s_agreement_detail[$i]['location_code']);
-
-
-                                               $buffer[$i]['belop']    =       
round($values['belop'] / $sum_agreement * $s_agreement_detail[$i]['cost'],2);
-                                               $buffer[$i]['godkjentbelop'] 
=$buffer[$i]['belop'];
-
-                                               if($values['auto_tax'])
-                                               {
-                                                       $buffer[$i]['mvakode'] 
= $this->soXport->auto_tax($buffer[$i]['dima']);
-                                                       $buffer[$i]['mvakode'] 
= 
$this->soXport->tax_b_account_override($buffer[$i]['mvakode'],$buffer[$i]['spbudact_code']);
-                                                       $buffer[$i]['mvakode'] 
= 
$this->soXport->tax_vendor_override($buffer[$i]['mvakode'],$buffer[$i]['spvend_code']);
-                                                       
$buffer[$i]['kostra_id'] = $this->soXport->get_kostra_id($buffer[$i]['dima']);
-                                               }
-                                       }
-                               }
-                       }
-                       else
-                       {
-                               if($values['auto_tax'])
-                               {
-                                       $values['mvakode'] = 
$this->soXport->auto_tax($values['loc1']);
-                                       $values['mvakode'] = 
$this->soXport->tax_b_account_override($values['mvakode'],$values['spbudact_code']);
-                                       $values['mvakode'] = 
$this->soXport->tax_vendor_override($values['mvakode'],$values['spvend_code']);
-                                       $values['kostra_id'] = 
$this->soXport->get_kostra_id($values['loc1']);
-                               }
-
-                               $buffer[0]=$values;
-                       }
-
-                       if($debug)
-                       {
-                               return $buffer;
-                       }
-
-                       if($this->soXport->add($buffer)>0)
-                       {
-                               $receipt['message'][] = 
array('msg'=>lang('Invoice %1 is added',$values['bilagsnr']));
-                       }
-                       else
-                       {
-                               $receipt['error'][] = 
array('msg'=>lang('Invoice is NOT added!'));
-                       }
-                       return $receipt;
-               }
-
-               function get_vendor_name($vendor_id='')
-               {
-                       $contacts       = 
CreateObject($this->currentapp.'.soactor');
-                       $contacts->role='vendor';
-
-                       $vendor_data    = 
$contacts->read_single(array('actor_id'=>$vendor_id));
-                       if(is_array($vendor_data))
-                       {
-                               foreach($vendor_data['attributes'] as 
$attribute)
-                               {
-                                       if($attribute['name']=='org_name')
-                                       {
-                                               return $attribute['value'];
-                                       }
-                               }
-                       }
-               }
-
-               function set_responsible($values,$user_id='',$b_account_id='')
-               {
-                       if (!$values['budget_responsible'])
-                       {
-                               $values['budget_responsible'] = 
$this->soXport->get_responsible($b_account_id);
-                               $values['budsjettansvarligid'] = 
$values['budget_responsible'];
-                       }
-
-                       $acl2   = 
CreateObject($this->currentapp.'.acl2',$user_id);
-                       if($acl2->check('.invoice',32) && 
!$acl2->check('.invoice',64)):
-                       {
-                               $values['janitor']      = 
$GLOBALS['phpgw']->accounts->id2name($user_id);
-                               $values['oppsynsmannid']        = 
$values['janitor'];
-                       }
-       //              elseif((!$acl2->check('.invoice',32) && 
$acl2->check('.invoice',64)) || ($acl2->check('.invoice',32) && 
$acl2->check('.invoice',64))):
-                       elseif($acl2->check('.invoice',64)):
-                       {
-                               $values['supervisor']   = 
$GLOBALS['phpgw']->accounts->id2name($user_id);
-                               $values['saksbehandlerid']      = 
$values['supervisor'];
-                       }
-                       endif;
-
-                       return $values;
-               }
-       }
-?>
+<?php
+       /**
+       * phpGroupWare - property: a Facilities Management System.
+       *
+       * @author Sigurd Nes <address@hidden>
+       * @copyright Copyright (C) 2003-2005 Free Software Foundation, Inc. 
http://www.fsf.org/
+       * @license http://www.gnu.org/licenses/gpl.html GNU General Public 
License
+       * @internal Development of this application was funded by 
http://www.bergen.kommune.no/bbb_/ekstern/
+       * @package property
+       * @subpackage eco
+       * @version $Id: class.boinvoice.inc.php,v 1.17 2006/02/03 12:05:49 
sigurdne Exp $
+       */
+
+       /**
+        * Description
+        * @package property
+        */
+
+       class boinvoice
+       {
+               var $db = '';
+
+               function boinvoice($session=False)
+               {
+                       $this->db                       = $GLOBALS['phpgw']->db;
+                       $this->currentapp       = 
$GLOBALS['phpgw_info']['flags']['currentapp'];
+                       $this->so              = 
CreateObject($this->currentapp.'.soinvoice',True);
+                       $this->bocommon    = 
CreateObject($this->currentapp.'.bocommon');
+                       $this->account_id = 
$GLOBALS['phpgw_info']['user']['account_id'];
+
+                       if ($session)
+                       {
+                               $this->read_sessiondata();
+                               $this->use_session = True;
+                       }
+
+                       $start                  = 
get_var('start',array('POST','GET'));
+                       $query                  = 
get_var('query',array('POST','GET'));
+                       $sort                   = 
get_var('sort',array('POST','GET'));
+                       $order                  = 
get_var('order',array('POST','GET'));
+                       $filter                 = 
get_var('filter',array('POST','GET'));
+                       $cat_id                 = 
get_var('cat_id',array('POST','GET'));
+                       $user_lid               = 
get_var('user_lid',array('POST','GET'));
+                       $allrows                = 
get_var('allrows',array('POST','GET'));
+
+                       if ($start)
+                       {
+                               $this->start=$start;
+                       }
+                       else
+                       {
+                               $this->start=0;
+                       }
+
+                       if(isset($query))
+                       {
+                               $this->query = $query;
+                       }
+                       if(!empty($filter))
+                       {
+                               $this->filter = $filter;
+                       }
+                       if(isset($sort))
+                       {
+                               $this->sort = $sort;
+                       }
+                       if(isset($order))
+                       {
+                               $this->order = $order;
+                       }
+                       if(isset($cat_id))
+                       {
+                               $this->cat_id = $cat_id;
+                       }
+                       if(isset($user_lid))
+                       {
+                               $this->user_lid = $user_lid;
+                       }
+                       if(isset($allrows))
+                       {
+                               $this->allrows = $allrows;
+                       }
+               }
+
+
+               function save_sessiondata($data)
+               {
+                       if ($this->use_session)
+                       {
+                               
$GLOBALS['phpgw']->session->appsession('session_data','invoice',$data);
+                       }
+               }
+
+               function read_sessiondata()
+               {
+                       $data = 
$GLOBALS['phpgw']->session->appsession('session_data',invoice);
+
+//     _debug_array($data);
+
+                       $this->start            = $data['start'];
+                       $this->query            = $data['query'];
+                       $this->filter           = $data['filter'];
+                       $this->sort                     = $data['sort'];
+                       $this->order            = $data['order'];
+                       $this->cat_id           = $data['cat_id'];
+                       $this->user_lid         = $data['user_lid'];
+                       $this->sub                      = $data['sub'];
+                       $this->allrows          = $data['allrows'];
+               }
+
+               function 
read_invoice($paid='',$start_date='',$end_date='',$vendor_id='',$loc1='',$workorder_id='',$voucher_id='')
+               {
+                       $invoice = $this->so->read_invoice(array('start' => 
$this->start,'query' => $this->query,'sort' => $this->sort,'order' => 
$this->order,
+                                                                               
        'user_lid' => $this->user_lid,'cat_id' => $this->cat_id, 'paid' => 
$paid,
+                                                                               
        'start_date'=>$start_date,'end_date'=>$end_date,'vendor_id'=>$vendor_id,
+                                                                               
        'loc1'=>$loc1,'workorder_id'=>$workorder_id,'allrows'=>$this->allrows,
+                                                                               
        'voucher_id'=>$voucher_id));
+
+                       $this->total_records = $this->so->total_records;
+                       $this->end_time = $this->so->end_time;
+
+                       return $invoice;
+               }
+
+               function read_invoice_sub($voucher_id='',$paid='')
+               {
+                       $invoice = $this->so->read_invoice_sub(array('start' => 
$this->start,'query' => $this->query,'sort' => $this->sort,'order' => 
$this->order,
+                                                                               
        'user_lid' => $this->user_lid,'cat_id' => 
$this->cat_id,'voucher_id'=>$voucher_id,'paid' => $paid));
+                       $this->total_records = $this->so->total_records;
+                       return $invoice;
+               }
+
+               function read_remark($id='',$paid='')
+               {
+                       return $remark = $this->so->read_remark($id,$paid);
+               }
+
+
+               function 
read_consume($start_date='',$end_date='',$vendor_id='',$loc1='',$workorder_id='',$b_account_class='',$district_id='')
+               {
+                       $invoice = $this->so->read_consume(array('start' => 
$this->start,'query' => $this->query,'sort' => $this->sort,'order' => 
$this->order,
+                                                                               
        'user_lid' => $this->user_lid,'cat_id' => $this->cat_id,
+                                                                               
        'start_date'=>$start_date,'end_date'=>$end_date,'vendor_id'=>$vendor_id,
+                                                                               
        'loc1'=>$loc1,'workorder_id'=>$workorder_id,'b_account_class' 
=>$b_account_class,
+                                                                               
        'district_id' => $district_id ));
+
+                       $this->total_records = $this->so->total_records;
+
+                       return $invoice;
+               }
+
+
+               function update_invoice($values)
+               {
+
+                       return $this->so->update_invoice($values);
+
+               }
+
+
+               function update_invoice_sub($values)
+               {
+                       return $this->so->update_invoice_sub($values);
+               }
+
+               function select_account_class($selected='')
+               {
+
+                       $b_account_class_list= 
$this->so->select_account_class();
+
+                       while (is_array($b_account_class_list) && list(,$class) 
= each($b_account_class_list))
+                       {
+                               $sel_class = '';
+                               if ($class['id']==$selected)
+                               {
+                                       $sel_class = 'selected';
+                               }
+
+                               $class_list[] = array
+                               (
+                                       'id'    => $class['id'],
+                                       'name'          => $class['name'],
+                                       'selected'      => $sel_class
+                               );
+                       }
+
+                       for ($i=0;$i<count($class_list);$i++)
+                       {
+                               if ($class_list[$i]['selected'] != 'selected')
+                               {
+                                       unset($class_list[$i]['selected']);
+                               }
+                       }
+
+                       return $class_list;
+               }
+
+
+
+               function period_list($selected='')
+               {
+                       for ($i=1; $i<=12; $i++)
+                       {
+                               $period_list[$i]['id'] = $i;
+                               $period_list[$i]['name'] = $i;
+                               if($i==$selected)
+                               {
+                                       $period_list[$i]['selected'] = 
'selected';
+                               }
+                       }
+                       return $period_list;
+               }
+
+               function tax_code_list($selected='')
+               {
+                       $tax_codes=$this->so->tax_code_list();
+
+                       while (is_array($tax_codes) && list(,$code) = 
each($tax_codes))
+                       {
+                               $sel_code = '';
+                               if ($code['id']==$selected)
+                               {
+                                       $sel_code = 'selected';
+                               }
+
+                               $tax_code_list[] = array
+                               (
+                                       'id'                    => $code['id'],
+                                       'selected'              => $sel_code
+                               );
+                       }
+
+                       for ($i=0;$i<count($tax_code_list);$i++)
+                       {
+                               if ($tax_code_list[$i]['selected'] != 
'selected')
+                               {
+                                       unset($tax_code_list[$i]['selected']);
+                               }
+                       }
+
+                       return $tax_code_list;
+               }
+
+               function update_period($voucher_id='',$period='')
+               {
+                       return $this->so->update_period($voucher_id,$period);
+               }
+
+               function increment_bilagsnr()
+               {
+
+                       return $this->so->increment_bilagsnr();
+
+               }
+
+               function next_bilagsnr()
+               {
+                       return $this->so->next_bilagsnr();
+               }
+
+               function check_vendor($vendor_id)
+               {
+
+                       return $this->so->check_vendor($vendor_id);
+               }
+
+
+               function get_lisfm_ecoart($selected='')
+               {
+                       $arts=$this->so->get_lisfm_ecoart();
+
+                       while (is_array($arts) && list(,$art) = each($arts))
+                       {
+                               $sel_art = '';
+                               if ($art['id']==$selected)
+                               {
+                                       $sel_art = 'selected';
+                               }
+
+                               $art_list[] = array
+                               (
+                                       'id'            => $art['id'],
+                                       'num'           => $art['num'],
+                                       'selected'      => $sel_art
+                               );
+                       }
+
+                       for ($i=0;$i<count($art_list);$i++)
+                       {
+                               if ($art_list[$i]['selected'] != 'selected')
+                               {
+                                       unset($art_list[$i]['selected']);
+                               }
+                       }
+
+                       return $art_list;
+               }
+       //----------
+
+               function select_category($format='',$selected='')
+               {
+                       switch($format)
+                       {
+                               case 'select':
+                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('cat_select'));
+                                       break;
+                               case 'filter':
+                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('cat_filter'));
+                                       break;
+                       }
+
+                       $categories= $this->so->get_type_list();
+
+                       while (is_array($categories) && list(,$category) = 
each($categories))
+                       {
+                               $sel_category = '';
+                               if ($category['id']==$selected)
+                               {
+                                       $sel_category = 'selected';
+                               }
+
+                               $category_list[] = array
+                               (
+                                       'cat_id'        => $category['id'],
+                                       'name'          => $category['num'],
+                                       'selected'      => $sel_category
+                               );
+                       }
+
+                       for ($i=0;$i<count($category_list);$i++)
+                       {
+                               if ($category_list[$i]['selected'] != 
'selected')
+                               {
+                                       unset($category_list[$i]['selected']);
+                               }
+                       }
+
+                       return $category_list;
+               }
+
+
+               function 
get_invoice_user_list($format='',$selected='',$extra='',$default='')
+               {
+                       if(!$selected && $default)
+                       {
+                               $selected = $default;
+                       }
+
+                       switch($format)
+                       {
+                               case 'select':
+                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('user_lid_select'));
+                                       break;
+                               case 'filter':
+                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('user_lid_filter'));
+                                       break;
+                       }
+
+                       if (is_array($extra))
+                       {
+                               foreach($extra as $extra_user)
+                               {
+                                       $users_extra[]=array
+                                       (
+                                               'account_lid' => $extra_user,
+                                               'account_firstname' => 
lang($extra_user)
+                                       );
+                               }
+                       }
+
+                       $users= $this->so->get_invoice_user_list();
+                       if (is_array($users_extra) && is_array($users))
+                       {
+                               $users = $users_extra + $users;
+                       }
+
+                       while (is_array($users) && list(,$user) = each($users))
+                       {
+                               $sel_user = '';
+                               if ($user['account_lid']==$selected)
+                               {
+                                       $sel_user = 'selected';
+                               }
+
+                               $user_list[] = array
+                               (
+                                       'user_lid'      => $user['account_lid'],
+                                       'name'          => 
$user['account_lastname'].' '.$user['account_firstname'],
+                                       'selected'      => $sel_user
+                               );
+                       }
+
+                       for ($i=0;$i<count($user_list);$i++)
+                       {
+                               if ($user_list[$i]['selected'] != 'selected')
+                               {
+                                       unset($user_list[$i]['selected']);
+                               }
+                       }
+
+//_debug_array($user_list);
+                       return $user_list;
+               }
+
+
+
+               function get_type_list($selected='')
+               {
+                       $types=$this->so->get_type_list();
+
+                       while (is_array($types) && list(,$type) = each($types))
+                       {
+                               $sel_type = '';
+                               if ($type['id']==$selected)
+                               {
+                                       $sel_type = 'selected';
+                               }
+
+                               $type_list[] = array
+                               (
+                                       'id'            => $type['id'],
+                                       'num'           => $type['num'],
+                                       'selected'      => $sel_type
+                               );
+                       }
+
+                       for ($i=0;$i<count($type_list);$i++)
+                       {
+                               if ($type_list[$i]['selected'] != 'selected')
+                               {
+                                       unset($type_list[$i]['selected']);
+                               }
+                       }
+
+                       return $type_list;
+               }
+
+       //----------
+               function select_dimb_list($selected='')
+               {
+                       $dimbs=$this->so->select_dimb_list();
+
+                       while (is_array($dimbs) && list(,$dimb) = each($dimbs))
+                       {
+                               $sel_dimb = '';
+                               if ($dimb['id']==$selected)
+                               {
+                                       $sel_dimb = 'selected';
+                               }
+
+                               $dimb_list[] = array
+                               (
+                                       'id'            => $dimb['id'],
+                                       'num'           => $dimb['num'],
+                                       'selected'      => $sel_dimb
+                               );
+                       }
+
+                       for ($i=0;$i<count($dimb_list);$i++)
+                       {
+                               if ($dimb_list[$i]['selected'] != 'selected')
+                               {
+                                       unset($dimb_list[$i]['selected']);
+                               }
+                       }
+
+                       return $dimb_list;
+               }
+
+       //-------------------
+               function select_dimd_list($selected='')
+               {
+                       $dimds=$this->so->select_dimd_list();
+
+                       while (is_array($dimds) && list(,$dimd) = each($dimds))
+                       {
+                               $sel_dimd = '';
+                               if ($dimd['id']==$selected)
+                               {
+                                       $sel_dimd = 'selected';
+                               }
+
+                               $dimd_list[] = array
+                               (
+                                       'id'            => $dimd['id'],
+                                       'num'           => $dimd['num'],
+                                       'selected'      => $sel_dimd
+                               );
+                       }
+
+                       for ($i=0;$i<count($dimd_list);$i++)
+                       {
+                               if ($dimd_list[$i]['selected'] != 'selected')
+                               {
+                                       unset($dimd_list[$i]['selected']);
+                               }
+                       }
+
+                       return $dimd_list;
+               }
+
+               function select_tax_code_list($selected='')
+               {
+                       $tax_codes=$this->so->select_tax_code_list();
+
+                       while (is_array($tax_codes) && list(,$tax_code) = 
each($tax_codes))
+                       {
+                               $sel_tax_code = '';
+                               if ($tax_code['id']==$selected)
+                               {
+                                       $sel_tax_code = 'selected';
+                               }
+
+                               $tax_code_list[] = array
+                               (
+                                       'id'            => $tax_code['id'],
+                                       'num'           => $tax_code['num'],
+                                       'selected'      => $sel_tax_code
+                               );
+                       }
+
+                       for ($i=0;$i<count($tax_code_list);$i++)
+                       {
+                               if ($tax_code_list[$i]['selected'] != 
'selected')
+                               {
+                                       unset($tax_code_list[$i]['selected']);
+                               }
+                       }
+                       return $tax_code_list;
+               }
+
+               function delete($params)
+               {
+                       if (is_array($params))
+                       {
+                               $this->so->delete($params[0]);
+                       }
+                       else
+                       {
+                               $this->so->delete($params);
+                       }
+               }
+
+               function add($values,$debug='')
+               {
+                       $this->soXport    = 
CreateObject($this->currentapp.'.soXport');
+                       if($values['loc1']=$values['location']['loc1'])
+                       {
+                               $values['dima']=implode('',$values['location']);
+                       }
+
+                       $values['spbudact_code']=$values['b_account_id'];
+                       $values['fakturanr']=$values['invoice_num'];
+                       $values['spvend_code']=$values['vendor_id'];
+
+                       $values['belop'] = 
str_replace('kr','',$values['amount']);
+                       $values['belop'] = str_replace(' ','',$values['belop']);
+                       $values['belop'] = 
str_replace(',','.',$values['belop']);
+                       $values['godkjentbelop']=$values['belop'];
+
+                       $values['fakturadato'] = 
date($this->bocommon->dateformat,mktime(2,0,0,$values['smonth'],$values['sday'],$values['syear']));
+
+                       if($values['num_days'])
+                       {
+                               $values['forfallsdato'] = 
date($this->bocommon->dateformat,mktime(2,0,0,$values['smonth'],$values['sday'],$values['syear'])+(86400*$values['num_days']));
+                       }
+                       else
+                       {
+                               $values['forfallsdato'] = 
date($this->bocommon->dateformat,mktime(2,0,0,$values['emonth'],$values['eday'],$values['eyear']));
+                       }
+
+                       $values['artid']                        = 
$values['art'];
+                       $values['periode']                      = 
$values['smonth'];
+                       $values['dimb']                         = 
$values['dim_b'];
+                       $values['oppsynsmannid']        = $values['janitor'];
+                       $values['saksbehandlerid']      = $values['supervisor'];
+                       $values['budsjettansvarligid'] = 
$values['budget_responsible'];
+                       $values['kildeid']                      = 1;
+                       $values['kidnr']                        = 
$values['kid_nr'];
+                       $values['typeid']                       = 
$values['type'];
+                       if($order_type = 
$this->soXport->check_order(intval($values['order'])))
+                       {
+                               if($order_type=='workorder')
+                               {
+                                       $soworkorder = 
CreateObject($this->currentapp.'.soworkorder');
+                                       $soproject = 
CreateObject($this->currentapp.'.soproject');
+                                       $workorder      = 
$soworkorder->read_single($values['order']);
+                                       $project        = 
$soproject->read_single($workorder['project_id']);
+
+                                       $values['spvend_code']  = 
$workorder['vendor_id'];
+                                       $values['spbudact_code']        = 
$workorder['b_account_id'];
+                                       $values['location_code']        
=$project['location_code'];
+                                       $values['dima']                         
=str_replace('-','',$project['location_code']);
+                                       $values['vendor_name']          = 
$this->get_vendor_name($workorder['vendor_id']);
+                                       $values['pmwrkord_code']        = 
$values['order'];
+                                       $values['project_id']                   
= $workorder['project_id'];
+
+                                       $values = 
$this->set_responsible($values,$workorder['user_id'],$workorder['b_account_id']);
+
+                                       if($values['auto_tax'])
+                                       {
+                                               $values['mvakode'] = 
$this->soXport->auto_tax($values['dima']);
+                                               $values['mvakode'] = 
$this->soXport->tax_b_account_override($values['mvakode'],$values['spbudact_code']);
+                                               $values['mvakode'] = 
$this->soXport->tax_vendor_override($values['mvakode'],$values['spvend_code']);
+                                               $values['kostra_id'] = 
$this->soXport->get_kostra_id($values['dima']);
+                                       }
+
+                                       $buffer[0]=$values;
+                               }
+
+                               if($order_type=='s_agreement')
+                               {
+                                       $sos_agreement = 
CreateObject($this->currentapp.'.sos_agreement');
+                                       $s_agreement = 
$sos_agreement->read_single(array('s_agreement_id'=>$values['order']));
+
+                                       $values['spvend_code']          = 
$s_agreement['vendor_id'];
+                                       $values['spbudact_code']        = 
$s_agreement['b_account_id'];
+                                       $values['vendor_name']          = 
$this->get_vendor_name($s_agreement['vendor_id']);
+                                       $values['pmwrkord_code']        = 
intval($values['order']);
+                                       $values = 
$this->set_responsible($values,$s_agreement['user_id'],$s_agreement['b_account_id']);
+
+
+                                       $s_agreement_detail = 
$sos_agreement->read(array('allrows'=>True,'s_agreement_id'=>$values['order'],'detail'=>True));
+
+                                       $sum_agreement=0;
+                                       for 
($i=0;$i<count($s_agreement_detail);$i++)
+                                       {
+                                               $sum_agreement = $sum_agreement 
+ $s_agreement_detail[$i]['cost'];
+                                       }
+
+
+                                       for 
($i=0;$i<count($s_agreement_detail);$i++)
+                                       {
+                                               $buffer[$i]=$values;
+
+                                               $buffer[$i]['location_code']    
=$s_agreement_detail[$i]['location_code'];
+                                               $buffer[$i]['dima']             
                =str_replace('-','',$s_agreement_detail[$i]['location_code']);
+
+
+                                               $buffer[$i]['belop']    =       
round($values['belop'] / $sum_agreement * $s_agreement_detail[$i]['cost'],2);
+                                               $buffer[$i]['godkjentbelop'] 
=$buffer[$i]['belop'];
+
+                                               if($values['auto_tax'])
+                                               {
+                                                       $buffer[$i]['mvakode'] 
= $this->soXport->auto_tax($buffer[$i]['dima']);
+                                                       $buffer[$i]['mvakode'] 
= 
$this->soXport->tax_b_account_override($buffer[$i]['mvakode'],$buffer[$i]['spbudact_code']);
+                                                       $buffer[$i]['mvakode'] 
= 
$this->soXport->tax_vendor_override($buffer[$i]['mvakode'],$buffer[$i]['spvend_code']);
+                                                       
$buffer[$i]['kostra_id'] = $this->soXport->get_kostra_id($buffer[$i]['dima']);
+                                               }
+                                       }
+                               }
+                       }
+                       else
+                       {
+                               if($values['auto_tax'])
+                               {
+                                       $values['mvakode'] = 
$this->soXport->auto_tax($values['loc1']);
+                                       $values['mvakode'] = 
$this->soXport->tax_b_account_override($values['mvakode'],$values['spbudact_code']);
+                                       $values['mvakode'] = 
$this->soXport->tax_vendor_override($values['mvakode'],$values['spvend_code']);
+                                       $values['kostra_id'] = 
$this->soXport->get_kostra_id($values['loc1']);
+                               }
+
+                               $buffer[0]=$values;
+                       }
+
+                       if($debug)
+                       {
+                               return $buffer;
+                       }
+
+                       if($this->soXport->add($buffer)>0)
+                       {
+                               $receipt['message'][] = 
array('msg'=>lang('Invoice %1 is added',$values['bilagsnr']));
+                       }
+                       else
+                       {
+                               $receipt['error'][] = 
array('msg'=>lang('Invoice is NOT added!'));
+                       }
+                       return $receipt;
+               }
+
+               function get_vendor_name($vendor_id='')
+               {
+                       $contacts       = 
CreateObject($this->currentapp.'.soactor');
+                       $contacts->role='vendor';
+
+                       $vendor_data    = 
$contacts->read_single(array('actor_id'=>$vendor_id));
+                       if(is_array($vendor_data))
+                       {
+                               foreach($vendor_data['attributes'] as 
$attribute)
+                               {
+                                       if($attribute['name']=='org_name')
+                                       {
+                                               return $attribute['value'];
+                                       }
+                               }
+                       }
+               }
+
+               function set_responsible($values,$user_id='',$b_account_id='')
+               {
+                       if (!$values['budget_responsible'])
+                       {
+                               $values['budget_responsible'] = 
$this->soXport->get_responsible($b_account_id);
+                               $values['budsjettansvarligid'] = 
$values['budget_responsible'];
+                       }
+
+                       $acl2   = 
CreateObject($this->currentapp.'.acl2',$user_id);
+                       if($acl2->check('.invoice',32) && 
!$acl2->check('.invoice',64)):
+                       {
+                               $values['janitor']      = 
$GLOBALS['phpgw']->accounts->id2name($user_id);
+                               $values['oppsynsmannid']        = 
$values['janitor'];
+                       }
+       //              elseif((!$acl2->check('.invoice',32) && 
$acl2->check('.invoice',64)) || ($acl2->check('.invoice',32) && 
$acl2->check('.invoice',64))):
+                       elseif($acl2->check('.invoice',64)):
+                       {
+                               $values['supervisor']   = 
$GLOBALS['phpgw']->accounts->id2name($user_id);
+                               $values['saksbehandlerid']      = 
$values['supervisor'];
+                       }
+                       endif;
+
+                       return $values;
+               }
+       }
+?>
Index: property/inc/class.bolocation.inc.php
diff -u property/inc/class.bolocation.inc.php:1.9 
property/inc/class.bolocation.inc.php:1.10
--- property/inc/class.bolocation.inc.php:1.9   Fri Jan 27 14:05:43 2006
+++ property/inc/class.bolocation.inc.php       Fri Feb  3 12:05:49 2006
@@ -1,820 +1,835 @@
-<?php
-       /**
-       * phpGroupWare - property: a Facilities Management System.
-       *
-       * @author Sigurd Nes <address@hidden>
-       * @copyright Copyright (C) 2003-2005 Free Software Foundation, Inc. 
http://www.fsf.org/
-       * @license http://www.gnu.org/licenses/gpl.html GNU General Public 
License
-       * @internal Development of this application was funded by 
http://www.bergen.kommune.no/bbb_/ekstern/
-       * @package property
-       * @subpackage location
-       * @version $Id: class.bolocation.inc.php,v 1.9 2006/01/27 14:05:43 
sigurdne Exp $
-       */
-
-       /**
-        * Description
-        * @package property
-        */
-
-       class bolocation
-       {
-               var $start;
-               var $query;
-               var $filter;
-               var $sort;
-               var $order;
-               var $cat_id;
-
-               var $public_functions = array
-               (
-                       'read'                          => True,
-                       'read_single'           => True,
-                       'save'                          => True,
-                       'delete'                        => True,
-                       'check_perms'           => True
-               );
-
-               var $soap_functions = array(
-                       'list' => array(
-                               'in'  => 
array('int','int','struct','string','int'),
-                               'out' => array('array')
-                       ),
-                       'read' => array(
-                               'in'  => array('int','struct'),
-                               'out' => array('array')
-                       ),
-                       'save' => array(
-                               'in'  => array('int','struct'),
-                               'out' => array()
-                       ),
-                       'delete' => array(
-                               'in'  => array('int','struct'),
-                               'out' => array()
-                       )
-               );
-
-               function bolocation($session=False)
-               {
-                       $this->currentapp                       = 
$GLOBALS['phpgw_info']['flags']['currentapp'];
-                       $this->so                                       = 
CreateObject($this->currentapp.'.solocation');
-                       $this->bocommon                         = 
CreateObject($this->currentapp.'.bocommon');
-                       $this->soadmin_location         = 
CreateObject($this->currentapp.'.soadmin_location');
-
-                       if ($session)
-                       {
-                               $this->read_sessiondata();
-                               $this->use_session = True;
-                       }
-
-                       $start  = get_var('start',array('POST','GET'));
-                       $query  = get_var('query',array('POST','GET'));
-                       $sort   = get_var('sort',array('POST','GET'));
-                       $order  = get_var('order',array('POST','GET'));
-                       $filter = get_var('filter',array('POST','GET'));
-                       $cat_id = get_var('cat_id',array('POST','GET'));
-                       $lookup_tenant  = 
get_var('lookup_tenant',array('POST','GET'));
-                       $district_id    = 
get_var('district_id',array('POST','GET'));
-                       $part_of_town_id        = 
get_var('part_of_town_id',array('POST','GET'));
-                       $status = get_var('status',array('POST','GET'));
-                       $type_id        = 
get_var('type_id',array('POST','GET'));
-                       $allrows        = 
get_var('allrows',array('POST','GET'));
-                       
-                       if ($start)
-                       {
-                               $this->start=$start;
-                       }
-                       else
-                       {
-                               $this->start=0;
-                       }
-
-                       if(isset($query))
-                       {
-                               $this->query = $query;
-                       }
-                       if(isset($filter))
-                       {
-                               $this->filter = $filter;
-                       }
-                       if(isset($sort))
-                       {
-                               $this->sort = $sort;
-                       }
-                       if(isset($order))
-                       {
-                               $this->order = $order;
-                       }
-                       if(isset($cat_id))
-                       {
-                               $this->cat_id = $cat_id;
-                       }
-                       if(isset($part_of_town_id))
-                       {
-                               $this->part_of_town_id = $part_of_town_id;
-                       }
-                       if(isset($district_id))
-                       {
-                               $this->district_id = $district_id;
-                       }
-                       if(isset($status))
-                       {
-                               $this->status = $status;
-                       }
-                       if(isset($type_id))
-                       {
-                               $this->type_id = $type_id;
-                       }
-                       if(isset($allrows))
-                       {
-                               $this->allrows = $allrows;
-                       }
-
-               }
-
-               function read_sessiondata()
-               {
-                       $data = 
$GLOBALS['phpgw']->session->appsession('session_data','location');
-
-                       $this->start                    = $data['start'];
-                       $this->query                    = $data['query'];
-                       $this->filter                   = $data['filter'];
-                       $this->sort                             = $data['sort'];
-                       $this->order                    = $data['order'];
-                       $this->cat_id                   = $data['cat_id'];
-                       $this->part_of_town_id  = $data['part_of_town_id'];
-                       $this->district_id              = $data['district_id'];
-                       $this->status                   = $data['status'];
-                       $this->type_id                  = $data['type_id'];     
                
-                       $this->allrows                  = $data['allrows'];
-               }
-
-               function save_sessiondata($data)
-               {
-                       if ($this->use_session)
-                       {
-                               
$GLOBALS['phpgw']->session->appsession('session_data','location',$data);
-                       }
-               }
-
-
-               function select_status_list($format='',$selected='')
-               {
-                       switch($format)
-                       {
-                               case 'select':
-                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('status_select'));
-                                       break;
-                               case 'filter':
-                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('status_filter'));
-                                       break;
-                       }
-
-                       $list= $this->so->select_status_list($this->type_id);
-                       return $this->bocommon->select_list($selected,$list);
-               }
-
-               function read_entity_to_link()
-               {
-                               return $this->so->read_entity_to_link();
-               }
-
-               function get_owner_list($format='',$selected='')
-               {
-
-                       switch($format)
-                       {
-                               case 'select':
-                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('filter_select'));
-                                       break;
-                               case 'filter':
-                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('filter_filter'));
-                                       break;
-                       }
-
-                       $owners = $this->so->get_owner_list();
-
-                       while (is_array($owners) && list(,$owner) = 
each($owners))
-                       {
-                               $sel_owner = '';
-                               if ($owner['id']==$selected)
-                               {
-                                       $sel_owner = 'selected';
-                               }
-
-                               $owner_list[] = array
-                               (
-                                       'id'    => $owner['id'],
-                                       'name'          => $owner['name'],
-                                       'selected'      => $sel_owner
-                               );
-                       }
-
-                       $owner_count=count($owner_list);
-                       for ($i=0;$i<$owner_count;$i++)
-                       {
-                               if ($owner_list[$i]['selected'] != 'selected')
-                               {
-                                       unset($owner_list[$i]['selected']);
-                               }
-                       }
-
-                       return $owner_list;
-               }
-
-               function get_owner_type_list($format='',$selected='')
-               {
-
-                       switch($format)
-                       {
-                               case 'select':
-                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('owner_select'));
-                                       break;
-                               case 'filter':
-                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('owner_filter'));
-                                       break;
-                       }
-
-                       $owners = $this->so->get_owner_type_list();
-
-                       while (is_array($owners) && list(,$owner) = 
each($owners))
-                       {
-                               $sel_owner = '';
-                               if ($owner['id']==$selected)
-                               {
-                                       $sel_owner = 'selected';
-                               }
-
-                               $owner_list[] = array
-                               (
-                                       'id'    => $owner['id'],
-                                       'name'          => $owner['name'],
-                                       'selected'      => $sel_owner
-                               );
-                       }
-
-                       $owner_count=count($owner_list);
-
-                       for ($i=0;$i<$owner_count;$i++)
-                       {
-                               if ($owner_list[$i]['selected'] != 'selected')
-                               {
-                                       unset($owner_list[$i]['selected']);
-                               }
-                       }
-
-                       return $owner_list;
-               }
-
-
-               function initiate_ui_location($data)
-               {
-
-                       switch($data['lookup_type'])
-                       {
-                               case 'form':
-                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('location_form'));
-                                       break;
-                               case 'view':
-                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('location_view'));
-                                       break;
-                       }
-
-                       $location_link          = 
$GLOBALS['phpgw']->link('/index.php','menuaction='.$this->currentapp.'.uilocation.index&lookup=1');
-
-                       $config = $this->soadmin_location->read_config('');
-
-                       $this->config   = $config;
-//_debug_array($config);
-                       $location_types = 
$this->soadmin_location->select_location_type();
-                       $this->location_types   = $location_types;
-
-                       if($data['type_id']<0)
-                       {
-                               $data['type_id'] = count($location_types);
-                       }
-//_debug_array($data);
-//_debug_array($location_types);
-                       $fm_location_cols = 
$this->soadmin_location->read_attrib(array('type_id'=>$data['type_id'],'lookup_type'=>$data['type_id']));
-//_debug_array($fm_location_cols);
-
-                       for ($i=0;$i<$data['type_id'];$i++)
-                       {
-                               $location['location'][$i]['input_type']         
                = 'text';
-                               $location['location'][$i]['input_name']         
                = 'loc' . ($i+1);
-                               $input_name[]                                   
                                        = 
$location['location'][$i]['input_name'];
-                               $insert_record['location'][]                    
                        = $location['location'][$i]['input_name'];
-                               $location['location'][$i]['size']               
                        = 5;
-                               $location['location'][$i]['name']               
                        = $location_types[($i)]['name'];
-                               $location['location'][$i]['value']              
                        = $data['values']['loc' . ($i+1)];
-                               $location['location'][$i]['statustext']         
                = lang('Klick this link to select') . ' ' . 
$location_types[($i)]['name'];
-
-                               if($i==0)
-                               {
-                                       
$location['location'][$i]['extra'][0]['input_name']             = 'loc' . 
($i+1).'_name';
-                                       $input_name[]                           
                                                        = 
$location['location'][$i]['extra'][0]['input_name'];
-                                       
$location['location'][$i]['extra'][0]['input_type']                             
= 'text';
-                                       
$location['location'][$i]['extra'][0]['size']                           = 30;
-                                       
$location['location'][$i]['extra'][0]['lookup_function_call']   = 'lookup_loc' 
. ($i+1) . '()';
-                                       
$location['location'][$i]['extra'][0]['value']                          = 
$data['values']['loc' . ($i+1).'_name'];
-                               }
-                               else
-                               {
-                                       
$location['location'][$i]['extra'][0]['input_name']             = 'loc' . 
($i+1).'_name';
-                                       $input_name[]                           
                                                        = 
$location['location'][$i]['extra'][0]['input_name'];
-                                       
$location['location'][$i]['extra'][0]['input_type']                             
= 'text';
-                                       
$location['location'][$i]['extra'][0]['size']                           = 30;
-                                       
$location['location'][$i]['extra'][0]['lookup_function_call']   = 'lookup_loc' 
. ($i+1) . '()';
-                                       
$location['location'][$i]['extra'][0]['value']                          = 
$data['values']['loc' . ($i+1).'_name'];
-                               }
-
-                               
$location['location'][$i]['lookup_function_call']       = 'lookup_loc' . ($i+1) 
. '()';
-                               $location['location'][$i]['lookup_link']        
                = True;
-                               $location['location'][$i]['readonly']           
                = True;
-                               $lookup_functions[$i]['name']                   
                        = 'lookup_loc' . ($i+1) . '()';
-                               $lookup_functions[$i]['action']                 
                        = 'Window1=window.open('."'" . $location_link 
.'&type_id=' . ($i+1) . '&lookup_name=' . $i . "'" 
.',"Search","width=800,height=700,toolbar=no,scrollbars=yes,resizable=yes");';
-
-                               if($data['no_link']>=($i+3))
-                               {
-                                       
$location['location'][$i]['lookup_link']                = False;
-                                       $lookup_functions[$i]['action']         
                        = 'Window1=window.open('."'" . $location_link 
.'&type_id=' . ($data['no_link']-1) . '&lookup_name=' . ($data[no_link]-2) . 
"'" 
.',"Search","width=800,height=700,toolbar=no,scrollbars=yes,resizable=yes");';
-                                       $location['location'][$i]['statustext'] 
                = lang('Klick this link to select') . ' ' . 
$location_types[($data[no_link]-2)]['name'];
-                               }
-
-
-                               if($data['query_link'] && $i < 
($data['type_id']-1))
-                               {
-                                               for ($j=1;$j<$i+2;$j++)
-                                               {
-                                                       $temp_location[]= 
$data['values']['loc' . ($j)];
-                                               }
-
-
-                                       $data['link_data']['query_location']    
                = implode('-',$temp_location);
-                                       $location['location'][$i]['query_link'] 
                = $GLOBALS['phpgw']->link('/index.php',$data['link_data']);
-                                       unset($temp_location);
-                               }
-
-
-                               $m=$i;
-                       }
-
-//_debug_array($fm_location_cols);
-//_debug_array($data);
-
-                       $location_cols_count =count($fm_location_cols);
-                       for ($j=0;$j<$location_cols_count;$j++)
-                       {
-                               if(($fm_location_cols[$j]['location_type'] <= 
$data['type_id']) && $fm_location_cols[$j]['lookup_form'])
-                               {
-                                       $location['location'][$i]['input_type'] 
                        = 'text';
-                                       $location['location'][$i]['input_name'] 
                        = $fm_location_cols[$j]['column_name'];
-                                       $input_name[]                           
                                                = 
$location['location'][$i]['input_name'];
-                                       $location['location'][$i]['size']       
                                = 5;
-                                       
$location['location'][$i]['lookup_function_call']       = 'lookup_loc' . 
$fm_location_cols[$j]['location_type'] . '()';
-                                       
$location['location'][$i]['lookup_link']                        = True;
-                                       $location['location'][$i]['readonly']   
                        = True;
-                                       $location['location'][$i]['name']       
                                = $fm_location_cols[$j]['input_text'];
-                                       $location['location'][$i]['value']      
                                = 
$data['values'][$fm_location_cols[$j]['column_name']];
-                                       $location['location'][$i]['statustext'] 
                        = lang('Klick this link to select') . ' ' . 
$location_types[($fm_location_cols[$j]['location_type']-1)]['name'];
-                                       $i++;
-
-                               }
-                       }
-
-
-                       $config_count =count($config);
-                       for ($j=0;$j<$config_count;$j++)
-                       {
-                               if($config[$j]['location_type'] <= 
$data['type_id'] && $config[$j]['lookup_form'] )
-                               {
-                                       
if($config[$j]['column_name']=='street_id'):
-                                       {
-                                               
$location['location'][$i]['input_name']                         = 
$config[$j]['column_name'];
-                                               $input_name[]                   
                                                        = 'street_id';
-                                               
$location['location'][$i]['lookup_link']                        = True;
-                                               
$location['location'][$i]['lookup_function_call']       = 'lookup_loc' . 
$config[$j]['location_type'] . '()';
-                                               
$location['location'][$i]['name']                                       = 
lang('address');
-                                               
$location['location'][$i]['input_type']                         = 'hidden';
-                                               
$location['location'][$i]['value']                                      = 
$data['values'][$config[$j]['column_name']];
-
-                                               
$location['location'][$i]['extra'][0]['input_type']                             
= 'text';
-                                               
$location['location'][$i]['extra'][0]['input_name']                             
= 'street_name';
-                                               
$location['location'][$i]['extra'][0]['readonly']                               
= True;
-                                               $input_name[]                   
                                                                                
= $location['location'][$i]['extra'][0]['input_name'];
-                                               
$location['location'][$i]['extra'][0]['size']                                   
= 30;
-                                               
$location['location'][$i]['extra'][0]['lookup_function_call']   = 'lookup_loc' 
. $config[$j]['location_type'] . '()';
-                                               
$location['location'][$i]['extra'][0]['value']                                  
= $data['values']['street_name'];
-
-                                               
$location['location'][$i]['extra'][1]['input_type']                             
= 'text';
-                                               
$location['location'][$i]['extra'][1]['input_name']                             
= 'street_number';
-                                               
$location['location'][$i]['extra'][1]['readonly']                               
= True;
-                                               $input_name[]                   
                                                                                
= $location['location'][$i]['extra'][1]['input_name'];
-                                               
$location['location'][$i]['extra'][1]['size']                                   
= 6;
-                                               
$location['location'][$i]['extra'][1]['lookup_function_call']   = 'lookup_loc' 
. $config[$j]['location_type'] . '()';
-                                               
$location['location'][$i]['extra'][1]['value']                                  
= $data['values']['street_number'];
-                                       }
-                                       
elseif($config[$j]['column_name']=='tenant_id' && $data['tenant']):
-                                       {
-                                               $m++;
-                                               $lookup_functions[$m]['name'] = 
'lookup_loc' . ($m+1) . '()';
-                                               $lookup_functions[$m]['action'] 
= 'Window1=window.open('."'" . $location_link .'&lookup_tenant=1&type_id=' . 
$config[$j]['location_type'] . '&lookup_name=' . $i ."'" 
.',"Search","width=800,height=700,toolbar=no,scrollbars=yes,resizable=yes");';
-
-                                               
$location['location'][$i]['lookup_link']                                        
        = True;
-                                               
$location['location'][$i]['name']                                               
                = lang('Tenant');
-                                               
$location['location'][$i]['input_type']                                         
        = 'hidden';
-                                               
$location['location'][$i]['input_name']                                         
        = 'tenant_id';
-                                               $input_name[]                   
                                                                                
= $location['location'][$i]['input_name'];
-                                               
$location['location'][$i]['value']                                              
                = $data['values'][$config[$j]['column_name']];
-                                               
$location['location'][$i]['lookup_function_call']                               
= $lookup_functions[$m]['name'];
-                                               
$location['location'][$i]['statustext']                                         
        = lang('tenant');
-                                               
$insert_record['extra']['tenant_id']                                            
        = 'tenant_id';
-
-                                               
$location['location'][$i]['extra'][0]['input_type']                             
= 'text';
-                                               
$location['location'][$i]['extra'][0]['input_name']                             
= 'last_name';
-                                               
$location['location'][$i]['extra'][0]['readonly']                               
= True;
-                                               $input_name[]                   
                                                                                
= $location['location'][$i]['extra'][0]['input_name'];
-                                               
$location['location'][$i]['extra'][0]['size']                                   
= 15;
-                                               
$location['location'][$i]['extra'][0]['lookup_function_call']   = 
$lookup_functions[$m]['name'];
-                                               
$location['location'][$i]['extra'][0]['value']                                  
= $data['values']['last_name'];
-                                               
$location['location'][$i]['extra'][0]['statustext']                             
= lang('last name');
-
-                                               
$location['location'][$i]['extra'][1]['input_type']                             
= 'text';
-                                               
$location['location'][$i]['extra'][1]['input_name']                             
= 'first_name';
-                                               
$location['location'][$i]['extra'][1]['readonly']                               
= True;
-                                               $input_name[]                   
                                                                                
= $location['location'][$i]['extra'][1]['input_name'];
-                                               
$location['location'][$i]['extra'][1]['size']                                   
= 15;
-                                               
$location['location'][$i]['extra'][1]['lookup_function_call']   = 
$lookup_functions[$m]['name'];
-                                               
$location['location'][$i]['extra'][1]['value']                                  
= $data['values']['first_name'];
-                                               
$location['location'][$i]['extra'][1]['statustext']                             
= lang('first name');
-                                               $i++;
-                                               
$location['location'][$i]['input_type']                         = 'text';
-                                               
$location['location'][$i]['name']                                       = 
lang('Contact phone');
-                                               
$location['location'][$i]['input_name']                         = 
'contact_phone';
-                                               $input_name[]                   
                                                        = 
$location['location'][$i]['input_name'];
-                                               
$location['location'][$i]['size']                                       = 12;
-                                               
$location['location'][$i]['lookup_function_call']       = 
'';//$lookup_functions[$m]['name'];
-                                               
$insert_record['extra']['contact_phone']                        = 
'contact_phone';
-                                               
$location['location'][$i]['value']                                      = 
$data['values']['contact_phone'];
-                                               
$location['location'][$i]['statustext']                         = lang('contact 
phone');
-                                       }
-                                       
elseif($config[$j]['column_name']!='tenant_id' && 
$config[$j]['column_name']!='street_id'):
-                                       {
-                                               
$location['location'][$i]['input_name']                         = 
$config[$j]['column_name'];
-                                               $input_name[]                   
                                                        = 
$location['location'][$i]['input_name'];
-//                                             $insert_record[]                
                                                        = 
$location['location'][$i]['input_name'];
-                                               
$location['location'][$i]['size']                                       = 5;
-                                               
$location['location'][$i]['value']                                      = 
$data['location']['value'][$config[$j]['column_name']];
-                                               
$location['location'][$i]['lookup_function_call']       = 'lookup_loc' . 
$fm_location_cols[$j]['location_type'] . '()';
-                                               
$location['location'][$i]['lookup_link']                        = True;
-                                               
$location['location'][$i]['name']                                       = 
$config[$j]['descr'];
-                                               
$location['location'][$i]['value']                                      = 
$data['values'][$config[$j]['column_name']];
-                                               
$location['location'][$i]['statustext']                         = lang('Klick 
this link to select') . ' ' 
.$location_types[($fm_location_cols[$j]['location_type']-1)]['name'];
-                                               
$location['location'][$i]['input_type']                         = 'text';
-                                       }
-                                       endif;
-                                       $i++;
-                               }
-                       }
-
-                       if (isset($data['lookup_entity']) && 
is_array($data['lookup_entity']))
-                       {
-                               foreach($data['lookup_entity'] as $entity)
-                               {
-                                       $m++;
-                                       $entity_link            = 
$GLOBALS['phpgw']->link('/index.php','menuaction='.$this->currentapp.'.uilookup.entity&location_type='
 . $data['type_id'] . '&entity_id=' .$entity['id']);
-
-                                       $lookup_functions[$m]['name'] = 
'lookup_entity_' . $entity['id'] .'()';
-                                       $lookup_functions[$m]['action'] = 
'Window1=window.open('."'" . $entity_link ."'" 
.',"Search","width=800,height=700,toolbar=no,scrollbars=yes,resizable=yes");';
-
-                                       $location['location'][$i]['input_type'] 
                                                = 'text';
-                                       $location['location'][$i]['input_name'] 
                                                = 'entity_num_' . $entity['id'];
-                                       $input_name[]                           
                                                                        = 
'entity_num_' . $entity['id'];
-                                       $insert_record['extra']['entity_num_' . 
$entity['id']]                  = 'p_num';
-
-                                       $location['location'][$i]['size']       
                                                        = 8;
-                                       
$location['location'][$i]['lookup_function_call']                               
= 'lookup_entity_' . $entity['id'] .'()';
-                                       
$location['location'][$i]['lookup_link']                                        
        = True;
-                                       $location['location'][$i]['name']       
                                                        = $entity['name'];
-                                       $location['location'][$i]['value']      
                                                        = 
$data['entity_data'][$entity['id']]['p_num'];
-                                       $location['location'][$i]['statustext'] 
                                                = lang('Klick this link to 
select') .' ' . $entity['name'];
-
-                                       
$location['location'][$i]['extra'][0]['input_name']                             
= 'entity_cat_name_' . $entity['id'];
-                                       $input_name[]                           
                                                                        = 
$location['location'][$i]['extra'][0]['input_name'];
-                                       
$location['location'][$i]['extra'][0]['input_type']                             
= 'text';
-                                       
$location['location'][$i]['extra'][0]['size']                                   
= 30;
-                                       
$location['location'][$i]['extra'][0]['lookup_function_call']   = 
'lookup_entity_' . $entity['id'] .'()';
-                                       
$location['location'][$i]['extra'][0]['value']                                  
= $data['entity_data'][$entity['id']]['p_cat_name'];
-
-                                       
$location['location'][$i]['extra'][1]['input_type']                             
= 'hidden';
-                                       
$location['location'][$i]['extra'][1]['input_name']                             
= 'entity_id_' . $entity['id'];
-                                       $input_name[]                           
                                                                        = 
'entity_id_' . $entity['id'];
-                                       $insert_record['extra']['entity_id_' . 
$entity['id']]                   = 'p_entity_id';
-                                       
$location['location'][$i]['extra'][1]['value']                                  
= $data['entity_data'][$entity['id']]['p_entity_id'];
-
-                                       
$location['location'][$i]['extra'][2]['input_type']                             
= 'hidden';
-                                       
$location['location'][$i]['extra'][2]['input_name']                             
= 'cat_id_' . $entity['id'];
-                                       $input_name[]                           
                                                                        = 
'cat_id_' . $entity['id'];
-                                       $insert_record['extra']['cat_id_' . 
$entity['id']]                              = 'p_cat_id';
-                                       
$location['location'][$i]['extra'][2]['value']                                  
= $data['entity_data'][$entity['id']]['p_cat_id'];
-
-                                       $i++;
-                               }
-                       }
-
-//_debug_array($location['location']);
-
-                       
$GLOBALS['phpgw']->session->appsession('lookup_fields',$this->currentapp,$input_name);
-                       
$GLOBALS['phpgw']->session->appsession('insert_record',$this->currentapp,$insert_record);
-//                     
$GLOBALS['phpgw']->session->appsession('input_name',$this->currentapp,$input_name);
-
-                       for ($i=0;$i<count($location['location']);$i++)
-                       {
-                               $lookup_name[] = 
$location['location'][$i]['name'];
-
-                       }
-
-                       
$GLOBALS['phpgw']->session->appsession('lookup_name',$this->currentapp,$lookup_name);
-
-                       for ($j=0;$j<count($lookup_functions);$j++)
-                       {
-                               $location['lookup_functions'] .= 'function ' . 
$lookup_functions[$j]['name'] ."\r\n";
-                               $location['lookup_functions'] .= '{'."\r\n";
-                               $location['lookup_functions'] .= 
$lookup_functions[$j]['action'] ."\r\n";
-                               $location['lookup_functions'] .= '}'."\r\n";
-                       }
-
-
-//_debug_array($location);
-
-                       return $location;
-
-               }
-
-               function 
select_category_list($format='',$selected='',$type_id='')
-               {
-                       switch($format)
-                       {
-                               case 'select':
-                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('cat_select'));
-                                       break;
-                               case 'filter':
-                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('cat_filter'));
-                                       break;
-                       }
-
-                       $categories= $this->so->select_category_list($type_id);
-
-                       while (is_array($categories) && list(,$category) = 
each($categories))
-                       {
-                               $sel_category = '';
-                               if ($category['id']==$selected)
-                               {
-                                       $sel_category = 'selected';
-                               }
-
-                               $category_list[] = array
-                               (
-                                       'cat_id'        => $category['id'],
-                                       'name'          => $category['name'],
-                                       'selected'      => $sel_category
-                               );
-                       }
-
-                       $category_count=count($category_list);
-                       for ($i=0;$i<$category_count;$i++)
-                       {
-                               if ($category_list[$i]['selected'] != 
'selected')
-                               {
-                                       unset($category_list[$i]['selected']);
-                               }
-                       }
-
-                       return $category_list;
-               }
-
-
-               function read($data='')
-               {
-                       $location = $this->so->read(array('start' => 
$this->start,'query' => $this->query,'sort' => $this->sort,'order' => 
$this->order,
-                                                                               
        'filter' => $this->filter,'cat_id' => $this->cat_id,'type_id' => 
$data['type_id'],
-                                                                               
        'lookup_tenant'=>$data['lookup_tenant'],'lookup'=>$data['lookup'],
-                                                                               
        'district_id'=>$this->district_id,'allrows'=>$data['allrows'],
-                                                                               
        'status'=>$this->status,'part_of_town_id'=>$this->part_of_town_id));
-                       $this->total_records = $this->so->total_records;
-                       $this->uicols = $this->so->uicols;
-
-                       return $location;
-               }
-
-               function read_single($location_code='',$extra='')
-               {
-                       $location_data = $this->so->read_single($location_code);
-
-                       if(!$extra['tenant_id']=='lookup')
-                       {
-                               if($extra['tenant_id']>0)
-                               {
-                                       
$tenant_data=$this->bocommon->read_single_tenant($extra['tenant_id']);
-                                       $location_data['tenant_id']     = 
$extra['tenant_id'];
-                                       $location_data['contact_phone']= 
$extra['contact_phone'];
-                                       $location_data['last_name']     = 
$tenant_data['last_name'];
-                                       $location_data['first_name']    = 
$tenant_data['first_name'];
-                               }
-                               else
-                               {
-                                       unset($location_data['tenant_id']);
-                                       unset($location_data['contact_phone']);
-                                       unset($location_data['last_name']);
-                                       unset($location_data['first_name']);
-                               }
-                       }
-
-                       if(is_array($extra))
-                       {
-                               $location_data = $location_data + $extra;
-                       }
-                       return $location_data;
-               }
-
-               function check_location($location_code='',$type_id='')
-               {
-                       return 
$this->so->check_location($location_code,$type_id);
-               }
-
-
-               function 
save($location,$values_attribute,$action='',$type_id='',$location_code_parent='')
-               {
-
-
-//_debug_array($values_attribute);
-/*                     $location_datatype = 
$GLOBALS['phpgw']->session->appsession('location_datatype',$this->currentapp);
-//     _debug_array($location_datatype);
-
-                       if(is_array($location_datatype))
-                       {
-                               for ($i=0;$i<count($location_datatype);$i++)
-                               {
-                                       
if($location_datatype[$i]['datatype']=='decimal' && 
$location[$location_datatype[$i]['input_name']])
-                                       {
-                                               
$location[$location_datatype[$i]['input_name']] = 
str_replace(",",".",$location[$location_datatype[$i]['input_name']]);
-                                       }
-
-                                       
if($location_datatype[$i]['datatype']=='date' && 
$location[$location_datatype[$i]['input_name']])
-                                       {
-                                               $dateformat= 
$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
-                                               $dateformat = 
str_replace(".","",$dateformat);
-                                               $dateformat = 
str_replace("-","",$dateformat);
-                                               $dateformat = 
str_replace("/","",$dateformat);
-                                               $y=strpos($dateformat,'Y');
-                                               $d=strpos($dateformat,'d');
-                                               $m=strpos($dateformat,'m');
-
-                                               $dateparts = explode('/', 
$location[$location_datatype[$i]['input_name']]);
-                                               $day            = 
$dateparts[$d];
-                                               $month          = 
$dateparts[$m];
-                                               $year           = 
$dateparts[$y];
-
-//                                             
$location[$location_datatype[$i]['input_name']] = 
date($this->bocommon->dateformat,mktime(2,0,0,$month,$day,$year));
-                                               
$location[$location_datatype[$i]['input_name']] = 
mktime(0,0,0,$month,$day,$year);
-
-                                       }
-                               }
-                       }
-
-*/
-
-                       $m=count($values_attribute);
-                       for ($i=0;$i<$m;$i++)
-                       {
-                               if($values_attribute[$i]['datatype']=='AB' || 
$values_attribute[$i]['datatype']=='VENDOR')
-                               {
-                                       $values_attribute[$i]['value'] = 
$_POST[$values_attribute[$i]['name']];
-                               }
-                               if($values_attribute[$i]['datatype']=='CH' && 
$values_attribute[$i]['value'])
-                               {
-                                       $values_attribute[$i]['value'] = 
serialize($values_attribute[$i]['value']);
-                               }
-                               if($values_attribute[$i]['datatype']=='R' && 
$values_attribute[$i]['value'])
-                               {
-                                       $values_attribute[$i]['value'] = 
$values_attribute[$i]['value'][0];
-                               }
-
-                               if($values_attribute[$i]['datatype']=='N' && 
$values_attribute[$i]['value'])
-                               {
-                                       $values_attribute[$i]['value'] = 
str_replace(",",".",$values_attribute[$i]['value']);
-                               }
-
-                               if($values_attribute[$i]['datatype']=='D' && 
$values_attribute[$i]['value'])
-                               {
-
-                                       $values_attribute[$i]['value'] = 
date($this->bocommon->dateformat,$this->bocommon->date_to_timestamp($values_attribute[$i]['value']));
-                               }
-                       }
-
-
-//_debug_array($values_attribute);
-
-
-
-//     _debug_array($location);
-
-                       if ($action=='edit')
-                       {
-                               if 
($this->so->check_location($location['location_code'],$type_id))
-                               {
-                                       $receipt = 
$this->so->edit($location,$values_attribute,$type_id);
-                               }
-                               else
-                               {
-                                       
$receipt['error'][]=array('msg'=>lang('This location ID does not exist!'));
-                               }
-                       }
-                       else
-                       {
-
-/*                             if($type_id>1)
-                               {
-                                       
if(!$this->so->check_location($location_code_parent,($type_id-1)))
-                                       {
-                                               
$receipt['error'][]=array('msg'=>lang('This location parent ID does not 
exist!'));
-                                       }
-                               }
-
-*/
-                               if(!$receipt['error'])
-                               {
-                                       $receipt = 
$this->so->add($location,$values_attribute,$type_id);
-                               }
-                       }
-                       return $receipt;
-               }
-
-               function delete($location_code)
-               {
-                       $this->so->delete($location_code);
-               }
-
-               function update_cat()
-               {
-                       return $this->so->update_cat();
-               }
-               function read_summary()
-               {
-
-                       $summary = $this->so->read_summary(array('filter' => 
$this->filter,'type_id' => $data['type_id'],
-                                                                               
        
'district_id'=>$this->district_id,'part_of_town_id'=>$this->part_of_town_id));
-                       $this->uicols = $this->so->uicols;
-                       return $summary;
-
-               }
-
-               function select_change_type($selected='')
-               {
-                       $nullable[0]['id']= 1;
-                       $nullable[0]['name']= lang('Correct error');
-                       $nullable[1]['id']= 2;
-                       $nullable[1]['name']= lang('New values');
-
-                       while (is_array($nullable) && list(,$type) = 
each($nullable))
-                       {
-                               $sel_type = '';
-                               if ($type['id']==$selected)
-                               {
-                                       $sel_type = 'selected';
-                               }
-
-                               $change_type_list[] = array
-                               (
-                                       'id'    => $type['id'],
-                                       'name'          => $type['name'],
-                                       'selected'      => $sel_type
-                               );
-                       }
-
-                       for ($i=0;$i<count($change_type_list);$i++)
-                       {
-                               if ($change_type_list[$i]['selected'] != 
'selected')
-                               {
-                                       
unset($change_type_list[$i]['selected']);
-                               }
-                       }
-                       return $change_type_list;
-               }
-
-               function check_history($location_code)
-               {
-                       return $this->so->check_history($location_code);
-               }
-
-               function get_history($location_code)
-               {
-                       $history = $this->so->get_history($location_code);
-                       $this->total_records = $this->so->total_records;
-                       $this->uicols = $this->so->uicols;
-
-                       return $history;
-
-               }
-
-       }
-?>
+<?php
+       /**
+       * phpGroupWare - property: a Facilities Management System.
+       *
+       * @author Sigurd Nes <address@hidden>
+       * @copyright Copyright (C) 2003-2005 Free Software Foundation, Inc. 
http://www.fsf.org/
+       * @license http://www.gnu.org/licenses/gpl.html GNU General Public 
License
+       * @internal Development of this application was funded by 
http://www.bergen.kommune.no/bbb_/ekstern/
+       * @package property
+       * @subpackage location
+       * @version $Id: class.bolocation.inc.php,v 1.10 2006/02/03 12:05:49 
sigurdne Exp $
+       */
+
+       /**
+        * Description
+        * @package property
+        */
+
+       class bolocation
+       {
+               var $start;
+               var $query;
+               var $filter;
+               var $sort;
+               var $order;
+               var $cat_id;
+
+               var $public_functions = array
+               (
+                       'read'          => True,
+                       'read_single'   => True,
+                       'save'          => True,
+                       'delete'        => True,
+                       'check_perms'   => True
+               );
+
+               var $soap_functions = array(
+                       'list' => array(
+                               'in'  => 
array('int','int','struct','string','int'),
+                               'out' => array('array')
+                       ),
+                       'read' => array(
+                               'in'  => array('int','struct'),
+                               'out' => array('array')
+                       ),
+                       'save' => array(
+                               'in'  => array('int','struct'),
+                               'out' => array()
+                       ),
+                       'delete' => array(
+                               'in'  => array('int','struct'),
+                               'out' => array()
+                       )
+               );
+
+               function bolocation($session=False)
+               {
+                       $this->currentapp               = 
$GLOBALS['phpgw_info']['flags']['currentapp'];
+                       $this->so                       = 
CreateObject($this->currentapp.'.solocation');
+                       $this->bocommon                 = 
CreateObject($this->currentapp.'.bocommon');
+                       $this->soadmin_location         = 
CreateObject($this->currentapp.'.soadmin_location');
+
+                       if ($session)
+                       {
+                               $this->read_sessiondata();
+                               $this->use_session = True;
+                       }
+
+                       $start          = get_var('start',array('POST','GET'));
+                       $query          = get_var('query',array('POST','GET'));
+                       $sort           = get_var('sort',array('POST','GET'));
+                       $order          = get_var('order',array('POST','GET'));
+                       $filter         = get_var('filter',array('POST','GET'));
+                       $cat_id         = get_var('cat_id',array('POST','GET'));
+                       $lookup_tenant  = 
get_var('lookup_tenant',array('POST','GET'));
+                       $district_id    = 
get_var('district_id',array('POST','GET'));
+                       $part_of_town_id = 
get_var('part_of_town_id',array('POST','GET'));
+                       $status         = get_var('status',array('POST','GET'));
+                       $type_id        = 
get_var('type_id',array('POST','GET'));
+                       $allrows        = 
get_var('allrows',array('POST','GET'));
+                       
+                       if ($start)
+                       {
+                               $this->start=$start;
+                       }
+                       else
+                       {
+                               $this->start=0;
+                       }
+
+                       if(isset($query))
+                       {
+                               $this->query = $query;
+                       }
+                       if(isset($filter))
+                       {
+                               $this->filter = $filter;
+                       }
+                       if(isset($sort))
+                       {
+                               $this->sort = $sort;
+                       }
+                       if(isset($order))
+                       {
+                               $this->order = $order;
+                       }
+                       if(isset($cat_id))
+                       {
+                               $this->cat_id = $cat_id;
+                       }
+                       if(isset($part_of_town_id))
+                       {
+                               $this->part_of_town_id = $part_of_town_id;
+                       }
+                       if(isset($district_id))
+                       {
+                               $this->district_id = $district_id;
+                       }
+                       if(isset($status))
+                       {
+                               $this->status = $status;
+                       }
+                       if(isset($type_id))
+                       {
+                               $this->type_id = $type_id;
+                       }
+                       if(isset($allrows))
+                       {
+                               $this->allrows = $allrows;
+                       }
+
+               }
+
+               function read_sessiondata()
+               {
+                       $data = 
$GLOBALS['phpgw']->session->appsession('session_data','location');
+
+                       $this->start                    = $data['start'];
+                       $this->query                    = $data['query'];
+                       $this->filter                   = $data['filter'];
+                       $this->sort                     = $data['sort'];
+                       $this->order                    = $data['order'];
+                       $this->cat_id                   = $data['cat_id'];
+                       $this->part_of_town_id          = 
$data['part_of_town_id'];
+                       $this->district_id              = $data['district_id'];
+                       $this->status                   = $data['status'];
+                       $this->type_id                  = $data['type_id'];     
                
+                       $this->allrows                  = $data['allrows'];
+               }
+
+               function save_sessiondata($data)
+               {
+                       if ($this->use_session)
+                       {
+                               
$GLOBALS['phpgw']->session->appsession('session_data','location',$data);
+                       }
+               }
+
+
+               function select_status_list($format='',$selected='')
+               {
+                       switch($format)
+                       {
+                               case 'select':
+                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('status_select'));
+                                       break;
+                               case 'filter':
+                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('status_filter'));
+                                       break;
+                       }
+
+                       $list= $this->so->select_status_list($this->type_id);
+                       return $this->bocommon->select_list($selected,$list);
+               }
+
+               function read_entity_to_link()
+               {
+                               return $this->so->read_entity_to_link();
+               }
+
+               function get_owner_list($format='',$selected='')
+               {
+
+                       switch($format)
+                       {
+                               case 'select':
+                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('filter_select'));
+                                       break;
+                               case 'filter':
+                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('filter_filter'));
+                                       break;
+                       }
+
+                       $owners = $this->so->get_owner_list();
+
+                       while (is_array($owners) && list(,$owner) = 
each($owners))
+                       {
+                               $sel_owner = '';
+                               if ($owner['id']==$selected)
+                               {
+                                       $sel_owner = 'selected';
+                               }
+
+                               $owner_list[] = array
+                               (
+                                       'id'            => $owner['id'],
+                                       'name'          => $owner['name'],
+                                       'selected'      => $sel_owner
+                               );
+                       }
+
+                       $owner_count=count($owner_list);
+                       for ($i=0;$i<$owner_count;$i++)
+                       {
+                               if ($owner_list[$i]['selected'] != 'selected')
+                               {
+                                       unset($owner_list[$i]['selected']);
+                               }
+                       }
+
+                       return $owner_list;
+               }
+
+               function get_owner_type_list($format='',$selected='')
+               {
+
+                       switch($format)
+                       {
+                               case 'select':
+                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('owner_select'));
+                                       break;
+                               case 'filter':
+                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('owner_filter'));
+                                       break;
+                       }
+
+                       $owners = $this->so->get_owner_type_list();
+
+                       while (is_array($owners) && list(,$owner) = 
each($owners))
+                       {
+                               $sel_owner = '';
+                               if ($owner['id']==$selected)
+                               {
+                                       $sel_owner = 'selected';
+                               }
+
+                               $owner_list[] = array
+                               (
+                                       'id'            => $owner['id'],
+                                       'name'          => $owner['name'],
+                                       'selected'      => $sel_owner
+                               );
+                       }
+
+                       $owner_count=count($owner_list);
+
+                       for ($i=0;$i<$owner_count;$i++)
+                       {
+                               if ($owner_list[$i]['selected'] != 'selected')
+                               {
+                                       unset($owner_list[$i]['selected']);
+                               }
+                       }
+
+                       return $owner_list;
+               }
+
+
+               function initiate_ui_location($data)
+               {
+
+                       switch($data['lookup_type'])
+                       {
+                               case 'form':
+                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('location_form'));
+                                       break;
+                               case 'view':
+                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('location_view'));
+                                       break;
+                       }
+
+                       $location_link          = 
$GLOBALS['phpgw']->link('/index.php','menuaction='.$this->currentapp.'.uilocation.index&lookup=1');
+
+                       $config = $this->soadmin_location->read_config('');
+
+                       $this->config   = $config;
+//_debug_array($config);
+                       $location_types = 
$this->soadmin_location->select_location_type();
+                       $this->location_types   = $location_types;
+
+                       if($data['type_id']<0)
+                       {
+                               $data['type_id'] = count($location_types);
+                       }
+//_debug_array($data);
+//_debug_array($location_types);
+                       $fm_location_cols = 
$this->soadmin_location->read_attrib(array('type_id'=>$data['type_id'],'lookup_type'=>$data['type_id']));
+//_debug_array($fm_location_cols);
+
+                       for ($i=0;$i<$data['type_id'];$i++)
+                       {
+                               $location['location'][$i]['input_type']         
                        = 'text';
+                               $location['location'][$i]['input_name']         
                        = 'loc' . ($i+1);
+                               $input_name[]                                   
                        = $location['location'][$i]['input_name'];
+                               $insert_record['location'][]                    
                        = $location['location'][$i]['input_name'];
+                               $location['location'][$i]['size']               
                        = 5;
+                               $location['location'][$i]['name']               
                        = $location_types[($i)]['name'];
+                               $location['location'][$i]['value']              
                        = $data['values']['loc' . ($i+1)];
+                               $location['location'][$i]['statustext']         
                        = lang('Klick this link to select') . ' ' . 
$location_types[($i)]['name'];
+
+                               if($i==0)
+                               {
+                                       
$location['location'][$i]['extra'][0]['input_name']             = 'loc' . 
($i+1).'_name';
+                                       $input_name[]                           
                        = $location['location'][$i]['extra'][0]['input_name'];
+                                       
$location['location'][$i]['extra'][0]['input_type']             = 'text';
+                                       
$location['location'][$i]['extra'][0]['size']                   = 30;
+                                       
$location['location'][$i]['extra'][0]['lookup_function_call']   = 'lookup_loc' 
. ($i+1) . '()';
+                                       
$location['location'][$i]['extra'][0]['value']                  = 
$data['values']['loc' . ($i+1).'_name'];
+                               }
+                               else
+                               {
+                                       
$location['location'][$i]['extra'][0]['input_name']             = 'loc' . 
($i+1).'_name';
+                                       $input_name[]                           
                        = $location['location'][$i]['extra'][0]['input_name'];
+                                       
$location['location'][$i]['extra'][0]['input_type']             = 'text';
+                                       
$location['location'][$i]['extra'][0]['size']                   = 30;
+                                       
$location['location'][$i]['extra'][0]['lookup_function_call']   = 'lookup_loc' 
. ($i+1) . '()';
+                                       
$location['location'][$i]['extra'][0]['value']                  = 
$data['values']['loc' . ($i+1).'_name'];
+                               }
+
+                               
$location['location'][$i]['lookup_function_call']                       = 
'lookup_loc' . ($i+1) . '()';
+                               $location['location'][$i]['lookup_link']        
                        = True;
+                               $location['location'][$i]['readonly']           
                        = True;
+                               $lookup_functions[$i]['name']                   
                        = 'lookup_loc' . ($i+1) . '()';
+                               $lookup_functions[$i]['action']                 
                        = 'Window1=window.open('."'" . $location_link 
.'&type_id=' . ($i+1) . '&lookup_name=' . $i . "'" 
.',"Search","width=800,height=700,toolbar=no,scrollbars=yes,resizable=yes");';
+
+                               if($data['no_link']>=($i+3))
+                               {
+                                       
$location['location'][$i]['lookup_link']                        = False;
+                                       $lookup_functions[$i]['action']         
                        = 'Window1=window.open('."'" . $location_link 
.'&type_id=' . ($data['no_link']-1) . '&lookup_name=' . ($data[no_link]-2) . 
"'" 
.',"Search","width=800,height=700,toolbar=no,scrollbars=yes,resizable=yes");';
+                                       $location['location'][$i]['statustext'] 
                        = lang('Klick this link to select') . ' ' . 
$location_types[($data[no_link]-2)]['name'];
+                               }
+
+
+                               if($data['query_link'] && $i < 
($data['type_id']-1))
+                               {
+                                               for ($j=1;$j<$i+2;$j++)
+                                               {
+                                                       $temp_location[]= 
$data['values']['loc' . ($j)];
+                                               }
+
+
+                                       $data['link_data']['query_location']    
                        = implode('-',$temp_location);
+                                       $location['location'][$i]['query_link'] 
                        = 
$GLOBALS['phpgw']->link('/index.php',$data['link_data']);
+                                       unset($temp_location);
+                               }
+
+
+                               $m=$i;
+                       }
+
+//_debug_array($fm_location_cols);
+//_debug_array($data);
+
+                       $location_cols_count =count($fm_location_cols);
+                       for ($j=0;$j<$location_cols_count;$j++)
+                       {
+                               if(($fm_location_cols[$j]['location_type'] <= 
$data['type_id']) && $fm_location_cols[$j]['lookup_form'])
+                               {
+                                       $location['location'][$i]['input_type'] 
                        = 'text';
+                                       $location['location'][$i]['input_name'] 
                        = $fm_location_cols[$j]['column_name'];
+                                       $input_name[]                           
                        = $location['location'][$i]['input_name'];
+                                       $location['location'][$i]['size']       
                        = 5;
+                                       
$location['location'][$i]['lookup_function_call']               = 'lookup_loc' 
. $fm_location_cols[$j]['location_type'] . '()';
+                                       
$location['location'][$i]['lookup_link']                        = True;
+                                       $location['location'][$i]['readonly']   
                        = True;
+                                       $location['location'][$i]['name']       
                        = $fm_location_cols[$j]['input_text'];
+                                       $location['location'][$i]['value']      
                        = $data['values'][$fm_location_cols[$j]['column_name']];
+                                       $location['location'][$i]['statustext'] 
                        = lang('Klick this link to select') . ' ' . 
$location_types[($fm_location_cols[$j]['location_type']-1)]['name'];
+                                       $i++;
+
+                               }
+                       }
+
+
+                       $config_count =count($config);
+                       for ($j=0;$j<$config_count;$j++)
+                       {
+                               if($config[$j]['location_type'] <= 
$data['type_id'] && $config[$j]['lookup_form'] )
+                               {
+                                       
if($config[$j]['column_name']=='street_id'):
+                                       {
+                                               
$location['location'][$i]['input_name']                 = 
$config[$j]['column_name'];
+                                               $input_name[]                   
                        = 'street_id';
+                                               
$location['location'][$i]['lookup_link']                = True;
+                                               
$location['location'][$i]['lookup_function_call']       = 'lookup_loc' . 
$config[$j]['location_type'] . '()';
+                                               
$location['location'][$i]['name']                       = lang('address');
+                                               
$location['location'][$i]['input_type']                 = 'hidden';
+                                               
$location['location'][$i]['value']                      = 
$data['values'][$config[$j]['column_name']];
+
+                                               
$location['location'][$i]['extra'][0]['input_type']     = 'text';
+                                               
$location['location'][$i]['extra'][0]['input_name']     = 'street_name';
+                                               
$location['location'][$i]['extra'][0]['readonly']       = True;
+                                               $input_name[]                   
                        = $location['location'][$i]['extra'][0]['input_name'];
+                                               
$location['location'][$i]['extra'][0]['size']           = 30;
+                                               
$location['location'][$i]['extra'][0]['lookup_function_call']   = 'lookup_loc' 
. $config[$j]['location_type'] . '()';
+                                               
$location['location'][$i]['extra'][0]['value']          = 
$data['values']['street_name'];
+
+                                               
$location['location'][$i]['extra'][1]['input_type']     = 'text';
+                                               
$location['location'][$i]['extra'][1]['input_name']     = 'street_number';
+                                               
$location['location'][$i]['extra'][1]['readonly']       = True;
+                                               $input_name[]                   
                        = $location['location'][$i]['extra'][1]['input_name'];
+                                               
$location['location'][$i]['extra'][1]['size']           = 6;
+                                               
$location['location'][$i]['extra'][1]['lookup_function_call']   = 'lookup_loc' 
. $config[$j]['location_type'] . '()';
+                                               
$location['location'][$i]['extra'][1]['value']          = 
$data['values']['street_number'];
+                                       }
+                                       
elseif($config[$j]['column_name']=='tenant_id' && $data['tenant']):
+                                       {
+                                               $m++;
+                                               $lookup_functions[$m]['name'] = 
'lookup_loc' . ($m+1) . '()';
+                                               $lookup_functions[$m]['action'] 
= 'Window1=window.open('."'" . $location_link .'&lookup_tenant=1&type_id=' . 
$config[$j]['location_type'] . '&lookup_name=' . $i ."'" 
.',"Search","width=800,height=700,toolbar=no,scrollbars=yes,resizable=yes");';
+
+                                               
$location['location'][$i]['lookup_link']                = True;
+                                               
$location['location'][$i]['name']                       = lang('Tenant');
+                                               
$location['location'][$i]['input_type']                 = 'hidden';
+                                               
$location['location'][$i]['input_name']                 = 'tenant_id';
+                                               $input_name[]                   
                        = $location['location'][$i]['input_name'];
+                                               
$location['location'][$i]['value']                      = 
$data['values'][$config[$j]['column_name']];
+                                               
$location['location'][$i]['lookup_function_call']       = 
$lookup_functions[$m]['name'];
+                                               
$location['location'][$i]['statustext']                 = lang('tenant');
+                                               
$insert_record['extra']['tenant_id']                    = 'tenant_id';
+
+                                               
$location['location'][$i]['extra'][0]['input_type']     = 'text';
+                                               
$location['location'][$i]['extra'][0]['input_name']     = 'last_name';
+                                               
$location['location'][$i]['extra'][0]['readonly']       = True;
+                                               $input_name[]                   
                        = $location['location'][$i]['extra'][0]['input_name'];
+                                               
$location['location'][$i]['extra'][0]['size']           = 15;
+                                               
$location['location'][$i]['extra'][0]['lookup_function_call']   = 
$lookup_functions[$m]['name'];
+                                               
$location['location'][$i]['extra'][0]['value']          = 
$data['values']['last_name'];
+                                               
$location['location'][$i]['extra'][0]['statustext']     = lang('last name');
+
+                                               
$location['location'][$i]['extra'][1]['input_type']     = 'text';
+                                               
$location['location'][$i]['extra'][1]['input_name']     = 'first_name';
+                                               
$location['location'][$i]['extra'][1]['readonly']       = True;
+                                               $input_name[]                   
                        = $location['location'][$i]['extra'][1]['input_name'];
+                                               
$location['location'][$i]['extra'][1]['size']           = 15;
+                                               
$location['location'][$i]['extra'][1]['lookup_function_call']   = 
$lookup_functions[$m]['name'];
+                                               
$location['location'][$i]['extra'][1]['value']          = 
$data['values']['first_name'];
+                                               
$location['location'][$i]['extra'][1]['statustext']     = lang('first name');
+                                               $i++;
+                                               
$location['location'][$i]['input_type']                 = 'text';
+                                               
$location['location'][$i]['name']                       = lang('Contact phone');
+                                               
$location['location'][$i]['input_name']                 = 'contact_phone';
+                                               $input_name[]                   
                        = $location['location'][$i]['input_name'];
+                                               
$location['location'][$i]['size']                       = 12;
+                                               
$location['location'][$i]['lookup_function_call']       = 
'';//$lookup_functions[$m]['name'];
+                                               
$insert_record['extra']['contact_phone']                = 'contact_phone';
+                                               
$location['location'][$i]['value']                      = 
$data['values']['contact_phone'];
+                                               
$location['location'][$i]['statustext']                 = lang('contact phone');
+                                       }
+                                       
elseif($config[$j]['column_name']!='tenant_id' && 
$config[$j]['column_name']!='street_id'):
+                                       {
+                                               
$location['location'][$i]['input_name']                 = 
$config[$j]['column_name'];
+                                               $input_name[]                   
                        = $location['location'][$i]['input_name'];
+//                                             $insert_record[]                
                        = $location['location'][$i]['input_name'];
+                                               
$location['location'][$i]['size']                       = 5;
+                                               
$location['location'][$i]['value']                      = 
$data['location']['value'][$config[$j]['column_name']];
+                                               
$location['location'][$i]['lookup_function_call']       = 'lookup_loc' . 
$fm_location_cols[$j]['location_type'] . '()';
+                                               
$location['location'][$i]['lookup_link']                = True;
+                                               
$location['location'][$i]['name']                       = $config[$j]['descr'];
+                                               
$location['location'][$i]['value']                      = 
$data['values'][$config[$j]['column_name']];
+                                               
$location['location'][$i]['statustext']                 = lang('Klick this link 
to select') . ' ' 
.$location_types[($fm_location_cols[$j]['location_type']-1)]['name'];
+                                               
$location['location'][$i]['input_type']                 = 'text';
+                                       }
+                                       endif;
+                                       $i++;
+                               }
+                       }
+
+                       if (isset($data['lookup_entity']) && 
is_array($data['lookup_entity']))
+                       {
+                               foreach($data['lookup_entity'] as $entity)
+                               {
+                                       $m++;
+                                       $entity_link            = 
$GLOBALS['phpgw']->link('/index.php','menuaction='.$this->currentapp.'.uilookup.entity&location_type='
 . $data['type_id'] . '&entity_id=' .$entity['id']);
+
+                                       $lookup_functions[$m]['name'] = 
'lookup_entity_' . $entity['id'] .'()';
+                                       $lookup_functions[$m]['action'] = 
'Window1=window.open('."'" . $entity_link ."'" 
.',"Search","width=800,height=700,toolbar=no,scrollbars=yes,resizable=yes");';
+
+                                       $location['location'][$i]['input_type'] 
                                        = 'text';
+                                       $location['location'][$i]['input_name'] 
                                        = 'entity_num_' . $entity['id'];
+                                       $input_name[]                           
                                                                        = 
'entity_num_' . $entity['id'];
+                                       $insert_record['extra']['entity_num_' . 
$entity['id']]                          = 'p_num';
+
+                                       $location['location'][$i]['size']       
                                        = 8;
+                                       
$location['location'][$i]['lookup_function_call']                               
= 'lookup_entity_' . $entity['id'] .'()';
+                                       
$location['location'][$i]['lookup_link']                                        
= True;
+                                       $location['location'][$i]['name']       
                                        = $entity['name'];
+                                       
+                                       if (is_array($data['entity_data']))
+                                       {
+                                               
$location['location'][$i]['value']                                      = 
$data['entity_data'][$entity['id']]['p_num'];
+                                       }
+                                       $location['location'][$i]['statustext'] 
                                        = lang('Klick this link to select') .' 
' . $entity['name'];
+
+                                       
$location['location'][$i]['extra'][0]['input_name']                             
= 'entity_cat_name_' . $entity['id'];
+                                       $input_name[]                           
                                        = 
$location['location'][$i]['extra'][0]['input_name'];
+                                       
$location['location'][$i]['extra'][0]['input_type']                             
= 'text';
+                                       
$location['location'][$i]['extra'][0]['size']                                   
= 30;
+                                       
$location['location'][$i]['extra'][0]['lookup_function_call']   = 
'lookup_entity_' . $entity['id'] .'()';
+                                       
+                                       if (is_array($data['entity_data']))
+                                       {
+                                               
$location['location'][$i]['extra'][0]['value']                          = 
$data['entity_data'][$entity['id']]['p_cat_name'];
+                                       }
+
+                                       
$location['location'][$i]['extra'][1]['input_type']                             
= 'hidden';
+                                       
$location['location'][$i]['extra'][1]['input_name']                             
= 'entity_id_' . $entity['id'];
+                                       $input_name[]                           
                                                                        = 
'entity_id_' . $entity['id'];
+                                       $insert_record['extra']['entity_id_' . 
$entity['id']]                           = 'p_entity_id';
+                                       if (is_array($data['entity_data']))
+                                       {
+                                               
$location['location'][$i]['extra'][1]['value']                          = 
$data['entity_data'][$entity['id']]['p_entity_id'];
+                                       }
+
+                                       
$location['location'][$i]['extra'][2]['input_type']                             
= 'hidden';
+                                       
$location['location'][$i]['extra'][2]['input_name']                             
= 'cat_id_' . $entity['id'];
+                                       $input_name[]                           
                                                                        = 
'cat_id_' . $entity['id'];
+                                       $insert_record['extra']['cat_id_' . 
$entity['id']]                              = 'p_cat_id';
+                               
+                                       if (is_array($data['entity_data']))
+                                       {
+                                               
$location['location'][$i]['extra'][2]['value']                          = 
$data['entity_data'][$entity['id']]['p_cat_id'];
+                                       }
+
+                                       $i++;
+                               }
+                       }
+
+//_debug_array($location['location']);
+
+                       
$GLOBALS['phpgw']->session->appsession('lookup_fields',$this->currentapp,$input_name);
+                       
$GLOBALS['phpgw']->session->appsession('insert_record',$this->currentapp,$insert_record);
+//                     
$GLOBALS['phpgw']->session->appsession('input_name',$this->currentapp,$input_name);
+
+                       for ($i=0;$i<count($location['location']);$i++)
+                       {
+                               $lookup_name[] = 
$location['location'][$i]['name'];
+
+                       }
+
+                       
$GLOBALS['phpgw']->session->appsession('lookup_name',$this->currentapp,$lookup_name);
+
+                       for ($j=0;$j<count($lookup_functions);$j++)
+                       {
+                               $location['lookup_functions'] .= 'function ' . 
$lookup_functions[$j]['name'] ."\r\n";
+                               $location['lookup_functions'] .= '{'."\r\n";
+                               $location['lookup_functions'] .= 
$lookup_functions[$j]['action'] ."\r\n";
+                               $location['lookup_functions'] .= '}'."\r\n";
+                       }
+
+
+//_debug_array($location);
+
+                       return $location;
+
+               }
+
+               function 
select_category_list($format='',$selected='',$type_id='')
+               {
+                       switch($format)
+                       {
+                               case 'select':
+                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('cat_select'));
+                                       break;
+                               case 'filter':
+                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('cat_filter'));
+                                       break;
+                       }
+
+                       $categories= $this->so->select_category_list($type_id);
+
+                       while (is_array($categories) && list(,$category) = 
each($categories))
+                       {
+                               $sel_category = '';
+                               if ($category['id']==$selected)
+                               {
+                                       $sel_category = 'selected';
+                               }
+
+                               $category_list[] = array
+                               (
+                                       'cat_id'        => $category['id'],
+                                       'name'          => $category['name'],
+                                       'selected'      => $sel_category
+                               );
+                       }
+
+                       $category_count=count($category_list);
+                       for ($i=0;$i<$category_count;$i++)
+                       {
+                               if ($category_list[$i]['selected'] != 
'selected')
+                               {
+                                       unset($category_list[$i]['selected']);
+                               }
+                       }
+
+                       return $category_list;
+               }
+
+
+               function read($data='')
+               {
+                       $location = $this->so->read(array('start' => 
$this->start,'query' => $this->query,'sort' => $this->sort,'order' => 
$this->order,
+                                                                               
        'filter' => $this->filter,'cat_id' => $this->cat_id,'type_id' => 
$data['type_id'],
+                                                                               
        'lookup_tenant'=>$data['lookup_tenant'],'lookup'=>$data['lookup'],
+                                                                               
        'district_id'=>$this->district_id,'allrows'=>$data['allrows'],
+                                                                               
        'status'=>$this->status,'part_of_town_id'=>$this->part_of_town_id));
+                       $this->total_records = $this->so->total_records;
+                       $this->uicols = $this->so->uicols;
+
+                       return $location;
+               }
+
+               function read_single($location_code='',$extra='')
+               {
+                       $location_data = $this->so->read_single($location_code);
+
+                       if(!$extra['tenant_id']=='lookup')
+                       {
+                               if($extra['tenant_id']>0)
+                               {
+                                       
$tenant_data=$this->bocommon->read_single_tenant($extra['tenant_id']);
+                                       $location_data['tenant_id']     = 
$extra['tenant_id'];
+                                       $location_data['contact_phone']= 
$extra['contact_phone'];
+                                       $location_data['last_name']     = 
$tenant_data['last_name'];
+                                       $location_data['first_name']    = 
$tenant_data['first_name'];
+                               }
+                               else
+                               {
+                                       unset($location_data['tenant_id']);
+                                       unset($location_data['contact_phone']);
+                                       unset($location_data['last_name']);
+                                       unset($location_data['first_name']);
+                               }
+                       }
+
+                       if(is_array($extra))
+                       {
+                               $location_data = $location_data + $extra;
+                       }
+                       return $location_data;
+               }
+
+               function check_location($location_code='',$type_id='')
+               {
+                       return 
$this->so->check_location($location_code,$type_id);
+               }
+
+
+               function 
save($location,$values_attribute,$action='',$type_id='',$location_code_parent='')
+               {
+
+
+//_debug_array($values_attribute);
+/*                     $location_datatype = 
$GLOBALS['phpgw']->session->appsession('location_datatype',$this->currentapp);
+//     _debug_array($location_datatype);
+
+                       if(is_array($location_datatype))
+                       {
+                               for ($i=0;$i<count($location_datatype);$i++)
+                               {
+                                       
if($location_datatype[$i]['datatype']=='decimal' && 
$location[$location_datatype[$i]['input_name']])
+                                       {
+                                               
$location[$location_datatype[$i]['input_name']] = 
str_replace(",",".",$location[$location_datatype[$i]['input_name']]);
+                                       }
+
+                                       
if($location_datatype[$i]['datatype']=='date' && 
$location[$location_datatype[$i]['input_name']])
+                                       {
+                                               $dateformat= 
$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
+                                               $dateformat = 
str_replace(".","",$dateformat);
+                                               $dateformat = 
str_replace("-","",$dateformat);
+                                               $dateformat = 
str_replace("/","",$dateformat);
+                                               $y=strpos($dateformat,'Y');
+                                               $d=strpos($dateformat,'d');
+                                               $m=strpos($dateformat,'m');
+
+                                               $dateparts = explode('/', 
$location[$location_datatype[$i]['input_name']]);
+                                               $day            = 
$dateparts[$d];
+                                               $month          = 
$dateparts[$m];
+                                               $year           = 
$dateparts[$y];
+
+//                                             
$location[$location_datatype[$i]['input_name']] = 
date($this->bocommon->dateformat,mktime(2,0,0,$month,$day,$year));
+                                               
$location[$location_datatype[$i]['input_name']] = 
mktime(0,0,0,$month,$day,$year);
+
+                                       }
+                               }
+                       }
+
+*/
+
+                       $m=count($values_attribute);
+                       for ($i=0;$i<$m;$i++)
+                       {
+                               if($values_attribute[$i]['datatype']=='AB' || 
$values_attribute[$i]['datatype']=='VENDOR')
+                               {
+                                       $values_attribute[$i]['value'] = 
$_POST[$values_attribute[$i]['name']];
+                               }
+                               if($values_attribute[$i]['datatype']=='CH' && 
$values_attribute[$i]['value'])
+                               {
+                                       $values_attribute[$i]['value'] = 
serialize($values_attribute[$i]['value']);
+                               }
+                               if($values_attribute[$i]['datatype']=='R' && 
$values_attribute[$i]['value'])
+                               {
+                                       $values_attribute[$i]['value'] = 
$values_attribute[$i]['value'][0];
+                               }
+
+                               if($values_attribute[$i]['datatype']=='N' && 
$values_attribute[$i]['value'])
+                               {
+                                       $values_attribute[$i]['value'] = 
str_replace(",",".",$values_attribute[$i]['value']);
+                               }
+
+                               if($values_attribute[$i]['datatype']=='D' && 
$values_attribute[$i]['value'])
+                               {
+
+                                       $values_attribute[$i]['value'] = 
date($this->bocommon->dateformat,$this->bocommon->date_to_timestamp($values_attribute[$i]['value']));
+                               }
+                       }
+
+
+//_debug_array($values_attribute);
+
+
+
+//     _debug_array($location);
+
+                       if ($action=='edit')
+                       {
+                               if 
($this->so->check_location($location['location_code'],$type_id))
+                               {
+                                       $receipt = 
$this->so->edit($location,$values_attribute,$type_id);
+                               }
+                               else
+                               {
+                                       
$receipt['error'][]=array('msg'=>lang('This location ID does not exist!'));
+                               }
+                       }
+                       else
+                       {
+
+/*                             if($type_id>1)
+                               {
+                                       
if(!$this->so->check_location($location_code_parent,($type_id-1)))
+                                       {
+                                               
$receipt['error'][]=array('msg'=>lang('This location parent ID does not 
exist!'));
+                                       }
+                               }
+
+*/
+                               if(!$receipt['error'])
+                               {
+                                       $receipt = 
$this->so->add($location,$values_attribute,$type_id);
+                               }
+                       }
+                       return $receipt;
+               }
+
+               function delete($location_code)
+               {
+                       $this->so->delete($location_code);
+               }
+
+               function update_cat()
+               {
+                       return $this->so->update_cat();
+               }
+               function read_summary()
+               {
+
+                       $summary = $this->so->read_summary(array('filter' => 
$this->filter,'type_id' => $data['type_id'],
+                                                                               
        
'district_id'=>$this->district_id,'part_of_town_id'=>$this->part_of_town_id));
+                       $this->uicols = $this->so->uicols;
+                       return $summary;
+
+               }
+
+               function select_change_type($selected='')
+               {
+                       $nullable[0]['id']= 1;
+                       $nullable[0]['name']= lang('Correct error');
+                       $nullable[1]['id']= 2;
+                       $nullable[1]['name']= lang('New values');
+
+                       while (is_array($nullable) && list(,$type) = 
each($nullable))
+                       {
+                               $sel_type = '';
+                               if ($type['id']==$selected)
+                               {
+                                       $sel_type = 'selected';
+                               }
+
+                               $change_type_list[] = array
+                               (
+                                       'id'    => $type['id'],
+                                       'name'          => $type['name'],
+                                       'selected'      => $sel_type
+                               );
+                       }
+
+                       for ($i=0;$i<count($change_type_list);$i++)
+                       {
+                               if ($change_type_list[$i]['selected'] != 
'selected')
+                               {
+                                       
unset($change_type_list[$i]['selected']);
+                               }
+                       }
+                       return $change_type_list;
+               }
+
+               function check_history($location_code)
+               {
+                       return $this->so->check_history($location_code);
+               }
+
+               function get_history($location_code)
+               {
+                       $history = $this->so->get_history($location_code);
+                       $this->total_records = $this->so->total_records;
+                       $this->uicols = $this->so->uicols;
+
+                       return $history;
+
+               }
+
+       }
+?>
Index: property/inc/class.bolookup.inc.php
diff -u property/inc/class.bolookup.inc.php:1.7 
property/inc/class.bolookup.inc.php:1.8
--- property/inc/class.bolookup.inc.php:1.7     Fri Jan 27 14:05:43 2006
+++ property/inc/class.bolookup.inc.php Fri Feb  3 12:05:49 2006
@@ -1,254 +1,254 @@
-<?php
-       /**
-       * phpGroupWare - property: a Facilities Management System.
-       *
-       * @author Sigurd Nes <address@hidden>
-       * @copyright Copyright (C) 2003-2005 Free Software Foundation, Inc. 
http://www.fsf.org/
-       * @license http://www.gnu.org/licenses/gpl.html GNU General Public 
License
-       * @internal Development of this application was funded by 
http://www.bergen.kommune.no/bbb_/ekstern/
-       * @package property
-       * @subpackage core
-       * @version $Id: class.bolookup.inc.php,v 1.7 2006/01/27 14:05:43 
sigurdne Exp $
-       */
-
-       /**
-        * Description
-        * @package property
-        */
-
-       class bolookup
-       {
-               var $start;
-               var $query;
-               var $filter;
-               var $sort;
-               var $order;
-               var $cat_id;
-
-               var $public_functions = array
-               (
-                       'read'                          => True,
-                       'read_single'           => True,
-                       'save'                          => True,
-                       'delete'                        => True,
-                       'check_perms'           => True
-               );
-
-               var $soap_functions = array(
-                       'list' => array(
-                               'in'  => 
array('int','int','struct','string','int'),
-                               'out' => array('array')
-                       ),
-                       'read' => array(
-                               'in'  => array('int','struct'),
-                               'out' => array('array')
-                       ),
-                       'save' => array(
-                               'in'  => array('int','struct'),
-                               'out' => array()
-                       ),
-                       'delete' => array(
-                               'in'  => array('int','struct'),
-                               'out' => array()
-                       )
-               );
-
-               function bolookup($session=False)
-               {
-                       $this->currentapp       = 
$GLOBALS['phpgw_info']['flags']['currentapp'];
-                       $this->so               = 
CreateObject($this->currentapp.'.solookup');
-                       $this->solocation = 
CreateObject($this->currentapp.'.solocation');
-
-
-                       if ($session)
-                       {
-                               $this->read_sessiondata();
-                               $this->use_session = True;
-                       }
-
-                       $start                  = 
get_var('start',array('POST','GET'));
-                       $query                  = 
get_var('query',array('POST','GET'));
-                       $sort                   = 
get_var('sort',array('POST','GET'));
-                       $order                  = 
get_var('order',array('POST','GET'));
-                       $filter                 = 
get_var('filter',array('POST','GET'));
-                       $cat_id                 = 
get_var('cat_id',array('POST','GET'));
-                       $district_id    = 
get_var('district_id',array('POST','GET'));
-
-                       if ($start)
-                       {
-                               $this->start=$start;
-                       }
-                       else
-                       {
-                               $this->start=0;
-                       }
-
-                       if(isset($query))
-                       {
-                               $this->query = $query;
-                       }
-                       if(!empty($filter))
-                       {
-                               $this->filter = $filter;
-                       }
-                       if(isset($sort))
-                       {
-                               $this->sort = $sort;
-                       }
-                       if(isset($order))
-                       {
-                               $this->order = $order;
-                       }
-                       if(isset($cat_id))
-                       {
-                               $this->cat_id = $cat_id;
-                       }
-                       if(isset($district_id))
-                       {
-                               $this->district_id = $district_id;
-                       }
-               }
-
-               function save_sessiondata($data)
-               {
-                       if ($this->use_session)
-                       {
-                               
$GLOBALS['phpgw']->session->appsession('session_data','lookup',$data);
-                       }
-               }
-
-               function read_sessiondata()
-               {
-                       $data = 
$GLOBALS['phpgw']->session->appsession('session_data','lookup');
-
-                       //_debug_array($data);
-
-                       $this->start    = $data['start'];
-                       $this->query    = $data['query'];
-                       $this->filter   = $data['filter'];
-                       $this->sort             = $data['sort'];
-                       $this->order    = $data['order'];
-                       $this->cat_id   = $data['cat_id'];
-                       $this->district_id      = $data['district_id'];
-               }
-
-
-               function read_addressbook()
-               {
-//                     $contact = $this->so->read_addressbook(array('start' => 
$this->start,'query' => $this->query,'sort' => $this->sort,'order' => 
$this->order,
-//                                                                             
        'filter' => $this->filter,'cat_id' => $this->cat_id));
-//                     $this->total_records = $this->so->total_records;
-
-
-                       
if($GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'] &&
-                               
$GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'] > 0)
-                       {
-                               $this->limit = 
$GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'];
-                       }
-                       else
-                       {
-                               $this->limit = 15;
-                       }
-
-                   $fields[0] = 'per_first_name';
-                   $fields[1] = 'per_last_name';
-                   $fields[2] = 'per_department';
-                   $fields[3] = 'per_title';
-                   $fields[4] = 'addr_add1';
-                   $fields[5] = 'addr_city';
-                   $fields['owner'] = 'owner';
-                   $fields['contact_id'] = 'contact_id';
-
-
-                       $addressbook    = 
CreateObject('addressbook.boaddressbook');
-
-                       $criteria = $addressbook->criteria_contacts(1, -3, 
'person', $this->query, $fields_search);
-
-//_debug_array($criteria);
-                       $entries = $addressbook->get_persons($fields, 
$this->limit, $this->start, $this->order, $this->sort, '', $criteria);
-
-//_debug_array($entries);
-                       return $entries;
-               }
-
-
-               /**
-               * Get the the person data what you want
-               *
-               * @param array $fields The fields that you can see from person
-               * @param integer $limit Limit of records that you want
-               * @param integer $ofset Ofset of record that you want start
-               * @param string $orderby The field which you want order
-               * @param string $sort ASC | DESC depending what you want
-               * @param mixed $criteria All criterias what you want
-               * @param mixed $criteria_token same like $criteria but 
builded<br>with sql_criteria class, more powerfull
-               * @return array with records
-               */
-               function get_persons($fields, $start='', $limit='', 
$orderby='', $sort='', $criteria='', $token_criteria='')
-               {
-                       $entries =  $this->so->get_persons($fields, $start, 
$limit, $orderby, $sort, $criteria, $token_criteria);
-                       if(is_array($entries))
-                       {
-                               foreach($entries as $data)
-                               {
-                                       $persons[$data['contact_id']] = $data;
-                               }
-                       }
-                       else
-                       {
-                               $persons = array();
-                       }
-                       $this->total = $this->so->contacts->total_records;
-                       return $persons;
-               }
-
-
-
-
-
-               function read_vendor()
-               {
-                       $vendor = $this->so->read_vendor(array('start' => 
$this->start,'query' => $this->query,'sort' => $this->sort,'order' => 
$this->order,
-                                                                               
        'filter' => $this->filter,'cat_id' => $this->cat_id));
-                       $this->total_records = $this->so->total_records;
-
-                       return $vendor;
-               }
-
-               function read_b_account()
-               {
-                       $b_account = $this->so->read_b_account(array('start' => 
$this->start,'query' => $this->query,'sort' => $this->sort,'order' => 
$this->order,
-                                                                               
        'filter' => $this->filter,'cat_id' => $this->cat_id));
-                       $this->total_records = $this->so->total_records;
-
-                       return $b_account;
-               }
-
-               function read_street()
-               {
-                       $street = $this->so->read_street(array('start' => 
$this->start,'query' => $this->query,'sort' => $this->sort,'order' => 
$this->order,
-                                                                               
        'filter' => $this->filter,'cat_id' => $this->cat_id));
-                       $this->total_records = $this->so->total_records;
-
-                       return $street;
-               }
-
-               function read_tenant()
-               {
-                       $tenant = $this->so->read_tenant(array('start' => 
$this->start,'query' => $this->query,'sort' => $this->sort,'order' => 
$this->order,
-                                                                               
        'filter' => $this->filter,'cat_id' => $this->cat_id));
-                       $this->total_records = $this->so->total_records;
-
-                       return $tenant;
-               }
-
-               function read_ns3420()
-               {
-                       $ns3420 = $this->so->read_ns3420(array('start' => 
$this->start,'query' => $this->query,'sort' => $this->sort,'order' => 
$this->order,
-                                                                               
        'filter' => $this->filter,'cat_id' => $this->cat_id));
-                       $this->total_records = $this->so->total_records;
-
-                       return $ns3420;
-               }
-       }
-?>
+<?php
+       /**
+       * phpGroupWare - property: a Facilities Management System.
+       *
+       * @author Sigurd Nes <address@hidden>
+       * @copyright Copyright (C) 2003-2005 Free Software Foundation, Inc. 
http://www.fsf.org/
+       * @license http://www.gnu.org/licenses/gpl.html GNU General Public 
License
+       * @internal Development of this application was funded by 
http://www.bergen.kommune.no/bbb_/ekstern/
+       * @package property
+       * @subpackage core
+       * @version $Id: class.bolookup.inc.php,v 1.8 2006/02/03 12:05:49 
sigurdne Exp $
+       */
+
+       /**
+        * Description
+        * @package property
+        */
+
+       class bolookup
+       {
+               var $start;
+               var $query;
+               var $filter;
+               var $sort;
+               var $order;
+               var $cat_id;
+
+               var $public_functions = array
+               (
+                       'read'                          => True,
+                       'read_single'           => True,
+                       'save'                          => True,
+                       'delete'                        => True,
+                       'check_perms'           => True
+               );
+
+               var $soap_functions = array(
+                       'list' => array(
+                               'in'  => 
array('int','int','struct','string','int'),
+                               'out' => array('array')
+                       ),
+                       'read' => array(
+                               'in'  => array('int','struct'),
+                               'out' => array('array')
+                       ),
+                       'save' => array(
+                               'in'  => array('int','struct'),
+                               'out' => array()
+                       ),
+                       'delete' => array(
+                               'in'  => array('int','struct'),
+                               'out' => array()
+                       )
+               );
+
+               function bolookup($session=False)
+               {
+                       $this->currentapp       = 
$GLOBALS['phpgw_info']['flags']['currentapp'];
+                       $this->so               = 
CreateObject($this->currentapp.'.solookup');
+                       $this->solocation = 
CreateObject($this->currentapp.'.solocation');
+
+
+                       if ($session)
+                       {
+                               $this->read_sessiondata();
+                               $this->use_session = True;
+                       }
+
+                       $start                  = 
get_var('start',array('POST','GET'));
+                       $query                  = 
get_var('query',array('POST','GET'));
+                       $sort                   = 
get_var('sort',array('POST','GET'));
+                       $order                  = 
get_var('order',array('POST','GET'));
+                       $filter                 = 
get_var('filter',array('POST','GET'));
+                       $cat_id                 = 
get_var('cat_id',array('POST','GET'));
+                       $district_id    = 
get_var('district_id',array('POST','GET'));
+
+                       if ($start)
+                       {
+                               $this->start=$start;
+                       }
+                       else
+                       {
+                               $this->start=0;
+                       }
+
+                       if(isset($query))
+                       {
+                               $this->query = $query;
+                       }
+                       if(!empty($filter))
+                       {
+                               $this->filter = $filter;
+                       }
+                       if(isset($sort))
+                       {
+                               $this->sort = $sort;
+                       }
+                       if(isset($order))
+                       {
+                               $this->order = $order;
+                       }
+                       if(isset($cat_id))
+                       {
+                               $this->cat_id = $cat_id;
+                       }
+                       if(isset($district_id))
+                       {
+                               $this->district_id = $district_id;
+                       }
+               }
+
+               function save_sessiondata($data)
+               {
+                       if ($this->use_session)
+                       {
+                               
$GLOBALS['phpgw']->session->appsession('session_data','lookup',$data);
+                       }
+               }
+
+               function read_sessiondata()
+               {
+                       $data = 
$GLOBALS['phpgw']->session->appsession('session_data','lookup');
+
+                       //_debug_array($data);
+
+                       $this->start    = $data['start'];
+                       $this->query    = $data['query'];
+                       $this->filter   = $data['filter'];
+                       $this->sort             = $data['sort'];
+                       $this->order    = $data['order'];
+                       $this->cat_id   = $data['cat_id'];
+                       $this->district_id      = $data['district_id'];
+               }
+
+
+               function read_addressbook()
+               {
+//                     $contact = $this->so->read_addressbook(array('start' => 
$this->start,'query' => $this->query,'sort' => $this->sort,'order' => 
$this->order,
+//                                                                             
        'filter' => $this->filter,'cat_id' => $this->cat_id));
+//                     $this->total_records = $this->so->total_records;
+
+
+                       
if($GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'] &&
+                               
$GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'] > 0)
+                       {
+                               $this->limit = 
$GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'];
+                       }
+                       else
+                       {
+                               $this->limit = 15;
+                       }
+
+                   $fields[0] = 'per_first_name';
+                   $fields[1] = 'per_last_name';
+                   $fields[2] = 'per_department';
+                   $fields[3] = 'per_title';
+                   $fields[4] = 'addr_add1';
+                   $fields[5] = 'addr_city';
+                   $fields['owner'] = 'owner';
+                   $fields['contact_id'] = 'contact_id';
+
+
+                       $addressbook    = 
CreateObject('addressbook.boaddressbook');
+
+                       $criteria = $addressbook->criteria_contacts(1, -3, 
'person', $this->query, $fields_search);
+
+//_debug_array($criteria);
+                       $entries = $addressbook->get_persons($fields, 
$this->limit, $this->start, $this->order, $this->sort, '', $criteria);
+
+//_debug_array($entries);
+                       return $entries;
+               }
+
+
+               /**
+               * Get the the person data what you want
+               *
+               * @param array $fields The fields that you can see from person
+               * @param integer $limit Limit of records that you want
+               * @param integer $ofset Ofset of record that you want start
+               * @param string $orderby The field which you want order
+               * @param string $sort ASC | DESC depending what you want
+               * @param mixed $criteria All criterias what you want
+               * @param mixed $criteria_token same like $criteria but 
builded<br>with sql_criteria class, more powerfull
+               * @return array with records
+               */
+               function get_persons($fields, $start='', $limit='', 
$orderby='', $sort='', $criteria='', $token_criteria='')
+               {
+                       $entries =  $this->so->get_persons($fields, $start, 
$limit, $orderby, $sort, $criteria, $token_criteria);
+                       if(is_array($entries))
+                       {
+                               foreach($entries as $data)
+                               {
+                                       $persons[$data['contact_id']] = $data;
+                               }
+                       }
+                       else
+                       {
+                               $persons = array();
+                       }
+                       $this->total = $this->so->contacts->total_records;
+                       return $persons;
+               }
+
+
+
+
+
+               function read_vendor()
+               {
+                       $vendor = $this->so->read_vendor(array('start' => 
$this->start,'query' => $this->query,'sort' => $this->sort,'order' => 
$this->order,
+                                                                               
        'filter' => $this->filter,'cat_id' => $this->cat_id));
+                       $this->total_records = $this->so->total_records;
+
+                       return $vendor;
+               }
+
+               function read_b_account()
+               {
+                       $b_account = $this->so->read_b_account(array('start' => 
$this->start,'query' => $this->query,'sort' => $this->sort,'order' => 
$this->order,
+                                                                               
        'filter' => $this->filter,'cat_id' => $this->cat_id));
+                       $this->total_records = $this->so->total_records;
+
+                       return $b_account;
+               }
+
+               function read_street()
+               {
+                       $street = $this->so->read_street(array('start' => 
$this->start,'query' => $this->query,'sort' => $this->sort,'order' => 
$this->order,
+                                                                               
        'filter' => $this->filter,'cat_id' => $this->cat_id));
+                       $this->total_records = $this->so->total_records;
+
+                       return $street;
+               }
+
+               function read_tenant()
+               {
+                       $tenant = $this->so->read_tenant(array('start' => 
$this->start,'query' => $this->query,'sort' => $this->sort,'order' => 
$this->order,
+                                                                               
        'filter' => $this->filter,'cat_id' => $this->cat_id));
+                       $this->total_records = $this->so->total_records;
+
+                       return $tenant;
+               }
+
+               function read_ns3420()
+               {
+                       $ns3420 = $this->so->read_ns3420(array('start' => 
$this->start,'query' => $this->query,'sort' => $this->sort,'order' => 
$this->order,
+                                                                               
        'filter' => $this->filter,'cat_id' => $this->cat_id));
+                       $this->total_records = $this->so->total_records;
+
+                       return $ns3420;
+               }
+       }
+?>
Index: property/inc/class.bometer.inc.php
diff -u property/inc/class.bometer.inc.php:1.6 
property/inc/class.bometer.inc.php:1.7
--- property/inc/class.bometer.inc.php:1.6      Fri Jan 27 14:05:43 2006
+++ property/inc/class.bometer.inc.php  Fri Feb  3 12:05:49 2006
@@ -1,260 +1,260 @@
-<?php
-       /**
-       * phpGroupWare - property: a Facilities Management System.
-       *
-       * @author Sigurd Nes <address@hidden>
-       * @copyright Copyright (C) 2003-2005 Free Software Foundation, Inc. 
http://www.fsf.org/
-       * @license http://www.gnu.org/licenses/gpl.html GNU General Public 
License
-       * @internal Development of this application was funded by 
http://www.bergen.kommune.no/bbb_/ekstern/
-       * @package property
-       * @subpackage entity
-       * @version $Id: class.bometer.inc.php,v 1.6 2006/01/27 14:05:43 
sigurdne Exp $
-       */
-
-       /**
-        * Description
-        * @package property
-        */
-
-       class bometer
-       {
-               var $start;
-               var $query;
-               var $filter;
-               var $sort;
-               var $order;
-               var $cat_id;
-
-               var $public_functions = array
-               (
-                       'read'                          => True,
-                       'read_single'           => True,
-                       'save'                          => True,
-                       'delete'                        => True,
-                       'check_perms'           => True
-               );
-
-               var $soap_functions = array(
-                       'list' => array(
-                               'in'  => 
array('int','int','struct','string','int'),
-                               'out' => array('array')
-                       ),
-                       'read' => array(
-                               'in'  => array('int','struct'),
-                               'out' => array('array')
-                       ),
-                       'save' => array(
-                               'in'  => array('int','struct'),
-                               'out' => array()
-                       ),
-                       'delete' => array(
-                               'in'  => array('int','struct'),
-                               'out' => array()
-                       )
-               );
-
-               function bometer($session=False)
-               {
-                       $this->currentapp       = 
$GLOBALS['phpgw_info']['flags']['currentapp'];
-                       $this->so               = 
CreateObject($this->currentapp.'.someter');
-                       $this->bocommon = 
CreateObject($this->currentapp.'.bocommon');
-
-                       if ($session)
-                       {
-                               $this->read_sessiondata();
-                               $this->use_session = True;
-                       }
-
-                       $start  = get_var('start',array('POST','GET'));
-                       $query  = get_var('query',array('POST','GET'));
-                       $sort   = get_var('sort',array('POST','GET'));
-                       $order  = get_var('order',array('POST','GET'));
-                       $filter = get_var('filter',array('POST','GET'));
-                       $cat_id = get_var('cat_id',array('POST','GET'));
-
-                       if ($start)
-                       {
-                               $this->start=$start;
-                       }
-                       else
-                       {
-                               $this->start=0;
-                       }
-
-                       if(isset($query))
-                       {
-                               $this->query = $query;
-                       }
-                       if(!empty($filter))
-                       {
-                               $this->filter = $filter;
-                       }
-                       if(isset($sort))
-                       {
-                               $this->sort = $sort;
-                       }
-                       if(isset($order))
-                       {
-                               $this->order = $order;
-                       }
-                       if(isset($cat_id))
-                       {
-                               $this->cat_id = $cat_id;
-                       }
-               }
-
-               function save_sessiondata($data)
-               {
-                       if ($this->use_session)
-                       {
-                               
$GLOBALS['phpgw']->session->appsession('session_data','meter',$data);
-                       }
-               }
-
-               function read_sessiondata()
-               {
-                       $data = 
$GLOBALS['phpgw']->session->appsession('session_data','meter');
-
-                       $this->start    = $data['start'];
-                       $this->query    = $data['query'];
-                       $this->filter   = $data['filter'];
-                       $this->sort             = $data['sort'];
-                       $this->order    = $data['order'];
-                       $this->cat_id   = $data['cat_id'];
-               }
-
-               function get_category_list($format='',$selected='')
-               {
-                       switch($format)
-                       {
-                               case 'select':
-                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('cat_select'));
-                                       break;
-                               case 'filter':
-                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('cat_filter'));
-                                       break;
-                       }
-
-                       $categories= $this->so->get_category_list();
-
-                       while (is_array($categories) && list(,$category) = 
each($categories))
-                       {
-                               $sel_category = '';
-                               if ($category['id']==$selected)
-                               {
-                                       $sel_category = 'selected';
-                               }
-
-                               $category_list[] = array
-                               (
-                                       'cat_id'        => $category['id'],
-                                       'name'          => $category['name'],
-                                       'selected'      => $sel_category
-                               );
-                       }
-
-                       for ($i=0;$i<count($category_list);$i++)
-                       {
-                               if ($category_list[$i]['selected'] != 
'selected')
-                               {
-                                       unset($category_list[$i]['selected']);
-                               }
-                       }
-
-                       return $category_list;
-               }
-
-               function read()
-               {
-                       $meter = $this->so->read(array('start' => 
$this->start,'query' => $this->query,'sort' => $this->sort,'order' => 
$this->order,
-                                                                               
        'filter' => $this->filter,'cat_id' => $this->cat_id));
-                       $this->total_records = $this->so->total_records;
-
-                       $this->uicols   = $this->so->uicols;
-/*                     $cols_extra             = $this->so->cols_extra;
-                       $dateformat = 
$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
-                       $solocation = 
CreateObject($this->currentapp.'.solocation');
-
-                       for ($i=0; $i<count($meter); $i++)
-                       {
-                               $meter[$i]['user']              = 
$GLOBALS['phpgw']->accounts->id2name($meter[$i]['user_id']);
-                               $meter[$i]['entry_date'] = 
$GLOBALS['phpgw']->common->show_date($meter[$i]['entry_date'],$dateformat);
-                               
$location_data=$solocation->read_single($meter[$i]['location_code']);
-
-                               for ($j=0;$j<count($cols_extra);$j++)
-                               {
-                                       $meter[$i][$cols_extra[$j]] = 
$location_data[$cols_extra[$j]];
-                               }
-
-                       }
-*/
-                       return $meter;
-               }
-
-               function read_single($meter_id)
-               {
-                       $meter= $this->so->read_single($meter_id);
-
-                       if($meter['location_code'])
-                       {
-                               $solocation = 
CreateObject($this->currentapp.'.solocation');
-
-                               $meter['location_data'] 
=$solocation->read_single($meter['location_code']);
-                       }
-
-                       if($meter['p_num'])
-                       {
-                               $soadmin_entity = 
CreateObject($this->currentapp.'.soadmin_entity');
-                               $category = 
$soadmin_entity->read_single_category($meter['p_entity_id'],$meter['p_cat_id']);
-
-                               
$meter['p'][$meter['p_entity_id']]['p_num']=$meter['p_num'];
-                               
$meter['p'][$meter['p_entity_id']]['p_entity_id']=$meter['p_entity_id'];
-                               
$meter['p'][$meter['p_entity_id']]['p_cat_id']=$meter['p_cat_id'];
-                               
$meter['p'][$meter['p_entity_id']]['p_cat_name'] = $category['name'];
-                       }
-
-                       return $meter;
-               }
-
-               function check_meter_num($num)
-               {
-                       return $this->so->check_meter_num($num);
-               }
-
-               function save($values,$action='')
-               {
-                       while (is_array($values['location']) && list(,$value) = 
each($values['location']))
-                       {
-                               if($value)
-                               {
-                                       $location[] = $value;
-                               }
-                       }
-
-                       $values['location_code']=implode("-", $location);
-
-                       if ($action=='edit')
-                       {
-                               $receipt = $this->so->edit($values);
-                       }
-                       else
-                       {
-                               $receipt = $this->so->add($values);
-                       }
-                       return $receipt;
-               }
-
-               function delete($params)
-               {
-                       if (is_array($params))
-                       {
-                               $this->so->delete($params[0]);
-                       }
-                       else
-                       {
-                               $this->so->delete($params);
-                       }
-               }
-
-       }
-?>
+<?php
+       /**
+       * phpGroupWare - property: a Facilities Management System.
+       *
+       * @author Sigurd Nes <address@hidden>
+       * @copyright Copyright (C) 2003-2005 Free Software Foundation, Inc. 
http://www.fsf.org/
+       * @license http://www.gnu.org/licenses/gpl.html GNU General Public 
License
+       * @internal Development of this application was funded by 
http://www.bergen.kommune.no/bbb_/ekstern/
+       * @package property
+       * @subpackage entity
+       * @version $Id: class.bometer.inc.php,v 1.7 2006/02/03 12:05:49 
sigurdne Exp $
+       */
+
+       /**
+        * Description
+        * @package property
+        */
+
+       class bometer
+       {
+               var $start;
+               var $query;
+               var $filter;
+               var $sort;
+               var $order;
+               var $cat_id;
+
+               var $public_functions = array
+               (
+                       'read'                          => True,
+                       'read_single'           => True,
+                       'save'                          => True,
+                       'delete'                        => True,
+                       'check_perms'           => True
+               );
+
+               var $soap_functions = array(
+                       'list' => array(
+                               'in'  => 
array('int','int','struct','string','int'),
+                               'out' => array('array')
+                       ),
+                       'read' => array(
+                               'in'  => array('int','struct'),
+                               'out' => array('array')
+                       ),
+                       'save' => array(
+                               'in'  => array('int','struct'),
+                               'out' => array()
+                       ),
+                       'delete' => array(
+                               'in'  => array('int','struct'),
+                               'out' => array()
+                       )
+               );
+
+               function bometer($session=False)
+               {
+                       $this->currentapp       = 
$GLOBALS['phpgw_info']['flags']['currentapp'];
+                       $this->so               = 
CreateObject($this->currentapp.'.someter');
+                       $this->bocommon = 
CreateObject($this->currentapp.'.bocommon');
+
+                       if ($session)
+                       {
+                               $this->read_sessiondata();
+                               $this->use_session = True;
+                       }
+
+                       $start  = get_var('start',array('POST','GET'));
+                       $query  = get_var('query',array('POST','GET'));
+                       $sort   = get_var('sort',array('POST','GET'));
+                       $order  = get_var('order',array('POST','GET'));
+                       $filter = get_var('filter',array('POST','GET'));
+                       $cat_id = get_var('cat_id',array('POST','GET'));
+
+                       if ($start)
+                       {
+                               $this->start=$start;
+                       }
+                       else
+                       {
+                               $this->start=0;
+                       }
+
+                       if(isset($query))
+                       {
+                               $this->query = $query;
+                       }
+                       if(!empty($filter))
+                       {
+                               $this->filter = $filter;
+                       }
+                       if(isset($sort))
+                       {
+                               $this->sort = $sort;
+                       }
+                       if(isset($order))
+                       {
+                               $this->order = $order;
+                       }
+                       if(isset($cat_id))
+                       {
+                               $this->cat_id = $cat_id;
+                       }
+               }
+
+               function save_sessiondata($data)
+               {
+                       if ($this->use_session)
+                       {
+                               
$GLOBALS['phpgw']->session->appsession('session_data','meter',$data);
+                       }
+               }
+
+               function read_sessiondata()
+               {
+                       $data = 
$GLOBALS['phpgw']->session->appsession('session_data','meter');
+
+                       $this->start    = $data['start'];
+                       $this->query    = $data['query'];
+                       $this->filter   = $data['filter'];
+                       $this->sort             = $data['sort'];
+                       $this->order    = $data['order'];
+                       $this->cat_id   = $data['cat_id'];
+               }
+
+               function get_category_list($format='',$selected='')
+               {
+                       switch($format)
+                       {
+                               case 'select':
+                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('cat_select'));
+                                       break;
+                               case 'filter':
+                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('cat_filter'));
+                                       break;
+                       }
+
+                       $categories= $this->so->get_category_list();
+
+                       while (is_array($categories) && list(,$category) = 
each($categories))
+                       {
+                               $sel_category = '';
+                               if ($category['id']==$selected)
+                               {
+                                       $sel_category = 'selected';
+                               }
+
+                               $category_list[] = array
+                               (
+                                       'cat_id'        => $category['id'],
+                                       'name'          => $category['name'],
+                                       'selected'      => $sel_category
+                               );
+                       }
+
+                       for ($i=0;$i<count($category_list);$i++)
+                       {
+                               if ($category_list[$i]['selected'] != 
'selected')
+                               {
+                                       unset($category_list[$i]['selected']);
+                               }
+                       }
+
+                       return $category_list;
+               }
+
+               function read()
+               {
+                       $meter = $this->so->read(array('start' => 
$this->start,'query' => $this->query,'sort' => $this->sort,'order' => 
$this->order,
+                                                                               
        'filter' => $this->filter,'cat_id' => $this->cat_id));
+                       $this->total_records = $this->so->total_records;
+
+                       $this->uicols   = $this->so->uicols;
+/*                     $cols_extra             = $this->so->cols_extra;
+                       $dateformat = 
$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
+                       $solocation = 
CreateObject($this->currentapp.'.solocation');
+
+                       for ($i=0; $i<count($meter); $i++)
+                       {
+                               $meter[$i]['user']              = 
$GLOBALS['phpgw']->accounts->id2name($meter[$i]['user_id']);
+                               $meter[$i]['entry_date'] = 
$GLOBALS['phpgw']->common->show_date($meter[$i]['entry_date'],$dateformat);
+                               
$location_data=$solocation->read_single($meter[$i]['location_code']);
+
+                               for ($j=0;$j<count($cols_extra);$j++)
+                               {
+                                       $meter[$i][$cols_extra[$j]] = 
$location_data[$cols_extra[$j]];
+                               }
+
+                       }
+*/
+                       return $meter;
+               }
+
+               function read_single($meter_id)
+               {
+                       $meter= $this->so->read_single($meter_id);
+
+                       if($meter['location_code'])
+                       {
+                               $solocation = 
CreateObject($this->currentapp.'.solocation');
+
+                               $meter['location_data'] 
=$solocation->read_single($meter['location_code']);
+                       }
+
+                       if($meter['p_num'])
+                       {
+                               $soadmin_entity = 
CreateObject($this->currentapp.'.soadmin_entity');
+                               $category = 
$soadmin_entity->read_single_category($meter['p_entity_id'],$meter['p_cat_id']);
+
+                               
$meter['p'][$meter['p_entity_id']]['p_num']=$meter['p_num'];
+                               
$meter['p'][$meter['p_entity_id']]['p_entity_id']=$meter['p_entity_id'];
+                               
$meter['p'][$meter['p_entity_id']]['p_cat_id']=$meter['p_cat_id'];
+                               
$meter['p'][$meter['p_entity_id']]['p_cat_name'] = $category['name'];
+                       }
+
+                       return $meter;
+               }
+
+               function check_meter_num($num)
+               {
+                       return $this->so->check_meter_num($num);
+               }
+
+               function save($values,$action='')
+               {
+                       while (is_array($values['location']) && list(,$value) = 
each($values['location']))
+                       {
+                               if($value)
+                               {
+                                       $location[] = $value;
+                               }
+                       }
+
+                       $values['location_code']=implode("-", $location);
+
+                       if ($action=='edit')
+                       {
+                               $receipt = $this->so->edit($values);
+                       }
+                       else
+                       {
+                               $receipt = $this->so->add($values);
+                       }
+                       return $receipt;
+               }
+
+               function delete($params)
+               {
+                       if (is_array($params))
+                       {
+                               $this->so->delete($params[0]);
+                       }
+                       else
+                       {
+                               $this->so->delete($params);
+                       }
+               }
+
+       }
+?>
Index: property/inc/class.bop_of_town.inc.php
diff -u property/inc/class.bop_of_town.inc.php:1.6 
property/inc/class.bop_of_town.inc.php:1.7
--- property/inc/class.bop_of_town.inc.php:1.6  Fri Jan 27 14:05:43 2006
+++ property/inc/class.bop_of_town.inc.php      Fri Feb  3 12:05:49 2006
@@ -1,242 +1,242 @@
-<?php
-       /**
-       * phpGroupWare - property: a Facilities Management System.
-       *
-       * @author Sigurd Nes <address@hidden>
-       * @copyright Copyright (C) 2003-2005 Free Software Foundation, Inc. 
http://www.fsf.org/
-       * @license http://www.gnu.org/licenses/gpl.html GNU General Public 
License
-       * @internal Development of this application was funded by 
http://www.bergen.kommune.no/bbb_/ekstern/
-       * @package property
-       * @subpackage admin
-       * @version $Id: class.bop_of_town.inc.php,v 1.6 2006/01/27 14:05:43 
sigurdne Exp $
-       */
-
-       /**
-        * Description
-        * @package property
-        */
-
-       class bop_of_town
-       {
-               var $start;
-               var $query;
-               var $filter;
-               var $sort;
-               var $order;
-               var $district_id;
-
-               var $public_functions = array
-               (
-                       'read'                          => True,
-                       'read_single'           => True,
-                       'save'                          => True,
-                       'delete'                        => True,
-                       'check_perms'           => True
-               );
-
-               var $soap_functions = array(
-                       'list' => array(
-                               'in'  => 
array('int','int','struct','string','int'),
-                               'out' => array('array')
-                       ),
-                       'read' => array(
-                               'in'  => array('int','struct'),
-                               'out' => array('array')
-                       ),
-                       'save' => array(
-                               'in'  => array('int','struct'),
-                               'out' => array()
-                       ),
-                       'delete' => array(
-                               'in'  => array('int','struct'),
-                               'out' => array()
-                       )
-               );
-
-               function bop_of_town($session=False)
-               {
-                       $this->currentapp               = 
$GLOBALS['phpgw_info']['flags']['currentapp'];
-                       $this->so = 
CreateObject($this->currentapp.'.sop_of_town');
-
-                       if ($session)
-                       {
-                               $this->read_sessiondata();
-                               $this->use_session = True;
-                       }
-
-                       $start  = get_var('start',array('POST','GET'));
-                       $query  = get_var('query',array('POST','GET'));
-                       $sort   = get_var('sort',array('POST','GET'));
-                       $order  = get_var('order',array('POST','GET'));
-                       $filter = get_var('filter',array('POST','GET'));
-                       $district_id    = 
get_var('district_id',array('POST','GET'));
-                       $allrows                        = 
get_var('allrows',array('POST','GET'));
-
-                       if ($start)
-                       {
-                               $this->start=$start;
-                       }
-                       else
-                       {
-                               $this->start=0;
-                       }
-
-                       if(isset($query))
-                       {
-                               $this->query = $query;
-                       }
-                       if(!empty($filter))
-                       {
-                               $this->filter = $filter;
-                       }
-                       if(isset($sort))
-                       {
-                               $this->sort = $sort;
-                       }
-                       if(isset($order))
-                       {
-                               $this->order = $order;
-                       }
-                       if(isset($district_id) && !empty($district_id))
-                       {
-                               $this->district_id = $district_id;
-                       }
-                       else
-                       {
-                               unset($this->district_id);
-                       }
-                       if(isset($allrows))
-                       {
-                               $this->allrows = $allrows;
-                       }
-               }
-
-               function list_methods($_type='xmlrpc')
-               {
-                       /*
-                         This handles introspection or discovery by the logged 
in client,
-                         in which case the input might be an array.  The 
server always calls
-                         this function to fill the server dispatch map using a 
string.
-                       */
-                       if (is_array($_type))
-                       {
-                               $_type = $_type['type'] ? $_type['type'] : 
$_type[0];
-                       }
-                       switch($_type)
-                       {
-                               case 'xmlrpc':
-                                       $xml_functions = array(
-                                               'read' => array(
-                                                       'function'  => 'read',
-                                                       'signature' => 
array(array(xmlrpcInt,xmlrpcStruct)),
-                                                       'docstring' => 
lang('Read a single entry by passing the id and fieldlist.')
-                                               ),
-                                               'save' => array(
-                                                       'function'  => 'save',
-                                                       'signature' => 
array(array(xmlrpcStruct,xmlrpcStruct)),
-                                                       'docstring' => 
lang('Update a single entry by passing the fields.')
-                                               ),
-                                               'delete' => array(
-                                                       'function'  => 'delete',
-                                                       'signature' => 
array(array(xmlrpcBoolean,xmlrpcInt)),
-                                                       'docstring' => 
lang('Delete a single entry by passing the id.')
-                                               ),
-                                               'list' => array(
-                                                       'function'  => '_list',
-                                                       'signature' => 
array(array(xmlrpcStruct,xmlrpcStruct)),
-                                                       'docstring' => 
lang('Read a list of entries.')
-                                               ),
-                                               'list_methods' => array(
-                                                       'function'  => 
'list_methods',
-                                                       'signature' => 
array(array(xmlrpcStruct,xmlrpcString)),
-                                                       'docstring' => 
lang('Read this list of methods.')
-                                               )
-                                       );
-                                       return $xml_functions;
-                                       break;
-                               case 'soap':
-                                       return $this->soap_functions;
-                                       break;
-                               default:
-                                       return array();
-                                       break;
-                       }
-               }
-
-               function save_sessiondata($data)
-               {
-                       if ($this->use_session)
-                       {
-                               
$GLOBALS['phpgw']->session->appsession('session_data','p_of_town',$data);
-                       }
-               }
-
-               function read_sessiondata()
-               {
-                       $data = 
$GLOBALS['phpgw']->session->appsession('session_data','p_of_town');
-
-                       $this->start    = $data['start'];
-                       $this->query    = $data['query'];
-                       $this->filter   = $data['filter'];
-                       $this->sort             = $data['sort'];
-                       $this->order    = $data['order'];
-                       $this->district_id      = $data['district_id'];
-               }
-
-               function check_perms($has, $needed)
-               {
-                       return (!!($has & $needed) == True);
-               }
-
-
-               function read_district_name($district_id='')
-               {
-                       return $this->so->read_district_name($district_id);
-               }
-
-
-               function read()
-               {
-                       $p_of_town = $this->so->read(array('start' => 
$this->start,'query' => $this->query,'sort' => $this->sort,'order' => 
$this->order,
-                                                                               
        'filter' => $this->filter,'district_id' => 
$this->district_id,'allrows'=>$this->allrows));
-                       $this->total_records = $this->so->total_records;
-
-                       return $p_of_town;
-               }
-
-               function read_single($part_of_town_id)
-               {
-                       return $this->so->read_single($part_of_town_id);
-               }
-
-               function save($p_of_town)
-               {
-
-                       if ($p_of_town['part_of_town_id'])
-                       {
-                               if ($p_of_town['part_of_town_id'] != 0)
-                               {
-                                       $part_of_town_id = 
$p_of_town['part_of_town_id'];
-                                       $receipt=$this->so->edit($p_of_town);
-                               }
-                       }
-                       else
-                       {
-                               $receipt = $this->so->add($p_of_town);
-                       }
-                       return $receipt;
-               }
-
-               function delete($params)
-               {
-                       if (is_array($params))
-                       {
-                               $this->so->delete($params[0]);
-                       }
-                       else
-                       {
-                               $this->so->delete($params);
-                       }
-               }
-       }
-?>
+<?php
+       /**
+       * phpGroupWare - property: a Facilities Management System.
+       *
+       * @author Sigurd Nes <address@hidden>
+       * @copyright Copyright (C) 2003-2005 Free Software Foundation, Inc. 
http://www.fsf.org/
+       * @license http://www.gnu.org/licenses/gpl.html GNU General Public 
License
+       * @internal Development of this application was funded by 
http://www.bergen.kommune.no/bbb_/ekstern/
+       * @package property
+       * @subpackage admin
+       * @version $Id: class.bop_of_town.inc.php,v 1.7 2006/02/03 12:05:49 
sigurdne Exp $
+       */
+
+       /**
+        * Description
+        * @package property
+        */
+
+       class bop_of_town
+       {
+               var $start;
+               var $query;
+               var $filter;
+               var $sort;
+               var $order;
+               var $district_id;
+
+               var $public_functions = array
+               (
+                       'read'                          => True,
+                       'read_single'           => True,
+                       'save'                          => True,
+                       'delete'                        => True,
+                       'check_perms'           => True
+               );
+
+               var $soap_functions = array(
+                       'list' => array(
+                               'in'  => 
array('int','int','struct','string','int'),
+                               'out' => array('array')
+                       ),
+                       'read' => array(
+                               'in'  => array('int','struct'),
+                               'out' => array('array')
+                       ),
+                       'save' => array(
+                               'in'  => array('int','struct'),
+                               'out' => array()
+                       ),
+                       'delete' => array(
+                               'in'  => array('int','struct'),
+                               'out' => array()
+                       )
+               );
+
+               function bop_of_town($session=False)
+               {
+                       $this->currentapp               = 
$GLOBALS['phpgw_info']['flags']['currentapp'];
+                       $this->so = 
CreateObject($this->currentapp.'.sop_of_town');
+
+                       if ($session)
+                       {
+                               $this->read_sessiondata();
+                               $this->use_session = True;
+                       }
+
+                       $start  = get_var('start',array('POST','GET'));
+                       $query  = get_var('query',array('POST','GET'));
+                       $sort   = get_var('sort',array('POST','GET'));
+                       $order  = get_var('order',array('POST','GET'));
+                       $filter = get_var('filter',array('POST','GET'));
+                       $district_id    = 
get_var('district_id',array('POST','GET'));
+                       $allrows                        = 
get_var('allrows',array('POST','GET'));
+
+                       if ($start)
+                       {
+                               $this->start=$start;
+                       }
+                       else
+                       {
+                               $this->start=0;
+                       }
+
+                       if(isset($query))
+                       {
+                               $this->query = $query;
+                       }
+                       if(!empty($filter))
+                       {
+                               $this->filter = $filter;
+                       }
+                       if(isset($sort))
+                       {
+                               $this->sort = $sort;
+                       }
+                       if(isset($order))
+                       {
+                               $this->order = $order;
+                       }
+                       if(isset($district_id) && !empty($district_id))
+                       {
+                               $this->district_id = $district_id;
+                       }
+                       else
+                       {
+                               unset($this->district_id);
+                       }
+                       if(isset($allrows))
+                       {
+                               $this->allrows = $allrows;
+                       }
+               }
+
+               function list_methods($_type='xmlrpc')
+               {
+                       /*
+                         This handles introspection or discovery by the logged 
in client,
+                         in which case the input might be an array.  The 
server always calls
+                         this function to fill the server dispatch map using a 
string.
+                       */
+                       if (is_array($_type))
+                       {
+                               $_type = $_type['type'] ? $_type['type'] : 
$_type[0];
+                       }
+                       switch($_type)
+                       {
+                               case 'xmlrpc':
+                                       $xml_functions = array(
+                                               'read' => array(
+                                                       'function'  => 'read',
+                                                       'signature' => 
array(array(xmlrpcInt,xmlrpcStruct)),
+                                                       'docstring' => 
lang('Read a single entry by passing the id and fieldlist.')
+                                               ),
+                                               'save' => array(
+                                                       'function'  => 'save',
+                                                       'signature' => 
array(array(xmlrpcStruct,xmlrpcStruct)),
+                                                       'docstring' => 
lang('Update a single entry by passing the fields.')
+                                               ),
+                                               'delete' => array(
+                                                       'function'  => 'delete',
+                                                       'signature' => 
array(array(xmlrpcBoolean,xmlrpcInt)),
+                                                       'docstring' => 
lang('Delete a single entry by passing the id.')
+                                               ),
+                                               'list' => array(
+                                                       'function'  => '_list',
+                                                       'signature' => 
array(array(xmlrpcStruct,xmlrpcStruct)),
+                                                       'docstring' => 
lang('Read a list of entries.')
+                                               ),
+                                               'list_methods' => array(
+                                                       'function'  => 
'list_methods',
+                                                       'signature' => 
array(array(xmlrpcStruct,xmlrpcString)),
+                                                       'docstring' => 
lang('Read this list of methods.')
+                                               )
+                                       );
+                                       return $xml_functions;
+                                       break;
+                               case 'soap':
+                                       return $this->soap_functions;
+                                       break;
+                               default:
+                                       return array();
+                                       break;
+                       }
+               }
+
+               function save_sessiondata($data)
+               {
+                       if ($this->use_session)
+                       {
+                               
$GLOBALS['phpgw']->session->appsession('session_data','p_of_town',$data);
+                       }
+               }
+
+               function read_sessiondata()
+               {
+                       $data = 
$GLOBALS['phpgw']->session->appsession('session_data','p_of_town');
+
+                       $this->start    = $data['start'];
+                       $this->query    = $data['query'];
+                       $this->filter   = $data['filter'];
+                       $this->sort             = $data['sort'];
+                       $this->order    = $data['order'];
+                       $this->district_id      = $data['district_id'];
+               }
+
+               function check_perms($has, $needed)
+               {
+                       return (!!($has & $needed) == True);
+               }
+
+
+               function read_district_name($district_id='')
+               {
+                       return $this->so->read_district_name($district_id);
+               }
+
+
+               function read()
+               {
+                       $p_of_town = $this->so->read(array('start' => 
$this->start,'query' => $this->query,'sort' => $this->sort,'order' => 
$this->order,
+                                                                               
        'filter' => $this->filter,'district_id' => 
$this->district_id,'allrows'=>$this->allrows));
+                       $this->total_records = $this->so->total_records;
+
+                       return $p_of_town;
+               }
+
+               function read_single($part_of_town_id)
+               {
+                       return $this->so->read_single($part_of_town_id);
+               }
+
+               function save($p_of_town)
+               {
+
+                       if ($p_of_town['part_of_town_id'])
+                       {
+                               if ($p_of_town['part_of_town_id'] != 0)
+                               {
+                                       $part_of_town_id = 
$p_of_town['part_of_town_id'];
+                                       $receipt=$this->so->edit($p_of_town);
+                               }
+                       }
+                       else
+                       {
+                               $receipt = $this->so->add($p_of_town);
+                       }
+                       return $receipt;
+               }
+
+               function delete($params)
+               {
+                       if (is_array($params))
+                       {
+                               $this->so->delete($params[0]);
+                       }
+                       else
+                       {
+                               $this->so->delete($params);
+                       }
+               }
+       }
+?>
Index: property/inc/class.bopricebook.inc.php
diff -u property/inc/class.bopricebook.inc.php:1.7 
property/inc/class.bopricebook.inc.php:1.8
--- property/inc/class.bopricebook.inc.php:1.7  Fri Jan 27 14:05:43 2006
+++ property/inc/class.bopricebook.inc.php      Fri Feb  3 12:05:49 2006
@@ -1,565 +1,565 @@
-<?php
-       /**
-       * phpGroupWare - property: a Facilities Management System.
-       *
-       * @author Sigurd Nes <address@hidden>
-       * @copyright Copyright (C) 2003-2005 Free Software Foundation, Inc. 
http://www.fsf.org/
-       * @license http://www.gnu.org/licenses/gpl.html GNU General Public 
License
-       * @internal Development of this application was funded by 
http://www.bergen.kommune.no/bbb_/ekstern/
-       * @package property
-       * @subpackage agreement
-       * @version $Id: class.bopricebook.inc.php,v 1.7 2006/01/27 14:05:43 
sigurdne Exp $
-       */
-
-       /**
-        * Description
-        * @package property
-        */
-
-       class bopricebook
-       {
-               var $start;
-               var $query;
-               var $filter;
-               var $sort;
-               var $order;
-               var $cat_id;
-
-               var $public_functions = array
-               (
-                       'read'                          => True,
-                       'read_single'           => True,
-                       'save'                          => True,
-                       'delete'                        => True,
-                       'check_perms'           => True
-               );
-
-               var $soap_functions = array(
-                       'list' => array(
-                               'in'  => 
array('int','int','struct','string','int'),
-                               'out' => array('array')
-                       ),
-                       'read' => array(
-                               'in'  => array('int','struct'),
-                               'out' => array('array')
-                       ),
-                       'save' => array(
-                               'in'  => array('int','struct'),
-                               'out' => array()
-                       ),
-                       'delete' => array(
-                               'in'  => array('int','struct'),
-                               'out' => array()
-                       )
-               );
-
-               function bopricebook($session=False)
-               {
-                       $this->currentapp       = 
$GLOBALS['phpgw_info']['flags']['currentapp'];
-                       $this->so               = 
CreateObject($this->currentapp.'.sopricebook');
-                       $this->socommon = 
CreateObject($this->currentapp.'.socommon');
-                       $this->bocommon = 
CreateObject($this->currentapp.'.bocommon');
-
-                       if ($session)
-                       {
-                               $this->read_sessiondata();
-                               $this->use_session = True;
-                       }
-
-                       $start  = get_var('start',array('POST','GET'));
-                       $query  = get_var('query',array('POST','GET'));
-                       $sort   = get_var('sort',array('POST','GET'));
-                       $order  = get_var('order',array('POST','GET'));
-                       $filter = get_var('filter',array('POST','GET'));
-                       $cat_id = get_var('cat_id',array('POST','GET'));
-                       $allrows                        = 
get_var('allrows',array('POST','GET'));
-
-                       if ($start)
-                       {
-                               $this->start=$start;
-                       }
-                       else
-                       {
-                               $this->start=0;
-                       }
-
-                       if(isset($query))
-                       {
-                               $this->query = $query;
-                       }
-                       if(!empty($filter))
-                       {
-                               $this->filter = $filter;
-                       }
-                       if(isset($sort))
-                       {
-                               $this->sort = $sort;
-                       }
-                       if(isset($order))
-                       {
-                               $this->order = $order;
-                       }
-                       if(isset($cat_id))
-                       {
-                               $this->cat_id = $cat_id;
-                       }
-                       if(isset($allrows))
-                       {
-                               $this->allrows = $allrows;
-                       }
-               }
-
-               function save_sessiondata($data)
-               {
-                       if ($this->use_session)
-                       {
-                               
$GLOBALS['phpgw']->session->appsession('session_data','pricebook',$data);
-                       }
-               }
-
-               function read_sessiondata()
-               {
-                       $data = 
$GLOBALS['phpgw']->session->appsession('session_data','pricebook');
-
-                       //_debug_array($data);
-
-                       $this->start    = $data['start'];
-                       $this->query    = $data['query'];
-                       $this->filter   = $data['filter'];
-                       $this->sort             = $data['sort'];
-                       $this->order    = $data['order'];
-                       $this->cat_id   = $data['cat_id'];
-               }
-
-
-               function select_status_list($format='',$selected='')
-               {
-                       switch($format)
-                       {
-                               case 'select':
-                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('status_select'));
-                                       break;
-                               case 'filter':
-                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('status_filter'));
-                                       break;
-                       }
-
-                       $status_entries= $this->so->select_status_list();
-
-                       while (is_array($status_entries) && list(,$status) = 
each($status_entries))
-                       {
-                               $sel_status = '';
-                               if ($status['id']==$selected)
-                               {
-                                       $sel_status = 'selected';
-                               }
-
-                               $status_list[] = array
-                               (
-                                       'id'            => $status['id'],
-                                       'name'          => $status['name'],
-                                       'selected'      => $sel_status
-                               );
-                       }
-
-                       for ($i=0;$i<count($status_list);$i++)
-                       {
-                               if ($status_list[$i]['selected'] != 'selected')
-                               {
-                                       unset($status_list[$i]['selected']);
-                               }
-                       }
-
-                       return $status_list;
-               }
-
-               function read()
-               {
-                       $pricebook = $this->so->read(array('start' => 
$this->start,'query' => $this->query,'sort' => $this->sort,'order' => 
$this->order,
-                                                                               
        'filter' => $this->filter,'cat_id' => 
$this->cat_id,'allrows'=>$this->allrows));
-                       $this->total_records = $this->so->total_records;
-                       return $pricebook;
-               }
-
-               function read_agreement_group()
-               {
-                       $agreement_group = 
$this->so->read_agreement_group(array('start' => $this->start,'query' => 
$this->query,'sort' => $this->sort,'order' => $this->order,
-                                                                               
        'filter' => $this->filter,'cat_id' => 
$this->cat_id,'allrows'=>$this->allrows));
-                       $this->total_records = $this->so->total_records;
-                       return $agreement_group;
-               }
-
-               function read_activity_prize($activity_id,$vendor_id)
-               {
-                       $pricebook = 
$this->so->read_activity_prize(array('start' => $this->start,'query' => 
$this->query,'sort' => $this->sort,'order' => $this->order,
-                                                                               
        'filter' => $this->filter,'cat_id' => 
$this->cat_id,'allrows'=>$this->allrows,'activity_id'=>$activity_id,'vendor_id'=>$vendor_id));
-                       $this->total_records = $this->so->total_records;
-                       return $pricebook;
-               }
-
-
-               function read_activities_pr_agreement_group()
-               {
-                       $pricebook = 
$this->so->read_activities_pr_agreement_group(array('start' => 
$this->start,'query' => $this->query,'sort' => $this->sort,'order' => 
$this->order,
-                                                                               
        'filter' => $this->filter,'cat_id' => 
$this->cat_id,'allrows'=>$this->allrows));
-                       $this->total_records = $this->so->total_records;
-                       return $pricebook;
-               }
-
-               function read_vendor_pr_activity($activity_id)
-               {
-                       $pricebook = 
$this->so->read_vendor_pr_activity(array('start' => $this->start,'query' => 
$this->query,'sort' => $this->sort,'order' => $this->order,
-                                                                               
        'filter' => $this->filter,'cat_id' => 
$this->cat_id,'allrows'=>$this->allrows,'activity_id'=>$activity_id));
-                       $this->total_records = $this->so->total_records;
-                       return $pricebook;
-               }
-
-               function add_activity_vendor($values)
-               {
-                       return $this->so->add_activity_vendor($values);
-               }
-
-               function read_single_activity($id='')
-               {
-                       return $this->so->read_single_activity($id);
-               }
-
-               function read_single_agreement_group($id='')
-               {
-                       return $this->so->read_single_agreement_group($id);
-               }
-
-
-               function read_category_name($cat_id)
-               {
-                       return $this->so->read_category_name($cat_id);
-               }
-
-               function update_pricebook($values)
-               {
-
-//_debug_array($values);
-                       
$date_array=$this->bocommon->date_array($values['date']);
-
-                       $date = mktime 
(2,0,0,$date_array['month'],$date_array['day'],$date_array['year']);
-//                     $date= date($this->bocommon->dateformat,$date);
-
-                       $new_index=str_replace(",",".",$values['new_index']);
-
-                       while(address@hidden($values['update']))
-                       {
-                               $n=$entry[0];
-
-                               if(!$values['old_total_cost'][$n])
-                               {
-                                       
$new_total_cost=($values['old_m_cost'][$n]+$values['old_w_cost'][$n])*$new_index;
-                               }
-                               else
-                               {
-                                       
$new_total_cost=$values['old_total_cost'][$n]*$new_index;
-                               }
-
-                               if(!$values['old_m_cost'][$n])
-                               {
-                                       $new_m_cost=0;
-                               }
-                               else
-                               {
-                                       
$new_m_cost=$values['old_m_cost'][$n]*$new_index;
-                               }
-
-                               if(!$values['old_w_cost'][$n])
-                               {
-                                       $new_w_cost=0;
-                               }
-                               else
-                               {
-                                       
$new_w_cost=$values['old_w_cost'][$n]*$new_index;
-                               }
-
-                               $update[]=array(
-                                       'new_m_cost'            => $new_m_cost,
-                                       'new_w_cost'            => $new_w_cost,
-                                       'new_total_cost'        => 
$new_total_cost,
-                                       'activity_id'           => 
$values['activity_id'][$n],
-                                       'vendor_id'                     => 
$values['vendor_id'][$n],
-                                       'new_index'                     => 
$new_index,
-                                       'new_date'                      => 
$date,
-                               );
-
-                       }
-//_debug_array($update);
-
-                       if($update)
-                       {
-                               $receipt =      
$this->so->update_pricebook($update);
-                       }
-                       else
-                       {
-                                       $receipt['message'][] = 
array('msg'=>lang('Nothing to do!'));
-                       }
-
-                       return $receipt;
-
-               }
-
-               function add_activity_first_prize($values)
-               {
-
-                       
$date_array=$this->bocommon->date_array($values['date']);
-
-                       $date = mktime 
(2,0,0,$date_array['month'],$date_array['day'],$date_array['year']);
-//                     $date= date($this->bocommon->dateformat,$date);
-
-                       $m_cost                 = 
str_replace(",",".",$values['m_cost']);
-                       $w_cost                 = 
str_replace(",",".",$values['w_cost']);
-                       $total_cost             = $m_cost + $w_cost;
-                       $activity_id    = $values['activity_id'][0];
-                       $vendor_id              = $values['vendor_id'][0];
-
-                       $receipt = 
$this->so->add_activity_first_prize($m_cost,$w_cost,$total_cost,$activity_id,$vendor_id,$date);
-
-                       return $receipt;
-               }
-
-               function get_vendor_list($format='',$selected='')
-               {
-                       switch($format)
-                       {
-                               case 'select':
-                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('cat_select'));
-                                       break;
-                               case 'filter':
-                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('cat_filter'));
-                                       break;
-                       }
-
-                       $vendors= $this->so->get_vendor_list();
-
-                       while (is_array($vendors) && list(,$vendor_entry) = 
each($vendors))
-                       {
-                               $sel_vendor_entry = '';
-                               if ($vendor_entry['id']==$selected)
-                               {
-                                       $sel_vendor_entry = 'selected';
-                               }
-
-                               $vendor_list[] = array
-                               (
-                                       'cat_id'        => $vendor_entry['id'],
-                                       'name'          => 
$vendor_entry['name'],
-                                       'selected'      => $sel_vendor_entry
-                               );
-                       }
-
-                       for ($i=0;$i<count($vendor_list);$i++)
-                       {
-                               if ($vendor_list[$i]['selected'] != 'selected')
-                               {
-                                       unset($vendor_list[$i]['selected']);
-                               }
-                       }
-
-                       return $vendor_list;
-               }
-
-               function get_dim_d_list($selected='')
-               {
-                       
$GLOBALS['phpgw']->xslttpl->add_file(array('dim_d_select'));
-
-                       $dim_ds= $this->so->get_dim_d_list();
-
-                       while (is_array($dim_ds) && list(,$dim_d_entry) = 
each($dim_ds))
-                       {
-                               $sel_dim_d_entry = '';
-                               if ($dim_d_entry['id']==$selected)
-                               {
-                                       $sel_dim_d_entry = 'selected';
-                               }
-
-                               $dim_d_list[] = array
-                               (
-                                       'id'            => $dim_d_entry['id'],
-                                       'name'          => $dim_d_entry['name'],
-                                       'selected'      => $sel_dim_d_entry
-                               );
-                       }
-
-                       for ($i=0;$i<count($dim_d_list);$i++)
-                       {
-                               if ($dim_d_list[$i]['selected'] != 'selected')
-                               {
-                                       unset($dim_d_list[$i]['selected']);
-                               }
-                       }
-
-                       return $dim_d_list;
-               }
-
-               function get_unit_list($selected='')
-               {
-                       
$GLOBALS['phpgw']->xslttpl->add_file(array('unit_select'));
-
-                       $units= $this->so->get_unit_list();
-
-                       while (is_array($units) && list(,$unit_entry) = 
each($units))
-                       {
-                               $sel_unit_entry = '';
-                               if ($unit_entry['id']==$selected)
-                               {
-                                       $sel_unit_entry = 'selected';
-                               }
-
-                               $unit_list[] = array
-                               (
-                                       'id'            => $unit_entry['id'],
-                                       'name'          => $unit_entry['name'],
-                                       'selected'      => $sel_unit_entry
-                               );
-                       }
-
-                       for ($i=0;$i<count($unit_list);$i++)
-                       {
-                               if ($unit_list[$i]['selected'] != 'selected')
-                               {
-                                       unset($unit_list[$i]['selected']);
-                               }
-                       }
-
-                       return $unit_list;
-               }
-
-               function get_branch_list($selected='')
-               {
-                       
$GLOBALS['phpgw']->xslttpl->add_file(array('branch_select'));
-
-                       $branches= $this->so->get_branch_list();
-
-                       while (is_array($branches) && list(,$branch_entry) = 
each($branches))
-                       {
-                               $sel_branch_entry = '';
-                               if ($branch_entry['id']==$selected)
-                               {
-                                       $sel_branch_entry = 'selected';
-                               }
-
-                               $branch_list[] = array
-                               (
-                                       'id'            => $branch_entry['id'],
-                                       'name'          => 
$branch_entry['name'],
-                                       'selected'      => $sel_branch_entry
-                               );
-                       }
-
-                       for ($i=0;$i<count($branch_list);$i++)
-                       {
-                               if ($branch_list[$i]['selected'] != 'selected')
-                               {
-                                       unset($branch_list[$i]['selected']);
-                               }
-                       }
-
-                       return $branch_list;
-               }
-
-               function get_agreement_group_list($format='',$selected='')
-               {
-                       switch($format)
-                       {
-                               case 'select':
-                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('cat_select'));
-                                       break;
-                               case 'filter':
-                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('cat_filter'));
-                                       break;
-                       }
-
-                       $agreement_groups= 
$this->so->get_agreement_group_list();
-
-                       while (is_array($agreement_groups) && 
list(,$agreement_group_entry) = each($agreement_groups))
-                       {
-                               $sel_agreement_group_entry = '';
-                               if ($agreement_group_entry['id']==$selected)
-                               {
-                                       $sel_agreement_group_entry = 'selected';
-                               }
-
-                               $agreement_group_list[] = array
-                               (
-                                       'cat_id'        => 
$agreement_group_entry['id'],
-                                       'name'          => 
$agreement_group_entry['name'],
-                                       'selected'      => 
$sel_agreement_group_entry
-                               );
-                       }
-
-                       for ($i=0;$i<count($agreement_group_list);$i++)
-                       {
-                               if ($agreement_group_list[$i]['selected'] != 
'selected')
-                               {
-                                       
unset($agreement_group_list[$i]['selected']);
-                               }
-                       }
-
-                       return $agreement_group_list;
-               }
-
-
-               function check_activity_num($num='',$agreement_group_id='')
-               {
-                       return 
$this->so->check_activity_num($num,$agreement_group_id);
-               }
-
-               function save_activity($values,$action='')
-               {
-                       if ($action=='edit')
-                       {
-                               $receipt = $this->so->edit_activity($values);
-                       }
-                       else
-                       {
-                               
$values['activity_id']=$this->socommon->next_id('fm_activities');
-                               $receipt = $this->so->add_activity($values);
-                       }
-                       return $receipt;
-               }
-
-               function check_agreement_group_num($num='')
-               {
-                       return $this->so->check_agreement_group_num($num);
-               }
-
-               function save_agreement_group($values,$action='')
-               {
-                       if ($action=='edit')
-                       {
-                               $receipt = 
$this->so->edit_agreement_group($values);
-                       }
-                       else
-                       {
-                               
$values['agreement_group_id']=$this->socommon->next_id('fm_agreement_group');
-                               $receipt = 
$this->so->add_agreement_group($values);
-                       }
-                       return $receipt;
-               }
-
-               function delete_activity_vendor($activity_id,$vendor_id)
-               {
-                       
$this->so->delete_activity_vendor($activity_id,$vendor_id);
-               }
-
-               function delete_activity($activity_id)
-               {
-                       $this->so->delete_activity($activity_id);
-               }
-
-               function 
delete_prize_index($activity_id,$vendor_id,$index_count)
-               {
-                       
$this->so->delete_prize_index($activity_id,$vendor_id,$index_count);
-               }
-
-               function delete_agreement_group($agreement_group_id)
-               {
-                       $this->so->delete_agreement_group($agreement_group_id);
-               }
-       }
-?>
+<?php
+       /**
+       * phpGroupWare - property: a Facilities Management System.
+       *
+       * @author Sigurd Nes <address@hidden>
+       * @copyright Copyright (C) 2003-2005 Free Software Foundation, Inc. 
http://www.fsf.org/
+       * @license http://www.gnu.org/licenses/gpl.html GNU General Public 
License
+       * @internal Development of this application was funded by 
http://www.bergen.kommune.no/bbb_/ekstern/
+       * @package property
+       * @subpackage agreement
+       * @version $Id: class.bopricebook.inc.php,v 1.8 2006/02/03 12:05:49 
sigurdne Exp $
+       */
+
+       /**
+        * Description
+        * @package property
+        */
+
+       class bopricebook
+       {
+               var $start;
+               var $query;
+               var $filter;
+               var $sort;
+               var $order;
+               var $cat_id;
+
+               var $public_functions = array
+               (
+                       'read'                          => True,
+                       'read_single'           => True,
+                       'save'                          => True,
+                       'delete'                        => True,
+                       'check_perms'           => True
+               );
+
+               var $soap_functions = array(
+                       'list' => array(
+                               'in'  => 
array('int','int','struct','string','int'),
+                               'out' => array('array')
+                       ),
+                       'read' => array(
+                               'in'  => array('int','struct'),
+                               'out' => array('array')
+                       ),
+                       'save' => array(
+                               'in'  => array('int','struct'),
+                               'out' => array()
+                       ),
+                       'delete' => array(
+                               'in'  => array('int','struct'),
+                               'out' => array()
+                       )
+               );
+
+               function bopricebook($session=False)
+               {
+                       $this->currentapp       = 
$GLOBALS['phpgw_info']['flags']['currentapp'];
+                       $this->so               = 
CreateObject($this->currentapp.'.sopricebook');
+                       $this->socommon = 
CreateObject($this->currentapp.'.socommon');
+                       $this->bocommon = 
CreateObject($this->currentapp.'.bocommon');
+
+                       if ($session)
+                       {
+                               $this->read_sessiondata();
+                               $this->use_session = True;
+                       }
+
+                       $start  = get_var('start',array('POST','GET'));
+                       $query  = get_var('query',array('POST','GET'));
+                       $sort   = get_var('sort',array('POST','GET'));
+                       $order  = get_var('order',array('POST','GET'));
+                       $filter = get_var('filter',array('POST','GET'));
+                       $cat_id = get_var('cat_id',array('POST','GET'));
+                       $allrows                        = 
get_var('allrows',array('POST','GET'));
+
+                       if ($start)
+                       {
+                               $this->start=$start;
+                       }
+                       else
+                       {
+                               $this->start=0;
+                       }
+
+                       if(isset($query))
+                       {
+                               $this->query = $query;
+                       }
+                       if(!empty($filter))
+                       {
+                               $this->filter = $filter;
+                       }
+                       if(isset($sort))
+                       {
+                               $this->sort = $sort;
+                       }
+                       if(isset($order))
+                       {
+                               $this->order = $order;
+                       }
+                       if(isset($cat_id))
+                       {
+                               $this->cat_id = $cat_id;
+                       }
+                       if(isset($allrows))
+                       {
+                               $this->allrows = $allrows;
+                       }
+               }
+
+               function save_sessiondata($data)
+               {
+                       if ($this->use_session)
+                       {
+                               
$GLOBALS['phpgw']->session->appsession('session_data','pricebook',$data);
+                       }
+               }
+
+               function read_sessiondata()
+               {
+                       $data = 
$GLOBALS['phpgw']->session->appsession('session_data','pricebook');
+
+                       //_debug_array($data);
+
+                       $this->start    = $data['start'];
+                       $this->query    = $data['query'];
+                       $this->filter   = $data['filter'];
+                       $this->sort             = $data['sort'];
+                       $this->order    = $data['order'];
+                       $this->cat_id   = $data['cat_id'];
+               }
+
+
+               function select_status_list($format='',$selected='')
+               {
+                       switch($format)
+                       {
+                               case 'select':
+                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('status_select'));
+                                       break;
+                               case 'filter':
+                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('status_filter'));
+                                       break;
+                       }
+
+                       $status_entries= $this->so->select_status_list();
+
+                       while (is_array($status_entries) && list(,$status) = 
each($status_entries))
+                       {
+                               $sel_status = '';
+                               if ($status['id']==$selected)
+                               {
+                                       $sel_status = 'selected';
+                               }
+
+                               $status_list[] = array
+                               (
+                                       'id'            => $status['id'],
+                                       'name'          => $status['name'],
+                                       'selected'      => $sel_status
+                               );
+                       }
+
+                       for ($i=0;$i<count($status_list);$i++)
+                       {
+                               if ($status_list[$i]['selected'] != 'selected')
+                               {
+                                       unset($status_list[$i]['selected']);
+                               }
+                       }
+
+                       return $status_list;
+               }
+
+               function read()
+               {
+                       $pricebook = $this->so->read(array('start' => 
$this->start,'query' => $this->query,'sort' => $this->sort,'order' => 
$this->order,
+                                                                               
        'filter' => $this->filter,'cat_id' => 
$this->cat_id,'allrows'=>$this->allrows));
+                       $this->total_records = $this->so->total_records;
+                       return $pricebook;
+               }
+
+               function read_agreement_group()
+               {
+                       $agreement_group = 
$this->so->read_agreement_group(array('start' => $this->start,'query' => 
$this->query,'sort' => $this->sort,'order' => $this->order,
+                                                                               
        'filter' => $this->filter,'cat_id' => 
$this->cat_id,'allrows'=>$this->allrows));
+                       $this->total_records = $this->so->total_records;
+                       return $agreement_group;
+               }
+
+               function read_activity_prize($activity_id,$vendor_id)
+               {
+                       $pricebook = 
$this->so->read_activity_prize(array('start' => $this->start,'query' => 
$this->query,'sort' => $this->sort,'order' => $this->order,
+                                                                               
        'filter' => $this->filter,'cat_id' => 
$this->cat_id,'allrows'=>$this->allrows,'activity_id'=>$activity_id,'vendor_id'=>$vendor_id));
+                       $this->total_records = $this->so->total_records;
+                       return $pricebook;
+               }
+
+
+               function read_activities_pr_agreement_group()
+               {
+                       $pricebook = 
$this->so->read_activities_pr_agreement_group(array('start' => 
$this->start,'query' => $this->query,'sort' => $this->sort,'order' => 
$this->order,
+                                                                               
        'filter' => $this->filter,'cat_id' => 
$this->cat_id,'allrows'=>$this->allrows));
+                       $this->total_records = $this->so->total_records;
+                       return $pricebook;
+               }
+
+               function read_vendor_pr_activity($activity_id)
+               {
+                       $pricebook = 
$this->so->read_vendor_pr_activity(array('start' => $this->start,'query' => 
$this->query,'sort' => $this->sort,'order' => $this->order,
+                                                                               
        'filter' => $this->filter,'cat_id' => 
$this->cat_id,'allrows'=>$this->allrows,'activity_id'=>$activity_id));
+                       $this->total_records = $this->so->total_records;
+                       return $pricebook;
+               }
+
+               function add_activity_vendor($values)
+               {
+                       return $this->so->add_activity_vendor($values);
+               }
+
+               function read_single_activity($id='')
+               {
+                       return $this->so->read_single_activity($id);
+               }
+
+               function read_single_agreement_group($id='')
+               {
+                       return $this->so->read_single_agreement_group($id);
+               }
+
+
+               function read_category_name($cat_id)
+               {
+                       return $this->so->read_category_name($cat_id);
+               }
+
+               function update_pricebook($values)
+               {
+
+//_debug_array($values);
+                       
$date_array=$this->bocommon->date_array($values['date']);
+
+                       $date = mktime 
(2,0,0,$date_array['month'],$date_array['day'],$date_array['year']);
+//                     $date= date($this->bocommon->dateformat,$date);
+
+                       $new_index=str_replace(",",".",$values['new_index']);
+
+                       while(address@hidden($values['update']))
+                       {
+                               $n=$entry[0];
+
+                               if(!$values['old_total_cost'][$n])
+                               {
+                                       
$new_total_cost=($values['old_m_cost'][$n]+$values['old_w_cost'][$n])*$new_index;
+                               }
+                               else
+                               {
+                                       
$new_total_cost=$values['old_total_cost'][$n]*$new_index;
+                               }
+
+                               if(!$values['old_m_cost'][$n])
+                               {
+                                       $new_m_cost=0;
+                               }
+                               else
+                               {
+                                       
$new_m_cost=$values['old_m_cost'][$n]*$new_index;
+                               }
+
+                               if(!$values['old_w_cost'][$n])
+                               {
+                                       $new_w_cost=0;
+                               }
+                               else
+                               {
+                                       
$new_w_cost=$values['old_w_cost'][$n]*$new_index;
+                               }
+
+                               $update[]=array(
+                                       'new_m_cost'            => $new_m_cost,
+                                       'new_w_cost'            => $new_w_cost,
+                                       'new_total_cost'        => 
$new_total_cost,
+                                       'activity_id'           => 
$values['activity_id'][$n],
+                                       'vendor_id'                     => 
$values['vendor_id'][$n],
+                                       'new_index'                     => 
$new_index,
+                                       'new_date'                      => 
$date,
+                               );
+
+                       }
+//_debug_array($update);
+
+                       if($update)
+                       {
+                               $receipt =      
$this->so->update_pricebook($update);
+                       }
+                       else
+                       {
+                                       $receipt['message'][] = 
array('msg'=>lang('Nothing to do!'));
+                       }
+
+                       return $receipt;
+
+               }
+
+               function add_activity_first_prize($values)
+               {
+
+                       
$date_array=$this->bocommon->date_array($values['date']);
+
+                       $date = mktime 
(2,0,0,$date_array['month'],$date_array['day'],$date_array['year']);
+//                     $date= date($this->bocommon->dateformat,$date);
+
+                       $m_cost                 = 
str_replace(",",".",$values['m_cost']);
+                       $w_cost                 = 
str_replace(",",".",$values['w_cost']);
+                       $total_cost             = $m_cost + $w_cost;
+                       $activity_id    = $values['activity_id'][0];
+                       $vendor_id              = $values['vendor_id'][0];
+
+                       $receipt = 
$this->so->add_activity_first_prize($m_cost,$w_cost,$total_cost,$activity_id,$vendor_id,$date);
+
+                       return $receipt;
+               }
+
+               function get_vendor_list($format='',$selected='')
+               {
+                       switch($format)
+                       {
+                               case 'select':
+                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('cat_select'));
+                                       break;
+                               case 'filter':
+                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('cat_filter'));
+                                       break;
+                       }
+
+                       $vendors= $this->so->get_vendor_list();
+
+                       while (is_array($vendors) && list(,$vendor_entry) = 
each($vendors))
+                       {
+                               $sel_vendor_entry = '';
+                               if ($vendor_entry['id']==$selected)
+                               {
+                                       $sel_vendor_entry = 'selected';
+                               }
+
+                               $vendor_list[] = array
+                               (
+                                       'cat_id'        => $vendor_entry['id'],
+                                       'name'          => 
$vendor_entry['name'],
+                                       'selected'      => $sel_vendor_entry
+                               );
+                       }
+
+                       for ($i=0;$i<count($vendor_list);$i++)
+                       {
+                               if ($vendor_list[$i]['selected'] != 'selected')
+                               {
+                                       unset($vendor_list[$i]['selected']);
+                               }
+                       }
+
+                       return $vendor_list;
+               }
+
+               function get_dim_d_list($selected='')
+               {
+                       
$GLOBALS['phpgw']->xslttpl->add_file(array('dim_d_select'));
+
+                       $dim_ds= $this->so->get_dim_d_list();
+
+                       while (is_array($dim_ds) && list(,$dim_d_entry) = 
each($dim_ds))
+                       {
+                               $sel_dim_d_entry = '';
+                               if ($dim_d_entry['id']==$selected)
+                               {
+                                       $sel_dim_d_entry = 'selected';
+                               }
+
+                               $dim_d_list[] = array
+                               (
+                                       'id'            => $dim_d_entry['id'],
+                                       'name'          => $dim_d_entry['name'],
+                                       'selected'      => $sel_dim_d_entry
+                               );
+                       }
+
+                       for ($i=0;$i<count($dim_d_list);$i++)
+                       {
+                               if ($dim_d_list[$i]['selected'] != 'selected')
+                               {
+                                       unset($dim_d_list[$i]['selected']);
+                               }
+                       }
+
+                       return $dim_d_list;
+               }
+
+               function get_unit_list($selected='')
+               {
+                       
$GLOBALS['phpgw']->xslttpl->add_file(array('unit_select'));
+
+                       $units= $this->so->get_unit_list();
+
+                       while (is_array($units) && list(,$unit_entry) = 
each($units))
+                       {
+                               $sel_unit_entry = '';
+                               if ($unit_entry['id']==$selected)
+                               {
+                                       $sel_unit_entry = 'selected';
+                               }
+
+                               $unit_list[] = array
+                               (
+                                       'id'            => $unit_entry['id'],
+                                       'name'          => $unit_entry['name'],
+                                       'selected'      => $sel_unit_entry
+                               );
+                       }
+
+                       for ($i=0;$i<count($unit_list);$i++)
+                       {
+                               if ($unit_list[$i]['selected'] != 'selected')
+                               {
+                                       unset($unit_list[$i]['selected']);
+                               }
+                       }
+
+                       return $unit_list;
+               }
+
+               function get_branch_list($selected='')
+               {
+                       
$GLOBALS['phpgw']->xslttpl->add_file(array('branch_select'));
+
+                       $branches= $this->so->get_branch_list();
+
+                       while (is_array($branches) && list(,$branch_entry) = 
each($branches))
+                       {
+                               $sel_branch_entry = '';
+                               if ($branch_entry['id']==$selected)
+                               {
+                                       $sel_branch_entry = 'selected';
+                               }
+
+                               $branch_list[] = array
+                               (
+                                       'id'            => $branch_entry['id'],
+                                       'name'          => 
$branch_entry['name'],
+                                       'selected'      => $sel_branch_entry
+                               );
+                       }
+
+                       for ($i=0;$i<count($branch_list);$i++)
+                       {
+                               if ($branch_list[$i]['selected'] != 'selected')
+                               {
+                                       unset($branch_list[$i]['selected']);
+                               }
+                       }
+
+                       return $branch_list;
+               }
+
+               function get_agreement_group_list($format='',$selected='')
+               {
+                       switch($format)
+                       {
+                               case 'select':
+                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('cat_select'));
+                                       break;
+                               case 'filter':
+                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('cat_filter'));
+                                       break;
+                       }
+
+                       $agreement_groups= 
$this->so->get_agreement_group_list();
+
+                       while (is_array($agreement_groups) && 
list(,$agreement_group_entry) = each($agreement_groups))
+                       {
+                               $sel_agreement_group_entry = '';
+                               if ($agreement_group_entry['id']==$selected)
+                               {
+                                       $sel_agreement_group_entry = 'selected';
+                               }
+
+                               $agreement_group_list[] = array
+                               (
+                                       'cat_id'        => 
$agreement_group_entry['id'],
+                                       'name'          => 
$agreement_group_entry['name'],
+                                       'selected'      => 
$sel_agreement_group_entry
+                               );
+                       }
+
+                       for ($i=0;$i<count($agreement_group_list);$i++)
+                       {
+                               if ($agreement_group_list[$i]['selected'] != 
'selected')
+                               {
+                                       
unset($agreement_group_list[$i]['selected']);
+                               }
+                       }
+
+                       return $agreement_group_list;
+               }
+
+
+               function check_activity_num($num='',$agreement_group_id='')
+               {
+                       return 
$this->so->check_activity_num($num,$agreement_group_id);
+               }
+
+               function save_activity($values,$action='')
+               {
+                       if ($action=='edit')
+                       {
+                               $receipt = $this->so->edit_activity($values);
+                       }
+                       else
+                       {
+                               
$values['activity_id']=$this->socommon->next_id('fm_activities');
+                               $receipt = $this->so->add_activity($values);
+                       }
+                       return $receipt;
+               }
+
+               function check_agreement_group_num($num='')
+               {
+                       return $this->so->check_agreement_group_num($num);
+               }
+
+               function save_agreement_group($values,$action='')
+               {
+                       if ($action=='edit')
+                       {
+                               $receipt = 
$this->so->edit_agreement_group($values);
+                       }
+                       else
+                       {
+                               
$values['agreement_group_id']=$this->socommon->next_id('fm_agreement_group');
+                               $receipt = 
$this->so->add_agreement_group($values);
+                       }
+                       return $receipt;
+               }
+
+               function delete_activity_vendor($activity_id,$vendor_id)
+               {
+                       
$this->so->delete_activity_vendor($activity_id,$vendor_id);
+               }
+
+               function delete_activity($activity_id)
+               {
+                       $this->so->delete_activity($activity_id);
+               }
+
+               function 
delete_prize_index($activity_id,$vendor_id,$index_count)
+               {
+                       
$this->so->delete_prize_index($activity_id,$vendor_id,$index_count);
+               }
+
+               function delete_agreement_group($agreement_group_id)
+               {
+                       $this->so->delete_agreement_group($agreement_group_id);
+               }
+       }
+?>
Index: property/inc/class.boproject.inc.php
diff -u property/inc/class.boproject.inc.php:1.13 
property/inc/class.boproject.inc.php:1.14
--- property/inc/class.boproject.inc.php:1.13   Fri Jan 27 14:05:43 2006
+++ property/inc/class.boproject.inc.php        Fri Feb  3 12:05:49 2006
@@ -1,575 +1,575 @@
-<?php
-       /**
-       * phpGroupWare - property: a Facilities Management System.
-       *
-       * @author Sigurd Nes <address@hidden>
-       * @copyright Copyright (C) 2003-2005 Free Software Foundation, Inc. 
http://www.fsf.org/
-       * @license http://www.gnu.org/licenses/gpl.html GNU General Public 
License
-       * @internal Development of this application was funded by 
http://www.bergen.kommune.no/bbb_/ekstern/
-       * @package property
-       * @subpackage project
-       * @version $Id: class.boproject.inc.php,v 1.13 2006/01/27 14:05:43 
sigurdne Exp $
-       */
-
-       /**
-        * Description
-        * @package property
-        */
-
-       class boproject
-       {
-               var $start;
-               var $query;
-               var $filter;
-               var $sort;
-               var $order;
-               var $cat_id;
-
-               var $public_functions = array
-               (
-                       'read'                          => True,
-                       'read_single'           => True,
-                       'save'                          => True,
-                       'delete'                        => True,
-                       'check_perms'           => True
-               );
-
-               function boproject($session=False)
-               {
-                       $this->currentapp       = 
$GLOBALS['phpgw_info']['flags']['currentapp'];
-                       $this->so                       = 
CreateObject($this->currentapp.'.soproject');
-                       $this->bocommon         = 
CreateObject($this->currentapp.'.bocommon');
-                       $this->solocation = 
CreateObject($this->currentapp.'.solocation');
-
-                       if ($session)
-                       {
-                               $this->read_sessiondata();
-                               $this->use_session = True;
-                       }
-
-                       $start  = get_var('start',array('POST','GET'));
-                       $query  = get_var('query',array('POST','GET'));
-                       $sort   = get_var('sort',array('POST','GET'));
-                       $order  = get_var('order',array('POST','GET'));
-                       $filter = get_var('filter',array('POST','GET'));
-                       $cat_id = get_var('cat_id',array('POST','GET'));
-                       $status_id      = 
get_var('status_id',array('POST','GET'));
-                       $wo_hour_cat_id = 
get_var('wo_hour_cat_id',array('POST','GET'));
-
-                       if ($start)
-                       {
-                               $this->start=$start;
-                       }
-                       else
-                       {
-                               $this->start=0;
-                       }
-
-                       if(isset($query))
-                       {
-                               $this->query = $query;
-                       }
-                       if(isset($filter))
-                       {
-                               $this->filter = $filter;
-                       }
-                       if(isset($sort))
-                       {
-                               $this->sort = $sort;
-                       }
-                       if(isset($order))
-                       {
-                               $this->order = $order;
-                       }
-                       if(isset($cat_id))
-                       {
-                               $this->cat_id = $cat_id;
-                       }
-                       if(isset($status_id))
-                       {
-                               $this->status_id = $status_id;
-                       }
-                       if(isset($wo_hour_cat_id))
-                       {
-                               $this->wo_hour_cat_id = $wo_hour_cat_id;
-                       }
-               }
-
-               function save_sessiondata($data)
-               {
-                       if ($this->use_session)
-                       {
-                               
$GLOBALS['phpgw']->session->appsession('session_data','project',$data);
-                       }
-               }
-
-               function read_sessiondata()
-               {
-                       $data = 
$GLOBALS['phpgw']->session->appsession('session_data','project');
-
-                       $this->start    = $data['start'];
-                       $this->query    = $data['query'];
-                       $this->filter   = $data['filter'];
-                       $this->sort             = $data['sort'];
-                       $this->order    = $data['order'];
-                       $this->cat_id   = $data['cat_id'];
-                       $this->status_id        = $data['status_id'];
-                       $this->wo_hour_cat_id   = $data['wo_hour_cat_id'];
-               }
-
-               function select_status_list($format='',$selected='')
-               {
-                       switch($format)
-                       {
-                               case 'select':
-                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('status_select'));
-                                       break;
-                               case 'filter':
-                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('status_filter'));
-                                       break;
-                       }
-
-                       $status_entries= $this->so->select_status_list();
-
-                       while (is_array($status_entries) && list(,$status) = 
each($status_entries))
-                       {
-                               $sel_status = '';
-                               if ($status['id']==$selected)
-                               {
-                                       $sel_status = 'selected';
-                               }
-
-                               $status_list[] = array
-                               (
-                                       'id'            => $status['id'],
-                                       'name'          => $status['name'],
-                                       'selected'      => $sel_status
-                               );
-                       }
-
-                       for ($i=0;$i<count($status_list);$i++)
-                       {
-                               if ($status_list[$i]['selected'] != 'selected')
-                               {
-                                       unset($status_list[$i]['selected']);
-                               }
-                       }
-
-                       return $status_list;
-               }
-
-               function select_branch_list($selected='')
-               {
-
-                       $branch_entries= $this->so->select_branch_list();
-
-                       while (is_array($branch_entries) && list(,$branch) = 
each($branch_entries))
-                       {
-                               $sel_branch = '';
-                               if ($branch['id']==$selected)
-                               {
-                                       $sel_branch = 'selected';
-                               }
-
-                               $branch_list[] = array
-                               (
-                                       'id'            => $branch['id'],
-                                       'name'          => $branch['name'],
-                                       'selected'      => $sel_branch
-                               );
-                       }
-
-                       for ($i=0;$i<count($branch_list);$i++)
-                       {
-                               if ($branch_list[$i]['selected'] != 'selected')
-                               {
-                                       unset($branch_list[$i]['selected']);
-                               }
-                       }
-
-                       return $branch_list;
-               }
-
-               function select_branch_p_list($project_id='')
-               {
-
-                       $selected               = 
$this->so->branch_p_list($project_id);
-                       $branch_entries = $this->so->select_branch_list();
-
-                       $j=0;
-                       while (is_array($branch_entries) && list(,$branch) = 
each($branch_entries))
-                       {
-                               $branch_list[$j]['id'] = $branch['id'];
-                               $branch_list[$j]['name'] = $branch['name'];
-
-                               for ($i=0;$i<count($selected);$i++)
-                               {
-                                       if($selected[$i]['branch_id'] == 
$branch['id'])
-                                       {
-                                               $branch_list[$j]['selected'] = 
'selected';
-                                       }
-                               }
-                               $j++;
-                       }
-
-                       for ($i=0;$i<count($branch_list);$i++)
-                       {
-                               if ($branch_list[$i]['selected'] != 'selected')
-                               {
-                                       unset($branch_list[$i]['selected']);
-                               }
-                       }
-
-                       return $branch_list;
-               }
-
-
-               function select_key_location_list($selected='')
-               {
-
-                       $key_location_entries= 
$this->so->select_key_location_list();
-
-                       while (is_array($key_location_entries) && 
list(,$key_location) = each($key_location_entries))
-                       {
-                               $sel_key_location = '';
-                               if ($key_location['id']==$selected)
-                               {
-                                       $sel_key_location = 'selected';
-                               }
-
-                               $key_location_list[] = array
-                               (
-                                       'id'            => $key_location['id'],
-                                       'name'          => 
$key_location['name'],
-                                       'selected'      => $sel_key_location
-                               );
-                       }
-
-                       for ($i=0;$i<count($key_location_list);$i++)
-                       {
-                               if ($key_location_list[$i]['selected'] != 
'selected')
-                               {
-                                       
unset($key_location_list[$i]['selected']);
-                               }
-                       }
-
-                       return $key_location_list;
-               }
-
-               function select_category_project_list($format='',$selected='')
-               {
-                       switch($format)
-                       {
-                               case 'select':
-                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('cat_select'));
-                                       break;
-                               case 'filter':
-                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('cat_filter'));
-                                       break;
-                       }
-
-                       $categories= 
$this->so->select_category_workorder_list();
-
-                       while (is_array($categories) && list(,$category) = 
each($categories))
-                       {
-                               $sel_category = '';
-                               if ($category['id']==$selected)
-                               {
-                                       $sel_category = 'selected';
-                               }
-
-                               $category_list[] = array
-                               (
-                                       'cat_id'        => $category['id'],
-                                       'name'          => $category['name'],
-                                       'selected'      => $sel_category
-                               );
-                       }
-
-                       for ($i=0;$i<count($category_list);$i++)
-                       {
-                               if ($category_list[$i]['selected'] != 
'selected')
-                               {
-                                       unset($category_list[$i]['selected']);
-                               }
-                       }
-
-                       return $category_list;
-               }
-
-
-               function read($start_date='',$end_date='',$allrows='')
-               {
-                       $start_date     = 
$this->bocommon->date_to_timestamp($start_date);
-                       $end_date       = 
$this->bocommon->date_to_timestamp($end_date);
-
-                       $project = $this->so->read(array('start' => 
$this->start,'query' => $this->query,'sort' => $this->sort,'order' => 
$this->order,
-                                                                               
        'filter' => $this->filter,'cat_id' => $this->cat_id,'status_id' => 
$this->status_id,'wo_hour_cat_id' => $this->wo_hour_cat_id,
-                                                                               
        'start_date'=>$start_date,'end_date'=>$end_date,'allrows'=>$allrows));
-                       $this->total_records = $this->so->total_records;
-
-                       $dateformat = 
$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
-
-                       $this->uicols   = $this->so->uicols;
-                       $this->uicols['input_type'][]   = 'link';
-                       $this->uicols['name'][]                 = 'ticket_id';
-                       $this->uicols['descr'][]                = 
lang('ticket');
-                       $this->uicols['statustext'][]   = false;
-
-//                     $cols_extra             = $this->so->cols_extra;
-
-                       for ($i=0; $i<count($project); $i++)
-                       {
-                               $project[$i]['start_date'] = 
$GLOBALS['phpgw']->common->show_date($project[$i]['start_date'],$dateformat);
-                               $project[$i]['ticket_id'] = 
$this->so->get_ticket($project[$i]['project_id']);
-
-/*                             
$location_data=$this->solocation->read_single($project[$i]['location_code']);
-
-                               for ($j=0;$j<count($cols_extra);$j++)
-                               {
-                                       $project[$i][$cols_extra[$j]] = 
$location_data[$cols_extra[$j]];
-                               }
-*/
-                       }
-
-//_debug_array($project);
-
-                       return $project;
-               }
-
-               function read_single($project_id)
-               {
-                       $contacts               = 
CreateObject($this->currentapp.'.soactor');
-                       $contacts->role='vendor';
-
-                       $config                         = 
CreateObject('phpgwapi.config');
-                       $config->read_repository();
-                       $tax = 1+($config->config_data['fm_tax'])/100;
-
-                       $project                                                
= $this->so->read_single($project_id);
-                       $dateformat                                             
= $GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
-                       $project['start_date']                  = 
$GLOBALS['phpgw']->common->show_date($project['start_date'],$dateformat);
-                       $project['end_date']                    = 
$GLOBALS['phpgw']->common->show_date($project['end_date'],$dateformat);
-                       $workorder_data                         = 
$this->so->project_workorder_data($project_id);
-
-                       for ($i=0;$i<count($workorder_data);$i++)
-                       {
-                               $sum_workorder_budget= 
$sum_workorder_budget+$workorder_data[$i]['budget'];
-                               $sum_deviation= 
$sum_deviation+$workorder_data[$i]['deviation'];
-                               $sum_workorder_calculation= 
$sum_workorder_calculation+$workorder_data[$i]['calculation'];
-                               $sum_workorder_actual_cost= 
$sum_workorder_actual_cost+$workorder_data[$i]['act_mtrl_cost']+$workorder_data[$i]['act_vendor_cost'];
-
-                               
$project['workorder_budget'][$i]['workorder_id']=$workorder_data[$i]['workorder_id'];
-                               
$project['workorder_budget'][$i]['budget']=number_format($workorder_data[$i]['budget'],
 2, ',', '');
-                               
$project['workorder_budget'][$i]['calculation']=number_format($workorder_data[$i]['calculation']*$tax,
 2, ',', '');
-                               
$project['workorder_budget'][$i]['charge_tenant'] = 
$workorder_data[$i]['charge_tenant'];
-                               $vendor = 
$contacts->read_single(array('actor_id'=>(int)$workorder_data[$i]['vendor_id']));
-                               if(is_array($vendor))
-                               {
-                                       foreach($vendor['attributes'] as 
$attribute)
-                                       {
-                                               
if($attribute['name']=='org_name')
-                                               {
-                                                       
$project['workorder_budget'][$i]['vendor_name']=$attribute['value'];
-                                                       break;
-                                               }
-                                       }
-                               }
-                       }
-                       if($workorder_data)
-                       {
-                               $project['sum_workorder_budget']= 
number_format($sum_workorder_budget, 2, ',', '');
-                               $project['deviation']= $sum_deviation;
-                               $project['sum_workorder_calculation']= 
number_format($sum_workorder_calculation*$tax, 2, ',', '');
-                               $project['sum_workorder_actual_cost']= 
number_format($sum_workorder_actual_cost, 2, ',', '');
-                       }
-
-                       if($project['location_code'])
-                       {
-                               $project['location_data'] 
=$this->solocation->read_single($project['location_code']);
-                       }
-
-                       if($project['tenant_id']>0)
-                       {
-                               
$tenant_data=$this->bocommon->read_single_tenant($project['tenant_id']);
-                               $project['location_data']['tenant_id']= 
$project['tenant_id'];
-                               $project['location_data']['contact_phone']= 
$tenant_data['contact_phone'];
-                               $project['location_data']['last_name']  = 
$tenant_data['last_name'];
-                               $project['location_data']['first_name'] = 
$tenant_data['first_name'];
-                       }
-                       else
-                       {
-                               unset($project['location_data']['tenant_id']);
-                               
unset($project['location_data']['contact_phone']);
-                               unset($project['location_data']['last_name']);
-                               unset($project['location_data']['first_name']);
-                       }
-
-                       if($project['p_num'])
-                       {
-                               $soadmin_entity = 
CreateObject($this->currentapp.'.soadmin_entity');
-                               $category = 
$soadmin_entity->read_single_category($project['p_entity_id'],$project['p_cat_id']);
-
-                               
$project['p'][$project['p_entity_id']]['p_num']=$project['p_num'];
-                               
$project['p'][$project['p_entity_id']]['p_entity_id']=$project['p_entity_id'];
-                               
$project['p'][$project['p_entity_id']]['p_cat_id']=$project['p_cat_id'];
-                               
$project['p'][$project['p_entity_id']]['p_cat_name'] = $category['name'];
-                       }
-
-
-//_debug_array($project);
-                       return $project;
-               }
-
-               function read_single_mini($project_id)
-               {
-                       $project                                                
= $this->so->read_single($project_id);
-                       $dateformat                                             
= $GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
-                       $project['start_date']                  = 
$GLOBALS['phpgw']->common->show_date($project['start_date'],$dateformat);
-                       $project['end_date']                    = 
$GLOBALS['phpgw']->common->show_date($project['end_date'],$dateformat);
-
-                       if($project['location_code'])
-                       {
-                               $project['location_data'] 
=$this->solocation->read_single($project['location_code']);
-                       }
-
-                       if($project['tenant_id']>0)
-                       {
-                               
$tenant_data=$this->bocommon->read_single_tenant($project['tenant_id']);
-                               $project['location_data']['tenant_id']= 
$project['tenant_id'];
-                               $project['location_data']['contact_phone']= 
$tenant_data['contact_phone'];
-                               $project['location_data']['last_name']  = 
$tenant_data['last_name'];
-                               $project['location_data']['first_name'] = 
$tenant_data['first_name'];
-                       }
-                       else
-                       {
-                               unset($project['location_data']['tenant_id']);
-                               
unset($project['location_data']['contact_phone']);
-                               unset($project['location_data']['last_name']);
-                               unset($project['location_data']['first_name']);
-                       }
-
-//_debug_array($project);
-                       return $project;
-               }
-
-
-               function read_record_history($id)
-               {
-                       $historylog     = 
CreateObject($this->currentapp.'.historylog','project');
-                       $history_array = 
$historylog->return_array(array('O'),array(),'','',$id);
-                       $i=0;
-                       while (is_array($history_array) && list(,$value) = 
each($history_array))
-                       {
-
-                               $record_history[$i]['value_date']       = 
$GLOBALS['phpgw']->common->show_date($value['datetime']);
-                               $record_history[$i]['value_user']       = 
$value['owner'];
-
-                               switch ($value['status'])
-                               {
-                                       case 'R': $type = lang('Re-opened'); 
break;
-                                       case 'X': $type = lang('Closed');    
break;
-                                       case 'O': $type = lang('Opened');    
break;
-                                       case 'A': $type = lang('Re-assigned'); 
break;
-                                       case 'P': $type = lang('Priority 
changed'); break;
-                                       case 'CO': $type = lang('Initial 
Coordinator'); break;
-                                       case 'C': $type = lang('Coordinator 
changed'); break;
-                                       case 'TO': $type = lang('Initial 
Category'); break;
-                                       case 'T': $type = lang('Category 
changed'); break;
-                                       case 'SO': $type = lang('Initial 
Status'); break;
-                                       case 'S': $type = lang('Status 
changed'); break;
-                                       default: break;
-                               }
-
-                               
if($value['new_value']=='O'){$value['new_value']=lang('Opened');}
-                               
if($value['new_value']=='X'){$value['new_value']=lang('Closed');}
-
-
-                               $record_history[$i]['value_action']     = 
$type?$type:'';
-                               unset($type);
-
-                               if ($value['status'] == 'A')
-                               {
-                                       if (! $value['new_value'])
-                                       {
-                                               
$record_history[$i]['value_new_value']  = lang('None');
-                                       }
-                                       else
-                                       {
-                                               
$record_history[$i]['value_new_value']  = 
$GLOBALS['phpgw']->accounts->id2name($value['new_value']);
-                                       }
-                               }
-                               else if ($value['status'] == 'C' || 
$value['status'] == 'CO')
-                               {
-                                       $record_history[$i]['value_new_value']  
= $GLOBALS['phpgw']->accounts->id2name($value['new_value']);
-                               }
-                               else if ($value['status'] == 'T' || 
$value['status'] == 'TO')
-                               {
-                                       $record_history[$i]['value_new_value']  
= $this->so->read_single_project_category($value['new_value']);
-                               }
-                               else if ($value['status'] != 'O' && 
$value['new_value'])
-                               {
-                                       $record_history[$i]['value_new_value']  
= $value['new_value'];
-                               }
-                               else
-                               {
-                                       $record_history[$i]['value_new_value']  
= '';
-                               }
-
-                               $i++;
-                       }
-
-                       return $record_history;
-               }
-
-
-               function next_project_id()
-               {
-                       return $this->so->next_project_id();
-               }
-
-               function save($project,$action='')
-               {
-
-//_debug_array($project);
-                       while (is_array($project['location']) && list(,$value) 
= each($project['location']))
-                       {
-                               if($value)
-                               {
-                                       $location[] = $value;
-                               }
-                       }
-
-                       $project['location_code']=implode("-", $location);
-
-                       $start_date     = 
$this->bocommon->date_array($project['start_date']);
-                       $end_date       = 
$this->bocommon->date_array($project['end_date']);
-
-                       $project['start_date']  = mktime 
(2,0,0,$start_date['month'],$start_date['day'],$start_date['year']);
-                       $project['end_date']    = mktime 
(2,0,0,$end_date['month'],$end_date['day'],$end_date['year']);
-
-
-                       if ($action=='edit')
-                       {
-                                       $receipt = $this->so->edit($project);
-                       }
-                       else
-                       {
-                               $receipt = $this->so->add($project);
-                       }
-                       return $receipt;
-               }
-
-               function add_request($add_request,$id)
-               {
-
-                       return $this->so->add_request($add_request,$id);
-               }
-
-               function delete($project_id)
-               {
-                       $this->so->delete($project_id);
-               }
-
-       }
-?>
+<?php
+       /**
+       * phpGroupWare - property: a Facilities Management System.
+       *
+       * @author Sigurd Nes <address@hidden>
+       * @copyright Copyright (C) 2003-2005 Free Software Foundation, Inc. 
http://www.fsf.org/
+       * @license http://www.gnu.org/licenses/gpl.html GNU General Public 
License
+       * @internal Development of this application was funded by 
http://www.bergen.kommune.no/bbb_/ekstern/
+       * @package property
+       * @subpackage project
+       * @version $Id: class.boproject.inc.php,v 1.14 2006/02/03 12:05:49 
sigurdne Exp $
+       */
+
+       /**
+        * Description
+        * @package property
+        */
+
+       class boproject
+       {
+               var $start;
+               var $query;
+               var $filter;
+               var $sort;
+               var $order;
+               var $cat_id;
+
+               var $public_functions = array
+               (
+                       'read'                          => True,
+                       'read_single'           => True,
+                       'save'                          => True,
+                       'delete'                        => True,
+                       'check_perms'           => True
+               );
+
+               function boproject($session=False)
+               {
+                       $this->currentapp       = 
$GLOBALS['phpgw_info']['flags']['currentapp'];
+                       $this->so                       = 
CreateObject($this->currentapp.'.soproject');
+                       $this->bocommon         = 
CreateObject($this->currentapp.'.bocommon');
+                       $this->solocation = 
CreateObject($this->currentapp.'.solocation');
+
+                       if ($session)
+                       {
+                               $this->read_sessiondata();
+                               $this->use_session = True;
+                       }
+
+                       $start  = get_var('start',array('POST','GET'));
+                       $query  = get_var('query',array('POST','GET'));
+                       $sort   = get_var('sort',array('POST','GET'));
+                       $order  = get_var('order',array('POST','GET'));
+                       $filter = get_var('filter',array('POST','GET'));
+                       $cat_id = get_var('cat_id',array('POST','GET'));
+                       $status_id      = 
get_var('status_id',array('POST','GET'));
+                       $wo_hour_cat_id = 
get_var('wo_hour_cat_id',array('POST','GET'));
+
+                       if ($start)
+                       {
+                               $this->start=$start;
+                       }
+                       else
+                       {
+                               $this->start=0;
+                       }
+
+                       if(isset($query))
+                       {
+                               $this->query = $query;
+                       }
+                       if(isset($filter))
+                       {
+                               $this->filter = $filter;
+                       }
+                       if(isset($sort))
+                       {
+                               $this->sort = $sort;
+                       }
+                       if(isset($order))
+                       {
+                               $this->order = $order;
+                       }
+                       if(isset($cat_id))
+                       {
+                               $this->cat_id = $cat_id;
+                       }
+                       if(isset($status_id))
+                       {
+                               $this->status_id = $status_id;
+                       }
+                       if(isset($wo_hour_cat_id))
+                       {
+                               $this->wo_hour_cat_id = $wo_hour_cat_id;
+                       }
+               }
+
+               function save_sessiondata($data)
+               {
+                       if ($this->use_session)
+                       {
+                               
$GLOBALS['phpgw']->session->appsession('session_data','project',$data);
+                       }
+               }
+
+               function read_sessiondata()
+               {
+                       $data = 
$GLOBALS['phpgw']->session->appsession('session_data','project');
+
+                       $this->start    = $data['start'];
+                       $this->query    = $data['query'];
+                       $this->filter   = $data['filter'];
+                       $this->sort             = $data['sort'];
+                       $this->order    = $data['order'];
+                       $this->cat_id   = $data['cat_id'];
+                       $this->status_id        = $data['status_id'];
+                       $this->wo_hour_cat_id   = $data['wo_hour_cat_id'];
+               }
+
+               function select_status_list($format='',$selected='')
+               {
+                       switch($format)
+                       {
+                               case 'select':
+                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('status_select'));
+                                       break;
+                               case 'filter':
+                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('status_filter'));
+                                       break;
+                       }
+
+                       $status_entries= $this->so->select_status_list();
+
+                       while (is_array($status_entries) && list(,$status) = 
each($status_entries))
+                       {
+                               $sel_status = '';
+                               if ($status['id']==$selected)
+                               {
+                                       $sel_status = 'selected';
+                               }
+
+                               $status_list[] = array
+                               (
+                                       'id'            => $status['id'],
+                                       'name'          => $status['name'],
+                                       'selected'      => $sel_status
+                               );
+                       }
+
+                       for ($i=0;$i<count($status_list);$i++)
+                       {
+                               if ($status_list[$i]['selected'] != 'selected')
+                               {
+                                       unset($status_list[$i]['selected']);
+                               }
+                       }
+
+                       return $status_list;
+               }
+
+               function select_branch_list($selected='')
+               {
+
+                       $branch_entries= $this->so->select_branch_list();
+
+                       while (is_array($branch_entries) && list(,$branch) = 
each($branch_entries))
+                       {
+                               $sel_branch = '';
+                               if ($branch['id']==$selected)
+                               {
+                                       $sel_branch = 'selected';
+                               }
+
+                               $branch_list[] = array
+                               (
+                                       'id'            => $branch['id'],
+                                       'name'          => $branch['name'],
+                                       'selected'      => $sel_branch
+                               );
+                       }
+
+                       for ($i=0;$i<count($branch_list);$i++)
+                       {
+                               if ($branch_list[$i]['selected'] != 'selected')
+                               {
+                                       unset($branch_list[$i]['selected']);
+                               }
+                       }
+
+                       return $branch_list;
+               }
+
+               function select_branch_p_list($project_id='')
+               {
+
+                       $selected               = 
$this->so->branch_p_list($project_id);
+                       $branch_entries = $this->so->select_branch_list();
+
+                       $j=0;
+                       while (is_array($branch_entries) && list(,$branch) = 
each($branch_entries))
+                       {
+                               $branch_list[$j]['id'] = $branch['id'];
+                               $branch_list[$j]['name'] = $branch['name'];
+
+                               for ($i=0;$i<count($selected);$i++)
+                               {
+                                       if($selected[$i]['branch_id'] == 
$branch['id'])
+                                       {
+                                               $branch_list[$j]['selected'] = 
'selected';
+                                       }
+                               }
+                               $j++;
+                       }
+
+                       for ($i=0;$i<count($branch_list);$i++)
+                       {
+                               if ($branch_list[$i]['selected'] != 'selected')
+                               {
+                                       unset($branch_list[$i]['selected']);
+                               }
+                       }
+
+                       return $branch_list;
+               }
+
+
+               function select_key_location_list($selected='')
+               {
+
+                       $key_location_entries= 
$this->so->select_key_location_list();
+
+                       while (is_array($key_location_entries) && 
list(,$key_location) = each($key_location_entries))
+                       {
+                               $sel_key_location = '';
+                               if ($key_location['id']==$selected)
+                               {
+                                       $sel_key_location = 'selected';
+                               }
+
+                               $key_location_list[] = array
+                               (
+                                       'id'            => $key_location['id'],
+                                       'name'          => 
$key_location['name'],
+                                       'selected'      => $sel_key_location
+                               );
+                       }
+
+                       for ($i=0;$i<count($key_location_list);$i++)
+                       {
+                               if ($key_location_list[$i]['selected'] != 
'selected')
+                               {
+                                       
unset($key_location_list[$i]['selected']);
+                               }
+                       }
+
+                       return $key_location_list;
+               }
+
+               function select_category_project_list($format='',$selected='')
+               {
+                       switch($format)
+                       {
+                               case 'select':
+                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('cat_select'));
+                                       break;
+                               case 'filter':
+                                       
$GLOBALS['phpgw']->xslttpl->add_file(array('cat_filter'));
+                                       break;
+                       }
+
+                       $categories= 
$this->so->select_category_workorder_list();
+
+                       while (is_array($categories) && list(,$category) = 
each($categories))
+                       {
+                               $sel_category = '';
+                               if ($category['id']==$selected)
+                               {
+                                       $sel_category = 'selected';
+                               }
+
+                               $category_list[] = array
+                               (
+                                       'cat_id'        => $category['id'],
+                                       'name'          => $category['name'],
+                                       'selected'      => $sel_category
+                               );
+                       }
+
+                       for ($i=0;$i<count($category_list);$i++)
+                       {
+                               if ($category_list[$i]['selected'] != 
'selected')
+                               {
+                                       unset($category_list[$i]['selected']);
+                               }
+                       }
+
+                       return $category_list;
+               }
+
+
+               function read($start_date='',$end_date='',$allrows='')
+               {
+                       $start_date     = 
$this->bocommon->date_to_timestamp($start_date);
+                       $end_date       = 
$this->bocommon->date_to_timestamp($end_date);
+
+                       $project = $this->so->read(array('start' => 
$this->start,'query' => $this->query,'sort' => $this->sort,'order' => 
$this->order,
+                                                                               
        'filter' => $this->filter,'cat_id' => $this->cat_id,'status_id' => 
$this->status_id,'wo_hour_cat_id' => $this->wo_hour_cat_id,
+                                                                               
        'start_date'=>$start_date,'end_date'=>$end_date,'allrows'=>$allrows));
+                       $this->total_records = $this->so->total_records;
+
+                       $dateformat = 
$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
+
+                       $this->uicols   = $this->so->uicols;
+                       $this->uicols['input_type'][]   = 'link';
+                       $this->uicols['name'][]                 = 'ticket_id';
+                       $this->uicols['descr'][]                = 
lang('ticket');
+                       $this->uicols['statustext'][]   = false;
+
+//                     $cols_extra             = $this->so->cols_extra;
+
+                       for ($i=0; $i<count($project); $i++)
+                       {
+                               $project[$i]['start_date'] = 
$GLOBALS['phpgw']->common->show_date($project[$i]['start_date'],$dateformat);
+                               $project[$i]['ticket_id'] = 
$this->so->get_ticket($project[$i]['project_id']);
+
+/*                             
$location_data=$this->solocation->read_single($project[$i]['location_code']);
+
+                               for ($j=0;$j<count($cols_extra);$j++)
+                               {
+                                       $project[$i][$cols_extra[$j]] = 
$location_data[$cols_extra[$j]];
+                               }
+*/
+                       }
+
+//_debug_array($project);
+
+                       return $project;
+               }
+
+               function read_single($project_id)
+               {
+                       $contacts               = 
CreateObject($this->currentapp.'.soactor');
+                       $contacts->role='vendor';
+
+                       $config                         = 
CreateObject('phpgwapi.config');
+                       $config->read_repository();
+                       $tax = 1+($config->config_data['fm_tax'])/100;
+
+                       $project                                                
= $this->so->read_single($project_id);
+                       $dateformat                                             
= $GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
+                       $project['start_date']                  = 
$GLOBALS['phpgw']->common->show_date($project['start_date'],$dateformat);
+                       $project['end_date']                    = 
$GLOBALS['phpgw']->common->show_date($project['end_date'],$dateformat);
+                       $workorder_data                         = 
$this->so->project_workorder_data($project_id);
+
+                       for ($i=0;$i<count($workorder_data);$i++)
+                       {
+                               $sum_workorder_budget= 
$sum_workorder_budget+$workorder_data[$i]['budget'];
+                               $sum_deviation= 
$sum_deviation+$workorder_data[$i]['deviation'];
+                               $sum_workorder_calculation= 
$sum_workorder_calculation+$workorder_data[$i]['calculation'];
+                               $sum_workorder_actual_cost= 
$sum_workorder_actual_cost+$workorder_data[$i]['act_mtrl_cost']+$workorder_data[$i]['act_vendor_cost'];
+
+                               
$project['workorder_budget'][$i]['workorder_id']=$workorder_data[$i]['workorder_id'];
+                               
$project['workorder_budget'][$i]['budget']=number_format($workorder_data[$i]['budget'],
 2, ',', '');
+                               
$project['workorder_budget'][$i]['calculation']=number_format($workorder_data[$i]['calculation']*$tax,
 2, ',', '');
+                               
$project['workorder_budget'][$i]['charge_tenant'] = 
$workorder_data[$i]['charge_tenant'];
+                               $vendor = 
$contacts->read_single(array('actor_id'=>(int)$workorder_data[$i]['vendor_id']));
+                               if(is_array($vendor))
+                               {
+                                       foreach($vendor['attributes'] as 
$attribute)
+                                       {
+                                               
if($attribute['name']=='org_name')
+                                               {
+                                                       
$project['workorder_budget'][$i]['vendor_name']=$attribute['value'];
+                                                       break;
+                                               }
+                                       }
+                               }
+                       }
+                       if($workorder_data)
+                       {
+                               $project['sum_workorder_budget']= 
number_format($sum_workorder_budget, 2, ',', '');
+                               $project['deviation']= $sum_deviation;
+                               $project['sum_workorder_calculation']= 
number_format($sum_workorder_calculation*$tax, 2, ',', '');
+                               $project['sum_workorder_actual_cost']= 
number_format($sum_workorder_actual_cost, 2, ',', '');
+                       }
+
+                       if($project['location_code'])
+                       {
+                               $project['location_data'] 
=$this->solocation->read_single($project['location_code']);
+                       }
+
+                       if($project['tenant_id']>0)
+                       {
+                               
$tenant_data=$this->bocommon->read_single_tenant($project['tenant_id']);
+                               $project['location_data']['tenant_id']= 
$project['tenant_id'];
+                               $project['location_data']['contact_phone']= 
$tenant_data['contact_phone'];
+                               $project['location_data']['last_name']  = 
$tenant_data['last_name'];
+                               $project['location_data']['first_name'] = 
$tenant_data['first_name'];
+                       }
+                       else
+                       {
+                               unset($project['location_data']['tenant_id']);
+                               
unset($project['location_data']['contact_phone']);
+                               unset($project['location_data']['last_name']);
+                               unset($project['location_data']['first_name']);
+                       }
+
+                       if($project['p_num'])
+                       {
+                               $soadmin_entity = 
CreateObject($this->currentapp.'.soadmin_entity');
+                               $category = 
$soadmin_entity->read_single_category($project['p_entity_id'],$project['p_cat_id']);
+
+                               
$project['p'][$project['p_entity_id']]['p_num']=$project['p_num'];
+                               
$project['p'][$project['p_entity_id']]['p_entity_id']=$project['p_entity_id'];
+                               
$project['p'][$project['p_entity_id']]['p_cat_id']=$project['p_cat_id'];
+                               
$project['p'][$project['p_entity_id']]['p_cat_name'] = $category['name'];
+                       }
+
+
+//_debug_array($project);
+                       return $project;
+               }
+
+               function read_single_mini($project_id)
+               {
+                       $project                                                
= $this->so->read_single($project_id);
+                       $dateformat                                             
= $GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
+                       $project['start_date']                  = 
$GLOBALS['phpgw']->common->show_date($project['start_date'],$dateformat);
+                       $project['end_date']                    = 
$GLOBALS['phpgw']->common->show_date($project['end_date'],$dateformat);
+
+                       if($project['location_code'])
+                       {
+                               $project['location_data'] 
=$this->solocation->read_single($project['location_code']);
+                       }
+
+                       if($project['tenant_id']>0)
+                       {
+                               
$tenant_data=$this->bocommon->read_single_tenant($project['tenant_id']);
+                               $project['location_data']['tenant_id']= 
$project['tenant_id'];
+                               $project['location_data']['contact_phone']= 
$tenant_data['contact_phone'];
+                               $project['location_data']['last_name']  = 
$tenant_data['last_name'];
+                               $project['location_data']['first_name'] = 
$tenant_data['first_name'];
+                       }
+                       else
+                       {
+                               unset($project['location_data']['tenant_id']);
+                               
unset($project['location_data']['contact_phone']);
+                               unset($project['location_data']['last_name']);
+                               unset($project['location_data']['first_name']);
+                       }
+
+//_debug_array($project);
+                       return $project;
+               }
+
+
+               function read_record_history($id)
+               {
+                       $historylog     = 
CreateObject($this->currentapp.'.historylog','project');
+                       $history_array = 
$historylog->return_array(array('O'),array(),'','',$id);
+                       $i=0;
+                       while (is_array($history_array) && list(,$value) = 
each($history_array))
+                       {
+
+                               $record_history[$i]['value_date']       = 
$GLOBALS['phpgw']->common->show_date($value['datetime']);
+                               $record_history[$i]['value_user']       = 
$value['owner'];
+
+                               switch ($value['status'])
+                               {
+                                       case 'R': $type = lang('Re-opened'); 
break;
+                                       case 'X': $type = lang('Closed');    
break;
+                                       case 'O': $type = lang('Opened');    
break;
+                                       case 'A': $type = lang('Re-assigned'); 
break;
+                                       case 'P': $type = lang('Priority 
changed'); break;
+                                       case 'CO': $type = lang('Initial 
Coordinator'); break;
+                                       case 'C': $type = lang('Coordinator 
changed'); break;
+                                       case 'TO': $type = lang('Initial 
Category'); break;
+                                       case 'T': $type = lang('Category 
changed'); break;
+                                       case 'SO': $type = lang('Initial 
Status'); break;
+                                       case 'S': $type = lang('Status 
changed'); break;
+                                       default: break;
+                               }
+
+                               
if($value['new_value']=='O'){$value['new_value']=lang('Opened');}
+                               
if($value['new_value']=='X'){$value['new_value']=lang('Closed');}
+
+
+                               $record_history[$i]['value_action']     = 
$type?$type:'';
+                               unset($type);
+
+                               if ($value['status'] == 'A')
+                               {
+                                       if (! $value['new_value'])
+                                       {
+                                               
$record_history[$i]['value_new_value']  = lang('None');
+                                       }
+                                       else
+                                       {
+                                               
$record_history[$i]['value_new_value']  = 
$GLOBALS['phpgw']->accounts->id2name($value['new_value']);
+                                       }
+                               }
+                               else if ($value['status'] == 'C' || 
$value['status'] == 'CO')
+                               {
+                                       $record_history[$i]['value_new_value']  
= $GLOBALS['phpgw']->accounts->id2name($value['new_va