Merged in bugfix/HOR-3485-A (pull request #5878)

HOR-3485

Approved-by: Paula Quispe <paula.quispe@processmaker.com>
Approved-by: Julio Cesar Laura Avendaño <contact@julio-laura.com>
This commit is contained in:
jonathan Quispe
2017-08-10 19:10:25 +00:00
committed by Julio Cesar Laura Avendaño

View File

@@ -451,15 +451,17 @@ class pmTablesProxy extends HttpProxyController
$this->message = $this->success ? G::loadTranslation( 'ID_DELETED_SUCCESSFULLY' ) : G::loadTranslation( 'ID_DELETE_FAILED' );
}
/**
* Import pmTable from CSV file
* @param $httpData
*/
public function importCSV($httpData)
{
$filter = new InputFilter();
$countRow = 250;
$tmpfilename = $_FILES['form']['tmp_name']['CSV_FILE'];
//$tmpfilename = $filter->xssFilterHard($tmpfilename, 'path');
if (preg_match('/[\x00-\x08\x0b-\x0c\x0e\x1f]/', file_get_contents($tmpfilename)) === 0) {
$filename = $_FILES['form']['name']['CSV_FILE'];
//$filename = $filter->xssFilterHard($filename, 'path');
if ($oFile = fopen($filter->xssFilterHard($tmpfilename, 'path'), 'r')) {
require_once 'classes/model/AdditionalTables.php';
$oAdditionalTables = new AdditionalTables();
@@ -470,7 +472,7 @@ class pmTablesProxy extends HttpProxyController
$insert = 'REPLACE INTO ' . $aAdditionalTables['ADD_TAB_NAME'] . ' (';
$query = '';
$swHead = false;
while (($aAux = fgetcsv( $oFile, 4096, $_POST['form']['CSV_DELIMITER'] )) !== false) {
while (($aAux = fgetcsv($oFile, 4096, $_POST['form']['CSV_DELIMITER'], '"', '"')) !== false) {
if (!is_null($aAux[0])) {
if (count($aAdditionalTables['FIELDS']) > count($aAux)) {
$this->success = false;
@@ -495,13 +497,11 @@ class pmTablesProxy extends HttpProxyController
$j = 0;
foreach ($aAdditionalTables['FIELDS'] as $aField) {
$conData++;
if (array_key_exists($j, $aAux)) {
$temp = '"' . addslashes(stripslashes(G::is_utf8($aAux[$j]) ? $aAux[$j] : utf8_encode($aAux[$j]))) . '"';
$temp = '"' . addslashes(G::is_utf8($aAux[$j]) ? $aAux[$j] : utf8_encode($aAux[$j])) . '"';
} else {
$temp = '""';
}
if ($temp == '') {
switch ($aField['FLD_TYPE']) {
case 'DATE':
@@ -637,9 +637,9 @@ class pmTablesProxy extends HttpProxyController
}
/**
* export a pm tables record to CSV
*
* @param string $httpData->id
* Export pmTable to CSV format
* @param $httpData
* @return StdClass
*/
public function exportCSV($httpData)
{
@@ -665,38 +665,18 @@ class pmTablesProxy extends HttpProxyController
$filenameOnly = strtolower($aAdditionalTables['ADD_TAB_NAME'] . "_" . date("Y-m-d") . '_' . date("Hi") . ".csv");
$filename = $PUBLIC_ROOT_PATH . $filenameOnly;
$fp = fopen($filename, "wb");
$swColumns = true;
foreach ($rows as $keyCol => $cols) {
$SDATA = "";
$header = "";
$cnt = $cntC = count( $cols );
foreach ($cols as $key => $val) {
if ($swColumns) {
$header .= $key;
if (-- $cntC > 0) {
$header .= $sDelimiter;
} else {
$header .= "\n";
$bytesSaved += fwrite( $fp, $header );
fputcsv($fp, array_keys($cols), $sDelimiter, '"', "\\");
$swColumns = false;
}
}
$SDATA .= addslashes($val);
if (-- $cnt > 0) {
$SDATA .= $sDelimiter;
}
}
$SDATA .= "\n";
$bytesSaved += fwrite( $fp, $SDATA );
fputcsv($fp, $cols, $sDelimiter, '"');
}
fclose($fp);
// $filenameLink = "pmTables/streamExported?f=$filenameOnly";
$filenameLink = "streamExported?f=$filenameOnly";
$size = round( ($bytesSaved / 1024), 2 ) . " Kb";
$filename = $filenameOnly;
$size = filesize($filename);
$link = $filenameLink;
$result->success = true;