phpgroupware-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Phpgroupware-cvs] property/class.sotenant.php, 1.1.1.7


From: nomail
Subject: [Phpgroupware-cvs] property/class.sotenant.php, 1.1.1.7
Date: Tue, 18 May 2004 08:19:43 +0200

Update of /property
Modified Files:
        Branch: 
          class.sotenant.php

date: 2004/05/18 06:19:43;  author: sigurdne;  state: Exp;  lines: +701 -19

Log Message:
no message
=====================================================================
Index: property/class.sotenant.php
diff -u property/class.sotenant.php:1.1.1.6 property/class.sotenant.php:1.1.1.7
--- property/class.sotenant.php:1.1.1.6 Sun May  9 13:42:34 2004
+++ property/class.sotenant.php Tue May 18 06:19:43 2004
@@ -24,11 +24,11 @@
                        $this->db               = $GLOBALS['phpgw']->db;
                        $this->db2              = $this->db;
                        $this->account  = $GLOBALS['phpgw_data']['user']['id'];
-                       $this->socommon         = 
CreateObject($this->currentapp.'_socommon');
+                       $this->bocommon         = 
CreateObject($this->currentapp.'_bocommon');
                        $this->functions        = 
CreateObject($this->currentapp.'_functions');
 
-                       $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()
@@ -53,7 +53,7 @@
                        return $dbresult->fields['descr'];
                }
 
-               function read($data)
+               function read_old($data)
                {
                        if(is_array($data))
                        {
@@ -123,33 +123,323 @@
                        return $tenants;
                }
 
-               function read_single($tenant_id)
+               function read($data)
                {
-                       $dbresult = $GLOBALS['phpgw']->db->Execute("SELECT * 
from fm_tenant where tenant_id='$tenant_id'");
+                       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']:'');
+                       }
 
-                       if (!$dbresult->EOF)
+                       $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= 
unserialize($GLOBALS['phpgw_data']['prefs'][$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)
+                               {
+                                       $dbresult = 
$GLOBALS['phpgw']->db->Execute("SELECT * FROM fm_tenant_attribute WHERE id= 
$column_id");
+
+                                       $uicols['input_type'][]         = 
'text';
+                                       $uicols['name'][]                       
= $dbresult->fields['column_name'];
+                                       $uicols['descr'][]                      
= $dbresult->fields['input_text'];
+                                       $uicols['statustext'][]         = 
$dbresult->fields['statustext'];
+                                       $uicols['datatype'][$i]         = 
$dbresult->fields['datatype'];
+                                       $cols_return_extra[]= array(
+                                               'name'  => 
$dbresult->fields['column_name'],
+                                               'datatype'      => 
$dbresult->fields['datatype'],
+                                               'attrib_id'     => 
$dbresult->fields['id']
+                                       );
+                                       $i++;
+                               }
+                       }
+
+                       $this->uicols   = $uicols;
+
+//html_print_r($cols_return_extra);
+                       if ($order)
+                       {
+                               $ordermethod = " order by $entity_table.$order 
$sort";
+                       }
+                       else
+                       {
+                               $ordermethod = ' order by tenant_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;
+
+                       $dbresult2 = $GLOBALS['phpgw']->db->Execute($sql);
+                       $this->total_records = $dbresult2->_numOfRows;
+                       $maxmatchs = 15;
+
+                       if(!$allrows)
+                       {
+                               $dbresult = 
$GLOBALS['phpgw']->db->SelectLimit($sql . $ordermethod,$maxmatchs,$start);
+
+                       }
+                       else
+                       {
+                               $dbresult = $GLOBALS['phpgw']->db->Execute($sql 
. $ordermethod);
+                       }
+
+                       $j=0;
+                       $n=count($cols_return);
+//html_print_r($cols_return);
+                       while (!$dbresult->EOF)
+                       {
+                               for ($i=0;$i<$n;$i++)
+                               {
+                                       $tenant_list[$j][$cols_return[$i]] = 
$dbresult->fields[$cols_return[$i]];
+                                       $tenant_list[$j]['grants'] = 
(int)$grants[$dbresult->fields['user_id']];
+                               }
+
+                               for ($i=0;$i<count($cols_return_extra);$i++)
+                               {
+                                       $value='';
+                                       
$value=$dbresult->fields[$cols_return_extra[$i]['name']];
+
+                                       
if(($cols_return_extra[$i]['datatype']=='R' || 
$cols_return_extra[$i]['datatype']=='LB') && $value):
+                                       {
+                                               $sql="SELECT value FROM 
fm_tenant_choice where attrib_id=" .$cols_return_extra[$i]['attrib_id']. "  AND 
id=" . $value;
+                                               $dbresult2 = 
$GLOBALS['phpgw']->db->Execute($sql);
+                                               
$tenant_list[$j][$cols_return_extra[$i]['name']] = $dbresult2->fields['value'];
+                                       }
+                                       
elseif($cols_return_extra[$i]['datatype']=='AB' && $value):
+                                       {
+                                               $sql="SELECT org_name FROM 
fm_addressbook where id=$value";
+                                               $dbresult2 = 
$GLOBALS['phpgw']->db->Execute($sql);
+                                               
$tenant_list[$j][$cols_return_extra[$i]['name']] = 
$dbresult2->fields['org_name'];
+                                       }
+                                       
elseif($cols_return_extra[$i]['datatype']=='CH' && $value):
+                                       {
+                                               $ch= unserialize($value);
+
+                                               if (isset($ch) AND 
is_array($ch))
+                                               {
+                                                       for 
($k=0;$k<count($ch);$k++)
+                                                       {
+                                                               $sql="SELECT 
value FROM fm_tenant_choice where attrib_id=" 
.$cols_return_extra[$i]['attrib_id']. "  AND id=" . $ch[$k];
+                                                               $dbresult2 = 
$GLOBALS['phpgw']->db->Execute($sql);
+                                                               while 
(!$dbresult2->EOF)
+                                                               {
+                                                                       
$ch_value[]=$dbresult2->fields['value'];
+                                                                       
$dbresult2->MoveNext();
+                                                               }
+                                                       }
+                                                       
$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++;
+                               $dbresult->MoveNext();
+                       }
+//html_print_r($tenant_list);
+                       return $tenant_list;
+               }
+
+
+               function read_single($data)
+               {
+                       $tenant_id =$data['tenant_id'];
+
+                       $dbresult = $GLOBALS['phpgw']->db->Execute("SELECT * 
FROM fm_tenant_attribute ORDER BY attrib_sort");
+
+                       while (!$dbresult->EOF)
+                       {
+                               $tenant['attributes'][] = array
+                               (
+                                       'attrib_id'             => 
$dbresult->fields['id'],
+                                       'name'                  => 
$dbresult->fields['column_name'],
+                                       'input_text'    => 
stripslashes($dbresult->fields['input_text']),
+                                       'statustext'    => 
stripslashes($dbresult->fields['statustext']),
+                                       'datatype'              => 
$dbresult->fields['datatype']
+                               );
+                               $dbresult->MoveNext();
+                       }
+
+                       if($tenant_id)
                        {
-                               $tenant['id']                   = 
(int)$dbresult->fields['tenant_id'];
-                               $tenant['last_name']            = 
stripslashes($dbresult->fields['last_name']);
-                               $tenant['first_name']           = 
stripslashes($dbresult->fields['first_name']);
-                               $tenant['contact_phone']        = 
$dbresult->fields['contact_phone'];
-                               $tenant['entry_date']           = 
$dbresult->fields['entry_date'];
-                               $tenant['cat_id']                       = 
(int)$dbresult->fields['category'];
+                               $dbresult = 
$GLOBALS['phpgw']->db->Execute("SELECT * from fm_tenant where 
tenant_id='$tenant_id'");
 
-                               return $tenant;
+                               if (!$dbresult->EOF)
+                               {
+                                       $tenant['id']                   = 
(int)$dbresult->fields['tenant_id'];
+                                       $tenant['last_name']            = 
stripslashes($dbresult->fields['last_name']);
+                                       $tenant['first_name']           = 
stripslashes($dbresult->fields['first_name']);
+                                       $tenant['contact_phone']        = 
$dbresult->fields['contact_phone'];
+                                       $tenant['entry_date']           = 
$dbresult->fields['entry_date'];
+                                       $tenant['cat_id']                       
= (int)$dbresult->fields['category'];
+
+                                       for 
($i=0;$i<count($tenant['attributes']);$i++)
+                                       {
+                                               
$tenant['attributes'][$i]['value']      = 
$dbresult->fields[$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->functions->db_addslashes($tenant['last_name']);
                        $tenant['first_name'] = 
$this->functions->db_addslashes($tenant['first_name']);
 
+                       if (isset($values_attribute) AND 
is_array($values_attribute))
+                       {
+                               foreach($values_attribute as $entry)
+                               {
+                                       if($entry['value'])
+                                       {
+                                               $cols[] = $entry['name'];
+                                               $vals[] = $entry['value'];
+                                       }
+                               }
+                       }
+
+                       if($cols)
+                       {
+                               $cols   = "," . implode(",", $cols);
+                               $vals   = "," . 
$this->bocommon->validate_db_insert($vals);
+                       }
+
                        $GLOBALS['phpgw']->db->begintrans();
                        $tenant_id = 
$GLOBALS['phpgw']->db->genid('fm_tenant_tenant_id_seq');
 
-                       $GLOBALS['phpgw']->db->Execute("INSERT INTO fm_tenant 
(tenant_id,entry_date,last_name,first_name,contact_phone,category) "
-                               . "VALUES ($tenant_id,'" . time() . "','" . 
$tenant['last_name'] . "','" . $tenant['first_name'] . "','" . 
$tenant['contact_phone'] . "','" . $tenant['cat_id'] . "')");
+                       $GLOBALS['phpgw']->db->Execute("INSERT INTO fm_tenant 
(tenant_id,entry_date,last_name,first_name,contact_phone,category $cols) "
+                               . "VALUES ($tenant_id,'" . 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;
@@ -159,13 +449,30 @@
                        return $receipt;
                }
 
-               function edit($tenant)
+               function edit($tenant,$values_attribute='')
                {
                        $tenant['last_name'] = 
$this->functions->db_addslashes($tenant['last_name']);
                        $tenant['first_name'] = 
$this->functions->db_addslashes($tenant['first_name']);
 
+
+                       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);
+                       }
+
                        $GLOBALS['phpgw']->db->Execute("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']));
+                                                       . $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']));
@@ -176,5 +483,380 @@
                {
                        $GLOBALS['phpgw']->db->Execute('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";
+
+                       $dbresult2 = $GLOBALS['phpgw']->db->Execute($sql);
+                       $this->total_records = $dbresult2->_numOfRows;
+
+                       $maxmatchs = 15;
+
+                       if(!$allrows)
+                       {
+                               $dbresult = 
$GLOBALS['phpgw']->db->SelectLimit($sql . $ordermethod,$maxmatchs,$start);
+
+                       }
+                       else
+                       {
+                               $dbresult = $GLOBALS['phpgw']->db->Execute($sql 
. $ordermethod);
+                       }
+
+
+                       while (!$dbresult->EOF)
+                       {
+                               $attrib[] = array
+                               (
+                                       'id'                    => 
$dbresult->fields['id'],
+                                       'attrib_sort'   => 
$dbresult->fields['attrib_sort'],
+                                       'list'                  => 
$dbresult->fields['list'],
+                                       'lookup_form'   => 
$dbresult->fields['lookup_form'],
+                                       'column_name'   => 
$dbresult->fields['column_name'],
+                                       'name'                  => 
$dbresult->fields['input_text'],
+                                       'size'                  => 
$dbresult->fields['size'],
+                                       'statustext'    => 
$dbresult->fields['statustext'],
+                                       'input_text'    => 
$dbresult->fields['input_text'],
+                                       'type_name'             => 
$dbresult->fields['type'],
+                                       'datatype'              => 
$dbresult->fields['datatype']
+                               );
+                               $dbresult->MoveNext();
+                       }
+                       return $attrib;
+               }
+
+               function read_single_attrib($id)
+               {
+
+                       $sql = "SELECT * FROM fm_tenant_attribute where 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_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($id);
+                               }
+
+                               return $attrib;
+                       }
+               }
+
+               function read_attrib_choice($attrib_id)
+               {
+                       $choice_table = 'fm_tenant_choice';
+                       $sql = "SELECT * FROM $choice_table WHERE 
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->functions->db_addslashes($attrib['column_name']);
+                       $attrib['input_text'] = 
$this->functions->db_addslashes($attrib['input_text']);
+                       $attrib['statustext'] = 
$this->functions->db_addslashes($attrib['statustext']);
+                       $attrib['default'] = 
$this->functions->db_addslashes($attrib['default']);
+                       $attrib['id'] = 
$this->bocommon->next_id('fm_tenant_attribute');
+
+                       $sql = "SELECT max(attrib_sort) as max_sort FROM 
fm_tenant_attribute";
+                       $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['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_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')     );
+                               $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_tenant_attribute WHERE id='" . $receipt['id'] . "'");
+                                       unset($receipt['id']);
+
+                               }
+                       }
+
+                       return $receipt;
+               }
+
+               function init_process()
+               {
+                       $this->oProc            = 
CreateObject($this->currentapp.'_oproc');
+               }
+
+               function edit_attrib($attrib)
+               {
+                       $attrib['column_name'] = 
$this->functions->db_addslashes($attrib['column_name']);
+                       $attrib['input_text'] = 
$this->functions->db_addslashes($attrib['input_text']);
+                       $attrib['statustext'] = 
$this->functions->db_addslashes($attrib['statustext']);
+                       $attrib['default'] = 
$this->functions->db_addslashes($attrib['default']);
+
+                       $choice_table ='fm_tenant_choice';
+
+                       $dbresult = $GLOBALS['phpgw']->db->Execute("SELECT 
column_name FROM fm_tenant_attribute WHERE id='" . $attrib['id']. "'");
+
+                       $OldColumnName          = 
$dbresult->fields['column_name'];
+
+                       $GLOBALS['phpgw']->db->begintrans();
+
+                       $attrib_type=$attrib['column_info']['type'];
+                       if(($OldColumnName !=$attrib['column_name']) || 
($attrib['column_info']['type'] != $dbresult->fields['datatype']))
+                       {
+                               $value_set=array(
+                                       'column_name'           => 
$attrib['column_name'],
+                                       'input_text'            => 
$attrib['input_text'],
+                                       'statustext'            => 
$attrib['statustext'],
+                                       'lookup_form'           => 
$attrib['lookup_form'],
+                                       '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_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);
+
+                               $GLOBALS['phpgw']->db->Execute("INSERT INTO 
$choice_table (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  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')
+                       {
+                               $GLOBALS['phpgw']->db->Execute("DELETE FROM 
$choice_table WHERE  attrib_id=" . $attrib['id']);
+                       }
+
+
+                       $GLOBALS['phpgw']->db->committrans();
+
+                       $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";
+                       $dbresult = $GLOBALS['phpgw']->db->Execute($sql);
+                       $attrib_sort    = $dbresult->fields['attrib_sort'];
+                       $sql = "SELECT max(attrib_sort) as max_sort FROM 
fm_tenant_attribute";
+                       $dbresult = $GLOBALS['phpgw']->db->Execute($sql);
+                       $max_sort       = $dbresult->fields['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);
+                                               
$GLOBALS['phpgw']->db->Execute($sql);
+                                               $sql = "UPDATE 
fm_tenant_attribute set attrib_sort=" . ($attrib_sort-1) ." WHERE id=$id";
+                                               
$GLOBALS['phpgw']->db->Execute($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);
+                                               
$GLOBALS['phpgw']->db->Execute($sql);
+                                               $sql = "UPDATE 
fm_tenant_attribute set attrib_sort=" . ($attrib_sort+1) ." WHERE id=$id";
+                                               
$GLOBALS['phpgw']->db->Execute($sql);
+                                       }
+                                       break;
+                               default:
+                                       return;
+                                       break;
+                       }
+               }
+               function delete_attrib($attrib_id)
+               {
+                       $this->init_process();
+
+                       $sql = "SELECT * FROM fm_tenant_attribute WHERE 
id=$attrib_id";
+
+                       $dbresult = $GLOBALS['phpgw']->db->Execute($sql);
+                       $ColumnName             = 
$dbresult->fields['column_name'];
+
+                       if($this->oProc->DropColumn('fm_tenant', $ColumnName))
+                       {
+                               $sql = "SELECT attrib_sort FROM 
fm_tenant_attribute where id=$attrib_id";
+                               $dbresult = 
$GLOBALS['phpgw']->db->Execute($sql);
+                               $attrib_sort    = 
$dbresult->fields['attrib_sort'];
+                               $sql2 = "SELECT max(attrib_sort) as max_sort 
FROM fm_tenant_attribute";
+                               $dbresult = 
$GLOBALS['phpgw']->db->Execute($sql2);
+                               $max_sort       = $dbresult->fields['max_sort'];
+                               if($max_sort>$attrib_sort)
+                               {
+                                       $sql = "UPDATE fm_tenant_attribute set 
attrib_sort=attrib_sort-1 WHERE attrib_sort > $attrib_sort";
+                                       $GLOBALS['phpgw']->db->Execute($sql);
+                               }
+
+                               $GLOBALS['phpgw']->db->Execute("DELETE FROM 
fm_tenant_attribute WHERE id=$attrib_id");
+                       }
+                       else
+                       {
+                               $receipt['error'][] = array('msg'       => 
lang('Attribute has NOT been deleted'));
+                       }
+
+                       return $receipt;
+               }
+
+
        }
 ?>




reply via email to

[Prev in Thread] Current Thread [Next in Thread]