Code

Updated server service.
[gosa.git] / plugins / admin / mimetypes / class_mimetypeManagement.inc
index a4da4d430fb733be84339de8230e682380f997b0..598027771eacd501d0bf3f50db3682a36a20d28e 100755 (executable)
@@ -32,8 +32,9 @@ class mimetypeManagement extends plugin
   var $enableReleaseManagement        = false;
   var $mimetabs                       = NULL;
   var $snapDialog                     = NULL;
-  var $acl                            = NULL;
   var $CopyPasteHandler               = NULL;
+  var $start_pasting_copied_objects = FALSE;
+
 
   function mimetypeManagement ($config, $ui)
   {
@@ -58,9 +59,6 @@ class mimetypeManagement extends plugin
       $this->DivListMimeTypes->DisableCheckBox("SubSearch");
     }
 
-    /* Get acls */
-    $acl= get_permissions ($ui->dn, $ui->subtreeACL);
-    $this->acl= get_module_permission($acl, "mimetype", $ui->dn);
   }
 
 
@@ -104,7 +102,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['LOCK_VARS_TO_USE'] = array("/^act$/","/^id$/","/^mime_edit_/","/^mime_del_/");
+    $_SESSION['LOCK_VARS_TO_USE'] = array("/^act$/","/^id$/","/^mime_edit_/","/^mime_del_/","/^item_selected/","/^remove_multiple_mimetypes/");
 
     $smarty       = get_smarty();             // Smarty instance
     $s_action     = "";                       // Contains the action to proceed
@@ -131,8 +129,14 @@ class mimetypeManagement extends plugin
         // Post for new
       }elseif(preg_match("/^mime_new.*/",$key)){
         $s_action="new";
+      }elseif(preg_match("/^remove_multiple_mimetypes/",$key)){
+        $s_action="del_multiple";
       }elseif(preg_match("/^editPaste.*/i",$key)){
         $s_action="editPaste";
+      }elseif(preg_match("/^multiple_copy_mimetypes/",$key)){
+        $s_action = "copy_multiple";
+      }elseif(preg_match("/^multiple_cut_mimetypes/",$key)){
+        $s_action = "cut_multiple";
       }
     }
 
@@ -148,12 +152,10 @@ class mimetypeManagement extends plugin
       Copy & Paste handling  
      ****************/
 
-    /* Only perform copy / paste if it is enabled 
-     */
-    if($this->CopyPasteHandler){
-      if($str = $this->copyPasteHandling($s_action,$s_entry)){
-       return($str);
-      };
+    /* Display the copy & paste dialog, if it is currently open */
+    $ret = $this->copyPasteHandling_from_queue($s_action,$s_entry);
+    if($ret){
+      return($ret);
     }
 
 
@@ -162,19 +164,18 @@ class mimetypeManagement extends plugin
      ****************/
 
     /* New mime type? */
-    if ($s_action=="new"){
+    $ui = get_userinfo();
+    $acl = $ui->get_permissions($this->DivListMimeTypes->selectedBase,"mimetypes/mimetype");
+    if (($s_action=="new") && preg_match("/c/",$acl)){
 
       /* By default we set 'dn' to 'new', all relevant plugins will
          react on this. */
       $this->dn= "new";
 
       /* Create new usertab object */
-      $this->mimetabs= new mimetabs($this->config, $this->config->data['TABS']['MIMETABS'], $this->dn);
-
-      /* set acl */
-      $acl= get_permissions ($this->DivListMimeTypes->selectedBase, $this->ui->subtreeACL);
-      $this->mimetabs->set_acl($acl);
-    }
+      $this->mimetabs= new mimetabs($this->config, $this->config->data['TABS']['MIMETABS'], $this->dn,"mimetypes");
+      $this->mimetabs->set_acl_base($this->DivListMimeTypes->selectedBase);
+    }   
 
 
     /**************** 
@@ -182,7 +183,7 @@ class mimetypeManagement extends plugin
      ****************/
 
     /* Cancel dialogs */
-    if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel'])){
+    if (isset($_POST['edit_cancel'])){
       del_lock ($this->mimetabs->dn);
       unset ($this->mimetabs);
       $this->mimetabs= NULL;
@@ -208,7 +209,6 @@ class mimetypeManagement extends plugin
         /* Save data data to ldap */
         $this->mimetabs->set_release($this->DivListMimeTypes->selectedRelease);
         $this->mimetabs->save();
-        gosa_log ("Mime object'".$this->dn."' has been saved");
 
         if (!isset($_POST['edit_apply'])){
           /* Mime type has been saved successfully, remove lock from LDAP. */
@@ -249,15 +249,98 @@ class mimetypeManagement extends plugin
 
 
       /* Register mimetabs to trigger edit dialog */
-      $this->mimetabs= new mimetabs($this->config,$this->config->data['TABS']['MIMETABS'], $this->dn);
-
-      /* Set up the users ACL's for this 'dn' */
-      $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
-      $this->mimetabs->set_acl($acl);
+      $this->mimetabs= new mimetabs($this->config,$this->config->data['TABS']['MIMETABS'], $this->dn,"mimetypes");
+      $this->mimetabs->set_acl_base($this->dn);
       $_SESSION['objectinfo']= $this->dn;
     }
 
 
+    /********************
+      Delete MULTIPLE entries requested, display confirm dialog
+     ********************/
+
+    if ($s_action=="del_multiple"){
+      $ids = $this->list_get_selected_items();
+
+      if(count($ids)){
+
+        foreach($ids as $id){
+          $dn = $this->mimetypes[$id]['dn'];
+          if (($user= get_lock($dn)) != ""){
+            return(gen_locked_message ($user, $dn));
+          }
+          $this->dns[$id] = $dn;
+        }
+
+        $dns_names = "<br><pre>";
+        foreach($this->dns as $dn){
+          add_lock ($dn, $this->ui->dn);
+          $dns_names .= $dn."\n";
+        }
+        $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)));
+        }
+        $smarty->assign("multiple", true);
+        return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
+      }
+    }
+
+
+
+
+    /********************
+      Delete MULTIPLE entries confirmed
+     ********************/
+
+    /* Confirmation for deletion has been passed. Users should be deleted. */
+    if (isset($_POST['delete_multiple_mimetype_confirm'])){
+
+      $ui = get_userinfo();
+
+      /* Remove user by user and check acls before removeing them */
+      foreach($this->dns as $key => $dn){
+
+        $acl = $ui->get_permissions($dn,"mimetypes/mimetype");
+        if(preg_match("/d/",$acl)){
+
+          /* Delete request is permitted, perform LDAP action */
+          $this->mimetabs= new mimetabs($this->config, $this->config->data['TABS']['MIMETABS'], $dn,"mimetypes");
+          $this->mimetabs->set_acl_base($dn);
+          $this->mimetabs->delete ();
+          unset ($this->mimetabs);
+          $this->mimetabs= NULL;
+
+        } else {
+          /* Normally this shouldn't be reached, send some extra
+             logs to notify the administrator */
+          print_red (_("You are not allowed to delete this mime type!"));
+          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]);
+      }
+    }
+
+
+    /********************
+      Delete MULTIPLE entries Canceled
+     ********************/
+
+    /* Remove lock */
+    if(isset($_POST['delete_multiple_mimetype_cancel'])){
+      foreach($this->dns as $key => $dn){
+        del_lock ($dn);
+        unset($this->dns[$key]);
+      }
+    }
+
+
     /**************** 
       Delete mime type 
      ****************/
@@ -270,7 +353,9 @@ class mimetypeManagement extends plugin
 
       /* Load permissions for selected 'dn' and check if
          we're allowed to remove this 'dn' */
-      if (chkacl($this->acl, "delete") == ""){
+      $ui = get_userinfo();
+      $acl = $ui->get_permissions($this->dn,"mimetypes/mimetype");
+      if (preg_match("/d/",$acl)){
 
         /* Check locking, save current plugin in 'back_plugin', so
            the dialog knows where to return. */
@@ -282,6 +367,7 @@ class mimetypeManagement extends plugin
         add_lock ($this->dn, $this->ui->dn);
         $smarty= get_smarty();
         $smarty->assign("intro", sprintf(_("You're about to delete the mime type '%s'."), @LDAP::fix($this->dn)));
+        $smarty->assign("multiple", false);
         return($smarty->fetch (get_template_path('remove.tpl', TRUE)));
       } else {
 
@@ -301,14 +387,14 @@ class mimetypeManagement extends plugin
 
       /* Some nice guy may send this as POST, so we've to check
          for the permissions again. */
-      if (chkacl($this->acl, "delete") == ""){
+      $ui = get_userinfo();
+      $acl = $ui->get_permissions($this->dn,"mimetypes/mimetype");
+      if(preg_match("/d/",$acl)){
 
         /* Delete request is permitted, perform LDAP action */
-        $this->mimetabs= new mimetabs($this->config, $this->config->data['TABS']['MIMETABS'], $this->dn);
-        $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
-        $this->mimetabs->set_acl($acl);
+        $this->mimetabs= new mimetabs($this->config, $this->config->data['TABS']['MIMETABS'], $this->dn,"mimetypes");
+        $this->mimetabs->set_acl_base($this->dn);
         $this->mimetabs->delete ();
-        gosa_log ("Mime type object'".$this->dn."' has been removed");
         unset ($this->mimetabs);
         $this->mimetabs= NULL;
 
@@ -317,7 +403,7 @@ class mimetypeManagement 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 mime type!"));
-        gosa_log ("Warning: '".$this->ui->uid."' tried to trick group deletion.");
+        new log("security","mimetypes/".get_class($this),$dn,array(),"Tried to trick deletion.");
       }
 
       /* Remove lock file after successfull deletion */
@@ -368,7 +454,7 @@ class mimetypeManagement extends plugin
     /* Display dialog with system list */
     $this->DivListMimeTypes->parent = $this;
     $this->DivListMimeTypes->execute();
-    $this->DivListMimeTypes->AddDepartments($this->DivListMimeTypes->selectedBase);
+    $this->DivListMimeTypes->AddDepartments($this->DivListMimeTypes->selectedBase,3,1);
     $this->reload();
     $this->DivListMimeTypes->setEntries($this->mimetypes);
     return($this->DivListMimeTypes->Draw());
@@ -412,12 +498,16 @@ class mimetypeManagement extends plugin
     /* In case of subsearch, add the subsearch flag */
     if($SubSearch){
       $Flags    |= GL_SUBSEARCH;  
+    }else{
+      if(!$this->enableReleaseManagement){
+        $use_base ="ou=mime,".$use_base;
+      }
     }
   
     /* Get results and create index */ 
     $res= get_list($Filter, "mimetypes", $use_base, array("cn","description","dn","objectClass"), $Flags);
     foreach ($res as $val){
-      $tmp[strtolower($val['cn'][0]).$val['cn'][0]]=$val;
+      $tmp[strtolower($val['cn'][0]).$val['cn'][0].$val['dn']]=$val;
     }
 
     /* sort entries */
@@ -436,39 +526,70 @@ class mimetypeManagement extends plugin
   }
 
 
-  function copyPasteHandling($s_action,$s_entry)
+  function copyPasteHandling_from_queue($s_action,$s_entry)
   {
-    /* Paste copied/cutted object in here
-     */
-    if(($s_action == "editPaste") || ($this->CopyPasteHandler->stillOpen())){
-      $this->CopyPasteHandler->save_object();
-      $this->CopyPasteHandler->SetVar("base", $this->DivListMimeTypes->selectedBase);
-
-      if($str = $this->CopyPasteHandler->execute()) {
-        return($str);
-      }
+    /* Check if Copy & Paste is disabled */
+    if(!is_object($this->CopyPasteHandler)){
+      return("");
     }
 
-    /* Copy current object to CopyHandler
-     */
-    if($s_action == "copy"){
-      $this->CopyPasteHandler->Clear();
+    /* 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'];
-      $obj    = new mimetabs($this->config, $this->config->data['TABS']['MIMETABS'], $dn);
-      $objNew = new mimetabs($this->config, $this->config->data['TABS']['MIMETABS'], "new");
-      $this->CopyPasteHandler->Copy($obj,$objNew);
+      $this->CopyPasteHandler->add_to_queue($dn,$s_action,"mimetabs","MIMETABS","mimetypes");
     }
 
-    /* Copy current object to CopyHandler
-     */
-    if($s_action == "cut"){
-      $this->CopyPasteHandler->Clear();
-      $dn = $this->mimetypes[$s_entry]['dn'];
-      $obj = new mimetabs($this->config, $this->config->data['TABS']['MIMETABS'], $dn);
-      $this->CopyPasteHandler->Cut($obj);
+    /* Add entries to queue */
+    if($s_action == "copy_multiple" || $s_action == "cut_multiple"){
+
+      /* Cleanup object queue */
+      $this->CopyPasteHandler->cleanup_queue();
+
+      /* Add new entries to CP queue */
+      foreach($this->list_get_selected_items() as $id){
+        $dn = $this->mimetypes[$id]['dn'];
+
+        if($s_action == "copy_multiple"){
+          $this->CopyPasteHandler->add_to_queue($dn,"copy","mimetabs","MIMETABS","mimetypes");
+        }
+        if($s_action == "cut_multiple"){
+          $this->CopyPasteHandler->add_to_queue($dn,"cut","mimetabs","MIMETABS","mimetypes");
+        }
+      }
     }
+
+    /* Start pasting entries */
+    if($s_action == "editPaste"){
+      $this->start_pasting_copied_objects = TRUE;
+    }
+
+    /* Return C&P dialog */
+    if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){
+
+      /* Load entry from queue and set base */
+      $this->CopyPasteHandler->load_entry_from_queue();
+      $this->CopyPasteHandler->SetVar("base",$this->DivListMimeTypes->selectedBase);
+
+      /* Get dialog */
+      $data = $this->CopyPasteHandler->execute();
+
+      /* Return dialog data */
+      if(!empty($data)){
+        return($data);
+      }
+    }
+
+    /* 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()
   {
@@ -480,6 +601,20 @@ class mimetypeManagement extends plugin
     return(false);
   }
 
+
+  function list_get_selected_items()
+  {
+    $ids = array();
+    foreach($_POST as $name => $value){
+      if(preg_match("/^item_selected_[0-9]*$/",$name)){
+        $id   = preg_replace("/^item_selected_/","",$name);
+        $ids[$id] = $id;
+      }
+    }
+    return($ids);
+  }
+
+
   /* Save to LDAP */
   function save()
   {