added host PDFs
This commit is contained in:
parent
0b9658c891
commit
5d3ab5976f
184
lam/lib/pdf.inc
184
lam/lib/pdf.inc
|
@ -285,6 +285,160 @@ function createUserPDF($accounts) {
|
||||||
return 0; // 0 means everything successful; page(s) printed
|
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 "<html><head><title>";
|
||||||
|
echo _("PDF File");
|
||||||
|
echo "</title>\n".
|
||||||
|
"<link rel=\"stylesheet\" type=\"text/css\" href=\"".$_SESSION['lamurl']."style/layout.css\">\n".
|
||||||
|
"<meta http-equiv=\"pragma\" content=\"no-cache\">\n".
|
||||||
|
"<meta http-equiv=\"cache-control\" content=\"no-cache\">\n".
|
||||||
|
"<meta http-equiv=\"refresh\" content=\"2; URL=$fileurl\">\n".
|
||||||
|
"</head><body>\n".
|
||||||
|
"<a href=\"$fileurl\">";
|
||||||
|
echo _('Please press here if meta-refresh didn\'t work.');
|
||||||
|
echo "</a></body></html>";
|
||||||
|
|
||||||
|
return 0; // 0 means everything successful; page(s) printed
|
||||||
|
}
|
||||||
|
|
||||||
// lamPDF class || For defining own a Header and Footer
|
// lamPDF class || For defining own a Header and Footer
|
||||||
class lamPDF extends FPDF {
|
class lamPDF extends FPDF {
|
||||||
// Print page header
|
// 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);
|
$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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -25,6 +25,8 @@ $Id$
|
||||||
include_once ("../../lib/config.inc");
|
include_once ("../../lib/config.inc");
|
||||||
include_once ("../../lib/ldap.inc");
|
include_once ("../../lib/ldap.inc");
|
||||||
include_once ("../../lib/status.inc");
|
include_once ("../../lib/status.inc");
|
||||||
|
include_once("../../lib/account.inc");
|
||||||
|
include_once("../../lib/pdf.inc");
|
||||||
|
|
||||||
// start session
|
// start session
|
||||||
session_save_path("../../sess");
|
session_save_path("../../sess");
|
||||||
|
@ -42,19 +44,37 @@ $hst_info = $_SESSION['hst_info'];
|
||||||
$hst_units = $_SESSION['hst_units'];
|
$hst_units = $_SESSION['hst_units'];
|
||||||
|
|
||||||
// check if button was pressed and if we have to add/delete a host
|
// 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
|
// add new host
|
||||||
if ($_POST['new_host']){
|
if ($_POST['new_host']){
|
||||||
metaRefresh("../account/hostedit.php");
|
metaRefresh("../account/hostedit.php");
|
||||||
exit;
|
|
||||||
}
|
}
|
||||||
// delete host(s)
|
// delete host(s)
|
||||||
if ($_POST['del_host']){
|
elseif ($_POST['del_host']){
|
||||||
// search for checkboxes
|
// search for checkboxes
|
||||||
$hosts = array_keys($_POST, "on");
|
$hosts = array_keys($_POST, "on");
|
||||||
$_SESSION['delete_dn'] = $hosts;
|
$_SESSION['delete_dn'] = $hosts;
|
||||||
metaRefresh("../delete.php?type=host");
|
metaRefresh("../delete.php?type=host");
|
||||||
}
|
}
|
||||||
|
// 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;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -268,9 +288,18 @@ echo ("</p>\n");
|
||||||
echo ("<p> </p>\n");
|
echo ("<p> </p>\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// add/delete/PDF buttons
|
||||||
echo ("<p align=\"left\">\n");
|
echo ("<p align=\"left\">\n");
|
||||||
echo ("<input type=\"submit\" name=\"new_host\" value=\"" . _("New Host") . "\">\n");
|
echo ("<input type=\"submit\" name=\"new_host\" value=\"" . _("New Host") . "\">\n");
|
||||||
if (sizeof($hst_info) > 0) echo ("<input type=\"submit\" name=\"del_host\" value=\"" . _("Delete Host(s)") . "\">\n");
|
if (sizeof($hst_info) > 0) {
|
||||||
|
echo ("<input type=\"submit\" name=\"del_host\" value=\"" . _("Delete Host(s)") . "\">\n");
|
||||||
|
echo ("<br><br><br>\n");
|
||||||
|
echo "<fieldset><legend><b>PDF</b></legend>\n";
|
||||||
|
echo ("<input type=\"submit\" name=\"pdf_host\" value=\"" . _("Create PDF for selected host(s)") . "\">\n");
|
||||||
|
echo " ";
|
||||||
|
echo ("<input type=\"submit\" name=\"pdf_all\" value=\"" . _("Create PDF for all hosts") . "\">\n");
|
||||||
|
echo "</fieldset>";
|
||||||
|
}
|
||||||
echo ("</p>\n");
|
echo ("</p>\n");
|
||||||
|
|
||||||
echo ("</form>\n");
|
echo ("</form>\n");
|
||||||
|
|
|
@ -67,7 +67,6 @@ if ($_POST['new_user'] || $_POST['del_user'] || $_POST['pdf_user'] || $_POST['pd
|
||||||
// add new user
|
// add new user
|
||||||
if ($_POST['new_user']){
|
if ($_POST['new_user']){
|
||||||
metaRefresh("../account/useredit.php?type=user");
|
metaRefresh("../account/useredit.php?type=user");
|
||||||
exit;
|
|
||||||
}
|
}
|
||||||
// delete user(s)
|
// delete user(s)
|
||||||
elseif ($_POST['del_user']){
|
elseif ($_POST['del_user']){
|
||||||
|
@ -348,13 +347,17 @@ if (in_array("gidnumber", $attr_array)) {
|
||||||
|
|
||||||
echo ("<p> </p>\n");
|
echo ("<p> </p>\n");
|
||||||
|
|
||||||
|
// new/delete/PDF buttons
|
||||||
echo ("<p align=\"left\">\n");
|
echo ("<p align=\"left\">\n");
|
||||||
echo ("<input type=\"submit\" name=\"new_user\" value=\"" . _("New user") . "\">\n");
|
echo ("<input type=\"submit\" name=\"new_user\" value=\"" . _("New user") . "\">\n");
|
||||||
if ($user_count != 0) {
|
if ($user_count != 0) {
|
||||||
echo ("<input type=\"submit\" name=\"del_user\" value=\"" . _("Delete user(s)") . "\">\n");
|
echo ("<input type=\"submit\" name=\"del_user\" value=\"" . _("Delete user(s)") . "\">\n");
|
||||||
echo ("<br><br>\n");
|
echo ("<br><br><br>\n");
|
||||||
|
echo "<fieldset><legend><b>PDF</b></legend>\n";
|
||||||
echo ("<input type=\"submit\" name=\"pdf_user\" value=\"" . _("Create PDF for selected user(s)") . "\">\n");
|
echo ("<input type=\"submit\" name=\"pdf_user\" value=\"" . _("Create PDF for selected user(s)") . "\">\n");
|
||||||
|
echo " ";
|
||||||
echo ("<input type=\"submit\" name=\"pdf_all\" value=\"" . _("Create PDF for all users") . "\">\n");
|
echo ("<input type=\"submit\" name=\"pdf_all\" value=\"" . _("Create PDF for all users") . "\">\n");
|
||||||
|
echo "</fieldset>";
|
||||||
}
|
}
|
||||||
echo ("</p>\n");
|
echo ("</p>\n");
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue