97732898ebc2b3ae53cf0d33f0856b0ef6102bab
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 public function __construct(&$config, $dn= NULL, $parent= NULL)
23 {
24 plugin::plugin($config,$dn,$parent);
25 $this->dn = $dn;
26 $this->_load_menu_structure();
27 $this->a_Structure_on_load = $this->a_Structure;
29 /* Check if we have relase mangement enabled and prepare group application for release management */
30 $tmp = $config->search("faiManagement", "CLASS",array('menu','tabs'));
31 if(!empty($tmp)){
32 $this->enableReleaseManagement = true;
33 }
35 /* Get required release informations */
36 if($this->enableReleaseManagement){
37 $this->Releases = $this->getReleases();
38 # $this->FAIrelease = 0;
39 }
40 # $this->curbase = $this->config->current['BASE'];
41 $this->reload();
42 }
45 function reload()
46 {
47 $ret = array();
48 $release_info = $this->Releases[$this->FAIrelease];
50 if(!isset($this->_cache['ReleaseApps'][$release_info['suffix']])){
52 $ldap = $this->config->get_ldap_link();
53 $ldap->cd($this->config->current['BASE']);
54 $ldap->search("ou=apps",array("dn"));
55 $app_deps = array();
56 while($attrs = $ldap->fetch()){
57 $app_deps[] = $attrs['dn'];
58 }
60 foreach($app_deps as $dep){
61 $ldap->cd($dep);
62 $ldap->search("objectClass=FAIbranch",array("dn"));
63 while($attrs = $ldap->fetch()){
64 $app_deps[] = $attrs['dn'];
65 }
66 }
68 foreach($app_deps as $dep){
69 if(preg_match("/^".normalizePreg($release_info['suffix'])."/",$dep)){
70 $ret = array_merge($ret,get_list("(objectClass=gosaApplication)","application",$dep,array("*"),GL_NONE));
71 }
72 }
73 $this->_cache['ReleaseApps'][$release_info['suffix']] = $ret;
74 }
75 $this->apps = $this->_cache['ReleaseApps'][$release_info['suffix']];
76 }
79 function getReleases()
80 {
81 /* Only display those releases that we are able to read */
82 $dn = $this->config->current['BASE'];
83 $filter = "(&(objectClass=organizationalUnit)(objectClass=FAIbranch))";
84 $res = get_list($filter,"application", $dn, array("ou","FAIstate"), GL_SUBSEARCH);
86 $ret =array(array("name" => "/" , "parts" => array(),"suffix" => get_ou('applicationou')));
87 foreach($res as $attrs){
88 if(preg_match("/".get_ou('applicationou')."/",$attrs['dn'])){
89 $bb = preg_replace("/".get_ou('applicationou').".*/","",$attrs['dn']);
90 $parts = array_reverse(split("ou=",$bb));
92 $str ="";
93 foreach($parts as $key => $part){
94 if(empty($part)) {
95 unset($parts[$key]);
96 continue;
97 }
98 $part = str_replace(",","",$part);
99 $str .= $part."/";
100 $parts[$key] = $part;
101 }
102 $name = preg_replace("/\/$/","",$str);
103 if(empty($name)) {
104 $name ="/";
105 }
106 $FAIstate = "";
107 if(isset($attrs['FAIstate'])){
108 $FAIstate = $attrs['FAIstate'][0];
109 }
111 $ret[] = array("name" => $name,
112 "FAIstate" => $FAIstate,
113 "dn" => $attrs['dn'],
114 "parts" => $parts,"suffix" => $bb.get_ou('applicationou'));
115 }
116 }
117 return($ret);
118 }
121 function _load_menu_structure()
122 {
123 $this->a_Structure = array();
124 $ldap = $this->config->get_ldap_link();
125 $ldap->cd($this->dn);
126 $ldap->search("(|(objectClass=gotoSubmenuEntry)(objectClass=FAIbranch)(objectClass=gotoMenuEntry))",array("*"));
128 $base = array();
129 $base['UNIQID'] = uniqid();
130 $base['PARENT'] = 0;
131 $base['NAME'] = "";
132 $base['TYPE'] = "BASE";
133 $base['ENTRIES']= array();
134 $base['STATUS'] = "LOADED";
136 $this->a_Structure[0] = $base;
138 while($attrs = $ldap->fetch()){
139 $cur = &$this->a_Structure[0]['ENTRIES'];
140 $parent_id = $base['UNIQID'];
141 $sub_dn = preg_replace("/,".normalizePreg($this->dn)."$/","",$attrs['dn']);
142 $sub_dn_array = split("\,",$sub_dn);
145 for($i = (count($sub_dn_array)-1) ; $i >= 0 ; $i--){
146 $name = preg_replace("/^[^=]*+=/","",$sub_dn_array[$i]);
147 if($i > 0){
148 foreach($cur as $key => $entry){
149 if($entry['NAME'] == $name){
150 $cur = &$cur[$key]['ENTRIES'];
151 $parent_id = $entry['UNIQID'];
152 }
153 }
154 }else{
156 $priority = 1;
157 if(isset($attrs['gosaApplicationPriority'])){
158 $priority= $attrs['gosaApplicationPriority'][0];
159 }
160 while(isset($cur[$priority])){
161 $priority ++;
162 }
164 $data = array();
165 if(in_array("gotoSubmenuEntry",$attrs['objectClass'])){
166 $type = "FOLDER";
167 }elseif(in_array("gotoMenuEntry",$attrs['objectClass'])){
168 $type = "ENTRY";
169 }elseif(in_array("FAIbranch",$attrs['objectClass'])){
170 $type = "RELEASE";
171 if(isset($attrs['FAIstate'][0])){
172 $data['FAIstate'] = $attrs['FAIstate'][0];
173 }else{
174 $data['FAIstate'] = "";
175 }
176 }
178 $data['DN'] = $attrs['dn'];
179 $data['NAME'] = $name;
180 $data['TYPE'] = $type;
181 $data['PRIORITY'] = $priority;
182 $data['ENTRIES'] = array();
183 $data['UNIQID'] = uniqid();
184 $data['PARENT'] = $parent_id;
185 $data['STATUS'] = "LOADED";
186 $cur[$priority] = $data;
187 ksort($cur);
188 }
189 }
190 }
191 }
194 function execute()
195 {
196 /* Call parent execute */
197 plugin::execute();
199 if(isset($_GET['r']))
200 $this->__construct($this->config,$this->dn);
202 $smarty = get_smarty();
204 /* Create application list */
205 $div = new divSelectBox("appgroup");
206 $div->SetHeight(300);
207 $departments = array();
208 $res = get_list("(objectClass=gosaDepartment)", "application", $this->curbase,array("description","cn","ou"),GL_SIZELIMIT);
209 foreach($res as $value){
210 $fdn = $value['dn'];
211 $fdn = preg_replace("/".normalizePreg($this->curbase)."/","",$fdn);
212 $fdn= @LDAP::fix($fdn);
213 if($value["description"][0]!=".."){
214 $departments[$value['dn']]= convert_department_dn($fdn)." - [".$value["description"][0]."]";
215 }else{
216 $departments[$value['dn']]=convert_department_dn($fdn)." ["._("Back")."]";
217 }
218 }
220 $linkopen = "<a href='?plug=".$_GET['plug']."&act=depopen&depid=%s'>%s</a>";
222 /* Create base back entry */
223 $base_back = preg_replace("/^[^,]+,/","",$this->curbase);
224 if((strlen($base_back)>= strlen($this->config->current['BASE']))&&($this->curbase!=$this->config->current['BASE'])){
225 $div->AddEntry(array(
226 array("string"=>sprintf($linkopen,base64_encode($base_back),".. ["._("back")."]"),
227 "attach"=>"style='border:0px;'")
228 ));
229 }
231 /* Append departments for current base */
232 foreach($departments as $key => $app){
233 $div->AddEntry(array(
234 array("string"=>"<img class='center' src='images/folder.png' alt='"._("department")."'> ".sprintf($linkopen,
235 base64_encode($key),$app),
236 "attach"=>"style='border:0px;'")
237 ));
238 }
241 /* Add applications found on this base */
242 $used_apps = $this->_get_used_entry_name();
243 foreach($this->apps as $key => $app){
244 if(in_array($app['cn'][0],$used_apps)){
245 continue;
246 }
247 if(!preg_match("/".get_ou('applicationou').normalizePreg($this->curbase)."$/",$app['dn'])){
248 continue;
249 }
251 $name = $app['cn'][0];
252 if(isset($app['description'])){
253 $name .= " [".$app['description'][0]."]";
254 }
255 $div->AddEntry(array(
256 array("string"=>sprintf("<input class='center' type='checkbox' value='1' name='AddApp_%s'>",$key).
257 "<img class='center' src='images/select_application.png' alt='"._("application")."'> ".$name,
258 "attach"=>"style='border:0px;'")
259 ));
260 }
263 $smarty->assign("FAIrelease",$this->FAIrelease);
264 $smarty->assign("app_list",$div->DrawList());
265 $smarty->assign("releases",$this->Releases);
266 $smarty->assign("folders" , $this->_get_folder_names());
267 $entries = $this->_get_entries_for_release($this->FAIrelease);
268 $smarty->assign("entries",$entries);
269 $display= $smarty->fetch (get_template_path('app_list.tpl', TRUE, dirname(__FILE__)));
270 return($display);
271 }
274 function _get_folder_names()
275 {
276 $data = $this->_get_entries_for_release($this->FAIrelease);
277 $ret = array("BASE" => ".");
278 foreach($data as $entry){
279 if($entry['TYPE'] == "FOLDER"){
280 $ret[$entry['UNIQID']] = $entry['NAME'];
281 }
282 }
283 return($ret);
284 }
287 function _get_used_entry_name()
288 {
289 $data = $this->_get_entries_for_release($this->FAIrelease);
290 $ret = array();
291 foreach($data as $entry){
292 if($entry['TYPE'] == "ENTRY"){
293 $ret[] = $entry['NAME'];
294 }
295 }
296 return($ret);
297 }
300 function _get_entries_for_release($release,$cur = NULL)
301 {
302 $all = $this->_get_all_entries();
303 $key = $this->_get_release_key($release);
304 if(isset($all[$key]) && count($all[$key]['ENTRIES'])){
305 $res = $this->_get_all_entries(TRUE,TRUE,&$all[$key]['ENTRIES']);
306 return($res);
307 }
308 return(array());
309 }
312 function _edit_entry_edit($id)
313 {
314 }
317 function remove_from_parent()
318 {
319 }
323 function check()
324 {
325 }
328 function _check_missing_release($release)
329 {
330 $release_info = $this->Releases[$release];
332 $parent_id = $this->a_Structure[0]['UNIQID'];
333 $cur = &$this->a_Structure[0]['ENTRIES'];
334 for($i = 0 ; $i < count($release_info['parts']) ; $i ++){
335 $part = $release_info['parts'][$i];
336 $found = FALSE;
337 foreach($cur as $key => $name){
338 if($name['NAME'] == $part){
339 $parent_id = $cur[$key]['UNIQID'];
340 $cur = &$cur[$key]['ENTRIES'];
342 $found =TRUE;
343 break;
344 }
345 }
346 if(!$found){
347 $release = array();
348 $release['UNIQID'] = uniqid();
349 $release['PARENT'] = $parent_id;
350 $release['NAME'] = $part;
351 $release['TYPE'] = "RELEASE";
352 $release['ENTRIES']= array();
353 $release['STATUS'] = "ADDED";
354 $release['FAIstate'] = $release_info['FAIstate'];
355 $cur[] = $release;
356 print_a($release);
357 $i --;
358 }
359 }
360 }
363 /* !\brief Handle ui POSTS, like sort up/down/delete
364 */
365 function save_object()
366 {
367 foreach($_POST as $name => $value){
368 if(preg_match("/del_/",$name)){
369 $id = preg_replace("/^del_/","",$name);
370 $id = preg_replace("/_(x|y)$/","",$id);
371 $this->_remove_entry_id($id);
372 break;
373 }
374 if(preg_match("/edit_/",$name)){
375 $id = preg_replace("/^edit_/","",$name);
376 $id = preg_replace("/_(x|y)$/","",$id);
377 $this->_edit_entry_edit($id);
378 break;
379 }
380 if(preg_match("/up_/",$name)){
381 $id = preg_replace("/^up_/","",$name);
382 $id = preg_replace("/_(x|y)$/","",$id);
383 $this->_move_entry_up($id);
384 break;
385 }
386 if(preg_match("/down_/",$name)){
387 $id = preg_replace("/^down_/","",$name);
388 $id = preg_replace("/_(x|y)$/","",$id);
389 $this->_move_entry_down($id);
390 break;
391 }
392 }
393 if(isset($_POST['FAIrelease'])){
394 $this->FAIrelease = $_POST['FAIrelease'];
395 $this->_check_missing_release($this->FAIrelease);
396 }
397 if(isset($_GET['act']) && $_GET['act'] == 'depopen'){
398 $this->curbase = base64_decode($_GET['depid']);
399 }
400 if(isset($_POST['add_to_folder']) && isset($_POST['folder'])){
401 $folder = $_POST['folder'];
402 foreach($_POST as $name => $value){
403 if(preg_match("/^AddApp_[0-9]*$/",$name)){
404 $this->_add_app_id($folder,preg_replace("/^AddApp_/","",$name));
405 }
406 }
407 }
408 if(isset($_POST['add_menu_to_folder']) && isset($_POST['menu_folder'])){
409 $folder = $_POST['menu_folder'];
410 $name = $_POST['menu_folder_name'];
411 if(strlen($name) > 0 && preg_match("/[a-z ]/i",$name)){
412 $this->_add_sub_folder($folder,$name);
413 }
414 }
415 $this->reload();
416 }
419 function _get_release_key($release,$add_if_missing = FALSE)
420 {
421 $release_info = $this->Releases[$release];
423 if($release_info['name'] == "/"){
424 return($this->a_Structure['0']['UNIQID']);
425 }
427 $cur = &$this->a_Structure[0]['ENTRIES'];
428 $s_key = "";
429 $found = FALSE;
430 foreach($release_info['parts'] as $name){
431 foreach($cur as $key => $obj){
432 if($obj['TYPE'] == "RELEASE" && $obj['NAME'] == $name){
433 $s_key = $cur[$key]['UNIQID'];
434 $cur = &$cur[$key]['ENTRIES'];
435 $found = TRUE;
436 break;
437 }
438 $found = FALSE;
439 }
440 }
441 if($found){
442 return($s_key);
443 }
444 return(FALSE);
445 }
448 function _add_sub_folder($folder,$name)
449 {
450 $all = $this->_get_all_entries();
451 if($folder == "BASE"){
452 $folder = $this->_get_release_key($this->FAIrelease,TRUE);
453 }
455 if(isset($all[$folder])){
456 $a_folder = array();
457 $a_folder['STATUS'] = "ADDED";
458 $a_folder['NAME'] = $name;
459 $a_folder['UNIQID'] = uniqid();
460 $a_folder['PARENT'] = $folder;
461 $a_folder['TYPE'] = "FOLDER";
462 $all[$folder]['ENTRIES'][] = $a_folder;
463 }
464 }
467 /* !\brief Remove the given id from the menu structure.
468 @param String ID to of the entry we want to remove.
469 @return Boolean TRUE on success
470 */
471 function _remove_entry_id($id)
472 {
473 $all = $this->_get_all_entries();
474 if(isset($all[$id])){
475 $all[$id]['STATUS'] = "REMOVED";
476 return(TRUE);
477 }
478 return(FALSE);
479 }
482 /* !\brief Remove the given id from the menu structure.
483 @param String ID to of the entry we want to remove.
484 @return Boolean TRUE on success
485 */
486 function _add_entry($folder_id,$entry,$pos = 0)
487 {
488 $all = $this->_get_all_entries();
490 if(isset($all[$folder_id])){
492 $folder = &$all[$folder_id];
493 $entries = $entry['ENTRIES'];
495 $entry['UNIQID'] = uniqid();
496 $entry['PARENT'] = $folder_id;
497 $entry['ENTRIES']= array();
498 $entry['STATUS'] = "ADDED";
500 $cnt = 0;
501 $new = array();
502 $added =FALSE;
503 foreach($folder['ENTRIES'] as $key => $obj){
504 if($pos == $cnt){
505 $new[] = $entry;
506 $added = TRUE;
507 $cnt ++;
508 }
509 $new[] = $obj;
510 }
511 if(!$added){
512 $new[] = $entry;
513 }
514 $all[$folder_id]['ENTRIES'] = $new;
515 foreach($entries as $sub){
516 $this->_add_entry($entry['UNIQID'],$sub);
517 }
518 return(TRUE);
519 }
520 return(FALSE);
521 }
524 function _add_app_id($folder_id,$app_id)
525 {
526 $all = $this->_get_all_entries();
527 if($folder_id == "BASE"){
528 $folder_id = $this->_get_release_key($this->FAIrelease);
529 }
530 if(isset($all[$folder_id]) && isset($this->apps[$app_id])){
532 $new = array();
533 $new['TYPE'] = "ENTRY";
534 $new['NAME'] = $this->apps[$app_id]['cn'][0];
535 $new['UNIQID']= uniqid();
536 $new['PARENT']= $folder_id;
537 $new['STATUS']= "ADDED";
538 $all[$folder_id]['ENTRIES'][] = $new;
539 }
540 }
543 /*! \brief move the object identified by the given ID one position up.
544 @param String The ID of the entry to be moved.
545 @return Boolean TRUE on success, else FALSE;
546 */
547 function _move_entry_up($id)
548 {
549 $all = $this->_get_all_entries(TRUE);
550 $parent = FALSE;
551 foreach($all as $entry){
552 if(isset($entry['UNIQID']) && $entry['UNIQID'] == $id){
553 if($parent != FALSE){
554 return($this->__switch_entries($id,"up",$parent));
555 }
556 }else{
557 if(in_array($entry['TYPE'],array("CLOSE","OPEN"))){
558 $parent = $entry['PARENT'];
559 }else{
560 $parent = $entry['UNIQID'];
561 }
562 }
563 }
564 return(FALSE);
565 }
568 /*! \brief move the object identified by the given ID one position down.
569 @param String The ID of the entry to be moved.
570 @return Boolean TRUE on success, else FALSE;
571 */
572 function _move_entry_down($id)
573 {
574 $all = $this->_get_all_entries(TRUE);
575 $found = FALSE;
576 foreach($all as $entry){
577 if(isset($entry['UNIQID']) && $entry['UNIQID'] == $id){
578 $found = TRUE;
579 continue;
580 }else{
581 if(in_array($entry['TYPE'],array("CLOSE","OPEN"))){
582 $parent = $entry['PARENT'];
583 }else{
584 $parent = $entry['UNIQID'];
585 }
586 if($found){
587 return($this->__switch_entries($id,"down",$parent));
588 }
589 }
590 }
591 return(FALSE);
592 }
595 /*! \brief Return all entries linear.
596 @param Boolean $add_tags If TRUE, OPEN/CLOSE Tags will be appended.
597 @param &Array Start here, Pointer to an array.
598 */
599 function _get_all_entries($add_tags = FALSE, $skip_release = FALSE, $cur = NULL)
600 {
601 $ret = array();
602 if($cur == NULL){
603 $cur = &$this->a_Structure;
604 }
605 foreach($cur as $key => $entry){
607 if($skip_release && $entry['TYPE'] == "RELEASE"){
608 continue;
609 }
610 if($entry['TYPE'] == "ENTRY"){
611 $found = FALSE;
612 foreach($this->apps as $app){
613 if($app['cn'][0] == $entry['NAME']){
614 $found = TRUE;
615 if(isset($app['description'][0])){
616 $entry['INFO'] = "[".$app['description'][0]."]";
617 }
618 break;
619 }
620 }
621 if(!$found){
622 $entry['INFO'] = "<font color='red'>"._("Not available in release.")."</font>";
623 }
624 }
627 $tmp = $entry;
628 if(!$add_tags){
629 $ret[$tmp['UNIQID']] = &$cur[$key];
630 if(isset($entry['ENTRIES']) && count($entry['ENTRIES'])){
631 $ret = array_merge($ret,$this->_get_all_entries($add_tags,$skip_release,&$cur[$key]['ENTRIES']));
632 }
633 }else{
635 if(isset($tmp['ENTRIES'])){
636 unset($tmp['ENTRIES']);
637 }
639 if($tmp['STATUS'] != "REMOVED"){
640 $ret[] = $tmp;
641 if(isset($entry['ENTRIES']) && count($entry['ENTRIES'])){
642 $ret[] = array("TYPE" => "OPEN", "PARENT" => $entry['UNIQID']);
643 $ret = array_merge($ret,$this->_get_all_entries($add_tags,$skip_release,&$cur[$key]['ENTRIES']));
644 $ret[] = array("TYPE" => "CLOSE" , "PARENT" => $entry['UNIQID']);
645 }
646 }
647 }
648 }
649 return($ret);
650 }
653 /* !\brief Switch one entry with another
654 @param String from The source ID.
655 @param String type "up"/"down" type switched.
656 @param String to The destination ID.
657 return Boolean TRUE on success
658 */
659 function __switch_entries($from,$type,$to)
660 {
661 $all = $this->_get_all_entries();
663 $o_to = &$all[$to];
664 $o_from = &$all[$from];
666 /***********************
667 * Source == Destination
668 * Move into next parent.
669 ************************/
670 if($to == $from){
671 $to = $o_to['PARENT'];
672 $o_to = &$all[$to];
673 }
675 /***********************
676 * Target is container
677 ************************/
678 if(in_array($o_to['TYPE'],array("FOLDER","RELEASE"))){
680 /***********************
681 * Move into parent folder
682 * + Target
683 * |-> Source
684 ************************/
685 if($to == $o_from['PARENT']){
688 /* Check if source is a folder object
689 */
690 $o_to_sub = &$all[$o_to['PARENT']];
691 if(in_array($o_to_sub['TYPE'],array("FOLDER","RELEASE"))){
693 $o_from['STATUS'] = "ADDED";
695 /* Adding new */
696 $tmp2 = array();
697 $cnt = 0;
698 foreach($o_to_sub['ENTRIES'] as $key => $entry){
699 $cnt ++;
700 if($entry['UNIQID'] == $to){
701 break;
702 }
703 }
704 if($type == "up"){
705 $cnt --;
707 }
708 $this->_add_entry($o_to_sub['UNIQID'],$o_from,$cnt);
710 /* Removing old */
711 $tmp = array();
712 if(!$this->_remove_entry_id($from)){
713 return(FALSE);
714 }
715 }
716 }else{
718 /***********************
719 * Target is NOT parent container
720 * + Parent Folder
721 * |-> Source
722 * + Destination
723 ************************/
725 /* Removing old */
726 $o_to = $all[$to];
727 $o_from = $all[$from];
728 $this->_add_entry($to,$o_from);
729 $this->_remove_entry_id($from);
730 }
731 }else{
733 /***********************
734 * Source and Destination in some Folder.
735 * + Parent folder
736 * |-> Source
737 * |-> Destination
738 ************************/
739 $o_to = &$all[$to];
740 $o_from = &$all[$from];
741 $parent = &$all[$o_to['PARENT']];
743 if($o_to['PARENT'] == $o_from['PARENT']){
744 $tmp = $all[$to];
745 $all[$to] = $o_from;
746 $all[$from] = $tmp;
748 /* Ensure that the app priority is updated */
749 foreach($parent['ENTRIES'] as $key => $entry){
750 $parent['ENTRIES'][$key]['STATUS'] = "EDITED";
751 }
752 }
753 }
754 }
757 function save()
758 {
759 $ldap = $this->config->get_ldap_link();
760 $all = $this->_get_all_entries();
761 $prio = 0;
762 $Actions = array("Remove" => array(),"Edit" => array() , "Add" => array());
764 foreach($all as $entry){
765 $prio ++;
766 $cur = $entry;
767 $dn = "";
769 do{
770 if($cur['TYPE'] == "ENTRY"){
771 $dn.= "cn=".$cur['NAME'].",";
772 }elseif($cur['TYPE'] == "FOLDER"){
773 $dn.= "cn=".$cur['NAME'].",";
774 }elseif($cur['TYPE'] == "RELEASE"){
775 $dn.= "ou=".$cur['NAME'].",";
776 }elseif($cur['TYPE'] == "BASE"){
777 }
778 if(!isset($all[$cur['PARENT']])){
779 $cur = NULL;
780 }else{
781 $cur = $all[$cur['PARENT']];
782 }
783 }while(is_array($cur));
785 $cur_dn = $dn.$this->dn;
787 $attrs = array();
788 switch($entry['TYPE']){
789 case "ENTRY" :
790 {
791 $attrs['objectClass'] = "gotoMenuEntry";
792 $attrs['cn'] = $entry['NAME'];
793 $attrs['gosaApplicationPriority'] = $prio;
794 }
795 break;
796 case "FOLDER" :
797 {
798 $attrs['objectClass'] = "gotoSubmenuEntry";
799 $attrs['cn'] = $entry['NAME'];
800 $attrs['gosaApplicationPriority'] = $prio;
801 }
802 break;
803 case "RELEASE" :
804 {
805 $attrs['ou'] = $entry['NAME'];
806 $attrs['objectClass'] = array();
807 $attrs['objectClass'][] = "top";
808 $attrs['objectClass'][] = "organizationalUnit";
809 $attrs['objectClass'][] = "FAIbranch";
810 if(!empty($entry['FAIstate'])){
811 $attrs['FAIstate'] = $entry['FAIstate'];
812 }
813 }
814 break;
815 }
817 if($entry['STATUS'] == "LOADED"){
818 continue;
819 }
820 if($entry['STATUS'] == "REMOVED"){
821 $Actions['Remove'][$cur_dn] = $cur_dn;
822 }
823 if($entry['STATUS'] == "EDITED"){
824 $Actions['Edit'][$cur_dn] = $attrs;
825 }
826 if($entry['STATUS'] == "ADDED"){
827 $Actions['Add'][$cur_dn] = $attrs;
828 }
829 }
831 $ldap = $this->config->get_ldap_link();
832 $ldap->cd($this->config->current['BASE']);
833 foreach($Actions['Remove'] as $dn){
834 $ldap->cd($dn);
835 $ldap->cat($dn);
836 if($ldap->count()){
837 $ldap->rmdir_recursive($dn);
838 }
839 }
840 foreach($Actions['Add'] as $dn => $data){
841 $ldap->cd($dn);
842 $ldap->cat($dn);
843 if(!$ldap->count()){
844 $ldap->add($data);
845 }
846 }
847 foreach($Actions['Edit'] as $dn => $data){
848 $ldap->cd($dn);
849 $ldap->cat($dn);
850 if($ldap->count()){
851 $ldap->modify($data);
852 }
853 }
854 }
857 /* Return plugin informations for acl handling */
858 static function plInfo()
859 {
860 return (array(
861 "plShortName" => _("Applications"),
862 "plDescription" => _("Group applications"),
863 "plSelfModify" => FALSE,
864 "plDepends" => array(),
865 "plPriority" => 0,
866 "plSection" => array("admin"),
867 "plCategory" => array("groups"),
868 "plProvidedAcls"=> array(
869 "gosaMemberApplication" => _("Application"),
870 "FAIrelease" => _("Release"),
871 "gosaApplicationParameter" => _("Application parameter"))
872 ));
873 }
876 function PrepareForCopyPaste($source)
877 {
878 }
881 function multiple_save_object()
882 {
883 if(isset($_POST['group_apps_multi'])){
884 $this->save_object();
885 plugin::multiple_save_object();
887 /* Get posts */
888 foreach(array("apps") as $attr){
889 if(isset($_POST['use_'.$attr])) {
890 $this->multi_boxes[] = $attr;
891 }
892 }
893 }
894 }
897 function get_multi_edit_values()
898 {
899 $ret = plugin::get_multi_edit_values();
901 if(in_array("apps",$this->multi_boxes)){
902 $ret['gosaApplicationParameter'] = $this->gosaApplicationParameter;
903 $ret['Categories'] = $this->Categories;
904 $ret['gosaMemberApplication'] = $this->gosaMemberApplication;
905 $ret['FAIrelease'] = $this->FAIrelease;
906 $ret['appoption'] = $this->appoption;
907 }
908 return($ret);
909 }
910 }
911 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
912 ?>