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,30 +451,32 @@ class pmTablesProxy extends HttpProxyController
|
||||
$this->message = $this->success ? G::loadTranslation( 'ID_DELETED_SUCCESSFULLY' ) : G::loadTranslation( 'ID_DELETE_FAILED' );
|
||||
}
|
||||
|
||||
public function importCSV ($httpData)
|
||||
/**
|
||||
* 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) {
|
||||
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' )) {
|
||||
if ($oFile = fopen($filter->xssFilterHard($tmpfilename, 'path'), 'r')) {
|
||||
require_once 'classes/model/AdditionalTables.php';
|
||||
$oAdditionalTables = new AdditionalTables();
|
||||
$aAdditionalTables = $oAdditionalTables->load( $_POST['form']['ADD_TAB_UID'], true );
|
||||
$aAdditionalTables = $oAdditionalTables->load($_POST['form']['ADD_TAB_UID'], true);
|
||||
$sErrorMessages = '';
|
||||
$i = 1;
|
||||
$conData = 0;
|
||||
$insert = 'REPLACE INTO ' . $aAdditionalTables['ADD_TAB_NAME'] . ' (';
|
||||
$query = '';
|
||||
$swHead = false;
|
||||
while (($aAux = fgetcsv( $oFile, 4096, $_POST['form']['CSV_DELIMITER'] )) !== false) {
|
||||
if (! is_null( $aAux[0] )) {
|
||||
if (count( $aAdditionalTables['FIELDS'] ) > count( $aAux )) {
|
||||
while (($aAux = fgetcsv($oFile, 4096, $_POST['form']['CSV_DELIMITER'], '"', '"')) !== false) {
|
||||
if (!is_null($aAux[0])) {
|
||||
if (count($aAdditionalTables['FIELDS']) > count($aAux)) {
|
||||
$this->success = false;
|
||||
$this->message = G::LoadTranslation( 'INVALID_FILE' );
|
||||
$this->message = G::LoadTranslation('INVALID_FILE');
|
||||
return 0;
|
||||
}
|
||||
if ($i == 1) {
|
||||
@@ -484,7 +486,7 @@ class pmTablesProxy extends HttpProxyController
|
||||
if ($aField['FLD_NAME'] === $aAux[$j]) {
|
||||
$swHead = true;
|
||||
}
|
||||
$j ++;
|
||||
$j++;
|
||||
}
|
||||
$insert = substr($insert, 0, -2);
|
||||
$insert .= ') VALUES ';
|
||||
@@ -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':
|
||||
@@ -510,7 +510,7 @@ class pmTablesProxy extends HttpProxyController
|
||||
break;
|
||||
}
|
||||
}
|
||||
$j ++;
|
||||
$j++;
|
||||
$queryRow .= $temp . ',';
|
||||
}
|
||||
$query .= substr($queryRow, 0, -1) . '),';
|
||||
@@ -522,15 +522,15 @@ class pmTablesProxy extends HttpProxyController
|
||||
$conData = 0;
|
||||
}
|
||||
} catch (Exception $oError) {
|
||||
$sErrorMessages .= G::LoadTranslation( 'ID_ERROR_INSERT_LINE' ) . ': ' . G::LoadTranslation( 'ID_LINE' ) . ' ' . $i . '. ';
|
||||
$sErrorMessages .= G::LoadTranslation('ID_ERROR_INSERT_LINE') . ': ' . G::LoadTranslation('ID_LINE') . ' ' . $i . '. ';
|
||||
}
|
||||
} else {
|
||||
$swHead = false;
|
||||
}
|
||||
$i ++;
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
fclose( $oFile );
|
||||
fclose($oFile);
|
||||
if ($conData > 0) {
|
||||
$query = substr($query, 0, -1);
|
||||
executeQuery($insert . $query . ';', $aAdditionalTables['DBS_UID']);
|
||||
@@ -541,12 +541,12 @@ class pmTablesProxy extends HttpProxyController
|
||||
$this->message = $sErrorMessages;
|
||||
} else {
|
||||
$this->success = true;
|
||||
$this->message = G::loadTranslation( 'ID_FILE_IMPORTED_SUCCESSFULLY', array ($filename
|
||||
) );
|
||||
$this->message = G::loadTranslation('ID_FILE_IMPORTED_SUCCESSFULLY', array($filename
|
||||
));
|
||||
G::auditLog("ImportTable", $filename);
|
||||
}
|
||||
} else {
|
||||
$sMessage = G::LoadTranslation( 'ID_UPLOAD_VALID_CSV_FILE' );
|
||||
$sMessage = G::LoadTranslation('ID_UPLOAD_VALID_CSV_FILE');
|
||||
$this->success = false;
|
||||
$this->message = $sMessage;
|
||||
}
|
||||
@@ -637,11 +637,11 @@ 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)
|
||||
public function exportCSV($httpData)
|
||||
{
|
||||
$result = new StdClass();
|
||||
try {
|
||||
@@ -653,50 +653,30 @@ class pmTablesProxy extends HttpProxyController
|
||||
|
||||
require_once 'classes/model/AdditionalTables.php';
|
||||
$oAdditionalTables = new AdditionalTables();
|
||||
$aAdditionalTables = $oAdditionalTables->load( $_POST['ADD_TAB_UID'], true );
|
||||
$aAdditionalTables = $oAdditionalTables->load($_POST['ADD_TAB_UID'], true);
|
||||
$sErrorMessages = '';
|
||||
$sDelimiter = $_POST['CSV_DELIMITER'];
|
||||
|
||||
$resultData = $oAdditionalTables->getAllData( $_POST['ADD_TAB_UID'], null, null, false );
|
||||
$resultData = $oAdditionalTables->getAllData($_POST['ADD_TAB_UID'], null, null, false);
|
||||
$rows = $resultData['rows'];
|
||||
$count = $resultData['count'];
|
||||
|
||||
$PUBLIC_ROOT_PATH = PATH_DATA . 'sites' . PATH_SEP . SYS_SYS . PATH_SEP . 'public' . PATH_SEP;
|
||||
$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;
|
||||
$fp = fopen( $filename, "wb" );
|
||||
|
||||
$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 );
|
||||
$swColumns = false;
|
||||
}
|
||||
}
|
||||
$SDATA .= addslashes($val);
|
||||
if (-- $cnt > 0) {
|
||||
$SDATA .= $sDelimiter;
|
||||
}
|
||||
if ($swColumns) {
|
||||
fputcsv($fp, array_keys($cols), $sDelimiter, '"', "\\");
|
||||
$swColumns = false;
|
||||
}
|
||||
$SDATA .= "\n";
|
||||
$bytesSaved += fwrite( $fp, $SDATA );
|
||||
fputcsv($fp, $cols, $sDelimiter, '"');
|
||||
}
|
||||
|
||||
fclose( $fp );
|
||||
|
||||
// $filenameLink = "pmTables/streamExported?f=$filenameOnly";
|
||||
fclose($fp);
|
||||
$filenameLink = "streamExported?f=$filenameOnly";
|
||||
$size = round( ($bytesSaved / 1024), 2 ) . " Kb";
|
||||
$filename = $filenameOnly;
|
||||
$size = filesize($filename);
|
||||
$link = $filenameLink;
|
||||
|
||||
$result->success = true;
|
||||
|
||||
Reference in New Issue
Block a user