Code

Bugfix for #4263
[gosa.git] / trunk / gosa-plugins / goto / admin / systems / goto / class_printGeneric.inc
index 377f6c4b1c5029e83c90211e85d3f3ceac232bd4..17e92cdd65236f95966931e0104add894db9bb5e 100644 (file)
@@ -14,6 +14,7 @@ class printgeneric extends plugin
   var $labeledURI       = "";
   var $gotoPrinterPPD   = "";
   var $initial_PPD      = "";
+  var $initial_PPD_URL  = "";
   var $orig_dn          = "";
   var $orig_cn          = "";
   var $orig_base        = "";
@@ -108,6 +109,7 @@ class printgeneric extends plugin
       }
     }
 
+    $this->initial_PPD_URL = $this->gotoPrinterPPD;
     /* Extract selected ppd */
     if(isset($this->gotoPrinterPPD)){
       $this->gotoPrinterPPD = preg_replace("/^http.*ppd\//i","",$this->gotoPrinterPPD);
@@ -410,6 +412,7 @@ class printgeneric extends plugin
       if($this->PPDdialogToSave && is_object($this->PPDdialogToSave)){
         $this->dialog = $this->PPDdialogToSave;
       }else{
+        $this->initial_PPD_URL = "";
         $this->dialog = new printerPPDDialog($this->config, $this->dn,$this->gotoPrinterPPD);
         $this->dialog->cn= $this->cn;
       }
@@ -499,6 +502,24 @@ class printgeneric extends plugin
       return $display;
     }
 
+    /* Get servername */
+    $server = $_SERVER['SERVER_NAME'];
+    if(tests::is_ip($server)){
+      $server_name = gethostbyaddr($server);
+    }else{
+      $server_name = gethostbyaddr(gethostbyname($server));
+    }
+    $orig_server_name = "";
+    if ($this->initial_PPD_URL != "") {
+      $ppd_server = preg_replace("/^http.*:../i","",$this->initial_PPD_URL);
+      $ppd_server = preg_replace("/\/.*/i","",$ppd_server);
+      if(tests::is_ip($ppd_server)){
+        $orig_server_name = gethostbyaddr($ppd_server);
+      }else{
+        $orig_server_name = $ppd_server;
+      }
+    }
+
     /* Parse selected ppd file */
     $config = session::get('config');
     if ($config->get_cfg_value("ppdPath") != ""){
@@ -509,11 +530,15 @@ class printgeneric extends plugin
 
       $ppdManager= new ppdManager($path);
       if(!empty($this->gotoPrinterPPD)){
-        if((!file_exists($path.$this->gotoPrinterPPD))){
-          $smarty->assign("driverInfo", "<b>".sprintf(_("Your currently selected PPD file '%s' doesn't exist."),$path.$this->gotoPrinterPPD)."</b>");
+        if($orig_server_name != "" && $server_name != $orig_server_name) {
+          $smarty->assign("driverInfo", "<b>".sprintf(_("Printer got configured on remote server '%s', Editing Driver will overwrite settings."),$orig_server_name)."</b>");
         }else{
-          $ppdDesc = $ppdManager->loadDescription($path.$this->gotoPrinterPPD);
-          $smarty->assign("driverInfo", $ppdDesc['name']);
+          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{
+            $ppdDesc = $ppdManager->loadDescription($path.$this->gotoPrinterPPD);
+            $smarty->assign("driverInfo", $ppdDesc['name']);
+          }
         }
       }else{
         $smarty->assign("driverInfo", _("Not defined"));
@@ -753,7 +778,7 @@ class printgeneric extends plugin
     if($this->PPDdialogToSave && is_object($this->PPDdialogToSave)){
       $this->PPDdialogToSave->save_ppd();
     }
-    if($this->orig_dn != $this->dn){
+    if($this->orig_dn != "new" && $this->orig_cn != $this->cn){
       if(!empty($this->gotoPrinterPPD)) {
         $this->PPDdialogToSave = new printerPPDDialog($this->config, $this->dn,$this->gotoPrinterPPD);
         $this->PPDdialogToSave->cn = $this->cn;
@@ -785,8 +810,17 @@ class printgeneric extends plugin
     }
 
     /* If no ppd is selected, remove this attribute */
-    if(!empty($this->gotoPrinterPPD) && $this->initially_was_account) {
-      $this->gotoPrinterPPD = $method.str_replace("//","/",$server_name."/ppd/".$this->gotoPrinterPPD);
+    if(!empty($this->gotoPrinterPPD)) {
+      if (($this->gotoPrinterPPD != $this->initial_PPD) || ($this->initial_PPD_URL == "")) {
+        /* PPD has changed, update it */
+        if (!preg_match('/^http[s]+:\/\/.*/', $this->gotoPrinterPPD)) {
+          /* ppd is not an url */
+          $this->gotoPrinterPPD = $method.str_replace("//","/",$server_name."/ppd/".$this->gotoPrinterPPD);
+        }
+      } else {
+        /* Restore original PPD URL */
+        $this->gotoPrinterPPD = $this->initial_PPD_URL;
+      }
     }else{
       $this->gotoPrinterPPD = array();
     }