fmsystem-commits
[Top][All Lists]
Advanced

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

[Fmsystem-commits] [15514]


From: nelson . guerra
Subject: [Fmsystem-commits] [15514]
Date: Fri, 26 Aug 2016 01:28:25 +0000 (UTC)

Revision: 15514
          http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=15514
Author:   nelson224
Date:     2016-08-26 01:28:25 +0000 (Fri, 26 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-26 01:28:11 UTC (rev 15513)
+++ branches/dev-syncromind-2/property/inc/class.uiimport_components.inc.php    
2016-08-26 01:28:25 UTC (rev 15514)
@@ -75,88 +75,119 @@
                        return true;
                }
                
+               private function getexcelcolumnname( $index )
+               {
+                       //Get the quotient : if the index superior to base 26 
max ?
+                       $quotient = $index / 26;
+                       if ($quotient >= 1)
+                       {
+                               //If yes, get top level column + the current 
column code
+                               return $this->getexcelcolumnname($quotient - 1) 
. chr(($index % 26) + 65);
+                       }
+                       else
+                       {
+                               //If no just return the current column code
+                               return chr(65 + $index);
+                       }
+               }
+               
                public function import_component_files()
                {
                        $location_code = phpgw::get_var('location_code');
                        $id = phpgw::get_var('location_item_id');
                        $message = array();
                        
+                       phpgw::import_class('phpgwapi.phpexcel');
+                       
                        if (empty($id))
                        {
                                return $message['error'][] = array('msg' => 
'location code is empty');
                        }
                                
-                       $exceldata = 
$this->getexceldata($_FILES['file']['tmp_name'], true);
-                       $relations = array();
-                       
-                       foreach ($exceldata as $row) 
+                       $sheet_id = phpgw::get_var('sheet_id', 'int', 
'REQUEST');
+
+               
+                       if (isset($_FILES['file']['tmp_name']))
                        {
-                               if (!$this->valid_row($row))
-                               {
-                                       continue;
-                               }
-                               
-                               $relations[$row[0]][] = $row[(count($row)-1)];
+                                       
+                               $file = $_FILES['file']['tmp_name'];
+                               $cached_file = "{$file}_temporary_import_file";
+                               // save a copy to survive multiple steps
+                               file_put_contents($cached_file, 
file_get_contents($file));
+                               phpgwapi_cache::session_set('property', 
'components_import_file', $cached_file);
                        }
                        
-                       $this->db->transaction_begin();
+                       $objPHPExcel = PHPExcel_IOFactory::load($cached_file);
+                       $AllSheets = $objPHPExcel->getSheetNames();
+
+                       $sheets = array();
+                       if ($AllSheets)
+                       {
+                               foreach ($AllSheets as $key => $sheet)
+                                       $sheets[] = array
+                                               (
+                                               'id' => ($key + 1),
+                                               'name' => $sheet,
+                                               'selected' => $sheet_id == 
($key + 1)
+                                       );
+                       }                                       
                        
-                       try
+                       if ($sheet_id) 
                        {
-                               $this->db->Exception_On_Error = true;
+                               $cached_file = 
phpgwapi_cache::session_get('property', 'components_import_file');
                                
-                               foreach ($relations as $k => $files) 
+                               $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);             
+       
+                               $html_table = '<table class="pure-table 
pure-table-bordered">';
+                               
+                               $cols = array();
+                               for ($j = 0; $j < $highestColumnIndex; $j++)
                                {
-                                       if (empty($k))
+                                       $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)
                                        {
-                                               $component = array('id' => $id, 
'location_id' => $GLOBALS['phpgw']->locations->get_id('property', 
'.location.'.count(explode('-', $location_code))));
+                                               break;
                                        }
-                                       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;
+                                       $_checked = '';
+                                       if ($start_line == $row_key)
+                                       {
+                                               $_checked = 'checked="checked"';
                                        }
-                                       
-                                       foreach($files as $path_file)
+
+                                       $_radio = "<input id=\"start_line\" 
type =\"radio\" {$_checked} name=\"start_line\" value=\"{$row_key}\">";
+
+                                       $cellIterator = $row->getCellIterator();
+                                       
$cellIterator->setIterateOnlyExistingCells(false);
+
+                                       $row_values = array();
+                                       foreach ($cellIterator as $cell)
                                        {
-                                               $parts = explode("\\", 
$path_file);
-                                               $file = $parts[count($parts)-1];
-                                               if 
(!is_file($this->tmp_upload_dir.$file))
+                                               if (!is_null($cell))
                                                {
-                                                       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}");
+                                                       $row_values[] = 
$cell->getCalculatedValue();
                                                }
                                        }
+                                       $html_table .= 
"<tr><td>{$_radio}</td><td>{$row_key}</td><td>" . implode('</td><td>', 
$row_values) . '</td></tr>';
                                }
-                               $this->db->Exception_On_Error = false;
+                               $html_table .= '</table>';
+                               
+                               return $html_table;
                        }
-                       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');
                        
-                       return $this->jquery_results($message);
+                       $result_data = array('results' => $sheets);
+                       return $this->jquery_results($result_data);
                }
                
                




reply via email to

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