Code

Mimetype department remove - Not finished yet
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 15 Apr 2008 14:01:38 +0000 (14:01 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 15 Apr 2008 14:01:38 +0000 (14:01 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@10479 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-plugins/goto/admin/mimetypes/class_divListMimeTypes.inc
gosa-plugins/goto/admin/mimetypes/class_mimetypeManagement.inc
gosa-plugins/goto/admin/mimetypes/release_select.tpl
gosa-plugins/goto/admin/mimetypes/tabs_mimetypes.inc

index 4ea92dc08fb37567055ecc17c4731dde131e3fe7..c9ab0cc0cdb475c3f9298906e5025a7fab06d351 100644 (file)
@@ -4,8 +4,6 @@ class divListMimeTypes extends MultiSelectWindow
 {
   /* Current base */
   var $selectedBase       = "";
-  var $selectedRelease    = "main";
-  var $AvailableReleases  = array();
   var $departments        = array();
   var $parent               ;
   var $ui                   ;
@@ -16,20 +14,14 @@ class divListMimeTypes extends MultiSelectWindow
   /* Subsearch checkbox */
   var $SubSearch;
 
-  /* These vars should be saved too */
-  var $SaveAdditionalVars = array("selectedRelease");
-
-
   function divListMimeTypes (&$config, &$parent)
   {
     /* Create divlist and setup */
     MultiSelectWindow::MultiSelectWindow($config, "Mimetypes", "mimetypes");
   
     /* initialize required attributes */ 
-    $this->selectedRelease  = get_ou('mimetypeou').session::get('CurrentMainBase');
     $this->parent           = &$parent;
     $this->ui               = get_userinfo();
-    $this->AvailableReleases= $this->parent->getReleases($this->selectedBase);
 
     /* Set list strings */
     $this->SetTitle       (_("List of defined mime types"));
@@ -67,16 +59,17 @@ class divListMimeTypes extends MultiSelectWindow
   }
 
 
-  /* This function allows us to add a user defined filter part at position $position*/
   function AddUserBoxToFilter($position)
   {
     $str = "";
     if(($position  == 2) && ($this->parent->IsReleaseManagementActivated($this->config))){
       $smarty = get_smarty();
-      $smarty->assign("selectedRelease",$this->selectedRelease);
+      $releases = $this->parent->getReleases();
+      $smarty->assign("mime_release" , $releases[$this->parent->mime_release]);
+      $smarty->assign("mime_base"    , $releases[$this->parent->mime_base]);
       $smarty->assign("branchimage","images/branch.png");
-      $smarty->assign("releases",$this->AvailableReleases);
-      $str = $smarty->fetch(get_template_path('release_select.tpl', TRUE,dirname(__FILE__)));
+      $smarty->assign("mime_releases", $releases);
+      $str = $smarty->fetch(get_template_path('release_select.tpl', TRUE));
     }
     return($str);
   }
@@ -85,65 +78,78 @@ class divListMimeTypes extends MultiSelectWindow
   /* Create list header, with create / copy & paste etc*/
   function GenHeader()
   {
-    /* Prepare departments,
-       which are shown in the listbox on top of the listbox
-     */
-    $options= "";
-
-    /* Get all departments within this subtree */
-    $ui= get_userinfo();
-    $first = "";
-    $found = FALSE;
-    $base = $this->config->current['BASE'];
-
-    /* Add base */
-    $tmp = array();
-    $tmp[] = array("dn"=>$this->config->current['BASE']);
-    $tmp=  array_merge($tmp,get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
-                    array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH));
-
-    $deps = array();
-    foreach($tmp as $tm){
-      $deps[$tm['dn']] = $tm['dn'];
-    }
 
-    /* Load possible departments */
-    $ui= get_userinfo();
-    $tdeps= $ui->get_module_departments($this->module);
-    $ids = $this->config->idepartments;
-    $first = "";
-    $found = FALSE;
-    foreach($ids as $dep => $name){
-      if(isset($deps[$dep]) && in_array_ics($dep, $tdeps)){
-
-        /* Keep first base dn in mind, we could need this
-         *  info if no valid base was found
-         */
-        if(empty($first)) {
-          $first = $dep['dn'];
-        }
 
-        $value = $ids[$dep];
-        if ($this->selectedBase == $dep){
-          $found = TRUE;
-          $options.= "<option selected='selected' value='".$dep."'>$value</option>";
-        } else {
-          $options.= "<option value='".$dep."'>$value</option>";
+    /* Add default header */
+    $listhead = MultiSelectWindow::get_default_header();
+    if(!$this->parent->IsReleaseManagementActivated()){
+
+      /* Prepare departments,
+         which are shown in the listbox on top of the listbox
+       */
+      $options= "";
+
+      /* Get all departments within this subtree */
+      $ui= get_userinfo();
+      $first = "";
+      $found = FALSE;
+      $base = $this->config->current['BASE'];
+
+      /* Add base */
+      $tmp = array();
+      $tmp[] = array("dn"=>$this->config->current['BASE']);
+      $tmp=  array_merge($tmp,get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
+            array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH));
+
+      $deps = array();
+      foreach($tmp as $tm){
+        $deps[$tm['dn']] = $tm['dn'];
+      }
+
+      /* Load possible departments */
+      $ui= get_userinfo();
+      $tdeps= $ui->get_module_departments($this->module);
+      $ids = $this->config->idepartments;
+      $first = "";
+      $found = FALSE;
+      foreach($ids as $dep => $name){
+        if(isset($deps[$dep]) && in_array_ics($dep, $tdeps)){
+
+          /* Keep first base dn in mind, we could need this
+           *  info if no valid base was found
+           */
+          if(empty($first)) {
+            $first = $dep['dn'];
+          }
+
+          $value = $ids[$dep];
+          if ($this->selectedBase == $dep){
+            $found = TRUE;
+            $options.= "<option selected='selected' value='".$dep."'>$value</option>";
+          } else {
+            $options.= "<option value='".$dep."'>$value</option>";
+          }
         }
       }
-    }
 
-    /* The currently used base is not visible with your acl setup.
-     * Set base to first useable base.
-     */
-    if(!$found){
-      $this->selectedBase = $first;
+      /* The currently used base is not visible with your acl setup.
+       * Set base to first useable base.
+       */
+      if(!$found){
+        $this->selectedBase = $first;
+      }
+
+      /* And at least add a department selection box */
+      $listhead .=  _("Base")."&nbsp;<select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
+        " <input class='center' type='image' src='images/list_submit.png' align='middle' 
+        title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'>&nbsp;";
+
     }
 
     /* Get acls */
     $ui       = get_userinfo();
-    $acl      = $ui->get_permissions("cn=dummy,".get_ou('mimetypeou').$this->selectedBase,"mimetypes/mimetype");
-    $acl_all  = $ui->has_complete_category_acls($this->selectedBase,"mimetypes") ;
+    $acl      = $ui->get_permissions("cn=dummy,".$this->parent->mime_base,"mimetypes/mimetype");
+    $acl_all  = $ui->has_complete_category_acls($this->parent->mime_base,"mimetypes") ;
 
 
     /* If this is true we add an additional seperator. Just look a few lines below */  
@@ -156,13 +162,6 @@ class divListMimeTypes extends MultiSelectWindow
       $add_sep = true;
     }
 
-    /* Add default header */
-    $listhead = MultiSelectWindow::get_default_header();
-
-    /* And at least add a department selection box */
-    $listhead .=  _("Base")."&nbsp;<select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
-      " <input class='center' type='image' src='images/list_submit.png' align='middle' 
-        title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'>&nbsp;";
 
     /* Create Layers menu */
     $s  = ".|"._("Actions")."|\n";
@@ -327,16 +326,6 @@ class divListMimeTypes extends MultiSelectWindow
   {
     /* Save automatic created POSTs like regex, checkboxes */
     MultiSelectWindow::save_object(); 
-
-    /* check if returned selectedRelease is a valid release.
-        If it isn't set to a valid release */
-    $this->AvailableReleases = $this->parent->getReleases($this->selectedBase);
-    if(!isset($this->AvailableReleases[$this->selectedRelease])){
-      $this->selectedRelease =key($this->AvailableReleases);
-    }
-    $mimefilter = session::get('mimefilter');
-    $mimefilter['release']  = $this->selectedRelease;
-    session::set('mimefilter',$mimefilter);
   }
 
 }
index 44fada93940f0eb0d48d640f2bb5c00c4dfd0e0f..c12bbdf8fc52b9609b88d2eca5262b6a25a21c85 100644 (file)
@@ -33,6 +33,20 @@ class mimetypeManagement extends plugin
   var $CopyPasteHandler               = NULL;
   var $start_pasting_copied_objects = FALSE;
 
+  var $mime_base    = "";
+  var $mime_release = "";
+
+
+  function IsReleaseManagementActivated()
+  {
+    /* 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 mimetypeManagement (&$config, &$ui)
   {
@@ -57,22 +71,39 @@ class mimetypeManagement extends plugin
       $this->DivListMimeTypes->DisableCheckBox("SubSearch");
     }
 
+
+    /* Set default release */
+    if(!$this->IsReleaseManagementActivated()){
+      $this->mime_base = get_ou("mimetypeou").$this->config->current['BASE'];
+      if(!session::is_set("mime_filter")){
+        session::set("mime_filter",array("mime_base" => $this->mime_base));
+      }
+      $mime_filter     = session::get("mime_filter");
+      $this->mime_base = $mime_filter['mime_base'];
+    }else{
+      $this->mime_base = get_ou("mimetypeou").$this->config->current['BASE'];
+      if(!session::is_set("mime_filter")){
+        session::set("mime_filter",array("mime_base" => $this->mime_base,"mime_release" => $this->mime_base));
+      }
+      $mime_filter         = session::get("mime_filter");
+      $this->mime_base     = $mime_filter['mime_base'];
+      $this->mime_release  = $mime_filter['mime_release'];
+    }
   }
 
 
   /* Get all releases */
-  function getReleases($base)
+  function getReleases()
   {
     $ldap                   = $this->config->get_ldap_link();
-    $dn                     = get_ou('mimetypeou').$base;
     $ret                    = array();
-    $ret [get_ou('mimetypeou').$base] = "/";    
+    $ret [$this->mime_base] = "/";    
 
-    $ldap->cd($dn);
-    $ldap->search("objectClass=organizationalUnit",array("ou"));
+    $ldap->cd($this->mime_base);
+    $ldap->search("(&(objectClass=FAIbranch)(objectClass=organizationalUnit))",array("ou"));
 
     while($attrs = $ldap->fetch()){
-      $str = str_replace($dn,"",$attrs['dn']);
+      $str = str_replace($this->mime_base,"",$attrs['dn']);
       $tmp = array_reverse( split("ou=",$str));
       $str = "";
       foreach($tmp as $val){
@@ -88,6 +119,7 @@ class mimetypeManagement extends plugin
     return($ret);
   }
 
+
   function execute()
   {
     /* Call parent execute */
@@ -185,7 +217,7 @@ class mimetypeManagement extends plugin
 
     /* New mime type? */
     $ui = get_userinfo();
-    $acl = $ui->get_permissions($this->DivListMimeTypes->selectedBase,"mimetypes/mimetype");
+    $acl = $ui->get_permissions($this->mime_base,"mimetypes/mimetype");
     if (($s_action=="new") && preg_match("/c/",$acl)){
 
       /* By default we set 'dn' to 'new', all relevant plugins will
@@ -194,7 +226,8 @@ class mimetypeManagement extends plugin
 
       /* Create new usertab object */
       $this->mimetabs= new mimetabs($this->config, $this->config->data['TABS']['MIMETABS'], $this->dn,"mimetypes");
-      $this->mimetabs->set_acl_base($this->DivListMimeTypes->selectedBase);
+      $this->mimetabs->parent = &$this;
+      $this->mimetabs->set_acl_base($this->mime_base);
     }   
 
 
@@ -227,7 +260,7 @@ class mimetypeManagement extends plugin
       if (count($message) == 0){
 
         /* Save data data to ldap */
-        $this->mimetabs->set_release($this->DivListMimeTypes->selectedRelease);
+        $this->mimetabs->set_release($this->mime_base);
         $this->mimetabs->save();
 
         if (!isset($_POST['edit_apply'])){
@@ -270,6 +303,7 @@ class mimetypeManagement extends plugin
 
       /* Register mimetabs to trigger edit dialog */
       $this->mimetabs= new mimetabs($this->config,$this->config->data['TABS']['MIMETABS'], $this->dn,"mimetypes");
+      $this->mimetabs->parent = &$this;
       $this->mimetabs->set_acl_base($this->dn);
       session::set('objectinfo',$this->dn);
     }
@@ -326,6 +360,7 @@ class mimetypeManagement extends plugin
 
           /* Delete request is permitted, perform LDAP action */
           $this->mimetabs= new mimetabs($this->config, $this->config->data['TABS']['MIMETABS'], $dn,"mimetypes");
+          $this->mimetabs->parent = &$this;
           $this->mimetabs->set_acl_base($dn);
           $this->mimetabs->delete ();
           unset ($this->mimetabs);
@@ -409,6 +444,7 @@ class mimetypeManagement extends plugin
 
         /* Delete request is permitted, perform LDAP action */
         $this->mimetabs= new mimetabs($this->config, $this->config->data['TABS']['MIMETABS'], $this->dn,"mimetypes");
+        $this->mimetabs->parent = &$this;
         $this->mimetabs->set_acl_base($this->dn);
         $this->mimetabs->delete ();
         unset ($this->mimetabs);
@@ -461,8 +497,12 @@ class mimetypeManagement extends plugin
       Dialog display
      ****************/
 
-        /* Check if there is a snapshot dialog open */
-    $base = $this->DivListMimeTypes->selectedBase;
+    /* Check if there is a snapshot dialog open */
+    if($this->IsReleaseManagementActivated()){
+      $base = $this->mime_release;
+    }else{
+      $base = $this->mime_base;
+    }
     if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
       return($str);
     }
@@ -470,7 +510,9 @@ class mimetypeManagement extends plugin
     /* Display dialog with system list */
     $this->DivListMimeTypes->parent = $this;
     $this->DivListMimeTypes->execute();
-    $this->DivListMimeTypes->AddDepartments($this->DivListMimeTypes->selectedBase,3,1);
+    if(!$this->IsReleaseManagementActivated()){
+      $this->DivListMimeTypes->AddDepartments($this->DivListMimeTypes->selectedBase,3,1);
+    }
     $this->reload();
     $this->DivListMimeTypes->setEntries($this->mimetypes);
     return($this->DivListMimeTypes->Draw());
@@ -480,48 +522,44 @@ class mimetypeManagement extends plugin
   /* Return departments, that will be included within snapshot detection */
   function get_used_snapshot_bases()
   {
-    return(array($this->DivListMimeTypes->selectedRelease));
+    if($this->IsReleaseManagementActivated()){
+      return(array($this->mime_release));
+    }else{
+      return(array($this->mime_base));
+    }
   }
 
 
-
   function reload()
   {
     $this->mimetypes= array();
 
     /* Set base for all searches */
-    $base       = $this->DivListMimeTypes->selectedBase;
-    $release    = $this->DivListMimeTypes->selectedRelease;
+    $base       = $this->mime_base;
     $Regex      = $this->DivListMimeTypes->Regex;
     $SubSearch  = $this->DivListMimeTypes->SubSearch; 
     $Flags      =  GL_NONE | GL_SIZELIMIT;
     $Filter     = "(&(|(cn=".$Regex.")(description=".$Regex."))(objectClass=gotoMimeType))";
     $tmp        = array();
-    $Releases   = $this->getReleases($base);
-
+    $Releases   = $this->getReleases();
 
-    /* If release management is enabled, use release as base. */
-    if(!$this->enableReleaseManagement){
-      $use_base = $base;
-    }else{
-      if(isset($Releases[$release])){
-        $use_base  = $release;
-      }else{
-        $use_base  = $base;
+    if(!$this->IsReleaseManagementActivated()){
+      $use_base = $this->mime_base;
+      if($SubSearch){
+        $use_base = preg_replace("/^".normalizePreg(get_ou("mimeou"))."/","",$use_base);
       }
+    }else{
+      $use_base = $this->mime_release;
+      $SubSearch= FALSE;
     }
 
-    /* In case of subsearch, add the subsearch flag */
     if($SubSearch){
-      $Flags    |= GL_SUBSEARCH;  
+      $res= get_sub_list($Filter, "mimetypes",get_ou("mimeou"), $use_base, array("cn","description","dn","objectClass"), $Flags);
     }else{
-      if(!$this->enableReleaseManagement){
-        $use_base = get_ou('mimetypeou').$use_base;
-      }
+      $res= get_list($Filter, "mimetypes",$use_base, array("cn","description","dn","objectClass"), $Flags);
     }
-  
-    /* Get results and create index */ 
-    $res= get_sub_list($Filter, "mimetypes",get_ou('mimetypeou'), $use_base, array("cn","description","dn","objectClass"), $Flags);
+
+
     $tmp2 = array();
     foreach ($res as $val){
       $tmp[strtolower($val['cn'][0]).$val['cn'][0].$val['dn']]=$val;
@@ -607,18 +645,6 @@ class mimetypeManagement extends plugin
   }
 
 
-  /* Check if the release management is activated. */
-  function IsReleaseManagementActivated()
-  {
-    /* 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 list_get_selected_items()
   {
     $ids = array();
@@ -646,13 +672,31 @@ class mimetypeManagement extends plugin
     }
   }
 
-  function save_object() {
+  function save_object() 
+  {
     $this->DivListMimeTypes->save_object();
     if(is_object($this->CopyPasteHandler)){
       $this->CopyPasteHandler->save_object();
     }
+
+    if($this->IsReleaseManagementActivated() && isset($_POST['mime_release'])){
+      $sel_rel = get_post('mime_release');
+      $releases = array_flip($this->getReleases());
+      if(isset($releases[$sel_rel])){
+        $this->mime_release = $releases[$sel_rel];
+      }
+      $mime_filter     = session::get("mime_filter");
+      $mime_filter['mime_release'] = $this->mime_release;
+      session::set("mime_filter",$mime_filter);
+    }elseif(!$this->IsReleaseManagementActivated()){
+      $this->mime_base = get_ou("mimetypeou").$this->DivListMimeTypes->selectedBase;
+      $mime_filter     = session::get("mime_filter");
+      $mime_filter['mime_base'] = $this->mime_base;
+      session::set("mime_filter",$mime_filter);
+    }
   }
 
+
   function check() {}
   function adapt_from_template($dn, $skip= array()) {}
   function password_change_needed() {}
index d864cebcf5243f4176582740bbc3ebcd0a2f3914..37813af2344c6cb5fa6591f85f0fc6f4e2b3bf54 100644 (file)
@@ -6,8 +6,8 @@
   <tr>
    <td>
     {t}Current release{/t}&nbsp;
-    <select name="selectedRelease" onChange="document.mainform.submit();">
-     {html_options options=$releases selected=$selectedRelease}
+    <select name="mime_release" onChange="document.mainform.submit();">
+        {html_options output=$mime_releases values=$mime_releases selected=$mime_release}
     </select>
    </td>
   </tr>
index 38570fde21c1fca85031a66d982757d9f95b39e6..9597704cafcc64f1794f3193192a3719d8fef839 100644 (file)
@@ -3,6 +3,7 @@
 class mimetabs extends tabs
 {
   var $Release= "";
+  var $parent = FALSE;
 
   function mimetabs($config, $data, $dn,$category)
   {
@@ -26,18 +27,10 @@ class mimetabs extends tabs
 
     /* Check for new 'dn', in order to propagate the
        'dn' to all plugins */
-    $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs'));
-
-    $mimefilter = session::get('mimefilter');
-
-    if((!empty($tmp)) && (isset($mimefilter['release']))){
-      if(!$baseobject->isReleaseMimeType){
-        $new_dn= "cn=".$baseobject->cn.",".get_ou('mimetypeou').$baseobject->base;
-      }else{
-        $new_dn ="cn=".$baseobject->cn.",".$mimefilter['release'];
-      }
+    if($this->parent->IsReleaseManagementActivated()){
+      $new_dn= "cn=".$baseobject->cn.",".$this->parent->mime_release;
     }else{
-      $new_dn= "cn=".$baseobject->cn.",".get_ou('mimetypeou').$baseobject->base;
+      $new_dn= "cn=".$baseobject->cn.",".get_ou('mimeou').$baseobject->base;
     }
 
     /* Move group? */