Code

Updated get_ou it receives values from the config registry now.
[gosa.git] / gosa-plugins / goto / admin / systems / goto / class_workstationStartup.inc
index 03c98ae4876876e3a6ac38d8f7aa489fe332b991..894f5e7588da8c12bc5ca466f8a851d052787033 100644 (file)
@@ -8,8 +8,6 @@ class workstartup extends plugin
 
   /* Generic terminal attributes */
        # This is disabled as long there is no possiblilty to set these parameters
-  #var $bootmode             = "G";
-  var $bootmode             = "";
   var $gotoBootKernel       = "default-inherited";
   var $gotoKernelParameters = "";
   var $gotoLdapServer       = "default-inherited";
@@ -61,8 +59,7 @@ class workstartup extends plugin
   function workstartup (&$config, $dn= NULL, $parent= NULL)
   {
     /* Check if FAI is active */
-    $tmp= $config->search("faiManagement", "CLASS",array('menu','tabs'));
-    if(!empty($tmp) && class_available("faiManagement")){
+    if($config->pluginEnabled("faiManagement")){
       $this->fai_activated = TRUE;
     }else{
       $this->attributes = array("gotoLdapServer", "gotoBootKernel", "gotoKernelParameters", "gotoShare");
@@ -72,7 +69,7 @@ class workstartup extends plugin
     plugin::plugin ($config, $dn, $parent);
 
     /* Check for si daemon */
-    $this->si_active = $this->config->get_cfg_value("gosaSupportURI") != "";
+    $this->si_active = $this->config->get_cfg_value("core","gosaSupportURI") != "";
 
     /* Check object group membership */
     if(!isset($this->parent->by_object['ogroup'])){
@@ -251,6 +248,26 @@ class workstartup extends plugin
         $this->update_fai_cache();
       }
     }
+
+
+    // Prepare lists
+    $this->ldapList = new sortableListing(array(),array(), TRUE);
+    $this->ldapList->setDeleteable(true);
+    $this->ldapList->setEditable(false);
+    $this->ldapList->setWidth("100%");
+    $this->ldapList->setHeight("100px");
+    $this->ldapList->setHeader(array(_("LDAP server")));
+    $this->ldapList->setDefaultSortColumn(0);
+
+    $this->faiList = new sortableListing(array(),array(), TRUE);
+    $this->faiList->setDeleteable(true);
+    $this->faiList->setEditable(false);
+    $this->faiList->setWidth("100%");
+    $this->faiList->setHeight("160px");
+    $this->faiList->setColspecs(array('50%','50%'));
+    $this->faiList->setHeader(array(_("Name"),_("Classes")));
+    $this->faiList->setDefaultSortColumn(0);
+
   }
 
   
@@ -326,66 +343,21 @@ class workstartup extends plugin
         }
       }
 
-      $sort = false;
+
+        $this->faiList->save_object();
+        $action = $this->faiList->getAction();
+        if($action['action'] == 'delete'){
+            $id = $this->faiList->getKey($action['targets'][0]);
+            unset($this->FAIclass[$id]);
+        }
+        if($action['action'] == 'reorder'){
+            $this->FAIclass= $this->faiList->getMaintainedData();
+        }
 
       /* Move one used class class one position up or down */
       if($this->acl_is_writeable("FAIclass")){
         foreach($_POST as $name => $val){
 
-          $sort_type = false;
-          if((preg_match("/sort_up/",$name))&&(!$sort)){
-            $sort_type = "sort_up_";
-          }
-          if((preg_match("/sort_down/",$name))&&(!$sort)){
-            $sort_type = "sort_down_";
-          }
-
-          if(($sort_type)&&(!$sort)){
-            $value = postDecode(preg_replace("/_.*$/i","",preg_replace("/".$sort_type."/i","",$name)));
-            $sort = true;
-
-            $last = -1;
-            $change_down  = -1;
-
-            /* Create array with numeric index */ 
-            $tmp = array();
-            foreach($this->FAIclass as $class){
-              $tmp [] = $class;
-            }
-
-            /* Walk trough array */
-            foreach($tmp as $key => $faiName){
-              if($faiName == $value){
-                if($sort_type == "sort_up_"){
-                  if($last != -1){
-                    $change_down= $last;
-                  }
-                }else{
-                  if(isset($tmp[$key+1])){
-                    $change_down = $key;
-                  }
-                }
-              }
-              $last = $key;
-            }
-
-            $tmp2 = array();
-            $skip = false;    
-
-            foreach($tmp as $ky => $vl){
-
-              if($ky == $change_down){
-                $skip = $vl;
-              }else{
-                $tmp2[$vl] = $vl;
-              }
-              if(($skip != false)&&($ky != $change_down)){
-                $tmp2[$skip]  = $skip;
-                $skip =false;
-              }
-            }   
-            $this->FAIclass = $tmp2; 
-          }
 
           if(preg_match("/fai_remove/i",$name)){
             $value = postDecode(preg_replace("/fai_remove_/i","",$name));
@@ -453,10 +425,7 @@ class workstartup extends plugin
     $smarty->assign("gotoShareKeys",array_flip($this->printOutAssignedShares()));
     $smarty->assign("gotoBootKernels",$this->gotoBootKernels);
 
-    /* Create divSelectBox for ldap server selection
-     */
-    $SelectBoxLdapServer = new divSelectBox("LdapServer");
-    $SelectBoxLdapServer->SetHeight(100);
+    $this->ldapList->setAcl($this->getacl('gotoLdapServer'));
 
     /* Add new ldap server to the list */
     if($this->acl_is_writeable("gotoLdapServer") && 
@@ -472,67 +441,38 @@ class workstartup extends plugin
     }
     
     /* Move ldap servers up and down */
-    if(!$this->gotoLdap_inherit && $this->acl_is_writeable("gotoLdapServer")){
-      foreach($_POST as $name => $value){
-        if(preg_match("/sort_ldap_up_/",$name)){
-          $id = preg_replace("/^sort_ldap_up_([0-9]*)$/","\\1",$name);
-          $from =  $id;  
-          $to   =  $id -1;
-          $tmp = $this->array_switch_item($this->gotoLdapServers,$from,$to);
-          if($tmp){
-            $this->gotoLdapServers = $tmp;
-          }
-          break;
-        }
-        if(preg_match("/sort_ldap_down_/",$name)){
-          $id = preg_replace("/^sort_ldap_down_([0-9]*)$/","\\1",$name);
-          $from =  $id;  
-          $to   =  $id +1;
-          $tmp = $this->array_switch_item($this->gotoLdapServers,$from,$to);
-          if($tmp){
-            $this->gotoLdapServers = $tmp;
-          }
-          break;
-        }
-        if(preg_match("/gotoLdapRemove_/",$name)){
-          $id = preg_replace("/^gotoLdapRemove_([0-9]*)$/","\\1",$name);
-          $value = $this->gotoLdapServers[$id];
-          $this->gotoLdapServers = array_remove_entries(array($value),$this->gotoLdapServers);
-          break;
-        }
-      } 
+    $this->ldapList->save_object();
+    $action = $this->ldapList->getAction();
+    if($action['action'] == 'reorder'){
+        $this->gotoLdapServers = array_values($this->ldapList->getMaintainedData());
+    }
+    if($action['action'] == 'delete'){
+        $id = $this->ldapList->getKey($action['targets'][0]);
+        $value = $this->gotoLdapServers[$id];
+        $this->gotoLdapServers = array_remove_entries(array($value),$this->gotoLdapServers);
     }
-  
-    /* Add Entries */
-    if($this->acl_is_readable("gotoLdapServer")){
 
-      foreach($this->gotoLdapServers as $key => $server){
+    /* Add Entries */
+    $data = $lData = array();
+    foreach($this->gotoLdapServers as $key => $server){
+        $data[$key]=$server;
 
         /* Announce missing entries */
         if(!in_array($server,$this->gotoLdapServerList)){
-          $server = $server."&nbsp;<font style='color:red'>(missing)</font>";
+            $server = $server."&nbsp;<font style='color:red'>(missing)</font>";
         }
 
         /* Convert old style entry */
         if (!preg_match('%:ldaps?://%', $server)){
-          $server= "ldap://".preg_replace('/^([^:]+):/', '\1/', $server);
-
-        /* Beautify new style entries */
-      } else {
-        $server= preg_replace("/^[^:]+:/", "", $server);
-      }
+            $server= "ldap://".preg_replace('/^([^:]+):/', '\1/', $server);
+        } else {
+            $server= preg_replace("/^[^:]+:/", "", $server);
+            $lData[$key] = array('data'=>array($server));
+        }    
+    }
+    $this->ldapList->setListData($data,$lData);
+    $this->ldapList->update();
 
-      $SelectBoxLdapServer->AddEntry(
-          array(
-            array(
-              "string" => $server),
-            array("string" =>
-              image('images/lists/sort-up.png',"sort_ldap_up_".$key,'',"top"). 
-              image('images/lists/sort-down.png',"sort_ldap_down_".$key,'',"bottom"). 
-              image('images/lists/trash.png',"gotoLdapRemove_".$key),
-              "attach" => "style='text-align:right;width:60px;border-right:0px;'")));
-      }    
-    }    
 
     if($this->gotoLdap_inherit){
       $smarty->assign("gotoLdapServerACL_inherit", preg_replace("/w/","",$this->getacl("gotoLdapServer")));;
@@ -556,7 +496,7 @@ class workstartup extends plugin
         $list[$key] = $entry;
       }
     }
-    $smarty->assign("gotoLdapServers",    $SelectBoxLdapServer->DrawList());
+    $smarty->assign("gotoLdapServers",    $this->ldapList->render());
     $smarty->assign("gotoLdapServerList", $list);
     $smarty->assign("gotoLdap_inherit",   $this->gotoLdap_inherit);
     $smarty->assign("JS",  session::get('js'));
@@ -576,9 +516,6 @@ class workstartup extends plugin
     $this->update_fai_cache();
     $smarty->assign("si_fai_action_failed",$this->si_fai_action_failed);
     $smarty->assign("si_active",$this->si_active);
-
-    $div = new divSelectBox("WSFAIscriptClasses");
-    $div -> SetHeight("100");
   
     if(!$this->si_fai_action_failed && $this->si_active && $this->fai_activated){
 
@@ -599,15 +536,6 @@ class workstartup extends plugin
       $smarty->assign("gotoBootKernels",$this->cache['KERNELS'][$release]);
       $smarty->assign("InheritedFAIrelease",$this->InheritedFAIrelease);
 
-      $str_empty  = image('images/empty.png');
-      if($this->acl_is_writeable("FAIclass")){
-        $str_up     = image('images/lists/sort-up.png','sort_up_%s');
-        $str_down   = image('images/lists/sort-down.png','sort_down_%s');
-        $str_remove = image('images/lists/trash.png','fai_remove_%s');
-      }else{
-        $str_up=$str_down=$str_remove=$str_empty;
-      }
-
       /* Get classes */
       if($this->FAIdebianMirror == "inherited"){
         $tmp = $this->InheritedFAIclass;
@@ -617,6 +545,7 @@ class workstartup extends plugin
 
       /* Get invalid classes */
       $invalid = $this->get_invalid_classes($tmp);
+      $data = $lData = array();
 
       /* Draw every single entry */
       $i = 1;
@@ -630,20 +559,6 @@ class workstartup extends plugin
             $marker = "&nbsp;<font color='red'>("._("Not available in current setup").")</font>";
           }
 
-          /* Create up/down priority icons  
-           * Skip this, if we have inherited the FAI classes.
-           */
-          if($this->FAIdebianMirror == "inherited"){
-            $str = "";
-          }else{
-            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 ++ ; 
 
           /* Get Description tag 
@@ -676,32 +591,18 @@ class workstartup extends plugin
             $desc = "&nbsp;".trim($desc)."";
           }        
 
-          $div->AddEntry(array(
-                array("string"=>$class.$marker),
-                array("string"=>$desc),
-                array("string"=>preg_replace("/\%s/",postEncode($class),$str),"attach"=>"style='width:60px;border-right:none;'")
-                ));
+          $data[$class] = $class;
+          $lData[$class] = array('data' => array($class,$desc));
         }  
       }// END FAI output generation 
     }// END FAI output generation 
-    $smarty->assign("FAIScriptlist",$div->DrawList()); 
 
-    /* Radio button group */
-    if (preg_match("/G/", $this->bootmode)) {
-      $smarty->assign("graphicalbootup", "checked");
-    } else {
-      $smarty->assign("graphicalbootup", "");
-    }
-    if (preg_match("/T/", $this->bootmode)) {
-      $smarty->assign("textbootup", "checked");
-    } else {
-      $smarty->assign("textbootup", "");
-    }
-    if (preg_match("/D/", $this->bootmode)) {
-      $smarty->assign("debugbootup", "checked");
-    } else {
-      $smarty->assign("debugbootup", "");
-    }
+    $this->faiList->setAcl('rwcdm');
+    $this->faiList->setReorderable($this->FAIdebianMirror != "inherited");
+    $this->faiList->setListData($data,$lData);
+    $this->faiList->update();
+
+    $smarty->assign("FAIScriptlist", $this->faiList->render());
 
     /* Show main page */
     $smarty->assign("gotoKernelParameters",$this->gotoKernelParameters);
@@ -735,11 +636,6 @@ class workstartup extends plugin
       }else{
         $this->gotoLdap_inherit = FALSE;
       }
-
-      /* Save group radio buttons */
-      if ($this->acl_is_writeable("bootmode") && isset($_POST["bootmode"])){
-        $this->bootmode= $_POST["bootmode"];
-      }
     }
   }
 
@@ -778,7 +674,7 @@ class workstartup extends plugin
       $ldap= $this->config->get_ldap_link();
 
       /* Strip relevant part from dn, keep trailing ',' */
-      $tmp= preg_replace("/^cn=[^,]+,".preg_quote(get_ou('terminalRDN'), '/')."/i", "", $this->dn);
+      $tmp= preg_replace("/^cn=[^,]+,".preg_quote(get_ou("termgeneric", "terminalRDN") , '/')."/i", "", $this->dn);
       $tmp= preg_replace("/".$this->config->current['BASE']."$/i", "", $tmp);
 
       /* Walk from top to base and try to load default values for
@@ -786,7 +682,7 @@ class workstartup extends plugin
       while (TRUE){
         $tmp= preg_replace ("/^[^,]+,/", "", $tmp);
 
-        $ldap->cat("cn=default,".get_ou('terminalRDN').$tmp.
+        $ldap->cat("cn=default,".get_ou("termgeneric", "terminalRDN") .$tmp.
             $this->config->current['BASE'], array('gotoTerminalPath'));
         $attrs= $ldap->fetch();
         if (isset($attrs['gotoTerminalPath'])){
@@ -892,7 +788,7 @@ class workstartup extends plugin
     $this->handle_post_events("modify");
 
     /* Check if LDAP server has changed */
-    if ((isset($this->attrs['gotoLdapServer']) && class_available("DaemonEvent")) || $this->gotoLdap_inherit){
+    if ($this->si_active && (isset($this->attrs['gotoLdapServer']) && class_available("DaemonEvent") || $this->gotoLdap_inherit)){
       $events = DaemonEvent::get_event_types(SYSTEM_EVENT | HIDDEN_EVENT);
       $o_queue = new gosaSupportDaemon();
       if(isset($events['TRIGGERED']['DaemonEvent_reload_ldap_config'])){
@@ -1029,7 +925,6 @@ class workstartup extends plugin
           "plProvidedAcls"=> array(
             "gotoLdapServer"        => _("Ldap server"),
             "gotoBootKernel"        => _("Boot kernel"),
-            "bootmode"              => _("Boot mode"),
             "gotoKernelParameters"  => _("Kernel parameter"),
 
             "gotoModules"           => _("Kernel modules"),
@@ -1304,7 +1199,7 @@ class workstartup extends plugin
   function GetHookElements()
   {
     $ret = array();
-    $cmd= $this->config->search("servrepository", "repositoryBranchHook",array('tabs'));
+    $cmd= $this->config->get_cfg_value("servrepository", "repositoryBranchHook");
     if(!empty($cmd)){
       $res = shell_exec($cmd);
       $res2 = trim($res);
@@ -1329,7 +1224,7 @@ class workstartup extends plugin
    */
   function dn_to_release_name($dn)
   {
-    $relevant = preg_replace("/,".preg_quote(get_ou("faiBaseRDN"), '/').".*$/i","",$dn);
+    $relevant = preg_replace("/,".preg_quote(get_ou("termgeneric", "terminalRDN") , '/').".*$/i","",$dn);
     $parts    = array_reverse(explode(",",$relevant));
     $str ="";
     foreach($parts as $part){