diff --git a/lam/lib/pdfstruct.inc b/lam/lib/pdfstruct.inc index 3f0b8b8d..bf81592c 100644 --- a/lam/lib/pdfstruct.inc +++ b/lam/lib/pdfstruct.inc @@ -4,7 +4,7 @@ $Id$ This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) Copyright (C) 2003 - 2006 Michael Duergner - 2011 Roland Gruber + 2011 - 2013 Roland Gruber This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -237,4 +237,71 @@ function copyPdfProfiles($pdfProfiles, $scope, $dests = array()) { return $state; } +/** + * Uploads a PDF logo file for the current server profile. + * + * @param String $file full path of temporary file + * @param String $name file name + * @return StatusMessage status message to display + */ +function uploadPDFLogo($file, $name) { + if (!preg_match('/[a-zA-Z0-9_-]+\\.(png)|(jpg)/', $name)) { + return new htmlStatusMessage('ERROR', _('Unable to upload logo file.'), _('The file name must end with ".png" or ".jpg".')); + } + $infos = getimagesize($file); + if ($infos[0] <= 2000 && $infos[1] <= 300) { + $dirPath = dirname(__FILE__) . '/../config/pdf/' . $_SESSION['config']->getName() . '/logos/'; + $success = copy($file, $dirPath . '/' . $name); + if ($success) { + return new htmlStatusMessage('INFO', _('Uploaded logo file.'), $name); + } + else { + return new htmlStatusMessage('ERROR', _('Unable to upload logo file.'), $name); + } + } + return new htmlStatusMessage('ERROR', _('Unable to upload logo file.'), _('The file must not exeed 2000x300px.')); +} + +/** + * Deletes a PDF logo file. + * + * @param String $name file name + * @return StatusMessage status message to display + */ +function deletePDFLogo($name) { + // check if valid file + $found = false; + $logos = getAvailableLogos(); + foreach ($logos as $logo) { + if ($logo['filename'] === $name) { + $found = true; + break; + } + } + if (!$found) { + return new htmlStatusMessage('ERROR', _('File does not exist.'), htmlspecialchars($name)); + } + // check if still in use + $activeTypes = $_SESSION['config']->get_ActiveTypes(); + foreach ($activeTypes as $type) { + $structures = getPDFStructureDefinitions($type); + foreach ($structures as $structure) { + $data = loadPDFStructureDefinitions($type, $structure); + if ($data['page_definitions']['filename'] == $name) { + return new htmlStatusMessage('ERROR', _('Unable to delete logo file.'), + sprintf(_('Logo is still in use by PDF structure "%s" in account type "%s".'), $structure, getTypeAlias($type))); + } + } + } + // delete file + $dirPath = dirname(__FILE__) . '/../config/pdf/' . $_SESSION['config']->getName() . '/logos/'; + $success = @unlink($dirPath . '/' . $name); + if ($success) { + return new htmlStatusMessage('INFO', _('Logo file deleted.'), $name); + } + else { + return new htmlStatusMessage('ERROR', _('Unable to delete logo file.'), $name); + } +} + ?> diff --git a/lam/templates/pdfedit/pdfmain.php b/lam/templates/pdfedit/pdfmain.php index 735d5431..924ef8b1 100644 --- a/lam/templates/pdfedit/pdfmain.php +++ b/lam/templates/pdfedit/pdfmain.php @@ -123,6 +123,19 @@ if (isset($_POST['importexport']) && ($_POST['importexport'] === '1')) { } } +// upload logo file +if (isset($_POST['uploadLogo']) && !empty($_FILES['logoUpload']) && !empty($_FILES['logoUpload']['size'])) { + $file = $_FILES['logoUpload']['tmp_name']; + $filename = $_FILES['logoUpload']['name']; + $container->addElement(uploadPDFLogo($file, $filename), true); +} + +// delete logo file +if (isset($_POST['delLogo'])) { + $toDel = $_POST['logo']; + $container->addElement(deletePDFLogo($toDel), true); +} + // get list of account types $availableScopes = ''; $templateClasses = array(); @@ -149,7 +162,7 @@ for ($i = 0; $i < sizeof($templateClasses); $i++) { include '../main_header.php'; ?>
-
+ addNewLine(); } $container->addElement($existingContainer, true); - $container->addElement(new htmlSpacer(null, '10px'), true); + // manage logos + $logoContainer = new htmlTable(); + $logoContainer->addElement(new htmlSpacer(null, '30px'), true); + $logoContainer->addElement(new htmlSubTitle(_('Manage logos')), true); + $logos = getAvailableLogos(); + $logoOptions = array(); + foreach ($logos as $logo) { + $file = $logo['filename']; + $label = $file . ' (' . $logo['infos'][0] . ' x ' . $logo['infos'][1] . ")"; + $logoOptions[$label] = $file; + } + $logoSelect = new htmlSelect('logo', $logoOptions, null); + $logoSelect->setHasDescriptiveElements(true); + $logoContainer->addElement($logoSelect); + $delLogo = new htmlButton('delLogo', _('Delete')); + $delLogo->setIconClass('deleteButton'); + $logoContainer->addElement($delLogo, true); + $logoContainer->addElement(new htmlInputFileUpload('logoUpload')); + $logoUpload = new htmlButton('uploadLogo', _('Upload')); + $logoUpload->setIconClass('upButton'); + $logoContainer->addElement($logoUpload); + $container->addElement($logoContainer, true); + + $container->addElement(new htmlSpacer(null, '10px'), true); // generate content $tabindex = 1; parseHtml(null, $container, array(), false, $tabindex, 'user');