]> git.tokkee.org Git - gosa.git/commitdiff

Code

Updated PPD handling.
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 15 Oct 2007 12:33:27 +0000 (12:33 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 15 Oct 2007 12:33:27 +0000 (12:33 +0000)
Allow overwrite of existing ppds.
Faster ppd handling, while adding or selectind ppds.

git-svn-id: https://oss.gonicus.de/repositories/gosa/branches/2.5@7552 594d385d-05f5-0310-b6e9-bd551577e9d8

include/class_ppdManager.inc
plugins/admin/systems/class_printerPPDDialog.inc
plugins/admin/systems/class_printerPPDSelectionDialog.inc

index 7e416556d036bcf13f8aa23af19f69c783d3b019..a9dfd1a7f995e5bb292b7985864ebac8984039c3 100644 (file)
@@ -4,6 +4,7 @@ class ppdManager
 {
        var $path= "";
        var $cachedList= array();
+       var $timestamps = array();
 
        function ppdManager($path)
        {
@@ -288,6 +289,16 @@ class ppdManager
                $model= "";
                $manufacturer= "";
 
+               
+               /* 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]){
+                       return($this->cachedList[$ppdFile]);
+               }
+
+               /* Remember modified timestamp, to speed up next request */
+               $this->timestamps[$ppdFile] = filemtime($ppdFile);
+
                $fh= fopen ($ppdFile, 'r');
                while ((!feof($fh))&&($fh)) {
 
@@ -329,10 +340,11 @@ class ppdManager
                        $list= $this->findPPD($this->path);
 
                        /* Load descriptive informations to build final printer list */
-                       $this->cachedList= array();
+                       $new = array();
                        foreach ($list as $ppdFile){
-                               $this->cachedList[$ppdFile]= $this->loadDescription($ppdFile);
+                               $new[$ppdFile] = $this->loadDescription($ppdFile); 
                        }
+                       $this->cachedList= $new ;
 
                }
 
index ecdacd44c74cab59ffb30d334e805b5fc55f8992..0bfc33a8155fe8e111331d366a93fda71c788895 100644 (file)
@@ -22,6 +22,14 @@ class printerPPDDialog extends plugin
   var $cn                   = "" ;          // Used to tag the ppds modified by the printer object, 
   var $dialog               = NULL;         // Contains sub dialogs 
 
+  /* If there is already a ppd file for the same type of printer,
+   *  remember the path to ppd file and display a dialog which allows
+   *  to overwrite the current ppd file.
+   */
+  var $add_ppd_later            = "";
+  var $add_later_msg_dialog     = NULL;
+
+
   function printerPPDDialog ($config, $dn= NULL,$ppdfile=NULL )
   {
     plugin::plugin ($config, $dn);
@@ -112,6 +120,15 @@ class printerPPDDialog extends plugin
       }
     }
 
+    /* Overwrite existing PPD file and select it as currently used for this object */
+    if(is_object($this->add_later_msg_dialog) && ($this->add_later_msg_dialog->is_confirmed()) && $this->add_ppd_later != ""){
+      if($name = $this->AddPPD($this->add_ppd_later,TRUE)){
+        $this->SelectPPD($name);
+      }
+      $this->add_ppd_later = "";
+      $this->add_later_msg_dialog = NULL;
+    } 
+
     /* Open a dialog that allow us to select different PPDs */
     if(isset($_POST['SelectPPD'])){
       $this->dialog= new printerPPDSelectionDialog($this->config,$this->dn,$this->ppdList,$this->ppdListHeader,$this->selectedPPD);
@@ -223,7 +240,7 @@ class printerPPDDialog extends plugin
   /* This function adds a new ppd file to the list of available ppds. 
      All required paths and files will be created 
       $_PathOnHdd e.g. = /tmp/PHP_tmpfile213452 */
-  function AddPPD($_PathOnHdd)
+  function AddPPD($_PathOnHdd,$overwrite = FALSE)
   {
     /* Check if file exists && is readable */
     if((!is_file($_PathOnHdd)) || (!is_readable($_PathOnHdd))){
@@ -254,16 +271,34 @@ class printerPPDDialog extends plugin
       $this->ppdList[$vendor] = array();
     }
 
+    /* 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);
+
+
     /* 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;
+        if(!$overwrite){
+          if(!copy($_PathOnHdd,$_PathOnHdd."_back")){
+            print_red(sprintf(_("Can't add new ppd file, the source file '%s' is not accessible."),$_PathOnHdd));         
+          }else{
+            $this->add_ppd_later = $_PathOnHdd."_back";
+            $this->add_later_msg_dialog = new msg_dialog(_("PPD file already exists"),
+                _("There is already a ppd file for this kind of printer."),CONFIRM_DIALOG);
+          }
+          return;
+        }
       }
     }
 
+    /* Open file handle */
+    $fp           = fopen($filename,"w+");
+
     /* Create the vendors path, if it doesn't exists already */
     if(!is_dir($this->pathToPPD.$vendor)){
       if(!(@mkdir($this->pathToPPD.$vendor))){
@@ -272,12 +307,6 @@ class printerPPDDialog extends plugin
       }
     }
   
-    /* Create ppd file and fill in the source contents */
-    $ppdname      = $vendor."/".$name.".ppd";
-    $filename     = $this->pathToPPD.$ppdname;
-    $fp           = fopen($filename,"w+");
-    $contents     = file_get_contents($_PathOnHdd);
-
     /* Check file handle & contents */
     if(!$fp){
       print_red(sprintf(_("Can't save file '%s'."),$filename));
index d1d3329fa5d73f5fc361378502b1f2001765b3cc..72db651b572eb5280e7131bb6f97826cd192800c 100644 (file)
@@ -127,9 +127,13 @@ class printerPPDSelectionDialog extends plugin
     $div ->SetHeight(450);
     $div ->SetSummary(_("Printer ppd selection."));
     
-    $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=open&amp;id=%s'>%s</a>";
+    $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=open&amp;id=%s'>
+      <img src='images/folder.png' class='center' border=0>&nbsp;%s
+      </a>";
     $uselink  = "<a href='?plug=".$_GET['plug']."&amp;act=use&amp;id=%s'>%s</a>";
-    $dellink  = "<a href='?plug=".$_GET['plug']."&amp;act=del&amp;id=%s'><img src='images/edittrash.png' alt='"._("delete")."' border=0></a>";
+    $dellink  = "<a href='?plug=".$_GET['plug']."&amp;act=del&amp;id=%s'>
+      <img src='images/edittrash.png' alt='"._("delete")."' border=0>
+      </a>";
 
     if(empty($this->Vendor)){
       foreach($this-> header as $key => $entry){