close PDF dialog after user clicked button

This commit is contained in:
Roland Gruber 2010-11-06 09:40:32 +00:00
parent 1116983fdd
commit 5c7e917ebb
2 changed files with 56 additions and 68 deletions

View File

@ -146,7 +146,7 @@ class lamList {
return; return;
} }
// do POST actions // do POST actions
$this->listDoPost(); $postFragment = $this->listDoPost();
// get some parameters // get some parameters
$this->listGetParams(); $this->listGetParams();
// print HTML head // print HTML head
@ -160,6 +160,8 @@ class lamList {
if (isset($this->entries)) { if (isset($this->entries)) {
$this->entries = $this->listSort($this->entries); $this->entries = $this->listSort($this->entries);
} }
// insert HTML fragment from listDoPost
echo $postFragment;
// show form // show form
echo "<div class=\"ui-tabs-panel ui-widget-content ui-corner-bottom\">"; echo "<div class=\"ui-tabs-panel ui-widget-content ui-corner-bottom\">";
echo "<div id=\"listTabContentArea\">\n"; echo "<div id=\"listTabContentArea\">\n";
@ -463,6 +465,8 @@ class lamList {
/** /**
* Manages all POST actions (e.g. button pressed) for the account lists. * 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() { protected function listDoPost() {
// check if button was pressed and if we have to add/delete an account or call file upload // 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'])) { if (isset($_POST['createPDFok'])) {
$pdfStruct = $_POST['pdf_structure']; $pdfStruct = $_POST['pdf_structure'];
$option = $_POST['createFor']; $option = $_POST['createFor'];
$filename = '';
// create for clicked account // create for clicked account
if ($option == 'DN') { if ($option == 'DN') {
$_SESSION["accountPDF"] = new accountContainer($this->type, "accountPDF"); $_SESSION["accountPDF"] = new accountContainer($this->type, "accountPDF");
$_SESSION["accountPDF"]->load_account(base64_decode($_POST['clickedAccount'])); $_SESSION["accountPDF"]->load_account(base64_decode($_POST['clickedAccount']));
createModulePDF(array($_SESSION["accountPDF"]),$pdfStruct); $filename = createModulePDF(array($_SESSION["accountPDF"]),$pdfStruct);
unset($_SESSION["accountPDF"]); unset($_SESSION["accountPDF"]);
exit;
} }
// create for all selected accounts // create for all selected accounts
elseif ($option == 'SELECTED') { elseif ($option == 'SELECTED') {
@ -529,11 +533,10 @@ class lamList {
$list[$i] = $_SESSION["accountPDF-$i"]; $list[$i] = $_SESSION["accountPDF-$i"];
} }
if (sizeof($list) > 0) { if (sizeof($list) > 0) {
createModulePDF($list,$pdfStruct); $filename = createModulePDF($list,$pdfStruct);
for ($i = 0; $i < sizeof($accounts); $i++) { for ($i = 0; $i < sizeof($accounts); $i++) {
unset($_SESSION["accountPDF-$i"]); unset($_SESSION["accountPDF-$i"]);
} }
exit;
} }
} }
// create for all accounts // create for all accounts
@ -545,18 +548,19 @@ class lamList {
$list[$i] = $_SESSION["accountPDF-$i"]; $list[$i] = $_SESSION["accountPDF-$i"];
} }
if (sizeof($list) > 0) { if (sizeof($list) > 0) {
createModulePDF($list,$pdfStruct); $filename = createModulePDF($list,$pdfStruct);
for ($i = 0; $i < sizeof($this->entries); $i++) { for ($i = 0; $i < sizeof($this->entries); $i++) {
// clean session // clean session
unset($_SESSION["accountPDF-$i"]); unset($_SESSION["accountPDF-$i"]);
} }
exit;
} }
} }
elseif ($option == 'SESSION') { elseif ($option == 'SESSION') {
createModulePDF(array($_SESSION[$_POST['PDFSessionID']]),$pdfStruct); $filename = createModulePDF(array($_SESSION[$_POST['PDFSessionID']]),$pdfStruct);
unset($_SESSION[$_GET['PDFSessionID']]); unset($_SESSION[$_GET['PDFSessionID']]);
exit; }
if ($filename != '') {
return "<script type=\"text/javascript\">window.open('" . $filename . "', '_blank');</script>";
} }
} }
// check if back from configuration page // check if back from configuration page
@ -573,6 +577,7 @@ class lamList {
$this->listConfigurationChanged(); $this->listConfigurationChanged();
} }
} }
return '';
} }
/** /**
@ -592,59 +597,14 @@ class lamList {
if (!in_array($id, $selAccounts)) { if (!in_array($id, $selAccounts)) {
$selAccounts[] = $id; $selAccounts[] = $id;
} }
// get possible PDF structures
$pdf_structures = getPDFStructureDefinitions($this->type);
$this->listPrintHeader(); $this->listPrintHeader();
echo "<br><div>\n"; echo "<div class=\"ui-tabs-nav " . $this->type . "list-bright\">";
echo "<div class=\"ui-tabs-nav\">"; echo "<div class=\"smallPaddingContent\">\n";
echo "<form target=\"_blank\" action=\"list.php?type=" . $this->type . "&amp;norefresh=true\" method=\"post\">\n"; echo "<form action=\"list.php?type=" . $this->type . "&amp;norefresh=true\" method=\"post\">\n";
echo '<fieldset class="' . $this->type . 'edit"><legend>' . _('Create PDF file') . '</legend><br>';
echo '<table class="' . $this->type . 'edit">';
echo '<tr>';
echo '<td>';
echo _('PDF structure') . " ";
echo '</td>';
echo '<td>';
echo "<select name=\"pdf_structure\">\n";
$pdf_structures = getPDFStructureDefinitions($this->type);
foreach($pdf_structures as $pdf_structure) {
echo "<option " . (($pdf_structure == 'default') ? " selected" : "") . ">" . $pdf_structure . "</option>";
}
echo "</select>\n";
echo '</td>';
echo '</tr>';
echo '<tr>';
echo '<td>';
echo _('Create for') . " ";
echo '</td>';
echo '<td>';
// check if account object is already in session
if ($sessionObject != null) {
echo $sessionObject->finalDN;
echo "<input type=\"hidden\" name=\"createFor\" value=\"SESSION\">\n";
echo "<input type=\"hidden\" name=\"PDFSessionID\" value=\"$PDFSessionID\">\n";
}
else {
echo '<select name="createFor">';
echo '<option value="DN">' . base64_decode($id) . '</option>';
echo '<option value="SELECTED">' . sprintf(_('All selected accounts (%s)'), sizeof($selAccounts)) . '</option>';
echo '<option value="ALL">' . sprintf(_('All accounts (%s)'), sizeof($this->entries)) . '</option>';
echo '</select>';
}
echo '</td>';
echo '</tr>';
echo '<tr>';
echo '<td colspan=2>&nbsp;</td>';
echo '</tr>';
echo '<tr>';
echo '<td colspan=2>';
echo '<input type="submit" name="createPDFok" value="' . _('Ok') . '"> ';
echo '&nbsp;<a href="list.php?type=' . $this->type . '&amp;norefresh=true">' . _('Cancel') . '</a>';
echo '</td>';
echo '</tr>';
echo '</table>';
echo '</fieldset>';
// hiden inputs for selected accounts // hiden inputs for selected accounts
for ($i = 0; $i < sizeof($selAccounts); $i++) { for ($i = 0; $i < sizeof($selAccounts); $i++) {
@ -652,6 +612,38 @@ class lamList {
} }
echo '<input type="hidden" name="clickedAccount" value="' . $id . '">'; echo '<input type="hidden" name="clickedAccount" value="' . $id . '">';
$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(); $this->listPrintFooter();
} }

View File

@ -42,16 +42,14 @@ $key = false;
$line_width = LAMPDF_LINEWIDTH; $line_width = LAMPDF_LINEWIDTH;
/** /**
* This function creates the PDF output of one or more accounts. At the moment * This function creates the PDF output of one or more accounts.
* 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.
* *
* @param array $accounts A numbered array containing all accounts the PDF page should * @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. * 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 * @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 * to create the PDF page. If not submitted the 'default.user' structure definition
* for the appropriate account type. * for the appropriate account type.
* @return String PDF file name
*/ */
function createModulePDF($accounts,$pdf_structure="default") { function createModulePDF($accounts,$pdf_structure="default") {
@ -143,12 +141,10 @@ function createModulePDF($accounts,$pdf_structure="default") {
// Close PDF // Close PDF
$pdf->Close(); $pdf->Close();
// use timestamp and random number from ldap.inc as filename so it should be unique. // 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 // Save PDF
$pdf->Output($filename); $pdf->Output($filename);
// Output meta refresh to pdf-file // return PDF file name
metaRefresh($filename);
// Return relative path of pdf-file
return $filename; return $filename;
} }