24bf8193d9597baa501b99d9e076f36680c86177
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 $i --;
357 }
358 }
359 }
362 /* !\brief Handle ui POSTS, like sort up/down/delete
363 */
364 function save_object()
365 {
366 foreach($_POST as $name => $value){
367 if(preg_match("/del_/",$name)){
368 $id = preg_replace("/^del_/","",$name);
369 $id = preg_replace("/_(x|y)$/","",$id);
370 $this->_remove_entry_id($id);
371 break;
372 }
373 if(preg_match("/edit_/",$name)){
374 $id = preg_replace("/^edit_/","",$name);
375 $id = preg_replace("/_(x|y)$/","",$id);
376 $this->_edit_entry_edit($id);
377 break;
378 }
379 if(preg_match("/up_/",$name)){
380 $id = preg_replace("/^up_/","",$name);
381 $id = preg_replace("/_(x|y)$/","",$id);
382 $this->_move_entry_up($id);
383 break;
384 }
385 if(preg_match("/down_/",$name)){
386 $id = preg_replace("/^down_/","",$name);
387 $id = preg_replace("/_(x|y)$/","",$id);
388 $this->_move_entry_down($id);
389 break;
390 }
391 }
392 if(isset($_POST['FAIrelease'])){
393 $this->FAIrelease = $_POST['FAIrelease'];
394 $this->_check_missing_release($this->FAIrelease);
395 }
396 if(isset($_GET['act']) && $_GET['act'] == 'depopen'){
397 $this->curbase = base64_decode($_GET['depid']);
398 }
399 if(isset($_POST['add_to_folder']) && isset($_POST['folder'])){
400 $folder = $_POST['folder'];
401 foreach($_POST as $name => $value){
402 if(preg_match("/^AddApp_[0-9]*$/",$name)){
403 $this->_add_app_id($folder,preg_replace("/^AddApp_/","",$name));
404 }
405 }
406 }
407 if(isset($_POST['add_menu_to_folder']) && isset($_POST['menu_folder'])){
408 $folder = $_POST['menu_folder'];
409 $name = $_POST['menu_folder_name'];
410 if(strlen($name) > 0 && preg_match("/[a-z ]/i",$name)){
411 $this->_add_sub_folder($folder,$name);
412 }
413 }
414 $this->reload();
415 }
418 function _get_release_key($release,$add_if_missing = FALSE)
419 {
420 $release_info = $this->Releases[$release];
422 if($release_info['name'] == "/"){
423 return($this->a_Structure['0']['UNIQID']);
424 }
426 $cur = &$this->a_Structure[0]['ENTRIES'];
427 $s_key = "";
428 $found = FALSE;
429 foreach($release_info['parts'] as $name){
430 foreach($cur as $key => $obj){
431 if($obj['TYPE'] == "RELEASE" && $obj['NAME'] == $name){
432 $s_key = $cur[$key]['UNIQID'];
433 $cur = &$cur[$key]['ENTRIES'];
434 $found = TRUE;
435 break;
436 }
437 $found = FALSE;
438 }
439 }
440 if($found){
441 return($s_key);
442 }
443 return(FALSE);
444 }
447 function _add_sub_folder($folder,$name)
448 {
449 $all = $this->_get_all_entries();
450 if($folder == "BASE"){
451 $folder = $this->_get_release_key($this->FAIrelease,TRUE);
452 }
454 if(isset($all[$folder])){
455 $a_folder = array();
456 $a_folder['STATUS'] = "ADDED";
457 $a_folder['NAME'] = $name;
458 $a_folder['UNIQID'] = uniqid();
459 $a_folder['PARENT'] = $folder;
460 $a_folder['TYPE'] = "FOLDER";
461 $all[$folder]['ENTRIES'][] = $a_folder;
462 }
463 }
466 /* !\brief Remove the given id from the menu structure.
467 @param String ID to of the entry we want to remove.
468 @return Boolean TRUE on success
469 */
470 function _remove_entry_id($id)
471 {
472 $all = $this->_get_all_entries();
473 if(isset($all[$id])){
474 $all[$id]['STATUS'] = "REMOVED";
475 return(TRUE);
476 }
477 return(FALSE);
478 }
481 /* !\brief Remove the given id from the menu structure.
482 @param String ID to of the entry we want to remove.
483 @return Boolean TRUE on success
484 */
485 function _add_entry($folder_id,$entry,$pos = 0)
486 {
487 $all = $this->_get_all_entries();
489 if(isset($all[$folder_id])){
491 $folder = &$all[$folder_id];
492 $entries = $entry['ENTRIES'];
494 $entry['UNIQID'] = uniqid();
495 $entry['PARENT'] = $folder_id;
496 $entry['ENTRIES']= array();
497 $entry['STATUS'] = "ADDED";
499 $cnt = 0;
500 $new = array();
501 $added =FALSE;
502 foreach($folder['ENTRIES'] as $key => $obj){
503 if($pos == $cnt){
504 $new[] = $entry;
505 $added = TRUE;
506 $cnt ++;
507 }
508 $new[] = $obj;
509 }
510 if(!$added){
511 $new[] = $entry;
512 }
513 $all[$folder_id]['ENTRIES'] = $new;
514 foreach($entries as $sub){
515 $this->_add_entry($entry['UNIQID'],$sub);
516 }
517 return(TRUE);
518 }
519 return(FALSE);
520 }
523 function _add_app_id($folder_id,$app_id)
524 {
525 $all = $this->_get_all_entries();
526 if($folder_id == "BASE"){
527 $folder_id = $this->_get_release_key($this->FAIrelease);
528 }
529 if(isset($all[$folder_id]) && isset($this->apps[$app_id])){
531 $new = array();
532 $new['TYPE'] = "ENTRY";
533 $new['NAME'] = $this->apps[$app_id]['cn'][0];
534 $new['UNIQID']= uniqid();
535 $new['PARENT']= $folder_id;
536 $new['STATUS']= "ADDED";
537 $all[$folder_id]['ENTRIES'][] = $new;
538 }
539 }
542 /*! \brief move the object identified by the given ID one position up.
543 @param String The ID of the entry to be moved.
544 @return Boolean TRUE on success, else FALSE;
545 */
546 function _move_entry_up($id)
547 {
548 $all = $this->_get_all_entries(TRUE);
549 $parent = FALSE;
550 foreach($all as $entry){
551 if(isset($entry['UNIQID']) && $entry['UNIQID'] == $id){
552 if($parent != FALSE){
553 return($this->__switch_entries($id,"up",$parent));
554 }
555 }else{
556 if(in_array($entry['TYPE'],array("CLOSE","OPEN"))){
557 $parent = $entry['PARENT'];
558 }else{
559 $parent = $entry['UNIQID'];
560 }
561 }
562 }
563 return(FALSE);
564 }
567 /*! \brief move the object identified by the given ID one position down.
568 @param String The ID of the entry to be moved.
569 @return Boolean TRUE on success, else FALSE;
570 */
571 function _move_entry_down($id)
572 {
573 $all = $this->_get_all_entries(TRUE);
574 $found = FALSE;
575 foreach($all as $entry){
576 if(isset($entry['UNIQID']) && $entry['UNIQID'] == $id){
577 $found = TRUE;
578 continue;
579 }else{
580 if(in_array($entry['TYPE'],array("CLOSE","OPEN"))){
581 $parent = $entry['PARENT'];
582 }else{
583 $parent = $entry['UNIQID'];
584 }
585 if($found){
586 return($this->__switch_entries($id,"down",$parent));
587 }
588 }
589 }
590 return(FALSE);
591 }
594 /*! \brief Return all entries linear.
595 @param Boolean $add_tags If TRUE, OPEN/CLOSE Tags will be appended.
596 @param &Array Start here, Pointer to an array.
597 */
598 function _get_all_entries($add_tags = FALSE, $skip_release = FALSE, $cur = NULL)
599 {
600 $ret = array();
601 if($cur == NULL){
602 $cur = &$this->a_Structure;
603 }
604 foreach($cur as $key => $entry){
606 if($skip_release && $entry['TYPE'] == "RELEASE"){
607 continue;
608 }
609 if($entry['TYPE'] == "ENTRY"){
610 $found = FALSE;
611 foreach($this->apps as $app){
612 if($app['cn'][0] == $entry['NAME']){
613 $found = TRUE;
614 if(isset($app['description'][0])){
615 $entry['INFO'] = "[".$app['description'][0]."]";
616 }
617 break;
618 }
619 }
620 if(!$found){
621 $entry['INFO'] = "<font color='red'>"._("Not available in release.")."</font>";
622 }
623 }
626 $tmp = $entry;
627 if(!$add_tags){
628 $ret[$tmp['UNIQID']] = &$cur[$key];
629 if(isset($entry['ENTRIES']) && count($entry['ENTRIES'])){
630 $ret = array_merge($ret,$this->_get_all_entries($add_tags,$skip_release,&$cur[$key]['ENTRIES']));
631 }
632 }else{
634 if(isset($tmp['ENTRIES'])){
635 unset($tmp['ENTRIES']);
636 }
638 if($tmp['STATUS'] != "REMOVED"){
639 $ret[] = $tmp;
640 if(isset($entry['ENTRIES']) && count($entry['ENTRIES'])){
641 $ret[] = array("TYPE" => "OPEN", "PARENT" => $entry['UNIQID']);
642 $ret = array_merge($ret,$this->_get_all_entries($add_tags,$skip_release,&$cur[$key]['ENTRIES']));
643 $ret[] = array("TYPE" => "CLOSE" , "PARENT" => $entry['UNIQID']);
644 }
645 }
646 }
647 }
648 return($ret);
649 }
652 /* !\brief Switch one entry with another
653 @param String from The source ID.
654 @param String type "up"/"down" type switched.
655 @param String to The destination ID.
656 return Boolean TRUE on success
657 */
658 function __switch_entries($from,$type,$to)
659 {
660 $all = $this->_get_all_entries();
662 $o_to = &$all[$to];
663 $o_from = &$all[$from];
665 /***********************
666 * Source == Destination
667 * Move into next parent.
668 ************************/
669 if($to == $from){
670 $to = $o_to['PARENT'];
671 $o_to = &$all[$to];
672 }
674 /***********************
675 * Target is container
676 ************************/
677 if(in_array($o_to['TYPE'],array("FOLDER","RELEASE"))){
679 /***********************
680 * Move into parent folder
681 * + Target
682 * |-> Source
683 ************************/
684 if($to == $o_from['PARENT']){
687 /* Check if source is a folder object
688 */
689 $o_to_sub = &$all[$o_to['PARENT']];
690 if(in_array($o_to_sub['TYPE'],array("FOLDER","RELEASE"))){
692 $o_from['STATUS'] = "ADDED";
694 /* Adding new */
695 $tmp2 = array();
696 $cnt = 0;
697 foreach($o_to_sub['ENTRIES'] as $key => $entry){
698 $cnt ++;
699 if($entry['UNIQID'] == $to){
700 break;
701 }
702 }
703 if($type == "up"){
704 $cnt --;
706 }
707 $this->_add_entry($o_to_sub['UNIQID'],$o_from,$cnt);
709 /* Removing old */
710 $tmp = array();
711 if(!$this->_remove_entry_id($from)){
712 return(FALSE);
713 }
714 }
715 }else{
717 /***********************
718 * Target is NOT parent container
719 * + Parent Folder
720 * |-> Source
721 * + Destination
722 ************************/
724 /* Removing old */
725 $o_to = $all[$to];
726 $o_from = $all[$from];
727 $this->_add_entry($to,$o_from);
728 $this->_remove_entry_id($from);
729 }
730 }else{
732 /***********************
733 * Source and Destination in some Folder.
734 * + Parent folder
735 * |-> Source
736 * |-> Destination
737 ************************/
738 $o_to = &$all[$to];
739 $o_from = &$all[$from];
740 $parent = &$all[$o_to['PARENT']];
742 if($o_to['PARENT'] == $o_from['PARENT']){
743 $tmp = $all[$to];
744 $all[$to] = $o_from;
745 $all[$from] = $tmp;
747 /* Ensure that the app priority is updated */
748 foreach($parent['ENTRIES'] as $key => $entry){
749 $parent['ENTRIES'][$key]['STATUS'] = "EDITED";
750 }
751 }
752 }
753 }
756 function save()
757 {
758 $ldap = $this->config->get_ldap_link();
759 $all = $this->_get_all_entries();
760 $prio = 0;
761 $Actions = array("Remove" => array(),"Edit" => array() , "Add" => array());
763 foreach($all as $entry){
764 $prio ++;
765 $cur = $entry;
766 $dn = "";
768 do{
769 if($cur['TYPE'] == "ENTRY"){
770 $dn.= "cn=".$cur['NAME'].",";
771 }elseif($cur['TYPE'] == "FOLDER"){
772 $dn.= "cn=".$cur['NAME'].",";
773 }elseif($cur['TYPE'] == "RELEASE"){
774 $dn.= "ou=".$cur['NAME'].",";
775 }elseif($cur['TYPE'] == "BASE"){
776 }
777 if(!isset($all[$cur['PARENT']])){
778 $cur = NULL;
779 }else{
780 $cur = $all[$cur['PARENT']];
781 }
782 }while(is_array($cur));
784 $cur_dn = $dn.$this->dn;
786 $attrs = array();
787 switch($entry['TYPE']){
788 case "ENTRY" :
789 {
790 $attrs['objectClass'] = "gotoMenuEntry";
791 $attrs['cn'] = $entry['NAME'];
792 $attrs['gosaApplicationPriority'] = $prio;
793 }
794 break;
795 case "FOLDER" :
796 {
797 $attrs['objectClass'] = "gotoSubmenuEntry";
798 $attrs['cn'] = $entry['NAME'];
799 $attrs['gosaApplicationPriority'] = $prio;
800 }
801 break;
802 case "RELEASE" :
803 {
804 $attrs['ou'] = $entry['NAME'];
805 $attrs['objectClass'] = array();
806 $attrs['objectClass'][] = "top";
807 $attrs['objectClass'][] = "organizationalUnit";
808 $attrs['objectClass'][] = "FAIbranch";
809 if(!empty($entry['FAIstate'])){
810 $attrs['FAIstate'] = $entry['FAIstate'];
811 }
812 }
813 break;
814 }
816 if($entry['STATUS'] == "LOADED"){
817 continue;
818 }
819 if($entry['STATUS'] == "REMOVED"){
820 $Actions['Remove'][$cur_dn] = $cur_dn;
821 }
822 if($entry['STATUS'] == "EDITED"){
823 $Actions['Edit'][$cur_dn] = $attrs;
824 }
825 if($entry['STATUS'] == "ADDED"){
826 $Actions['Add'][$cur_dn] = $attrs;
827 }
828 }
830 $ldap = $this->config->get_ldap_link();
831 $ldap->cd($this->config->current['BASE']);
832 foreach($Actions['Remove'] as $dn){
833 $ldap->cd($dn);
834 $ldap->cat($dn);
835 if($ldap->count()){
836 $ldap->rmdir_recursive($dn);
837 }
838 }
839 foreach($Actions['Add'] as $dn => $data){
840 $ldap->cd($dn);
841 $ldap->cat($dn);
842 if(!$ldap->count()){
843 $ldap->add($data);
844 }
845 }
846 foreach($Actions['Edit'] as $dn => $data){
847 $ldap->cd($dn);
848 $ldap->cat($dn);
849 if($ldap->count()){
850 $ldap->modify($data);
851 }
852 }
853 }
856 /* Return plugin informations for acl handling */
857 static function plInfo()
858 {
859 return (array(
860 "plShortName" => _("Applications"),
861 "plDescription" => _("Group applications"),
862 "plSelfModify" => FALSE,
863 "plDepends" => array(),
864 "plPriority" => 0,
865 "plSection" => array("admin"),
866 "plCategory" => array("groups"),
867 "plProvidedAcls"=> array(
868 "gosaMemberApplication" => _("Application"),
869 "FAIrelease" => _("Release"),
870 "gosaApplicationParameter" => _("Application parameter"))
871 ));
872 }
875 function PrepareForCopyPaste($source)
876 {
877 }
880 function multiple_save_object()
881 {
882 if(isset($_POST['group_apps_multi'])){
883 $this->save_object();
884 plugin::multiple_save_object();
886 /* Get posts */
887 foreach(array("apps") as $attr){
888 if(isset($_POST['use_'.$attr])) {
889 $this->multi_boxes[] = $attr;
890 }
891 }
892 }
893 }
896 function get_multi_edit_values()
897 {
898 $ret = plugin::get_multi_edit_values();
900 if(in_array("apps",$this->multi_boxes)){
901 $ret['gosaApplicationParameter'] = $this->gosaApplicationParameter;
902 $ret['Categories'] = $this->Categories;
903 $ret['gosaMemberApplication'] = $this->gosaMemberApplication;
904 $ret['FAIrelease'] = $this->FAIrelease;
905 $ret['appoption'] = $this->appoption;
906 }
907 return($ret);
908 }
909 }
910 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
911 ?>