Code

71ba96fb25d5561832a80e0cc940dfd24d6306f1
[gosa.git] / gosa-plugins / goto / admin / groups / apps / class_groupApplication2.inc
1 <?php
2 class appgroup2 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");
10   var $config;
11   var $curbase;
13   /* Contains the menu structure in an array.
14    */
15   var $a_Structure= array();
16   var $a_Structure_on_load = array();
17   var $Releases;
18   var $FAIrelease = 0;
19   var $apps = array();
20   var $_cache = array();
22   var $app_parameter = array();
23   var $edit_entry    = array();
25   public function __construct(&$config, $dn= NULL, $parent= NULL)
26   {
27     plugin::plugin($config,$dn,$parent);
28     $this->dn = $dn; 
29     $this->_load_menu_structure();
30     $this->a_Structure_on_load = $this->a_Structure;
32     /* Check if we have relase mangement enabled and prepare group application for release management */
33     $tmp = $config->search("faiManagement", "CLASS",array('menu','tabs'));
34     if(!empty($tmp)){
35       $this->enableReleaseManagement = true;
36     }
38     /* Get required release informations */
39     if($this->enableReleaseManagement){
40       $this->Releases   = $this->getReleases();
41 #      $this->FAIrelease = 0;
42     }
43 #    $this->curbase = $this->config->current['BASE'];
44     $this->reload();
45   }
48   function reload()
49   {
50     $ret = array();
51     $release_info = $this->Releases[$this->FAIrelease];
53     if(!isset($this->_cache['ReleaseApps'][$release_info['suffix']])){
55       $ldap = $this->config->get_ldap_link();
56       $ldap->cd($this->config->current['BASE']);
57       $ldap->search("ou=apps",array("dn"));
58       $app_deps = array();
59       while($attrs = $ldap->fetch()){
60         $app_deps[] = $attrs['dn'];
61       }
63       foreach($app_deps as $dep){
64         $ldap->cd($dep);
65         $ldap->search("objectClass=FAIbranch",array("dn"));
66         while($attrs = $ldap->fetch()){
67           $app_deps[] = $attrs['dn'];
68         }
69       }
71       foreach($app_deps as $dep){
72         if(preg_match("/^".normalizePreg($release_info['suffix'])."/",$dep)){
73           $ret = array_merge($ret,get_list("(objectClass=gosaApplication)","application",$dep,array("*"),GL_NONE));
74         }
75       }
76       $this->_cache['ReleaseApps'][$release_info['suffix']] = $ret;
77     } 
78     $this->apps = $this->_cache['ReleaseApps'][$release_info['suffix']];
79   }
81   
82   
85   function getReleases()
86   {
87     /* Only display those releases that we are able to read */
88     $dn     = $this->config->current['BASE'];
89     $filter = "(&(objectClass=organizationalUnit)(objectClass=FAIbranch))";
90     $res    = get_list($filter,"application", $dn, array("ou","FAIstate"), GL_SUBSEARCH);
92     $ret =array(array("name" => "/" , "parts" => array(),"suffix" => get_ou('applicationou')));
93     foreach($res as $attrs){
94       if(preg_match("/".get_ou('applicationou')."/",$attrs['dn'])){
95         $bb     = preg_replace("/".get_ou('applicationou').".*/","",$attrs['dn']);
96         $parts  = array_reverse(split("ou=",$bb));
98         $str ="";
99         foreach($parts as $key => $part){
100           if(empty($part)) {
101             unset($parts[$key]);
102             continue;
103           }
104           $part = str_replace(",","",$part);
105           $str .= $part."/";
106           $parts[$key] = $part;
107         }
108         $name = preg_replace("/\/$/","",$str);
109         if(empty($name)) {
110           $name ="/";
111         }
112         $FAIstate = "";
113         if(isset($attrs['FAIstate'])){
114           $FAIstate = $attrs['FAIstate'][0];
115         }
116         
117         $ret[] = array("name"     => $name, 
118                        "FAIstate" => $FAIstate,
119                        "dn"       => $attrs['dn'], 
120                        "parts"    => $parts,"suffix" => $bb.get_ou('applicationou'));
121       }
122     }
123     return($ret);
124   }
127   function _load_menu_structure()
128   {
129     $this->a_Structure  = array();
130     $ldap = $this->config->get_ldap_link();
131     $ldap->cd($this->dn);
132     $ldap->search("(|(objectClass=gotoSubmenuEntry)(objectClass=FAIbranch)(objectClass=gotoMenuEntry))",array("*"));
134     $base =  array();
135     $base['UNIQID'] = uniqid();
136     $base['PARENT'] = 0; 
137     $base['NAME']   = "";
138     $base['TYPE']   = "BASE";
139     $base['ENTRIES']= array();
140     $base['STATUS'] = "LOADED";
141     
142     $this->a_Structure[0] = $base;
144     while($attrs = $ldap->fetch()){
145       $cur = &$this->a_Structure[0]['ENTRIES'];
146       $parent_id    = $base['UNIQID'];
147       $sub_dn       = preg_replace("/,".normalizePreg($this->dn)."$/","",$attrs['dn']);
148       $sub_dn_array = split("\,",$sub_dn);
151       for($i = (count($sub_dn_array)-1) ; $i >= 0 ; $i--){
152         $name = preg_replace("/^[^=]*+=/","",$sub_dn_array[$i]);
153         if($i > 0){
154           foreach($cur as $key => $entry){
155             if($entry['NAME'] == $name){
156               $cur = &$cur[$key]['ENTRIES'];
157               $parent_id = $entry['UNIQID'];
158             }
159           }
160         }else{
162           $priority = 1;
163           if(isset($attrs['gosaApplicationPriority'])){
164             $priority= $attrs['gosaApplicationPriority'][0];
165           }
166           while(isset($cur[$priority])){
167             $priority ++;
168           }
170           $data = array();
171           if(in_array("gotoSubmenuEntry",$attrs['objectClass'])){
172             $type = "FOLDER";
174             $data['ICON'] = "";
175             if(isset($attrs['gosaApplicationIcon'])){
176               $data['ICON'] = $ldap->get_attribute($attrs['dn'],"gosaApplicationIcon");
177             }
179           }elseif(in_array("gotoMenuEntry",$attrs['objectClass'])){
180             $type = "ENTRY";
181             $data['PARAMETER'] = array();
182             if(isset($attrs['gosaApplicationParameter'])){
183               for($p = 0 ; $p < $attrs['gosaApplicationParameter']['count'] ; $p ++){
184                 $tmp = split(":",$attrs['gosaApplicationParameter'][$p]);
185                 $data['PARAMETER'][$tmp[0]] = $tmp[1];
186               }
187             }
188           }elseif(in_array("FAIbranch",$attrs['objectClass'])){
189             $type = "RELEASE";
190             if(isset($attrs['FAIstate'][0])){
191               $data['FAIstate'] = $attrs['FAIstate'][0];
192             }else{
193               $data['FAIstate'] = "";
194             }
195           }
197           $data['DN']       = $attrs['dn'];
198           $data['NAME']     = $name;
199           $data['TYPE']     = $type;
200           $data['PRIORITY'] = $priority;
201           $data['ENTRIES']  = array();
202           $data['UNIQID']   = uniqid();
203           $data['PARENT']   = $parent_id;
204           $data['STATUS']   = "LOADED";
205           $cur[$priority]   = $data;
206           ksort($cur);
207         }
208       }
209     }
210   } 
213   function execute()
214   {
215     /* Call parent execute */
216     plugin::execute();
218     if(isset($_GET['r']))
219     $this->__construct($this->config,$this->dn);
221     if(count($this->edit_entry)){
222       if($this->edit_entry['TYPE'] == "ENTRY"){
223         $smarty = get_smarty();
224         $smarty->assign("type", "ENTRY");
225         $smarty->assign("entry",$this->edit_entry);
226         $smarty->assign("paras",$this->app_parameter);
227         $display= $smarty->fetch (get_template_path('edit_entry.tpl', TRUE, dirname(__FILE__)));
228         return($display);
229       }
230       if($this->edit_entry['TYPE'] == "FOLDER"){
231         $smarty = get_smarty();
233         session::set("binarytype" , "image/jpeg");
234         session::set("binary" , $this->edit_entry['ICON']);
235   
236         $smarty->assign("rand", microtime(TRUE));
237         $smarty->assign("image_set" , strlen($this->edit_entry['ICON']) > 0); 
238         $smarty->assign("type", "FOLDER");
239         $smarty->assign("entry",$this->edit_entry);
240         $display= $smarty->fetch (get_template_path('edit_entry.tpl', TRUE, dirname(__FILE__)));
241         return($display);
242       }
243     }
245     $smarty = get_smarty();
247     /* Create application list */
248     $div = new divSelectBox("appgroup");
249     $div->SetHeight(300);
250     $departments = array();
251     $res = get_list("(objectClass=gosaDepartment)", "application", $this->curbase,array("description","cn","ou"),GL_SIZELIMIT);
252     foreach($res as $value){
253       $fdn = $value['dn'];
254       $fdn = preg_replace("/".normalizePreg($this->curbase)."/","",$fdn);
255       $fdn= @LDAP::fix($fdn);
256       if($value["description"][0]!=".."){
257         $departments[$value['dn']]= convert_department_dn($fdn)." - [".$value["description"][0]."]";
258       }else{
259         $departments[$value['dn']]=convert_department_dn($fdn)." ["._("Back")."]";
260       }
261     }
263     $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=depopen&amp;depid=%s'>%s</a>";
265     /* Create base back entry */
266     $base_back = preg_replace("/^[^,]+,/","",$this->curbase);
267     if((strlen($base_back)>= strlen($this->config->current['BASE']))&&($this->curbase!=$this->config->current['BASE'])){
268       $div->AddEntry(array(
269             array("string"=>sprintf($linkopen,base64_encode($base_back),".. ["._("back")."]"),
270               "attach"=>"style='border:0px;'")
271             ));
272     }
274     /* Append departments for current base */
275     foreach($departments as $key => $app){
276       $div->AddEntry(array(
277             array("string"=>"<img class='center' src='images/folder.png' alt='"._("department")."'>&nbsp;".sprintf($linkopen,
278                 base64_encode($key),$app),
279               "attach"=>"style='border:0px;'")
280             ));
281     }
283   
284     /* Add applications found on this base */
285     $used_apps = $this->_get_used_entry_name();
286     foreach($this->apps as $key => $app){
287       if(in_array($app['cn'][0],$used_apps)){
288         continue;
289       }
290       if(!preg_match("/".get_ou('applicationou').normalizePreg($this->curbase)."$/",$app['dn'])){
291         continue;
292       }
294       $name = $app['cn'][0];
295       if(isset($app['description'])){
296         $name .= "&nbsp;[".$app['description'][0]."]";
297       }
298       $div->AddEntry(array(
299             array("string"=>sprintf("<input class='center' type='checkbox' value='1' name='AddApp_%s'>",$key).
300               "<img class='center' src='images/select_application.png' alt='"._("application")."'>&nbsp;".$name,
301               "attach"=>"style='border:0px;'")
302             ));
303     }
305     
306     $smarty->assign("FAIrelease",$this->FAIrelease);
307     $smarty->assign("app_list",$div->DrawList());
308     $smarty->assign("releases",$this->Releases);
309     $smarty->assign("folders" , $this->_get_folder_names());
310     $entries = $this->_get_entries_for_release($this->FAIrelease);
311     $smarty->assign("entries",$entries);
312     $display= $smarty->fetch (get_template_path('app_list.tpl', TRUE, dirname(__FILE__)));
313     return($display);
314   }
316     
317   function _get_folder_names()
318   {
319     $data = $this->_get_entries_for_release($this->FAIrelease);
320     $ret = array("BASE" => ".");
321     foreach($data as $entry){
322       if($entry['TYPE'] == "FOLDER"){
323         $ret[$entry['UNIQID']] = $entry['NAME'];
324       }
325     }
326     return($ret);
327   }
329  
330   function _get_used_entry_name()
331   {
332     $data = $this->_get_entries_for_release($this->FAIrelease);
333     $ret = array();
334     foreach($data as $entry){
335       if($entry['TYPE'] == "ENTRY"){
336         $ret[] = $entry['NAME'];
337       }
338     }
339     return($ret);
340   }
342  
343   function _get_entries_for_release($release,$cur = NULL)
344   {
345     $all = $this->_get_all_entries();
346     $key = $this->_get_release_key($release);
347     if(isset($all[$key]) && count($all[$key]['ENTRIES'])){
348       $res = $this->_get_all_entries(TRUE,TRUE,&$all[$key]['ENTRIES']);
349       return($res);
350     } 
351     return(array());
352   }
355   function _save_entry_edit()
356   {
357     $all    = $this->_get_all_entries();
358     $entry  = $this->edit_entry;
359     $r_entry= &$all[$entry['UNIQID']];
361     if($entry['TYPE'] == "ENTRY"){
362       $r_entry['PARAMETER'] = $this->app_parameter;
363       $r_entry['STATUS'] = "EDITED";
364     }
365     if($entry['TYPE'] == "FOLDER"){
366       $r_entry['ICON']   = $this->edit_entry['ICON'];
367       $r_entry['STATUS'] = "EDITED";
368     }
369     $this->dialog = FALSE;
370     $this->edit_entry = array();
371   }
374   function _edit_entry_edit($id)
375   {
376     $all   = $this->_get_all_entries();
377     $entry = $all[$id];
379     $this->app_parameter = array();
380     if($entry['TYPE'] == "ENTRY"){
381       $found = FALSE;
382       foreach($this->apps as $id => $app){
384         if($app['cn'][0] == $entry['NAME']){
385           $found = TRUE;
386           break;
387         }
388       }
389       if($found){
390       
391         /* Create a list of editable parameter */
392         if(isset($app['gosaApplicationParameter'])){
393           for($i = 0 ; $i < $app['gosaApplicationParameter']['count'] ; $i++) {
394             $para = $app['gosaApplicationParameter'][$i];
395             $tmp  = split(":",$para);
396             $this->app_parameter[$tmp[0]] = $tmp[1];
397           }
398         }
400         /* Overwrite parameters with entry parameters */
401         foreach($entry['PARAMETER'] as $name => $value){
402           $this->app_parameter[$name] = $value;
403         }
404         
405         $this->dialog = TRUE;
406         $this->edit_entry = $entry;
407       }
408     }
410     if($entry['TYPE'] == "FOLDER"){
411       $this->dialog = TRUE;
412       $this->edit_entry = $entry;
413     }
414   }
417   function remove_from_parent()
418   {
419   }
423   function check()
424   {
425   }
428   function _check_missing_release($release)
429   {
430     $release_info = $this->Releases[$release];
432     $parent_id = $this->a_Structure[0]['UNIQID'];
433     $cur = &$this->a_Structure[0]['ENTRIES'];
434     for($i = 0 ; $i < count($release_info['parts']) ; $i ++){
435       $part = $release_info['parts'][$i];
436       $found = FALSE;
437       foreach($cur as $key => $name){
438         if($name['NAME'] == $part){
439           $parent_id = $cur[$key]['UNIQID'];
440           $cur = &$cur[$key]['ENTRIES'];
441           
442           $found =TRUE;
443           break;
444         }
445       }
446       if(!$found){
447         $release           =  array();
448         $release['UNIQID'] = uniqid();
449         $release['PARENT'] = $parent_id;
450         $release['NAME']   = $part;
451         $release['TYPE']   = "RELEASE";
452         $release['ENTRIES']= array();
453         $release['STATUS']   = "ADDED";
454         $release['FAIstate'] =  $release_info['FAIstate'];
455         $cur[] = $release;
456         $i --;
457       }
458     }
459   }
462   /* !\brief Handle ui POSTS, like sort up/down/delete
463    */ 
464   function save_object()
465   {
466     foreach($_POST as $name => $value){
467       if(preg_match("/del_/",$name)){
468         $id = preg_replace("/^del_/","",$name);
469         $id = preg_replace("/_(x|y)$/","",$id);
470         $this->_remove_entry_id($id);
471         break;
472       }
473       if(preg_match("/app_entry_edit/",$name)){
474         $id = preg_replace("/^app_entry_edit/","",$name);
475         $id = preg_replace("/_(x|y)$/","",$id);
476         $this->_edit_entry_edit($id);
477         break;
478       }
479       if(preg_match("/up_/",$name)){
480         $id = preg_replace("/^up_/","",$name);
481         $id = preg_replace("/_(x|y)$/","",$id);
482         $this->_move_entry_up($id);
483         break;
484       }
485       if(preg_match("/down_/",$name)){
486         $id = preg_replace("/^down_/","",$name);
487         $id = preg_replace("/_(x|y)$/","",$id);
488         $this->_move_entry_down($id);
489         break;
490       }
491       if(preg_match("/^parameter_/",$name) && 
492         count($this->edit_entry) && $this->edit_entry['TYPE'] == "ENTRY"){
493         $name = preg_replace("/^parameter_/","",$name);
494         $this->app_parameter[$name] = $value;
495       }
496     }
497     if(isset($_POST['FAIrelease'])){
498       $this->FAIrelease = $_POST['FAIrelease'];
499       $this->_check_missing_release($this->FAIrelease);
500     }
501     if(isset($_GET['act']) && $_GET['act'] == 'depopen'){
502       $this->curbase = base64_decode($_GET['depid']);
503     }
504     if(isset($_POST['add_to_folder']) && isset($_POST['folder'])){
505       $folder = $_POST['folder'];
506       foreach($_POST as $name => $value){
507         if(preg_match("/^AddApp_[0-9]*$/",$name)){
508           $this->_add_app_id($folder,preg_replace("/^AddApp_/","",$name));   
509         }
510       }
511     }
512     if(isset($_POST['add_menu_to_folder']) && isset($_POST['menu_folder'])){
513       $folder = $_POST['menu_folder'];
514       $name = $_POST['menu_folder_name'];
515       if(strlen($name) > 0 && preg_match("/[a-z ]/i",$name)){
516         $this->_add_sub_folder($folder,$name);
517       }
518     }
519     if(isset($_POST['app_entry_save'])){ 
520       $this->_save_entry_edit();
521     }
523     if(isset($_FILES['folder_image']) && isset($_POST['folder_image_upload'])){
524       if($_FILES['folder_image']['error'] == 0 && $_FILES['folder_image']['size'] > 0){
525         $this->edit_entry['ICON'] = file_get_contents($_FILES['folder_image']['tmp_name']);
526       }
527     }
529     if(isset($_POST['app_entry_cancel'])){
530       $this->edit_entry = array();
531       $this->dialog = FALSE;
532     }
533     $this->reload();
534   }
536   
537   function _get_release_key($release,$add_if_missing = FALSE)
538   {
539     $release_info = $this->Releases[$release];
541     if($release_info['name'] == "/"){
542       return($this->a_Structure['0']['UNIQID']);
543     }
545     $cur = &$this->a_Structure[0]['ENTRIES'];
546     $s_key = "";
547     $found = FALSE;
548     foreach($release_info['parts'] as $name){
549       foreach($cur as $key => $obj){
550         if($obj['TYPE'] == "RELEASE" && $obj['NAME'] == $name){
551           $s_key = $cur[$key]['UNIQID'];
552           $cur = &$cur[$key]['ENTRIES'];
553           $found = TRUE;
554           break;
555         }
556         $found = FALSE;
557       }
558     }
559     if($found){
560       return($s_key);  
561     }  
562     return(FALSE);
563   }
565   
566   function _add_sub_folder($folder,$name)
567   {
568     $all = $this->_get_all_entries();
569     if($folder == "BASE"){
570       $folder = $this->_get_release_key($this->FAIrelease,TRUE);
571     }
572     
573     if(isset($all[$folder])){
574       $a_folder = array();
575       $a_folder['STATUS'] = "ADDED";
576       $a_folder['NAME']   = $name;
577       $a_folder['UNIQID'] = uniqid();
578       $a_folder['PARENT'] = $folder;      
579       $a_folder['TYPE']   = "FOLDER";
580       $all[$folder]['ENTRIES'][] = $a_folder;
581     }
582   }
585   /* !\brief Remove the given id from the menu structure.
586       @param  String  ID to of the entry we want to remove.
587       @return Boolean TRUE on success
588    */
589   function _remove_entry_id($id)
590   {
591     $all = $this->_get_all_entries();
592     if(isset($all[$id])){
593       $all[$id]['STATUS'] = "REMOVED";
594       return(TRUE);
595     }
596     return(FALSE);
597   }
599   
600   /* !\brief Remove the given id from the menu structure.
601       @param  String  ID to of the entry we want to remove.
602       @return Boolean TRUE on success
603    */
604   function _add_entry($folder_id,$entry,$pos = 0)
605   {
606     $all = $this->_get_all_entries();
608     if(isset($all[$folder_id])){
610       $folder  = &$all[$folder_id];
611       $entries = $entry['ENTRIES'];
613       $entry['UNIQID'] = uniqid();     
614       $entry['PARENT'] = $folder_id;
615       $entry['ENTRIES']= array();
616       $entry['STATUS'] = "ADDED";
617       
618       $cnt = 0; 
619       $new = array();
620       $added =FALSE;
621       foreach($folder['ENTRIES'] as $key => $obj){
622         if($pos == $cnt){
623           $new[] = $entry;
624           $added = TRUE;
625           $cnt ++;
626         }
627         $new[] = $obj;
628       }
629       if(!$added){
630         $new[] = $entry;
631       }
632       $all[$folder_id]['ENTRIES'] = $new;
633       foreach($entries as $sub){
634         $this->_add_entry($entry['UNIQID'],$sub);
635       }
636       return(TRUE);
637     }
638     return(FALSE);
639   }
641   
642   function _add_app_id($folder_id,$app_id)
643   {
644     $all = $this->_get_all_entries();
645     if($folder_id == "BASE"){
646       $folder_id = $this->_get_release_key($this->FAIrelease);
647     }
648     if(isset($all[$folder_id]) && isset($this->apps[$app_id])){
650       $new = array();
651       $new['TYPE']  = "ENTRY";
652       $new['NAME']  = $this->apps[$app_id]['cn'][0];
653       $new['UNIQID']= uniqid(); 
654       $new['PARENT']= $folder_id;
655       $new['STATUS']= "ADDED";
656       $all[$folder_id]['ENTRIES'][] = $new;
657     }
658   }
661   /*! \brief move the object identified by the given ID one position up.
662       @param  String  The ID of the entry to be moved.
663       @return Boolean TRUE on success, else FALSE;
664    */
665   function _move_entry_up($id)
666   {
667     $all = $this->_get_all_entries(TRUE);
668     $parent = FALSE;
669     foreach($all as $entry){
670       if(isset($entry['UNIQID']) && $entry['UNIQID'] == $id){
671         if($parent != FALSE){
672           return($this->__switch_entries($id,"up",$parent));
673         }
674       }else{
675         if(in_array($entry['TYPE'],array("CLOSE","OPEN"))){
676           $parent = $entry['PARENT'];
677         }else{
678           $parent = $entry['UNIQID'];
679         }
680       }
681     }
682     return(FALSE);
683   }
686   /*! \brief move the object identified by the given ID one position down.
687       @param  String  The ID of the entry to be moved.
688       @return Boolean TRUE on success, else FALSE;
689    */
690   function _move_entry_down($id)
691   {
692     $all = $this->_get_all_entries(TRUE);
693     $found = FALSE;
694     foreach($all as $entry){
695       if(isset($entry['UNIQID']) && $entry['UNIQID'] == $id){
696         $found = TRUE;
697         continue;
698       }else{
699         if(in_array($entry['TYPE'],array("CLOSE","OPEN"))){
700           $parent = $entry['PARENT'];
701         }else{
702           $parent = $entry['UNIQID'];
703         }
704         if($found){
705           return($this->__switch_entries($id,"down",$parent));
706         }
707       }
708     }
709     return(FALSE);
710   }
713   /*! \brief  Return all entries linear. 
714       @param  Boolean   $add_tags  If TRUE, OPEN/CLOSE Tags will be appended.
715       @param  &Array    Start here, Pointer to an array.
716    */ 
717   function _get_all_entries($add_tags = FALSE, $skip_release = FALSE, $cur = NULL)
718   {
719     $ret = array();
720     if($cur == NULL){
721       $cur = &$this->a_Structure;
722     }
723     foreach($cur as $key => $entry){
725       if($skip_release && $entry['TYPE'] == "RELEASE"){
726         continue;
727       }    
728       if($entry['TYPE'] == "ENTRY"){
729         $found = FALSE;
730         foreach($this->apps as $app){
731           if($app['cn'][0] == $entry['NAME']){
732             $found = TRUE;
733             if(isset($app['description'][0])){
734               $entry['INFO'] = "[".$app['description'][0]."]";
735             }
736             break;
737           }
738         } 
739         if(!$found){
740           $entry['INFO'] = "<font color='red'>"._("Not available in release.")."</font>";
741         }
742       }
743       
745       $tmp = $entry;
746       if(!$add_tags){
747         $ret[$tmp['UNIQID']] = &$cur[$key];
748         if(isset($entry['ENTRIES']) && count($entry['ENTRIES'])){
749           $ret = array_merge($ret,$this->_get_all_entries($add_tags,$skip_release,&$cur[$key]['ENTRIES']));
750         }
751       }else{
752       
753         if(isset($tmp['ENTRIES'])){
754           unset($tmp['ENTRIES']);
755         }
756         if($tmp['STATUS'] != "REMOVED"){
757           $ret[] = $tmp;
758           if(isset($entry['ENTRIES']) && count($entry['ENTRIES'])){
759             $add = false;
760             foreach($entry['ENTRIES'] as $entry){
761               if($entry['STATUS'] != "REMOVED"){
762                 $add = TRUE;
763                 break;
764               }
765             }
767             if($add){
768               $ret[] = array("TYPE" => "OPEN", "PARENT" => $entry['UNIQID']);
769               $ret = array_merge($ret,$this->_get_all_entries($add_tags,$skip_release,&$cur[$key]['ENTRIES']));
770               $ret[] = array("TYPE" => "CLOSE" , "PARENT" => $entry['UNIQID']);
771             }
772           }
773         }
774       }
775     }
776     return($ret);
777   }
780   /* !\brief Switch one entry with another 
781      @param  String  from  The source ID.
782      @param  String  type  "up"/"down" type switched.
783      @param  String  to    The destination ID.
784      return  Boolean TRUE on success 
785    */
786   function __switch_entries($from,$type,$to)
787   {
788     $all = $this->_get_all_entries();
790     $o_to   = &$all[$to];
791     $o_from = &$all[$from];
793     print_a($o_to,$o_from);
794   
795     /***********************
796      * Source == Destination 
797      * Move into next parent. 
798      ************************/
799     if($to == $from){
800       $to = $o_to['PARENT'];
801       $o_to   = &$all[$to];
802     }
804     /***********************
805      * Target is container 
806      ************************/
807     if(in_array($o_to['TYPE'],array("FOLDER","RELEASE"))){
809       /***********************
810        * Move into parent folder  
811        *   + Target 
812        *   |-> Source
813        ************************/
814       if($to == $o_from['PARENT']){
816  
817         /* Check if source is a folder object 
818          */
819         $o_to_sub = &$all[$o_to['PARENT']]; 
820         if(in_array($o_to_sub['TYPE'],array("FOLDER","RELEASE"))){
822           $o_from['STATUS'] = "ADDED";
824           /* Adding new */
825           $tmp2 = array();  
826           $cnt = 0; 
827           foreach($o_to_sub['ENTRIES'] as $key => $entry){
828             $cnt ++;
829             if($entry['UNIQID'] == $to){
830               break;
831             }
832           }
833           if($type == "up"){
834             $cnt --;
835  
836          }
837          $this->_add_entry($o_to_sub['UNIQID'],$o_from,$cnt);
839           /* Removing old */
840           $tmp = array();
841           if(!$this->_remove_entry_id($from)){
842             return(FALSE);
843           }
844         } 
845       }else{
847         /***********************
848          * Target is NOT parent container
849          *  + Parent Folder
850          *  |-> Source 
851          *  + Destination
852          ************************/
854         /* Removing old */
855         $o_to   = $all[$to];
856         $o_from = $all[$from];
857         $this->_add_entry($to,$o_from);
858         $this->_remove_entry_id($from);
859       }
860     }else{
862       /***********************
863        * Source and Destination in some Folder.
864        *  + Parent folder
865        *  |-> Source
866        *  |-> Destination
867        ************************/
868       $o_to   = &$all[$to];
869       $o_from = &$all[$from];
870       $parent = &$all[$o_to['PARENT']];
872       if($o_to['PARENT'] == $o_from['PARENT']){
873         $tmp = $all[$to];
874         $all[$to]   = $o_from;
875         $all[$from] = $tmp;
876   
877         /* Ensure that the app priority is updated */
878         foreach($parent['ENTRIES'] as $key => $entry){
879           $parent['ENTRIES'][$key]['STATUS'] = "EDITED";
880         }
881       }
882     }
883   }
886   function save()
887   {
888     $ldap = $this->config->get_ldap_link();
889     $all = $this->_get_all_entries();
890     $prio = 0;
891     $Actions = array("Remove" => array(),"Edit" => array() , "Add" => array());
893     foreach($all as $entry){
894       $prio ++;
895       $cur = $entry;
896       $dn = "";
898       do{  
899         if($cur['TYPE'] == "ENTRY"){
900           $dn.= "cn=".$cur['NAME'].",";
901         }elseif($cur['TYPE'] == "FOLDER"){
902           $dn.= "cn=".$cur['NAME'].",";
903         }elseif($cur['TYPE'] == "RELEASE"){
904           $dn.= "ou=".$cur['NAME'].",";
905         }elseif($cur['TYPE'] == "BASE"){
906         }
907         if(!isset($all[$cur['PARENT']])){
908           $cur = NULL;
909         }else{
910           $cur = $all[$cur['PARENT']];
911         }
912       }while(is_array($cur));
914       $cur_dn = $dn.$this->dn;
916       $attrs = array();
917       switch($entry['TYPE']){
918         case "ENTRY"    :
919         { 
920           $attrs['objectClass'] = "gotoMenuEntry";
921           $attrs['cn']          = $entry['NAME'];
922           $attrs['gosaApplicationPriority'] = $prio;
923           $attrs['gosaApplicationParameter'] = array(); 
924      
925           foreach($entry['PARAMETER'] as $name => $value){
926             $attrs['gosaApplicationParameter'][] = $name.":".$value; 
927           }
928         }
929         break;
930         case "FOLDER"   : 
931         { 
932           $attrs['objectClass'] = "gotoSubmenuEntry";
933           $attrs['cn']          = $entry['NAME'];
934           $attrs['gosaApplicationPriority'] = $prio;
935           $attrs['gosaApplicationIcon']     = $entry['ICON'];
936         }
937         break;
938         case "RELEASE"  : 
939         { 
940           $attrs['ou']            = $entry['NAME'];
941           $attrs['objectClass']   = array();
942           $attrs['objectClass'][] = "top";
943           $attrs['objectClass'][] = "organizationalUnit";
944           $attrs['objectClass'][] = "FAIbranch";
945           if(!empty($entry['FAIstate'])){
946             $attrs['FAIstate']      = $entry['FAIstate'];
947           }
948         }
949         break;
950       }
951   
952       if($entry['STATUS'] == "LOADED"){
953         continue;
954       }
955       if($entry['STATUS'] == "REMOVED"){
956         $Actions['Remove'][$cur_dn] = $cur_dn;
957       }
958       if($entry['STATUS'] == "EDITED"){
959         $Actions['Edit'][$cur_dn] = $attrs;
960       }
961       if($entry['STATUS'] == "ADDED"){
962         $Actions['Add'][$cur_dn] = $attrs;
963       }
964     }
966     $ldap = $this->config->get_ldap_link();
967     $ldap->cd($this->config->current['BASE']);
968     foreach($Actions['Remove'] as $dn){
969       $ldap->cd($dn);
970       $ldap->cat($dn);
971       if($ldap->count()){
972         $ldap->rmdir_recursive($dn);
973       }
974     }
975     foreach($Actions['Add'] as $dn => $data){
976       $ldap->cd($dn);
977       $ldap->cat($dn);
978       if(!$ldap->count()){
979         $ldap->add($data);
980       }
981     }
982     foreach($Actions['Edit'] as $dn => $data){
983       $ldap->cd($dn);
984       $ldap->cat($dn);
985       if($ldap->count()){
986         $ldap->modify($data);
987       }
988     }
989   }
992   /* Return plugin informations for acl handling  */ 
993   static function plInfo()
994   {
995     return (array(
996           "plShortName"   => _("Applications"),
997           "plDescription" => _("Group applications"),
998           "plSelfModify"  => FALSE,
999           "plDepends"     => array(),
1000           "plPriority"    => 0,
1001           "plSection"     => array("admin"),
1002           "plCategory"    => array("groups"),
1003           "plProvidedAcls"=> array(
1004             "gosaMemberApplication"     => _("Application"),
1005             "FAIrelease"                => _("Release"),
1006             "gosaApplicationParameter"  => _("Application parameter"))
1007           ));
1008   }
1011   function PrepareForCopyPaste($source)
1012   {
1013   }
1016   function multiple_save_object()
1017   {
1018     if(isset($_POST['group_apps_multi'])){
1019       $this->save_object(); 
1020       plugin::multiple_save_object();    
1021   
1022       /* Get posts */
1023       foreach(array("apps") as $attr){
1024         if(isset($_POST['use_'.$attr])) {
1025           $this->multi_boxes[] = $attr;
1026         }
1027       }
1028     }
1029   }
1030   
1032   function get_multi_edit_values()
1033   {
1034     $ret = plugin::get_multi_edit_values();
1036     if(in_array("apps",$this->multi_boxes)){
1037       $ret['gosaApplicationParameter'] = $this->gosaApplicationParameter;
1038       $ret['Categories']               = $this->Categories;
1039       $ret['gosaMemberApplication']    = $this->gosaMemberApplication;
1040       $ret['FAIrelease']               = $this->FAIrelease;
1041       $ret['appoption']                = $this->appoption;
1042     }
1043     return($ret);
1044   }
1046 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1047 ?>