[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Phpgroupware-cvs] property/class.soadmin_entity.php, 1.1.1.3
From: |
nomail |
Subject: |
[Phpgroupware-cvs] property/class.soadmin_entity.php, 1.1.1.3 |
Date: |
Fri, 21 May 2004 19:30:06 -0000 |
Update of /property
Modified Files:
Branch:
class.soadmin_entity.php
date: 2004/04/23 21:26:33; author: sigurdne; state: Exp; lines: +1065 -1065
Log Message:
no message
=====================================================================
Index: property/class.soadmin_entity.php
diff -u property/class.soadmin_entity.php:1.1.1.2
property/class.soadmin_entity.php:1.1.1.3
--- property/class.soadmin_entity.php:1.1.1.2 Fri Apr 23 20:25:38 2004
+++ property/class.soadmin_entity.php Fri Apr 23 21:26:33 2004
@@ -1,1065 +1,1065 @@
-<?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_soadmin_entity
- {
- var $grants;
-
- function property_soadmin_entity($entity_id='',$cat_id='')
- {
- $this->currentapp = 'property';
//$GLOBALS['phpgw_info']['flags']['currentapp'];
- $this->db = $GLOBALS['phpgw']->db;
- $this->db2 = $this->db;
- $this->account =
$GLOBALS['phpgw_data']['user']['id'];
- $this->bocommon =
CreateObject($this->currentapp.'_bocommon');
-
- $this->join = $this->bocommon->join;
-
- if($entity_id && $cat_id)
- {
- $this->category_name =
$this->read_category_name($entity_id,$cat_id);
- }
- }
-
- function reset_fm_cache()
- {
- $GLOBALS['phpgw']->db->Execute("DELETE FROM fm_cache");
- }
-
- function read($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']:'');
- }
-
- if ($order)
- {
- $ordermethod = " order by $order $sort";
-
- }
- else
- {
- $ordermethod = ' order by id asc';
- }
-
- $table = 'fm_entity';
-
- if($query)
- {
- $query = ereg_replace("'",'',$query);
- $query = ereg_replace('"','',$query);
-
- $querymethod = " where name LIKE '%$query%' or
descr LIKE '%$query%'";
- }
-
- $sql = "SELECT * FROM $table $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)
- {
- $entity[] = array
- (
- 'id' => $dbresult->fields['id'],
- 'name' => $dbresult->fields['name'],
- 'descr' => $dbresult->fields['descr'],
- 'documentation' =>
$dbresult->fields['documentation']
- );
- $dbresult->MoveNext();
- }
- return $entity;
- }
-
- function read_category($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']:'');
- $entity_id =
(isset($data['entity_id'])?$data['entity_id']:'');
- }
-
- if ($order)
- {
- $ordermethod = " order by $order $sort";
-
- }
- else
- {
- $ordermethod = ' order by id asc';
- }
-
- $table = 'fm_entity_category';
-
- if($query)
- {
- $query = ereg_replace("'",'',$query);
- $query = ereg_replace('"','',$query);
-
- $querymethod = " AND name LIKE '%$query%' or
descr LIKE '%$query%'";
- }
-
- $sql = "SELECT * FROM $table WHERE entity_id=$entity_id
$querymethod";
-
- $dbresult2 = $GLOBALS['phpgw']->db->Execute($sql);
- $this->total_records = $dbresult2->_numOfRows;
-
- if(!$allrows)
- {
- $dbresult =
$GLOBALS['phpgw']->db->SelectLimit($sql . $ordermethod,$maxmatchs,$start);
- }
- else
- {
- $dbresult = $GLOBALS['phpgw']->db->Execute($sql
. $ordermethod);
- }
-
- while (!$dbresult->EOF)
- {
- $standard[] = array
- (
- 'id' => $dbresult->fields['id'],
- 'name' => $dbresult->fields['name'],
- 'prefix'=> $dbresult->fields['prefix'],
- 'descr' => $dbresult->fields['descr']
- );
- $dbresult->MoveNext();
- }
- return $standard;
- }
-
- function read_status($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']:'');
- $entity_id =
(isset($data['entity_id'])?$data['entity_id']:'');
- $cat_id =
(isset($data['cat_id'])?$data['cat_id']:'');
- }
-
- if ($order)
- {
- $ordermethod = " order by $order $sort";
-
- }
- else
- {
- $ordermethod = ' order by id asc';
- }
-
- $table = 'fm_entity_'. $entity_id .'_'.$cat_id .
'_status';
-
- if($query)
- {
- $query = ereg_replace("'",'',$query);
- $query = ereg_replace('"','',$query);
-
- $querymethod = " AND name LIKE '%$query%' or
descr LIKE '%$query%'";
- }
-
- $sql = "SELECT * FROM $table $querymethod";
-
- $dbresult2 = $GLOBALS['phpgw']->db->Execute($sql);
- $this->total_records = $dbresult2->_numOfRows;
-
- if(!$allrows)
- {
- $dbresult =
$GLOBALS['phpgw']->db->SelectLimit($sql . $ordermethod,$maxmatchs,$start);
- }
- else
- {
- $dbresult = $GLOBALS['phpgw']->db->Execute($sql
. $ordermethod);
- }
-
- while (!$dbresult->EOF)
- {
- $status[] = array
- (
- 'id' => $dbresult->fields['id'],
- 'descr' => $dbresult->fields['descr']
- );
-
- $dbresult->MoveNext();
- }
- return $status;
- }
-
-
- function read_single($id)
- {
-
- $sql = "SELECT * FROM fm_entity where id='$id'";
-
- $dbresult = $GLOBALS['phpgw']->db->Execute($sql);
-
- while (!$dbresult->EOF)
- {
- $entity['id'] =
$dbresult->fields['id'];
- $entity['name'] =
$dbresult->fields['name'];
- $entity['descr'] =
$dbresult->fields['descr'];
- $entity['location_form'] =
$dbresult->fields['location_form'];
- $entity['lookup_entity'] =
unserialize($dbresult->fields['lookup_entity']);
- $entity['documentation'] =
$dbresult->fields['documentation'];
- $dbresult->MoveNext();
- }
-
- $sql = "SELECT location FROM fm_entity_lookup where
entity_id=$id AND type='lookup'";
-
- $dbresult = $GLOBALS['phpgw']->db->Execute($sql);
-
- while (!$dbresult->EOF)
- {
- $entity['include_entity_for'][] =
$dbresult->fields['location'];
- $dbresult->MoveNext();
- }
-
- $sql = "SELECT location FROM fm_entity_lookup where
entity_id=$id AND type='start'";
-
- $dbresult = $GLOBALS['phpgw']->db->Execute($sql);
-
- while (!$dbresult->EOF)
- {
- $entity['start_entity_from'][] =
$dbresult->fields['location'];
- $dbresult->MoveNext();
- }
-
- return $entity;
- }
-
- function read_single_category($entity_id,$cat_id)
- {
- $sql = "SELECT * FROM fm_entity_category where
entity_id=$entity_id AND id=$cat_id";
-
- $dbresult = $GLOBALS['phpgw']->db->Execute($sql);
-
- if (!$dbresult->EOF)
- {
- $category['id'] =
$dbresult->fields['id'];
- $category['name'] =
$dbresult->fields['name'];
- $category['descr'] =
$dbresult->fields['descr'];
- $category['prefix'] =
$dbresult->fields['prefix'];
- $category['lookup_tenant'] =
$dbresult->fields['lookup_tenant'];
- $category['tracking'] =
$dbresult->fields['tracking'];
- $category['location_level'] =
$dbresult->fields['location_level'];
- $category['fileupload'] =
$dbresult->fields['fileupload'];
- $category['loc_link'] =
$dbresult->fields['loc_link'];
- return $category;
- }
- }
-
- function read_category_name($entity_id,$cat_id)
- {
- $sql = "SELECT * FROM fm_entity_category where
entity_id=$entity_id AND id=$cat_id";
- $dbresult = $GLOBALS['phpgw']->db->Execute($sql);
- return $dbresult->fields['name'];
- }
-
- function read_single_status($entity_id,$cat_id,$id)
- {
-
- $table = 'fm_entity_'. $entity_id .'_'.$cat_id .
'_status';
- $sql = "SELECT * FROM $table where id='$id'";
-
- $dbresult = $GLOBALS['phpgw']->db->Execute($sql);
-
- if (!$dbresult->EOF)
- {
- $status['id'] =
$dbresult->fields['id'];
- $status['descr'] =
$dbresult->fields['descr'];
-
- return $status;
- }
- }
-
- function add_entity($entity)
- {
- $entity['name'] =
$this->db->db_addslashes($entity['name']);
- $entity['descr'] =
$this->db->db_addslashes($entity['descr']);
-
- $entity['id'] = $this->bocommon->next_id('fm_entity');
-
- $values= array(
- $entity['id'],
- $entity['name'],
- $entity['descr'],
- $entity['location_form'],
- $entity['documentation']
- );
-
- $values = $this->bocommon->validate_db_insert($values);
-
- $GLOBALS['phpgw']->db->Execute("INSERT INTO fm_entity
(id,name, descr,location_form,documentation) "
- . "VALUES ($values)");
-
-
- $values_acl_location= array(
- '.entity.' . $entity['id'],
- $entity['name'],
- 1
- );
-
- $values_acl_location =
$this->bocommon->validate_db_insert($values_acl_location);
-
- $GLOBALS['phpgw']->db->Execute("INSERT INTO
fm_acl_location (id,descr,allow_grant) "
- . "VALUES ($values_acl_location)");
-
- $receipt['id']= $entity['id'];
-
- $receipt['message'][] = array('msg'=> lang('entity has
been added'));
- return $receipt;
- }
-
-
- function add_status($values,$entity_id,$cat_id)
- {
- $values['id'] = $this->db->db_addslashes($values['id']);
- $values['descr'] =
$this->db->db_addslashes($values['descr']);
-
- $values_insert= array(
- $values['id'],
- $values['descr'],
- );
-
- $values_insert =
$this->bocommon->validate_db_insert($values_insert);
-
- $table = 'fm_entity_'. $entity_id .'_'.$cat_id .
'_status';
-
- $GLOBALS['phpgw']->db->Execute("INSERT INTO $table
(id,descr) VALUES ($values_insert)");
-
- $receipt['id']= $values['id'];
-
- $receipt['message'][] = array('msg'=> lang('status has
been added'));
- return $receipt;
- }
-
-
- function add_category($values)
- {
- $values['name'] =
$this->db->db_addslashes($values['name']);
- $values['descr'] =
$this->db->db_addslashes($values['descr']);
-
- $values['id'] =
$this->bocommon->next_id('fm_entity_category',array('entity_id'=>$values['entity_id']));
-
- $location_type =
$this->bocommon->next_id('fm_location_type');
-
- $values_insert= array(
- $values['entity_id'],
- $values['id'],
- $values['name'],
- $values['descr'],
- $values['prefix'],
- $values['lookup_tenant'],
- $values['tracking'],
- $values['location_level'],
- $values['fileupload'],
- $values['loc_link']
- );
-
- $values_insert =
$this->bocommon->validate_db_insert($values_insert);
-
-
- $GLOBALS['phpgw']->db->begintrans();
-
- $GLOBALS['phpgw']->db->Execute("INSERT INTO
fm_entity_category (entity_id,id,name,
descr,prefix,lookup_tenant,tracking,location_level,fileupload,loc_link) "
- . "VALUES ($values_insert)");
-
- $values_acl_location= array(
- '.entity.' . $values['entity_id'] . '.' .
$values['id'],
- $values['name'],
- 1
- );
-
- $values_acl_location =
$this->bocommon->validate_db_insert($values_acl_location);
-
- $GLOBALS['phpgw']->db->Execute("INSERT INTO
fm_acl_location (id,descr,allow_grant) "
- . "VALUES ($values_acl_location)");
-
- $receipt['id']= $values['id'];
-
- $this->init_process();
-
- $fd=array();
- $fd['id'] = array('type' => 'int', 'precision' => 4,
'nullable' => False);
- $fd['num'] = array('type' => 'varchar', 'precision' =>
16, 'nullable' => False);
- $fd['p_num'] = array('type' => 'varchar', 'precision'
=> 16, 'nullable' => True);
- $fd['p_entity_id'] = array('type' => 'int', 'precision'
=> 4, 'nullable' => True);
- $fd['p_cat_id'] = array('type' => 'int', 'precision' =>
4, 'nullable' => True);
- $fd['location_code'] = array('type' => 'varchar',
'precision' => 25, 'nullable' => True);
-
- for ($i=1; $i<$location_type; $i++)
- {
- $fd['loc' . $i] = array('type' => 'varchar',
'precision' => 4, 'nullable' => True);
- }
-
- $fd['address'] = array('type' => 'varchar', 'precision'
=> 100, 'nullable' => True);
- $fd['tenant_id'] = array('type' => 'int', 'precision'
=> 4, 'nullable' => True);
- $fd['contact_phone'] = array('type' => 'varchar',
'precision' => 30, 'nullable' => True);
- $fd['status'] = array('type' => 'int', 'precision' =>
4, 'nullable' => True);
- $fd['entry_date'] = array('type' => 'int', 'precision'
=> 4, 'nullable' => True);
- $fd['user_id'] = array('type' => 'int', 'precision' =>
4, 'nullable' => True);
-
- $pk[]= 'id';
- $table = 'fm_entity_'.
$values['entity_id'] .'_'.$values['id'];
-/*
- $fd_status['id'] = array('type' => 'varchar',
'precision' => 20, 'nullable' => False);
- $fd_status['descr'] = array('type' => 'varchar',
'precision' => 255, 'nullable' => False);
- $pk_status[]= 'id';
-
- $statustable = $table . '_' .'status';
-*/
- if(($this->oProc->CreateTable($table,array('fd' =>
$fd,'pk' => $pk,'fk' => $fk,'ix' => array('location_code'),'uc' => array()))))
-// &&
($this->oProc->CreateTable($statustable,array('fd' => $fd_status,'pk' =>
$pk_status,'fk' => $fk_status,'ix' => False,'uc' => array()))))
- {
-
- $values_insert= array(
- $values['entity_id'],
- $values['id'],
- 1,
- 'status',
- 'Status',
- 'Status',
- 'LB',
- 1,
- 'True'
- );
-
- $values_insert =
$this->bocommon->validate_db_insert($values_insert);
-
- $GLOBALS['phpgw']->db->Execute("INSERT INTO
fm_entity_attribute
(entity_id,cat_id,id,column_name,input_text,statustext,datatype,attrib_sort,nullable)
"
- . "VALUES ($values_insert)");
-
- $receipt['message'][] = array('msg' =>
lang('table %1 has been saved',$table));
- $GLOBALS['phpgw']->db->committrans();
- }
- else
- {
- $receipt['error'][] = array('msg' =>
lang('table could not be added') );
- if($this->db->Transaction)
- {
- $GLOBALS['phpgw']->db->rollbacktrans();
- }
- else
- {
- $GLOBALS['phpgw']->db->Execute("DELETE
FROM fm_entity_category WHERE id=" . $values['id'] . " AND entity_id=" .
$values['entity_id']);
- unset($receipt['id']);
-
- }
- }
-
- return $receipt;
- }
-
- function edit_status($values,$entity_id,$cat_id)
- {
- $table = 'fm_entity_'. $entity_id .'_'.$cat_id .
'_status';
-
- $values['descr'] =
$this->db->db_addslashes($values['descr']);
-
- $value_set=array(
- 'descr' => $values['descr'],
- );
-
- $value_set =
$this->bocommon->validate_db_update($value_set);
-
- $this->db->query("UPDATE $table set $value_set WHERE
id='" . $values['id'] . "'");
-
- $receipt['message'][] = array('msg'=> lang('Status has
been edited'));
-
- return $receipt;
- }
-
- function edit_entity($entity)
- {
- if (!$entity['name'])
- {
- $receipt['error'][] = array('msg'=>lang('Name
not entered!'));
- }
-
- if (!$receipt['error'])
- {
- $table = 'fm_entity';
-
- $entity['name'] =
$this->db->db_addslashes($entity['name']);
- $entity['descr'] =
$this->db->db_addslashes($entity['descr']);
-
- if(!$entity['location_form'])
- {
- unset($entity['lookup_entity']);
- }
-
- $value_set=array(
- 'descr' => $entity['descr'],
- 'name' => $entity['name'],
- 'location_form' => $entity['location_form'],
- 'lookup_entity' =>
serialize($entity['lookup_entity']),
- 'documentation' => $entity['documentation']
- );
-
- $value_set =
$this->bocommon->validate_db_update($value_set);
-
- $GLOBALS['phpgw']->db->begintrans();
-
- $GLOBALS['phpgw']->db->Execute("UPDATE $table
set $value_set WHERE id=" . $entity['id']);
-
- $value_set_acl=array(
- 'descr' =>
$entity['name']
- );
-
- $value_set_acl =
$this->bocommon->validate_db_update($value_set_acl);
-
- $GLOBALS['phpgw']->db->Execute("UPDATE
fm_acl_location set $value_set_acl WHERE id='.entity." . $entity['id']. "'");
-
- $GLOBALS['phpgw']->db->Execute("DELETE FROM
fm_entity_lookup WHERE type='lookup' AND entity_id=" . $entity['id']);
- if (isset($entity['include_entity_for']) AND
is_array($entity['include_entity_for']))
- {
- foreach($entity['include_entity_for']
as $location)
- {
-
$GLOBALS['phpgw']->db->Execute("INSERT INTO fm_entity_lookup
(entity_id,location,type)"
- . "VALUES (" .$entity['id'] .
",'$location','lookup' )");
- }
- }
-
- $GLOBALS['phpgw']->db->Execute("DELETE FROM
fm_entity_lookup WHERE type='start' AND entity_id=" . $entity['id']);
-
- if (isset($entity['start_entity_from']) AND
is_array($entity['start_entity_from']))
- {
- foreach($entity['start_entity_from'] as
$location)
- {
-
$GLOBALS['phpgw']->db->Execute("INSERT INTO fm_entity_lookup
(entity_id,location,type)"
- . "VALUES (" .$entity['id'] .
",'$location','start' )");
- }
- }
-
- $GLOBALS['phpgw']->db->committrans();
-
- $receipt['message'][] = array('msg'=>
lang('entity has been edited'));
- }
- else
- {
- $receipt['error'][] = array('msg' =>
lang('entity has NOT been edited'));
- }
-
- return $receipt;
- }
-
- function edit_category($entity)
- {
-
- if (!$entity['name'])
- {
- $receipt['error'][] = array('msg'=>lang('Name
not entered!'));
- }
-
- if (!$receipt['error'])
- {
- $table = 'fm_entity_category';
-
- $entity['name'] =
$this->db->db_addslashes($entity['name']);
- $entity['descr'] =
$this->db->db_addslashes($entity['descr']);
-
- $value_set=array(
- 'descr' =>
$entity['descr'],
- 'name' =>
$entity['name'],
- 'prefix' =>
$entity['prefix'],
- 'lookup_tenant' =>
$entity['lookup_tenant'],
- 'tracking' =>
$entity['tracking'],
- 'location_level'=>
$entity['location_level'],
- 'fileupload' =>
$entity['fileupload'],
- 'loc_link' => $entity['loc_link']
- );
-
- $value_set =
$this->bocommon->validate_db_update($value_set);
-
- $GLOBALS['phpgw']->db->Execute("UPDATE $table
set $value_set WHERE entity_id=" . $entity['entity_id']. " AND id=" .
$entity['id']);
-
- $value_set_acl=array(
- 'descr' =>
$entity['name']
- );
-
- $value_set_acl =
$this->bocommon->validate_db_update($value_set_acl);
-
- $GLOBALS['phpgw']->db->Execute("UPDATE
fm_acl_location set $value_set_acl WHERE id='.entity." . $entity['entity_id'].
"." . $entity['id']. "'");
-
-
- $receipt['message'][] = array('msg'=>
lang('entity has been edited'));
- }
- else
- {
- $receipt['error'][] = array('msg' =>
lang('entity has NOT been edited'));
- }
-
- return $receipt;
- }
-
- function delete_entity($id)
- {
-
$category_list=$this->read_category(array('entity_id'=>$id));
- $GLOBALS['phpgw']->db->Execute("DELETE FROM fm_entity
WHERE id=$id");
- $GLOBALS['phpgw']->db->Execute("DELETE FROM
fm_entity_category WHERE entity_id=$id");
- $GLOBALS['phpgw']->db->Execute("DELETE FROM
fm_entity_attribute WHERE entity_id=$id");
- $GLOBALS['phpgw']->db->Execute("DELETE FROM
fm_acl_location WHERE id LIKE '.entity." . $id ."%'");
- $GLOBALS['phpgw']->db->Execute("DELETE FROM fm_acl2
WHERE acl_location LIKE '.entity." . $id ."%'");
- if (isset($category_list) AND is_array($category_list))
- {
- $this->init_process();
-
- foreach($category_list as $entry)
- {
- $this->oProc->DropTable('fm_entity_' .
$id . '_' . $entry['id']);
- }
- }
-
- }
-
- function delete_category($id,$entity_id)
- {
- $this->init_process();
- $this->oProc->DropTable('fm_entity_' . $entity_id . '_'
. $id);
-// $this->oProc->DropTable('fm_entity_' . $entity_id . '_'
. $id . '_' . 'status');
- $GLOBALS['phpgw']->db->Execute("DELETE FROM
fm_entity_category WHERE entity_id= $entity_id AND id= $id");
- $GLOBALS['phpgw']->db->Execute("DELETE FROM
fm_entity_attribute WHERE entity_id= $entity_id AND cat_id= $id");
- $GLOBALS['phpgw']->db->Execute("DELETE FROM
fm_acl_location WHERE id='.entity." . $entity_id . "." . $id ."'");
- $GLOBALS['phpgw']->db->Execute("DELETE FROM fm_acl2
WHERE acl_location='.entity." . $entity_id . "." . $id ."'");
- }
-
- function delete_attrib($cat_id,$entity_id,$attrib_id)
- {
- $this->init_process();
-
- $sql = "SELECT * FROM fm_entity_attribute WHERE
entity_id=$entity_id AND cat_id=$cat_id AND id=$attrib_id";
-
- $dbresult = $GLOBALS['phpgw']->db->Execute($sql);
- $ColumnName =
$dbresult->fields['column_name'];
-
- $this->oProc->DropColumn('fm_entity_' .$entity_id.'_'.
$cat_id,'', $ColumnName);
-
- $sql = "SELECT attrib_sort FROM fm_entity_attribute
where entity_id=$entity_id AND cat_id=$cat_id AND id=$attrib_id";
- $dbresult = $GLOBALS['phpgw']->db->Execute($sql);
- $attrib_sort = $dbresult->fields['attrib_sort'];
- $sql2 = "SELECT max(attrib_sort) as max_sort FROM
fm_entity_attribute where entity_id=$entity_id AND cat_id=$cat_id";
- $dbresult = $GLOBALS['phpgw']->db->Execute($sql2);
- $max_sort = $dbresult->fields['max_sort'];
- if($max_sort>$attrib_sort)
- {
- $sql = "UPDATE fm_entity_attribute set
attrib_sort=attrib_sort-1 WHERE entity_id=$entity_id AND cat_id=$cat_id AND
attrib_sort > $attrib_sort";
- $GLOBALS['phpgw']->db->Execute($sql);
- }
-
- $GLOBALS['phpgw']->db->Execute("DELETE FROM
fm_entity_attribute WHERE entity_id=$entity_id AND cat_id=$cat_id AND
id=$attrib_id");
- }
-
- function delete_status($cat_id,$entity_id,$status_id)
- {
- $table = 'fm_entity_'. $entity_id .'_'.$cat_id .
'_status';
-
- $GLOBALS['phpgw']->db->Execute("DELETE FROM $table
WHERE id='$status_id'");
- }
-
- function read_attrib($data)
- {
-
-//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']:'');
- $entity_id =
(isset($data['entity_id'])?$data['entity_id']:0);
- $cat_id =
(isset($data['cat_id'])?$data['cat_id']:0);
- }
-
- 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 = " AND (fm_entity_attribute.name
LIKE '%$query%' or fm_entity_attribute.descr LIKE '%$query%')";
- }
-
- $sql = "SELECT * FROM fm_entity_attribute WHERE
entity_id=$entity_id AND cat_id = $cat_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)
- {
- $attrib[] = array
- (
- 'id' =>
$dbresult->fields['id'],
- 'entity_type' =>
$dbresult->fields['type_id'],
- 'attrib_sort' =>
$dbresult->fields['attrib_sort'],
- 'list' =>
$dbresult->fields['list'],
- 'lookup_form' =>
$dbresult->fields['lookup_form'],
- 'entity_form' =>
$dbresult->fields['entity_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']
- );
- $dbresult->MoveNext();
- }
- return $attrib;
- }
-
- function read_single_attrib($entity_id,$cat_id,$id)
- {
-
- $sql = "SELECT * FROM fm_entity_attribute where
entity_id=$entity_id AND cat_id=$cat_id AND id=$id";
-
- $dbresult = $GLOBALS['phpgw']->db->Execute($sql);
-
- if (!$dbresult->EOF)
- {
- $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_id']
= $dbresult->fields['type_id'];
- $attrib['type_name']
= $dbresult->fields['type_name'];
- $attrib['lookup_form']
= $dbresult->fields['lookup_form'];
- $attrib['list']
= $dbresult->fields['list'];
- if($dbresult->fields['datatype']=='R' ||
$dbresult->fields['datatype']=='CH' || $dbresult->fields['datatype']=='LB')
- {
- $attrib['choice'] =
$this->read_attrib_choice($entity_id,$cat_id,$id);
- }
-
- return $attrib;
- }
- }
-
- function read_attrib_choice($entity_id,$cat_id,$attrib_id)
- {
- $choice_table = 'fm_entity_choice';
- $sql = "SELECT * FROM $choice_table WHERE
entity_id=$entity_id AND cat_id=$cat_id AND attrib_id=$attrib_id";
- $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)
- {
-
- $attrib['column_name'] =
$this->db->db_addslashes($attrib['column_name']);
- $attrib['input_text'] =
$this->db->db_addslashes($attrib['input_text']);
- $attrib['statustext'] =
$this->db->db_addslashes($attrib['statustext']);
- $attrib['default'] =
$this->db->db_addslashes($attrib['default']);
- $attrib['id'] =
$this->bocommon->next_id('fm_entity_attribute',array('entity_id'=>$attrib['entity_id'],'cat_id'=>$attrib['cat_id']));
-
- $sql = "SELECT max(attrib_sort) as max_sort FROM
fm_entity_attribute where entity_id=" . $attrib['entity_id'] . " AND cat_id=" .
$attrib['cat_id'];
- $dbresult = $GLOBALS['phpgw']->db->Execute($sql);
- $attrib_sort = $dbresult->fields['max_sort']+1;
-
- $values= array(
- $attrib['entity_id'],
- $attrib['cat_id'],
- $attrib['id'],
- $attrib['column_name'],
- $attrib['input_text'],
- $attrib['statustext'],
- $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
fm_entity_attribute (entity_id,cat_id,id,column_name, input_text,
statustext,list,attrib_sort, datatype,precision_,scale,default_value,nullable) "
- . "VALUES ($values)");
-
- $receipt['id']= $attrib['id'];
-
- $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('fm_entity_'.$attrib['entity_id'] . '_' .
$attrib['cat_id'],$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 fm_entity_attribute WHERE entity_id=" . $attrib['entity_id']. " AND
cat_id=" . $attrib['id']. " AND id='" . $receipt['id'] . "'");
- unset($receipt['id']);
-
- }
- }
-
- return $receipt;
- }
-
- function init_process()
- {
- $this->oProc
=
CreateObject('phpgwapi_schema_proc',$GLOBALS['phpgw_info']['server']['db_type']);
- $this->oProc->m_odb
= $this->db;
- $this->oProc->m_odb->Halt_On_Error = 'report';
- }
-
- function edit_attrib($attrib)
- {
-
- $attrib['column_name'] =
$this->db->db_addslashes($attrib['column_name']);
- $attrib['input_text'] =
$this->db->db_addslashes($attrib['input_text']);
- $attrib['statustext'] =
$this->db->db_addslashes($attrib['statustext']);
- $attrib['default'] =
$this->db->db_addslashes($attrib['default']);
-
- $GLOBALS['phpgw']->db->Execute("SELECT column_name FROM
fm_entity_attribute WHERE entity_id=" . $attrib['entity_id']. " AND cat_id=" .
$attrib['cat_id']. " AND id='" . $attrib['id']. "'");
- $OldColumnName =
$dbresult->fields['column_name'];
-
- $GLOBALS['phpgw']->db->begintrans();
-
- if($OldColumnName !=$attrib['column_name'])
- {
-
- $value_set=array(
- 'column_name' =>
$attrib['column_name'],
- 'input_text' =>
$attrib['input_text'],
- 'statustext' =>
$attrib['statustext'],
- '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
fm_entity_attribute set $value_set WHERE entity_id=" . $attrib['entity_id']. "
AND cat_id=" . $attrib['cat_id']. " AND id=" . $attrib['id']);
-
- if($attrib['column_info']['type']!='R' &&
$attrib['column_info']['type']!='CH' && $attrib['column_info']['type']!='LB')
- {
- $GLOBALS['phpgw']->db->Execute("DELETE
FROM $choice_table WHERE entity_id=" . $attrib['entity_id']. " AND cat_id=" .
$attrib['cat_id']. " AND attrib_id=" . $attrib['id']);
- }
-
-
- $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->RenameColumn('fm_entity_'.$attrib['entity_id'] . '_' .
$attrib['cat_id'], $OldColumnName, $attrib['column_name']);
-
$this->oProc->AlterColumn('fm_entity_'.$attrib['entity_id'] . '_' .
$attrib['cat_id'],$attrib['column_name'],$attrib['column_info']);
- }
-
- $choice_table ='fm_entity_choice';
-
- if($attrib['new_choice'])
- {
- $choice_id =
$this->bocommon->next_id($choice_table
,array('entity_id'=>$attrib['entity_id'],'cat_id'=>$attrib['cat_id'],'attrib_id'=>$attrib['id']));
-
- $values= array(
- $attrib['entity_id'],
- $attrib['cat_id'],
- $attrib['id'],
- $choice_id,
- $attrib['new_choice']
- );
-
- $values =
$this->bocommon->validate_db_insert($values);
-
- $GLOBALS['phpgw']->db->Execute("INSERT INTO
$choice_table (entity_id,cat_id,attrib_id,id,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 entity_id=" . $attrib['entity_id']. " AND cat_id=" .
$attrib['cat_id']. " AND attrib_id=" . $attrib['id'] ." AND id=" .
$attrib['delete_choice'][$i]);
- }
- }
-
- $GLOBALS['phpgw']->db->committrans();
-
- $receipt['message'][] = array('msg' =>
lang('Attribute has been edited'));
-
- return $receipt;
- }
- function resort_attrib($data)
- {
- if(is_array($data))
- {
- $resort =
(isset($data['resort'])?$data['resort']:'up');
- $entity_id =
(isset($data['entity_id'])?$data['entity_id']:0);
- $cat_id =
(isset($data['cat_id'])?$data['cat_id']:0);
- $id = (isset($data['id'])?$data['id']:'');
- }
-
- $sql = "SELECT attrib_sort FROM fm_entity_attribute
where entity_id=$entity_id AND cat_id=$cat_id AND id=$id";
- $dbresult = $GLOBALS['phpgw']->db->Execute($sql);
- $attrib_sort = $dbresult->fields['attrib_sort'];
- $sql2 = "SELECT max(attrib_sort) as max_sort FROM
fm_entity_attribute where entity_id=$entity_id AND cat_id=$cat_id";
- $dbresult = $GLOBALS['phpgw']->db->Execute($sql);
- $max_sort = $dbresult->fields['max_sort'];
-
- switch($resort)
- {
- case 'up':
- if($attrib_sort>1)
- {
- $sql = "UPDATE
fm_entity_attribute set attrib_sort=$attrib_sort WHERE entity_id=$entity_id AND
cat_id=$cat_id AND attrib_sort =" . ($attrib_sort-1);
-
$GLOBALS['phpgw']->db->Execute($sql);
- $sql = "UPDATE
fm_entity_attribute set attrib_sort=" . ($attrib_sort-1) ." WHERE
entity_id=$entity_id AND cat_id=$cat_id AND id=$id";
-
$GLOBALS['phpgw']->db->Execute($sql);
- }
- break;
- case 'down':
- if($max_sort > $attrib_sort)
- {
- $sql = "UPDATE
fm_entity_attribute set attrib_sort=$attrib_sort WHERE entity_id=$entity_id AND
cat_id=$cat_id AND attrib_sort =" . ($attrib_sort+1);
-
$GLOBALS['phpgw']->db->Execute($sql);
- $sql = "UPDATE
fm_entity_attribute set attrib_sort=" . ($attrib_sort+1) ." WHERE
entity_id=$entity_id AND cat_id=$cat_id AND id=$id";
-
$GLOBALS['phpgw']->db->Execute($sql);
- }
- break;
- default:
- return;
- break;
- }
- }
-
- }
-?>
+<?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_soadmin_entity
+ {
+ var $grants;
+
+ function property_soadmin_entity($entity_id='',$cat_id='')
+ {
+ $this->currentapp = 'property';
//$GLOBALS['phpgw_info']['flags']['currentapp'];
+ $this->db = $GLOBALS['phpgw']->db;
+ $this->db2 = $this->db;
+ $this->account =
$GLOBALS['phpgw_data']['user']['id'];
+ $this->bocommon =
CreateObject($this->currentapp.'_bocommon');
+
+ $this->join = $this->bocommon->join;
+
+ if($entity_id && $cat_id)
+ {
+ $this->category_name =
$this->read_category_name($entity_id,$cat_id);
+ }
+ }
+
+ function reset_fm_cache()
+ {
+ $GLOBALS['phpgw']->db->Execute("DELETE FROM fm_cache");
+ }
+
+ function read($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']:'');
+ }
+
+ if ($order)
+ {
+ $ordermethod = " order by $order $sort";
+
+ }
+ else
+ {
+ $ordermethod = ' order by id asc';
+ }
+
+ $table = 'fm_entity';
+
+ if($query)
+ {
+ $query = ereg_replace("'",'',$query);
+ $query = ereg_replace('"','',$query);
+
+ $querymethod = " where name LIKE '%$query%' or
descr LIKE '%$query%'";
+ }
+
+ $sql = "SELECT * FROM $table $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)
+ {
+ $entity[] = array
+ (
+ 'id' => $dbresult->fields['id'],
+ 'name' => $dbresult->fields['name'],
+ 'descr' => $dbresult->fields['descr'],
+ 'documentation' =>
$dbresult->fields['documentation']
+ );
+ $dbresult->MoveNext();
+ }
+ return $entity;
+ }
+
+ function read_category($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']:'');
+ $entity_id =
(isset($data['entity_id'])?$data['entity_id']:'');
+ }
+
+ if ($order)
+ {
+ $ordermethod = " order by $order $sort";
+
+ }
+ else
+ {
+ $ordermethod = ' order by id asc';
+ }
+
+ $table = 'fm_entity_category';
+
+ if($query)
+ {
+ $query = ereg_replace("'",'',$query);
+ $query = ereg_replace('"','',$query);
+
+ $querymethod = " AND name LIKE '%$query%' or
descr LIKE '%$query%'";
+ }
+
+ $sql = "SELECT * FROM $table WHERE entity_id=$entity_id
$querymethod";
+
+ $dbresult2 = $GLOBALS['phpgw']->db->Execute($sql);
+ $this->total_records = $dbresult2->_numOfRows;
+
+ if(!$allrows)
+ {
+ $dbresult =
$GLOBALS['phpgw']->db->SelectLimit($sql . $ordermethod,$maxmatchs,$start);
+ }
+ else
+ {
+ $dbresult = $GLOBALS['phpgw']->db->Execute($sql
. $ordermethod);
+ }
+
+ while (!$dbresult->EOF)
+ {
+ $standard[] = array
+ (
+ 'id' => $dbresult->fields['id'],
+ 'name' => $dbresult->fields['name'],
+ 'prefix'=> $dbresult->fields['prefix'],
+ 'descr' => $dbresult->fields['descr']
+ );
+ $dbresult->MoveNext();
+ }
+ return $standard;
+ }
+
+ function read_status($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']:'');
+ $entity_id =
(isset($data['entity_id'])?$data['entity_id']:'');
+ $cat_id =
(isset($data['cat_id'])?$data['cat_id']:'');
+ }
+
+ if ($order)
+ {
+ $ordermethod = " order by $order $sort";
+
+ }
+ else
+ {
+ $ordermethod = ' order by id asc';
+ }
+
+ $table = 'fm_entity_'. $entity_id .'_'.$cat_id .
'_status';
+
+ if($query)
+ {
+ $query = ereg_replace("'",'',$query);
+ $query = ereg_replace('"','',$query);
+
+ $querymethod = " AND name LIKE '%$query%' or
descr LIKE '%$query%'";
+ }
+
+ $sql = "SELECT * FROM $table $querymethod";
+
+ $dbresult2 = $GLOBALS['phpgw']->db->Execute($sql);
+ $this->total_records = $dbresult2->_numOfRows;
+
+ if(!$allrows)
+ {
+ $dbresult =
$GLOBALS['phpgw']->db->SelectLimit($sql . $ordermethod,$maxmatchs,$start);
+ }
+ else
+ {
+ $dbresult = $GLOBALS['phpgw']->db->Execute($sql
. $ordermethod);
+ }
+
+ while (!$dbresult->EOF)
+ {
+ $status[] = array
+ (
+ 'id' => $dbresult->fields['id'],
+ 'descr' => $dbresult->fields['descr']
+ );
+
+ $dbresult->MoveNext();
+ }
+ return $status;
+ }
+
+
+ function read_single($id)
+ {
+
+ $sql = "SELECT * FROM fm_entity where id='$id'";
+
+ $dbresult = $GLOBALS['phpgw']->db->Execute($sql);
+
+ while (!$dbresult->EOF)
+ {
+ $entity['id'] =
$dbresult->fields['id'];
+ $entity['name'] =
$dbresult->fields['name'];
+ $entity['descr'] =
$dbresult->fields['descr'];
+ $entity['location_form'] =
$dbresult->fields['location_form'];
+ $entity['lookup_entity'] =
unserialize($dbresult->fields['lookup_entity']);
+ $entity['documentation'] =
$dbresult->fields['documentation'];
+ $dbresult->MoveNext();
+ }
+
+ $sql = "SELECT location FROM fm_entity_lookup where
entity_id=$id AND type='lookup'";
+
+ $dbresult = $GLOBALS['phpgw']->db->Execute($sql);
+
+ while (!$dbresult->EOF)
+ {
+ $entity['include_entity_for'][] =
$dbresult->fields['location'];
+ $dbresult->MoveNext();
+ }
+
+ $sql = "SELECT location FROM fm_entity_lookup where
entity_id=$id AND type='start'";
+
+ $dbresult = $GLOBALS['phpgw']->db->Execute($sql);
+
+ while (!$dbresult->EOF)
+ {
+ $entity['start_entity_from'][] =
$dbresult->fields['location'];
+ $dbresult->MoveNext();
+ }
+
+ return $entity;
+ }
+
+ function read_single_category($entity_id,$cat_id)
+ {
+ $sql = "SELECT * FROM fm_entity_category where
entity_id=$entity_id AND id=$cat_id";
+
+ $dbresult = $GLOBALS['phpgw']->db->Execute($sql);
+
+ if (!$dbresult->EOF)
+ {
+ $category['id'] =
$dbresult->fields['id'];
+ $category['name'] =
$dbresult->fields['name'];
+ $category['descr'] =
$dbresult->fields['descr'];
+ $category['prefix'] =
$dbresult->fields['prefix'];
+ $category['lookup_tenant'] =
$dbresult->fields['lookup_tenant'];
+ $category['tracking'] =
$dbresult->fields['tracking'];
+ $category['location_level'] =
$dbresult->fields['location_level'];
+ $category['fileupload'] =
$dbresult->fields['fileupload'];
+ $category['loc_link'] =
$dbresult->fields['loc_link'];
+ return $category;
+ }
+ }
+
+ function read_category_name($entity_id,$cat_id)
+ {
+ $sql = "SELECT * FROM fm_entity_category where
entity_id=$entity_id AND id=$cat_id";
+ $dbresult = $GLOBALS['phpgw']->db->Execute($sql);
+ return $dbresult->fields['name'];
+ }
+
+ function read_single_status($entity_id,$cat_id,$id)
+ {
+
+ $table = 'fm_entity_'. $entity_id .'_'.$cat_id .
'_status';
+ $sql = "SELECT * FROM $table where id='$id'";
+
+ $dbresult = $GLOBALS['phpgw']->db->Execute($sql);
+
+ if (!$dbresult->EOF)
+ {
+ $status['id'] =
$dbresult->fields['id'];
+ $status['descr'] =
$dbresult->fields['descr'];
+
+ return $status;
+ }
+ }
+
+ function add_entity($entity)
+ {
+ $entity['name'] =
$this->db->db_addslashes($entity['name']);
+ $entity['descr'] =
$this->db->db_addslashes($entity['descr']);
+
+ $entity['id'] = $this->bocommon->next_id('fm_entity');
+
+ $values= array(
+ $entity['id'],
+ $entity['name'],
+ $entity['descr'],
+ $entity['location_form'],
+ $entity['documentation']
+ );
+
+ $values = $this->bocommon->validate_db_insert($values);
+
+ $GLOBALS['phpgw']->db->Execute("INSERT INTO fm_entity
(id,name, descr,location_form,documentation) "
+ . "VALUES ($values)");
+
+
+ $values_acl_location= array(
+ '.entity.' . $entity['id'],
+ $entity['name'],
+ 1
+ );
+
+ $values_acl_location =
$this->bocommon->validate_db_insert($values_acl_location);
+
+ $GLOBALS['phpgw']->db->Execute("INSERT INTO
fm_acl_location (id,descr,allow_grant) "
+ . "VALUES ($values_acl_location)");
+
+ $receipt['id']= $entity['id'];
+
+ $receipt['message'][] = array('msg'=> lang('entity has
been added'));
+ return $receipt;
+ }
+
+
+ function add_status($values,$entity_id,$cat_id)
+ {
+ $values['id'] = $this->db->db_addslashes($values['id']);
+ $values['descr'] =
$this->db->db_addslashes($values['descr']);
+
+ $values_insert= array(
+ $values['id'],
+ $values['descr'],
+ );
+
+ $values_insert =
$this->bocommon->validate_db_insert($values_insert);
+
+ $table = 'fm_entity_'. $entity_id .'_'.$cat_id .
'_status';
+
+ $GLOBALS['phpgw']->db->Execute("INSERT INTO $table
(id,descr) VALUES ($values_insert)");
+
+ $receipt['id']= $values['id'];
+
+ $receipt['message'][] = array('msg'=> lang('status has
been added'));
+ return $receipt;
+ }
+
+
+ function add_category($values)
+ {
+ $values['name'] =
$this->db->db_addslashes($values['name']);
+ $values['descr'] =
$this->db->db_addslashes($values['descr']);
+
+ $values['id'] =
$this->bocommon->next_id('fm_entity_category',array('entity_id'=>$values['entity_id']));
+
+ $location_type =
$this->bocommon->next_id('fm_location_type');
+
+ $values_insert= array(
+ $values['entity_id'],
+ $values['id'],
+ $values['name'],
+ $values['descr'],
+ $values['prefix'],
+ $values['lookup_tenant'],
+ $values['tracking'],
+ $values['location_level'],
+ $values['fileupload'],
+ $values['loc_link']
+ );
+
+ $values_insert =
$this->bocommon->validate_db_insert($values_insert);
+
+
+ $GLOBALS['phpgw']->db->begintrans();
+
+ $GLOBALS['phpgw']->db->Execute("INSERT INTO
fm_entity_category (entity_id,id,name,
descr,prefix,lookup_tenant,tracking,location_level,fileupload,loc_link) "
+ . "VALUES ($values_insert)");
+
+ $values_acl_location= array(
+ '.entity.' . $values['entity_id'] . '.' .
$values['id'],
+ $values['name'],
+ 1
+ );
+
+ $values_acl_location =
$this->bocommon->validate_db_insert($values_acl_location);
+
+ $GLOBALS['phpgw']->db->Execute("INSERT INTO
fm_acl_location (id,descr,allow_grant) "
+ . "VALUES ($values_acl_location)");
+
+ $receipt['id']= $values['id'];
+
+ $this->init_process();
+
+ $fd=array();
+ $fd['id'] = array('type' => 'int', 'precision' => 4,
'nullable' => False);
+ $fd['num'] = array('type' => 'varchar', 'precision' =>
16, 'nullable' => False);
+ $fd['p_num'] = array('type' => 'varchar', 'precision'
=> 16, 'nullable' => True);
+ $fd['p_entity_id'] = array('type' => 'int', 'precision'
=> 4, 'nullable' => True);
+ $fd['p_cat_id'] = array('type' => 'int', 'precision' =>
4, 'nullable' => True);
+ $fd['location_code'] = array('type' => 'varchar',
'precision' => 25, 'nullable' => True);
+
+ for ($i=1; $i<$location_type; $i++)
+ {
+ $fd['loc' . $i] = array('type' => 'varchar',
'precision' => 4, 'nullable' => True);
+ }
+
+ $fd['address'] = array('type' => 'varchar', 'precision'
=> 100, 'nullable' => True);
+ $fd['tenant_id'] = array('type' => 'int', 'precision'
=> 4, 'nullable' => True);
+ $fd['contact_phone'] = array('type' => 'varchar',
'precision' => 30, 'nullable' => True);
+ $fd['status'] = array('type' => 'int', 'precision' =>
4, 'nullable' => True);
+ $fd['entry_date'] = array('type' => 'int', 'precision'
=> 4, 'nullable' => True);
+ $fd['user_id'] = array('type' => 'int', 'precision' =>
4, 'nullable' => True);
+
+ $pk[]= 'id';
+ $table = 'fm_entity_'.
$values['entity_id'] .'_'.$values['id'];
+/*
+ $fd_status['id'] = array('type' => 'varchar',
'precision' => 20, 'nullable' => False);
+ $fd_status['descr'] = array('type' => 'varchar',
'precision' => 255, 'nullable' => False);
+ $pk_status[]= 'id';
+
+ $statustable = $table . '_' .'status';
+*/
+ if(($this->oProc->CreateTable($table,array('fd' =>
$fd,'pk' => $pk,'fk' => $fk,'ix' => array('location_code'),'uc' => array()))))
+// &&
($this->oProc->CreateTable($statustable,array('fd' => $fd_status,'pk' =>
$pk_status,'fk' => $fk_status,'ix' => False,'uc' => array()))))
+ {
+
+ $values_insert= array(
+ $values['entity_id'],
+ $values['id'],
+ 1,
+ 'status',
+ 'Status',
+ 'Status',
+ 'LB',
+ 1,
+ 'True'
+ );
+
+ $values_insert =
$this->bocommon->validate_db_insert($values_insert);
+
+ $GLOBALS['phpgw']->db->Execute("INSERT INTO
fm_entity_attribute
(entity_id,cat_id,id,column_name,input_text,statustext,datatype,attrib_sort,nullable)
"
+ . "VALUES ($values_insert)");
+
+ $receipt['message'][] = array('msg' =>
lang('table %1 has been saved',$table));
+ $GLOBALS['phpgw']->db->committrans();
+ }
+ else
+ {
+ $receipt['error'][] = array('msg' =>
lang('table could not be added') );
+ if($this->db->Transaction)
+ {
+ $GLOBALS['phpgw']->db->rollbacktrans();
+ }
+ else
+ {
+ $GLOBALS['phpgw']->db->Execute("DELETE
FROM fm_entity_category WHERE id=" . $values['id'] . " AND entity_id=" .
$values['entity_id']);
+ unset($receipt['id']);
+
+ }
+ }
+
+ return $receipt;
+ }
+
+ function edit_status($values,$entity_id,$cat_id)
+ {
+ $table = 'fm_entity_'. $entity_id .'_'.$cat_id .
'_status';
+
+ $values['descr'] =
$this->db->db_addslashes($values['descr']);
+
+ $value_set=array(
+ 'descr' => $values['descr'],
+ );
+
+ $value_set =
$this->bocommon->validate_db_update($value_set);
+
+ $this->db->query("UPDATE $table set $value_set WHERE
id='" . $values['id'] . "'");
+
+ $receipt['message'][] = array('msg'=> lang('Status has
been edited'));
+
+ return $receipt;
+ }
+
+ function edit_entity($entity)
+ {
+ if (!$entity['name'])
+ {
+ $receipt['error'][] = array('msg'=>lang('Name
not entered!'));
+ }
+
+ if (!$receipt['error'])
+ {
+ $table = 'fm_entity';
+
+ $entity['name'] =
$this->db->db_addslashes($entity['name']);
+ $entity['descr'] =
$this->db->db_addslashes($entity['descr']);
+
+ if(!$entity['location_form'])
+ {
+ unset($entity['lookup_entity']);
+ }
+
+ $value_set=array(
+ 'descr' => $entity['descr'],
+ 'name' => $entity['name'],
+ 'location_form' => $entity['location_form'],
+ 'lookup_entity' =>
serialize($entity['lookup_entity']),
+ 'documentation' => $entity['documentation']
+ );
+
+ $value_set =
$this->bocommon->validate_db_update($value_set);
+
+ $GLOBALS['phpgw']->db->begintrans();
+
+ $GLOBALS['phpgw']->db->Execute("UPDATE $table
set $value_set WHERE id=" . $entity['id']);
+
+ $value_set_acl=array(
+ 'descr' =>
$entity['name']
+ );
+
+ $value_set_acl =
$this->bocommon->validate_db_update($value_set_acl);
+
+ $GLOBALS['phpgw']->db->Execute("UPDATE
fm_acl_location set $value_set_acl WHERE id='.entity." . $entity['id']. "'");
+
+ $GLOBALS['phpgw']->db->Execute("DELETE FROM
fm_entity_lookup WHERE type='lookup' AND entity_id=" . $entity['id']);
+ if (isset($entity['include_entity_for']) AND
is_array($entity['include_entity_for']))
+ {
+ foreach($entity['include_entity_for']
as $location)
+ {
+
$GLOBALS['phpgw']->db->Execute("INSERT INTO fm_entity_lookup
(entity_id,location,type)"
+ . "VALUES (" .$entity['id'] .
",'$location','lookup' )");
+ }
+ }
+
+ $GLOBALS['phpgw']->db->Execute("DELETE FROM
fm_entity_lookup WHERE type='start' AND entity_id=" . $entity['id']);
+
+ if (isset($entity['start_entity_from']) AND
is_array($entity['start_entity_from']))
+ {
+ foreach($entity['start_entity_from'] as
$location)
+ {
+
$GLOBALS['phpgw']->db->Execute("INSERT INTO fm_entity_lookup
(entity_id,location,type)"
+ . "VALUES (" .$entity['id'] .
",'$location','start' )");
+ }
+ }
+
+ $GLOBALS['phpgw']->db->committrans();
+
+ $receipt['message'][] = array('msg'=>
lang('entity has been edited'));
+ }
+ else
+ {
+ $receipt['error'][] = array('msg' =>
lang('entity has NOT been edited'));
+ }
+
+ return $receipt;
+ }
+
+ function edit_category($entity)
+ {
+
+ if (!$entity['name'])
+ {
+ $receipt['error'][] = array('msg'=>lang('Name
not entered!'));
+ }
+
+ if (!$receipt['error'])
+ {
+ $table = 'fm_entity_category';
+
+ $entity['name'] =
$this->db->db_addslashes($entity['name']);
+ $entity['descr'] =
$this->db->db_addslashes($entity['descr']);
+
+ $value_set=array(
+ 'descr' =>
$entity['descr'],
+ 'name' =>
$entity['name'],
+ 'prefix' =>
$entity['prefix'],
+ 'lookup_tenant' =>
$entity['lookup_tenant'],
+ 'tracking' =>
$entity['tracking'],
+ 'location_level'=>
$entity['location_level'],
+ 'fileupload' =>
$entity['fileupload'],
+ 'loc_link' => $entity['loc_link']
+ );
+
+ $value_set =
$this->bocommon->validate_db_update($value_set);
+
+ $GLOBALS['phpgw']->db->Execute("UPDATE $table
set $value_set WHERE entity_id=" . $entity['entity_id']. " AND id=" .
$entity['id']);
+
+ $value_set_acl=array(
+ 'descr' =>
$entity['name']
+ );
+
+ $value_set_acl =
$this->bocommon->validate_db_update($value_set_acl);
+
+ $GLOBALS['phpgw']->db->Execute("UPDATE
fm_acl_location set $value_set_acl WHERE id='.entity." . $entity['entity_id'].
"." . $entity['id']. "'");
+
+
+ $receipt['message'][] = array('msg'=>
lang('entity has been edited'));
+ }
+ else
+ {
+ $receipt['error'][] = array('msg' =>
lang('entity has NOT been edited'));
+ }
+
+ return $receipt;
+ }
+
+ function delete_entity($id)
+ {
+
$category_list=$this->read_category(array('entity_id'=>$id));
+ $GLOBALS['phpgw']->db->Execute("DELETE FROM fm_entity
WHERE id=$id");
+ $GLOBALS['phpgw']->db->Execute("DELETE FROM
fm_entity_category WHERE entity_id=$id");
+ $GLOBALS['phpgw']->db->Execute("DELETE FROM
fm_entity_attribute WHERE entity_id=$id");
+ $GLOBALS['phpgw']->db->Execute("DELETE FROM
fm_acl_location WHERE id LIKE '.entity." . $id ."%'");
+ $GLOBALS['phpgw']->db->Execute("DELETE FROM fm_acl2
WHERE acl_location LIKE '.entity." . $id ."%'");
+ if (isset($category_list) AND is_array($category_list))
+ {
+ $this->init_process();
+
+ foreach($category_list as $entry)
+ {
+ $this->oProc->DropTable('fm_entity_' .
$id . '_' . $entry['id']);
+ }
+ }
+
+ }
+
+ function delete_category($id,$entity_id)
+ {
+ $this->init_process();
+ $this->oProc->DropTable('fm_entity_' . $entity_id . '_'
. $id);
+// $this->oProc->DropTable('fm_entity_' . $entity_id . '_'
. $id . '_' . 'status');
+ $GLOBALS['phpgw']->db->Execute("DELETE FROM
fm_entity_category WHERE entity_id= $entity_id AND id= $id");
+ $GLOBALS['phpgw']->db->Execute("DELETE FROM
fm_entity_attribute WHERE entity_id= $entity_id AND cat_id= $id");
+ $GLOBALS['phpgw']->db->Execute("DELETE FROM
fm_acl_location WHERE id='.entity." . $entity_id . "." . $id ."'");
+ $GLOBALS['phpgw']->db->Execute("DELETE FROM fm_acl2
WHERE acl_location='.entity." . $entity_id . "." . $id ."'");
+ }
+
+ function delete_attrib($cat_id,$entity_id,$attrib_id)
+ {
+ $this->init_process();
+
+ $sql = "SELECT * FROM fm_entity_attribute WHERE
entity_id=$entity_id AND cat_id=$cat_id AND id=$attrib_id";
+
+ $dbresult = $GLOBALS['phpgw']->db->Execute($sql);
+ $ColumnName =
$dbresult->fields['column_name'];
+
+ $this->oProc->DropColumn('fm_entity_' .$entity_id.'_'.
$cat_id,'', $ColumnName);
+
+ $sql = "SELECT attrib_sort FROM fm_entity_attribute
where entity_id=$entity_id AND cat_id=$cat_id AND id=$attrib_id";
+ $dbresult = $GLOBALS['phpgw']->db->Execute($sql);
+ $attrib_sort = $dbresult->fields['attrib_sort'];
+ $sql2 = "SELECT max(attrib_sort) as max_sort FROM
fm_entity_attribute where entity_id=$entity_id AND cat_id=$cat_id";
+ $dbresult = $GLOBALS['phpgw']->db->Execute($sql2);
+ $max_sort = $dbresult->fields['max_sort'];
+ if($max_sort>$attrib_sort)
+ {
+ $sql = "UPDATE fm_entity_attribute set
attrib_sort=attrib_sort-1 WHERE entity_id=$entity_id AND cat_id=$cat_id AND
attrib_sort > $attrib_sort";
+ $GLOBALS['phpgw']->db->Execute($sql);
+ }
+
+ $GLOBALS['phpgw']->db->Execute("DELETE FROM
fm_entity_attribute WHERE entity_id=$entity_id AND cat_id=$cat_id AND
id=$attrib_id");
+ }
+
+ function delete_status($cat_id,$entity_id,$status_id)
+ {
+ $table = 'fm_entity_'. $entity_id .'_'.$cat_id .
'_status';
+
+ $GLOBALS['phpgw']->db->Execute("DELETE FROM $table
WHERE id='$status_id'");
+ }
+
+ function read_attrib($data)
+ {
+
+//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']:'');
+ $entity_id =
(isset($data['entity_id'])?$data['entity_id']:0);
+ $cat_id =
(isset($data['cat_id'])?$data['cat_id']:0);
+ }
+
+ 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 = " AND (fm_entity_attribute.name
LIKE '%$query%' or fm_entity_attribute.descr LIKE '%$query%')";
+ }
+
+ $sql = "SELECT * FROM fm_entity_attribute WHERE
entity_id=$entity_id AND cat_id = $cat_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)
+ {
+ $attrib[] = array
+ (
+ 'id' =>
$dbresult->fields['id'],
+ 'entity_type' =>
$dbresult->fields['type_id'],
+ 'attrib_sort' =>
$dbresult->fields['attrib_sort'],
+ 'list' =>
$dbresult->fields['list'],
+ 'lookup_form' =>
$dbresult->fields['lookup_form'],
+ 'entity_form' =>
$dbresult->fields['entity_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']
+ );
+ $dbresult->MoveNext();
+ }
+ return $attrib;
+ }
+
+ function read_single_attrib($entity_id,$cat_id,$id)
+ {
+
+ $sql = "SELECT * FROM fm_entity_attribute where
entity_id=$entity_id AND cat_id=$cat_id AND id=$id";
+
+ $dbresult = $GLOBALS['phpgw']->db->Execute($sql);
+
+ if (!$dbresult->EOF)
+ {
+ $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_id']
= $dbresult->fields['type_id'];
+ $attrib['type_name']
= $dbresult->fields['type_name'];
+ $attrib['lookup_form']
= $dbresult->fields['lookup_form'];
+ $attrib['list']
= $dbresult->fields['list'];
+ if($dbresult->fields['datatype']=='R' ||
$dbresult->fields['datatype']=='CH' || $dbresult->fields['datatype']=='LB')
+ {
+ $attrib['choice'] =
$this->read_attrib_choice($entity_id,$cat_id,$id);
+ }
+
+ return $attrib;
+ }
+ }
+
+ function read_attrib_choice($entity_id,$cat_id,$attrib_id)
+ {
+ $choice_table = 'fm_entity_choice';
+ $sql = "SELECT * FROM $choice_table WHERE
entity_id=$entity_id AND cat_id=$cat_id AND attrib_id=$attrib_id";
+ $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)
+ {
+
+ $attrib['column_name'] =
$this->db->db_addslashes($attrib['column_name']);
+ $attrib['input_text'] =
$this->db->db_addslashes($attrib['input_text']);
+ $attrib['statustext'] =
$this->db->db_addslashes($attrib['statustext']);
+ $attrib['default'] =
$this->db->db_addslashes($attrib['default']);
+ $attrib['id'] =
$this->bocommon->next_id('fm_entity_attribute',array('entity_id'=>$attrib['entity_id'],'cat_id'=>$attrib['cat_id']));
+
+ $sql = "SELECT max(attrib_sort) as max_sort FROM
fm_entity_attribute where entity_id=" . $attrib['entity_id'] . " AND cat_id=" .
$attrib['cat_id'];
+ $dbresult = $GLOBALS['phpgw']->db->Execute($sql);
+ $attrib_sort = $dbresult->fields['max_sort']+1;
+
+ $values= array(
+ $attrib['entity_id'],
+ $attrib['cat_id'],
+ $attrib['id'],
+ $attrib['column_name'],
+ $attrib['input_text'],
+ $attrib['statustext'],
+ $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
fm_entity_attribute (entity_id,cat_id,id,column_name, input_text,
statustext,list,attrib_sort, datatype,precision_,scale,default_value,nullable) "
+ . "VALUES ($values)");
+
+ $receipt['id']= $attrib['id'];
+
+ $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('fm_entity_'.$attrib['entity_id'] . '_' .
$attrib['cat_id'],$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 fm_entity_attribute WHERE entity_id=" . $attrib['entity_id']. " AND
cat_id=" . $attrib['id']. " AND id='" . $receipt['id'] . "'");
+ unset($receipt['id']);
+
+ }
+ }
+
+ return $receipt;
+ }
+
+ function init_process()
+ {
+ $this->oProc
=
CreateObject('phpgwapi_schema_proc',$GLOBALS['phpgw_info']['server']['db_type']);
+ $this->oProc->m_odb
= $this->db;
+ $this->oProc->m_odb->Halt_On_Error = 'report';
+ }
+
+ function edit_attrib($attrib)
+ {
+
+ $attrib['column_name'] =
$this->db->db_addslashes($attrib['column_name']);
+ $attrib['input_text'] =
$this->db->db_addslashes($attrib['input_text']);
+ $attrib['statustext'] =
$this->db->db_addslashes($attrib['statustext']);
+ $attrib['default'] =
$this->db->db_addslashes($attrib['default']);
+
+ $GLOBALS['phpgw']->db->Execute("SELECT column_name FROM
fm_entity_attribute WHERE entity_id=" . $attrib['entity_id']. " AND cat_id=" .
$attrib['cat_id']. " AND id='" . $attrib['id']. "'");
+ $OldColumnName =
$dbresult->fields['column_name'];
+
+ $GLOBALS['phpgw']->db->begintrans();
+
+ if($OldColumnName !=$attrib['column_name'])
+ {
+
+ $value_set=array(
+ 'column_name' =>
$attrib['column_name'],
+ 'input_text' =>
$attrib['input_text'],
+ 'statustext' =>
$attrib['statustext'],
+ '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
fm_entity_attribute set $value_set WHERE entity_id=" . $attrib['entity_id']. "
AND cat_id=" . $attrib['cat_id']. " AND id=" . $attrib['id']);
+
+ if($attrib['column_info']['type']!='R' &&
$attrib['column_info']['type']!='CH' && $attrib['column_info']['type']!='LB')
+ {
+ $GLOBALS['phpgw']->db->Execute("DELETE
FROM $choice_table WHERE entity_id=" . $attrib['entity_id']. " AND cat_id=" .
$attrib['cat_id']. " AND attrib_id=" . $attrib['id']);
+ }
+
+
+ $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->RenameColumn('fm_entity_'.$attrib['entity_id'] . '_' .
$attrib['cat_id'], $OldColumnName, $attrib['column_name']);
+
$this->oProc->AlterColumn('fm_entity_'.$attrib['entity_id'] . '_' .
$attrib['cat_id'],$attrib['column_name'],$attrib['column_info']);
+ }
+
+ $choice_table ='fm_entity_choice';
+
+ if($attrib['new_choice'])
+ {
+ $choice_id =
$this->bocommon->next_id($choice_table
,array('entity_id'=>$attrib['entity_id'],'cat_id'=>$attrib['cat_id'],'attrib_id'=>$attrib['id']));
+
+ $values= array(
+ $attrib['entity_id'],
+ $attrib['cat_id'],
+ $attrib['id'],
+ $choice_id,
+ $attrib['new_choice']
+ );
+
+ $values =
$this->bocommon->validate_db_insert($values);
+
+ $GLOBALS['phpgw']->db->Execute("INSERT INTO
$choice_table (entity_id,cat_id,attrib_id,id,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 entity_id=" . $attrib['entity_id']. " AND cat_id=" .
$attrib['cat_id']. " AND attrib_id=" . $attrib['id'] ." AND id=" .
$attrib['delete_choice'][$i]);
+ }
+ }
+
+ $GLOBALS['phpgw']->db->committrans();
+
+ $receipt['message'][] = array('msg' =>
lang('Attribute has been edited'));
+
+ return $receipt;
+ }
+ function resort_attrib($data)
+ {
+ if(is_array($data))
+ {
+ $resort =
(isset($data['resort'])?$data['resort']:'up');
+ $entity_id =
(isset($data['entity_id'])?$data['entity_id']:0);
+ $cat_id =
(isset($data['cat_id'])?$data['cat_id']:0);
+ $id = (isset($data['id'])?$data['id']:'');
+ }
+
+ $sql = "SELECT attrib_sort FROM fm_entity_attribute
where entity_id=$entity_id AND cat_id=$cat_id AND id=$id";
+ $dbresult = $GLOBALS['phpgw']->db->Execute($sql);
+ $attrib_sort = $dbresult->fields['attrib_sort'];
+ $sql2 = "SELECT max(attrib_sort) as max_sort FROM
fm_entity_attribute where entity_id=$entity_id AND cat_id=$cat_id";
+ $dbresult = $GLOBALS['phpgw']->db->Execute($sql);
+ $max_sort = $dbresult->fields['max_sort'];
+
+ switch($resort)
+ {
+ case 'up':
+ if($attrib_sort>1)
+ {
+ $sql = "UPDATE
fm_entity_attribute set attrib_sort=$attrib_sort WHERE entity_id=$entity_id AND
cat_id=$cat_id AND attrib_sort =" . ($attrib_sort-1);
+
$GLOBALS['phpgw']->db->Execute($sql);
+ $sql = "UPDATE
fm_entity_attribute set attrib_sort=" . ($attrib_sort-1) ." WHERE
entity_id=$entity_id AND cat_id=$cat_id AND id=$id";
+
$GLOBALS['phpgw']->db->Execute($sql);
+ }
+ break;
+ case 'down':
+ if($max_sort > $attrib_sort)
+ {
+ $sql = "UPDATE
fm_entity_attribute set attrib_sort=$attrib_sort WHERE entity_id=$entity_id AND
cat_id=$cat_id AND attrib_sort =" . ($attrib_sort+1);
+
$GLOBALS['phpgw']->db->Execute($sql);
+ $sql = "UPDATE
fm_entity_attribute set attrib_sort=" . ($attrib_sort+1) ." WHERE
entity_id=$entity_id AND cat_id=$cat_id AND id=$id";
+
$GLOBALS['phpgw']->db->Execute($sql);
+ }
+ break;
+ default:
+ return;
+ break;
+ }
+ }
+
+ }
+?>
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Phpgroupware-cvs] property/class.soadmin_entity.php, 1.1.1.3,
nomail <=