Code

We're html5, right?
[gosa.git] / gosa-core / include / class_management.inc
index c03e860e55c7dd92337ca4897299733ab65ffc06..66bdc4cf2b73a201e86ef9ecc36b881d2bb39540 100644 (file)
@@ -118,10 +118,12 @@ class management
     $this->registerAction("restore",     "restoreSnapshotDialog");
     $this->registerAction("saveSnapshot","saveSnapshot");
     $this->registerAction("restoreSnapshot","restoreSnapshot");
+    $this->registerAction("removeSnapshotConfirmed","removeSnapshotConfirmed");
     $this->registerAction("cancelSnapshot","closeDialogs");
 
     $this->registerAction("config-filter","editFilter");
     $this->registerAction("saveFilter","saveFilter");
+    $this->registerAction("cancelFilter","cancelFilter");
 
     // To temporay disable the filter caching UNcomment this line.
     #session::global_un_set(get_class($this)."_filter");
@@ -255,7 +257,7 @@ class management
 
       // Display ok, (apply) and cancel buttons
       $str.= "<p style=\"text-align:right\">\n";
-      $str.= "<button type=\"submit\" name=\"edit_finish\" style=\"width:80px\">".msgPool::okButton()."</button>\n";
+      $str.= "<button type=\"submit\" name=\"edit_finish\">".msgPool::okButton()."</button>\n";
       $str.= "&nbsp;\n";
       if($this->displayApplyBtn){
         $str.= "<button type=\"submit\" name=\"edit_apply\">".msgPool::applyButton()."</button>\n";
@@ -286,8 +288,12 @@ class management
     @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$target,"Entry removel requested!");
 
     // Check permissons for each target 
+    $h = $this->getHeadpage();
+    $oTypes = array_reverse($h->objectTypes);
     foreach($target as $dn){
-      $acl = $this->ui->get_permissions($dn, $this->aclCategory."/".$this->aclPlugin);
+      $entry = $h->getEntry($dn);
+      $obj   = $h->getObjectType($oTypes, $entry['objectClass']);
+      $acl = $this->ui->get_permissions($dn, $obj['category']."/".$obj['class']);
       if(preg_match("/d/",$acl)){
         $this->dns[] = $dn;
       }else{
@@ -309,7 +315,6 @@ class management
       // Add locks
       $dns_names = array();
       $types = array();
-      $h = $this->getHeadpage();
 
       // Build list of object -labels
       foreach($h->objectTypes as $type){
@@ -355,10 +360,15 @@ class management
 
     @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$target,"Entry removel confirmed!");
 
+    // Check permissons for each target 
+    $h = $this->getHeadpage();
+    $oTypes = array_reverse($h->objectTypes);
     foreach($this->dns as $key => $dn){
+      $entry = $h->getEntry($dn);
+      $obj   = $h->getObjectType($oTypes, $entry['objectClass']);
+      $acl = $this->ui->get_permissions($dn, $obj['category']."/".$obj['class']);
 
       // Check permissions, are we allowed to remove this object? 
-      $acl = $this->ui->get_permissions($dn, $aclCategory."/".$aclPlugin);
       if(preg_match("/d/",$acl)){
 
         // Delete the object
@@ -397,9 +407,10 @@ class management
     if(isset($_POST['edit_finish'])) $action['action'] = "save";    
     if(isset($_POST['edit_cancel'])) $action['action'] = "cancel";    
     if(isset($_POST['delete_confirmed'])) $action['action'] = "removeConfirmed";   
+    if(isset($_POST['delete_snapshot_confirm'])) $action['action'] = "removeSnapshotConfirmed";   
     if(isset($_POST['delete_cancel'])) $action['action'] = "cancelDelete";   
     if(isset($_POST['saveFilter'])) $action['action'] = "saveFilter";   
-    if(isset($_POST['cancelFilter'])) $action['action'] = "cancel";   
+    if(isset($_POST['cancelFilter'])) $action['action'] = "cancelFilter";   
 
     // Detect Snapshot actions
     if(isset($_POST['CreateSnapshot'])) $action['action'] = "saveSnapshot";   
@@ -408,7 +419,7 @@ class management
       $once =TRUE;
       if(preg_match("/^RestoreSnapShot_/",$name) && $once){
         $once = FALSE;
-        $entry = base64_decode(preg_replace("/^RestoreSnapShot_([^_]*)_[xy]$/i","\\1",$name));
+        $entry = base64_decode(preg_replace("/^RestoreSnapShot_(.*)$/i","\\1",$name));
         $action['action'] = "restoreSnapshot";
         $action['targets'] = array($entry);
       }
@@ -448,7 +459,7 @@ class management
         $this->dialogObject->parent = &$this;
 
       }else{
-        msg_dialog::display(_("Permission"),sprintf(_("You are not allowed to create a snapshot for %s."),$entry),
+        msg_dialog::display(_("Permission"),sprintf(_("You are not allowed to create a snapshot for %s!"), bold($entry)),
             ERROR_DIALOG);
       }
     }
@@ -495,7 +506,22 @@ class management
       @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dn,"Snaptshot restored!");
       $this->closeDialogs();
     }else{
-      msg_dialog::display(_("Permission"),sprintf(_("You are not allowed to restore a snapshot for %s."),$entry),
+      msg_dialog::display(_("Permission"),sprintf(_("You are not allowed to restore a snapshot for %s!"), bold($entry)),
+          ERROR_DIALOG);
+    }
+  }
+
+
+  /*! \brief  Removes a snapshot object.
+   */
+  function removeSnapshotConfirmed($action="",$target=array(),$all=array())
+  {
+    $entry = $this->dialogObject->del_dn;
+    if(!empty($entry) && $this->ui->allow_snapshot_create($entry,$this->aclCategory)){
+      $this->snapHandler->remove_snapshot($entry);
+      @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$entry,"Snaptshot removed!");
+    }else{
+      msg_dialog::display(_("Permission"),sprintf(_("You are not allowed to remove a snapshot for %s!"), bold($entry)),
           ERROR_DIALOG);
     }
   }
@@ -532,7 +558,7 @@ class management
         $this->dialogObject->display_restore_dialog = true;
         $this->dialogObject->parent = &$this;
       }else{
-        msg_dialog::display(_("Permission"),sprintf(_("You are not allowed to restore a snapshot for %s."),$entry),
+        msg_dialog::display(_("Permission"),sprintf(_("You are not allowed to restore a snapshot for %s!"), bold($entry)),
             ERROR_DIALOG);
       } 
     }else{
@@ -546,7 +572,7 @@ class management
         $this->dialogObject->display_restore_dialog = true;
         $this->dialogObject->parent = &$this;
       }else{
-        msg_dialog::display(_("Permission"),sprintf(_("You are not allowed to restore a snapshot for %s."),$entry),
+        msg_dialog::display(_("Permission"),sprintf(_("You are not allowed to restore a snapshot for %s!"), bold($entry)),
             ERROR_DIALOG);
       } 
     }
@@ -605,7 +631,7 @@ class management
         $this->tabObject->parent = &$this;
         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dn,"Create new entry initiated!");
       } else {
-        msg_dialog::display(_("Error"), sprintf(_("No tab declaration for '%s' found in your configuration file. Cannot create plugin instance!"), $tabType), ERROR_DIALOG);
+        msg_dialog::display(_("Error"), sprintf(_("No tab definition for %s found in configuration file: cannot create plugin instance!"), bold($tabType)), ERROR_DIALOG);
       }
     }
   }
@@ -664,7 +690,7 @@ class management
       set_object_info($this->dn);
       $user = get_lock($this->dn);
       if ($user != ""){
-        return(gen_locked_message ($user, $this->dn,TRUE));
+        return(gen_locked_message ($user, array($this->dn),TRUE));
       }
       add_lock ($this->dn, $this->ui->dn);
 
@@ -711,6 +737,17 @@ class management
   }
 
 
+  /*! \brief  Close filter dialog
+   */
+  protected function cancelFilter()
+  {
+      if($this->dialogObject instanceOf userFilter){
+          $this->remove_lock();
+          $this->closeDialogs();
+      }
+  }
+
+
   /*! \brief  Save filter modifcations.
    */
   protected function saveFilter()
@@ -913,55 +950,13 @@ class management
 
 
   function postcreate() {
-    $this->_handlePostEvent('POSTCREATE');
+    $this->handle_post_events('create');
   }
   function postmodify(){
-    $this->_handlePostEvent('POSTMODIFY');
+    $this->handle_post_events('modify');
   }
   function postremove(){
-    $this->_handlePostEvent('POSTREMOVE');
-  }
-
-  function _handlePostEvent($type)
-  {
-
-    /* Find postcreate entries for this class */
-    $command= $this->config->search(get_class($this), $type,array('menu', 'tabs'));
-    if ($command != ""){
-
-      /* Walk through attribute list */
-      foreach ($this->attributes as $attr){
-        if (!is_array($this->$attr)){
-          $add_attrs[$attr] = $this->$attr;
-        }
-      }
-      $add_attrs['dn']=$this->dn;
-
-      $tmp = array();
-      foreach($add_attrs as $name => $value){
-        $tmp[$name] =  strlen($name);
-      }
-      arsort($tmp);
-
-      /* Additional attributes */
-      foreach ($tmp as $name => $len){
-        $value = $add_attrs[$name];
-        $command= str_replace("%$name", "$value", $command);
-      }
-
-      if (check_command($command)){
-        @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
-            $command, "Execute");
-        exec($command,$arr);
-        foreach($arr as $str){
-          @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
-              $command, "Result: ".$str);
-        }
-      } else {
-        $message= msgPool::cmdnotfound($type, get_class($this));
-        msg_dialog::display(_("Error"), $message, ERROR_DIALOG);
-      }
-    }
+    $this->handle_post_events('remove');
   }
 
   function is_modal_dialog()
@@ -976,7 +971,7 @@ class management
   function handle_post_events($mode, $addAttrs= array())
   {
     if(!in_array($mode, array('add','remove','modify'))){
-      trigger_error(sprintf("Invalid post event type given '%s'! Valid types are [add,modify,remove].", $mode));
+      trigger_error(sprintf("Invalid post event type given %s! Valid types are [add,modify,remove].", bold($mode)));
       return;
     }
     switch ($mode){