Code

Department list strips to long entries ......
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Fri, 13 Jan 2006 13:20:02 +0000 (13:20 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Fri, 13 Jan 2006 13:20:02 +0000 (13:20 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@2478 594d385d-05f5-0310-b6e9-bd551577e9d8

include/class_config.inc

index 84f9b176406c77c57cee97603b4e32ecd22916fe..505e48563419643602371fb225a97313a773d4e0 100644 (file)
@@ -456,18 +456,80 @@ class config  {
 
   function make_idepartments($max_size= 28)
   {
+       global $config;
+       $base = $config->current['BASE'];
+               
+       $arr = array();
+       
        $this->idepartments= array();
        foreach ($this->departments as $key => $val){
-               if (strlen($key) > $max_size){
-                       $this->idepartments[$val]= substr($key, 0, $max_size/2 - 3)."...".substr($key, -$max_size/2);
-               } else {
-                       $this->idepartments[$val]= $key;
+
+               $val2 = str_replace($base,"",$val);
+
+               $str = preg_replace("/ou=/","|ou=",$val2);      
+               $elements = array_reverse(split("\|",$str));            
+
+               $last = &$arr;
+               $cnt = count($elements);
+               foreach($elements as $key => $ele){
+               
+                       if(empty($ele)) continue;
+                       $elestr = preg_replace("/^ou=/","", $ele);
+                       $elestr = preg_replace("/,$/","",$elestr);      
+                       if($key == ($cnt-2)){
+                               $last[$elestr]['ENTRY'] = $val;
+                       }
+                       $last = &$last[$elestr]['SUB'];
                }
        }
-
-       asort($this->idepartments);
+       $ret["/"]["ENTRY"]      = $base;
+       $ret["/"]["SUB"]        = $arr;
+       
+       $this->idepartments= $this->generateDepartmentArray($ret,-1,$max_size);
   }
 
+       function generateDepartmentArray($arr,$depth = -1,$max_size){
+               $ret = array();
+               $depth ++;
+
+               foreach($arr as $name => $entries){
+
+                       if(count($entries['SUB'])==0){
+                               unset($entries['SUB']);
+                       }
+                       if(strlen($name)> $max_size){
+                               $name = substr($name,0,($max_size-3))." ...";
+                       }
+       
+                       if(isset($entries['ENTRY'])){
+                               $a = "";
+                               for($i = 0 ; $i < $depth ; $i ++){
+                                       $a.="&nbsp;";
+                               }
+                               $ret[$entries['ENTRY']]=$a."&nbsp;".$name;
+                       }       
+                       /* For debugging        
+                       if(isset($entries['ENTRY'])){
+                               $a = "";
+                               for($i = 0 ; $i < $depth ; $i ++){
+                                       $a.="&nbsp;|";
+                               }
+                       
+                               if(!isset($entries['SUB'])){
+                                       $ret[$entries['ENTRY']]=$a."-&nbsp;".$name;
+                               }else{
+                                       $ret[$entries['ENTRY']]=$a."#"."&nbsp;".$name;
+                               }
+                       }       
+                       */
+                       if(isset($entries['SUB'])){
+                               $ret = array_merge($ret,$this->generateDepartmentArray($entries['SUB'],$depth,$max_size));
+                       }
+               }
+               
+               return($ret);
+       }
+
   /* This function returns all available Shares defined in this ldap
   * There are two ways to call this function, if listboxEntry is true
   *  only name and path are attached to the array, in it is false, the whole