X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=include%2Fclass_ppdManager.inc;h=7e416556d036bcf13f8aa23af19f69c783d3b019;hb=97422459b78af5cde7f4359d803f564dafc01507;hp=f9318195185e1993f51d9c1b22e6a718e5fd75bb;hpb=c3300623efba74c4e3dcb380bed77a673ae9581c;p=gosa.git
diff --git a/include/class_ppdManager.inc b/include/class_ppdManager.inc
index f93181951..7e416556d 100644
--- a/include/class_ppdManager.inc
+++ b/include/class_ppdManager.inc
@@ -7,8 +7,12 @@ class ppdManager
function ppdManager($path)
{
+ if(is_dir($path)){
$this->path= $path;
- echo "Path set to $path
";
+ }else{
+ print_red(sprintf(_("PPD manager : The specified path '%s' doesn't exists."),$path));
+ return (false);
+ }
}
@@ -43,20 +47,120 @@ class ppdManager
}
+ function updateAttribute($file, $section, $attribute, $value)
+ {
+ $fsection= false;
+ $fattribute= false;
+ $section= preg_replace('/^\*/', '', $section);
+ $attribute= preg_replace('/^\*/', '', $attribute);
+
+ $rp= @fopen($file, "r");
+ $wp= @fopen("$file.tmp", "w");
+
+
+
+ while (!feof($rp)){
+ $lines[]= fgets($rp, 1024);
+ }
+
+ $ret = "";
+ $done =false;
+ foreach($lines as $nr => $line){
+
+ if (preg_match("/\*OpenGroup:*\s+\**$section\/*/", $line)){
+ $fsection= true;
+ $ret .=$line;
+ continue;
+ }
+
+ /* Change model name .. */
+ if ((preg_match("/^\*".$attribute.":*\s+/",$line)) && ($attribute == "ModelName")){
+ $line= "*$attribute: \"$value\"\n";
+ $done =true;
+ }
+
+ if (($fsection) && ($section != "NO_SECTION")){
+ if (preg_match("/^\*CloseGroup:*\s+\**$section\/*/", $line)){
+ $fsection= false;
+ $ret .=$line;
+ continue;
+ }
+
+
+ if (preg_match("/^\*OpenUI:*\s+\**$attribute\/*/", $line)){
+ $fattribute= true;
+ $ret .= $line;
+ continue;
+ }
+
+ if ($fattribute){
+ if (preg_match("/^\*CloseUI:*\s+\**$attribute\/*/", $line)){
+ $fattribute= false;
+ $ret .= $line;
+ continue;
+ }
+
+ if (preg_match("/^\*Default$attribute:*\s+/", $line)){
+ $line= "*Default$attribute: $value\n";
+ $done =true;
+ }
+ }
+ }else{
+ if (preg_match("/^\*OpenUI:*\s+\**$attribute\/*/", $line)){
+ $fattribute= true;
+ $ret .= $line;
+ continue;
+ }
+
+ if ($fattribute){
+ if (preg_match("/^\*CloseUI:*\s+\**$attribute\/*/", $line)){
+ $fattribute= false;
+ $ret .= $line;
+ continue;
+ }
+
+ if (preg_match("/^\*Default$attribute:*\s+/", $line)){
+ $line= "*Default$attribute: $value\n";
+ $done =true;
+ }
+ }
+ }
+ $ret .=$line;
+ }
+
+ fwrite($wp,$ret);
+
+ fclose($wp);
+ fclose($rp);
+
+ copy("$file.tmp", "$file");
+ unlink("$file.tmp");
+ }
+
+
function saveProperties($ppdFile, $properties)
{
- echo "
"; - print_r ($properties); - echo ""; + if(!is_readable($ppdFile)){ + print_red(sprintf(_("Specified ppd file '%s' can't be opened for reading."),$ppdFile)); + }elseif(!is_writeable(preg_replace("#(^.*/).*$#","\\1",$ppdFile.".tmp"))){ + print_red(sprintf(_("The required tmp file file '%s' can't be opened for writing."),$ppdFile.".tmp")); + }else{ + foreach ($properties as $name => $section){ + foreach ($section as $attribute => $value){ + if (is_array($value)){ + $this->updateAttribute($ppdFile, $name, $attribute, $value['_default']); + } + } + } + } } - - + function loadProperties($ppdFile) { $group= ""; $option= ""; $properties= array(); - + $fh= fopen ($ppdFile, 'r'); while (!feof($fh)) { @@ -78,7 +182,7 @@ class ppdManager trigger_error(_('Group name not unique!'), E_USER_WARNING); continue; } - + // TODO: Symbol values are not supported yet! if (preg_match('/\^/', $line)){ trigger_error(_('Symbol values are not supported yet!'), E_USER_WARNING); @@ -108,7 +212,7 @@ class ppdManager trigger_error(_('Nested options are not supported!'), E_USER_WARNING); continue; } - + // TODO: Symbol values are not supported yet! if (preg_match('/\^/', $line)){ trigger_error(_('Symbol values are not supported yet!'), E_USER_WARNING); @@ -127,13 +231,16 @@ class ppdManager $type= trim(preg_replace('/^[^:]+:\s+/', '', $line)); $name= preg_replace('/:.*$/', '', $name); $option= preg_replace('/:.*$/', '', $option); - + // TODO: PickMany is not supported yet! if (preg_match('/PickMany/i', $type)){ trigger_error(_('PickMany is not supported yet!'), E_USER_WARNING); } - - $properties[$group][$option]= array('_name' => $name, '_type' => $type); + if(empty($group)){ + $properties["NO_SECTION"][$option]= array('_name' => $name, '_type' => $type); + }else{ + $properties[$group][$option]= array('_name' => $name, '_type' => $type); + } continue; } /* Show interest for option parsing */ @@ -150,40 +257,46 @@ class ppdManager /* Default value? */ if (preg_match("@^\*Default$eoption:@", $line)){ $c= preg_replace("@^\*Default$eoption:\s+@", "", $line); - $properties[$group][$option]['_default']= trim(trim($c, '"')); + if(empty($group)){ + $properties["NO_SECTION"][$option]['_default']= trim(trim($c, '"')); + }else{ + $properties[$group][$option]['_default']= trim(trim($c, '"')); + } continue; } /* Possible value? */ if (preg_match("@^\*$eoption\s+@", $line)){ - #*PageSize Letter/US Letter: "<>setpagedevice" +#*PageSize Letter/US Letter: "<>setpagedevice" $c= preg_replace("@^\*$eoption\s+([^/]+).*$@", "$1", $line); $d= preg_replace("@^\*$eoption\s+[^/]+/([^:]+).*$@", "$1", $line); - $properties[$group][$option][trim($c)]= trim($d); + if(empty($group)){ + $properties["NO_SECTION"][$option][trim($c)]= trim($d); + }else{ + $properties[$group][$option][trim($c)]= trim($d); + } continue; } } - } fclose ($fh); - return ($properties); } - + function loadDescription($ppdFile) { $model= ""; $manufacturer= ""; - + $fh= fopen ($ppdFile, 'r'); - while (!feof($fh)) { + while ((!feof($fh))&&($fh)) { /* Read line */ $line= fgets($fh, 256); if (strlen($line) >= 256){ trigger_error(_('Parsing PPD file %s failed - line too long. Trailing characters have been ignored'), E_USER_WARNING); } - + /* Extract interesting informations */ if (preg_match('/^\*Manufacturer:/i', $line)){ $manufacturer= preg_replace('/^\*Manufacturer:\s+"?([^"]+)"?.*$/i', '\1', $line); @@ -225,7 +338,7 @@ class ppdManager return ($this->cachedList); } - + } ?>