//File uploaded successfully and matches the given model : switch to the import tab $_SESSION['datainjection']['file_name'] = $_FILES['filename']['name']; $_SESSION['datainjection']['step'] = PluginDatainjectionClientInjection::STEP_PROCESS; //Store model in session for injection $_SESSION['datainjection']['currentmodel'] = serialize($model); $_SESSION['datainjection']['go'] = true; } else { //Got back to the file upload page $_SESSION['datainjection']['step'] = PluginDatainjectionClientInjection::STEP_UPLOAD; } } else { Session::addMessageAfterRedirect(__('The file could not be found', 'datainjection'), true, ERROR, true); } } Html::back(); } else { if (isset($_POST['finish']) || isset($_POST['cancel'])) { PluginDatainjectionSession::removeParams(); Html::redirect(Toolbox::getItemTypeFormURL('PluginDatainjectionClientInjection')); } else { if (isset($_GET['id'])) { // Allow link to a model PluginDatainjectionSession::setParam('models_id', $_GET['id']); } $clientInjection = new PluginDatainjectionClientInjection(); $clientInjection->title(); $clientInjection->showForm(0); } } } Html::footer();
static function exportAsPDF($models_id) { $logresults = self::prepareLogResults($models_id); $model = new self(); $model->getFromDB($models_id); if (!empty($logresults)) { $pdf = new PluginPdfSimplePDF('a4', 'landscape'); $pdf->setHeader(sprintf(__('%1$s (%2$s)'), __('File injection report', 'datainjection') . ' - <b>' . PluginDatainjectionSession::getParam('file_name') . '</b>', $model->getName())); $pdf->newPage(); if (isset($logresults[PluginDatainjectionCommonInjectionLib::SUCCESS])) { $pdf->setColumnsSize(100); $pdf->displayTitle('<b>' . __('Array of successful injections', 'datainjection') . '</b>'); $pdf->setColumnsSize(6, 54, 20, 20); $pdf->setColumnsAlign('center', 'center', 'center', 'center'); $col0 = '<b>' . __('Line', 'datainjection') . '</b>'; $col1 = '<b>' . __('Data Import', 'datainjection') . '</b>'; $col2 = '<b>' . __('Injection type', 'datainjection') . '</b>'; $col3 = '<b>' . __('Object Identifier', 'datainjection') . '</b>'; $pdf->displayTitle($col0, $col1, $col2, $col3); $index = 0; foreach ($logresults[PluginDatainjectionCommonInjectionLib::SUCCESS] as $result) { $pdf->displayLine($result['line'], $result['status_message'], $result['type'], $result['item']); } } if (isset($logresults[PluginDatainjectionCommonInjectionLib::FAILED])) { $pdf->setColumnsSize(100); $pdf->displayTitle('<b>' . __('Array of unsuccessful injections', 'datainjection') . '</b>'); $pdf->setColumnsSize(6, 16, 38, 20, 20); $pdf->setColumnsAlign('center', 'center', 'center', 'center', 'center'); $col0 = '<b>' . __('Line', 'datainjection') . '</b>'; $col1 = '<b>' . __('Data check', 'datainjection') . '</b>'; $col2 = '<b>' . __('Data Import', 'datainjection') . '</b>'; $col3 = '<b>' . __('Injection type', 'datainjection') . '</b>'; $col4 = '<b>' . __('Object Identifier', 'datainjection') . '</b>'; $pdf->displayTitle($col0, $col1, $col2, $col3, $col4); $index = 0; foreach ($logresults[PluginDatainjectionCommonInjectionLib::FAILED] as $result) { $pdf->setColumnsSize(6, 16, 38, 20, 20); $pdf->setColumnsAlign('center', 'center', 'center', 'center', 'center'); $pdf->displayLine($result['line'], $result['check_sumnary'], $result['status_message'], $result['type'], $result['item']); if ($result['check_message']) { $pdf->displayText('<b>' . __('Data check', 'datainjection') . '</b> :', $result['check_message'], 1); } } } $pdf->render(); } }
static function exportErrorsInCSV() { $error_lines = json_decode(PluginDatainjectionSession::getParam('error_lines'), true); self::stripslashes_array($error_lines); if (!empty($error_lines)) { $model = unserialize(PluginDatainjectionSession::getParam('currentmodel')); $file = PLUGIN_DATAINJECTION_UPLOAD_DIR . PluginDatainjectionSession::getParam('file_name'); $mappings = $model->getMappings(); $tmpfile = fopen($file, 'w'); //If headers present if ($model->getBackend()->isHeaderPresent()) { $headers = PluginDatainjectionMapping::getMappingsSortedByRank($model->fields['id']); fputcsv($tmpfile, $headers, $model->getBackend()->getDelimiter()); } //Write lines foreach ($error_lines as $line) { fputcsv($tmpfile, $line, $model->getBackend()->getDelimiter()); } fclose($tmpfile); $name = "Error-" . PluginDatainjectionSession::getParam('file_name'); $name = str_replace(' ', '', $name); header('Content-disposition: attachment; filename=' . $name); header('Content-Type: application/octet-stream'); header('Content-Transfer-Encoding: fichier'); header('Content-Length: ' . filesize($file)); header('Pragma: no-cache'); header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0'); header('Expires: 0'); readfile($file); unlink($file); } }