ce0f8e0e3b3ff0c68f60a6dd2be115bfeaf761e0
1 <?php
2 class appgroup extends plugin
3 {
4 /* CLI vars */
5 var $cli_summary= "Manage application groups";
6 var $cli_description= "Some longer text\nfor help";
7 var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
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();
24 var $enableReleaseManagement = FALSE;
26 public function __construct(&$config, $dn= NULL, $parent= NULL)
27 {
28 plugin::plugin($config,$dn,$parent);
29 $this->dn = $dn;
30 $this->_load_menu_structure();
31 $this->a_Structure_on_load = $this->a_Structure;
33 /* Check if we have relase mangement enabled and prepare group application for release management */
34 $tmp = $config->search("faiManagement", "CLASS",array('menu','tabs'));
35 if(!empty($tmp)){
36 $this->enableReleaseManagement = true;
37 }
39 $this->Releases = $this->getReleases();
40 $this->FAIrelease = "/";
41 $this->curbase = $this->config->current['BASE'];
42 $this->reload();
43 }
46 /*! \brief Reload the list of applications for the currently selected release
47 */
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 }
84 /*! \brief generate a list of available releases
85 @return return an array with all available releases.
86 */
87 function getReleases()
88 {
89 $ret =array("/" => array("name" => "/" , "parts" => array(),"suffix" => get_ou('applicationou')));
90 if($this->enableReleaseManagement){
92 /* Only display those releases that we are able to read */
93 $dn = $this->config->current['BASE'];
94 $filter = "(&(objectClass=organizationalUnit)(objectClass=FAIbranch))";
95 $res = get_list($filter,"application", $dn, array("ou","FAIstate"), GL_SUBSEARCH);
97 foreach($res as $attrs){
98 if(preg_match("/".get_ou('applicationou')."/",$attrs['dn'])){
99 $bb = preg_replace("/".get_ou('applicationou').".*/","",$attrs['dn']);
100 $parts = array_reverse(split("ou=",$bb));
102 $str ="";
103 foreach($parts as $key => $part){
104 if(empty($part)) {
105 unset($parts[$key]);
106 continue;
107 }
108 $part = str_replace(",","",$part);
109 $str .= $part."/";
110 $parts[$key] = $part;
111 }
112 $name = preg_replace("/\/$/","",$str);
113 if(empty($name)) {
114 $name ="/";
115 }
116 $FAIstate = "";
117 if(isset($attrs['FAIstate'])){
118 $FAIstate = $attrs['FAIstate'][0];
119 }
121 $ret[$name] = array("name" => $name,
122 "FAIstate" => $FAIstate,
123 "dn" => $attrs['dn'],
124 "parts" => $parts,"suffix" => $bb.get_ou('applicationou'));
125 }
126 }
127 }
128 ksort($ret);
129 return($ret);
130 }
133 /*! \brief Load the menu structure from ldap and create a multi dimensional array
134 */
135 function _load_menu_structure()
136 {
137 $this->a_Structure = array();
138 $ldap = $this->config->get_ldap_link();
139 $ldap->cd($this->dn);
140 $ldap->search("(|(objectClass=gotoSubmenuEntry)(objectClass=FAIbranch)(objectClass=gotoMenuEntry))",array("*"));
142 $base = array();
143 $base['UNIQID'] = uniqid();
144 $base['PARENT'] = 0;
145 $base['NAME'] = "";
146 $base['TYPE'] = "BASE";
147 $base['ENTRIES']= array();
148 $base['STATUS'] = "LOADED";
150 $this->a_Structure[0] = $base;
152 while($attrs = $ldap->fetch()){
153 $cur = &$this->a_Structure[0]['ENTRIES'];
154 $parent_id = $base['UNIQID'];
155 $sub_dn = preg_replace("/,".normalizePreg($this->dn)."$/","",$attrs['dn']);
156 $sub_dn_array = split("\,",$sub_dn);
159 for($i = (count($sub_dn_array)-1) ; $i >= 0 ; $i--){
160 $name = preg_replace("/^[^=]*+=/","",$sub_dn_array[$i]);
161 if($i > 0){
162 foreach($cur as $key => $entry){
163 if($entry['NAME'] == $name){
164 $cur = &$cur[$key]['ENTRIES'];
165 $parent_id = $entry['UNIQID'];
166 }
167 }
168 }else{
170 $priority = 1;
171 if(isset($attrs['gosaApplicationPriority'])){
172 $priority= $attrs['gosaApplicationPriority'][0];
173 }
174 while(isset($cur[$priority])){
175 $priority ++;
176 }
178 $data = array();
179 if(in_array("gotoSubmenuEntry",$attrs['objectClass'])){
180 $type = "FOLDER";
182 $data['ICON'] = "";
183 if(isset($attrs['gosaApplicationIcon'])){
184 $data['ICON'] = $ldap->get_attribute($attrs['dn'],"gosaApplicationIcon");
185 }
187 }elseif(in_array("gotoMenuEntry",$attrs['objectClass'])){
188 $type = "ENTRY";
189 $data['INFO'] = "";
190 $data['PARAMETER'] = array();
191 if(isset($attrs['gosaApplicationParameter'])){
192 for($p = 0 ; $p < $attrs['gosaApplicationParameter']['count'] ; $p ++){
193 $tmp = split(":",$attrs['gosaApplicationParameter'][$p]);
194 $data['PARAMETER'][$tmp[0]] = $tmp[1];
195 }
196 }
197 }elseif(in_array("FAIbranch",$attrs['objectClass'])){
199 $type = "RELEASE";
200 if(isset($attrs['FAIstate'][0])){
201 $data['FAIstate'] = $attrs['FAIstate'][0];
202 }else{
203 $data['FAIstate'] = "";
204 }
205 }
207 $data['DN'] = $attrs['dn'];
208 $data['NAME'] = $name;
209 $data['TYPE'] = $type;
210 $data['PRIORITY'] = $priority;
211 $data['ENTRIES'] = array();
212 $data['UNIQID'] = uniqid();
213 $data['PARENT'] = $parent_id;
214 $data['STATUS'] = "LOADED";
215 $cur[$priority] = $data;
216 ksort($cur);
217 }
218 }
219 }
220 }
223 function execute()
224 {
225 /* Call parent execute */
226 plugin::execute();
228 if(isset($_GET['send'])){
229 $id = $_GET['send'];
230 $all = $this->_get_all_entries();
231 if(isset($all[$id])){
232 send_binary_content($all[$id]['ICON'],$id.".jpg","image/jpeg");
233 exit;
234 }
235 }
237 if(isset($_GET['r']))
238 $this->__construct($this->config,$this->dn);
240 if(count($this->edit_entry)){
241 if($this->edit_entry['TYPE'] == "ENTRY"){
242 $smarty = get_smarty();
243 $smarty->assign("type", "ENTRY");
244 $smarty->assign("entry",$this->edit_entry);
245 $smarty->assign("paras",$this->app_parameter);
246 $display= $smarty->fetch (get_template_path('edit_entry.tpl', TRUE, dirname(__FILE__)));
247 return($display);
248 }
249 if($this->edit_entry['TYPE'] == "FOLDER"){
250 $smarty = get_smarty();
252 session::set("binarytype" , "image/jpeg");
253 session::set("binary" , $this->edit_entry['ICON']);
255 $smarty->assign("rand", microtime(TRUE));
256 $smarty->assign("image_set" , strlen($this->edit_entry['ICON']) > 0);
257 $smarty->assign("type", "FOLDER");
258 $smarty->assign("entry",$this->edit_entry);
259 $display= $smarty->fetch (get_template_path('edit_entry.tpl', TRUE, dirname(__FILE__)));
260 return($display);
261 }
262 }
264 $smarty = get_smarty();
265 $smarty->assign("plug_id" , $_GET['plug']);
267 /* Create application list */
268 $div = new divSelectBox("appgroup");
269 $div->SetHeight(300);
270 $departments = array();
271 $res = get_list("(objectClass=gosaDepartment)", "application", $this->curbase,array("description","cn","ou"),GL_SIZELIMIT);
272 foreach($res as $value){
273 $fdn = $value['dn'];
274 $fdn = preg_replace("/".normalizePreg($this->curbase)."/","",$fdn);
275 $fdn= @LDAP::fix($fdn);
276 if($value["description"][0]!=".."){
277 $departments[$value['dn']]= convert_department_dn($fdn)." - [".$value["description"][0]."]";
278 }else{
279 $departments[$value['dn']]=convert_department_dn($fdn)." ["._("Back")."]";
280 }
281 }
283 $linkopen = "<a href='?plug=".$_GET['plug']."&act=depopen&depid=%s'>%s</a>";
285 /* Create base back entry */
286 $base_back = preg_replace("/^[^,]+,/","",$this->curbase);
287 if((strlen($base_back)>= strlen($this->config->current['BASE']))&&($this->curbase!=$this->config->current['BASE'])){
288 $div->AddEntry(array(
289 array("string"=>sprintf($linkopen,base64_encode($base_back),".. ["._("back")."]"),
290 "attach"=>"style='border:0px;'")
291 ));
292 }
294 /* Append departments for current base */
295 foreach($departments as $key => $app){
296 $div->AddEntry(array(
297 array("string"=>"<img class='center' src='images/folder.png' alt='"._("department")."'> ".sprintf($linkopen,
298 base64_encode($key),$app),
299 "attach"=>"style='border:0px;'")
300 ));
301 }
304 /* Add applications found on this base */
305 $used_apps = $this->_get_used_entry_name();
306 foreach($this->apps as $key => $app){
307 if(in_array($app['cn'][0],$used_apps)){
308 continue;
309 }
310 if(!preg_match("/".get_ou('applicationou').normalizePreg($this->curbase)."$/",$app['dn'])){
311 continue;
312 }
314 $name = $app['cn'][0];
315 if(isset($app['description'])){
316 $name .= " [".$app['description'][0]."]";
317 }
318 $div->AddEntry(array(
319 array("string"=>sprintf("<input class='center' type='checkbox' value='1' name='AddApp_%s'>",$key).
320 "<img class='center' src='images/select_application.png' alt='"._("application")."'> ".$name,
321 "attach"=>"style='border:0px;'")
322 ));
323 }
326 $smarty->assign("enableReleaseManagement",$this->enableReleaseManagement);
327 $smarty->assign("FAIrelease",$this->FAIrelease);
328 $smarty->assign("app_list",$div->DrawList());
329 $smarty->assign("releases",$this->Releases);
330 $smarty->assign("folders" , $this->_get_folder_names());
331 $entries = $this->_get_entries_for_release($this->FAIrelease);
332 $smarty->assign("entries",$entries);
333 $display= $smarty->fetch (get_template_path('app_list.tpl', TRUE, dirname(__FILE__)));
334 return($display);
335 }
338 /*! \brief Returns all used folder names
339 @return Array All used folder names.
340 */
341 function _get_folder_names()
342 {
343 $data = $this->_get_entries_for_release($this->FAIrelease);
344 $ret = array("BASE" => ".");
345 foreach($data as $entry){
346 if($entry['TYPE'] == "FOLDER"){
347 $ret[$entry['UNIQID']] = $entry['NAME'];
348 }
349 }
350 return($ret);
351 }
354 /*! \brief return all used applications
355 @return Array All used applications.
356 */
357 function _get_used_entry_name()
358 {
359 $data = $this->_get_entries_for_release($this->FAIrelease);
360 $ret = array();
361 foreach($data as $entry){
362 if($entry['TYPE'] == "ENTRY"){
363 $ret[] = $entry['NAME'];
364 }
365 }
366 return($ret);
367 }
370 /*! \brief Returns all folder an entries for the selected release
371 @return Array Returns the complete menu structure for the given array.
372 */
373 function _get_entries_for_release($release,$cur = NULL)
374 {
375 $all = $this->_get_all_entries();
376 $key = $this->_get_release_key($release);
377 if(isset($all[$key]) && count($all[$key]['ENTRIES'])){
378 $res = $this->_get_all_entries(TRUE,TRUE,&$all[$key]['ENTRIES']);
379 return($res);
380 }
381 return(array());
382 }
385 /*! \brief Save the currently edited entry */
386 function _save_entry_edit()
387 {
388 $all = $this->_get_all_entries();
389 $entry = $this->edit_entry;
390 $r_entry= &$all[$entry['UNIQID']];
392 if($entry['TYPE'] == "ENTRY"){
393 $r_entry['PARAMETER'] = $this->app_parameter;
394 $r_entry['STATUS'] = "EDITED";
395 }
396 if($entry['TYPE'] == "FOLDER"){
397 $r_entry['ICON'] = $this->edit_entry['ICON'];
398 $r_entry['STATUS'] = "EDITED";
399 }
400 $this->dialog = FALSE;
401 $this->edit_entry = array();
402 }
405 /*! \brief prepare the entry with the given ID, to be edited.
406 */
407 function _edit_entry_edit($id)
408 {
409 $all = $this->_get_all_entries();
410 $entry = $all[$id];
412 $this->app_parameter = array();
413 if($entry['TYPE'] == "ENTRY"){
414 $found = FALSE;
415 foreach($this->apps as $id => $app){
417 if($app['cn'][0] == $entry['NAME']){
418 $found = TRUE;
419 break;
420 }
421 }
422 if($found){
424 /* Create a list of editable parameter */
425 if(isset($app['gosaApplicationParameter'])){
426 for($i = 0 ; $i < $app['gosaApplicationParameter']['count'] ; $i++) {
427 $para = $app['gosaApplicationParameter'][$i];
428 $tmp = split(":",$para);
429 $this->app_parameter[$tmp[0]] = $tmp[1];
430 }
431 }
433 /* Overwrite parameters with entry parameters */
434 foreach($entry['PARAMETER'] as $name => $value){
435 $this->app_parameter[$name] = $value;
436 }
438 $this->dialog = TRUE;
439 $this->edit_entry = $entry;
440 }
441 }
443 if($entry['TYPE'] == "FOLDER"){
444 $this->dialog = TRUE;
445 $this->edit_entry = $entry;
446 }
447 }
450 function remove_from_parent()
451 {
452 }
456 function check()
457 {
458 }
461 /*! \brief Create missing releases, if there is a release selected \
462 that is currently not part of the menu structure \
463 then create this entry
464 */
465 function _check_missing_release($release)
466 {
467 $release_info = $this->Releases[$release];
469 $parent_id = $this->a_Structure[0]['UNIQID'];
470 $cur = &$this->a_Structure[0]['ENTRIES'];
471 for($i = 0 ; $i < count($release_info['parts']) ; $i ++){
472 $part = $release_info['parts'][$i];
473 $found = FALSE;
474 foreach($cur as $key => $name){
475 if($name['NAME'] == $part){
476 $parent_id = $cur[$key]['UNIQID'];
477 $cur = &$cur[$key]['ENTRIES'];
479 $found =TRUE;
480 break;
481 }
482 }
483 if(!$found){
484 $release = array();
485 $release['UNIQID'] = uniqid();
486 $release['PARENT'] = $parent_id;
487 $release['NAME'] = $part;
488 $release['TYPE'] = "RELEASE";
489 $release['ENTRIES']= array();
490 $release['STATUS'] = "ADDED";
491 $release['FAIstate'] = $release_info['FAIstate'];
492 $cur[] = $release;
493 $i --;
494 }
495 }
496 }
500 function _move_entry($id,$dir)
501 {
502 $all = $this->_get_all_entries();
503 if($dir == "down"){
504 $to = $this->_get_next($id);
505 }
506 if($dir == "up"){
507 $to = $this->_get_last($id);
508 }
510 if(!$to){
511 return;
512 }
514 $o_to = $all[$to];
515 $o_from = $all[$id];
517 if($o_to['PARENT'] == $o_from['UNIQID'] && $dir == "down"){
518 $to = $this->_get_next($to,$o_from['PARENT']);
519 $o_to = $all[$to];
520 }
523 /* Target is ENTRY && same BASE, just switch */
524 if($o_to['PARENT'] == $o_from['PARENT'] ){
525 $parent = $all[$o_to['PARENT']];
526 $pos = 0;
527 foreach($parent['ENTRIES'] as $entry){
528 $pos ++;
529 if($entry['UNIQID'] == $to){
530 break;
531 }
532 }
533 if($dir == "up" && $pos > 0){
534 $pos --;
535 }
536 $this->_add_entry($parent['UNIQID'],$o_from,$pos);
537 $this->_remove_entry_id($id);
538 return(TRUE);
539 }
540 return(FALSE);
541 }
545 function _get_last($id)
546 {
547 $all_l = array_reverse($this->_get_entries_for_release($this->FAIrelease));
548 for($i = 0 ; $i < count($all_l) ; $i ++){
549 if(isset($all_l[$i]['UNIQID']) && $all_l[$i]['UNIQID'] == $id){
550 $i++;
551 break;
552 }
553 }
554 while(isset($all_l[$i]) && !in_array($all_l[$i]['TYPE'],array("ENTRY","FOLDER","CLOSE","OPEN")) && $i < count($all_l)){
555 $i++;
556 }
558 if(!isset($all_l[$i])){
559 return(FALSE);
560 }
562 if(in_array($all_l[$i]['TYPE'],array("CLOSE","OPEN"))){
563 return($all_l[$i]['PARENT']);
564 }
566 return($all_l[$i]['UNIQID']);
567 }
570 function _get_next($id,$parent = 0)
571 {
572 $all_l = $this->_get_entries_for_release($this->FAIrelease);
573 for($i = 0 ; $i < count($all_l) ; $i ++){
574 if(isset($all_l[$i]['UNIQID']) && $all_l[$i]['UNIQID'] == $id){
575 $i++;
576 break;
577 }
578 }
579 if($parent != 0){
580 while(isset($all_l[$i]) && $all_l[$i]['PARENT'] != $parent){
581 $i++;
582 }
583 }else{
584 while(isset($all_l[$i]) && !in_array($all_l[$i]['TYPE'],array("ENTRY","FOLDER")) && $i < count($all_l)){
585 $i++;
586 }
587 }
588 if(!isset($all_l[$i])){
589 return(FALSE);
590 }
591 if(in_array($all_l[$i]['TYPE'],array("CLOSE","OPEN"))){
592 return($all_l[$i]['PARENT']);
593 }
594 return($all_l[$i]['UNIQID']);
595 }
600 /* !\brief Handle ui POSTS, like sort up/down/delete
601 */
602 function save_object()
603 {
604 foreach($_POST as $name => $value){
605 if(preg_match("/del_/",$name)){
606 $id = preg_replace("/^del_/","",$name);
607 $id = preg_replace("/_(x|y)$/","",$id);
608 $this->_remove_entry_id($id);
609 break;
610 }
611 if(preg_match("/app_entry_edit/",$name)){
612 $id = preg_replace("/^app_entry_edit/","",$name);
613 $id = preg_replace("/_(x|y)$/","",$id);
614 $this->_edit_entry_edit($id);
615 break;
616 }
617 if(preg_match("/up_/",$name)){
618 $id = preg_replace("/^up_/","",$name);
619 $id = preg_replace("/_(x|y)$/","",$id);
620 $this->_move_entry($id,"up");
621 break;
622 }
623 if(preg_match("/down_/",$name)){
624 $id = preg_replace("/^down_/","",$name);
625 $id = preg_replace("/_(x|y)$/","",$id);
626 $this->_move_entry($id,"down");
627 break;
628 }
629 if(preg_match("/^parameter_/",$name) &&
630 count($this->edit_entry) && $this->edit_entry['TYPE'] == "ENTRY"){
631 $name = preg_replace("/^parameter_/","",$name);
632 $this->app_parameter[$name] = $value;
633 }
634 }
635 if(isset($_POST['FAIrelease'])){
636 $this->FAIrelease = $_POST['FAIrelease'];
637 $this->_check_missing_release($this->FAIrelease);
638 }
639 if(isset($_GET['act']) && $_GET['act'] == 'depopen'){
640 $this->curbase = base64_decode($_GET['depid']);
641 }
642 if(isset($_POST['add_to_folder']) && isset($_POST['folder'])){
643 $folder = $_POST['folder'];
644 foreach($_POST as $name => $value){
645 if(preg_match("/^AddApp_[0-9]*$/",$name)){
646 $this->_add_app_id($folder,preg_replace("/^AddApp_/","",$name));
647 }
648 }
649 }
650 if(isset($_POST['add_menu_to_folder']) && isset($_POST['menu_folder'])){
651 $folder = $_POST['menu_folder'];
652 $name = $_POST['menu_folder_name'];
653 if(strlen($name) > 0 && preg_match("/[a-z ]/i",$name)){
654 $this->_add_sub_folder($folder,$name);
655 }
656 }
657 if(isset($_POST['app_entry_save'])){
658 $this->_save_entry_edit();
659 }
661 if(isset($_FILES['folder_image']) && isset($_POST['folder_image_upload'])){
662 if($_FILES['folder_image']['error'] == 0 && $_FILES['folder_image']['size'] > 0){
663 $this->edit_entry['ICON'] = file_get_contents($_FILES['folder_image']['tmp_name']);
664 }
665 }
667 if(isset($_POST['edit_reset_image'])){
668 $this->edit_entry['ICON'] = "";
669 }
671 if(isset($_POST['app_entry_cancel'])){
672 $this->edit_entry = array();
673 $this->dialog = FALSE;
674 }
675 $this->reload();
676 }
679 /*! \brief Returns the UNIQID of the currently selected release
680 */
681 function _get_release_key($release,$add_if_missing = FALSE)
682 {
683 $release_info = $this->Releases[$release];
685 if($release_info['name'] == "/"){
686 return($this->a_Structure['0']['UNIQID']);
687 }
689 $cur = &$this->a_Structure[0]['ENTRIES'];
690 $s_key = "";
691 $found = FALSE;
692 foreach($release_info['parts'] as $name){
693 foreach($cur as $key => $obj){
694 if($obj['TYPE'] == "RELEASE" && $obj['NAME'] == $name){
695 $s_key = $cur[$key]['UNIQID'];
696 $cur = &$cur[$key]['ENTRIES'];
697 $found = TRUE;
698 break;
699 }
700 $found = FALSE;
701 }
702 }
703 if($found){
704 return($s_key);
705 }
706 return(FALSE);
707 }
710 /*! \brief Add a new folder folder to the specified folder id
711 @param String $folder The folder id in where we want to add the new folder.
712 @param String $name The name of the new folder.
713 */
714 function _add_sub_folder($folder,$name)
715 {
716 $all = $this->_get_all_entries();
717 if($folder == "BASE"){
718 $folder = $this->_get_release_key($this->FAIrelease,TRUE);
719 }
721 if(isset($all[$folder])){
722 $a_folder = array();
723 $a_folder['STATUS'] = "ADDED";
724 $a_folder['NAME'] = $name;
725 $a_folder['UNIQID'] = uniqid();
726 $a_folder['ENTRIES']= array();
727 $a_folder['PARENT'] = $folder;
728 $a_folder['TYPE'] = "FOLDER";
729 $a_folder['ICON'] = "";
730 $all[$folder]['ENTRIES'][] = $a_folder;
731 }
732 }
735 /* !\brief Remove the given id from the menu structure.
736 @param String ID to of the entry we want to remove.
737 @return Boolean TRUE on success
738 */
739 function _remove_entry_id($id)
740 {
741 $all = $this->_get_all_entries();
742 if(isset($all[$id])){
743 $all[$id]['STATUS'] = "REMOVED";
744 return(TRUE);
745 }
746 return(FALSE);
747 }
750 /* !\brief Remove the given id from the menu structure.
751 @param String ID to of the entry we want to remove.
752 @return Boolean TRUE on success
753 */
754 function _add_entry($folder_id,$entry,$pos = 0)
755 {
756 $all = $this->_get_all_entries();
758 /* Do not add removed */
759 if($entry['STATUS'] == "REMOVED"){
760 return;
761 }
763 if(isset($all[$folder_id])){
765 $folder = &$all[$folder_id];
766 $entries = $entry['ENTRIES'];
768 $entry['UNIQID'] = uniqid();
769 $entry['PARENT'] = $folder_id;
770 $entry['ENTRIES']= array();
771 $entry['STATUS'] = "ADDED";
773 $cnt = 0;
774 $new = array();
775 $added =FALSE;
776 foreach($folder['ENTRIES'] as $key => $obj){
777 if($pos == $cnt){
778 $new[] = $entry;
779 $added = TRUE;
780 }
781 $cnt ++;
782 $new[] = $obj;
783 }
784 if(!$added){
785 $new[] = $entry;
786 }
788 $all[$folder_id]['ENTRIES'] = $new;
789 foreach($entries as $sub){
790 $this->_add_entry($entry['UNIQID'],$sub,-1);
791 }
792 return(TRUE);
793 }
794 return(FALSE);
795 }
798 /*! \brief Add the application identified by $app_id to folder $folder_id
799 @param String folder_id The UNIQID of the folder where we want to add the new folder.
800 @param Integer app_id The ID of the application which should be added.
801 */
802 function _add_app_id($folder_id,$app_id)
803 {
804 $all = $this->_get_all_entries();
805 if($folder_id == "BASE"){
806 $folder_id = $this->_get_release_key($this->FAIrelease);
807 }
808 if(isset($all[$folder_id]) && isset($this->apps[$app_id])){
810 $new = array();
811 $new['TYPE'] = "ENTRY";
812 $new['NAME'] = $this->apps[$app_id]['cn'][0];
813 $new['UNIQID']= uniqid();
814 $new['PARENT']= $folder_id;
815 $new['PARAMETER']= array();
816 if(isset($this->apps[$app_id]['description'][0])){
817 $new['INFO'] = $this->apps[$app_id]['description'][0];
818 }else{
819 $new['INFO'] = "";
820 }
821 $new['STATUS']= "ADDED";
822 $all[$folder_id]['ENTRIES'][] = $new;
823 }
824 }
827 /*! \brief Return all entries linear.
828 @param Boolean $add_tags If TRUE, OPEN/CLOSE Tags will be appended.
829 @param &Array Start here, Pointer to an array.
830 */
831 function _get_all_entries($add_tags = FALSE, $skip_release = FALSE, $cur = NULL)
832 {
833 $ret = array();
834 if($cur == NULL){
835 $cur = &$this->a_Structure;
836 }
837 foreach($cur as $key => $entry){
839 if($skip_release && $entry['TYPE'] == "RELEASE"){
840 continue;
841 }
842 if($entry['TYPE'] == "ENTRY"){
843 $found = FALSE;
844 foreach($this->apps as $app){
845 if($app['cn'][0] == $entry['NAME']){
846 $found = TRUE;
847 if(isset($app['description'][0])){
848 $entry['INFO'] = "[".$app['description'][0]."]";
849 }
850 break;
851 }
852 }
853 if(!$found){
854 $entry['INFO'] = "<font color='red'>"._("Not available in release.")."</font>";
855 }
856 }
859 $tmp = $entry;
860 if(!$add_tags){
861 $ret[$tmp['UNIQID']] = &$cur[$key];
862 if(isset($entry['ENTRIES']) && count($entry['ENTRIES'])){
863 $ret = array_merge($ret,$this->_get_all_entries($add_tags,$skip_release,&$cur[$key]['ENTRIES']));
864 }
865 }else{
867 if(isset($tmp['ENTRIES'])){
868 unset($tmp['ENTRIES']);
869 }
870 if($tmp['STATUS'] != "REMOVED"){
871 $ret[] = $tmp;
872 if(isset($entry['ENTRIES']) && count($entry['ENTRIES'])){
873 $add = false;
874 foreach($entry['ENTRIES'] as $entry){
875 if($entry['STATUS'] != "REMOVED"){
876 $add = TRUE;
877 break;
878 }
879 }
881 if($add){
882 $ret[] = array("TYPE" => "OPEN", "PARENT" => $entry['PARENT']);
883 $ret = array_merge($ret,$this->_get_all_entries($add_tags,$skip_release,&$cur[$key]['ENTRIES']));
884 $ret[] = array("TYPE" => "CLOSE" , "PARENT" => $entry['PARENT']);
885 }
886 }
887 }
888 }
889 }
890 return($ret);
891 }
894 function save()
895 {
896 $ldap = $this->config->get_ldap_link();
897 $all = $this->_get_all_entries();
898 $prio = 0;
899 $Actions = array("Remove" => array(),"Edit" => array() , "Add" => array());
901 foreach($all as $entry){
902 $prio ++;
903 $cur = $entry;
904 $dn = "";
906 do{
907 if($cur['TYPE'] == "ENTRY"){
908 $dn.= "cn=".$cur['NAME'].",";
909 }elseif($cur['TYPE'] == "FOLDER"){
910 $dn.= "cn=".$cur['NAME'].",";
911 }elseif($cur['TYPE'] == "RELEASE"){
912 $dn.= "ou=".$cur['NAME'].",";
913 }elseif($cur['TYPE'] == "BASE"){
914 }
915 if(!isset($all[$cur['PARENT']])){
916 $cur = NULL;
917 }else{
918 $cur = $all[$cur['PARENT']];
919 }
920 }while(is_array($cur));
922 $cur_dn = $dn.$this->dn;
924 $attrs = array();
925 switch($entry['TYPE']){
926 case "ENTRY" :
927 {
928 $attrs['objectClass'] = "gotoMenuEntry";
929 $attrs['cn'] = $entry['NAME'];
930 $attrs['gosaApplicationPriority'] = $prio;
931 $attrs['gosaApplicationParameter'] = array();
934 foreach($entry['PARAMETER'] as $name => $value){
935 $attrs['gosaApplicationParameter'][] = $name.":".$value;
936 }
937 if($entry['STATUS'] == "ADDED" && !count($attrs['gosaApplicationParameter'])){
938 unset($attrs['gosaApplicationParameter']);
939 }
940 }
941 break;
942 case "FOLDER" :
943 {
944 $attrs['objectClass'] = "gotoSubmenuEntry";
945 $attrs['cn'] = $entry['NAME'];
946 $attrs['gosaApplicationPriority'] = $prio;
947 if($entry['STATUS'] != "ADDED"){
948 $attrs['gosaApplicationIcon'] = array();
949 }
951 if(!empty($entry['ICON'])){
952 $attrs['gosaApplicationIcon'] = $entry['ICON'];
953 }
954 }
955 break;
956 case "RELEASE" :
957 {
958 $attrs['ou'] = $entry['NAME'];
959 $attrs['objectClass'] = array();
960 $attrs['objectClass'][] = "top";
961 $attrs['objectClass'][] = "organizationalUnit";
962 $attrs['objectClass'][] = "FAIbranch";
963 if(!empty($entry['FAIstate'])){
964 $attrs['FAIstate'] = $entry['FAIstate'];
965 }
966 }
967 break;
968 }
970 if($entry['STATUS'] == "LOADED"){
971 continue;
972 }
973 if($entry['STATUS'] == "REMOVED"){
974 $Actions['Remove'][$cur_dn] = $cur_dn;
975 }
976 if($entry['STATUS'] == "EDITED"){
977 $Actions['Edit'][$cur_dn] = $attrs;
978 }
979 if($entry['STATUS'] == "ADDED"){
980 $Actions['Add'][$cur_dn] = $attrs;
981 }
982 }
984 $ldap = $this->config->get_ldap_link();
985 $ldap->cd($this->config->current['BASE']);
986 foreach($Actions['Remove'] as $dn){
987 $ldap->cd($dn);
988 $ldap->cat($dn);
989 if($ldap->count()){
990 $ldap->rmdir_recursive($dn);
991 show_ldap_error($ldap->get_error(), _("Could not save group application settings."));
992 }
993 }
994 foreach($Actions['Add'] as $dn => $data){
995 $ldap->cd($dn);
996 $ldap->cat($dn);
997 if(!$ldap->count()){
998 $ldap->add($data);
999 show_ldap_error($ldap->get_error(), _("Could not save group application settings."));
1000 }
1001 }
1002 foreach($Actions['Edit'] as $dn => $data){
1003 $ldap->cd($dn);
1004 $ldap->cat($dn);
1005 if($ldap->count()){
1006 $ldap->modify($data);
1007 show_ldap_error($ldap->get_error(), _("Could not save group application settings."));
1008 }
1009 }
1010 $this->_load_menu_structure();
1011 }
1014 /* Return plugin informations for acl handling */
1015 static function plInfo()
1016 {
1017 return (array(
1018 "plShortName" => _("Applications"),
1019 "plDescription" => _("Group applications"),
1020 "plSelfModify" => FALSE,
1021 "plDepends" => array(),
1022 "plPriority" => 0,
1023 "plSection" => array("admin"),
1024 "plCategory" => array("groups"),
1025 "plProvidedAcls"=> array(
1026 "gosaMemberApplication" => _("Application"),
1027 "FAIrelease" => _("Release"),
1028 "gosaApplicationParameter" => _("Application parameter"))
1029 ));
1030 }
1033 function PrepareForCopyPaste($source)
1034 {
1035 }
1038 function multiple_save_object()
1039 {
1040 if(isset($_POST['group_apps_multi'])){
1041 $this->save_object();
1042 plugin::multiple_save_object();
1044 /* Get posts */
1045 foreach(array("apps") as $attr){
1046 if(isset($_POST['use_'.$attr])) {
1047 $this->multi_boxes[] = $attr;
1048 }
1049 }
1050 }
1051 }
1054 function get_multi_edit_values()
1055 {
1056 $ret = plugin::get_multi_edit_values();
1058 if(in_array("apps",$this->multi_boxes)){
1059 $ret['gosaApplicationParameter'] = $this->gosaApplicationParameter;
1060 $ret['Categories'] = $this->Categories;
1061 $ret['gosaMemberApplication'] = $this->gosaMemberApplication;
1062 $ret['FAIrelease'] = $this->FAIrelease;
1063 $ret['appoption'] = $this->appoption;
1064 }
1065 return($ret);
1066 }
1067 }
1068 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1069 ?>