Code

Updated server service.
[gosa.git] / plugins / admin / mimetypes / class_mimetypeGeneric.inc
index f4bb14f11d0380202b8102115a764c538ba8221a..e7585c90b44a1c5551795b8774f10673367c4637 100644 (file)
@@ -47,6 +47,8 @@ class mimetype extends plugin
   var $CopyPasteVars        = array("use_gotoMimeFilePattern","use_gotoMimeApplication","use_gotoMimeEmbeddedApplication","iconData",
                                     "gotoMimeLeftClickAction_I","gotoMimeLeftClickAction_E","gotoMimeLeftClickAction_Q","use_gotoMimeIcon");
 
+  var $view_logged  = FALSE;
+
   /* Select options */
   var $MimeGroups                            = array("application","audio","chemical","image","inode","message","model",
                                       "multipart","text","video","x-conference","x-world");
@@ -148,25 +150,22 @@ class mimetype extends plugin
   {
     $smarty = get_smarty();
 
+    if(!$this->view_logged){
+      $this->view_logged =TRUE;
+      new log("view","mimetypes/".get_class($this),$this->dn);
+    }
+
     $tmp = $this->plInfo();
     foreach($tmp['plProvidedAcls'] as $name => $translation){
       $smarty->assign($name."ACL",$this->getacl($name));
     }
 
-    /* Assign base ACL */
-    $baseACL = $this->getacl("base");
-    if(!$this->acl_is_moveable()) {
-      $baseACL = preg_replace("/w/","",$baseACL);
-    }
-    $smarty->assign("baseACL",          $baseACL);
-
     /* Base select dialog */
     $once = true;
     foreach($_POST as $name => $value){
       if(preg_match("/^chooseBase/",$name) && $once){
         $once = false;
         $this->dialog = new baseSelectDialog($this->config,$this,$this->get_allowed_bases());
-        echo $this->base;
         $this->dialog->setCurrentBase($this->base);
       }
     }
@@ -180,7 +179,13 @@ class mimetype extends plugin
       if($this->dialog->isClosed()){
         $this->dialog = false;
       }elseif($this->dialog->isSelected()){
-        $this->base = $this->dialog->isSelected();
+
+        /* A new base was selected, check if it is a valid one */
+        $tmp = $this->get_allowed_bases();
+        if(isset($tmp[$this->dialog->isSelected()])){
+          $this->base = $this->dialog->isSelected();
+        }
+
         $this->dialog= false;
       }else{
         return($this->dialog->execute());
@@ -348,13 +353,25 @@ class mimetype extends plugin
   function save_object()
   {
     if(isset($_POST['MimeGeneric'])){
+
+      /* Create a base backup and reset the
+         base directly after calling plugin::save_object();
+         Base will be set seperatly a few lines below */
+      $base_tmp = $this->base;
       plugin::save_object();
+      $this->base = $base_tmp;
   
       /* Only save base if we are not in release mode */
       if(!$this->isReleaseMimeType){
+
+        /* Set new base if allowed */
+        $tmp = $this->get_allowed_bases();
         if(isset($_POST['base'])){
-          $this->base = $_POST['base'];
+          if(isset($tmp[$_POST['base']])){
+            $this->base= $_POST['base'];
+          }
         }
+
       }
 
       /* Save radio buttons */
@@ -443,10 +460,12 @@ class mimetype extends plugin
       $ldap->cd($this->dn);
       $this->cleanup();
       $ldap->modify($this->attrs);
+      new log("modify","mimetypes/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
     }else{
       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
       $ldap->cd($this->dn);
       $ldap->add($this->attrs);
+      new log("create","mimetypes/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
     }
     show_ldap_error($ldap->get_error(), sprintf(_("Saving of mime type/generic with dn '%s' failed."),$this->dn));
   }
@@ -455,9 +474,11 @@ class mimetype extends plugin
   /* Remove current mime type */
   function remove_from_parent()
   {
+    plugin::remove_from_parent();
     $ldap = $this->config->get_ldap_link();
     $ldap->rmDir($this->dn);
     show_ldap_error($ldap->get_error(), sprintf(_("Removing of mime type/generic with dn '%s' failed."),$this->dn));
+    new log("remove","mimetypes/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
 
     /* Optionally execute a command after we're done */
     $this->handle_post_events("remove");
@@ -508,22 +529,6 @@ class mimetype extends plugin
       }
     }
 
-    /* Check permissions for that base? */
-    if ($this->base != ""){
-      $new_dn= "cn=".$this->cn.",ou=mime,".$this->base;
-    } else {
-      $new_dn= $this->dn;
-    }
-
-    /* Set new acl base */
-    if($this->dn == "new") {
-      $this->set_acl_base($new_dn);
-    }
-
-    if (!$this->acl_is_createable() && $this->dn == "new"){
-      $message[]= _("You have no permissions to create a mime type on this 'Base'.");
-    }
-
     return($message);
   }
 
@@ -699,8 +704,23 @@ class mimetype extends plugin
   function PrepareForCopyPaste($source)
   {
     plugin::PrepareForCopyPaste($source);
-    $this->gotoMimeIcon       = $this->iconData;
-    $this->use_gotoMimeIcon   = $source->use_gotoMimeIcon;
+
+    $source_o = new mimetype($this->config,$source['dn'],$this->parent);
+
+    foreach(array("gotoMimeLeftClickAction_Q","gotoMimeEmbeddedApplication","gotoMimeApplication","gotoMimeFilePattern","gotoMimeIcon","iconData") as $name){
+      $use_attr     = "use_".$name;
+      if(isset($this->$use_attr)){
+        $this->$use_attr= $source_o->$use_attr;
+      }
+      $this->$name = $source_o->$name;
+    } 
+    foreach($this->attributes as $name){
+      $this->$name = $source_o->$name;
+    }
+
+    if($this->iconData){
+      $this->use_gotoMimeIcon ="Not emtpy, causes icon to be written.";
+    }
   }
 }
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: