fmsystem-commits
[Top][All Lists]
Advanced

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

[Fmsystem-commits] [15556]


From: nelson . guerra
Subject: [Fmsystem-commits] [15556]
Date: Wed, 31 Aug 2016 23:30:42 +0000 (UTC)

Revision: 15556
          http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=15556
Author:   nelson224
Date:     2016-08-31 23:30:41 +0000 (Wed, 31 Aug 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-08-31 23:30:28 UTC (rev 15555)
+++ branches/dev-syncromind-2/property/inc/class.uiimport_components.inc.php    
2016-08-31 23:30:41 UTC (rev 15556)
@@ -104,162 +104,130 @@
                {
                        $location_code = phpgw::get_var('location_code');
                        $id = phpgw::get_var('location_item_id');
-                       $template_id = phpgw::get_var('template_id');
-                       
-                       $step = phpgw::get_var('step', 'int', 'REQUEST');
-                       $sheet_id = phpgw::get_var('sheet_id', 'int', 
'REQUEST');
-                       $start_line = phpgw::get_var('start_line', 'int', 
'REQUEST');
-                       $columns = phpgw::get_var('columns');
-                       $columns = $columns && is_array($columns) ? $columns : 
array();
-                                       
                        $message = array();
                        
-                       phpgw::import_class('phpgwapi.phpexcel');
-                       
                        if (empty($id))
                        {
                                return $message['error'][] = array('msg' => 
'location code is empty');
                        }
                                
-                       if ($step == 1 && isset($_FILES['file']['tmp_name']))
+                       $exceldata = 
$this->getexceldata($_FILES['file']['tmp_name'], true);
+                       $relations = array();
+                       
+                       foreach ($exceldata as $row) 
                        {
-                               $file = $_FILES['file']['tmp_name'];
-                               $cached_file = "{$file}_temporary_import_file";
-
-                               file_put_contents($cached_file, 
file_get_contents($file));
-                               phpgwapi_cache::session_set('property', 
'components_import_file', $cached_file);
-                               
-                               $objPHPExcel = 
PHPExcel_IOFactory::load($cached_file);
-                               $AllSheets = $objPHPExcel->getSheetNames();
-
-                               $sheets = array();
-                               if ($AllSheets)
+                               if (!$this->valid_row($row))
                                {
-                                       foreach ($AllSheets as $key => $sheet)
-                                       {
-                                               $sheets[] = array
-                                                       (
-                                                       'id' => ($key + 1),
-                                                       'name' => $sheet
-                                               );
-                                       }
-                               }       
+                                       continue;
+                               }
                                
-                               return $sheets;
+                               $relations[$row[0]][] = $row[(count($row)-1)];
                        }
-                                               
-                       if ($step > 1) 
-                       {
-                               $cached_file = 
phpgwapi_cache::session_get('property', 'components_import_file');
-                               
-                               $objPHPExcel = 
PHPExcel_IOFactory::load($cached_file);
-                               
$objPHPExcel->setActiveSheetIndex((int)($sheet_id - 1));
-                               $rows = 
$objPHPExcel->getActiveSheet()->getHighestDataRow();
-                               $highestColumm = 
$objPHPExcel->getActiveSheet()->getHighestDataColumn();
-                               $highestColumnIndex = 
PHPExcel_Cell::columnIndexFromString($highestColumm);                           
          
-                       }       
                        
-                       if ($step == 2 && $sheet_id) 
+                       $this->db->transaction_begin();
+                       
+                       try
                        {
-                               $html_table = '<table class="pure-table 
pure-table-bordered">';
-                               $i = 0;
-                               $cols = array();
-                               for ($j = 0; $j < $highestColumnIndex; $j++)
+                               $this->db->Exception_On_Error = true;
+                               
+                               foreach ($relations as $k => $files) 
                                {
-                                       $cols[] = $this->getexcelcolumnname($j);
-                               }
-
-                               $html_table .= "<thead><tr><th align = 
'center'>" . lang('select') . "</th><th align = 'center'>" . lang('row') . 
"</th><th align='center'>" . implode("</th><th align='center'>", $cols) . 
'</th></tr></thead>';
-                               foreach 
($objPHPExcel->getActiveSheet()->getRowIterator() as $row)
-                               {
-                                       if ($i > 20)
+                                       if (empty($k))
                                        {
-                                               break;
+                                               $component = array('id' => $id, 
'location_id' => $GLOBALS['phpgw']->locations->get_id('property', 
'.location.'.count(explode('-', $location_code))));
                                        }
+                                       else {
+                                               $component = 
$this->get_component[$k];
+                                               if( empty($component['id']) || 
empty($component['location_id']))
+                                               {
+                                                       throw new 
Exception("component {$k} does not exist");
+                                               }
+                                       }
                                        
-                                       $i++;
-                                       $row_key = $i;
-
-                                       $_radio = "<input type =\"radio\" 
name=\"start_line\" value=\"{$row_key}\">";
-
-                                       $cellIterator = $row->getCellIterator();
-                                       
$cellIterator->setIterateOnlyExistingCells(false);
-
-                                       $row_values = array();
-                                       foreach ($cellIterator as $cell)
+                                       foreach($files as $path_file)
                                        {
-                                               if (!is_null($cell))
+                                               $parts = explode("\\", 
$path_file);
+                                               $file = $parts[count($parts)-1];
+                                               if 
(!is_file($this->tmp_upload_dir.$file))
                                                {
-                                                       $row_values[] = 
$cell->getCalculatedValue();
+                                                       throw new 
Exception("the file {$file} does not exist, component: {$k}");
+                                               }       
+                                               
+                                               $file_id = 
$this->save_file($file);
+                                               if (!$file_id)
+                                               {                               
                
+                                                       throw new 
Exception("failed to save file {$file}, component: {$k}");
+                                               } 
+                       
+                                               $result = 
$this->save_file_relation($component['id'], $component['location_id'], 
$file_id);
+                                               if (!$result)
+                                               {                               
                
+                                                       throw new 
Exception("failed to save relation, file: {$file}, component: {$k}");
                                                }
                                        }
-                                       $html_table .= 
"<tr><td>{$_radio}</td><td>{$row_key}</td><td>" . implode('</td><td>', 
$row_values) . '</td></tr>';
                                }
-                               $html_table .= '</table>';
-                               
-                               return $html_table;
+                               $this->db->Exception_On_Error = false;
                        }
+                       catch (Exception $e)
+                       {
+                               if ($e)
+                               {
+                                       $this->db->transaction_abort();         
                
+                                       $message['error'][] = array('msg' => 
$e->getMessage());
+                                       return $this->jquery_results($message);
+                               }
+                       }
+
+                       $this->db->transaction_commit();
+                       $message['message'][] = array('msg' => 'all files saved 
successfully');
                        
-                       if ($step == 3 && $start_line) 
+                       return $this->jquery_results($message);
+               }
+               
+               private function getArrayItem($id, $name, $selected, $options = 
array(), $no_lang = false, $attribs = '' )
+               {
+                       // should be in class common.sbox
+                       if ( !is_array($options) || !count($options) )
                        {
-                               $html_table = '<table class="pure-table 
pure-table-bordered">';
-                               
-                               $_options = array
-                               (
-                                       'custom_attribute_1' => 'Romfnr',
-                                       'custom_attribute_2' => 'Prosj. romnr',
-                                       'custom_attribute_3' => 'Bruksromnr',
-                                       'custom_attribute_4' => 'Kontrakt',
-                                       'custom_attribute_5' => 'Kontrakt - 
navn',
-                                       'custom_attribute_6' => 'NS3420 - Kode',
-                                       'custom_attribute_7' => 'NS3420 - 
Beskrivelsestekst',
-                                       'custom_attribute_8' => 'Produkttype',
-                                       'custom_attribute_9' => 
'Produktbetegnelse',
-                                       'custom_attribute_10' => 
'EL.nr./NRF.nr.',
-                                       'custom_attribute_11' => 'Produsent',
-                                       'custom_attribute_12' => 'Leverandør',
-                                       'custom_attribute_13' => 'Ansvar',
-                                       'custom_attribute_14' => 'Antall 
dokumenter',
-                                       'custom_attribute_15' => 'Bygning',
-                                       'custom_attribute_16' => 
'Komponentløpenr',
-                                       'custom_attribute_17' => 
'Leverandør/Organisjonsnr',
-                                       'custom_attribute_18' => 
'Produsent/Organisjonsnr',
-                                       'custom_attribute_19' => 'Prosjekt',
-                                       'custom_attribute_20' => 'Status',
-                                       'custom_attribute_21' => 'Systemløpenr',
-                                       'custom_attribute_22' => 'TFM Type',
-                                       'custom_attribute_23' => 'Typeunikt'
-                               );
-                               
-                               $template = explode("_", $template_id);
-                               
-                               $attributes = 
$this->custom->find($this->type_app[$this->type], 
".{$this->type}.{$template[0]}.{$template[1]}", 0, '', 'ASC', 'attrib_sort', 
true, true);
+                               $options = array('no', 'yes');
+                       }
 
-                               foreach ($attributes as $attribute)
+                       $html = <<<HTML
+                       <select name="$name" id="$id" $attribs>
+
+HTML;
+
+                       $check = array();
+
+                       if (!is_array($selected))
+                       {
+                               $check[$selected] = true;       
+                       }
+                       else
+                       {
+                               foreach ($selected as $sel)
                                {
-                                       $_options[$attribute['input_text']] = 
$attribute['input_text'];
+                                       $check[$sel] = true;
                                }
+                       }
 
-                               phpgw::import_class('phpgwapi.sbox');
+                       foreach ( $options as $value => $option )
+                       {
+                               $check2 = isset( $check[$value] ) ? ' selected' 
: '';
+                               $option = $no_lang ? $option : lang($option);
 
-                               for ($j = 0; $j < $highestColumnIndex; $j++)
-                               {
-                                       $_column = 
$this->getexcelcolumnname($j);
-                                       $_value = 
$objPHPExcel->getActiveSheet()->getCellByColumnAndRow($j, 
$start_line)->getCalculatedValue();
-                                       $selected = isset($columns[$_column]) 
&& $columns[$_column] ? $columns[$_column] : '';
+                               $html .= <<<HTML
+                                       <option 
value="{$value}"{$check2}>{$option}</option>
 
-                                       $_listbox = 
phpgwapi_sbox::getArrayItem("columns[{$_column}]", $selected, $_options, true);
-                                       $html_table .= "<tr><td>[{$_column}] 
{$_value}</td><td>{$_listbox}</td><tr>";
-                               }
-                               
-                               $html_table .= '</table>';
-                               
-                               return $html_table;
+HTML;
                        }
-                       
+                       $html .= <<<HTML
+                       </select>
+
+HTML;
+                       return $html;
                }
                
-               
                public function handle_import_files()
                {
                        require_once PHPGW_SERVER_ROOT . 
"/property/inc/import/UploadHandler.php";
@@ -355,162 +323,149 @@
                
                public function import_components()
                {
-                       $get_identificator = false;
-
                        $location_code = phpgw::get_var('location_code');
+                       $id = phpgw::get_var('location_item_id');
+                       $template_id = phpgw::get_var('template_id');
                        
-                       $entity_categories_in_xml = array();
-
-                       $import_components = new import_components();
-                       $entity_categories  = 
$import_components->get_entity_categories();
-
-                       $exceldata = 
$this->getexceldata($_FILES['file']['tmp_name'], true);
-
-                       foreach ($exceldata as $row) 
+                       $step = phpgw::get_var('step', 'int', 'REQUEST');
+                       $sheet_id = phpgw::get_var('sheet_id', 'int', 
'REQUEST');
+                       $start_line = phpgw::get_var('start_line', 'int', 
'REQUEST');
+                       $columns = phpgw::get_var('columns');
+                       $columns = $columns && is_array($columns) ? $columns : 
array();
+                                       
+                       $message = array();
+                       
+                       phpgw::import_class('phpgwapi.phpexcel');
+                       
+                       if (empty($id))
                        {
-                               if (!$this->valid_row_component($row))
-                               {
-                                       continue;
-                               }
+                               return $message['error'][] = array('msg' => 
'location code is empty');
+                       }
+                               
+                       if ($step == 1 && isset($_FILES['file']['tmp_name']))
+                       {
+                               $file = $_FILES['file']['tmp_name'];
+                               $cached_file = "{$file}_temporary_import_file";
 
-                               if (array_key_exists((string)$row[0], 
$entity_categories))
-                               {                                               
-                                       $cat_id = 
$entity_categories[$row[0]]['id'];
-                                       $entity_id = 
$entity_categories[$row[0]]['entity_id'];                                       
   
-                               } 
-                               else {
-                                       $buildingpart_out_table[$row[0]] = 
$row[0].' - '.$row[2];
-                                       $cat_id = '';
-                                       $entity_id = '';
-                               }
+                               file_put_contents($cached_file, 
file_get_contents($file));
+                               phpgwapi_cache::session_set('property', 
'components_import_file', $cached_file);
+                               
+                               $objPHPExcel = 
PHPExcel_IOFactory::load($cached_file);
+                               $AllSheets = $objPHPExcel->getSheetNames();
 
-                               if (!empty($row[1]))
+                               $sheets = array();
+                               if ($AllSheets)
                                {
-                                       
$entity_categories_in_xml[$row[0]]['cat_id'] = $cat_id;
-                                       
$entity_categories_in_xml[$row[0]]['entity_id'] = $entity_id;
-                                       
$entity_categories_in_xml[$row[0]]['components'][] = array(
-                                               array('name' => 'benevnelse', 
'value' => trim($row[1])),
-                                               array('name' => 'beskrivelse', 
'value' => trim($row[3]))
-                                       );                                      
                
-                               }                               
+                                       foreach ($AllSheets as $key => $sheet)
+                                       {
+                                               $sheets[] = array
+                                                       (
+                                                       'id' => ($key + 1),
+                                                       'name' => $sheet
+                                               );
+                                       }
+                               }       
+                               
+                               return $sheets;
                        }
-       //print_r($buildingpart_out_table); die;
-                       if (count($buildingpart_out_table))
+                                               
+                       if ($step > 1) 
                        {
-                               ksort($buildingpart_out_table);
-                               $buildingpart_processed = 
$import_components->add_entity_categories($buildingpart_out_table);
+                               $cached_file = 
phpgwapi_cache::session_get('property', 'components_import_file');
                                
-                               if (count($buildingpart_processed['not_added']))
+                               $objPHPExcel = 
PHPExcel_IOFactory::load($cached_file);
+                               
$objPHPExcel->setActiveSheetIndex((int)($sheet_id - 1));
+                               $rows = 
$objPHPExcel->getActiveSheet()->getHighestDataRow();
+                               $highestColumm = 
$objPHPExcel->getActiveSheet()->getHighestDataColumn();
+                               $highestColumnIndex = 
PHPExcel_Cell::columnIndexFromString($highestColumm);                           
          
+                       }       
+                       
+                       if ($step == 2 && $sheet_id) 
+                       {
+                               $html_table = '<table class="pure-table 
pure-table-bordered">';
+                               $i = 0;
+                               $cols = array();
+                               for ($j = 0; $j < $highestColumnIndex; $j++)
                                {
-                                       
foreach($buildingpart_processed['not_added'] as $k => $v)
-                                       {
-                                               $message['error'][] = 
array('msg' => "parent {$k} not added");  
-                                       }
-                                       return $this->jquery_results($message);
+                                       $cols[] = $this->getexcelcolumnname($j);
                                }
-                               
-                               if (count($buildingpart_processed['added']))
+
+                               $html_table .= "<thead><tr><th align = 
'center'>" . lang('select') . "</th><th align = 'center'>" . lang('row') . 
"</th><th align='center'>" . implode("</th><th align='center'>", $cols) . 
'</th></tr></thead>';
+                               foreach 
($objPHPExcel->getActiveSheet()->getRowIterator() as $row)
                                {
-                                       
foreach($buildingpart_processed['added'] as $k => $v)
+                                       if ($i > 20)
                                        {
-                                               
$entity_categories_in_xml[$k]['cat_id'] = $v['id'];
-                                               
$entity_categories_in_xml[$k]['entity_id'] = $v['entity_id'];                   
+                                               break;
                                        }
-                               } 
-                       }
-                       
+                                       
+                                       $i++;
+                                       $row_key = $i;
 
+                                       $_radio = "<input type =\"radio\" 
name=\"start_line\" value=\"{$row_key}\">";
 
-                       $message = 
$import_components->add_bim_item($entity_categories_in_xml, $location_code);
-                       
-                       return $this->jquery_results($message);
-               }
-               
-/*
-               public function import_components()
-               {
-                       $get_identificator = false;
+                                       $cellIterator = $row->getCellIterator();
+                                       
$cellIterator->setIterateOnlyExistingCells(false);
 
-                       $location_code = phpgw::get_var('location_code');
-                       
-                       $entity_categories_in_xml = array();
-
-                       $result = 
$this->getxmldata($_FILES['file']['tmp_name'], $get_identificator);
-
-                       $postnrdelkode = 
$result['Prosjekter']['ProsjektNS']['Postnrplan']['PostnrdelKoder']['PostnrdelKode'];
-                       $entities_name = array();
-                       foreach ($postnrdelkode as $items) 
-                       {
-                               if 
($items['PostnrdelKoder']['PostnrdelKode']['Kode'])
-                               {
-                                               
$entities_name[$items['PostnrdelKoder']['PostnrdelKode']['Kode']] = array(
-                                                       'name' => 
$items['PostnrdelKoder']['PostnrdelKode']['Kode'].' - 
'.$items['PostnrdelKoder']['PostnrdelKode']['Navn']
-                                               );                              
                        
-                               }
-                               else {
-                                       foreach 
($items['PostnrdelKoder']['PostnrdelKode'] as $item) 
+                                       $row_values = array();
+                                       foreach ($cellIterator as $cell)
                                        {
-                                               $entities_name[$item['Kode']] = 
array('name' => $item['Kode'].' - '.$item['Navn']);
+                                               if (!is_null($cell))
+                                               {
+                                                       $row_values[] = 
$cell->getCalculatedValue();
+                                               }
                                        }
+                                       $html_table .= 
"<tr><td>{$_radio}</td><td>{$row_key}</td><td>" . implode('</td><td>', 
$row_values) . '</td></tr>';
                                }
+                               $html_table .= '</table>';
+                               
+                               return $html_table;
                        }
-
-                       $posts = 
$result['Prosjekter']['ProsjektNS']['Prosjektdata']['Post'];
-                       foreach ($posts as $post) 
+                       
+                       if ($step == 3 && $start_line) 
                        {
-                               $buildingpart = 
$post['Postnrdeler']['Postnrdel'][1]['Kode'];
-                               
$entity_categories_in_xml[$buildingpart]['name'] = 
$entities_name[$buildingpart]['name'];
-                               
$entity_categories_in_xml[$buildingpart]['components'][] = array(
-                                       array('name' => 'benevnelse', 'value' 
=> trim($post['Egenskaper']['Egenskap']['Verdi'])),
-                                       array('name' => 'beskrivelse', 'value' 
=> trim($post['Tekst']['Uformatert']))
+                               $html_table = '<table class="pure-table 
pure-table-bordered">';
+                               
+                               $_options = array
+                               (
+                                       '' => ' ... ',
+                                       'new_column' => 'New column',
+                                       'building_part' => 'Building part'
                                );
-                       }
+                               
+                               $template = explode("_", $template_id);
+                               
+                               $attributes = 
$this->custom->find($this->type_app[$this->type], 
".{$this->type}.{$template[0]}.{$template[1]}", 0, '', 'ASC', 'attrib_sort', 
true, true);
 
-                       $import_components = new import_components();
-                       $entity_categories  = 
$import_components->get_entity_categories();
-
-                       $buildingpart_out_table = array();
-                       foreach ($entity_categories_in_xml as $k => $v) 
-                       {
-                               if (!array_key_exists((string)$k, 
$entity_categories))
+                               foreach ($attributes as $attribute)
                                {
-                                       $buildingpart_parent = substr($k, 0, 
strlen($k) -1);
-                                       $buildingpart_out_table[$k] = 
array('parent' => $entity_categories[$buildingpart_parent], 'name' => 
$v['name']);
-                               } else {
-                                       $entity_categories_in_xml[$k]['cat_id'] 
= $entity_categories[$k]['id'];
-                                       
$entity_categories_in_xml[$k]['entity_id'] = 
$entity_categories[$k]['entity_id'];
+                                       $_options[$attribute['input_text']] = 
$attribute['input_text'];
                                }
-                       }
-
-                       if (count($buildingpart_out_table))
-                       {
-                               $buildingpart_processed = 
$import_components->add_entity_categories($buildingpart_out_table);
                                
-                               if (count($buildingpart_processed['not_added']))
+                               $data_types = 
$this->bocommon->select_datatype();
+                               foreach($data_types as $row) 
                                {
-                                       
foreach($buildingpart_processed['not_added'] as $k => $v)
-                                       {
-                                               $message['error'][] = 
array('msg' => "parent {$k} not added");  
-                                       }
-                                       return $this->jquery_results($message);
+                                       $_options_data_type[$row['id']] = 
$row['name'];
                                }
                                
-                               if (count($buildingpart_processed['added']))
+
+                               phpgw::import_class('phpgwapi.sbox');
+
+                               for ($j = 0; $j < $highestColumnIndex; $j++)
                                {
-                                       
foreach($buildingpart_processed['added'] as $k => $v)
-                                       {
-                                               
$entity_categories_in_xml[$k]['cat_id'] = $v['id'];
-                                               
$entity_categories_in_xml[$k]['entity_id'] = $v['entity_id'];                   
-                                       }
-                               } 
-                       }
+                                       $_column = 
$this->getexcelcolumnname($j);
+                                       $_value = 
$objPHPExcel->getActiveSheet()->getCellByColumnAndRow($j, 
$start_line)->getCalculatedValue();
+                                       $selected = isset($columns[$_column]) 
&& $columns[$_column] ? $columns[$_column] : '';
 
-                       $message = 
$import_components->add_bim_item($entity_categories_in_xml, $location_code);
-                       
-                       return $this->jquery_results($message);
+                                       $_listbox = 
$this->getArrayItem("column_{$_column}", "columns[{$_column}]", $selected, 
$_options, true, "onchange=\"enabledAtributes('{$_column}')\"");
+                                       $_listTypes = 
$this->getArrayItem("data_type_{$_column}", "data_types[{$_column}]", 
$selected, $_options_data_type, true, 'disabled');
+                                       $html_table .= "<tr><td>[{$_column}] 
{$_value}</td><td>{$_listbox}</td><td><input type='text' id='name_{$_column}' 
name='names[{$_column}]' disabled></input></td><td>{$_listTypes}</td></tr>";
+                               }
+                               
+                               $html_table .= '</table>';
+                               
+                               return $html_table;
+                       }
                }
-*/
-
                /**
                 * Prepare UI
                 * @return void
@@ -666,6 +621,12 @@
                        return $categories;
                }
                
+               public function get_data_type()
+               {
+                       $values = $this->bocommon->select_datatype();
+                       return $values;
+               }
+               
                public function get_part_of_town()
                {
                        $district_id = phpgw::get_var('district_id', 'int');




reply via email to

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