Skip to content

Commit

Permalink
#8 [Index] add: uploadZip action
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-eoxia committed Dec 2, 2022
1 parent 8f79d71 commit d4d35e5
Showing 1 changed file with 87 additions and 3 deletions.
90 changes: 87 additions & 3 deletions doliocrindex.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
}

// Libraries
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php';

// Global variables definitions
Expand All @@ -75,6 +76,58 @@
* Actions
*/

if (GETPOST('dataMigrationImportGlobalDolibarr', 'alpha') && ! empty($conf->global->MAIN_UPLOAD_DOC)) {
// Submit file
if ( ! empty($_FILES)) {
if ( ! preg_match('/FDS.zip/', $_FILES['dataMigrationImportGlobalDolibarrfile']['name'][0]) || $_FILES['dataMigrationImportGlobalDolibarrfile']['size'][0] < 1) {
setEventMessages($langs->trans('ErrorFileNotWellFormattedZIP'), null, 'errors');
} else {
if (is_array($_FILES['dataMigrationImportGlobalDolibarrfile']['tmp_name'])) $userfiles = $_FILES['dataMigrationImportGlobalDolibarrfile']['tmp_name'];
else $userfiles = array($_FILES['dataMigrationImportGlobalDolibarrfile']['tmp_name']);

foreach ($userfiles as $key => $userfile) {
if (empty($_FILES['dataMigrationImportGlobalDolibarrfile']['tmp_name'][$key])) {
$error++;
if ($_FILES['dataMigrationImportGlobalDolibarrfile']['error'][$key] == 1 || $_FILES['dataMigrationImportGlobalDolibarrfile']['error'][$key] == 2) {
setEventMessages($langs->trans('ErrorFileSizeTooLarge'), null, 'errors');
} else {
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("File")), null, 'errors');
}
}
}

if ( ! $error) {
$filedir = $upload_dir . '/temp/';
if ( ! empty($filedir)) {
$result = dol_add_file_process($filedir, 0, 1, 'dataMigrationImportGlobalDolibarrfile', '', null, '', 0, null);
}
}

if ($result > 0) {
$zip = new ZipArchive;
if ($zip->open($filedir . $_FILES['dataMigrationImportGlobalDolibarrfile']['name'][0]) === TRUE) {
$zip->extractTo($filedir);
$zip->close();
}
}

$fileImportGlobals = dol_dir_list($filedir, "files", 0, 'pdf', '', '', '', 1);
echo '<pre>'; print_r( $fileImportGlobals ); echo '</pre>'; exit;


// $json = file_get_contents($filedir . $filename);
// $digiriskExportArray = json_decode($json, true);
}

// $fileImportGlobals = dol_dir_list($filedir, "files", 0, '', '', '', '', 1);
// if ( ! empty($fileImportGlobals)) {
// foreach ($fileImportGlobals as $fileImportGlobal) {
// unlink($fileImportGlobal['fullname']);
// }
// }
}
}

if ($action == 'convertTxtToCSV') {
$pdffilename = GETPOST('pdffilename');
$txtfilename = GETPOST('txtfilename');
Expand Down Expand Up @@ -152,11 +205,42 @@

<textarea id='inputText'></textarea>

<?php
print load_fiche_titre($langs->trans("UploadFiles"), '', '');

print '<form class="data-migration-from" name="DataMigration" id="DataMigration" action="' . $_SERVER["PHP_SELF"] . '" enctype="multipart/form-data" method="POST">';
print '<input type="hidden" name="token" value="' . newToken() . '">';
print '<input type="hidden" name="action" value="">';

print '<table class="noborder centpercent">';
print '<tr class="liste_titre">';
print '<td>' . $langs->trans("Name") . '</td>';
print '<td>' . $langs->trans("Description") . '</td>';
print '<td class="center">' . $langs->trans("Action") . '</td>';
print '</tr>';

// Import data from Dolibarr
print '<tr class="oddeven"><td>';
print $langs->trans('DataMigrationImportGlobal');
print "</td><td>";
print $langs->trans('DataMigrationImportGlobalDolibarrDescription');
print '</td>';

print '<td class="center data-migration-import-global-dolibarr">';
print '<input class="flat" type="file" name="dataMigrationImportGlobalDolibarrfile[]" id="data-migration-import-global-dolibarr" />';
print '<input type="submit" class="button reposition data-migration-submit" name="dataMigrationImportGlobalDolibarr" value="' . $langs->trans("Upload") . '">';
print '</td>';
print '</tr>';
print '</table>';
print '</form>';

?>

<!--<script src='https://unpkg.com/[email protected]/dist/tesseract.min.js'></script>-->
<!--<script src="https://cdn.jsdelivr.net/npm/[email protected]/build/pdf.min.js"></script>-->
<script src="<?php echo DOL_URL_ROOT . '/custom/doliocr/js/tesseract/tesseract.min.js'; ?>"></script>
<script src="<?php echo DOL_URL_ROOT . '/custom/doliocr/js/pdf/pdf.min.js'; ?>"></script>
<script src="<?php echo DOL_URL_ROOT . '/custom/doliocr/js/doliocr.js'; ?>"></script>
<!--<script src="--><?php //echo DOL_URL_ROOT . '/custom/doliocr/js/tesseract/tesseract.min.js'; ?><!--"></script>-->
<!--<script src="--><?php //echo DOL_URL_ROOT . '/custom/doliocr/js/pdf/pdf.min.js'; ?><!--"></script>-->
<!--<script src="--><?php //echo DOL_URL_ROOT . '/custom/doliocr/js/doliocr.js'; ?><!--"></script>-->

<?php
// End of page
Expand Down

0 comments on commit d4d35e5

Please sign in to comment.