diff --git a/lam/HISTORY b/lam/HISTORY index 55d6d950..f46493b0 100644 --- a/lam/HISTORY +++ b/lam/HISTORY @@ -1,7 +1,9 @@ March 2012 3.7 - Login: support bind user for login search - Personal: added labeledURI and cosmetic changes, description is now multi-valued (RFE 3446363) - - File upload: support custom scripts postCreate (LAM Pro) + - File upload: + -> support custom scripts postCreate (LAM Pro) + -> PDF export - New translation: Slovakian - removed phpGroupWare support (project no longer exists) - LAM Pro: diff --git a/lam/lib/checkEnvironment.inc b/lam/lib/checkEnvironment.inc index 614a15e5..0ce3ee31 100644 --- a/lam/lib/checkEnvironment.inc +++ b/lam/lib/checkEnvironment.inc @@ -103,6 +103,10 @@ if (isset($memLimit) && ($memLimit != '') && (substr(strtoupper($memLimit), strl if (!@preg_match('/^\p{L}+$/u', "abc")) { $criticalErrors[] = array("ERROR", "Your PCRE library has no complete Unicode support. Please upgrade libpcre or compile with \"--enable-unicode-properties\"."); } +// check ZIP support for PDF files in file upload +if (!extension_loaded('zip')) { + $criticalErrors[] = array("ERROR", "Your PHP has no ZIP support.", "Please install the ZIP extension for PHP."); +} // stop login if critical errors occured if (sizeof($criticalErrors) > 0) { echo "\n\n"; diff --git a/lam/lib/lamPDF.inc b/lam/lib/lamPDF.inc index 0a9b2558..36c241cf 100644 --- a/lam/lib/lamPDF.inc +++ b/lam/lib/lamPDF.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 + 2007 - 2012 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 @@ -27,6 +27,7 @@ $Id$ * and furthermore some helper functions. * * @author Michael Duergner + * @author Roland Gruber * @package PDF */ @@ -35,6 +36,7 @@ $Id$ * * @package PDF * @author Michael Duergner + * @author Roland Gruber */ class lamPDF extends UFPDF { @@ -64,7 +66,9 @@ class lamPDF extends UFPDF { */ function __construct($page_definitions = array(),$fontName) { $this->fontName = $fontName; - define('FPDF_FONTPATH', dirname(__FILE__) . '/font/'); + if (!defined('FPDF_FONTPATH')) { + define('FPDF_FONTPATH', dirname(__FILE__) . '/font/'); + } // Call constructor of superclass $this->FPDF('P','mm','A4'); diff --git a/lam/lib/ldap.inc b/lam/lib/ldap.inc index 997bd6d9..13215fa7 100644 --- a/lam/lib/ldap.inc +++ b/lam/lib/ldap.inc @@ -122,7 +122,9 @@ class Ldap{ /** Closes connection to server */ function close() { - @ldap_close($this->server); + if ($this->server != null) { + @ldap_close($this->server); + } } /** @@ -158,7 +160,7 @@ class Ldap{ $dir = @opendir($tmpDir); $file = @readdir($dir); while ($file) { - if ((substr($file, -4) == '.pdf') || (substr($file, -4) == '.jpg')) { + if ((substr($file, -4) == '.pdf') || (substr($file, -4) == '.jpg') || (substr($file, -4) == '.zip')) { $path = $tmpDir . $file; if ($time - filemtime($path) > 600) { @unlink($path); diff --git a/lam/lib/lists.inc b/lam/lib/lists.inc index b69ca9fb..6ebba0b7 100644 --- a/lam/lib/lists.inc +++ b/lam/lib/lists.inc @@ -923,6 +923,9 @@ class lamList { } elseif (isset($_GET['uploadAllOk'])) { StatusMessage('INFO', _("Upload has finished")); + if (isset($_SESSION['mass_pdf']['file'])) { + StatusMessage('INFO', sprintf(_('You can download your PDF files {link=%s}here{endlink}.'), '../' . $_SESSION['mass_pdf']['file'])); + } } elseif (isset($_SESSION['listRedirectMessages'])) { for ($i = 0; $i < sizeof($_SESSION['listRedirectMessages']); $i++) { diff --git a/lam/lib/pdf.inc b/lam/lib/pdf.inc index 634ccd2d..2fd7f53f 100644 --- a/lam/lib/pdf.inc +++ b/lam/lib/pdf.inc @@ -3,7 +3,8 @@ $Id$ This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) - Copyright (C) 2003 - 2006 Michael Duergner + Copyright (C) 2003 - 2004 Michael Duergner + 2003 - 2012 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 @@ -26,6 +27,7 @@ $Id$ * and furthermore some helper functions. * * @author Michael Duergner + * @author Roland Gruber * @package PDF */ @@ -49,9 +51,10 @@ $line_width = LAMPDF_LINEWIDTH; * @param string $pdf_structure The filename of the structure definition that should be used * to create the PDF page. If not submitted the 'default.user' structure definition * for the appropriate account type. + * @param $returnAsString returns the PDF output as String value instead of writing it to a file * @return String PDF file name */ -function createModulePDF($accounts,$pdf_structure="default") { +function createModulePDF($accounts, $pdf_structure="default", $returnAsString = false) { /** PDF generator class */ include_once("fpdf.php"); @@ -142,12 +145,17 @@ function createModulePDF($accounts,$pdf_structure="default") { // Close PDF $pdf->Close(); - // use timestamp and random number from ldap.inc as filename so it should be unique. - $filename = '../../tmp/' . $_SESSION['ldap']->new_rand() . time() .'.pdf'; - // Save PDF - $pdf->Output($filename); - // return PDF file name - return $filename; + if (!$returnAsString) { + // use timestamp and random number from ldap.inc as filename so it should be unique. + $filename = '../../tmp/' . $_SESSION['ldap']->new_rand() . time() .'.pdf'; + // Save PDF + $pdf->Output($filename); + // return PDF file name + return $filename; + } + else { + return $pdf->Output('', 'S'); + } } /** diff --git a/lam/templates/massBuildAccounts.php b/lam/templates/massBuildAccounts.php index 33fab11a..13068133 100644 --- a/lam/templates/massBuildAccounts.php +++ b/lam/templates/massBuildAccounts.php @@ -3,7 +3,7 @@ $Id$ This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) - Copyright (C) 2004 - 2011 Roland Gruber + Copyright (C) 2004 - 2012 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 @@ -195,6 +195,17 @@ if ($_FILES['inputfile'] && ($_FILES['inputfile']['size'] > 0)) { $_SESSION['mass_ids'] = $ids; $_SESSION['mass_scope'] = $_POST['scope']; $_SESSION['mass_selectedModules'] = $selectedModules; + if (isset($_SESSION['mass_pdf'])) { + unset($_SESSION['mass_pdf']); + } + if (isset($_POST['createPDF']) && ($_POST['createPDF'] == 'on')) { + $_SESSION['mass_pdf']['structure'] = $_POST['pdfStructure']; + $_SESSION['mass_pdf']['counter'] = 0; + $_SESSION['mass_pdf']['file'] = '../tmp/lam_pdf' . $_SESSION['ldap']->new_rand() . '.zip'; + } + else { + $_SESSION['mass_pdf']['structure'] = null; + } // show links for upload and LDIF export echo "
\n"; echo "

" . _("LAM has checked your input and is now ready to create the accounts.") . "

\n"; @@ -238,6 +249,12 @@ function massPrintBackButton($scope, $selectedModules) { $container->addElement(new htmlSpacer(null, '10px'), true); $container->addElement(new htmlButton('submit', _('Back'))); $container->addElement(new htmlHiddenInput('type', $scope)); + $createPDF = 0; + if (isset($_POST['createPDF']) && ($_POST['createPDF'] == 'on')) { + $createPDF = 1; + } + $container->addElement(new htmlHiddenInput('createPDF', $createPDF)); + $container->addElement(new htmlHiddenInput('pdfStructure', $_POST['pdfStructure'])); for ($i = 0; $i < sizeof($selectedModules); $i++) { $container->addElement(new htmlHiddenInput($scope . '_' . $selectedModules[$i], 'on')); } diff --git a/lam/templates/massDoUpload.php b/lam/templates/massDoUpload.php index 93536950..faf434b3 100644 --- a/lam/templates/massDoUpload.php +++ b/lam/templates/massDoUpload.php @@ -3,7 +3,7 @@ $Id$ This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) - Copyright (C) 2004 - 2011 Roland Gruber + Copyright (C) 2004 - 2012 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 @@ -38,6 +38,8 @@ include_once('../lib/ldap.inc'); include_once('../lib/status.inc'); /** account modules */ include_once('../lib/modules.inc'); +/** PDF */ +include_once('../lib/pdf.inc'); // Start session @@ -60,12 +62,11 @@ echo '
\n"; echo "

" . _("LDAP upload in progress. Please wait.") . "

\n"; echo "
"; @@ -116,7 +117,7 @@ if (($_SESSION['mass_counter'] < sizeof($accounts)) || !isset($_SESSION['mass_po = sizeof($accounts)) { $data = unserialize($_SESSION['ldap']->decrypt($_SESSION['mass_data'])); $return = doUploadPostActions($_SESSION['mass_scope'], $data, $_SESSION['mass_ids'], $_SESSION['mass_failed'], $_SESSION['mass_selectedModules'], $accounts); @@ -148,6 +149,61 @@ if (($_SESSION['mass_counter'] < sizeof($accounts)) || !isset($_SESSION['mass_po } } } + // create PDF when upload post actions are done + if (isset($_SESSION['mass_postActions']['finished'])) { + if (($_SESSION['mass_pdf']['structure'] != null) && !isset($_SESSION['mass_pdf']['finished'])) { + $file = $_SESSION['mass_pdf']['file']; + $pdfStructure = $_SESSION['mass_pdf']['structure']; + $pdfZip = new ZipArchive(); + if ($_SESSION['mass_pdf']['counter'] == 0) { + $pdfZipResult = @$pdfZip->open($_SESSION['mass_pdf']['file'], ZipArchive::CREATE); + if (!$pdfZipResult === true) { + $_SESSION['mass_errors'][] = array('ERROR', _('Unable to create ZIP file for PDF export.'), $file); + $_SESSION['mass_pdf']['finished'] = true; + } + } + else { + @$pdfZip->open($_SESSION['mass_pdf']['file']); + } + // show progress bar + $progress = ($_SESSION['mass_pdf']['counter'] * 100) / sizeof($accounts); + echo "

" . _('Create PDF files') . "

\n"; + ?> +
+ + time())) { + // load account + $attrs = $accounts[$_SESSION['mass_pdf']['counter']]; + $dn = $attrs['dn']; + $_SESSION['pdfAccount'] = new accountContainer($_SESSION['mass_scope'], 'pdfAccount'); + $pdfErrors = $_SESSION['pdfAccount']->load_account($dn); + if (sizeof($pdfErrors) > 0) { + $_SESSION['mass_errors'] = array_merge($_SESSION['mass_errors'], $pdfErrors); + $_SESSION['mass_pdf']['finished'] = true; + break; + } + // create and save PDF + $pdfContent = createModulePDF(array($_SESSION['pdfAccount']), $pdfStructure, true); + $pdfZip->addFromString($dn, $pdfContent); + $_SESSION['mass_pdf']['counter'] ++; + if ($_SESSION['mass_pdf']['counter'] >= sizeof($accounts)) { + $_SESSION['mass_pdf']['finished'] = true; + } + } + @$pdfZip->close(); + } + else { + $_SESSION['mass_pdf']['finished'] = true; + } + } // refresh with JavaScript echo "