Code

Removed duplicated post call
[gosa.git] / plugins / admin / systems / class_workstationGeneric.inc
index 0330d015e3443af3949ddf272230a2ca545aad1f..4604c98a77c16c7965795458e083127982d3c129 100644 (file)
@@ -48,9 +48,10 @@ class workgeneric extends plugin
       "gotoFloppyEnable", "gotoCdromEnable", "cn", "gotoSndModule",
       "ghCpuType", "ghMemSize", "ghUsbSupport",
       "ghGfxAdapter", "ghSoundAdapter", "gotoLastUser", "l","FAIscript");
-  var $objectclasses= array("top", "gotoWorkstation", "GOhard","FAIobject");
+  var $objectclasses= array("top", "gotoWorkstation", "GOhard");
 
   var $mapActions   = array("reboot"          => "localboot",
+                            "localboot"       => "localboot",
                             "instant_update"  => "softupdate",
                             "update"          => "sceduledupdate",
                             "reinstall"       => "install",
@@ -58,10 +59,16 @@ class workgeneric extends plugin
                             "memcheck"        => "memcheck",
                             "sysinfo"         => "sysinfo");
 
-
+  
+  var $fai_activated = FALSE;
 
   function workgeneric ($config, $dn= NULL, $parent= NULL)
   {
+    $tmp = search_config($config->data,"faiManagement","CLASS");
+    if(!empty($tmp)){
+      $this->fai_activated = TRUE;
+    }
+
     plugin::plugin ($config, $dn, $parent);
     $this->netConfigDNS = new termDNS($this->config,$this->dn,$this->objectclasses);
 
@@ -120,6 +127,10 @@ class workgeneric extends plugin
       $this->gotoSyslogServers[$server] = $visible;
     }
 
+    if($this->is_account){
+      @log::log("view","workstation/".get_class($this),$this->dn);
+    } 
+
     /* Save 'dn' for later referal */
     $this->orig_dn= $this->dn;
   }
@@ -162,34 +173,36 @@ class workgeneric extends plugin
         } elseif ($_POST['saction'] != "wake") {
 
           /* Set FAIstate */
-          $ldap = $this->config->get_ldap_link();
-          $ldap->cd($this->config->current['BASE']);
-          $ldap->cat($this->dn,array("objectClass"));
-          $res = $ldap->fetch();
-
-          $attrs = array();
-          $attrs['FAIstate'] = "";
-          if(isset($this->mapActions[$_POST['saction']])){
-            $attrs['FAIstate'] = $this->mapActions[$_POST ['saction']];
-          }
+          if($this->fai_activated && $this->dn != "new"){
+            $ldap = $this->config->get_ldap_link();
+            $ldap->cd($this->config->current['BASE']);
+            $ldap->cat($this->dn,array("objectClass"));
+            $res = $ldap->fetch();
+
+            $attrs = array();
+            $attrs['FAIstate'] = "";
+            if(isset($this->mapActions[$_POST['saction']])){
+              $attrs['FAIstate'] = $this->mapActions[$_POST ['saction']];
+            }
 
-          for($i = 0; $i < $res['objectClass']['count'] ; $i ++){
-            $attrs['objectClass'][] = $res['objectClass'][$i];
-          }
+            for($i = 0; $i < $res['objectClass']['count'] ; $i ++){
+              $attrs['objectClass'][] = $res['objectClass'][$i];
+            }
 
-          if(($attrs['FAIstate'] != "") && (!in_array("FAIobject",$attrs['objectClass']))){
-            $attrs['objectClass'][] = "FAIobject";
-          }
+            if(($attrs['FAIstate'] != "") && (!in_array("FAIobject",$attrs['objectClass']))){
+              $attrs['objectClass'][] = "FAIobject";
+            }
 
-          if($attrs['FAIstate'] == ""){
-            #FIXME we should check if FAIobject is used anymore
-            $attrs['FAIstate'] = array();
-          }
+            if($attrs['FAIstate'] == ""){
+#FIXME we should check if FAIobject is not used anymore
+              $attrs['FAIstate'] = array();
+            }
+
+            $ldap->cd($this->dn);
+            $ldap->modify($attrs);
+            show_ldap_error($ldap->get_error(), sprintf(_("Saving of system workstation/generic (FAIstate) with dn '%s' failed."),$this->dn));
 
-          $ldap->cd($this->dn);
-          $ldap->modify($attrs);
-          show_ldap_error($ldap->get_error(), sprintf(_("Saving of system workstation/generic (FAIstate) with dn '%s' failed."),$this->dn));
+          }
           $this->didAction= TRUE;
         }
       }
@@ -279,18 +292,21 @@ class workgeneric extends plugin
                                        "reinstall" => _("Reinstall"),
                                        "rescan" => _("Rescan hardware"),
                                        "memcheck" => _("Memory test"),
+                                       "localboot" => _("Force localboot"),
                                        "sysinfo"  => _("System analysis")));
     } else {
       $smarty->assign("actions", array("wake" => _("Wake up"),
                                        "reinstall" => _("Reinstall"),
                                        "update" => _("Scheduled update"),
                                        "memcheck" => _("Memory test"),
+                                       "localboot" => _("Force localboot"),
                                        "sysinfo"  => _("System analysis")));
     }
     /* Arrays */
     $smarty->assign("modes", $this->modes);
     $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
     $smarty->assign("syslogservers", $this->gotoSyslogServers);
+    $smarty->assign("fai_activated",$this->fai_activated);
 
     $ntpser = array();
     foreach($this->gotoNtpServers as $server){
@@ -320,10 +336,11 @@ class workgeneric extends plugin
       $this->netConfigDNS->remove_from_parent();
       $ldap= $this->config->get_ldap_link();
       $ldap->rmdir($this->dn);
+      @log::log("remove","workstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
       show_ldap_error($ldap->get_error(), sprintf(_("Removing of system workstation/generic with dn '%s' failed."),$this->dn));
 
       /* Optionally execute a command after we're done */
-      $this->handle_post_events("remove", array("macAddress" => $this->netConfigDNS->macAddress));
+      $this->handle_post_events("remove", array("macAddress" => $this->netConfigDNS->macAddress,"ipHostNumber" => $this->netConfigDNS-ipHostNumber));
 
       /* Delete references to object groups */
       $ldap->cd ($this->config->current['BASE']);
@@ -427,7 +444,7 @@ class workgeneric extends plugin
     /* Strip out 'default' values */
     foreach (array("gotoSyslogServer") as $val){
 
-      if ($this->attrs[$val] == "default"){
+      if (isset($this->attrs[$val]) && $this->attrs[$val] == "default"){
         $this->attrs[$val]= array();
       }
     }
@@ -479,9 +496,10 @@ class workgeneric extends plugin
       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
       $ldap->cd($this->dn);
       $ldap->add($this->attrs);
+      @log::log("create","workstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
       show_ldap_error($ldap->get_error(), sprintf(_("Saving of system workstation/generic with dn '%s' failed."),$this->dn));
       if(!$this->didAction){
-        $this->handle_post_events("add");
+        $this->handle_post_events("add",array("macAddress" => $this->netConfigDNS->macAddress,"ipHostNumber" => $this->netConfigDNS->ipHostNumber));
       }
     } else {
       if ($this->orig_dn != $this->dn){
@@ -490,9 +508,10 @@ class workgeneric extends plugin
       $ldap->cd($this->dn);
       $this->cleanup();
       $ldap->modify ($this->attrs); 
+      @log::log("modify","workstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
 
       if(!$this->didAction){
-        $this->handle_post_events("modify");
+        $this->handle_post_events("modify",array("macAddress" => $this->netConfigDNS->macAddress,"ipHostNumber" => $this->netConfigDNS->ipHostNumber));
       }
     }