Code

Fixed stupid name parsing
[gosa.git] / plugins / admin / groups / class_groupApplication.inc
1 <?php
2 class appgroup extends plugin
3 {
4   /* CLI vars */
5   var $cli_summary= "Manage application groups";
6   var $cli_description= "Some longer text\nfor help";
7   var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
9   /* Appgroup attributes */
10   var $gosaMemberApplication= array();
12   /* Helpers */
13   var $departments        = "";       // All departments within $this->curbase;
14   var $apps               = array();  // All available applications
15   var $used_apps          = array();  // Specifies which applications are currently assigned 
17   var $option_name  = array();
18   var $option_value = array();
19   var $appoption    = array();
21   var $table          = "";
22   var $curbase        = "";
23   var $curCatDir      ;
24   var $curCatDepth    =0;         //
26   /* attribute list for save action */
27   var $attributes= array();
28   var $objectclasses= array("gosaApplicationGroup");
31   function appgroup ($config, $dn= NULL)
32   {
33     plugin::plugin ($config, $dn);
35     /* Load member applications */
36     if (isset ($this->attrs["gosaMemberApplication"][0])){
37       for ($i= 0; $i<$this->attrs["gosaMemberApplication"]["count"]; $i++){
38         $this->gosaMemberApplication[]=
39           $this->attrs["gosaMemberApplication"][$i];
40       }
41     }
43     /* Load application options */
44     if (isset($this->attrs['gosaApplicationParameter'])){
45       for ($i= 0; $i<$this->attrs['gosaApplicationParameter']['count']; $i++){
46         $option= preg_replace('/^[^:]+:/', '',
47             $this->attrs['gosaApplicationParameter'][$i]);
48         $name= preg_replace('/:.*$/', '',
49             $this->attrs['gosaApplicationParameter'][$i]);
50         $this->appoption[$name]= $option;
51       }
52     }
54     /* Parse MemberApplication*/
55     $tmp = array();
56     $tmp2 = array();
57     $prios = array();
58     $cats = array();
60     foreach($this->gosaMemberApplication as $memberApp){
61       if(preg_match("/\|/i",$memberApp)){
62     
63         $tmp = split("\|",$memberApp);
64  
65         if(!empty($tmp[0])){
66           $tmp2[$tmp[1]][$tmp[2]] = array("App"=>$tmp[0]);
67         }
68         if(!empty($tmp[1])){
69           $n = split("/",$tmp[1]);
70           $c = count($n);
71           $cats [$tmp[1]] = $n[$c-1];
72         }
73         $prios[$tmp[1]][$tmp[2]] = $tmp[2];
74       }else{
75         $tmp2[]['App'] = $memberApp;
76       }
77     }
79     $this->Categories = $cats;
81     $this->gosaMemberApplication = $tmp2;
82     $cats[""]="";
83     foreach($cats as $cat ){
84       if((isset($prios[$cat]))&&(count($prios[$cat]))){
85         $max = max($prios[$cat]);
86         $min = 1;//min($prios[$cat]);  
87         $last = false;
88         for($i = $min ; $i < $max ; $i++){
89           if(!isset($prios[$cat][$i])){
90             if($last == false){
91               $this->gosaMemberApplication[$cat][$i]['App'] = "__SEPARATOR__".$i;
92             
93               $last = true;
94             }
95           }else{
96             $last = false;
97           }
98         }
99       }
100     }
102     $tmp = array();
103     foreach($this->gosaMemberApplication as $key =>  $entries){
104       ksort ($entries);
105       foreach($entries as $entry){
106         $tmp[$key][]= $entry;
107       }
108     }
109     $this->gosaMemberApplication = $tmp;
110     $this->curbase = $this->config->current['BASE'];
111   }
114   /* Combine new array */
115   function combineArrays($ar0,$ar1,$ar2)
116   {
117     $ret = array();
118     if(is_array($ar0))
119     foreach($ar0 as $ar => $a){
120         $ret[$ar]=$a;
121     }
122     if(is_array($ar1))
123     foreach($ar1 as $ar => $a){
124         $ret[$ar]=$a;
125     }
126     if(is_array($ar2))
127     foreach($ar2 as $ar => $a){
128         $ret[$ar]=$a;
129     }
130     return($ret);
131   }
133   function getpos($atr,$attrs)
134   {
135     $i = 0;
136     foreach($attrs as $attr => $name)    {
137       $i++;
138       if($attr == $atr){
139         return($i);
140       }
141     }
142     return(-1);
143   }
146   /* TRansports the geiven Arraykey one position up*/
147   function ArrayUp($atr,$attrs)
148   {
149     $ret = $attrs;
150     $pos = $this->getpos($atr,$attrs) ;
151     $cn = count($attrs);
152     if(!(($pos == -1)||($pos == 1))){
153       $before = array_slice($attrs,0,($pos-2));
154       $mitte  = array_reverse(array_slice($attrs,($pos-2),2));
155       $unten  = array_slice($attrs,$pos);
156       $ret = array();
157       $ret = $this->combineArrays($before,$mitte,$unten);
158     }
159     return($ret);
160   }
163   /* TRansports the geiven Arraykey one position up*/
164   function ArrayDown($atr,$attrs)
165   {
166     $ret = $attrs;
167     $pos = $this->getpos($atr,$attrs) ;
168     $cn = count($attrs);
169     if(!(($pos == -1)||($pos == $cn))){
170       $before = array_slice($attrs,0,($pos-1));
171       $mitte  = array_reverse(array_slice($attrs,($pos-1),2));
172       $unten  = array_slice($attrs,($pos+1));
173       $ret = array();
174       $ret = $this->combineArrays($before,$mitte,$unten);
175     }
176     return($ret);
177   }
180   function catUp($id)
181   {
182     /* Get all cats depinding on current dir */
183     $cats = $this->GetSubdirs($this->curCatDir);
184     $newcats =$this->ArrayUp($id,$cats);
186     foreach($newcats as $cat => $name){
187       unset($this->Categories[$cat]);
188     }
189     foreach($newcats as $cat => $name){
190       $this->Categories[$cat]=$name;
191     }
192   }
194   
195   function catDown($id)
196   {
197    /* Get all cats depinding on current dir */
198     $cats = $this->GetSubdirs($this->curCatDir);
199      
200     $newcats =$this->ArrayDown($id,$cats);
202     foreach($newcats as $cat => $name){
203       unset($this->Categories[$cat]);
204     }
205     foreach($newcats as $cat => $name){
206       $this->Categories[$cat]=$name;
207     }
208   }
211   function getOneUp($appl)
212   { 
213     $cat  = $this->curCatDir;
214     $apps = $this->gosaMemberApplication[$cat];
216     $appsA = array();
217     foreach ($apps as $appkey => $name){
218       $appsA[$name['App']] =$name['App'];
219     }
220  
221     $result = $this->ArrayUp($appl,$appsA);
223     $ret = array();
224     foreach($result as $app){
225       $ret[]=array("App"=>$app);
226     }
227     $this->gosaMemberApplication[$cat] = $ret;
228   }
231   function getOneDown($appl)
232   {
233     $cat  = $this->curCatDir;
234     $apps = $this->gosaMemberApplication[$cat];
236     $appsA = array();
237     foreach ($apps as $appkey => $name){
238       $appsA[$name['App']] =$name['App'];
239     }
241     $result = $this->ArrayDown($appl,$appsA);
243     $ret = array();
244     foreach($result as $app){
245       $ret[]=array("App"=>$app);
246     }
247     $this->gosaMemberApplication[$cat] = $ret;
248   } 
250    
251   
252   function AddSeperator($id)
253   {
254     $found  = false;
255     $cat    = "";
256     $tmp = array();
257     foreach($this->gosaMemberApplication[$this->curCatDir] as $appID => $app){  
258       $tmp[] = $app;    
259       if(($app['App'] == $id)&&(!$found)){
260         $cnt = count($this->gosaMemberApplication[$this->curCatDir]);
261         $tmp[] = array("App" => "__SEPARATOR__".($cnt+1));
262         $found = true;
263       }
264     }
265     if($found){
266       $this->gosaMemberApplication[$this->curCatDir]=$tmp;
267     }
268   }
270   function execute()
271   {
272           /* Call parent execute */
273         plugin::execute();
275     if((isset($_GET['act']))&&($_GET['act']=="depopen")){
276       print $_GET['id'];
277       $dep = base64_decode($_GET['id']);  
278       if(isset($this->config->idepartments[$dep])){
279         $this->curbase =$dep;
280       }
281     }
283     if((isset($_GET['act']))&&($_GET['act']=="open")){
284       $this->curCatDir = base64_decode($_GET['id']);
285     }
287     /* Do we need to flip is_account state? */
288     if (isset($_POST['modify_state'])){
289       $this->is_account= !$this->is_account;
290     }
292     /* Do we represent a valid group? */
293     if (!$this->is_account && $this->parent == NULL){
294       $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\">&nbsp;<b>".
295         _("This 'dn' is no appgroup.")."</b>";
296       return ($display);
297     }
299     /* Show tab dialog headers */
300     $display= "";
301     if ($this->parent != NULL){
302       if ($this->is_account){
303         $display= $this->show_header(_("Remove applications"),
304             _("This group has application features enabled. You can disable them by clicking below."));
305       } else {
306         $display.= $this->show_header(_("Create applications"),
307             _("This group has application features disabled. You can enable them by clicking below."));
308         return ($display);
309       }
310     }
313     /* Add Categorie */ 
314   
315     
316     if((isset($_POST['AddCat']))&&(isset($_POST['CatName']))&&(!empty($_POST['CatName']))){
318       if(preg_match("/[\\\\\/]/i",$_POST['CatName'])){
319         print_red(_("Invalid character in category name."));
320       }elseif(!in_array($_POST['CatName'],$this->Categories)){ 
321         if(empty($this->curCatDir)){
322           $this->Categories[$_POST['CatName']]=$_POST['CatName'];
323         }else{
324           $this->Categories[$this->curCatDir."/".$_POST['CatName']]=$_POST['CatName'];
325         }
326       }else{
327         print_red(_("The specified category already exists."));
328       }
329     }
332     $this->reload();
333     $only_once = false;
334     foreach($_POST as $name => $value){
335       
336       if((preg_match("/AddSep_/",$name))&&(!$only_once)){
337         $only_once = true;
338         $n = preg_replace("/AddSep_/","",$name);
339         $val= preg_replace("/_.*$/","",$n);
340         $this->AddSeperator($val);
341       }
343       if((preg_match("/DelApp_/",$name))&&(!$only_once)){
344         $only_once = true;
345    
347         if(preg_match("/DelApp___SEPARATOR__/",$name)) {
348           $n=  preg_replace("/DelApp___SEPARATOR__/","",$name);
349           $val= "__SEPARATOR__".preg_replace("/_.*$/","",$n);
350         }else{
351           $n = preg_replace("/DelApp_/","",$name);
352           $val= preg_replace("/_.*$/","",$n);
353         }
355         foreach($this->gosaMemberApplication as $key =>  $cat){
356           foreach($cat as $key2 => $app){
357             if($app['App'] == $val){
358               unset($this->gosaMemberApplication[$key][$key2]);
359               if(isset($this->used_apps[$val])){
360                 unset($this->used_apps[$val]);
361               }
362             }
363           }
364         }
365       }
366   
367       if(preg_match("/DelCat_/",$name)){
368         $n = preg_replace("/DelCat_/","",$name);
369         $app = base64_decode( preg_replace("/_.*$/","",$n));
370         foreach($this->Categories as $key =>  $cat){
371           if($cat == $app){
372             foreach($this->Categories as $p => $n){
373               if(preg_match("/^".$key."\/.*/",$p)){
374                 unset($this->Categories[$p]);    
375               }
376             }
377             unset($this->Categories[$key]);
378           }
379         }
380       }
381       $only_once = true; 
382       if((preg_match("/EdiApp_/",$name))&&($only_once)){
384         $only_once = false;
385         $appname = $value;
386         $appname = preg_replace("/EdiApp_/","",$name);  
387         $appname = preg_replace("/_.*$/","",$appname);
388         /* We've got the appname, get parameters from ldap */
389         $ldap= $this->config->get_ldap_link();
390         $ldap->cd($this->config->current['BASE']);
391         $ldap->search("(&(objectClass=gosaApplication)(cn=$appname))");
392         if ($ldap->count() != 1){
393           print_red (_("The selected application name is not uniq. Please check your LDAP."));
394         } else {
395           $attrs= $ldap->fetch();
396           if(isset($attrs['gosaApplicationParameter'])){
397             $this->dialog= TRUE;
399             /* Fill name and value arrays */
400             for ($i= 0; $i<$attrs['gosaApplicationParameter']['count']; $i++){
401               $option= preg_replace('/^[^:]+:/', '',
402                   $attrs['gosaApplicationParameter'][$i]);
403               $name= preg_replace('/:.*$/', '', 
404                   $attrs['gosaApplicationParameter'][$i]);
405               $this->option_name[$i]= $name;
407               /* Fill with values from application, default should be
408                  loaded by the external scripts */
409               if (isset($this->appoption[$name])){
410                 $this->option_value[$i]= $this->appoption[$name];
411               }
412             }
414             /* Create edit field */
415             $table= "<table summary=\"\">";
416             for ($i= 0; $i < count($this->option_name); $i++){
417               if (isset($this->option_value[$i])){
418                 $value= $this->option_value[$i];
419               } else {
420                 $value= "";
421               }
422               $table.="<tr><td>".$this->option_name[$i]."</td><td>".
423                 "<input name=\"value$i\" size=60 maxlength=250 ".
424                 "value=\"".$value."\"><br></td></tr>";
425             }
426             $table.= "</table>";
427             $this->table= $table;
428           } else {
429             print_red (_("The selected application has no options."));
430           }
431         }
432       }
433     }
434     $this->reload();
435     /* Add group with post */
436     if((isset($_GET['act']))&&($_GET['act']=="add")){
437       $this->used_apps[$_GET['id']]= $_GET['id'];
438       asort($this->used_apps);
439       $this->addApp($_GET['id']);
440     }
442     /* Add multiple */
443     if(isset($_POST['AddApps'])){
444       foreach($_POST as $name => $value){
445         if(preg_match("/AddApp_/",$name)){
446           $app = preg_replace("/AddApp_/","",$name);
447           $this->addApp($app);
448         }
449       }
450     }
453     /* Cancel edit options? */
454     if (isset($_POST['edit_options_cancel'])){
455       $this->dialog= FALSE;
456     }
458     /* Finish edit options? */
459     if (isset($_POST['edit_options_finish'])){
460       $this->dialog= FALSE;
462       /* Save informations passed by the user */
463       $this->option_value= array();
464       for ($i= 0; $i<count($this->option_name); $i++){
465         $this->appoption[$this->option_name[$i]]= $_POST["value$i"];
466         $this->is_modified= TRUE;
467       }
468     }
470     /* Prepare templating stuff */
471     $smarty= get_smarty();
472     $smarty->assign("used_apps", $this->used_apps);
473     $apps= array();
474     foreach ($this->apps as $key => $value){
475       if (!array_key_exists($key, $this->used_apps)){
476         $apps["$key"]= "$value";
477       }
478     }
480     $div = new DivSelectBox("appgroup");    
482     $div->SetHeight(400);
484     /* NEW LIST MANAGMENT
485      * We also need to search for the departments
486      * So we are able to navigate like in konquerer
487      */
489     $ldap = $this->config->get_ldap_link();
490     $ldap->cd($this->curbase) ;
491     $ldap->ls("(objectClass=gosaDepartment)"); 
492     $departments= array();
493     $tmp = array();
494     while ($value = $ldap->fetch()){
495       $tmp[strtolower($value['dn']).$value['dn']]=$value;
496     }
497     ksort($tmp);
498     foreach($tmp as $value){
499       if($value["description"][0]!=".."){
500         $departments[$value['dn']]=convert_department_dn($value['dn'])." - [".$value["description"][0]."]";
501       }else{
502         $departments[$value['dn']]=convert_department_dn($value['dn']);
503       }
504     }
506     /* END NEW LIST MANAGMENT
507      */
509     $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=depopen&amp;depid=%s'>%s</a>";
510     $linkadd  = "<a href='?plug=".$_GET['plug']."&amp;act=add&amp;id=%s'>%s</a>";
512     $base_back = preg_replace("/^[^,]+,/","",$this->curbase);
513     if((strlen($base_back)>= strlen($this->config->current['BASE']))&&($this->curbase!=$this->config->current['BASE'])){
514       $div->AddEntry(array(
515             array("string"=>sprintf($linkopen,base64_encode($base_back),".. ["._("back")."]"),
516               "attach"=>"style='border:0px;'")
517             ));
518     }
519     foreach($departments as $key => $app){
520       $div->AddEntry(array(
521             array("string"=>"<img src='images/folder.png' alt='"._("department")."'>&nbsp;".sprintf($linkopen,base64_encode($key),$app),
522               "attach"=>"style='border:0px;'")
523             ));
524     }
526     foreach($apps as $key => $app){
527       $div->AddEntry(array(
528             array("string"=>sprintf("<input type='checkbox' value='1' name='AddApp_%s'>",$key).
529               "<img src='images/select_application.png' alt='"._("application")."'>&nbsp;".sprintf($linkadd,$key,$app),
530               "attach"=>"style='border:0px;'")
531             ));
532     }
534     if((isset($_GET['act']))&&(($_GET['act'] == "cat_up")||($_GET['act']=="cat_down"))){
535       if($_GET['act']=="cat_up"){
536         $this->catUp(base64_decode($_GET['id']));
537       }
538       if($_GET['act']=="cat_down"){
539         $this->catDown(base64_decode($_GET['id']));
540       }
541     }
543     if((isset($_GET['act']))&&(($_GET['act'] == "one_up")||($_GET['act']=="one_down"))){
544       if(isset($_GET['id'])){
545         $id   = $_GET['id'];
546         $act  = $_GET['act']; 
548         if($act == "one_up"){
549           $this->getOneUp($id);
550         }elseif($act == "one_down")   { 
551           $this->getOneDown($id);
552         }
553       }
554     }
556     $div2 = new DivSelectBox("appgroup");
557     $div2->SetHeight(400);
559     $linkopen       = "<img src='images/folder.png' alt=\"\">&nbsp;<a href='?plug=".$_GET['plug']."&amp;act=open&amp;id=%s'>%s</a>";
560     $catremove      = "&nbsp;<input type='image' src='images/edittrash.png' title='"._("Delete entry")."' name='DelCat_%s' value='%s'>";
561     $app            = "<img src='images/select_application.png' alt=\"\">&nbsp;%s";
562     
563     $catupdown        = "<a href='?plug=".$_GET['plug']."&amp;act=cat_up&amp;id=%s'>
564                        <img align='top' alt=\"\" src='images/sort_up.png' border=0 title='"._("Move up")."'></a>&nbsp;<a href='?plug=".$_GET['plug']."&amp;act=cat_down&amp;id=%s'> 
565                        <img alt=\"\" src='images/sort_down.png' title='"._("Move down")."' border=0></a>";
567     if(empty($this->curCatDir)){
568       $cnt =0;
569     }else{
570       $cnt = count(split("/",$this->curCatDir));
571       $tmp = split("/",$this->curCatDir);
572       $bbk = "";
573       for($i = 0 ; $i < ($cnt -1 ) ; $i++){
574         $bbk .= $tmp[$i];
575       }
576       $div2 ->AddEntry(array(array("string"=>sprintf($linkopen,$bbk,"..")),array("string"=>"&nbsp;","attach"=>"style='border-right:0px;'")));
577     }
579     $this->GetSubdirs($this->curCatDir);
581     foreach($this->GetSubdirs($this->curCatDir) as $path => $name){
582       $div2 ->AddEntry(array( 
583             array("string"=>sprintf($linkopen,base64_encode($path),$name)),
584             array("string"=>preg_replace("/%s/",base64_encode($path),$catupdown.$catremove),
585               "attach"=>"align='right' style='width:80px;border-right:0px;'"))); 
586     }
588     /* Append entries */
590     $separator ="<hr size=1>"; 
592     $sep = "<input type='image' src='images/back.png' title='"._("Insert seperator")."' value='%s' name='AddSep_%s'>";
593   
594     $upudown ="<a href='?plug=".$_GET['plug']."&amp;act=one_up&amp;id=%s'>   <img alt='{t}sort{/t}' align='top' src='images/sort_up.png' title='"._("Move up")."' border=0></a>".
595       "&nbsp;<a href='?plug=".$_GET['plug']."&amp;act=one_down&amp;id=%s'> <img alt='{t}sort{/t}' src='images/sort_down.png' title='"._("Move down")."' border=0></a>".
596       "&nbsp;<input type='image' src='images/edittrash.png' title='"._("Delete entry")."' name='DelApp_%s' value='%s' alt='{t}delete{/t}' >";
597     $edit=      "&nbsp;<input type='image' src='images/edit.png' title='"._("Edit entry")."' name='EdiApp_%s' value='%s' alt='{t}edit{/t}' >";
599     if(isset($this->gosaMemberApplication[$this->curCatDir])){
600       foreach($this->gosaMemberApplication[$this->curCatDir] as $cat => $entry){
601         if(preg_match("/__SEPARATOR__/",$entry['App'])){
602           $div2 ->AddEntry(array(array("string"=>$separator),
603                 array("string"=>preg_replace("/\%s/",htmlentities($entry['App']),$upudown),"attach"=>"align='right' style='border-right:0px;'")));
604         }else{
605           $div2 ->AddEntry(array(array("string"=>sprintf($app,$entry['App'])),
606                 array("string"=>preg_replace("/\%s/",htmlentities($entry['App']),$sep.$edit.$upudown),"attach"=>"align='right' style='border-right:0px;'")));
607         }
608       }
609     }
611     $smarty->assign("UsedApps", $div2->DrawList());
612     $smarty->assign("List", $div->DrawList());
613     $smarty->assign("apps", $apps);
615     /* Show main page */
616     if ($this->dialog){
617       $smarty->assign("table", $this->table);
618       $display.= $smarty->fetch (get_template_path('application_options.tpl', TRUE));
619     } else {
620       $display.= $smarty->fetch (get_template_path('application.tpl', TRUE));
621     }
622     return ($display);
623   }
626   function remove_from_parent()
627   {
628     plugin::remove_from_parent();
630     $this->attrs["gosaMemberApplication"]= array();
632     $ldap= $this->config->get_ldap_link();
633     $ldap->cd($this->dn);
634     $ldap->modify($this->attrs);
635     show_ldap_error($ldap->get_error());
637     /* Optionally execute a command after we're done */
638     $this->handle_post_events("remove");
639   }
642   /* Save to LDAP */
643   function save()
644   {
645     plugin::save();
647     /* Copy members */
648     $this->Categories[""]=""; 
649     $this->attrs["gosaMemberApplication"]= array();
650     $cats = array();
651     foreach($this->Categories as $name => $cats){
652       $cats[$name] =0;
653       if(isset($this->gosaMemberApplication[$name])){
654         foreach($this->gosaMemberApplication[$name] as $entry){
655           if(!preg_match("/__SEPARATOR__/",$entry['App'])){
656             $this->attrs["gosaMemberApplication"][]= $entry['App']."|".$name."|".$cats[$name];
657           }
658           $cats[$name] = $cats[$name] + 1;
659         }
660       }
661       if(($cats[$name]==0)&&(!empty($name))){
662         $this->attrs["gosaMemberApplication"][]= "|".$name."|".$cats[$name];
663       }
664     }
666     /* Are there application parameters to be saved */
667     $this->attrs['gosaApplicationParameter']= array();
668     foreach($this->appoption as $name => $value){
669       if ($value != ""){
670         $this->attrs['gosaApplicationParameter'][]= "$name:$value";
671       }
672     }
674     /* Write back to LDAP */
675     $ldap= $this->config->get_ldap_link();
676     $ldap->cd($this->dn);
677     $ldap->modify($this->attrs);
678     show_ldap_error($ldap->get_error());
680     /* Optionally execute a command after we're done */
681     if ($this->initially_was_account == $this->is_account){
682       if ($this->is_modified){
683         $this->handle_post_events("mofify");
684       }
685     } else {
686       $this->handle_post_events("add");
687     }
689   }
691   function check()
692   {
693     $message= array();
694     return ($message);
695   }
698   function reload()
699   {
700     /* Generate applist */
701     $this->apps= array();
702     $ldap= $this->config->get_ldap_link();
703     $ldap->cd ("ou=apps,".$this->curbase);
705     $ldap->ls ("(objectClass=gosaApplication)","ou=apps,".$this->curbase);
706     while ($attrs= $ldap->fetch()){
707       if (isset($attrs["description"][0])){    
708         $this->apps[$attrs["cn"][0]]=
709           $attrs["cn"][0]." (".
710           $attrs["description"][0].")";
711       } else {
712         $this->apps[$attrs["cn"][0]]=
713           $attrs["cn"][0];
714       }
715     }
716     natcasesort ($this->apps);
717     reset ($this->apps);
719     if(is_array($this->gosaMemberApplication))
720       foreach ($this->gosaMemberApplication as $cat){   
721         if(is_array($cat))
722           foreach($cat as $entry){
723             $this->used_apps[$entry['App']]= $entry['App'];
724           }
725       }
726   }
729   function addApp($cn)
730   {
731     if((isset($this->gosaMemberApplication[$this->curCatDir]))&&(is_array($this->gosaMemberApplication[$this->curCatDir]))){
732       foreach($this->gosaMemberApplication[$this->curCatDir] as $entry){
733         if($entry['App'] == $cn) return;
734       }
735     }
736     $this->gosaMemberApplication[$this->curCatDir][]= array("App"=>$cn);
737     $this->used_apps[$cn]=$cn;
738     $this->is_modified= TRUE;
739   }
742   function removeApp($cn)
743   {
744     $temp= array();
745     foreach ($this->gosaMemberApplication as $value){
746       if ($value != $cn){
747         $temp[]= $value;
748       }
749     }
750     $this->gosaMemberApplication= $temp;
751     $this->is_modified= TRUE;
752   }
754   function GetSubdirs($dir)
755   {
756     $ret = array();
757     $tmp1 = split("/",$this->curCatDir);
758  
759     foreach($this->Categories as $path=>$cat){
760       $tmp2 = split("/",$path);
761       
762       if((empty($this->curCatDir))&&(!preg_match("/\//",$path))){
763         $abort = false;
764       }elseif(((count($tmp1))+1) == (count($tmp2))){
765         $abort = false;
766         for($i = 0 ; $i < count($tmp1) ; $i++){
767           if($tmp1[$i] != $tmp2[$i]){
768             $abort = true;
769           }
770         }
771       }else{
772         $abort= true;
773       }
774       if(!$abort){
775         $ret[$path]=$cat;
776       } 
777     }
778   return($ret);
779   }
783 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
784 ?>