Code

Removed pass-by-reference
[gosa.git] / gosa-plugins / goto / admin / mimetypes / class_mimetypeGeneric.inc
index 03867ebab5497458f99500b8ca130b91de98329f..c5d52cf27d5a8d639de01f0ab5153e2b6d4d2414 100644 (file)
@@ -1,11 +1,7 @@
 <?php
 class mimetype extends plugin
 {
-       /* CLI vars */
-       var $cli_summary                  = "This tab allows you to modify, add or remove mime types in the selected department.";
-       var $cli_description    = "Management dialog to handle mime types";
        var $ignore_account     = true; // This is always a valid account
-       var $cli_parameters             = array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
        var $objectclasses              = array("top","gotoMimeType");
        var $attributes                   = array("cn","gotoMimeApplication","gotoMimeLeftClickAction","gotoMimeIcon",
                                                                        "description","gotoMimeFilePattern","gotoMimeEmbeddedApplication",
@@ -41,9 +37,6 @@ class mimetype extends plugin
   var $DivApps                                                             = NULL;
   var $DivEApps                                                                    = NULL;
 
-  /* Mime type release mode */
-  var $isReleaseMimeType                                             = false;
-
   /* These vars will be copied too, if you use copy&paste mode */
   var $CopyPasteVars        = array("use_gotoMimeFilePattern","use_gotoMimeApplication","use_gotoMimeEmbeddedApplication","iconData",
                                     "gotoMimeLeftClickAction_I","gotoMimeLeftClickAction_E","gotoMimeLeftClickAction_Q","use_gotoMimeIcon");
@@ -124,12 +117,6 @@ class mimetype extends plugin
       }
     }
 
-    /* Check if release Management is enabled */
-    $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs'));
-    if(!empty($tmp)) {
-      $this->isReleaseMimeType= true;
-    }
-
     /* Set base */     
     if ($this->dn == "new"){
       if(session::is_set('CurrentMainBase')){
@@ -303,25 +290,25 @@ class mimetype extends plugin
 
 
     if($this->acl_is_writeable("gotoMimeFilePattern")){
-      $Pattern_Actions= " <input type='image' src='images/sort_up.png'         class='center'  name='Pattern_SortUp_%s' >&nbsp;
-      <input type='image' src='images/sort_down.png'   class='center'  name='Pattern_SortDown_%s'>&nbsp;
-      <input type='image' src='images/edittrash.png'   class='center'  name='Pattern_Remove_%s'>";
+      $Pattern_Actions= " <input type='image' src='images/lists/sort-up.png'   class='center'  name='Pattern_SortUp_%s' >&nbsp;
+      <input type='image' src='images/lists/sort-down.png'     class='center'  name='Pattern_SortDown_%s'>&nbsp;
+      <input type='image' src='images/lists/trash.png' class='center'  name='Pattern_Remove_%s'>";
     }else{
       $Pattern_Actions= "";    
     }
 
     if($this->acl_is_writeable("gotoMimeApplication")){
-      $Apps_Actions    = " <input type='image' src='images/sort_up.png'        class='center'  name='Apps_SortUp_%s' >&nbsp;
-      <input type='image' src='images/sort_down.png'   class='center'  name='Apps_SortDown_%s'>&nbsp;
-      <input type='image' src='images/edittrash.png'   class='center'  name='Apps_Remove_%s'>";
+      $Apps_Actions    = " <input type='image' src='images/lists/sort-up.png'  class='center'  name='Apps_SortUp_%s' >&nbsp;
+      <input type='image' src='images/lists/sort-down.png'     class='center'  name='Apps_SortDown_%s'>&nbsp;
+      <input type='image' src='images/lists/trash.png' class='center'  name='Apps_Remove_%s'>";
     }else{
       $Apps_Actions= "";       
     }
 
     if($this->acl_is_writeable("gotoMimeEmbeddedApplication")){
-      $EApps_Actions   = " <input type='image' src='images/sort_up.png'        class='center'  name='EApps_SortUp_%s' >&nbsp;
-      <input type='image' src='images/sort_down.png'   class='center'  name='EApps_SortDown_%s'>&nbsp;
-      <input type='image' src='images/edittrash.png'   class='center'  name='EApps_Remove_%s'>";
+      $EApps_Actions   = " <input type='image' src='images/lists/sort-up.png'  class='center'  name='EApps_SortUp_%s' >&nbsp;
+      <input type='image' src='images/lists/sort-down.png'     class='center'  name='EApps_SortDown_%s'>&nbsp;
+      <input type='image' src='images/lists/trash.png' class='center'  name='EApps_Remove_%s'>";
     }else{
       $EApps_Actions= "";      
     }
@@ -354,7 +341,7 @@ class mimetype extends plugin
     }                  
     $smarty->assign("bases",                                           $this->get_allowed_bases());            
     $smarty->assign("base_select",                                     $this->base);           
-    $smarty->assign("isReleaseMimeType",                       $this->isReleaseMimeType);
+    $smarty->assign("isReleaseMimeType",                       $this->is_release());
     $smarty->assign("gotoMimeFilePatterns",                    $DivPatterns->DrawList());
     $smarty->assign("gotoMimeApplications",                    $DivApps->DrawList());
     $smarty->assign("gotoMimeEmbeddedApplications",    $DivEApps->DrawList());
@@ -390,7 +377,7 @@ class mimetype extends plugin
       $this->base = $base_tmp;
   
       /* Only save base if we are not in release mode */
-      if(!$this->isReleaseMimeType){
+      if(!$this->is_release()){
 
         /* Set new base if allowed */
         $tmp = $this->get_allowed_bases();
@@ -495,7 +482,9 @@ class mimetype extends plugin
       $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));
+    if (!$ldap->success()){
+      msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
+    }
   }
 
 
@@ -505,7 +494,9 @@ class mimetype extends plugin
     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));
+    if (!$ldap->success()){
+      msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_DEL, get_class()));
+    }
     new log("remove","mimetypes/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
 
     /* Optionally execute a command after we're done */
@@ -518,7 +509,9 @@ class mimetype extends plugin
       $og= new ogroup($this->config, $ldap->getDN());
       unset($og->member[$this->dn]);
       $og->save ();
-      show_ldap_error($ldap->get_error(), sprintf(_("Removing mime type from objectgroup '%s' failed"), $og->dn));
+      if (!$ldap->success()){
+        msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $og->dn, 0, get_class()));
+      }
     }
   }
 
@@ -528,41 +521,33 @@ class mimetype extends plugin
   {
     $message = plugin::check();
     if(empty($this->cn)){
-      $message[] = _("Please specify a valid name for this mime type.");
+      $message[] = msgPool::required(_("Name"));
     }
     if(!count($this->use_gotoMimeFilePattern)){
-      $message[] = _("Please specify at least one file pattern.") ;
+      $message[] = msgPool::required(_("File pattern"));
     }
 
     /* Check if there is already a mime type with this cn */
     $ldap = $this->config->get_ldap_link();
     $ldap->cd($this->config->current["BASE"]);
 
-    $mimefilter = session::get('mimefilter');
-  
-    if($this->isReleaseMimeType && (isset($mimefilter['release']))){
-      $baseDn = str_replace($this->config->current['BASE'],$this->base,$mimefilter['release']);
-      $baseDn = preg_replace("/".get_ou('mimetypeou').".*/",get_ou('mimetypeou').$this->base,$mimefilter['release']);
-      $ldap->ls("(&(objectClass=gotoMimeType)(cn=".$this->cn."))",$baseDn,array("cn"));
-      if($ldap->count()){
-        $attrs = $ldap->fetch();
-        if($this->dn != $attrs['dn']) {
-          $message[]= _("There's already a mime type with this 'Name'.");
-        }
-      }
+    if($this->is_release()){
+      $base = $this->parent->parent->mime_release;
     }else{
-      $ldap->ls("(&(objectClass=gotoMimeType)(cn=".$this->cn."))",get_ou('mimetypeou').$this->base,array("cn"));
-      if ($ldap->count()){
-        $attrs = $ldap->fetch();
-        if($this->dn != $attrs['dn']) {
-          $message[]= _("There's already an mime with this 'Name'.");
-        }
-      }
+      $base = get_ou("mimetypeou").$this->base;
     }
 
+    $ldap->ls("(&(objectClass=gotoMimeType)(cn=".$this->cn."))",$base,array("cn"));
+    if($ldap->count()){
+      $attrs = $ldap->fetch();
+      if($this->dn != $attrs['dn']) {
+        $message[]= msgPool::duplicated("cn");
+      }
+    }
     return($message);
   }
 
+
   /** Helper functions **/
 
   /* Set a new picture */      
@@ -732,6 +717,22 @@ class mimetype extends plugin
 
   }
 
+
+  function is_release()
+  {
+    if(is_object($this->parent->parent)){
+      return($this->parent->parent->IsReleaseManagementActivated());
+    }else{
+      /* 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 PrepareForCopyPaste($source)
   {
     plugin::PrepareForCopyPaste($source);