phpgroupware-cvs
[Top][All Lists]
Advanced

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

[Phpgroupware-cvs] property/inc class.soadmin_location.inc.php,1.9


From: sigurdne
Subject: [Phpgroupware-cvs] property/inc class.soadmin_location.inc.php,1.9
Date: Wed, 11 May 2005 21:25:00 +0200

Update of property/inc

Modified Files:
     Branch: MAIN
            class.soadmin_location.inc.php lines: +216 -41

Log Message:
no message

====================================================
Index: property/inc/class.soadmin_location.inc.php
diff -u property/inc/class.soadmin_location.inc.php:1.8 
property/inc/class.soadmin_location.inc.php:1.9
--- property/inc/class.soadmin_location.inc.php:1.8     Mon May  9 09:17:49 2005
+++ property/inc/class.soadmin_location.inc.php Wed May 11 19:25:36 2005
@@ -203,21 +203,60 @@

                        $this->db->transaction_begin();

-                       $this->db->query("INSERT INTO fm_location_type 
(id,name, descr) "
-                               . "VALUES ('" . $standard['id'] . "','" . 
$standard['name'] . "','" . $standard['descr']. "')",__LINE__,__FILE__);

                        $receipt['id']= $standard['id'];

                        $this->init_process();

+                       $default_attrib['id'][]= 1;
+                       $default_attrib['column_name'][]= 'location_code';
+                       $default_attrib['type'][]='V';
+                       $default_attrib['precision'][] =4*$standard['id'];
+                       $default_attrib['nullable'][] ='False';
+
+                       $default_attrib['id'][]= 2;
+                       $default_attrib['column_name'][]= 'loc' . 
$standard['id'] . '_name';
+                       $default_attrib['type'][]='V';
+                       $default_attrib['precision'][] =50;
+                       $default_attrib['nullable'][] ='True';
+
+                       $default_attrib['id'][]= 3;
+                       $default_attrib['column_name'][]= 'entry_date';
+                       $default_attrib['type'][]='I';
+                       $default_attrib['precision'][] =4;
+                       $default_attrib['nullable'][] ='True';
+
+                       $default_attrib['id'][]= 4;
+                       $default_attrib['column_name'][]= 'category';
+                       $default_attrib['type'][]='I';
+                       $default_attrib['precision'][] =4;
+                       $default_attrib['nullable'][] ='False';
+
+                       $default_attrib['id'][]= 5;
+                       $default_attrib['column_name'][]= 'user_id';
+                       $default_attrib['type'][]='I';
+                       $default_attrib['precision'][] =4;
+                       $default_attrib['nullable'][] ='False';
+
+                       $default_attrib['id'][]= 6;
+                       $default_attrib['column_name'][]= 'remark';
+                       $default_attrib['type'][]='T';
+                       $default_attrib['precision'][] = False;
+                       $default_attrib['nullable'][] ='False';
+
                        $fd=array();
                        $fd['location_code'] = array('type' => 'varchar', 
'precision' => 25, 'nullable' => False);

                        for ($i=1; $i<$standard['id']+1; $i++)
                        {
-
                                $fd['loc' . $i] = array('type' => 'varchar', 
'precision' => 4, 'nullable' => False);
                                $pk[$i-1]= 'loc' . $i;
+
+                               $default_attrib['id'][]= $i+6;
+                               $default_attrib['column_name'][]= 'loc' . $i;
+                               $default_attrib['type'][]='V';
+                               $default_attrib['precision'][] =4;
+                               $default_attrib['nullable'][] ='False';
                        }

                        $fk_table='fm_location'. ($standard['id']-1);
@@ -227,7 +266,6 @@
                                $fk['loc' . $i] = $fk_table . '.loc' . $i;
                        }

-
                        if($standard['id']==1)
                        {
                                $fd['part_of_town_id'] = array('type' => 'int', 
'precision' => 2, 'nullable' => True);
@@ -240,10 +278,12 @@
                        $fd['remark'] = array('type' => 'text', 'nullable' => 
True);
                        $fd['status'] = array('type' => 'int', 'precision' => 
4, 'nullable' => True);

-//                     
$add_columns_in_tables=array('fm_meter','fm_project','fm_tts_tickets','fm_request','fm_document','fm_investment');
-                       
$add_columns_in_tables=array('fm_project','fm_tts_tickets','fm_request','fm_document','fm_investment');
+                       $ix = array('location_code');
+                       $uc = array();

-                       if($this->oProc->CreateTable('fm_location'. 
$standard['id'],array('fd' => $fd,'pk' => $pk,'fk' => $fk,'ix' => 
array('location_code'),'uc' => array())))
+//                     
$add_columns_in_tables=array('fm_project','fm_tts_tickets','fm_request','fm_document','fm_investment');
+
+                       if($this->oProc->CreateTable('fm_location'. 
$standard['id'],array('fd' => $fd,'pk' => $pk,'fk' => $fk,'ix' => $ix,'uc' => 
$uc)))
                        {

                                $this->oProc->CreateTable('fm_location'. 
$standard['id'] . '_category', array(
@@ -263,6 +303,40 @@

                                $values_insert= array(
                                        $standard['id'],
+                                       $standard['name'],
+                                       $standard['descr'],
+                                   $this->db->db_addslashes(implode(',',$pk)),
+                                   $this->db->db_addslashes(implode(',',$ix)),
+                                   $this->db->db_addslashes(implode(',',$uc)),
+                                       );
+
+                               $values_insert  = 
$this->bocommon->validate_db_insert($values_insert);
+
+                               $this->db->query("INSERT INTO fm_location_type 
(id,name, descr,pk,ix,uc) "
+                                       . "VALUES 
($values_insert)",__LINE__,__FILE__);
+
+                               for ($i=0;$i<count($default_attrib['id']);$i++)
+                               {
+                                       $values_insert= array(
+                                               $standard['id'],
+                                               $default_attrib['id'][$i],
+                                               
$default_attrib['column_name'][$i],
+                                               $default_attrib['type'][$i],
+                                               
$default_attrib['precision'][$i],
+                                               'dummy',
+                                               'dummy',
+                                               'False'
+                                               );
+
+                                       $values_insert  = 
$this->bocommon->validate_db_insert($values_insert);
+
+                                       $this->db->query("INSERT INTO 
fm_location_attrib 
(type_id,id,column_name,datatype,precision_,input_text,statustext,nullable) "
+                                               . "VALUES 
($values_insert)",__LINE__,__FILE__);
+                               }
+
+                               $values_insert= array(
+                                       $standard['id'],
+                                       count($default_attrib['id'])+1,
                                        1,
                                        'status',
                                        'Status',
@@ -274,11 +348,9 @@

                                $values_insert  = 
$this->bocommon->validate_db_insert($values_insert);

-                               $this->db->query("INSERT INTO 
fm_location_attrib 
(type_id,id,column_name,input_text,statustext,datatype,attrib_sort,nullable) "
+                               $this->db->query("INSERT INTO 
fm_location_attrib 
(type_id,id,custom,column_name,input_text,statustext,datatype,attrib_sort,nullable)
 "
                                        . "VALUES 
($values_insert)",__LINE__,__FILE__);

-
-
                                $type_id=$standard['id'];

                                $this->db->query("INSERT INTO 
fm_location_choice (type_id,attrib_id,id,value) "
@@ -361,7 +433,7 @@
                                $table                  = 'fm_location_type';
                                $attrib_table   = 'fm_location_attrib';
                                $this->db->query("DELETE FROM $attrib_table 
WHERE type_id='" . $id . "'",__LINE__,__FILE__);
-
+                               $this->db->query("DELETE FROM 
fm_location_choice WHERE type_id='" . $id . "'",__LINE__,__FILE__);
                        }
                        $this->db->query("DELETE FROM $table WHERE id='" . $id 
. "'",__LINE__,__FILE__);
                }
@@ -417,7 +489,7 @@

                        $sql = "SELECT 
$table.id,$table.type_id,$table.list,$table.attrib_sort,$table.location_form,lookup_form,$table.column_name,$table.size
 ,statustext,$table.input_text,"
                                . " $table.datatype ,$type_table.name as type 
FROM $type_table $this->join $table on $table.type_id = $type_table.id "
-                               . " WHERE $table.type_id= '$type_id' 
$filtermethod $querymethod";
+                               . " WHERE $table.type_id= '$type_id' AND custom 
= 1 $filtermethod $querymethod";

                        $this->db2->query($sql,__LINE__,__FILE__);
                        $this->total_records = $this->db2->num_rows();
@@ -515,6 +587,11 @@
                        $this->db->next_record();
                        $attrib_sort    = $this->db->f('max_sort')+1;

+                       if($precision = 
$this->bocommon->translate_datatype_precision($attrib['column_info']['type']))
+                       {
+                               $attrib['column_info']['precision']=$precision;
+                       }
+
                        $values= array(
                                $attrib['id'],
                                $attrib['column_name'],
@@ -540,18 +617,20 @@

                        $receipt['id']= $attrib['id'];

-                       if($attrib['column_info']['type']=='email' && 
!$attrib['column_info']['precision'])
+
+
+/*                     if($attrib['column_info']['type']=='email' && 
!$attrib['column_info']['precision'])
                        {
                                $attrib['column_info']['precision']=64;
                        }
-
+*/
                        $attrib['column_info']['type']  = 
$this->bocommon->translate_datatype_insert($attrib['column_info']['type']);

-                       if($attrib['column_info']['type']=='int' && 
!$attrib['column_info']['precision'])
+/*                     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']);
@@ -643,12 +722,15 @@
                        $attrib['statustext'] = 
$this->db->db_addslashes($attrib['statustext']);
                        $attrib['default'] = 
$this->db->db_addslashes($attrib['default']);

-                       $this->db->query("SELECT column_name FROM 
fm_location_attrib WHERE type_id = " . $attrib['type_id'] ." AND id=" . 
$attrib['id'],__LINE__,__FILE__);
+                       $this->db->query("SELECT * FROM fm_location_attrib 
WHERE type_id = " . $attrib['type_id'] ." AND id=" . 
$attrib['id'],__LINE__,__FILE__);
                        $this->db->next_record();
                        $OldColumnName          = $this->db->f('column_name');
+                       $OldColumnType          = $this->db->f('datatype');
+                       $OldColumnPrecision     = $this->db->f('precision_');

                        $this->db->transaction_begin();

+                       $table_def = $this->get_table_def($attrib['type_id']);

                        $value_set=array(
                                'input_text'    => $attrib['input_text'],
@@ -661,14 +743,27 @@

                        $this->db->query("UPDATE fm_location_attrib set 
$value_set WHERE type_id = " . $attrib['type_id'] ." AND id=" . 
$attrib['id'],__LINE__,__FILE__);

-//                     if($OldColumnName !=$attrib['column_name'])
+                       $this->init_process();
+
+//_debug_array($table_def);
+                       $this->oProc->m_aTables = $table_def;
+
+                       if($OldColumnName !=$attrib['column_name'])
                        {

-                               if($attrib['column_info']['type']=='email' && 
!$attrib['column_info']['precision'])
-                               {
-                                       $attrib['column_info']['precision']=64;
-                               }
+                               $value_set=array(
+                                       'column_name'           => 
$attrib['column_name']
+                                       );

+                               $value_set      = 
$this->bocommon->validate_db_update($value_set);
+
+                               $this->db->query("UPDATE fm_location_attrib set 
$value_set WHERE type_id = " . $attrib['type_id'] ." AND id=" . 
$attrib['id'],__LINE__,__FILE__);
+
+                               
$this->oProc->RenameColumn('fm_location'.$attrib['type_id'], $OldColumnName, 
$attrib['column_name']);
+                       }
+
+                       if($OldColumnType !=$attrib['column_info']['type'])
+                       {
                                if($precision = 
$this->bocommon->translate_datatype_precision($attrib['column_info']['type']))
                                {
                                        
$attrib['column_info']['precision']=$precision;
@@ -679,8 +774,8 @@
                                        
unset($attrib['column_info']['default']);
                                }

+
                                $value_set=array(
-                                       'column_name'           => 
$attrib['column_name'],
                                        'type_id'                       => 
$attrib['type_id'],
                                        'datatype'                      => 
$attrib['column_info']['type'],
                                        'precision_'            => 
$attrib['column_info']['precision'],
@@ -695,21 +790,6 @@

                                $attrib['column_info']['type']  = 
$this->bocommon->translate_datatype_insert($attrib['column_info']['type']);

-                               $this->init_process();
-
-                               $mini_table_def = array(
-                                       'fm_location'.$attrib['type_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_location'.$attrib['type_id'], $OldColumnName, 
$attrib['column_name']);
                                
$this->oProc->AlterColumn('fm_location'.$attrib['type_id'],$attrib['column_name'],$attrib['column_info']);
                        }

@@ -745,16 +825,110 @@
                                $this->db->query("DELETE FROM $choice_table 
WHERE type_id=" . $attrib['type_id']. " AND attrib_id=" . 
$attrib['id'],__LINE__,__FILE__);
                        }

-
                        $this->db->transaction_commit();

                        $receipt['message'][] = array('msg'     => 
lang('Attribute has been edited'));

-
                        return $receipt;

                }

+               function get_table_def($id='')
+               {
+
+                       $metadata = $this->db->metadata('fm_location'.$id);
+//     _debug_array($metadata);
+
+                       for ($i=0; $i<count($metadata); $i++)
+                       {
+                               $sql = "SELECT * FROM fm_location_attrib WHERE 
type_id=$id AND column_name = '" . $metadata[$i]['name'] . "'";
+//     _debug_array($sql);
+
+                               $this->db->query($sql,__LINE__,__FILE__);
+                               if($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);
+                               }
+                       }
+
+
+
+/*                     $this->db->query("SELECT * FROM fm_location_attrib 
WHERE type_id=$id");
+
+                       while ($this->db->next_record())
+                       {
+                               if(!$precision = $this->db->f('precision_'))
+                               {
+                                       $precision = 
$this->bocommon->translate_datatype_precision($this->db->f('datatype'));
+                               }
+
+
+                               $fd[stripslashes($this->db->f('column_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);
+                       }
+
+*/
+                       $this->db->query("SELECT * FROM fm_location_type WHERE 
id=$id");
+                       $this->db->next_record();
+
+
+                       if($id>1)
+                       {
+                               $fk_table='fm_location'. ($id-1);
+                               for ($i=1; $i<$id; $i++)
+                               {
+                                       $fk['loc' . $i] = $fk_table . '.loc' . 
$i;
+                               }
+                       }
+
+                       $table_def = array(
+                               'fm_location'.$id =>    array(
+                                       'fd' => $fd
+                                       )
+                               );
+
+                       if($this->db->f('pk'))
+                       {
+                               $table_def['fm_location'.$id]['pk'] = 
explode(',',$this->db->f('pk'));
+                       }
+                       if($fk)
+                       {
+                               $table_def['fm_location'.$id]['fk'] = $fk;
+                       }
+                       if($this->db->f('ix'))
+                       {
+                               $table_def['fm_location'.$id]['ix'] = 
explode(',',$this->db->f('ix'));
+                       }
+                       if($this->db->f('uc'))
+                       {
+                               $table_def['fm_location'.$id]['uc'] = 
explode(',',$this->db->f('uc'));
+                       }
+
+
+
+                       return $table_def;
+               }
+
+
                function select_location_type()
                {
                        $this->db->query("SELECT * FROM fm_location_type ORDER 
BY id ");
@@ -771,6 +945,7 @@

                        return $location_type;
                }
+
                function resort_attrib($data)
                {
                        if(is_array($data))






reply via email to

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