Code

Moved folder image
[gosa.git] / gosa-plugins / goto / admin / groups / apps / class_groupApplication.inc
index 0877b855fb5dfb6b1851057bc14c5e3080792bd3..29a6d540fa80ab2627a8b1f0c07a37ca2af47814 100644 (file)
@@ -1,12 +1,6 @@
 <?php
 class appgroup extends plugin
 {
-  /* CLI vars */
-  var $cli_summary= "Manage application groups";
-  var $cli_description= "Some longer text\nfor help";
-  var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
-
-
   var $config;
   var $curbase;
 
@@ -80,7 +74,18 @@ class appgroup extends plugin
           $ret = array_merge($ret,get_list("(objectClass=gosaApplication)","application",$dep,array("*"),GL_NONE));
         }
       }
-      $this->_cache['ReleaseApps'][$release_info['suffix']] = $ret;
+
+      $tmp = array();
+      foreach($ret as $key => $app){
+        $tmp[$key] = $app['cn'][0];
+      }
+      natcasesort($tmp);
+      $res = array();
+      foreach($tmp as $key => $app){
+        $res[] = $ret[$key];
+      }
+
+      $this->_cache['ReleaseApps'][$release_info['suffix']] = $res;
     } 
     $this->apps = $this->_cache['ReleaseApps'][$release_info['suffix']];
   }
@@ -93,13 +98,14 @@ class appgroup extends plugin
     */
   function getReleases()
   {
-    $ret =array("/" => array("name" => "/" , "parts" => array(),"suffix" => get_ou('applicationou')));
+    $ret =array("/" => array("name" => "/", "found" => TRUE , "parts" => array(),"suffix" => get_ou('applicationou')));
     if($this->enableReleaseManagement){
 
       /* Only display those releases that we are able to read */
-      $dn     = $this->config->current['BASE'];
+      $dn     = get_ou("applicationou").$this->config->current['BASE'];
       $filter = "(&(objectClass=organizationalUnit)(objectClass=FAIbranch))";
-      $res    = get_list($filter,"application", $dn, array("ou","FAIstate"), GL_SUBSEARCH);
+      $res    = get_sub_list($filter,array("application","fai"), array(get_ou("applicationou"),get_ou("faiou")),$dn, array("ou","FAIstate"), GL_SUBSEARCH);
+
 
       foreach($res as $attrs){
         if(preg_match("/".get_ou('applicationou')."/",$attrs['dn'])){
@@ -125,7 +131,18 @@ class appgroup extends plugin
             $FAIstate = $attrs['FAIstate'][0];
           }
 
+          $all = $this->_get_all_entries();
+          $found = FALSE;
+          foreach($all as $entry){
+            if(isset($entry['DN']) && preg_match("/^".normalizePreg($bb)."/",$entry['DN'])){
+              $found =TRUE;
+              break;
+            }
+          }
+
+          $cnt = 0;
           $ret[$name] = array("name"     => $name, 
+              "found"    => $found,
               "FAIstate" => $FAIstate,
               "dn"       => $attrs['dn'], 
               "parts"    => $parts,"suffix" => $bb.get_ou('applicationou'));
@@ -162,18 +179,25 @@ class appgroup extends plugin
       $sub_dn       = preg_replace("/,".normalizePreg($this->dn)."$/","",$attrs['dn']);
       $sub_dn_array = split("\,",$sub_dn);
 
-
+      $found = true;
       for($i = (count($sub_dn_array)-1) ; $i >= 0 ; $i--){
         $name = preg_replace("/^[^=]*+=/","",$sub_dn_array[$i]);
+        
         if($i > 0){
+          $found =FALSE;
           foreach($cur as $key => $entry){
             if($entry['NAME'] == $name){
               $cur = &$cur[$key]['ENTRIES'];
               $parent_id = $entry['UNIQID'];
+              $found =true;
+              break;
             }
           }
         }else{
-
+          
+          if(!$found){
+            break;
+          }
           $priority = 1;
           if(isset($attrs['gosaApplicationPriority'])){
             $priority= $attrs['gosaApplicationPriority'][0];
@@ -192,13 +216,20 @@ class appgroup extends plugin
             }
 
           }elseif(in_array("gotoMenuEntry",$attrs['objectClass'])){
+
             $type = "ENTRY";
             $data['INFO'] = "";
             $data['PARAMETER'] = array();
             if(isset($attrs['gosaApplicationParameter'])){
               for($p = 0 ; $p < $attrs['gosaApplicationParameter']['count'] ; $p ++){
-                $tmp = split(":",$attrs['gosaApplicationParameter'][$p]);
-                $data['PARAMETER'][$tmp[0]] = $tmp[1];
+                if(preg_match("/:/",$attrs['gosaApplicationParameter'][$p])){
+                  $tmp = split(":",$attrs['gosaApplicationParameter'][$p]);
+                  $data['PARAMETER'][$tmp[0]] = $tmp[1];
+                }elseif($attrs['gosaApplicationParameter'][$p] == "*separator*"){
+                  $type = "SEPERATOR";
+                  $data['PARAMETER'] = array();
+                  break;
+                }
               }
             }
           }elseif(in_array("FAIbranch",$attrs['objectClass'])){
@@ -211,6 +242,7 @@ class appgroup extends plugin
             }
           }
 
+          $data['LDAP_ATTRS'] = $attrs;
           $data['DN']       = $attrs['dn'];
           $data['NAME']     = $name;
           $data['TYPE']     = $type;
@@ -232,20 +264,19 @@ class appgroup extends plugin
     /* Call parent execute */
     plugin::execute();
 
+    if(isset($_GET['r'])) $this->__construct($this->config,$this->dn);
+
     if (isset($_POST['modify_state'])){
       $this->is_account = !$this->is_account;
     }
 
     /* Do we represent a valid account? */
     if (!$this->is_account){
-      $display= $this->show_enable_header(_("Add application extension"),
-          _("Application extension disabled. You can enable it by clicking below."));
+      $display= $this->show_disable_header(msgPool::addFeaturesButton(_("Menu")), msgPool::featuresDisabled(_("Menu")));
       return ($display);
     }
 
-    $display =  $this->show_enable_header(_("Remove application extension"),
-          _("Application extension enabled. You can disable it by clicking below."));
-
+    $display= $this->show_disable_header(msgPool::removeFeaturesButton(_("Menu")), msgPool::featuresEnabled(_("Menu")));
 
     if(isset($_GET['send'])){
       $id = $_GET['send'];
@@ -316,7 +347,7 @@ class appgroup extends plugin
     /* Append departments for current base */
     foreach($departments as $key => $app){
       $div->AddEntry(array(
-            array("string"=>"<img class='center' src='images/folder.png' alt='"._("department")."'>&nbsp;".sprintf($linkopen,
+            array("string"=>"<img class='center' src='images/lists/folder.png' alt='"._("department")."'>&nbsp;".sprintf($linkopen,
                 base64_encode($key),$app),
               "attach"=>"style='border:0px;'")
             ));
@@ -348,6 +379,7 @@ class appgroup extends plugin
     $smarty->assign("enableReleaseManagement",$this->enableReleaseManagement);
     $smarty->assign("FAIrelease",$this->FAIrelease);
     $smarty->assign("app_list",$div->DrawList());
+    $smarty->assign("i",0);
     $smarty->assign("releases",$this->Releases);
     $smarty->assign("folders" , $this->_get_folder_names());
     $entries = $this->_get_entries_for_release($this->FAIrelease);
@@ -363,10 +395,21 @@ class appgroup extends plugin
   function _get_folder_names()
   {
     $data = $this->_get_entries_for_release($this->FAIrelease);
+    $all    = $this->_get_all_entries();
     $ret = array("BASE" => ".");
     foreach($data as $entry){
+
       if($entry['TYPE'] == "FOLDER"){
-        $ret[$entry['UNIQID']] = $entry['NAME'];
+        $str = $entry['NAME'];
+        $parent = $entry['PARENT'];
+        $i = 10;
+        while(isset($all[$parent]) && $i){  
+          $i --;
+          $parent_o = $all[$parent];
+          $str      = $parent_o['NAME']."/".$str;
+          $parent   = $all[$parent_o['UNIQID']]['PARENT'];
+        }        
+        $ret[$entry['UNIQID']] = $str;
       }
     }
     return($ret);
@@ -397,7 +440,7 @@ class appgroup extends plugin
     $all = $this->_get_all_entries();
     $key = $this->_get_release_key($release);
     if(isset($all[$key]) && count($all[$key]['ENTRIES'])){
-      $res = $this->_get_all_entries(TRUE,TRUE,&$all[$key]['ENTRIES']);
+      $res = $this->_get_all_entries(TRUE,TRUE,$all[$key]['ENTRIES']);
       return($res);
     } 
     return(array());
@@ -480,9 +523,9 @@ class appgroup extends plugin
     }
     foreach($a_remove as $remove){
       $ldap->rmdir_recursive($remove);
-      show_ldap_error($ldap->get_error(),
-          sprintf(_("Removing of group/application account with dn '%s' failed, could not remove '%s'."),
-            $this->dn,$remove));
+      if (!$ldap->success()){
+        msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_DEL, get_class()));
+      }
     }
     $this->_load_menu_structure();
   }
@@ -682,6 +725,13 @@ class appgroup extends plugin
         }
       }
     }
+
+    /* Add seperator */
+    if(isset($_POST['add_seperator']) && isset($_POST['menu_folder'])){
+      $folder = $_POST['menu_folder'];
+      $this->_add_seperator($folder);
+    }
+
     if(isset($_POST['add_menu_to_folder']) && isset($_POST['menu_folder'])){
       $folder = $_POST['menu_folder'];
       $name = $_POST['menu_folder_name'];
@@ -776,6 +826,7 @@ class appgroup extends plugin
     $all = $this->_get_all_entries();
     if(isset($all[$id])){
       $all[$id]['STATUS'] = "REMOVED";
+      $all[$id]['ENTRIES'] = array();
       return(TRUE);
     }
     return(FALSE);
@@ -797,8 +848,13 @@ class appgroup extends plugin
 
     if(isset($all[$folder_id])){
 
+      if(!isset($entry['ENTRIES'])){
+        $entries = array();
+      }else{
+        $entries = $entry['ENTRIES'];
+      }
+
       $folder  = &$all[$folder_id];
-      $entries = $entry['ENTRIES'];
 
       $entry['UNIQID'] = uniqid();     
       $entry['PARENT'] = $folder_id;
@@ -862,11 +918,35 @@ class appgroup extends plugin
   }
 
 
+  /*! \brief Add the application identified by $app_id to folder $folder_id 
+      @param  String  folder_id The UNIQID of the folder where we want to add the new folder.
+      @param  Integer app_id    The ID of the application which should be added.
+   */ 
+  function _add_seperator($folder_id)
+  {
+    $all = $this->_get_all_entries();
+    if($folder_id == "BASE"){
+      $folder_id = $this->_get_release_key($this->FAIrelease);
+    }
+
+    if(isset($all[$folder_id])){
+      $new = array();
+      $new['TYPE']  = "SEPERATOR";
+      $new['NAME']  = "SEPERATOR";
+      $new['UNIQID']= uniqid(); 
+      $new['PARENT']= $folder_id;
+      $new['PARAMETER']= array();
+      $new['STATUS']= "ADDED";
+      $all[$folder_id]['ENTRIES'][] = $new;
+    }
+  }
+
+
   /*! \brief  Return all entries linear. 
       @param  Boolean   $add_tags  If TRUE, OPEN/CLOSE Tags will be appended.
       @param  &Array    Start here, Pointer to an array.
    */ 
-  function _get_all_entries($add_tags = FALSE, $skip_release = FALSE, $cur = NULL)
+  function _get_all_entries($add_tags = FALSE, $skip_release = FALSE, &$cur = NULL)
   {
     $ret = array();
     if($cur == NULL){
@@ -898,7 +978,7 @@ class appgroup extends plugin
       if(!$add_tags){
         $ret[$tmp['UNIQID']] = &$cur[$key];
         if(isset($entry['ENTRIES']) && count($entry['ENTRIES'])){
-          $ret = array_merge($ret,$this->_get_all_entries($add_tags,$skip_release,&$cur[$key]['ENTRIES']));
+          $ret = array_merge($ret,$this->_get_all_entries($add_tags,$skip_release,$cur[$key]['ENTRIES']));
         }
       }else{
       
@@ -918,7 +998,7 @@ class appgroup extends plugin
 
             if($add){
               $ret[] = array("TYPE" => "OPEN", "PARENT" => $entry['PARENT']);
-              $ret = array_merge($ret,$this->_get_all_entries($add_tags,$skip_release,&$cur[$key]['ENTRIES']));
+              $ret = array_merge($ret,$this->_get_all_entries($add_tags,$skip_release,$cur[$key]['ENTRIES']));
               $ret[] = array("TYPE" => "CLOSE" , "PARENT" => $entry['PARENT']);
             }
           }
@@ -936,13 +1016,17 @@ class appgroup extends plugin
     $prio = 0;
     $Actions = array("Remove" => array(),"Edit" => array() , "Add" => array());
 
+    $sep_id = 0;
     foreach($all as $entry){
       $prio ++;
       $cur = $entry;
       $dn = "";
 
       do{  
-        if($cur['TYPE'] == "ENTRY"){
+        if($cur['TYPE'] == "SEPERATOR"){
+          $sep_id ++;
+          $dn.= "cn=seperator_".$sep_id.",";
+        }elseif($cur['TYPE'] == "ENTRY"){
           $dn.= "cn=".$cur['NAME'].",";
         }elseif($cur['TYPE'] == "FOLDER"){
           $dn.= "cn=".$cur['NAME'].",";
@@ -960,10 +1044,19 @@ class appgroup extends plugin
       $cur_dn = $dn.$this->dn;
 
       $attrs = array();
+
       switch($entry['TYPE']){
+        case "SEPERATOR"    :
+        { 
+          $attrs['objectClass'] = array("gotoMenuEntry");
+          $attrs['cn']          = "seperator_".$sep_id;
+          $attrs['gosaApplicationPriority'] = $prio;
+          $attrs['gosaApplicationParameter'] = "*separator*";
+        }
+        break;
         case "ENTRY"    :
         { 
-          $attrs['objectClass'] = "gotoMenuEntry";
+          $attrs['objectClass'] = array("gotoMenuEntry");
           $attrs['cn']          = $entry['NAME'];
           $attrs['gosaApplicationPriority'] = $prio;
           $attrs['gosaApplicationParameter'] = array(); 
@@ -979,7 +1072,7 @@ class appgroup extends plugin
         break;
         case "FOLDER"   : 
         { 
-          $attrs['objectClass'] = "gotoSubmenuEntry";
+          $attrs['objectClass'] = array("gotoSubmenuEntry");
           $attrs['cn']          = $entry['NAME'];
           $attrs['gosaApplicationPriority'] = $prio;
           if($entry['STATUS'] != "ADDED"){
@@ -992,7 +1085,7 @@ class appgroup extends plugin
         }
         break;
         case "RELEASE"  : 
-        { 
+        {
           $attrs['ou']            = $entry['NAME'];
           $attrs['objectClass']   = array();
           $attrs['objectClass'][] = "top";
@@ -1004,12 +1097,26 @@ class appgroup extends plugin
         }
         break;
       }
-  
+      /* Append missing ObjectClasses,  ...  Tagging */
+      if(isset($entry['LDAP_ATTRS'])){
+        for($i = 0 ; $i < $entry['LDAP_ATTRS']['objectClass']['count']; $i ++){
+          $oc = $entry['LDAP_ATTRS']['objectClass'][$i];
+          if(!in_array($oc,$attrs['objectClass'])){
+            $attrs['objectClass'][] = $oc;
+          }
+        }
+      }
       if($entry['STATUS'] == "LOADED"){
         continue;
       }
       if($entry['STATUS'] == "REMOVED"){
-        $Actions['Remove'][$cur_dn] = $cur_dn;
+        if(isset($entry['DN'])){
+          $Actions['Remove'][$entry['DN']] = $entry['DN'];
+        }else{
+          $Actions['Remove'][$cur_dn] = $cur_dn;
+        }
       }
       if($entry['STATUS'] == "EDITED"){
         $Actions['Edit'][$cur_dn] = $attrs;
@@ -1026,7 +1133,9 @@ class appgroup extends plugin
       $ldap->cat($dn);
       if($ldap->count()){
         $ldap->rmdir_recursive($dn);
-        show_ldap_error($ldap->get_error(), _("Could not save group application settings."));
+        if (!$ldap->success()){
+          msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $dn, LDAP_DEL, get_class()));
+        }
       }
     }
     foreach($Actions['Add'] as $dn => $data){
@@ -1034,7 +1143,9 @@ class appgroup extends plugin
       $ldap->cat($dn);
       if(!$ldap->count()){
         $ldap->add($data);
-        show_ldap_error($ldap->get_error(), _("Could not save group application settings."));
+        if (!$ldap->success()){
+          msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $dn, LDAP_DEL, get_class()));
+        }
       }
     }
     foreach($Actions['Edit'] as $dn => $data){
@@ -1042,9 +1153,12 @@ class appgroup extends plugin
       $ldap->cat($dn);
       if($ldap->count()){
         $ldap->modify($data);
-        show_ldap_error($ldap->get_error(), _("Could not save group application settings."));
+        if (!$ldap->success()){
+          msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $dn, LDAP_DEL, get_class()));
+        }
       }
     }
+
     $this->_load_menu_structure();
   }