[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Phpgroupware-cvs] property/class.soadmin_location.php, 1.1.1.3
From: |
nomail |
Subject: |
[Phpgroupware-cvs] property/class.soadmin_location.php, 1.1.1.3 |
Date: |
Fri, 21 May 2004 15:42:56 -0000 |
Update of /property
Modified Files:
Branch:
class.soadmin_location.php
date: 2004/04/23 21:26:33; author: sigurdne; state: Exp; lines: +816 -816
Log Message:
no message
=====================================================================
Index: property/class.soadmin_location.php
diff -u property/class.soadmin_location.php:1.1.1.2
property/class.soadmin_location.php:1.1.1.3
--- property/class.soadmin_location.php:1.1.1.2 Fri Apr 23 20:25:39 2004
+++ property/class.soadmin_location.php Fri Apr 23 21:26:33 2004
@@ -1,816 +1,816 @@
-<?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_location
- {
- var $grants;
-
- function property_soadmin_location()
- {
- $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;
-
- }
-
-
- 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']:'');
- }
-
- if ($order)
- {
- $ordermethod = " order by $order $sort";
-
- }
- else
- {
- $ordermethod = ' order by id asc';
- }
-
- $table = 'fm_location_type';
-
- 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;
- $dbresult = $GLOBALS['phpgw']->db->SelectLimit($sql .
$ordermethod,$maxmatchs,$start);
-
- 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_config($data='')
- {
- if(is_array($data))
- {
- if ($data['start'])
- {
- $start=$data['start'];
- }
- else
- {
- $start=0;
- }
-
-// $query =
(isset($data['start'])?$data['start']:0);
- $query =
(isset($data['query'])?$data['query']:'');
- $sort =
(isset($data['sort'])?$data['sort']:'DESC');
- $order =
(isset($data['order'])?$data['order']:'');
- }
-
- if ($order)
- {
- $ordermethod = " order by $order $sort";
-
- }
- else
- {
- $ordermethod = ' order by column_name asc';
- }
-
- if($query)
- {
- $query = ereg_replace("'",'',$query);
- $query = ereg_replace('"','',$query);
-
- $querymethod = " where name LIKE '%$query%' or
column_name LIKE '%$query%'";
- }
-
- $sql = "SELECT fm_location_config.*
,fm_location_type.name as name FROM fm_location_config $this->join
fm_location_type on fm_location_config.location_type=fm_location_type.id
$querymethod";
-
- $dbresult2 = $GLOBALS['phpgw']->db->Execute($sql);
- $this->total_records = $dbresult2->_numOfRows;
-/* $maxmatchs = 15;
-
-html_print_r($maxmatchs);
-html_print_r($data);
-html_print_r($start);
-echo $sql . $ordermethod;
-
- if(!$allrows)
- {
- $dbresult =
$GLOBALS['phpgw']->db->SelectLimit($sql . $ordermethod,$maxmatchs,$start);
-
- }
- else
- {
- $dbresult = $GLOBALS['phpgw']->db->Execute($sql
. $ordermethod);
- }
-*/
- $dbresult = $GLOBALS['phpgw']->db->Execute($sql
. $ordermethod);
-
-
- while (!$dbresult->EOF)
- {
- $config[] = array
- (
- 'column_name' =>
$dbresult->fields['column_name'],
- 'input_text' =>
$dbresult->fields['column_name'], //input_text
- 'f_key' =>
$dbresult->fields['f_key'],
- 'lookup_form' =>
$dbresult->fields['lookup_form'],
- 'ref_to_category' =>
$dbresult->fields['ref_to_category'],
- 'query_value' =>
$dbresult->fields['query_value'],
- 'reference_table' =>
$dbresult->fields['reference_table'],
- 'reference_id' =>
$dbresult->fields['reference_id'],
- 'location_name' =>
$dbresult->fields['name'],
- 'location_type' =>
$dbresult->fields['location_type']
- );
- $dbresult->MoveNext();
- }
-//html_print_r($config);
- return $config;
- }
-
- function read_config_single($column_name='')
- {
- $dbresult = $GLOBALS['phpgw']->db->Execute("SELECT
location_type FROM fm_location_config where column_name='$column_name'");
-
- return $dbresult->fields['location_type'];
- }
-
-
- function read_single($id)
- {
-
- $table = 'fm_location_type';
-
- $sql = "SELECT * FROM $table where id='$id'";
-
- $dbresult = $GLOBALS['phpgw']->db->Execute($sql);
-
- if (!$dbresult->EOF)
- {
- $standard['id'] =
$dbresult->fields['id'];
- $standard['name'] =
$dbresult->fields['name'];
- $standard['descr'] =
$dbresult->fields['descr'];
- $standard['prefix'] =
$dbresult->fields['prefix'];
-
- return $standard;
- }
- }
-
- function add($standard)
- {
-
- $standard['name'] =
$this->db->db_addslashes($standard['name']);
- $standard['descr'] =
$this->db->db_addslashes($standard['descr']);
-
- $standard['id'] =
$this->bocommon->next_id('fm_location_type');
-
- $GLOBALS['phpgw']->db->begintrans();
-
- $GLOBALS['phpgw']->db->Execute("INSERT INTO
fm_location_type (id,name, descr) "
- . "VALUES ('" . $standard['id'] . "','" .
$standard['name'] . "','" . $standard['descr']. "')");
-
- $receipt['id']= $standard['id'];
-
- $this->init_process();
-
- $fd=array();
- $fd['location_code'] = array('type' => 'varchar',
'precision' => 25, 'nullable' => False);
-
- for ($i=1; $i<$standard['id']+1; $i++)
- {
-
- $fd['loc' . $i] = array('type' => 'varchar',
'precision' => 4, 'nullable' => False);
- $pk[$i-1]= 'loc' . $i;
- }
-
- $fk_table='fm_location'. ($standard['id']-1);
-
- for ($i=1; $i<$standard['id']; $i++)
- {
- $fk['loc' . $i] = $fk_table . '.loc' . $i;
- }
-
-
- if($standard['id']==1)
- {
- $fd['part_of_town_id'] = array('type' => 'int',
'precision' => 2, 'nullable' => True);
- }
-
- $fd['loc' .$standard['id'] . '_name'] = array('type' =>
'varchar', 'precision' => 25, 'nullable' => True);
- $fd['entry_date'] = array('type' => 'int', 'precision'
=> 4, 'nullable' => True);
- $fd['category'] = array('type' => 'int', 'precision' =>
4, 'nullable' => True);
- $fd['user_id'] = array('type' => 'int', 'precision' =>
4, 'nullable' => True);
- $fd['remark'] = array('type' => 'text', 'nullable' =>
True);
- $fd['status'] = array('type' => 'int', 'precision' =>
4, 'nullable' => True);
-
-
$add_columns_in_tables=array('fm_meter','fm_project','fm_tts_tickets','fm_request','fm_document','fm_investment');
-
- if($this->oProc->CreateTable('fm_location'.
$standard['id'],array('fd' => $fd,'pk' => $pk,'fk' => $fk,'ix' =>
array('location_code'),'uc' => array())))
- {
-
- $this->oProc->CreateTable('fm_location'.
$standard['id'] . '_category', array(
- 'fd' => array(
- 'id' => array('type' =>
'int','precision' => '4','nullable' => False),
- 'descr' => array('type' =>
'varchar','precision' => '50','nullable' => True)
- ),
- 'pk' => array('id'),
- 'fk' => array(),
- 'ix' => array(),
- 'uc' => array()));
-
- for ($i=0;$i<count($add_columns_in_tables);$i++)
- {
-
$this->oProc->AddColumn($add_columns_in_tables[$i],'loc'. $standard['id'],
array('type' => 'varchar', 'precision' => 4, 'nullable' => True));
- }
-
- $values_insert= array(
- $standard['id'],
- 1,
- 'status',
- 'Status',
- 'Status',
- 'LB',
- 1,
- 'True'
- );
-
- $values_insert =
$this->bocommon->validate_db_insert($values_insert);
-
- $GLOBALS['phpgw']->db->Execute("INSERT INTO
fm_location_attrib
(type_id,id,column_name,input_text,statustext,datatype,attrib_sort,nullable) "
- . "VALUES ($values_insert)");
-
-
-
- $type_id=$standard['id'];
-
- $GLOBALS['phpgw']->db->Execute("INSERT INTO
fm_location_choice (type_id,attrib_id,id,value) "
- . "VALUES ($type_id,1,1,'ok')");
- $GLOBALS['phpgw']->db->Execute("INSERT INTO
fm_location_choice (type_id,attrib_id,id,value) "
- . "VALUES ($type_id,1,2,'Not Active')");
-
-
- $receipt['message'][] = array('msg' =>
lang('table %1 has been saved','fm_location'. $receipt['id']) );
- $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_location_type WHERE id='" . $standard['id'] . "'");
- unset($receipt['id']);
-
- }
- }
-
- return $receipt;
- }
-
- function edit($standard)
- {
-
- if (!$standard['name'])
- {
- $receipt['error'][] = array('msg'=>lang('Name
not entered!'));
- }
-
- if (!$receipt['error'])
- {
- $table = 'fm_location_type';
-
- $standard['name'] =
$this->db->db_addslashes($standard['name']);
- $standard['descr'] =
$this->db->db_addslashes($standard['descr']);
-
- $GLOBALS['phpgw']->db->Execute("UPDATE $table
set descr='" . $standard['descr'] . "', name='". $standard['name']
- . "' WHERE id='" . $standard['id'].
"'");
-
-
- $receipt['message'][] = array('msg'=>
lang('Standard has been edited'));
- }
- else
- {
- $receipt['error'][] = array('msg' =>
lang('Standard has NOT been edited'));
- }
-
- return $receipt;
- }
-
- function delete($id,$attrib)
- {
- $this->init_process();
-
- if($attrib)
- {
- $table = 'fm_location_attrib';
-
- $dbresult =
$GLOBALS['phpgw']->db->Execute("SELECT column_name,type_id FROM
fm_location_attrib WHERE id='" . $id . "'");
-
- $ColumnName =
$dbresult->fields['column_name'];
- $type_id =
$dbresult->fields['type_id'];
-
- $this->oProc->DropColumn('fm_location'
.$type_id ,'', $ColumnName);
-
- }
- else
- {
- $this->oProc->DropTable('fm_location' . $id);
- $this->oProc->DropTable('fm_location' . $id .
'_category');
-
- $table = 'fm_location_type';
- $attrib_table = 'fm_location_attrib';
- $GLOBALS['phpgw']->db->Execute("DELETE FROM
$attrib_table WHERE type_id='" . $id . "'");
-
- }
- $GLOBALS['phpgw']->db->Execute("DELETE FROM $table
WHERE id='" . $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']:'');
- $type_id =
(isset($data['type_id'])?$data['type_id']:0);
- $lookup_type =
(isset($data['lookup_type'])?$data['lookup_type']:'');
- $allrows =
(isset($data['allrows'])?$data['allrows']:'');
- }
-
- if ($order)
- {
- $ordermethod = " order by $order $sort";
-
- }
- else
- {
- $ordermethod = ' order by
fm_location_attrib.attrib_sort asc';
- }
-
- $table = 'fm_location_attrib';
- $type_table = 'fm_location_type';
-
- if ($lookup_type)
- {
- $filtermethod = " OR (type_id < $lookup_type
AND lookup_form=1) ";
-
- }
-
- if($query)
- {
- $query = ereg_replace("'",'',$query);
- $query = ereg_replace('"','',$query);
-
- $querymethod = " and ($table.name LIKE
'%$query%' or $table.descr LIKE '%$query%')";
- }
-
- $sql = "SELECT
$table.id,$table.type_id,$table.list,$table.attrib_sort,$table.location_form,lookup_form,$table.column_name,$table.size
,statustext,$table.input_text,"
- . " $table.datatype ,$type_table.name as type
FROM $type_table $this->join $table on $table.type_id = $type_table.id "
- . " WHERE $table.type_id= '$type_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'],
- 'location_type' =>
$dbresult->fields['type_id'],
- 'attrib_sort' =>
$dbresult->fields['attrib_sort'],
- 'list' =>
$dbresult->fields['list'],
- 'lookup_form' =>
$dbresult->fields['lookup_form'],
- 'location_form' =>
$dbresult->fields['location_form'],
- 'column_name' =>
$dbresult->fields['column_name'],
- '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($type_id,$id)
- {
-
- $table = 'fm_location_attrib';
- $type_table = 'fm_location_type';
-
- $sql = "SELECT $table.* ,$type_table.name as type_name
FROM $type_table $this->join $table on $table.type_id = $type_id where
$table.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']
= $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($type_id,$id);
- }
-
- return $attrib;
- }
- }
-
- function read_attrib_choice($type_id,$attrib_id)
- {
- $choice_table = 'fm_location_choice';
- $sql = "SELECT * FROM $choice_table WHERE
type_id=$type_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_location_attrib',array('type_id'=>$attrib['type_id']));
-
- $sql = "SELECT max(attrib_sort) as max_sort FROM
fm_location_attrib where type_id=" . $attrib['type_id'];
- $dbresult = $GLOBALS['phpgw']->db->Execute($sql);
-
- $attrib_sort = $dbresult->fields['max_sort']+1;
-
- $values= array(
- $attrib['id'],
- $attrib['column_name'],
- $attrib['input_text'],
- $attrib['statustext'],
- $attrib['type_id'],
- $attrib['lookup_form'],
- $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_location_attrib (id,column_name, input_text, statustext,
type_id,lookup_form,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_location'.$attrib['type_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_location_attrib WHERE 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 save_config($values='',$column_name='')
- {
-
- $dbresult = $GLOBALS['phpgw']->db->Execute("SELECT *
FROM fm_location_config WHERE column_name='$column_name' ");
-
-
- $column_info['type'] =
$dbresult->fields['datatype'];
- $column_info['precision'] =
$dbresult->fields['precision_'];
- $column_info['scale'] =
$dbresult->fields['scale'];
- $column_info['default'] =
$dbresult->fields['default_value'];
- $column_info['nullable'] =
$dbresult->fields['nullable'];
- $location_type =
$dbresult->fields['location_type'];
-
- if(!($location_type==$values[$column_name]))
- {
- $this->init_process();
-
-
if($this->oProc->AddColumn('fm_location'.$values[$column_name],$column_name,
$column_info))
- {
- if($column_name=='street_id')
- {
-
$this->oProc->AddColumn('fm_location'.$values[$column_name],'street_number',
array('type'=>'varchar','precision'=>10));
-
$this->oProc->DropColumn('fm_location' .$location_type ,'','street_number');
- }
-
- $this->oProc->DropColumn('fm_location'
.$location_type ,'', $column_name);
-
-
- $GLOBALS['phpgw']->db->Execute("UPDATE
fm_location_config set
- location_type = '".
$values[$column_name] . "' WHERE column_name='" . $column_name . "'");
-
- $receipt['message'][] = array('msg'
=> lang('column %1 has been moved',$column_name));
- }
- else
- {
- $receipt['message'][] = array('msg'
=> lang('column %1 could not be moved',$column_name));
-
- }
- }
-
- return $receipt;
-
- }
-
-
- 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']);
-
- $dbresult = $GLOBALS['phpgw']->db->Execute("SELECT
column_name FROM fm_location_attrib WHERE 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'],
- 'type_id' =>
$attrib['type_id'],
- 'lookup_form' =>
$attrib['lookup_form'],
- '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_location_attrib set $value_set WHERE 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_location'.$attrib['type_id'], $OldColumnName,
$attrib['column_name']);
-
$this->oProc->AlterColumn('fm_location'.$attrib['type_id'],$attrib['column_name'],$attrib['column_info']);
-
- }
-
- $choice_table ='fm_location_choice';
-
- if($attrib['new_choice'])
- {
- $choice_id =
$this->bocommon->next_id($choice_table
,array('type_id'=>$attrib['type_id'],'attrib_id'=>$attrib['id']));
-
- $values= array(
- $attrib['type_id'],
- $attrib['id'],
- $choice_id,
- $attrib['new_choice']
- );
-
- $values =
$this->bocommon->validate_db_insert($values);
-
- $GLOBALS['phpgw']->db->Execute("INSERT INTO
$choice_table (type_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 type_id=" . $attrib['type_id']. " AND attrib_id=" .
$attrib['id'] ." AND id=" . $attrib['delete_choice'][$i]);
- }
- }
-
- 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 type_id=" . $attrib['type_id']. " AND attrib_id=" .
$attrib['id']);
- }
-
-
- $GLOBALS['phpgw']->db->committrans();
-
- $receipt['message'][] = array('msg' =>
lang('Attribute has been edited'));
-
-
- return $receipt;
-
- }
-
- function select_location_type()
- {
-
- $dbresult = $GLOBALS['phpgw']->db->Execute("SELECT *
FROM fm_location_type ORDER BY id");
-// $dbresult = $GLOBALS['phpgw']->db->Execute("SELECT *
FROM fm_location_type ORDER BY id ");
-
- $i = 0;
- while (!$dbresult->EOF)
- {
- $location_type[$i]['id'] =
$dbresult->fields['id'];
- $location_type[$i]['name'] =
stripslashes($dbresult->fields['name']);
- $location_type[$i]['descr'] =
stripslashes($dbresult->fields['descr']);
- $i++;
- $dbresult->MoveNext();
- }
-//html_print_r($location_type);
-
- return $location_type;
- }
- function resort_attrib($data)
- {
- if(is_array($data))
- {
- $resort =
(isset($data['resort'])?$data['resort']:'up');
- $type_id =
(isset($data['type_id'])?$data['type_id']:'');
- $id = (isset($data['id'])?$data['id']:'');
- }
-
- if(!$type_id)
- {
- return;
- }
-
- $sql = "SELECT attrib_sort FROM fm_location_attrib
where type_id=$type_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_location_attrib where type_id=$type_id";
- $dbresult = $GLOBALS['phpgw']->db->Execute($sql2);
-
- $max_sort = $dbresult->fields['max_sort'];
-
- switch($resort)
- {
- case 'up':
- if($attrib_sort>1)
- {
- $sql = "UPDATE
fm_location_attrib set attrib_sort=$attrib_sort WHERE type_id=$type_id AND
attrib_sort =" . ($attrib_sort-1);
-
$GLOBALS['phpgw']->db->Execute($sql);
- $sql = "UPDATE
fm_location_attrib set attrib_sort=" . ($attrib_sort-1) ." WHERE
type_id=$type_id AND id=$id";
-
$GLOBALS['phpgw']->db->Execute($sql);
- }
- break;
- case 'down':
- if($max_sort > $attrib_sort)
- {
- $sql = "UPDATE
fm_location_attrib set attrib_sort=$attrib_sort WHERE type_id=$type_id AND
attrib_sort =" . ($attrib_sort+1);
-
$GLOBALS['phpgw']->db->Execute($sql);
- $sql = "UPDATE
fm_location_attrib set attrib_sort=" . ($attrib_sort+1) ." WHERE
type_id=$type_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_location
+ {
+ var $grants;
+
+ function property_soadmin_location()
+ {
+ $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;
+
+ }
+
+
+ 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']:'');
+ }
+
+ if ($order)
+ {
+ $ordermethod = " order by $order $sort";
+
+ }
+ else
+ {
+ $ordermethod = ' order by id asc';
+ }
+
+ $table = 'fm_location_type';
+
+ 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;
+ $dbresult = $GLOBALS['phpgw']->db->SelectLimit($sql .
$ordermethod,$maxmatchs,$start);
+
+ 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_config($data='')
+ {
+ if(is_array($data))
+ {
+ if ($data['start'])
+ {
+ $start=$data['start'];
+ }
+ else
+ {
+ $start=0;
+ }
+
+// $query =
(isset($data['start'])?$data['start']:0);
+ $query =
(isset($data['query'])?$data['query']:'');
+ $sort =
(isset($data['sort'])?$data['sort']:'DESC');
+ $order =
(isset($data['order'])?$data['order']:'');
+ }
+
+ if ($order)
+ {
+ $ordermethod = " order by $order $sort";
+
+ }
+ else
+ {
+ $ordermethod = ' order by column_name asc';
+ }
+
+ if($query)
+ {
+ $query = ereg_replace("'",'',$query);
+ $query = ereg_replace('"','',$query);
+
+ $querymethod = " where name LIKE '%$query%' or
column_name LIKE '%$query%'";
+ }
+
+ $sql = "SELECT fm_location_config.*
,fm_location_type.name as name FROM fm_location_config $this->join
fm_location_type on fm_location_config.location_type=fm_location_type.id
$querymethod";
+
+ $dbresult2 = $GLOBALS['phpgw']->db->Execute($sql);
+ $this->total_records = $dbresult2->_numOfRows;
+/* $maxmatchs = 15;
+
+html_print_r($maxmatchs);
+html_print_r($data);
+html_print_r($start);
+echo $sql . $ordermethod;
+
+ if(!$allrows)
+ {
+ $dbresult =
$GLOBALS['phpgw']->db->SelectLimit($sql . $ordermethod,$maxmatchs,$start);
+
+ }
+ else
+ {
+ $dbresult = $GLOBALS['phpgw']->db->Execute($sql
. $ordermethod);
+ }
+*/
+ $dbresult = $GLOBALS['phpgw']->db->Execute($sql
. $ordermethod);
+
+
+ while (!$dbresult->EOF)
+ {
+ $config[] = array
+ (
+ 'column_name' =>
$dbresult->fields['column_name'],
+ 'input_text' =>
$dbresult->fields['column_name'], //input_text
+ 'f_key' =>
$dbresult->fields['f_key'],
+ 'lookup_form' =>
$dbresult->fields['lookup_form'],
+ 'ref_to_category' =>
$dbresult->fields['ref_to_category'],
+ 'query_value' =>
$dbresult->fields['query_value'],
+ 'reference_table' =>
$dbresult->fields['reference_table'],
+ 'reference_id' =>
$dbresult->fields['reference_id'],
+ 'location_name' =>
$dbresult->fields['name'],
+ 'location_type' =>
$dbresult->fields['location_type']
+ );
+ $dbresult->MoveNext();
+ }
+//html_print_r($config);
+ return $config;
+ }
+
+ function read_config_single($column_name='')
+ {
+ $dbresult = $GLOBALS['phpgw']->db->Execute("SELECT
location_type FROM fm_location_config where column_name='$column_name'");
+
+ return $dbresult->fields['location_type'];
+ }
+
+
+ function read_single($id)
+ {
+
+ $table = 'fm_location_type';
+
+ $sql = "SELECT * FROM $table where id='$id'";
+
+ $dbresult = $GLOBALS['phpgw']->db->Execute($sql);
+
+ if (!$dbresult->EOF)
+ {
+ $standard['id'] =
$dbresult->fields['id'];
+ $standard['name'] =
$dbresult->fields['name'];
+ $standard['descr'] =
$dbresult->fields['descr'];
+ $standard['prefix'] =
$dbresult->fields['prefix'];
+
+ return $standard;
+ }
+ }
+
+ function add($standard)
+ {
+
+ $standard['name'] =
$this->db->db_addslashes($standard['name']);
+ $standard['descr'] =
$this->db->db_addslashes($standard['descr']);
+
+ $standard['id'] =
$this->bocommon->next_id('fm_location_type');
+
+ $GLOBALS['phpgw']->db->begintrans();
+
+ $GLOBALS['phpgw']->db->Execute("INSERT INTO
fm_location_type (id,name, descr) "
+ . "VALUES ('" . $standard['id'] . "','" .
$standard['name'] . "','" . $standard['descr']. "')");
+
+ $receipt['id']= $standard['id'];
+
+ $this->init_process();
+
+ $fd=array();
+ $fd['location_code'] = array('type' => 'varchar',
'precision' => 25, 'nullable' => False);
+
+ for ($i=1; $i<$standard['id']+1; $i++)
+ {
+
+ $fd['loc' . $i] = array('type' => 'varchar',
'precision' => 4, 'nullable' => False);
+ $pk[$i-1]= 'loc' . $i;
+ }
+
+ $fk_table='fm_location'. ($standard['id']-1);
+
+ for ($i=1; $i<$standard['id']; $i++)
+ {
+ $fk['loc' . $i] = $fk_table . '.loc' . $i;
+ }
+
+
+ if($standard['id']==1)
+ {
+ $fd['part_of_town_id'] = array('type' => 'int',
'precision' => 2, 'nullable' => True);
+ }
+
+ $fd['loc' .$standard['id'] . '_name'] = array('type' =>
'varchar', 'precision' => 25, 'nullable' => True);
+ $fd['entry_date'] = array('type' => 'int', 'precision'
=> 4, 'nullable' => True);
+ $fd['category'] = array('type' => 'int', 'precision' =>
4, 'nullable' => True);
+ $fd['user_id'] = array('type' => 'int', 'precision' =>
4, 'nullable' => True);
+ $fd['remark'] = array('type' => 'text', 'nullable' =>
True);
+ $fd['status'] = array('type' => 'int', 'precision' =>
4, 'nullable' => True);
+
+
$add_columns_in_tables=array('fm_meter','fm_project','fm_tts_tickets','fm_request','fm_document','fm_investment');
+
+ if($this->oProc->CreateTable('fm_location'.
$standard['id'],array('fd' => $fd,'pk' => $pk,'fk' => $fk,'ix' =>
array('location_code'),'uc' => array())))
+ {
+
+ $this->oProc->CreateTable('fm_location'.
$standard['id'] . '_category', array(
+ 'fd' => array(
+ 'id' => array('type' =>
'int','precision' => '4','nullable' => False),
+ 'descr' => array('type' =>
'varchar','precision' => '50','nullable' => True)
+ ),
+ 'pk' => array('id'),
+ 'fk' => array(),
+ 'ix' => array(),
+ 'uc' => array()));
+
+ for ($i=0;$i<count($add_columns_in_tables);$i++)
+ {
+
$this->oProc->AddColumn($add_columns_in_tables[$i],'loc'. $standard['id'],
array('type' => 'varchar', 'precision' => 4, 'nullable' => True));
+ }
+
+ $values_insert= array(
+ $standard['id'],
+ 1,
+ 'status',
+ 'Status',
+ 'Status',
+ 'LB',
+ 1,
+ 'True'
+ );
+
+ $values_insert =
$this->bocommon->validate_db_insert($values_insert);
+
+ $GLOBALS['phpgw']->db->Execute("INSERT INTO
fm_location_attrib
(type_id,id,column_name,input_text,statustext,datatype,attrib_sort,nullable) "
+ . "VALUES ($values_insert)");
+
+
+
+ $type_id=$standard['id'];
+
+ $GLOBALS['phpgw']->db->Execute("INSERT INTO
fm_location_choice (type_id,attrib_id,id,value) "
+ . "VALUES ($type_id,1,1,'ok')");
+ $GLOBALS['phpgw']->db->Execute("INSERT INTO
fm_location_choice (type_id,attrib_id,id,value) "
+ . "VALUES ($type_id,1,2,'Not Active')");
+
+
+ $receipt['message'][] = array('msg' =>
lang('table %1 has been saved','fm_location'. $receipt['id']) );
+ $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_location_type WHERE id='" . $standard['id'] . "'");
+ unset($receipt['id']);
+
+ }
+ }
+
+ return $receipt;
+ }
+
+ function edit($standard)
+ {
+
+ if (!$standard['name'])
+ {
+ $receipt['error'][] = array('msg'=>lang('Name
not entered!'));
+ }
+
+ if (!$receipt['error'])
+ {
+ $table = 'fm_location_type';
+
+ $standard['name'] =
$this->db->db_addslashes($standard['name']);
+ $standard['descr'] =
$this->db->db_addslashes($standard['descr']);
+
+ $GLOBALS['phpgw']->db->Execute("UPDATE $table
set descr='" . $standard['descr'] . "', name='". $standard['name']
+ . "' WHERE id='" . $standard['id'].
"'");
+
+
+ $receipt['message'][] = array('msg'=>
lang('Standard has been edited'));
+ }
+ else
+ {
+ $receipt['error'][] = array('msg' =>
lang('Standard has NOT been edited'));
+ }
+
+ return $receipt;
+ }
+
+ function delete($id,$attrib)
+ {
+ $this->init_process();
+
+ if($attrib)
+ {
+ $table = 'fm_location_attrib';
+
+ $dbresult =
$GLOBALS['phpgw']->db->Execute("SELECT column_name,type_id FROM
fm_location_attrib WHERE id='" . $id . "'");
+
+ $ColumnName =
$dbresult->fields['column_name'];
+ $type_id =
$dbresult->fields['type_id'];
+
+ $this->oProc->DropColumn('fm_location'
.$type_id ,'', $ColumnName);
+
+ }
+ else
+ {
+ $this->oProc->DropTable('fm_location' . $id);
+ $this->oProc->DropTable('fm_location' . $id .
'_category');
+
+ $table = 'fm_location_type';
+ $attrib_table = 'fm_location_attrib';
+ $GLOBALS['phpgw']->db->Execute("DELETE FROM
$attrib_table WHERE type_id='" . $id . "'");
+
+ }
+ $GLOBALS['phpgw']->db->Execute("DELETE FROM $table
WHERE id='" . $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']:'');
+ $type_id =
(isset($data['type_id'])?$data['type_id']:0);
+ $lookup_type =
(isset($data['lookup_type'])?$data['lookup_type']:'');
+ $allrows =
(isset($data['allrows'])?$data['allrows']:'');
+ }
+
+ if ($order)
+ {
+ $ordermethod = " order by $order $sort";
+
+ }
+ else
+ {
+ $ordermethod = ' order by
fm_location_attrib.attrib_sort asc';
+ }
+
+ $table = 'fm_location_attrib';
+ $type_table = 'fm_location_type';
+
+ if ($lookup_type)
+ {
+ $filtermethod = " OR (type_id < $lookup_type
AND lookup_form=1) ";
+
+ }
+
+ if($query)
+ {
+ $query = ereg_replace("'",'',$query);
+ $query = ereg_replace('"','',$query);
+
+ $querymethod = " and ($table.name LIKE
'%$query%' or $table.descr LIKE '%$query%')";
+ }
+
+ $sql = "SELECT
$table.id,$table.type_id,$table.list,$table.attrib_sort,$table.location_form,lookup_form,$table.column_name,$table.size
,statustext,$table.input_text,"
+ . " $table.datatype ,$type_table.name as type
FROM $type_table $this->join $table on $table.type_id = $type_table.id "
+ . " WHERE $table.type_id= '$type_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'],
+ 'location_type' =>
$dbresult->fields['type_id'],
+ 'attrib_sort' =>
$dbresult->fields['attrib_sort'],
+ 'list' =>
$dbresult->fields['list'],
+ 'lookup_form' =>
$dbresult->fields['lookup_form'],
+ 'location_form' =>
$dbresult->fields['location_form'],
+ 'column_name' =>
$dbresult->fields['column_name'],
+ '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($type_id,$id)
+ {
+
+ $table = 'fm_location_attrib';
+ $type_table = 'fm_location_type';
+
+ $sql = "SELECT $table.* ,$type_table.name as type_name
FROM $type_table $this->join $table on $table.type_id = $type_id where
$table.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']
= $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($type_id,$id);
+ }
+
+ return $attrib;
+ }
+ }
+
+ function read_attrib_choice($type_id,$attrib_id)
+ {
+ $choice_table = 'fm_location_choice';
+ $sql = "SELECT * FROM $choice_table WHERE
type_id=$type_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_location_attrib',array('type_id'=>$attrib['type_id']));
+
+ $sql = "SELECT max(attrib_sort) as max_sort FROM
fm_location_attrib where type_id=" . $attrib['type_id'];
+ $dbresult = $GLOBALS['phpgw']->db->Execute($sql);
+
+ $attrib_sort = $dbresult->fields['max_sort']+1;
+
+ $values= array(
+ $attrib['id'],
+ $attrib['column_name'],
+ $attrib['input_text'],
+ $attrib['statustext'],
+ $attrib['type_id'],
+ $attrib['lookup_form'],
+ $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_location_attrib (id,column_name, input_text, statustext,
type_id,lookup_form,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_location'.$attrib['type_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_location_attrib WHERE 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 save_config($values='',$column_name='')
+ {
+
+ $dbresult = $GLOBALS['phpgw']->db->Execute("SELECT *
FROM fm_location_config WHERE column_name='$column_name' ");
+
+
+ $column_info['type'] =
$dbresult->fields['datatype'];
+ $column_info['precision'] =
$dbresult->fields['precision_'];
+ $column_info['scale'] =
$dbresult->fields['scale'];
+ $column_info['default'] =
$dbresult->fields['default_value'];
+ $column_info['nullable'] =
$dbresult->fields['nullable'];
+ $location_type =
$dbresult->fields['location_type'];
+
+ if(!($location_type==$values[$column_name]))
+ {
+ $this->init_process();
+
+
if($this->oProc->AddColumn('fm_location'.$values[$column_name],$column_name,
$column_info))
+ {
+ if($column_name=='street_id')
+ {
+
$this->oProc->AddColumn('fm_location'.$values[$column_name],'street_number',
array('type'=>'varchar','precision'=>10));
+
$this->oProc->DropColumn('fm_location' .$location_type ,'','street_number');
+ }
+
+ $this->oProc->DropColumn('fm_location'
.$location_type ,'', $column_name);
+
+
+ $GLOBALS['phpgw']->db->Execute("UPDATE
fm_location_config set
+ location_type = '".
$values[$column_name] . "' WHERE column_name='" . $column_name . "'");
+
+ $receipt['message'][] = array('msg'
=> lang('column %1 has been moved',$column_name));
+ }
+ else
+ {
+ $receipt['message'][] = array('msg'
=> lang('column %1 could not be moved',$column_name));
+
+ }
+ }
+
+ return $receipt;
+
+ }
+
+
+ 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']);
+
+ $dbresult = $GLOBALS['phpgw']->db->Execute("SELECT
column_name FROM fm_location_attrib WHERE 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'],
+ 'type_id' =>
$attrib['type_id'],
+ 'lookup_form' =>
$attrib['lookup_form'],
+ '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_location_attrib set $value_set WHERE 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_location'.$attrib['type_id'], $OldColumnName,
$attrib['column_name']);
+
$this->oProc->AlterColumn('fm_location'.$attrib['type_id'],$attrib['column_name'],$attrib['column_info']);
+
+ }
+
+ $choice_table ='fm_location_choice';
+
+ if($attrib['new_choice'])
+ {
+ $choice_id =
$this->bocommon->next_id($choice_table
,array('type_id'=>$attrib['type_id'],'attrib_id'=>$attrib['id']));
+
+ $values= array(
+ $attrib['type_id'],
+ $attrib['id'],
+ $choice_id,
+ $attrib['new_choice']
+ );
+
+ $values =
$this->bocommon->validate_db_insert($values);
+
+ $GLOBALS['phpgw']->db->Execute("INSERT INTO
$choice_table (type_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 type_id=" . $attrib['type_id']. " AND attrib_id=" .
$attrib['id'] ." AND id=" . $attrib['delete_choice'][$i]);
+ }
+ }
+
+ 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 type_id=" . $attrib['type_id']. " AND attrib_id=" .
$attrib['id']);
+ }
+
+
+ $GLOBALS['phpgw']->db->committrans();
+
+ $receipt['message'][] = array('msg' =>
lang('Attribute has been edited'));
+
+
+ return $receipt;
+
+ }
+
+ function select_location_type()
+ {
+
+ $dbresult = $GLOBALS['phpgw']->db->Execute("SELECT *
FROM fm_location_type ORDER BY id");
+// $dbresult = $GLOBALS['phpgw']->db->Execute("SELECT *
FROM fm_location_type ORDER BY id ");
+
+ $i = 0;
+ while (!$dbresult->EOF)
+ {
+ $location_type[$i]['id'] =
$dbresult->fields['id'];
+ $location_type[$i]['name'] =
stripslashes($dbresult->fields['name']);
+ $location_type[$i]['descr'] =
stripslashes($dbresult->fields['descr']);
+ $i++;
+ $dbresult->MoveNext();
+ }
+//html_print_r($location_type);
+
+ return $location_type;
+ }
+ function resort_attrib($data)
+ {
+ if(is_array($data))
+ {
+ $resort =
(isset($data['resort'])?$data['resort']:'up');
+ $type_id =
(isset($data['type_id'])?$data['type_id']:'');
+ $id = (isset($data['id'])?$data['id']:'');
+ }
+
+ if(!$type_id)
+ {
+ return;
+ }
+
+ $sql = "SELECT attrib_sort FROM fm_location_attrib
where type_id=$type_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_location_attrib where type_id=$type_id";
+ $dbresult = $GLOBALS['phpgw']->db->Execute($sql2);
+
+ $max_sort = $dbresult->fields['max_sort'];
+
+ switch($resort)
+ {
+ case 'up':
+ if($attrib_sort>1)
+ {
+ $sql = "UPDATE
fm_location_attrib set attrib_sort=$attrib_sort WHERE type_id=$type_id AND
attrib_sort =" . ($attrib_sort-1);
+
$GLOBALS['phpgw']->db->Execute($sql);
+ $sql = "UPDATE
fm_location_attrib set attrib_sort=" . ($attrib_sort-1) ." WHERE
type_id=$type_id AND id=$id";
+
$GLOBALS['phpgw']->db->Execute($sql);
+ }
+ break;
+ case 'down':
+ if($max_sort > $attrib_sort)
+ {
+ $sql = "UPDATE
fm_location_attrib set attrib_sort=$attrib_sort WHERE type_id=$type_id AND
attrib_sort =" . ($attrib_sort+1);
+
$GLOBALS['phpgw']->db->Execute($sql);
+ $sql = "UPDATE
fm_location_attrib set attrib_sort=" . ($attrib_sort+1) ." WHERE
type_id=$type_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_location.php, 1.1.1.3,
nomail <=