Code

Fixed layout
[gosa.git] / include / class_plugin.inc
index 6cbec1b4eddc6cf2a5559cf6b04e21b406a3c27c..953f18ddaab3023caf0e722c82c3ce6e4a25aa6e 100644 (file)
@@ -115,6 +115,9 @@ class plugin
   var $plHeadline= "";
   var $plDescription= "";
 
+  /* This can be set to render the tabulators in another stylesheet */
+  var $pl_notify= FALSE;
+
   /*! \brief plugin constructor
 
     If 'dn' is set, the node loads the given 'dn' from LDAP
@@ -122,10 +125,10 @@ class plugin
     \param dn Distinguished name to initialize plugin from
     \sa plugin()
    */
-  function plugin ($config, $dn= NULL, $parent= NULL)
+  function plugin (&$config, $dn= NULL, $parent= NULL)
   {
     /* Configuration is fine, allways */
-    $this->config= $config;    
+    $this->config= &$config;   
     $this->dn= $dn;
 
     /* Handle new accounts, don't read information from LDAP */
@@ -138,10 +141,10 @@ class plugin
 
     /* Get LDAP descriptor */
     $ldap= $this->config->get_ldap_link();
-    if ($dn != NULL){
+    if ($dn !== NULL){
 
       /* Load data to 'attrs' and save 'dn' */
-      if ($parent != NULL){
+      if ($parent !== NULL){
         $this->attrs= $parent->attrs;
       } else {
         $ldap->cat ($dn);
@@ -172,7 +175,6 @@ class plugin
       }
 
       /* Is Account? */
-      error_reporting(0);
       $found= TRUE;
       foreach ($this->objectclasses as $obj){
         if (preg_match('/top/i', $obj)){
@@ -183,7 +185,6 @@ class plugin
           break;
         }
       }
-      error_reporting(E_ALL);
       if ($found){
         $this->is_account= TRUE;
         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
@@ -222,8 +223,6 @@ class plugin
    */
   function execute()
   {
-    gosa_log("ACL ".get_class($this)." - ".$this->acl_category." - ".$this->acl_base);
-
     /* This one is empty currently. Fabian - please fill in the docu code */
     $_SESSION['current_class_for_help'] = get_class($this);
 
@@ -242,21 +241,16 @@ class plugin
     /* Get current objectClasses in order to add the required ones */
     $ldap->cat($this->dn);
     $tmp= $ldap->fetch ();
+    $oc= array();
     if (isset($tmp['objectClass'])){
       $oc= $tmp['objectClass'];
-    } else {
-      $oc= array("count" => 0);
+      unset($oc['count']);
     }
 
     /* Remove objectClasses from entry */
     $ldap->cd($this->dn);
     $this->attrs= array();
-    $this->attrs['objectClass']= array();
-    for ($i= 0; $i<$oc["count"]; $i++){
-      if (!in_array_ics($oc[$i], $this->objectclasses)){
-        $this->attrs['objectClass'][]= $oc[$i];
-      }
-    }
+    $this->attrs['objectClass']= array_remove_entries($this->objectclasses,$oc);
 
     /* Unset attributes from entry */
     foreach ($this->attributes as $val){
@@ -323,22 +317,18 @@ class plugin
     $ldap->cat($this->dn);
     
     $tmp= $ldap->fetch ();
-    
+
+    $oc= array();
     if (isset($tmp['objectClass'])){
       $oc= $tmp["objectClass"];
       $this->is_new= FALSE;
+      unset($oc['count']);
     } else {
-      $oc= array("count" => 0);
       $this->is_new= TRUE;
     }
 
     /* Load (minimum) attributes, add missing ones */
-    $this->attrs['objectClass']= $this->objectclasses;
-    for ($i= 0; $i<$oc["count"]; $i++){
-      if (!in_array_ics($oc[$i], $this->objectclasses)){
-        $this->attrs['objectClass'][]= $oc[$i];
-      }
-    }
+    $this->attrs['objectClass']= gosa_array_merge($oc,$this->objectclasses);
 
     /* Copy standard attributes */
     foreach ($this->attributes as $val){
@@ -397,6 +387,11 @@ class plugin
         }
       }
     }
+
+    /* Update saved attributes and ensure that next cleanups will be successful too */
+    foreach($this->attrs as $name => $value){
+      $this->saved_attributes[$name] = $value;
+    }
   }
 
   /* Check formular input */
@@ -405,15 +400,12 @@ class plugin
     $message= array();
 
     /* Skip if we've no config object */
-    if (!isset($this->config)){
+    if (!isset($this->config) || !is_object($this->config)){
       return $message;
     }
 
     /* Find hooks entries for this class */
-    $command= search_config($this->config->data['MENU'], get_class($this), "CHECK");
-    if ($command == "" && isset($this->config->data['TABS'])){
-      $command= search_config($this->config->data['TABS'], get_class($this), "CHECK");
-    }
+    $command= $this->config->search(get_class($this), "CHECK", array('menu', 'tabs'));
 
     if ($command != ""){
 
@@ -574,12 +566,15 @@ class plugin
   function postcreate($add_attrs= array())
   {
     /* Find postcreate entries for this class */
-    $command= search_config($this->config->data['MENU'], get_class($this), "POSTCREATE");
-    if ($command == "" && isset($this->config->data['TABS'])){
-      $command= search_config($this->config->data['TABS'], get_class($this), "POSTCREATE");
-    }
+    $command= $this->config->search(get_class($this), "POSTCREATE",array('menu', 'tabs'));
 
     if ($command != ""){
+
+      /* Additional attributes */
+      foreach ($add_attrs as $name => $value){
+        $command= preg_replace("/%$name/", $value, $command);
+      }
+
       /* Walk through attribute list */
       foreach ($this->attributes as $attr){
         if (!is_array($this->$attr)){
@@ -588,11 +583,6 @@ class plugin
       }
       $command= preg_replace("/%dn/", $this->dn, $command);
 
-      /* Additional attributes */
-      foreach ($add_attrs as $name => $value){
-        $command= preg_replace("/%$name/", $value, $command);
-      }
-
       if (check_command($command)){
         @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
             $command, "Execute");
@@ -608,12 +598,15 @@ class plugin
   function postmodify($add_attrs= array())
   {
     /* Find postcreate entries for this class */
-    $command= search_config($this->config->data['MENU'], get_class($this), "POSTMODIFY");
-    if ($command == "" && isset($this->config->data['TABS'])){
-      $command= search_config($this->config->data['TABS'], get_class($this), "POSTMODIFY");
-    }
+    $command= $this->config->search(get_class($this), "POSTMODIFY",array('menu','tabs'));
 
     if ($command != ""){
+
+      /* Additional attributes */
+      foreach ($add_attrs as $name => $value){
+        $command= preg_replace("/%$name/", $value, $command);
+      }
+
       /* Walk through attribute list */
       foreach ($this->attributes as $attr){
         if (!is_array($this->$attr)){
@@ -622,11 +615,6 @@ class plugin
       }
       $command= preg_replace("/%dn/", $this->dn, $command);
 
-      /* Additional attributes */
-      foreach ($add_attrs as $name => $value){
-        $command= preg_replace("/%$name/", $value, $command);
-      }
-
       if (check_command($command)){
         @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
             $command, "Execute");
@@ -642,12 +630,14 @@ class plugin
   function postremove($add_attrs= array())
   {
     /* Find postremove entries for this class */
-    $command= search_config($this->config->data['MENU'], get_class($this), "POSTREMOVE");
-    if ($command == "" && isset($this->config->data['TABS'])){
-      $command= search_config($this->config->data['TABS'], get_class($this), "POSTREMOVE");
-    }
-
+    $command= $this->config->search(get_class($this), "POSTREMOVE",array('menu','tabs'));
     if ($command != ""){
+
+      /* Additional attributes */
+      foreach ($add_attrs as $name => $value){
+        $command= preg_replace("/%$name/", $value, $command);
+      }
+
       /* Walk through attribute list */
       foreach ($this->attributes as $attr){
         if (!is_array($this->$attr)){
@@ -755,7 +745,6 @@ class plugin
     }
 
     $r=ldap_bind($ds,$this->config->current['ADMIN'], $this->config->current['PASSWORD']);
-    error_reporting (0);
     $sr=ldap_read($ds, @LDAP::fix($src_dn), "objectClass=*");
 
     /* Fill data from LDAP */
@@ -764,7 +753,7 @@ class plugin
       $ei=ldap_first_entry($ds, $sr);
       if ($ei) {
         foreach($attrs as $attr => $val){
-          if ($info = ldap_get_values_len($ds, $ei, $attr)){
+          if ($info = @ldap_get_values_len($ds, $ei, $attr)){
             for ($i= 0; $i<$info['count']; $i++){
               if ($info['count'] == 1){
                 $new[$attr]= $info[$i];
@@ -778,7 +767,6 @@ class plugin
     }
 
     /* close conncetion */
-    error_reporting (E_ALL);
     ldap_unbind($ds);
 
     /* Adapt naming attribute */
@@ -909,15 +897,41 @@ class plugin
   }
 
 
-  function PrepareForCopyPaste($source){
+  function PrepareForCopyPaste($source)
+  {
     $todo = $this->attributes;
     if(isset($this->CopyPasteVars)){
       $todo = array_merge($todo,$this->CopyPasteVars);
     }
-    $todo[] = "is_account";
+
+    if(count($this->objectclasses)){
+      $this->is_account = TRUE;
+      foreach($this->objectclasses as $class){
+        if(!in_array($class,$source['objectClass'])){
+          $this->is_account = FALSE;
+        }
+      }
+    }
+
     foreach($todo as $var){
-      if (isset($source->$var)){
-        $this->$var= $source->$var;
+      if (isset($source[$var])){
+        if(isset($source[$var]['count'])){
+          if($source[$var]['count'] > 1){
+            $this->$var = array();
+            $tmp = array();
+            for($i = 0 ; $i < $source[$var]['count']; $i++){
+              $tmp = $source[$var][$i];
+            }
+            $this->$var = $tmp;
+#            echo $var."=".$tmp."<br>";
+          }else{
+            $this->$var = $source[$var][0];
+#            echo $var."=".$source[$var][0]."<br>";
+          }
+        }else{
+          $this->$var= $source[$var];
+#          echo $var."=".$source[$var]."<br>";
+        }
       }
     }
   }
@@ -1069,7 +1083,7 @@ class plugin
       $server         = $tmp['SNAPSHOT_SERVER'];
       $user           = $tmp['SNAPSHOT_USER'];
       $password       = $tmp['SNAPSHOT_PASSWORD'];
-      $snapldapbase   = $tmp['SNAPSHOT_LDAP_BASE'];
+      $snapldapbase   = $tmp['SNAPSHOT_BASE'];
 
       $ldap_to        = new LDAP($user,$password, $server);
       $ldap_to -> cd($snapldapbase);
@@ -1146,7 +1160,7 @@ class plugin
 
         /* Check if the snapshot_base is defined */
         if(!isset($tmp['SNAPSHOT_BASE'])){
-          print_red(sprintf(_("The snapshot functionality is enabled, but the required variable '%s' is not configured in your gosa.conf."),$missing));
+          print_red(sprintf(_("The snapshot functionality is enabled, but the required variable '%s' is not configured in your gosa.conf."),"SNAPSHOT_BASE"));
           return(FALSE);
         }
 
@@ -1155,7 +1169,7 @@ class plugin
 
           /* check if all required vars are available to create a new ldap connection */
           $missing = "";
-          foreach(array("SNAPSHOT_SERVER","SNAPSHOT_USER","SNAPSHOT_PASSWORD","SNAPSHOT_LDAP_BASE") as $var){
+          foreach(array("SNAPSHOT_SERVER","SNAPSHOT_USER","SNAPSHOT_PASSWORD","SNAPSHOT_BASE") as $var){
             if(!isset($tmp[$var])){
               $missing .= $var." ";
               print_red(sprintf(_("The snapshot functionality is enabled, but the required variable(s) '%s' is not configured in your gosa.conf."),$missing));
@@ -1180,14 +1194,14 @@ class plugin
        points to our ldap snapshot server */
     $ldap= $this->config->get_ldap_link();
     $ldap->cd($this->config->current['BASE']);
-    $tmp = $this->config->current;
+    $cfg= &$this->config->current;
 
     /* check if there are special server configurations for snapshots */
-    if(isset($tmp['SNAPSHOT_SERVER'])){
-      $server       = $tmp['SNAPSHOT_SERVER'];
-      $user         = $tmp['SNAPSHOT_USER'];
-      $password     = $tmp['SNAPSHOT_PASSWORD'];
-      $snapldapbase = $tmp['SNAPSHOT_LDAP_BASE'];
+    if(isset($cfg['SNAPSHOT_SERVER'])){
+      $server       = $cfg['SNAPSHOT_SERVER'];
+      $user         = $cfg['SNAPSHOT_USER'];
+      $password     = $cfg['SNAPSHOT_PASSWORD'];
+      $snapldapbase = $cfg['SNAPSHOT_BASE'];
       $ldap_to      = new LDAP($user,$password, $server);
       $ldap_to -> cd ($snapldapbase);
       show_ldap_error($ldap->get_error(), sprintf(_("Method get available snapshots with dn '%s' failed."),$this->dn));
@@ -1197,7 +1211,7 @@ class plugin
 
     /* Prepare bases and some other infos */
     $base           = $this->config->current['BASE'];
-    $snap_base      = $tmp['SNAPSHOT_BASE'];
+    $snap_base      = $cfg['SNAPSHOT_BASE'];
     $base_of_object = preg_replace ('/^[^,]+,/i', '', $dn);
     $new_base       = preg_replace("/".normalizePreg($base)."$/","",$base_of_object).$snap_base;
     $tmp            = array(); 
@@ -1236,14 +1250,14 @@ class plugin
        points to our ldap snapshot server */
     $ldap= $this->config->get_ldap_link();
     $ldap->cd($this->config->current['BASE']);
-    $tmp = $this->config->current;
+    $cfg= &$this->config->current;
 
     /* check if there are special server configurations for snapshots */
-    if(isset($tmp['SNAPSHOT_SERVER'])){
-      $server       = $tmp['SNAPSHOT_SERVER'];
-      $user         = $tmp['SNAPSHOT_USER'];
-      $password     = $tmp['SNAPSHOT_PASSWORD'];
-      $snapldapbase = $tmp['SNAPSHOT_LDAP_BASE'];
+    if(isset($cfg['SNAPSHOT_SERVER'])){
+      $server       = $cfg['SNAPSHOT_SERVER'];
+      $user         = $cfg['SNAPSHOT_USER'];
+      $password     = $cfg['SNAPSHOT_PASSWORD'];
+      $snapldapbase = $cfg['SNAPSHOT_BASE'];
       $ldap_to      = new LDAP($user,$password, $server);
       $ldap_to->cd ($snapldapbase);
       show_ldap_error($ldap->get_error(), sprintf(_("Method get deleted snapshots with dn '%s' failed."),$this->dn));
@@ -1253,7 +1267,7 @@ class plugin
 
     /* Prepare bases */ 
     $base           = $this->config->current['BASE'];
-    $snap_base      = $tmp['SNAPSHOT_BASE'];
+    $snap_base      = $cfg['SNAPSHOT_BASE'];
     $new_base       = preg_replace("/".normalizePreg($base)."$/","",$base_of_object).$snap_base;
 
     /* Fetch all objects and check if they do not exist anymore */
@@ -1300,14 +1314,14 @@ class plugin
 
     $ldap= $this->config->get_ldap_link();
     $ldap->cd($this->config->current['BASE']);
-    $tmp = $this->config->current;
+    $cfg= &$this->config->current;
 
     /* check if there are special server configurations for snapshots */
-    if(isset($tmp['SNAPSHOT_SERVER'])){
-      $server       = $tmp['SNAPSHOT_SERVER'];
-      $user         = $tmp['SNAPSHOT_USER'];
-      $password     = $tmp['SNAPSHOT_PASSWORD'];
-      $snapldapbase = $tmp['SNAPSHOT_LDAP_BASE'];
+    if(isset($cfg['SNAPSHOT_SERVER'])){
+      $server       = $cfg['SNAPSHOT_SERVER'];
+      $user         = $cfg['SNAPSHOT_USER'];
+      $password     = $cfg['SNAPSHOT_PASSWORD'];
+      $snapldapbase = $cfg['SNAPSHOT_BASE'];
       $ldap_to      = new LDAP($user,$password, $server);
       $ldap_to->cd ($snapldapbase);
       show_ldap_error($ldap->get_error(), sprintf(_("Restore snapshot with dn '%s' failed."),$snapldapbase));
@@ -1395,7 +1409,7 @@ class plugin
       $this->snapDialog = NULL;
     }
 
-    if($this->snapDialog){
+    if(is_object($this->snapDialog )){
       $this->snapDialog->save_object();
       return($this->snapDialog->execute());
     }
@@ -1516,8 +1530,6 @@ class plugin
    */
   function update_acls($old_dn,$new_dn,$output_changes = FALSE)
   {
-    global $config;
-
     /* Check if old_dn is empty. This should never happen */
     if(empty($old_dn) || empty($new_dn)){
       trigger_error("Failed to check acl dependencies, wrong dn given.");
@@ -1527,7 +1539,7 @@ class plugin
     /* Update userinfo if necessary */
     if($_SESSION['ui']->dn == $old_dn){
       $_SESSION['ui']->dn = $new_dn;
-      gosa_log(_("Updated current user dn from '".$old_dn."' to '".$new_dn."'"));
+      new log("view","acl/".get_class($this),$this->dn,array(),"Updated current user dn from '".$old_dn."' to '".$new_dn."'");
     }
 
     /* Object was moved, ensure that all acls will be moved too */
@@ -1535,8 +1547,8 @@ class plugin
 
       /* get_ldap configuration */
       $update = array();
-      $ldap = $config->get_ldap_link();
-      $ldap->cd ($config->current['BASE']);
+      $ldap = $this->config->get_ldap_link();
+      $ldap->cd ($this->config->current['BASE']);
       $ldap->search("(&(objectClass=gosaAcl)(gosaAclEntry=*))",array("cn","gosaAclEntry"));
       while($attrs = $ldap->fetch()){