Skip to content

Commit

Permalink
Remove references to PHPExcel
Browse files Browse the repository at this point in the history
Implies that import/export from/to Excel is no longer possible. Actually only the export was used in database_tooltips.php., resulting in unrecoverable errors in the Excel code. The interactive option to modify the tips is OK, so there is no need for the Excel route
  • Loading branch information
fho4abcd committed Jun 28, 2022
1 parent 6cdf36c commit 87fc654
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 114 deletions.
32 changes: 2 additions & 30 deletions www/htdocs/central/barcode/bcl_labelshow_result.php
Expand Up @@ -3,7 +3,8 @@
20220306 fho4abcd div-helper, added informational and error messages, moved functions to end of file
20220309 fho4abcd No "em" this is a relative unit, add link to barcode font script,add option border
20220310 fho4abcd Better check for nothing returned.
20220321fho4abcd adapt to new includes, renamed to bcl_labelshow_result
20220321 fho4abcd adapt to new includes, renamed to bcl_labelshow_result
20220628 fho4abcd removed unused output options (e.g Excel)
*/
set_time_limit(0);
//error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING);
Expand Down Expand Up @@ -39,35 +40,6 @@
#echo ' xmlns:w="urn:schemas-microsoft-com:office:word"' . "\n";
#echo ' xmlns="http://www.w3.org/TR/REC-html40">' . "\n";
break;
case "xls":
include('../Classes/PHPExcel.php');
$objPHPExcel = new PHPExcel();
$sheetIndex=-1;
break;
case "calc":
$filename="barcode_".$base.".ods";
header('Content-Type: application/vnd.oasis.opendocument.spreadsheet; charset=windows-1252');
header("Content-Disposition: inline; filename=\"$filename\"");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0,pre-check=0");
header("Pragma: public");
break;
case "odt":
$filename="barcode_".$base.".odt";
header('Content-Type: application/vnd.oasis.opendocument.text; charset=windows-1252');
header("Content-Disposition: attachment; filename=\"$filename\"");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0,pre-check=0");
header("Pragma: public");
break;
case "csv":
$filename="barcode_".$base.".csv";
header('Content-Type: text/plain; charset=windows-1252');
header("Content-Disposition: attachment; filename=\"$filename\"");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0,pre-check=0");
header("Pragma: public");
break;
case "txt":
$filename="barcode_".$base.".txt";
header('Content-Type: text/plain; charset=windows-1252');
Expand Down
86 changes: 2 additions & 84 deletions www/htdocs/central/dbadmin/database_tooltips.php
@@ -1,6 +1,7 @@
<?php
/*
20220203 fho4abcd back button, div-helper
20220628 fho4abcd Remove import/export with excel
*/
session_start();
if (!isset($_SESSION["permiso"])){
Expand Down Expand Up @@ -55,10 +56,6 @@

}
}
if (isset($arrHttp["Opcion"]) and $arrHttp["Opcion"]=="xls"){
EnviarAxls($fdt,$tooltip,$base);
die;
}


include("../common/header.php");
Expand Down Expand Up @@ -127,22 +124,7 @@ function VerificarUpload(){
</form>
<?php
die;
}else{
$nombre = $_FILES['archivo']['name'];
$nombre_tmp = $_FILES['archivo']['tmp_name'];
$file=$db_path."wrk/" . $nombre;
if (file_exists($file)){
copy($file,$file."bak");
}
move_uploaded_file($nombre_tmp,$db_path."wrk/" . $nombre);
$tooltip=ImportarHoja($file,$tooltip);
}
}
if (!isset($arrHttp["Opcion"]) or isset($arrHttp["Opcion"]) and $arrHttp["Opcion"]!="importado"){
?>
<a href=database_tooltips.php?Opcion=xls&base=<?php echo $base?>><?php echo $msgstr["sendto"]." ".$msgstr["wks"]?></a>
&nbsp; &nbsp;
<?php
}
}
?>
<a href=database_tooltips.php?Opcion=Importar&base=<?php echo $base?>><?php echo $msgstr["import_ods"]?></a><br>
Expand All @@ -162,67 +144,3 @@ function VerificarUpload(){
</div>
<?php
include("../common/footer.php");

//============================== functions =======================
function ImportarHoja($file,$fdt){

/** PHPExcel_IOFactory */
require_once '../Classes/PHPExcel/IOFactory.php';

$objReader = PHPExcel_IOFactory::createReader('OOCalc');
$objPHPExcel = $objReader->load("$file");
$objWorksheet = $objPHPExcel->setActiveSheetIndex(0);
foreach ($objWorksheet->getRowIterator() as $row) {
$rowIndex = $row->getRowIndex ();
if ($rowIndex==1) continue;
$cellIterator = $row->getCellIterator();
$cellIterator->setIterateOnlyExistingCells(false);
$id=utf8_decode($objWorksheet->getCell('A' . $rowIndex));
$value=utf8_decode($objWorksheet->getCell('B' . $rowIndex));
if ($value=="") continue;
$fdt[$id]=$value;
}
return $fdt;
}

function EnviarAxls($fdt,$tooltip,$base){
require_once ('../Classes/PHPExcel.php');
// Create new PHPExcel object
$objPHPExcel = new PHPExcel();
$objPHPExcel->setActiveSheetIndex(0);

$objPHPExcel->getActiveSheet()->setCellValue('A1', "Campo");
$objPHPExcel->getActiveSheet()->setCellValue('B1', "Ayuda");

$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setAutoSize(true);
$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setAutoSize(true);
$objPHPExcel->getActiveSheet()->getStyle('D1')->getAlignment()->setWrapText(true);

$ix=1;
foreach($fdt as $key=>$value) {
$ix=$ix+1;
if (!isset($tooltip[$key])) {
$tooltip[$key]="";
}
$objPHPExcel->getActiveSheet()->setCellValue('A'.$ix, $key);
$objPHPExcel->getActiveSheet()->setCellValue('B'.$ix,utf8_encode($tooltip[$key]));
$objPHPExcel->getActiveSheet()->getStyle('B'.$ix)->getAlignment()->setWrapText(true);
$objPHPExcel->getActiveSheet()->getStyle('A'.$ix)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_TOP);
$objPHPExcel->getActiveSheet()->getStyle('B'.$ix)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_TOP);
}

// Rename sheet
$title="tooltips_".$base.".xls";
$objPHPExcel->getActiveSheet()->setTitle('tooltips');
// Set active sheet index to the first sheet, so Excel opens this as the first sheet
// Redirect output to a client’s web browser (Excel2007)
header('Content-Type: application/vnd.ms-excel');

header('Content-Disposition: attachment;filename="'.$title.'"');
header('Content-Charset: iso-8859-1');
header('Cache-Control: max-age=0');

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');
exit;
}

0 comments on commit 87fc654

Please sign in to comment.