Code

Added fix for non existing fai classes
[gosa.git] / plugins / admin / systems / class_workstationStartup.inc
index 71e39672ed1f42554b1c74262b62f6c2cf0f6168..88e4d38c79874a6407dc76556dfed5729f732056 100644 (file)
@@ -41,6 +41,12 @@ class workstartup extends plugin
   var $FAIrelease         = "";
   var $FAIdebianMirror    = "auto";
 
+  
+  /* FAI class selection */
+  var $InheritedFAIclass           = array();
+  var $InheritedFAIrelease         = "";
+  var $InheritedFAIdebianMirror    = "auto";
+
   /* Contains all possible server/release/class settings */
   var $FAIServRepConfig   = array();
 
@@ -53,8 +59,10 @@ class workstartup extends plugin
      */
     $ldap   = $this->config->get_ldap_link();
     $ldap->cd($this->config->current['BASE']);
-   
-    $this->goLdapServerList = array("default" =>"["._("inherited")."]");
+
+    foreach($this->config->data['SERVERS']['LDAP'] as $server) {
+      $this->goLdapServerList[$server]= $server; // $this->config->data['SERVERS']['LDAP'];
+    }
    
     $_SESSION['getAvailableClassesForThisRelease_CACHE'] = array();
     $_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES'] = array();
@@ -110,8 +118,11 @@ class workstartup extends plugin
       natcasesort($this->FAIclasses);
     }
 
-    $this->FAIclassInfo = $tmp2;
-
+    if(isset($tmp2)){
+      $this->FAIclassInfo = $tmp2;
+    } else {
+      $this->FAIclassInfo = array();
+    }
 
     /* Build up an array like this one :
         [$url]['SERVER'] = 'srv1-002';
@@ -254,6 +265,42 @@ class workstartup extends plugin
     /* Handle inheritance value "default" */
     $this->gotoBootKernels= array("%default%" => '['._("inherited").']');
 
+
+    /* Load hardware list */
+    $ldap= $this->config->get_ldap_link();
+    $ldap->cd($this->config->current['BASE']);
+    $ldap->search("(&(objectClass=gotoWorkstationTemplate)(member=".$this->dn."))");
+    if ($ldap->count() == 1){
+      $map= array("gotoLdapServer","FAIclass","FAIdebianMirror");
+      $attrs= $ldap->fetch();
+
+      foreach ($map as $name){
+        if (!isset($attrs[$name][0])){
+          continue;
+        }
+
+        switch ($name){
+          case 'gotoLdapServer':
+            $this->goLdapServerList= array_merge(array('default' => _("inherited").' ['.$attrs[$name][0].']' ), $this->goLdapServerList);
+            break;
+
+          case 'gotoBootKernel':
+            $this->gotoBootKernels['%default%']=  _("inherited").' ['.$attrs[$name][0].']' ;
+            break;
+
+          case 'FAIclass':
+            $str = split(":",$attrs[$name][0]);
+            $this->InheritedFAIclass    = split("\ ",trim($str[0]));
+            $this->InheritedFAIrelease  = trim($str[1]);
+            break;
+
+          case 'FAIdebianMirror':
+            $this->InheritedFAIdebianMirror = $attrs[$name][0];
+            break;
+        }
+      }
+    }
+
     /* Get list of boot kernels */
     if (isset($this->config->data['TABS'])){
       $command= search_config($this->config->data['TABS'], get_class($this), "KERNELS");
@@ -262,20 +309,21 @@ class workstartup extends plugin
         $message[]= sprintf(_("Command '%s', specified as KERNELS hook for plugin '%s' doesn't seem to exist."), $command,
             get_class($this));
       } else {
+        
         $fh= popen($command, "r");
         while (!feof($fh)) {
           $buffer= trim(fgets($fh, 256));
-          
           if ($buffer != ""){
             $this->gotoBootKernels[preg_replace('/:.*$/', '', $buffer)]= $buffer;
           }
         }
         pclose($fh);
-        ksort($this->gotoBootKernels);
       }
-      
     }
 
+    if(count($this->FAIclass)==0 && $this->FAIrelease == ""){
+      $this->FAIdebianMirror = "inherited";
+    }
   }
 
   
@@ -351,6 +399,8 @@ class workstartup extends plugin
   function selectFriendlyClasses(){
     $tmp=array();
 
+    if($this->FAIdebianMirror == "inherited") return($tmp);
+
     /* check if the current release exists,
         else select the first one ..
      */
@@ -562,11 +612,13 @@ class workstartup extends plugin
       if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
         print_red(_("You must specify a valid mount point."));
       }else{
-        $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
-        $s_mount = $_POST['gotoShareMountPoint'];
-        /* Preparing the new assignment */
-        $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
-        $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
+        if(count($this->gotoAvailableShares)){
+          $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
+          $s_mount = $_POST['gotoShareMountPoint'];
+          /* Preparing the new assignment */
+          $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
+          $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
+        }
       }
     }
 
@@ -578,11 +630,12 @@ class workstartup extends plugin
     }
 
     $smarty->assign("gotoShares",$this->printOutAssignedShares());
+    $smarty->assign("gotoSharesCount",count($this->printOutAssignedShares()));
     $smarty->assign("gotoShareKeys",array_flip($this->printOutAssignedShares()));
     $smarty->assign("gotoBootKernels",$this->gotoBootKernels);
 
     /* Arrays */
-    $tmp = $this->config->data['SERVERS']['LDAP'];
+    $tmp = $this->goLdapServerList;
 
     /* Create divSelectBox for ldap server selection
      */
@@ -601,24 +654,20 @@ class workstartup extends plugin
 
     /* Add Entries 
      */
-    foreach($tmp as $server){
+    foreach($tmp as $key => $server){
       $use ="";
       if(($this->gotoLdapServer == $server) || ($found == false)) {
         $found = true;
         $use = " checked ";
       };
 
-      if($server == "default"){
-        $display = "["._("inherited")."]";
-      }else{
-        $display = $server;
-      }
+      $display = $server;
 
       $SelectBoxLdapServer->AddEntry(
           array(
-            array("string"=>$display),
-            array("string"=>"<input type='radio' name='gotoLdapServer' value='".$server."' ".$use.">",
-                  "attach"=>"style='border-right:0px;'")
+            array("string"=>"<input type='radio' name='gotoLdapServer' value='".$key."' ".$use.">",
+                  "attach"=>"style='border-left:0px;'"),
+            array("string"=>$display)
             ));
     }    
 
@@ -641,6 +690,7 @@ class workstartup extends plugin
     $smarty->assign("FAIclasses",$this->selectFriendlyClasses());
     $smarty->assign("FAIclassesKeys",array_flip($this->selectFriendlyClasses()));
     $smarty->assign("FAIclassKeys",$this->FAIclass);
+    $smarty->assign("InheritedFAIrelease",$this->InheritedFAIrelease);
     
     $div = new divSelectBox("WSFAIscriptClasses");
     $div -> SetHeight("110");
@@ -650,13 +700,25 @@ class workstartup extends plugin
     $str_empty  = " &nbsp;<img src='images/empty.png' alt=\"\" width='7'>"; 
 
     $i = 1;
-    foreach($this->FAIclass as $class){
-      if($i==1){
-        $str = $str_empty.$str_down.$str_remove;
-      }elseif($i == count($this->FAIclass)){
-        $str = $str_up.$str_empty.$str_remove;
+
+    if($this->FAIdebianMirror == "inherited"){
+      $tmp = $this->InheritedFAIclass;
+    }else{
+      $tmp = $this->FAIclass;
+    }
+
+    foreach($tmp as $class){
+
+      if($this->FAIdebianMirror == "inherited"){
+        $str = "";
       }else{
-        $str = $str_up.$str_down.$str_remove;
+        if($i==1){
+          $str = $str_empty.$str_down.$str_remove;
+        }elseif($i == count($this->FAIclass)){
+          $str = $str_up.$str_empty.$str_remove;
+        }else{
+          $str = $str_up.$str_down.$str_remove;
+        }
       }
       $i ++ ; 
 
@@ -723,6 +785,7 @@ class workstartup extends plugin
   function getFAIdebianMirrors()
   {
     $ret = array();
+    $ret['inherited']="["._("inherited")."]";
     $ret['auto']=_("automatic");
     $secs  = array();
 
@@ -759,6 +822,8 @@ class workstartup extends plugin
   {
     $ret = array();
 
+    if($this->FAIdebianMirror == "inherited") return(array());
+
     if(!isset($this->FAIServRepConfig[$this->FAIdebianMirror])){
       $this->FAIdebianMirror = "auto";
     }
@@ -821,6 +886,7 @@ class workstartup extends plugin
     if (chkacl ($this->acl, "gotoKernelParameters") == "" && isset($_POST["customParameters"])){
       $this->customParameters= $_POST["customParameters"];
     }
+
   }
 
 
@@ -847,7 +913,7 @@ class workstartup extends plugin
     /* Find proper terminal path for tftp configuration
        FIXME: This is suboptimal when the default has changed to
        another location! */
-    if ($this->gotoTerminalPath == "default"){
+    if (($this->gotoTerminalPath == "default")){
       $ldap= $this->config->get_ldap_link();
 
       /* Strip relevant part from dn, keep trailing ',' */
@@ -895,15 +961,23 @@ class workstartup extends plugin
     unset( $this->attrs['FAIrelease'] );
     
     $str = "";
-    foreach($this->FAIclass as $class){
-      $str .= $class." ";
-    }
-    $str .= ":" . $this->FAIrelease;
-    $this->attrs['FAIclass']= "";
-    $this->attrs['FAIclass']= trim($str);
 
-    if(empty($this->attrs['FAIclass'])){
-      $this->attrs['FAIclass'] = array();
+    if($this->FAIdebianMirror == "inherited"){
+  
+      $this->attrs['FAIclass'] = $this->attrs['FAIrelease'] =  $this->attrs['FAIdebianMirror'] = array(); 
+
+    }else{
+
+      foreach($this->FAIclass as $class){
+        $str .= $class." ";
+      }
+      $str .= ":" . $this->FAIrelease;
+      $this->attrs['FAIclass']= "";
+      $this->attrs['FAIclass']= trim($str);
+
+      if(empty($this->attrs['FAIclass'])){
+        $this->attrs['FAIclass'] = array();
+      }
     }
 
     /* Add missing arrays */
@@ -914,12 +988,13 @@ class workstartup extends plugin
       }
       if(!isset($this->attrs["$val"])) $this->attrs["$val"]=array();
     }
+
     /* Strip out 'default' values */
     if ($this->attrs['gotoLdapServer'] == "default"){
       $this->attrs['gotoLdapServer']= array();
     }
 
-    if ($this->attrs['gotoBootKernel'] == "%default%" || $this->attrs['gotoBootKernel'] == "default"){
+    if (($this->attrs['gotoBootKernel'] == "default") || ($this->attrs['gotoBootKernel'] == "%default%")){
       $this->attrs['gotoBootKernel']= array();
     }
 
@@ -928,8 +1003,14 @@ class workstartup extends plugin
       $this->FAIdebianMirror = "";
     }
    
+    /* Get FAIstate from object, the generic tab could have changed it during execute */
+    $ldap= $this->config->get_ldap_link();
+    $ldap->cd($this->dn);
+    $ldap->cat($this->dn,array("FAIstate"));
+    $checkFAIstate = $ldap->fetch();
+
     /* Remove FAI objects if no FAI class is selected */ 
-    if(count($this->FAIclass)==0){
+    if((count($this->FAIclass)==0) && (!isset($checkFAIstate['FAIstate']))){
       $tmp = array();
       foreach($this->attrs['objectClass'] as $class){
         if($class != "FAIobject"){
@@ -950,8 +1031,6 @@ class workstartup extends plugin
     }
     $this->attrs['gotoShare']=$tmp;
 
-    $ldap= $this->config->get_ldap_link();
-    $ldap->cd($this->dn);
     $this->cleanup();
     $ldap->modify ($this->attrs);