X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=include%2Fclass_debconfTemplate.inc;h=d781321ec8daba9f701e18fa561ff5738a966e41;hb=895712accc11cf9defc13cdbc64a6b3c7e7e548a;hp=7438df7ca349b0e2c79fc068bb8012a2a15f2a3f;hpb=c6f03516d30bf1c806d97541e1729bc57573c5cd;p=gosa.git diff --git a/include/class_debconfTemplate.inc b/include/class_debconfTemplate.inc index 7438df7ca..d781321ec 100644 --- a/include/class_debconfTemplate.inc +++ b/include/class_debconfTemplate.inc @@ -4,8 +4,8 @@ class debconf { 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(); @@ -19,7 +19,6 @@ class debconf function set_package($package) { $this->package= $package; - return ($this->load()); } @@ -43,25 +42,30 @@ class debconf 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 */ @@ -144,7 +148,7 @@ class debconf } fclose($fh); - $this->has_template= TRUE; + $this->loaded_template= TRUE; $tmp= array(); foreach($this->template as $post_name => $template){ @@ -156,14 +160,19 @@ class debconf 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)); } @@ -172,10 +181,10 @@ class debconf { /* Walk through all template variables */ foreach($this->template as $post_name => $entry){ - + /* Check if this var is set*/ if(isset($_POST[$entry['post_name']])){ - + /* special handling for arrays */ if(is_array($_POST[$entry['post_name']])){ $str = ""; @@ -189,14 +198,27 @@ class debconf } } } - + + foreach($this->template as $post_name => $entry){ + if(isset($_POST["multi-".$entry['post_name']])){ + $this->template[$post_name]['Default']= ""; + foreach($_POST as $name => $value){ + if(preg_match("/".$entry['post_name']."-multi-/",$name)){ + $this->template[$post_name]['Default'] .= $value.", "; + } + } + $this->template[$post_name]['Default'] = preg_replace("/, $/","",$this->template[$post_name]['Default']); + } + } + + } /* 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; @@ -209,8 +231,8 @@ class debconf /* Display all possible options in html*/ function get_dialog() { - if ($this->has_template){ - $result= ""; + if ($this->loaded_template) { + $result= ""; foreach ($this->template as $post_name => $entry){ @@ -222,13 +244,17 @@ class debconf /* Produce type specific output */ $fn= "render_".$entry['Type']; - $result.= $this->$fn($entry); + $str = $this->$fn($entry); + if(!empty($str)){ + $result.=$str.""; + } } else { //php_error(E_WARNING, "An unknown type has been specified in the debconf template. Please fix."); } } - $result .= ""; + + $result .= "

 

"; return ($result); } else { return _("This package has no debconf options."); @@ -241,31 +267,26 @@ class debconf $post_name= $data['post_name']; $result=" - - - - - - -
- ".$data['Topic']." + +

".$data['Topic']."

".$data['Description']."
"; + "; foreach(array("true","false") as $value){ if($data['Default'] == $value){ - $result.="".$value.""; + $result.=""._($value); }else{ - $result.="".$value.""; + $result.=""._($value); } + $result.="
"; } $result.= "
".$data['Description']." -
"; + "; - $result.= "

 

"; return ($result); } @@ -274,44 +295,36 @@ class debconf { $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=" - - - - + + - - - - -
- ".$data['Topic']." - -
+

".$data['Topic']."

".$data['Description']." +
+ + "; + + $defs = split(", ",$data['Default']); + foreach($choices as $value){ + if(in_array($value,$defs)){ + $result.="\n".$value."
"; + }else{ + $result.="\n".$value."
"; + } } - } - $result.= " - -
".$data['Description']." -
"; - $result.= "

 

"; + $result .= " + + "; + } return ($result); } @@ -327,12 +340,11 @@ class debconf function render_password($data) { - $result= ""; + $result= ""; $result.= "
"; - $result.= "".$data['Topic']." 

"; + $result.= "

".$data['Topic']."

".$data['Description']."
 

"; $result.= $data['Description']; - $result.= "
"; - $result.= "

 

"; + $result.= ""; return ($result); } @@ -353,32 +365,27 @@ class debconf $result=" - + - - - - -
- ".$data['Topic']." +

".$data['Topic']."

".$data['Description']."
- + "; foreach($choices as $value){ if($data['Default'] == $value){ - $result.="\n"; + $result.="\n".htmlentities($value)."
"; }else{ - $result.="\n"; + $result.="\n".htmlentities($value)."
"; } } $result.= " - -
".$data['Description']." +
"; - $result.= "

 

"; + "; return ($result); } @@ -386,22 +393,16 @@ class debconf function render_string($data) { - $result= " + $result= " - - - - -
- ".$data['Topic']."  +

".$data['Topic']."

".$data['Description']."
- -
- ".$data['Description']." + +
"; - $result.= "

 

"; + "; return ($result); } @@ -422,9 +423,6 @@ class debconf } -# Example: -#$debconf= new debconf("libnss-ldap", "de"); -#echo $debconf->get_dialog(); // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: ?>