diff --git a/lam/config/pdf/logos/printLogo.jpg b/lam/config/pdf/logos/printLogo.jpg new file mode 100644 index 00000000..45e0b799 Binary files /dev/null and b/lam/config/pdf/logos/printLogo.jpg differ diff --git a/lam/lib/pdf.inc b/lam/lib/pdf.inc index 762d96a8..6595db55 100644 --- a/lam/lib/pdf.inc +++ b/lam/lib/pdf.inc @@ -54,13 +54,14 @@ function createModulePDF($accounts,$pdf_structure="default.xml") { } // Get PDF structure from xml file - $structure = getStructure($account_type,$pdf_structure); + $load = getStructure($account_type,$pdf_structure); + $structure = $load['structure']; // The decimal separator must be a dot in order to write pdf-files setlocale(LC_NUMERIC, "C"); // Create a new PDF file acording to the account type - $pdf = new LamPDF($account_type); + $pdf = new LamPDF($account_type,$load['page_definitions']); // Loop over each account and add a new page in the PDF file for it foreach($accounts as $account) { @@ -178,14 +179,18 @@ function getStructure($scope,$pdf_structure) { $border = array(); $structure = array(); - $pdf_entries = $xml[1]['PDF']; - while(($index = current($pdf_entries)) != null) { - $border['start'] = $index; - next($pdf_entries); - $border['end'] = current($pdf_entries); - next($pdf_entries); + $complete_page_definitions = array('filename' => 'printLogo.jpg', 'headline' => 'LDAP Account Manager', 'margin-top' => '10.0', 'margin-bottom' => '20.0', 'margin-left' => '10.0', 'margin-right' => '10.0'); + if($xml[0][$xml[1]['PDF'][0]]['attributes']['TYPE'] == $scope) { + $border['start'] = $xml[1]['PDF'][0]; + $page_definitions = $xml[0][$xml[1]['PDF'][0]]['attributes']; + foreach($page_definitions as $key => $value) { + $complete_page_definitions[strtolower($key)] = $value; + unset($page_definitions[$key]); + } + $border['end'] = $xml[1]['PDF'][1]; } - return array_slice($xml[0],$border['start'] + 1,$border['end'] - ($border['start'] + 1)); + $structure = array_slice($xml[0],$border['start'] + 1,$border['end'] - ($border['start'] + 1)); + return array('structure' => $structure, 'page_definitions' => $complete_page_definitions); } function getSectionHeadline($line) { @@ -325,10 +330,18 @@ function processAttributes($attrs,$return = array()) { // lamPDF class || For defining own a Header and Footer class lamPDF extends FPDF { - function lamPDF($account_type = "User") { + var $page_definitions; + + function lamPDF($account_type = "User",$page_definitions = array()) { // Call constructor of superclass $this->FPDF('P','mm','A4'); + $this->page_definitions = $page_definitions; + + echo "
";
+		print_r($this->page_definitions);
+		echo "
"; + // Decide which PDF file type we shall use switch($account_type) { case "user": @@ -345,24 +358,43 @@ class lamPDF extends FPDF { // Open PDF file and write some basic information $this->Open(); $this->setFont("arial","",12); - $this->setTitle("LDAP Account Manager"); + $this->setTitle($this->page_definitions['headline']); $this->setSubject($subject); $this->setAuthor("LDAP Account Manager Devel-Team -Michael Duergner-"); $this->setCreator("LDAP Account Manager (pdf.inc)"); + //$this->setMargins(10.0,10.0,10.0); + $this->setMargins($this->page_definitions['margin-left'],$this->page_definitions['margin-top'],$this->page_definitions['margin-right']); + $this->setAutoPageBreak(true,$this->page_definitions['margin-bottom']); } // Print page header function header() { - $imageFile = substr(__FILE__,0,strlen(__FILE__)- 11) . "graphics/printLogo.jpg"; - $this->Image($imageFile,10,10,50,20,"JPG"); + if($this->page_definitions['filename'] != 'none') { + $imageFile = substr(__FILE__,0,strlen(__FILE__)- 11) . "config/pdf/logos/" . $this->page_definitions['filename']; + $width = $this->page_definitions['logo-width']; + $height = $this->page_definitions['logo-height']; + if($this->page_definitions['logo-max'] == true) { + if(($width / $height) <= 2.5) { + $factor = 20 / $height; + $width = $factor * $width; + $height = 20; + } + else { + $factor = 50 / $width; + $height = $factor * $height; + $width = 50; + } + } + $this->Image($imageFile,10,10,$width,$height,"JPG"); + } $this->SetFont("arial","B",22); - $this->Cell(170,5,"LDAP Account Manager",0,1,"R",0); + $this->Cell(170,5,$this->page_definitions['headline'],0,1,"R",0); $this->Ln(3); $this->SetFont("times","",14); $this->Cell(170,5,"- " . $this->subject . " -",0,0,"R",0); $this->SetLineWidth(0.8); - $this->Line(10,40,200,40); - $this->Line(10,42,200,42); + $this->Line(10,$this->page_definitions['margin-top'] + 30,200,$this->page_definitions['margin-top'] + 30); + $this->Line(10,$this->page_definitions['margin-top'] + 32,200,$this->page_definitions['margin-top'] + 32); $this->SetY(50); } diff --git a/lam/lib/pdfstruct.inc b/lam/lib/pdfstruct.inc index 63bae5e9..fb75bddb 100644 --- a/lam/lib/pdfstruct.inc +++ b/lam/lib/pdfstruct.inc @@ -42,23 +42,30 @@ function loadPDFStructureDefinitions($scope='user', $definition='default.xml') { $border = array(); $structure = array(); - $pdf_entries = $xml[1]['PDF']; $border[$current] = array(); - while(($index = current($pdf_entries)) != null) { - if($xml[0][$index]['attributes']['TYPE'] == $scope) { - $border['start'] = $index; - next($pdf_entries); - $border['end'] = current($pdf_entries); + $page_definitions = array(); + if($xml[0][$xml[1]['PDF'][0]]['attributes']['TYPE'] == $scope) { + $border['start'] = $xml[1]['PDF'][0]; + $page_definitions = $xml[0][$xml[1]['PDF'][0]]['attributes']; + foreach($page_definitions as $key => $value) { + $page_definitions[strtolower($key)] = $value; + unset($page_definitions[$key]); } - next($pdf_entries); + $border['end'] = $xml[1]['PDF'][1]; } $structure = array_slice($xml[0],$border['start'] + 1,$border['end'] - ($border['start'] + 1)); - return $structure; + return array('structure' => $structure, 'page_definitions' => $page_definitions); } function savePDFStructureDefinitions($scope,$definition) { $handle = fopen($_SESSION['lampath'] . 'config/pdf/' . $scope . '/' . $definition,'w'); - $file = "\n"; + $pdf_attributes = ''; + foreach($_SESSION['currentPageDefinitions'] as $key => $value) { + if($key != 'TYPE') { + $pdf_attributes .= ' ' . $key . '="' . $value . '"'; + } + } + $file = '\n"; foreach($_SESSION['currentPDFStructure'] as $entry) { $ident = ''; for($i=0;$i<$entry['level'] -1;$i++) { @@ -93,4 +100,20 @@ function savePDFStructureDefinitions($scope,$definition) { function deletePDFStructureDefinition($scope,$definition) { return unlink($_SESSION['lampath'] . 'config/pdf/' . $scope . '/' . $definition . '.xml'); } + +function getAvailableLogos() { + $return = array(); + $dirPath = $_SESSION['lampath'] . '/config/pdf/logos/'; + $dirHandle = opendir($dirPath); + while($file = readdir($dirHandle)) { + if(!is_dir($file) && $file != '.' && $file != '..' && preg_match('/\\.(jpg|png)$/',$file)) { + $infos = getimagesize($dirPath . $file); + if($infos[0] <= 400 && $infos[1] <= 60) { + array_push($return, array('filename' => $file, 'infos' => $infos)); + } + } + } + sort($return); + return $return; +} ?> \ No newline at end of file diff --git a/lam/templates/pdfedit/pdfmain.php b/lam/templates/pdfedit/pdfmain.php index 67b4181f..74f10e8d 100644 --- a/lam/templates/pdfedit/pdfmain.php +++ b/lam/templates/pdfedit/pdfmain.php @@ -38,11 +38,12 @@ setlanguage(); if(isset($_SESSION['currentPDFStructure'])) { unset($_SESSION['currentPDFStructure']); unset($_SESSION['availablePDFFields']); + unset($_SESSION['currentPageDefinitions']); session_unregister('currentPDFStructure'); session_unregister('availablePDFFields'); + session_unregister('currentPageDefinitions'); } - // check if user is logged in, if not go to login if (!$_SESSION['ldap'] || !$_SESSION['ldap']->server()) { metaRefresh("../login.php"); diff --git a/lam/templates/pdfedit/pdfpage.php b/lam/templates/pdfedit/pdfpage.php index 32725007..6cbf2eec 100644 --- a/lam/templates/pdfedit/pdfpage.php +++ b/lam/templates/pdfedit/pdfpage.php @@ -44,6 +44,9 @@ if (!$_SESSION['ldap'] || !$_SESSION['ldap']->server()) { // Write $_POST variables to $_GET when form was submitted via post if(isset($_POST['type'])) { $_GET = $_POST; + if($_POST['pdfname'] == '') { + unset($_GET['pdfname']); + } } // Abort and go back to main pdf structure page @@ -297,17 +300,89 @@ elseif(isset($_GET['down'])) { $_SESSION['currentPDFStructure'][$_GET['down'] + 1] = $tmp; } } +// TODO implement page handling +elseif(isset($_POST['page'])) { + if($_POST['logoFile'] != 'printLogo.jpg' && $_POST['logoFile'] != $_SESSION['currentPageDefinitions']['filename']) { + $_SESSION['currentPageDefinitions']['filename'] = $_POST['logoFile']; + } + if($_POST['logo-width'] != '50' && $_POST['logo-width'] != $_SESSION['currentPageDefinitions']['logo-width']) { + if($_POST['logo-width'] <= 50 && $_POST['logo-width'] > 0) { + $_SESSION['currentPageDefinitions']['logo-width'] = $_POST['logo-width']; + } + } + if($_POST['logo-height'] != '20' && $_POST['logo-height'] != $_SESSION['currentPageDefinitions']['logo-height']) { + if($_POST['logo-height'] <= 20 && $_POST['logo-height'] > 0) { + $_SESSION['currentPageDefinitions']['logo-height'] = $_POST['logo-height']; + } + } + if(isset($_POST['logo-max']) && !isset($_SESSION['currentPageDefinitions']['logo-max'])) { + $_SESSION['currentPageDefinitions']['logo-max'] = true; + } + if($_POST['headline'] != 'LDAP Account Manager' && $_POST['headline'] != $_SESSION['currentPageDefinitions']['headline']) { + $_SESSION['currentPageDefinitions']['headline'] = $_POST['headline']; + } + if($_POST['margin-top'] != '10.0' && $_SESSION['currentPageDefinitions']['margin-top'] != $_POST['margin-top']) { + $_SESSION['currentPageDefinitions']['margin-top'] = $_POST['margin-top']; + } + if($_POST['margin-bottom'] != '20.0' && $_SESSION['currentPageDefinitions']['margin-bottom'] != $_POST['margin-bottom']) { + $_SESSION['currentPageDefinitions']['margin-bottom'] = $_POST['margin-bottom']; + } + if($_POST['margin-left'] != '10.0' && $_SESSION['currentPageDefinitions']['margin-left'] != $_POST['margin-left']) { + $_SESSION['currentPageDefinitions']['margin-left'] = $_POST['margin-left']; + } + if($_POST['margin-right'] != '10.0' && $_SESSION['currentPageDefinitions']['margin-right'] != $_POST['margin-right']) { + $_SESSION['currentPageDefinitions']['margin-right'] = $_POST['margin-right']; + } + if(isset($_POST['defaults'])) { + foreach($_POST['defaults'] as $default) { + switch($default) { + case 'logoFile': + unset($_SESSION['currentPageDefinitions']['filename']); + break; + case 'logoSize': + unset($_SESSION['currentPageDefinitions']['logo-width']); + unset($_SESSION['currentPageDefinitions']['logo-height']); + unset($_SESSION['currentPageDefinitions']['logo-max']); + break; + case 'headline': + unset($_SESSION['currentPageDefinitions']['headline']); + break; + case 'margin-top': + unset($_SESSION['currentPageDefinitions']['margin-top']); + break; + case 'margin-bottom': + unset($_SESSION['currentPageDefinitions']['margin-bottom']); + break; + case 'margin-left': + unset($_SESSION['currentPageDefinitions']['margin-left']); + break; + case 'margin-right': + unset($_SESSION['currentPageDefinitions']['margin-right']); + break; + default: + break; + } + } + if(count($_SESSION['currentPageDefinitions']['margin']) == 0) { + unset($_SESSION['currentPageDefinitions']['margin']); + } + } +} // Load PDF structure from file if it is not defined in session if(!isset($_SESSION['currentPDFStructure'])) { // Load structure file to be edit if($_GET['edit']) { - $_SESSION['currentPDFStructure'] = loadPDFStructureDefinitions($_GET['type'],$_GET['edit']); + $load = loadPDFStructureDefinitions($_GET['type'],$_GET['edit']); + $_SESSION['currentPDFStructure'] = $load['structure']; + $_SESSION['currentPageDefinitions'] = $load['page_definitions']; $_GET['pdfname'] = substr($_GET['edit'],0,strlen($_GET['edit']) - 4); } // Load default structure file when creating a new one else { - $_SESSION['currentPDFStructure'] = loadPDFStructureDefinitions($_GET['type']); + $load = loadPDFStructureDefinitions($_GET['type']); + $_SESSION['currentPDFStructure'] = $load['structure']; + $_SESSION['currentPageDefinitions'] = $load['page_definitions']; } } @@ -330,8 +405,15 @@ foreach($_SESSION['availablePDFFields'] as $module => $values) { } $modules = join(',',$modules); +$logoFiles = getAvailableLogos(); +$logos = '\n"; +foreach($logoFiles as $logoFile) { + $logos .= "\t\t\t\t\t\t\t\t\t\t\t\n"; +} + // print header echo $_SESSION['header']; +// TODO Change enctype of form ?> LDAP Account Manager @@ -340,12 +422,155 @@ echo $_SESSION['header'];
+ + + + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
+ : + + + + + + +
+ +

+

+ + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+ > + + +
+
+

+
+ +
+ : + + + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
+ : + + + + +
+ : + + + + +
+ : + + + + +
+ : + + + + +
+
+
+
+
+
+
- +