summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 7a507f1)
raw | patch | inline | side by side (parent: 7a507f1)
author | hickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Thu, 20 Oct 2005 07:03:44 +0000 (07:03 +0000) | ||
committer | hickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Thu, 20 Oct 2005 07:03:44 +0000 (07:03 +0000) |
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@1627 594d385d-05f5-0310-b6e9-bd551577e9d8
index 197fdc44bcdf142da2ed98c2937918f4f35ca660..57de6487616fb21044f49822a5f157f949d99f71 100644 (file)
/* 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");
+ var $sub64coded = array("FAIscript");
+
/* Specific attributes */
var $cn = ""; // The class name for this object
var $description = ""; // The description for this set of partitions
var $dialog = NULL; // a dialog, e.g. new disk dialog
var $SubObjects = array(); // All leafobjects of this object
- /* new dn*/
- var $use_dn ="";
-
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];
+ }
+ }
+
+ foreach($this->sub64coded as $codeIt){
+ $this->SubObjects[$object['cn'][0]][$codeIt]=(base64_decode($this->SubObjects[$object['cn'][0]][$codeIt]));
+ }
+
+ foreach($this->subAttributes as $attrs){
+ $this->SubObjects[$object['cn'][0]][$attrs]=addslashes($this->SubObjects[$object['cn'][0]][$attrs]);
+ }
+
+ $this->SubObjects[$object['cn'][0]]['status'] = "edited";
+ $this->SubObjects[$object['cn'][0]]['dn'] = $object['dn'];
+ }
+ }
}
function execute()
/* Add new sub object */
if(isset($_POST['AddSubObject'])){
- $this->dialog= new faiScriptEntry($this->config,"new");
- $this->dialog->parent = &$this;
+ $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 faiScriptEntry($this->config,$this->SubObjects[$_POST['SubObject']]['dn']);
- $this->dialog->parent = &$this;
+ $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']))){
- $tmp = new faiScriptEntry($this->config,$this->SubObjects[$_POST['SubObject']]['dn']);
- $tmp->remove_from_parent();
- unset($tmp);
+ if($this->SubObjects[$_POST['SubObject']]['status'] == "edited"){
+ $this->SubObjects[$_POST['SubObject']]['status']= "delete";
+ }else{
+ unset($this->SubObjects[$_POST['SubObject']]);
+ }
}
/* Save Dialog */
print_red($msg);
}
}else{
- $this->dialog->save_object();
- $this->dialog->save();
+ $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;
return($display);
}
- $buffer = $this->getList();
- $smarty->assign("SubObjects",$buffer);
- $smarty->assign("SubObjectKeys",array_flip($buffer));
+ $smarty->assign("SubObjects",$this->getList());
+ $smarty->assign("SubObjectKeys",array_flip($this->getList()));
/* Magic quotes GPC, escapes every ' " \, to solve some security risks
* If we post the escaped strings they will be escaped again
/* Generate listbox friendly SubObject list
*/
function getList(){
- $a_return = array();
- $this->SubObjects = array();
-
- $ldap = $this->config->get_ldap_link();
- $ldap->cd ($this->config->current['BASE']);
- $ldap->cd ($this->dn);
-
- $ldap->search("(objectClass=FAIscriptEntry)",array("cn"));
-
- while($entry = $ldap->fetch()){
- $tmp = array();
- $tmp['cn'] = $entry['cn'][0];
- $tmp['dn']=$entry['dn'];
- $this->SubObjects[$tmp['cn']] = $tmp;
-
- if(isset($entry['description'][0])){
- $a_return[$tmp['cn']] = $tmp['cn']." [".$entry['description'][0]."]";
- }else{
- $a_return[$tmp['cn']] = $tmp['cn'];
+ $a_return=array();
+ foreach($this->SubObjects as $obj){
+ if($obj['status'] != "delete"){
+ if((isset($obj['description']))&&(!empty($obj['description']))){
+ $a_return[$obj['cn']]= $obj['cn']." [".$obj['description']."]";
+ }else{
+ $a_return[$obj['cn']]= $obj['cn'];
+ }
}
}
return($a_return);
$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");
}
*/
function save_object()
{
- if(isset($_POST['FAIscript_submit'])){
- plugin::save_object();
- foreach($this->attributes as $attrs){
- if(isset($_POST[$attrs])){
- $this->$attrs = $_POST[$attrs];
- }
+ plugin::save_object();
+ foreach($this->attributes as $attrs){
+ if(isset($_POST[$attrs])){
+ $this->$attrs = $_POST[$attrs];
}
}
}
function save()
{
plugin::save();
-
- if($this->dn == "new"){
- $this->dn = $this->use_dn;
- }
$ldap = $this->config->get_ldap_link();
+
$ldap->cat($this->dn);
if($ldap->count()!=0){
/* Write FAIscript to ldap*/
$ldap->add($this->attrs);
}
show_ldap_error($ldap->get_error());
+
+ /* 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){
+
+ foreach($this->sub64coded as $codeIt){
+ $obj[$codeIt]=base64_encode(stripslashes($obj[$codeIt]));
+ }
+
+ $tmp = array();
+ foreach($this->subAttributes as $attrs){
+ if(empty($obj[$attrs])){
+ $obj[$attrs] = array();
+ }
+ if(!is_array($obj[$attrs])){
+ $tmp[$attrs] = stripslashes($obj[$attrs]);
+ }else{
+ $tmp[$attrs] = $obj[$attrs];
+ }
+ }
+
+ $tmp['objectClass'] = $this->subClasses;
+
+ $sub_dn = "cn=".$obj['cn'].",".$this->dn;
+
+ if($obj['status']=="new"){
+ $ldap->cat($sub_dn);
+ if($ldap->count()){
+ $obj['status']="modify";
+ }
+ }
+
+ 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"){
+ if($tmp['description']==array()){
+ unset($tmp['description']);
+ }
+ if($tmp['FAIscript']==array()){
+ $tmp['FAIscript']=" ";
+ }
+ $ldap->cd($this->config->current['BASE']);
+ $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
+ $ldap->cd($sub_dn);
+ $ldap->add($tmp);
+ $this->handle_post_events("add");
+ }
+ show_ldap_error($ldap->get_error());
+ }
}
}
diff --git a/plugins/admin/fai/class_faiScriptEntry.inc b/plugins/admin/fai/class_faiScriptEntry.inc
index e2148014f10384477609556c510980887142ac0d..1fb0239d9088aa3a47b1b1d011c65f719399a986 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 $attributes = array("Object_cn","Object_description","Object_FAIpriority","Object_FAIscript");
+ var $objectclasses= array();
- 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 $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)
+ 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 = "Object_".$name;
+ $this->$oname=$value;
+ }
}else{
- $this->status = "new";
- $this->orig_cn = false;
+ $this->Object_status = "new";
+ $this->orig_cn = false;
}
}
print_red(_("Selected file is empty."));
}else{
$str = utf8_encode(file_get_contents($_FILES['ImportFile']['tmp_name']));
- $this->FAIscript = $str;
+ $this->Object_FAIscript = $str;
}
}
+
foreach($this->attributes as $attrs){
if(get_magic_quotes_gpc()){
}
for($i =0 ; $i < 100 ; $i++){
- $FAIprioritys[$i]=$i;
+ $Object_FAIprioritys[$i]=$i;
}
- $smarty->assign("FAIprioritys",$FAIprioritys);
+ $smarty->assign("Object_FAIprioritys",$Object_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()
{
{
$message= array();
- if(empty($this->cn)){
+ if(empty($this->Object_cn)){
$message[] = _("Please enter a name.");
}
- if(preg_match("/[^0-9a-z]/i",$this->cn)){
+ if(preg_match("/[^0-9a-z]/i",$this->Object_cn)){
$message[] = _("Please enter a valid name. Only a-Z 0-9 are allowed.");
}
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){
+ $attr = preg_replace("/^Object_/","",$attrs);
+ $tmp[$attr] = $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());
+ 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:
index 43000d7ee30ab57f9042b3338fd3f198cafe93e5..7896626c7f0e3e344c1d87db8dd671d2544a5ff5 100644 (file)
</td>
</tr>
</table>
-<input type="hidden" value="1" name="FAIscript_submit">
index 6a137a4bafe4c0f05599989b364847fe51fadd17..0017e6095012e2b3bb2d43019a4dc1c5887bcddb 100644 (file)
{t}Name{/t}{$must}
</td>
<td>
- <input value="{$cn}" name="cn">
+ <input value="{$Object_cn}" name="Object_cn">
</td>
</tr>
<tr>
{t}Description{/t}
</td>
<td>
- <input size=40 value="{$description}" name="description">
+ <input size=40 value="{$Object_description}" name="Object_description">
</td>
</tr>
</table>
<table width="100%">
<tr>
<td>
- <LABEL for="FAIpriority">
+ <LABEL for="Object_FAIpriority">
{t}Priority{/t}
</LABEL>
</td>
<td>
- <select name="FAIpriority" title="{t}Choose a priority{/t}" FAIpriority>
- {html_options values=$FAIprioritys output=$FAIprioritys selected=$FAIpriority}
+ <select name="Object_FAIpriority" title="{t}Choose a priority{/t}" Object_FAIpriority>
+ {html_options values=$Object_FAIprioritys output=$Object_FAIprioritys selected=$Object_FAIpriority}
</select>
</td>
</tr>
</table>
<p class="seperator"> </p>
<h2><img alt="" src="images/fai_script.png" align="middle" title="{t}Script attributes{/t}">
- <LABEL for="FAIscript">
+ <LABEL for="Object_FAIscript">
{t}Script{/t}
</LABEL>
</h2>
<table width="99%">
<tr>
<td>
- <textarea name="FAIscript" style="width:100%;height:300px;" id="FAIscript">{$FAIscript}</textarea>
+ <textarea name="Object_FAIscript" style="width:100%;height:300px;" id="Object_FAIscript">{$Object_FAIscript}</textarea>
</td>
</tr>
</table>
index 75f7e39d08f0f598f2eed6b2f723de28d775ad4c..b9a63d34bf78265dc162219924903188022d5a6e 100644 (file)
{
var $base= "";
- function tabsScript($config, $data, $dn, $new_cn = "")
+ function tabsScript($config, $data, $dn)
{
tabs::tabs($config, $data, $dn);
-
- /* Directly assign a valid dn
- * cn can't be changed anymore, since the object was created
- */
- $baseobject= $this->by_object['faiScript'];
- $use_dn= 'cn='.$new_cn.",ou=scripts,ou=fai,ou=configs,ou=systems,".$_SESSION['faifilter']['base'];
- $this->by_object['faiScript']->use_dn=$use_dn;
}
function check()
{
return (tabs::check(TRUE));
}
+
function save()
{