index 7b586b28c6d4b994c4fb7845b79b1c212b7c2bcc..d781321ec8daba9f701e18fa561ff5738a966e41 100644 (file)
{
var $package= "";
var $language= "";
- var $has_template= FALSE;
- var $template_directory= "/var/lib/dpkg/info";
+ var $loaded_template= FALSE;
+ var $template_directory= "";
var $template= array();
function set_package($package)
{
$this->package= $package;
- return ($this->load());
}
function load()
{
- /* Reject requests, if parameters are not set */
- if ($this->package == "" || $this->template_directory == ""){
- return (FALSE);
- }
-
- /* Try to load package based template file */
- $filename= preg_replace("/\/+/", "/", $this->template_directory."/".$this->package.".templates");
- if (is_file($filename) && is_readable($filename)){
+ if( TRUE === $this->has_template() ) {
+
+ /* Try to load package based template file */
$this->template= array();
/* Read template array */
- $post_name = 0;
- $langcode = $this->language.".UTF-8";
- $in_description = FALSE;
- $got_local_description= FALSE;
+ $post_name = 0;
+ $langcode = $this->language.".UTF-8";
+ $in_description = FALSE;
+ $got_local_description = FALSE;
+
+ /* get filename */
+ $filename= preg_replace("/\/+/", "/", $this->template_directory."/".$this->package.".templates");
+ /* Check if file is readable */
+ if (!is_file($filename) || !is_readable($filename)){
+ return(FALSE);
+ }
+
+ /* Open file and read content line by line */
$fh= fopen($filename, 'r');
- while (!feof($fh)){
+ /* While the file handle is valid && there is still data to read -> parse configuration file */
+ while ($fh && !feof($fh)){
$line= fgets($fh, 1024);
/* Reset description flag */
}
fclose($fh);
- $this->has_template= TRUE;
+ $this->loaded_template= TRUE;
$tmp= array();
foreach($this->template as $post_name => $template){
return (TRUE);
}
- $this->has_template= FALSE;
+ $this->loaded_template= FALSE;
return (FALSE);
}
function has_template()
{
- return ($this->has_template);
+ /* Reject requests, if parameters are not set */
+ if ($this->package == "" || $this->template_directory == ""){
+ return (FALSE);
+ }
+ $filename= preg_replace("/\/+/", "/", $this->template_directory."/".$this->package.".templates");
+ return (is_file($filename) && is_readable($filename));
}
/* This funtion sets the defualt value */
function SetDefault($var,$val)
{
- if($this->has_template){
+ if ($this->loaded_template) {
foreach($this->template as $key => $tmp){
if($tmp['Name'] == $var ){
$this->template[$key]['Default'] = $val;
/* Display all possible options in html*/
function get_dialog()
{
- if ($this->has_template){
- $result= "<table><tr><td width='50%'> </td><td> </td></tr>";
+ if ($this->loaded_template) {
+ $result= "<table summary=''>";
foreach ($this->template as $post_name => $entry){
$post_name= $data['post_name'];
$result="
<tr>
- <td valign='top'>
- <b>".$data['Topic']."</b><br>".$data['Description']."
+ <td valign='top' style='width:100%'>
+ <h2>".$data['Topic']."</h2>".$data['Description']."
</td>
- <td valign='top' style=\"border-left: 1px solid rgb(160, 160, 160);\">";
+ <td style=\"white-space:nowrap; vertical-align:top; border-left: 1px solid rgb(160, 160, 160);\">";
foreach(array("true","false") as $value){
if($data['Default'] == $value){
- $result.="<input type='radio' name='".$data['post_name']."' value='".$value."' checked>".$value."</option>";
+ $result.="<input type='radio' name='".$data['post_name']."' value='".$value."' checked>"._($value);
}else{
- $result.="<input type='radio' name='".$data['post_name']."' value='".$value."' >".$value."</option>";
+ $result.="<input type='radio' name='".$data['post_name']."' value='".$value."' >"._($value);
}
+ $result.="<br>";
}
$result.= "
{
$post_name= $data['post_name'];
if (preg_match('/\$\{/', $data['Choices'])){
- $choices= array("Need to use some text...");
+ $result= $this->render_string($data);
} else {
$choices= "";
foreach (split(", ", $data['Choices']) as $choice){
$choices[]= $choice;
}
- }
- $result="
- <tr>
- <td valign='top'>
- <b>".$data['Topic']."</b><br>".$data['Description']."
- </td>
- <td valign='top' style=\"border-left: 1px solid rgb(160, 160, 160);\">
- <input type='hidden' name='multi-".$post_name."' value='1'>
- ";
-
- $defs = split(", ",$data['Default']);
- foreach($choices as $value){
- if(in_array($value,$defs)){
- $result.="\n<input name='".$post_name."-multi-".$value."' type='checkbox' value='".htmlentities($value)."' checked>".$value."<br>";
- }else{
- $result.="\n<input name='".$post_name."-multi-".$value."' type='checkbox' value='".htmlentities($value)."'>".$value."<br>";
+
+ $result="
+ <tr>
+ <td valign='top'>
+ <h2>".$data['Topic']."</h2>".$data['Description']."
+ </td>
+ <td valign='top' style=\"white-space:nowrap; border-left: 1px solid rgb(160, 160, 160);\">
+ <input type='hidden' name='multi-".$post_name."' value='1'>
+ ";
+
+ $defs = split(", ",$data['Default']);
+ foreach($choices as $value){
+ if(in_array($value,$defs)){
+ $result.="\n<input name='".$post_name."-multi-".$value."' type='checkbox' value='".htmlentities($value)."' checked>".$value."<br>";
+ }else{
+ $result.="\n<input name='".$post_name."-multi-".$value."' type='checkbox' value='".htmlentities($value)."'>".$value."<br>";
+ }
}
- }
- $result .= "</td>
- </tr>
- ";
+ $result .= "</td>
+ </tr>
+ ";
+ }
return ($result);
}
{
$result= "";
$result.= "<tr><td valign='top'>";
- $result.= "<b>".$data['Topic']."<br>".$data['Description']."</td><td style=\"border-left: 1px solid rgb(160, 160, 160);\"> <input type='text' name='".$data['post_name']."' value='".$data['Default']."'></b><br><br>";
+ $result.= "<h2>".$data['Topic']."</h2>".$data['Description']."</td><td style=\"white-space:nowrap; border-left: 1px solid rgb(160, 160, 160);\"> <input type='text' name='".$data['post_name']."' value='".$data['Default']."'></b><br><br>";
$result.= $data['Description'];
$result.= "</td>";
<tr>
<td valign='top'>
- <b>".$data['Topic']."</b><br>".$data['Description']."
+ <h2>".$data['Topic']."</h2>".$data['Description']."
</td>
- <td valign='top' style=\"border-left: 1px solid rgb(160, 160, 160);\">
+ <td valign='top' style=\"white-space:nowrap; border-left: 1px solid rgb(160, 160, 160);\">
";
foreach($choices as $value){
$result= "
<tr>
<td valign='top'>
- <b>".$data['Topic']."</b> <br>".$data['Description']."
+ <h2>".$data['Topic']."</h2>".$data['Description']."
</td>
- <td style=\"border-left: 1px solid rgb(160, 160, 160);\">
- <input type='text' name='".$data['post_name']."' value='".$data['Default']."'>
+ <td style=\"white-space:nowrap; border-left: 1px solid rgb(160, 160, 160);\" valign='top'>
+ <input type='text' name='".$data['post_name']."' value='".$data['Default']."' style='width:300px;'>
</td>
</tr>
";
}
-# Example:
-#$debconf= new debconf("libnss-ldap", "de");
-#echo $debconf->get_dialog();
// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
?>