parse($file); $border = array(); $structure = array(); $complete_page_definitions = array('filename' => 'printLogo.jpg', 'headline' => 'LDAP Account Manager'); 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]; } $structure = array_slice($xml[0],$border['start'] + 1,$border['end'] - ($border['start'] + 1)); return array('structure' => $structure, 'page_definitions' => $complete_page_definitions); } /** * Saves PDF structure definitions to XML file in format: ..xml * * @param string $scope account type * @param string $definition Name of definition * @return string "no perms" if access denied or "ok". */ function savePDFStructureDefinitions($scope,$definition) { if (!preg_match('/[a-zA-Z0-9\-\_]+/',$definition)) return 'no perms'; if (!preg_match('/[a-zA-Z]+/',$scope)) return 'no perms'; $struct_file = dirname(__FILE__) . '/../config/pdf/' . $definition . '.' . $scope . '.xml'; if(!is_writable(dirname(__FILE__) . '/../config/pdf/')) { return 'no perms'; } else { $handle = @fopen($struct_file,'w'); if (!$handle) return 'no perms'; $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++) { $ident .= "\t"; } $attributes = ''; if(isset($entry['attributes']) && is_array($entry['attributes'])) { foreach($entry['attributes'] as $key => $value) { $attributes .= ' ' . strtolower($key) . '="' . $value . '"'; } } if($entry['type'] == 'open') { $file .= $ident . '<' . strtolower($entry['tag']) . $attributes . ">\n"; } elseif($entry['type'] == 'close') { $file .= $ident . '\n"; } elseif($entry['type'] == 'complete') { if(isset($entry['value'])) { $file .= $ident . '<' . strtolower($entry['tag']) . $attributes . '>' . $entry['value'] . '\n"; } else { $file .= $ident . '<' . strtolower($entry['tag']) . $attributes . " />\n"; } } } $file .= ""; fwrite($handle,$file); fclose($handle); return 'ok'; } } /** * Deletes XML file with PDF structure definitions. * * @param string $scope account type * @param string $definition Name of definition to delete * * @return boolean True if file was deleted or false if a problem occured. */ function deletePDFStructureDefinition($scope, $definition) { if (!preg_match('/[a-zA-Z0-9\-\_]+/',$definition)) return false; if (!preg_match('/[a-zA-Z]+/',$scope)) return false; $file = dirname(__FILE__) . '/../config/pdf/' . $definition . '.' . $scope . '.xml'; if(is_file($file) && is_writable($file)) { return unlink($file); } else { return false; } } /** * This function returns an array with all aviliable logo images. * * @return array list of logo files */ function getAvailableLogos() { $return = array(); $dirPath = dirname(__FILE__) . '/../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] <= 2000 && $infos[1] <= 300) { array_push($return, array('filename' => $file, 'infos' => $infos)); } } } sort($return); return $return; } ?>