From 5329a4a3744b10b24e0d4f1901818b3b290b8703 Mon Sep 17 00:00:00 2001 From: hickert Date: Wed, 7 Sep 2005 12:41:10 +0000 Subject: [PATCH] Added script classes git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@1316 594d385d-05f5-0310-b6e9-bd551577e9d8 --- plugins/admin/FAI/class_faiScript.inc | 261 +++++++++++++++++++++ plugins/admin/FAI/class_faiScriptEntry.inc | 100 ++++++++ plugins/admin/FAI/faiScript.tpl | 35 +++ plugins/admin/FAI/faiScriptEntry.tpl | 50 ++++ plugins/admin/FAI/tabsScript.inc | 42 ++++ 5 files changed, 488 insertions(+) create mode 100644 plugins/admin/FAI/class_faiScript.inc create mode 100644 plugins/admin/FAI/class_faiScriptEntry.inc create mode 100644 plugins/admin/FAI/faiScript.tpl create mode 100644 plugins/admin/FAI/faiScriptEntry.tpl create mode 100644 plugins/admin/FAI/tabsScript.inc diff --git a/plugins/admin/FAI/class_faiScript.inc b/plugins/admin/FAI/class_faiScript.inc new file mode 100644 index 000000000..ff452e087 --- /dev/null +++ b/plugins/admin/FAI/class_faiScript.inc @@ -0,0 +1,261 @@ + "Eins ist toll", "zwei" => "Zwei ist noch besser"); + + /* attribute list for save action */ + var $ignore_account = TRUE; + + /* Attributes for this Object */ + var $attributes = array("cn","description"); + + /* ObjectClasses for this Object*/ + var $objectclasses = array("top","FAIclass","FAIscript"); + + /* Class name of the Ldap ObjectClass for the Sub Object */ + var $subClass = "FAIscriptEntry"; + var $subClasses = array("top","FAIclass","FAIscriptEntry"); + + /* Class name of the php class which allows us to edit a Sub Object */ + var $subClassName = "faiScriptEntry"; + + /* Attributes to initialise for each subObject */ + var $subAttributes = array("cn","description","FAIpriority","FAIscript"); + + /* Specific attributes */ + 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 $dialog = NULL; // a dialog, e.g. new disk dialog + var $SubObjects = array(); // All leafobjects of this object + + function faiScript ($config, $dn= NULL) + { + /* Load Attributes */ + plugin::plugin ($config, $dn); + + /* If "dn==new" we try to create a new entry + * Else we must read all objects from ldap which belong to this entry. + * First read SubObjects from ldap ... and then the partition definitions for the SubObjects. + */ + if($dn != "new"){ + $this->dn =$dn; + + /* Read all leaf objects of this object (For FAIscript this would be FAIscriptEntry) + */ + $ldap = $this->config->get_ldap_link(); + $ldap->cd ($this->dn); + $ldap->search("(&(objectClass=FAIclass)(objectClass=".$this->subClass."))",$this->subAttributes); + + while($object = $ldap->fetch()){ + /* Set status for save management */ + + foreach($this->subAttributes as $attrs){ + if(!isset($object[$attrs][0])){ + $this->SubObjects[$object['cn'][0]][$attrs]=""; + }else{ + $this->SubObjects[$object['cn'][0]][$attrs]=$object[$attrs][0]; + } + } + + $this->SubObjects[$object['cn'][0]]['status'] = "edited"; + $this->SubObjects[$object['cn'][0]]['dn'] = $object['dn']; + } + } + } + + function execute() + { + /* Fill templating stuff */ + $smarty= get_smarty(); + $display= ""; + + /* Add new sub object */ + if(isset($_POST['AddSubObject'])){ + $this->dialog= new $this->subClassName($this->config,"new"); + $this->is_dialog=true; + } + + /* Edit selected Sub Object */ + if((isset($_POST['EditSubObject']))&&(isset($_POST['SubObject']))){ + $this->dialog= new $this->subClassName($this->config,$this->dn,$this->SubObjects[$_POST['SubObject']]); + $this->is_dialog=true; + } + + /* Remove Sub object */ + if((isset($_POST['DelSubObject']))&&(isset($_POST['SubObject']))){ + if($this->SubObjects[$_POST['SubObject']]['status'] == "edited"){ + $this->SubObjects[$_POST['SubObject']]['status']= "delete"; + }else{ + unset($this->SubObjects[$_POST['SubObject']]); + } + } + + /* Save Dialog */ + if(isset($_POST['SaveSubObject'])){ + $this->dialog->save_object(); + $msgs = $this->dialog->check(); + if(count($msgs)>0){ + foreach($msgs as $msg){ + print_red($msg); + } + }else{ + $obj = $this->dialog->save(); + if(isset($obj['remove'])){ + if($this->SubObjects[$obj['remove']['from']]['status']=="edited"){ + $this->SubObjects[$obj['remove']['from']]['status'] = "delete"; + }elseif($this->SubObjects[$obj['remove']['from']]['status']=="new"){ + unset($this->SubObjects[$obj['remove']['from']]); + } + $obj['status'] = "new"; + $this->SubObjects[$obj['remove']['to']] = $obj; + unset($this->SubObjects[$obj['remove']['to']]['remove']); + }else{ + $this->SubObjects[$obj['cn']]=$obj; + } + $this->is_dialog=false; + unset($this->dialog); + $this->dialog=NULL; + } + } + + /* Cancel Dialog */ + if(isset($_POST['CancelSubObject'])){ + $this->is_dialog=false; + unset($this->dialog); + $this->dialog=NULL; + } + + /* Print dialog if $this->dialog is set */ + if($this->dialog){ + $this->dialog->save_object(); + $display = $this->dialog->execute(); + return($display); + } + + $smarty->assign("SubObjects",$this->getList()); + $smarty->assign("SubObjectKeys",array_flip($this->getList())); + /* Assign variables */ + foreach($this->attributes as $attrs){ + $smarty->assign($attrs,$this->$attrs); + } + + $display.= $smarty->fetch(get_template_path('faiScript.tpl', TRUE)); + return($display); + } + + /* Generate listbox friendly SubObject list + */ + function getList(){ + $a_return=array(); + foreach($this->SubObjects as $obj){ + if($obj['status'] != "delete"){ + $a_return[$obj['cn']]= $obj['cn']." [".$obj['description']."]"; + } + } + return($a_return); + } + + /* 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); + $this->handle_post_events("remove"); + } + + + /* Save data to object + */ + function save_object() + { + plugin::save_object(); + foreach($this->attributes as $attrs){ + if(isset($_POST[$attrs])){ + $this->$attrs = $_POST[$attrs]; + } + } + } + + + /* Check supplied data */ + function check() + { + $message= array(); + $str = utf8_encode("üöä"); + if((empty($this->description))||(preg_match("/[^a-z0-9".$str."\.,;:-_\? ]/i",$this->description))){ + $message[]=_("Please enter a valid description."); + } + return ($message); + } + + + /* Save to LDAP */ + function save() + { + plugin::save(); + + $ldap = $this->config->get_ldap_link(); + + /* Write FAIscript to ldap*/ + $ldap->cd($this->dn); + $ldap->modify($this->attrs); + + /* Prepare FAIscriptEntry to write it to ldap + * First sort array. + * Because we must delete old entries first. + * After deletion, we perform add and modify + */ + $Objects = array(); + foreach($this->SubObjects as $name => $obj){ + if($obj['status'] == "delete"){ + $Objects[$name] = $obj; + } + } + foreach($this->SubObjects as $name => $obj){ + if($obj['status'] != "delete"){ + $Objects[$name] = $obj; + } + } + + foreach($Objects as $name => $obj){ + $tmp = array(); + foreach($this->subAttributes as $attrs){ + if(empty($obj[$attrs])){ + $obj[$attrs] = array(); + } + $tmp[$attrs] = $obj[$attrs]; + } + + $tmp['objectClass'] = $this->subClasses; + + $sub_dn = "cn=".$obj['cn'].",".$this->dn; + + if($obj['status'] == "delete"){ + $ldap->cd($sub_dn); + $ldap->rmdir_recursive($sub_dn); + $this->handle_post_events("remove"); + }elseif($obj['status'] == "edited"){ + $ldap->cd($sub_dn); + $ldap->modify($tmp); + $this->handle_post_events("modify"); + }elseif($obj['status']=="new"){ + $ldap->cd($sub_dn); + $ldap->create_missing_trees($sub_dn); + $ldap->cd($sub_dn); + $ldap->add($tmp); + $this->handle_post_events("add"); + } + show_ldap_error($ldap->get_error()); + } + } +} + +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/plugins/admin/FAI/class_faiScriptEntry.inc b/plugins/admin/FAI/class_faiScriptEntry.inc new file mode 100644 index 000000000..f43052fa1 --- /dev/null +++ b/plugins/admin/FAI/class_faiScriptEntry.inc @@ -0,0 +1,100 @@ + "Eins ist toll", "zwei" => "Zwei ist noch besser"); + + /* attribute list for save action */ + var $ignore_account= TRUE; + var $attributes = array("Object_cn","Object_description","Object_FAIpriority","Object_FAIscript"); + var $objectclasses= array(); + + var $orig_cn = ""; + + var $Object_dn = ""; + var $Object_cn = ""; + var $Object_FAIpriority = ""; + var $Object_FAIscript = ""; + var $Object_description = ""; + var $Object_status = "new"; + + function faiScriptEntry ($config, $dn= NULL,$object=false) + { + plugin::plugin ($config, $dn); + if($dn != "new"){ + $this->orig_cn= $object['cn']; + $this->dn=$object['dn']; + foreach($object as $name=>$value){ + $oname = "Object_".$name; + $this->$oname=$value; + } + }else{ + $this->Object_status = "new"; + $this->orig_cn = false; + } + } + + function execute() + { + /* Fill templating stuff */ + $smarty = get_smarty(); + $display = ""; + + foreach($this->attributes as $attrs){ + $smarty->assign($attrs,stripslashes($this->$attrs)); + } + + for($i =1 ; $i <= 100 ; $i++){ + $Object_FAIprioritys[$i]=$i; + } + $smarty->assign("Object_FAIprioritys",$Object_FAIprioritys); + $display.= $smarty->fetch(get_template_path('faiScriptEntry.tpl', TRUE)); + return($display); + } + + /* Save data to object */ + function save_object() + { + if(isset($_POST['SubObjectFormSubmitted'])){ + foreach($this->attributes as $attrs){ + if(isset($_POST[$attrs])){ + $this->$attrs = $_POST[$attrs]; + }else{ + $this->$attrs = ""; + } + } + } + } + + /* Check supplied data */ + function check() + { + $message= array(); + + + return ($message); + } + + function save() + { + $tmp=array(); + foreach($this->attributes as $attrs){ + $attr = preg_replace("/^Object_/","",$attrs); + $tmp[$attr] = $this->$attrs; + } + + 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->Object_status; + return($tmp); + } +} +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/plugins/admin/FAI/faiScript.tpl b/plugins/admin/FAI/faiScript.tpl new file mode 100644 index 000000000..e7ac45b21 --- /dev/null +++ b/plugins/admin/FAI/faiScript.tpl @@ -0,0 +1,35 @@ +

{t}FAI script set{/t} +

+ + + + + + + + + +
+ {t}Name{/t} + + +
+ {t}Description{/t} + + +
+
+
+

{t}Already defined scripts{/t}

+ + + + +
+
+ + + +
diff --git a/plugins/admin/FAI/faiScriptEntry.tpl b/plugins/admin/FAI/faiScriptEntry.tpl new file mode 100644 index 000000000..a2ce2216f --- /dev/null +++ b/plugins/admin/FAI/faiScriptEntry.tpl @@ -0,0 +1,50 @@ +

{t}FAI script set{/t} +

+ + + + + + + + + + + + + + +
+ {t}Name{/t} + + +
+ {t}Description{/t} + + +
+ {t}Priority{/t} + +
+ +
+

 

+
+

{t}Script{/t}

+ + + + +
+ +
+
+

 

+
+
+ + +
+ diff --git a/plugins/admin/FAI/tabsScript.inc b/plugins/admin/FAI/tabsScript.inc new file mode 100644 index 000000000..cb6dcf302 --- /dev/null +++ b/plugins/admin/FAI/tabsScript.inc @@ -0,0 +1,42 @@ +by_object['faiScript']; + + $new_dn= 'cn='.$baseobject->cn.",ou=scripts,ou=fai,ou=configs,ou=systems,".$_SESSION['config']->current['BASE']; + + if ($this->dn != $new_dn && $this->dn != "new"){ + + /* if( new_dn is subtree of this->dn ) */ + $cnt1 = count(split(",",$this->dn)); + $cnt2 = count(split(",",$new_dn)); + if((strstr($new_dn,$this->dn))&&($cnt1<$cnt2)){ + print_red(_("Try to move tree failed. Destination tree is subtree of source tree.")); + }else{ + $baseobject->recursive_move($this->dn, $new_dn); + } + } + $this->dn= $new_dn; + + tabs::save(TRUE); + } + +} + +?> -- 2.30.2