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 }
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 }
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";
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['send'])){
219 $id = $_GET['send'];
220 $all = $this->_get_all_entries();
221 if(isset($all[$id])){
222 send_binary_content($all[$id]['ICON'],$id.".jpg","image/jpeg");
223 exit;
224 }
225 }
227 if(isset($_GET['r']))
228 $this->__construct($this->config,$this->dn);
230 if(count($this->edit_entry)){
231 if($this->edit_entry['TYPE'] == "ENTRY"){
232 $smarty = get_smarty();
233 $smarty->assign("type", "ENTRY");
234 $smarty->assign("entry",$this->edit_entry);
235 $smarty->assign("paras",$this->app_parameter);
236 $display= $smarty->fetch (get_template_path('edit_entry.tpl', TRUE, dirname(__FILE__)));
237 return($display);
238 }
239 if($this->edit_entry['TYPE'] == "FOLDER"){
240 $smarty = get_smarty();
242 session::set("binarytype" , "image/jpeg");
243 session::set("binary" , $this->edit_entry['ICON']);
245 $smarty->assign("rand", microtime(TRUE));
246 $smarty->assign("image_set" , strlen($this->edit_entry['ICON']) > 0);
247 $smarty->assign("type", "FOLDER");
248 $smarty->assign("entry",$this->edit_entry);
249 $display= $smarty->fetch (get_template_path('edit_entry.tpl', TRUE, dirname(__FILE__)));
250 return($display);
251 }
252 }
254 $smarty = get_smarty();
255 $smarty->assign("plug_id" , $_GET['plug']);
257 /* Create application list */
258 $div = new divSelectBox("appgroup");
259 $div->SetHeight(300);
260 $departments = array();
261 $res = get_list("(objectClass=gosaDepartment)", "application", $this->curbase,array("description","cn","ou"),GL_SIZELIMIT);
262 foreach($res as $value){
263 $fdn = $value['dn'];
264 $fdn = preg_replace("/".normalizePreg($this->curbase)."/","",$fdn);
265 $fdn= @LDAP::fix($fdn);
266 if($value["description"][0]!=".."){
267 $departments[$value['dn']]= convert_department_dn($fdn)." - [".$value["description"][0]."]";
268 }else{
269 $departments[$value['dn']]=convert_department_dn($fdn)." ["._("Back")."]";
270 }
271 }
273 $linkopen = "<a href='?plug=".$_GET['plug']."&act=depopen&depid=%s'>%s</a>";
275 /* Create base back entry */
276 $base_back = preg_replace("/^[^,]+,/","",$this->curbase);
277 if((strlen($base_back)>= strlen($this->config->current['BASE']))&&($this->curbase!=$this->config->current['BASE'])){
278 $div->AddEntry(array(
279 array("string"=>sprintf($linkopen,base64_encode($base_back),".. ["._("back")."]"),
280 "attach"=>"style='border:0px;'")
281 ));
282 }
284 /* Append departments for current base */
285 foreach($departments as $key => $app){
286 $div->AddEntry(array(
287 array("string"=>"<img class='center' src='images/folder.png' alt='"._("department")."'> ".sprintf($linkopen,
288 base64_encode($key),$app),
289 "attach"=>"style='border:0px;'")
290 ));
291 }
294 /* Add applications found on this base */
295 $used_apps = $this->_get_used_entry_name();
296 foreach($this->apps as $key => $app){
297 if(in_array($app['cn'][0],$used_apps)){
298 continue;
299 }
300 if(!preg_match("/".get_ou('applicationou').normalizePreg($this->curbase)."$/",$app['dn'])){
301 continue;
302 }
304 $name = $app['cn'][0];
305 if(isset($app['description'])){
306 $name .= " [".$app['description'][0]."]";
307 }
308 $div->AddEntry(array(
309 array("string"=>sprintf("<input class='center' type='checkbox' value='1' name='AddApp_%s'>",$key).
310 "<img class='center' src='images/select_application.png' alt='"._("application")."'> ".$name,
311 "attach"=>"style='border:0px;'")
312 ));
313 }
316 $smarty->assign("FAIrelease",$this->FAIrelease);
317 $smarty->assign("app_list",$div->DrawList());
318 $smarty->assign("releases",$this->Releases);
319 $smarty->assign("folders" , $this->_get_folder_names());
320 $entries = $this->_get_entries_for_release($this->FAIrelease);
321 $smarty->assign("entries",$entries);
322 $display= $smarty->fetch (get_template_path('app_list.tpl', TRUE, dirname(__FILE__)));
323 return($display);
324 }
327 function _get_folder_names()
328 {
329 $data = $this->_get_entries_for_release($this->FAIrelease);
330 $ret = array("BASE" => ".");
331 foreach($data as $entry){
332 if($entry['TYPE'] == "FOLDER"){
333 $ret[$entry['UNIQID']] = $entry['NAME'];
334 }
335 }
336 return($ret);
337 }
340 function _get_used_entry_name()
341 {
342 $data = $this->_get_entries_for_release($this->FAIrelease);
343 $ret = array();
344 foreach($data as $entry){
345 if($entry['TYPE'] == "ENTRY"){
346 $ret[] = $entry['NAME'];
347 }
348 }
349 return($ret);
350 }
353 function _get_entries_for_release($release,$cur = NULL)
354 {
355 $all = $this->_get_all_entries();
356 $key = $this->_get_release_key($release);
357 if(isset($all[$key]) && count($all[$key]['ENTRIES'])){
358 $res = $this->_get_all_entries(TRUE,TRUE,&$all[$key]['ENTRIES']);
359 return($res);
360 }
361 return(array());
362 }
365 function _save_entry_edit()
366 {
367 $all = $this->_get_all_entries();
368 $entry = $this->edit_entry;
369 $r_entry= &$all[$entry['UNIQID']];
371 if($entry['TYPE'] == "ENTRY"){
372 $r_entry['PARAMETER'] = $this->app_parameter;
373 $r_entry['STATUS'] = "EDITED";
374 }
375 if($entry['TYPE'] == "FOLDER"){
376 $r_entry['ICON'] = $this->edit_entry['ICON'];
377 $r_entry['STATUS'] = "EDITED";
378 }
379 $this->dialog = FALSE;
380 $this->edit_entry = array();
381 }
384 function _edit_entry_edit($id)
385 {
386 $all = $this->_get_all_entries();
387 $entry = $all[$id];
389 $this->app_parameter = array();
390 if($entry['TYPE'] == "ENTRY"){
391 $found = FALSE;
392 foreach($this->apps as $id => $app){
394 if($app['cn'][0] == $entry['NAME']){
395 $found = TRUE;
396 break;
397 }
398 }
399 if($found){
401 /* Create a list of editable parameter */
402 if(isset($app['gosaApplicationParameter'])){
403 for($i = 0 ; $i < $app['gosaApplicationParameter']['count'] ; $i++) {
404 $para = $app['gosaApplicationParameter'][$i];
405 $tmp = split(":",$para);
406 $this->app_parameter[$tmp[0]] = $tmp[1];
407 }
408 }
410 /* Overwrite parameters with entry parameters */
411 foreach($entry['PARAMETER'] as $name => $value){
412 $this->app_parameter[$name] = $value;
413 }
415 $this->dialog = TRUE;
416 $this->edit_entry = $entry;
417 }
418 }
420 if($entry['TYPE'] == "FOLDER"){
421 $this->dialog = TRUE;
422 $this->edit_entry = $entry;
423 }
424 }
427 function remove_from_parent()
428 {
429 }
433 function check()
434 {
435 }
438 function _check_missing_release($release)
439 {
440 $release_info = $this->Releases[$release];
442 $parent_id = $this->a_Structure[0]['UNIQID'];
443 $cur = &$this->a_Structure[0]['ENTRIES'];
444 for($i = 0 ; $i < count($release_info['parts']) ; $i ++){
445 $part = $release_info['parts'][$i];
446 $found = FALSE;
447 foreach($cur as $key => $name){
448 if($name['NAME'] == $part){
449 $parent_id = $cur[$key]['UNIQID'];
450 $cur = &$cur[$key]['ENTRIES'];
452 $found =TRUE;
453 break;
454 }
455 }
456 if(!$found){
457 $release = array();
458 $release['UNIQID'] = uniqid();
459 $release['PARENT'] = $parent_id;
460 $release['NAME'] = $part;
461 $release['TYPE'] = "RELEASE";
462 $release['ENTRIES']= array();
463 $release['STATUS'] = "ADDED";
464 $release['FAIstate'] = $release_info['FAIstate'];
465 $cur[] = $release;
466 $i --;
467 }
468 }
469 }
472 /* !\brief Handle ui POSTS, like sort up/down/delete
473 */
474 function save_object()
475 {
476 foreach($_POST as $name => $value){
477 if(preg_match("/del_/",$name)){
478 $id = preg_replace("/^del_/","",$name);
479 $id = preg_replace("/_(x|y)$/","",$id);
480 $this->_remove_entry_id($id);
481 break;
482 }
483 if(preg_match("/app_entry_edit/",$name)){
484 $id = preg_replace("/^app_entry_edit/","",$name);
485 $id = preg_replace("/_(x|y)$/","",$id);
486 $this->_edit_entry_edit($id);
487 break;
488 }
489 if(preg_match("/up_/",$name)){
490 $id = preg_replace("/^up_/","",$name);
491 $id = preg_replace("/_(x|y)$/","",$id);
492 $this->_move_entry_up($id);
493 break;
494 }
495 if(preg_match("/down_/",$name)){
496 $id = preg_replace("/^down_/","",$name);
497 $id = preg_replace("/_(x|y)$/","",$id);
498 $this->_move_entry_down($id);
499 break;
500 }
501 if(preg_match("/^parameter_/",$name) &&
502 count($this->edit_entry) && $this->edit_entry['TYPE'] == "ENTRY"){
503 $name = preg_replace("/^parameter_/","",$name);
504 $this->app_parameter[$name] = $value;
505 }
506 }
507 if(isset($_POST['FAIrelease'])){
508 $this->FAIrelease = $_POST['FAIrelease'];
509 $this->_check_missing_release($this->FAIrelease);
510 }
511 if(isset($_GET['act']) && $_GET['act'] == 'depopen'){
512 $this->curbase = base64_decode($_GET['depid']);
513 }
514 if(isset($_POST['add_to_folder']) && isset($_POST['folder'])){
515 $folder = $_POST['folder'];
516 foreach($_POST as $name => $value){
517 if(preg_match("/^AddApp_[0-9]*$/",$name)){
518 $this->_add_app_id($folder,preg_replace("/^AddApp_/","",$name));
519 }
520 }
521 }
522 if(isset($_POST['add_menu_to_folder']) && isset($_POST['menu_folder'])){
523 $folder = $_POST['menu_folder'];
524 $name = $_POST['menu_folder_name'];
525 if(strlen($name) > 0 && preg_match("/[a-z ]/i",$name)){
526 $this->_add_sub_folder($folder,$name);
527 }
528 }
529 if(isset($_POST['app_entry_save'])){
530 $this->_save_entry_edit();
531 }
533 if(isset($_FILES['folder_image']) && isset($_POST['folder_image_upload'])){
534 if($_FILES['folder_image']['error'] == 0 && $_FILES['folder_image']['size'] > 0){
535 $this->edit_entry['ICON'] = file_get_contents($_FILES['folder_image']['tmp_name']);
536 }
537 }
539 if(isset($_POST['app_entry_cancel'])){
540 $this->edit_entry = array();
541 $this->dialog = FALSE;
542 }
543 $this->reload();
544 }
547 function _get_release_key($release,$add_if_missing = FALSE)
548 {
549 $release_info = $this->Releases[$release];
551 if($release_info['name'] == "/"){
552 return($this->a_Structure['0']['UNIQID']);
553 }
555 $cur = &$this->a_Structure[0]['ENTRIES'];
556 $s_key = "";
557 $found = FALSE;
558 foreach($release_info['parts'] as $name){
559 foreach($cur as $key => $obj){
560 if($obj['TYPE'] == "RELEASE" && $obj['NAME'] == $name){
561 $s_key = $cur[$key]['UNIQID'];
562 $cur = &$cur[$key]['ENTRIES'];
563 $found = TRUE;
564 break;
565 }
566 $found = FALSE;
567 }
568 }
569 if($found){
570 return($s_key);
571 }
572 return(FALSE);
573 }
576 function _add_sub_folder($folder,$name)
577 {
578 $all = $this->_get_all_entries();
579 if($folder == "BASE"){
580 $folder = $this->_get_release_key($this->FAIrelease,TRUE);
581 }
583 if(isset($all[$folder])){
584 $a_folder = array();
585 $a_folder['STATUS'] = "ADDED";
586 $a_folder['NAME'] = $name;
587 $a_folder['UNIQID'] = uniqid();
588 $a_folder['PARENT'] = $folder;
589 $a_folder['TYPE'] = "FOLDER";
590 $all[$folder]['ENTRIES'][] = $a_folder;
591 }
592 }
595 /* !\brief Remove the given id from the menu structure.
596 @param String ID to of the entry we want to remove.
597 @return Boolean TRUE on success
598 */
599 function _remove_entry_id($id)
600 {
601 $all = $this->_get_all_entries();
602 if(isset($all[$id])){
603 $all[$id]['STATUS'] = "REMOVED";
604 return(TRUE);
605 }
606 return(FALSE);
607 }
610 /* !\brief Remove the given id from the menu structure.
611 @param String ID to of the entry we want to remove.
612 @return Boolean TRUE on success
613 */
614 function _add_entry($folder_id,$entry,$pos = 0)
615 {
616 $all = $this->_get_all_entries();
618 if(isset($all[$folder_id])){
620 $folder = &$all[$folder_id];
621 $entries = $entry['ENTRIES'];
623 $entry['UNIQID'] = uniqid();
624 $entry['PARENT'] = $folder_id;
625 $entry['ENTRIES']= array();
626 $entry['STATUS'] = "ADDED";
628 $cnt = 0;
629 $new = array();
630 $added =FALSE;
631 foreach($folder['ENTRIES'] as $key => $obj){
632 if($pos == $cnt){
633 $new[] = $entry;
634 $added = TRUE;
635 $cnt ++;
636 }
637 $new[] = $obj;
638 }
639 if(!$added){
640 $new[] = $entry;
641 }
642 $all[$folder_id]['ENTRIES'] = $new;
643 foreach($entries as $sub){
644 $this->_add_entry($entry['UNIQID'],$sub);
645 }
646 return(TRUE);
647 }
648 return(FALSE);
649 }
652 function _add_app_id($folder_id,$app_id)
653 {
654 $all = $this->_get_all_entries();
655 if($folder_id == "BASE"){
656 $folder_id = $this->_get_release_key($this->FAIrelease);
657 }
658 if(isset($all[$folder_id]) && isset($this->apps[$app_id])){
660 $new = array();
661 $new['TYPE'] = "ENTRY";
662 $new['NAME'] = $this->apps[$app_id]['cn'][0];
663 $new['UNIQID']= uniqid();
664 $new['PARENT']= $folder_id;
665 $new['STATUS']= "ADDED";
666 $all[$folder_id]['ENTRIES'][] = $new;
667 }
668 }
671 /*! \brief move the object identified by the given ID one position up.
672 @param String The ID of the entry to be moved.
673 @return Boolean TRUE on success, else FALSE;
674 */
675 function _move_entry_up($id)
676 {
677 $all = $this->_get_all_entries(TRUE);
678 $parent = FALSE;
679 foreach($all as $entry){
680 if(isset($entry['UNIQID']) && $entry['UNIQID'] == $id){
681 if($parent != FALSE){
682 return($this->__switch_entries($id,"up",$parent));
683 }
684 }else{
685 if(in_array($entry['TYPE'],array("CLOSE","OPEN"))){
686 $parent = $entry['PARENT'];
687 }else{
688 $parent = $entry['UNIQID'];
689 }
690 }
691 }
692 return(FALSE);
693 }
696 /*! \brief move the object identified by the given ID one position down.
697 @param String The ID of the entry to be moved.
698 @return Boolean TRUE on success, else FALSE;
699 */
700 function _move_entry_down($id)
701 {
702 $all = $this->_get_all_entries(TRUE);
703 $found = FALSE;
704 foreach($all as $entry){
705 if(isset($entry['UNIQID']) && $entry['UNIQID'] == $id){
706 $found = TRUE;
707 continue;
708 }else{
709 if(in_array($entry['TYPE'],array("CLOSE","OPEN"))){
710 $parent = $entry['PARENT'];
711 }else{
712 $parent = $entry['UNIQID'];
713 }
714 if($found){
715 return($this->__switch_entries($id,"down",$parent));
716 }
717 }
718 }
719 return(FALSE);
720 }
723 /*! \brief Return all entries linear.
724 @param Boolean $add_tags If TRUE, OPEN/CLOSE Tags will be appended.
725 @param &Array Start here, Pointer to an array.
726 */
727 function _get_all_entries($add_tags = FALSE, $skip_release = FALSE, $cur = NULL)
728 {
729 $ret = array();
730 if($cur == NULL){
731 $cur = &$this->a_Structure;
732 }
733 foreach($cur as $key => $entry){
735 if($skip_release && $entry['TYPE'] == "RELEASE"){
736 continue;
737 }
738 if($entry['TYPE'] == "ENTRY"){
739 $found = FALSE;
740 foreach($this->apps as $app){
741 if($app['cn'][0] == $entry['NAME']){
742 $found = TRUE;
743 if(isset($app['description'][0])){
744 $entry['INFO'] = "[".$app['description'][0]."]";
745 }
746 break;
747 }
748 }
749 if(!$found){
750 $entry['INFO'] = "<font color='red'>"._("Not available in release.")."</font>";
751 }
752 }
755 $tmp = $entry;
756 if(!$add_tags){
757 $ret[$tmp['UNIQID']] = &$cur[$key];
758 if(isset($entry['ENTRIES']) && count($entry['ENTRIES'])){
759 $ret = array_merge($ret,$this->_get_all_entries($add_tags,$skip_release,&$cur[$key]['ENTRIES']));
760 }
761 }else{
763 if(isset($tmp['ENTRIES'])){
764 unset($tmp['ENTRIES']);
765 }
766 if($tmp['STATUS'] != "REMOVED"){
767 $ret[] = $tmp;
768 if(isset($entry['ENTRIES']) && count($entry['ENTRIES'])){
769 $add = false;
770 foreach($entry['ENTRIES'] as $entry){
771 if($entry['STATUS'] != "REMOVED"){
772 $add = TRUE;
773 break;
774 }
775 }
777 if($add){
778 $ret[] = array("TYPE" => "OPEN", "PARENT" => $entry['UNIQID']);
779 $ret = array_merge($ret,$this->_get_all_entries($add_tags,$skip_release,&$cur[$key]['ENTRIES']));
780 $ret[] = array("TYPE" => "CLOSE" , "PARENT" => $entry['UNIQID']);
781 }
782 }
783 }
784 }
785 }
786 return($ret);
787 }
790 /* !\brief Switch one entry with another
791 @param String from The source ID.
792 @param String type "up"/"down" type switched.
793 @param String to The destination ID.
794 return Boolean TRUE on success
795 */
796 function __switch_entries($from,$type,$to)
797 {
798 $all = $this->_get_all_entries();
800 $o_to = &$all[$to];
801 $o_from = &$all[$from];
803 print_a($o_to,$o_from);
805 /***********************
806 * Source == Destination
807 * Move into next parent.
808 ************************/
809 if($to == $from){
810 $to = $o_to['PARENT'];
811 $o_to = &$all[$to];
812 }
814 /***********************
815 * Target is container
816 ************************/
817 if(in_array($o_to['TYPE'],array("FOLDER","RELEASE"))){
819 /***********************
820 * Move into parent folder
821 * + Target
822 * |-> Source
823 ************************/
824 if($to == $o_from['PARENT']){
827 /* Check if source is a folder object
828 */
829 $o_to_sub = &$all[$o_to['PARENT']];
830 if(in_array($o_to_sub['TYPE'],array("FOLDER","RELEASE"))){
832 $o_from['STATUS'] = "ADDED";
834 /* Adding new */
835 $tmp2 = array();
836 $cnt = 0;
837 foreach($o_to_sub['ENTRIES'] as $key => $entry){
838 $cnt ++;
839 if($entry['UNIQID'] == $to){
840 break;
841 }
842 }
843 if($type == "up"){
844 $cnt --;
846 }
847 $this->_add_entry($o_to_sub['UNIQID'],$o_from,$cnt);
849 /* Removing old */
850 $tmp = array();
851 if(!$this->_remove_entry_id($from)){
852 return(FALSE);
853 }
854 }
855 }else{
857 /***********************
858 * Target is NOT parent container
859 * + Parent Folder
860 * |-> Source
861 * + Destination
862 ************************/
864 /* Removing old */
865 $o_to = $all[$to];
866 $o_from = $all[$from];
867 $this->_add_entry($to,$o_from);
868 $this->_remove_entry_id($from);
869 }
870 }else{
872 /***********************
873 * Source and Destination in some Folder.
874 * + Parent folder
875 * |-> Source
876 * |-> Destination
877 ************************/
878 $o_to = &$all[$to];
879 $o_from = &$all[$from];
880 $parent = &$all[$o_to['PARENT']];
882 if($o_to['PARENT'] == $o_from['PARENT']){
883 $tmp = $all[$to];
884 $all[$to] = $o_from;
885 $all[$from] = $tmp;
887 /* Ensure that the app priority is updated */
888 foreach($parent['ENTRIES'] as $key => $entry){
889 $parent['ENTRIES'][$key]['STATUS'] = "EDITED";
890 }
891 }
892 }
893 }
896 function save()
897 {
898 $ldap = $this->config->get_ldap_link();
899 $all = $this->_get_all_entries();
900 $prio = 0;
901 $Actions = array("Remove" => array(),"Edit" => array() , "Add" => array());
903 foreach($all as $entry){
904 $prio ++;
905 $cur = $entry;
906 $dn = "";
908 do{
909 if($cur['TYPE'] == "ENTRY"){
910 $dn.= "cn=".$cur['NAME'].",";
911 }elseif($cur['TYPE'] == "FOLDER"){
912 $dn.= "cn=".$cur['NAME'].",";
913 }elseif($cur['TYPE'] == "RELEASE"){
914 $dn.= "ou=".$cur['NAME'].",";
915 }elseif($cur['TYPE'] == "BASE"){
916 }
917 if(!isset($all[$cur['PARENT']])){
918 $cur = NULL;
919 }else{
920 $cur = $all[$cur['PARENT']];
921 }
922 }while(is_array($cur));
924 $cur_dn = $dn.$this->dn;
926 $attrs = array();
927 switch($entry['TYPE']){
928 case "ENTRY" :
929 {
930 $attrs['objectClass'] = "gotoMenuEntry";
931 $attrs['cn'] = $entry['NAME'];
932 $attrs['gosaApplicationPriority'] = $prio;
933 $attrs['gosaApplicationParameter'] = array();
935 foreach($entry['PARAMETER'] as $name => $value){
936 $attrs['gosaApplicationParameter'][] = $name.":".$value;
937 }
938 }
939 break;
940 case "FOLDER" :
941 {
942 $attrs['objectClass'] = "gotoSubmenuEntry";
943 $attrs['cn'] = $entry['NAME'];
944 $attrs['gosaApplicationPriority'] = $prio;
945 $attrs['gosaApplicationIcon'] = $entry['ICON'];
946 }
947 break;
948 case "RELEASE" :
949 {
950 $attrs['ou'] = $entry['NAME'];
951 $attrs['objectClass'] = array();
952 $attrs['objectClass'][] = "top";
953 $attrs['objectClass'][] = "organizationalUnit";
954 $attrs['objectClass'][] = "FAIbranch";
955 if(!empty($entry['FAIstate'])){
956 $attrs['FAIstate'] = $entry['FAIstate'];
957 }
958 }
959 break;
960 }
962 if($entry['STATUS'] == "LOADED"){
963 continue;
964 }
965 if($entry['STATUS'] == "REMOVED"){
966 $Actions['Remove'][$cur_dn] = $cur_dn;
967 }
968 if($entry['STATUS'] == "EDITED"){
969 $Actions['Edit'][$cur_dn] = $attrs;
970 }
971 if($entry['STATUS'] == "ADDED"){
972 $Actions['Add'][$cur_dn] = $attrs;
973 }
974 }
976 $ldap = $this->config->get_ldap_link();
977 $ldap->cd($this->config->current['BASE']);
978 foreach($Actions['Remove'] as $dn){
979 $ldap->cd($dn);
980 $ldap->cat($dn);
981 if($ldap->count()){
982 $ldap->rmdir_recursive($dn);
983 }
984 }
985 foreach($Actions['Add'] as $dn => $data){
986 $ldap->cd($dn);
987 $ldap->cat($dn);
988 if(!$ldap->count()){
989 $ldap->add($data);
990 }
991 }
992 foreach($Actions['Edit'] as $dn => $data){
993 $ldap->cd($dn);
994 $ldap->cat($dn);
995 if($ldap->count()){
996 $ldap->modify($data);
997 }
998 }
999 }
1002 /* Return plugin informations for acl handling */
1003 static function plInfo()
1004 {
1005 return (array(
1006 "plShortName" => _("Applications"),
1007 "plDescription" => _("Group applications"),
1008 "plSelfModify" => FALSE,
1009 "plDepends" => array(),
1010 "plPriority" => 0,
1011 "plSection" => array("admin"),
1012 "plCategory" => array("groups"),
1013 "plProvidedAcls"=> array(
1014 "gosaMemberApplication" => _("Application"),
1015 "FAIrelease" => _("Release"),
1016 "gosaApplicationParameter" => _("Application parameter"))
1017 ));
1018 }
1021 function PrepareForCopyPaste($source)
1022 {
1023 }
1026 function multiple_save_object()
1027 {
1028 if(isset($_POST['group_apps_multi'])){
1029 $this->save_object();
1030 plugin::multiple_save_object();
1032 /* Get posts */
1033 foreach(array("apps") as $attr){
1034 if(isset($_POST['use_'.$attr])) {
1035 $this->multi_boxes[] = $attr;
1036 }
1037 }
1038 }
1039 }
1042 function get_multi_edit_values()
1043 {
1044 $ret = plugin::get_multi_edit_values();
1046 if(in_array("apps",$this->multi_boxes)){
1047 $ret['gosaApplicationParameter'] = $this->gosaApplicationParameter;
1048 $ret['Categories'] = $this->Categories;
1049 $ret['gosaMemberApplication'] = $this->gosaMemberApplication;
1050 $ret['FAIrelease'] = $this->FAIrelease;
1051 $ret['appoption'] = $this->appoption;
1052 }
1053 return($ret);
1054 }
1055 }
1056 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1057 ?>