Code

Updated printGeneric.
[gosa.git] / plugins / admin / systems / class_printerPPDDialog.inc
index 103825ac47b7c51aec9fbc4be19339de542ffe6b..cf36067aea6df1c7f85fb229b9c6cd0ec5a1461d 100644 (file)
@@ -189,7 +189,7 @@ class printerPPDDialog extends plugin
       $Model  = trim(preg_replace("/".$Vendor."/","",$Name));
     }    
 
-    $PrinterName  = $this->cn."-".$Name
+    $PrinterName  = $this->cn."-".preg_replace("/[^a-z0-9-_\.]/i","_",$Name)
     $PPDName      = $Vendor."/".$PrinterName.".ppd";
     
     /* Create the vendors path, if it doesn't exists already */
@@ -245,7 +245,7 @@ class printerPPDDialog extends plugin
 
     /* Check if parse was successfull */
     if(empty($name) || empty($vendor)){
-      print_red(sprintf(_("The given ppd file '%s' seams to be invalid, can't get any modell or vendor informations."),$_PathOnHdd));
+      print_red(sprintf(_("The given ppd file '%s' seams to be invalid, can't get any model or vendor informations."),$_PathOnHdd));
       return(false);
     }
 
@@ -254,15 +254,11 @@ class printerPPDDialog extends plugin
       $this->ppdList[$vendor] = array();
     }
 
-    /* Check if this ppd already exists */
-    $found = false;
-    foreach($this->ppdList[$vendor] as $key => $val){
-      if(preg_match("/".$model.".*/i",$key)){
-        $found = true;
-        print_red(sprintf(_("There is already a ppd file for this kind of printer.")));
-        return;
-      }
-    }
+    /* Create ppd file and fill in the source contents */
+    $ppdname      = $vendor."/".$name.".ppd";
+    $filename     = $this->pathToPPD.preg_replace("/[^a-z0-9-_\.\/]/i","_",$ppdname);
+    $filename     = $this->pathToPPD.$ppdname;
+    $contents     = file_get_contents($_PathOnHdd);
 
     /* Create the vendors path, if it doesn't exists already */
     if(!is_dir($this->pathToPPD.$vendor)){
@@ -272,11 +268,8 @@ class printerPPDDialog extends plugin
       }
     }
   
-    /* Create ppd file and fill in the source contents */
-    $ppdname      = $vendor."/".$name.".ppd";
-    $filename     = $this->pathToPPD.$ppdname;
+    /* Open file handle */
     $fp           = fopen($filename,"w+");
-    $contents     = file_get_contents($_PathOnHdd);
 
     /* Check file handle & contents */
     if(!$fp){
@@ -308,7 +301,7 @@ class printerPPDDialog extends plugin
   function getPrinterReload()
   {
     if(is_readable($this->pathToPPD)){
-      $tmp = $this->ppdManager->getPrinterList(true);
+      $tmp = @$this->ppdManager->getPrinterList(true);
 
       $this->ppdListHeader = $this->ppdList = array();
 
@@ -349,7 +342,8 @@ class printerPPDDialog extends plugin
 
 
   /* Save modified ppd */
-  function save_ppd(){
+  function save_ppd()
+  {
     if($this->ppdManager){
       $this->ppdManager->saveProperties($this->pathToPPD.$this->pathToModified.$this->selectedPPD['link'],$this->ppdConfig);
     }
@@ -417,7 +411,11 @@ class printerPPDDialog extends plugin
           /* Prepare data */
           $values   = array();
           $name     = $settings['_name'];
-          $default  = $settings['_default'];
+          if (!isset($settings['_default'])){
+            $default  = "";
+          } else {
+            $default  = $settings['_default'];
+          }
           $type     = $settings['_type'];
 
           /* Add name to table */ 
@@ -489,6 +487,12 @@ class printerPPDDialog extends plugin
       print_red(sprintf(_("Removing old ppd file '%s' failed. File does not exists or is not accessible."),$path));
     }
   }
+
+  function update_ppd_url()
+  {
+    $this->SelectPPD("modified/".$this->selectedPPD['link']);
+    return("modified/".$this->selectedPPD['link']);
+  }
   
   function check()
   {