X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=plugins%2Fadmin%2Ffai%2Fclass_faiProfile.inc;h=e9b59675fe583568bf80df95c71d288fcec7b878;hb=5911441e8460700302accbdc64249b2207324415;hp=5ca3329b1550f2d7c50d21f0d97607efe6b51f97;hpb=37b9ba6c41c1a84cbbd4da1b57e9af9667743e4d;p=gosa.git diff --git a/plugins/admin/fai/class_faiProfile.inc b/plugins/admin/fai/class_faiProfile.inc index 5ca3329b1..e9b59675f 100644 --- a/plugins/admin/fai/class_faiProfile.inc +++ b/plugins/admin/fai/class_faiProfile.inc @@ -2,11 +2,6 @@ class faiProfile extends plugin { - /* CLI vars */ - var $cli_summary = "Manage server basic objects"; - var $cli_description = "Some longer text\nfor help"; - var $cli_parameters = array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser"); - /* attribute list for save action */ var $ignore_account = TRUE; @@ -30,41 +25,91 @@ class faiProfile extends plugin var $FAIclasses = array(); // Contains classname seperated in an array var $FAIAllclasses = array(); // Contains all possible Classnames + var $FAIstate = ""; + var $base = ""; + var $release = ""; + var $copy_paste_mode= false; + var $cut_paste_mode = false; + + var $CopyPasteVars = array("FAIclass","FAIclasses","FAIAllclasses"); + function faiProfile($config, $dn= NULL) { /* Load Attributes */ plugin::plugin ($config, $dn); $ldap=$this->config->get_ldap_link(); + $this->acl = "#all#"; + + if($this->dn != "new"){ + /* Set acls + */ + $ui = get_userinfo(); + $acl = get_permissions ($this->dn, $ui->subtreeACL); + $acli = get_module_permission($acl, "FAIclass", $this->dn); + $this->acl=$acli; + } + + /* Parse ldap attribute to get all assigned classes */ $tmp = split(" ",$this->FAIclass); - + $tmp2 = array(); foreach($tmp as $class){ if(!empty($class)){ - $this->FAIclasses[trim($class)] = trim($class); + $tmp2[trim($class)] = trim($class); } } - natcasesort($this->FAIclasses); - reset($this->FAIclasses) ; - - $categories = array("FAIscript","FAItemplate","FAIhook","FAIvariable","FAIpartitionTAble","FAIpackage"); - - $sort = array(); - - $base = $_SESSION['faifilter']['base']; + + if(isset($this->attrs['FAIstate'][0])){ + $this->FAIstate = $this->attrs['FAIstate'][0]; + } + + /* Sort assigned classes */ + if(is_array($tmp2)){ + foreach($tmp2 as $class){ + $this->FAIclasses[$class]=$class; + } + } + + /* Search only in fai tree */ + $ObjectTypes = array( + "FAIpartitionTable" => array("OU"=>"ou=disk," ), + "FAIpackageList" => array("OU"=>"ou=packages," ), + "FAIscript" => array("OU"=>"ou=scripts," ), + "FAIvariable" => array("OU"=>"ou=variables," ), + "FAIhook" => array("OU"=>"ou=hooks," ), +# "FAIprofile" => array("OU"=>"ou=profiles," ), + "FAItemplate" => array("OU"=>"ou=templates," )); + + $base= "ou=fai,ou=configs,ou=systems,".$_SESSION['CurrentMainBase']; + if($_SESSION['faifilter']['branch']!="main"){ + $base = $_SESSION['faifilter']['branch']; + } + + /* Get ldap connection */ + $ldap= $this->config->get_ldap_link(); $ldap->cd($base); - $ldap->search("(objectClass=*)",array("*")); - while($attrs = $ldap->fetch()){ - foreach($categories as $cat){ - if(in_array($cat,$attrs['objectClass'])){ - $this->FAIAllclasses[$attrs['cn'][0]][$cat]=$attrs; - $sort[strtolower($attrs['cn'][0])] = $attrs['cn'][0]; - } + $sort = array(); + /* Capture objects from given base */ + $result = array(); + foreach($ObjectTypes as $oc => $data){ + $ou = $data['OU'].$base; + + $ldap->ls("(objectClass=".$oc.")",$ou,array("cn","objectClass","dn")); + while($attrs = $ldap->fetch()){ + $this->FAIAllclasses[$attrs['cn'][0]][$oc]=$attrs; + $sort[strtolower($attrs['cn'][0])] = $attrs['cn'][0]; } - } - ksort($sort); + } + + /* Sort the sort array */ + //ksort($sort); + + /* Reorder the FAIclasses array */ foreach($sort as $name){ $tmp[$name] =$this->FAIAllclasses[$name]; } + + /* Assign sorted classes */ $this->FAIAllclasses = array(); $this->FAIAllclasses = $tmp; @@ -74,8 +119,92 @@ class faiProfile extends plugin $this->old_cn = $this->cn; } + + /* Combine new array, used for up down buttons */ + function combineArrays($ar0,$ar1,$ar2) + { + $ret = array(); + if(is_array($ar0)) + foreach($ar0 as $ar => $a){ + $ret[$ar]=$a; + } + if(is_array($ar1)) + foreach($ar1 as $ar => $a){ + $ret[$ar]=$a; + } + if(is_array($ar2)) + foreach($ar2 as $ar => $a){ + $ret[$ar]=$a; + } + return($ret); + } + + /* returns position in array */ + function getpos($atr,$attrs) + { + $i = 0; + foreach($attrs as $attr => $name) { + $i++; + if($attr == $atr){ + return($i); + } + } + return(-1); + } + + /* Transports the given Arraykey one position up*/ + function ArrayUp($atr,$attrs) + { + $ret = $attrs; + $pos = $this->getpos($atr,$attrs) ; + $cn = count($attrs); + if(!(($pos == -1)||($pos == 1))){ + $before = array_slice($attrs,0,($pos-2)); + $mitte = array_reverse(array_slice($attrs,($pos-2),2)); + $unten = array_slice($attrs,$pos); + $ret = array(); + $ret = $this->combineArrays($before,$mitte,$unten); + } + return($ret); + } + + + /* Transports the given Arraykey one position down*/ + function ArrayDown($atr,$attrs) + { + $ret = $attrs; + $pos = $this->getpos($atr,$attrs) ; + $cn = count($attrs); + if(!(($pos == -1)||($pos == $cn))){ + $before = array_slice($attrs,0,($pos-1)); + $mitte = array_reverse(array_slice($attrs,($pos-1),2)); + $unten = array_slice($attrs,($pos+1)); + $ret = array(); + $ret = $this->combineArrays($before,$mitte,$unten); + } + return($ret); + } + + /* class one position up */ + function catUp($id) + { + /* Get all cats depinding on current dir */ + $cats = $this->FAIclasses; + $this->FAIclasses =$this->ArrayUp($id,$cats); + } + + /* Class one position down */ + function catDown($id) + { + /* Get all cats depinding on current dir */ + $cats = $this->FAIclasses; + $this->FAIclasses =$this->ArrayDown($id,$cats); + } + function execute() { + /* Call parent execute */ + plugin::execute(); /* Fill templating stuff */ $smarty= get_smarty(); $display= ""; @@ -84,14 +213,39 @@ class faiProfile extends plugin $s_action = ""; /* Remove class name From list */ + $sort_once = false; foreach($_POST as $name => $post){ if(preg_match("/DEL_/i",$name)){ $s_action = "delete"; $s_entry = preg_replace("/DEL_/","",$name); - $s_entry = preg_replace("/_.*$/","",$s_entry); + $s_entry = base64_decode(preg_replace("/_.*$/","",$s_entry)); }elseif(preg_match("/Add_class/i",$name)){ $s_action = "add"; + }elseif(preg_match("/DelClass/i",$name)){ + $s_action = "delete"; + $s_entry = $_POST['FAIclass']; + }elseif(preg_match("/AddClass/i",$name)){ + $s_action = "add"; } + + /* Check if a list element should be pushed one position up */ + if((preg_match("/sortup_/",$name))&&(!$sort_once)){ + $sort_once = true; + $val = preg_replace("/sortup_/","",$name); + $val = preg_replace("/_.*$/","",$val); + $val = base64_decode($val); + $this->catUp($val); + } + + /* Check if a list element should be pushed one position down */ + if((preg_match("/sortdown_/",$name))&&(!$sort_once)){ + $sort_once = true; + $val = preg_replace("/sortdown_/","",$name); + $val = preg_replace("/_.*$/","",$val); + $val = base64_decode($val); + $this->catDown($val); + } + } if($s_action == "delete"){ @@ -102,7 +256,7 @@ class faiProfile extends plugin $this->dialog = new faiProfileEntry($this->config,$this->dn,$this->FAIclasses); $this->is_dialog =true; } - + /* Save Dialog */ if(isset($_POST['SaveSubObject'])){ $this->dialog->save_object(); @@ -117,6 +271,7 @@ class faiProfile extends plugin $this->is_dialog=false; unset($this->dialog); $this->dialog=NULL; + //ksort($this->FAIclasses); } } @@ -126,51 +281,56 @@ class faiProfile extends plugin unset($this->dialog); $this->dialog=NULL; } - + if(isset($this->dialog)){ $this->dialog->save_object(); return($this->dialog->execute()); } - $divlist =new divlist("Profile"); + $divlist =new divSelectBox("Profile"); $divlist->SetSummary(_("This list displays all assigned class names for this profile.")); - $divlist->SetEntriesPerPage(10); - - $divlist->SetHeader(array(array("string"=>"Class name"), - array("string"=>"Objects","attach"=>"style='width:120px;'"), - array("string"=>"Options","attach"=>"style='border-right:none;width:60px;'"))); - $listhead = - "