Code

Migration to get_value
[gosa.git] / gosa-plugins / goto / admin / mimetypes / class_mimetypeManagement.inc
index 44fada93940f0eb0d48d640f2bb5c00c4dfd0e0f..5bbe95dea17fb7f48876fd2d10896b5650942ea6 100644 (file)
@@ -23,15 +23,31 @@ class mimetypeManagement extends plugin
   /* Definitions */
   var $plHeadline     = "Mime types";
   var $plDescription  = "Manage mime types";
+  var $plIcon         = "plugins/goto/images/mimetypes.png";
 
   /* Dialog attributes */
   var $ui                             = NULL;
   var $DivListMimeTypes               = NULL;
-  var $enableReleaseManagement        = false;
   var $mimetabs                       = NULL;
   var $snapDialog                     = NULL;
   var $CopyPasteHandler               = NULL;
-  var $start_pasting_copied_objects = FALSE;
+  var $start_pasting_copied_objects   = FALSE;
+  var $enableReleaseManagement        = false;
+
+  var $mime_base    = "";
+  var $mime_release = "";
+
+  var $acl_module = array("mimetypes");
+
+  function IsReleaseManagementActivated()
+  {
+    /* Check if we should enable the release selection */
+    $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs'));
+    if(!empty($tmp)){
+      return(true);
+    }
+    return(false);
+  }
 
 
   function mimetypeManagement (&$config, &$ui)
@@ -41,7 +57,7 @@ class mimetypeManagement extends plugin
     $this->ui       = &$ui;
 
     /* Check if copy & paste is activated */
-    if($this->config->boolValueIsTrue("MAIN","ENABLECOPYPASTE")){
+    if($this->config->get_cfg_value("enablecopypaste")){
       $this->CopyPasteHandler = new CopyPasteHandler($this->config);
     }
 
@@ -57,22 +73,38 @@ class mimetypeManagement extends plugin
       $this->DivListMimeTypes->DisableCheckBox("SubSearch");
     }
 
+    /* Set default release */
+    if(!$this->IsReleaseManagementActivated()){
+      $this->mime_base = get_ou("mimetypeou").$this->config->current['BASE'];
+      if(!session::is_set("mime_filter")){
+        session::set("mime_filter",array("mime_base" => $this->mime_base));
+      }
+      $mime_filter     = session::get("mime_filter");
+      $this->mime_base = $mime_filter['mime_base'];
+    }else{
+      $this->mime_base = get_ou("mimetypeou").$this->config->current['BASE'];
+      if(!session::is_set("mime_filter")){
+        session::set("mime_filter",array("mime_base" => $this->mime_base,"mime_release" => $this->mime_base));
+      }
+      $mime_filter         = session::get("mime_filter");
+      $this->mime_base     = $mime_filter['mime_base'];
+      $this->mime_release  = $mime_filter['mime_release'];
+    }
   }
 
 
   /* Get all releases */
-  function getReleases($base)
+  function getReleases()
   {
     $ldap                   = $this->config->get_ldap_link();
-    $dn                     = get_ou('mimetypeou').$base;
     $ret                    = array();
-    $ret [get_ou('mimetypeou').$base] = "/";    
+    $ret [$this->mime_base] = "/";    
 
-    $ldap->cd($dn);
-    $ldap->search("objectClass=organizationalUnit",array("ou"));
+    $ldap->cd($this->mime_base);
+    $ldap->search("(&(objectClass=FAIbranch)(objectClass=organizationalUnit))",array("ou"));
 
     while($attrs = $ldap->fetch()){
-      $str = str_replace($dn,"",$attrs['dn']);
+      $str = str_replace($this->mime_base,"",$attrs['dn']);
       $tmp = array_reverse( split("ou=",$str));
       $str = "";
       foreach($tmp as $val){
@@ -88,6 +120,7 @@ class mimetypeManagement extends plugin
     return($ret);
   }
 
+
   function execute()
   {
     /* Call parent execute */
@@ -100,7 +133,8 @@ class mimetypeManagement extends plugin
 
     /* These vars will be stored if you try to open a locked mime, 
         to be able to perform your last requests after showing a warning message */
-    session::set('LOCK_VARS_TO_USE',array("/^act$/","/^id$/","/^mime_edit_/","/^mime_del_/","/^item_selected/","/^remove_multiple_mimetypes/"));
+    session::set('LOCK_VARS_TO_USE',array("/^act$/","/^id$/","/^mime_edit_/","/^mime_del_/",
+          "/^item_selected/","/^remove_multiple_mimetypes/","/^menu_action/"));
 
     $smarty       = get_smarty();             // Smarty instance
     $s_action     = "";                       // Contains the action to proceed
@@ -145,8 +179,6 @@ class mimetypeManagement extends plugin
 
     $s_entry  = preg_replace("/_.$/","",$s_entry);
 
-
     /* handle C&P from layers menu */
     if(isset($_POST['menu_action']) && preg_match("/^multiple_copy_systems/",$_POST['menu_action'])){
       $s_action = "copy_multiple";
@@ -168,6 +200,7 @@ class mimetypeManagement extends plugin
       $s_action = "del_multiple";
     }
 
+
     /**************** 
       Copy & Paste handling  
      ****************/
@@ -185,7 +218,7 @@ class mimetypeManagement extends plugin
 
     /* New mime type? */
     $ui = get_userinfo();
-    $acl = $ui->get_permissions($this->DivListMimeTypes->selectedBase,"mimetypes/mimetype");
+    $acl = $ui->get_permissions($this->mime_base,"mimetypes/mimetype");
     if (($s_action=="new") && preg_match("/c/",$acl)){
 
       /* By default we set 'dn' to 'new', all relevant plugins will
@@ -194,7 +227,8 @@ class mimetypeManagement extends plugin
 
       /* Create new usertab object */
       $this->mimetabs= new mimetabs($this->config, $this->config->data['TABS']['MIMETABS'], $this->dn,"mimetypes");
-      $this->mimetabs->set_acl_base($this->DivListMimeTypes->selectedBase);
+      $this->mimetabs->parent = &$this;
+      $this->mimetabs->set_acl_base($this->mime_base);
     }   
 
 
@@ -204,8 +238,7 @@ class mimetypeManagement extends plugin
 
     /* Cancel dialogs */
     if (isset($_POST['edit_cancel'])){
-      del_lock ($this->mimetabs->dn);
-      unset ($this->mimetabs);
+      $this->remove_lock();
       $this->mimetabs= NULL;
       session::un_set('objectinfo');
     }
@@ -227,17 +260,22 @@ class mimetypeManagement extends plugin
       if (count($message) == 0){
 
         /* Save data data to ldap */
-        $this->mimetabs->set_release($this->DivListMimeTypes->selectedRelease);
         $this->mimetabs->save();
 
         if (!isset($_POST['edit_apply'])){
           /* Mime type has been saved successfully, remove lock from LDAP. */
           if ($this->dn != "new"){
-            del_lock ($this->dn);
+            $this->remove_lock();
           }
           unset ($this->mimetabs);
           $this->mimetabs= NULL;
           session::un_set('objectinfo');
+        }else{
+
+          /* Reinitialize tab */
+          if($this->mimetabs instanceof tabs){
+            $this->mimetabs->re_init();
+          }
         }
       } else {
         /* Ok. There seem to be errors regarding to the tab data,
@@ -267,9 +305,12 @@ class mimetypeManagement extends plugin
          above dialog */
       add_lock ($this->dn, $this->ui->dn);
 
-
       /* Register mimetabs to trigger edit dialog */
       $this->mimetabs= new mimetabs($this->config,$this->config->data['TABS']['MIMETABS'], $this->dn,"mimetypes");
+      if($this->IsReleaseManagementActivated()){
+        $this->mimetabs->set_FAIstate($this->mimetypes[$s_entry]['FAIstate'][0]);
+      }
+      $this->mimetabs->parent = &$this;
       $this->mimetabs->set_acl_base($this->dn);
       session::set('objectinfo',$this->dn);
     }
@@ -285,28 +326,42 @@ class mimetypeManagement extends plugin
       $this->dns = array();
       if(count($ids)){
 
+        $disallowed = array();
         foreach($ids as $id){
           $dn = $this->mimetypes[$id]['dn'];
-          if (($user= get_lock($dn)) != ""){
-            return(gen_locked_message ($user, $dn));
+          $acl = $this->ui->get_permissions($dn, "mimetypes/mimetype");
+          if(preg_match("/d/",$acl)){
+            $this->dns[$id] = $dn;
+          }else{
+            $disallowed[] = $dn;
           }
-          $this->dns[$id] = $dn;
         }
 
-        $dns_names = array();
-        foreach($this->dns as $dn){
-          add_lock ($dn, $this->ui->dn);
-          $dns_names[] = @LDAP::fix($dn);
+        if(count($disallowed)){
+          msg_dialog::display(_("Permission"),msgPool::permDelete($disallowed),INFO_DIALOG);
         }
 
-        /* Lock the current entry, so nobody will edit it during deletion */
-        $smarty->assign("info", msgPool::deleteInfo($dns_names,_("Mime type")));
-        $smarty->assign("multiple", true);
-        return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
-      }
-    }
+        if(count($this->dns)){
 
+          /* Check locks */
+          if ($user= get_multiple_locks($this->dns)){
+            return(gen_locked_message($user,$this->dns));
+          }
+
+          $dns_names = array();
+          foreach($this->dns as $dn){
+            $dns_names[] = @LDAP::fix($dn);
+          }
 
+          add_lock ($this->dns, $this->ui->dn);
+
+          /* Lock the current entry, so nobody will edit it during deletion */
+          $smarty->assign("info", msgPool::deleteInfo($dns_names,_("Mime type")));
+          $smarty->assign("multiple", true);
+          return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
+        }
+      }
+    }
 
 
     /********************
@@ -326,6 +381,7 @@ class mimetypeManagement extends plugin
 
           /* Delete request is permitted, perform LDAP action */
           $this->mimetabs= new mimetabs($this->config, $this->config->data['TABS']['MIMETABS'], $dn,"mimetypes");
+          $this->mimetabs->parent = &$this;
           $this->mimetabs->set_acl_base($dn);
           $this->mimetabs->delete ();
           unset ($this->mimetabs);
@@ -337,10 +393,11 @@ class mimetypeManagement extends plugin
           msg_dialog::display(_("Permission error"), msgPool::permDelete(), INFO_DIALOG);
           new log("security","mimetypes/".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 +407,8 @@ class mimetypeManagement extends plugin
 
     /* Remove lock */
     if(isset($_POST['delete_multiple_mimetype_cancel'])){
-      foreach($this->dns as $key => $dn){
-        del_lock ($dn);
-        unset($this->dns[$key]);
-      }
+      $this->remove_lock();
+      $this->dns = array();
     }
 
 
@@ -409,6 +464,7 @@ class mimetypeManagement extends plugin
 
         /* Delete request is permitted, perform LDAP action */
         $this->mimetabs= new mimetabs($this->config, $this->config->data['TABS']['MIMETABS'], $this->dn,"mimetypes");
+        $this->mimetabs->parent = &$this;
         $this->mimetabs->set_acl_base($this->dn);
         $this->mimetabs->delete ();
         unset ($this->mimetabs);
@@ -423,7 +479,7 @@ class mimetypeManagement extends plugin
       }
 
       /* Remove lock file after successfull deletion */
-      del_lock ($this->dn);
+      $this->remove_lock();
     }
 
 
@@ -433,7 +489,7 @@ class mimetypeManagement extends plugin
 
     /* Delete mime type canceled? */
     if (isset($_POST['delete_cancel'])){
-      del_lock ($this->dn);
+      $this->remove_lock();
       session::un_set('objectinfo');
     }
 
@@ -444,12 +500,16 @@ class mimetypeManagement extends plugin
       /* Don't show buttons if tab dialog requests this */
       if (!$this->mimetabs->by_object[$this->mimetabs->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->mimetabs->FAIstate) && !preg_match("/freeze/i",$this->mimetabs->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>";
       }
@@ -461,16 +521,22 @@ class mimetypeManagement extends plugin
       Dialog display
      ****************/
 
-        /* Check if there is a snapshot dialog open */
-    $base = $this->DivListMimeTypes->selectedBase;
-    if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
+    /* Check if there is a snapshot dialog open */
+    if($this->IsReleaseManagementActivated()){
+      $base = $this->mime_release;
+    }else{
+      $base = $this->mime_base;
+    }
+    if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases(),$this)){
       return($str);
     }
 
     /* Display dialog with system list */
     $this->DivListMimeTypes->parent = $this;
     $this->DivListMimeTypes->execute();
-    $this->DivListMimeTypes->AddDepartments($this->DivListMimeTypes->selectedBase,3,1);
+    if(!$this->IsReleaseManagementActivated()){
+      $this->DivListMimeTypes->AddDepartments($this->DivListMimeTypes->selectedBase,3,1);
+    }
     $this->reload();
     $this->DivListMimeTypes->setEntries($this->mimetypes);
     return($this->DivListMimeTypes->Draw());
@@ -480,50 +546,54 @@ class mimetypeManagement extends plugin
   /* Return departments, that will be included within snapshot detection */
   function get_used_snapshot_bases()
   {
-    return(array($this->DivListMimeTypes->selectedRelease));
+    if($this->IsReleaseManagementActivated()){
+      return(array($this->mime_release));
+    }else{
+      return(array($this->mime_base));
+    }
   }
 
 
-
   function reload()
   {
     $this->mimetypes= array();
 
     /* Set base for all searches */
-    $base       = $this->DivListMimeTypes->selectedBase;
-    $release    = $this->DivListMimeTypes->selectedRelease;
+    $base       = $this->mime_base;
     $Regex      = $this->DivListMimeTypes->Regex;
     $SubSearch  = $this->DivListMimeTypes->SubSearch; 
     $Flags      =  GL_NONE | GL_SIZELIMIT;
     $Filter     = "(&(|(cn=".$Regex.")(description=".$Regex."))(objectClass=gotoMimeType))";
     $tmp        = array();
-    $Releases   = $this->getReleases($base);
-
 
-    /* If release management is enabled, use release as base. */
-    if(!$this->enableReleaseManagement){
-      $use_base = $base;
-    }else{
-      if(isset($Releases[$release])){
-        $use_base  = $release;
-      }else{
-        $use_base  = $base;
+    if(!$this->IsReleaseManagementActivated()){
+      $use_base = $this->mime_base;
+      if($SubSearch){
+        $use_base = preg_replace("/^".normalizePreg(get_ou("mimeou"))."/","",$use_base);
       }
+    }else{
+      $use_base = $this->mime_release;
+      $SubSearch= FALSE;
+    }
+
+    /* Add FAIstate to the search attributes */
+    $search_attrs = array("cn","description","dn","objectClass");
+    if($this->IsReleaseManagementActivated()) {
+      $search_attrs[] = "FAIstate";
     }
 
-    /* In case of subsearch, add the subsearch flag */
     if($SubSearch){
-      $Flags    |= GL_SUBSEARCH;  
+      $res= get_sub_list($Filter, "mimetypes",get_ou("mimeou"), $use_base, $search_attrs, $Flags);
     }else{
-      if(!$this->enableReleaseManagement){
-        $use_base = get_ou('mimetypeou').$use_base;
-      }
+      $res= get_list($Filter, "mimetypes",$use_base, $search_attrs, $Flags);
     }
-  
-    /* Get results and create index */ 
-    $res= get_sub_list($Filter, "mimetypes",get_ou('mimetypeou'), $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'];
     }
@@ -537,6 +607,7 @@ class mimetypeManagement extends plugin
     reset ($this->mimetypes);
   }
 
+
   function remove_from_parent()
   {
     /* Optionally execute a command after we're done */
@@ -551,14 +622,20 @@ class mimetypeManagement 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();
-      $this->start_pasting_copied_objects = FALSE;
       $dn = $this->mimetypes[$s_entry]['dn'];
-      $this->CopyPasteHandler->add_to_queue($dn,$s_action,"mimetabs","MIMETABS","mimetypes");
+      if($s_action == "copy" && $ui->is_copyable($dn,"mimetypes","mimetype")){
+        $this->CopyPasteHandler->add_to_queue($dn,$s_action,"mimetabs","MIMETABS","mimetypes");
+      }
+      if($s_action == "cut" && $ui->is_cutable($dn,"mimetypes","mimetype")){ 
+        $this->CopyPasteHandler->add_to_queue($dn,$s_action,"mimetabs","MIMETABS","mimetypes");
+      }
     }
 
     /* Add entries to queue */
@@ -566,16 +643,15 @@ class mimetypeManagement extends plugin
 
       /* Cleanup object queue */
       $this->CopyPasteHandler->cleanup_queue();
-      $this->start_pasting_copied_objects = FALSE;
   
       /* Add new entries to CP queue */
       foreach($this->list_get_selected_items() as $id){
         $dn = $this->mimetypes[$id]['dn'];
 
-        if($s_action == "copy_multiple"){
+        if($s_action == "copy_multiple" && $ui->is_copyable($dn,"mimetypes","mimetype")){ 
           $this->CopyPasteHandler->add_to_queue($dn,"copy","mimetabs","MIMETABS","mimetypes");
         }
-        if($s_action == "cut_multiple"){
+        if($s_action == "cut_multiple" && $ui->is_cutable($dn,"mimetypes","mimetype")){
           $this->CopyPasteHandler->add_to_queue($dn,"cut","mimetabs","MIMETABS","mimetypes");
         }
       }
@@ -590,8 +666,9 @@ class mimetypeManagement extends plugin
     if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){
 
       /* Get dialog */
+      $this->CopyPasteHandler->SetVar("base",preg_replace("/^".normalizePreg(get_ou("mimetypeou"))."/","",$this->mime_base));
+      $this->CopyPasteHandler->SetVar("parent",$this);
       $data = $this->CopyPasteHandler->execute();
-      $this->CopyPasteHandler->SetVar("base",$this->DivListMimeTypes->selectedBase);
 
       /* Return dialog data */
       if(!empty($data)){
@@ -600,22 +677,10 @@ class mimetypeManagement extends plugin
     }
 
     /* Automatically disable status for pasting */
-    #if(!$this->CopyPasteHandler->entries_queued()){
-    #  $this->start_pasting_copied_objects = FALSE;
-    #}
-    return("");
-  }
-
-
-  /* Check if the release management is activated. */
-  function IsReleaseManagementActivated()
-  {
-    /* Check if we should enable the release selection */
-    $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs'));
-    if(!empty($tmp)){
-      return(true);
+    if(!$this->CopyPasteHandler->entries_queued()){
+      $this->start_pasting_copied_objects = FALSE;
     }
-    return(false);
+    return("");
   }
 
 
@@ -644,15 +709,39 @@ class mimetypeManagement extends plugin
     if (isset($this->mimetabs->dn)){
       del_lock ($this->mimetabs->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->DivListMimeTypes->save_object();
     if(is_object($this->CopyPasteHandler)){
       $this->CopyPasteHandler->save_object();
     }
+
+    if($this->IsReleaseManagementActivated() && isset($_POST['mime_release'])){
+      $sel_rel = get_post('mime_release');
+      $releases = array_flip($this->getReleases());
+      if(isset($releases[$sel_rel])){
+        $this->mime_release = $releases[$sel_rel];
+      }
+      $mime_filter     = session::get("mime_filter");
+      $mime_filter['mime_release'] = $this->mime_release;
+      session::set("mime_filter",$mime_filter);
+    }elseif(!$this->IsReleaseManagementActivated()){
+      $this->mime_base = get_ou("mimetypeou").$this->DivListMimeTypes->selectedBase;
+      $mime_filter     = session::get("mime_filter");
+      $mime_filter['mime_base'] = $this->mime_base;
+      session::set("mime_filter",$mime_filter);
+    }
   }
 
+
   function check() {}
   function adapt_from_template($dn, $skip= array()) {}
   function password_change_needed() {}