[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Phpgroupware-cvs] property/class.sos_agreement.php, 1.1.2.1
From: |
nomail |
Subject: |
[Phpgroupware-cvs] property/class.sos_agreement.php, 1.1.2.1 |
Date: |
Sun, 20 Jun 2004 11:04:46 +0200 |
Update of /property
Added Files:
Branch: proposal-branch
class.sos_agreement.php
date: 2004/06/20 09:04:46; author: sigurdne; state: Exp; lines: +1356 -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 property_sos_agreement
{
var $role;
function property_sos_agreement()
{
$this->currentapp = 'property';
//$GLOBALS['phpgw_data']['flags']['req_app'];
$this->functions =
CreateObject($this->currentapp.'_functions');
// $this->db = $GLOBALS['phpgw']->db;
// $this->db2 = $this->db;
$this->account = $GLOBALS['phpgw_data']['user']['id'];
$this->bocommon =
CreateObject($this->currentapp.'_bocommon');
$this->join = $this->bocommon->join;
$this->left_join = $this->bocommon->left_join;
}
function select_category_list()
{
$table = 'fm_s_agreement' . '_category';
$dbresult = $GLOBALS['phpgw']->db->Execute("SELECT
id,descr FROM $table 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($data)
{
if(is_array($data))
{
$start =
(isset($data['start'])?$data['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']:'');
$allrows =
(isset($data['allrows'])?$data['allrows']:'');
$member_id =
(isset($data['member_id'])?$data['member_id']:0);
$s_agreement_id =
(isset($data['s_agreement_id'])?$data['s_agreement_id']:'');
$detail =
(isset($data['detail'])?$data['detail']:'');
}
$choice_table = 'fm_s_agreement_choice';
$attribute_table = 'fm_s_agreement_attribute';
if(!$detail)
{
$entity_table = 'fm_s_agreement';
$category_table = 'fm_s_agreement_category';
$attribute_filter = " AND attrib_detail = 1";
$paranthesis .='(';
$joinmethod .= " $this->join $category_table ON
( $entity_table.category =$category_table.id))";
$cols = $entity_table .
".*,$category_table.descr as category";
$cols_return[] = 'id';
$uicols['input_type'][] = 'text';
$uicols['name'][] = 'id';
$uicols['descr'][] =
lang('ID');
$uicols['statustext'][] = lang('ID');
$cols_return[] =
'name';
$uicols['input_type'][] = 'text';
$uicols['name'][] =
'name';
$uicols['descr'][] =
lang('name');
$uicols['statustext'][] = lang('name');
$cols_return[] =
'category';
$uicols['input_type'][] = 'text';
$uicols['name'][] =
'category';
$uicols['descr'][] =
lang('category');
$uicols['statustext'][] =
lang('category');
}
else
{
$allrows=True;
$entity_table = 'fm_s_agreement_detail';
$attribute_filter = " AND attrib_detail = 2";
$paranthesis .='(';
$joinmethod .= " $this->join
fm_s_agreement_pricing ON ( $entity_table.agreement_id
=fm_s_agreement_pricing.agreement_id AND $entity_table.id
=fm_s_agreement_pricing.item_id))";
$cols = "$entity_table.*,
fm_s_agreement_pricing.cost,fm_s_agreement_pricing.id as
index_count,fm_s_agreement_pricing.date,fm_s_agreement_pricing.item_id,fm_s_agreement_pricing.this_index";
$cols_return[] =
'agreement_id';
$uicols['input_type'][] = 'hidden';
$uicols['name'][] =
'agreement_id';
$uicols['descr'][] =
lang('agreement_id');
$uicols['statustext'][] =
lang('agreement_id');
$cols_return[] =
'item_id';
$uicols['input_type'][] = 'text';
$uicols['name'][] =
'item_id';
$uicols['descr'][] =
lang('ID');
$uicols['statustext'][] = lang('ID');
$cols_return[] = 'id';
$uicols['input_type'][] = 'hidden';
$uicols['name'][] = 'id';
$uicols['descr'][] = False;
$uicols['statustext'][] = False;
$cols_return[] =
'location_code';
$uicols['input_type'][] = 'text';
$uicols['name'][] =
'location_code';
$uicols['descr'][] =
lang('location');
$uicols['statustext'][] =
lang('location');
$cols_return[] =
'address';
$uicols['input_type'][] = 'text';
$uicols['name'][] =
'address';
$uicols['descr'][] =
lang('address');
$uicols['statustext'][] =
lang('address');
$cols_return[] =
'p_num';
$uicols['input_type'][] = 'text';
$uicols['name'][] =
'p_num';
$uicols['descr'][] =
lang('entity num');
$uicols['statustext'][] = lang('entity
num');
$cols_return[] =
'cost';
$uicols['input_type'][] = 'text';
$uicols['name'][] =
'cost';
$uicols['descr'][] =
lang('cost');
$uicols['statustext'][] = lang('cost');
$cols_return[] =
'this_index';
$uicols['input_type'][] = 'text';
$uicols['name'][] =
'this_index';
$uicols['descr'][] =
lang('index');
$uicols['statustext'][] = lang('index');
$cols_return[] =
'index_count';
$uicols['input_type'][] = 'text';
$uicols['name'][] =
'index_count';
$uicols['descr'][] =
lang('index_count');
$uicols['statustext'][] =
lang('index_count');
$cols_return[] =
'date';
$uicols['input_type'][] = 'text';
$uicols['name'][] =
'date';
$uicols['descr'][] =
lang('date');
$uicols['statustext'][] = lang('date');
}
$from .= " FROM $paranthesis $entity_table ";
$sql = "SELECT $cols $from $joinmethod";
$i = count($uicols['name']);
$dbresult = $GLOBALS['phpgw']->db->Execute("SELECT *
FROM $attribute_table WHERE list=1 $attribute_filter ");
while (!$dbresult->EOF)
{
$uicols['input_type'][] = 'text';
$uicols['name'][] =
$dbresult->fields['column_name'];
$uicols['descr'][] =
$dbresult->fields['input_text'];
$uicols['statustext'][] =
$dbresult->fields['statustext'];
$uicols['datatype'][$i] =
$dbresult->fields['datatype'];
$cols_return_extra[]= array(
'name' =>
$dbresult->fields['column_name'],
'datatype' =>
$dbresult->fields['datatype'],
'attrib_id' =>
$dbresult->fields['id']
);
$i++;
$dbresult->MoveNext();
}
$user_columns=$GLOBALS['phpgw_info']['user']['preferences'][$this->currentapp]['s_agreement_columns'
. !!$s_agreement_id];
//html_print_r($user_columns);
if (isset($user_columns) AND is_array($user_columns)
AND $user_columns[0])
{
foreach($user_columns as $column_id)
{
$dbresult =
$GLOBALS['phpgw']->db->Execute("SELECT * FROM $attribute_table WHERE id=
$column_id");
$uicols['input_type'][] =
'text';
$uicols['name'][]
= $dbresult->fields['column_name'];
$uicols['descr'][]
= $dbresult->fields['input_text'];
$uicols['statustext'][] =
$dbresult->fields['statustext'];
$uicols['datatype'][$i] =
$dbresult->fields['datatype'];
$cols_return_extra[]= array(
'name' =>
$dbresult->fields['column_name'],
'datatype' =>
$dbresult->fields['datatype'],
'attrib_id' =>
$dbresult->fields['id']
);
$i++;
}
}
$this->uicols = $uicols;
//html_print_r($cols_return_extra);
if ($order)
{
$ordermethod = " order by $entity_table.$order
$sort";
}
else
{
$ordermethod = " order by $entity_table.id
DESC";
}
$where= 'WHERE';
/* if ($filter=='all')
{
if (is_array($grants))
{
while (list($user) = each($grants))
{
$public_user_list[] = $user;
}
reset($public_user_list);
$filtermethod .= " $where (
$entity_table.user_id IN(" . implode(',',$public_user_list) . "))";
$where= 'AND';
}
}
else
{
$filtermethod = " $where
$entity_table.user_id=$filter ";
$where= 'AND';
}
*/
if ($s_agreement_id)
{
$filtermethod .= " $where
$entity_table.agreement_id=$s_agreement_id AND current_index = 1";
$where= 'AND';
}
if ($cat_id)
{
$filtermethod .= " $where
$entity_table.category='$cat_id' ";
$where= 'AND';
}
if ($member_id>0)
{
$filtermethod .= " $where
$entity_table.member_of LIKE '%,$member_id,%' ";
$where= 'AND';
}
if ($status)
{
$filtermethod .= " $where
$entity_table.status='$status' ";
$where= 'AND';
}
if($query)
{
$query = ereg_replace("'",'',$query);
$query = ereg_replace('"','',$query);
$dbresult =
$GLOBALS['phpgw']->db->Execute("SELECT * FROM $attribute_table where
search='1'");
while (!$dbresult->EOF)
{
$querymethod[]= "$entity_table." .
$dbresult->fields['column_name'] . " LIKE '%$query%'";
$dbresult->MoveNext();
}
if (isset($querymethod) AND
is_array($querymethod))
{
$querymethod = " $where (" . implode ('
OR ',$querymethod) . ')';
$where = 'AND';
}
}
$sql .= " $filtermethod $querymethod";
//echo $sql;
$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;
$n=count($cols_return);
//html_print_r($cols_return);
while (!$dbresult->EOF)
{
for ($i=0;$i<$n;$i++)
{
$s_agreement_list[$j][$cols_return[$i]]
= $dbresult->fields[$cols_return[$i]];
$s_agreement_list[$j]['grants'] =
(int)$grants[$dbresult->fields['user_id']];
}
for ($i=0;$i<count($cols_return_extra);$i++)
{
$value='';
$value=$dbresult->fields[$cols_return_extra[$i]['name']];
if(($cols_return_extra[$i]['datatype']=='R' ||
$cols_return_extra[$i]['datatype']=='LB') && $value):
{
$sql="SELECT value FROM
$choice_table where attrib_id=" .$cols_return_extra[$i]['attrib_id']. " AND
id=" . $value . $attribute_filter;
$dbresult2 =
$GLOBALS['phpgw']->db->Execute($sql);
$s_agreement_list[$j][$cols_return_extra[$i]['name']] =
$dbresult2->fields['value'];
}
elseif($cols_return_extra[$i]['datatype']=='AB' && $value):
{
$sql="SELECT org_name FROM
phpgw_addressbook where id=$value";
$dbresult2 =
$GLOBALS['phpgw']->db->Execute($sql);
$s_agreement_list[$j][$cols_return_extra[$i]['name']] =
$dbresult2->fields['org_name'];
}
elseif($cols_return_extra[$i]['datatype']=='CH' && $value):
{
$ch= unserialize($value);
if (isset($ch) AND
is_array($ch))
{
for
($k=0;$k<count($ch);$k++)
{
$sql="SELECT
value FROM $choice_table where attrib_id="
.$cols_return_extra[$i]['attrib_id']. " AND id=" . $ch[$k] . $attribute_filter;
$dbresult2 =
$GLOBALS['phpgw']->db->Execute($sql);
while
(!$dbresult2->EOF)
{
$ch_value[]=$dbresult2->fields['value'];
}
}
$s_agreement_list[$j][$cols_return_extra[$i]['name']] = @implode(",",
$ch_value);
unset($ch_value);
}
}
elseif($cols_return_extra[$i]['datatype']=='D' && $value):
{
//html_print_r($value);
$s_agreement_list[$j][$cols_return_extra[$i]['name']]=date($GLOBALS['phpgw_data']['prefs'][$this->currentapp
. '.dateformat'],strtotime($value));
}
else:
{
$s_agreement_list[$j][$cols_return_extra[$i]['name']]=$value;
}
endif;
}
$j++;
$dbresult->MoveNext();
}
//html_print_r($s_agreement_list);
return $s_agreement_list;
}
function read_prizing($data)
{
if(is_array($data))
{
$s_agreement_id =
(isset($data['s_agreement_id'])?$data['s_agreement_id']:0);
$item_id =
(isset($data['item_id'])?$data['item_id']:0);
}
$entity_table = 'fm_s_agreement_pricing';
$cols =
"fm_s_agreement_pricing.cost,fm_s_agreement_pricing.id as
index_count,fm_s_agreement_pricing.date,fm_s_agreement_pricing.item_id,fm_s_agreement_pricing.this_index";
$cols_return[] = 'item_id';
$uicols['input_type'][] = 'text';
$uicols['name'][] = 'item_id';
$uicols['descr'][] = lang('ID');
$uicols['statustext'][] = lang('ID');
$cols_return[] = 'id';
$uicols['input_type'][] = 'hidden';
$uicols['name'][] = 'id';
$uicols['descr'][] = False;
$uicols['statustext'][] = False;
$cols_return[] = 'cost';
$uicols['input_type'][] = 'text';
$uicols['name'][] = 'cost';
$uicols['descr'][] = lang('cost');
$uicols['statustext'][] = lang('cost');
$cols_return[] = 'this_index';
$uicols['input_type'][] = 'text';
$uicols['name'][] = 'this_index';
$uicols['descr'][] = lang('index');
$uicols['statustext'][] = lang('index');
$cols_return[] = 'index_count';
$uicols['input_type'][] = 'text';
$uicols['name'][] = 'index_count';
$uicols['descr'][] =
lang('index_count');
$uicols['statustext'][] = lang('index_count');
$cols_return[] = 'date';
$uicols['input_type'][] = 'text';
$uicols['name'][] = 'date';
$uicols['descr'][] = lang('date');
$uicols['statustext'][] = lang('date');
$from .= " FROM $entity_table ";
$sql = "SELECT $cols $from $joinmethod";
$this->uicols = $uicols;
$ordermethod = " order by $entity_table.id ASC";
$where= 'WHERE';
if ($s_agreement_id)
{
$filtermethod .= " $where
$entity_table.agreement_id=$s_agreement_id AND item_id=$item_id";
$where= 'AND';
}
$sql .= " $filtermethod";
//echo $sql;
$dbresult2 = $GLOBALS['phpgw']->db->Execute($sql);
$this->total_records = $dbresult2->_numOfRows;
$dbresult = $GLOBALS['phpgw']->db->Execute($sql .
$ordermethod);
$j=0;
$n=count($cols_return);
//html_print_r($cols_return);
while (!$dbresult->EOF)
{
for ($i=0;$i<$n;$i++)
{
$s_agreement_list[$j][$cols_return[$i]]
= $dbresult->fields[$cols_return[$i]];
$s_agreement_list[$j]['agreement_id'] =
$s_agreement_id;
}
$j++;
$dbresult->MoveNext();
}
//html_print_r($s_agreement_list);
return $s_agreement_list;
}
function read_single($data)
{
$attribute_table = 'fm_s_agreement_attribute';
$table = 'fm_s_agreement';
$s_agreement_id =$data['s_agreement_id'];
$dbresult = $GLOBALS['phpgw']->db->Execute("SELECT *
FROM $attribute_table WHERE attrib_detail = 1 ORDER BY attrib_sort");
while (!$dbresult->EOF)
{
$s_agreement['attributes'][] = array
(
'attrib_id' =>
$dbresult->fields['id'],
'name' =>
$dbresult->fields['column_name'],
'input_text' =>
stripslashes($dbresult->fields['input_text']),
'statustext' =>
stripslashes($dbresult->fields['statustext']),
'datatype' =>
$dbresult->fields['datatype']
);
$dbresult->MoveNext();
}
if($s_agreement_id)
{
$dbresult =
$GLOBALS['phpgw']->db->Execute("SELECT * from $table where
id='$s_agreement_id'");
if($dbresult->fields[0])
{
$s_agreement['id']
= (int)$dbresult->fields['id'];
$s_agreement['entry_date']
= $dbresult->fields['entry_date'];
$s_agreement['cat_id']
= $dbresult->fields['category'];
$s_agreement['member_of']
= explode(',',$dbresult->fields['member_of']);
$s_agreement['cat_id']
= $dbresult->fields['category'];
$s_agreement['start_date']
= $dbresult->fields['start_date'];
$s_agreement['end_date']
= $dbresult->fields['end_date'];
$s_agreement['vendor_id']
= $dbresult->fields['vendor_id'];
$s_agreement['b_account_id'] =
$dbresult->fields['account_id'];
$s_agreement['name']
= stripslashes($dbresult->fields['name']);
$s_agreement['descr']
= stripslashes($dbresult->fields['descr']);
for
($i=0;$i<count($s_agreement['attributes']);$i++)
{
$s_agreement['attributes'][$i]['value'] =
$dbresult->fields[$s_agreement['attributes'][$i]['name']];
$s_agreement['attributes'][$i]['datatype_text'] =
$this->bocommon->translate_datatype($s_agreement['attributes'][$i]['datatype']);
}
}
}
return $s_agreement;
}
function read_single_item($data)
{
$attribute_table = 'fm_s_agreement_attribute';
$table = 'fm_s_agreement_detail';
$s_agreement_id =$data['s_agreement_id'];
$id =$data['id'];
$dbresult = $GLOBALS['phpgw']->db->Execute("SELECT *
FROM $attribute_table WHERE attrib_detail = 2 ORDER BY attrib_sort");
while (!$dbresult->EOF)
{
$item['attributes'][] = array
(
'attrib_id' =>
$dbresult->fields['id'],
'name' =>
$dbresult->fields['column_name'],
'input_text' =>
stripslashes($dbresult->fields['input_text']),
'statustext' =>
stripslashes($dbresult->fields['statustext']),
'datatype' =>
$dbresult->fields['datatype']
);
$dbresult->MoveNext();
}
if($id && $s_agreement_id)
{
$dbresult =
$GLOBALS['phpgw']->db->Execute("SELECT * from $table where
agreement_id=$s_agreement_id AND id=$id");
if($dbresult->fields[0])
{
$item['agreement_id'] =
(int)$dbresult->fields['agreement_id'];
$item['id']
= (int)$dbresult->fields['id'];
$item['entry_date'] =
$dbresult->fields['entry_date'];
$item['location_code'] =
$dbresult->fields['location_code'];
$item['p_num'] =
$dbresult->fields['p_num'];
$item['p_entity_id'] =
$dbresult->fields['p_entity_id'];
$item['p_cat_id'] =
$dbresult->fields['p_cat_id'];
$item['cost'] =
$dbresult->fields['cost'];
for
($i=0;$i<count($item['attributes']);$i++)
{
$item['attributes'][$i]['value'] =
$dbresult->fields[$item['attributes'][$i]['name']];
$item['attributes'][$i]['datatype_text'] =
$this->bocommon->translate_datatype($item['attributes'][$i]['datatype']);
}
}
}
return $item;
}
function add($s_agreement,$values_attribute='')
{
//html_print_r($s_agreement);
$table = 'fm_s_agreement';
$s_agreement['name'] =
$this->functions->db_addslashes($s_agreement['name']);
$s_agreement['descr'] =
$this->functions->db_addslashes($s_agreement['descr']);
if($s_agreement['member_of'])
{
$s_agreement['member_of']=',' .
implode(',',$s_agreement['member_of']) . ',';
}
while (is_array($s_agreement['extra']) &&
list($input_name,$value) = each($s_agreement['extra']))
{
if($value)
{
$cols[] = $input_name;
$vals[] = $value;
}
}
if (isset($values_attribute) AND
is_array($values_attribute))
{
foreach($values_attribute as $entry)
{
if($entry['value'])
{
$cols[] = $entry['name'];
$vals[] = $entry['value'];
}
}
}
if($cols)
{
$cols = "," . implode(",", $cols);
$vals = "," .
$this->bocommon->validate_db_insert($vals);
}
$GLOBALS['phpgw']->db->begintrans();
// $id = $this->bocommon->next_id($table);
$id = $this->bocommon->increment_id('workorder');
$GLOBALS['phpgw']->db->Execute("INSERT INTO $table
(id,name,descr,entry_date,category,member_of,start_date,end_date,vendor_id,account_id,user_id
$cols) "
. "VALUES ($id,'" . $s_agreement['name'] ."','"
. $s_agreement['descr'] ."','" . time() . "','" . $s_agreement['cat_id'] .
"','" . $s_agreement['member_of']
. "','" . $s_agreement['start_date'] . "','" .
$s_agreement['end_date']
. "','" . $s_agreement['vendor_id'] . "','" .
$s_agreement['b_account_id']
. "','" . $this->account . "' $vals)");
$GLOBALS['phpgw']->db->Execute("INSERT INTO fm_orders
(id,type) VALUES ($id,'s_agreement')");
$receipt['s_agreement_id']=
$id;//$this->db->get_last_insert_id($table,'id');
$receipt['message'][] = array('msg'=>lang('s_agreement
%1 has been saved',$receipt['s_agreement_id']));
$GLOBALS['phpgw']->db->committrans();
return $receipt;
}
function add_item($values,$values_attribute='')
{
//html_print_r($values);
$table = 'fm_s_agreement_detail';
$cols[] = 'location_code';
$vals[] = $values['location_code'];
/* while (is_array($values['location']) &&
list($input_name,$value) = each($values['location']))
{
if($value)
{
$cols[] = $input_name;
$vals[] = $value;
}
}
*/
while (is_array($values['extra']) &&
list($input_name,$value) = each($values['extra']))
{
if($value)
{
$cols[] = $input_name;
$vals[] = $value;
}
}
if (isset($values_attribute) AND
is_array($values_attribute))
{
foreach($values_attribute as $entry)
{
if($entry['value'])
{
$cols[] = $entry['name'];
$vals[] = $entry['value'];
}
}
}
if($values['street_name'])
{
$address[]= $values['street_name'];
$address[]= $values['street_number'];
$address = implode(" ", $address);
}
if(!$address)
{
$address = $values['location_name'];
}
$cols[] = 'address';
$vals[] = $address;
$cols[] = 'cost';
$vals[] = $this->floatval($values['cost']);
if($cols)
{
$cols = "," . implode(",", $cols);
$vals = "," .
$this->bocommon->validate_db_insert($vals);
}
$GLOBALS['phpgw']->db->begintrans();
$id =
$this->bocommon->next_id($table,array('agreement_id'=>$values['s_agreement_id']));
$GLOBALS['phpgw']->db->Execute("INSERT INTO $table
(id,agreement_id,entry_date,user_id $cols) "
. "VALUES ($id," . $values['s_agreement_id']
."," . time()
. "," . $this->account . " $vals)");
$dbresult = $GLOBALS['phpgw']->db->Execute("SELECT
start_date FROM fm_s_agreement WHERE id=" . $values['s_agreement_id']);
$start_date = $dbresult->fields['start_date'];
$GLOBALS['phpgw']->db->Execute("INSERT INTO
fm_s_agreement_pricing
(agreement_id,item_id,id,current_index,this_index,cost,date,entry_date,user_id)
"
. "VALUES (" . $values['s_agreement_id'] . ","
. $id .",1,1,1," . $this->floatval($values['cost']) . "," . (int)$start_date .
"," . time()
. "," . $this->account . ")");
$receipt['s_agreement_id']= $values['s_agreement_id'];
$receipt['id']= $id;
$receipt['message'][] = array('msg'=>lang('s_agreement
%1 has been saved',$receipt['s_agreement_id']));
$GLOBALS['phpgw']->db->committrans();
return $receipt;
}
function edit($values,$values_attribute='')
{
//html_print_r($values);
//html_print_r($values_attribute);
$table = 'fm_s_agreement';
$values['name'] =
$this->functions->db_addslashes($values['name']);
if($values['member_of'])
{
$values['member_of']=',' .
implode(',',$values['member_of']) . ',';
}
while (is_array($values['extra']) &&
list($column,$value) = each($values['extra']))
{
$value_set[$column] = $value;
}
if (isset($values_attribute) AND
is_array($values_attribute))
{
foreach($values_attribute as $entry)
{
if($entry['datatype']!='AB')
{
$value_set[$entry['name']]
= $entry['value'];
}
}
}
$value_set['name'] = $values['name'];
$value_set['descr'] = $values['descr'];
if($value_set)
{
$value_set = ',' .
$this->bocommon->validate_db_update($value_set);
}
$GLOBALS['phpgw']->db->Execute("UPDATE $table set
entry_date='" . time() . "', category='"
. $values['cat_id'] .
"', member_of='" . $values['member_of'] . "', start_date=" .
intval($values['start_date']) . ", end_date=" . intval($values['end_date']) .
", account_id=" . intval($values['b_account_id']) . "$value_set WHERE id=" .
intval($values['s_agreement_id']));
$GLOBALS['phpgw']->db->Execute("UPDATE
fm_s_agreement_pricing set date=" . intval($values['start_date']) . " WHERE
id=1 AND agreement_id= " . intval($values['s_agreement_id']));
$receipt['s_agreement_id']= $values['s_agreement_id'];
$receipt['message'][] = array('msg'=>lang('s_agreement
%1 has been edited',$values['s_agreement_id']));
return $receipt;
}
function edit_item($values,$values_attribute='')
{
//html_print_r($values);
//html_print_r($values_attribute);
$table = 'fm_s_agreement_detail';
while (is_array($values['extra']) &&
list($column,$value) = each($values['extra']))
{
$value_set[$column] = $value;
}
if (isset($values_attribute) AND
is_array($values_attribute))
{
foreach($values_attribute as $entry)
{
if($entry['datatype']!='AB')
{
$value_set[$entry['name']]
= $entry['value'];
}
}
}
if($values['street_name'])
{
$address[]= $values['street_name'];
$address[]= $values['street_number'];
$address = implode(" ", $address);
}
if(!$address)
{
$address = $values['location_name'];
}
$value_set['location_code'] =
$values['location_code'];
$value_set['cost'] = $values['cost'];
$value_set['address'] = $address;
if($value_set)
{
$value_set = ',' .
$this->bocommon->validate_db_update($value_set);
}
$GLOBALS['phpgw']->db->Execute("UPDATE $table set
entry_date=" . time() . "$value_set WHERE agreement_id=" .
intval($values['s_agreement_id']) . ' AND id=' . intval($values['id']));
$GLOBALS['phpgw']->db->Execute("UPDATE
fm_s_agreement_pricing set cost = this_index *" .
$this->floatval($values['cost']) . " WHERE agreement_id=" .
intval($values['s_agreement_id']) . ' AND item_id=' . intval($values['id']));
$receipt['s_agreement_id']= $values['s_agreement_id'];
$receipt['id']= $values['id'];
$receipt['message'][] = array('msg'=>lang('s_agreement
%1 has been edited',$values['s_agreement_id']));
return $receipt;
}
function update($values)
{
//html_print_r($values);
$values['new_index']=$this->floatval($values['new_index']);
$GLOBALS['phpgw']->db->begintrans();
while (is_array($values['select']) &&
list($item_id,$value) = each($values['select']))
{
$GLOBALS['phpgw']->db->Execute("UPDATE
fm_s_agreement_pricing set current_index = NULL WHERE agreement_id=" .
intval($values['agreement_id']) . ' AND item_id=' . intval($item_id));
$GLOBALS['phpgw']->db->Execute("INSERT INTO
fm_s_agreement_pricing
(agreement_id,item_id,id,current_index,this_index,cost,date,entry_date,user_id)"
. "VALUES (" . $values['agreement_id']
. "," . $item_id ."," . ($values['id'][$item_id]+1) .",1,'" .
$values['new_index'] . "','" . ($value * $values['new_index']) . "'," .
(int)$values['date'] . "," . time()
. "," . $this->account . ")");
}
$GLOBALS['phpgw']->db->committrans();
$receipt['message'][] = array('msg'=>lang('s_agreement
%1 has been updated for index',$values['agreement_id']));
return $receipt;
}
function floatval($strValue)
{
$floatValue =
ereg_replace("(^[0-9]*)(\\.|,)([0-9]*)(.*)", "\\1.\\3", $strValue);
if(!is_numeric($floatValue))
{
$floatValue = ereg_replace("(^[0-9]*)(.*)",
"\\1", $strValue);
}
if(!is_numeric($floatValue))
{
$floatValue = 0;
}
return $floatValue;
}
function delete_last_index($s_agreement_id,$item_id)
{
$GLOBALS['phpgw']->db->begintrans();
$dbresult = $GLOBALS['phpgw']->db->Execute("SELECT
max(id) as index_count FROM fm_s_agreement_pricing WHERE
agreement_id=$s_agreement_id AND item_id=$item_id");
$index_count = $dbresult->fields['index_count'];
if($index_count>1)
{
$GLOBALS['phpgw']->db->Execute("DELETE FROM
fm_s_agreement_pricing WHERE agreement_id=$s_agreement_id AND item_id=$item_id
AND id=$index_count");
$GLOBALS['phpgw']->db->Execute("UPDATE
fm_s_agreement_pricing set current_index = 1 WHERE agreement_id=$s_agreement_id
AND item_id=$item_id AND id =" . ($index_count-1));
}
$GLOBALS['phpgw']->db->committrans();
}
function delete_item($s_agreement_id,$item_id)
{
$GLOBALS['phpgw']->db->begintrans();
$GLOBALS['phpgw']->db->Execute("DELETE FROM
fm_s_agreement_detail WHERE agreement_id=$s_agreement_id AND id=$item_id");
$GLOBALS['phpgw']->db->Execute("DELETE FROM
fm_s_agreement_pricing WHERE agreement_id=$s_agreement_id AND
item_id=$item_id");
$GLOBALS['phpgw']->db->committrans();
}
function delete($s_agreement_id)
{
$table = 'fm_s_agreement';
$GLOBALS['phpgw']->db->begintrans();
$GLOBALS['phpgw']->db->Execute("DELETE FROM $table
WHERE id=" . intval($s_agreement_id));
$GLOBALS['phpgw']->db->Execute("DELETE FROM
fm_s_agreement_detail WHERE agreement_id=" . intval($s_agreement_id));
$GLOBALS['phpgw']->db->Execute("DELETE FROM
fm_s_agreement_pricing WHERE agreement_id=" . intval($s_agreement_id));
$GLOBALS['phpgw']->db->Execute("DELETE FROM fm_orders
WHERE id=" . intval($s_agreement_id));
$GLOBALS['phpgw']->db->committrans();
}
function read_attrib($data)
{
$attribute_table = 'fm_s_agreement_attribute';
//html_print_r($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']:'');
$allrows =
(isset($data['allrows'])?$data['allrows']:'');
$column_list =
(isset($data['column_list'])?$data['column_list']:'');
}
$where = 'WHERE';
if ($column_list)
{
$filtermethod = " $where list !=1 or list is
null";
$where = 'AND';
}
if ($this->role=='detail')
{
$filtermethod .= " $where attrib_detail=2 ";
}
else
{
$filtermethod .= " $where attrib_detail=1 ";
}
$where = 'AND';
if ($order)
{
$ordermethod = " order by $order $sort";
}
else
{
$ordermethod = ' order by attrib_sort asc';
}
if($query)
{
$query = ereg_replace("'",'',$query);
$query = ereg_replace('"','',$query);
$querymethod = " $where
($attribute_table.input_text LIKE '%$query%' or $attribute_table.column_name
LIKE '%$query%')";
}
$sql = "SELECT * FROM $attribute_table $filtermethod
$querymethod";
//echo $sql;
$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)
{
$attrib[] = array
(
'id' =>
$dbresult->fields['id'],
'attrib_sort' =>
$dbresult->fields['attrib_sort'],
'list' =>
$dbresult->fields['list'],
'lookup_form' =>
$dbresult->fields['lookup_form'],
'column_name' =>
$dbresult->fields['column_name'],
'name' =>
$dbresult->fields['input_text'],
'size' =>
$dbresult->fields['size'],
'statustext' =>
$dbresult->fields['statustext'],
'input_text' =>
$dbresult->fields['input_text'],
'type_name' =>
$dbresult->fields['type'],
'datatype' =>
$dbresult->fields['datatype'],
'search' =>
$dbresult->fields['search']
);
$dbresult->MoveNext();
}
return $attrib;
}
function read_single_attrib($id)
{
$attribute_table = 'fm_s_agreement_attribute';
if ($this->role=='detail')
{
$filtermethod = " AND attrib_detail=2 ";
}
else
{
$filtermethod = " AND attrib_detail=1 ";
}
$sql = "SELECT * FROM $attribute_table where id=$id
$filtermethod";
$dbresult = $GLOBALS['phpgw']->db->Execute($sql);
if($dbresult->fields[0])
{
$attrib['id']
= $dbresult->fields['id'];
$attrib['column_name']
= $dbresult->fields['column_name'];
$attrib['input_text']
= $dbresult->fields['input_text'];
$attrib['statustext']
= $dbresult->fields['statustext'];
$attrib['column_info']['precision'] =
$dbresult->fields['precision_'];
$attrib['column_info']['scale'] =
$dbresult->fields['scale'];
$attrib['column_info']['default'] =
$dbresult->fields['default_value'];
$attrib['column_info']['nullable'] =
$dbresult->fields['nullable'];
$attrib['column_info']['type'] =
$dbresult->fields['datatype'];
$attrib['type_name']
= $dbresult->fields['type_name'];
$attrib['lookup_form']
= $dbresult->fields['lookup_form'];
$attrib['list']
= $dbresult->fields['list'];
$attrib['search']
= $dbresult->fields['search'];
if($dbresult->fields['datatype']=='R' ||
$dbresult->fields['datatype']=='CH' || $dbresult->fields['datatype']=='LB')
{
$attrib['choice'] =
$this->read_attrib_choice($id);
}
return $attrib;
}
}
function read_attrib_choice($attrib_id)
{
$choice_table = 'fm_s_agreement_choice';
if ($this->role=='detail')
{
$filtermethod = " AND attrib_detail=2 ";
}
else
{
$filtermethod = " AND attrib_detail=1 ";
}
$sql = "SELECT * FROM $choice_table WHERE
attrib_id=$attrib_id $filtermethod";
$dbresult = $GLOBALS['phpgw']->db->Execute($sql);
while (!$dbresult->EOF)
{
$choice[] = array
(
'id' => $dbresult->fields['id'],
'value' => $dbresult->fields['value']
);
$dbresult->MoveNext();
}
return $choice;
}
function add_attrib($attrib)
{
$attribute_table = 'fm_s_agreement_attribute';
$attrib['column_name'] =
$this->functions->db_addslashes($attrib['column_name']);
$attrib['input_text'] =
$this->functions->db_addslashes($attrib['input_text']);
$attrib['statustext'] =
$this->functions->db_addslashes($attrib['statustext']);
$attrib['default'] =
$this->functions->db_addslashes($attrib['default']);
$attrib['id'] =
$this->bocommon->next_id($attribute_table, array('attrib_detail'=>!!$this->role
+1));
if($this->role=='detail')
{
$filtermethod= 'WHERE attrib_detail=2';
$table = 'fm_s_agreement_detail';
}
else
{
$filtermethod= 'WHERE attrib_detail=1';
$table = 'fm_s_agreement';
}
$sql = "SELECT max(attrib_sort) as max_sort FROM
$attribute_table $filtermethod";
$dbresult = $GLOBALS['phpgw']->db->Execute($sql);
$attrib_sort = $dbresult->fields['max_sort']+1;
$values= array(
!!$this->role +1,
$attrib['id'],
$attrib['column_name'],
$attrib['input_text'],
$attrib['statustext'],
$attrib['lookup_form'],
$attrib['search'],
$attrib['list'],
$attrib_sort,
$attrib['column_info']['type'],
$attrib['column_info']['precision'],
$attrib['column_info']['scale'],
$attrib['column_info']['default'],
$attrib['column_info']['nullable']
);
$values = $this->bocommon->validate_db_insert($values);
$GLOBALS['phpgw']->db->begintrans();
$GLOBALS['phpgw']->db->Execute("INSERT INTO
$attribute_table (attrib_detail,id,column_name, input_text,
statustext,lookup_form,search,list,attrib_sort,datatype,precision_,scale,default_value,nullable)
"
. "VALUES ($values)");
$receipt['id']= $attrib['id'];
if($attrib['column_info']['type']=='email' &&
!$attrib['column_info']['precision'])
{
$attrib['column_info']['precision']=64;
}
$attrib['column_info']['type'] =
$this->bocommon->translate_datatype_insert($attrib['column_info']['type']);
if($attrib['column_info']['type']=='int' &&
!$attrib['column_info']['precision'])
{
$attrib['column_info']['precision']=4;
}
if(!$attrib['column_info']['default'])
{
unset($attrib['column_info']['default']);
}
$this->init_process();
if($this->oProc->AddColumn($table,$attrib['column_name'],
$attrib['column_info']))
{
$receipt['message'][] = array('msg' =>
lang('Attribute has been saved') );
$GLOBALS['phpgw']->db->committrans();
}
else
{
$receipt['error'][] = array('msg' =>
lang('column could not be added') );
if($this->db->Transaction)
{
$GLOBALS['phpgw']->db->rollbacktrans();
}
else
{
$GLOBALS['phpgw']->db->Execute("DELETE
FROM $attribute_table WHERE id='" . $receipt['id'] . "'");
unset($receipt['id']);
}
}
return $receipt;
}
function init_process()
{
$this->oProc =
CreateObject($this->currentapp.'_oproc');
}
function edit_attrib($attrib)
{
$attribute_table = 'fm_s_agreement_attribute';
$table = 'fm_s_agreement';
$attrib['column_name'] =
$this->functions->db_addslashes($attrib['column_name']);
$attrib['input_text'] =
$this->functions->db_addslashes($attrib['input_text']);
$attrib['statustext'] =
$this->functions->db_addslashes($attrib['statustext']);
$attrib['default'] =
$this->functions->db_addslashes($attrib['default']);
$choice_table = 'fm_s_agreement_choice';
if($this->role=='detail')
{
$filtermethod= ' AND attrib_detail=2';
$table = 'fm_s_agreement_detail';
}
else
{
$filtermethod= ' AND attrib_detail=1';
$table = 'fm_s_agreement';
}
$dbresult = $GLOBALS['phpgw']->db->Execute("SELECT
column_name FROM $attribute_table WHERE id='" . $attrib['id']. "'
$filtermethod");
$OldColumnName =
$dbresult->fields['column_name'];
$GLOBALS['phpgw']->db->begintrans();
$attrib_type=$attrib['column_info']['type'];
if(($OldColumnName !=$attrib['column_name']) ||
($attrib['column_info']['type'] != $dbresult->fields['datatype']))
{
$value_set=array(
'column_name' =>
$attrib['column_name'],
'input_text' =>
$attrib['input_text'],
'statustext' =>
$attrib['statustext'],
'lookup_form' =>
$attrib['lookup_form'],
'search' =>
$attrib['search'],
'list' =>
$attrib['list'],
'datatype' =>
$attrib['column_info']['type'],
'precision_' =>
$attrib['column_info']['precision'],
'scale' =>
$attrib['column_info']['scale'],
'default_value' =>
$attrib['column_info']['default'],
'nullable' =>
$attrib['column_info']['nullable']
);
$value_set =
$this->bocommon->validate_db_update($value_set);
$GLOBALS['phpgw']->db->Execute("UPDATE
$attribute_table set $value_set WHERE id=" . $attrib['id'] . $filtermethod);
if($attrib['column_info']['type']=='email' &&
!$attrib['column_info']['precision'])
{
$attrib['column_info']['precision']=64;
}
$attrib['column_info']['type'] =
$this->bocommon->translate_datatype_insert($attrib['column_info']['type']);
if($attrib['column_info']['type']=='int' &&
!$attrib['column_info']['precision'])
{
$attrib['column_info']['precision']=4;
}
if(!$attrib['column_info']['default'])
{
unset($attrib['column_info']['default']);
}
$this->init_process();
$this->oProc->AlterColumn($table,$OldColumnName,$attrib['column_name'],$attrib['column_info']);
}
if($attrib['new_choice'])
{
$dbresult =
$GLOBALS['phpgw']->db->Execute("SELECT max(id) as id FROM $choice_table WHERE
attrib_id='" . $attrib['id']. "' $filtermethod");
$choice_id =
$dbresult->fields['id']+1;
$values= array(
$attrib['id'],
$choice_id,
!!$this->role +1,
$attrib['new_choice']
);
$values =
$this->bocommon->validate_db_insert($values);
$GLOBALS['phpgw']->db->Execute("INSERT INTO
$choice_table (attrib_id,id,attrib_detail,value) "
. "VALUES ($values)");
}
if($attrib['delete_choice'])
{
for
($i=0;$i<count($attrib['delete_choice']);$i++)
{
$GLOBALS['phpgw']->db->Execute("DELETE
FROM $choice_table WHERE attrib_id=" . $attrib['id'] ." AND id=" .
$attrib['delete_choice'][$i] . $filtermethod);
}
}
//html_print_r($attrib_type);
if($attrib_type!='R' && $attrib_type!='CH' &&
$attrib_type!='LB')
{
$GLOBALS['phpgw']->db->Execute("DELETE FROM
$choice_table WHERE attrib_id=" . $attrib['id'] . $filtermethod);
}
$GLOBALS['phpgw']->db->committrans();
$receipt['message'][] = array('msg' =>
lang('Attribute has been edited'));
return $receipt;
}
function resort_attrib($data)
{
//html_print_r($data);
$attribute_table = 'fm_s_agreement_attribute';
if(is_array($data))
{
$resort =
(isset($data['resort'])?$data['resort']:'up');
$id = (isset($data['id'])?$data['id']:'');
}
$sql = "SELECT attrib_sort FROM $attribute_table where
id=$id";
$dbresult = $GLOBALS['phpgw']->db->Execute($sql);
$attrib_sort = $dbresult->fields['attrib_sort'];
$sql = "SELECT max(attrib_sort) as max_sort FROM
$attribute_table";
$dbresult = $GLOBALS['phpgw']->db->Execute($sql);
$max_sort = $dbresult->fields['max_sort'];
switch($resort)
{
case 'up':
if($attrib_sort>1)
{
$sql = "UPDATE $attribute_table
set attrib_sort=$attrib_sort WHERE attrib_sort =" . ($attrib_sort-1);
$GLOBALS['phpgw']->db->Execute($sql);
$sql = "UPDATE $attribute_table
set attrib_sort=" . ($attrib_sort-1) ." WHERE id=$id";
$GLOBALS['phpgw']->db->Execute($sql);
}
break;
case 'down':
if($max_sort > $attrib_sort)
{
$sql = "UPDATE $attribute_table
set attrib_sort=$attrib_sort WHERE attrib_sort =" . ($attrib_sort+1);
$GLOBALS['phpgw']->db->Execute($sql);
$sql = "UPDATE $attribute_table
set attrib_sort=" . ($attrib_sort+1) ." WHERE id=$id";
$GLOBALS['phpgw']->db->Execute($sql);
}
break;
default:
return;
break;
}
}
function delete_attrib($attrib_id)
{
$table = 'fm_s_agreement';
$attribute_table = 'fm_s_agreement_attribute';
$this->init_process();
$sql = "SELECT * FROM $attribute_table WHERE
id=$attrib_id";
$dbresult = $GLOBALS['phpgw']->db->Execute($sql);
$ColumnName =
$dbresult->fields['column_name'];
if($this->oProc->DropColumn($table,'', $ColumnName))
{
$sql = "SELECT attrib_sort FROM
$attribute_table where id=$attrib_id";
$dbresult =
$GLOBALS['phpgw']->db->Execute($sql);
$attrib_sort =
$dbresult->fields['attrib_sort'];
$sql2 = "SELECT max(attrib_sort) as max_sort
FROM $attribute_table";
$dbresult =
$GLOBALS['phpgw']->db->Execute($sql2);
$max_sort = $dbresult->fields['max_sort'];
if($max_sort>$attrib_sort)
{
$sql = "UPDATE $attribute_table set
attrib_sort=attrib_sort-1 WHERE attrib_sort > $attrib_sort";
$GLOBALS['phpgw']->db->Execute($sql);
}
$GLOBALS['phpgw']->db->Execute("DELETE FROM
$attribute_table WHERE id=$attrib_id");
}
else
{
$receipt['error'][] = array('msg' =>
lang('Attribute has NOT been deleted'));
}
return $receipt;
}
function request_next_id()
{
$dbresult = $GLOBALS['phpgw']->db->Execute("SELECT
max(id) as id FROM fm_s_agreement");
$next_id= $dbresult->fields['id']+1;
return $next_id;
}
}
?>
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Phpgroupware-cvs] property/class.sos_agreement.php, 1.1.2.1,
nomail <=