diff --git a/lam/lib/pdf.inc b/lam/lib/pdf.inc index d5a5e4fa..3acbf092 100644 --- a/lam/lib/pdf.inc +++ b/lam/lib/pdf.inc @@ -256,7 +256,7 @@ function createUserPDF($accounts) { } } closedir($h); - + // Close PDF $pdfFile->Close(); // use timestamp as filename so it should be unique. @@ -285,6 +285,160 @@ function createUserPDF($accounts) { return 0; // 0 means everything successful; page(s) printed } +// creates a PDF with host accounts +// $accounts: array of account +function createHostPDF($accounts) { + // Start PDF file + $pdfFile = new lamHostPDF(); + $pdfFile->Open(); + // Write some information into the PDF file + $pdfFile->setFont("arial","",12); + $pdfFile->setTitle("LDAP Account Manager"); + $pdfFile->setSubject(_("Samba-Host information page")); + $pdfFile->setAuthor("LDAP Account Manager Devel-Team -Roland Gruber-"); + $pdfFile->setCreator("LDAP Account Manager (pdf.inc)"); + // print host accounts + $pdfFile->addPage(); + $k = 0; // used to count the already printed accounts per page + for($i = 0; $i < count($accounts); $i++) { + $k++; + $account = $accounts[$i]; + $ypos = $pdfFile->GetY(); + $pdfFile->setFont("times","B",16); + $pdfFile->Write(5,$account->general_username); + $pdfFile->Ln(8); + $pdfFile->setFont("times","",10); + $pdfFile->Write(5,_("Description") . ": "); + $pdfFile->setFont("times","B",10); + $pdfFile->Write(5,$account->general_gecos); + $pdfFile->Ln(5); + $pdfFile->setFont("times","",10); + $pdfFile->Write(5,_("UID") . ": "); + $pdfFile->setFont("times","B",10); + $pdfFile->Write(5,$account->general_uidNumber); + $pdfFile->Ln(5); + $pdfFile->setFont("times","",10); + $pdfFile->Write(5,_("Primary group") . ": "); + $pdfFile->setFont("times","B",10); + $pdfFile->Write(5,$account->general_group); + $pdfFile->Ln(5); + $pdfFile->setFont("times","",10); + $pdfFile->Write(5,_("Domain") . ": "); + $pdfFile->setFont("times","B",10); + unset($domain); + if (is_string($account->smb_domain)) { + $domain = $account->smb_domain; + } + else { + $domain = $account->smb_domain->name; + } + $pdfFile->Write(5,$domain); + $pdfFile->Ln(5); + $pdfFile->setFont("times","",10); + $pdfFile->Write(5,_("DN") . ": "); + $pdfFile->setFont("times","B",9); + $pdfFile->Write(5,$account->general_dn); + // print second column + if ($accounts[$i+1]) { + $k++; + $i++; + $account = $accounts[$i]; + $pdfFile->SetY($ypos); + $pdfFile->SetX(115); + $pdfFile->setFont("times","B",16); + $pdfFile->Write(5,$account->general_username); + $pdfFile->Ln(7); + $pdfFile->SetX(115); + $pdfFile->setFont("times","",10); + $pdfFile->Write(5,_("Description") . ": "); + $pdfFile->setFont("times","B",10); + $pdfFile->Write(5,$account->general_gecos); + $pdfFile->Ln(5); + $pdfFile->SetX(115); + $pdfFile->setFont("times","",10); + $pdfFile->Write(5,_("UID") . ": "); + $pdfFile->setFont("times","B",10); + $pdfFile->Write(5,$account->general_uidNumber); + $pdfFile->Ln(5); + $pdfFile->SetX(115); + $pdfFile->setFont("times","",10); + $pdfFile->Write(5,_("Primary group") . ": "); + $pdfFile->setFont("times","B",10); + $pdfFile->Write(5,$account->general_group); + $pdfFile->Ln(5); + $pdfFile->SetX(115); + $pdfFile->setFont("times","",10); + $pdfFile->Write(5,_("Domain") . ": "); + $pdfFile->setFont("times","B",10); + unset($domain); + if (is_string($account->smb_domain)) { + $domain = $account->smb_domain; + } + else { + $domain = $account->smb_domain->name; + } + $pdfFile->Write(5,$domain); + $pdfFile->Ln(5); + $pdfFile->SetX(115); + $pdfFile->setFont("times","",10); + $pdfFile->Write(5,_("DN") . ": "); + $pdfFile->setFont("times","B",9); + $pdfFile->Write(5,$account->general_dn); + } + // space between two rows + if ($i < count($accounts) - 1) { + $pdfFile->Ln(12); + } + // new page after twelve accounts + if ($k == 12) { + $k = 0; + $pdfFile->addPage(); + } + } + + // Close PDF + $pdfFile->Close(); + + // Delete old PDF older than 3 min + $relpath = $_SESSION['lampath'].'tmp/'; + + $t=time(); + $h=opendir("$relpath"); + while ($file=readdir($h)) { + if (substr($file, -4)=='.pdf') { + $path = $relpath.$file; + if ($t-filemtime($path)>180) + @unlink($path); + } + } + closedir($h); + + // use timestamp as filename so it should be unique. + $time = time(); + $filename = $relpath. $time .'.pdf'; + $fileurl = $_SESSION['lamurl'].'templates/getpdf.php?&f='.$_SESSION['lampath'] .'tmp/'. $time .'.pdf'; + // Save PDF + $pdfFile->Output($filename); + + // Create redirector page + + + echo $_SESSION['header']; + echo ""; + echo _("PDF File"); + echo "\n". + "\n". + "\n". + "\n". + "\n". + "\n". + ""; + echo _('Please press here if meta-refresh didn\'t work.'); + echo ""; + + return 0; // 0 means everything successful; page(s) printed +} + // lamPDF class || For defining own a Header and Footer class lamPDF extends FPDF { // Print page header @@ -311,3 +465,33 @@ class lamPDF extends FPDF { $this->Cell(0,5,_("This document was automatically created by LDAP Account Manager"),0,0,"C",0); } } + +// lamHostPDF class || For defining own a Header and Footer +class lamHostPDF extends FPDF { + // Print page header + function header() { + $imageFile = substr(__FILE__,0,strlen(__FILE__)- 11) . "graphics/printLogo.jpg"; + $this->Image($imageFile,10,10,50,20,"JPG"); + $this->SetFont("arial","B",22); + $this->Cell(170,5,"LDAP Account Manager",0,1,"R",0); + $this->Ln(3); + $this->SetFont("times","",14); + $this->Cell(170,5,"-" . _("Samba-Host information page") . "-",0,0,"R",0); + $this->SetLineWidth(0.8); + $this->Line(10,35,200,35); + $this->Line(10,37,200,37); + $this->SetY(45); + } + + // Print page footer + function footer() { + $this->SetLineWidth(0.8); + $this->Line(10,280,200,280); + $this->Line(10,282,200,282); + $this->SetY(285); + $this->SetFont("arial","B",12); + $this->Cell(0,5,_("This document was automatically created by LDAP Account Manager"),0,0,"C",0); + $this->SetFont("arial","",12); + $this->Cell(0,5,$this->PageNo(),0,1,"R",0); + } +} diff --git a/lam/templates/lists/listhosts.php b/lam/templates/lists/listhosts.php index 5b05abc1..a2dc584e 100644 --- a/lam/templates/lists/listhosts.php +++ b/lam/templates/lists/listhosts.php @@ -25,6 +25,8 @@ $Id$ include_once ("../../lib/config.inc"); include_once ("../../lib/ldap.inc"); include_once ("../../lib/status.inc"); +include_once("../../lib/account.inc"); +include_once("../../lib/pdf.inc"); // start session session_save_path("../../sess"); @@ -42,20 +44,38 @@ $hst_info = $_SESSION['hst_info']; $hst_units = $_SESSION['hst_units']; // check if button was pressed and if we have to add/delete a host -if ($_POST['new_host'] || $_POST['del_host']){ +if ($_POST['new_host'] || $_POST['del_host'] || $_POST['pdf_host'] || $_POST['pdf_all']){ // add new host if ($_POST['new_host']){ metaRefresh("../account/hostedit.php"); - exit; } // delete host(s) - if ($_POST['del_host']){ + elseif ($_POST['del_host']){ // search for checkboxes $hosts = array_keys($_POST, "on"); $_SESSION['delete_dn'] = $hosts; metaRefresh("../delete.php?type=host"); } - exit; + // PDF for selected hosts + elseif ($_POST['pdf_host']){ + // search for checkboxes + $hosts = array_keys($_POST, "on"); + $list = array(); + // load hosts from LDAP + for ($i = 0; $i < sizeof($hosts); $i++) { + $list[$i] = loadhost($hosts[$i]); + } + if (sizeof($list) > 0) createHostPDF($list); + } + // PDF for all users + elseif ($_POST['pdf_all']){ + $list = array(); + for ($i = 0; $i < sizeof($_SESSION['hst_info']); $i++) { + $list[$i] = loadhost($_SESSION['hst_info'][$i]['dn']); + } + if (sizeof($list) > 0) createHostPDF($list); + } + exit; } echo $_SESSION['header']; @@ -268,9 +288,18 @@ echo ("

\n"); echo ("

 

\n"); } +// add/delete/PDF buttons echo ("

\n"); echo ("\n"); -if (sizeof($hst_info) > 0) echo ("\n"); +if (sizeof($hst_info) > 0) { + echo ("\n"); + echo ("


\n"); + echo "

PDF\n"; + echo ("\n"); + echo " "; + echo ("\n"); + echo "
"; +} echo ("

\n"); echo ("\n"); diff --git a/lam/templates/lists/listusers.php b/lam/templates/lists/listusers.php index 0578cdce..7c447e7a 100644 --- a/lam/templates/lists/listusers.php +++ b/lam/templates/lists/listusers.php @@ -67,7 +67,6 @@ if ($_POST['new_user'] || $_POST['del_user'] || $_POST['pdf_user'] || $_POST['pd // add new user if ($_POST['new_user']){ metaRefresh("../account/useredit.php?type=user"); - exit; } // delete user(s) elseif ($_POST['del_user']){ @@ -348,13 +347,17 @@ if (in_array("gidnumber", $attr_array)) { echo ("

 

\n"); +// new/delete/PDF buttons echo ("

\n"); echo ("\n"); if ($user_count != 0) { echo ("\n"); - echo ("

\n"); + echo ("


\n"); + echo "

PDF\n"; echo ("\n"); + echo " "; echo ("\n"); + echo "
"; } echo ("

\n");