phpgroupware-cvs
[Top][All Lists]
Advanced

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

[Phpgroupware-cvs] property/inc class.soadmin_entity.inc.php


From: Sigurd Nes
Subject: [Phpgroupware-cvs] property/inc class.soadmin_entity.inc.php
Date: Tue, 07 Feb 2006 14:17:29 +0000

CVSROOT:        /sources/phpgroupware
Module name:    property
Branch:         
Changes by:     Sigurd Nes <address@hidden>     06/02/07 14:17:28

Modified files:
        inc            : class.soadmin_entity.inc.php 

Log message:
        

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/inc/class.soadmin_entity.inc.php.diff?tr1=1.13&tr2=1.14&r1=text&r2=text

Patches:
Index: property/inc/class.soadmin_entity.inc.php
diff -u property/inc/class.soadmin_entity.inc.php:1.13 
property/inc/class.soadmin_entity.inc.php:1.14
--- property/inc/class.soadmin_entity.inc.php:1.13      Sun Feb  5 20:07:35 2006
+++ property/inc/class.soadmin_entity.inc.php   Tue Feb  7 14:17:28 2006
@@ -8,7 +8,7 @@
        * @internal Development of this application was funded by 
http://www.bergen.kommune.no/bbb_/ekstern/
        * @package property
        * @subpackage admin
-       * @version $Id: class.soadmin_entity.inc.php,v 1.13 2006/02/05 20:07:35 
sigurdne Exp $
+       * @version $Id: class.soadmin_entity.inc.php,v 1.14 2006/02/07 14:17:28 
sigurdne Exp $
        */
 
        /**
@@ -385,6 +385,34 @@
                }
 
 
+               function get_default_column_def()
+               {
+               
+                       $fd=array();
+                       $fd['id'] = array('type' => 'int', 'precision' => 4, 
'nullable' => False);
+                       $fd['num'] = array('type' => 'varchar', 'precision' => 
16, 'nullable' => False);
+                       $fd['p_num'] = array('type' => 'varchar', 'precision' 
=> 16, 'nullable' => True);
+                       $fd['p_entity_id'] = array('type' => 'int', 'precision' 
=> 4, 'nullable' => True);
+                       $fd['p_cat_id'] = array('type' => 'int', 'precision' => 
4, 'nullable' => True);
+                       $fd['location_code'] = array('type' => 'varchar', 
'precision' => 25, 'nullable' => True);
+
+                       $location_type = 
$this->bocommon->next_id('fm_location_type');
+                       
+                       for ($i=1; $i<$location_type; $i++)
+                       {
+                               $fd['loc' . $i] = array('type' => 'varchar', 
'precision' => 4, 'nullable' => True);
+                       }
+
+                       $fd['address'] = array('type' => 'varchar', 'precision' 
=> 150, 'nullable' => True);
+                       $fd['tenant_id'] = array('type' => 'int', 'precision' 
=> 4, 'nullable' => True);
+                       $fd['contact_phone'] = array('type' => 'varchar', 
'precision' => 30, 'nullable' => True);
+                       $fd['status'] = array('type' => 'int', 'precision' => 
4, 'nullable' => True);
+                       $fd['entry_date'] = array('type' => 'int', 'precision' 
=> 4, 'nullable' => True);
+                       $fd['user_id'] = array('type' => 'int', 'precision' => 
4, 'nullable' => True);
+                       
+                       return $fd;
+               }
+
                function add_category($values)
                {
                        $values['name'] = 
$this->db->db_addslashes($values['name']);
@@ -392,8 +420,6 @@
 
                        $values['id'] = 
$this->bocommon->next_id('fm_entity_category',array('entity_id'=>$values['entity_id']));
 
-                       $location_type = 
$this->bocommon->next_id('fm_location_type');
-
                        $values_insert= array(
                                $values['entity_id'],
                                $values['id'],
@@ -431,25 +457,7 @@
 
                        $this->init_process();
 
-                       $fd=array();
-                       $fd['id'] = array('type' => 'int', 'precision' => 4, 
'nullable' => False);
-                       $fd['num'] = array('type' => 'varchar', 'precision' => 
16, 'nullable' => False);
-                       $fd['p_num'] = array('type' => 'varchar', 'precision' 
=> 16, 'nullable' => True);
-                       $fd['p_entity_id'] = array('type' => 'int', 'precision' 
=> 4, 'nullable' => True);
-                       $fd['p_cat_id'] = array('type' => 'int', 'precision' => 
4, 'nullable' => True);
-                       $fd['location_code'] = array('type' => 'varchar', 
'precision' => 25, 'nullable' => True);
-
-                       for ($i=1; $i<$location_type; $i++)
-                       {
-                               $fd['loc' . $i] = array('type' => 'varchar', 
'precision' => 4, 'nullable' => True);
-                       }
-
-                       $fd['address'] = array('type' => 'varchar', 'precision' 
=> 150, 'nullable' => True);
-                       $fd['tenant_id'] = array('type' => 'int', 'precision' 
=> 4, 'nullable' => True);
-                       $fd['contact_phone'] = array('type' => 'varchar', 
'precision' => 30, 'nullable' => True);
-                       $fd['status'] = array('type' => 'int', 'precision' => 
4, 'nullable' => True);
-                       $fd['entry_date'] = array('type' => 'int', 'precision' 
=> 4, 'nullable' => True);
-                       $fd['user_id'] = array('type' => 'int', 'precision' => 
4, 'nullable' => True);
+                       $fd = $this->get_default_column_def();
 
                        $pk[]= 'id';
                        $table                  = 'fm_entity_'. 
$values['entity_id'] .'_'.$values['id'];
@@ -674,19 +682,72 @@
                        $this->db->query("DELETE FROM fm_entity_attribute WHERE 
entity_id= $entity_id AND cat_id= $id",__LINE__,__FILE__);
                        $this->db->query("DELETE FROM fm_acl_location WHERE 
id='.entity." . $entity_id . "." . $id ."'",__LINE__,__FILE__);
                        $this->db->query("DELETE FROM fm_acl2 WHERE 
acl_location='.entity." . $entity_id . "." . $id ."'",__LINE__,__FILE__);
+                       $this->db->query("DELETE FROM fm_entity_history WHERE 
history_appname = 'entity_" . $entity_id  . '_' . $id . "'",__LINE__,__FILE__);
+               }
+
+
+               function get_table_def($entity_id,$cat_id)
+               {
+                       $table = 'fm_entity_' . $entity_id . '_' . $cat_id;
+                       $metadata = $this->db->metadata($table);
+
+                       $fd = $this->get_default_column_def();
+                       
+                       for ($i=0; $i<count($metadata); $i++)
+                       {
+                               $sql = "SELECT * FROM fm_entity_attribute WHERE 
entity_id = $entity_id AND cat_id=$cat_id AND column_name = '" . 
$metadata[$i]['name'] . "'";
+
+                               $this->db->query($sql,__LINE__,__FILE__);
+                               while($this->db->next_record())
+                               {
+                                       if(!$precision = 
$this->db->f('precision_'))
+                                       {
+                                               $precision = 
$this->bocommon->translate_datatype_precision($this->db->f('datatype'));
+                                       }
+
+                                       $fd[$metadata[$i]['name']] = array(
+                                                       'type' => 
$this->bocommon->translate_datatype_insert(stripslashes($this->db->f('datatype'))),
+                                                       'precision' => 
$precision,
+                                                       'nullable' => 
stripslashes($this->db->f('nullable')),
+                                                       'default' => 
stripslashes($this->db->f('default_value')),
+                                                       'scale' => 
$this->db->f('scale')
+                                                       );
+                                       unset($precision);
+                               }
+                       }
+
+                       $table_def = array(
+                               $table =>       array(
+                                       'fd' => $fd
+                                       )
+                               );
+                       
+                       $table_def[$table]['pk'] = array('id');
+                       $table_def[$table]['fk'] = array();                     
+                       $table_def[$table]['ix'] = array();                     
+                       $table_def[$table]['uc'] = array();                     
+
+                       return $table_def;
                }
 
+
                function delete_attrib($cat_id,$entity_id,$attrib_id)
                {
                        $this->init_process();
 
+                       $this->db->transaction_begin();
+
                        $sql = "SELECT * FROM fm_entity_attribute WHERE 
entity_id=$entity_id AND cat_id=$cat_id AND id=$attrib_id";
 
                        $this->db->query($sql,__LINE__,__FILE__);
                        $this->db->next_record();
+
                        $ColumnName             = $this->db->f('column_name');
+                       $table  = 'fm_entity_'. $entity_id .'_'.$cat_id;
+                       $table_def = $this->get_table_def($entity_id,$cat_id);  
+                       $this->oProc->m_aTables = $table_def;
 
-                       $this->oProc->DropColumn('fm_entity_' .$entity_id.'_'. 
$cat_id,'', $ColumnName);
+                       $this->oProc->DropColumn($table,$table_def[$table], 
$ColumnName);
 
                        $sql = "SELECT attrib_sort FROM fm_entity_attribute 
where entity_id=$entity_id AND cat_id=$cat_id AND id=$attrib_id";
                        $this->db->query($sql,__LINE__,__FILE__);
@@ -703,6 +764,8 @@
                        }
 
                        $this->db->query("DELETE FROM fm_entity_attribute WHERE 
entity_id=$entity_id AND cat_id=$cat_id AND id=$attrib_id",__LINE__,__FILE__);
+                       $this->db->query("DELETE FROM fm_entity_history WHERE 
history_appname = 'entity_" . $entity_id  . '_' . $cat_id . "' AND 
history_entity_attrib_id = $attrib_id",__LINE__,__FILE__);
+                       $this->db->transaction_commit();
                }
 
                function delete_status($cat_id,$entity_id,$status_id)
@@ -714,8 +777,6 @@
 
                function read_attrib($data)
                {
-
-//_debug_array($data);
                        if(is_array($data))
                        {
                                if ($data['start'])
@@ -765,54 +826,52 @@
                                $this->db->query($sql . 
$ordermethod,__LINE__,__FILE__);
                        }
 
-
                        while ($this->db->next_record())
                        {
                                $attrib[] = array
                                (
-                                       'id'                    => 
$this->db->f('id'),
+                                       'id'            => $this->db->f('id'),
                                        'entity_type'   => 
$this->db->f('type_id'),
                                        'attrib_sort'   => 
$this->db->f('attrib_sort'),
-                                       'list'                  => 
$this->db->f('list'),
+                                       'list'          => $this->db->f('list'),
                                        'lookup_form'   => 
$this->db->f('lookup_form'),
                                        'entity_form'   => 
$this->db->f('entity_form'),
                                        'column_name'   => 
$this->db->f('column_name'),
-                                       'name'                  => 
$this->db->f('input_text'),
-                                       'size'                  => 
$this->db->f('size'),
+                                       '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'),
-                                       'search'                => 
$this->db->f('search')
-                       );
+                                       'type_name'     => $this->db->f('type'),
+                                       'datatype'      => 
$this->db->f('datatype'),
+                                       'search'        => 
$this->db->f('search')
+                               );
                        }
                        return $attrib;
                }
 
                function read_single_attrib($entity_id,$cat_id,$id)
                {
-
                        $sql = "SELECT * FROM fm_entity_attribute where 
entity_id=$entity_id AND cat_id=$cat_id AND id=$id";
 
                        $this->db->query($sql,__LINE__,__FILE__);
 
                        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['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_id']                              
        = $this->db->f('type_id');
-                               $attrib['type_name']                            
= $this->db->f('type_name');
-                               $attrib['lookup_form']                          
= $this->db->f('lookup_form');
-                               $attrib['list']                                 
        = $this->db->f('list');
-                               $attrib['search']                               
        = $this->db->f('search');
-                               $attrib['history']                              
        = $this->db->f('history');
+                               $attrib['type_id']                      = 
$this->db->f('type_id');
+                               $attrib['type_name']                    = 
$this->db->f('type_name');
+                               $attrib['lookup_form']                  = 
$this->db->f('lookup_form');
+                               $attrib['list']                         = 
$this->db->f('list');
+                               $attrib['search']                       = 
$this->db->f('search');
+                               $attrib['history']                      = 
$this->db->f('history');
                                if($this->db->f('datatype')=='R' || 
$this->db->f('datatype')=='CH' || $this->db->f('datatype')=='LB')
                                {
                                        $attrib['choice'] = 
$this->read_attrib_choice($entity_id,$cat_id,$id);
@@ -841,7 +900,6 @@
 
                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']);
@@ -852,6 +910,16 @@
                        $this->db->query($sql,__LINE__,__FILE__);
                        $this->db->next_record();
                        $attrib_sort    = $this->db->f('max_sort')+1;
+               
+                       if($attrib['column_info']['type']=='R' || 
$attrib['column_info']['type']== 'CH' || $attrib['column_info']['type'] =='LB' 
|| $attrib['column_info']['type'] =='AB' || $attrib['column_info']['type'] 
=='VENDOR')
+                       {
+                               if ($attrib['history'])
+                               {
+                                       $receipt['error'][] = array('msg'       
=> lang('History not allowed for this datatype'));
+                               }
+
+                               $attrib['history'] = False;
+                       }
 
                        $values= array(
                                $attrib['entity_id'],
@@ -925,14 +993,13 @@
 
                function init_process()
                {
-                       $this->oProc                                            
= 
CreateObject('phpgwapi.schema_proc',$GLOBALS['phpgw_info']['server']['db_type']);
-                       $this->oProc->m_odb                                     
= $this->db;
+                       $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)
                {
-
                        $choice_table = 'fm_entity_choice';
 
                        $attrib['column_name'] = 
$this->db->db_addslashes($attrib['column_name']);
@@ -940,27 +1007,57 @@
                        $attrib['statustext'] = 
$this->db->db_addslashes($attrib['statustext']);
                        $attrib['default'] = 
$this->db->db_addslashes($attrib['default']);
 
-                       $this->db->query("SELECT column_name FROM 
fm_entity_attribute WHERE entity_id=" . $attrib['entity_id']. " AND cat_id=" . 
$attrib['cat_id']. " AND id='" . $attrib['id']. "'",__LINE__,__FILE__);
+                       if($attrib['column_info']['type']=='R' || 
$attrib['column_info']['type']== 'CH' || $attrib['column_info']['type'] =='LB' 
|| $attrib['column_info']['type'] =='AB' || $attrib['column_info']['type'] 
=='VENDOR')
+                       {
+                               if ($attrib['history'])
+                               {
+                                       $receipt['error'][] = array('msg'       
=> lang('History not allowed for this datatype'));
+                               }
+                               
+                               $attrib['history'] = False;
+                       }
+
+                       $this->db->query("SELECT column_name, 
datatype,precision_ FROM fm_entity_attribute WHERE entity_id=" . 
$attrib['entity_id']. " AND cat_id=" . $attrib['cat_id']. " AND id='" . 
$attrib['id']. "'",__LINE__,__FILE__);
                        $this->db->next_record();
                        $OldColumnName          = $this->db->f('column_name');
+                       $OldDataType            = $this->db->f('datatype');
+                       $OldPrecision           = $this->db->f('precision_');   
                
+                       
+                       $table_def = 
$this->get_table_def($attrib['entity_id'],$attrib['cat_id']);      
 
                        $this->db->transaction_begin();
 
-                               $value_set=array(
-                                       'input_text'    => 
$attrib['input_text'],
-                                       'statustext'    => 
$attrib['statustext'],
-                                       'search'        => $attrib['search'],
-                                       'list'          => $attrib['list'],
-                                       'history'       => $attrib['history'],
-                                       );
+                       $value_set=array(
+                               'input_text'    => $attrib['input_text'],
+                               'statustext'    => $attrib['statustext'],
+                               'search'        => $attrib['search'],
+                               'list'          => $attrib['list'],
+                               'history'       => $attrib['history'],
+                               );
 
-                               $value_set      = 
$this->bocommon->validate_db_update($value_set);
+                       $value_set      = 
$this->bocommon->validate_db_update($value_set);
 
-                               $this->db->query("UPDATE fm_entity_attribute 
set $value_set WHERE entity_id=" . $attrib['entity_id']. " AND cat_id=" . 
$attrib['cat_id']. " AND id=" . $attrib['id'],__LINE__,__FILE__);
+                       $this->db->query("UPDATE fm_entity_attribute set 
$value_set WHERE entity_id=" . $attrib['entity_id']. " AND cat_id=" . 
$attrib['cat_id']. " AND id=" . $attrib['id'],__LINE__,__FILE__);
+
+                       $this->init_process();
+                       
+                       $this->oProc->m_odb->transaction_begin();
+
+                       $this->oProc->m_aTables = $table_def;
 
                        if($OldColumnName !=$attrib['column_name'])
                        {
+                               $value_set=array('column_name'  => 
$attrib['column_name']);
 
+                               $value_set      = 
$this->bocommon->validate_db_update($value_set);
+
+                               $this->db->query("UPDATE fm_entity_attribute 
set $value_set WHERE entity_id=" . $attrib['entity_id']. " AND cat_id=" . 
$attrib['cat_id']. " AND id=" . $attrib['id'],__LINE__,__FILE__);
+
+                               
$this->oProc->RenameColumn('fm_entity_'.$attrib['entity_id'] . '_' . 
$attrib['cat_id'], $OldColumnName, $attrib['column_name']);
+                       }
+
+                       if (($OldDataType != $attrib['column_info']['type']) || 
($OldPrecision != $attrib['column_info']['precision']) )
+                       {
                                if($attrib['column_info']['type']!='R' && 
$attrib['column_info']['type']!='CH' && $attrib['column_info']['type']!='LB')
                                {
                                        $this->db->query("DELETE FROM 
$choice_table WHERE entity_id=" . $attrib['entity_id']. " AND cat_id=" . 
$attrib['cat_id']. " AND attrib_id=" . $attrib['id'],__LINE__,__FILE__);
@@ -983,11 +1080,11 @@
 
                                $value_set=array(
                                        'column_name'   => 
$attrib['column_name'],
-                                       'datatype'              => 
$attrib['column_info']['type'],
+                                       'datatype'      => 
$attrib['column_info']['type'],
                                        'precision_'    => 
$attrib['column_info']['precision'],
-                                       'scale'                 => 
$attrib['column_info']['scale'],
+                                       'scale'         => 
$attrib['column_info']['scale'],
                                        'default_value' => 
$attrib['column_info']['default'],
-                                       'nullable'              => 
$attrib['column_info']['nullable']
+                                       'nullable'      => 
$attrib['column_info']['nullable']
                                        );
 
                                $value_set      = 
$this->bocommon->validate_db_update($value_set);
@@ -995,25 +1092,9 @@
                                $this->db->query("UPDATE fm_entity_attribute 
set $value_set WHERE entity_id=" . $attrib['entity_id']. " AND cat_id=" . 
$attrib['cat_id']. " AND id=" . $attrib['id'],__LINE__,__FILE__);
 
                                $attrib['column_info']['type']  = 
$this->bocommon->translate_datatype_insert($attrib['column_info']['type']);
-
-                               $this->init_process();
-
-                               $mini_table_def = array(
-                                       'fm_entity_'.$attrib['entity_id'] . '_' 
. $attrib['cat_id'] =>  array(
-                                               'fd' => array(
-                                                       $OldColumnName  
=>$attrib['column_info']),
-                                               'pk' => array(),
-                                               'fk' => array(),
-                                               'ix' => array(),
-                                               'uc' => array()
-                                               )
-                                       );
-
-                               $this->oProc->GenerateScripts($mini_table_def);
-                               
$this->oProc->RenameColumn('fm_entity_'.$attrib['entity_id'] . '_' . 
$attrib['cat_id'], $OldColumnName, $attrib['column_name']);
-                               
$this->oProc->AlterColumn('fm_entity_'.$attrib['entity_id'] . '_' . 
$attrib['cat_id'],$attrib['column_name'],$attrib['column_info']);
+                               
$this->oProc->AlterColumn('fm_entity_'.$attrib['entity_id'] . '_' . 
$attrib['cat_id'],$attrib['column_name'],$attrib['column_info']);               
    
                        }
-
+                       
                        $choice_table ='fm_entity_choice';
 
                        if($attrib['new_choice'])
@@ -1043,7 +1124,7 @@
                        }
 
                        $this->db->transaction_commit();
-
+                       $this->oProc->m_odb->transaction_commit();
                        $receipt['message'][] = array('msg'     => 
lang('Attribute has been edited'));
 
                        return $receipt;
@@ -1225,7 +1306,6 @@
 
                        $values = $this->bocommon->validate_db_insert($values);
 
-//_debug_array($custom_function);
                        $this->db->transaction_begin();
 
                        $this->db->query("INSERT INTO fm_custom_function 
(acl_location, id, file_name, descr, active, custom_sort) "




reply via email to

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