From f5c976cc06c8b689e50200d2ad53a1dc877ea464 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Sun, 25 Nov 2007 12:52:18 +0000 Subject: [PATCH] new PDF system --- lam/lib/lists.inc | 156 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 116 insertions(+), 40 deletions(-) diff --git a/lam/lib/lists.inc b/lam/lib/lists.inc index 4a41d028..581e889f 100644 --- a/lam/lib/lists.inc +++ b/lam/lib/lists.inc @@ -177,8 +177,6 @@ class lamList { // buttons $this->listPrintButtons(false); echo ("
\n"); - // PDF bar - $this->listPrintPDFButtons(); } else { // buttons @@ -428,7 +426,7 @@ class lamList { " type=\"checkbox\" name=\"" . $info[$i]['LAM_ID'] . "\">\n"; } echo " "; - $this->listPrintToolLinks($info[$i]); + $this->listPrintToolLinks($info[$i], $info[$i]['LAM_ID']); echo "\n"; for ($k = 0; $k < sizeof($this->attrArray); $k++) { echo (""); @@ -452,23 +450,26 @@ class lamList { /** * Prints the tool image links (e.g. edit and delete) for each account. * - * $account array LDAP attributes + * @param array $account LDAP attributes + * @param String $id account ID */ - private function listPrintToolLinks($account) { + private function listPrintToolLinks($account, $id) { // edit image echo "type . "&DN='" . $account['dn'] . "'\">"; echo "\"""; - echo ""; + echo "\n "; // delete image echo "type . "&DN='" . $account['dn'] . "'\">"; echo "\"""; - echo ""; + echo "\n "; + // pdf image + echo "\n "; // additional tools $tools = $this->getAdditionalTools(); for ($i = 0; $i < sizeof($tools); $i++) { echo "getLinkTarget() . "?type=" . $this->type . "&DN='" . $account['dn'] . "'\">"; echo "getImage() . "\" alt=\"" . $tools[$i]->getName() . "\" title=\"" . $tools[$i]->getName() . "\">"; - echo ""; + echo "\n "; } } @@ -499,7 +500,7 @@ class lamList { */ private function listDoPost() { // check if button was pressed and if we have to add/delete an account - if (isset($_POST['new']) || isset($_POST['del']) || isset($_POST['pdf']) || isset($_POST['pdf_all'])){ + if (isset($_POST['new']) || isset($_POST['del'])){ // add new account if (isset($_POST['new'])){ metaRefresh("../account/edit.php?type=" . $this->type . "&suffix=" . $this->suffix); @@ -530,9 +531,31 @@ class lamList { exit; } } - // PDF for selected accounts - elseif (isset($_POST['pdf'])){ - $pdf_structure = $_POST['pdf_structure']; + } + // PDF button + foreach ($_POST as $key => $value) { + if (strpos($key, 'createPDF_') > -1) { + $parts = explode("_", $key); + if (sizeof($parts) == 3) { + $this->showPDFPage($parts[1]); + exit; + } + } + } + // PDF creation Ok + if (isset($_POST['createPDFok'])) { + $pdfStruct = $_POST['pdf_structure']; + $option = $_POST['createFor']; + // create for clicked account + if ($option == 'DN') { + $_SESSION["accountPDF"] = new accountContainer($this->type, "accountPDF"); + $_SESSION["accountPDF"]->load_account($this->entries[$_POST['clickedAccount']]['dn']); + createModulePDF(array($_SESSION["accountPDF"]),$pdfStruct); + unset($_SESSION["accountPDF"]); + exit; + } + // create for all selected accounts + elseif ($option == 'SELECTED') { // search for checkboxes $accounts = array_keys($_POST, "on"); $list = array(); @@ -544,12 +567,15 @@ class lamList { $list[$i] = $_SESSION["accountPDF-$i"]; } if (sizeof($list) > 0) { - createModulePDF($list,$pdf_structure); + createModulePDF($list,$pdfStruct); + for ($i = 0; $i < sizeof($accounts); $i++) { + unset($_SESSION["accountPDF-$i"]); + } exit; } } - // PDF for all accounts - elseif (isset($_POST['pdf_all'])){ + // create for all accounts + elseif ($option == 'ALL') { $list = array(); for ($i = 0; $i < sizeof($this->entries); $i++) { $_SESSION["accountPDF-$i"] = new accountContainer($this->type, "accountPDF-$i"); @@ -557,7 +583,11 @@ class lamList { $list[$i] = $_SESSION["accountPDF-$i"]; } if (sizeof($list) > 0) { - createModulePDF($list,$_POST['pdf_structure']); + createModulePDF($list,$pdfStruct); + for ($i = 0; $i < sizeof($this->entries); $i++) { + // clean session + unset($_SESSION["accountPDF-$i"]); + } exit; } } @@ -577,6 +607,68 @@ class lamList { } } } + + /** + * Shows the page where the user may select the PDF options. + * + * @param String $id account ID + */ + private function showPDFPage($id) { + // search for checkboxes + $selAccounts = array_keys($_POST, "on"); + + $this->listPrintHeader(); + + echo '

' . _('Create PDF') . "

\n"; + echo "
type . "&norefresh=true\" method=\"post\">\n"; + + echo '
'; + 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 ''; + echo ''; + echo '
 
'; + echo ' '; + echo ''; + echo '
'; + echo '
'; + + // hiden inputs for selected accounts + for ($i = 0; $i < sizeof($selAccounts); $i++) { + echo ''; + } + echo ''; + + $this->listPrintFooter(); + } /** * Prints a combobox with possible sub-DNs. @@ -584,7 +676,7 @@ class lamList { protected function listShowOUSelection() { if (sizeof($this->possibleSuffixes) > 1) { echo ("" . _("Suffix") . ": "); - echo ("type . "\" size=1 name=\"suffix\" onchange=\"listOUchanged('" . $this->type . "')\">\n"); for ($i = 0; $i < sizeof($this->possibleSuffixes); $i++) { if ($this->suffix == $this->possibleSuffixes[$i]) { echo ("\n"); @@ -597,7 +689,7 @@ class lamList { } /** - * Prints the create, delete and PDF buttons. + * Prints the create and delete buttons. * * @param boolean $createOnly true if only the create button should be displayed */ @@ -605,7 +697,7 @@ class lamList { echo "\n"; echo "\n"; echo "
\n"; - // add/delete/PDF buttons + // add/delete buttons echo ("type . "\" type=\"submit\" name=\"new\" value=\"" . $this->labels['newEntry'] . "\">\n"); if (!$createOnly) { echo ("type . "\" type=\"submit\" name=\"del\" value=\"" . $this->labels['deleteEntry'] . "\">\n"); @@ -623,23 +715,6 @@ class lamList { echo "
\n"; } - /** - * Prints the PDF button bar. - */ - protected function listPrintPDFButtons() { - echo "
type . "edit\">PDF\n"; - echo ("" . _('PDF structure') . ":      \n"; - echo ("labels['createPDF'] . "\">\n"); - echo " "; - echo ("labels['createPDFAll'] . "\">\n"); - echo "
"; - } - /** * Prints the HTML header. */ @@ -701,9 +776,9 @@ class lamList { echo "}\n"; // OU selection changed - echo "function listOUchanged() {\n"; + echo "function listOUchanged(type) {\n"; echo "selectOU = document.getElementsByName('suffix')[0];\n"; - echo "location.href='list.php?type=" . $this->type . "&suffix=' + selectOU.options[selectOU.selectedIndex].value;\n"; + echo "location.href='list.php?type=' + type + '&suffix=' + selectOU.options[selectOU.selectedIndex].value;\n"; echo "}\n"; echo "//-->\n"; @@ -851,7 +926,8 @@ class lamList { echo '

' . _('Change list settings') . "

\n"; echo "type . "&norefresh=true\" method=\"post\">\n"; - echo "type . "list\" width=\"100%\">\n"; + echo '
'; + echo "
type . "edit\" width=\"100%\">\n"; echo "type . "list\">
\n"; $tabindex = 0; @@ -864,7 +940,7 @@ class lamList { echo "\n"; echo "\n"; echo "
\n"; - echo "
\n"; + echo "\n"; $this->listPrintFooter(); }