From: hickert Date: Thu, 8 Apr 2010 13:18:40 +0000 (+0000) Subject: Updated FAI profiles, removed old style list X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=9d2c424b659431efe5bf1305037dbb467551a3c0;p=gosa.git Updated FAI profiles, removed old style list git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@17554 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/gosa-plugins/fai/admin/fai/class_faiProfile.inc b/gosa-plugins/fai/admin/fai/class_faiProfile.inc index 06c46533b..4e804413a 100644 --- a/gosa-plugins/fai/admin/fai/class_faiProfile.inc +++ b/gosa-plugins/fai/admin/fai/class_faiProfile.inc @@ -2,507 +2,484 @@ class faiProfile extends plugin { - /* attribute list for save action */ - var $ignore_account = TRUE; - - /* Attributes for this Object */ - var $attributes = array("cn","description","FAIclass"); - - /* ObjectClasses for this Object*/ - var $objectclasses = array("top","FAIclass","FAIprofile"); - - /* Specific attributes */ - var $old_cn = ""; - var $cn = ""; // The class name for this object - var $description = ""; // The description for this set of partitions - var $is_dialog = false; // specifies which buttons will be shown to save or abort - var $FAIclass = ""; // Classnames used for this profile - var $FAIclasses = array(); // Contains classname seperated in an array - var $FAIAllclasses = array(); // Contains all possible Classnames - var $ui ; - var $FAIstate = ""; - var $view_logged = FALSE; - - var $classSelect; - - function faiProfile(&$config, $dn= NULL) - { - /* Load Attributes */ - plugin::plugin ($config, $dn); - $ldap=$this->config->get_ldap_link(); - - $this->ui = get_userinfo(); - - /* Parse ldap attribute to get all assigned classes */ - $tmp = explode(" ",$this->FAIclass); - $tmp2 = array(); - foreach($tmp as $class){ - if(!empty($class)){ - $tmp2[trim($class)] = trim($class); - } - } + /* attribute list for save action */ + var $ignore_account = TRUE; + + /* Attributes for this Object */ + var $attributes = array("cn","description","FAIclass"); + + /* ObjectClasses for this Object*/ + var $objectclasses = array("top","FAIclass","FAIprofile"); + + /* Specific attributes */ + var $old_cn = ""; + var $cn = ""; // The class name for this object + var $description = ""; // The description for this set of partitions + var $is_dialog = false; // specifies which buttons will be shown to save or abort + var $FAIclass = ""; // Classnames used for this profile + var $FAIclasses = array(); // Contains classname seperated in an array + var $FAIAllclasses = array(); // Contains all possible Classnames + var $ui ; + var $FAIstate = ""; + var $view_logged = FALSE; + + var $classSelect; + + function faiProfile(&$config, $dn= NULL) + { + /* Load Attributes */ + plugin::plugin ($config, $dn); + $ldap=$this->config->get_ldap_link(); + + $this->ui = get_userinfo(); + + /* Parse ldap attribute to get all assigned classes */ + $tmp = explode(" ",$this->FAIclass); + $tmp2 = array(); + foreach($tmp as $class){ + if(!empty($class)){ + $tmp2[trim($class)] = trim($class); + } + } - /* Sort assigned classes */ - if(is_array($tmp2)){ - foreach($tmp2 as $class){ - $this->FAIclasses[$class]=$class; - } - } + /* Sort assigned classes */ + if(is_array($tmp2)){ + foreach($tmp2 as $class){ + $this->FAIclasses[$class]=$class; + } + } - $categories = array("FAIscript","FAItemplate","FAIhook","FAIvariable","FAIpartitionTable","FAIpackageList"); + $categories = array("FAIscript","FAItemplate","FAIhook","FAIvariable","FAIpartitionTable","FAIpackageList"); - /* Build filter */ - $filter= ""; - foreach ($categories as $cat){ - $filter.= "(objectClass=$cat)"; - } - - /* Get ldap connection */ - $base = session::get('CurrentMainBase'); - $ldap->cd($base); - $sort = array(); - - /* search all FAI classes */ - $ldap->search("(|$filter)",array("*")); - while($attrs = $ldap->fetch()){ - - /* Sort by categorie */ - foreach($categories as $cat){ - if(in_array($cat,$attrs['objectClass'])){ - - /* Append entry */ - $this->FAIAllclasses[$attrs['cn'][0]][$cat]=$attrs; - - /* Create sort array, because the array above is a multidimensional array, and can't be sorted by php sorting functions*/ - $sort[strtolower($attrs['cn'][0])] = $attrs['cn'][0]; + /* Build filter */ + $filter= ""; + foreach ($categories as $cat){ + $filter.= "(objectClass=$cat)"; } - } - } - /* Sort the sort array */ - //ksort($sort); + /* Get ldap connection */ + $base = session::get('CurrentMainBase'); + $ldap->cd($base); + $sort = array(); - /* Reorder the FAIclasses array */ - foreach($sort as $name){ - $tmp[$name] =$this->FAIAllclasses[$name]; - } + /* search all FAI classes */ + $ldap->search("(|$filter)",array("*")); + while($attrs = $ldap->fetch()){ - /* Assign sorted classes */ - $this->FAIAllclasses = array(); - $this->FAIAllclasses = $tmp; + /* Sort by categorie */ + foreach($categories as $cat){ + if(in_array($cat,$attrs['objectClass'])){ - if($dn != "new"){ - $this->dn =$dn; - } - $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); - } - - - function acl_base_for_current_object($dn) - { - if($dn == "new" || $dn == ""){ - if($this->dn == "new"){ - $dn= $this->parent->parent->acl_base; - }else{ - $dn = $this->dn; - } - } - return($dn); - } - - - /* 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(); - - if($this->is_account && !$this->view_logged){ - $this->view_logged = TRUE; - new log("view","fai/".get_class($this),$this->dn); - } + /* Append entry */ + $this->FAIAllclasses[$attrs['cn'][0]][$cat]=$attrs; + + /* Create sort array, because the array above is a multidimensional array, and can't be sorted by php sorting functions*/ + $sort[strtolower($attrs['cn'][0])] = $attrs['cn'][0]; + } + } + } + + /* Sort the sort array */ + //ksort($sort); - /* Fill templating stuff */ - $smarty= get_smarty(); - $display= ""; - - $s_entry = ""; - $s_action = ""; - - /* Remove class name From list */ - $sort_once = false; - 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 = postDecode($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"; + /* Reorder the FAIclasses array */ + foreach($sort as $name){ + $tmp[$name] =$this->FAIAllclasses[$name]; } - /* 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 = postDecode($val); - $this->catUp($val); + /* Assign sorted classes */ + $this->FAIAllclasses = array(); + $this->FAIAllclasses = $tmp; + + if($dn != "new"){ + $this->dn =$dn; } + $this->old_cn = $this->cn; + + // Prepare lists + $this->classList = new sortableListing(array(),array(), TRUE); + $this->classList->setDeleteable(true); + $this->classList->setEditable(false); + $this->classList->setWidth("100%"); + $this->classList->setHeight("200px"); + $this->classList->setHeader(array(_("Name"),_("Types"))); + $this->classList->setDefaultSortColumn(0); + } + + + /* 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); + } + - /* 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 = postDecode($val); - $this->catDown($val); + function acl_base_for_current_object($dn) + { + if($dn == "new" || $dn == ""){ + if($this->dn == "new"){ + $dn= $this->parent->parent->acl_base; + }else{ + $dn = $this->dn; + } } + return($dn); + } - } - if($s_action == "delete" && $this->acl_is_writeable("FAIclass")){ - unset($this->FAIclasses[$s_entry]); - } + /* returns position in array */ + function getpos($atr,$attrs) + { + $i = 0; + foreach($attrs as $attr => $name) { + $i++; + if($attr == $atr){ + return($i); + } + } + return(-1); + } - if($s_action == "add" && $this->acl_is_writeable("FAIclass")){ - $this->classSelect = new classSelect($this->config, get_userinfo()); - $this->dialog =true; - } + /* 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); + } - /* 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; + + /* 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); } - $this->dialog=false; - $this->classSelect=FALSE; - } + return($ret); } - /* Cancel Dialog */ - if(isset($_POST['classSelect_cancel']) && $this->classSelect instanceOf classSelect){ - $this->dialog=false; - $this->classSelect=FALSE; + /* class one position up */ + function catUp($id) + { + /* Get all cats depinding on current dir */ + $cats = $this->FAIclasses; + $this->FAIclasses =$this->ArrayUp($id,$cats); } - 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()); + /* Class one position down */ + function catDown($id) + { + /* Get all cats depinding on current dir */ + $cats = $this->FAIclasses; + $this->FAIclasses =$this->ArrayDown($id,$cats); } - $divlist =new divSelectBox("Profile"); - $divlist->SetSummary(_("This list displays all assigned class names for this profile.")); - - /* item images */ - $objTypes['FAIhook'] = image('plugins/fai/images/fai_hook.png','',_("Hook bundle")); - $objTypes['FAItemplate'] = image('plugins/fai/images/fai_template.png','',_("Template bundle")); - $objTypes['FAIscript'] = image('plugins/fai/images/fai_script.png','',_("Script bundle")); - $objTypes['FAIvariable'] = image('plugins/fai/images/fai_variable.png','',_("Variable bundle")); - $objTypes['FAIpackageList'] = image('plugins/fai/images/fai_packages.png','',_("Package bundle")); - $objTypes['FAIpartitionTable'] = image('plugins/fai/images/fai_partitionTable.png','',_("Partition table")); - - $emp = image('images/empty.png'); - - /* Delete button */ - $actions = image('images/lists/trash.png','DEL_%KEY%',_("Remove class from profile")); - - /* Up down buttons */ - $linkupdown = image('images/lists/sort-up.png','sortup_%s',_("Up"), 'top'); - $linkupdown.= image('images/lists/sort-down.png','sortdown_%s',_("Down"), 'bottom'); - - /* Append fai classes to divlist */ - if($this->acl_is_readable("FAIclass")){ - foreach($this->FAIclasses as $usedClass){ - $str = " "; - $act = ""; - - if(isset($this->FAIAllclasses[$usedClass])){ - foreach($this->FAIAllclasses[$usedClass] as $class => $obj){ - $str.= $objTypes[$class]; - } + function execute() + { + /* Call parent execute */ + plugin::execute(); + + if($this->is_account && !$this->view_logged){ + $this->view_logged = TRUE; + new log("view","fai/".get_class($this),$this->dn); } - $field1 = array("string"=> $usedClass,"attach"=>""); - $field2 = array("string"=> $str,"attach"=>""); - if(!preg_match("/freeze/", $this->FAIstate) && $this->acl_is_writeable("FAIclass")){ - $field3 = array("string"=> preg_replace("/%KEY%/",postEncode($usedClass),$actions). - preg_replace("/%s/",postEncode($usedClass),$linkupdown), - "attach"=>"style='border-right:none;'"); - }else{ - $field3 = array("string"=>" ", "attach"=>"style='border-right:none;'"); + /* Fill templating stuff */ + $smarty= get_smarty(); + $display= ""; + + $s_entry = ""; + $s_action = ""; + + /* Remove class name From list */ + $sort_once = false; + if(!preg_match("/freeze/",$this->FAIstate)){ + + if(isset($_POST['AddClass']) && $this->acl_is_writeable("FAIclass")){ + $this->classSelect = new classSelect($this->config, get_userinfo()); + $this->dialog =true; } - $divlist->AddEntry(array($field1,$field2,$field3)); - } - } - $smarty->assign("freeze", preg_match("/freeze/i",$this->FAIstate)); - $smarty->assign("FAIclasses" ,$this->FAIclasses); - $smarty->assign("divlist" ,$divlist->DrawList()); + /* 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->dialog=false; + $this->classSelect=FALSE; + } + } - /* Magic quotes GPC, escapes every ' " \, to solve some security risks - * If we post the escaped strings they will be escaped again - */ - foreach($this->attributes as $attrs){ - if(get_magic_quotes_gpc()){ - $smarty->assign($attrs,stripslashes($this->$attrs)); - }else{ - $smarty->assign($attrs,($this->$attrs)); - } - } + /* Cancel Dialog */ + if(isset($_POST['classSelect_cancel']) && $this->classSelect instanceOf classSelect){ + $this->dialog=false; + $this->classSelect=FALSE; + } - - $dn = $this->acl_base_for_current_object($this->dn); - $smarty->assign("sub_object_is_addable", - preg_match("/c/",$this->ui->get_permissions($dn,"fai/faiScriptEntry")) && - !preg_match("/freeze/",$this->FAIstate)); + 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()); + } - $tmp = $this->plInfo(); - foreach($tmp['plProvidedAcls'] as $name => $translated){ - $smarty->assign($name."ACL",$this->getacl($name, preg_match("/freeze/",$this->FAIstate))); - } + $divlist =new divSelectBox("Profile"); + $divlist->SetSummary(_("This list displays all assigned class names for this profile.")); + + /* item images */ + $objTypes['FAIhook'] = image('plugins/fai/images/fai_hook.png','',_("Hook bundle")); + $objTypes['FAItemplate'] = image('plugins/fai/images/fai_template.png','',_("Template bundle")); + $objTypes['FAIscript'] = image('plugins/fai/images/fai_script.png','',_("Script bundle")); + $objTypes['FAIvariable'] = image('plugins/fai/images/fai_variable.png','',_("Variable bundle")); + $objTypes['FAIpackageList'] = image('plugins/fai/images/fai_packages.png','',_("Package bundle")); + $objTypes['FAIpartitionTable'] = image('plugins/fai/images/fai_partitionTable.png','',_("Partition table")); + + $emp = image('images/empty.png'); + + /* Delete button */ + $actions = image('images/lists/trash.png','DEL_%KEY%',_("Remove class from profile")); + + /* Up down buttons */ + $linkupdown = image('images/lists/sort-up.png','sortup_%s',_("Up"), 'top'); + $linkupdown.= image('images/lists/sort-down.png','sortdown_%s',_("Down"), 'bottom'); + + /* Append fai classes to divlist */ + + $this->classList->setAcl($this->getacl('FAIclass',preg_match('/^freeze/', $this->FAIstate))); + $data = $lData = array(); + foreach($this->FAIclasses as $usedClass){ + $str = ""; + if(isset($this->FAIAllclasses[$usedClass])){ + foreach($this->FAIAllclasses[$usedClass] as $class => $obj){ + $str.= $objTypes[$class]; + } + } + $data[$usedClass] = $usedClass; + $lData[$usedClass] = array('data'=>array($usedClass,$str)); + } + $this->classList->setListData($data,$lData); + $this->classList->update(); + + $smarty->assign("usePrototype", "true"); + $smarty->assign("freeze", preg_match("/freeze/i",$this->FAIstate)); + $smarty->assign("FAIclasses" ,$this->FAIclasses); + $smarty->assign("divlist" ,$this->classList->render()); + + /* Magic quotes GPC, escapes every ' " \, to solve some security risks + * If we post the escaped strings they will be escaped again + */ + foreach($this->attributes as $attrs){ + if(get_magic_quotes_gpc()){ + $smarty->assign($attrs,stripslashes($this->$attrs)); + }else{ + $smarty->assign($attrs,($this->$attrs)); + } + } - $display.= $smarty->fetch(get_template_path('faiProfile.tpl', TRUE)); - return($display); - } - - function remove_from_parent() - { - $ldap = $this->config->get_ldap_link(); - $ldap->cd ($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"); - } - - - /* Save data to object - */ - function save_object() - { - if(!preg_match("/freeze/",$this->FAIstate)){ - plugin::save_object(); - } - } + $dn = $this->acl_base_for_current_object($this->dn); + $smarty->assign("sub_object_is_addable", + preg_match("/c/",$this->ui->get_permissions($dn,"fai/faiScriptEntry")) && + !preg_match("/freeze/",$this->FAIstate)); - /* Check supplied data */ - function check() - { - /* Call common method to give check the hook */ - $message= plugin::check(); + $tmp = $this->plInfo(); + foreach($tmp['plProvidedAcls'] as $name => $translated){ + $smarty->assign($name."ACL",$this->getacl($name, preg_match("/freeze/",$this->FAIstate))); + } - if(count($this->FAIclasses) == 0){ - $message[]=_("No class specified for this profile!"); + $display.= $smarty->fetch(get_template_path('faiProfile.tpl', TRUE)); + return($display); } - if($this->cn == ""){ - $message[]= msgPool::required(_("Name")); + function remove_from_parent() + { + $ldap = $this->config->get_ldap_link(); + $ldap->cd ($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"); } - /* Ensure that we do not overwrite an allready existing entry + + /* Save data to object */ - 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")); - } + function save_object() + { + if(!preg_match("/freeze/",$this->FAIstate)){ + plugin::save_object(); + + $this->classList->save_object(); + $action = $this->classList->getAction(); + if($action['action'] == 'reorder'){ + $this->FAIclasses = $this->classList->getMaintainedData(); + } + if($action['action'] == 'delete'){ + $s_entry = $this->classList->getKey($action['targets'][0]); + unset($this->FAIclasses[$s_entry]); + } + } } - return ($message); - } + /* Check supplied data */ + function check() + { + /* Call common method to give check the hook */ + $message= plugin::check(); + + if(count($this->FAIclasses) == 0){ + $message[]=_("No class specified for this profile!"); + } - /* Save to LDAP */ - function save() - { - plugin::save(); + if($this->cn == ""){ + $message[]= msgPool::required(_("Name")); + } - $ldap = $this->config->get_ldap_link(); + /* 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")); + } + } - $this->FAIclass = ""; - foreach($this->FAIclasses as $class){ - $this->FAIclass.=$class." "; + return ($message); } - $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 != ""){ + /* Save to LDAP */ + function save() + { + plugin::save(); - $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){ - new log("modify","fai/".get_class($this),$this->dn,$this->attributes); - }else{ - new log("create","fai/".get_class($this),$this->dn,$this->attributes); + $ldap = $this->config->get_ldap_link(); + + $this->FAIclass = ""; + foreach($this->FAIclasses as $class){ + $this->FAIclass.=$class." "; + } + + $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){ + new log("modify","fai/".get_class($this),$this->dn,$this->attributes); + }else{ + new log("create","fai/".get_class($this),$this->dn,$this->attributes); + } } - } - function PrepareForCopyPaste($source) - { - plugin::PrepareForCopyPaste($source); + function PrepareForCopyPaste($source) + { + plugin::PrepareForCopyPaste($source); - /* Parse ldap attribute to get all assigned classes */ - $tmp = explode(" ",$this->FAIclass); - $tmp2 = array(); - foreach($tmp as $class){ - if(!empty($class)){ - $tmp2[trim($class)] = trim($class); - } + /* Parse ldap attribute to get all assigned classes */ + $tmp = explode(" ",$this->FAIclass); + $tmp2 = array(); + foreach($tmp as $class){ + if(!empty($class)){ + $tmp2[trim($class)] = trim($class); + } + } + + /* Sort assigned classes */ + if(is_array($tmp2)){ + foreach($tmp2 as $class){ + $this->FAIclasses[$class]=$class; + } + } } - /* Sort assigned classes */ - if(is_array($tmp2)){ - foreach($tmp2 as $class){ - $this->FAIclasses[$class]=$class; - } + + /* Return plugin informations for acl handling */ + static function plInfo() + { + return (array( + "plShortName" => _("Profile"), + "plDescription" => _("FAI profile"), + "plSelfModify" => FALSE, + "plDepends" => array(), + "plPriority" => 30, + "plSection" => array("administration"), + "plCategory" => array("fai"), + "plProvidedAcls" => array( + "cn" => _("Name"), + "description" => _("Description"), + "FAIclass" => _("FAI classes")) + )); } - } - - - /* Return plugin informations for acl handling */ - static function plInfo() - { - return (array( - "plShortName" => _("Profile"), - "plDescription" => _("FAI profile"), - "plSelfModify" => FALSE, - "plDepends" => array(), - "plPriority" => 30, - "plSection" => array("administration"), - "plCategory" => array("fai"), - "plProvidedAcls" => array( - "cn" => _("Name"), - "description" => _("Description"), - "FAIclass" => _("FAI classes")) - )); - } - - - /*! \brief Used for copy & paste. - Returns a HTML input mask, which allows to change the cn of this entry. + + + /*! \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'); + */ + 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: