Code

Upload for PPD files added
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Fri, 28 Oct 2005 09:14:00 +0000 (09:14 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Fri, 28 Oct 2005 09:14:00 +0000 (09:14 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@1721 594d385d-05f5-0310-b6e9-bd551577e9d8

plugins/admin/systems/class_printerPPDDialog.inc
plugins/admin/systems/printerPPDDialog.tpl

index b5547fff8d403e7e6deff08c8ed2867bbac5d670..4123a0466d0c04c28c886e43b107301b8cb71da0 100644 (file)
@@ -55,8 +55,25 @@ class printerPPDDialog extends plugin
       $tmp3['ppd']    =$this->ppdManager->loadDescription($ppdfile);
       $this->selectedPPD = $tmp3;
    }
+  }
+
+  function getPrinterReload()
+  {
+    $tmp = $this->ppdManager->getPrinterList(true);
+
+    /* Sort all available files, and create header (Vendor index) */
+    foreach($tmp as $file=>$ppd){
+      $tmp2 = split("\n",$ppd);
+      if(!isset($this->ppdListHeader[$tmp2[0]])){
+        $this->ppdListHeader[$tmp2[0]]=0;
+      }
+      $tmp3['name']   =preg_replace("/^ -/","",$tmp2[1]." - ".$tmp2[2]);
+      $tmp3['link']   =$file;
+      $tmp3['ppd']    =$ppd;
+      $this->ppdListHeader[$tmp2[0]]++;
+      $this->ppdList[$tmp2[0]][preg_replace("/^ -/","",$tmp2[1]." - ".$tmp2[2])]=$tmp3;
+    }
 
   }
 
   function execute()
@@ -65,6 +82,61 @@ class printerPPDDialog extends plugin
     $smarty= get_smarty();
     $display= "";
 
+    /* Is there a new PPD file uploaded ? */
+    if((isset($_FILES['NewPPDFile']))&&(isset($_POST['SubmitNewPPDFile']))){
+      $file = ($_FILES['NewPPDFile']);
+      if($file['size'] != 0 ){
+        $res  = @$this->ppdManager->loadDescription($file['tmp_name']);
+        $name = (trim(preg_replace("/-/","",$res)));
+        if(!empty($name)){
+          $vendor = trim(preg_replace("/-.*$/i","",$res));
+          $model  = trim(preg_replace("/".$vendor."/","",$name));
+          if(!is_dir('/var/spool/ppd/'.$vendor)){
+            if(!(@mkdir('/var/spool/ppd/'.$vendor))){
+              print_red(sprintf(_("Cab't create folder '%s' for the uploaded ppd file."),$vendor));
+            }
+          }
+
+          if(!isset($this->ppdList[$vendor])){
+            $this->ppdList[$vendor] = array();
+          }
+  
+          if(is_dir('/var/spool/ppd/'.$vendor)){  
+            $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.")));
+              }
+            }// Foreach
+            if(!$found){
+              $filename = '/var/spool/ppd/'.$vendor."/".$vendor."-".preg_replace("/^[^ ]/","",str_replace("-","",$model)).".ppd";
+              $fp = @fopen($filename,"w+");
+              if(!$fp){
+                print_red(sprintf(_("Can't save file '%s'"),$filename));
+              }else{
+                $str = file_get_contents($file['tmp_name']);
+                fputs($fp,$str);
+                @fclose($fp);
+               
+                $tmp2= split("\n", $res);
+                $tmp3['name']   =preg_replace("/^ -/","",$tmp2[1]);
+                $tmp3['link']   =$filename;
+                $tmp3['ppd']    =$res;
+                $this->selectedPPD = $tmp3;
+                $this->getPrinterReload(); 
+              }
+            }
+          }// If dir
+        }else{
+          print_red(_("Please specify a valid ppd file."));
+        }
+      }else{
+        print_red(_("Please specify a valid ppd file."));
+      }
+  
+    }
+
 
     /* Open a dialog that allow us to select different PPDs
      */
index 9a68fc43ba5c10bc3c3a8cb2e4eb1d149328cdbf..0a8fe89b620c3d6fa3468197bb648c12f392b20b 100644 (file)
@@ -1,12 +1,16 @@
-<h2><img src="images/house.png">&nbsp;{t}Printer driver information file setup{/t}</h2>
-
-<table summary="" width="50%">
+<table summary="" width="100%">
        <tr>
-               <td>
+               <td width="50%">
+                       <h2><img src="images/house.png">&nbsp;{t}Printer driver information file setup{/t}</h2>
                        {t}Current used information setup{/t} :
                        {$ppdString}<br>
                        <input type="submit" name="SelectPPD" value="{t}Select{/t}">
                </td>
+               <td style="border-left: 1px solid rgb(160, 160, 160);padding-left:10px;">
+                       <h2><img src="images/house.png" alt="">&nbsp;{t}Upload new PPD file{/t} :</h2>
+                       <input type="file" value="" name="NewPPDFile">
+                       <input type="submit" name="SubmitNewPPDFile" value="{t}Upload{/t}">
+               </td>
        </tr>
 </table>
 <p class="seperator">&nbsp;</p>