phpgroupware-cvs
[Top][All Lists]
Advanced

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

[Phpgroupware-cvs] property/class.soentity.php, 1.1.1.3


From: nomail
Subject: [Phpgroupware-cvs] property/class.soentity.php, 1.1.1.3
Date: Fri, 21 May 2004 16:04:21 -0000

Update of /property
Modified Files:
        Branch: 
          class.soentity.php

date: 2004/04/23 21:26:33;  author: sigurdne;  state: Exp;  lines: +617 -617

Log Message:
no message
=====================================================================
Index: property/class.soentity.php
diff -u property/class.soentity.php:1.1.1.2 property/class.soentity.php:1.1.1.3
--- property/class.soentity.php:1.1.1.2 Fri Apr 23 20:25:47 2004
+++ property/class.soentity.php Fri Apr 23 21:26:33 2004
@@ -1,617 +1,617 @@
-<?php
-       
/**************************************************************************\
-       * phpGroupWare - property                                               
   *
-       * http://www.phpgroupware.org                                           
   *
-       *                                                                       
   *
-       * Facilities Management                                                 
   *
-       * Written by Sigurd Nes [sigurdne at online.no]                         
   *
-       * 
------------------------------------------------------------------------ *
-       * Copyright 2000 - 2003 Free Software Foundation, Inc                   
   *
-       * This program is part of the GNU project, see http://www.gnu.org/      
   *
-       * 
------------------------------------------------------------------------ *
-       * This program is free software; you can redistribute it and/or modify 
it  *
-       * under the terms of the GNU General Public License as published by the 
   *
-       * Free Software Foundation; either version 2 of the License, or (at 
your   *
-       * option) any later version.                                            
   *
-       
\**************************************************************************/
-
-       class property_soentity
-       {
-               function property_soentity()
-               {
-                       $this->currentapp       = 'property'; 
//$GLOBALS['phpgw_info']['flags']['currentapp'];
-                       $this->db                       = $GLOBALS['phpgw']->db;
-                       $this->db2                      = $this->db;
-                       $this->account          = 
$GLOBALS['phpgw_data']['user']['id'];
-                       $this->bocommon         = 
CreateObject($this->currentapp.'_bocommon');
-                       $this->fm_session       = 
CreateObject($this->currentapp.'_session');
-
-                       $this->join                     = $this->bocommon->join;
-                       $this->left_join        = $this->bocommon->left_join;
-               }
-
-               function select_status_list($entity_id,$cat_id)
-               {
-                       if(!$entity_id || !$cat_id)
-                       {
-                               return;
-                       }
-
-                       $sql= "SELECT fm_entity_choice.id, 
fm_entity_choice.value FROM fm_entity_attribute $this->join fm_entity_choice ON 
"
-                       . " fm_entity_attribute.entity_id= 
fm_entity_choice.entity_id AND "
-                       . " fm_entity_attribute.cat_id= fm_entity_choice.cat_id 
AND "
-                       . " fm_entity_attribute.id= fm_entity_choice.attrib_id "
-                       . " WHERE fm_entity_attribute.column_name='status' "
-                       . " AND fm_entity_choice.entity_id=$entity_id "
-                       . " AND fm_entity_choice.cat_id=$cat_id ORDER BY 
fm_entity_choice.id";
-
-
-                       $dbresult = $GLOBALS['phpgw']->db->Execute($sql);
-
-                       $i = 0;
-                       while (!$dbresult->EOF)
-                       {
-                               $status[$i]['id']                               
= $dbresult->fields['id'];
-                               $status[$i]['name']                             
= stripslashes($dbresult->fields['value']);
-                               $i++;
-                               $dbresult->MoveNext();
-                       }
-                       return $status;
-               }
-
-
-               function read($data)
-               {
-                       if(is_array($data))
-                       {
-                               if ($data['start'])
-                               {
-                                       $start=$data['start'];
-                               }
-                               else
-                               {
-                                       $start=0;
-                               }
-                               $filter = $data['filter']?$data['filter']:'all';
-                               $query = 
(isset($data['query'])?$data['query']:'');
-                               $sort = 
(isset($data['sort'])?$data['sort']:'DESC');
-                               $order = 
(isset($data['order'])?$data['order']:'');
-                               $cat_id = 
(isset($data['cat_id'])?$data['cat_id']:0);
-                               $district_id = 
(isset($data['district_id'])?$data['district_id']:0);
-                               $lookup = 
(isset($data['lookup'])?$data['lookup']:'');
-                               $allrows = 
(isset($data['allrows'])?$data['allrows']:'');
-                               $entity_id = 
(isset($data['entity_id'])?$data['entity_id']:'');
-                               $cat_id = 
(isset($data['cat_id'])?$data['cat_id']:'');
-                               $status = 
(isset($data['status'])?$data['status']:'');
-                               $start_date = 
(isset($data['start_date'])?$data['start_date']:'');
-                               $end_date = 
(isset($data['end_date'])?$data['end_date']:'');
-                       }
-
-                       if(!$entity_id || !$cat_id)
-                       {
-                               return;
-                       }
-
-                       $grants         = 
$this->fm_session->appsession('grants_entity_'.$entity_id.'_'.$cat_id,$this->currentapp);
-
-                       if(!$grants)
-                       {
-                               $this->acl2             = 
CreateObject($this->currentapp.'_acl2','##DEFAULT##','##DEFAULT##');
-                               $grants         = 
$this->acl2->get_grants($this->currentapp,'.entity.' . $entity_id . '.' . 
$cat_id);
-                               
$this->fm_session->appsession('grants_entity_'.$entity_id.'_'.$cat_id,$this->currentapp,$grants);
-                       }
-
-
-                       $sql = $this->bocommon->fm_cache('sql_entity_' . 
$entity_id . '_' . $cat_id . '_' . $lookup);
-
-                       $entity_table = 'fm_entity_' . $entity_id . '_' . 
$cat_id;
-                       if(!$sql)
-                       {
-                               $cols = $entity_table . '.*';
-                               $cols_return[] = 'location_code';
-
-                               $cols_return[]                          = 'num';
-                               $uicols['input_type'][]         = 'text';
-                               $uicols['name'][]                       = 'num';
-                               $uicols['descr'][]                      = 
lang('ID');
-                               $uicols['statustext'][]         = lang('ID');
-
-                               $cols_return[]                          = 'id';
-                               $uicols['input_type'][]         = 'hidden';
-                               $uicols['name'][]                       = 'id';
-                               $uicols['descr'][]                      = false;
-                               $uicols['statustext'][]         = false;
-                               if($lookup)
-                               {
-                                       $cols .= ',num as entity_num_' . 
$entity_id;
-                                       $cols_return[] = 'entity_num_' . 
$entity_id;
-                               }
-
-
-                               $admin_entity   = 
CreateObject($this->currentapp.'_soadmin_entity');
-                               $category = 
$admin_entity->read_single_category($entity_id,$cat_id);
-
-                               $sql = 
$this->bocommon->generate_sql(array('entity_table'=>$entity_table,'cols_return'=>$cols_return,'cols'=>$cols,
-                                                               
'uicols'=>$uicols,'joinmethod'=>$joinmethod,'paranthesis'=>$paranthesis,'query'=>$query,'lookup'=>$lookup,'location_level'=>$category['location_level']));
-
-                               $this->bocommon->fm_cache('sql_entity_' . 
$entity_id . '_' . $cat_id . '_' . $lookup,$sql);
-                               $this->bocommon->fm_cache('uicols_entityt_' . 
$entity_id . '_' . $cat_id . '_' . $lookup,$this->bocommon->uicols);
-                               
$this->bocommon->fm_cache('cols_return_entityt_' . $entity_id . '_' . $cat_id . 
'_' . $lookup,$this->bocommon->cols_return);
-                               
$this->bocommon->fm_cache('cols_return_lookup_entityt_' . $entity_id . '_' . 
$cat_id . '_' . $lookup,$this->bocommon->cols_return_lookup);
-                               $this->bocommon->fm_cache('cols_extra_entityt_' 
. $entity_id . '_' . $cat_id . '_' . $lookup,$this->bocommon->cols_extra);
-
-                               $uicols                                         
= $this->bocommon->uicols;
-                               $cols_return                            = 
$this->bocommon->cols_return;
-                               $this->cols_return_lookup       = 
$this->bocommon->cols_return_lookup;
-                               $this->cols_extra                       = 
$this->bocommon->cols_extra;
-                       }
-                       else
-                       {
-                               $uicols                                         
        = $this->bocommon->fm_cache('uicols_entityt_' . $entity_id . '_' . 
$cat_id . '_' . $lookup);
-                               $cols_return                                    
= $this->bocommon->fm_cache('cols_return_entityt_' . $entity_id . '_' . $cat_id 
. '_' . $lookup);
-                               $this->cols_return_lookup               = 
$this->bocommon->fm_cache('cols_return_lookup_entityt_' . $entity_id . '_' . 
$cat_id . '_' . $lookup);
-                               $this->cols_extra                               
= $this->bocommon->fm_cache('cols_extra_entityt_' . $entity_id . '_' . $cat_id 
. '_' . $lookup);
-                               if($lookup)
-                               {
-                                       $admin_entity   = 
CreateObject($this->currentapp.'_soadmin_entity');
-                                       $category = 
$admin_entity->read_single_category($entity_id,$cat_id);
-                               }
-
-                       }
-
-                       if ($cat_id > 0)
-                       {
-                               
$user_columns=$GLOBALS['phpgw_info']['user']['preferences'][$this->currentapp]['entity_columns_'.$entity_id.'_'.$cat_id];
-//html_print_r($user_columns);
-
-                               if (isset($user_columns) AND 
is_array($user_columns) AND $user_columns[0])
-                               {
-                                       $i      = count($uicols['name']);
-                                       foreach($user_columns as $column_id)
-                                       {
-                                               $dbresult = 
$GLOBALS['phpgw']->db->Execute("SELECT * FROM fm_entity_attribute WHERE 
entity_id= $entity_id AND cat_id= $cat_id AND id= $column_id");
-
-
-                                               $uicols['input_type'][]         
= 'text';
-                                               $uicols['name'][]               
        = $dbresult->fields['column_name'];
-                                               $uicols['descr'][]              
        = $dbresult->fields['input_text'];
-                                               $uicols['statustext'][]         
= $dbresult->fields['statustext'];
-                                               $uicols['datatype'][$i]         
= $dbresult->fields['datatype'];
-                                               $cols_return_extra[]= array(
-                                                       'name'  => 
$dbresult->fields['column_name'],
-                                                       'datatype'      => 
$dbresult->fields['datatype'],
-                                                       'attrib_id'     => 
$dbresult->fields['id']
-                                               );
-                                               $i++;
-                                       }
-                               }
-                       }
-                       else
-                       {
-                               return;
-                       }
-
-                       $this->uicols   = $uicols;
-
-//html_print_r($cols_return_extra);
-                       if ($order)
-                       {
-                               $ordermethod = " order by $entity_table.$order 
$sort";
-                       }
-                       else
-                       {
-                               $ordermethod = ' order by id DESC';
-                       }
-
-                       $where= 'WHERE';
-
-                       if ($filter=='all')
-                       {
-                               if (is_array($grants))
-                               {
-                                       while (list($user) = each($grants))
-                                       {
-                                               $public_user_list[] = $user;
-                                       }
-                                       reset($public_user_list);
-                                       $filtermethod .= " $where ( 
$entity_table.user_id IN(" . implode(',',$public_user_list) . "))";
-
-                                       $where= 'AND';
-                               }
-
-                       }
-                       else
-                       {
-                               $filtermethod = " $where 
$entity_table.user_id=$filter ";
-                               $where= 'AND';
-                       }
-
-
-                       if ($status)
-                       {
-                               $filtermethod .= " $where 
$entity_table.status='$status' ";
-                               $where= 'AND';
-                       }
-
-                       if ($district_id > 0)
-                       {
-                               $filtermethod .= " $where  
district_id='$district_id' ";
-                               $where = 'AND';
-                       }
-
-                       if ($start_date)
-                       {
-                               $filtermethod .= " $where 
$entity_table.entry_date >= $start_date AND $entity_table.entry_date <= 
$end_date ";
-                               $where= 'AND';
-                       }
-
-                       if($query)
-                       {
-                               $query = ereg_replace("'",'',$query);
-                               $query = ereg_replace('"','',$query);
-
-                               $querymethod = " $where ( 
$entity_table.location_code LIKE '%$query%' OR $entity_table.num LIKE 
'%$query%'  OR loc1_name LIKE '%$query%' OR address LIKE '%$query%')";
-                               $where = 'AND';
-                       }
-
-                       $sql .= " $filtermethod $querymethod";
-
-//echo $sql;
-
-                       $dbresult2 = $GLOBALS['phpgw']->db->Execute($sql);
-                       $this->total_records = $dbresult2->_numOfRows;
-                       $maxmatchs = 15;
-
-                       if(!$allrows)
-                       {
-                               $dbresult = 
$GLOBALS['phpgw']->db->SelectLimit($sql . $ordermethod,$maxmatchs,$start);
-
-                       }
-                       else
-                       {
-                               $dbresult = $GLOBALS['phpgw']->db->Execute($sql 
. $ordermethod);
-                       }
-
-                       $j=0;
-                       $n=count($cols_return);
-//html_print_r($cols_return);
-                       while (!$dbresult->EOF)
-                       {
-                               for ($i=0;$i<$n;$i++)
-                               {
-                                       $entity_list[$j][$cols_return[$i]] = 
$dbresult->fields[$cols_return[$i]];
-                                       $entity_list[$j]['grants'] = 
(int)$grants[$dbresult->fields['user_id']];
-                                       if($lookup)
-                                       {
-                                               
$entity_list[$j]['entity_cat_name_' . $entity_id] = $category['name'];
-                                               $entity_list[$j]['entity_id_' . 
$entity_id] = $entity_id;
-                                               $entity_list[$j]['cat_id_' . 
$entity_id] = $cat_id;
-                                       }
-                               }
-
-                               for ($i=0;$i<count($cols_return_extra);$i++)
-                               {
-                                       $value='';
-                                       
$value=$dbresult->fields[$cols_return_extra[$i]['name']];
-
-                                       
if(($cols_return_extra[$i]['datatype']=='R' || 
$cols_return_extra[$i]['datatype']=='LB') && $value):
-                                       {
-                                               $sql="SELECT value FROM 
fm_entity_choice where entity_id=$entity_id AND cat_id=$cat_id AND attrib_id=" 
.$cols_return_extra[$i]['attrib_id']. "  AND id=" . $value;
-                                               $dbresult2 = 
$GLOBALS['phpgw']->db->Execute($sql);
-                                               
$entity_list[$j][$cols_return_extra[$i]['name']] = $dbresult2->fields['value'];
-                                       }
-                                       
elseif($cols_return_extra[$i]['datatype']=='AB' && $value):
-                                       {
-                                               $sql="SELECT org_name FROM 
phpgw_addressbook where id=$value";
-                                               $dbresult2 = 
$GLOBALS['phpgw']->db->Execute($sql);
-                                               
$entity_list[$j][$cols_return_extra[$i]['name']] = 
$dbresult2->fields['org_name'];
-                                       }
-                                       
elseif($cols_return_extra[$i]['datatype']=='CH' && $value):
-                                       {
-                                               $ch= unserialize($value);
-
-                                               if (isset($ch) AND 
is_array($ch))
-                                               {
-                                                       for 
($k=0;$k<count($ch);$k++)
-                                                       {
-                                                               $sql="SELECT 
value FROM fm_entity_choice where entity_id=$entity_id AND cat_id=$cat_id AND 
attrib_id=" .$cols_return_extra[$i]['attrib_id']. "  AND id=" . $ch[$k];
-                                                               $dbresult2 = 
$GLOBALS['phpgw']->db->Execute($sql);
-                                                               while 
(!$dbresult2->EOF)
-                                                               {
-                                                                       
$ch_value[]=$dbresult2->fields['value'];
-                                                                       
$dbresult2->MoveNext();
-                                                               }
-                                                       }
-                                                       
$entity_list[$j][$cols_return_extra[$i]['name']] = @implode(",", $ch_value);
-                                                       unset($ch_value);
-                                               }
-                                       }
-                                       
elseif($cols_return_extra[$i]['datatype']=='D' && $value):
-                                       {
-//html_print_r($value);
-
-                                               
$entity_list[$j][$cols_return_extra[$i]['name']]=date($GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'],strtotime($value));
-                                       }
-                                       else:
-                                       {
-                                               
$entity_list[$j][$cols_return_extra[$i]['name']]=$value;
-                                       }
-                                       endif;
-                               }
-
-                               $location_code= 
$dbresult->fields['location_code'];
-                               $location = split('-',$location_code);
-                               for ($m=0;$m<count($location);$m++)
-                               {
-                                       $entity_list[$j]['loc' . ($m+1)] = 
$location[$m];
-                                       
$entity_list[$j]['query_location']['loc' . ($m+1)]=implode("-", 
array_slice($location, 0, ($m+1)));
-                               }
-
-                               $j++;
-                               $dbresult->MoveNext();
-                       }
-//html_print_r($entity_list);
-                       return $entity_list;
-               }
-
-               function read_single($data)
-               {
-                       $entity_id =$data['entity_id'];
-                       $cat_id =$data['cat_id'];
-                       $id =$data['id'];
-
-                       $dbresult = $GLOBALS['phpgw']->db->Execute("SELECT * 
FROM fm_entity_attribute WHERE entity_id =$entity_id AND cat_id =$cat_id ORDER 
BY attrib_sort");
-
-                       while (!$dbresult->EOF)
-                       {
-                               $entity['attributes'][] = array
-                               (
-                                       'attrib_id'             => 
$dbresult->fields['id'],
-                                       'name'                  => 
$dbresult->fields['column_name'],
-                                       'input_text'    => 
stripslashes($dbresult->fields['input_text']),
-                                       'statustext'    => 
stripslashes($dbresult->fields['statustext']),
-//                                     'statustext'    => str_replace("\n"," 
",stripslashes($dbresult->fields['statustext'])),
-                                       'datatype'              => 
$dbresult->fields['datatype']
-                               );
-                               $dbresult->MoveNext();
-                       }
-//html_print_r($entity);
-
-                       if($id)
-                       {
-                               $table='fm_entity_' . $entity_id .'_' . $cat_id;
-
-                               $dbresult = 
$GLOBALS['phpgw']->db->Execute("SELECT * FROM $table WHERE id =$id");
-
-                               if(!$dbresult->EOF)
-                               {
-                                       $entity['id']                           
= $id;
-                                       $entity['num']                          
= $dbresult->fields['num'];
-                                       $entity['p_num']                        
= $dbresult->fields['p_num'];
-                                       $entity['p_entity_id']          = 
$dbresult->fields['p_entity_id'];
-                                       $entity['p_cat_id']                     
= $dbresult->fields['p_cat_id'];
-                                       $entity['location_code']        = 
$dbresult->fields['location_code'];
-                                       $entity['tenant_id']            = 
$dbresult->fields['tenant_id'];
-                                       $entity['contact_phone']        = 
$dbresult->fields['contact_phone'];
-                                       $entity['status']                       
= $dbresult->fields['status'];
-
-                                       for 
($i=0;$i<count($entity['attributes']);$i++)
-                                       {
-                                               
$entity['attributes'][$i]['value']      = 
$dbresult->fields[$entity['attributes'][$i]['name']];
-                                               
$entity['attributes'][$i]['datatype_text']      = 
$this->bocommon->translate_datatype($entity['attributes'][$i]['datatype']);
-                                       }
-                               }
-
-                               $sql = "SELECT * FROM fm_entity_origin WHERE 
entity_id = $entity_id AND cat_id = $cat_id AND id =$id";
-
-                               $dbresult = 
$GLOBALS['phpgw']->db->Execute($sql);
-                               $i=0;
-                               while (!$dbresult->EOF)
-                               {
-                                       $entity['origin'][$i]['id']             
= $dbresult->fields['origin_id'];
-                                       $entity['origin'][$i]['type']   = 
$dbresult->fields['origin'];
-                                       $i++;
-                                       $dbresult->MoveNext();
-                               }
-                       }
-
-                       return  $entity;
-               }
-
-
-               function check_entity($entity_id,$cat_id,$num)
-               {
-                       $table='fm_entity_' . $entity_id .'_' . $cat_id;
-                       $dbresult = $GLOBALS['phpgw']->db->Execute("SELECT 
count(*) FROM $table where num='$num'");
-
-
-
-                       if ( $dbresult->fields[0])
-                       {
-                               return True;
-                       }
-               }
-
-               function generate_id($data)
-               {
-                       $table='fm_entity_' . $data['entity_id'] .'_' . 
$data['cat_id'];
-                       $dbresult = $GLOBALS['phpgw']->db->Execute("select 
max(id) as id from $table");
-
-                       $id = $dbresult->fields['id']+1;
-
-                       return $id;
-               }
-
-               function generate_num($entity_id,$cat_id,$id)
-               {
-                       $dbresult = $GLOBALS['phpgw']->db->Execute("select 
prefix from fm_entity_category WHERE entity_id=$entity_id AND id=$cat_id ");
-
-                       $prefix = $dbresult->fields['prefix'];
-
-                       if (strlen($id) == 4)
-                               $return = $id;
-                       if (strlen($id) == 3)
-                               $return = "0$id";
-                       if (strlen($id) == 2)
-                               $return = "00$id";
-                       if (strlen($id) == 1)
-                               $return = "000$id";
-                       if (strlen($id) == 0)
-                               $return = "0001";
-
-                       return $prefix . strtoupper($return);
-               }
-
-
-               function add($values,$values_attribute,$entity_id,$cat_id)
-               {
-                       if($values['street_name'])
-                       {
-                               $address[]= $values['street_name'];
-                               $address[]= $values['street_number'];
-                               $address        = implode(" ", $address);
-                       }
-
-                       if(!$address)
-                       {
-                               $address = $values['location_name'];
-                       }
-
-                       $values['descr'] = 
$this->db->db_addslashes($values['descr']);
-
-                       while (is_array($values['location']) && 
list($input_name,$value) = each($values['location']))
-                       {
-                               if($value)
-                               {
-                                       $cols[] = $input_name;
-                                       $vals[] = $value;
-                               }
-                       }
-//html_print_r($values);
-                       while (is_array($values['extra']) && 
list($input_name,$value) = each($values['extra']))
-                       {
-                               if($value)
-                               {
-                                       $cols[] = $input_name;
-                                       $vals[] = $value;
-                               }
-                       }
-
-                       if (isset($values_attribute) AND 
is_array($values_attribute))
-                       {
-                               foreach($values_attribute as $entry)
-                               {
-                                       if($entry['value'])
-                                       {
-                                               $cols[] = $entry['name'];
-                                               $vals[] = $entry['value'];
-                                       }
-                               }
-                       }
-
-                       if($cols)
-                       {
-                               $cols   = "," . implode(",", $cols);
-                               $vals   = "," . 
$this->bocommon->validate_db_insert($vals);
-                       }
-
-                       $table='fm_entity_' . $entity_id .'_' . $cat_id;
-                       
$num=$this->generate_num($entity_id,$cat_id,$values['id']);
-                       $GLOBALS['phpgw']->db->begintrans();
-
-                       $GLOBALS['phpgw']->db->Execute("INSERT INTO $table 
(id,num,address,location_code,entry_date,user_id $cols) "
-                               . "VALUES ("
-                               . $values['id']. ",'"
-                               . $num . "','"
-                               . $address. "','"
-                               . $values['location_code']. "',"
-                               . time() . ","
-                               . $this->account. " $vals)");
-
-                       if($values['origin_type'] && $values['origin_id'])
-                       {
-                               $GLOBALS['phpgw']->db->Execute("INSERT INTO 
fm_entity_origin (origin,origin_id,entity_id,cat_id,id,entry_date) "
-                                       . "VALUES ('"
-                                       . $values['origin_type']. "',"
-                                       . $values['origin_id']. ","
-                                       . $entity_id. ","
-                                       . $cat_id. ","
-                                       . $values['id']. ","
-                                       . time() . ")");
-                       }
-
-                       $GLOBALS['phpgw']->db->committrans();
-
-                       $receipt['message'][] = array('msg'=>lang('Entity %1 
has been saved',$values['id']));
-                       return $receipt;
-               }
-
-               function edit($values,$values_attribute,$entity_id,$cat_id)
-               {
-
-//html_print_r($values);
-                       if($values['street_name'])
-                       {
-                               $address[]= $values['street_name'];
-                               $address[]= $values['street_number'];
-                               $address        = implode(" ", $address);
-                       }
-
-                       if(!$address)
-                       {
-                               $address = $values['location_name'];
-                       }
-
-                       $values['descr'] = 
$this->db->db_addslashes($values['descr']);
-
-                       $value_set=array(
-                               'location_code' => $values['location_code'],
-                               'address'               => $address
-                               );
-
-                       while (is_array($values['location']) && 
list($column,$value) = each($values['location']))
-                       {
-                               $value_set[$column]     = $value;
-                       }
-
-                       while (is_array($values['extra']) && 
list($column,$value) = each($values['extra']))
-                       {
-                               $value_set[$column]     = $value;
-                       }
-
-
-                       if (isset($values_attribute) AND 
is_array($values_attribute))
-                       {
-                               foreach($values_attribute as $entry)
-                               {
-                                       if($entry['datatype']!='AB')
-                                       {
-                                               $value_set[$entry['name']]      
= $entry['value'];
-                                       }
-                               }
-                       }
-
-                       $value_set      = 
$this->bocommon->validate_db_update($value_set);
-
-                       $table='fm_entity_' . $entity_id .'_' . $cat_id;
-
-                       $GLOBALS['phpgw']->db->begintrans();
-
-                       $GLOBALS['phpgw']->db->Execute("UPDATE $table set 
$value_set WHERE id=" . $values['id']);
-
-                       $GLOBALS['phpgw']->db->committrans();
-
-                       $receipt['message'][] = array('msg'=>lang('entity %1 
has been edited',$values['num']));
-                       return $receipt;
-               }
-
-               function delete($entity_id,$cat_id,$id )
-               {
-                       $table='fm_entity_' . $entity_id .'_' . $cat_id;
-                       $GLOBALS['phpgw']->db->begintrans();
-                       $GLOBALS['phpgw']->db->Execute("DELETE FROM $table 
WHERE id=$id");
-                       $GLOBALS['phpgw']->db->Execute("DELETE FROM 
fm_entity_origin WHERE entity_id=$entity_id AND cat_id=$cat_id AND id=$id");
-                       $GLOBALS['phpgw']->db->committrans();
-               }
-       }
-?>
+<?php
+       
/**************************************************************************\
+       * phpGroupWare - property                                               
   *
+       * http://www.phpgroupware.org                                           
   *
+       *                                                                       
   *
+       * Facilities Management                                                 
   *
+       * Written by Sigurd Nes [sigurdne at online.no]                         
   *
+       * 
------------------------------------------------------------------------ *
+       * Copyright 2000 - 2003 Free Software Foundation, Inc                   
   *
+       * This program is part of the GNU project, see http://www.gnu.org/      
   *
+       * 
------------------------------------------------------------------------ *
+       * This program is free software; you can redistribute it and/or modify 
it  *
+       * under the terms of the GNU General Public License as published by the 
   *
+       * Free Software Foundation; either version 2 of the License, or (at 
your   *
+       * option) any later version.                                            
   *
+       
\**************************************************************************/
+
+       class property_soentity
+       {
+               function property_soentity()
+               {
+                       $this->currentapp       = 'property'; 
//$GLOBALS['phpgw_info']['flags']['currentapp'];
+                       $this->db                       = $GLOBALS['phpgw']->db;
+                       $this->db2                      = $this->db;
+                       $this->account          = 
$GLOBALS['phpgw_data']['user']['id'];
+                       $this->bocommon         = 
CreateObject($this->currentapp.'_bocommon');
+                       $this->fm_session       = 
CreateObject($this->currentapp.'_session');
+
+                       $this->join                     = $this->bocommon->join;
+                       $this->left_join        = $this->bocommon->left_join;
+               }
+
+               function select_status_list($entity_id,$cat_id)
+               {
+                       if(!$entity_id || !$cat_id)
+                       {
+                               return;
+                       }
+
+                       $sql= "SELECT fm_entity_choice.id, 
fm_entity_choice.value FROM fm_entity_attribute $this->join fm_entity_choice ON 
"
+                       . " fm_entity_attribute.entity_id= 
fm_entity_choice.entity_id AND "
+                       . " fm_entity_attribute.cat_id= fm_entity_choice.cat_id 
AND "
+                       . " fm_entity_attribute.id= fm_entity_choice.attrib_id "
+                       . " WHERE fm_entity_attribute.column_name='status' "
+                       . " AND fm_entity_choice.entity_id=$entity_id "
+                       . " AND fm_entity_choice.cat_id=$cat_id ORDER BY 
fm_entity_choice.id";
+
+
+                       $dbresult = $GLOBALS['phpgw']->db->Execute($sql);
+
+                       $i = 0;
+                       while (!$dbresult->EOF)
+                       {
+                               $status[$i]['id']                               
= $dbresult->fields['id'];
+                               $status[$i]['name']                             
= stripslashes($dbresult->fields['value']);
+                               $i++;
+                               $dbresult->MoveNext();
+                       }
+                       return $status;
+               }
+
+
+               function read($data)
+               {
+                       if(is_array($data))
+                       {
+                               if ($data['start'])
+                               {
+                                       $start=$data['start'];
+                               }
+                               else
+                               {
+                                       $start=0;
+                               }
+                               $filter = $data['filter']?$data['filter']:'all';
+                               $query = 
(isset($data['query'])?$data['query']:'');
+                               $sort = 
(isset($data['sort'])?$data['sort']:'DESC');
+                               $order = 
(isset($data['order'])?$data['order']:'');
+                               $cat_id = 
(isset($data['cat_id'])?$data['cat_id']:0);
+                               $district_id = 
(isset($data['district_id'])?$data['district_id']:0);
+                               $lookup = 
(isset($data['lookup'])?$data['lookup']:'');
+                               $allrows = 
(isset($data['allrows'])?$data['allrows']:'');
+                               $entity_id = 
(isset($data['entity_id'])?$data['entity_id']:'');
+                               $cat_id = 
(isset($data['cat_id'])?$data['cat_id']:'');
+                               $status = 
(isset($data['status'])?$data['status']:'');
+                               $start_date = 
(isset($data['start_date'])?$data['start_date']:'');
+                               $end_date = 
(isset($data['end_date'])?$data['end_date']:'');
+                       }
+
+                       if(!$entity_id || !$cat_id)
+                       {
+                               return;
+                       }
+
+                       $grants         = 
$this->fm_session->appsession('grants_entity_'.$entity_id.'_'.$cat_id,$this->currentapp);
+
+                       if(!$grants)
+                       {
+                               $this->acl2             = 
CreateObject($this->currentapp.'_acl2','##DEFAULT##','##DEFAULT##');
+                               $grants         = 
$this->acl2->get_grants($this->currentapp,'.entity.' . $entity_id . '.' . 
$cat_id);
+                               
$this->fm_session->appsession('grants_entity_'.$entity_id.'_'.$cat_id,$this->currentapp,$grants);
+                       }
+
+
+                       $sql = $this->bocommon->fm_cache('sql_entity_' . 
$entity_id . '_' . $cat_id . '_' . $lookup);
+
+                       $entity_table = 'fm_entity_' . $entity_id . '_' . 
$cat_id;
+                       if(!$sql)
+                       {
+                               $cols = $entity_table . '.*';
+                               $cols_return[] = 'location_code';
+
+                               $cols_return[]                          = 'num';
+                               $uicols['input_type'][]         = 'text';
+                               $uicols['name'][]                       = 'num';
+                               $uicols['descr'][]                      = 
lang('ID');
+                               $uicols['statustext'][]         = lang('ID');
+
+                               $cols_return[]                          = 'id';
+                               $uicols['input_type'][]         = 'hidden';
+                               $uicols['name'][]                       = 'id';
+                               $uicols['descr'][]                      = false;
+                               $uicols['statustext'][]         = false;
+                               if($lookup)
+                               {
+                                       $cols .= ',num as entity_num_' . 
$entity_id;
+                                       $cols_return[] = 'entity_num_' . 
$entity_id;
+                               }
+
+
+                               $admin_entity   = 
CreateObject($this->currentapp.'_soadmin_entity');
+                               $category = 
$admin_entity->read_single_category($entity_id,$cat_id);
+
+                               $sql = 
$this->bocommon->generate_sql(array('entity_table'=>$entity_table,'cols_return'=>$cols_return,'cols'=>$cols,
+                                                               
'uicols'=>$uicols,'joinmethod'=>$joinmethod,'paranthesis'=>$paranthesis,'query'=>$query,'lookup'=>$lookup,'location_level'=>$category['location_level']));
+
+                               $this->bocommon->fm_cache('sql_entity_' . 
$entity_id . '_' . $cat_id . '_' . $lookup,$sql);
+                               $this->bocommon->fm_cache('uicols_entityt_' . 
$entity_id . '_' . $cat_id . '_' . $lookup,$this->bocommon->uicols);
+                               
$this->bocommon->fm_cache('cols_return_entityt_' . $entity_id . '_' . $cat_id . 
'_' . $lookup,$this->bocommon->cols_return);
+                               
$this->bocommon->fm_cache('cols_return_lookup_entityt_' . $entity_id . '_' . 
$cat_id . '_' . $lookup,$this->bocommon->cols_return_lookup);
+                               $this->bocommon->fm_cache('cols_extra_entityt_' 
. $entity_id . '_' . $cat_id . '_' . $lookup,$this->bocommon->cols_extra);
+
+                               $uicols                                         
= $this->bocommon->uicols;
+                               $cols_return                            = 
$this->bocommon->cols_return;
+                               $this->cols_return_lookup       = 
$this->bocommon->cols_return_lookup;
+                               $this->cols_extra                       = 
$this->bocommon->cols_extra;
+                       }
+                       else
+                       {
+                               $uicols                                         
        = $this->bocommon->fm_cache('uicols_entityt_' . $entity_id . '_' . 
$cat_id . '_' . $lookup);
+                               $cols_return                                    
= $this->bocommon->fm_cache('cols_return_entityt_' . $entity_id . '_' . $cat_id 
. '_' . $lookup);
+                               $this->cols_return_lookup               = 
$this->bocommon->fm_cache('cols_return_lookup_entityt_' . $entity_id . '_' . 
$cat_id . '_' . $lookup);
+                               $this->cols_extra                               
= $this->bocommon->fm_cache('cols_extra_entityt_' . $entity_id . '_' . $cat_id 
. '_' . $lookup);
+                               if($lookup)
+                               {
+                                       $admin_entity   = 
CreateObject($this->currentapp.'_soadmin_entity');
+                                       $category = 
$admin_entity->read_single_category($entity_id,$cat_id);
+                               }
+
+                       }
+
+                       if ($cat_id > 0)
+                       {
+                               
$user_columns=$GLOBALS['phpgw_info']['user']['preferences'][$this->currentapp]['entity_columns_'.$entity_id.'_'.$cat_id];
+//html_print_r($user_columns);
+
+                               if (isset($user_columns) AND 
is_array($user_columns) AND $user_columns[0])
+                               {
+                                       $i      = count($uicols['name']);
+                                       foreach($user_columns as $column_id)
+                                       {
+                                               $dbresult = 
$GLOBALS['phpgw']->db->Execute("SELECT * FROM fm_entity_attribute WHERE 
entity_id= $entity_id AND cat_id= $cat_id AND id= $column_id");
+
+
+                                               $uicols['input_type'][]         
= 'text';
+                                               $uicols['name'][]               
        = $dbresult->fields['column_name'];
+                                               $uicols['descr'][]              
        = $dbresult->fields['input_text'];
+                                               $uicols['statustext'][]         
= $dbresult->fields['statustext'];
+                                               $uicols['datatype'][$i]         
= $dbresult->fields['datatype'];
+                                               $cols_return_extra[]= array(
+                                                       'name'  => 
$dbresult->fields['column_name'],
+                                                       'datatype'      => 
$dbresult->fields['datatype'],
+                                                       'attrib_id'     => 
$dbresult->fields['id']
+                                               );
+                                               $i++;
+                                       }
+                               }
+                       }
+                       else
+                       {
+                               return;
+                       }
+
+                       $this->uicols   = $uicols;
+
+//html_print_r($cols_return_extra);
+                       if ($order)
+                       {
+                               $ordermethod = " order by $entity_table.$order 
$sort";
+                       }
+                       else
+                       {
+                               $ordermethod = ' order by id DESC';
+                       }
+
+                       $where= 'WHERE';
+
+                       if ($filter=='all')
+                       {
+                               if (is_array($grants))
+                               {
+                                       while (list($user) = each($grants))
+                                       {
+                                               $public_user_list[] = $user;
+                                       }
+                                       reset($public_user_list);
+                                       $filtermethod .= " $where ( 
$entity_table.user_id IN(" . implode(',',$public_user_list) . "))";
+
+                                       $where= 'AND';
+                               }
+
+                       }
+                       else
+                       {
+                               $filtermethod = " $where 
$entity_table.user_id=$filter ";
+                               $where= 'AND';
+                       }
+
+
+                       if ($status)
+                       {
+                               $filtermethod .= " $where 
$entity_table.status='$status' ";
+                               $where= 'AND';
+                       }
+
+                       if ($district_id > 0)
+                       {
+                               $filtermethod .= " $where  
district_id='$district_id' ";
+                               $where = 'AND';
+                       }
+
+                       if ($start_date)
+                       {
+                               $filtermethod .= " $where 
$entity_table.entry_date >= $start_date AND $entity_table.entry_date <= 
$end_date ";
+                               $where= 'AND';
+                       }
+
+                       if($query)
+                       {
+                               $query = ereg_replace("'",'',$query);
+                               $query = ereg_replace('"','',$query);
+
+                               $querymethod = " $where ( 
$entity_table.location_code LIKE '%$query%' OR $entity_table.num LIKE 
'%$query%'  OR loc1_name LIKE '%$query%' OR address LIKE '%$query%')";
+                               $where = 'AND';
+                       }
+
+                       $sql .= " $filtermethod $querymethod";
+
+//echo $sql;
+
+                       $dbresult2 = $GLOBALS['phpgw']->db->Execute($sql);
+                       $this->total_records = $dbresult2->_numOfRows;
+                       $maxmatchs = 15;
+
+                       if(!$allrows)
+                       {
+                               $dbresult = 
$GLOBALS['phpgw']->db->SelectLimit($sql . $ordermethod,$maxmatchs,$start);
+
+                       }
+                       else
+                       {
+                               $dbresult = $GLOBALS['phpgw']->db->Execute($sql 
. $ordermethod);
+                       }
+
+                       $j=0;
+                       $n=count($cols_return);
+//html_print_r($cols_return);
+                       while (!$dbresult->EOF)
+                       {
+                               for ($i=0;$i<$n;$i++)
+                               {
+                                       $entity_list[$j][$cols_return[$i]] = 
$dbresult->fields[$cols_return[$i]];
+                                       $entity_list[$j]['grants'] = 
(int)$grants[$dbresult->fields['user_id']];
+                                       if($lookup)
+                                       {
+                                               
$entity_list[$j]['entity_cat_name_' . $entity_id] = $category['name'];
+                                               $entity_list[$j]['entity_id_' . 
$entity_id] = $entity_id;
+                                               $entity_list[$j]['cat_id_' . 
$entity_id] = $cat_id;
+                                       }
+                               }
+
+                               for ($i=0;$i<count($cols_return_extra);$i++)
+                               {
+                                       $value='';
+                                       
$value=$dbresult->fields[$cols_return_extra[$i]['name']];
+
+                                       
if(($cols_return_extra[$i]['datatype']=='R' || 
$cols_return_extra[$i]['datatype']=='LB') && $value):
+                                       {
+                                               $sql="SELECT value FROM 
fm_entity_choice where entity_id=$entity_id AND cat_id=$cat_id AND attrib_id=" 
.$cols_return_extra[$i]['attrib_id']. "  AND id=" . $value;
+                                               $dbresult2 = 
$GLOBALS['phpgw']->db->Execute($sql);
+                                               
$entity_list[$j][$cols_return_extra[$i]['name']] = $dbresult2->fields['value'];
+                                       }
+                                       
elseif($cols_return_extra[$i]['datatype']=='AB' && $value):
+                                       {
+                                               $sql="SELECT org_name FROM 
phpgw_addressbook where id=$value";
+                                               $dbresult2 = 
$GLOBALS['phpgw']->db->Execute($sql);
+                                               
$entity_list[$j][$cols_return_extra[$i]['name']] = 
$dbresult2->fields['org_name'];
+                                       }
+                                       
elseif($cols_return_extra[$i]['datatype']=='CH' && $value):
+                                       {
+                                               $ch= unserialize($value);
+
+                                               if (isset($ch) AND 
is_array($ch))
+                                               {
+                                                       for 
($k=0;$k<count($ch);$k++)
+                                                       {
+                                                               $sql="SELECT 
value FROM fm_entity_choice where entity_id=$entity_id AND cat_id=$cat_id AND 
attrib_id=" .$cols_return_extra[$i]['attrib_id']. "  AND id=" . $ch[$k];
+                                                               $dbresult2 = 
$GLOBALS['phpgw']->db->Execute($sql);
+                                                               while 
(!$dbresult2->EOF)
+                                                               {
+                                                                       
$ch_value[]=$dbresult2->fields['value'];
+                                                                       
$dbresult2->MoveNext();
+                                                               }
+                                                       }
+                                                       
$entity_list[$j][$cols_return_extra[$i]['name']] = @implode(",", $ch_value);
+                                                       unset($ch_value);
+                                               }
+                                       }
+                                       
elseif($cols_return_extra[$i]['datatype']=='D' && $value):
+                                       {
+//html_print_r($value);
+
+                                               
$entity_list[$j][$cols_return_extra[$i]['name']]=date($GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'],strtotime($value));
+                                       }
+                                       else:
+                                       {
+                                               
$entity_list[$j][$cols_return_extra[$i]['name']]=$value;
+                                       }
+                                       endif;
+                               }
+
+                               $location_code= 
$dbresult->fields['location_code'];
+                               $location = split('-',$location_code);
+                               for ($m=0;$m<count($location);$m++)
+                               {
+                                       $entity_list[$j]['loc' . ($m+1)] = 
$location[$m];
+                                       
$entity_list[$j]['query_location']['loc' . ($m+1)]=implode("-", 
array_slice($location, 0, ($m+1)));
+                               }
+
+                               $j++;
+                               $dbresult->MoveNext();
+                       }
+//html_print_r($entity_list);
+                       return $entity_list;
+               }
+
+               function read_single($data)
+               {
+                       $entity_id =$data['entity_id'];
+                       $cat_id =$data['cat_id'];
+                       $id =$data['id'];
+
+                       $dbresult = $GLOBALS['phpgw']->db->Execute("SELECT * 
FROM fm_entity_attribute WHERE entity_id =$entity_id AND cat_id =$cat_id ORDER 
BY attrib_sort");
+
+                       while (!$dbresult->EOF)
+                       {
+                               $entity['attributes'][] = array
+                               (
+                                       'attrib_id'             => 
$dbresult->fields['id'],
+                                       'name'                  => 
$dbresult->fields['column_name'],
+                                       'input_text'    => 
stripslashes($dbresult->fields['input_text']),
+                                       'statustext'    => 
stripslashes($dbresult->fields['statustext']),
+//                                     'statustext'    => str_replace("\n"," 
",stripslashes($dbresult->fields['statustext'])),
+                                       'datatype'              => 
$dbresult->fields['datatype']
+                               );
+                               $dbresult->MoveNext();
+                       }
+//html_print_r($entity);
+
+                       if($id)
+                       {
+                               $table='fm_entity_' . $entity_id .'_' . $cat_id;
+
+                               $dbresult = 
$GLOBALS['phpgw']->db->Execute("SELECT * FROM $table WHERE id =$id");
+
+                               if(!$dbresult->EOF)
+                               {
+                                       $entity['id']                           
= $id;
+                                       $entity['num']                          
= $dbresult->fields['num'];
+                                       $entity['p_num']                        
= $dbresult->fields['p_num'];
+                                       $entity['p_entity_id']          = 
$dbresult->fields['p_entity_id'];
+                                       $entity['p_cat_id']                     
= $dbresult->fields['p_cat_id'];
+                                       $entity['location_code']        = 
$dbresult->fields['location_code'];
+                                       $entity['tenant_id']            = 
$dbresult->fields['tenant_id'];
+                                       $entity['contact_phone']        = 
$dbresult->fields['contact_phone'];
+                                       $entity['status']                       
= $dbresult->fields['status'];
+
+                                       for 
($i=0;$i<count($entity['attributes']);$i++)
+                                       {
+                                               
$entity['attributes'][$i]['value']      = 
$dbresult->fields[$entity['attributes'][$i]['name']];
+                                               
$entity['attributes'][$i]['datatype_text']      = 
$this->bocommon->translate_datatype($entity['attributes'][$i]['datatype']);
+                                       }
+                               }
+
+                               $sql = "SELECT * FROM fm_entity_origin WHERE 
entity_id = $entity_id AND cat_id = $cat_id AND id =$id";
+
+                               $dbresult = 
$GLOBALS['phpgw']->db->Execute($sql);
+                               $i=0;
+                               while (!$dbresult->EOF)
+                               {
+                                       $entity['origin'][$i]['id']             
= $dbresult->fields['origin_id'];
+                                       $entity['origin'][$i]['type']   = 
$dbresult->fields['origin'];
+                                       $i++;
+                                       $dbresult->MoveNext();
+                               }
+                       }
+
+                       return  $entity;
+               }
+
+
+               function check_entity($entity_id,$cat_id,$num)
+               {
+                       $table='fm_entity_' . $entity_id .'_' . $cat_id;
+                       $dbresult = $GLOBALS['phpgw']->db->Execute("SELECT 
count(*) FROM $table where num='$num'");
+
+
+
+                       if ( $dbresult->fields[0])
+                       {
+                               return True;
+                       }
+               }
+
+               function generate_id($data)
+               {
+                       $table='fm_entity_' . $data['entity_id'] .'_' . 
$data['cat_id'];
+                       $dbresult = $GLOBALS['phpgw']->db->Execute("select 
max(id) as id from $table");
+
+                       $id = $dbresult->fields['id']+1;
+
+                       return $id;
+               }
+
+               function generate_num($entity_id,$cat_id,$id)
+               {
+                       $dbresult = $GLOBALS['phpgw']->db->Execute("select 
prefix from fm_entity_category WHERE entity_id=$entity_id AND id=$cat_id ");
+
+                       $prefix = $dbresult->fields['prefix'];
+
+                       if (strlen($id) == 4)
+                               $return = $id;
+                       if (strlen($id) == 3)
+                               $return = "0$id";
+                       if (strlen($id) == 2)
+                               $return = "00$id";
+                       if (strlen($id) == 1)
+                               $return = "000$id";
+                       if (strlen($id) == 0)
+                               $return = "0001";
+
+                       return $prefix . strtoupper($return);
+               }
+
+
+               function add($values,$values_attribute,$entity_id,$cat_id)
+               {
+                       if($values['street_name'])
+                       {
+                               $address[]= $values['street_name'];
+                               $address[]= $values['street_number'];
+                               $address        = implode(" ", $address);
+                       }
+
+                       if(!$address)
+                       {
+                               $address = $values['location_name'];
+                       }
+
+                       $values['descr'] = 
$this->db->db_addslashes($values['descr']);
+
+                       while (is_array($values['location']) && 
list($input_name,$value) = each($values['location']))
+                       {
+                               if($value)
+                               {
+                                       $cols[] = $input_name;
+                                       $vals[] = $value;
+                               }
+                       }
+//html_print_r($values);
+                       while (is_array($values['extra']) && 
list($input_name,$value) = each($values['extra']))
+                       {
+                               if($value)
+                               {
+                                       $cols[] = $input_name;
+                                       $vals[] = $value;
+                               }
+                       }
+
+                       if (isset($values_attribute) AND 
is_array($values_attribute))
+                       {
+                               foreach($values_attribute as $entry)
+                               {
+                                       if($entry['value'])
+                                       {
+                                               $cols[] = $entry['name'];
+                                               $vals[] = $entry['value'];
+                                       }
+                               }
+                       }
+
+                       if($cols)
+                       {
+                               $cols   = "," . implode(",", $cols);
+                               $vals   = "," . 
$this->bocommon->validate_db_insert($vals);
+                       }
+
+                       $table='fm_entity_' . $entity_id .'_' . $cat_id;
+                       
$num=$this->generate_num($entity_id,$cat_id,$values['id']);
+                       $GLOBALS['phpgw']->db->begintrans();
+
+                       $GLOBALS['phpgw']->db->Execute("INSERT INTO $table 
(id,num,address,location_code,entry_date,user_id $cols) "
+                               . "VALUES ("
+                               . $values['id']. ",'"
+                               . $num . "','"
+                               . $address. "','"
+                               . $values['location_code']. "',"
+                               . time() . ","
+                               . $this->account. " $vals)");
+
+                       if($values['origin_type'] && $values['origin_id'])
+                       {
+                               $GLOBALS['phpgw']->db->Execute("INSERT INTO 
fm_entity_origin (origin,origin_id,entity_id,cat_id,id,entry_date) "
+                                       . "VALUES ('"
+                                       . $values['origin_type']. "',"
+                                       . $values['origin_id']. ","
+                                       . $entity_id. ","
+                                       . $cat_id. ","
+                                       . $values['id']. ","
+                                       . time() . ")");
+                       }
+
+                       $GLOBALS['phpgw']->db->committrans();
+
+                       $receipt['message'][] = array('msg'=>lang('Entity %1 
has been saved',$values['id']));
+                       return $receipt;
+               }
+
+               function edit($values,$values_attribute,$entity_id,$cat_id)
+               {
+
+//html_print_r($values);
+                       if($values['street_name'])
+                       {
+                               $address[]= $values['street_name'];
+                               $address[]= $values['street_number'];
+                               $address        = implode(" ", $address);
+                       }
+
+                       if(!$address)
+                       {
+                               $address = $values['location_name'];
+                       }
+
+                       $values['descr'] = 
$this->db->db_addslashes($values['descr']);
+
+                       $value_set=array(
+                               'location_code' => $values['location_code'],
+                               'address'               => $address
+                               );
+
+                       while (is_array($values['location']) && 
list($column,$value) = each($values['location']))
+                       {
+                               $value_set[$column]     = $value;
+                       }
+
+                       while (is_array($values['extra']) && 
list($column,$value) = each($values['extra']))
+                       {
+                               $value_set[$column]     = $value;
+                       }
+
+
+                       if (isset($values_attribute) AND 
is_array($values_attribute))
+                       {
+                               foreach($values_attribute as $entry)
+                               {
+                                       if($entry['datatype']!='AB')
+                                       {
+                                               $value_set[$entry['name']]      
= $entry['value'];
+                                       }
+                               }
+                       }
+
+                       $value_set      = 
$this->bocommon->validate_db_update($value_set);
+
+                       $table='fm_entity_' . $entity_id .'_' . $cat_id;
+
+                       $GLOBALS['phpgw']->db->begintrans();
+
+                       $GLOBALS['phpgw']->db->Execute("UPDATE $table set 
$value_set WHERE id=" . $values['id']);
+
+                       $GLOBALS['phpgw']->db->committrans();
+
+                       $receipt['message'][] = array('msg'=>lang('entity %1 
has been edited',$values['num']));
+                       return $receipt;
+               }
+
+               function delete($entity_id,$cat_id,$id )
+               {
+                       $table='fm_entity_' . $entity_id .'_' . $cat_id;
+                       $GLOBALS['phpgw']->db->begintrans();
+                       $GLOBALS['phpgw']->db->Execute("DELETE FROM $table 
WHERE id=$id");
+                       $GLOBALS['phpgw']->db->Execute("DELETE FROM 
fm_entity_origin WHERE entity_id=$entity_id AND cat_id=$cat_id AND id=$id");
+                       $GLOBALS['phpgw']->db->committrans();
+               }
+       }
+?>




reply via email to

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