[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Phpgroupware-cvs] property/class.sotemplate.php, 1.1.1.3
From: |
nomail |
Subject: |
[Phpgroupware-cvs] property/class.sotemplate.php, 1.1.1.3 |
Date: |
Fri, 21 May 2004 16:02:00 -0000 |
Update of /property
Modified Files:
Branch:
class.sotemplate.php
date: 2004/04/23 21:26:33; author: sigurdne; state: Exp; lines: +481 -481
Log Message:
no message
=====================================================================
Index: property/class.sotemplate.php
diff -u property/class.sotemplate.php:1.1.1.2
property/class.sotemplate.php:1.1.1.3
--- property/class.sotemplate.php:1.1.1.2 Fri Apr 23 20:26:09 2004
+++ property/class.sotemplate.php Fri Apr 23 21:26:33 2004
@@ -1,481 +1,481 @@
-<?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_sotemplate
- {
-
- function property_sotemplate()
- {
- $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->socommon =
CreateObject($this->currentapp.'_socommon');
-
- $this->join = $this->socommon->join;
- $this->left_join = $this->socommon->left_join;
- }
-
- 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']:'');
- $chapter_id =
(isset($data['chapter_id'])?$data['chapter_id']:0);
- $allrows =
(isset($data['allrows'])?$data['allrows']:'');
- $template_id =
(isset($data['template_id'])?$data['template_id']:0);
- }
-
- if ($order)
- {
- $ordermethod = " order by $order $sort";
- }
- else
- {
- $ordermethod = ' order by fm_template.id desc';
- }
-
- $where= 'WHERE';
-
- if ($chapter_id > 0)
- {
- $filtermethod .= " $where
chapter_id='$chapter_id' ";
- $where= 'AND';
- }
-
- if ($filter)
- {
- $filtermethod .= " $where
fm_template.owner='$filter' ";
- $where= 'AND';
- }
-
-
- if($query)
- {
- $query = ereg_replace("'",'',$query);
- $query = ereg_replace('"','',$query);
-
- $querymethod = " $where (fm_template.descr LIKE
'%$query%')";
- }
-
- $sql = "SELECT
fm_template.id,fm_template.descr,fm_template.name,fm_template.owner,fm_template.entry_date,"
- . " fm_chapter.descr as chapter FROM fm_template
$this->left_join fm_chapter on fm_template.chapter_id=fm_chapter.id"
- . " $filtermethod $querymethod";
-
- $dbresult2 = $GLOBALS['phpgw']->db->Execute($sql);
- $this->total_records = $dbresult2->_numOfRows;
-
- $maxmatchs = 15;
-
- if(!$allrows)
- {
- $dbresult =
$GLOBALS['phpgw']->db->SelectLimit($sql . $ordermethod,$maxmatchs,$start);
-
- }
- else
- {
- $dbresult = $GLOBALS['phpgw']->db->Execute($sql
. $ordermethod);
- }
-
- while (!$dbresult->EOF)
- {
- $template_list[] = array
- (
- 'template_id' =>
$dbresult->fields['id'],
- 'name' =>
stripslashes($dbresult->fields['name']),
- 'descr' =>
stripslashes($dbresult->fields['descr']),
- 'owner' =>
$dbresult->fields['owner'],
- 'entry_date' =>
$dbresult->fields['entry_date'],
- 'chapter' =>
$dbresult->fields['chapter']
- );
- $dbresult->MoveNext();
- }
- return $template_list;
- }
-
- function read_template_hour($data)
- {
-
- if(is_array($data))
- {
- if ($data['start'])
- {
- $start=$data['start'];
- }
- else
- {
- $start=0;
- }
- $query =
(isset($data['query'])?$data['query']:'');
- $sort =
(isset($data['sort'])?$data['sort']:'DESC');
- $order =
(isset($data['order'])?$data['order']:'');
- $chapter_id =
(isset($data['chapter_id'])?$data['chapter_id']:0);
- $allrows =
(isset($data['allrows'])?$data['allrows']:'');
- $template_id =
(isset($data['template_id'])?$data['template_id']:0);
- }
-
- if ($order)
- {
- $ordermethod = " order by $order $sort";
- }
- else
- {
- $ordermethod = ' order by record ';
- }
-
-
- $filtermethod .= " where template_id='$template_id' ";
-
- if($query)
- {
- $query = ereg_replace("'",'',$query);
- $query = ereg_replace('"','',$query);
-
- $querymethod = " AND (hours_descr LIKE
'%$query%' or fm_template_hours.remark LIKE '%$query%' or ns3420_id LIKE
'%$query%')";
- }
-
- $sql = "SELECT fm_template_hours.*, chapter_id from
fm_template_hours $this->join fm_template on
fm_template.id=fm_template_hours.template_id $filtermethod $querymethod";
-
- $dbresult2 = $GLOBALS['phpgw']->db->Execute($sql);
- $this->total_records = $dbresult2->_numOfRows;
-
- $maxmatchs = 15;
-
- if(!$allrows)
- {
- $dbresult =
$GLOBALS['phpgw']->db->SelectLimit($sql . $ordermethod,$maxmatchs,$start);
-
- }
- else
- {
- $dbresult = $GLOBALS['phpgw']->db->Execute($sql
. $ordermethod);
- }
-
- while (!$dbresult->EOF)
- {
- $hour_list[] = array
- (
- 'hour_id' =>
$dbresult->fields['id'],
- 'chapter_id' =>
$dbresult->fields['chapter_id'],
- 'activity_num' =>
$dbresult->fields['activity_num'],
- 'hours_descr' =>
stripslashes($dbresult->fields['hours_descr']),
- 'remark' =>
stripslashes($dbresult->fields['remark']),
- 'grouping_id' =>
$dbresult->fields['grouping_id'],
- 'grouping_descr' =>
$dbresult->fields['grouping_descr'],
- 'ns3420_id' =>
$dbresult->fields['ns3420_id'],
- 'tolerance' =>
$dbresult->fields['tolerance'],
- 'activity_id' =>
$dbresult->fields['activity_id'],
- 'unit' =>
$dbresult->fields['unit'],
- 'record' =>
$dbresult->fields['record'],
- 'cost' =>
$dbresult->fields['cost'],
- 'billperae' =>
$dbresult->fields['billperae'],
- 'building_part' =>
$dbresult->fields['building_part'],
- 'dim_d' =>
$dbresult->fields['dim_d']
- );
- $dbresult->MoveNext();
- }
- return $hour_list;
- }
-
- function read_single_template($template_id)
- {
- $sql = "SELECT * FROM fm_template where
id='$template_id'";
-
- $dbresult = $GLOBALS['phpgw']->db->Execute($sql);
-
- if (!$dbresult->EOF)
- {
- $template['template_id'] =
$dbresult->fields['id'];
- $template['name']
= stripslashes($dbresult->fields['name']);
- $template['descr']
= stripslashes($dbresult->fields['descr']);
- $template['chapter_id'] =
(int)$dbresult->fields['chapter_id'];
- }
- return $template;
- }
-
- function read_single_hour($hour_id)
- {
- $sql = "SELECT * from fm_template_hours where
id='$hour_id'";
-
- $dbresult = $GLOBALS['phpgw']->db->Execute($sql);
-
- if (!$dbresult->EOF)
- {
- $hour['hour_id']
= $dbresult->fields['id'];
- $hour['record']
= $dbresult->fields['record'];
- $hour['activity_id'] =
$dbresult->fields['activity_id'];
- $hour['activity_num'] =
$dbresult->fields['activity_num'];
- $hour['grouping_id'] =
$dbresult->fields['grouping_id'];
- $hour['hours_descr'] =
$dbresult->fields['hours_descr'];
- $hour['remark']
= $dbresult->fields['remark'];
- $hour['billperae']
= $dbresult->fields['billperae'];
- $hour['unit']
= $dbresult->fields['unit'];
- $hour['ns3420_id']
= $dbresult->fields['ns3420_id'];
- $hour['tolerance_id'] =
(int)$dbresult->fields['tolerance'];
- $hour['building_part_id'] =
(int)$dbresult->fields['building_part'];
- $hour['quantity']
= $dbresult->fields['quantity'];
- $hour['cost']
= $dbresult->fields['cost'];
- $hour['dim_d']
= $dbresult->fields['dim_d'];
- }
-
- return $hour;
- }
-
- function next_record($template_id)
- {
-
- $dbresult = $GLOBALS['phpgw']->db->Execute("SELECT
max(record) as record FROM fm_template_hours where template_id='$template_id'");
-
- $record = $dbresult->fields['record']+1;
- return $record;
-
- }
-
- function add_custom_hour($hour,$template_id)
- {
-
- $hour['record'] = $this->next_record($template_id);
-
- $GLOBALS['phpgw']->db->Execute("UPDATE fm_template set
- chapter_id ='" . $hour['chapter_id'] . "'
WHERE id= '$template_id'");
-
- if($hour['grouping_id'])
- {
- $dbresult =
$GLOBALS['phpgw']->db->Execute("SELECT grouping_descr , max(record) as record
FROM fm_template_hours where grouping_id='" .$hour['grouping_id'] . "' and
template_id= '$template_id' GROUP by grouping_descr");
-
- $hour['grouping_descr'] =
$dbresult->fields['grouping_descr'];
- }
-
- if($hour['new_grouping'])
- {
- $dbresult =
$GLOBALS['phpgw']->db->Execute("SELECT grouping_id FROM fm_template_hours where
grouping_descr ='" .$hour['new_grouping'] . "' and template_id=
'$template_id'");
-
- if ( $dbresult->fields['grouping_id'])
- {
- $hour['grouping_id'] =
$dbresult->fields['grouping_id'];
- }
- else
- {
- $dbresult =
$GLOBALS['phpgw']->db->Execute("SELECT max(grouping_id) as grouping_id FROM
fm_template_hours where template_id= '$template_id'");
-
- $hour['grouping_id'] =
$dbresult->fields['grouping_id']+1;
- }
-
- $hour['grouping_descr'] = $hour['new_grouping'];
- }
-
- $GLOBALS['phpgw']->db->Execute("INSERT into
fm_template_hours
(owner,hours_descr,unit,cost,quantity,billperae,ns3420_id,dim_d,"
- . "
grouping_id,grouping_descr,record,building_part,tolerance,remark,entry_date,template_id)
"
- . " values ('" .
- $this->account . "','" .
- $hour['descr'] . "','" .
- $hour['unit'] . "','" .
- $hour['cost'] . "','" .
- $hour['quantity'] . "','" .
- $hour['billperae'] . "','" .
- $hour['ns3420_id'] . "','" .
- $hour['dim_d'] . "','" .
- $hour['grouping_id'] . "','" .
- $hour['grouping_descr'] . "','" .
- $hour['record'] . "','" .
- $hour['building_part_id'] . "','" .
- $hour['tolerance_id'] . "','" .
- $hour['remark'] . "','" .
- time() . "','" .
- $template_id . "')");
-
- $receipt['hour_id'] =
$this->db->get_last_insert_id('fm_template_hours','id');
-
- $receipt['message'][] = array('msg'=>lang('hour %1 is
added!',$hour['record']));
-
- return $receipt;
- }
-
-
- function edit_hour($hour,$template_id)
- {
-
- $hour['descr'] =
$this->db->db_addslashes($hour['descr']);
- $hour['remark'] =
$this->db->db_addslashes($hour['remark']);
-
- $GLOBALS['phpgw']->db->Execute("UPDATE fm_template set
- chapter_id ='" . $hour['chapter_id'] . "'
WHERE id= '$template_id'");
-
- if($hour['new_grouping'])
- {
- $dbresult =
$GLOBALS['phpgw']->db->Execute("SELECT grouping_id FROM fm_template_hours where
grouping_descr ='" .$hour['new_grouping'] . "' and template_id=
'$template_id'");
-
- if ( $dbresult->fields['grouping_id'])
- {
- $hour['grouping_id'] =
$dbresult->fields['grouping_id'];
- }
- else
- {
-
- $GLOBALS['phpgw']->db->Execute("UPDATE
fm_template_hours set grouping_id = NULL WHERE id ='" .$hour['hour_id'] . "'");
- $dbresult =
$GLOBALS['phpgw']->db->Execute("SELECT count(grouping_id) as num_grouping FROM
fm_template_hours where template_id= '$template_id' and grouping_id >0 ");
-
- if
($dbresult->fields['num_grouping']==1)
- {
- $hour['grouping_id']=1;
- }
- else
- {
- $dbresult =
$GLOBALS['phpgw']->db->Execute("SELECT max(grouping_id) as grouping_id FROM
fm_template_hours where template_id= '$template_id'");
-
- $hour['grouping_id'] =
$dbresult->fields['grouping_id']+1;
- }
- }
- $hour['grouping_descr'] = $hour['new_grouping'];
- }
- else
- {
- $dbresult =
$GLOBALS['phpgw']->db->Execute("SELECT grouping_id,grouping_descr FROM
fm_template_hours where id ='" .$hour['hour_id'] . "'");
-
- $old_grouping_id =
$dbresult->fields['grouping_id'];
-
- if ( $old_grouping_id == $hour['grouping_id'])
- {
-
- $hour['grouping_descr'] =
$dbresult->fields['grouping_descr'];
- }
- else
- {
- $dbresult =
$GLOBALS['phpgw']->db->Execute("SELECT grouping_descr , max(record) as record
FROM fm_template_hours where grouping_id='" .$hour['grouping_id'] . "' and
template_id= '$template_id' GROUP by grouping_descr");
-
- if($dbresult->fields['grouping_descr'])
- {
- $hour['grouping_descr'] =
$dbresult->fields['grouping_descr'];
- }
- else
- {
- $hour['grouping_id']='';
- $hour['grouping_descr']='';
- }
-
- }
- }
-
- $dbresult = $GLOBALS['phpgw']->db->Execute("SELECT
record FROM fm_template_hours where id ='" .$hour['hour_id'] . "'");
-
- $hour['record'] = $dbresult->fields['record'];
-
- $GLOBALS['phpgw']->db->Execute("UPDATE
fm_template_hours set
- hours_descr ='" .
$hour['descr'] . "',
- remark ='" .
$hour['remark'] . "',
- billperae ='" .
$hour['billperae'] . "',
- unit ='" .
$hour['unit'] . "',
- quantity ='" .
$hour['quantity'] . "',
- cost ='" .
$hour['cost'] . "',
- ns3420_id ='" .
$hour['ns3420_id'] . "',
- tolerance ='" .
$hour['tolerance_id'] . "',
- building_part ='" .
$hour['building_part_id'] . "',
- dim_d ='" .
$hour['dim_d'] . "',
- grouping_id ='" .
$hour['grouping_id'] . "',
- grouping_descr ='" .
$hour['grouping_descr']
- . "' WHERE id= '" . $hour['hour_id'] ."'");
-
- $receipt['hour_id'] = $hour['hour_id'];
- $receipt['message'][] = array('msg'=>lang('hour %1 has
been edited',$hour['record']));
- return $receipt;
-
- }
-
- function get_grouping_list($template_id='')
- {
- $dbresult = $GLOBALS['phpgw']->db->Execute("SELECT
grouping_id, grouping_descr FROM fm_template_hours where
template_id='$template_id' and grouping_id >0 group by grouping_id,
grouping_descr");
-
- $i = 0;
- while (!$dbresult->EOF)
- {
- $grouping_entries[$i]['id']
= $dbresult->fields['grouping_id'];
- $grouping_entries[$i]['name']
= stripslashes($dbresult->fields['grouping_descr']);
- $i++;
- $dbresult->MoveNext();
- }
- return $grouping_entries;
- }
-
- function add_template($values)
- {
-
- $values['name'] =
$this->db->db_addslashes($values['name']);
-
- $GLOBALS['phpgw']->db->Execute("INSERT into fm_template
(owner,name,descr,chapter_id,entry_date) "
- . " values ('" .
- $this->account . "','" .
- $values['name'] . "','" .
- $values['descr'] . "','" .
- $values['chapter_id'] . "','" .
- time() . "')");
-
- $template_id =
$this->db->get_last_insert_id('fm_template','id');
-
- $receipt['template_id'] = $template_id;
- $receipt['message'][] = array('msg'=>lang('template %1
is added',$values['name']));
- return $receipt;
- }
-
- function edit_template($values)
- {
- $values['name'] =
$this->db->db_addslashes($values['name']);
- $values['descr'] =
$this->db->db_addslashes($values['descr']);
-
- $GLOBALS['phpgw']->db->Execute("UPDATE fm_template set
name='" . $values['name'] . "', descr='" . $values['descr'] . "', chapter_id='"
- .
(int)$values['chapter_id']
- . "' WHERE id='" .
$values['template_id'] . "'");
-
- $receipt['message'][]=array('msg'=>lang('Property has
been edited'));
- return $receipt;
- }
-
- function delete($id)
- {
- $GLOBALS['phpgw']->db->Execute("DELETE FROM fm_template
WHERE id='$id'");
- $GLOBALS['phpgw']->db->Execute("DELETE FROM
fm_template_hours WHERE template_id='$id'");
- }
-
- function delete_hour($hour_id,$template_id )
- {
- $dbresult = $GLOBALS['phpgw']->db->Execute("SELECT
record FROM fm_template_hours where id ='$hour_id'");
-
- $old_record = $dbresult->fields['record'];
-
- $GLOBALS['phpgw']->db->Execute("DELETE FROM
fm_template_hours WHERE id='" . $hour_id . "'");
- if($old_record)
- {
- $GLOBALS['phpgw']->db->Execute("UPDATE
fm_template_hours set record = record - 1 where template_id=
'$template_id' and record > $old_record ");
- }
-
- $receipt['message'][] = array('msg'=>lang('hour %1 has
been deleted',$hour_id));
- return $receipt;
-
- }
- }
-?>
+<?php
+
/**************************************************************************\
+ * phpGroupWare - property
*
+ * http://www.phpgroupware.org
*
+ *
*
+ * Facilities Management
*
+ * Written by Sigurd Nes [sigurdne at online.no]
*
+ *
------------------------------------------------------------------------ *
+ * Copyright 2000 - 2003 Free Software Foundation, Inc
*
+ * This program is part of the GNU project, see http://www.gnu.org/
*
+ *
------------------------------------------------------------------------ *
+ * This program is free software; you can redistribute it and/or modify
it *
+ * under the terms of the GNU General Public License as published by the
*
+ * Free Software Foundation; either version 2 of the License, or (at
your *
+ * option) any later version.
*
+
\**************************************************************************/
+
+ class property_sotemplate
+ {
+
+ function property_sotemplate()
+ {
+ $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->socommon =
CreateObject($this->currentapp.'_socommon');
+
+ $this->join = $this->socommon->join;
+ $this->left_join = $this->socommon->left_join;
+ }
+
+ 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']:'');
+ $chapter_id =
(isset($data['chapter_id'])?$data['chapter_id']:0);
+ $allrows =
(isset($data['allrows'])?$data['allrows']:'');
+ $template_id =
(isset($data['template_id'])?$data['template_id']:0);
+ }
+
+ if ($order)
+ {
+ $ordermethod = " order by $order $sort";
+ }
+ else
+ {
+ $ordermethod = ' order by fm_template.id desc';
+ }
+
+ $where= 'WHERE';
+
+ if ($chapter_id > 0)
+ {
+ $filtermethod .= " $where
chapter_id='$chapter_id' ";
+ $where= 'AND';
+ }
+
+ if ($filter)
+ {
+ $filtermethod .= " $where
fm_template.owner='$filter' ";
+ $where= 'AND';
+ }
+
+
+ if($query)
+ {
+ $query = ereg_replace("'",'',$query);
+ $query = ereg_replace('"','',$query);
+
+ $querymethod = " $where (fm_template.descr LIKE
'%$query%')";
+ }
+
+ $sql = "SELECT
fm_template.id,fm_template.descr,fm_template.name,fm_template.owner,fm_template.entry_date,"
+ . " fm_chapter.descr as chapter FROM fm_template
$this->left_join fm_chapter on fm_template.chapter_id=fm_chapter.id"
+ . " $filtermethod $querymethod";
+
+ $dbresult2 = $GLOBALS['phpgw']->db->Execute($sql);
+ $this->total_records = $dbresult2->_numOfRows;
+
+ $maxmatchs = 15;
+
+ if(!$allrows)
+ {
+ $dbresult =
$GLOBALS['phpgw']->db->SelectLimit($sql . $ordermethod,$maxmatchs,$start);
+
+ }
+ else
+ {
+ $dbresult = $GLOBALS['phpgw']->db->Execute($sql
. $ordermethod);
+ }
+
+ while (!$dbresult->EOF)
+ {
+ $template_list[] = array
+ (
+ 'template_id' =>
$dbresult->fields['id'],
+ 'name' =>
stripslashes($dbresult->fields['name']),
+ 'descr' =>
stripslashes($dbresult->fields['descr']),
+ 'owner' =>
$dbresult->fields['owner'],
+ 'entry_date' =>
$dbresult->fields['entry_date'],
+ 'chapter' =>
$dbresult->fields['chapter']
+ );
+ $dbresult->MoveNext();
+ }
+ return $template_list;
+ }
+
+ function read_template_hour($data)
+ {
+
+ if(is_array($data))
+ {
+ if ($data['start'])
+ {
+ $start=$data['start'];
+ }
+ else
+ {
+ $start=0;
+ }
+ $query =
(isset($data['query'])?$data['query']:'');
+ $sort =
(isset($data['sort'])?$data['sort']:'DESC');
+ $order =
(isset($data['order'])?$data['order']:'');
+ $chapter_id =
(isset($data['chapter_id'])?$data['chapter_id']:0);
+ $allrows =
(isset($data['allrows'])?$data['allrows']:'');
+ $template_id =
(isset($data['template_id'])?$data['template_id']:0);
+ }
+
+ if ($order)
+ {
+ $ordermethod = " order by $order $sort";
+ }
+ else
+ {
+ $ordermethod = ' order by record ';
+ }
+
+
+ $filtermethod .= " where template_id='$template_id' ";
+
+ if($query)
+ {
+ $query = ereg_replace("'",'',$query);
+ $query = ereg_replace('"','',$query);
+
+ $querymethod = " AND (hours_descr LIKE
'%$query%' or fm_template_hours.remark LIKE '%$query%' or ns3420_id LIKE
'%$query%')";
+ }
+
+ $sql = "SELECT fm_template_hours.*, chapter_id from
fm_template_hours $this->join fm_template on
fm_template.id=fm_template_hours.template_id $filtermethod $querymethod";
+
+ $dbresult2 = $GLOBALS['phpgw']->db->Execute($sql);
+ $this->total_records = $dbresult2->_numOfRows;
+
+ $maxmatchs = 15;
+
+ if(!$allrows)
+ {
+ $dbresult =
$GLOBALS['phpgw']->db->SelectLimit($sql . $ordermethod,$maxmatchs,$start);
+
+ }
+ else
+ {
+ $dbresult = $GLOBALS['phpgw']->db->Execute($sql
. $ordermethod);
+ }
+
+ while (!$dbresult->EOF)
+ {
+ $hour_list[] = array
+ (
+ 'hour_id' =>
$dbresult->fields['id'],
+ 'chapter_id' =>
$dbresult->fields['chapter_id'],
+ 'activity_num' =>
$dbresult->fields['activity_num'],
+ 'hours_descr' =>
stripslashes($dbresult->fields['hours_descr']),
+ 'remark' =>
stripslashes($dbresult->fields['remark']),
+ 'grouping_id' =>
$dbresult->fields['grouping_id'],
+ 'grouping_descr' =>
$dbresult->fields['grouping_descr'],
+ 'ns3420_id' =>
$dbresult->fields['ns3420_id'],
+ 'tolerance' =>
$dbresult->fields['tolerance'],
+ 'activity_id' =>
$dbresult->fields['activity_id'],
+ 'unit' =>
$dbresult->fields['unit'],
+ 'record' =>
$dbresult->fields['record'],
+ 'cost' =>
$dbresult->fields['cost'],
+ 'billperae' =>
$dbresult->fields['billperae'],
+ 'building_part' =>
$dbresult->fields['building_part'],
+ 'dim_d' =>
$dbresult->fields['dim_d']
+ );
+ $dbresult->MoveNext();
+ }
+ return $hour_list;
+ }
+
+ function read_single_template($template_id)
+ {
+ $sql = "SELECT * FROM fm_template where
id='$template_id'";
+
+ $dbresult = $GLOBALS['phpgw']->db->Execute($sql);
+
+ if (!$dbresult->EOF)
+ {
+ $template['template_id'] =
$dbresult->fields['id'];
+ $template['name']
= stripslashes($dbresult->fields['name']);
+ $template['descr']
= stripslashes($dbresult->fields['descr']);
+ $template['chapter_id'] =
(int)$dbresult->fields['chapter_id'];
+ }
+ return $template;
+ }
+
+ function read_single_hour($hour_id)
+ {
+ $sql = "SELECT * from fm_template_hours where
id='$hour_id'";
+
+ $dbresult = $GLOBALS['phpgw']->db->Execute($sql);
+
+ if (!$dbresult->EOF)
+ {
+ $hour['hour_id']
= $dbresult->fields['id'];
+ $hour['record']
= $dbresult->fields['record'];
+ $hour['activity_id'] =
$dbresult->fields['activity_id'];
+ $hour['activity_num'] =
$dbresult->fields['activity_num'];
+ $hour['grouping_id'] =
$dbresult->fields['grouping_id'];
+ $hour['hours_descr'] =
$dbresult->fields['hours_descr'];
+ $hour['remark']
= $dbresult->fields['remark'];
+ $hour['billperae']
= $dbresult->fields['billperae'];
+ $hour['unit']
= $dbresult->fields['unit'];
+ $hour['ns3420_id']
= $dbresult->fields['ns3420_id'];
+ $hour['tolerance_id'] =
(int)$dbresult->fields['tolerance'];
+ $hour['building_part_id'] =
(int)$dbresult->fields['building_part'];
+ $hour['quantity']
= $dbresult->fields['quantity'];
+ $hour['cost']
= $dbresult->fields['cost'];
+ $hour['dim_d']
= $dbresult->fields['dim_d'];
+ }
+
+ return $hour;
+ }
+
+ function next_record($template_id)
+ {
+
+ $dbresult = $GLOBALS['phpgw']->db->Execute("SELECT
max(record) as record FROM fm_template_hours where template_id='$template_id'");
+
+ $record = $dbresult->fields['record']+1;
+ return $record;
+
+ }
+
+ function add_custom_hour($hour,$template_id)
+ {
+
+ $hour['record'] = $this->next_record($template_id);
+
+ $GLOBALS['phpgw']->db->Execute("UPDATE fm_template set
+ chapter_id ='" . $hour['chapter_id'] . "'
WHERE id= '$template_id'");
+
+ if($hour['grouping_id'])
+ {
+ $dbresult =
$GLOBALS['phpgw']->db->Execute("SELECT grouping_descr , max(record) as record
FROM fm_template_hours where grouping_id='" .$hour['grouping_id'] . "' and
template_id= '$template_id' GROUP by grouping_descr");
+
+ $hour['grouping_descr'] =
$dbresult->fields['grouping_descr'];
+ }
+
+ if($hour['new_grouping'])
+ {
+ $dbresult =
$GLOBALS['phpgw']->db->Execute("SELECT grouping_id FROM fm_template_hours where
grouping_descr ='" .$hour['new_grouping'] . "' and template_id=
'$template_id'");
+
+ if ( $dbresult->fields['grouping_id'])
+ {
+ $hour['grouping_id'] =
$dbresult->fields['grouping_id'];
+ }
+ else
+ {
+ $dbresult =
$GLOBALS['phpgw']->db->Execute("SELECT max(grouping_id) as grouping_id FROM
fm_template_hours where template_id= '$template_id'");
+
+ $hour['grouping_id'] =
$dbresult->fields['grouping_id']+1;
+ }
+
+ $hour['grouping_descr'] = $hour['new_grouping'];
+ }
+
+ $GLOBALS['phpgw']->db->Execute("INSERT into
fm_template_hours
(owner,hours_descr,unit,cost,quantity,billperae,ns3420_id,dim_d,"
+ . "
grouping_id,grouping_descr,record,building_part,tolerance,remark,entry_date,template_id)
"
+ . " values ('" .
+ $this->account . "','" .
+ $hour['descr'] . "','" .
+ $hour['unit'] . "','" .
+ $hour['cost'] . "','" .
+ $hour['quantity'] . "','" .
+ $hour['billperae'] . "','" .
+ $hour['ns3420_id'] . "','" .
+ $hour['dim_d'] . "','" .
+ $hour['grouping_id'] . "','" .
+ $hour['grouping_descr'] . "','" .
+ $hour['record'] . "','" .
+ $hour['building_part_id'] . "','" .
+ $hour['tolerance_id'] . "','" .
+ $hour['remark'] . "','" .
+ time() . "','" .
+ $template_id . "')");
+
+ $receipt['hour_id'] =
$this->db->get_last_insert_id('fm_template_hours','id');
+
+ $receipt['message'][] = array('msg'=>lang('hour %1 is
added!',$hour['record']));
+
+ return $receipt;
+ }
+
+
+ function edit_hour($hour,$template_id)
+ {
+
+ $hour['descr'] =
$this->db->db_addslashes($hour['descr']);
+ $hour['remark'] =
$this->db->db_addslashes($hour['remark']);
+
+ $GLOBALS['phpgw']->db->Execute("UPDATE fm_template set
+ chapter_id ='" . $hour['chapter_id'] . "'
WHERE id= '$template_id'");
+
+ if($hour['new_grouping'])
+ {
+ $dbresult =
$GLOBALS['phpgw']->db->Execute("SELECT grouping_id FROM fm_template_hours where
grouping_descr ='" .$hour['new_grouping'] . "' and template_id=
'$template_id'");
+
+ if ( $dbresult->fields['grouping_id'])
+ {
+ $hour['grouping_id'] =
$dbresult->fields['grouping_id'];
+ }
+ else
+ {
+
+ $GLOBALS['phpgw']->db->Execute("UPDATE
fm_template_hours set grouping_id = NULL WHERE id ='" .$hour['hour_id'] . "'");
+ $dbresult =
$GLOBALS['phpgw']->db->Execute("SELECT count(grouping_id) as num_grouping FROM
fm_template_hours where template_id= '$template_id' and grouping_id >0 ");
+
+ if
($dbresult->fields['num_grouping']==1)
+ {
+ $hour['grouping_id']=1;
+ }
+ else
+ {
+ $dbresult =
$GLOBALS['phpgw']->db->Execute("SELECT max(grouping_id) as grouping_id FROM
fm_template_hours where template_id= '$template_id'");
+
+ $hour['grouping_id'] =
$dbresult->fields['grouping_id']+1;
+ }
+ }
+ $hour['grouping_descr'] = $hour['new_grouping'];
+ }
+ else
+ {
+ $dbresult =
$GLOBALS['phpgw']->db->Execute("SELECT grouping_id,grouping_descr FROM
fm_template_hours where id ='" .$hour['hour_id'] . "'");
+
+ $old_grouping_id =
$dbresult->fields['grouping_id'];
+
+ if ( $old_grouping_id == $hour['grouping_id'])
+ {
+
+ $hour['grouping_descr'] =
$dbresult->fields['grouping_descr'];
+ }
+ else
+ {
+ $dbresult =
$GLOBALS['phpgw']->db->Execute("SELECT grouping_descr , max(record) as record
FROM fm_template_hours where grouping_id='" .$hour['grouping_id'] . "' and
template_id= '$template_id' GROUP by grouping_descr");
+
+ if($dbresult->fields['grouping_descr'])
+ {
+ $hour['grouping_descr'] =
$dbresult->fields['grouping_descr'];
+ }
+ else
+ {
+ $hour['grouping_id']='';
+ $hour['grouping_descr']='';
+ }
+
+ }
+ }
+
+ $dbresult = $GLOBALS['phpgw']->db->Execute("SELECT
record FROM fm_template_hours where id ='" .$hour['hour_id'] . "'");
+
+ $hour['record'] = $dbresult->fields['record'];
+
+ $GLOBALS['phpgw']->db->Execute("UPDATE
fm_template_hours set
+ hours_descr ='" .
$hour['descr'] . "',
+ remark ='" .
$hour['remark'] . "',
+ billperae ='" .
$hour['billperae'] . "',
+ unit ='" .
$hour['unit'] . "',
+ quantity ='" .
$hour['quantity'] . "',
+ cost ='" .
$hour['cost'] . "',
+ ns3420_id ='" .
$hour['ns3420_id'] . "',
+ tolerance ='" .
$hour['tolerance_id'] . "',
+ building_part ='" .
$hour['building_part_id'] . "',
+ dim_d ='" .
$hour['dim_d'] . "',
+ grouping_id ='" .
$hour['grouping_id'] . "',
+ grouping_descr ='" .
$hour['grouping_descr']
+ . "' WHERE id= '" . $hour['hour_id'] ."'");
+
+ $receipt['hour_id'] = $hour['hour_id'];
+ $receipt['message'][] = array('msg'=>lang('hour %1 has
been edited',$hour['record']));
+ return $receipt;
+
+ }
+
+ function get_grouping_list($template_id='')
+ {
+ $dbresult = $GLOBALS['phpgw']->db->Execute("SELECT
grouping_id, grouping_descr FROM fm_template_hours where
template_id='$template_id' and grouping_id >0 group by grouping_id,
grouping_descr");
+
+ $i = 0;
+ while (!$dbresult->EOF)
+ {
+ $grouping_entries[$i]['id']
= $dbresult->fields['grouping_id'];
+ $grouping_entries[$i]['name']
= stripslashes($dbresult->fields['grouping_descr']);
+ $i++;
+ $dbresult->MoveNext();
+ }
+ return $grouping_entries;
+ }
+
+ function add_template($values)
+ {
+
+ $values['name'] =
$this->db->db_addslashes($values['name']);
+
+ $GLOBALS['phpgw']->db->Execute("INSERT into fm_template
(owner,name,descr,chapter_id,entry_date) "
+ . " values ('" .
+ $this->account . "','" .
+ $values['name'] . "','" .
+ $values['descr'] . "','" .
+ $values['chapter_id'] . "','" .
+ time() . "')");
+
+ $template_id =
$this->db->get_last_insert_id('fm_template','id');
+
+ $receipt['template_id'] = $template_id;
+ $receipt['message'][] = array('msg'=>lang('template %1
is added',$values['name']));
+ return $receipt;
+ }
+
+ function edit_template($values)
+ {
+ $values['name'] =
$this->db->db_addslashes($values['name']);
+ $values['descr'] =
$this->db->db_addslashes($values['descr']);
+
+ $GLOBALS['phpgw']->db->Execute("UPDATE fm_template set
name='" . $values['name'] . "', descr='" . $values['descr'] . "', chapter_id='"
+ .
(int)$values['chapter_id']
+ . "' WHERE id='" .
$values['template_id'] . "'");
+
+ $receipt['message'][]=array('msg'=>lang('Property has
been edited'));
+ return $receipt;
+ }
+
+ function delete($id)
+ {
+ $GLOBALS['phpgw']->db->Execute("DELETE FROM fm_template
WHERE id='$id'");
+ $GLOBALS['phpgw']->db->Execute("DELETE FROM
fm_template_hours WHERE template_id='$id'");
+ }
+
+ function delete_hour($hour_id,$template_id )
+ {
+ $dbresult = $GLOBALS['phpgw']->db->Execute("SELECT
record FROM fm_template_hours where id ='$hour_id'");
+
+ $old_record = $dbresult->fields['record'];
+
+ $GLOBALS['phpgw']->db->Execute("DELETE FROM
fm_template_hours WHERE id='" . $hour_id . "'");
+ if($old_record)
+ {
+ $GLOBALS['phpgw']->db->Execute("UPDATE
fm_template_hours set record = record - 1 where template_id=
'$template_id' and record > $old_record ");
+ }
+
+ $receipt['message'][] = array('msg'=>lang('hour %1 has
been deleted',$hour_id));
+ return $receipt;
+
+ }
+ }
+?>
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Phpgroupware-cvs] property/class.sotemplate.php, 1.1.1.3,
nomail <=