Code

Fixed Terminal NTPserver .... syslogserver default to inherited
[gosa.git] / plugins / admin / systems / class_terminalGeneric.inc
index e7c8fe4b4ff65da5afc7aa31308030566a674a10..812b4f90f8ea6dd9a1d13e6f56c6ca9c5ce5d072 100644 (file)
@@ -12,7 +12,9 @@ class termgeneric extends plugin
   var $gotoTerminalPath= "";
   var $gotoSwapServer= "";
   var $gotoSyslogServer= "";
+  var $gotoSyslogServers = array();
   var $gotoNtpServer= array();
+  var $gotoNtpServers= array();
   var $gotoSndModule= "";
   var $gotoFloppyEnable= "";
   var $gotoCdromEnable= "";
@@ -31,6 +33,8 @@ class termgeneric extends plugin
   var $cn= "";
   var $orig_dn= "";
 
+  var $inheritTimeServer = true;
+
   /* Plugin side filled */
   var $modes= array();
 
@@ -58,14 +62,29 @@ class termgeneric extends plugin
     }
 
     /* Create used ntp server array */
-    $this->gotoNtpServer= array("default"=>"default");
+    $this->gotoNtpServer= array();
     if(isset($this->attrs['gotoNtpServer'])){
+      $this->inheritTimeServer = false;
       unset($this->attrs['gotoNtpServer']['count']);
       foreach($this->attrs['gotoNtpServer'] as $server){
         $this->gotoNtpServer[$server] = $server;
       }
     }
 
+    /* Set inherit checkbox state */
+    if((in_array("default",$this->gotoNtpServer)) || (count($this->gotoNtpServer)==0)){
+      $this->inheritTimeServer = true;
+      $this->gotoNtpServer=array();
+    }
+
+    /* Create available ntp options */
+    $this->gotoNtpServers = $this->config->data['SERVERS']['NTP'];
+    foreach($this->gotoNtpServers as $key => $server){
+      if($server == "default"){
+        unset($this->gotoNtpServers[$key]);
+      }
+    }
+
     $this->modes["disabled"]= _("disabled");
     $this->modes["text"]= _("text");
     $this->modes["graphic"]= _("graphic");
@@ -78,6 +97,16 @@ class termgeneric extends plugin
       $this->base= preg_replace ("/^[^,]+,[^,]+,[^,]+,/", "", $this->dn);
     }
 
+    /* Create an array of all Syslog servers */
+    $tmp = $this->config->data['SERVERS']['SYSLOG'];
+    foreach($tmp as $server){
+      $visible = $server;
+      if($server == "default") {
+        $visible = "["._("inherited")."]";
+      }
+      $this->gotoSyslogServers[$server] = $visible;
+    }
+
     $this->orig_dn= $this->dn;
   }
 
@@ -173,14 +202,8 @@ class termgeneric extends plugin
       foreach($_POST['gotoNtpServerSelected'] as $name){
         unset($this->gotoNtpServer[$name]);
       } 
-    
-      /* if nothing is selected, add default */
-      if(count($this->gotoNtpServer) == 0){
-        $this->gotoNtpServer['default'] = "default";
-      }
     }
 
-
     /* Fill templating stuff */
     $smarty= get_smarty();
     $smarty->assign("cn", $this->cn);
@@ -188,6 +211,9 @@ class termgeneric extends plugin
 
     $smarty->assign("bases", $this->config->idepartments);
 
+    /* tell smarty the inherit checkbox state */
+    $smarty->assign("inheritTimeServer",$this->inheritTimeServer);
+
     /* Check if terminal is online */
     $query= "fping -q -r 1 -t 500 ".$this->cn;
     exec ($query, $dummy, $retval);
@@ -221,9 +247,12 @@ class termgeneric extends plugin
       }
     }
   
-    $smarty->assign("nfsservers", $tmp2);
-    $smarty->assign("syslogservers", $this->config->data['SERVERS']['SYSLOG']);
-    $smarty->assign("ntpservers", $this->config->data['SERVERS']['NTP']);
+    $smarty->assign("nfsservers",     $tmp2);
+
+    
+
+    $smarty->assign("syslogservers",  $this->gotoSyslogServers);
+    $smarty->assign("ntpservers",     $this->gotoNtpServers);
 
     /* Variables */
     foreach(array("base", "gotoMode", "gotoTerminalPath", "gotoSwapServer",
@@ -244,14 +273,14 @@ class termgeneric extends plugin
     
     $ldap= $this->config->get_ldap_link();
     $ldap->cd($this->dn);
-    $ldap->cat($this->dn);
+    $ldap->cat($this->dn, array('dn'));
     if($ldap->count()){
       $this->netConfigDNS->remove_from_parent();
       $ldap->rmDir($this->dn);
-      show_ldap_error($ldap->get_error());
+      show_ldap_error($ldap->get_error(), _("Removing terminal failed"));
 
       /* Optionally execute a command after we're done */
-      $this->handle_post_events("remove");
+      $this->handle_post_events("remove", array("macAddress" => $this->netConfigDNS->macAddress));
 
       /* Delete references to object groups */
       $ldap->cd ($this->config->current['BASE']);
@@ -278,6 +307,14 @@ class termgeneric extends plugin
     /* Save terminal path to parent since it is used by termstartup, too */
     $this->parent->by_object['termstartup']->gotoTerminalPath=
       $this->gotoTerminalPath;
+  
+    if(isset($_POST['termgeneric_posted'])){
+      if(isset($_POST["inheritTimeServer"])){
+        $this->inheritTimeServer = true;
+      }else{
+        $this->inheritTimeServer = false;
+      }
+    }  
   }
 
 
@@ -320,6 +357,11 @@ class termgeneric extends plugin
       }
     }
 
+    /* Check for valid ntpServer selection */
+    if((!$this->inheritTimeServer) && (!count($this->gotoNtpServer))){
+      $message[]= _("There must be at least one NTP server selected, or the inherit mode activated.");
+    }
+
     return ($message);
   }
 
@@ -356,10 +398,14 @@ class termgeneric extends plugin
       $this->attrs= $attrs;
     }
 
-    /* Set ntpServers */
-    $this->attrs['gotoNtpServer'] = array();
-    foreach($this->gotoNtpServer as $server){
-      $this->attrs['gotoNtpServer'][] = $server;
+    if($this->inheritTimeServer){
+      $this->attrs['gotoNtpServer'] = array();
+    }else{  
+      /* Set ntpServers */
+      $this->attrs['gotoNtpServer'] = array();
+      foreach($this->gotoNtpServer as $server){
+        $this->attrs['gotoNtpServer'][] = $server;
+      }
     }
 
     /* Write back to ldap */
@@ -376,13 +422,13 @@ class termgeneric extends plugin
       }
       $ldap->cd($this->dn);
       $this->cleanup();
-$ldap->modify ($this->attrs); 
+      $ldap->modify ($this->attrs); 
 
       $this->handle_post_events("modify");
     }
     $this->netConfigDNS->cn = $this->cn;
     $this->netConfigDNS->save($this->dn);
-    show_ldap_error($ldap->get_error());
+    show_ldap_error($ldap->get_error(), _("Saving terminal failed"));
 
     /* Optionally execute a command after we're done */
     $this->postcreate();