9785878ded6851ea69914c2f4d74ba06f06da461
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->FAIrelease = 0;
40 $this->Releases = $this->getReleases();
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['PARAMETER'] = array();
190 if(isset($attrs['gosaApplicationParameter'])){
191 for($p = 0 ; $p < $attrs['gosaApplicationParameter']['count'] ; $p ++){
192 $tmp = split(":",$attrs['gosaApplicationParameter'][$p]);
193 $data['PARAMETER'][$tmp[0]] = $tmp[1];
194 }
195 }
196 }elseif(in_array("FAIbranch",$attrs['objectClass'])){
198 $type = "RELEASE";
199 if(isset($attrs['FAIstate'][0])){
200 $data['FAIstate'] = $attrs['FAIstate'][0];
201 }else{
202 $data['FAIstate'] = "";
203 }
204 }
206 $data['DN'] = $attrs['dn'];
207 $data['NAME'] = $name;
208 $data['TYPE'] = $type;
209 $data['PRIORITY'] = $priority;
210 $data['ENTRIES'] = array();
211 $data['UNIQID'] = uniqid();
212 $data['PARENT'] = $parent_id;
213 $data['STATUS'] = "LOADED";
214 $cur[$priority] = $data;
215 ksort($cur);
216 }
217 }
218 }
219 }
222 function execute()
223 {
224 /* Call parent execute */
225 plugin::execute();
227 if(isset($_GET['send'])){
228 $id = $_GET['send'];
229 $all = $this->_get_all_entries();
230 if(isset($all[$id])){
231 send_binary_content($all[$id]['ICON'],$id.".jpg","image/jpeg");
232 exit;
233 }
234 }
236 if(isset($_GET['r']))
237 $this->__construct($this->config,$this->dn);
239 if(count($this->edit_entry)){
240 if($this->edit_entry['TYPE'] == "ENTRY"){
241 $smarty = get_smarty();
242 $smarty->assign("type", "ENTRY");
243 $smarty->assign("entry",$this->edit_entry);
244 $smarty->assign("paras",$this->app_parameter);
245 $display= $smarty->fetch (get_template_path('edit_entry.tpl', TRUE, dirname(__FILE__)));
246 return($display);
247 }
248 if($this->edit_entry['TYPE'] == "FOLDER"){
249 $smarty = get_smarty();
251 session::set("binarytype" , "image/jpeg");
252 session::set("binary" , $this->edit_entry['ICON']);
254 $smarty->assign("rand", microtime(TRUE));
255 $smarty->assign("image_set" , strlen($this->edit_entry['ICON']) > 0);
256 $smarty->assign("type", "FOLDER");
257 $smarty->assign("entry",$this->edit_entry);
258 $display= $smarty->fetch (get_template_path('edit_entry.tpl', TRUE, dirname(__FILE__)));
259 return($display);
260 }
261 }
263 $smarty = get_smarty();
264 $smarty->assign("plug_id" , $_GET['plug']);
266 /* Create application list */
267 $div = new divSelectBox("appgroup");
268 $div->SetHeight(300);
269 $departments = array();
270 $res = get_list("(objectClass=gosaDepartment)", "application", $this->curbase,array("description","cn","ou"),GL_SIZELIMIT);
271 foreach($res as $value){
272 $fdn = $value['dn'];
273 $fdn = preg_replace("/".normalizePreg($this->curbase)."/","",$fdn);
274 $fdn= @LDAP::fix($fdn);
275 if($value["description"][0]!=".."){
276 $departments[$value['dn']]= convert_department_dn($fdn)." - [".$value["description"][0]."]";
277 }else{
278 $departments[$value['dn']]=convert_department_dn($fdn)." ["._("Back")."]";
279 }
280 }
282 $linkopen = "<a href='?plug=".$_GET['plug']."&act=depopen&depid=%s'>%s</a>";
284 /* Create base back entry */
285 $base_back = preg_replace("/^[^,]+,/","",$this->curbase);
286 if((strlen($base_back)>= strlen($this->config->current['BASE']))&&($this->curbase!=$this->config->current['BASE'])){
287 $div->AddEntry(array(
288 array("string"=>sprintf($linkopen,base64_encode($base_back),".. ["._("back")."]"),
289 "attach"=>"style='border:0px;'")
290 ));
291 }
293 /* Append departments for current base */
294 foreach($departments as $key => $app){
295 $div->AddEntry(array(
296 array("string"=>"<img class='center' src='images/folder.png' alt='"._("department")."'> ".sprintf($linkopen,
297 base64_encode($key),$app),
298 "attach"=>"style='border:0px;'")
299 ));
300 }
303 /* Add applications found on this base */
304 $used_apps = $this->_get_used_entry_name();
305 foreach($this->apps as $key => $app){
306 if(in_array($app['cn'][0],$used_apps)){
307 continue;
308 }
309 if(!preg_match("/".get_ou('applicationou').normalizePreg($this->curbase)."$/",$app['dn'])){
310 continue;
311 }
313 $name = $app['cn'][0];
314 if(isset($app['description'])){
315 $name .= " [".$app['description'][0]."]";
316 }
317 $div->AddEntry(array(
318 array("string"=>sprintf("<input class='center' type='checkbox' value='1' name='AddApp_%s'>",$key).
319 "<img class='center' src='images/select_application.png' alt='"._("application")."'> ".$name,
320 "attach"=>"style='border:0px;'")
321 ));
322 }
325 $smarty->assign("enableReleaseManagement",$this->enableReleaseManagement);
326 $smarty->assign("FAIrelease",$this->FAIrelease);
327 $smarty->assign("app_list",$div->DrawList());
328 $smarty->assign("releases",$this->Releases);
329 $smarty->assign("folders" , $this->_get_folder_names());
330 $entries = $this->_get_entries_for_release($this->FAIrelease);
331 $smarty->assign("entries",$entries);
332 $display= $smarty->fetch (get_template_path('app_list.tpl', TRUE, dirname(__FILE__)));
333 return($display);
334 }
337 /*! \brief Returns all used folder names
338 @return Array All used folder names.
339 */
340 function _get_folder_names()
341 {
342 $data = $this->_get_entries_for_release($this->FAIrelease);
343 $ret = array("BASE" => ".");
344 foreach($data as $entry){
345 if($entry['TYPE'] == "FOLDER"){
346 $ret[$entry['UNIQID']] = $entry['NAME'];
347 }
348 }
349 return($ret);
350 }
353 /*! \brief return all used applications
354 @return Array All used applications.
355 */
356 function _get_used_entry_name()
357 {
358 $data = $this->_get_entries_for_release($this->FAIrelease);
359 $ret = array();
360 foreach($data as $entry){
361 if($entry['TYPE'] == "ENTRY"){
362 $ret[] = $entry['NAME'];
363 }
364 }
365 return($ret);
366 }
369 /*! \brief Returns all folder an entries for the selected release
370 @return Array Returns the complete menu structure for the given array.
371 */
372 function _get_entries_for_release($release,$cur = NULL)
373 {
374 $all = $this->_get_all_entries();
375 $key = $this->_get_release_key($release);
376 if(isset($all[$key]) && count($all[$key]['ENTRIES'])){
377 $res = $this->_get_all_entries(TRUE,TRUE,&$all[$key]['ENTRIES']);
378 return($res);
379 }
380 return(array());
381 }
384 /*! \brief Save the currently edited entry */
385 function _save_entry_edit()
386 {
387 $all = $this->_get_all_entries();
388 $entry = $this->edit_entry;
389 $r_entry= &$all[$entry['UNIQID']];
391 if($entry['TYPE'] == "ENTRY"){
392 $r_entry['PARAMETER'] = $this->app_parameter;
393 $r_entry['STATUS'] = "EDITED";
394 }
395 if($entry['TYPE'] == "FOLDER"){
396 $r_entry['ICON'] = $this->edit_entry['ICON'];
397 $r_entry['STATUS'] = "EDITED";
398 }
399 $this->dialog = FALSE;
400 $this->edit_entry = array();
401 }
404 /*! \brief prepare the entry with the given ID, to be edited.
405 */
406 function _edit_entry_edit($id)
407 {
408 $all = $this->_get_all_entries();
409 $entry = $all[$id];
411 $this->app_parameter = array();
412 if($entry['TYPE'] == "ENTRY"){
413 $found = FALSE;
414 foreach($this->apps as $id => $app){
416 if($app['cn'][0] == $entry['NAME']){
417 $found = TRUE;
418 break;
419 }
420 }
421 if($found){
423 /* Create a list of editable parameter */
424 if(isset($app['gosaApplicationParameter'])){
425 for($i = 0 ; $i < $app['gosaApplicationParameter']['count'] ; $i++) {
426 $para = $app['gosaApplicationParameter'][$i];
427 $tmp = split(":",$para);
428 $this->app_parameter[$tmp[0]] = $tmp[1];
429 }
430 }
432 /* Overwrite parameters with entry parameters */
433 foreach($entry['PARAMETER'] as $name => $value){
434 $this->app_parameter[$name] = $value;
435 }
437 $this->dialog = TRUE;
438 $this->edit_entry = $entry;
439 }
440 }
442 if($entry['TYPE'] == "FOLDER"){
443 $this->dialog = TRUE;
444 $this->edit_entry = $entry;
445 }
446 }
449 function remove_from_parent()
450 {
451 }
455 function check()
456 {
457 }
460 /*! \brief Create missing releases, if there is a release selected \
461 that is currently not part of the menu structure \
462 then create this entry
463 */
464 function _check_missing_release($release)
465 {
466 $release_info = $this->Releases[$release];
468 $parent_id = $this->a_Structure[0]['UNIQID'];
469 $cur = &$this->a_Structure[0]['ENTRIES'];
470 for($i = 0 ; $i < count($release_info['parts']) ; $i ++){
471 $part = $release_info['parts'][$i];
472 $found = FALSE;
473 foreach($cur as $key => $name){
474 if($name['NAME'] == $part){
475 $parent_id = $cur[$key]['UNIQID'];
476 $cur = &$cur[$key]['ENTRIES'];
478 $found =TRUE;
479 break;
480 }
481 }
482 if(!$found){
483 $release = array();
484 $release['UNIQID'] = uniqid();
485 $release['PARENT'] = $parent_id;
486 $release['NAME'] = $part;
487 $release['TYPE'] = "RELEASE";
488 $release['ENTRIES']= array();
489 $release['STATUS'] = "ADDED";
490 $release['FAIstate'] = $release_info['FAIstate'];
491 $cur[] = $release;
492 $i --;
493 }
494 }
495 }
498 /* !\brief Handle ui POSTS, like sort up/down/delete
499 */
500 function save_object()
501 {
502 foreach($_POST as $name => $value){
503 if(preg_match("/del_/",$name)){
504 $id = preg_replace("/^del_/","",$name);
505 $id = preg_replace("/_(x|y)$/","",$id);
506 $this->_remove_entry_id($id);
507 break;
508 }
509 if(preg_match("/app_entry_edit/",$name)){
510 $id = preg_replace("/^app_entry_edit/","",$name);
511 $id = preg_replace("/_(x|y)$/","",$id);
512 $this->_edit_entry_edit($id);
513 break;
514 }
515 if(preg_match("/up_/",$name)){
516 $id = preg_replace("/^up_/","",$name);
517 $id = preg_replace("/_(x|y)$/","",$id);
518 $this->_move_entry_up($id);
519 break;
520 }
521 if(preg_match("/down_/",$name)){
522 $id = preg_replace("/^down_/","",$name);
523 $id = preg_replace("/_(x|y)$/","",$id);
524 $this->_move_entry_down($id);
525 break;
526 }
527 if(preg_match("/^parameter_/",$name) &&
528 count($this->edit_entry) && $this->edit_entry['TYPE'] == "ENTRY"){
529 $name = preg_replace("/^parameter_/","",$name);
530 $this->app_parameter[$name] = $value;
531 }
532 }
533 if(isset($_POST['FAIrelease'])){
534 $this->FAIrelease = $_POST['FAIrelease'];
535 $this->_check_missing_release($this->FAIrelease);
536 }
537 if(isset($_GET['act']) && $_GET['act'] == 'depopen'){
538 $this->curbase = base64_decode($_GET['depid']);
539 }
540 if(isset($_POST['add_to_folder']) && isset($_POST['folder'])){
541 $folder = $_POST['folder'];
542 foreach($_POST as $name => $value){
543 if(preg_match("/^AddApp_[0-9]*$/",$name)){
544 $this->_add_app_id($folder,preg_replace("/^AddApp_/","",$name));
545 }
546 }
547 }
548 if(isset($_POST['add_menu_to_folder']) && isset($_POST['menu_folder'])){
549 $folder = $_POST['menu_folder'];
550 $name = $_POST['menu_folder_name'];
551 if(strlen($name) > 0 && preg_match("/[a-z ]/i",$name)){
552 $this->_add_sub_folder($folder,$name);
553 }
554 }
555 if(isset($_POST['app_entry_save'])){
556 $this->_save_entry_edit();
557 }
559 if(isset($_FILES['folder_image']) && isset($_POST['folder_image_upload'])){
560 if($_FILES['folder_image']['error'] == 0 && $_FILES['folder_image']['size'] > 0){
561 $this->edit_entry['ICON'] = file_get_contents($_FILES['folder_image']['tmp_name']);
562 }
563 }
565 if(isset($_POST['edit_reset_image'])){
566 $this->edit_entry['ICON'] = "";
567 }
569 if(isset($_POST['app_entry_cancel'])){
570 $this->edit_entry = array();
571 $this->dialog = FALSE;
572 }
573 $this->reload();
574 }
577 /*! \brief Returns the UNIQID of the currently selected release
578 */
579 function _get_release_key($release,$add_if_missing = FALSE)
580 {
581 $release_info = $this->Releases[$release];
583 if($release_info['name'] == "/"){
584 return($this->a_Structure['0']['UNIQID']);
585 }
587 $cur = &$this->a_Structure[0]['ENTRIES'];
588 $s_key = "";
589 $found = FALSE;
590 foreach($release_info['parts'] as $name){
591 foreach($cur as $key => $obj){
592 if($obj['TYPE'] == "RELEASE" && $obj['NAME'] == $name){
593 $s_key = $cur[$key]['UNIQID'];
594 $cur = &$cur[$key]['ENTRIES'];
595 $found = TRUE;
596 break;
597 }
598 $found = FALSE;
599 }
600 }
601 if($found){
602 return($s_key);
603 }
604 return(FALSE);
605 }
608 /*! \brief Add a new folder folder to the specified folder id
609 @param String $folder The folder id in where we want to add the new folder.
610 @param String $name The name of the new folder.
611 */
612 function _add_sub_folder($folder,$name)
613 {
614 $all = $this->_get_all_entries();
615 if($folder == "BASE"){
616 $folder = $this->_get_release_key($this->FAIrelease,TRUE);
617 }
619 if(isset($all[$folder])){
620 $a_folder = array();
621 $a_folder['STATUS'] = "ADDED";
622 $a_folder['NAME'] = $name;
623 $a_folder['UNIQID'] = uniqid();
624 $a_folder['PARENT'] = $folder;
625 $a_folder['TYPE'] = "FOLDER";
626 $a_folder['ICON'] = "";
627 $all[$folder]['ENTRIES'][] = $a_folder;
628 }
629 }
632 /* !\brief Remove the given id from the menu structure.
633 @param String ID to of the entry we want to remove.
634 @return Boolean TRUE on success
635 */
636 function _remove_entry_id($id)
637 {
638 $all = $this->_get_all_entries();
639 if(isset($all[$id])){
640 $all[$id]['STATUS'] = "REMOVED";
641 return(TRUE);
642 }
643 return(FALSE);
644 }
647 /* !\brief Remove the given id from the menu structure.
648 @param String ID to of the entry we want to remove.
649 @return Boolean TRUE on success
650 */
651 function _add_entry($folder_id,$entry,$pos = 0)
652 {
653 $all = $this->_get_all_entries();
655 if(isset($all[$folder_id])){
657 $folder = &$all[$folder_id];
658 $entries = $entry['ENTRIES'];
660 $entry['UNIQID'] = uniqid();
661 $entry['PARENT'] = $folder_id;
662 $entry['ENTRIES']= array();
663 $entry['STATUS'] = "ADDED";
665 $cnt = 0;
666 $new = array();
667 $added =FALSE;
668 foreach($folder['ENTRIES'] as $key => $obj){
669 if($pos == $cnt){
670 $new[] = $entry;
671 $added = TRUE;
672 $cnt ++;
673 }
674 $new[] = $obj;
675 }
676 if(!$added){
677 $new[] = $entry;
678 }
679 $all[$folder_id]['ENTRIES'] = $new;
680 foreach($entries as $sub){
681 $this->_add_entry($entry['UNIQID'],$sub);
682 }
683 return(TRUE);
684 }
685 return(FALSE);
686 }
689 /*! \brief Add the application identified by $app_id to folder $folder_id
690 @param String folder_id The UNIQID of the folder where we want to add the new folder.
691 @param Integer app_id The ID of the application which should be added.
692 */
693 function _add_app_id($folder_id,$app_id)
694 {
695 $all = $this->_get_all_entries();
696 if($folder_id == "BASE"){
697 $folder_id = $this->_get_release_key($this->FAIrelease);
698 }
699 if(isset($all[$folder_id]) && isset($this->apps[$app_id])){
701 $new = array();
702 $new['TYPE'] = "ENTRY";
703 $new['NAME'] = $this->apps[$app_id]['cn'][0];
704 $new['UNIQID']= uniqid();
705 $new['PARENT']= $folder_id;
706 $new['STATUS']= "ADDED";
707 $all[$folder_id]['ENTRIES'][] = $new;
708 }
709 }
712 /*! \brief move the object identified by the given ID one position up.
713 @param String The ID of the entry to be moved.
714 @return Boolean TRUE on success, else FALSE;
715 */
716 function _move_entry_up($id)
717 {
718 $all = $this->_get_all_entries(TRUE);
719 $parent = FALSE;
720 foreach($all as $entry){
721 if(isset($entry['UNIQID']) && $entry['UNIQID'] == $id){
722 if($parent != FALSE){
723 return($this->__switch_entries($id,"up",$parent));
724 }
725 }else{
726 if(in_array($entry['TYPE'],array("CLOSE","OPEN"))){
727 $parent = $entry['PARENT'];
728 }else{
729 $parent = $entry['UNIQID'];
730 }
731 }
732 }
733 return(FALSE);
734 }
737 /*! \brief move the object identified by the given ID one position down.
738 @param String The ID of the entry to be moved.
739 @return Boolean TRUE on success, else FALSE;
740 */
741 function _move_entry_down($id)
742 {
743 $all = $this->_get_all_entries(TRUE);
744 $found = FALSE;
745 foreach($all as $entry){
746 if(isset($entry['UNIQID']) && $entry['UNIQID'] == $id){
747 $found = TRUE;
748 continue;
749 }else{
750 if(in_array($entry['TYPE'],array("CLOSE","OPEN"))){
751 $parent = $entry['PARENT'];
752 }else{
753 $parent = $entry['UNIQID'];
754 }
755 if($found){
756 return($this->__switch_entries($id,"down",$parent));
757 }
758 }
759 }
760 return(FALSE);
761 }
764 /*! \brief Return all entries linear.
765 @param Boolean $add_tags If TRUE, OPEN/CLOSE Tags will be appended.
766 @param &Array Start here, Pointer to an array.
767 */
768 function _get_all_entries($add_tags = FALSE, $skip_release = FALSE, $cur = NULL)
769 {
770 $ret = array();
771 if($cur == NULL){
772 $cur = &$this->a_Structure;
773 }
774 foreach($cur as $key => $entry){
776 if($skip_release && $entry['TYPE'] == "RELEASE"){
777 continue;
778 }
779 if($entry['TYPE'] == "ENTRY"){
780 $found = FALSE;
781 foreach($this->apps as $app){
782 if($app['cn'][0] == $entry['NAME']){
783 $found = TRUE;
784 if(isset($app['description'][0])){
785 $entry['INFO'] = "[".$app['description'][0]."]";
786 }
787 break;
788 }
789 }
790 if(!$found){
791 $entry['INFO'] = "<font color='red'>"._("Not available in release.")."</font>";
792 }
793 }
796 $tmp = $entry;
797 if(!$add_tags){
798 $ret[$tmp['UNIQID']] = &$cur[$key];
799 if(isset($entry['ENTRIES']) && count($entry['ENTRIES'])){
800 $ret = array_merge($ret,$this->_get_all_entries($add_tags,$skip_release,&$cur[$key]['ENTRIES']));
801 }
802 }else{
804 if(isset($tmp['ENTRIES'])){
805 unset($tmp['ENTRIES']);
806 }
807 if($tmp['STATUS'] != "REMOVED"){
808 $ret[] = $tmp;
809 if(isset($entry['ENTRIES']) && count($entry['ENTRIES'])){
810 $add = false;
811 foreach($entry['ENTRIES'] as $entry){
812 if($entry['STATUS'] != "REMOVED"){
813 $add = TRUE;
814 break;
815 }
816 }
818 if($add){
819 $ret[] = array("TYPE" => "OPEN", "PARENT" => $entry['UNIQID']);
820 $ret = array_merge($ret,$this->_get_all_entries($add_tags,$skip_release,&$cur[$key]['ENTRIES']));
821 $ret[] = array("TYPE" => "CLOSE" , "PARENT" => $entry['UNIQID']);
822 }
823 }
824 }
825 }
826 }
827 return($ret);
828 }
831 /* !\brief Switch one entry with another
832 @param String from The source ID.
833 @param String type "up"/"down" type switched.
834 @param String to The destination ID.
835 return Boolean TRUE on success
836 */
837 function __switch_entries($from,$type,$to)
838 {
839 $all = $this->_get_all_entries();
841 $o_to = &$all[$to];
842 $o_from = &$all[$from];
844 print_a($o_to,$o_from);
846 /***********************
847 * Source == Destination
848 * Move into next parent.
849 ************************/
850 if($to == $from){
851 $to = $o_to['PARENT'];
852 $o_to = &$all[$to];
853 }
855 /***********************
856 * Target is container
857 ************************/
858 if(in_array($o_to['TYPE'],array("FOLDER","RELEASE"))){
860 /***********************
861 * Move into parent folder
862 * + Target
863 * |-> Source
864 ************************/
865 if($to == $o_from['PARENT']){
868 /* Check if source is a folder object
869 */
870 $o_to_sub = &$all[$o_to['PARENT']];
871 if(in_array($o_to_sub['TYPE'],array("FOLDER","RELEASE"))){
873 $o_from['STATUS'] = "ADDED";
875 /* Adding new */
876 $tmp2 = array();
877 $cnt = 0;
878 foreach($o_to_sub['ENTRIES'] as $key => $entry){
879 $cnt ++;
880 if($entry['UNIQID'] == $to){
881 break;
882 }
883 }
884 if($type == "up"){
885 $cnt --;
887 }
888 $this->_add_entry($o_to_sub['UNIQID'],$o_from,$cnt);
890 /* Removing old */
891 $tmp = array();
892 if(!$this->_remove_entry_id($from)){
893 return(FALSE);
894 }
895 }
896 }else{
898 /***********************
899 * Target is NOT parent container
900 * + Parent Folder
901 * |-> Source
902 * + Destination
903 ************************/
905 /* Removing old */
906 $o_to = $all[$to];
907 $o_from = $all[$from];
908 $this->_add_entry($to,$o_from);
909 $this->_remove_entry_id($from);
910 }
911 }else{
913 /***********************
914 * Source and Destination in some Folder.
915 * + Parent folder
916 * |-> Source
917 * |-> Destination
918 ************************/
919 $o_to = &$all[$to];
920 $o_from = &$all[$from];
921 $parent = &$all[$o_to['PARENT']];
923 if($o_to['PARENT'] == $o_from['PARENT']){
924 $tmp = $all[$to];
925 $all[$to] = $o_from;
926 $all[$from] = $tmp;
928 /* Ensure that the app priority is updated */
929 foreach($parent['ENTRIES'] as $key => $entry){
930 $parent['ENTRIES'][$key]['STATUS'] = "EDITED";
931 }
932 }
933 }
934 }
937 function save()
938 {
939 $ldap = $this->config->get_ldap_link();
940 $all = $this->_get_all_entries();
941 $prio = 0;
942 $Actions = array("Remove" => array(),"Edit" => array() , "Add" => array());
944 foreach($all as $entry){
945 $prio ++;
946 $cur = $entry;
947 $dn = "";
949 do{
950 if($cur['TYPE'] == "ENTRY"){
951 $dn.= "cn=".$cur['NAME'].",";
952 }elseif($cur['TYPE'] == "FOLDER"){
953 $dn.= "cn=".$cur['NAME'].",";
954 }elseif($cur['TYPE'] == "RELEASE"){
955 $dn.= "ou=".$cur['NAME'].",";
956 }elseif($cur['TYPE'] == "BASE"){
957 }
958 if(!isset($all[$cur['PARENT']])){
959 $cur = NULL;
960 }else{
961 $cur = $all[$cur['PARENT']];
962 }
963 }while(is_array($cur));
965 $cur_dn = $dn.$this->dn;
967 $attrs = array();
968 switch($entry['TYPE']){
969 case "ENTRY" :
970 {
971 $attrs['objectClass'] = "gotoMenuEntry";
972 $attrs['cn'] = $entry['NAME'];
973 $attrs['gosaApplicationPriority'] = $prio;
974 $attrs['gosaApplicationParameter'] = array();
976 foreach($entry['PARAMETER'] as $name => $value){
977 $attrs['gosaApplicationParameter'][] = $name.":".$value;
978 }
979 }
980 break;
981 case "FOLDER" :
982 {
983 $attrs['objectClass'] = "gotoSubmenuEntry";
984 $attrs['cn'] = $entry['NAME'];
985 $attrs['gosaApplicationPriority'] = $prio;
986 if($entry['STATUS'] != "ADDED"){
987 $attrs['gosaApplicationIcon'] = array();
988 }
990 if(!empty($entry['ICON'])){
991 $attrs['gosaApplicationIcon'] = $entry['ICON'];
992 }
993 }
994 break;
995 case "RELEASE" :
996 {
997 $attrs['ou'] = $entry['NAME'];
998 $attrs['objectClass'] = array();
999 $attrs['objectClass'][] = "top";
1000 $attrs['objectClass'][] = "organizationalUnit";
1001 $attrs['objectClass'][] = "FAIbranch";
1002 if(!empty($entry['FAIstate'])){
1003 $attrs['FAIstate'] = $entry['FAIstate'];
1004 }
1005 }
1006 break;
1007 }
1009 if($entry['STATUS'] == "LOADED"){
1010 continue;
1011 }
1012 if($entry['STATUS'] == "REMOVED"){
1013 $Actions['Remove'][$cur_dn] = $cur_dn;
1014 }
1015 if($entry['STATUS'] == "EDITED"){
1016 $Actions['Edit'][$cur_dn] = $attrs;
1017 }
1018 if($entry['STATUS'] == "ADDED"){
1019 $Actions['Add'][$cur_dn] = $attrs;
1020 }
1021 }
1023 $ldap = $this->config->get_ldap_link();
1024 $ldap->cd($this->config->current['BASE']);
1025 foreach($Actions['Remove'] as $dn){
1026 $ldap->cd($dn);
1027 $ldap->cat($dn);
1028 if($ldap->count()){
1029 $ldap->rmdir_recursive($dn);
1030 show_ldap_error($ldap->get_error(), _("Could not save group application settings."));
1031 }
1032 }
1033 foreach($Actions['Add'] as $dn => $data){
1034 $ldap->cd($dn);
1035 $ldap->cat($dn);
1036 if(!$ldap->count()){
1037 $ldap->add($data);
1038 show_ldap_error($ldap->get_error(), _("Could not save group application settings."));
1039 }
1040 }
1041 foreach($Actions['Edit'] as $dn => $data){
1042 $ldap->cd($dn);
1043 $ldap->cat($dn);
1044 if($ldap->count()){
1045 $ldap->modify($data);
1046 show_ldap_error($ldap->get_error(), _("Could not save group application settings."));
1047 }
1048 }
1049 $this->_load_menu_structure();
1050 }
1053 /* Return plugin informations for acl handling */
1054 static function plInfo()
1055 {
1056 return (array(
1057 "plShortName" => _("Applications"),
1058 "plDescription" => _("Group applications"),
1059 "plSelfModify" => FALSE,
1060 "plDepends" => array(),
1061 "plPriority" => 0,
1062 "plSection" => array("admin"),
1063 "plCategory" => array("groups"),
1064 "plProvidedAcls"=> array(
1065 "gosaMemberApplication" => _("Application"),
1066 "FAIrelease" => _("Release"),
1067 "gosaApplicationParameter" => _("Application parameter"))
1068 ));
1069 }
1072 function PrepareForCopyPaste($source)
1073 {
1074 }
1077 function multiple_save_object()
1078 {
1079 if(isset($_POST['group_apps_multi'])){
1080 $this->save_object();
1081 plugin::multiple_save_object();
1083 /* Get posts */
1084 foreach(array("apps") as $attr){
1085 if(isset($_POST['use_'.$attr])) {
1086 $this->multi_boxes[] = $attr;
1087 }
1088 }
1089 }
1090 }
1093 function get_multi_edit_values()
1094 {
1095 $ret = plugin::get_multi_edit_values();
1097 if(in_array("apps",$this->multi_boxes)){
1098 $ret['gosaApplicationParameter'] = $this->gosaApplicationParameter;
1099 $ret['Categories'] = $this->Categories;
1100 $ret['gosaMemberApplication'] = $this->gosaMemberApplication;
1101 $ret['FAIrelease'] = $this->FAIrelease;
1102 $ret['appoption'] = $this->appoption;
1103 }
1104 return($ret);
1105 }
1106 }
1107 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1108 ?>