Code

Init require with parent
[gosa.git] / include / sieve / class_My_Tree.inc
index f38f3bab81eb608f548871ba84a78b5674dc6fbb..645188fc283be7b43d8019c907e7a1c2cd57eb2b 100644 (file)
@@ -15,6 +15,13 @@ class My_Tree extends Tree
 
   var $mode_stack = array();
   var $pap             = array();
+  var $parent = NULL;
+
+       function My_Tree(&$root,$parent)
+       {
+    $this->parent = $parent;
+               $this->_construct($root);
+       }
 
   function execute()
   {
@@ -136,7 +143,7 @@ class My_Tree extends Tree
     
     $class_name= "sieve_".$type ;
     if(class_exists($class_name)){
-      $this->pap[] = new $class_name($data,$id);
+      $this->pap[] = new $class_name($data,$id,$this);
     }else{
       echo "<font color='red'>Missing : ".$class_name."</font>"."<br>";
     }
@@ -564,6 +571,35 @@ class My_Tree extends Tree
                }
                return($msgs);
   }
+
+
+  /* We are forced to add a new require.
+   *  This function is called by the 
+   *  sieveElement_Classes->parent->add_require()  
+   */ 
+  function add_require($str)
+  {
+    $require_id = -1;
+    foreach($this->pap as $key => $obj){
+      if(get_class($obj) == "sieve_require"){
+        $require_id = $key;
+      }
+    }
+  
+    /* No require found, add one */
+    if($require_id == -1){
+      $require = new sieve_require(NULL,preg_replace("/[^0-9]/","",microtime()),$this);
+      $require -> Add_Require($str);
+      $new = array();
+      $new[] = $require;
+      foreach($this->pap as $obj){
+        $new[] = $obj;
+      }
+      $this->pap = $new;
+    } else { 
+      $this->pap[$require_id]->Add_Require($str);
+    } 
+  }
 }