diff --git a/plugins/admin/fai/class_faiScriptEntry.inc b/plugins/admin/fai/class_faiScriptEntry.inc
index e2148014f10384477609556c510980887142ac0d..617de2612d6d27e72b8d0ec6a1192ccc35c730b9 100644 (file)
class faiScriptEntry 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");
+ 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;
var $attributes = array("cn","description","FAIpriority","FAIscript");
- var $objectclasses= array("FAIscriptEntry");
-
- var $orig_cn = "";
- var $dn = "";
- var $cn = "";
- var $FAIpriority = "";
- var $FAIscript = "";
- var $description = "";
- var $status = "new";
- var $parent = false;
- var $is_parent_saved = false;
+ var $objectclasses= array();
+
+ var $orig_cn = "";
+
+ var $dn = "";
+ var $cn = "";
+ var $FAIpriority = "0";
+ var $FAIscript = "";
+ var $description = "";
+ var $status = "new";
+
+ var $FAIstate = "";
- function faiScriptEntry ($config, $dn)
+ function faiScriptEntry ($config, $dn= NULL,$object=false)
{
- /* Dn is dn currently assigned to this object
- 'new' if object wasn't saved yet
- */
plugin::plugin ($config, $dn);
if($dn != "new"){
- $this->orig_cn = $this->cn;
+ $this->orig_cn= $object['cn'];
+ $this->dn=$object['dn'];
+ foreach($object as $name=>$value){
+ $oname = $name;
+ $this->$oname=$value;
+ }
+
+ if(isset($this->attrs['FAIstate'][0])){
+ $this->FAIstate = $this->attrs['FAIstate'][0];
+ }
+
}else{
- $this->status = "new";
- $this->orig_cn = false;
+ if(is_array($object)&&count($object)){
+ $this->orig_cn= $object['cn'];
+ $this->dn=$object['dn'];
+ foreach($object as $name=>$value){
+ $oname = $name;
+ $this->$oname=$value;
+ }
+ }else{
+
+ $this->status = "new";
+ $this->orig_cn = false;
+ }
}
}
function execute()
{
+ /* Call parent execute */
+ plugin::execute();
+
/* Fill templating stuff */
$smarty = get_smarty();
$display = "";
if(($_FILES['ImportFile']['size']==0)){
print_red(_("Selected file is empty."));
}else{
- $str = utf8_encode(file_get_contents($_FILES['ImportFile']['tmp_name']));
+ $str = utf8_encode(addslashes(file_get_contents($_FILES['ImportFile']['tmp_name'])));
$this->FAIscript = $str;
}
}
}
}
+ /* Create download button*/
+ if($this->dn != "new"){
+ $smarty->assign("DownMe","<a href='getFAIscript.php?id=".base64_encode($this->dn)."'>
+ <input type='button' value='"._("Download")."'>
+ </a>");
+ }else{
+ $smarty->assign("DownMe","");
+ }
+
for($i =0 ; $i < 100 ; $i++){
$FAIprioritys[$i]=$i;
}
+
+ foreach($this->attributes as $attr){
+ if(($this->FAIstate == "freeze") || (chkacl($this->acl,$attr)!= "")){
+ $smarty->assign($attr."ACL"," disabled ");
+ }else{
+ $smarty->assign($attr."ACL"," ");
+ }
+ }
+
$smarty->assign("FAIprioritys",$FAIprioritys);
$display.= $smarty->fetch(get_template_path('faiScriptEntry.tpl', TRUE));
return($display);
}
- /* Delete me, and all my subtrees
- */
- function remove_from_parent()
- {
- $ldap = $this->config->get_ldap_link();
- $ldap->cd ($this->dn);
- $ldap->rmdir_recursive($this->dn);
- show_ldap_error($ldap->get_error());
- $this->handle_post_events("remove");
- }
-
-
/* Save data to object */
function save_object()
{
- if(isset($_POST['SubObjectFormSubmitted'])){
+ if((isset($_POST['SubObjectFormSubmitted'])) && ($this->FAIstate != "freeze")){
foreach($this->attributes as $attrs){
if(isset($_POST[$attrs])){
$this->$attrs = $_POST[$attrs];
/* Check supplied data */
function check()
{
- $message= array();
+ /* Call common method to give check the hook */
+ $message= plugin::check();
if(empty($this->cn)){
$message[] = _("Please enter a name.");
}
- if(preg_match("/[^0-9a-z]/i",$this->cn)){
- $message[] = _("Please enter a valid name. Only a-Z 0-9 are allowed.");
+ if(empty($this->FAIscript)){
+ $message[]=_("Please enter a script.");
}
-
+
return ($message);
}
function save()
{
- plugin::save();
-
- /* Get ldap connection */
- $ldap = $this->config->get_ldap_link();
- $ldap->cd ($this->config->current['BASE']);
-
- /* First : Check if parent was already saved ... */
- $ldap->cd($this->parent->dn);
- $ldap->cat($this->parent->dn);
-
- /* no entry was found. So save our base object first */
- if($ldap->count()==0){
- $this->parent->save();
- }
-
- /* Generate this->dn */
- /* if !orig_dn -> This is a new object */
- if($this->orig_cn == false){
- $this->dn = "cn=".$this->cn.",".$this->parent->dn;
- $mode = "add";
- }else{
- /* This is an already existing entry, check if cn was changed */
- if($this->orig_cn != $this->cn ){
- /* rename */
- $ldap->cd($this->dn);
- $ldap->rmdir($this->dn);
- $this->dn = "cn=".$this->cn.",".$this->parent->dn;
- $mode = "add";
- }else{
- /* modify */
- $mode = "modify";
- }
+ $tmp=array();
+ foreach($this->attributes as $attrs){
+ $tmp[$attrs] = $this->$attrs;
}
- $ldap->cd($this->config->current['BASE']);
- $ldap->create_missing_trees($this->parent->dn);
- $ldap->cd ($this->dn);
- $ldap->$mode($this->attrs);
- show_ldap_error($ldap->get_error());
+ /* Strip out dos newlines */
+ $tmp['FAIscript']= strtr($this->FAIscript, array("\x0D" => ""));
+
+ if(($this->orig_cn)&&($tmp['cn']!=$this->orig_cn)){
+ $tmp['remove']['from'] = $this->orig_cn;
+ $tmp['remove']['to'] = $tmp['cn'];
+ }
+
+ $tmp['dn'] = $this->dn;
+ $tmp['status'] = $this->status;
+ return($tmp);
}
}
// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: