Code

Migration to get_value
[gosa.git] / gosa-plugins / goto / admin / mimetypes / class_mimetypeManagement.inc
index fc6f056068617fce33bad440ecf1db9657b5f94e..5bbe95dea17fb7f48876fd2d10896b5650942ea6 100644 (file)
@@ -23,6 +23,7 @@ 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;
@@ -36,6 +37,7 @@ class mimetypeManagement extends plugin
   var $mime_base    = "";
   var $mime_release = "";
 
+  var $acl_module = array("mimetypes");
 
   function IsReleaseManagementActivated()
   {
@@ -55,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);
     }
 
@@ -132,7 +134,7 @@ 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/"));
+          "/^item_selected/","/^remove_multiple_mimetypes/","/^menu_action/"));
 
     $smarty       = get_smarty();             // Smarty instance
     $s_action     = "";                       // Contains the action to proceed
@@ -236,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');
     }
@@ -264,11 +265,17 @@ class mimetypeManagement extends plugin
         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,
@@ -300,6 +307,9 @@ class mimetypeManagement extends plugin
 
       /* 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);
@@ -316,24 +326,40 @@ 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("intro", 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)));
+        }
       }
     }
 
@@ -367,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();
     }
 
 
@@ -380,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();
     }
 
 
@@ -454,7 +479,7 @@ class mimetypeManagement extends plugin
       }
 
       /* Remove lock file after successfull deletion */
-      del_lock ($this->dn);
+      $this->remove_lock();
     }
 
 
@@ -464,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');
     }
 
@@ -475,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>";
       }
@@ -498,7 +527,7 @@ class mimetypeManagement extends plugin
     }else{
       $base = $this->mime_base;
     }
-    if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
+    if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases(),$this)){
       return($str);
     }
 
@@ -547,15 +576,24 @@ class mimetypeManagement extends plugin
       $SubSearch= FALSE;
     }
 
+    /* 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, "mimetypes",get_ou("mimeou"), $use_base, array("cn","description","dn","objectClass"), $Flags);
+      $res= get_sub_list($Filter, "mimetypes",get_ou("mimeou"), $use_base, $search_attrs, $Flags);
     }else{
-      $res= get_list($Filter, "mimetypes",$use_base, array("cn","description","dn","objectClass"), $Flags);
+      $res= get_list($Filter, "mimetypes",$use_base, $search_attrs, $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'];
     }
@@ -584,16 +622,22 @@ 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();
       $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 */
     if($s_action == "copy_multiple" || $s_action == "cut_multiple"){
 
@@ -604,10 +648,10 @@ class mimetypeManagement extends plugin
       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");
         }
       }
@@ -665,6 +709,12 @@ 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()