[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Phpgroupware-cvs] property/inc/class.someter.inc.php, 1.2
From: |
nomail |
Subject: |
[Phpgroupware-cvs] property/inc/class.someter.inc.php, 1.2 |
Date: |
Wed, 2 Jun 2004 20:54:28 +0200 |
Update of /property/inc
Added Files:
Branch:
class.someter.inc.php
date: 2004/06/02 18:54:28; author: sigurdne; state: Exp; lines: +282 -0
Log Message:
no message
=====================================================================
<?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 someter
{
function someter()
{
$this->currentapp =
$GLOBALS['phpgw_info']['flags']['currentapp'];
$this->db = $GLOBALS['phpgw']->db;
$this->db2 = $this->db;
$this->account =
$GLOBALS['phpgw_info']['user']['account_id'];
$this->bocommon =
CreateObject($this->currentapp.'.bocommon');
$this->join = $this->bocommon->join;
}
function get_category_list()
{
$this->db->query("SELECT id, descr FROM
fm_meter_category ORDER BY descr ");
$i = 0;
while ($this->db->next_record())
{
$categories[$i]['id']
= $this->db->f('id');
$categories[$i]['name']
= stripslashes($this->db->f('descr'));
$i++;
}
return $categories;
}
function check_meter_num($num='')
{
$this->db->query("SELECT count(*) FROM fm_meter where
num='$num'");
$this->db->next_record();
if ( $this->db->f(0))
{
return True;
}
}
function read($data)
{
if(is_array($data))
{
if ($data['start'])
{
$start=$data['start'];
}
else
{
$start=0;
}
$filter =
(isset($data['filter'])?$data['filter']:'none');
$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);
}
$entity_table = 'fm_meter';
$cols .= $entity_table . '.location_code';
$cols_return[] = 'location_code';
$cols .= ",$entity_table.id as meter_id";
$cols_return[] = 'meter_id';
$cols .= ",$entity_table.num as num";
$cols_return[] = 'num';
$uicols['input_type'][] = 'text';
$uicols['name'][] = 'num';
$uicols['descr'][] = lang('Meter
ID');
$uicols['statustext'][] = lang('Meter ID');
$cols .= ",$entity_table.name ";
$cols_return[] = 'name';
$uicols['input_type'][] = 'text';
$uicols['name'][] = 'name';
$uicols['descr'][] = lang('Name');
$uicols['statustext'][] = lang('Name');
$cols .= ",fm_meter_category.descr as meter_type";
$cols_return[] = 'meter_type';
$uicols['input_type'][] = 'text';
$uicols['name'][] = 'meter_type';
$uicols['descr'][] = lang('Meter
Type');
$uicols['statustext'][] = lang('Meter Type');
$joinmethod .= " $this->join fm_meter_category ON
($entity_table.category = fm_meter_category.id))";
$paranthesis .='(';
$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 $entity_table.$order
$sort";
}
else
{
$ordermethod = " order by
$entity_table.location_code asc";
}
$where = 'WHERE';
if ($cat_id)
{
$filtermethod .= " $where
fm_meter.category='$cat_id' ";
$where = 'AND';
}
if($query)
{
$query = ereg_replace("'",'',$query);
$query = ereg_replace('"','',$query);
$querymethod = " $where (fm_meter.name LIKE
'%$query%' OR fm_meter.num LIKE '%$query%' OR fm_meter.location_code LIKE
'%$query%' OR fm_meter.address LIKE '%$query%')";
}
$sql .= " $filtermethod $querymethod";
//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;
$this->db2->query($sql,__LINE__,__FILE__);
$this->total_records = $this->db2->num_rows();
$this->db->limit_query($sql .
$ordermethod,$start,__LINE__,__FILE__);
$j=0;
while ($this->db->next_record())
{
for ($i=0;$i<count($cols_return);$i++)
{
$meter[$j][$cols_return[$i]] =
$this->db->f($cols_return[$i]);
}
$location_code= $this->db->f('location_code');
$location = split('-',$location_code);
for ($m=0;$m<count($location);$m++)
{
$meter[$j]['loc' . ($m+1)] =
$location[$m];
$meter[$j]['query_location']['loc' .
($m+1)]=implode("-", array_slice($location, 0, ($m+1)));
}
$j++;
}
return $meter;
}
function read_single($meter_id)
{
$sql = "SELECT * FROM fm_meter where id='$meter_id'";
$this->db->query($sql,__LINE__,__FILE__);
if ($this->db->next_record())
{
$meter['meter_id'] =
$this->db->f('id');
$meter['num'] =
$this->db->f('num');
$meter['name'] =
stripslashes($this->db->f('name'));
$meter['remark'] =
stripslashes($this->db->f('remark'));
$meter['cat_id'] =
$this->db->f('category');
$meter['location_code'] =
$this->db->f('location_code');
$meter['p_num'] =
$this->db->f('p_num');
$meter['p_entity_id'] =
$this->db->f('p_entity_id');
$meter['p_cat_id'] =
$this->db->f('p_cat_id');
}
return $meter;
}
function add($meter)
{
while (is_array($meter['location']) &&
list($input_name,$value) = each($meter['location']))
{
if($value)
{
$cols[] = $input_name;
$vals[] = $value;
}
}
if($cols)
{
$cols = "," . implode(",", $cols);
$vals = ",'" . implode("','", $vals) . "'";
}
if($meter['street_name'])
{
$address[]= $meter['street_name'];
$address[]= $meter['street_number'];
$address = implode(" ", $address);
}
if(!$address)
{
$address = $meter['location_name'];
}
$meter['remark'] =
$this->db->db_addslashes($meter['remark']);
$this->db->query("INSERT INTO fm_meter (location_code,
num,user_id,entry_date,name,address,category,remark $cols ) "
. "VALUES ('" . $meter['location_code'] . "','"
. $meter['num'] . "','" . $this->account . "','" . time() . "','" .
$meter['name']
. "','" . $address ."','" . $meter['cat_id']
."','" . $meter['remark']. "' $vals )",__LINE__,__FILE__);
$meter_id =
$this->db->get_last_insert_id('fm_meter','id');
$receipt['meter_id'] = $meter_id;
$receipt['message'][]=array('msg'=>lang('Meter %1 has
been saved',$meter['num']));
return $receipt;
}
function edit($meter)
{
while (is_array($meter['location']) &&
list($input_name,$value) = each($meter['location']))
{
$vals[] = "$input_name = '$value'";
}
if($vals)
{
$vals = "," . implode(",",$vals);
}
if($meter['street_name'])
{
$address[]= $meter['street_name'];
$address[]= $meter['street_number'];
$address = implode(" ", $address);
}
if(!$address)
{
$address = $meter['location_name'];
}
$meter['remark'] =
$this->db->db_addslashes($meter['remark']);
$this->db->query("UPDATE fm_meter set name='" .
$meter['name'] . "', entry_date='" . time() . "', category='"
. $meter['cat_id'] .
"', location_code='" . $meter['location_code'] . "', address='" . $address .
"', remark='" . $meter['remark']
. "' $vals WHERE id='"
. $meter['meter_id'] . "'",__LINE__,__FILE__);
$receipt['message'][]=array('msg'=>lang('Meter %1 has
been edited',$meter['num']));
return $receipt;
}
function delete($meter_id)
{
$this->db->query("DELETE FROM fm_meter WHERE id='" .
$meter_id ."'",__LINE__,__FILE__);
}
}
?>