diff --git a/lam/lib/html.inc b/lam/lib/html.inc index 8f196be9..bf6c515e 100644 --- a/lam/lib/html.inc +++ b/lam/lib/html.inc @@ -4777,6 +4777,7 @@ class htmlResponsiveInputCheckbox extends htmlInputCheckbox { } // label text $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();'); // input field $fieldGroup = new htmlGroup(); diff --git a/lam/lib/pdfstruct.inc b/lam/lib/pdfstruct.inc index 1df4e334..e80591de 100644 --- a/lam/lib/pdfstruct.inc +++ b/lam/lib/pdfstruct.inc @@ -118,7 +118,7 @@ function getAvailableLogos($serverProfileName) { * @param \LAM\TYPES\ConfiguredType $sourceType source type * @param string $sourceStructureName structure name * @param \LAM\TYPES\ConfiguredType $targetType target type - * @throws Exception + * @throws LAMException error during copy */ function copyStructure($sourceType, $sourceStructureName, $targetType) { if (!isValidPDFStructureName($sourceStructureName)) { @@ -427,7 +427,7 @@ class PDFStructureWriter { /** * Constructor. * - * @param $serverProfileName server profile name + * @param string $serverProfileName server profile name */ public function __construct($serverProfileName) { $this->serverProfileName = $serverProfileName; @@ -439,6 +439,7 @@ class PDFStructureWriter { * @param string $typeId type ID * @param string $name structure name * @param PDFStructure $structure structure + * @throws LAMException error during write */ public function write($typeId, $name, $structure) { $fileName = $this->getFileName($typeId, $name); @@ -452,6 +453,7 @@ class PDFStructureWriter { * @param string $typeId type ID * @param string $name structure name * @return string file name + * @throws LAMException file not valid or not writable */ protected function getFileName($typeId, $name) { if (!isValidPDFStructureName($name) || !preg_match('/[a-zA-Z]+/', $typeId)) { @@ -510,6 +512,7 @@ class PDFStructureWriter { * * @param string $xml XML * @param string $file file name + * @throws LAMException error during write */ protected function writeXML($xml, $file) { $handle = @fopen($file,'w'); @@ -713,7 +716,7 @@ class PDFTextSection { class PDFEntrySection { private $title; - private $entries; + private $entries = array(); /** * Constructor diff --git a/lam/lib/persistence.inc b/lam/lib/persistence.inc index edb400ab..849641aa 100644 --- a/lam/lib/persistence.inc +++ b/lam/lib/persistence.inc @@ -1,11 +1,14 @@ $profileData) { + $mainStep->addSubStep(new ImporterStep($profileName, 'pdfProfile_' . $profileName, $profileData)); + } + $steps[] = $mainStep; + break; default: logNewMessage(LOG_WARNING, 'Unknown import type: ' . $key); } @@ -243,6 +252,9 @@ class ConfigDataImporter { case 'accountProfiles': $this->importAccountProfiles($step); break; + case 'pdfProfiles': + $this->importPdfProfiles($step); + break; default: 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)); + } + } + } /** diff --git a/lam/templates/config/confImportExport.php b/lam/templates/config/confImportExport.php index 57ba7fd4..5bf10110 100644 --- a/lam/templates/config/confImportExport.php +++ b/lam/templates/config/confImportExport.php @@ -189,10 +189,13 @@ printHeaderContents(_("Import and export configuration"), '../..'); $validUpload = false; $importSteps = array(); if (isset($_POST['importConfig'])) { - $handle = fopen($_FILES['import-file']['tmp_name'], "r"); - $data = fread($handle, 100000000); - fclose($handle); 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"); + $data = fread($handle, 100000000); + fclose($handle); $importer = new ConfigDataImporter(); $importSteps = $importer->getPossibleImportSteps($data); $tmpFile = __DIR__ . '/../../tmp/internal/import_' . getRandomNumber() . '.tmp'; @@ -219,13 +222,14 @@ printHeaderContents(_("Import and export configuration"), '../..'); $stepKey = 'step_' . $importStep->getKey(); $stepCheckbox = new htmlResponsiveInputCheckbox($stepKey, true, $importStep->getLabel()); $stepCheckbox->setLabelAfterCheckbox(); + $stepCheckbox->setCSSClasses(array('bold')); $subStepIds = array(); $content->add($stepCheckbox, 12); $content->addVerticalSpacer('0.3rem'); foreach ($importStep->getSubSteps() as $subStep) { $subStepKey = 'step_' . $subStep->getKey(); $subStepIds[] = $subStepKey; - $subStepCheckbox = new htmlResponsiveInputCheckbox($subStepKey, true, ' - ' . $subStep->getLabel()); + $subStepCheckbox = new htmlResponsiveInputCheckbox($subStepKey, true, $subStep->getLabel()); $subStepCheckbox->setLabelAfterCheckbox(); $content->add($subStepCheckbox, 12); }