736c591d74fa78e3435dfeab1badbe0476fb2979
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();
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 echo "Fehler";
512 return;
513 }
515 $o_to = $all[$to];
516 $o_from = $all[$id];
518 if($o_to['PARENT'] == $o_from['UNIQID'] && $dir == "down"){
519 $to = $this->_get_next($to,$o_from['PARENT']);
520 $o_to = $all[$to];
521 }
524 /* Target is ENTRY && same BASE, just switch */
525 if($o_to['PARENT'] == $o_from['PARENT'] ){
526 $parent = $all[$o_to['PARENT']];
527 $pos = 0;
528 foreach($parent['ENTRIES'] as $entry){
529 $pos ++;
530 if($entry['UNIQID'] == $to){
531 break;
532 }
533 }
534 if($dir == "up" && $pos > 0){
535 $pos --;
536 }
537 $this->_add_entry($parent['UNIQID'],$o_from,$pos);
538 $this->_remove_entry_id($id);
539 return(TRUE);
540 }
541 return(FALSE);
542 }
546 function _get_last($id)
547 {
548 $all_l = array_reverse($this->_get_entries_for_release($this->FAIrelease));
549 for($i = 0 ; $i < count($all_l) ; $i ++){
550 if(isset($all_l[$i]['UNIQID']) && $all_l[$i]['UNIQID'] == $id){
551 $i++;
552 break;
553 }
554 }
555 while(isset($all_l[$i]) && !in_array($all_l[$i]['TYPE'],array("ENTRY","FOLDER","CLOSE","OPEN")) && $i < count($all_l)){
556 $i++;
557 }
559 if(!isset($all_l[$i])){
560 return(FALSE);
561 }
563 if(in_array($all_l[$i]['TYPE'],array("CLOSE","OPEN"))){
564 return($all_l[$i]['PARENT']);
565 }
567 return($all_l[$i]['UNIQID']);
568 }
571 function _get_next($id,$parent = 0)
572 {
573 $all_l = $this->_get_entries_for_release($this->FAIrelease);
574 for($i = 0 ; $i < count($all_l) ; $i ++){
575 if(isset($all_l[$i]['UNIQID']) && $all_l[$i]['UNIQID'] == $id){
576 $i++;
577 break;
578 }
579 }
580 if($parent != 0){
581 while(isset($all_l[$i]) && $all_l[$i]['PARENT'] != $parent){
582 $i++;
583 }
584 }else{
585 while(isset($all_l[$i]) && !in_array($all_l[$i]['TYPE'],array("ENTRY","FOLDER")) && $i < count($all_l)){
586 $i++;
587 }
588 }
589 if(!isset($all_l[$i])){
590 return(FALSE);
591 }
592 if(in_array($all_l[$i]['TYPE'],array("CLOSE","OPEN"))){
593 return($all_l[$i]['PARENT']);
594 }
595 return($all_l[$i]['UNIQID']);
596 }
601 /* !\brief Handle ui POSTS, like sort up/down/delete
602 */
603 function save_object()
604 {
605 foreach($_POST as $name => $value){
606 if(preg_match("/del_/",$name)){
607 $id = preg_replace("/^del_/","",$name);
608 $id = preg_replace("/_(x|y)$/","",$id);
609 $this->_remove_entry_id($id);
610 break;
611 }
612 if(preg_match("/app_entry_edit/",$name)){
613 $id = preg_replace("/^app_entry_edit/","",$name);
614 $id = preg_replace("/_(x|y)$/","",$id);
615 $this->_edit_entry_edit($id);
616 break;
617 }
618 if(preg_match("/up_/",$name)){
619 $id = preg_replace("/^up_/","",$name);
620 $id = preg_replace("/_(x|y)$/","",$id);
621 # $this->_move_entry_up($id);
622 $this->_move_entry($id,"up");
623 break;
624 }
625 if(preg_match("/down_/",$name)){
626 $id = preg_replace("/^down_/","",$name);
627 $id = preg_replace("/_(x|y)$/","",$id);
628 # $this->_move_entry_down($id);
629 $this->_move_entry($id,"down");
630 break;
631 }
632 if(preg_match("/^parameter_/",$name) &&
633 count($this->edit_entry) && $this->edit_entry['TYPE'] == "ENTRY"){
634 $name = preg_replace("/^parameter_/","",$name);
635 $this->app_parameter[$name] = $value;
636 }
637 }
638 if(isset($_POST['FAIrelease'])){
639 $this->FAIrelease = $_POST['FAIrelease'];
640 $this->_check_missing_release($this->FAIrelease);
641 }
642 if(isset($_GET['act']) && $_GET['act'] == 'depopen'){
643 $this->curbase = base64_decode($_GET['depid']);
644 }
645 if(isset($_POST['add_to_folder']) && isset($_POST['folder'])){
646 $folder = $_POST['folder'];
647 foreach($_POST as $name => $value){
648 if(preg_match("/^AddApp_[0-9]*$/",$name)){
649 $this->_add_app_id($folder,preg_replace("/^AddApp_/","",$name));
650 }
651 }
652 }
653 if(isset($_POST['add_menu_to_folder']) && isset($_POST['menu_folder'])){
654 $folder = $_POST['menu_folder'];
655 $name = $_POST['menu_folder_name'];
656 if(strlen($name) > 0 && preg_match("/[a-z ]/i",$name)){
657 $this->_add_sub_folder($folder,$name);
658 }
659 }
660 if(isset($_POST['app_entry_save'])){
661 $this->_save_entry_edit();
662 }
664 if(isset($_FILES['folder_image']) && isset($_POST['folder_image_upload'])){
665 if($_FILES['folder_image']['error'] == 0 && $_FILES['folder_image']['size'] > 0){
666 $this->edit_entry['ICON'] = file_get_contents($_FILES['folder_image']['tmp_name']);
667 }
668 }
670 if(isset($_POST['edit_reset_image'])){
671 $this->edit_entry['ICON'] = "";
672 }
674 if(isset($_POST['app_entry_cancel'])){
675 $this->edit_entry = array();
676 $this->dialog = FALSE;
677 }
678 $this->reload();
679 }
682 /*! \brief Returns the UNIQID of the currently selected release
683 */
684 function _get_release_key($release,$add_if_missing = FALSE)
685 {
686 $release_info = $this->Releases[$release];
688 if($release_info['name'] == "/"){
689 return($this->a_Structure['0']['UNIQID']);
690 }
692 $cur = &$this->a_Structure[0]['ENTRIES'];
693 $s_key = "";
694 $found = FALSE;
695 foreach($release_info['parts'] as $name){
696 foreach($cur as $key => $obj){
697 if($obj['TYPE'] == "RELEASE" && $obj['NAME'] == $name){
698 $s_key = $cur[$key]['UNIQID'];
699 $cur = &$cur[$key]['ENTRIES'];
700 $found = TRUE;
701 break;
702 }
703 $found = FALSE;
704 }
705 }
706 if($found){
707 return($s_key);
708 }
709 return(FALSE);
710 }
713 /*! \brief Add a new folder folder to the specified folder id
714 @param String $folder The folder id in where we want to add the new folder.
715 @param String $name The name of the new folder.
716 */
717 function _add_sub_folder($folder,$name)
718 {
719 $all = $this->_get_all_entries();
720 if($folder == "BASE"){
721 $folder = $this->_get_release_key($this->FAIrelease,TRUE);
722 }
724 if(isset($all[$folder])){
725 $a_folder = array();
726 $a_folder['STATUS'] = "ADDED";
727 $a_folder['NAME'] = $name;
728 $a_folder['UNIQID'] = uniqid();
729 $a_folder['ENTRIES']= array();
730 $a_folder['PARENT'] = $folder;
731 $a_folder['TYPE'] = "FOLDER";
732 $a_folder['ICON'] = "";
733 $all[$folder]['ENTRIES'][] = $a_folder;
734 }
735 }
738 /* !\brief Remove the given id from the menu structure.
739 @param String ID to of the entry we want to remove.
740 @return Boolean TRUE on success
741 */
742 function _remove_entry_id($id)
743 {
744 $all = $this->_get_all_entries();
745 if(isset($all[$id])){
746 $all[$id]['STATUS'] = "REMOVED";
747 return(TRUE);
748 }
749 return(FALSE);
750 }
753 /* !\brief Remove the given id from the menu structure.
754 @param String ID to of the entry we want to remove.
755 @return Boolean TRUE on success
756 */
757 function _add_entry($folder_id,$entry,$pos = 0)
758 {
759 $all = $this->_get_all_entries();
761 /* Do not add removed */
762 if($entry['STATUS'] == "REMOVED"){
763 return;
764 }
766 if(isset($all[$folder_id])){
768 $folder = &$all[$folder_id];
769 $entries = $entry['ENTRIES'];
771 $entry['UNIQID'] = uniqid();
772 $entry['PARENT'] = $folder_id;
773 $entry['ENTRIES']= array();
774 $entry['STATUS'] = "ADDED";
776 $cnt = 0;
777 $new = array();
778 $added =FALSE;
779 foreach($folder['ENTRIES'] as $key => $obj){
780 if($pos == $cnt){
781 $new[] = $entry;
782 $added = TRUE;
783 }
784 $cnt ++;
785 $new[] = $obj;
786 }
787 if(!$added){
788 echo "hmkk";
789 $new[] = $entry;
790 }
791 $all[$folder_id]['ENTRIES'] = $new;
792 foreach($entries as $sub){
793 $this->_add_entry($entry['UNIQID'],$sub);
794 }
795 return(TRUE);
796 }
797 return(FALSE);
798 }
801 /*! \brief Add the application identified by $app_id to folder $folder_id
802 @param String folder_id The UNIQID of the folder where we want to add the new folder.
803 @param Integer app_id The ID of the application which should be added.
804 */
805 function _add_app_id($folder_id,$app_id)
806 {
807 $all = $this->_get_all_entries();
808 if($folder_id == "BASE"){
809 $folder_id = $this->_get_release_key($this->FAIrelease);
810 }
811 if(isset($all[$folder_id]) && isset($this->apps[$app_id])){
813 $new = array();
814 $new['TYPE'] = "ENTRY";
815 $new['NAME'] = $this->apps[$app_id]['cn'][0];
816 $new['UNIQID']= uniqid();
817 $new['PARENT']= $folder_id;
818 $new['PARAMETER']= array();
819 if(isset($this->apps[$app_id]['description'][0])){
820 $new['INFO'] = $this->apps[$app_id]['description'][0];
821 }else{
822 $new['INFO'] = "";
823 }
824 $new['STATUS']= "ADDED";
825 $all[$folder_id]['ENTRIES'][] = $new;
826 }
827 }
830 /*! \brief move the object identified by the given ID one position up.
831 @param String The ID of the entry to be moved.
832 @return Boolean TRUE on success, else FALSE;
833 */
834 function _move_entry_up($id)
835 {
837 $all = $this->_get_entries_for_release($this->FAIrelease);
838 $all2 = $this->_get_all_entries();
839 $parent = FALSE;
841 foreach($all as $entry){
842 if(isset($entry['STATUS']) && $entry['STATUS'] == "REMOVED"){
843 continue;
844 }
845 if(isset($entry['UNIQID']) && $entry['UNIQID'] == $id){
846 if($parent != FALSE){
847 return($this->__switch_entries($id,"up",$parent));
848 }
849 trigger_error("Unknown ID ".$id);
850 return(FALSE);
851 }else{
852 if(in_array($entry['TYPE'],array("CLOSE","OPEN"))){
853 $parent = $entry['PARENT'];
854 }else{
855 $parent = $entry['UNIQID'];
856 }
857 }
858 }
859 return(FALSE);
860 }
863 /*! \brief move the object identified by the given ID one position down.
864 @param String The ID of the entry to be moved.
865 @return Boolean TRUE on success, else FALSE;
866 */
867 function _move_entry_down($id)
868 {
869 $all = $this->_get_entries_for_release($this->FAIrelease);
870 $found = FALSE;
871 foreach($all as $entry){
873 if(isset($entry['STATUS']) && $entry['STATUS'] == "REMOVED"){
874 continue;
875 }
877 if(isset($entry['UNIQID']) && $entry['UNIQID'] == $id){
878 $found = TRUE;
879 continue;
880 }else{
881 if(in_array($entry['TYPE'],array("CLOSE","OPEN"))){
882 $parent = $entry['PARENT'];
883 }else{
884 $parent = $entry['UNIQID'];
885 }
886 if($found){
889 if($id == $parent && $entry['TYPE'] == "OPEN"){
891 for($i = 0 ; $i < count($all) ; $i ++){
892 $sub = $all[$i];
893 if($sub['TYPE'] == "CLOSE" && $sub['PARENT'] == $entry['PARENT']){
894 $i++;
895 while($all[$i]['TYPE'] == "ENTRY" && count($all) < $i){
896 $i++;
897 }
898 if(isset($all[$i])){
899 $parent = $all[$i]['UNIQID'];
900 }
901 }
902 }
903 }
905 return($this->__switch_entries($id,"down",$parent));
906 }
907 }
908 }
909 return(FALSE);
910 }
913 /*! \brief Return all entries linear.
914 @param Boolean $add_tags If TRUE, OPEN/CLOSE Tags will be appended.
915 @param &Array Start here, Pointer to an array.
916 */
917 function _get_all_entries($add_tags = FALSE, $skip_release = FALSE, $cur = NULL)
918 {
919 $ret = array();
920 if($cur == NULL){
921 $cur = &$this->a_Structure;
922 }
923 foreach($cur as $key => $entry){
925 if($skip_release && $entry['TYPE'] == "RELEASE"){
926 continue;
927 }
928 if($entry['TYPE'] == "ENTRY"){
929 $found = FALSE;
930 foreach($this->apps as $app){
931 if($app['cn'][0] == $entry['NAME']){
932 $found = TRUE;
933 if(isset($app['description'][0])){
934 $entry['INFO'] = "[".$app['description'][0]."]";
935 }
936 break;
937 }
938 }
939 if(!$found){
940 $entry['INFO'] = "<font color='red'>"._("Not available in release.")."</font>";
941 }
942 }
945 $tmp = $entry;
946 if(!$add_tags){
947 $ret[$tmp['UNIQID']] = &$cur[$key];
948 if(isset($entry['ENTRIES']) && count($entry['ENTRIES'])){
949 $ret = array_merge($ret,$this->_get_all_entries($add_tags,$skip_release,&$cur[$key]['ENTRIES']));
950 }
951 }else{
953 if(isset($tmp['ENTRIES'])){
954 unset($tmp['ENTRIES']);
955 }
956 if($tmp['STATUS'] != "REMOVED"){
957 $ret[] = $tmp;
958 if(isset($entry['ENTRIES']) && count($entry['ENTRIES'])){
959 $add = false;
960 foreach($entry['ENTRIES'] as $entry){
961 if($entry['STATUS'] != "REMOVED"){
962 $add = TRUE;
963 break;
964 }
965 }
967 if($add){
968 $ret[] = array("TYPE" => "OPEN", "PARENT" => $entry['PARENT']);
969 $ret = array_merge($ret,$this->_get_all_entries($add_tags,$skip_release,&$cur[$key]['ENTRIES']));
970 $ret[] = array("TYPE" => "CLOSE" , "PARENT" => $entry['PARENT']);
971 }
972 }
973 }
974 }
975 }
976 return($ret);
977 }
980 /* !\brief Switch one entry with another
981 @param String from The source ID.
982 @param String type "up"/"down" type switched.
983 @param String to The destination ID.
984 return Boolean TRUE on success
985 */
986 function __switch_entries($from,$type,$to)
987 {
988 $all = $this->_get_all_entries();
990 $o_to = &$all[$to];
991 $o_from = &$all[$from];
993 if($o_to['TYPE'] == "ENTRY" && $o_from['TYPE'] == "FOLDER"){
994 echo "FEHLER 1";
995 return;
996 }
999 if($type == "down"){
1000 $this->_add_entry($o_to['UNIQID'],$o_from);
1001 $this->_remove_entry_id($from);
1002 }
1008 print_a(array($o_to,$o_from));
1010 return;
1011 /***********************
1012 * Source == Destination
1013 * Move into next parent.
1014 ************************/
1015 if($to == $from){
1016 $to = $o_to['PARENT'];
1017 $o_to = &$all[$to];
1018 }
1020 /***********************
1021 * Target is container
1022 ************************/
1023 if(in_array($o_to['TYPE'],array("FOLDER","RELEASE"))){
1025 /***********************
1026 * Move into parent folder
1027 * + Target
1028 * |-> Source
1029 ************************/
1030 if($to == $o_from['PARENT']){
1033 /* Check if source is a folder object
1034 */
1035 $o_to_sub = &$all[$o_to['PARENT']];
1036 if(in_array($o_to_sub['TYPE'],array("FOLDER","RELEASE"))){
1038 $o_from['STATUS'] = "ADDED";
1040 /* Adding new */
1041 $tmp2 = array();
1042 $cnt = 0;
1043 foreach($o_to_sub['ENTRIES'] as $key => $entry){
1044 $cnt ++;
1045 if($entry['UNIQID'] == $to){
1046 break;
1047 }
1048 }
1049 if($type == "up"){
1050 $cnt --;
1052 }
1053 $this->_add_entry($o_to_sub['UNIQID'],$o_from,$cnt);
1055 /* Removing old */
1056 $tmp = array();
1057 if(!$this->_remove_entry_id($from)){
1058 return(FALSE);
1059 }
1060 }
1061 }else{
1063 /***********************
1064 * Target is NOT parent container
1065 * + Parent Folder
1066 * |-> Source
1067 * + Destination
1068 ************************/
1070 /* Removing old */
1071 $o_to = $all[$to];
1072 $o_from = $all[$from];
1073 $this->_add_entry($to,$o_from);
1074 $this->_remove_entry_id($from);
1075 }
1076 }else{
1078 /***********************
1079 * Source and Destination in some Folder.
1080 * + Parent folder
1081 * |-> Source
1082 * |-> Destination
1083 ************************/
1084 $o_to = &$all[$to];
1085 $o_from = &$all[$from];
1086 $parent = &$all[$o_to['PARENT']];
1088 if($o_to['PARENT'] == $o_from['PARENT']){
1089 $tmp = $all[$to];
1090 $all[$to] = $o_from;
1091 $all[$from] = $tmp;
1093 /* Ensure that the app priority is updated */
1094 foreach($parent['ENTRIES'] as $key => $entry){
1095 $parent['ENTRIES'][$key]['STATUS'] = "EDITED";
1096 }
1097 }
1098 }
1099 }
1102 function save()
1103 {
1104 $ldap = $this->config->get_ldap_link();
1105 $all = $this->_get_all_entries();
1106 $prio = 0;
1107 $Actions = array("Remove" => array(),"Edit" => array() , "Add" => array());
1109 foreach($all as $entry){
1110 $prio ++;
1111 $cur = $entry;
1112 $dn = "";
1114 do{
1115 if($cur['TYPE'] == "ENTRY"){
1116 $dn.= "cn=".$cur['NAME'].",";
1117 }elseif($cur['TYPE'] == "FOLDER"){
1118 $dn.= "cn=".$cur['NAME'].",";
1119 }elseif($cur['TYPE'] == "RELEASE"){
1120 $dn.= "ou=".$cur['NAME'].",";
1121 }elseif($cur['TYPE'] == "BASE"){
1122 }
1123 if(!isset($all[$cur['PARENT']])){
1124 $cur = NULL;
1125 }else{
1126 $cur = $all[$cur['PARENT']];
1127 }
1128 }while(is_array($cur));
1130 $cur_dn = $dn.$this->dn;
1132 $attrs = array();
1133 switch($entry['TYPE']){
1134 case "ENTRY" :
1135 {
1136 $attrs['objectClass'] = "gotoMenuEntry";
1137 $attrs['cn'] = $entry['NAME'];
1138 $attrs['gosaApplicationPriority'] = $prio;
1139 $attrs['gosaApplicationParameter'] = array();
1142 foreach($entry['PARAMETER'] as $name => $value){
1143 $attrs['gosaApplicationParameter'][] = $name.":".$value;
1144 }
1145 if($entry['STATUS'] == "ADDED" && !count($attrs['gosaApplicationParameter'])){
1146 unset($attrs['gosaApplicationParameter']);
1147 }
1148 }
1149 break;
1150 case "FOLDER" :
1151 {
1152 $attrs['objectClass'] = "gotoSubmenuEntry";
1153 $attrs['cn'] = $entry['NAME'];
1154 $attrs['gosaApplicationPriority'] = $prio;
1155 if($entry['STATUS'] != "ADDED"){
1156 $attrs['gosaApplicationIcon'] = array();
1157 }
1159 if(!empty($entry['ICON'])){
1160 $attrs['gosaApplicationIcon'] = $entry['ICON'];
1161 }
1162 }
1163 break;
1164 case "RELEASE" :
1165 {
1166 $attrs['ou'] = $entry['NAME'];
1167 $attrs['objectClass'] = array();
1168 $attrs['objectClass'][] = "top";
1169 $attrs['objectClass'][] = "organizationalUnit";
1170 $attrs['objectClass'][] = "FAIbranch";
1171 if(!empty($entry['FAIstate'])){
1172 $attrs['FAIstate'] = $entry['FAIstate'];
1173 }
1174 }
1175 break;
1176 }
1178 if($entry['STATUS'] == "LOADED"){
1179 continue;
1180 }
1181 if($entry['STATUS'] == "REMOVED"){
1182 $Actions['Remove'][$cur_dn] = $cur_dn;
1183 }
1184 if($entry['STATUS'] == "EDITED"){
1185 $Actions['Edit'][$cur_dn] = $attrs;
1186 }
1187 if($entry['STATUS'] == "ADDED"){
1188 $Actions['Add'][$cur_dn] = $attrs;
1189 }
1190 }
1192 $ldap = $this->config->get_ldap_link();
1193 $ldap->cd($this->config->current['BASE']);
1194 foreach($Actions['Remove'] as $dn){
1195 $ldap->cd($dn);
1196 $ldap->cat($dn);
1197 if($ldap->count()){
1198 $ldap->rmdir_recursive($dn);
1199 show_ldap_error($ldap->get_error(), _("Could not save group application settings."));
1200 }
1201 }
1202 foreach($Actions['Add'] as $dn => $data){
1203 $ldap->cd($dn);
1204 $ldap->cat($dn);
1205 if(!$ldap->count()){
1206 $ldap->add($data);
1207 show_ldap_error($ldap->get_error(), _("Could not save group application settings."));
1208 }
1209 }
1210 foreach($Actions['Edit'] as $dn => $data){
1211 $ldap->cd($dn);
1212 $ldap->cat($dn);
1213 if($ldap->count()){
1214 $ldap->modify($data);
1215 show_ldap_error($ldap->get_error(), _("Could not save group application settings."));
1216 }
1217 }
1218 $this->_load_menu_structure();
1219 }
1222 /* Return plugin informations for acl handling */
1223 static function plInfo()
1224 {
1225 return (array(
1226 "plShortName" => _("Applications"),
1227 "plDescription" => _("Group applications"),
1228 "plSelfModify" => FALSE,
1229 "plDepends" => array(),
1230 "plPriority" => 0,
1231 "plSection" => array("admin"),
1232 "plCategory" => array("groups"),
1233 "plProvidedAcls"=> array(
1234 "gosaMemberApplication" => _("Application"),
1235 "FAIrelease" => _("Release"),
1236 "gosaApplicationParameter" => _("Application parameter"))
1237 ));
1238 }
1241 function PrepareForCopyPaste($source)
1242 {
1243 }
1246 function multiple_save_object()
1247 {
1248 if(isset($_POST['group_apps_multi'])){
1249 $this->save_object();
1250 plugin::multiple_save_object();
1252 /* Get posts */
1253 foreach(array("apps") as $attr){
1254 if(isset($_POST['use_'.$attr])) {
1255 $this->multi_boxes[] = $attr;
1256 }
1257 }
1258 }
1259 }
1262 function get_multi_edit_values()
1263 {
1264 $ret = plugin::get_multi_edit_values();
1266 if(in_array("apps",$this->multi_boxes)){
1267 $ret['gosaApplicationParameter'] = $this->gosaApplicationParameter;
1268 $ret['Categories'] = $this->Categories;
1269 $ret['gosaMemberApplication'] = $this->gosaMemberApplication;
1270 $ret['FAIrelease'] = $this->FAIrelease;
1271 $ret['appoption'] = $this->appoption;
1272 }
1273 return($ret);
1274 }
1275 }
1276 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1277 ?>