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