Code

Applied changes from extern
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 24 Feb 2009 12:06:50 +0000 (12:06 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 24 Feb 2009 12:06:50 +0000 (12:06 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@13449 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-plugins/goto/admin/systems/goto/class_printGeneric.inc
gosa-plugins/goto/admin/systems/ppd/class_ppdManager.inc
gosa-plugins/goto/admin/systems/ppd/class_printerPPDDialog.inc
gosa-plugins/goto/admin/systems/ppd/class_printerPPDSelectionDialog.inc

index e12c79d6b9d022905079d7e4dfc58716a7910bc4..377f6c4b1c5029e83c90211e85d3f3ceac232bd4 100644 (file)
@@ -512,7 +512,8 @@ class printgeneric extends plugin
         if((!file_exists($path.$this->gotoPrinterPPD))){
           $smarty->assign("driverInfo", "<b>".sprintf(_("Your currently selected PPD file '%s' doesn't exist."),$path.$this->gotoPrinterPPD)."</b>");
         }else{
-          $smarty->assign("driverInfo", $ppdManager->loadDescription($path.$this->gotoPrinterPPD));
+          $ppdDesc = $ppdManager->loadDescription($path.$this->gotoPrinterPPD);
+          $smarty->assign("driverInfo", $ppdDesc['name']);
         }
       }else{
         $smarty->assign("driverInfo", _("Not defined"));
index fe72164d2ea787168b9528d62d5b275d3fec9439..ade6e78f62ed9127de6d7a0568c20f1d151458d5 100644 (file)
@@ -291,10 +291,9 @@ class ppdManager
 
        function loadDescription($ppdFile)
        {
-               $model= "";
-               $manufacturer= "";
-
-               
+       
+    $ppdDesc = array();
+       
                /* Only parse complete PPD file again, if it was changed */
                $modified = filemtime($ppdFile);
                if(isset($this->cachedList[$ppdFile]) && isset($this->timestamps[$ppdFile]) && $modified == $this->timestamps[$ppdFile]){
@@ -315,26 +314,30 @@ class ppdManager
 
                        /* Extract interesting informations */
                        if (preg_match('/^\*Manufacturer:/i', $line)){
-                               $manufacturer= preg_replace('/^\*Manufacturer:\s+"?([^"]+)"?.*$/i', '\1', $line);
+        $ppdDesc['manufacturer'] = trim(preg_replace('/^\*Manufacturer:\s+"?([^"]+)"?.*$/i', '\1',    $line));
                        }
                        if (preg_match('/^\*ModelName:/i', $line)){
-                               $model= preg_replace('/^\*ModelName:\s+"?([^"]+)"?.*$/i', '\1', $line);
+        $ppdDesc['model'] = trim(preg_replace('/^\*ModelName:\s+"?([^"]+)"?.*$/i', '\1', $line));
                        }
 
                        /* Got everything we need? Skip rest for speed reasons... */
-                       if ($model != '' && $manufacturer != ''){
+      if (isset($ppdDesc['manufacturer'])  && isset($ppdDesc['model'])){
                                break;
                        }
                }
                gzclose ($fh);
 
+    /* If model contains manufacturer strip it */
+    $ppdDesc['model'] = str_replace($ppdDesc['manufacturer']." ", '', $ppdDesc['model']);
+
                /* Write out a notice that the PPD file seems to be broken if we can't
                   extract any usefull informations */
-               if ($model == '' || $manufacturer == ''){
+    if ($ppdDesc['manufacturer'] == '' || $ppdDesc['model'] == ''){
                        trigger_error(sprintf(_('Parsing PPD file %s failed - no information found.'), $ppdFile), E_USER_WARNING);
                }
 
-               return ($manufacturer.' - '.$model);
+    $ppdDesc['name'] = $ppdDesc['manufacturer'] . " - " . $ppdDesc['model'];
+    return $ppdDesc;
        }
 
 
index 2f176e75a93eed251cc7bce270434166127c9ae2..8fa944bcd504cafdd2f1abf34f5f112b62e7cd88 100644 (file)
@@ -71,15 +71,14 @@ class printerPPDDialog extends plugin
         if(!file_exists($this->pathToPPD.$this->pathToModified.$ppdfile)){
           msg_dialog::display(_("PPD error"), sprintf(_("Cannot open PPD '%s'!"), $ppdfile), ERROR_DIALOG);
         }else{
-          $res  = $this->ppdManager->loadDescription($this->pathToPPD.$this->pathToModified.$ppdfile);
-          if($res){
-            $tmp = split("\n",$res);
-            $tmp3 = array(); 
-            $tmp3['name']   = trim(preg_replace("/^\-/","",trim($tmp[1])));
-            $tmp3['link']   = $ppdfile;
-            $tmp3['ppd']    = $res;
+          $ppdDesc = $this->ppdManager->loadDescription($this->pathToPPD.$this->pathToModified.$ppdfile);
+          if($ppdDesc){            
+            $selectedPPD = array(); 
+            $selectedPPD['name']   = $ppdDesc['name'];
+            $selectedPPD['link']   = $ppdfile;
+            $selectedPPD['ppd']    = $ppdDesc;
           }    
-          $this->selectedPPD = $tmp3;
+          $this->selectedPPD = $selectedPPD;
         }
       }
     }
@@ -223,12 +222,11 @@ class printerPPDDialog extends plugin
       msg_dialog::display(_("PPD error"), msgPool::cannotReadFile($AbsoluteSourceName), ERROR_DIALOG);
       return;
     }
-    $res  = $this->ppdManager->loadDescription($AbsoluteSourceName);
-    if($res){
-      $tmp = split("\n",$res);
-      $Name   = trim(preg_replace("/^\-/","",trim($tmp[1])));
-      $Vendor = trim($tmp[0]);
-      $Model  = trim(preg_replace("/".$Vendor."/","",$Name));
+    $ppdDesc  = $this->ppdManager->loadDescription($AbsoluteSourceName);
+    if($ppdDesc){
+      $Name   = $ppdDesc['name'];
+      $Vendor = $ppdDesc['manufacturer'];
+      $Model  = $ppdDesc['model'];
     }    
 
     $PrinterName  = $this->cn."-".preg_replace("/[^a-z0-9-_\.]/i","_",$Name);
@@ -277,12 +275,11 @@ class printerPPDDialog extends plugin
     $this->getPrinterReload();
 
     /* Get Description from ppd, & parse out some informations */   
-    $res  = @$this->ppdManager->loadDescription($_PathOnHdd);
-    if($res){
-      $tmp = split("\n",$res);
-      $name   = @trim(preg_replace("/^\-/","",trim($tmp[1])));
-      $vendor = @trim($tmp[0]);
-      $model  = @trim(preg_replace("/".$vendor."/","",$name));
+    $ppdDesc  = @$this->ppdManager->loadDescription($_PathOnHdd);
+    if($ppdDesc){
+      $name   = $ppdDesc['name'];
+      $vendor = $ppdDesc['manufacturer'];
+      $model  = $ppdDesc['model'];
     }    
 
     /* Check if parse was successfull */
@@ -368,18 +365,18 @@ class printerPPDDialog extends plugin
 
       /* Sort all available files, and create header (Vendor index) */
       foreach($tmp as $file=>$ppd){
-
+               
         if(preg_match("#".$this->pathToModified."#",$file)) continue;
 
-        $tmp2 = split("\n",$ppd);
-        if(!isset($this->ppdListHeader[$tmp2[0]])){
-          $this->ppdListHeader[$tmp2[0]]=0;
+        if(!isset($this->ppdListHeader[$ppd['manufacturer']])){
+          $this->ppdListHeader[$ppd['manufacturer']]=0;
         }
-        $tmp3['name']   =preg_replace("/^ -/","",$tmp2[1]." - ".$tmp2[2]);
+       
+        $tmp3['name']   =$ppd['name'];
         $tmp3['link']   =$file;
         $tmp3['ppd']    =$ppd;
-        $this->ppdListHeader[$tmp2[0]]++;
-        $this->ppdList[$tmp2[0]][preg_replace("/^ -/","",$tmp2[1]." - ".$tmp2[2])]=$tmp3;
+        $this->ppdListHeader[$ppd['manufacturer']]++;
+        $this->ppdList[$ppd['manufacturer']][$ppd['name']]=$tmp3;
       }
     }
   }
@@ -428,12 +425,12 @@ class printerPPDDialog extends plugin
   {
     $str = "none";
     if(!empty($this->selectedPPD)){
-      $str = $this->ppdManager->loadDescription($this->pathToPPD.$this->pathToModified.$this->selectedPPD['link']);
+      $ppdDesc = $this->ppdManager->loadDescription($this->pathToPPD.$this->pathToModified.$this->selectedPPD['link']);
+      $str = $ppdDesc['name'];
     }
     return($str) ; 
   }
 
-
   /* Display all options from the selected ppd file */
   function generateProperties()
   { 
index 8d109d11bf0219ec120a67ddaad781b1613f3037..4bbebfa2e7173c6c39b280c41e9630dbe0c7b22e 100644 (file)
@@ -106,7 +106,8 @@ class printerPPDSelectionDialog extends plugin
     $list = array();
     foreach($this->list as $cat => $ppds){
       foreach($ppds as $ppd){
-        if(preg_match("/^".str_replace("*",".*",$regex)."/i",$ppd['ppd'])){
+       $name = $ppd['ppd']['name'];
+        if(preg_match("/^".str_replace("*",".*",$regex)."/i",$name)){
           if(is_readable($ppd['link'])){
             $list[$ppd['link']] = $ppd;
           }
@@ -142,6 +143,7 @@ class printerPPDSelectionDialog extends plugin
     if(empty($this->Vendor)){
       foreach($this-> header as $key => $entry){
         $div ->AddEntry (array(
+                 
               array("string"=>sprintf($linkopen,base64_encode($key),$key),"attach"=>"style='border-right:0px;'")
               ));
       }
@@ -150,7 +152,8 @@ class printerPPDSelectionDialog extends plugin
             array("string"=>sprintf($linkopen,"",".. ["._("back")."]"),"attach"=>"style='border-right:0px;'")
             ));
       foreach($list as $key => $ppd){
-        if(preg_match("/^".$this->Vendor."/",$ppd['ppd'])){
+       $name = $ppd['ppd']['name'];
+        if(preg_match("/^".$this->Vendor."/", $name)){
 
           if(is_writeable($ppd['link'])){
             $del_str = sprintf($dellink,base64_encode($key));
@@ -159,7 +162,7 @@ class printerPPDSelectionDialog extends plugin
           }
 
           $div ->AddEntry (array(
-                                  array("string"=>sprintf($uselink,base64_encode($key),$ppd['ppd'])),
+                                  array("string"=>sprintf($uselink,base64_encode($key),$name)),
                                   array("string"=>$del_str,"attach"=>"style='border-right:0px;'")
 
                 ));