Code

More speed optimizations
[gosa.git] / plugins / admin / systems / class_workstationStartup.inc
index ad9077747ed8082abc1b2b88b64c8e4e44e5e396..812a48982592ef4df973562f09cbee2308fc918d 100644 (file)
@@ -1,4 +1,5 @@
 <?php
+
 class workstartup extends plugin
 {
   /* CLI vars */
@@ -9,9 +10,9 @@ class workstartup extends plugin
   /* Generic terminal attributes */
   var $bootmode             = "G";
   var $goLdapServerList     = array();
-  var $gotoBootKernel       = "default";
+  var $gotoBootKernel       = "default-inherited";
   var $gotoKernelParameters = "";
-  var $gotoLdapServer       = "default";
+  var $gotoLdapServer       = "default-inherited";
   var $gotoModules          = array();
   var $gotoAutoFs           = array();
   var $gotoFilesystem       = array();
@@ -43,7 +44,6 @@ class workstartup extends plugin
 
   
   /* FAI class selection */
-  var $FAIinherit                  = false; 
   var $InheritedFAIclass           = array();
   var $InheritedFAIrelease         = "";
   var $InheritedFAIdebianMirror    = "auto";
@@ -51,9 +51,9 @@ class workstartup extends plugin
   /* Contains all possible server/release/class settings */
   var $FAIServRepConfig   = array();
 
-  function workstartup ($config, $dn= NULL)
+  function workstartup ($config, $dn= NULL, $parent= NULL)
   {
-    plugin::plugin ($config, $dn);
+    plugin::plugin ($config, $dn, $parent);
 
     /* Creating a list of valid Mirrors 
      * none will not be saved to ldap.
@@ -68,12 +68,18 @@ class workstartup extends plugin
     $_SESSION['getAvailableClassesForThisRelease_CACHE'] = array();
     $_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES'] = array();
 
-    /* Search all FAI objects */
-    $ldap->search("(|(objectClass=FAIpackageList)(objectClass=FAItemplate)(objectClass=FAIvariable)(objectClass=FAIscript)(objectClass=FAIhook)(objectClass=FAIprofile)(objectClass=FAIpartitionTable))",array("cn","objectClass","FAIdebianSection"));
-    /* Sort all entries, and attach elementtype.
-     * To be able to show the types in the listbox.
-     */
-    while($attr = $ldap->fetch()){
+    $ui = get_userinfo();
+    $res = get_list(          "(|(objectClass=FAIpackageList)".
+        "(objectClass=FAItemplate)".
+        "(objectClass=FAIvariable)".
+        "(objectClass=FAIscript)".
+        "(objectClass=FAIhook)".
+        "(objectClass=FAIprofile)".
+        "(objectClass=FAIpartitionTable))",
+        $ui->subtreeACL,$this->config->current['BASE'],
+        array("cn","objectClass","FAIdebianSection"));
+    
+    foreach($res as $attr){
       $cn = $attr['cn'][0];
     
       $_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES'][] = $attr;
@@ -119,8 +125,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';
@@ -261,7 +270,7 @@ class workstartup extends plugin
     $this->orig_dn= $this->dn;
 
     /* Handle inheritance value "default" */
-    $this->gotoBootKernels= array("%default%" => '['._("inherited").']');
+    $this->gotoBootKernels= array();
 
 
     /* Load hardware list */
@@ -269,7 +278,7 @@ class workstartup extends plugin
     $ldap->cd($this->config->current['BASE']);
     $ldap->search("(&(objectClass=gotoWorkstationTemplate)(member=".$this->dn."))");
     if ($ldap->count() == 1){
-      $map= array("gotoLdapServer","gotoBootKernel","FAIclass","FAIdebianMirror");
+      $map= array("gotoLdapServer","FAIclass","FAIdebianMirror","gotoBootKernel");
       $attrs= $ldap->fetch();
 
       foreach ($map as $name){
@@ -279,11 +288,11 @@ class workstartup extends plugin
 
         switch ($name){
           case 'gotoLdapServer':
-            $this->goLdapServerList= array_merge(array('default' => _("inherited").' ['.$attrs[$name][0].']' ), $this->goLdapServerList);
+            $this->goLdapServerList= array_merge(array('default-inherited' => _("inherited").' ['.$attrs[$name][0].']' ), $this->goLdapServerList);
             break;
 
           case 'gotoBootKernel':
-            $this->gotoBootKernels['%default%']=  _("inherited").' ['.$attrs[$name][0].']' ;
+            $this->gotoBootKernels['default-inherited']=  _("inherited").' ['.$attrs[$name][0].']' ;
             break;
 
           case 'FAIclass':
@@ -308,19 +317,38 @@ class workstartup extends plugin
             get_class($this));
       } else {
         
+        $first = false; 
         $fh= popen($command, "r");
         while (!feof($fh)) {
           $buffer= trim(fgets($fh, 256));
-          if ($buffer != ""){
-            $this->gotoBootKernels[preg_replace('/:.*$/', '', $buffer)]= $buffer;
+  
+          if(!empty($buffer)){
+
+            $name=$value = $buffer;
+            if(preg_match("/:/",$buffer)){
+              $name = preg_replace("/:.*$/","",$buffer);
+              $value= preg_replace("/^.*:/","",$buffer);
+              $this->gotoBootKernels[$name]= $name.":".$value;
+            }else{
+              $this->gotoBootKernels[$name]= $value;
+            }
+            if($this->gotoBootKernel =="" ){
+              $this->gotoBootKernel = $name;
+            }
+
           }
         }
         pclose($fh);
       }
     }
 
+    /* Turn to default, if we've nothing to inherit */
+    if (!isset($this->gotoBootKernels['default-inherited']) && $this->gotoBootKernel == "default-inherited"){
+      $this->gotoBootKernel= "default";
+    }
+
     if(count($this->FAIclass)==0 && $this->FAIrelease == ""){
-      $this->FAIinherit =true;
+      $this->FAIdebianMirror = "inherited";
     }
   }
 
@@ -339,28 +367,6 @@ class workstartup extends plugin
       return($_SESSION['getAvailableClassesForThisRelease_CACHE'][$release]);
     }
 
-    /* Create cache with all classes 
-     */
-    if((!isset($_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES'])) ||
-       (!is_array($_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES'])) ||
-       (count($_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES']) ==0 )){
-
-      /* Get ldap connection */
-      $ldap   = $this->config->get_ldap_link();
-      $ldap->cd($this->config->current['BASE']);
-
-      /* Get possible classes ... 
-         This would be faste with some kind of caching ... 
-       */
-      $ldap->search("(|(objectClass=FAIpackageList)(objectClass=FAItemplate)(objectClass=FAIvariable)(objectClass=FAIscript)(objectClass=FAIhook)(objectClass=FAIprofile)(objectClass=FAIpartitionTable))",array("cn"),true);
-      /* Sort all entries, and attach elementtype.
-       * To be able to show the types in the listbox.
-       */
-      while($attr = $ldap->fetch()){
-        $_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES'][] = $attr;
-      }  
-    }
-
     /* Walk through cache and get out what we need.
      *   
      *   Function od : "$this->generateDNSyn($release)"
@@ -397,6 +403,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 ..
      */
@@ -582,13 +590,6 @@ class workstartup extends plugin
       }
     }
 
-    /* Delete selected class from our list */
-    if((isset($_POST['DelClass']))&&(isset($_POST['FAIclassSel']))){
-      if(isset($this->FAIclass[$_POST['FAIclassSel']])){
-        unset($this->FAIclass[$_POST['FAIclassSel']]);
-      }
-    }
-
     /* Show main page */
     $smarty= get_smarty();
     $smarty->assign("SelectBoxLdapServer","");
@@ -608,11 +609,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;
+        }
       }
     }
 
@@ -624,6 +627,7 @@ 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);
 
@@ -658,9 +662,9 @@ class workstartup extends plugin
 
       $SelectBoxLdapServer->AddEntry(
           array(
-            array("string"=>$display),
             array("string"=>"<input type='radio' name='gotoLdapServer' value='".$key."' ".$use.">",
-                  "attach"=>"style='border-right:0px;'")
+                  "attach"=>"style='border-left:0px;'"),
+            array("string"=>$display)
             ));
     }    
 
@@ -677,14 +681,12 @@ class workstartup extends plugin
       $smarty->assign($val."ACL", chkacl($this->acl, $val));
     }
 
-    $smarty->assign("FAIinherit",$this->FAIinherit);
     $smarty->assign("FAIdebianMirrors",$this->getFAIdebianMirrors());
     $smarty->assign("FAIreleases",$this->getFAIreleases());
     $smarty->assign("FAIrelease",$this->FAIrelease);
     $smarty->assign("FAIclasses",$this->selectFriendlyClasses());
     $smarty->assign("FAIclassesKeys",array_flip($this->selectFriendlyClasses()));
     $smarty->assign("FAIclassKeys",$this->FAIclass);
-    $smarty->assign("InheritedFAIdebianMirror",$this->InheritedFAIdebianMirror);
     $smarty->assign("InheritedFAIrelease",$this->InheritedFAIrelease);
     
     $div = new divSelectBox("WSFAIscriptClasses");
@@ -696,7 +698,7 @@ class workstartup extends plugin
 
     $i = 1;
 
-    if($this->FAIinherit){
+    if($this->FAIdebianMirror == "inherited"){
       $tmp = $this->InheritedFAIclass;
     }else{
       $tmp = $this->FAIclass;
@@ -704,7 +706,7 @@ class workstartup extends plugin
 
     foreach($tmp as $class){
 
-      if($this->FAIinherit){
+      if($this->FAIdebianMirror == "inherited"){
         $str = "";
       }else{
         if($i==1){
@@ -780,6 +782,7 @@ class workstartup extends plugin
   function getFAIdebianMirrors()
   {
     $ret = array();
+    $ret['inherited']="["._("inherited")."]";
     $ret['auto']=_("automatic");
     $secs  = array();
 
@@ -816,29 +819,32 @@ class workstartup extends plugin
   {
     $ret = array();
 
+    if($this->FAIdebianMirror == "inherited") return(array());
+
     if(!isset($this->FAIServRepConfig[$this->FAIdebianMirror])){
       $this->FAIdebianMirror = "auto";
     }
 
-    $errorClasses = "";  
-  
-    foreach($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'] as $release => $sections){
-      $use = true;
-      
-      if(!count($this->FAIclass) == 0){
-        foreach($this->FAIclass as $class){
-          if(!in_array($class, $sections['PACKAGES'])){
-            $use = false;
-            $errorClasses[$class] = $class;
-          }else{
-            if(isset($errorClasses[$class])){
-              unset($errorClasses[$class]); 
+    $errorClasses = array();  
+    if(isset($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'])) {
+      foreach($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'] as $release => $sections){
+        $use = true;
+
+        if(!count($this->FAIclass) == 0){
+          foreach($this->FAIclass as $class){
+            if(!in_array($class, $sections['PACKAGES'])){
+              $use = false;
+              $errorClasses[$class] = $class;
+            }else{
+              if(isset($errorClasses[$class])){
+                unset($errorClasses[$class]); 
+              }
             }
           }
         }
-      }
-      if($use){
-        $ret[$release]=$release;
+        if($use){
+          $ret[$release]=$release;
+        }
       }
     } 
     if((count($ret) == 0 ) && ($this->FAIdebianMirror != "auto")){
@@ -879,13 +885,6 @@ class workstartup extends plugin
       $this->customParameters= $_POST["customParameters"];
     }
 
-    if(isset($_POST['WorkstationStarttabPosted'])){
-      if(isset($_POST['FAIinherit'])){
-        $this->FAIinherit = true;
-      }else{
-        $this->FAIinherit = false;
-      }
-    }
   }
 
 
@@ -961,7 +960,7 @@ class workstartup extends plugin
     
     $str = "";
 
-    if($this->FAIinherit){
+    if($this->FAIdebianMirror == "inherited"){
   
       $this->attrs['FAIclass'] = $this->attrs['FAIrelease'] =  $this->attrs['FAIdebianMirror'] = array(); 
 
@@ -989,11 +988,11 @@ class workstartup extends plugin
     }
 
     /* Strip out 'default' values */
-    if ($this->attrs['gotoLdapServer'] == "default"){
+    if ($this->attrs['gotoLdapServer'] == "default-inherited"){
       $this->attrs['gotoLdapServer']= array();
     }
 
-    if (($this->attrs['gotoBootKernel'] == "default") || ($this->attrs['gotoBootKernel'] == "%default%")){
+    if (($this->attrs['gotoBootKernel'] == "default-inherited") || ($this->attrs['gotoBootKernel'] == "%default%")){
       $this->attrs['gotoBootKernel']= array();
     }
 
@@ -1002,15 +1001,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){
-      $tmp = array();
-      foreach($this->attrs['objectClass'] as $class){
-        if($class != "FAIobject"){
-          $tmp[] = $class;
-        }
-      }
-      $this->attrs['objectClass']     = $tmp;
+    if((count($this->FAIclass)==0) && (!isset($checkFAIstate['FAIstate']))){
       $this->attrs['FAIclass']        = array();
       $this->attrs['FAIdebianMirror'] = array();
     }
@@ -1024,8 +1022,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);