From 5c7e917ebb0851f96695e4ef003c742842c75277 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Sat, 6 Nov 2010 09:40:32 +0000 Subject: [PATCH] close PDF dialog after user clicked button --- lam/lib/lists.inc | 112 +++++++++++++++++++++------------------------- lam/lib/pdf.inc | 12 ++--- 2 files changed, 56 insertions(+), 68 deletions(-) diff --git a/lam/lib/lists.inc b/lam/lib/lists.inc index da3dfd42..7691a2d3 100644 --- a/lam/lib/lists.inc +++ b/lam/lib/lists.inc @@ -146,7 +146,7 @@ class lamList { return; } // do POST actions - $this->listDoPost(); + $postFragment = $this->listDoPost(); // get some parameters $this->listGetParams(); // print HTML head @@ -160,6 +160,8 @@ class lamList { if (isset($this->entries)) { $this->entries = $this->listSort($this->entries); } + // insert HTML fragment from listDoPost + echo $postFragment; // show form echo "
"; echo "
\n"; @@ -463,6 +465,8 @@ class lamList { /** * Manages all POST actions (e.g. button pressed) for the account lists. + * + * @return String HTML fragment to insert into beginning of account list */ protected function listDoPost() { // check if button was pressed and if we have to add/delete an account or call file upload @@ -509,13 +513,13 @@ class lamList { if (isset($_POST['createPDFok'])) { $pdfStruct = $_POST['pdf_structure']; $option = $_POST['createFor']; + $filename = ''; // create for clicked account if ($option == 'DN') { $_SESSION["accountPDF"] = new accountContainer($this->type, "accountPDF"); $_SESSION["accountPDF"]->load_account(base64_decode($_POST['clickedAccount'])); - createModulePDF(array($_SESSION["accountPDF"]),$pdfStruct); + $filename = createModulePDF(array($_SESSION["accountPDF"]),$pdfStruct); unset($_SESSION["accountPDF"]); - exit; } // create for all selected accounts elseif ($option == 'SELECTED') { @@ -529,11 +533,10 @@ class lamList { $list[$i] = $_SESSION["accountPDF-$i"]; } if (sizeof($list) > 0) { - createModulePDF($list,$pdfStruct); + $filename = createModulePDF($list,$pdfStruct); for ($i = 0; $i < sizeof($accounts); $i++) { unset($_SESSION["accountPDF-$i"]); } - exit; } } // create for all accounts @@ -545,18 +548,19 @@ class lamList { $list[$i] = $_SESSION["accountPDF-$i"]; } if (sizeof($list) > 0) { - createModulePDF($list,$pdfStruct); + $filename = createModulePDF($list,$pdfStruct); for ($i = 0; $i < sizeof($this->entries); $i++) { // clean session unset($_SESSION["accountPDF-$i"]); } - exit; } } elseif ($option == 'SESSION') { - createModulePDF(array($_SESSION[$_POST['PDFSessionID']]),$pdfStruct); + $filename = createModulePDF(array($_SESSION[$_POST['PDFSessionID']]),$pdfStruct); unset($_SESSION[$_GET['PDFSessionID']]); - exit; + } + if ($filename != '') { + return ""; } } // check if back from configuration page @@ -573,6 +577,7 @@ class lamList { $this->listConfigurationChanged(); } } + return ''; } /** @@ -592,59 +597,14 @@ class lamList { if (!in_array($id, $selAccounts)) { $selAccounts[] = $id; } - + // get possible PDF structures + $pdf_structures = getPDFStructureDefinitions($this->type); + $this->listPrintHeader(); - echo "
\n"; - echo "
"; - echo "
type . "&norefresh=true\" method=\"post\">\n"; - - echo '
' . _('Create PDF file') . '
'; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo '
'; - echo _('PDF structure') . " "; - echo ''; - echo "\n"; - echo '
'; - echo _('Create for') . " "; - echo ''; - // check if account object is already in session - if ($sessionObject != null) { - echo $sessionObject->finalDN; - echo "\n"; - echo "\n"; - } - else { - echo ''; - } - echo '
 
'; - echo ' '; - echo ' ' . _('Cancel') . ''; - echo '
'; - echo '
'; + echo "
type . "list-bright\">"; + echo "
\n"; + echo "type . "&norefresh=true\" method=\"post\">\n"; // hiden inputs for selected accounts for ($i = 0; $i < sizeof($selAccounts); $i++) { @@ -652,6 +612,38 @@ class lamList { } echo ''; + $container = new htmlTable(); + $container->addElement(new htmlSubTitle(_('Create PDF file')), true); + + $container->addElement(new htmlTableExtendedSelect('pdf_structure', $pdf_structures, array('default'), _('PDF structure')), true); + + $container->addElement(new htmlSpacer(null, '5px'), true); + $container->addElement(new htmlOutputText(_('Create for'))); + // check if account object is already in session + if ($sessionObject != null) { + $container->addElement(new htmlOutputText($sessionObject->finalDN)); + $container->addElement(new htmlHiddenInput('createFor', 'SESSION')); + $container->addElement(new htmlHiddenInput('PDFSessionID', $PDFSessionID), true); + } + else { + $radioOptions = array( + base64_decode($id) => 'DN', + sprintf(_('All selected accounts (%s)'), sizeof($selAccounts)) => 'SELECTED', + sprintf(_('All accounts (%s)'), sizeof($this->entries)) => 'ALL' + ); + $container->addElement(new htmlRadio('createFor', $radioOptions, 'DN'), true); + } + + $container->addElement(new htmlSpacer(null, '10px'), true); + $buttonContainer = new htmlTable(); + $buttonContainer->colspan = 2; + $buttonContainer->addElement(new htmlButton('createPDFok', _('Ok'))); + $buttonContainer->addElement(new htmlButton('createPDFCancel', _('Cancel'))); + $container->addElement($buttonContainer); + + $tabindex = 1; + parseHtml(null, $container, array(), false, $tabindex, $this->type); + $this->listPrintFooter(); } diff --git a/lam/lib/pdf.inc b/lam/lib/pdf.inc index 893c117f..b3e8b832 100644 --- a/lam/lib/pdf.inc +++ b/lam/lib/pdf.inc @@ -42,16 +42,14 @@ $key = false; $line_width = LAMPDF_LINEWIDTH; /** - * This function creates the PDF output of one or more accounts. At the moment - * this function can create a PDF page for user, group and host accounts. But - * this is not limited by the function itself but by the account types that are - * allowed in LAM and the exsisting PDF structure definitions. + * This function creates the PDF output of one or more accounts. * * @param array $accounts A numbered array containing all accounts the PDF page should * be created for. The entries of the array must be AccountContainer objects. * @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. + * @return String PDF file name */ function createModulePDF($accounts,$pdf_structure="default") { @@ -143,12 +141,10 @@ 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'; + $filename = '../../tmp/' . $_SESSION['ldap']->new_rand() . time() .'.pdf'; // Save PDF $pdf->Output($filename); - // Output meta refresh to pdf-file - metaRefresh($filename); - // Return relative path of pdf-file + // return PDF file name return $filename; }