fmsystem-commits
[Top][All Lists]
Advanced

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

[Fmsystem-commits] [15574]


From: nelson . guerra
Subject: [Fmsystem-commits] [15574]
Date: Sat, 3 Sep 2016 01:04:18 +0000 (UTC)

Revision: 15574
          http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=15574
Author:   nelson224
Date:     2016-09-03 01:04:17 +0000 (Sat, 03 Sep 2016)
Log Message:
-----------


Modified Paths:
--------------
    branches/dev-syncromind-2/property/inc/class.uiimport_components.inc.php

Modified: 
branches/dev-syncromind-2/property/inc/class.uiimport_components.inc.php
===================================================================
--- branches/dev-syncromind-2/property/inc/class.uiimport_components.inc.php    
2016-09-03 00:21:27 UTC (rev 15573)
+++ branches/dev-syncromind-2/property/inc/class.uiimport_components.inc.php    
2016-09-03 01:04:17 UTC (rev 15574)
@@ -34,6 +34,7 @@
 
        class property_uiimport_components extends phpgwapi_uicommon_jquery
        {
+               private $receipt = array();
                var $type = 'entity';
                protected $type_app = array
                        (
@@ -457,7 +458,11 @@
                        {
                                if (count($attrib_names))
                                {
-                                       $columns = 
$this->add_attribute_to_template($columns, $attrib_names, $attrib_data_types, 
$template_id);
+                                       $receipt = 
$this->add_attribute_to_template($columns, $attrib_names, $attrib_data_types, 
$template_id);
+                                       if ($receipt['error'])
+                                       {
+                                               print_r($receipt); die;
+                                       }
                                }
                                        
                                //$rows = 
$objPHPExcel->getActiveSheet()->getHighestDataRow();
@@ -476,17 +481,119 @@
                                        $import_data[] = $_result;
                                }
                                
-                               
+                               print_r($import_data); die;
                                return $import_data;
                        }
                }
                
-               private function add_attribute_to_template($columns, 
$attrib_names, $attrib_data_types, $template_id)
+               private function add_attribute_to_template(&$columns, 
$attrib_names, $attrib_data_types, $template_id)
                {
+                       $receipt = array();
                        
-                       return $columns;
+                       $template = explode('_', $template_id);
+                       $entity_id = $template[0];
+                       $cat_id = $template[1];
+
+                       $appname = $this->type_app[$this->type];
+                       $location = ".{$this->type}.{$entity_id}.{$cat_id}";
+                       $attrib_table = 
$GLOBALS['phpgw']->locations->get_attrib_table($appname, $location);
+                       
+                       $attributes = array();
+                       
+                       foreach ($columns as $_row_key => $_value_key)
+                       {
+                               $attrib = array();
+                               if ($_value_key == 'new_column')
+                               {
+                                       $attrib['entity_id'] = $entity_id;
+                                       $attrib['cat_id'] = $cat_id;
+                                       $attrib['appname'] = $appname;
+                                       $attrib['location'] = $location;
+                       
+                                       $attrib['column_name'] = 
$attrib_names[$_row_key];
+                                       $attrib['input_text'] = 
ucfirst($attrib_names[$_row_key]);
+                                       $attrib['statustext'] = 
ucfirst($attrib_names[$_row_key]);
+                                       $attrib['column_info']['type'] = 
$attrib_data_types[$_row_key];
+                                       $attrib['column_info']['precision'] = 
255;
+                                       $attrib['column_info']['nullable'] = 
'True';
+                                       $attrib['search'] = 1;
+                                       
+                                       $receipt = 
$this->valid_attributes($attrib);
+                                       if ($receipt['error'])
+                                       {
+                                               break;
+                                       }
+                                       $attrib['_row_key'] = $_row_key;
+                                       $attributes[] = $attrib;
+                               }
+                       }
+                       
+                       foreach($attributes as $attrib)
+                       {
+                               $id = $this->custom->add($attrib, 
$attrib_table);       
+                               if ($id <= 0)
+                               {
+                                       $receipt['error'][] = array('msg' => 
lang('Unable to add field'));
+                                       break;
+                               }
+                               else if ($id == -1)
+                               {
+                                       $receipt['error'][] = array('msg' => 
lang('field already exists, please choose another name'));
+                                       $receipt['error'][] = array('msg' => 
lang('Attribute has NOT been saved'));
+                                       break;
+                               }
+                               $columns[$attrib['_row_key']] = 
$attrib['column_name'];
+                       }
+                       
+                       return $receipt;
                }
                
+               private function valid_attributes($values)
+               {
+                       $receipt = array();
+                       
+                       if (!$values['column_name'])
+                       {
+                               $receipt['error'][] = array('msg' => 
lang('Column name not entered!'));
+                       }
+
+                       if (!preg_match('/^[a-z0-9_]+$/i', 
$values['column_name']))
+                       {
+                               $receipt['error'][] = array('msg' => 
lang('Column name %1 contains illegal character', $values['column_name']));
+                       }
+
+                       if (!$values['input_text'])
+                       {
+                               $receipt['error'][] = array('msg' => 
lang('Input text not entered!'));
+                       }
+                       
+                       if (!$values['statustext'])
+                       {
+                               $receipt['error'][] = array('msg' => 
lang('Statustext not entered!'));
+                       }
+
+                       if (!$values['entity_id'])
+                       {
+                               $receipt['error'][] = array('msg' => 
lang('entity type not chosen!'));
+                       }
+
+                       if (!$values['column_info']['type'])
+                       {
+                               $receipt['error'][] = array('msg' => 
lang('Datatype type not chosen!'));
+                       }
+
+                       if (!ctype_digit($values['column_info']['precision']) 
&& $values['column_info']['precision'])
+                       {
+                               $receipt['error'][] = array('msg' => 
lang('Please enter precision as integer !'));
+                       }
+
+                       if (!$values['column_info']['nullable'])
+                       {
+                               $receipt['error'][] = array('msg' => 
lang('Nullable not chosen!'));
+                       }                       
+                       
+                       return $receipt;
+               }
                /**
                 * Prepare UI
                 * @return void




reply via email to

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