X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=include%2Fclass_debconfTemplate.inc;h=d781321ec8daba9f701e18fa561ff5738a966e41;hb=31ad1193eaf79a30a3e0cd11c509c7f89d5364f7;hp=a900d453f8d02d89697cd6de90bee6ef8e46586d;hpb=ab36df6f879030fcfcb6dc4b94ef50db7790963d;p=gosa.git diff --git a/include/class_debconfTemplate.inc b/include/class_debconfTemplate.inc index a900d453f..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,14 +19,13 @@ class debconf function set_package($package) { $this->package= $package; - return ($this->load()); } - + function set_template_directory($directory) { if (is_dir($directory) && is_readable($directory)){ - $this->template_directory($directory); + $this->template_directory = $directory; return TRUE; } @@ -34,7 +33,7 @@ class debconf return FALSE; } - + function set_language($language) { $this->language= $language; @@ -43,35 +42,44 @@ 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 */ - $name= ""; - $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 */ if ($in_description && !preg_match("/^ /", $line)){ $in_description= FALSE; } - + /* Template header */ if (preg_match("/^Template: /", $line)){ + $post_name ++; $name= trim(preg_replace("/^Template: (.*)$/", "\\1", $line)); - $this->template[$name]= array(); + $this->template[$post_name]['Name'] = $name; + $this->template[$post_name]['Default'] =""; + $got_local_description= FALSE; continue; } @@ -79,22 +87,24 @@ class debconf /* Get type */ if (preg_match("/^Type: /", $line)){ $type= trim(preg_replace("/^Type: (.*)$/", "\\1", $line)); - $this->template[$name]['Type']= $type; + $this->template[$post_name]['Type']= $type; continue; } /* Get default */ if (preg_match("/^Default: /", $line)){ + $this->template[$post_name]['Default']= ""; $default= trim(preg_replace("/^Default: (.*)$/", "\\1", $line)); - $this->template[$name]['Default']= $default; + $this->template[$post_name]['Default']= $default; continue; } /* Get description */ if (!$got_local_description && preg_match("/^Description: /", $line)){ + $this->template[$post_name]['Description']= ""; $description= trim(preg_replace("/^Description: (.*)$/", "\\1", $line)); - $this->template[$name]['Topic']= $description; - $this->template[$name]['Description']= ""; + $this->template[$post_name]['Topic']= $description; + $this->template[$post_name]['Description']= ""; $in_description= TRUE; continue; } @@ -102,79 +112,149 @@ class debconf /* Fill description */ if (!$got_local_description && $in_description){ $description= preg_replace("/^ (.*)$/", "\\1", $line); - $this->template[$name]['Description'].= $description; + $this->template[$post_name]['Description'].= $description; continue; } /* Get local description */ if (preg_match("/^Description-$langcode: /", $line)){ $description= trim(preg_replace("/^Description-$langcode: (.*)$/", "\\1", $line)); - $this->template[$name]['Topic']= $description; + $this->template[$post_name]['Topic']= $description; $in_description= TRUE; $got_local_description= TRUE; - $this->template[$name]['Description']= ""; + $this->template[$post_name]['Description']= ""; continue; } /* Fill local description */ if ($got_local_description && $in_description){ $description= preg_replace("/^ (.*)$/", "\\1", $line); - $this->template[$name]['Description'].= $description; + $this->template[$post_name]['Description'].= $description; continue; } /* Get native choices */ if (preg_match("/^Choices: /", $line)){ $type= trim(preg_replace("/^Choices: (.*)$/", "\\1", $line)); - $this->template[$name]['Choices']= $type; + $this->template[$post_name]['Choices']= $type; } /* Get local choices */ if (preg_match("/^Choices-$langcode: /", $line)){ $type= trim(preg_replace("/^Choices-$langcode: (.*)$/", "\\1", $line)); - $this->template[$name]['Choices-local']= $type; + $this->template[$post_name]['Choices-local']= $type; } } fclose($fh); - $this->has_template= TRUE; + $this->loaded_template= TRUE; + + $tmp= array(); + foreach($this->template as $post_name => $template){ + $template['post_name'] = "post_".$post_name; + $tmp[] = $template; + } + $this->template = $tmp; + 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)); + } + + + /* Check if some fields are posted */ + function PostCheck() + { + /* 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 = ""; + foreach($_POST[$entry['post_name']] as $val){ + $str.= $val.", "; + } + $str = preg_replace("/\,\ $/","",$str); + $this->template[$post_name]['Default'] = $str; + }else{ + $this->template[$post_name]['Default'] = $_POST[$entry['post_name']]; + } + } + } + + 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->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= ""; + if ($this->loaded_template) { + $result= "
|
";
- $result.= "".$data['Topic']." "; - $result.= $data['Description']; - $result.= " | O Yes O No | ";
- $result.= "
";
- $result.= "".$data['Topic']." "; - $result.= $data['Description']; - $result.= " | $choices | "; - $result.= "
";
- $result.= "".$data['Topic']." [......................] "; + $result.= " ".$data['Topic']."".$data['Description']." | "; $result.= $data['Description']; - $result.= " |
";
- $result.= "".$data['Topic']." "; - $result.= $data['Description']; - $result.= " | $choices | "; - $result.= "
";
- $result.= "".$data['Topic']." [......................] "; - $result.= $data['Description']; - $result.= " |