X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=gosa-plugins%2Ffai%2Fadmin%2Ffai%2Fclass_faiProfile.inc;h=db587ac06f055f69019b88dab17e8760664771e2;hb=ac00a6eccb7dd4f40043288482e701a3f17fcc6e;hp=3eaa08b5e2f12ad61595284fab5c8a08c2e840a1;hpb=9169b2843e25912293f2c2ef8f96278b52b9fbae;p=gosa.git diff --git a/gosa-plugins/fai/admin/fai/class_faiProfile.inc b/gosa-plugins/fai/admin/fai/class_faiProfile.inc index 3eaa08b5e..db587ac06 100644 --- a/gosa-plugins/fai/admin/fai/class_faiProfile.inc +++ b/gosa-plugins/fai/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; @@ -28,6 +23,8 @@ class faiProfile extends plugin var $FAIstate = ""; var $view_logged = FALSE; + var $classSelect; + function faiProfile(&$config, $dn= NULL) { /* Load Attributes */ @@ -37,7 +34,7 @@ class faiProfile extends plugin $this->ui = get_userinfo(); /* Parse ldap attribute to get all assigned classes */ - $tmp = split(" ",$this->FAIclass); + $tmp = explode(" ",$this->FAIclass); $tmp2 = array(); foreach($tmp as $class){ if(!empty($class)){ @@ -45,10 +42,6 @@ class faiProfile extends plugin } } - if(isset($this->attrs['FAIstate'][0])){ - $this->FAIstate = $this->attrs['FAIstate'][0]; - } - /* Sort assigned classes */ if(is_array($tmp2)){ foreach($tmp2 as $class){ @@ -127,9 +120,9 @@ class faiProfile extends plugin function acl_base_for_current_object($dn) { - if($dn == "new"){ + if($dn == "new" || $dn == ""){ if($this->dn == "new"){ - $dn = session::get('CurrentMainBase'); + $dn= $this->parent->parent->acl_base; }else{ $dn = $this->dn; } @@ -219,96 +212,91 @@ class faiProfile extends plugin /* Remove class name From list */ $sort_once = false; - foreach($_POST as $name => $post){ - if(preg_match("/DEL_/i",$name) && $this->acl_is_writeable("FAIclass")){ - $s_action = "delete"; - $s_entry = preg_replace("/DEL_/","",$name); - $s_entry = base64_decode(preg_replace("/_.*$/","",$s_entry)); - }elseif(preg_match("/Add_class/i",$name)&& $this->acl_is_writeable("FAIclass")){ - $s_action = "add"; - }elseif(preg_match("/DelClass/i",$name) && $this->acl_is_writeable("FAIclass")){ - $s_action = "delete"; - $s_entry = $_POST['FAIclass']; - }elseif(preg_match("/AddClass/i",$name) && $this->acl_is_writeable("FAIclass")){ - $s_action = "add"; - } + if(!preg_match("/freeze/",$this->FAIstate)){ + foreach($_POST as $name => $post){ + if(preg_match("/DEL_/i",$name) && $this->acl_is_writeable("FAIclass")){ + $s_action = "delete"; + $s_entry = preg_replace("/DEL_/","",$name); + $s_entry = base64_decode(preg_replace("/_.*$/","",$s_entry)); + }elseif(preg_match("/Add_class/i",$name)&& $this->acl_is_writeable("FAIclass")){ + $s_action = "add"; + }elseif(preg_match("/DelClass/i",$name) && $this->acl_is_writeable("FAIclass")){ + $s_action = "delete"; + $s_entry = $_POST['FAIclass']; + }elseif(preg_match("/AddClass/i",$name) && $this->acl_is_writeable("FAIclass")){ + $s_action = "add"; + } - /* Check if a list element should be pushed one position up */ - if((preg_match("/sortup_/",$name))&&(!$sort_once) && $this->acl_is_writeable("FAIclass")){ - $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) && $this->acl_is_writeable("FAIclass")){ - $sort_once = true; - $val = preg_replace("/sortdown_/","",$name); - $val = preg_replace("/_.*$/","",$val); - $val = base64_decode($val); - $this->catDown($val); - } + /* Check if a list element should be pushed one position up */ + if((preg_match("/sortup_/",$name))&&(!$sort_once) && $this->acl_is_writeable("FAIclass")){ + $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) && $this->acl_is_writeable("FAIclass")){ + $sort_once = true; + $val = preg_replace("/sortdown_/","",$name); + $val = preg_replace("/_.*$/","",$val); + $val = base64_decode($val); + $this->catDown($val); + } - if($s_action == "delete" && $this->acl_is_writeable("FAIclass")){ - unset($this->FAIclasses[$s_entry]); - } + } - if($s_action == "add" && $this->acl_is_writeable("FAIclass")){ - $this->dialog = new faiProfileEntry($this->config,$this->dn,$this->FAIclasses); - $this->is_dialog =true; - } + if($s_action == "delete" && $this->acl_is_writeable("FAIclass")){ + unset($this->FAIclasses[$s_entry]); + } - /* Save Dialog */ - if(isset($_POST['SaveSubObject'])){ - $this->dialog->save_object(); - $msgs= $this->dialog->check(); - if(count($msgs)){ - print_red($msgs); - }else{ - $ret = $this->dialog->save(); - foreach($ret as $class){ + if($s_action == "add" && $this->acl_is_writeable("FAIclass")){ + $this->classSelect = new classSelect($this->config, get_userinfo()); + $this->dialog =true; + } + + /* Save Dialog */ + if(isset($_POST['classSelect_save']) && $this->classSelect instanceOf classSelect){ + $list = $this->classSelect->save(); + foreach($list as $entry){ + $class = $entry['cn'][0]; $this->FAIclasses[$class] =$class; } - $this->is_dialog=false; - unset($this->dialog); - $this->dialog=FALSE; - //ksort($this->FAIclasses); + $this->dialog=false; + $this->classSelect=FALSE; } } /* Cancel Dialog */ - if(isset($_POST['CancelSubObject'])){ - $this->is_dialog=false; - unset($this->dialog); - $this->dialog=FALSE; + if(isset($_POST['classSelect_cancel']) && $this->classSelect instanceOf classSelect){ + $this->dialog=false; + $this->classSelect=FALSE; } - if(is_object($this->dialog)){ - $this->dialog->save_object(); - return($this->dialog->execute()); + if($this->classSelect instanceOf classSelect){ + session::set('filterFAIClass_base',$this->parent->parent->fai_release); + session::set('filterBlacklist', array('cn' => array_values($this->FAIclasses))); + return($this->classSelect->execute()); } $divlist =new divSelectBox("Profile"); $divlist->SetSummary(_("This list displays all assigned class names for this profile.")); /* item images */ - $objTypes['FAIhook'] = ""; - $objTypes['FAItemplate'] = ""; - $objTypes['FAIscript'] = ""; - $objTypes['FAIvariable'] = ""; - $objTypes['FAIpackageList'] = ""; - $objTypes['FAIpartitionTable'] = ""; + $objTypes['FAIhook'] = ""; + $objTypes['FAItemplate'] = ""; + $objTypes['FAIscript'] = ""; + $objTypes['FAIvariable'] = ""; + $objTypes['FAIpackageList'] = ""; + $objTypes['FAIpartitionTable'] = ""; /* Delete button */ - $actions = ""; + $actions = ""; /* Up down buttons */ - $linkupdown = " "; - $linkupdown.= ""; + $linkupdown = " "; + $linkupdown.= ""; /* Append fai classes to divlist */ if($this->acl_is_readable("FAIclass")){ @@ -324,7 +312,7 @@ class faiProfile extends plugin $field1 = array("string"=> $usedClass,"attach"=>""); $field2 = array("string"=> $str,"attach"=>""); - if(($this->FAIstate != "freeze") && $this->acl_is_writeable("FAIclass")){ + if(!preg_match("/freeze/", $this->FAIstate) && $this->acl_is_writeable("FAIclass")){ $field3 = array("string"=> preg_replace("/%KEY%/",base64_encode($usedClass),$actions). preg_replace("/%s/",base64_encode($usedClass),$linkupdown), "attach"=>"style='border-right:none;'"); @@ -335,6 +323,8 @@ class faiProfile extends plugin } } + $smarty->assign("freeze", preg_match("/freeze/i",$this->FAIstate)); + $smarty->assign("FAIclasses" ,$this->FAIclasses); $smarty->assign("divlist" ,$divlist->DrawList()); @@ -357,7 +347,7 @@ class faiProfile extends plugin $tmp = $this->plInfo(); foreach($tmp['plProvidedAcls'] as $name => $translated){ - $smarty->assign($name."ACL",$this->getacl($name)); + $smarty->assign($name."ACL",$this->getacl($name, preg_match("/freeze/",$this->FAIstate))); } $display.= $smarty->fetch(get_template_path('faiProfile.tpl', TRUE)); @@ -368,13 +358,8 @@ class faiProfile extends plugin { $ldap = $this->config->get_ldap_link(); $ldap->cd ($this->dn); - - $faifilter = session::get('faifilter'); - $use_dn = preg_replace("/".normalizePreg(FAI::get_release_dn($this->dn))."/i", $faifilter['branch'], $this->dn); - if($faifilter['branch'] == "main"){ - $use_dn = $this->dn; - } - + $release = $this->parent->parent->fai_release; + $use_dn = preg_replace("/".preg_quote(FAI::get_release_dn($this->dn), '/')."/i", $release, $this->dn); new log("remove","fai/".get_class($this),$use_dn,$this->attributes); FAI::prepare_to_save_FAI_object($use_dn,array(),true); $this->handle_post_events("remove"); @@ -385,7 +370,9 @@ class faiProfile extends plugin */ function save_object() { - plugin::save_object(); + if(!preg_match("/freeze/",$this->FAIstate)){ + plugin::save_object(); + } } @@ -396,30 +383,22 @@ class faiProfile extends plugin $message= plugin::check(); if(count($this->FAIclasses) == 0){ - $message[]=_("Please assign at least one class to this profile."); + $message[]=_("No class specified for this profile!"); } - if(empty($this->cn)){ - $message[]=_("Please enter a valid name."); + if($this->cn == ""){ + $message[]= msgPool::required(_("Name")); } - $ldap = $this->config->get_ldap_link(); - $faifilter = session::get('faifilter'); - $base = $faifilter['branch']; - if($base == "main"){ - $base = session::get('CurrentMainBase'); - } - $base = get_ou('faiprofileou').$base; - - $ldap->cd($base); - if ($this->old_cn == ""){ - $ldap->ls("(&(objectClass=FAIprofile)(cn=".$this->cn."))",$base,array("*")); - } else { - $ldap->ls("(&(objectClass=FAIprofile)(cn=".$this->cn.")(!cn=".$this->old_cn."))",$base,array("*")); - } - - if($ldap->count() || isset($this->FAIAllclasses[$this->cn])){ - $message[]=_("There is already a FAI object with this class name defined."); + /* Ensure that we do not overwrite an allready existing entry + */ + if($this->dn == "new" || $this->cn != $this->old_cn){ + $release = $this->parent->parent->fai_release; + $new_dn= 'cn='.$this->cn.",".get_ou('faiProfileRDN').get_ou('faiBaseRDN').$release; + $res = faiManagement::check_class_name("FAIprofile",$this->cn,$new_dn); + if(isset($res[$this->cn])){ + $message[] = msgPool::duplicated(_("Name")); + } } return ($message); @@ -440,6 +419,13 @@ class faiProfile extends plugin $this->attrs['FAIclass']=trim($this->FAIclass); + /* Remove the old FAI profile, if the dn has changed. + */ + if($this->cn != $this->old_cn && $this->old_cn != ""){ + + $old_dn = preg_replace("/^cn=[^,]+,/","cn=".$this->old_cn.",",$this->dn); + FAI::prepare_to_save_FAI_object($old_dn,array(),TRUE); + } FAI::prepare_to_save_FAI_object($this->dn,$this->attrs); if($this->initially_was_account){ @@ -447,8 +433,6 @@ class faiProfile extends plugin }else{ new log("create","fai/".get_class($this),$this->dn,$this->attributes); } - - show_ldap_error($ldap->get_error(), sprintf(_("Saving of FAI/profile with dn '%s' failed."),$this->dn)); } @@ -457,7 +441,7 @@ class faiProfile extends plugin plugin::PrepareForCopyPaste($source); /* Parse ldap attribute to get all assigned classes */ - $tmp = split(" ",$this->FAIclass); + $tmp = explode(" ",$this->FAIclass); $tmp2 = array(); foreach($tmp as $class){ if(!empty($class)){ @@ -491,6 +475,34 @@ class faiProfile extends plugin "FAIclass" => _("FAI classes")) )); } + + + /*! \brief Used for copy & paste. + Returns a HTML input mask, which allows to change the cn of this entry. + @param Array Array containing current status && a HTML template. + */ + function getCopyDialog() + { + $vars = array("cn"); + $smarty = get_smarty(); + $smarty->assign("cn", htmlentities($this->cn)); + $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE)); + $ret = array(); + $ret['string'] = $str; + $ret['status'] = ""; + return($ret); + } + + + /*! \brief Used for copy & paste. + Some entries must be renamed to avaoid duplicate entries. + */ + function saveCopyDialog() + { + if(isset($_POST['cn'])){ + $this->cn = get_post('cn'); + } + } } // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: