allow to upload and delete logo files
This commit is contained in:
parent
3c497505a3
commit
2e27115031
|
@ -4,7 +4,7 @@ $Id$
|
||||||
|
|
||||||
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
|
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
|
||||||
Copyright (C) 2003 - 2006 Michael Duergner
|
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
|
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
|
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;
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
|
@ -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
|
// get list of account types
|
||||||
$availableScopes = '';
|
$availableScopes = '';
|
||||||
$templateClasses = array();
|
$templateClasses = array();
|
||||||
|
@ -149,7 +162,7 @@ for ($i = 0; $i < sizeof($templateClasses); $i++) {
|
||||||
include '../main_header.php';
|
include '../main_header.php';
|
||||||
?>
|
?>
|
||||||
<div class="user-bright smallPaddingContent">
|
<div class="user-bright smallPaddingContent">
|
||||||
<form action="pdfmain.php" method="post" name="pdfmainForm" >
|
<form enctype="multipart/form-data" action="pdfmain.php" method="post" name="pdfmainForm" >
|
||||||
<?php
|
<?php
|
||||||
if (isset($_GET['savedSuccessfully'])) {
|
if (isset($_GET['savedSuccessfully'])) {
|
||||||
$message = new htmlStatusMessage("INFO", _("PDF structure was successfully saved."), htmlspecialchars($_GET['savedSuccessfully']));
|
$message = new htmlStatusMessage("INFO", _("PDF structure was successfully saved."), htmlspecialchars($_GET['savedSuccessfully']));
|
||||||
|
@ -210,8 +223,31 @@ include '../main_header.php';
|
||||||
$existingContainer->addNewLine();
|
$existingContainer->addNewLine();
|
||||||
}
|
}
|
||||||
$container->addElement($existingContainer, true);
|
$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
|
// generate content
|
||||||
$tabindex = 1;
|
$tabindex = 1;
|
||||||
parseHtml(null, $container, array(), false, $tabindex, 'user');
|
parseHtml(null, $container, array(), false, $tabindex, 'user');
|
||||||
|
|
Loading…
Reference in New Issue