phpgroupware-cvs
[Top][All Lists]
Advanced

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

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


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

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

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

Log Message:
no message
=====================================================================
Index: property/class.solocation.php
diff -u property/class.solocation.php:1.1.1.2 
property/class.solocation.php:1.1.1.3
--- property/class.solocation.php:1.1.1.2       Fri Apr 23 20:25:52 2004
+++ property/class.solocation.php       Fri Apr 23 21:26:33 2004
@@ -1,1015 +1,1015 @@
-<?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_solocation
-       {
-
-               function property_solocation()
-               {
-                       $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->soadmin_location         = 
CreateObject($this->currentapp.'_soadmin_location');
-                       $this->bocommon         = 
CreateObject($this->currentapp.'_bocommon');
-                       $this->socommon         = 
CreateObject($this->currentapp.'_socommon');
-                       $this->fm_session       = 
CreateObject($this->currentapp.'_session');
-
-                       $this->join                     = $this->socommon->join;
-                       $this->left_join        = $this->socommon->left_join;
-               }
-
-               function read_entity_to_link()
-               {
-                       $sql = "SELECT * FROM fm_entity_category where 
loc_link=1";
-
-                       $dbresult = $GLOBALS['phpgw']->db->Execute($sql);
-
-                       while (!$dbresult->EOF)
-                       {
-                               $entity[] = array
-                               (
-                                       'entity_id'     => 
$dbresult->fields['entity_id'],
-                                       'cat_id'        => 
$dbresult->fields['id'],
-                                       'name'          => 
$dbresult->fields['name'],
-                                       'descr'         => 
$dbresult->fields['descr']
-                               );
-                               $dbresult->MoveNext();
-                       }
-
-                       return $entity;
-               }
-
-               function select_status_list($type_id)
-               {
-                       if(!$type_id)
-                       {
-                               return;
-                       }
-
-                       $sql= "SELECT fm_location_choice.id, 
fm_location_choice.value FROM fm_location_attrib $this->join fm_location_choice 
ON "
-                       . " fm_location_attrib.type_id= 
fm_location_choice.type_id AND "
-                       . " fm_location_attrib.id= fm_location_choice.attrib_id 
"
-                       . " WHERE fm_location_attrib.column_name='status' "
-                       . " AND fm_location_choice.type_id=$type_id ORDER BY 
fm_location_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 get_tenant_status($type)
-               {
-                       $sql= "SELECT * from fm_tenant_status WHERE type 
='$type' ";
-                       $dbresult = $GLOBALS['phpgw']->db->Execute($sql);
-
-                       $i = 0;
-                       while (!$dbresult->EOF)
-                       {
-                               $status[$i]['id']                               
= $dbresult->fields['id'];
-                               $status[$i]['name']                             
= $dbresult->fields['id'] . ' [' . stripslashes($dbresult->fields['descr']) 
.']';
-                               $i++;
-                               $dbresult->MoveNext();
-                       }
-                       return $status;
-               }
-
-
-               function get_owner_type_list()
-               {
-                       $dbresult = $GLOBALS['phpgw']->db->Execute("SELECT 
id,descr FROM fm_owner_category  ORDER BY descr ");
-
-                       $i = 0;
-                       while (!$dbresult->EOF)
-                       {
-                               $owner_type[$i]['id']                   = 
$dbresult->fields['id'];
-                               $owner_type[$i]['name']         = 
stripslashes($dbresult->fields['descr']);
-                               $i++;
-                               $dbresult->MoveNext();
-                       }
-                       return $owner_type;
-               }
-
-               function get_owner_list()
-               {
-                       $dbresult = $GLOBALS['phpgw']->db->Execute("SELECT 
fm_owner.* ,fm_owner_category.descr as category FROM fm_owner $this->join 
fm_owner_category on fm_owner.category=fm_owner_category.id  ORDER BY descr ");
-
-                       $i = 0;
-                       while (!$dbresult->EOF)
-                       {
-                               $owners[$i]['id']                       = 
$dbresult->fields['owner_id'];
-                               $owners[$i]['name']             = 
stripslashes($dbresult->fields['org_name']) . ' ['. 
$dbresult->fields['category'] . ']';
-                               $i++;
-                               $dbresult->MoveNext();
-                       }
-                       return $owners;
-               }
-
-               function check_location($location_code='',$type_id='')
-               {
-                       $dbresult = $GLOBALS['phpgw']->db->Execute("SELECT 
count(*) FROM fm_location$type_id where location_code='$location_code'");
-
-                       if ( $dbresult->fields[0])
-                       {
-                               return True;
-                       }
-               }
-
-
-               function select_category_list($type_id='')
-               {
-                       if (!$type_id)
-                       {
-                               return;
-                       }
-
-                       $table= 'fm_location'. $type_id . '_category';
-                       $dbresult = $GLOBALS['phpgw']->db->Execute("SELECT id, 
descr FROM $table where id >'0' ORDER BY id asc ");
-
-                       $i = 0;
-                       while (!$dbresult->EOF)
-                       {
-                               $categories[$i]['id']                           
= $dbresult->fields['id'];
-                               $categories[$i]['name']                         
= stripslashes($dbresult->fields['descr']) . ' [' . $dbresult->fields['id'] . 
']';
-                               $i++;
-                               $dbresult->MoveNext();
-                       }
-                       return $categories;
-               }
-
-
-               function read($data)
-               {
-
-                       if(is_array($data))
-                       {
-                               if ($data['start'])
-                               {
-                                       $start=$data['start'];
-                               }
-                               else
-                               {
-                                       $start=0;
-                               }
-                               $filter = 
(isset($data['filter'])?$data['filter']:0);
-                               $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);
-                               $type_id = 
(isset($data['type_id'])?$data['type_id']:'');
-                               $lookup_tenant = 
(isset($data['lookup_tenant'])?$data['lookup_tenant']:'');
-                               $district_id = 
(isset($data['district_id'])?$data['district_id']:'');
-                               $allrows = 
(isset($data['allrows'])?$data['allrows']:'');
-                               $status_eco_id = 
(isset($data['status_eco_id'])?$data['status_eco_id']:'');
-                               $status_drift_id = 
(isset($data['status_drift_id'])?$data['status_drift_id']:'');
-                               $lookup = 
(isset($data['lookup'])?$data['lookup']:'');
-                               $status = 
(isset($data['status'])?$data['status']:'');
-
-                       }
-
-                       if (!$type_id)
-                       {
-                               return;
-                       }
-
-                       $sql = $this->socommon->fm_cache('sql_'. $type_id . '_' 
. $lookup_tenant . '_' . $lookup);
-
-                       if(!$sql)
-                       {
-                               $location_types = 
$this->soadmin_location->select_location_type();
-
-                               $cols = "fm_location" . ($type_id) 
.".location_code";
-                               $cols_return[] = 'location_code';
-                               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'];
-                                       $uicols['exchange'][]           = True;
-                                       $cols .= ",fm_location" . ($type_id) 
.".loc" . $location_types[$i]['id'];
-                                       $cols_return[] = 'loc' . 
$location_types[$i]['id'];
-                               }
-
-                               $fm_location_cols = 
$this->soadmin_location->read_attrib(array('type_id'=>$type_id,'lookup_type'=>$type_id));
-
-//html_print_r($fm_location_cols);
-                               $location_cols_count    = 
count($fm_location_cols);
-
-                               for ($i=0;$i<$location_cols_count;$i++)
-                               {
-                                       if($fm_location_cols[$i]['list']==1)
-                                       {
-                                               $cols .= ",fm_location" . 
$fm_location_cols[$i]['location_type'] 
.".".$fm_location_cols[$i]['column_name'];
-                                               $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'];
-
-                                               
if($fm_location_cols[$i]['lookup_form']==1)
-                                               {
-                                                       $uicols['exchange'][]   
        = True;
-                                               }
-                                               else
-                                               {
-                                                       $uicols['exchange'][]   
        = False;
-                                               }
-                                       }
-                               }
-
-                               $street_level = 
$this->soadmin_location->read_config_single('street_id');
-                               if ($street_level > $type_id)
-                               {
-                                       $cols.= ',fm_location1.loc1_name as 
loc1_name';
-                                       $cols_return[]                          
= 'loc1_name';
-                                       $uicols['input_type'][]         = 
'text';
-                                       $uicols['name'][]                       
= 'loc1_name';
-                                       $uicols['descr'][]                      
= lang('Property Name');
-                                       $uicols['statustext'][]         = 
lang('Property Name');
-                                       $uicols['exchange'][]           = True;
-
-                                       if($type_id>1)
-                                       {
-                                               $cols.= ',fm_location' . 
$type_id . '.loc' . $type_id . '_name';
-                                               $cols_return[]                  
        = 'loc' . $type_id . '_name';
-                                               $uicols['input_type'][]         
= 'text';
-                                               $uicols['name'][]               
        = 'loc' . $type_id . '_name';
-                                               $uicols['descr'][]              
        = lang('Name');
-                                               $uicols['statustext'][]         
= lang('Name');
-                                               $uicols['exchange'][]           
= True;
-                                       }
-                               }
-
-/*                             for ($i=2;$i<($type_id+1);$i++)
-                               {
-                                       $cols.= ',fm_location' . $i . '.loc' . 
$i . '_name';
-                                       $cols_return[]                          
= 'loc' . $i . '_name';
-                                       $uicols['input_type'][]         = 
'text';
-                                       $uicols['name'][]                       
= 'loc' . $i . '_name';
-                                       $uicols['descr'][]                      
= '';
-                                       $uicols['statustext'][]         = '';
-                               }
-
-*/
-
-                               for ($j=($type_id-1); $j>0; $j--)
-                               {
-                                       $joinmethod .= " $this->join 
fm_location". ($j);
-
-                                       $paranthesis .='(';
-
-                                       $on = 'ON';
-                                       for ($i=($j); $i>0; $i--)
-                                       {
-                                               $joinmethod .= " $on 
(fm_location" . ($j+1) .".loc" . ($i). " = fm_location" . ($j) . ".loc" . ($i) 
. ")";
-                                               $on = 'AND';
-                                               if($i==1)
-                                               {
-                                                       $joinmethod .= ")";
-                                               }
-                                       }
-                               }
-
-                               $config = 
$this->soadmin_location->read_config();
-
-//html_print_r($config);
-
-                               if($lookup_tenant)
-                               {
-                                       $cols.= ',fm_tenant.tenant_id';
-                                       $cols_return[]                          
= 'tenant_id';
-                                       $uicols['input_type'][]         = 
'hidden';
-                                       $uicols['name'][]                       
= 'tenant_id';
-                                       $uicols['descr'][]                      
= 'dummy';
-                                       $uicols['statustext'][]         = 
'dummy';
-                                       $uicols['exchange'][]           = True;
-
-                                       $cols.= ',fm_tenant.last_name';
-                                       $cols_return[]                          
= 'last_name';
-                                       $uicols['input_type'][]         = 
'text';
-                                       $uicols['name'][]                       
= 'last_name';
-                                       $uicols['descr'][]                      
= lang('last name');
-                                       $uicols['statustext'][]         = 
lang('last name');
-                                       $uicols['exchange'][]           = True;
-
-                                       $cols.= ',fm_tenant.first_name';
-                                       $cols_return[]                          
= 'first_name';
-                                       $uicols['input_type'][]         = 
'text';
-                                       $uicols['name'][]                       
= 'first_name';
-                                       $uicols['descr'][]                      
= lang('first name');
-                                       $uicols['statustext'][]         = 
lang('first name');
-                                       $uicols['exchange'][]           = True;
-
-                                       $cols.= ',fm_tenant.contact_phone';
-                                       $cols_return[]                          
= 'contact_phone';
-                                       $uicols['input_type'][]         = 
'text';
-                                       $uicols['name'][]                       
= 'contact_phone';
-                                       $uicols['descr'][]                      
= lang('contact phone');
-                                       $uicols['statustext'][]         = 
lang('contact phone');
-                                       $uicols['exchange'][]           = True;
-
-                                       if(!$lookup)
-                                       {
-                                               $cols.= ',fm_tenant.status_eco';
-                                               $cols_return[]                  
        = 'status_eco';
-                                               $uicols['input_type'][]         
= 'text';
-                                               $uicols['name'][]               
        = 'status_eco';
-                                               $uicols['descr'][]              
        = lang('status eco');
-                                               $uicols['statustext'][]         
= lang('status eco');
-                                               $uicols['exchange'][]           
= False;
-
-                                               $cols.= 
',fm_tenant.status_drift';
-                                               $cols_return[]                  
        = 'status_drift';
-                                               $uicols['input_type'][]         
= 'text';
-                                               $uicols['name'][]               
        = 'status_drift';
-                                               $uicols['descr'][]              
        = lang('status drift');
-                                               $uicols['statustext'][]         
= lang('status drift');
-                                               $uicols['exchange'][]           
= False;
-                                       }
-
-                                       $sub_query_tenant=1;
-                                       
$this->socommon->fm_cache('sub_query_tenant_'. $type_id  . '_' . $lookup_tenant 
. '_' . $lookup,$sub_query_tenant);
-                               }
-
-                               $config_count   = count($config);
-                               for ($i=0;$i<$config_count;$i++)
-                               {
-                                       if (($config[$i]['location_type'] <= 
$type_id) && ($config[$i]['f_key'] ==1))
-                                       {
-                                               if(!$lookup_tenant && 
$config[$i]['column_name']=='tenant_id')
-                                               {
-                                               }
-                                               else
-                                               {
-                                                       $joinmethod .= " 
$this->join  " . $config[$i]['reference_table'] . " ON ( fm_location" . 
$config[$i]['location_type'] . "." . $config[$i]['column_name'] . "=" . 
$config[$i]['reference_table'] . ".".$config[$i]['reference_id']."))";
-                                                       $paranthesis .='(';
-                                               }
-                                       }
-
-                                       if (($config[$i]['location_type'] <= 
$type_id)  && ($config[$i]['query_value'] ==1))
-                                       {
-
-                                               
if($config[$i]['column_name']=='street_id')
-                                               {
-
-                                                       $sub_query_street=1;
-                                                       
$this->socommon->fm_cache('sub_query_street_'. $type_id  . '_' . $lookup_tenant 
. '_' . $lookup,$sub_query_street);
-
-                                                       $cols.= 
',fm_streetaddress.descr as street_name';
-                                                       $cols_return[]          
                = 'street_name';
-                                                       $uicols['input_type'][] 
        = 'text';
-                                                       $uicols['name'][]       
                = 'street_name';
-                                                       $uicols['descr'][]      
                = lang('street name');
-                                                       $uicols['statustext'][] 
        = lang('street name');
-                                                       $uicols['exchange'][]   
        = True;
-
-                                                       $cols.= 
',street_number';
-                                                       $cols_return[]          
                = 'street_number';
-                                                       $uicols['input_type'][] 
        = 'text';
-                                                       $uicols['name'][]       
                = 'street_number';
-                                                       $uicols['descr'][]      
                = lang('street number');
-                                                       $uicols['statustext'][] 
        = lang('street number');
-                                                       $uicols['exchange'][]   
        = True;
-
-                                                       $cols.= ',fm_location' 
. $config[$i]['location_type'] . '.' . $config[$i]['column_name'];
-                                                       $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']);
-                                                       $uicols['exchange'][]   
        = True;
-                                               }
-                                               else
-                                               {
-                                                       $cols.= ',fm_location' 
. $config[$i]['location_type'] . '.' . $config[$i]['column_name'];
-                                                       $cols_return[]          
                = $config[$i]['column_name'];
-                                                       $uicols['input_type'][] 
        = 'hidden';
-                                                       $uicols['name'][]       
                = $config[$i]['column_name'];
-                                                       $uicols['descr'][]      
                = $config[$i]['input_text'];
-                                                       $uicols['statustext'][] 
        = $config[$i]['input_text'];
-                                                       $uicols['exchange'][]   
        = True;
-                                               }
-                                       }
-                               }
-
-                               $from .= " FROM $paranthesis 
fm_location$type_id ";
-
-                               $sql = "SELECT $cols $from $joinmethod";
-
-                               $this->socommon->fm_cache('sql_'. $type_id . 
'_' . $lookup_tenant . '_' . $lookup ,$sql);
-                               $this->socommon->fm_cache('uicols_'. $type_id  
. '_' . $lookup_tenant . '_' . $lookup,$uicols);
-                               $this->socommon->fm_cache('cols_return_'. 
$type_id  . '_' . $lookup_tenant . '_' . $lookup,$cols_return);
-
-                       }
-                       else
-                       {
-                               $uicols = $this->socommon->fm_cache('uicols_'. 
$type_id  . '_' . $lookup_tenant . '_' . $lookup);
-                               $cols_return = 
$this->socommon->fm_cache('cols_return_'. $type_id  . '_' . $lookup_tenant . 
'_' . $lookup);
-
-                               $sub_query_tenant       = 
$this->socommon->fm_cache('sub_query_tenant_'. $type_id  . '_' . $lookup_tenant 
. '_' . $lookup);
-                               $sub_query_street       = 
$this->socommon->fm_cache('sub_query_street_'. $type_id  . '_' . $lookup_tenant 
. '_' . $lookup);
-                       }
-
-                       $this->uicols = $uicols;
-
-                       $where= 'WHERE';
-
-                       if ($order)
-                       {
-                               $ordermethod = " order by $order $sort";
-                       }
-                       else
-                       {
-                               $ordermethod = ' order by fm_location' . 
($type_id) .'.location_code ASC';
-                       }
-
-                       if ($cat_id > 0)
-                       {
-                               $filtermethod .= " $where fm_location" . 
($type_id). ".category=$cat_id ";
-                               $where= 'AND';
-                       }
-                       else
-                       {
-//                             $filtermethod .= " $where  (fm_location" . 
($type_id). ".category !=99 OR fm_location" . ($type_id). ".category IS NULL)";
-                       }
-
-                       if ($filter > 0)
-                       {
-                               $filtermethod .= " $where 
fm_owner.category='$filter' ";
-                               $where= 'AND';
-                       }
-
-
-                       if ($status > 0)
-                       {
-                               $filtermethod .= " $where fm_location" . 
($type_id). ".status=$status ";
-                               $where= 'AND';
-                       }
-                       else
-                       {
-                               $filtermethod .= " $where fm_location" . 
($type_id). ".status IS NULL ";
-//                             $filtermethod .= " $where fm_location" . 
($type_id). ".status !=2 ";
-                               $where= 'AND';
-                       }
-
-
-                       if ($district_id > 0)
-                       {
-                               $filtermethod .= " $where 
fm_part_of_town.district_id='$district_id' ";
-                               $where= 'AND';
-                       }
-
-                       if($query)
-                       {
-                               if(stristr($query, '.'))
-                               {
-                                       $query=explode(".",$query);
-                                       $querymethod = " $where (fm_location" . 
($type_id).".loc1='" . $query[0] . "' AND fm_location" . $type_id .".loc" . 
($type_id)."='" . $query[1] . "')";
-                               }
-                               else
-                               {
-                                       $query = ereg_replace("'",'',$query);
-                                       $query = ereg_replace('"','',$query);
-
-                                       if($sub_query_tenant)
-                                       {
-                                               $sub_query = "OR 
fm_tenant.last_name LIKE '%$query%' OR fm_tenant.first_name LIKE '%$query%' OR 
fm_tenant.contact_phone LIKE '%$query%'";
-                                       }
-
-                                       if($sub_query_street)
-                                       {
-                                               $sub_query .= "OR 
fm_streetaddress.descr LIKE '%$query%'";
-                                       }
-
-                                       $querymethod = " $where (fm_location" . 
($type_id).".loc1 LIKE '%$query%' $sub_query OR fm_location" . 
($type_id).".location_code LIKE '%$query%' OR loc" . ($type_id)."_name LIKE 
'%$query%')";
-                               }
-                               $where= 'AND';
-                       }
-
-                       if ($status_eco_id > 0)
-                       {
-                               $filtermethod .= " $where 
(fm_tenant.status_eco=$status_eco_id ";
-                               $and='OR';
-                       }
-                       else
-                       {
-                               $and='AND (';
-                       }
-
-                       if ($status_drift_id > 0)
-                       {
-                               $filtermethod .= " $and 
fm_tenant.status_drift=$status_drift_id ) ";
-                       }
-                       else
-                       {
-                               if ($status_eco_id > 0)
-                               {
-                                       $filtermethod .= ')';
-                               }
-                       }
-
-
-                       $sql .= "$filtermethod $querymethod";
-
-                       $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;
-                       $cols_return_count      = count($cols_return);
-                       $location_count = $type_id-1;
-
-                       while (!$dbresult->EOF)
-                       {
-                               for ($i=0;$i<$cols_return_count;$i++)
-                               {
-                                       $location_list[$j][$cols_return[$i]] = 
$dbresult->fields[$cols_return[$i]];
-                               }
-
-                               $location_code= 
$dbresult->fields['location_code'];
-                               $location = split('-',$location_code);
-                               for ($m=0;$m<$location_count;$m++)
-                               {
-                                       $location_list[$j]['loc' . ($m+1)] = 
$location[$m];
-                                       
$location_list[$j]['query_location']['loc' . ($m+1)]=implode("-", 
array_slice($location, 0, ($m+1)));
-                               }
-
-                               $j++;
-                               $dbresult->MoveNext();
-                       }
-
-//print_r($location_list);
-//                     $this->total_records = 
_numofrows;//count($location_list);
-//                     echo $this->total_records;
-
-                       return $location_list;
-               }
-
-
-               function 
generate_sql($type_id='',$cols='',$cols_return='',$uicols='',$read_single='')
-               {
-
-                       $joinmethod .= " fm_location" . ($type_id);
-
-                       $location_types = 
$this->soadmin_location->select_location_type();
-
-                       $cols .= "fm_location" . ($type_id) .".location_code";
-                       $cols_return[] = 'location_code';
-                       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'];
-                               $cols .= ",fm_location" . ($type_id) .".loc" . 
$location_types[$i]['id'];
-                               $cols_return[] = 'loc' . 
$location_types[$i]['id'];
-                       }
-
-                       $fm_location_cols = 
$this->soadmin_location->read_attrib(array('type_id'=>$type_id,'lookup_type'=>$type_id,'allrows'=>True));
-//html_print_r($fm_location_cols);
-
-                       $location_cols_count    = count($fm_location_cols);
-
-                       for ($i=0;$i<$location_cols_count;$i++)
-                       {
-
-                               if($read_single)
-                               {
-                                       $cols .= ",fm_location" . 
$fm_location_cols[$i]['location_type'] 
.".".$fm_location_cols[$i]['column_name'];
-                                       $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'];
-
-                                       $cols .= ",fm_location" . ($type_id) 
.".category as cat_id";
-                                       $cols_return[]                          
= 'cat_id';
-
-                               }
-                               else
-                               {
-                                       if($fm_location_cols[$i]['list']==1)
-                                       {
-                                               $cols .= ",fm_location" . 
($type_id) .".".$fm_location_cols[$i]['column_name'];
-                                               $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'];
-                                       }
-                               }
-                       }
-
-                       if($type!=1)
-                       {
-//                             $cols.= ',fm_location1.loc1_name as loc1_name';
-//                             $cols_return[]                          = 
'loc1_name';
-                               $uicols['input_type'][]         = 'text';
-                               $uicols['name'][]                       = 
'loc1_name';
-                               $uicols['descr'][]                      = 
lang('Property Name');
-                               $uicols['statustext'][]         = 
lang('Property Name');
-                       }
-
-                       for ($j=($type_id-1); $j>0; $j--)
-                       {
-                               $joinmethod .= " $this->join fm_location". ($j);
-
-                               $paranthesis .='(';
-
-
-                               $on = 'ON';
-                               for ($i=($j); $i>0; $i--)
-                               {
-                                       $joinmethod .= " $on (fm_location" . 
($j+1) .".loc" . ($i). " = fm_location" . ($j) . ".loc" . ($i) . ")";
-                                       $on = 'AND';
-                                       if($i==1)
-                                       {
-                                               $joinmethod .= ")";
-                                       }
-                               }
-                       }
-
-                       $config = $this->soadmin_location->read_config('');
-
-                       $config_count   = count($config);
-                       for ($i=0;$i<$config_count;$i++)
-                       {
-                               if (($config[$i]['location_type'] <= $type_id) 
&& ($config[$i]['f_key'] ==1))
-                               {
-
-                                       
if($config[$i]['column_name']=='tenant_id')
-                                       {
-                                               $join=$this->left_join;
-                                       }
-                                       else
-                                       {
-                                               $join =$this->join;
-                                       }
-
-                                       $joinmethod .= " $join  " . 
$config[$i]['reference_table'] . " ON ( fm_location" . 
$config[$i]['location_type'] . "." . $config[$i]['column_name'] . "=" . 
$config[$i]['reference_table'] . ".".$config[$i]['reference_id']."))";
-
-                                       $paranthesis .='(';
-                               }
-
-                               if ($config[$i]['location_type'] <= $type_id)
-                               {
-
-                                       
if($config[$i]['column_name']=='street_id'):
-                                       {
-                                               $cols.= 
',fm_streetaddress.descr as street_name';
-                                               $cols_return[]                  
        = 'street_name';
-                                               $uicols['input_type'][]         
= 'text';
-                                               $uicols['name'][]               
        = 'street_name';
-                                               $uicols['descr'][]              
        = lang('street name');
-                                               $uicols['statustext'][]         
= lang('street name');
-
-                                               $cols.= ',street_number';
-                                               $cols_return[]                  
        = 'street_number';
-                                               $uicols['input_type'][]         
= 'text';
-                                               $uicols['name'][]               
        = 'street_number';
-                                               $uicols['descr'][]              
        = lang('street number');
-                                               $uicols['statustext'][]         
= lang('street number');
-
-                                               $cols.= ',fm_location' . 
$config[$i]['location_type'] . '.' . $config[$i]['column_name'];
-                                               $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']);
-
-                                       }
-                                       
elseif($config[$i]['column_name']=='tenant_id'):
-                                       {
-                                               $cols.= ',fm_tenant.tenant_id';
-                                               $cols_return[]                  
        = 'tenant_id';
-                                               $uicols['input_type'][]         
        = 'hidden';
-                                               $uicols['name'][]               
        = 'tenant_id';
-                                               $uicols['descr'][]              
        = 'dummy';
-                                               $uicols['statustext'][]         
= 'dummy';
-
-                                               $cols.= ',fm_tenant.last_name 
as last_name';
-                                               $cols_return[]                  
        = 'last_name';
-                                               $uicols['input_type'][]         
= 'text';
-                                               $uicols['name'][]               
        = 'last_name';
-                                               $uicols['descr'][]              
        = lang('last name');
-                                               $uicols['statustext'][]         
= lang('last name');
-
-                                               $cols.= ',fm_tenant.first_name 
as first_name';
-                                               $cols_return[]                  
        = 'first_name';
-                                               $uicols['input_type'][]         
= 'text';
-                                               $uicols['name'][]               
        = 'first_name';
-                                               $uicols['descr'][]              
        = lang('first name');
-                                               $uicols['statustext'][]         
= lang('first name');
-
-                                               $cols.= ',contact_phone';
-                                               $cols_return[]                  
        = 'contact_phone';
-                                               $uicols['input_type'][]         
= 'text';
-                                               $uicols['name'][]               
        = 'contact_phone';
-                                               $uicols['descr'][]              
        = lang('contact phone');
-                                               $uicols['statustext'][]         
= lang('contact phone');
-
-                                       }
-                                       else:
-                                       {
-                                               $cols.= ',fm_location' . 
$config[$i]['location_type'] . '.' . $config[$i]['column_name'];
-                                               $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'];
-                                       }
-                                       endif;
-                               }
-                       }
-
-                       $cols.= ',district_id';
-                       $cols_return[]  = 'district_id';
-
-                       $this->uicols           = $uicols;
-                       $this->cols_return      = $cols_return;
-
-                       $from .= " FROM $paranthesis $entity_table ";
-
-                       $sql = "SELECT $cols $from $joinmethod";
-
-                       $this->socommon->fm_cache('sql_single_'. $type_id,$sql);
-                       $this->socommon->fm_cache('uicols_single_'. 
$type_id,$uicols);
-                       $this->socommon->fm_cache('cols_return_single_'. 
$type_id,$cols_return);
-
-
-//                     $this->fm_session->appsession('sql_single_'. $type_id 
,$this->currentapp,$sql);
-//                     $this->fm_session->appsession('uicols_single_'. 
$type_id ,$this->currentapp,$uicols);
-//                     $this->fm_session->appsession('cols_return_single_'. 
$type_id ,$this->currentapp,$cols_return);
-
-                       return $sql;
-
-               }
-
-               function read_single($location_code='')
-               {
-                       $location_array = split('-',$location_code);
-                       $type_id= count($location_array);
-
-                       if (!$type_id)
-                       {
-                               return;
-                       }
-
-                       $cols.= 'fm_location' . $type_id .'.category as 
cat_id,';
-                       $cols_return[]                          = 'cat_id';
-
-                       for ($i=1;$i<($type_id+1);$i++)
-                       {
-                               $cols.= 'fm_location' . $i .'.loc' . $i 
.'_name,';
-                               $cols_return[]                          = 'loc' 
. $i .'_name';
-                       }
-
-
-//                     $cols.= 'loc' . $type_id .'_name';
-//                     $cols_return[]                          = 'loc' . 
$type_id .'_name';
-                       $uicols['input_type'][]         = 'text';
-                       $uicols['name'][]                       = 'loc' . 
$type_id .'_name';
-                       $uicols['descr'][]                      = lang('name');
-                       $uicols['statustext'][]         = lang('name');
-
-                       $cols.= 'fm_location' . $type_id .'.remark as remark,';
-                       $cols_return[]                          = 'remark';
-                       $uicols['input_type'][]         = 'text';
-                       $uicols['name'][]                       = 'descr';
-                       $uicols['descr'][]                      = 
lang('remark');
-                       $uicols['statustext'][]         = lang('remark');
-
-                       $sql = $this->socommon->fm_cache('sql_single_'. 
$type_id);
-
-                       if(!$sql)
-                       {
-                               $sql    = 
$this->generate_sql($type_id,$cols,$cols_return,$uicols,True);
-                       }
-                       else
-                       {
-
-                               $this->uicols   =       
$this->socommon->fm_cache('uicols_single_'. $type_id);
-                               $this->cols_return      =       
$this->socommon->fm_cache('cols_return_single_'. $type_id);
-                       }
-
-                       $sql .= " WHERE 
fm_location$type_id.location_code='$location_code' ";
-
-                       $dbresult = $GLOBALS['phpgw']->db->Execute($sql);
-
-//echo $sql;
-                       $cols_return    = $this->cols_return;
-
-                       $cols_return_count      = count($cols_return);
-
-                       for ($i=0;$i<$cols_return_count;$i++)
-                       {
-                               $location[$cols_return[$i]] = 
$dbresult->fields[$cols_return[$i]];
-                       }
-
-//html_print_r($cols_return);
-//html_print_r($location);
-                       return $location;
-               }
-
-               function add($location='',$values_attribute='',$type_id='')
-               {
-                       $location['remark'] = 
$this->db->db_addslashes($location['remark']);
-
-                       while (is_array($location) && list($input_name,$value) 
= each($location))
-                       {
-                               if($value)
-                               {
-                                       if($input_name=='cat_id')
-                                       {
-                                               $input_name='category';
-                                       }
-                                       $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'];
-                                       }
-                               }
-                       }
-
-                       $cols   =implode(",", $cols) . ",entry_date,user_id";
-                       $vals   ="'" . implode("','", $vals) . "'," . "'" . 
time() . "','" . $this->account . "'";
-
-
-                       $sql    = "INSERT INTO fm_location$type_id ($cols) 
VALUES ($vals)";
-
-//echo $sql;
-                       $dbresult = $GLOBALS['phpgw']->db->Execute($sql);
-
-                       $receipt['message'][] = array('msg'=>lang('Location %1 
has been saved',$location['location_code']));
-                       return $receipt;
-               }
-
-               function edit($location='',$values_attribute='',$type_id='')
-               {
-//html_print_r($values_attribute);
-                       $location['remark'] = 
$this->db->db_addslashes($location['remark']);
-
-                       while (is_array($location) && list($input_name,$value) 
= each($location))
-                       {
-                               if($value)
-                               {
-                                       if($input_name=='cat_id')
-                                       {
-                                               $input_name='category';
-                                       }
-                                       $value_set[$input_name] = $value;
-                               }
-                       }
-
-                       if (isset($values_attribute) AND 
is_array($values_attribute))
-                       {
-                               foreach($values_attribute as $entry)
-                               {
-                                       $value_set[$entry['name']]      = 
$entry['value'];
-                               }
-                       }
-
-                       $value_set      = 
$this->bocommon->validate_db_update($value_set);
-
-                       $sql    = "UPDATE fm_location$type_id SET $value_set 
WHERE location_code='" . $location['location_code'] . "'";
-
-                       $dbresult = $GLOBALS['phpgw']->db->Execute($sql);
-
-//echo $sql;
-
-                       $receipt['message'][] = array('msg'=>lang('Location %1 
has been edited',$location['location_code']));
-                       return $receipt;
-               }
-
-               function delete($location_code )
-               {
-                       $location_array = split('-',$location_code);
-                       $type_id= count($location_array);
-
-                       $GLOBALS['phpgw']->db->Execute("DELETE FROM 
fm_location$type_id WHERE location_code='" . $location_code ."'");
-                       $GLOBALS['phpgw']->db->Execute("DELETE FROM fm_location 
WHERE location_code='" . $location_code ."'");
-               }
-
-               function update_cat()
-               {
-                       $location_types = 
$this->soadmin_location->select_location_type();
-
-                       $m= count($location_types);
-
-                       $GLOBALS['phpgw']->db->begintrans();
-
-                       $GLOBALS['phpgw']->db->Execute("UPDATE fm_location" . 
$m. " set status= 2  WHERE category=99");
-
-                       for ($type_id=$m; $type_id>1; $type_id--)
-                       {
-                               $parent_table = 'fm_location' . ($type_id-1);
-
-                               $joinmethod .= " $this->join $parent_table";
-
-                               $paranthesis .='(';
-
-                               $on = 'ON';
-                               for ($i=($type_id-1); $i>0; $i--)
-                               {
-                                       $joinmethod .= " $on (fm_location" . 
($type_id) .".loc" . ($i). ' = '.$parent_table . ".loc" . ($i) . ")";
-                                       $on = 'AND';
-                                       if($i==1)
-                                       {
-                                               $joinmethod .= ")";
-                                       }
-                               }
-
-                               $sql = "SELECT $parent_table.location_code 
,count(*) as count_99  FROM $paranthesis fm_location$type_id $joinmethod where 
fm_location$type_id.status=2 group by $parent_table.location_code ";
-                               $dbresult = 
$GLOBALS['phpgw']->db->Execute($sql);
-
-                               while (!$dbresult->EOF)
-                               {
-                                       
$outdated[$dbresult->fields['location_code']]['count_99']=$dbresult->fields['count_99'];
-                                       $dbresult->MoveNext();
-                               }
-
-                               $sql = "SELECT $parent_table.location_code 
,count(*) as count_all  FROM $paranthesis fm_location$type_id $joinmethod group 
by $parent_table.location_code ";
-                               $dbresult = 
$GLOBALS['phpgw']->db->Execute($sql);
-                               while (!$dbresult->EOF)
-                               {
-                                       if( 
$outdated[$dbresult->fields['location_code']]['count_99']==$dbresult->fields['count_all'])
-                                       {
-                                               $update[]=array('location_code' 
=> $dbresult->fields['location_code']);
-                                       }
-                                       $dbresult->MoveNext();
-                               }
-
-                               $j=0;
-                               for ($i=0; $i<count($update); $i++)
-                               {
-
-                                       $sql = "SELECT status  FROM 
$parent_table WHERE location_code= '" . $update[$i]['location_code'] ."'";
-
-                                       $dbresult = 
$GLOBALS['phpgw']->db->Execute($sql);
-
-                                       if($dbresult->fields['status']!=2)
-                                       {
-                                               $j++;
-                                               
$GLOBALS['phpgw']->db->Execute("UPDATE fm_location" . ($type_id-1). " set       
status= 2  WHERE location_code= '" . $update[$i]['location_code'] ."'");
-                                       }
-                               }
-
-                               $receipt['message'][]=array('msg'=>lang('%1 
location %2 has been updated to not active of %3 already not 
active',$j,$location_types[($type_id-2)]['descr'],count($update)));
-
-                               unset($outdated);
-                               unset($update);
-                               unset($joinmethod);
-                               unset($paranthesis);
-                       }
-
-                       $GLOBALS['phpgw']->db->committrans();
-
-                       return $receipt;
-               }
-       }
-?>
+<?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_solocation
+       {
+
+               function property_solocation()
+               {
+                       $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->soadmin_location         = 
CreateObject($this->currentapp.'_soadmin_location');
+                       $this->bocommon         = 
CreateObject($this->currentapp.'_bocommon');
+                       $this->socommon         = 
CreateObject($this->currentapp.'_socommon');
+                       $this->fm_session       = 
CreateObject($this->currentapp.'_session');
+
+                       $this->join                     = $this->socommon->join;
+                       $this->left_join        = $this->socommon->left_join;
+               }
+
+               function read_entity_to_link()
+               {
+                       $sql = "SELECT * FROM fm_entity_category where 
loc_link=1";
+
+                       $dbresult = $GLOBALS['phpgw']->db->Execute($sql);
+
+                       while (!$dbresult->EOF)
+                       {
+                               $entity[] = array
+                               (
+                                       'entity_id'     => 
$dbresult->fields['entity_id'],
+                                       'cat_id'        => 
$dbresult->fields['id'],
+                                       'name'          => 
$dbresult->fields['name'],
+                                       'descr'         => 
$dbresult->fields['descr']
+                               );
+                               $dbresult->MoveNext();
+                       }
+
+                       return $entity;
+               }
+
+               function select_status_list($type_id)
+               {
+                       if(!$type_id)
+                       {
+                               return;
+                       }
+
+                       $sql= "SELECT fm_location_choice.id, 
fm_location_choice.value FROM fm_location_attrib $this->join fm_location_choice 
ON "
+                       . " fm_location_attrib.type_id= 
fm_location_choice.type_id AND "
+                       . " fm_location_attrib.id= fm_location_choice.attrib_id 
"
+                       . " WHERE fm_location_attrib.column_name='status' "
+                       . " AND fm_location_choice.type_id=$type_id ORDER BY 
fm_location_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 get_tenant_status($type)
+               {
+                       $sql= "SELECT * from fm_tenant_status WHERE type 
='$type' ";
+                       $dbresult = $GLOBALS['phpgw']->db->Execute($sql);
+
+                       $i = 0;
+                       while (!$dbresult->EOF)
+                       {
+                               $status[$i]['id']                               
= $dbresult->fields['id'];
+                               $status[$i]['name']                             
= $dbresult->fields['id'] . ' [' . stripslashes($dbresult->fields['descr']) 
.']';
+                               $i++;
+                               $dbresult->MoveNext();
+                       }
+                       return $status;
+               }
+
+
+               function get_owner_type_list()
+               {
+                       $dbresult = $GLOBALS['phpgw']->db->Execute("SELECT 
id,descr FROM fm_owner_category  ORDER BY descr ");
+
+                       $i = 0;
+                       while (!$dbresult->EOF)
+                       {
+                               $owner_type[$i]['id']                   = 
$dbresult->fields['id'];
+                               $owner_type[$i]['name']         = 
stripslashes($dbresult->fields['descr']);
+                               $i++;
+                               $dbresult->MoveNext();
+                       }
+                       return $owner_type;
+               }
+
+               function get_owner_list()
+               {
+                       $dbresult = $GLOBALS['phpgw']->db->Execute("SELECT 
fm_owner.* ,fm_owner_category.descr as category FROM fm_owner $this->join 
fm_owner_category on fm_owner.category=fm_owner_category.id  ORDER BY descr ");
+
+                       $i = 0;
+                       while (!$dbresult->EOF)
+                       {
+                               $owners[$i]['id']                       = 
$dbresult->fields['owner_id'];
+                               $owners[$i]['name']             = 
stripslashes($dbresult->fields['org_name']) . ' ['. 
$dbresult->fields['category'] . ']';
+                               $i++;
+                               $dbresult->MoveNext();
+                       }
+                       return $owners;
+               }
+
+               function check_location($location_code='',$type_id='')
+               {
+                       $dbresult = $GLOBALS['phpgw']->db->Execute("SELECT 
count(*) FROM fm_location$type_id where location_code='$location_code'");
+
+                       if ( $dbresult->fields[0])
+                       {
+                               return True;
+                       }
+               }
+
+
+               function select_category_list($type_id='')
+               {
+                       if (!$type_id)
+                       {
+                               return;
+                       }
+
+                       $table= 'fm_location'. $type_id . '_category';
+                       $dbresult = $GLOBALS['phpgw']->db->Execute("SELECT id, 
descr FROM $table where id >'0' ORDER BY id asc ");
+
+                       $i = 0;
+                       while (!$dbresult->EOF)
+                       {
+                               $categories[$i]['id']                           
= $dbresult->fields['id'];
+                               $categories[$i]['name']                         
= stripslashes($dbresult->fields['descr']) . ' [' . $dbresult->fields['id'] . 
']';
+                               $i++;
+                               $dbresult->MoveNext();
+                       }
+                       return $categories;
+               }
+
+
+               function read($data)
+               {
+
+                       if(is_array($data))
+                       {
+                               if ($data['start'])
+                               {
+                                       $start=$data['start'];
+                               }
+                               else
+                               {
+                                       $start=0;
+                               }
+                               $filter = 
(isset($data['filter'])?$data['filter']:0);
+                               $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);
+                               $type_id = 
(isset($data['type_id'])?$data['type_id']:'');
+                               $lookup_tenant = 
(isset($data['lookup_tenant'])?$data['lookup_tenant']:'');
+                               $district_id = 
(isset($data['district_id'])?$data['district_id']:'');
+                               $allrows = 
(isset($data['allrows'])?$data['allrows']:'');
+                               $status_eco_id = 
(isset($data['status_eco_id'])?$data['status_eco_id']:'');
+                               $status_drift_id = 
(isset($data['status_drift_id'])?$data['status_drift_id']:'');
+                               $lookup = 
(isset($data['lookup'])?$data['lookup']:'');
+                               $status = 
(isset($data['status'])?$data['status']:'');
+
+                       }
+
+                       if (!$type_id)
+                       {
+                               return;
+                       }
+
+                       $sql = $this->socommon->fm_cache('sql_'. $type_id . '_' 
. $lookup_tenant . '_' . $lookup);
+
+                       if(!$sql)
+                       {
+                               $location_types = 
$this->soadmin_location->select_location_type();
+
+                               $cols = "fm_location" . ($type_id) 
.".location_code";
+                               $cols_return[] = 'location_code';
+                               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'];
+                                       $uicols['exchange'][]           = True;
+                                       $cols .= ",fm_location" . ($type_id) 
.".loc" . $location_types[$i]['id'];
+                                       $cols_return[] = 'loc' . 
$location_types[$i]['id'];
+                               }
+
+                               $fm_location_cols = 
$this->soadmin_location->read_attrib(array('type_id'=>$type_id,'lookup_type'=>$type_id));
+
+//html_print_r($fm_location_cols);
+                               $location_cols_count    = 
count($fm_location_cols);
+
+                               for ($i=0;$i<$location_cols_count;$i++)
+                               {
+                                       if($fm_location_cols[$i]['list']==1)
+                                       {
+                                               $cols .= ",fm_location" . 
$fm_location_cols[$i]['location_type'] 
.".".$fm_location_cols[$i]['column_name'];
+                                               $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'];
+
+                                               
if($fm_location_cols[$i]['lookup_form']==1)
+                                               {
+                                                       $uicols['exchange'][]   
        = True;
+                                               }
+                                               else
+                                               {
+                                                       $uicols['exchange'][]   
        = False;
+                                               }
+                                       }
+                               }
+
+                               $street_level = 
$this->soadmin_location->read_config_single('street_id');
+                               if ($street_level > $type_id)
+                               {
+                                       $cols.= ',fm_location1.loc1_name as 
loc1_name';
+                                       $cols_return[]                          
= 'loc1_name';
+                                       $uicols['input_type'][]         = 
'text';
+                                       $uicols['name'][]                       
= 'loc1_name';
+                                       $uicols['descr'][]                      
= lang('Property Name');
+                                       $uicols['statustext'][]         = 
lang('Property Name');
+                                       $uicols['exchange'][]           = True;
+
+                                       if($type_id>1)
+                                       {
+                                               $cols.= ',fm_location' . 
$type_id . '.loc' . $type_id . '_name';
+                                               $cols_return[]                  
        = 'loc' . $type_id . '_name';
+                                               $uicols['input_type'][]         
= 'text';
+                                               $uicols['name'][]               
        = 'loc' . $type_id . '_name';
+                                               $uicols['descr'][]              
        = lang('Name');
+                                               $uicols['statustext'][]         
= lang('Name');
+                                               $uicols['exchange'][]           
= True;
+                                       }
+                               }
+
+/*                             for ($i=2;$i<($type_id+1);$i++)
+                               {
+                                       $cols.= ',fm_location' . $i . '.loc' . 
$i . '_name';
+                                       $cols_return[]                          
= 'loc' . $i . '_name';
+                                       $uicols['input_type'][]         = 
'text';
+                                       $uicols['name'][]                       
= 'loc' . $i . '_name';
+                                       $uicols['descr'][]                      
= '';
+                                       $uicols['statustext'][]         = '';
+                               }
+
+*/
+
+                               for ($j=($type_id-1); $j>0; $j--)
+                               {
+                                       $joinmethod .= " $this->join 
fm_location". ($j);
+
+                                       $paranthesis .='(';
+
+                                       $on = 'ON';
+                                       for ($i=($j); $i>0; $i--)
+                                       {
+                                               $joinmethod .= " $on 
(fm_location" . ($j+1) .".loc" . ($i). " = fm_location" . ($j) . ".loc" . ($i) 
. ")";
+                                               $on = 'AND';
+                                               if($i==1)
+                                               {
+                                                       $joinmethod .= ")";
+                                               }
+                                       }
+                               }
+
+                               $config = 
$this->soadmin_location->read_config();
+
+//html_print_r($config);
+
+                               if($lookup_tenant)
+                               {
+                                       $cols.= ',fm_tenant.tenant_id';
+                                       $cols_return[]                          
= 'tenant_id';
+                                       $uicols['input_type'][]         = 
'hidden';
+                                       $uicols['name'][]                       
= 'tenant_id';
+                                       $uicols['descr'][]                      
= 'dummy';
+                                       $uicols['statustext'][]         = 
'dummy';
+                                       $uicols['exchange'][]           = True;
+
+                                       $cols.= ',fm_tenant.last_name';
+                                       $cols_return[]                          
= 'last_name';
+                                       $uicols['input_type'][]         = 
'text';
+                                       $uicols['name'][]                       
= 'last_name';
+                                       $uicols['descr'][]                      
= lang('last name');
+                                       $uicols['statustext'][]         = 
lang('last name');
+                                       $uicols['exchange'][]           = True;
+
+                                       $cols.= ',fm_tenant.first_name';
+                                       $cols_return[]                          
= 'first_name';
+                                       $uicols['input_type'][]         = 
'text';
+                                       $uicols['name'][]                       
= 'first_name';
+                                       $uicols['descr'][]                      
= lang('first name');
+                                       $uicols['statustext'][]         = 
lang('first name');
+                                       $uicols['exchange'][]           = True;
+
+                                       $cols.= ',fm_tenant.contact_phone';
+                                       $cols_return[]                          
= 'contact_phone';
+                                       $uicols['input_type'][]         = 
'text';
+                                       $uicols['name'][]                       
= 'contact_phone';
+                                       $uicols['descr'][]                      
= lang('contact phone');
+                                       $uicols['statustext'][]         = 
lang('contact phone');
+                                       $uicols['exchange'][]           = True;
+
+                                       if(!$lookup)
+                                       {
+                                               $cols.= ',fm_tenant.status_eco';
+                                               $cols_return[]                  
        = 'status_eco';
+                                               $uicols['input_type'][]         
= 'text';
+                                               $uicols['name'][]               
        = 'status_eco';
+                                               $uicols['descr'][]              
        = lang('status eco');
+                                               $uicols['statustext'][]         
= lang('status eco');
+                                               $uicols['exchange'][]           
= False;
+
+                                               $cols.= 
',fm_tenant.status_drift';
+                                               $cols_return[]                  
        = 'status_drift';
+                                               $uicols['input_type'][]         
= 'text';
+                                               $uicols['name'][]               
        = 'status_drift';
+                                               $uicols['descr'][]              
        = lang('status drift');
+                                               $uicols['statustext'][]         
= lang('status drift');
+                                               $uicols['exchange'][]           
= False;
+                                       }
+
+                                       $sub_query_tenant=1;
+                                       
$this->socommon->fm_cache('sub_query_tenant_'. $type_id  . '_' . $lookup_tenant 
. '_' . $lookup,$sub_query_tenant);
+                               }
+
+                               $config_count   = count($config);
+                               for ($i=0;$i<$config_count;$i++)
+                               {
+                                       if (($config[$i]['location_type'] <= 
$type_id) && ($config[$i]['f_key'] ==1))
+                                       {
+                                               if(!$lookup_tenant && 
$config[$i]['column_name']=='tenant_id')
+                                               {
+                                               }
+                                               else
+                                               {
+                                                       $joinmethod .= " 
$this->join  " . $config[$i]['reference_table'] . " ON ( fm_location" . 
$config[$i]['location_type'] . "." . $config[$i]['column_name'] . "=" . 
$config[$i]['reference_table'] . ".".$config[$i]['reference_id']."))";
+                                                       $paranthesis .='(';
+                                               }
+                                       }
+
+                                       if (($config[$i]['location_type'] <= 
$type_id)  && ($config[$i]['query_value'] ==1))
+                                       {
+
+                                               
if($config[$i]['column_name']=='street_id')
+                                               {
+
+                                                       $sub_query_street=1;
+                                                       
$this->socommon->fm_cache('sub_query_street_'. $type_id  . '_' . $lookup_tenant 
. '_' . $lookup,$sub_query_street);
+
+                                                       $cols.= 
',fm_streetaddress.descr as street_name';
+                                                       $cols_return[]          
                = 'street_name';
+                                                       $uicols['input_type'][] 
        = 'text';
+                                                       $uicols['name'][]       
                = 'street_name';
+                                                       $uicols['descr'][]      
                = lang('street name');
+                                                       $uicols['statustext'][] 
        = lang('street name');
+                                                       $uicols['exchange'][]   
        = True;
+
+                                                       $cols.= 
',street_number';
+                                                       $cols_return[]          
                = 'street_number';
+                                                       $uicols['input_type'][] 
        = 'text';
+                                                       $uicols['name'][]       
                = 'street_number';
+                                                       $uicols['descr'][]      
                = lang('street number');
+                                                       $uicols['statustext'][] 
        = lang('street number');
+                                                       $uicols['exchange'][]   
        = True;
+
+                                                       $cols.= ',fm_location' 
. $config[$i]['location_type'] . '.' . $config[$i]['column_name'];
+                                                       $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']);
+                                                       $uicols['exchange'][]   
        = True;
+                                               }
+                                               else
+                                               {
+                                                       $cols.= ',fm_location' 
. $config[$i]['location_type'] . '.' . $config[$i]['column_name'];
+                                                       $cols_return[]          
                = $config[$i]['column_name'];
+                                                       $uicols['input_type'][] 
        = 'hidden';
+                                                       $uicols['name'][]       
                = $config[$i]['column_name'];
+                                                       $uicols['descr'][]      
                = $config[$i]['input_text'];
+                                                       $uicols['statustext'][] 
        = $config[$i]['input_text'];
+                                                       $uicols['exchange'][]   
        = True;
+                                               }
+                                       }
+                               }
+
+                               $from .= " FROM $paranthesis 
fm_location$type_id ";
+
+                               $sql = "SELECT $cols $from $joinmethod";
+
+                               $this->socommon->fm_cache('sql_'. $type_id . 
'_' . $lookup_tenant . '_' . $lookup ,$sql);
+                               $this->socommon->fm_cache('uicols_'. $type_id  
. '_' . $lookup_tenant . '_' . $lookup,$uicols);
+                               $this->socommon->fm_cache('cols_return_'. 
$type_id  . '_' . $lookup_tenant . '_' . $lookup,$cols_return);
+
+                       }
+                       else
+                       {
+                               $uicols = $this->socommon->fm_cache('uicols_'. 
$type_id  . '_' . $lookup_tenant . '_' . $lookup);
+                               $cols_return = 
$this->socommon->fm_cache('cols_return_'. $type_id  . '_' . $lookup_tenant . 
'_' . $lookup);
+
+                               $sub_query_tenant       = 
$this->socommon->fm_cache('sub_query_tenant_'. $type_id  . '_' . $lookup_tenant 
. '_' . $lookup);
+                               $sub_query_street       = 
$this->socommon->fm_cache('sub_query_street_'. $type_id  . '_' . $lookup_tenant 
. '_' . $lookup);
+                       }
+
+                       $this->uicols = $uicols;
+
+                       $where= 'WHERE';
+
+                       if ($order)
+                       {
+                               $ordermethod = " order by $order $sort";
+                       }
+                       else
+                       {
+                               $ordermethod = ' order by fm_location' . 
($type_id) .'.location_code ASC';
+                       }
+
+                       if ($cat_id > 0)
+                       {
+                               $filtermethod .= " $where fm_location" . 
($type_id). ".category=$cat_id ";
+                               $where= 'AND';
+                       }
+                       else
+                       {
+//                             $filtermethod .= " $where  (fm_location" . 
($type_id). ".category !=99 OR fm_location" . ($type_id). ".category IS NULL)";
+                       }
+
+                       if ($filter > 0)
+                       {
+                               $filtermethod .= " $where 
fm_owner.category='$filter' ";
+                               $where= 'AND';
+                       }
+
+
+                       if ($status > 0)
+                       {
+                               $filtermethod .= " $where fm_location" . 
($type_id). ".status=$status ";
+                               $where= 'AND';
+                       }
+                       else
+                       {
+                               $filtermethod .= " $where fm_location" . 
($type_id). ".status IS NULL ";
+//                             $filtermethod .= " $where fm_location" . 
($type_id). ".status !=2 ";
+                               $where= 'AND';
+                       }
+
+
+                       if ($district_id > 0)
+                       {
+                               $filtermethod .= " $where 
fm_part_of_town.district_id='$district_id' ";
+                               $where= 'AND';
+                       }
+
+                       if($query)
+                       {
+                               if(stristr($query, '.'))
+                               {
+                                       $query=explode(".",$query);
+                                       $querymethod = " $where (fm_location" . 
($type_id).".loc1='" . $query[0] . "' AND fm_location" . $type_id .".loc" . 
($type_id)."='" . $query[1] . "')";
+                               }
+                               else
+                               {
+                                       $query = ereg_replace("'",'',$query);
+                                       $query = ereg_replace('"','',$query);
+
+                                       if($sub_query_tenant)
+                                       {
+                                               $sub_query = "OR 
fm_tenant.last_name LIKE '%$query%' OR fm_tenant.first_name LIKE '%$query%' OR 
fm_tenant.contact_phone LIKE '%$query%'";
+                                       }
+
+                                       if($sub_query_street)
+                                       {
+                                               $sub_query .= "OR 
fm_streetaddress.descr LIKE '%$query%'";
+                                       }
+
+                                       $querymethod = " $where (fm_location" . 
($type_id).".loc1 LIKE '%$query%' $sub_query OR fm_location" . 
($type_id).".location_code LIKE '%$query%' OR loc" . ($type_id)."_name LIKE 
'%$query%')";
+                               }
+                               $where= 'AND';
+                       }
+
+                       if ($status_eco_id > 0)
+                       {
+                               $filtermethod .= " $where 
(fm_tenant.status_eco=$status_eco_id ";
+                               $and='OR';
+                       }
+                       else
+                       {
+                               $and='AND (';
+                       }
+
+                       if ($status_drift_id > 0)
+                       {
+                               $filtermethod .= " $and 
fm_tenant.status_drift=$status_drift_id ) ";
+                       }
+                       else
+                       {
+                               if ($status_eco_id > 0)
+                               {
+                                       $filtermethod .= ')';
+                               }
+                       }
+
+
+                       $sql .= "$filtermethod $querymethod";
+
+                       $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;
+                       $cols_return_count      = count($cols_return);
+                       $location_count = $type_id-1;
+
+                       while (!$dbresult->EOF)
+                       {
+                               for ($i=0;$i<$cols_return_count;$i++)
+                               {
+                                       $location_list[$j][$cols_return[$i]] = 
$dbresult->fields[$cols_return[$i]];
+                               }
+
+                               $location_code= 
$dbresult->fields['location_code'];
+                               $location = split('-',$location_code);
+                               for ($m=0;$m<$location_count;$m++)
+                               {
+                                       $location_list[$j]['loc' . ($m+1)] = 
$location[$m];
+                                       
$location_list[$j]['query_location']['loc' . ($m+1)]=implode("-", 
array_slice($location, 0, ($m+1)));
+                               }
+
+                               $j++;
+                               $dbresult->MoveNext();
+                       }
+
+//print_r($location_list);
+//                     $this->total_records = 
_numofrows;//count($location_list);
+//                     echo $this->total_records;
+
+                       return $location_list;
+               }
+
+
+               function 
generate_sql($type_id='',$cols='',$cols_return='',$uicols='',$read_single='')
+               {
+
+                       $joinmethod .= " fm_location" . ($type_id);
+
+                       $location_types = 
$this->soadmin_location->select_location_type();
+
+                       $cols .= "fm_location" . ($type_id) .".location_code";
+                       $cols_return[] = 'location_code';
+                       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'];
+                               $cols .= ",fm_location" . ($type_id) .".loc" . 
$location_types[$i]['id'];
+                               $cols_return[] = 'loc' . 
$location_types[$i]['id'];
+                       }
+
+                       $fm_location_cols = 
$this->soadmin_location->read_attrib(array('type_id'=>$type_id,'lookup_type'=>$type_id,'allrows'=>True));
+//html_print_r($fm_location_cols);
+
+                       $location_cols_count    = count($fm_location_cols);
+
+                       for ($i=0;$i<$location_cols_count;$i++)
+                       {
+
+                               if($read_single)
+                               {
+                                       $cols .= ",fm_location" . 
$fm_location_cols[$i]['location_type'] 
.".".$fm_location_cols[$i]['column_name'];
+                                       $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'];
+
+                                       $cols .= ",fm_location" . ($type_id) 
.".category as cat_id";
+                                       $cols_return[]                          
= 'cat_id';
+
+                               }
+                               else
+                               {
+                                       if($fm_location_cols[$i]['list']==1)
+                                       {
+                                               $cols .= ",fm_location" . 
($type_id) .".".$fm_location_cols[$i]['column_name'];
+                                               $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'];
+                                       }
+                               }
+                       }
+
+                       if($type!=1)
+                       {
+//                             $cols.= ',fm_location1.loc1_name as loc1_name';
+//                             $cols_return[]                          = 
'loc1_name';
+                               $uicols['input_type'][]         = 'text';
+                               $uicols['name'][]                       = 
'loc1_name';
+                               $uicols['descr'][]                      = 
lang('Property Name');
+                               $uicols['statustext'][]         = 
lang('Property Name');
+                       }
+
+                       for ($j=($type_id-1); $j>0; $j--)
+                       {
+                               $joinmethod .= " $this->join fm_location". ($j);
+
+                               $paranthesis .='(';
+
+
+                               $on = 'ON';
+                               for ($i=($j); $i>0; $i--)
+                               {
+                                       $joinmethod .= " $on (fm_location" . 
($j+1) .".loc" . ($i). " = fm_location" . ($j) . ".loc" . ($i) . ")";
+                                       $on = 'AND';
+                                       if($i==1)
+                                       {
+                                               $joinmethod .= ")";
+                                       }
+                               }
+                       }
+
+                       $config = $this->soadmin_location->read_config('');
+
+                       $config_count   = count($config);
+                       for ($i=0;$i<$config_count;$i++)
+                       {
+                               if (($config[$i]['location_type'] <= $type_id) 
&& ($config[$i]['f_key'] ==1))
+                               {
+
+                                       
if($config[$i]['column_name']=='tenant_id')
+                                       {
+                                               $join=$this->left_join;
+                                       }
+                                       else
+                                       {
+                                               $join =$this->join;
+                                       }
+
+                                       $joinmethod .= " $join  " . 
$config[$i]['reference_table'] . " ON ( fm_location" . 
$config[$i]['location_type'] . "." . $config[$i]['column_name'] . "=" . 
$config[$i]['reference_table'] . ".".$config[$i]['reference_id']."))";
+
+                                       $paranthesis .='(';
+                               }
+
+                               if ($config[$i]['location_type'] <= $type_id)
+                               {
+
+                                       
if($config[$i]['column_name']=='street_id'):
+                                       {
+                                               $cols.= 
',fm_streetaddress.descr as street_name';
+                                               $cols_return[]                  
        = 'street_name';
+                                               $uicols['input_type'][]         
= 'text';
+                                               $uicols['name'][]               
        = 'street_name';
+                                               $uicols['descr'][]              
        = lang('street name');
+                                               $uicols['statustext'][]         
= lang('street name');
+
+                                               $cols.= ',street_number';
+                                               $cols_return[]                  
        = 'street_number';
+                                               $uicols['input_type'][]         
= 'text';
+                                               $uicols['name'][]               
        = 'street_number';
+                                               $uicols['descr'][]              
        = lang('street number');
+                                               $uicols['statustext'][]         
= lang('street number');
+
+                                               $cols.= ',fm_location' . 
$config[$i]['location_type'] . '.' . $config[$i]['column_name'];
+                                               $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']);
+
+                                       }
+                                       
elseif($config[$i]['column_name']=='tenant_id'):
+                                       {
+                                               $cols.= ',fm_tenant.tenant_id';
+                                               $cols_return[]                  
        = 'tenant_id';
+                                               $uicols['input_type'][]         
        = 'hidden';
+                                               $uicols['name'][]               
        = 'tenant_id';
+                                               $uicols['descr'][]              
        = 'dummy';
+                                               $uicols['statustext'][]         
= 'dummy';
+
+                                               $cols.= ',fm_tenant.last_name 
as last_name';
+                                               $cols_return[]                  
        = 'last_name';
+                                               $uicols['input_type'][]         
= 'text';
+                                               $uicols['name'][]               
        = 'last_name';
+                                               $uicols['descr'][]              
        = lang('last name');
+                                               $uicols['statustext'][]         
= lang('last name');
+
+                                               $cols.= ',fm_tenant.first_name 
as first_name';
+                                               $cols_return[]                  
        = 'first_name';
+                                               $uicols['input_type'][]         
= 'text';
+                                               $uicols['name'][]               
        = 'first_name';
+                                               $uicols['descr'][]              
        = lang('first name');
+                                               $uicols['statustext'][]         
= lang('first name');
+
+                                               $cols.= ',contact_phone';
+                                               $cols_return[]                  
        = 'contact_phone';
+                                               $uicols['input_type'][]         
= 'text';
+                                               $uicols['name'][]               
        = 'contact_phone';
+                                               $uicols['descr'][]              
        = lang('contact phone');
+                                               $uicols['statustext'][]         
= lang('contact phone');
+
+                                       }
+                                       else:
+                                       {
+                                               $cols.= ',fm_location' . 
$config[$i]['location_type'] . '.' . $config[$i]['column_name'];
+                                               $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'];
+                                       }
+                                       endif;
+                               }
+                       }
+
+                       $cols.= ',district_id';
+                       $cols_return[]  = 'district_id';
+
+                       $this->uicols           = $uicols;
+                       $this->cols_return      = $cols_return;
+
+                       $from .= " FROM $paranthesis $entity_table ";
+
+                       $sql = "SELECT $cols $from $joinmethod";
+
+                       $this->socommon->fm_cache('sql_single_'. $type_id,$sql);
+                       $this->socommon->fm_cache('uicols_single_'. 
$type_id,$uicols);
+                       $this->socommon->fm_cache('cols_return_single_'. 
$type_id,$cols_return);
+
+
+//                     $this->fm_session->appsession('sql_single_'. $type_id 
,$this->currentapp,$sql);
+//                     $this->fm_session->appsession('uicols_single_'. 
$type_id ,$this->currentapp,$uicols);
+//                     $this->fm_session->appsession('cols_return_single_'. 
$type_id ,$this->currentapp,$cols_return);
+
+                       return $sql;
+
+               }
+
+               function read_single($location_code='')
+               {
+                       $location_array = split('-',$location_code);
+                       $type_id= count($location_array);
+
+                       if (!$type_id)
+                       {
+                               return;
+                       }
+
+                       $cols.= 'fm_location' . $type_id .'.category as 
cat_id,';
+                       $cols_return[]                          = 'cat_id';
+
+                       for ($i=1;$i<($type_id+1);$i++)
+                       {
+                               $cols.= 'fm_location' . $i .'.loc' . $i 
.'_name,';
+                               $cols_return[]                          = 'loc' 
. $i .'_name';
+                       }
+
+
+//                     $cols.= 'loc' . $type_id .'_name';
+//                     $cols_return[]                          = 'loc' . 
$type_id .'_name';
+                       $uicols['input_type'][]         = 'text';
+                       $uicols['name'][]                       = 'loc' . 
$type_id .'_name';
+                       $uicols['descr'][]                      = lang('name');
+                       $uicols['statustext'][]         = lang('name');
+
+                       $cols.= 'fm_location' . $type_id .'.remark as remark,';
+                       $cols_return[]                          = 'remark';
+                       $uicols['input_type'][]         = 'text';
+                       $uicols['name'][]                       = 'descr';
+                       $uicols['descr'][]                      = 
lang('remark');
+                       $uicols['statustext'][]         = lang('remark');
+
+                       $sql = $this->socommon->fm_cache('sql_single_'. 
$type_id);
+
+                       if(!$sql)
+                       {
+                               $sql    = 
$this->generate_sql($type_id,$cols,$cols_return,$uicols,True);
+                       }
+                       else
+                       {
+
+                               $this->uicols   =       
$this->socommon->fm_cache('uicols_single_'. $type_id);
+                               $this->cols_return      =       
$this->socommon->fm_cache('cols_return_single_'. $type_id);
+                       }
+
+                       $sql .= " WHERE 
fm_location$type_id.location_code='$location_code' ";
+
+                       $dbresult = $GLOBALS['phpgw']->db->Execute($sql);
+
+//echo $sql;
+                       $cols_return    = $this->cols_return;
+
+                       $cols_return_count      = count($cols_return);
+
+                       for ($i=0;$i<$cols_return_count;$i++)
+                       {
+                               $location[$cols_return[$i]] = 
$dbresult->fields[$cols_return[$i]];
+                       }
+
+//html_print_r($cols_return);
+//html_print_r($location);
+                       return $location;
+               }
+
+               function add($location='',$values_attribute='',$type_id='')
+               {
+                       $location['remark'] = 
$this->db->db_addslashes($location['remark']);
+
+                       while (is_array($location) && list($input_name,$value) 
= each($location))
+                       {
+                               if($value)
+                               {
+                                       if($input_name=='cat_id')
+                                       {
+                                               $input_name='category';
+                                       }
+                                       $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'];
+                                       }
+                               }
+                       }
+
+                       $cols   =implode(",", $cols) . ",entry_date,user_id";
+                       $vals   ="'" . implode("','", $vals) . "'," . "'" . 
time() . "','" . $this->account . "'";
+
+
+                       $sql    = "INSERT INTO fm_location$type_id ($cols) 
VALUES ($vals)";
+
+//echo $sql;
+                       $dbresult = $GLOBALS['phpgw']->db->Execute($sql);
+
+                       $receipt['message'][] = array('msg'=>lang('Location %1 
has been saved',$location['location_code']));
+                       return $receipt;
+               }
+
+               function edit($location='',$values_attribute='',$type_id='')
+               {
+//html_print_r($values_attribute);
+                       $location['remark'] = 
$this->db->db_addslashes($location['remark']);
+
+                       while (is_array($location) && list($input_name,$value) 
= each($location))
+                       {
+                               if($value)
+                               {
+                                       if($input_name=='cat_id')
+                                       {
+                                               $input_name='category';
+                                       }
+                                       $value_set[$input_name] = $value;
+                               }
+                       }
+
+                       if (isset($values_attribute) AND 
is_array($values_attribute))
+                       {
+                               foreach($values_attribute as $entry)
+                               {
+                                       $value_set[$entry['name']]      = 
$entry['value'];
+                               }
+                       }
+
+                       $value_set      = 
$this->bocommon->validate_db_update($value_set);
+
+                       $sql    = "UPDATE fm_location$type_id SET $value_set 
WHERE location_code='" . $location['location_code'] . "'";
+
+                       $dbresult = $GLOBALS['phpgw']->db->Execute($sql);
+
+//echo $sql;
+
+                       $receipt['message'][] = array('msg'=>lang('Location %1 
has been edited',$location['location_code']));
+                       return $receipt;
+               }
+
+               function delete($location_code )
+               {
+                       $location_array = split('-',$location_code);
+                       $type_id= count($location_array);
+
+                       $GLOBALS['phpgw']->db->Execute("DELETE FROM 
fm_location$type_id WHERE location_code='" . $location_code ."'");
+                       $GLOBALS['phpgw']->db->Execute("DELETE FROM fm_location 
WHERE location_code='" . $location_code ."'");
+               }
+
+               function update_cat()
+               {
+                       $location_types = 
$this->soadmin_location->select_location_type();
+
+                       $m= count($location_types);
+
+                       $GLOBALS['phpgw']->db->begintrans();
+
+                       $GLOBALS['phpgw']->db->Execute("UPDATE fm_location" . 
$m. " set status= 2  WHERE category=99");
+
+                       for ($type_id=$m; $type_id>1; $type_id--)
+                       {
+                               $parent_table = 'fm_location' . ($type_id-1);
+
+                               $joinmethod .= " $this->join $parent_table";
+
+                               $paranthesis .='(';
+
+                               $on = 'ON';
+                               for ($i=($type_id-1); $i>0; $i--)
+                               {
+                                       $joinmethod .= " $on (fm_location" . 
($type_id) .".loc" . ($i). ' = '.$parent_table . ".loc" . ($i) . ")";
+                                       $on = 'AND';
+                                       if($i==1)
+                                       {
+                                               $joinmethod .= ")";
+                                       }
+                               }
+
+                               $sql = "SELECT $parent_table.location_code 
,count(*) as count_99  FROM $paranthesis fm_location$type_id $joinmethod where 
fm_location$type_id.status=2 group by $parent_table.location_code ";
+                               $dbresult = 
$GLOBALS['phpgw']->db->Execute($sql);
+
+                               while (!$dbresult->EOF)
+                               {
+                                       
$outdated[$dbresult->fields['location_code']]['count_99']=$dbresult->fields['count_99'];
+                                       $dbresult->MoveNext();
+                               }
+
+                               $sql = "SELECT $parent_table.location_code 
,count(*) as count_all  FROM $paranthesis fm_location$type_id $joinmethod group 
by $parent_table.location_code ";
+                               $dbresult = 
$GLOBALS['phpgw']->db->Execute($sql);
+                               while (!$dbresult->EOF)
+                               {
+                                       if( 
$outdated[$dbresult->fields['location_code']]['count_99']==$dbresult->fields['count_all'])
+                                       {
+                                               $update[]=array('location_code' 
=> $dbresult->fields['location_code']);
+                                       }
+                                       $dbresult->MoveNext();
+                               }
+
+                               $j=0;
+                               for ($i=0; $i<count($update); $i++)
+                               {
+
+                                       $sql = "SELECT status  FROM 
$parent_table WHERE location_code= '" . $update[$i]['location_code'] ."'";
+
+                                       $dbresult = 
$GLOBALS['phpgw']->db->Execute($sql);
+
+                                       if($dbresult->fields['status']!=2)
+                                       {
+                                               $j++;
+                                               
$GLOBALS['phpgw']->db->Execute("UPDATE fm_location" . ($type_id-1). " set       
status= 2  WHERE location_code= '" . $update[$i]['location_code'] ."'");
+                                       }
+                               }
+
+                               $receipt['message'][]=array('msg'=>lang('%1 
location %2 has been updated to not active of %3 already not 
active',$j,$location_types[($type_id-2)]['descr'],count($update)));
+
+                               unset($outdated);
+                               unset($update);
+                               unset($joinmethod);
+                               unset($paranthesis);
+                       }
+
+                       $GLOBALS['phpgw']->db->committrans();
+
+                       return $receipt;
+               }
+       }
+?>




reply via email to

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