phpgroupware-cvs
[Top][All Lists]
Advanced

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

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


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

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

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

Log Message:
no message
=====================================================================
Index: property/class.sorequest.php
diff -u property/class.sorequest.php:1.1.1.2 
property/class.sorequest.php:1.1.1.3
--- property/class.sorequest.php:1.1.1.2        Fri Apr 23 20:25:59 2004
+++ property/class.sorequest.php        Fri Apr 23 21:26:33 2004
@@ -1,697 +1,697 @@
-<?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_sorequest
-       {
-               function property_sorequest()
-               {
-                       $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->soproject        = 
CreateObject($this->currentapp.'_soproject');
-                       $this->historylog       = 
CreateObject($this->currentapp.'_historylog','request');
-                       $this->bocommon         = 
CreateObject($this->currentapp.'_bocommon');
-                       $this->socommon         = 
CreateObject($this->currentapp.'_socommon');
-
-                       $this->join                     = $this->socommon->join;
-               }
-
-               function select_category_workorder_list()
-               {
-
-                       $dbresult = $GLOBALS['phpgw']->db->Execute("SELECT id, 
descr FROM fm_workorder_category  ORDER BY descr ");
-
-                       $i = 0;
-                       while (!$dbresult->EOF)
-                       {
-                               $categories[$i]['id']                           
= $dbresult->fields['id'];
-                               $categories[$i]['name']                         
= stripslashes($dbresult->fields['descr']);
-                               $i++;
-                               $dbresult->MoveNext();
-                       }
-                       return $categories;
-               }
-
-               function read_priority_key()
-               {
-                       $dbresult = $GLOBALS['phpgw']->db->Execute("SELECT * 
FROM fm_request_priority_key");
-
-
-                       $priority_key['safety']                                 
        = $dbresult->fields['safety'];
-                       $priority_key['aesthetics']                             
        = $dbresult->fields['aesthetics'];
-                       $priority_key['indoor_climate']                         
= $dbresult->fields['indoor_climate'];
-                       $priority_key['consequential_damage']           = 
$dbresult->fields['consequential_damage'];
-                       $priority_key['user_gratification']                     
= $dbresult->fields['user_gratification'];
-                       $priority_key['residential_environment']        = 
$dbresult->fields['residential_environment'];
-                       $priority_key['authorities_demands']            = 
$dbresult->fields['authorities_demands'];
-
-                       return $priority_key;
-               }
-
-               function update_priority_key($values)
-               {
-
-                       
$values['safety']=str_replace(",",".",$values['safety']);
-                       
$values['aesthetics']=str_replace(",",".",$values['aesthetics']);
-                       
$values['indoor_climate']=str_replace(",",".",$values['indoor_climate']);
-                       
$values['consequential_damage']=str_replace(",",".",$values['consequential_damage']);
-                       
$values['user_gratification']=str_replace(",",".",$values['user_gratification']);
-                       
$values['residential_environment']=str_replace(",",".",$values['residential_environment']);
-                       
$values['authorities_demands']=str_replace(",",".",$values['authorities_demands']);
-
-
-                       $GLOBALS['phpgw']->db->Execute("UPDATE 
fm_request_priority_key set
-                               safety  ='" . $values['safety'] . "',
-                               aesthetics      ='" . $values['aesthetics'] . 
"',
-                               indoor_climate  ='" . $values['indoor_climate'] 
. "',
-                               consequential_damage    ='" . 
$values['consequential_damage'] . "',
-                               user_gratification      ='" . 
$values['user_gratification'] . "',
-                               residential_environment ='" . 
$values['residential_environment'] . "',
-                               authorities_demands     ='" . 
$values['authorities_demands'] ."'");
-
-                       $this->update_score($values,'');
-
-                       $receipt['message'][] = array('msg'=> lang('priority 
keys has been updated'));
-                       return $receipt;
-
-               }
-
-
-               function update_score($priority_key,$request_id='')
-               {
-//html_print_r($priority_key);
-                       if(!$priority_key)
-                       {
-                               $priority_key = $this->read_priority_key();
-                       }
-
-
-                       $safety                                         = 
$priority_key['safety'];
-                       $aesthetics                                     = 
$priority_key['aesthetics'];
-                       $indoor_climate                         = 
$priority_key['indoor_climate'];
-                       $consequential_damage           = 
$priority_key['consequential_damage'];
-                       $user_gratification                     = 
$priority_key['user_gratification'];
-                       $residential_environment        = 
$priority_key['residential_environment'];
-                       $authorities_demands            = 
$priority_key['authorities_demands'];
-
-                       if($request_id)
-                       {
-                               $where =" where id = $request_id";
-                       }
-
-                       $GLOBALS['phpgw']->db->Execute("UPDATE fm_request set 
score=($safety* (d_safety*p_safety*(c_safety+1)))"
-                       . "+ ($aesthetics* 
(d_aesthetics*p_aesthetics*(c_aesthetics+1)))"
-                       . "+ ($indoor_climate* 
(d_indoor_climate*p_indoor_climate*(c_indoor_climate+1)))"
-                       . "+ ($consequential_damage* 
(d_consequential_damage*p_consequential_damage*(c_consequential_damage+1)))"
-                       . "+ ($user_gratification* 
(d_user_gratification*p_user_gratification*(c_user_gratification+1)))"
-                       . "+ ($residential_environment* 
(d_residential_environment*p_residential_environment*(c_residential_environment+1)))"
-                       . "+ ($authorities_demands* authorities_demands) $where 
");
-
-               }
-
-
-               function read_single_request_category($id='')
-               {
-                       $dbresult = $GLOBALS['phpgw']->db->Execute("SELECT 
descr FROM fm_workorder_category where id='$id' ");
-
-                       return $dbresult->fields['descr'];
-               }
-
-               function select_status_list()
-               {
-                       $dbresult = $GLOBALS['phpgw']->db->Execute("SELECT id, 
descr FROM fm_request_status ORDER BY id ");
-
-                       $i = 0;
-                       while (!$dbresult->EOF)
-                       {
-                               $status_entries[$i]['id']                       
        = $dbresult->fields['id'];
-                               $status_entries[$i]['name']                     
        = stripslashes($dbresult->fields['descr']);
-                               $i++;
-                               $dbresult->MoveNext();
-                       }
-                       return $status_entries;
-               }
-
-               function select_branch_list()
-               {
-                       $dbresult = $GLOBALS['phpgw']->db->Execute("SELECT id, 
descr FROM fm_branch ORDER BY id ");
-
-                       $i = 0;
-                       while (!$dbresult->EOF)
-                       {
-                               $branch_entries[$i]['id']                       
        = $dbresult->fields['id'];
-                               $branch_entries[$i]['name']                     
        = stripslashes($dbresult->fields['descr']);
-                               $i++;
-                               $dbresult->MoveNext();
-                       }
-                       return $branch_entries;
-               }
-
-               function select_key_location_list()
-               {
-                       $dbresult = $GLOBALS['phpgw']->db->Execute("SELECT id, 
descr FROM fm_key_loc ORDER BY descr ");
-
-                       $i = 0;
-                       while (!$dbresult->EOF)
-                       {
-                               $key_location_entries[$i]['id']                 
        = $dbresult->fields['id'];
-                               $key_location_entries[$i]['name']               
        = stripslashes($dbresult->fields['descr']);
-                               $i++;
-                               $dbresult->MoveNext();
-                       }
-                       return $key_location_entries;
-               }
-
-               function read($data)
-               {
-                       if(is_array($data))
-                       {
-                               if ($data['start'])
-                               {
-                                       $start=$data['start'];
-                               }
-                               else
-                               {
-                                       $start=0;
-                               }
-                               $filter = 
(isset($data['filter'])?$data['filter']:'');
-                               $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);
-                               $status_id = 
(isset($data['status_id'])?$data['status_id']:0);
-                               $project_id = 
(isset($data['project_id'])?$data['project_id']:'');
-                       }
-
-                       $entity_table = 'fm_request';
-
-                       $cols .= $entity_table . '.location_code';
-                       $cols_return[] = 'location_code';
-
-                       $cols .= ",$entity_table.id as request_id";
-                       $cols_return[]                          = 'request_id';
-                       $uicols['input_type'][]         = 'text';
-                       $uicols['name'][]                       = 'request_id';
-                       $uicols['descr'][]                      = 
lang('Request');
-                       $uicols['statustext'][]         = lang('Request ID');
-
-                       $cols.= ",$entity_table.entry_date";
-                       $cols_return[]                          = 'entry_date';
-                       $uicols['input_type'][]         = 'text';
-                       $uicols['name'][]                       = 'entry_date';
-                       $uicols['descr'][]                      = lang('entry 
date');
-                       $uicols['statustext'][]         = lang('Request entry 
date');
-
-                       $cols.= ",$entity_table.title as title";
-                       $cols_return[]                          = 'title';
-                       $uicols['input_type'][]         = 'text';
-                       $uicols['name'][]                       = 'title';
-                       $uicols['descr'][]                      = lang('title');
-                       $uicols['statustext'][]         = lang('Request title');
-
-                       $cols.= ",$entity_table.coordinator";
-                       $cols_return[]                          = 'coordinator';
-                       $uicols['input_type'][]         = 'text';
-                       $uicols['name'][]                       = 'coordinator';
-                       $uicols['descr'][]                      = 
lang('Coordinator');
-                       $uicols['statustext'][]         = lang('Project 
coordinator');
-
-                       $cols.= ",$entity_table.score";
-                       $cols_return[]                          = 'score';
-                       $uicols['input_type'][]         = 'text';
-                       $uicols['name'][]                       = 'score';
-                       $uicols['descr'][]                      = lang('score');
-                       $uicols['statustext'][]         = lang('score');
-
-                       $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_request.id ASC';
-                       }
-
-                       $where = 'WHERE';
-                       if ($cat_id > 0)
-                       {
-                               $filtermethod .= " $where 
fm_request.category='$cat_id' ";
-                               $where = 'AND';
-                       }
-
-                       if ($status_id)
-                       {
-                               $filtermethod .= " $where  
fm_request.status='$status_id' ";
-                               $where = 'AND';
-                       }
-
-                       if ($filter)
-                       {
-                               $filtermethod .= " $where 
fm_request.coordinator='$filter' ";
-                               $where = 'AND';
-                       }
-
-                       if ($project_id)// lookup requests not already 
allocated to projects
-                       {
-                               $filtermethod .= " $where project_id is NULL ";
-                               $where = 'AND';
-                       }
-
-                       if($query)
-                       {
-                               $query = ereg_replace("'",'',$query);
-                               $query = ereg_replace('"','',$query);
-
-                               $querymethod = " $where (fm_request.title LIKE 
'%$query%' or fm_request.address LIKE '%$query%' or fm_request.location_code 
LIKE '%$query%')";
-                       }
-
-                       $sql .= " $filtermethod $querymethod";
-
-                       $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++)
-                               {
-                                       $request_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++)
-                               {
-                                       $request_list[$j]['loc' . ($m+1)] = 
$location[$m];
-                                       
$request_list[$j]['query_location']['loc' . ($m+1)]=implode("-", 
array_slice($location, 0, ($m+1)));
-                               }
-
-                               $j++;
-                               $dbresult->MoveNext();
-                       }
-//html_print_r($request_list);
-                       return $request_list;
-               }
-
-               function read_single($request_id)
-               {
-                       $sql = "SELECT * from fm_request where 
id='$request_id'";
-
-                       $dbresult = $GLOBALS['phpgw']->db->Execute($sql);
-
-                       if (!$dbresult->EOF)
-                       {
-                               $request['request_id']                          
        = $dbresult->fields['id'];
-                               $request['title']                               
                = $dbresult->fields['title'];
-                               $request['location_code']                       
        = $dbresult->fields['location_code'];
-                               $request['descr']                               
                = $dbresult->fields['descr'];
-                               $request['status']                              
                = $dbresult->fields['status'];
-                               $request['budget']                              
                = (int)$dbresult->fields['budget'];
-                               $request['tenant_id']                           
        = $dbresult->fields['tenant_id'];
-                               $request['owner']                               
                = $dbresult->fields['owner'];
-                               $request['coordinator']                         
        = $dbresult->fields['coordinator'];
-                               $request['access']                              
                = $dbresult->fields['access'];
-                               $request['start_date']                          
        = $dbresult->fields['start_date'];
-                               $request['end_date']                            
        = $dbresult->fields['end_date'];
-                               $request['cat_id']                              
                = $dbresult->fields['category'];
-
-                               $request['branch_id']                           
        = $dbresult->fields['branch_id'];
-                               $request['d_safety']                            
        = $dbresult->fields['d_safety'];
-                               $request['d_aesthetics']                        
        = $dbresult->fields['d_aesthetics'];
-                               $request['d_indoor_climate']                    
= $dbresult->fields['d_indoor_climate'];
-                               $request['d_consequential_damage']              
= $dbresult->fields['d_consequential_damage'];
-                               $request['d_user_gratification']                
= $dbresult->fields['d_user_gratification'];
-                               $request['d_residential_environment']   = 
$dbresult->fields['d_residential_environment'];
-                               $request['c_safety']                            
        = $dbresult->fields['c_safety'];
-                               $request['c_aesthetics']                        
        = $dbresult->fields['c_aesthetics'];
-                               $request['c_indoor_climate']                    
= $dbresult->fields['c_indoor_climate'];
-                               $request['c_consequential_damage']              
= $dbresult->fields['c_consequential_damage'];
-                               $request['c_user_gratification']                
= $dbresult->fields['c_user_gratification'];
-                               $request['c_residential_environment']   = 
$dbresult->fields['c_residential_environment'];
-                               $request['p_safety']                            
        = $dbresult->fields['p_safety'];
-                               $request['p_aesthetics']                        
        = $dbresult->fields['p_aesthetics'];
-                               $request['p_indoor_climate']                    
= $dbresult->fields['p_indoor_climate'];
-                               $request['p_consequential_damage']              
= $dbresult->fields['p_consequential_damage'];
-                               $request['p_user_gratification']                
= $dbresult->fields['p_user_gratification'];
-                               $request['p_residential_environment']   = 
$dbresult->fields['p_residential_environment'];
-                               $request['authorities_demands']                 
= $dbresult->fields['authorities_demands'];
-                               $request['score']                               
                = $dbresult->fields['score'];
-                               $request['p_num']                               
                = $dbresult->fields['p_num'];
-                               $request['p_entity_id']                         
        = $dbresult->fields['p_entity_id'];
-                               $request['p_cat_id']                            
        = $dbresult->fields['p_cat_id'];
-
-                               $request['power_meter'] = 
$this->soproject->get_power_meter($dbresult->fields['location_code']);
-                       }
-
-
-                       $sql = "SELECT * FROM fm_request_origin WHERE 
request_id='$request_id'";
-
-                       $dbresult = $GLOBALS['phpgw']->db->Execute($sql);
-
-                       if (!$dbresult->EOF)
-                       {
-                               $request['origin_id']   = 
$dbresult->fields['origin_id'];
-                               $request['origin']              = 
$dbresult->fields['origin'];
-                       }
-
-                       $sql = "SELECT * FROM fm_project_origin WHERE 
origin_id='$request_id' and origin ='request'";
-
-                       $dbresult = $GLOBALS['phpgw']->db->Execute($sql);
-
-                       while (!$dbresult->EOF)
-                       {
-                               $request['project_id'][]['id']  = 
$dbresult->fields['project_id'];
-                               $dbresult->MoveNext();
-                       }
-
-//html_print_r($request);
-                               return $request;
-               }
-
-               function request_workorder_data($request_id = '')
-               {
-                       $dbresult = $GLOBALS['phpgw']->db->Execute("SELECT 
budget, id as workorder_id, vendor_id from fm_workorder where 
request_id='$request_id'");
-                       while (!$dbresult->EOF)
-                       {
-                               $budget[] = array(
-                                       'workorder_id'  => 
$dbresult->fields['workorder_id'],
-                                       'budget'                => 
sprintf("%01.2f",$dbresult->fields['budget']),
-                                       'vendor_id'     => 
$dbresult->fields['vendor_id']
-                                       );
-                               $dbresult->MoveNext();
-                       }
-                       return $budget;
-               }
-
-               function branch_p_list($request_id = '')
-               {
-
-                       $dbresult = $GLOBALS['phpgw']->db->Execute("SELECT 
branch_id from fm_requestbranch WHERE request_id='$request_id' ");
-                       while (!$dbresult->EOF)
-                       {
-                               $selected[] = array('branch_id' => 
$dbresult->fields['branch_id']);
-                               $dbresult->MoveNext();
-                       }
-
-                       return $selected;
-               }
-
-               function increment_request_id()
-               {
-                       $GLOBALS['phpgw']->db->Execute("UPDATE fm_idgenerator 
set value = value + 1 where name = 'request'");
-               }
-
-               function next_id()
-               {
-                       $dbresult = $GLOBALS['phpgw']->db->Execute("SELECT 
value from fm_idgenerator where name = 'request'");
-
-                       $id = $dbresult->fields['value']+1;
-                       return $id;
-               }
-
-               function add($request)
-               {
-//html_print_r($request);
-                       while (is_array($request['location']) && 
list($input_name,$value) = each($request['location']))
-                       {
-                               if($value)
-                               {
-                                       $cols[] = $input_name;
-                                       $vals[] = $value;
-                               }
-                       }
-
-                       while (is_array($request['extra']) && 
list($input_name,$value) = each($request['extra']))
-                       {
-                               if($value)
-                               {
-                                       $cols[] = $input_name;
-                                       $vals[] = $value;
-                               }
-                       }
-
-                       if($cols)
-                       {
-                               $cols   = "," . implode(",", $cols);
-                               $vals   = ",'" . implode("','", $vals) . "'";
-                       }
-
-                       if($request['street_name'])
-                       {
-                               $address[]= $request['street_name'];
-                               $address[]= $request['street_number'];
-                               $address        = implode(" ", $address);
-                       }
-
-                       if(!$address)
-                       {
-                               $address = $request['location_name'];
-                       }
-
-                       $request['descr'] = 
$this->db->db_addslashes($request['descr']);
-                       $request['name'] = 
$this->db->db_addslashes($request['name']);
-                       $request['title'] = 
$this->db->db_addslashes($request['title']);
-
-                       $values= array(
-                               $request['request_id'],
-                               $request['title'],
-                               $this->account,
-                               $request['cat_id'],
-                               $request['descr'],
-                               $request['location_code'],
-                               $address,
-                               time(),
-                               $request['budget'],
-                               $request['status'],
-                               $request['branch_id'],
-                               $request['coordinator'],
-                               $request['d_safety'],
-                               $request['d_aesthetics'],
-                               $request['d_indoor_climate'],
-                               $request['d_consequential_damage'],
-                               $request['d_user_gratification'],
-                               $request['d_residential_environment'],
-                               $request['c_safety'],
-                               $request['c_aesthetics'],
-                               $request['c_indoor_climate'],
-                               $request['c_consequential_damage'],
-                               $request['c_user_gratification'],
-                               $request['c_residential_environment'],
-                               $request['p_safety'],
-                               $request['p_aesthetics'],
-                               $request['p_indoor_climate'],
-                               $request['p_consequential_damage'],
-                               $request['p_user_gratification'],
-                               $request['p_residential_environment'],
-                               $request['authorities_demands']);
-
-                       $values = $this->bocommon->validate_db_insert($values);
-
-                       $GLOBALS['phpgw']->db->begintrans();
-
-                       $GLOBALS['phpgw']->db->Execute("INSERT into fm_request 
(id,title,owner,category,descr,location_code,"
-                               . 
"address,entry_date,budget,status,branch_id,coordinator,"
-                               . 
"d_safety,d_aesthetics,d_indoor_climate,d_consequential_damage,d_user_gratification,d_residential_environment,"
-                               . 
"c_safety,c_aesthetics,c_indoor_climate,c_consequential_damage,c_user_gratification,c_residential_environment,"
-                               . 
"p_safety,p_aesthetics,p_indoor_climate,p_consequential_damage,p_user_gratification,p_residential_environment,authorities_demands
  $cols) "
-                               . "VALUES ($values $vals )");
-
-
-                       $this->update_score('',$request['request_id']);
-
-
-                       if($request['contact_phone'])
-                       {
-                               $GLOBALS['phpgw']->db->Execute("UPDATE 
fm_tenant set contact_phone='". $request['contact_phone']. "' where 
tenant_id='". $request['tenant_id']. "'");
-                       }
-
-                       if ($request['power_meter'] )
-                       {
-                               
$this->soproject->update_power_meter($request['power_meter'],$request['location_code'],$address);
-                       }
-
-                       if($request['origin'] && $request['origin_id'])
-                       {
-                               $GLOBALS['phpgw']->db->Execute("INSERT INTO  
fm_request_origin (origin,origin_id,request_id,entry_date) "
-                                       . "VALUES ('"
-                                       . $request['origin']. "','"
-                                       . $request['origin_id']. "',"
-                                       . $request['request_id']. ","
-                                       . time() . ")");
-                       }
-
-                       if($GLOBALS['phpgw']->db->committrans())
-                       {
-                               $this->increment_request_id();
-                               
$this->historylog->add('SO',$request['request_id'],$request['status']);
-                               
$this->historylog->add('TO',$request['request_id'],$request['cat_id']);
-                               
$this->historylog->add('CO',$request['request_id'],$request['coordinator']);
-                               $receipt['message'][] = 
array('msg'=>lang('request %1 has been saved',$request['request_id']));
-                       }
-                       else
-                       {
-                               $receipt['error'][] = 
array('msg'=>lang('request %1 has not been saved',$request['request_id']));
-                       }
-                       return $receipt;
-               }
-
-               function edit($request)
-               {
-                       while (is_array($request['location']) && 
list($input_name,$value) = each($request['location']))
-                       {
-                               $vals[] = "$input_name = '$value'";
-                       }
-
-                       while (is_array($request['extra']) && 
list($input_name,$value) = each($request['extra']))
-                       {
-                               $vals[] = "$input_name = '$value'";
-                       }
-
-                       if($vals)
-                       {
-                               $vals   = "," . implode(",",$vals);
-                       }
-
-                       if($request['street_name'])
-                       {
-                               $address[]= $request['street_name'];
-                               $address[]= $request['street_number'];
-                               $address        = implode(" ", $address);
-                       }
-
-                       if(!$address)
-                       {
-                               $address = $request['location_name'];
-                       }
-
-
-                       $request['descr'] = 
$this->db->db_addslashes($request['descr']);
-                       $request['name'] = 
$this->db->db_addslashes($request['name']);
-                       $request['title'] = 
$this->db->db_addslashes($request['title']);
-//html_print_r($request);
-
-                       $value_set=array(
-                               'status'                                => 
$request['status'],
-                               'category'                              => 
$request['cat_id'],
-                               'coordinator'                   => 
$request['coordinator'],
-                               'descr'                                 => 
$request['descr'],
-                               'title'                                 => 
$request['title'],
-                               'budget'                                => 
(int)$request['budget'],
-                               'location_code'                 => 
$request['location_code'],
-                               'floor'                                 => 
$request['floor'],
-                               'branch_id'                             => 
$request['branch_id'],
-                               'd_safety'                              => 
$request['d_safety'],
-                               'd_aesthetics'                  => 
$request['d_aesthetics'],
-                               'd_indoor_climate'              => 
$request['d_indoor_climate'],
-                               'd_consequential_damage'=> 
$request['d_consequential_damage'],
-                               'd_user_gratification'  => 
$request['d_user_gratification'],
-                               'd_residential_environment'     => 
$request['d_residential_environment'],
-                               'c_safety'                              => 
$request['c_safety'],
-                               'c_aesthetics'                  => 
$request['c_aesthetics'],
-                               'c_indoor_climate'              => 
$request['c_indoor_climate'],
-                               'c_consequential_damage'=> 
$request['c_consequential_damage'],
-                               'c_user_gratification'  => 
$request['c_user_gratification'],
-                               'c_residential_environment'     => 
$request['c_residential_environment'],
-                               'p_safety'                              => 
$request['p_safety'],
-                               'p_aesthetics'                  => 
$request['p_aesthetics'],
-                               'p_indoor_climate'              => 
$request['p_indoor_climate'],
-                               'p_consequential_damage'=> 
$request['p_consequential_damage'],
-                               'p_user_gratification'  => 
$request['p_user_gratification'],
-                               'p_residential_environment'     => 
$request['p_residential_environment'],
-                               'authorities_demands'   => 
$request['authorities_demands'],
-                               'address'                               => 
$address
-                               );
-
-                       $value_set      = 
$this->bocommon->validate_db_update($value_set);
-
-                       $GLOBALS['phpgw']->db->begintrans();
-
-                       $GLOBALS['phpgw']->db->Execute("UPDATE fm_request set 
$value_set $vals WHERE id= '" . $request['request_id'] ."'");
-
-                       $this->update_score('',$request['request_id']);
-
-                       if($request['extra']['contact_phone'])
-                       {
-                               $GLOBALS['phpgw']->db->Execute("UPDATE 
fm_tenant set contact_phone='". $request['extra']['contact_phone']. "' where 
tenant_id='". $request['extra']['tenant_id']. "'");
-                       }
-
-                       if ($request['power_meter'] )
-                       {
-                               
$this->soproject->update_power_meter($request['power_meter'],$request['location_code'],$address);
-                       }
-
-                       if($GLOBALS['phpgw']->db->committrans())
-                       {
-                               $dbresult = 
$GLOBALS['phpgw']->db->Execute("SELECT status,category,coordinator FROM 
fm_request where id='" .$request['request_id']."'");
-
-
-                               $old_status = $dbresult->fields['status'];
-                               $old_categroy = $dbresult->fields['category'];
-                               $old_coordinator = 
$dbresult->fields['coordinator'];
-                               if ($old_status != $request['status'])
-                               {
-                                       
$this->historylog->add('S',$request['request_id'],$request['status']);
-                               }
-                               if ($old_categroy != $request['cat_id'])
-                               {
-                                       
$this->historylog->add('T',$request['request_id'],$request['cat_id']);
-                               }
-                               if ($old_coordinator != $request['coordinator'])
-                               {
-                                       
$this->historylog->add('C',$request['request_id'],$request['coordinator']);
-                               }
-
-                               $receipt['message'][] = 
array('msg'=>lang('request %1 has been edited',$request['request_id']));
-                       }
-                       else
-                       {
-                               $receipt['message'][] = 
array('msg'=>lang('request %1 has not been edited',$request['request_id']));
-                       }
-                       return $receipt;
-
-               }
-
-               function delete($request_id )
-               {
-                       $GLOBALS['phpgw']->db->Execute("DELETE FROM fm_request 
WHERE id='" . $request_id . "'");
-                       $GLOBALS['phpgw']->db->Execute("DELETE FROM 
fm_request_history  WHERE  history_record_id='" . $request_id   . "'");
-                       $GLOBALS['phpgw']->db->Execute("DELETE FROM 
fm_request_origin WHERE request_id='" . $request_id . "'");
-               }
-       }
-?>
+<?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_sorequest
+       {
+               function property_sorequest()
+               {
+                       $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->soproject        = 
CreateObject($this->currentapp.'_soproject');
+                       $this->historylog       = 
CreateObject($this->currentapp.'_historylog','request');
+                       $this->bocommon         = 
CreateObject($this->currentapp.'_bocommon');
+                       $this->socommon         = 
CreateObject($this->currentapp.'_socommon');
+
+                       $this->join                     = $this->socommon->join;
+               }
+
+               function select_category_workorder_list()
+               {
+
+                       $dbresult = $GLOBALS['phpgw']->db->Execute("SELECT id, 
descr FROM fm_workorder_category  ORDER BY descr ");
+
+                       $i = 0;
+                       while (!$dbresult->EOF)
+                       {
+                               $categories[$i]['id']                           
= $dbresult->fields['id'];
+                               $categories[$i]['name']                         
= stripslashes($dbresult->fields['descr']);
+                               $i++;
+                               $dbresult->MoveNext();
+                       }
+                       return $categories;
+               }
+
+               function read_priority_key()
+               {
+                       $dbresult = $GLOBALS['phpgw']->db->Execute("SELECT * 
FROM fm_request_priority_key");
+
+
+                       $priority_key['safety']                                 
        = $dbresult->fields['safety'];
+                       $priority_key['aesthetics']                             
        = $dbresult->fields['aesthetics'];
+                       $priority_key['indoor_climate']                         
= $dbresult->fields['indoor_climate'];
+                       $priority_key['consequential_damage']           = 
$dbresult->fields['consequential_damage'];
+                       $priority_key['user_gratification']                     
= $dbresult->fields['user_gratification'];
+                       $priority_key['residential_environment']        = 
$dbresult->fields['residential_environment'];
+                       $priority_key['authorities_demands']            = 
$dbresult->fields['authorities_demands'];
+
+                       return $priority_key;
+               }
+
+               function update_priority_key($values)
+               {
+
+                       
$values['safety']=str_replace(",",".",$values['safety']);
+                       
$values['aesthetics']=str_replace(",",".",$values['aesthetics']);
+                       
$values['indoor_climate']=str_replace(",",".",$values['indoor_climate']);
+                       
$values['consequential_damage']=str_replace(",",".",$values['consequential_damage']);
+                       
$values['user_gratification']=str_replace(",",".",$values['user_gratification']);
+                       
$values['residential_environment']=str_replace(",",".",$values['residential_environment']);
+                       
$values['authorities_demands']=str_replace(",",".",$values['authorities_demands']);
+
+
+                       $GLOBALS['phpgw']->db->Execute("UPDATE 
fm_request_priority_key set
+                               safety  ='" . $values['safety'] . "',
+                               aesthetics      ='" . $values['aesthetics'] . 
"',
+                               indoor_climate  ='" . $values['indoor_climate'] 
. "',
+                               consequential_damage    ='" . 
$values['consequential_damage'] . "',
+                               user_gratification      ='" . 
$values['user_gratification'] . "',
+                               residential_environment ='" . 
$values['residential_environment'] . "',
+                               authorities_demands     ='" . 
$values['authorities_demands'] ."'");
+
+                       $this->update_score($values,'');
+
+                       $receipt['message'][] = array('msg'=> lang('priority 
keys has been updated'));
+                       return $receipt;
+
+               }
+
+
+               function update_score($priority_key,$request_id='')
+               {
+//html_print_r($priority_key);
+                       if(!$priority_key)
+                       {
+                               $priority_key = $this->read_priority_key();
+                       }
+
+
+                       $safety                                         = 
$priority_key['safety'];
+                       $aesthetics                                     = 
$priority_key['aesthetics'];
+                       $indoor_climate                         = 
$priority_key['indoor_climate'];
+                       $consequential_damage           = 
$priority_key['consequential_damage'];
+                       $user_gratification                     = 
$priority_key['user_gratification'];
+                       $residential_environment        = 
$priority_key['residential_environment'];
+                       $authorities_demands            = 
$priority_key['authorities_demands'];
+
+                       if($request_id)
+                       {
+                               $where =" where id = $request_id";
+                       }
+
+                       $GLOBALS['phpgw']->db->Execute("UPDATE fm_request set 
score=($safety* (d_safety*p_safety*(c_safety+1)))"
+                       . "+ ($aesthetics* 
(d_aesthetics*p_aesthetics*(c_aesthetics+1)))"
+                       . "+ ($indoor_climate* 
(d_indoor_climate*p_indoor_climate*(c_indoor_climate+1)))"
+                       . "+ ($consequential_damage* 
(d_consequential_damage*p_consequential_damage*(c_consequential_damage+1)))"
+                       . "+ ($user_gratification* 
(d_user_gratification*p_user_gratification*(c_user_gratification+1)))"
+                       . "+ ($residential_environment* 
(d_residential_environment*p_residential_environment*(c_residential_environment+1)))"
+                       . "+ ($authorities_demands* authorities_demands) $where 
");
+
+               }
+
+
+               function read_single_request_category($id='')
+               {
+                       $dbresult = $GLOBALS['phpgw']->db->Execute("SELECT 
descr FROM fm_workorder_category where id='$id' ");
+
+                       return $dbresult->fields['descr'];
+               }
+
+               function select_status_list()
+               {
+                       $dbresult = $GLOBALS['phpgw']->db->Execute("SELECT id, 
descr FROM fm_request_status ORDER BY id ");
+
+                       $i = 0;
+                       while (!$dbresult->EOF)
+                       {
+                               $status_entries[$i]['id']                       
        = $dbresult->fields['id'];
+                               $status_entries[$i]['name']                     
        = stripslashes($dbresult->fields['descr']);
+                               $i++;
+                               $dbresult->MoveNext();
+                       }
+                       return $status_entries;
+               }
+
+               function select_branch_list()
+               {
+                       $dbresult = $GLOBALS['phpgw']->db->Execute("SELECT id, 
descr FROM fm_branch ORDER BY id ");
+
+                       $i = 0;
+                       while (!$dbresult->EOF)
+                       {
+                               $branch_entries[$i]['id']                       
        = $dbresult->fields['id'];
+                               $branch_entries[$i]['name']                     
        = stripslashes($dbresult->fields['descr']);
+                               $i++;
+                               $dbresult->MoveNext();
+                       }
+                       return $branch_entries;
+               }
+
+               function select_key_location_list()
+               {
+                       $dbresult = $GLOBALS['phpgw']->db->Execute("SELECT id, 
descr FROM fm_key_loc ORDER BY descr ");
+
+                       $i = 0;
+                       while (!$dbresult->EOF)
+                       {
+                               $key_location_entries[$i]['id']                 
        = $dbresult->fields['id'];
+                               $key_location_entries[$i]['name']               
        = stripslashes($dbresult->fields['descr']);
+                               $i++;
+                               $dbresult->MoveNext();
+                       }
+                       return $key_location_entries;
+               }
+
+               function read($data)
+               {
+                       if(is_array($data))
+                       {
+                               if ($data['start'])
+                               {
+                                       $start=$data['start'];
+                               }
+                               else
+                               {
+                                       $start=0;
+                               }
+                               $filter = 
(isset($data['filter'])?$data['filter']:'');
+                               $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);
+                               $status_id = 
(isset($data['status_id'])?$data['status_id']:0);
+                               $project_id = 
(isset($data['project_id'])?$data['project_id']:'');
+                       }
+
+                       $entity_table = 'fm_request';
+
+                       $cols .= $entity_table . '.location_code';
+                       $cols_return[] = 'location_code';
+
+                       $cols .= ",$entity_table.id as request_id";
+                       $cols_return[]                          = 'request_id';
+                       $uicols['input_type'][]         = 'text';
+                       $uicols['name'][]                       = 'request_id';
+                       $uicols['descr'][]                      = 
lang('Request');
+                       $uicols['statustext'][]         = lang('Request ID');
+
+                       $cols.= ",$entity_table.entry_date";
+                       $cols_return[]                          = 'entry_date';
+                       $uicols['input_type'][]         = 'text';
+                       $uicols['name'][]                       = 'entry_date';
+                       $uicols['descr'][]                      = lang('entry 
date');
+                       $uicols['statustext'][]         = lang('Request entry 
date');
+
+                       $cols.= ",$entity_table.title as title";
+                       $cols_return[]                          = 'title';
+                       $uicols['input_type'][]         = 'text';
+                       $uicols['name'][]                       = 'title';
+                       $uicols['descr'][]                      = lang('title');
+                       $uicols['statustext'][]         = lang('Request title');
+
+                       $cols.= ",$entity_table.coordinator";
+                       $cols_return[]                          = 'coordinator';
+                       $uicols['input_type'][]         = 'text';
+                       $uicols['name'][]                       = 'coordinator';
+                       $uicols['descr'][]                      = 
lang('Coordinator');
+                       $uicols['statustext'][]         = lang('Project 
coordinator');
+
+                       $cols.= ",$entity_table.score";
+                       $cols_return[]                          = 'score';
+                       $uicols['input_type'][]         = 'text';
+                       $uicols['name'][]                       = 'score';
+                       $uicols['descr'][]                      = lang('score');
+                       $uicols['statustext'][]         = lang('score');
+
+                       $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_request.id ASC';
+                       }
+
+                       $where = 'WHERE';
+                       if ($cat_id > 0)
+                       {
+                               $filtermethod .= " $where 
fm_request.category='$cat_id' ";
+                               $where = 'AND';
+                       }
+
+                       if ($status_id)
+                       {
+                               $filtermethod .= " $where  
fm_request.status='$status_id' ";
+                               $where = 'AND';
+                       }
+
+                       if ($filter)
+                       {
+                               $filtermethod .= " $where 
fm_request.coordinator='$filter' ";
+                               $where = 'AND';
+                       }
+
+                       if ($project_id)// lookup requests not already 
allocated to projects
+                       {
+                               $filtermethod .= " $where project_id is NULL ";
+                               $where = 'AND';
+                       }
+
+                       if($query)
+                       {
+                               $query = ereg_replace("'",'',$query);
+                               $query = ereg_replace('"','',$query);
+
+                               $querymethod = " $where (fm_request.title LIKE 
'%$query%' or fm_request.address LIKE '%$query%' or fm_request.location_code 
LIKE '%$query%')";
+                       }
+
+                       $sql .= " $filtermethod $querymethod";
+
+                       $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++)
+                               {
+                                       $request_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++)
+                               {
+                                       $request_list[$j]['loc' . ($m+1)] = 
$location[$m];
+                                       
$request_list[$j]['query_location']['loc' . ($m+1)]=implode("-", 
array_slice($location, 0, ($m+1)));
+                               }
+
+                               $j++;
+                               $dbresult->MoveNext();
+                       }
+//html_print_r($request_list);
+                       return $request_list;
+               }
+
+               function read_single($request_id)
+               {
+                       $sql = "SELECT * from fm_request where 
id='$request_id'";
+
+                       $dbresult = $GLOBALS['phpgw']->db->Execute($sql);
+
+                       if (!$dbresult->EOF)
+                       {
+                               $request['request_id']                          
        = $dbresult->fields['id'];
+                               $request['title']                               
                = $dbresult->fields['title'];
+                               $request['location_code']                       
        = $dbresult->fields['location_code'];
+                               $request['descr']                               
                = $dbresult->fields['descr'];
+                               $request['status']                              
                = $dbresult->fields['status'];
+                               $request['budget']                              
                = (int)$dbresult->fields['budget'];
+                               $request['tenant_id']                           
        = $dbresult->fields['tenant_id'];
+                               $request['owner']                               
                = $dbresult->fields['owner'];
+                               $request['coordinator']                         
        = $dbresult->fields['coordinator'];
+                               $request['access']                              
                = $dbresult->fields['access'];
+                               $request['start_date']                          
        = $dbresult->fields['start_date'];
+                               $request['end_date']                            
        = $dbresult->fields['end_date'];
+                               $request['cat_id']                              
                = $dbresult->fields['category'];
+
+                               $request['branch_id']                           
        = $dbresult->fields['branch_id'];
+                               $request['d_safety']                            
        = $dbresult->fields['d_safety'];
+                               $request['d_aesthetics']                        
        = $dbresult->fields['d_aesthetics'];
+                               $request['d_indoor_climate']                    
= $dbresult->fields['d_indoor_climate'];
+                               $request['d_consequential_damage']              
= $dbresult->fields['d_consequential_damage'];
+                               $request['d_user_gratification']                
= $dbresult->fields['d_user_gratification'];
+                               $request['d_residential_environment']   = 
$dbresult->fields['d_residential_environment'];
+                               $request['c_safety']                            
        = $dbresult->fields['c_safety'];
+                               $request['c_aesthetics']                        
        = $dbresult->fields['c_aesthetics'];
+                               $request['c_indoor_climate']                    
= $dbresult->fields['c_indoor_climate'];
+                               $request['c_consequential_damage']              
= $dbresult->fields['c_consequential_damage'];
+                               $request['c_user_gratification']                
= $dbresult->fields['c_user_gratification'];
+                               $request['c_residential_environment']   = 
$dbresult->fields['c_residential_environment'];
+                               $request['p_safety']                            
        = $dbresult->fields['p_safety'];
+                               $request['p_aesthetics']                        
        = $dbresult->fields['p_aesthetics'];
+                               $request['p_indoor_climate']                    
= $dbresult->fields['p_indoor_climate'];
+                               $request['p_consequential_damage']              
= $dbresult->fields['p_consequential_damage'];
+                               $request['p_user_gratification']                
= $dbresult->fields['p_user_gratification'];
+                               $request['p_residential_environment']   = 
$dbresult->fields['p_residential_environment'];
+                               $request['authorities_demands']                 
= $dbresult->fields['authorities_demands'];
+                               $request['score']                               
                = $dbresult->fields['score'];
+                               $request['p_num']                               
                = $dbresult->fields['p_num'];
+                               $request['p_entity_id']                         
        = $dbresult->fields['p_entity_id'];
+                               $request['p_cat_id']                            
        = $dbresult->fields['p_cat_id'];
+
+                               $request['power_meter'] = 
$this->soproject->get_power_meter($dbresult->fields['location_code']);
+                       }
+
+
+                       $sql = "SELECT * FROM fm_request_origin WHERE 
request_id='$request_id'";
+
+                       $dbresult = $GLOBALS['phpgw']->db->Execute($sql);
+
+                       if (!$dbresult->EOF)
+                       {
+                               $request['origin_id']   = 
$dbresult->fields['origin_id'];
+                               $request['origin']              = 
$dbresult->fields['origin'];
+                       }
+
+                       $sql = "SELECT * FROM fm_project_origin WHERE 
origin_id='$request_id' and origin ='request'";
+
+                       $dbresult = $GLOBALS['phpgw']->db->Execute($sql);
+
+                       while (!$dbresult->EOF)
+                       {
+                               $request['project_id'][]['id']  = 
$dbresult->fields['project_id'];
+                               $dbresult->MoveNext();
+                       }
+
+//html_print_r($request);
+                               return $request;
+               }
+
+               function request_workorder_data($request_id = '')
+               {
+                       $dbresult = $GLOBALS['phpgw']->db->Execute("SELECT 
budget, id as workorder_id, vendor_id from fm_workorder where 
request_id='$request_id'");
+                       while (!$dbresult->EOF)
+                       {
+                               $budget[] = array(
+                                       'workorder_id'  => 
$dbresult->fields['workorder_id'],
+                                       'budget'                => 
sprintf("%01.2f",$dbresult->fields['budget']),
+                                       'vendor_id'     => 
$dbresult->fields['vendor_id']
+                                       );
+                               $dbresult->MoveNext();
+                       }
+                       return $budget;
+               }
+
+               function branch_p_list($request_id = '')
+               {
+
+                       $dbresult = $GLOBALS['phpgw']->db->Execute("SELECT 
branch_id from fm_requestbranch WHERE request_id='$request_id' ");
+                       while (!$dbresult->EOF)
+                       {
+                               $selected[] = array('branch_id' => 
$dbresult->fields['branch_id']);
+                               $dbresult->MoveNext();
+                       }
+
+                       return $selected;
+               }
+
+               function increment_request_id()
+               {
+                       $GLOBALS['phpgw']->db->Execute("UPDATE fm_idgenerator 
set value = value + 1 where name = 'request'");
+               }
+
+               function next_id()
+               {
+                       $dbresult = $GLOBALS['phpgw']->db->Execute("SELECT 
value from fm_idgenerator where name = 'request'");
+
+                       $id = $dbresult->fields['value']+1;
+                       return $id;
+               }
+
+               function add($request)
+               {
+//html_print_r($request);
+                       while (is_array($request['location']) && 
list($input_name,$value) = each($request['location']))
+                       {
+                               if($value)
+                               {
+                                       $cols[] = $input_name;
+                                       $vals[] = $value;
+                               }
+                       }
+
+                       while (is_array($request['extra']) && 
list($input_name,$value) = each($request['extra']))
+                       {
+                               if($value)
+                               {
+                                       $cols[] = $input_name;
+                                       $vals[] = $value;
+                               }
+                       }
+
+                       if($cols)
+                       {
+                               $cols   = "," . implode(",", $cols);
+                               $vals   = ",'" . implode("','", $vals) . "'";
+                       }
+
+                       if($request['street_name'])
+                       {
+                               $address[]= $request['street_name'];
+                               $address[]= $request['street_number'];
+                               $address        = implode(" ", $address);
+                       }
+
+                       if(!$address)
+                       {
+                               $address = $request['location_name'];
+                       }
+
+                       $request['descr'] = 
$this->db->db_addslashes($request['descr']);
+                       $request['name'] = 
$this->db->db_addslashes($request['name']);
+                       $request['title'] = 
$this->db->db_addslashes($request['title']);
+
+                       $values= array(
+                               $request['request_id'],
+                               $request['title'],
+                               $this->account,
+                               $request['cat_id'],
+                               $request['descr'],
+                               $request['location_code'],
+                               $address,
+                               time(),
+                               $request['budget'],
+                               $request['status'],
+                               $request['branch_id'],
+                               $request['coordinator'],
+                               $request['d_safety'],
+                               $request['d_aesthetics'],
+                               $request['d_indoor_climate'],
+                               $request['d_consequential_damage'],
+                               $request['d_user_gratification'],
+                               $request['d_residential_environment'],
+                               $request['c_safety'],
+                               $request['c_aesthetics'],
+                               $request['c_indoor_climate'],
+                               $request['c_consequential_damage'],
+                               $request['c_user_gratification'],
+                               $request['c_residential_environment'],
+                               $request['p_safety'],
+                               $request['p_aesthetics'],
+                               $request['p_indoor_climate'],
+                               $request['p_consequential_damage'],
+                               $request['p_user_gratification'],
+                               $request['p_residential_environment'],
+                               $request['authorities_demands']);
+
+                       $values = $this->bocommon->validate_db_insert($values);
+
+                       $GLOBALS['phpgw']->db->begintrans();
+
+                       $GLOBALS['phpgw']->db->Execute("INSERT into fm_request 
(id,title,owner,category,descr,location_code,"
+                               . 
"address,entry_date,budget,status,branch_id,coordinator,"
+                               . 
"d_safety,d_aesthetics,d_indoor_climate,d_consequential_damage,d_user_gratification,d_residential_environment,"
+                               . 
"c_safety,c_aesthetics,c_indoor_climate,c_consequential_damage,c_user_gratification,c_residential_environment,"
+                               . 
"p_safety,p_aesthetics,p_indoor_climate,p_consequential_damage,p_user_gratification,p_residential_environment,authorities_demands
  $cols) "
+                               . "VALUES ($values $vals )");
+
+
+                       $this->update_score('',$request['request_id']);
+
+
+                       if($request['contact_phone'])
+                       {
+                               $GLOBALS['phpgw']->db->Execute("UPDATE 
fm_tenant set contact_phone='". $request['contact_phone']. "' where 
tenant_id='". $request['tenant_id']. "'");
+                       }
+
+                       if ($request['power_meter'] )
+                       {
+                               
$this->soproject->update_power_meter($request['power_meter'],$request['location_code'],$address);
+                       }
+
+                       if($request['origin'] && $request['origin_id'])
+                       {
+                               $GLOBALS['phpgw']->db->Execute("INSERT INTO  
fm_request_origin (origin,origin_id,request_id,entry_date) "
+                                       . "VALUES ('"
+                                       . $request['origin']. "','"
+                                       . $request['origin_id']. "',"
+                                       . $request['request_id']. ","
+                                       . time() . ")");
+                       }
+
+                       if($GLOBALS['phpgw']->db->committrans())
+                       {
+                               $this->increment_request_id();
+                               
$this->historylog->add('SO',$request['request_id'],$request['status']);
+                               
$this->historylog->add('TO',$request['request_id'],$request['cat_id']);
+                               
$this->historylog->add('CO',$request['request_id'],$request['coordinator']);
+                               $receipt['message'][] = 
array('msg'=>lang('request %1 has been saved',$request['request_id']));
+                       }
+                       else
+                       {
+                               $receipt['error'][] = 
array('msg'=>lang('request %1 has not been saved',$request['request_id']));
+                       }
+                       return $receipt;
+               }
+
+               function edit($request)
+               {
+                       while (is_array($request['location']) && 
list($input_name,$value) = each($request['location']))
+                       {
+                               $vals[] = "$input_name = '$value'";
+                       }
+
+                       while (is_array($request['extra']) && 
list($input_name,$value) = each($request['extra']))
+                       {
+                               $vals[] = "$input_name = '$value'";
+                       }
+
+                       if($vals)
+                       {
+                               $vals   = "," . implode(",",$vals);
+                       }
+
+                       if($request['street_name'])
+                       {
+                               $address[]= $request['street_name'];
+                               $address[]= $request['street_number'];
+                               $address        = implode(" ", $address);
+                       }
+
+                       if(!$address)
+                       {
+                               $address = $request['location_name'];
+                       }
+
+
+                       $request['descr'] = 
$this->db->db_addslashes($request['descr']);
+                       $request['name'] = 
$this->db->db_addslashes($request['name']);
+                       $request['title'] = 
$this->db->db_addslashes($request['title']);
+//html_print_r($request);
+
+                       $value_set=array(
+                               'status'                                => 
$request['status'],
+                               'category'                              => 
$request['cat_id'],
+                               'coordinator'                   => 
$request['coordinator'],
+                               'descr'                                 => 
$request['descr'],
+                               'title'                                 => 
$request['title'],
+                               'budget'                                => 
(int)$request['budget'],
+                               'location_code'                 => 
$request['location_code'],
+                               'floor'                                 => 
$request['floor'],
+                               'branch_id'                             => 
$request['branch_id'],
+                               'd_safety'                              => 
$request['d_safety'],
+                               'd_aesthetics'                  => 
$request['d_aesthetics'],
+                               'd_indoor_climate'              => 
$request['d_indoor_climate'],
+                               'd_consequential_damage'=> 
$request['d_consequential_damage'],
+                               'd_user_gratification'  => 
$request['d_user_gratification'],
+                               'd_residential_environment'     => 
$request['d_residential_environment'],
+                               'c_safety'                              => 
$request['c_safety'],
+                               'c_aesthetics'                  => 
$request['c_aesthetics'],
+                               'c_indoor_climate'              => 
$request['c_indoor_climate'],
+                               'c_consequential_damage'=> 
$request['c_consequential_damage'],
+                               'c_user_gratification'  => 
$request['c_user_gratification'],
+                               'c_residential_environment'     => 
$request['c_residential_environment'],
+                               'p_safety'                              => 
$request['p_safety'],
+                               'p_aesthetics'                  => 
$request['p_aesthetics'],
+                               'p_indoor_climate'              => 
$request['p_indoor_climate'],
+                               'p_consequential_damage'=> 
$request['p_consequential_damage'],
+                               'p_user_gratification'  => 
$request['p_user_gratification'],
+                               'p_residential_environment'     => 
$request['p_residential_environment'],
+                               'authorities_demands'   => 
$request['authorities_demands'],
+                               'address'                               => 
$address
+                               );
+
+                       $value_set      = 
$this->bocommon->validate_db_update($value_set);
+
+                       $GLOBALS['phpgw']->db->begintrans();
+
+                       $GLOBALS['phpgw']->db->Execute("UPDATE fm_request set 
$value_set $vals WHERE id= '" . $request['request_id'] ."'");
+
+                       $this->update_score('',$request['request_id']);
+
+                       if($request['extra']['contact_phone'])
+                       {
+                               $GLOBALS['phpgw']->db->Execute("UPDATE 
fm_tenant set contact_phone='". $request['extra']['contact_phone']. "' where 
tenant_id='". $request['extra']['tenant_id']. "'");
+                       }
+
+                       if ($request['power_meter'] )
+                       {
+                               
$this->soproject->update_power_meter($request['power_meter'],$request['location_code'],$address);
+                       }
+
+                       if($GLOBALS['phpgw']->db->committrans())
+                       {
+                               $dbresult = 
$GLOBALS['phpgw']->db->Execute("SELECT status,category,coordinator FROM 
fm_request where id='" .$request['request_id']."'");
+
+
+                               $old_status = $dbresult->fields['status'];
+                               $old_categroy = $dbresult->fields['category'];
+                               $old_coordinator = 
$dbresult->fields['coordinator'];
+                               if ($old_status != $request['status'])
+                               {
+                                       
$this->historylog->add('S',$request['request_id'],$request['status']);
+                               }
+                               if ($old_categroy != $request['cat_id'])
+                               {
+                                       
$this->historylog->add('T',$request['request_id'],$request['cat_id']);
+                               }
+                               if ($old_coordinator != $request['coordinator'])
+                               {
+                                       
$this->historylog->add('C',$request['request_id'],$request['coordinator']);
+                               }
+
+                               $receipt['message'][] = 
array('msg'=>lang('request %1 has been edited',$request['request_id']));
+                       }
+                       else
+                       {
+                               $receipt['message'][] = 
array('msg'=>lang('request %1 has not been edited',$request['request_id']));
+                       }
+                       return $receipt;
+
+               }
+
+               function delete($request_id )
+               {
+                       $GLOBALS['phpgw']->db->Execute("DELETE FROM fm_request 
WHERE id='" . $request_id . "'");
+                       $GLOBALS['phpgw']->db->Execute("DELETE FROM 
fm_request_history  WHERE  history_record_id='" . $request_id   . "'");
+                       $GLOBALS['phpgw']->db->Execute("DELETE FROM 
fm_request_origin WHERE request_id='" . $request_id . "'");
+               }
+       }
+?>




reply via email to

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