Code

Hide tabs frames
[gosa.git] / plugins / admin / ogroups / class_termgroup.inc
index 49d099202667cf6422bb458a4f4a3e1791f3ad2a..61e5c21764bd5baec5bdf639a313ceaa931bbb8f 100644 (file)
@@ -19,14 +19,23 @@ class termgroup extends plugin
   var $orig_dn               = "";
   var $didAction                 = FALSE;
 
+  var $mapActions   = array("reboot"          => "localboot",
+                            "instant_update"  => "softupdate",
+                            "update"          => "scheduledupdate",
+                            "reinstall"       => "install",
+                            "rescan"          => "",
+                            "memcheck"        => "memcheck",
+                            "sysinfo"         => "sysinfo");
 
-  function termgroup ($config, $dn= NULL)
+  var $CopyPasteVars = array("gotoNtpServers","modes","inheritTimeServer");
+
+  function termgroup ($config, $dn= NULL, $parent= NULL)
   {
     /***************
       Some  initialisations
      ***************/
 
-    plugin::plugin($config, $dn);
+    plugin::plugin($config, $dn, $parent);
 
     $ldap= $config->get_ldap_link();
 
@@ -108,7 +117,7 @@ class termgroup 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.");
+      $message[]= _("There must be at least one NTP server selected.");
     }
     return($message);
   }
@@ -129,6 +138,51 @@ class termgroup extends plugin
     $this->handle_post_events("remove");
   }
 
+
+  function update_term_member_FAIstate($act)
+  {
+    /* Get required informations */
+    $og    = $this->parent->by_object['ogroup'];  
+    $allobs= $og->objcache;
+
+    /* Get correct value for FAIstate */
+    $action= $this->mapActions[$act];
+
+    /* Get ldap connection */
+    $ldap= $this->config->get_ldap_link();
+    $ldap->cd ($this->config->current['BASE']);
+
+    /* Foreach member of mthis ogroup  ... */
+    foreach($og->member as $key ){
+  
+      /* check objectClasses and create attributes array */
+      $attrs = array("FAIstate" => $action);  
+      for($i = 0; $i < $allobs[$key]['objectClass']['count'] ; $i ++){
+        $attrs['objectClass'][] = $allobs[$key]['objectClass'][$i];
+      }
+      if(($attrs['FAIstate'] != "") && (!in_array("FAIobject",$attrs['objectClass']))){
+        $attrs['objectClass'][] = "FAIobject";
+      }
+      if($attrs['FAIstate'] == ""){
+        $attrs['FAIstate'] = array();
+      }
+
+      /* If this objects is workstation,terminal or server upodate FAIstate */ 
+      if(preg_match("/(w|t|s)/i",$allobs[$key]['type'])){
+        $ldap->cd ($key);
+        $ldap->modify($attrs);
+        show_ldap_error($ldap->get_error(),sprintf(_("Setting action state (FAIstate) failed for object '%s', value was '%s'."),$key,$action));
+        
+        if(!preg_match("/success/i",$ldap->get_error())) {
+          gosa_log("FAILED !! Updating FAIstate to '".$action."' : ".$key);
+        }else{
+          gosa_log("OK.  Updating FAIstate to '".$action."' : ".$key);
+        }
+      }
+    }
+  }
+
+
   function execute()
   {
     /* Call parent execute */
@@ -148,7 +202,11 @@ class termgroup extends plugin
         $names.= "$cn ";
       }
 
-      if (isset($_POST['action'])){
+      if (isset($_POST['action']) && $this->acl == "#all#"){
+
+        /* Update members fai state */
+        $this->update_term_member_FAIstate(trim($_POST['saction']));
+
         $cmd= search_config($this->config->data['TABS'], "workgeneric", "ACTIONCMD");
         if ($cmd == ""){
           print_red(_("No ACTIONCMD definition found in your gosa.conf"));
@@ -169,12 +227,12 @@ class termgroup extends plugin
      ***************/
 
     /* Add new ntp Server to our list */
-    if((isset($_POST['addNtpServer'])) && (isset($_POST['gotoNtpServers']))){
+    if((isset($_POST['addNtpServer'])) && (isset($_POST['gotoNtpServers'])) && $this->acl == "#all#"){
       $this->gotoNtpServer[$_POST['gotoNtpServers']] = $_POST['gotoNtpServers'];
     }
 
     /* Delete selected NtpServer for list of used servers  */
-    if((isset($_POST['delNtpServer'])) && (isset($_POST['gotoNtpServerSelected']))){
+    if((isset($_POST['delNtpServer'])) && (isset($_POST['gotoNtpServerSelected'])) && $this->acl == "#all#"){
       foreach($_POST['gotoNtpServerSelected'] as $name){
         unset($this->gotoNtpServer[$name]);
       }
@@ -210,7 +268,6 @@ class termgroup extends plugin
 
     $smarty->assign("inheritTimeServer",$this->inheritTimeServer);
     $smarty->assign("modes", $this->modes);
-    $smarty->assign("actions", array("wake" => _("Wake up"), "halt" => _("Switch off"), "reboot" => _("Reboot")));
     $smarty->assign("actionACL", chkacl($this->acl, 'action'));
     $smarty->assign("gotoNtpServers",$this->gotoNtpServers); 
     $smarty->assign("syslogservers", $this->config->data['SERVERS']['SYSLOG']); 
@@ -267,25 +324,12 @@ class termgroup extends plugin
 
     /* Write back to ldap */
     $ldap= $this->config->get_ldap_link();
-    if ($this->orig_dn == 'new'){
-      $ldap->cd($this->config->current['BASE']);
-      $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
-      $ldap->cd($this->dn);
-      $ldap->add($this->attrs);
-      if(!$this->didAction){
-        $this->handle_post_events("add");
-      }
-    } else {
-      if ($this->orig_dn != $this->dn){
-        $this->move($this->orig_dn, $this->dn);
-      }
-      $ldap->cd($this->dn);
-      $this->cleanup();
-      $ldap->modify ($this->attrs);
+    $ldap->cd($this->dn);
+    $this->cleanup();
+    $ldap->modify ($this->attrs);
 
-      if(!$this->didAction){
-        $this->handle_post_events("modify");
-      }
+    if(!$this->didAction){
+      $this->handle_post_events("modify");
     }
     show_ldap_error($ldap->get_error(), _("Saving workstation failed"));
   }