Code

Reset array of dns to delete, before adding new dns
[gosa.git] / gosa-plugins / goto / admin / applications / class_applicationManagement.inc
index 9cecb11035cfaa0fa37c2979af4531b881be1f93..7024e7991199da05e2c41791cfbdcc465f2e8075 100644 (file)
@@ -33,6 +33,11 @@ class applicationManagement extends plugin
   var $enableReleaseManagement  = false;
   var $start_pasting_copied_objects = FALSE;
 
+  var $app_base     ="";
+  var $app_release  ="";
+
+  var $dns = array();
+
   function IsReleaseManagementActivated()
   {
     /* Check if we should enable the release selection */
@@ -43,6 +48,7 @@ class applicationManagement extends plugin
     return(false);
   }
 
+
   function applicationManagement (&$config, &$ui)
   {
     /* Save configuration for internal use */
@@ -64,20 +70,38 @@ class applicationManagement extends plugin
       /* Hide SubSearch checkbox */
       $this->DivListApplication->DisableCheckBox("SubSearch");
     }
+
+    /* Set default release */
+    if(!$this->IsReleaseManagementActivated()){
+      $this->app_base = get_ou("applicationou").$this->config->current['BASE'];
+      if(!session::is_set("app_filter")){
+        session::set("app_filter",array("app_base" => $this->app_base));
+      }
+      $app_filter     = session::get("app_filter");
+      $this->app_base = $app_filter['app_base'];
+    }else{
+      $this->app_base = get_ou("applicationou").$this->config->current['BASE'];
+      if(!session::is_set("app_filter")){
+        session::set("app_filter",array("app_base" => $this->app_base,"app_release" => $this->app_base));
+      }
+      $app_filter         = session::get("app_filter");
+      $this->app_base     = $app_filter['app_base'];
+      $this->app_release  = $app_filter['app_release'];
+    }
   }
 
-  function getReleases($base)
-  {
-    $ldap                   = $this->config->get_ldap_link();
-    $dn                     = get_ou('applicationou').$base;
-    $ret                    = array();
-    $ret [get_ou('applicationou').$base] = "/";
 
-    $ldap->cd($dn);
-    $ldap->search("objectClass=organizationalUnit",array("ou"));
+  function getReleases()
+  {
+    $ldap = $this->config->get_ldap_link();
+    $ret  = array();
+    $base = $this->app_base; 
 
+    $ret[$this->app_base] = "/";
+    $ldap->cd($base);
+    $ldap->search("(&(objectClass=organizationalUnit)(objectClass=FAIbranch))",array("ou"));
     while($attrs = $ldap->fetch()){
-      $str = str_replace($dn,"",$attrs['dn']);
+      $str = str_replace($base,"",$attrs['dn']);
       $tmp = array_reverse( split("ou=",$str));
       $str = "";
       foreach($tmp as $val){
@@ -105,7 +129,7 @@ class applicationManagement extends plugin
 
     /* These vars will be stored if you try to open a locked app, 
         to be able to perform your last requests after showing a warning message */
-    session::set('LOCK_VARS_TO_USE',array("/^act$/","/^id$/","/^appl_edit_/","/^appl_del_/","/^item_selected/","/^remove_multiple_applications/"));
+    session::set('LOCK_VARS_TO_USE',array("/^act$/","/^id$/","/^appl_edit_/","/^appl_del_/","/^item_selected/","/^remove_multiple_applications/","/^menu_action/"));
 
     $smarty       = get_smarty();             // Smarty instance
     $s_action     = "";                       // Contains the action to proceed
@@ -195,7 +219,8 @@ class applicationManagement extends plugin
 
       /* Create new usertab object */
       $this->apptabs= new apptabs($this->config,$this->config->data['TABS']['APPSTABS'], $this->dn,"application");
-      $this->apptabs->set_acl_base($this->DivListApplication->selectedBase);
+      $this->apptabs->parent = &$this;
+      $this->apptabs->set_acl_base($this->app_base);
     }
 
 
@@ -205,8 +230,7 @@ class applicationManagement extends plugin
 
     /* Cancel dialogs */
     if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel'])){
-      del_lock ($this->apptabs->dn);
-      unset ($this->apptabs);
+      $this->remove_lock();
       $this->apptabs= NULL;
       session::un_set('objectinfo');
     }
@@ -230,18 +254,22 @@ class applicationManagement extends plugin
       if (count($message) == 0){
 
         /* Save data data to ldap */
-        $this->apptabs->set_release($this->DivListApplication->selectedRelease);
         $this->apptabs->save();
 
         if (!isset($_POST['edit_apply'])){
           /* Application has been saved successfully, remove lock from
              LDAP. */
           if ($this->dn != "new"){
-            del_lock ($this->dn);
+            $this->remove_lock();
           }
-          unset ($this->apptabs);
           $this->apptabs= NULL;
           session::un_set('objectinfo');
+        }else{
+
+          /* Reinitialize tab */
+          if($this->apptabs instanceof tabs){
+            $this->apptabs->re_init();
+          }
         }
       } else {
         /* Ok. There seem to be errors regarding to the tab data,
@@ -273,6 +301,7 @@ class applicationManagement extends plugin
 
       /* Register apptabs to trigger edit dialog */
       $this->apptabs= new apptabs($this->config,$this->config->data['TABS']['APPSTABS'], $this->dn,"application");
+      $this->apptabs->parent = &$this;
       $this->apptabs->set_acl_base($this->dn);
       session::set('objectinfo',$this->dn);
     }
@@ -287,16 +316,15 @@ class applicationManagement extends plugin
       $ids = $this->list_get_selected_items();
 
       if(count($ids)){
-
+        $this->dns = array();
         foreach($ids as $id){
-          $dn = $this->applications[$id]['dn'];
-          $this->dns[$id] = $dn;
+          $this->dns[$id] = $this->applications[$id]['dn'];
         }
         if ($user= get_multiple_locks($this->dns)){
           return(gen_locked_message($user,$this->dns));
         }
 
-        $dns_names[] = array();
+        $dns_names = array();
         foreach($this->dns as $dn){
           add_lock ($dn, $this->ui->dn);
           $dns_names[] =@LDAP::fix($dn);
@@ -326,6 +354,7 @@ class applicationManagement extends plugin
 
           /* Delete request is permitted, perform LDAP action */
           $this->apptabs= new apptabs($this->config, $this->config->data['TABS']['APPSTABS'], $dn,"application");
+          $this->apptabs->parent = &$this;
           $this->apptabs->set_acl_base($dn);
           $this->apptabs->delete ();
           unset ($this->apptabs);
@@ -334,13 +363,14 @@ class applicationManagement extends plugin
         } else {
           /* Normally this shouldn't be reached, send some extra
              logs to notify the administrator */
-          print_red (msgPool::permDelete());
+          msg_dialog::display(_("Permission error"), msgPool::permDelete(), INFO_DIALOG);
           new log("security","application/".get_class($this),$dn,array(),"Tried to trick deletion.");
         }
-        /* Remove lock file after successfull deletion */
-        del_lock ($dn);
-        unset($this->dns[$key]);
       }
+
+      /* Remove lock file after successfull deletion */
+      $this->remove_lock();
+      $this->dns = array();
     }
 
 
@@ -350,10 +380,10 @@ class applicationManagement extends plugin
 
     /* Remove lock */
     if(isset($_POST['delete_multiple_application_cancel'])){
-      foreach($this->dns as $key => $dn){
-        del_lock ($dn);
-        unset($this->dns[$key]);
-      }
+
+      /* Remove lock file after successfull deletion */
+      $this->remove_lock();
+      $this->dns = array();
     }
 
     /**************** 
@@ -388,7 +418,7 @@ class applicationManagement extends plugin
 
         /* Obviously the user isn't allowed to delete. Show message and
            clean session. */
-        print_red(msgPool::permDelete());
+        msg_dialog::display(_("Permission error"), msgPool::permDelete(), INFO_DIALOG);
       }
     }
 
@@ -409,6 +439,7 @@ class applicationManagement extends plugin
 
         /* Delete request is permitted, perform LDAP action */
         $this->apptabs= new apptabs($this->config, $this->config->data['TABS']['APPSTABS'], $this->dn,"application");
+        $this->apptabs->parent = &$this;
         $this->apptabs->set_acl_base($this->dn);
         $this->apptabs->delete ();
         unset ($this->apptabs);
@@ -418,12 +449,12 @@ class applicationManagement extends plugin
 
         /* Normally this shouldn't be reached, send some extra
            logs to notify the administrator */
-        print_red(msgPool::permDelete());
+        msg_dialog::display(_("Permission error"), msgPool::permDelete(), INFO_DIALOG);
         new log("security","application/".get_class($this),$dn,array(),"Tried to trick deletion.");
       }
 
       /* Remove lock file after successfull deletion */
-      del_lock ($this->dn);
+      $this->remove_lock();
     }
 
 
@@ -433,7 +464,7 @@ class applicationManagement extends plugin
 
     /* Delete application canceled? */
     if (isset($_POST['delete_cancel'])){
-      del_lock ($this->dn);
+      $this->remove_lock();
       session::un_set('objectinfo');
     }
 
@@ -462,15 +493,21 @@ class applicationManagement extends plugin
      ****************/
 
     /* Check if there is a snapshot dialog open */
-    $base = $this->DivListApplication->selectedBase;
-    if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases($base))){
+    if($this->IsReleaseManagementActivated()){
+      $base = $this->app_release;  
+    }else{
+      $base = $this->app_base;  
+    }
+    if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
       return($str);
     }
 
     /* Display dialog with system list */
     $this->DivListApplication->parent = $this;
     $this->DivListApplication->execute();
-    $this->DivListApplication->AddDepartments($this->DivListApplication->selectedBase,3,1);
+    if(!$this->IsReleaseManagementActivated()){
+      $this->DivListApplication->AddDepartments($this->DivListApplication->selectedBase,3,1);
+    } 
     $this->reload();
     $this->DivListApplication->setEntries($this->applications);
     return($this->DivListApplication->Draw());
@@ -478,11 +515,12 @@ class applicationManagement extends plugin
 
 
   /* Return departments, that will be included within snapshot detection */
-  function get_used_snapshot_bases(){
-    if($this->DivListApplication->selectedRelease == "main"){
-      return(array($this->DivListApplication->selectedBase));
+  function get_used_snapshot_bases()
+  {
+    if($this->IsReleaseManagementActivated()){
+      return(array($this->app_release));  
     }else{
-      return(array($this->DivListApplication->selectedRelease));
+      return(array($this->app_base));  
     }
   }
 
@@ -492,30 +530,27 @@ class applicationManagement extends plugin
     $this->applications= array();
 
     /* Set base for all searches */
-    $base       = $this->DivListApplication->selectedBase;
-    $release    = $this->DivListApplication->selectedRelease;
     $Regex      = $this->DivListApplication->Regex;
     $SubSearch  = $this->DivListApplication->SubSearch; 
     $Flags      =  GL_NONE | GL_SIZELIMIT;
     $Filter     = "(&(cn=".$Regex.")(objectClass=gosaApplication))";
     $tmp        = array();
-    $Releases   = $this->getReleases($base);
 
-    if(!$this->enableReleaseManagement){
-      $use_base = get_ou('applicationou').$base;
-    }else{
-      if(isset($Releases[$release])){
-        $use_base  = $release;
-      }else{
-        $use_base  = get_ou('applicationou').$base;
+    if(!$this->IsReleaseManagementActivated()){
+      $use_base = $this->app_base;
+      if($SubSearch){
+        $use_base = preg_replace("/^".normalizePreg(get_ou("applicationou"))."/","",$use_base);
       }
+    }else{
+      $use_base = $this->app_release;
+      $SubSearch= FALSE;
     }
-
-    if($SubSearch){
-      $Flags    |= GL_SUBSEARCH;  
+  
+    if($SubSearch){ 
+      $res= get_sub_list($Filter, "application",get_ou("applicationou"), $use_base, array("cn","description","dn","objectClass"), $Flags);
+    }else{
+      $res= get_list($Filter, "application",$use_base, array("cn","description","dn","objectClass"), $Flags);
     }
-   
-    $res= get_list($Filter, "application", $use_base, array("cn","description","dn","objectClass"), $Flags);
     $tmp2 = array();
     foreach ($res as $val){
       $tmp[strtolower($val['cn'][0]).$val['cn'][0].$val['dn']]=$val;
@@ -584,7 +619,8 @@ class applicationManagement extends plugin
 
 
       /* Get dialog */
-      $this->CopyPasteHandler->SetVar("base",$this->DivListApplication->selectedBase);
+      $this->CopyPasteHandler->SetVar("base",$this->app_base);
+      $this->CopyPasteHandler->SetVar("parent",$this);
       $data = $this->CopyPasteHandler->execute();
 
       /* Return dialog data */
@@ -621,19 +657,47 @@ class applicationManagement extends plugin
     $this->postcreate();
   }
 
+
   function remove_lock()
   {
     if (isset($this->apptabs->dn)){
       del_lock ($this->apptabs->dn);
     }
+    if(isset($this->dn) && !empty($this->dn) && $this->dn != "new"){
+      del_lock($this->dn);
+    }
+    if(isset($this->dns) && is_array($this->dns) && count($this->dns)){
+      del_lock($this->dns);
+    }
   }
 
-  function save_object() {
+
+  function save_object() 
+  {
     $this->DivListApplication->save_object();
+    if(is_object($this->CopyPasteHandler)){
+      $this->CopyPasteHandler->save_object();
+    }
+    
+    if($this->IsReleaseManagementActivated() && isset($_POST['app_release'])){
+      $sel_rel = get_post('app_release');
+      $releases = array_flip($this->getReleases());
+      if(isset($releases[$sel_rel])){
+        $this->app_release = $releases[$sel_rel];
+      }
+      $app_filter     = session::get("app_filter");
+      $app_filter['app_release'] = $this->app_release;
+      session::set("app_filter",$app_filter);
+    }elseif(!$this->IsReleaseManagementActivated()){
+      $this->app_base = get_ou("applicationou").$this->DivListApplication->selectedBase;
+      $app_filter     = session::get("app_filter");
+      $app_filter['app_base'] = $this->app_base;
+      session::set("app_filter",$app_filter);
+    }
   }
 
   function check() {}
-  function adapt_from_template($dn) {}
+  function adapt_from_template($dn, $skip= array()) {}
   function password_change_needed() {}
 }
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: