Code

Added branches container for old stuff
[gosa.git] / gosa-plugins / goto / admin / applications / class_applicationManagement.inc
index 0ad9836b2d36c0b8ebc7959a20d23ad5f7a46fbb..d4d18b060ec665bf7e40f9e9bc12c77fddc6c59a 100644 (file)
@@ -23,6 +23,7 @@ class applicationManagement extends plugin
   /* Definitions */
   var $plHeadline     = "Applications";
   var $plDescription  = "This does something";
+  var $plIcon         = "plugins/goto/images/application.png";
 
   /* Dialog attributes */
   var $apptabs                  = NULL;
@@ -33,6 +34,13 @@ class applicationManagement extends plugin
   var $enableReleaseManagement  = false;
   var $start_pasting_copied_objects = FALSE;
 
+  var $acl_base     ="";
+  var $app_base     ="";
+  var $app_release  ="";
+  var $acl_module   = array("application");  
+
+  var $dns = array();
+
   function IsReleaseManagementActivated()
   {
     /* Check if we should enable the release selection */
@@ -43,14 +51,16 @@ class applicationManagement extends plugin
     return(false);
   }
 
+
   function applicationManagement (&$config, &$ui)
   {
     /* Save configuration for internal use */
     $this->config   = &$config;
     $this->ui       = &$ui;
+    $this->acl_base = $this->config->current['BASE'];
 
     /* Check if copy & paste is activated */
-    if($this->config->boolValueIsTrue("MAIN","ENABLECOPYPASTE")){
+    if($this->config->boolValueIsTrue("MAIN","COPYPASTE")){
       $this->CopyPasteHandler = new CopyPasteHandler($this->config);
     }
 
@@ -64,20 +74,47 @@ 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");
+    }else{
+
+      /* Set intial release */
+      $this->app_base = get_ou("applicationou").$this->config->current['BASE'];
+      $rel = $config->search("faiManagement","DEFAULT_RELEASE",array("menu"));
+      $rels = array_flip($this->getReleases());
+      if(isset($rels[$rel])){
+        $rel = $rels[$rel];
+      }else{
+        $rel = $this->app_base;
+      }
+
+      if(!session::is_set("app_filter")){
+        session::set("app_filter",array("app_base" => $this->app_base,"app_release" => $rel));
+      }
+      $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 +142,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 +232,14 @@ 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;
+
+      /* Check if there is a snapshot dialog open */
+      if($this->IsReleaseManagementActivated()){
+        $this->apptabs->set_acl_base($this->acl_base);
+      }else{
+        $this->apptabs->set_acl_base($this->DivListApplication->selectedBase);
+      }
     }
 
 
@@ -205,8 +249,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,23 +273,27 @@ 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,
            show message and continue as usual. */
-        msgDialog::displayChecks($message);
+        msg_dialog::displayChecks($message);
       }
     }
 
@@ -273,6 +320,10 @@ class applicationManagement extends plugin
 
       /* Register apptabs to trigger edit dialog */
       $this->apptabs= new apptabs($this->config,$this->config->data['TABS']['APPSTABS'], $this->dn,"application");
+      if($this->IsReleaseManagementActivated()){
+        $this->apptabs->set_FAIstate($this->applications[$s_entry]['FAIstate'][0]);
+      }
+      $this->apptabs->parent = &$this;
       $this->apptabs->set_acl_base($this->dn);
       session::set('objectinfo',$this->dn);
     }
@@ -287,30 +338,40 @@ class applicationManagement extends plugin
       $ids = $this->list_get_selected_items();
 
       if(count($ids)){
+        $this->dns = array();
 
+        $disallowed = array();
         foreach($ids as $id){
           $dn = $this->applications[$id]['dn'];
-          if (($user= get_lock($dn)) != ""){
-            return(gen_locked_message ($user, $dn));
+          $acl = $this->ui->get_permissions($dn, "application/application");
+          if(preg_match("/d/",$acl)){
+            $this->dns[$id] = $dn;
+          }else{
+            $disallowed[] = $dn;
           }
-          $this->dns[$id] = $dn;
         }
 
-        $dns_names = "<br><pre>";
-        foreach($this->dns as $dn){
-          add_lock ($dn, $this->ui->dn);
-          $dns_names .= $dn."\n";
+        if(count($disallowed)){
+          msg_dialog::display(_("Permission"),msgPool::permDelete($disallowed),INFO_DIALOG);
         }
-        $dns_names .="</pre>";
 
-        /* Lock the current entry, so nobody will edit it during deletion */
-        if (count($this->dns) == 1){
-          $smarty->assign("intro",     sprintf(_("You're about to delete the following entry %s"), @LDAP::fix($dns_names)));
-        } else {
-          $smarty->assign("intro",     sprintf(_("You're about to delete the following entries %s"), @LDAP::fix($dns_names)));
+        if(count($this->dns)){
+
+          if ($user= get_multiple_locks($this->dns)){
+            return(gen_locked_message($user,$this->dns));
+          }
+
+          $dns_names = array();
+          foreach($this->dns as $dn){
+            add_lock ($dn, $this->ui->dn);
+            $dns_names[] =@LDAP::fix($dn);
+          }
+
+          /* Lock the current entry, so nobody will edit it during deletion */
+          $smarty->assign("intro",  msgPool::deleteInfo($dns_names,_("application")));
+          $smarty->assign("multiple", true);
+          return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
         }
-        $smarty->assign("multiple", true);
-        return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
       }
     }
 
@@ -331,6 +392,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);
@@ -339,13 +401,14 @@ class applicationManagement extends plugin
         } else {
           /* Normally this shouldn't be reached, send some extra
              logs to notify the administrator */
-          print_red (_("You are not allowed to delete this application!"));
+          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();
     }
 
 
@@ -355,10 +418,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();
     }
 
     /**************** 
@@ -386,14 +449,14 @@ class applicationManagement extends plugin
         /* Lock the current entry, so nobody will edit it during deletion */
         add_lock ($this->dn, $this->ui->dn);
         $smarty= get_smarty();
-        $smarty->assign("intro", sprintf(_("You're about to delete the application '%s'."), @LDAP::fix($this->dn)));
+        $smarty->assign("intro",msgPool::deleteInfo(@LDAP::fix($this->dn),_("application")));
         $smarty->assign("multiple", false);
         return($smarty->fetch (get_template_path('remove.tpl', TRUE)));
       } else {
 
         /* Obviously the user isn't allowed to delete. Show message and
            clean session. */
-        print_red (_("You are not allowed to delete this application!"));
+        msg_dialog::display(_("Permission error"), msgPool::permDelete(), INFO_DIALOG);
       }
     }
 
@@ -414,6 +477,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);
@@ -423,12 +487,12 @@ class applicationManagement extends plugin
 
         /* Normally this shouldn't be reached, send some extra
            logs to notify the administrator */
-        print_red (_("You are not allowed to delete this application!"));
+        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();
     }
 
 
@@ -438,7 +502,7 @@ class applicationManagement extends plugin
 
     /* Delete application canceled? */
     if (isset($_POST['delete_cancel'])){
-      del_lock ($this->dn);
+      $this->remove_lock();
       session::un_set('objectinfo');
     }
 
@@ -449,11 +513,14 @@ class applicationManagement extends plugin
       /* Don't show buttons if tab dialog requests this */
       if (!$this->apptabs->by_object[$this->apptabs->current]->dialog){
         $display.= "<p style=\"text-align:right\">\n";
-        $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\"".msgPool::okButton()."\">\n";
-        $display.= "&nbsp;\n";
-        if ($this->dn != "new"){
-          $display.= "<input type=submit name=\"edit_apply\" value=\"".msgPool::applyButton()."\">\n";
+
+        if(isset($this->apptabs->FAIstate) && !preg_match("/freeze/i",$this->apptabs->FAIstate)){
+          $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\"".msgPool::okButton()."\">\n";
           $display.= "&nbsp;\n";
+          if ($this->dn != "new"){
+            $display.= "<input type=submit name=\"edit_apply\" value=\"".msgPool::applyButton()."\">\n";
+            $display.= "&nbsp;\n";
+          }
         }
         $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
         $display.= "</p>";
@@ -467,15 +534,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(),$this)){
       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());
@@ -483,11 +556,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));  
     }
   }
 
@@ -497,32 +571,38 @@ 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;  
+    /* Add FAIstate to the search attributes */
+    $search_attrs = array("cn","description","dn","objectClass");
+    if($this->IsReleaseManagementActivated()) {
+      $search_attrs[] = "FAIstate";
+    }
+    if($SubSearch){ 
+      $res= get_sub_list($Filter, "application",get_ou("applicationou"), $use_base, $search_attrs, $Flags);
+    }else{
+      $res= get_list($Filter, "application",$use_base, $search_attrs, $Flags);
     }
-   
-    $res= get_list($Filter, "application", $use_base, array("cn","description","dn","objectClass"), $Flags);
     $tmp2 = array();
     foreach ($res as $val){
+      if(!isset($val['FAIstate'])){
+        $val['FAIstate'][0] = "";
+      }
       $tmp[strtolower($val['cn'][0]).$val['cn'][0].$val['dn']]=$val;
       $tmp2[strtolower($val['cn'][0]).$val['cn'][0].$val['dn']] = strtolower($val['cn'][0]).$val['cn'][0].$val['dn'];
     }
@@ -549,13 +629,20 @@ class applicationManagement extends plugin
       return("");
     }
 
+    $ui = get_userinfo();
+
     /* Add a single entry to queue */
     if($s_action == "cut" || $s_action == "copy"){
 
       /* Cleanup object queue */
       $this->CopyPasteHandler->cleanup_queue();
       $dn = $this->applications[$s_entry]['dn'];
-      $this->CopyPasteHandler->add_to_queue($dn,$s_action,"apptabs","APPSTABS","application");
+      if($s_action == "copy" && $ui->is_copyable($dn,"application","application")){
+        $this->CopyPasteHandler->add_to_queue($dn,$s_action,"apptabs","APPSTABS","application");
+      }
+      if($s_action == "cut" && $ui->is_cutable($dn,"application","application")){ 
+        $this->CopyPasteHandler->add_to_queue($dn,$s_action,"apptabs","APPSTABS","application");
+      }
     }
 
 
@@ -569,10 +656,10 @@ class applicationManagement extends plugin
       foreach($this->list_get_selected_items() as $id){
         $dn = $this->applications[$id]['dn'];
 
-        if($s_action == "copy_multiple"){
+        if($s_action == "copy_multiple" && $ui->is_copyable($dn,"application","application")){ 
           $this->CopyPasteHandler->add_to_queue($dn,"copy","apptabs","APPSTABS","application");
         }
-        if($s_action == "cut_multiple"){
+        if($s_action == "cut_multiple" && $ui->is_cutable($dn,"application","application")){
           $this->CopyPasteHandler->add_to_queue($dn,"cut","apptabs","APPSTABS","application");
         }
       }
@@ -589,7 +676,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 */
@@ -626,19 +714,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: