config import and export
This commit is contained in:
parent
6fc259d718
commit
0a72bc9635
|
@ -4777,6 +4777,7 @@ class htmlResponsiveInputCheckbox extends htmlInputCheckbox {
|
||||||
}
|
}
|
||||||
// label text
|
// label text
|
||||||
$text = new htmlSpan(new htmlOutputText($this->label));
|
$text = new htmlSpan(new htmlOutputText($this->label));
|
||||||
|
$text->setCSSClasses($this->cssClasses);
|
||||||
$text->setOnclick('jQuery(\'#' . $this->name . '\').prop(\'checked\',!jQuery(\'#' . $this->name . '\').prop(\'checked\')); jQuery(\'#' . $this->name . '\').change();');
|
$text->setOnclick('jQuery(\'#' . $this->name . '\').prop(\'checked\',!jQuery(\'#' . $this->name . '\').prop(\'checked\')); jQuery(\'#' . $this->name . '\').change();');
|
||||||
// input field
|
// input field
|
||||||
$fieldGroup = new htmlGroup();
|
$fieldGroup = new htmlGroup();
|
||||||
|
|
|
@ -118,7 +118,7 @@ function getAvailableLogos($serverProfileName) {
|
||||||
* @param \LAM\TYPES\ConfiguredType $sourceType source type
|
* @param \LAM\TYPES\ConfiguredType $sourceType source type
|
||||||
* @param string $sourceStructureName structure name
|
* @param string $sourceStructureName structure name
|
||||||
* @param \LAM\TYPES\ConfiguredType $targetType target type
|
* @param \LAM\TYPES\ConfiguredType $targetType target type
|
||||||
* @throws Exception
|
* @throws LAMException error during copy
|
||||||
*/
|
*/
|
||||||
function copyStructure($sourceType, $sourceStructureName, $targetType) {
|
function copyStructure($sourceType, $sourceStructureName, $targetType) {
|
||||||
if (!isValidPDFStructureName($sourceStructureName)) {
|
if (!isValidPDFStructureName($sourceStructureName)) {
|
||||||
|
@ -427,7 +427,7 @@ class PDFStructureWriter {
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
* @param $serverProfileName server profile name
|
* @param string $serverProfileName server profile name
|
||||||
*/
|
*/
|
||||||
public function __construct($serverProfileName) {
|
public function __construct($serverProfileName) {
|
||||||
$this->serverProfileName = $serverProfileName;
|
$this->serverProfileName = $serverProfileName;
|
||||||
|
@ -439,6 +439,7 @@ class PDFStructureWriter {
|
||||||
* @param string $typeId type ID
|
* @param string $typeId type ID
|
||||||
* @param string $name structure name
|
* @param string $name structure name
|
||||||
* @param PDFStructure $structure structure
|
* @param PDFStructure $structure structure
|
||||||
|
* @throws LAMException error during write
|
||||||
*/
|
*/
|
||||||
public function write($typeId, $name, $structure) {
|
public function write($typeId, $name, $structure) {
|
||||||
$fileName = $this->getFileName($typeId, $name);
|
$fileName = $this->getFileName($typeId, $name);
|
||||||
|
@ -452,6 +453,7 @@ class PDFStructureWriter {
|
||||||
* @param string $typeId type ID
|
* @param string $typeId type ID
|
||||||
* @param string $name structure name
|
* @param string $name structure name
|
||||||
* @return string file name
|
* @return string file name
|
||||||
|
* @throws LAMException file not valid or not writable
|
||||||
*/
|
*/
|
||||||
protected function getFileName($typeId, $name) {
|
protected function getFileName($typeId, $name) {
|
||||||
if (!isValidPDFStructureName($name) || !preg_match('/[a-zA-Z]+/', $typeId)) {
|
if (!isValidPDFStructureName($name) || !preg_match('/[a-zA-Z]+/', $typeId)) {
|
||||||
|
@ -510,6 +512,7 @@ class PDFStructureWriter {
|
||||||
*
|
*
|
||||||
* @param string $xml XML
|
* @param string $xml XML
|
||||||
* @param string $file file name
|
* @param string $file file name
|
||||||
|
* @throws LAMException error during write
|
||||||
*/
|
*/
|
||||||
protected function writeXML($xml, $file) {
|
protected function writeXML($xml, $file) {
|
||||||
$handle = @fopen($file,'w');
|
$handle = @fopen($file,'w');
|
||||||
|
@ -713,7 +716,7 @@ class PDFTextSection {
|
||||||
class PDFEntrySection {
|
class PDFEntrySection {
|
||||||
|
|
||||||
private $title;
|
private $title;
|
||||||
private $entries;
|
private $entries = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
|
|
|
@ -1,11 +1,14 @@
|
||||||
<?php
|
<?php
|
||||||
namespace LAM\PERSISTENCE;
|
namespace LAM\PERSISTENCE;
|
||||||
|
use LAM\PDF\PDFStructure;
|
||||||
use LAM\PDF\PDFStructureReader;
|
use LAM\PDF\PDFStructureReader;
|
||||||
|
use LAM\PDF\PDFStructureWriter;
|
||||||
use LAMCfgMain;
|
use LAMCfgMain;
|
||||||
use LAMConfig;
|
use LAMConfig;
|
||||||
use LAMException;
|
use LAMException;
|
||||||
use function LAM\PDF\getAvailableLogos;
|
use function LAM\PDF\getAvailableLogos;
|
||||||
use function LAM\PDF\getPDFStructures;
|
use function LAM\PDF\getPDFStructures;
|
||||||
|
use function LAM\PDF\uploadPDFLogo;
|
||||||
use function LAM\PROFILES\getAccountProfiles;
|
use function LAM\PROFILES\getAccountProfiles;
|
||||||
use function LAM\PROFILES\loadAccountProfile;
|
use function LAM\PROFILES\loadAccountProfile;
|
||||||
use function LAM\PROFILES\saveAccountProfile;
|
use function LAM\PROFILES\saveAccountProfile;
|
||||||
|
@ -65,7 +68,7 @@ class ConfigDataExporter {
|
||||||
/**
|
/**
|
||||||
* TODO
|
* TODO
|
||||||
*
|
*
|
||||||
* PDF profiles
|
* pdf/account templates /config/templates
|
||||||
* self service profiles
|
* self service profiles
|
||||||
* webauthn
|
* webauthn
|
||||||
*/
|
*/
|
||||||
|
@ -207,7 +210,13 @@ class ConfigDataImporter {
|
||||||
}
|
}
|
||||||
$steps[] = $mainStep;
|
$steps[] = $mainStep;
|
||||||
break;
|
break;
|
||||||
// TODO PDF structures
|
case 'pdfProfiles':
|
||||||
|
$mainStep = new ImporterStep(_('PDF structures'), 'pdfProfiles', $value);
|
||||||
|
foreach ($value as $profileName => $profileData) {
|
||||||
|
$mainStep->addSubStep(new ImporterStep($profileName, 'pdfProfile_' . $profileName, $profileData));
|
||||||
|
}
|
||||||
|
$steps[] = $mainStep;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
logNewMessage(LOG_WARNING, 'Unknown import type: ' . $key);
|
logNewMessage(LOG_WARNING, 'Unknown import type: ' . $key);
|
||||||
}
|
}
|
||||||
|
@ -243,6 +252,9 @@ class ConfigDataImporter {
|
||||||
case 'accountProfiles':
|
case 'accountProfiles':
|
||||||
$this->importAccountProfiles($step);
|
$this->importAccountProfiles($step);
|
||||||
break;
|
break;
|
||||||
|
case 'pdfProfiles':
|
||||||
|
$this->importPdfProfiles($step);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
logNewMessage(LOG_WARNING, 'Unknown import type: ' . $key);
|
logNewMessage(LOG_WARNING, 'Unknown import type: ' . $key);
|
||||||
}
|
}
|
||||||
|
@ -327,6 +339,53 @@ class ConfigDataImporter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Imports the PDF profiles.
|
||||||
|
*
|
||||||
|
* @param ImporterStep $step step
|
||||||
|
* @throws LAMException error during import
|
||||||
|
*/
|
||||||
|
private function importPdfProfiles($step) {
|
||||||
|
$failedProfiles = array();
|
||||||
|
foreach ($step->getSubSteps() as $profileStep) {
|
||||||
|
if (!$profileStep->isActive()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$data = $profileStep->getValue();
|
||||||
|
$serverProfileName = str_replace('pdfProfile_', '', $profileStep->getKey());
|
||||||
|
if (isset($data['structures'])) {
|
||||||
|
$writer = new PDFStructureWriter($serverProfileName);
|
||||||
|
foreach ($data['structures'] as $typeId => $pdfProfiles) {
|
||||||
|
foreach ($pdfProfiles as $pdfProfileName => $pdfProfileData) {
|
||||||
|
$structure = new PDFStructure();
|
||||||
|
$structure->import($pdfProfileData);
|
||||||
|
try {
|
||||||
|
$writer->write($typeId, $pdfProfileName, $structure);
|
||||||
|
}
|
||||||
|
catch (LAMException $e) {
|
||||||
|
logNewMessage('ERROR', $e->getMessage());
|
||||||
|
$failedProfiles[] = $serverProfileName . ':' . $typeId . ':' . $pdfProfileName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isset($data['logos'])) {
|
||||||
|
foreach ($data['logos'] as $logoFileName => $logoData) {
|
||||||
|
$tempFilePath = tempnam("/tmp", "lam");
|
||||||
|
$tempFile = fopen($tempFilePath, "w");
|
||||||
|
$logoBinary = base64_decode($logoData);
|
||||||
|
fwrite($tempFile, $logoBinary);
|
||||||
|
fclose($tempFile);
|
||||||
|
uploadPDFLogo($tempFilePath, $logoFileName, $serverProfileName);
|
||||||
|
unlink($tempFilePath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!empty($failedProfiles)) {
|
||||||
|
throw new LAMException(_('Could not save PDF structure, access denied.'), implode(', ', $failedProfiles));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -189,10 +189,13 @@ printHeaderContents(_("Import and export configuration"), '../..');
|
||||||
$validUpload = false;
|
$validUpload = false;
|
||||||
$importSteps = array();
|
$importSteps = array();
|
||||||
if (isset($_POST['importConfig'])) {
|
if (isset($_POST['importConfig'])) {
|
||||||
|
try {
|
||||||
|
if (empty($_FILES['import-file']['tmp_name'])) {
|
||||||
|
throw new LAMException('The file you uploaded is too large. Please check php.ini, upload_max_size setting');
|
||||||
|
}
|
||||||
$handle = fopen($_FILES['import-file']['tmp_name'], "r");
|
$handle = fopen($_FILES['import-file']['tmp_name'], "r");
|
||||||
$data = fread($handle, 100000000);
|
$data = fread($handle, 100000000);
|
||||||
fclose($handle);
|
fclose($handle);
|
||||||
try {
|
|
||||||
$importer = new ConfigDataImporter();
|
$importer = new ConfigDataImporter();
|
||||||
$importSteps = $importer->getPossibleImportSteps($data);
|
$importSteps = $importer->getPossibleImportSteps($data);
|
||||||
$tmpFile = __DIR__ . '/../../tmp/internal/import_' . getRandomNumber() . '.tmp';
|
$tmpFile = __DIR__ . '/../../tmp/internal/import_' . getRandomNumber() . '.tmp';
|
||||||
|
@ -219,13 +222,14 @@ printHeaderContents(_("Import and export configuration"), '../..');
|
||||||
$stepKey = 'step_' . $importStep->getKey();
|
$stepKey = 'step_' . $importStep->getKey();
|
||||||
$stepCheckbox = new htmlResponsiveInputCheckbox($stepKey, true, $importStep->getLabel());
|
$stepCheckbox = new htmlResponsiveInputCheckbox($stepKey, true, $importStep->getLabel());
|
||||||
$stepCheckbox->setLabelAfterCheckbox();
|
$stepCheckbox->setLabelAfterCheckbox();
|
||||||
|
$stepCheckbox->setCSSClasses(array('bold'));
|
||||||
$subStepIds = array();
|
$subStepIds = array();
|
||||||
$content->add($stepCheckbox, 12);
|
$content->add($stepCheckbox, 12);
|
||||||
$content->addVerticalSpacer('0.3rem');
|
$content->addVerticalSpacer('0.3rem');
|
||||||
foreach ($importStep->getSubSteps() as $subStep) {
|
foreach ($importStep->getSubSteps() as $subStep) {
|
||||||
$subStepKey = 'step_' . $subStep->getKey();
|
$subStepKey = 'step_' . $subStep->getKey();
|
||||||
$subStepIds[] = $subStepKey;
|
$subStepIds[] = $subStepKey;
|
||||||
$subStepCheckbox = new htmlResponsiveInputCheckbox($subStepKey, true, ' - ' . $subStep->getLabel());
|
$subStepCheckbox = new htmlResponsiveInputCheckbox($subStepKey, true, $subStep->getLabel());
|
||||||
$subStepCheckbox->setLabelAfterCheckbox();
|
$subStepCheckbox->setLabelAfterCheckbox();
|
||||||
$content->add($subStepCheckbox, 12);
|
$content->add($subStepCheckbox, 12);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue