phpgroupware-cvs
[Top][All Lists]
Advanced

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

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


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

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

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

Log Message:
no message
=====================================================================
Index: property/class.sogab.php
diff -u property/class.sogab.php:1.1.1.2 property/class.sogab.php:1.1.1.3
--- property/class.sogab.php:1.1.1.2    Fri Apr 23 20:25:47 2004
+++ property/class.sogab.php    Fri Apr 23 21:26:33 2004
@@ -1,449 +1,449 @@
-<?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_sogab
-       {
-               var $gab_insert_level;
-
-               function property_sogab($gab_insert_level)
-               {
-                       $this->currentapp       = 'property'; 
//$GLOBALS['phpgw_info']['flags']['currentapp'];
-                       $this->db                       = $GLOBALS['phpgw']->db;
-                       $this->db2                      = $this->db;
-                       $this->account          = 
$GLOBALS['phpgw_data']['user']['id'];
-                       $this->bocommon         = 
CreateObject($this->currentapp.'_bocommon');
-                       $this->socommon         = 
CreateObject($this->currentapp.'_socommon');
-
-                       $this->join                     = $this->socommon->join;
-
-                       $this->gab_insert_level = $gab_insert_level;
-
-               }
-
-               function read($data)
-               {
-                       if(is_array($data))
-                       {
-                               if ($data['start'])
-                               {
-                                       $start=$data['start'];
-                               }
-                               else
-                               {
-                                       $start=0;
-                               }
-                               $sort = 
(isset($data['sort'])?$data['sort']:'DESC');
-                               $order = 
(isset($data['order'])?$data['order']:'');
-                               $cat_id = 
(isset($data['cat_id'])?$data['cat_id']:0);
-                               $loc1 = (isset($data['loc1'])?$data['loc1']:'');
-                               $gaards_nr = 
(isset($data['gaards_nr'])?$data['gaards_nr']:'');
-                               $bruksnr = 
(isset($data['bruksnr'])?$data['bruksnr']:'');
-                               $feste_nr = 
(isset($data['feste_nr'])?$data['feste_nr']:'');
-                               $seksjons_nr = 
(isset($data['seksjons_nr'])?$data['seksjons_nr']:'');
-                               $allrows                = 
(isset($data['allrows'])?$data['allrows']:'');
-                       }
-
-                       if ($order)
-                       {
-                               $ordermethod = " order by $order $sort";
-                       }
-                       else
-                       {
-                               $ordermethod = ' order by gab_id ASC';
-                       }
-
-                       $where = 'WHERE';
-
-                       if ($cat_id > 0)
-                       {
-                               $filtermethod .= " $where 
fm_gab_location.category='$cat_id' ";
-                               $where = 'AND';
-                       }
-
-                       if ($status_id)
-                       {
-                               $filtermethod .= " $where 
fm_gab_location.status='$status_id' ";
-                               $where = 'AND';
-                       }
-
-                       if ($loc1)
-                       {
-                               $filtermethod .= " $where 
fm_gab_location.loc1='$loc1' ";
-                               $where = 'AND';
-                       }
-
-                       if ($gaards_nr)
-                       {
-                               $filtermethod .= " $where SUBSTRING(gab_id,5,5) 
like '%$gaards_nr%' ";
-                               $where = 'AND';
-                       }
-                       if ($bruksnr)
-                       {
-                               $filtermethod .= " $where 
SUBSTRING(gab_id,10,4) like '%$bruksnr%' ";
-                               $where = 'AND';
-                       }
-                       if ($feste_nr)
-                       {
-                               $filtermethod .= " $where 
SUBSTRING(gab_id,14,4) like '%$feste_nr%' ";
-                               $where = 'AND';
-                       }
-                       if ($seksjons_nr)
-                       {
-                               $filtermethod .= " $where 
SUBSTRING(gab_id,18,3) like '%$seksjons_nr%' ";
-                               $where = 'AND';
-                       }
-
-                       $sql = "SELECT gab_id,count(gab_id) as hits, loc1_name 
as address FROM fm_gab_location $this->join fm_location1 on 
fm_gab_location.loc1=fm_location1.loc1 $filtermethod GROUP BY gab_id,loc1_name 
";
-
-                       $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);
-                       }
-
-                       while (!$dbresult->EOF)
-                       {
-                               $gab_list[] = array
-                               (
-                                       'gab_id'                => 
$dbresult->fields['gab_id'],
-                                       'location_code' => 
$dbresult->fields['location_code'],
-                                       'address'               => 
$dbresult->fields['address'],
-                                       'hits'                  => 
$dbresult->fields['hits']
-                                       );
-                               $dbresult->MoveNext();
-                       }
-                       return $gab_list;
-               }
-
-               function read_detail($data)
-               {
-                       if(is_array($data))
-                       {
-                               if ($data['start'])
-                               {
-                                       $start=$data['start'];
-                               }
-                               else
-                               {
-                                       $start=0;
-                               }
-                               $sort = 
(isset($data['sort'])?$data['sort']:'DESC');
-                               $order = 
(isset($data['order'])?$data['order']:'');
-                               $cat_id = 
(isset($data['cat_id'])?$data['cat_id']:0);
-                               $gab_id = 
(isset($data['gab_id'])?$data['gab_id']:'0');
-                               $allrows                = 
(isset($data['allrows'])?$data['allrows']:'');
-                       }
-
-
-                       $entity_table = 'fm_gab_location';
-
-                       $cols .= $entity_table . '.location_code';
-                       $cols_return[] = 'location_code';
-                       $cols .= ',gab_id';
-                       $cols_return[] = 'gab_id';
-
-
-                       $sql    = 
$this->bocommon->generate_sql(array('entity_table'=>$entity_table,'cols'=>$cols,'cols_return'=>$cols_return,
-                                                                               
                                        
'uicols'=>$uicols,'joinmethod'=>$joinmethod,'paranthesis'=>$paranthesis,'query'=>$query));
-
-
-                       if ($order)
-                       {
-                               $ordermethod = " order by $order $sort";
-                       }
-                       else
-                       {
-                               $ordermethod = ' order by 
fm_gab_location.location_code ASC';
-                       }
-
-                       $filtermethod = " WHERE 
fm_gab_location.gab_id='$gab_id'";
-
-                       if ($cat_id > 0)
-                       {
-                               $filtermethod .= " AND 
fm_gab_location.category='$cat_id' ";
-                       }
-
-                       if ($status_id)
-                       {
-                               $filtermethod .= " AND 
fm_gab_location.status='$status_id' ";
-                       }
-
-                       $sql .= " $filtermethod ";
-//echo $sql;
-                       $this->uicols           = $this->bocommon->uicols;
-                       $cols_return            = $this->bocommon->cols_return;
-                       $type_id                        = 
$this->bocommon->type_id;
-                       $this->cols_extra       = $this->bocommon->cols_extra;
-
-
-                       $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;
-                       while (!$dbresult->EOF)
-                       {
-                               for ($i=0;$i<count($cols_return);$i++)
-                               {
-                                       $gab_list[$j][$cols_return[$i]] = 
$dbresult->fields[$cols_return[$i]];
-                               }
-
-                               $location_code= 
$dbresult->fields['location_code'];
-                               $location = split('-',$location_code);
-                               for ($m=0;$m<count($location);$m++)
-                               {
-                                       $gab_list[$j]['loc' . ($m+1)] = 
$location[$m];
-                                       $gab_list[$j]['query_location']['loc' . 
($m+1)]=implode("-", array_slice($location, 0, ($m+1)));
-                               }
-
-                               $j++;
-                               $dbresult->MoveNext();
-                       }
-                       return $gab_list;
-               }
-
-               function read_single($gab_id='',$location_code='')
-               {
-                       $sql = "SELECT * from fm_gab_location where 
gab_id='$gab_id' and location_code='$location_code' ";
-
-                       $dbresult = $GLOBALS['phpgw']->db->Execute($sql);
-
-                       if (!$dbresult->EOF)
-                       {
-                               $gab['location_code']           = 
$location_code;
-                               $gab['remark']                          = 
$dbresult->fields['remark'];
-                       }
-
-//html_print_r($gab);
-                               return $gab;
-               }
-
-               function exist_gab_location($gab_id='',$location_code='')
-               {
-                       $dbresult = $GLOBALS['phpgw']->db->Execute("SELECT 
count(*) FROM fm_gab_location where gab_id='$gab_id' and 
location_code='$location_code'");
-
-                       if ( $dbresult->fields[0])
-                       {
-                               return True;
-                       }
-               }
-
-
-               function add($gab)
-               {
-                       $location = explode('-', $gab['location_code']);
-                       $next_type      = count($location)+1;
-
-//html_print_r($gab);
-
-                       $where= 'WHERE';
-                       for ($i=0;$i<count($location);$i++)
-                       {
-                               $where_condition .= " $where loc" . ($i+1) . 
"='" . $location[$i] . "'";
-                               $where= 'AND';
-                       }
-
-                       $gab['remark'] = 
$this->db->db_addslashes($gab['remark']);
-
-                       $gab_id= $gab['kommune_nr'] . 
sprintf("%05s",$gab['gaards_nr']) . sprintf("%04s",$gab['bruks_nr']) . 
sprintf("%04s",$gab['feste_nr']) . sprintf("%03s",$gab['seksjons_nr']);
-
-                       if($gab['propagate'] && ($next_type < 
($this->gab_insert_level+1)))
-                       {
-
-                               $sql = 'SELECT location_code,loc' . 
$this->gab_insert_level . '_name as location_name FROM fm_location' . 
$this->gab_insert_level . " $where_condition ";
-
-                               $dbresult = 
$GLOBALS['phpgw']->db->Execute($sql);
-
-                               while (!$dbresult->EOF)
-                               {
-                                       
if(!$this->exist_gab_location($gab_id,$dbresult->fields['location_code']))
-                                       {
-                                               $gab_insert[] = 
array('location_code'   => $dbresult->fields['location_code'],
-                                                                               
                'gab_id'                => $gab_id,
-                                                                               
                'location_name' => $dbresult->fields['location_name'],
-                                                                               
                'remark'                => $gab['remark']);
-                                       }
-                                       else
-                                       {
-                                               $gab_update[] = 
array('location_code'   => $dbresult->fields['location_code'],
-                                                                               
                'gab_id'                => $gab_id,
-                                                                               
                'location_name' => $dbresult->fields['location_name'],
-                                                                               
                'remark'                => $gab['remark']);
-                                       }
-                                       $dbresult->MoveNext();
-                               }
-                       }
-                       else
-                       {
-                               if(count($location)==$this->gab_insert_level)
-                               {
-                                       $gab_insert[] = array('location_code'=> 
$gab['location_code'],
-                                                                               
'gab_id'        => $gab_id,
-                                                                               
'street_name'   => $gab['street_name'],
-                                                                               
'street_number' => $gab['street_number'],
-                                                                               
'location_name' => $gab['location_name'],
-                                                                               
'remark'        => $gab['remark']);
-                               }
-                       }
-
-                       if($gab_insert)
-                       {
-                               $receipt = $this->insert($gab_insert);
-                       }
-                       else
-                       {
-                               $receipt['error'][] = array('msg'=>lang('Could 
not find any location to save to!'));
-                       }
-
-                       if($gab_update)
-                       {
-                               $receipt = $this->update($gab_update,$receipt);
-                       }
-
-                       $receipt['gab_id'] = $gab_id;
-
-                       return $receipt;
-               }
-
-
-               function insert($gab_insert)
-               {
-                       $receipt['message'][] = array('msg'=>lang('gab %1 has 
been added',$gab_insert[0]['gab_id']));
-
-                       for ($i=0;$i<count($gab_insert);$i++)
-                       {
-                               $location = explode('-', 
$gab_insert[$i]['location_code']);
-
-                               while (is_array($location) && 
list($input_name,$value) = each($location))
-                               {
-                                       if($value)
-                                       {
-                                               $cols[] = 'loc' . 
($input_name+1);
-                                               $vals[] = $value;
-                                       }
-                               }
-
-                               if($cols)
-                               {
-                                       $cols   = "," . implode(",", $cols);
-                                       $vals   = ",'" . implode("','", $vals) 
. "'";
-                               }
-
-                               unset($location);
-
-
-
-                               if($gab_insert[$i]['street_name'])
-                               {
-                                       $address[]= 
$gab_insert[$i]['street_name'];
-                                       $address[]= 
$gab_insert[$i]['street_number'];
-                                       $address        = implode(" ", 
$address);
-                               }
-
-                               if(!$address)
-                               {
-                                       $address = 
$gab_insert[$i]['location_name'];
-                               }
-
-                               $GLOBALS['phpgw']->db->Execute("INSERT INTO 
fm_gab_location (location_code,gab_id,remark,entry_date,user_id,address $cols) "
-                                       . "VALUES ('"
-                                       . $gab_insert[$i]['location_code']. 
"','"
-                                       . $gab_insert[$i]['gab_id']. "','"
-                                       . $gab_insert[$i]['remark']. "','"
-                                       . time() . "','"
-                                       . $this->account. "','"
-                                       . $address . "' $vals )");
-
-                                       $receipt['message'][] = 
array('msg'=>lang('at location %1',$gab_insert[$i]['location_code']));
-                       }
-
-
-                       return $receipt;
-               }
-
-               function update($gab_update,$receipt)
-               {
-                       $receipt['message'][] = array('msg'=>lang('gab %1 has 
been updated',$gab_update[0]['gab_id']));
-
-                       for ($i=0;$i<count($gab_update);$i++)
-                       {
-                               $GLOBALS['phpgw']->db->Execute("UPDATE 
fm_gab_location set
-                                       gab_id                  ='" . 
$gab_insert[$i]['gab_id'] . "',
-                                       remark                  ='" . 
$gab_insert[$i]['remark'] . "',
-                                       entry_date              ='"     . 
time() . "',
-                                       user_id                 ='" . 
$this->account
-                                       . "' WHERE location_code = '" . 
$gab_insert[$i]['location_code'] ."'");
-
-                                       $receipt['message'][] = 
array('msg'=>lang('at location %1',$gab_update[$i]['location_code']));
-                       }
-
-                       return $receipt;
-               }
-
-               function edit($gab)
-               {
-                       $location = explode('-', $gab['location_code']);
-
-//html_print_r($gab);
-
-                       if(count($location)==$this->gab_insert_level)
-                       {
-
-                               $GLOBALS['phpgw']->db->Execute("UPDATE 
fm_gab_location set
-                                       remark                  ='" . 
$gab['remark'] . "',
-                                       entry_date              ='"     . 
time() . "',
-                                       user_id                 ='" . 
$this->account
-                                       . "' WHERE location_code= '" . 
$gab['location_code'] ."' and gab_id= '" . $gab['gab_id'] ."'");
-
-                               $receipt['message'][] = array('msg'=>lang('gab 
%1 has been edited',"'".$gab['gab_id']."'"));
-                               $receipt['message'][] = array('msg'=>lang('at 
location %1',$gab['location_code']));
-                       }
-                       else
-                       {
-                               $receipt['error'][] = 
array('msg'=>lang('Nothing to do !'));
-                       }
-                       $receipt['gab_id'] = $gab['gab_id'];
-                       return $receipt;
-
-               }
-
-               function delete($gab_id='',$location_code='')
-               {
-                       $GLOBALS['phpgw']->db->Execute("DELETE FROM 
fm_gab_location WHERE gab_id='$gab_id' and location_code='$location_code'");
-               }
-       }
-?>
+<?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_sogab
+       {
+               var $gab_insert_level;
+
+               function property_sogab($gab_insert_level)
+               {
+                       $this->currentapp       = 'property'; 
//$GLOBALS['phpgw_info']['flags']['currentapp'];
+                       $this->db                       = $GLOBALS['phpgw']->db;
+                       $this->db2                      = $this->db;
+                       $this->account          = 
$GLOBALS['phpgw_data']['user']['id'];
+                       $this->bocommon         = 
CreateObject($this->currentapp.'_bocommon');
+                       $this->socommon         = 
CreateObject($this->currentapp.'_socommon');
+
+                       $this->join                     = $this->socommon->join;
+
+                       $this->gab_insert_level = $gab_insert_level;
+
+               }
+
+               function read($data)
+               {
+                       if(is_array($data))
+                       {
+                               if ($data['start'])
+                               {
+                                       $start=$data['start'];
+                               }
+                               else
+                               {
+                                       $start=0;
+                               }
+                               $sort = 
(isset($data['sort'])?$data['sort']:'DESC');
+                               $order = 
(isset($data['order'])?$data['order']:'');
+                               $cat_id = 
(isset($data['cat_id'])?$data['cat_id']:0);
+                               $loc1 = (isset($data['loc1'])?$data['loc1']:'');
+                               $gaards_nr = 
(isset($data['gaards_nr'])?$data['gaards_nr']:'');
+                               $bruksnr = 
(isset($data['bruksnr'])?$data['bruksnr']:'');
+                               $feste_nr = 
(isset($data['feste_nr'])?$data['feste_nr']:'');
+                               $seksjons_nr = 
(isset($data['seksjons_nr'])?$data['seksjons_nr']:'');
+                               $allrows                = 
(isset($data['allrows'])?$data['allrows']:'');
+                       }
+
+                       if ($order)
+                       {
+                               $ordermethod = " order by $order $sort";
+                       }
+                       else
+                       {
+                               $ordermethod = ' order by gab_id ASC';
+                       }
+
+                       $where = 'WHERE';
+
+                       if ($cat_id > 0)
+                       {
+                               $filtermethod .= " $where 
fm_gab_location.category='$cat_id' ";
+                               $where = 'AND';
+                       }
+
+                       if ($status_id)
+                       {
+                               $filtermethod .= " $where 
fm_gab_location.status='$status_id' ";
+                               $where = 'AND';
+                       }
+
+                       if ($loc1)
+                       {
+                               $filtermethod .= " $where 
fm_gab_location.loc1='$loc1' ";
+                               $where = 'AND';
+                       }
+
+                       if ($gaards_nr)
+                       {
+                               $filtermethod .= " $where SUBSTRING(gab_id,5,5) 
like '%$gaards_nr%' ";
+                               $where = 'AND';
+                       }
+                       if ($bruksnr)
+                       {
+                               $filtermethod .= " $where 
SUBSTRING(gab_id,10,4) like '%$bruksnr%' ";
+                               $where = 'AND';
+                       }
+                       if ($feste_nr)
+                       {
+                               $filtermethod .= " $where 
SUBSTRING(gab_id,14,4) like '%$feste_nr%' ";
+                               $where = 'AND';
+                       }
+                       if ($seksjons_nr)
+                       {
+                               $filtermethod .= " $where 
SUBSTRING(gab_id,18,3) like '%$seksjons_nr%' ";
+                               $where = 'AND';
+                       }
+
+                       $sql = "SELECT gab_id,count(gab_id) as hits, loc1_name 
as address FROM fm_gab_location $this->join fm_location1 on 
fm_gab_location.loc1=fm_location1.loc1 $filtermethod GROUP BY gab_id,loc1_name 
";
+
+                       $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);
+                       }
+
+                       while (!$dbresult->EOF)
+                       {
+                               $gab_list[] = array
+                               (
+                                       'gab_id'                => 
$dbresult->fields['gab_id'],
+                                       'location_code' => 
$dbresult->fields['location_code'],
+                                       'address'               => 
$dbresult->fields['address'],
+                                       'hits'                  => 
$dbresult->fields['hits']
+                                       );
+                               $dbresult->MoveNext();
+                       }
+                       return $gab_list;
+               }
+
+               function read_detail($data)
+               {
+                       if(is_array($data))
+                       {
+                               if ($data['start'])
+                               {
+                                       $start=$data['start'];
+                               }
+                               else
+                               {
+                                       $start=0;
+                               }
+                               $sort = 
(isset($data['sort'])?$data['sort']:'DESC');
+                               $order = 
(isset($data['order'])?$data['order']:'');
+                               $cat_id = 
(isset($data['cat_id'])?$data['cat_id']:0);
+                               $gab_id = 
(isset($data['gab_id'])?$data['gab_id']:'0');
+                               $allrows                = 
(isset($data['allrows'])?$data['allrows']:'');
+                       }
+
+
+                       $entity_table = 'fm_gab_location';
+
+                       $cols .= $entity_table . '.location_code';
+                       $cols_return[] = 'location_code';
+                       $cols .= ',gab_id';
+                       $cols_return[] = 'gab_id';
+
+
+                       $sql    = 
$this->bocommon->generate_sql(array('entity_table'=>$entity_table,'cols'=>$cols,'cols_return'=>$cols_return,
+                                                                               
                                        
'uicols'=>$uicols,'joinmethod'=>$joinmethod,'paranthesis'=>$paranthesis,'query'=>$query));
+
+
+                       if ($order)
+                       {
+                               $ordermethod = " order by $order $sort";
+                       }
+                       else
+                       {
+                               $ordermethod = ' order by 
fm_gab_location.location_code ASC';
+                       }
+
+                       $filtermethod = " WHERE 
fm_gab_location.gab_id='$gab_id'";
+
+                       if ($cat_id > 0)
+                       {
+                               $filtermethod .= " AND 
fm_gab_location.category='$cat_id' ";
+                       }
+
+                       if ($status_id)
+                       {
+                               $filtermethod .= " AND 
fm_gab_location.status='$status_id' ";
+                       }
+
+                       $sql .= " $filtermethod ";
+//echo $sql;
+                       $this->uicols           = $this->bocommon->uicols;
+                       $cols_return            = $this->bocommon->cols_return;
+                       $type_id                        = 
$this->bocommon->type_id;
+                       $this->cols_extra       = $this->bocommon->cols_extra;
+
+
+                       $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;
+                       while (!$dbresult->EOF)
+                       {
+                               for ($i=0;$i<count($cols_return);$i++)
+                               {
+                                       $gab_list[$j][$cols_return[$i]] = 
$dbresult->fields[$cols_return[$i]];
+                               }
+
+                               $location_code= 
$dbresult->fields['location_code'];
+                               $location = split('-',$location_code);
+                               for ($m=0;$m<count($location);$m++)
+                               {
+                                       $gab_list[$j]['loc' . ($m+1)] = 
$location[$m];
+                                       $gab_list[$j]['query_location']['loc' . 
($m+1)]=implode("-", array_slice($location, 0, ($m+1)));
+                               }
+
+                               $j++;
+                               $dbresult->MoveNext();
+                       }
+                       return $gab_list;
+               }
+
+               function read_single($gab_id='',$location_code='')
+               {
+                       $sql = "SELECT * from fm_gab_location where 
gab_id='$gab_id' and location_code='$location_code' ";
+
+                       $dbresult = $GLOBALS['phpgw']->db->Execute($sql);
+
+                       if (!$dbresult->EOF)
+                       {
+                               $gab['location_code']           = 
$location_code;
+                               $gab['remark']                          = 
$dbresult->fields['remark'];
+                       }
+
+//html_print_r($gab);
+                               return $gab;
+               }
+
+               function exist_gab_location($gab_id='',$location_code='')
+               {
+                       $dbresult = $GLOBALS['phpgw']->db->Execute("SELECT 
count(*) FROM fm_gab_location where gab_id='$gab_id' and 
location_code='$location_code'");
+
+                       if ( $dbresult->fields[0])
+                       {
+                               return True;
+                       }
+               }
+
+
+               function add($gab)
+               {
+                       $location = explode('-', $gab['location_code']);
+                       $next_type      = count($location)+1;
+
+//html_print_r($gab);
+
+                       $where= 'WHERE';
+                       for ($i=0;$i<count($location);$i++)
+                       {
+                               $where_condition .= " $where loc" . ($i+1) . 
"='" . $location[$i] . "'";
+                               $where= 'AND';
+                       }
+
+                       $gab['remark'] = 
$this->db->db_addslashes($gab['remark']);
+
+                       $gab_id= $gab['kommune_nr'] . 
sprintf("%05s",$gab['gaards_nr']) . sprintf("%04s",$gab['bruks_nr']) . 
sprintf("%04s",$gab['feste_nr']) . sprintf("%03s",$gab['seksjons_nr']);
+
+                       if($gab['propagate'] && ($next_type < 
($this->gab_insert_level+1)))
+                       {
+
+                               $sql = 'SELECT location_code,loc' . 
$this->gab_insert_level . '_name as location_name FROM fm_location' . 
$this->gab_insert_level . " $where_condition ";
+
+                               $dbresult = 
$GLOBALS['phpgw']->db->Execute($sql);
+
+                               while (!$dbresult->EOF)
+                               {
+                                       
if(!$this->exist_gab_location($gab_id,$dbresult->fields['location_code']))
+                                       {
+                                               $gab_insert[] = 
array('location_code'   => $dbresult->fields['location_code'],
+                                                                               
                'gab_id'                => $gab_id,
+                                                                               
                'location_name' => $dbresult->fields['location_name'],
+                                                                               
                'remark'                => $gab['remark']);
+                                       }
+                                       else
+                                       {
+                                               $gab_update[] = 
array('location_code'   => $dbresult->fields['location_code'],
+                                                                               
                'gab_id'                => $gab_id,
+                                                                               
                'location_name' => $dbresult->fields['location_name'],
+                                                                               
                'remark'                => $gab['remark']);
+                                       }
+                                       $dbresult->MoveNext();
+                               }
+                       }
+                       else
+                       {
+                               if(count($location)==$this->gab_insert_level)
+                               {
+                                       $gab_insert[] = array('location_code'=> 
$gab['location_code'],
+                                                                               
'gab_id'        => $gab_id,
+                                                                               
'street_name'   => $gab['street_name'],
+                                                                               
'street_number' => $gab['street_number'],
+                                                                               
'location_name' => $gab['location_name'],
+                                                                               
'remark'        => $gab['remark']);
+                               }
+                       }
+
+                       if($gab_insert)
+                       {
+                               $receipt = $this->insert($gab_insert);
+                       }
+                       else
+                       {
+                               $receipt['error'][] = array('msg'=>lang('Could 
not find any location to save to!'));
+                       }
+
+                       if($gab_update)
+                       {
+                               $receipt = $this->update($gab_update,$receipt);
+                       }
+
+                       $receipt['gab_id'] = $gab_id;
+
+                       return $receipt;
+               }
+
+
+               function insert($gab_insert)
+               {
+                       $receipt['message'][] = array('msg'=>lang('gab %1 has 
been added',$gab_insert[0]['gab_id']));
+
+                       for ($i=0;$i<count($gab_insert);$i++)
+                       {
+                               $location = explode('-', 
$gab_insert[$i]['location_code']);
+
+                               while (is_array($location) && 
list($input_name,$value) = each($location))
+                               {
+                                       if($value)
+                                       {
+                                               $cols[] = 'loc' . 
($input_name+1);
+                                               $vals[] = $value;
+                                       }
+                               }
+
+                               if($cols)
+                               {
+                                       $cols   = "," . implode(",", $cols);
+                                       $vals   = ",'" . implode("','", $vals) 
. "'";
+                               }
+
+                               unset($location);
+
+
+
+                               if($gab_insert[$i]['street_name'])
+                               {
+                                       $address[]= 
$gab_insert[$i]['street_name'];
+                                       $address[]= 
$gab_insert[$i]['street_number'];
+                                       $address        = implode(" ", 
$address);
+                               }
+
+                               if(!$address)
+                               {
+                                       $address = 
$gab_insert[$i]['location_name'];
+                               }
+
+                               $GLOBALS['phpgw']->db->Execute("INSERT INTO 
fm_gab_location (location_code,gab_id,remark,entry_date,user_id,address $cols) "
+                                       . "VALUES ('"
+                                       . $gab_insert[$i]['location_code']. 
"','"
+                                       . $gab_insert[$i]['gab_id']. "','"
+                                       . $gab_insert[$i]['remark']. "','"
+                                       . time() . "','"
+                                       . $this->account. "','"
+                                       . $address . "' $vals )");
+
+                                       $receipt['message'][] = 
array('msg'=>lang('at location %1',$gab_insert[$i]['location_code']));
+                       }
+
+
+                       return $receipt;
+               }
+
+               function update($gab_update,$receipt)
+               {
+                       $receipt['message'][] = array('msg'=>lang('gab %1 has 
been updated',$gab_update[0]['gab_id']));
+
+                       for ($i=0;$i<count($gab_update);$i++)
+                       {
+                               $GLOBALS['phpgw']->db->Execute("UPDATE 
fm_gab_location set
+                                       gab_id                  ='" . 
$gab_insert[$i]['gab_id'] . "',
+                                       remark                  ='" . 
$gab_insert[$i]['remark'] . "',
+                                       entry_date              ='"     . 
time() . "',
+                                       user_id                 ='" . 
$this->account
+                                       . "' WHERE location_code = '" . 
$gab_insert[$i]['location_code'] ."'");
+
+                                       $receipt['message'][] = 
array('msg'=>lang('at location %1',$gab_update[$i]['location_code']));
+                       }
+
+                       return $receipt;
+               }
+
+               function edit($gab)
+               {
+                       $location = explode('-', $gab['location_code']);
+
+//html_print_r($gab);
+
+                       if(count($location)==$this->gab_insert_level)
+                       {
+
+                               $GLOBALS['phpgw']->db->Execute("UPDATE 
fm_gab_location set
+                                       remark                  ='" . 
$gab['remark'] . "',
+                                       entry_date              ='"     . 
time() . "',
+                                       user_id                 ='" . 
$this->account
+                                       . "' WHERE location_code= '" . 
$gab['location_code'] ."' and gab_id= '" . $gab['gab_id'] ."'");
+
+                               $receipt['message'][] = array('msg'=>lang('gab 
%1 has been edited',"'".$gab['gab_id']."'"));
+                               $receipt['message'][] = array('msg'=>lang('at 
location %1',$gab['location_code']));
+                       }
+                       else
+                       {
+                               $receipt['error'][] = 
array('msg'=>lang('Nothing to do !'));
+                       }
+                       $receipt['gab_id'] = $gab['gab_id'];
+                       return $receipt;
+
+               }
+
+               function delete($gab_id='',$location_code='')
+               {
+                       $GLOBALS['phpgw']->db->Execute("DELETE FROM 
fm_gab_location WHERE gab_id='$gab_id' and location_code='$location_code'");
+               }
+       }
+?>




reply via email to

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