[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Phpgroupware-cvs] property/inc/class.sotenant.inc.php, 1.2
From: |
nomail |
Subject: |
[Phpgroupware-cvs] property/inc/class.sotenant.inc.php, 1.2 |
Date: |
Wed, 2 Jun 2004 20:54:28 +0200 |
Update of /property/inc
Added Files:
Branch:
class.sotenant.inc.php
date: 2004/06/02 18:54:28; author: sigurdne; state: Exp; lines: +810 -0
Log Message:
no message
=====================================================================
<?php
/**************************************************************************\
* phpGroupWare - property
*
* http://www.phpgroupware.org
*
*
*
* Facilities Management
*
* Written by Sigurd Nes [sigurdne at online.no]
*
*
------------------------------------------------------------------------ *
* Copyright 2000 - 2003 Free Software Foundation, Inc
*
* This program is part of the GNU project, see http://www.gnu.org/
*
*
------------------------------------------------------------------------ *
* This program is free software; you can redistribute it and/or modify
it *
* under the terms of the GNU General Public License as published by the
*
* Free Software Foundation; either version 2 of the License, or (at
your *
* option) any later version.
*
\**************************************************************************/
class sotenant
{
function sotenant()
{
$this->currentapp =
$GLOBALS['phpgw_info']['flags']['currentapp'];
$this->db = $GLOBALS['phpgw']->db;
$this->db2 = $this->db;
$this->account =
$GLOBALS['phpgw_info']['user']['account_id'];
$this->bocommon =
CreateObject($this->currentapp.'.bocommon');
$this->join = $this->bocommon->join;
$this->left_join = $this->bocommon->left_join;
}
function select_category_list()
{
$this->db->query("SELECT id,descr FROM
fm_tenant_category ORDER BY descr ");
$i = 0;
while ($this->db->next_record())
{
$categories[$i]['id']
= $this->db->f('id');
$categories[$i]['name']
= stripslashes($this->db->f('descr'));
$i++;
}
return $categories;
}
function read_category_name($cat_id)
{
$this->db->query("SELECT descr FROM fm_tenant_sex
where id='$cat_id'");
$this->db->next_record();
return $this->db->f('descr');
}
function read($data)
{
if(is_array($data))
{
$start =
(isset($data['start'])?$data['start']:0);
$filter =
(isset($data['filter'])?$data['filter']:'none');
$query =
(isset($data['query'])?$data['query']:'');
$sort =
(isset($data['sort'])?$data['sort']:'DESC');
$order =
(isset($data['order'])?$data['order']:'');
$cat_id =
(isset($data['cat_id'])?$data['cat_id']:0);
$allrows =
(isset($data['allrows'])?$data['allrows']:'');
}
$sql = $this->bocommon->fm_cache('sql_tenant_' .
$lookup);
$entity_table = 'fm_tenant';
if(!$sql)
{
$cols = $entity_table .
'.*,fm_tenant_category.descr as category';
$cols_return[] = 'id';
$uicols['input_type'][] = 'text';
$uicols['name'][] = 'id';
$uicols['descr'][] =
lang('ID');
$uicols['statustext'][] = lang('ID');
$cols_return[] = 'id';
$uicols['input_type'][] = 'hidden';
$uicols['name'][] = 'id';
$uicols['descr'][] = false;
$uicols['statustext'][] = false;
$cols_return[] =
'last_name';
$uicols['input_type'][] = 'text';
$uicols['name'][] =
'last_name';
$uicols['descr'][] =
lang('last name');
$uicols['statustext'][] = lang('last
name');
$cols_return[] =
'first_name';
$uicols['input_type'][] = 'text';
$uicols['name'][] =
'first_name';
$uicols['descr'][] =
lang('first name');
$uicols['statustext'][] = lang('first
name');
$cols_return[] =
'category';
$uicols['input_type'][] = 'text';
$uicols['name'][] =
'category';
$uicols['descr'][] =
lang('category');
$uicols['statustext'][] =
lang('category');
$paranthesis .='(';
$joinmethod .= " $this->join " . $entity_table
. "_category ON ( $entity_table" . ".category =" .$entity_table .
"_category.id))";
$from .= " FROM $paranthesis $entity_table ";
$sql = "SELECT $cols $from $joinmethod";
$this->bocommon->fm_cache('sql_tenant_' .
$lookup,$sql);
$this->bocommon->fm_cache('uicols_tenant_' .
$lookup,$uicols);
$this->bocommon->fm_cache('cols_return_tenant_'
. $lookup,$cols_return);
}
else
{
$uicols
= $this->bocommon->fm_cache('uicols_tenant_' . $lookup);
$cols_return
= $this->bocommon->fm_cache('cols_return_tenant_' . $lookup);
if($lookup)
{
$admin_entity =
CreateObject($this->currentapp.'_soadmin_entity');
$category =
$admin_entity->read_single_category($entity_id,$cat_id);
}
}
$user_columns=$GLOBALS['phpgw_info']['user']['preferences'][$this->currentapp]['tenant_columns'];
//html_print_r($user_columns);
if (isset($user_columns) AND is_array($user_columns)
AND $user_columns[0])
{
$i = count($uicols['name']);
foreach($user_columns as $column_id)
{
$this->db->query("SELECT * FROM
fm_tenant_attribute WHERE id= $column_id");
$this->db->next_record();
$uicols['input_type'][] =
'text';
$uicols['name'][]
= $this->db->f('column_name');
$uicols['descr'][]
= $this->db->f('input_text');
$uicols['statustext'][] =
$this->db->f('statustext');
$uicols['datatype'][$i] =
$this->db->f('datatype');
$cols_return_extra[]= array(
'name' =>
$this->db->f('column_name'),
'datatype' =>
$this->db->f('datatype'),
'attrib_id' =>
$this->db->f('id')
);
$i++;
}
}
$this->uicols = $uicols;
//html_print_r($cols_return_extra);
if ($order)
{
$ordermethod = " order by $entity_table.$order
$sort";
}
else
{
$ordermethod = " order by $entity_table.id
DESC";
}
$where= 'WHERE';
/* if ($filter=='all')
{
if (is_array($grants))
{
while (list($user) = each($grants))
{
$public_user_list[] = $user;
}
reset($public_user_list);
$filtermethod .= " $where (
$entity_table.user_id IN(" . implode(',',$public_user_list) . "))";
$where= 'AND';
}
}
else
{
$filtermethod = " $where
$entity_table.user_id=$filter ";
$where= 'AND';
}
*/
if ($cat_id>0)
{
$filtermethod .= " $where
$entity_table.category=$cat_id ";
$where= 'AND';
}
if ($status)
{
$filtermethod .= " $where
$entity_table.status='$status' ";
$where= 'AND';
}
if($query)
{
$query = ereg_replace("'",'',$query);
$query = ereg_replace('"','',$query);
$querymethod = " $where (
$entity_table.first_name LIKE '%$query%' OR $entity_table.last_name LIKE
'%$query%')";
$where = 'AND';
}
$sql .= " $filtermethod $querymethod";
//echo $sql;
$this->db2->query($sql,__LINE__,__FILE__);
$this->total_records = $this->db2->num_rows();
if(!$allrows)
{
$this->db->limit_query($sql .
$ordermethod,$start,__LINE__,__FILE__);
}
else
{
$this->db->query($sql .
$ordermethod,__LINE__,__FILE__);
}
$j=0;
$n=count($cols_return);
//html_print_r($cols_return);
while ($this->db->next_record())
{
for ($i=0;$i<$n;$i++)
{
$tenant_list[$j][$cols_return[$i]] =
$this->db->f($cols_return[$i]);
$tenant_list[$j]['grants'] =
(int)$grants[$this->db->f('user_id')];
}
for ($i=0;$i<count($cols_return_extra);$i++)
{
$value='';
$value=$this->db->f($cols_return_extra[$i]['name']);
if(($cols_return_extra[$i]['datatype']=='R' ||
$cols_return_extra[$i]['datatype']=='LB') && $value):
{
$sql="SELECT value FROM
fm_tenant_choice where attrib_id=" .$cols_return_extra[$i]['attrib_id']. " AND
id=" . $value;
$this->db2->query($sql);
$this->db2->next_record();
$tenant_list[$j][$cols_return_extra[$i]['name']] = $this->db2->f('value');
}
elseif($cols_return_extra[$i]['datatype']=='AB' && $value):
{
$sql="SELECT org_name FROM
phpgw_addressbook where id=$value";
$this->db2->query($sql);
$this->db2->next_record();
$tenant_list[$j][$cols_return_extra[$i]['name']] = $this->db2->f('org_name');
}
elseif($cols_return_extra[$i]['datatype']=='CH' && $value):
{
$ch= unserialize($value);
if (isset($ch) AND
is_array($ch))
{
for
($k=0;$k<count($ch);$k++)
{
$sql="SELECT
value FROM fm_tenant_choice where attrib_id="
.$cols_return_extra[$i]['attrib_id']. " AND id=" . $ch[$k];
$this->db2->query($sql);
while
($this->db2->next_record())
{
$ch_value[]=$this->db2->f('value');
}
}
$tenant_list[$j][$cols_return_extra[$i]['name']] = @implode(",", $ch_value);
unset($ch_value);
}
}
elseif($cols_return_extra[$i]['datatype']=='D' && $value):
{
//html_print_r($value);
$tenant_list[$j][$cols_return_extra[$i]['name']]=date($GLOBALS['phpgw_data']['prefs'][$this->currentapp
. '.dateformat'],strtotime($value));
}
else:
{
$tenant_list[$j][$cols_return_extra[$i]['name']]=$value;
}
endif;
}
$j++;
}
//html_print_r($tenant_list);
return $tenant_list;
}
function read_single($data)
{
$tenant_id =$data['tenant_id'];
$this->db->query("SELECT * FROM fm_tenant_attribute
ORDER BY attrib_sort");
while ($this->db->next_record())
{
$tenant['attributes'][] = array
(
'attrib_id' =>
$this->db->f('id'),
'name' =>
$this->db->f('column_name'),
'input_text' =>
stripslashes($this->db->f('input_text')),
'statustext' =>
stripslashes($this->db->f('statustext')),
'datatype' =>
$this->db->f('datatype')
);
}
if($tenant_id)
{
$this->db->query("SELECT * from fm_tenant where
id='$tenant_id'");
if($this->db->next_record())
{
$tenant['id'] =
(int)$this->db->f('tenant_id');
$tenant['last_name'] =
stripslashes($this->db->f('last_name'));
$tenant['first_name'] =
stripslashes($this->db->f('first_name'));
$tenant['contact_phone'] =
$this->db->f('contact_phone');
$tenant['entry_date'] =
$this->db->f('entry_date');
$tenant['cat_id']
= (int)$this->db->f('category');
for
($i=0;$i<count($tenant['attributes']);$i++)
{
$tenant['attributes'][$i]['value'] =
$this->db->f($tenant['attributes'][$i]['name']);
$tenant['attributes'][$i]['datatype_text'] =
$this->bocommon->translate_datatype($tenant['attributes'][$i]['datatype']);
}
}
}
return $tenant;
}
function add($tenant,$values_attribute='')
{
$tenant['last_name'] =
$this->db->db_addslashes($tenant['last_name']);
$tenant['first_name'] =
$this->db->db_addslashes($tenant['first_name']);
while (is_array($tenant['extra']) &&
list($input_name,$value) = each($tenant['extra']))
{
if($value)
{
$cols[] = $input_name;
$vals[] = $value;
}
}
if (isset($values_attribute) AND
is_array($values_attribute))
{
foreach($values_attribute as $entry)
{
if($entry['value'])
{
$cols[] = $entry['name'];
$vals[] = $entry['value'];
}
}
}
if($cols)
{
$cols = "," . implode(",", $cols);
$vals = "," .
$this->bocommon->validate_db_insert($vals);
}
$this->db->transaction_begin();
$this->db->query("INSERT INTO fm_tenant
(entry_date,last_name,first_name,contact_phone,category $cols) "
. "VALUES ('" . time() . "','" .
$tenant['last_name'] . "','" . $tenant['first_name'] . "','" .
$tenant['contact_phone'] . "','" . $tenant['cat_id'] . "' $vals)");
$receipt['tenant_id']=
$this->db->get_last_insert_id('fm_tenant','id');
$receipt['message'][] = array('msg'=>lang('tenant %1
has been saved',$receipt['tenant_id']));
$this->db->transaction_commit();
return $receipt;
}
function edit($tenant,$values_attribute='')
{
//_debug_array($tenant);
//_debug_array($values_attribute);
$tenant['last_name'] =
$this->db->db_addslashes($tenant['last_name']);
$tenant['first_name'] =
$this->db->db_addslashes($tenant['first_name']);
while (is_array($tenant['extra']) &&
list($column,$value) = each($tenant['extra']))
{
$value_set[$column] = $value;
}
if (isset($values_attribute) AND
is_array($values_attribute))
{
foreach($values_attribute as $entry)
{
if($entry['datatype']!='AB')
{
$value_set[$entry['name']]
= $entry['value'];
}
}
}
if($value_set)
{
$value_set = ',' .
$this->bocommon->validate_db_update($value_set);
}
$this->db->query("UPDATE fm_tenant set last_name='" .
$tenant['last_name'] . "', first_name='" . $tenant['first_name'] . "',
contact_phone='" . $tenant['contact_phone'] . "', entry_date='" . time() . "',
category='"
. $tenant['cat_id'] .
"' $value_set WHERE id=" . intval($tenant['tenant_id']));
$receipt['tenant_id']= $tenant['tenant_id'];
$receipt['message'][] = array('msg'=>lang('tenant %1
has been edited',$tenant['tenant_id']));
return $receipt;
}
function delete($tenant_id)
{
$this->db->query('DELETE FROM fm_tenant WHERE id=' .
intval($tenant_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']:'');
}
if ($order)
{
$ordermethod = " order by $order $sort";
}
else
{
$ordermethod = ' order by attrib_sort asc';
}
if($query)
{
$query = ereg_replace("'",'',$query);
$query = ereg_replace('"','',$query);
$querymethod = " WHERE
(fm_tenant_attribute.input_text LIKE '%$query%' or
fm_tenant_attribute.column_name LIKE '%$query%')";
}
$sql = "SELECT * FROM fm_tenant_attribute $filtermethod
$querymethod";
$this->db2->query($sql,__LINE__,__FILE__);
$this->total_records = $this->db2->num_rows();
if(!$allrows)
{
$this->db->limit_query($sql .
$ordermethod,$start,__LINE__,__FILE__);
}
else
{
$this->db->query($sql .
$ordermethod,__LINE__,__FILE__);
}
while ($this->db->next_record())
{
$attrib[] = array
(
'id' =>
$this->db->f('id'),
'attrib_sort' =>
$this->db->f('attrib_sort'),
'list' =>
$this->db->f('list'),
'lookup_form' =>
$this->db->f('lookup_form'),
'column_name' =>
$this->db->f('column_name'),
'name' =>
$this->db->f('input_text'),
'size' =>
$this->db->f('size'),
'statustext' =>
$this->db->f('statustext'),
'input_text' =>
$this->db->f('input_text'),
'type_name' =>
$this->db->f('type'),
'datatype' =>
$this->db->f('datatype')
);
}
return $attrib;
}
function read_single_attrib($id)
{
$sql = "SELECT * FROM fm_tenant_attribute where id=$id";
$this->db->query($sql);
if($this->db->next_record())
{
$attrib['id']
= $this->db->f('id');
$attrib['column_name']
= $this->db->f('column_name');
$attrib['input_text']
= $this->db->f('input_text');
$attrib['statustext']
= $this->db->f('statustext');
$attrib['column_info']['precision'] =
$this->db->f('precision_');
$attrib['column_info']['scale'] =
$this->db->f('scale');
$attrib['column_info']['default'] =
$this->db->f('default_value');
$attrib['column_info']['nullable'] =
$this->db->f('nullable');
$attrib['column_info']['type'] =
$this->db->f('datatype');
$attrib['type_name']
= $this->db->f('type_name');
$attrib['lookup_form']
= $this->db->f('lookup_form');
$attrib['list']
= $this->db->f('list');
if($this->db->f('datatype')=='R' ||
$this->db->f('datatype')=='CH' || $this->db->f('datatype')=='LB')
{
$attrib['choice'] =
$this->read_attrib_choice($id);
}
return $attrib;
}
}
function read_attrib_choice($attrib_id)
{
$choice_table = 'fm_tenant_choice';
$sql = "SELECT * FROM $choice_table WHERE
attrib_id=$attrib_id";
$this->db->query($sql);
while ($this->db->next_record())
{
$choice[] = array
(
'id' => $this->db->f('id'),
'value' => $this->db->f('value')
);
}
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_tenant_attribute');
$sql = "SELECT max(attrib_sort) as max_sort FROM
fm_tenant_attribute";
$this->db->query($sql);
$this->db->next_record();
$attrib_sort = $this->db->f('max_sort')+1;
$values= array(
$attrib['id'],
$attrib['column_name'],
$attrib['input_text'],
$attrib['statustext'],
$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);
$this->db->transaction_begin();
$this->db->query("INSERT INTO fm_tenant_attribute
(id,column_name, input_text,
statustext,lookup_form,list,attrib_sort,datatype,precision_,scale,default_value,nullable)
"
. "VALUES ($values)");
$receipt['id']= $attrib['id'];
if($attrib['column_info']['type']=='email' &&
!$attrib['column_info']['precision'])
{
$attrib['column_info']['precision']=64;
}
$attrib['column_info']['type'] =
$this->bocommon->translate_datatype_insert($attrib['column_info']['type']);
if($attrib['column_info']['type']=='int' &&
!$attrib['column_info']['precision'])
{
$attrib['column_info']['precision']=4;
}
if(!$attrib['column_info']['default'])
{
unset($attrib['column_info']['default']);
}
$this->init_process();
if($this->oProc->AddColumn('fm_tenant',$attrib['column_name'],
$attrib['column_info']))
{
$receipt['message'][] = array('msg' =>
lang('Attribute has been saved') );
$this->db->transaction_commit();
}
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_tenant_attribute 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 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']);
$choice_table ='fm_tenant_choice';
$this->db->query("SELECT column_name FROM
fm_tenant_attribute WHERE id='" . $attrib['id']. "'");
$this->db->next_record();
$OldColumnName = $this->db->f('column_name');
$this->db->transaction_begin();
$attrib_type=$attrib['column_info']['type'];
if(($OldColumnName !=$attrib['column_name']) ||
($attrib['column_info']['type'] != $this->db->f('datatype')))
{
$value_set=array(
'column_name' =>
$attrib['column_name'],
'input_text' =>
$attrib['input_text'],
'statustext' =>
$attrib['statustext'],
'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);
$this->db->query("UPDATE fm_tenant_attribute
set $value_set WHERE id=" . $attrib['id']);
if($attrib['column_info']['type']=='email' &&
!$attrib['column_info']['precision'])
{
$attrib['column_info']['precision']=64;
}
$attrib['column_info']['type'] =
$this->bocommon->translate_datatype_insert($attrib['column_info']['type']);
if($attrib['column_info']['type']=='int' &&
!$attrib['column_info']['precision'])
{
$attrib['column_info']['precision']=4;
}
if(!$attrib['column_info']['default'])
{
unset($attrib['column_info']['default']);
}
$this->init_process();
$this->oProc->AlterColumn('fm_tenant',$OldColumnName,$attrib['column_name'],$attrib['column_info']);
}
if($attrib['new_choice'])
{
$choice_id =
$this->bocommon->next_id($choice_table ,array('attrib_id'=>$attrib['id']));
$values= array(
$attrib['id'],
$choice_id,
$attrib['new_choice']
);
$values =
$this->bocommon->validate_db_insert($values);
$this->db->query("INSERT INTO $choice_table
(attrib_id,id,value) "
. "VALUES ($values)");
}
if($attrib['delete_choice'])
{
for
($i=0;$i<count($attrib['delete_choice']);$i++)
{
$this->db->query("DELETE FROM
$choice_table WHERE attrib_id=" . $attrib['id'] ." AND id=" .
$attrib['delete_choice'][$i]);
}
}
//html_print_r($attrib_type);
if($attrib_type!='R' && $attrib_type!='CH' &&
$attrib_type!='LB')
{
$this->db->query("DELETE FROM $choice_table
WHERE attrib_id=" . $attrib['id']);
}
$this->db->transaction_commit();
$receipt['message'][] = array('msg' =>
lang('Attribute has been edited'));
return $receipt;
}
function resort_attrib($data)
{
//html_print_r($data);
if(is_array($data))
{
$resort =
(isset($data['resort'])?$data['resort']:'up');
$id = (isset($data['id'])?$data['id']:'');
}
$sql = "SELECT attrib_sort FROM fm_tenant_attribute
where id=$id";
$this->db->query($sql);
$this->db->next_record();
$attrib_sort = $this->db->f('attrib_sort');
$sql = "SELECT max(attrib_sort) as max_sort FROM
fm_tenant_attribute";
$this->db->query($sql);
$this->db->next_record();
$max_sort = $this->db->f('max_sort');
switch($resort)
{
case 'up':
if($attrib_sort>1)
{
$sql = "UPDATE
fm_tenant_attribute set attrib_sort=$attrib_sort WHERE attrib_sort =" .
($attrib_sort-1);
$this->db->query($sql);
$sql = "UPDATE
fm_tenant_attribute set attrib_sort=" . ($attrib_sort-1) ." WHERE id=$id";
$this->db->query($sql);
}
break;
case 'down':
if($max_sort > $attrib_sort)
{
$sql = "UPDATE
fm_tenant_attribute set attrib_sort=$attrib_sort WHERE attrib_sort =" .
($attrib_sort+1);
$this->db->query($sql);
$sql = "UPDATE
fm_tenant_attribute set attrib_sort=" . ($attrib_sort+1) ." WHERE id=$id";
$this->db->query($sql);
}
break;
default:
return;
break;
}
}
function delete_attrib($attrib_id)
{
$this->init_process();
$sql = "SELECT * FROM fm_tenant_attribute WHERE
id=$attrib_id";
$this->db->query($sql);
$this->db->next_record();
$ColumnName = $this->db->f('column_name');
if($this->oProc->DropColumn('fm_tenant','',
$ColumnName))
{
$sql = "SELECT attrib_sort FROM
fm_tenant_attribute where id=$attrib_id";
$this->db->query($sql);
$this->db->next_record();
$attrib_sort = $this->db->f('attrib_sort');
$sql2 = "SELECT max(attrib_sort) as max_sort
FROM fm_tenant_attribute";
$this->db->query($sql2);
$this->db->next_record();
$max_sort = $this->db->f('max_sort');
if($max_sort>$attrib_sort)
{
$sql = "UPDATE fm_tenant_attribute set
attrib_sort=attrib_sort-1 WHERE attrib_sort > $attrib_sort";
$this->db->query($sql);
}
$this->db->query("DELETE FROM
fm_tenant_attribute WHERE id=$attrib_id");
}
else
{
$receipt['error'][] = array('msg' =>
lang('Attribute has NOT been deleted'));
}
return $receipt;
}
}
?>