[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Phpgroupware-cvs] property/inc/class.sotenant.inc.php, 1.1.1.2
From: |
nomail |
Subject: |
[Phpgroupware-cvs] property/inc/class.sotenant.inc.php, 1.1.1.2 |
Date: |
Tue, 18 May 2004 15:45:24 +0200 |
Update of /property/inc
Modified Files:
Branch:
class.sotenant.inc.php
date: 2004/05/18 13:45:24; author: sigurdne; state: Exp; lines: +668 -36
Log Message:
no message
=====================================================================
Index: property/inc/class.sotenant.inc.php
diff -u property/inc/class.sotenant.inc.php:1.1.1.1
property/inc/class.sotenant.inc.php:1.1.1.2
--- property/inc/class.sotenant.inc.php:1.1.1.1 Fri Apr 23 13:13:57 2004
+++ property/inc/class.sotenant.inc.php Tue May 18 13:45:24 2004
@@ -24,10 +24,10 @@
$this->db = $GLOBALS['phpgw']->db;
$this->db2 = $this->db;
$this->account =
$GLOBALS['phpgw_info']['user']['account_id'];
- $this->socommon =
CreateObject($this->currentapp.'.socommon');
+ $this->bocommon =
CreateObject($this->currentapp.'.bocommon');
- $this->join = $this->socommon->join;
- $this->left_join = $this->socommon->left_join;
+ $this->join = $this->bocommon->join;
+ $this->left_join = $this->bocommon->left_join;
}
function select_category_list()
@@ -64,37 +64,158 @@
$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[] =
'tenant_id';
+ $uicols['input_type'][] = 'text';
+ $uicols['name'][] =
'tenant_id';
+ $uicols['descr'][] =
lang('ID');
+ $uicols['statustext'][] = lang('ID');
+
+ $cols_return[] =
'tenant_id';
+ $uicols['input_type'][] = 'hidden';
+ $uicols['name'][] =
'tenant_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 $order $sort";
+ $ordermethod = " order by $entity_table.$order
$sort";
}
else
{
- $ordermethod = ' order by last_name DESC';
+ $ordermethod = ' order by tenant_id DESC';
}
+ $where= 'WHERE';
- $where = 'WHERE';
- if ($cat_id > 0)
+/* if ($filter=='all')
{
- $filtermethod .= " $where category='$cat_id' ";
- $where = 'AND';
+ 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 ( last_name LIKE
'%$query%' OR first_name LIKE '%$query%' OR contact_phone LIKE '%$query%')";
+ $querymethod = " $where (
$entity_table.first_name LIKE '%$query%' OR $entity_table.last_name LIKE
'%$query%')";
+ $where = 'AND';
}
- $sql = "SELECT fm_tenant.*, fm_tenant_category.descr
as category FROM fm_tenant $this->left_join fm_tenant_category on
fm_tenant.category=fm_tenant_category.id $filtermethod $querymethod";
+ $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__);
@@ -104,56 +225,193 @@
$this->db->query($sql .
$ordermethod,__LINE__,__FILE__);
}
+ $j=0;
+ $n=count($cols_return);
+//html_print_r($cols_return);
while ($this->db->next_record())
{
- $tenants[] = array
- (
- 'tenant_id' =>
$this->db->f('tenant_id'),
- 'entry_date' =>
$this->db->f('entry_date'),
- 'category' =>
$this->db->f('category'),
- 'name' =>
stripslashes($this->db->f('last_name')) . ' ' .
stripslashes($this->db->f('first_name')),
- );
+ 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++;
}
- return $tenants;
+//html_print_r($tenant_list);
+ return $tenant_list;
}
- function read_single($tenant_id)
+
+ function read_single($data)
{
- $this->db->query("select * from fm_tenant where
tenant_id='$tenant_id'",__LINE__,__FILE__);
+ $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 ($this->db->next_record())
+ if($tenant_id)
{
- $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');
+ $this->db->query("SELECT * from fm_tenant where
tenant_id='$tenant_id'");
- return $tenant;
+ 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)
+ 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']);
- $this->db->query("INSERT INTO fm_tenant
(entry_date,last_name,first_name,contact_phone,category) "
- . "VALUES ('" . time() . "','" .
$tenant['last_name'] . "','" . $tenant['first_name'] . "','" .
$tenant['contact_phone'] . "','" . $tenant['cat_id'] . "')",__LINE__,__FILE__);
+ 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','tenant_id');
+ $receipt['tenant_id']= $tenant_id;
$receipt['message'][] = array('msg'=>lang('tenant %1
has been saved',$receipt['tenant_id']));
+
+ $this->db->transaction_commit();
return $receipt;
}
- function edit($tenant)
+ 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'] .
"' WHERE tenant_id=" . intval($tenant['tenant_id']),__LINE__,__FILE__);
+ . $tenant['cat_id'] .
"' $value_set WHERE tenant_id=" . intval($tenant['tenant_id']));
$receipt['tenant_id']= $tenant['tenant_id'];
$receipt['message'][] = array('msg'=>lang('tenant %1
has been edited',$tenant['tenant_id']));
@@ -162,7 +420,381 @@
function delete($tenant_id)
{
- $this->db->query('DELETE FROM fm_tenant WHERE
tenant_id=' . intval($tenant_id),__LINE__,__FILE__);
+ $this->db->query('DELETE FROM fm_tenant WHERE
tenant_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'];
+
+ $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']);
+
+ $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;
}
}
?>
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Phpgroupware-cvs] property/inc/class.sotenant.inc.php, 1.1.1.2,
nomail <=