Code

Exported ppd_path to gosa.conf.
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 9 Nov 2005 09:07:18 +0000 (09:07 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 9 Nov 2005 09:07:18 +0000 (09:07 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@1887 594d385d-05f5-0310-b6e9-bd551577e9d8

plugins/admin/systems/class_printGeneric.inc
plugins/admin/systems/class_printerPPDDialog.inc

index 12b5514738b45e4ceed52cc2eece9ac2b92644ff..7c32d07de5bfa91288bee819269b7170d2694fec 100644 (file)
@@ -351,17 +351,23 @@ class printgeneric extends plugin
 
 
     require_once ("class_ppdManager.inc");
-    $ppdManager= new ppdManager('/var/spool/ppd/');
-    if(!empty($this->gotoPrinterPPD)){
-      if((!file_exists("/var/spool/ppd/".$this->gotoPrinterPPD))){
-        $smarty->assign("driverInfo", "<b>".sprintf(_("Your currently selected PPD file '%s' doesn't exist."),$this->gotoPrinterPPD))."</b>";
+
+    if((isset($_SESSION['config']->data['MAIN']['PPD_PATH']))&&(is_dir($_SESSION['config']->data['MAIN']['PPD_PATH']))){
+      $ppdManager= new ppdManager($_SESSION['config']->data['MAIN']['PPD_PATH']);
+      if(!empty($this->gotoPrinterPPD)){
+        if((!file_exists($_SESSION['config']->data['MAIN']['PPD_PATH'].$this->gotoPrinterPPD))){
+          $smarty->assign("driverInfo", "<b>".sprintf(_("Your currently selected PPD file '%s' doesn't exist."),$this->gotoPrinterPPD))."</b>";
+        }else{
+          $smarty->assign("driverInfo", $ppdManager->loadDescription($_SESSION['config']->data['MAIN']['PPD_PATH'].$this->gotoPrinterPPD));
+        }
       }else{
-        $smarty->assign("driverInfo", $ppdManager->loadDescription("/var/spool/ppd/".$this->gotoPrinterPPD));
+        $smarty->assign("driverInfo", _("not defined"));
       }
     }else{
-      $smarty->assign("driverInfo", _("not defined"));
+      $smarty->assign("driverInfo",_("can't get ppd informations."));
     }
 
+
     $list=$this->generateList();
     $userlist   = array_merge($list['AddUser'],$list['AddGroup']);
     $adminlist  = array_merge($list['AddAdminUser'],$list['AddAdminGroup']);
index ead6e8de243397fc245a703fbf61960c3c116b7e..dc359d9fb7cbd9ec5e5ef5e50a7d5abc8dea262c 100644 (file)
@@ -21,44 +21,53 @@ class printerPPDDialog extends plugin
   var $ppdManager           = false;    // new ppdManager;
   var $ppdConfig            = false;    // $this->ppdManager->loadProperties($this->selectedPPD['link']);
 
-  var $pathToPPD            = "/var/spool/ppd/";
+  var $pathToPPD            = "";
 
   function printerPPDDialog ($config, $dn= NULL,$ppdfile=NULL )
   {
     plugin::plugin ($config, $dn);
     $this->depselect = $this->config->current['BASE'];
 
-    /* Load all available PPD files and sort them into an array 
-     */
-    require_once ("class_ppdManager.inc");
-    $this->ppdManager= new ppdManager($this->pathToPPD);
-    $tmp = $this->ppdManager->getPrinterList();
+    if(isset($_SESSION['config']->data['MAIN']['PPD_PATH'])){
+      $this->pathToPPD = $_SESSION['config']->data['MAIN']['PPD_PATH'];
+    }else{
+      $this->pathToPPD = "";
+    }
 
-    /* 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;
+    if(!((!is_dir($this->pathToPPD))||(empty($this->pathToPPD)))){ 
+
+      /* Load all available PPD files and sort them into an array 
+       */
+      require_once ("class_ppdManager.inc");
+      $this->ppdManager= new ppdManager($this->pathToPPD);
+      $tmp = $this->ppdManager->getPrinterList();
+
+      /* 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']   =preg_replace("/".str_replace("/","\/",$this->pathToPPD)."/i","",$file);
+        $tmp3['ppd']    =$ppd;
+        $this->ppdListHeader[$tmp2[0]]++;
+        $this->ppdList[$tmp2[0]][preg_replace("/^ -/","",$tmp2[1]." - ".$tmp2[2])]=$tmp3;
       }
-      $tmp3['name']   =preg_replace("/^ -/","",$tmp2[1]." - ".$tmp2[2]);
-      $tmp3['link']   =preg_replace("/".str_replace("/","\/",$this->pathToPPD)."/i","",$file);
-      $tmp3['ppd']    =$ppd;
-      $this->ppdListHeader[$tmp2[0]]++;
-      $this->ppdList[$tmp2[0]][preg_replace("/^ -/","",$tmp2[1]." - ".$tmp2[2])]=$tmp3;
-    }
 
-   /* The user has already a valid PPD assigned
-    * Get some informations about this PPD
-    */
-    if(($ppdfile!= NULL)&&(strlen($ppdfile)>0)){
-      if(!file_exists($this->pathToPPD.$ppdfile)){
-        print_red(sprintf(_("Can't open '%s', ppd settings resetted."),$ppdfile));
-      }else{
-        $tmp2= split("\n", $this->ppdManager->loadDescription($this->pathToPPD.$ppdfile));
-        $tmp3['name']   =preg_replace("/^ -/","",$tmp2[1]);
-        $tmp3['link']   =$ppdfile;
-        $tmp3['ppd']    =$this->ppdManager->loadDescription($this->pathToPPD.$ppdfile);
-        $this->selectedPPD = $tmp3;
+      /* The user has already a valid PPD assigned
+       * Get some informations about this PPD
+       */
+      if(($ppdfile!= NULL)&&(strlen($ppdfile)>0)){
+        if(!file_exists($this->pathToPPD.$ppdfile)){
+          print_red(sprintf(_("Can't open '%s', ppd settings resetted."),$ppdfile));
+        }else{
+          $tmp2= split("\n", $this->ppdManager->loadDescription($this->pathToPPD.$ppdfile));
+          $tmp3['name']   =preg_replace("/^ -/","",$tmp2[1]);
+          $tmp3['link']   =$ppdfile;
+          $tmp3['ppd']    =$this->ppdManager->loadDescription($this->pathToPPD.$ppdfile);
+          $this->selectedPPD = $tmp3;
+        }
       }
     }
   }
@@ -84,113 +93,120 @@ class printerPPDDialog extends plugin
 
   function execute()
   {
-       /* Call parent execute */
-       plugin::execute();
+    /* Call parent execute */
+    plugin::execute();
 
     /* Fill templating stuff */
     $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($this->pathToPPD.$vendor)){
-            if(!(@mkdir($this->pathToPPD.$vendor))){
-              print_red(sprintf(_("Can't create folder '%s' for the uploaded ppd file."),$vendor));
+    if((!is_dir($this->pathToPPD))||(empty($this->pathToPPD))){
+      print_red(sprintf(_("The specified PPD_PATH='%s' in your gosa.conf is invalid, can't read any ppd informations."),$this->pathToPPD));
+      $smarty->assign("ppdString", _("Can't get ppd informations."));
+      $smarty->assign("showOptions", "");
+    }else{
+
+
+      /* 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($this->pathToPPD.$vendor)){
+              if(!(@mkdir($this->pathToPPD.$vendor))){
+                print_red(sprintf(_("Can't create folder '%s' for the uploaded ppd file."),$vendor));
+              }
             }
-          }
 
-          if(!isset($this->ppdList[$vendor])){
-            $this->ppdList[$vendor] = array();
-          }
-  
-          if(is_dir($this->pathToPPD.$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 = $this->pathToPPD.$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(!isset($this->ppdList[$vendor])){
+              $this->ppdList[$vendor] = array();
             }
-          }// If dir
+
+            if(is_dir($this->pathToPPD.$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 = $this->pathToPPD.$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."));
         }
-      }else{
-        print_red(_("Please specify a valid ppd file."));
+
       }
-  
-    }
 
 
-    /* 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);
-    }
+      /* 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);
+      }
 
-    /* The selection dialog fpr PPDs is canceled
-     */
-    if(isset($_POST['ClosePPDSelection'])){
-      unset($this->dialog);
-      $this->dialog=NULL;
-    }
-  
-    /* A new PPDs was selected in the PPDs selection Dialog
-     * Perform a Check. If everything is fine, use the new PPD.
-     */
-    if(isset($_POST['SavePPDSelection'])){
-      if(!isset($_POST['PPDselection'])){
-        print_red(_("Please select a valid ppd."));
-      }else{
-        $this->selectedPPD['link'] = $_POST['PPDselection'];
-        $this->ppdConfig   = false;
+      /* The selection dialog fpr PPDs is canceled
+       */
+      if(isset($_POST['ClosePPDSelection'])){
         unset($this->dialog);
         $this->dialog=NULL;
       }
-    }
-    /* if a dialog is open, print the dialog instead of this class
-     */
-    if($this->dialog!=NULL){
-      $display = $this->dialog->execute();
-      return($display);
-    }
 
-    /* Give smarty the information it needs */
-    $smarty->assign("ppdString" ,$this->getPPDInformation());
-    $tmp= $this->generateProperties();
-    if ($tmp == ""){
-      $smarty->assign("showOptions", 0);
-    } else {
-      $smarty->assign("showOptions", 1);
-      $smarty->assign("properties",$this->generateProperties());
-    }
-  
+      /* A new PPDs was selected in the PPDs selection Dialog
+       * Perform a Check. If everything is fine, use the new PPD.
+       */
+      if(isset($_POST['SavePPDSelection'])){
+        if(!isset($_POST['PPDselection'])){
+          print_red(_("Please select a valid ppd."));
+        }else{
+          $this->selectedPPD['link'] = $_POST['PPDselection'];
+          $this->ppdConfig   = false;
+          unset($this->dialog);
+          $this->dialog=NULL;
+        }
+      }
+
+      /* if a dialog is open, print the dialog instead of this class
+       */
+      if($this->dialog!=NULL){
+        $display = $this->dialog->execute();
+        return($display);
+      }
+
+      /* Give smarty the information it needs */
+      $smarty->assign("ppdString" ,$this->getPPDInformation());
+      $tmp= $this->generateProperties();
+      if ($tmp == ""){
+        $smarty->assign("showOptions", 0);
+      } else {
+        $smarty->assign("showOptions", 1);
+        $smarty->assign("properties",$this->generateProperties());
+      }
+    } 
     /* Print out template */
     $display.= $smarty->fetch(get_template_path('printerPPDDialog.tpl', TRUE,dirname(__FILE__)));
     return($display);
@@ -218,7 +234,7 @@ class printerPPDDialog extends plugin
     }
 
   }
-  
+
   function save_ppd(){
     $this->ppdManager->saveProperties($this->pathToPPD.$this->selectedPPD['link'],$this->ppdConfig);
   }
@@ -247,7 +263,7 @@ class printerPPDDialog extends plugin
     /* In future there will be a schema parser that provide us all settings that can be made in the selected PPD file. 
      * This function will generate a userfriendly post based form with this informations
      */
-  
+
     /* Set Headline */
     $str = "";
     $feed= "";
@@ -256,7 +272,7 @@ class printerPPDDialog extends plugin
 
     /* If ppd exists and is readable */
     if((!empty($this->selectedPPD['link']))&&(file_exists($s_ppd))){
-    
+
       /* If there is no initial Configuration, load it */
       if($this->ppdConfig == false){
         $this->ppdConfig = $this->ppdManager->loadProperties($s_ppd);
@@ -267,7 +283,7 @@ class printerPPDDialog extends plugin
 
       /* Input all data to the table */
       foreach($this->ppdConfig as $cat => $obj){
-    
+
         /* Add new category */
         $str .= "<tr><td colspan='2'>$feed";
         if ($feed == ""){
@@ -278,22 +294,22 @@ class printerPPDDialog extends plugin
 
         /* Add attributes of the current category */
         foreach($obj as $attr => $settings){
-  
-      
+
+
           /* Skip all entries beginning with _ */
           if($attr[0] == "_") continue;  
-          
+
           /* Prepare data */
           $values   = array();
           $name     = $settings['_name'];
           $default  = $settings['_default'];
           $type     = $settings['_type'];
+
           /* Add name to table */ 
           $str .= "<tr><td style='padding-left:40px;'>\n";
           $str .= $name."<br>\n";
           $str .= "</td><td>\n";
-   
+
           /* Get all values */ 
           foreach( $settings as $vname => $value){
             if($vname[0] != "_"){