a4396270b35a5e43fbbc1196271d1a8ec661e938
1 <?php
2 class appgroup extends plugin
3 {
4 var $config;
5 var $curbase;
7 /* Contains the menu structure in an array.
8 */
9 var $a_Structure= array();
10 var $a_Structure_on_load = array();
11 var $Releases;
12 var $FAIrelease = 0;
13 var $apps = array();
14 var $_cache = array();
16 var $app_parameter = array();
17 var $edit_entry = array();
18 var $enableReleaseManagement = FALSE;
21 public function __construct(&$config, $dn= NULL, $parent= NULL)
22 {
23 plugin::plugin($config,$dn,$parent);
24 $this->dn = $dn;
25 $this->_load_menu_structure();
26 $this->a_Structure_on_load = $this->a_Structure;
28 /* Check if we have relase mangement enabled and prepare group application for release management */
29 $tmp = $config->search("faiManagement", "CLASS",array('menu','tabs'));
30 if(!empty($tmp)){
31 $this->enableReleaseManagement = true;
32 }
34 $this->Releases = $this->getReleases();
35 $this->FAIrelease = "/";
36 $this->curbase = $this->config->current['BASE'];
37 $this->reload();
39 $this->is_account = FALSE;
40 if(count($this->_get_all_entries()) > 1){
41 $this->is_account= TRUE;
42 }
43 $this->initially_was_account = $this->is_account;
44 }
47 /*! \brief Reload the list of applications for the currently selected release
48 */
49 function reload()
50 {
51 $ret = array();
52 $release_info = $this->Releases[$this->FAIrelease];
54 if(!isset($this->_cache['ReleaseApps'][$release_info['suffix']])){
56 $ldap = $this->config->get_ldap_link();
57 $ldap->cd($this->config->current['BASE']);
58 $ldap->search("ou=apps",array("dn"));
59 $app_deps = array();
60 while($attrs = $ldap->fetch()){
61 $app_deps[] = $attrs['dn'];
62 }
64 foreach($app_deps as $dep){
65 $ldap->cd($dep);
66 $ldap->search("objectClass=FAIbranch",array("dn"));
67 while($attrs = $ldap->fetch()){
68 $app_deps[] = $attrs['dn'];
69 }
70 }
72 foreach($app_deps as $dep){
73 if(preg_match("/^".normalizePreg($release_info['suffix'])."/",$dep)){
74 $ret = array_merge($ret,get_list("(objectClass=gosaApplication)","application",$dep,array("*"),GL_NONE));
75 }
76 }
78 $tmp = array();
79 foreach($ret as $key => $app){
80 $tmp[$key] = $app['cn'][0];
81 }
82 natcasesort($tmp);
83 $res = array();
84 foreach($tmp as $key => $app){
85 $res[] = $ret[$key];
86 }
88 $this->_cache['ReleaseApps'][$release_info['suffix']] = $res;
89 }
90 $this->apps = $this->_cache['ReleaseApps'][$release_info['suffix']];
91 }
96 /*! \brief generate a list of available releases
97 @return return an array with all available releases.
98 */
99 function getReleases()
100 {
101 $ret =array("/" => array("name" => "/", "found" => TRUE , "parts" => array(),"suffix" => get_ou('applicationou')));
102 if($this->enableReleaseManagement){
104 /* Only display those releases that we are able to read */
105 $dn = $this->config->current['BASE'];
106 $filter = "(&(objectClass=organizationalUnit)(objectClass=FAIbranch))";
107 $res = get_sub_list($filter,array("application","fai"), array(get_ou("applicationou"),get_ou("faiou")),$dn, array("ou","FAIstate"), GL_SUBSEARCH);
110 foreach($res as $attrs){
111 if(preg_match("/".get_ou('applicationou')."/",$attrs['dn'])){
112 $bb = preg_replace("/".get_ou('applicationou').".*/","",$attrs['dn']);
113 $parts = array_reverse(split("ou=",$bb));
115 $str ="";
116 foreach($parts as $key => $part){
117 if(empty($part)) {
118 unset($parts[$key]);
119 continue;
120 }
121 $part = str_replace(",","",$part);
122 $str .= $part."/";
123 $parts[$key] = $part;
124 }
125 $name = preg_replace("/\/$/","",$str);
126 if(empty($name)) {
127 $name ="/";
128 }
129 $FAIstate = "";
130 if(isset($attrs['FAIstate'])){
131 $FAIstate = $attrs['FAIstate'][0];
132 }
134 $all = $this->_get_all_entries();
135 $found = FALSE;
136 foreach($all as $entry){
137 if(isset($entry['DN']) && preg_match("/^".normalizePreg($bb)."/",$entry['DN'])){
138 $found =TRUE;
139 break;
140 }
141 }
143 $cnt = 0;
144 $ret[$name] = array("name" => $name,
145 "found" => $found,
146 "FAIstate" => $FAIstate,
147 "dn" => $attrs['dn'],
148 "parts" => $parts,"suffix" => $bb.get_ou('applicationou'));
149 }
150 }
151 }
152 ksort($ret);
153 return($ret);
154 }
157 /*! \brief Load the menu structure from ldap and create a multi dimensional array
158 */
159 function _load_menu_structure()
160 {
161 $this->a_Structure = array();
162 $ldap = $this->config->get_ldap_link();
163 $ldap->cd($this->dn);
164 $ldap->search("(|(objectClass=gotoSubmenuEntry)(objectClass=FAIbranch)(objectClass=gotoMenuEntry))",array("*"));
166 $base = array();
167 $base['UNIQID'] = uniqid();
168 $base['PARENT'] = 0;
169 $base['NAME'] = "";
170 $base['TYPE'] = "BASE";
171 $base['ENTRIES']= array();
172 $base['STATUS'] = "LOADED";
174 $this->a_Structure[0] = $base;
176 while($attrs = $ldap->fetch()){
177 $cur = &$this->a_Structure[0]['ENTRIES'];
178 $parent_id = $base['UNIQID'];
179 $sub_dn = preg_replace("/,".normalizePreg($this->dn)."$/","",$attrs['dn']);
180 $sub_dn_array = split("\,",$sub_dn);
182 $found = true;
183 for($i = (count($sub_dn_array)-1) ; $i >= 0 ; $i--){
184 $name = preg_replace("/^[^=]*+=/","",$sub_dn_array[$i]);
186 if($i > 0){
187 $found =FALSE;
188 foreach($cur as $key => $entry){
189 if($entry['NAME'] == $name){
190 $cur = &$cur[$key]['ENTRIES'];
191 $parent_id = $entry['UNIQID'];
192 $found =true;
193 break;
194 }
195 }
196 }else{
198 if(!$found){
199 break;
200 }
201 $priority = 1;
202 if(isset($attrs['gosaApplicationPriority'])){
203 $priority= $attrs['gosaApplicationPriority'][0];
204 }
205 while(isset($cur[$priority])){
206 $priority ++;
207 }
209 $data = array();
210 if(in_array("gotoSubmenuEntry",$attrs['objectClass'])){
211 $type = "FOLDER";
213 $data['ICON'] = "";
214 if(isset($attrs['gosaApplicationIcon'])){
215 $data['ICON'] = $ldap->get_attribute($attrs['dn'],"gosaApplicationIcon");
216 }
218 }elseif(in_array("gotoMenuEntry",$attrs['objectClass'])){
219 $type = "ENTRY";
220 $data['INFO'] = "";
221 $data['PARAMETER'] = array();
222 if(isset($attrs['gosaApplicationParameter'])){
223 for($p = 0 ; $p < $attrs['gosaApplicationParameter']['count'] ; $p ++){
224 $tmp = split(":",$attrs['gosaApplicationParameter'][$p]);
225 $data['PARAMETER'][$tmp[0]] = $tmp[1];
226 }
227 }
228 }elseif(in_array("FAIbranch",$attrs['objectClass'])){
230 $type = "RELEASE";
231 if(isset($attrs['FAIstate'][0])){
232 $data['FAIstate'] = $attrs['FAIstate'][0];
233 }else{
234 $data['FAIstate'] = "";
235 }
236 }
238 $data['DN'] = $attrs['dn'];
239 $data['NAME'] = $name;
240 $data['TYPE'] = $type;
241 $data['PRIORITY'] = $priority;
242 $data['ENTRIES'] = array();
243 $data['UNIQID'] = uniqid();
244 $data['PARENT'] = $parent_id;
245 $data['STATUS'] = "LOADED";
246 $cur[$priority] = $data;
247 ksort($cur);
248 }
249 }
250 }
251 }
254 function execute()
255 {
256 /* Call parent execute */
257 plugin::execute();
259 if (isset($_POST['modify_state'])){
260 $this->is_account = !$this->is_account;
261 }
263 /* Do we represent a valid account? */
264 if (!$this->is_account){
265 $display= $this->show_enable_header(_("Add application extension"),
266 msgPool::featuresDisabled(_("application")));
267 return ($display);
268 }
270 $display = $this->show_enable_header(_("Remove application extension"),
271 msgPool::featuresEnabled(_("application")));
273 if(isset($_GET['send'])){
274 $id = $_GET['send'];
275 $all = $this->_get_all_entries();
276 if(isset($all[$id])){
277 send_binary_content($all[$id]['ICON'],$id.".jpg","image/jpeg");
278 exit;
279 }
280 }
282 if(isset($_GET['r']))
283 $this->__construct($this->config,$this->dn);
285 if(count($this->edit_entry)){
286 if($this->edit_entry['TYPE'] == "ENTRY"){
287 $smarty = get_smarty();
288 $smarty->assign("type", "ENTRY");
289 $smarty->assign("entry",$this->edit_entry);
290 $smarty->assign("paras",$this->app_parameter);
291 $display= $smarty->fetch (get_template_path('edit_entry.tpl', TRUE, dirname(__FILE__)));
292 return($display);
293 }
294 if($this->edit_entry['TYPE'] == "FOLDER"){
295 $smarty = get_smarty();
297 session::set("binarytype" , "image/jpeg");
298 session::set("binary" , $this->edit_entry['ICON']);
300 $smarty->assign("rand", microtime(TRUE));
301 $smarty->assign("image_set" , strlen($this->edit_entry['ICON']) > 0);
302 $smarty->assign("type", "FOLDER");
303 $smarty->assign("entry",$this->edit_entry);
304 $display= $smarty->fetch (get_template_path('edit_entry.tpl', TRUE, dirname(__FILE__)));
305 return($display);
306 }
307 }
309 $smarty = get_smarty();
310 $smarty->assign("plug_id" , $_GET['plug']);
312 /* Create application list */
313 $div = new divSelectBox("appgroup");
314 $div->SetHeight(300);
315 $departments = array();
316 $res = get_list("(objectClass=gosaDepartment)", "application", $this->curbase,array("description","cn","ou"),GL_SIZELIMIT);
317 foreach($res as $value){
318 $fdn = $value['dn'];
319 $fdn = preg_replace("/".normalizePreg($this->curbase)."/","",$fdn);
320 $fdn= @LDAP::fix($fdn);
321 if($value["description"][0]!=".."){
322 $departments[$value['dn']]= convert_department_dn($fdn)." - [".$value["description"][0]."]";
323 }else{
324 $departments[$value['dn']]=convert_department_dn($fdn)." ["._("Back")."]";
325 }
326 }
328 $linkopen = "<a href='?plug=".$_GET['plug']."&act=depopen&depid=%s'>%s</a>";
330 /* Create base back entry */
331 $base_back = preg_replace("/^[^,]+,/","",$this->curbase);
332 if((strlen($base_back)>= strlen($this->config->current['BASE']))&&($this->curbase!=$this->config->current['BASE'])){
333 $div->AddEntry(array(
334 array("string"=>sprintf($linkopen,base64_encode($base_back),".. ["._("back")."]"),
335 "attach"=>"style='border:0px;'")
336 ));
337 }
339 /* Append departments for current base */
340 foreach($departments as $key => $app){
341 $div->AddEntry(array(
342 array("string"=>"<img class='center' src='images/folder.png' alt='"._("department")."'> ".sprintf($linkopen,
343 base64_encode($key),$app),
344 "attach"=>"style='border:0px;'")
345 ));
346 }
349 /* Add applications found on this base */
350 $used_apps = $this->_get_used_entry_name();
351 foreach($this->apps as $key => $app){
352 if(in_array($app['cn'][0],$used_apps)){
353 continue;
354 }
355 if(!preg_match("/".get_ou('applicationou').normalizePreg($this->curbase)."$/",$app['dn'])){
356 continue;
357 }
359 $name = $app['cn'][0];
360 if(isset($app['description'])){
361 $name .= " [".$app['description'][0]."]";
362 }
363 $div->AddEntry(array(
364 array("string"=>sprintf("<input class='center' type='checkbox' value='1' name='AddApp_%s'>",$key).
365 "<img class='center' src='images/select_application.png' alt='"._("application")."'> ".$name,
366 "attach"=>"style='border:0px;'")
367 ));
368 }
371 $smarty->assign("enableReleaseManagement",$this->enableReleaseManagement);
372 $smarty->assign("FAIrelease",$this->FAIrelease);
373 $smarty->assign("app_list",$div->DrawList());
374 $smarty->assign("i",0);
375 $smarty->assign("releases",$this->Releases);
376 $smarty->assign("folders" , $this->_get_folder_names());
377 $entries = $this->_get_entries_for_release($this->FAIrelease);
378 $smarty->assign("entries",$entries);
379 $display.= $smarty->fetch (get_template_path('app_list.tpl', TRUE, dirname(__FILE__)));
380 return($display);
381 }
384 /*! \brief Returns all used folder names
385 @return Array All used folder names.
386 */
387 function _get_folder_names()
388 {
389 $data = $this->_get_entries_for_release($this->FAIrelease);
390 $all = $this->_get_all_entries();
391 $ret = array("BASE" => ".");
392 foreach($data as $entry){
394 if($entry['TYPE'] == "FOLDER"){
395 $str = $entry['NAME'];
396 $parent = $entry['PARENT'];
397 $i = 10;
398 while(isset($all[$parent]) && $i){
399 $i --;
400 $parent_o = $all[$parent];
401 $str = $parent_o['NAME']."/".$str;
402 $parent = $all[$parent_o['UNIQID']]['PARENT'];
403 }
404 $ret[$entry['UNIQID']] = $str;
405 }
406 }
407 return($ret);
408 }
411 /*! \brief return all used applications
412 @return Array All used applications.
413 */
414 function _get_used_entry_name()
415 {
416 $data = $this->_get_entries_for_release($this->FAIrelease);
417 $ret = array();
418 foreach($data as $entry){
419 if($entry['TYPE'] == "ENTRY"){
420 $ret[] = $entry['NAME'];
421 }
422 }
423 return($ret);
424 }
427 /*! \brief Returns all folder an entries for the selected release
428 @return Array Returns the complete menu structure for the given array.
429 */
430 function _get_entries_for_release($release,$cur = NULL)
431 {
432 $all = $this->_get_all_entries();
433 $key = $this->_get_release_key($release);
434 if(isset($all[$key]) && count($all[$key]['ENTRIES'])){
435 $res = $this->_get_all_entries(TRUE,TRUE,$all[$key]['ENTRIES']);
436 return($res);
437 }
438 return(array());
439 }
442 /*! \brief Save the currently edited entry */
443 function _save_entry_edit()
444 {
445 $all = $this->_get_all_entries();
446 $entry = $this->edit_entry;
447 $r_entry= &$all[$entry['UNIQID']];
449 if($entry['TYPE'] == "ENTRY"){
450 $r_entry['PARAMETER'] = $this->app_parameter;
451 $r_entry['STATUS'] = "EDITED";
452 }
453 if($entry['TYPE'] == "FOLDER"){
454 $r_entry['ICON'] = $this->edit_entry['ICON'];
455 $r_entry['STATUS'] = "EDITED";
456 }
457 $this->dialog = FALSE;
458 $this->edit_entry = array();
459 }
462 /*! \brief prepare the entry with the given ID, to be edited.
463 */
464 function _edit_entry_edit($id)
465 {
466 $all = $this->_get_all_entries();
467 $entry = $all[$id];
469 $this->app_parameter = array();
470 if($entry['TYPE'] == "ENTRY"){
471 $found = FALSE;
472 foreach($this->apps as $id => $app){
474 if($app['cn'][0] == $entry['NAME']){
475 $found = TRUE;
476 break;
477 }
478 }
479 if($found){
481 /* Create a list of editable parameter */
482 if(isset($app['gosaApplicationParameter'])){
483 for($i = 0 ; $i < $app['gosaApplicationParameter']['count'] ; $i++) {
484 $para = $app['gosaApplicationParameter'][$i];
485 $tmp = split(":",$para);
486 $this->app_parameter[$tmp[0]] = $tmp[1];
487 }
488 }
490 /* Overwrite parameters with entry parameters */
491 foreach($entry['PARAMETER'] as $name => $value){
492 $this->app_parameter[$name] = $value;
493 }
495 $this->dialog = TRUE;
496 $this->edit_entry = $entry;
497 }
498 }
500 if($entry['TYPE'] == "FOLDER"){
501 $this->dialog = TRUE;
502 $this->edit_entry = $entry;
503 }
504 }
507 function remove_from_parent()
508 {
509 $ldap = $this->config->get_ldap_link();
510 $ldap->cd($this->dn);
511 $ldap->ls("(|(objectClass=gotoSubmenuEntry)(objectClass=FAIbranch)(objectClass=gotoMenuEntry))",$this->dn,array("*"));
512 $a_remove = array();
513 while($attrs = $ldap->fetch()){
514 $a_remove[] = $attrs['dn'];
515 }
516 foreach($a_remove as $remove){
517 $ldap->rmdir_recursive($remove);
518 if (!$ldap->success()){
519 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_DEL, get_class()));
520 }
521 }
522 $this->_load_menu_structure();
523 }
526 function check()
527 {
528 }
531 /*! \brief Create missing releases, if there is a release selected \
532 that is currently not part of the menu structure \
533 then create this entry
534 */
535 function _check_missing_release($release)
536 {
537 $release_info = $this->Releases[$release];
539 $parent_id = $this->a_Structure[0]['UNIQID'];
540 $cur = &$this->a_Structure[0]['ENTRIES'];
541 for($i = 0 ; $i < count($release_info['parts']) ; $i ++){
542 $part = $release_info['parts'][$i];
543 $found = FALSE;
544 foreach($cur as $key => $name){
545 if($name['NAME'] == $part){
546 $parent_id = $cur[$key]['UNIQID'];
547 $cur = &$cur[$key]['ENTRIES'];
549 $found =TRUE;
550 break;
551 }
552 }
553 if(!$found){
554 $release = array();
555 $release['UNIQID'] = uniqid();
556 $release['PARENT'] = $parent_id;
557 $release['NAME'] = $part;
558 $release['TYPE'] = "RELEASE";
559 $release['ENTRIES']= array();
560 $release['STATUS'] = "ADDED";
561 $release['FAIstate'] = $release_info['FAIstate'];
562 $cur[] = $release;
563 $i --;
564 }
565 }
566 }
570 function _move_entry($id,$dir)
571 {
572 $all = $this->_get_all_entries();
573 if($dir == "down"){
574 $to = $this->_get_next($id);
575 }
576 if($dir == "up"){
577 $to = $this->_get_last($id);
578 }
580 if(!$to){
581 return;
582 }
584 $o_to = $all[$to];
585 $o_from = $all[$id];
587 if($o_to['PARENT'] == $o_from['UNIQID'] && $dir == "down"){
588 $to = $this->_get_next($to,$o_from['PARENT']);
589 $o_to = $all[$to];
590 }
593 /* Target is ENTRY && same BASE, just switch */
594 if($o_to['PARENT'] == $o_from['PARENT'] ){
595 $parent = $all[$o_to['PARENT']];
596 $pos = 0;
597 foreach($parent['ENTRIES'] as $entry){
598 $pos ++;
599 if($entry['UNIQID'] == $to){
600 break;
601 }
602 }
603 if($dir == "up" && $pos > 0){
604 $pos --;
605 }
606 $this->_add_entry($parent['UNIQID'],$o_from,$pos);
607 $this->_remove_entry_id($id);
608 return(TRUE);
609 }
610 return(FALSE);
611 }
615 function _get_last($id)
616 {
617 $all_l = array_reverse($this->_get_entries_for_release($this->FAIrelease));
618 for($i = 0 ; $i < count($all_l) ; $i ++){
619 if(isset($all_l[$i]['UNIQID']) && $all_l[$i]['UNIQID'] == $id){
620 $i++;
621 break;
622 }
623 }
624 while(isset($all_l[$i]) && !in_array($all_l[$i]['TYPE'],array("ENTRY","FOLDER","CLOSE","OPEN")) && $i < count($all_l)){
625 $i++;
626 }
628 if(!isset($all_l[$i])){
629 return(FALSE);
630 }
632 if(in_array($all_l[$i]['TYPE'],array("CLOSE","OPEN"))){
633 return($all_l[$i]['PARENT']);
634 }
636 return($all_l[$i]['UNIQID']);
637 }
640 function _get_next($id,$parent = 0)
641 {
642 $all_l = $this->_get_entries_for_release($this->FAIrelease);
643 for($i = 0 ; $i < count($all_l) ; $i ++){
644 if(isset($all_l[$i]['UNIQID']) && $all_l[$i]['UNIQID'] == $id){
645 $i++;
646 break;
647 }
648 }
649 if($parent != 0){
650 while(isset($all_l[$i]) && $all_l[$i]['PARENT'] != $parent){
651 $i++;
652 }
653 }else{
654 while(isset($all_l[$i]) && !in_array($all_l[$i]['TYPE'],array("ENTRY","FOLDER")) && $i < count($all_l)){
655 $i++;
656 }
657 }
658 if(!isset($all_l[$i])){
659 return(FALSE);
660 }
661 if(in_array($all_l[$i]['TYPE'],array("CLOSE","OPEN"))){
662 return($all_l[$i]['PARENT']);
663 }
664 return($all_l[$i]['UNIQID']);
665 }
670 /* !\brief Handle ui POSTS, like sort up/down/delete
671 */
672 function save_object()
673 {
674 foreach($_POST as $name => $value){
675 if(preg_match("/del_/",$name)){
676 $id = preg_replace("/^del_/","",$name);
677 $id = preg_replace("/_(x|y)$/","",$id);
678 $this->_remove_entry_id($id);
679 break;
680 }
681 if(preg_match("/app_entry_edit/",$name)){
682 $id = preg_replace("/^app_entry_edit/","",$name);
683 $id = preg_replace("/_(x|y)$/","",$id);
684 $this->_edit_entry_edit($id);
685 break;
686 }
687 if(preg_match("/up_/",$name)){
688 $id = preg_replace("/^up_/","",$name);
689 $id = preg_replace("/_(x|y)$/","",$id);
690 $this->_move_entry($id,"up");
691 break;
692 }
693 if(preg_match("/down_/",$name)){
694 $id = preg_replace("/^down_/","",$name);
695 $id = preg_replace("/_(x|y)$/","",$id);
696 $this->_move_entry($id,"down");
697 break;
698 }
699 if(preg_match("/^parameter_/",$name) &&
700 count($this->edit_entry) && $this->edit_entry['TYPE'] == "ENTRY"){
701 $name = preg_replace("/^parameter_/","",$name);
702 $this->app_parameter[$name] = $value;
703 }
704 }
705 if(isset($_POST['FAIrelease'])){
706 $this->FAIrelease = $_POST['FAIrelease'];
707 $this->_check_missing_release($this->FAIrelease);
708 }
709 if(isset($_GET['act']) && $_GET['act'] == 'depopen'){
710 $this->curbase = base64_decode($_GET['depid']);
711 }
712 if(isset($_POST['add_to_folder']) && isset($_POST['folder'])){
713 $folder = $_POST['folder'];
714 foreach($_POST as $name => $value){
715 if(preg_match("/^AddApp_[0-9]*$/",$name)){
716 $this->_add_app_id($folder,preg_replace("/^AddApp_/","",$name));
717 }
718 }
719 }
720 if(isset($_POST['add_menu_to_folder']) && isset($_POST['menu_folder'])){
721 $folder = $_POST['menu_folder'];
722 $name = $_POST['menu_folder_name'];
723 if(strlen($name) > 0 && preg_match("/[a-z ]/i",$name)){
724 $this->_add_sub_folder($folder,$name);
725 }
726 }
727 if(isset($_POST['app_entry_save'])){
728 $this->_save_entry_edit();
729 }
731 if(isset($_FILES['folder_image']) && isset($_POST['folder_image_upload'])){
732 if($_FILES['folder_image']['error'] == 0 && $_FILES['folder_image']['size'] > 0){
733 $this->edit_entry['ICON'] = file_get_contents($_FILES['folder_image']['tmp_name']);
734 }
735 }
737 if(isset($_POST['edit_reset_image'])){
738 $this->edit_entry['ICON'] = "";
739 }
741 if(isset($_POST['app_entry_cancel'])){
742 $this->edit_entry = array();
743 $this->dialog = FALSE;
744 }
745 $this->reload();
746 }
749 /*! \brief Returns the UNIQID of the currently selected release
750 */
751 function _get_release_key($release,$add_if_missing = FALSE)
752 {
753 $release_info = $this->Releases[$release];
755 if($release_info['name'] == "/"){
756 return($this->a_Structure['0']['UNIQID']);
757 }
759 $cur = &$this->a_Structure[0]['ENTRIES'];
760 $s_key = "";
761 $found = FALSE;
762 foreach($release_info['parts'] as $name){
763 foreach($cur as $key => $obj){
764 if($obj['TYPE'] == "RELEASE" && $obj['NAME'] == $name){
765 $s_key = $cur[$key]['UNIQID'];
766 $cur = &$cur[$key]['ENTRIES'];
767 $found = TRUE;
768 break;
769 }
770 $found = FALSE;
771 }
772 }
773 if($found){
774 return($s_key);
775 }
776 return(FALSE);
777 }
780 /*! \brief Add a new folder folder to the specified folder id
781 @param String $folder The folder id in where we want to add the new folder.
782 @param String $name The name of the new folder.
783 */
784 function _add_sub_folder($folder,$name)
785 {
786 $all = $this->_get_all_entries();
787 if($folder == "BASE"){
788 $folder = $this->_get_release_key($this->FAIrelease,TRUE);
789 }
791 if(isset($all[$folder])){
792 $a_folder = array();
793 $a_folder['STATUS'] = "ADDED";
794 $a_folder['NAME'] = $name;
795 $a_folder['UNIQID'] = uniqid();
796 $a_folder['ENTRIES']= array();
797 $a_folder['PARENT'] = $folder;
798 $a_folder['TYPE'] = "FOLDER";
799 $a_folder['ICON'] = "";
800 $all[$folder]['ENTRIES'][] = $a_folder;
801 }
802 }
805 /* !\brief Remove the given id from the menu structure.
806 @param String ID to of the entry we want to remove.
807 @return Boolean TRUE on success
808 */
809 function _remove_entry_id($id)
810 {
811 $all = $this->_get_all_entries();
812 if(isset($all[$id])){
813 $all[$id]['STATUS'] = "REMOVED";
814 $all[$id]['ENTRIES'] = array();
815 return(TRUE);
816 }
817 return(FALSE);
818 }
821 /* !\brief Remove the given id from the menu structure.
822 @param String ID to of the entry we want to remove.
823 @return Boolean TRUE on success
824 */
825 function _add_entry($folder_id,$entry,$pos = 0)
826 {
827 $all = $this->_get_all_entries();
829 /* Do not add removed */
830 if($entry['STATUS'] == "REMOVED"){
831 return;
832 }
834 if(isset($all[$folder_id])){
836 if(!isset($entry['ENTRIES'])){
837 $entries = array();
838 }else{
839 $entries = $entry['ENTRIES'];
840 }
842 $folder = &$all[$folder_id];
844 $entry['UNIQID'] = uniqid();
845 $entry['PARENT'] = $folder_id;
846 $entry['ENTRIES']= array();
847 $entry['STATUS'] = "ADDED";
849 $cnt = 0;
850 $new = array();
851 $added =FALSE;
852 if($obj['STATUS'] == "LOADED"){
853 $obj['STATUS'] = "EDITED";
854 }
855 if($pos == $cnt){
856 $new[] = $entry;
857 $added = TRUE;
858 }
859 $cnt ++;
860 $new[] = $obj;
861 }
862 if(!$added){
863 $new[] = $entry;
864 }
866 $all[$folder_id]['ENTRIES'] = $new;
867 foreach($entries as $sub){
868 $this->_add_entry($entry['UNIQID'],$sub,-1);
869 }
870 return(TRUE);
871 }
874 /*! \brief Add the application identified by $app_id to folder $folder_id
875 @param String folder_id The UNIQID of the folder where we want to add the new folder.
876 @param Integer app_id The ID of the application which should be added.
877 */
878 function _add_app_id($folder_id,$app_id)
879 {
880 $all = $this->_get_all_entries();
881 if($folder_id == "BASE"){
882 $folder_id = $this->_get_release_key($this->FAIrelease);
883 }
884 if(isset($all[$folder_id]) && isset($this->apps[$app_id])){
886 $new = array();
887 $new['TYPE'] = "ENTRY";
888 $new['NAME'] = $this->apps[$app_id]['cn'][0];
889 $new['UNIQID']= uniqid();
890 $new['PARENT']= $folder_id;
891 $new['PARAMETER']= array();
892 if(isset($this->apps[$app_id]['description'][0])){
893 $new['INFO'] = $this->apps[$app_id]['description'][0];
894 }else{
895 $new['INFO'] = "";
896 }
897 $new['STATUS']= "ADDED";
898 $all[$folder_id]['ENTRIES'][] = $new;
899 }
900 }
903 /*! \brief Return all entries linear.
904 @param Boolean $add_tags If TRUE, OPEN/CLOSE Tags will be appended.
905 @param &Array Start here, Pointer to an array.
906 */
907 function _get_all_entries($add_tags = FALSE, $skip_release = FALSE, &$cur = NULL)
908 {
909 $ret = array();
910 if($cur == NULL){
911 $cur = &$this->a_Structure;
912 }
913 foreach($cur as $key => $entry){
915 if($skip_release && $entry['TYPE'] == "RELEASE"){
916 continue;
917 }
918 if($entry['TYPE'] == "ENTRY"){
919 $found = FALSE;
920 foreach($this->apps as $app){
921 if($app['cn'][0] == $entry['NAME']){
922 $found = TRUE;
923 if(isset($app['description'][0])){
924 $entry['INFO'] = "[".$app['description'][0]."]";
925 }
926 break;
927 }
928 }
929 if(!$found){
930 $entry['INFO'] = "<font color='red'>"._("Not available in release.")."</font>";
931 }
932 }
935 $tmp = $entry;
936 if(!$add_tags){
937 $ret[$tmp['UNIQID']] = &$cur[$key];
938 if(isset($entry['ENTRIES']) && count($entry['ENTRIES'])){
939 $ret = array_merge($ret,$this->_get_all_entries($add_tags,$skip_release,$cur[$key]['ENTRIES']));
940 }
941 }else{
943 if(isset($tmp['ENTRIES'])){
944 unset($tmp['ENTRIES']);
945 }
946 if($tmp['STATUS'] != "REMOVED"){
947 $ret[] = $tmp;
948 if(isset($entry['ENTRIES']) && count($entry['ENTRIES'])){
949 $add = false;
950 foreach($entry['ENTRIES'] as $entry){
951 if($entry['STATUS'] != "REMOVED"){
952 $add = TRUE;
953 break;
954 }
955 }
957 if($add){
958 $ret[] = array("TYPE" => "OPEN", "PARENT" => $entry['PARENT']);
959 $ret = array_merge($ret,$this->_get_all_entries($add_tags,$skip_release,$cur[$key]['ENTRIES']));
960 $ret[] = array("TYPE" => "CLOSE" , "PARENT" => $entry['PARENT']);
961 }
962 }
963 }
964 }
965 }
966 return($ret);
967 }
970 function save()
971 {
972 $ldap = $this->config->get_ldap_link();
973 $all = $this->_get_all_entries();
974 $prio = 0;
975 $Actions = array("Remove" => array(),"Edit" => array() , "Add" => array());
977 foreach($all as $entry){
978 $prio ++;
979 $cur = $entry;
980 $dn = "";
982 do{
983 if($cur['TYPE'] == "ENTRY"){
984 $dn.= "cn=".$cur['NAME'].",";
985 }elseif($cur['TYPE'] == "FOLDER"){
986 $dn.= "cn=".$cur['NAME'].",";
987 }elseif($cur['TYPE'] == "RELEASE"){
988 $dn.= "ou=".$cur['NAME'].",";
989 }elseif($cur['TYPE'] == "BASE"){
990 }
991 if(!isset($all[$cur['PARENT']])){
992 $cur = NULL;
993 }else{
994 $cur = $all[$cur['PARENT']];
995 }
996 }while(is_array($cur));
998 $cur_dn = $dn.$this->dn;
1000 $attrs = array();
1001 switch($entry['TYPE']){
1002 case "ENTRY" :
1003 {
1004 $attrs['objectClass'] = "gotoMenuEntry";
1005 $attrs['cn'] = $entry['NAME'];
1006 $attrs['gosaApplicationPriority'] = $prio;
1007 $attrs['gosaApplicationParameter'] = array();
1010 foreach($entry['PARAMETER'] as $name => $value){
1011 $attrs['gosaApplicationParameter'][] = $name.":".$value;
1012 }
1013 if($entry['STATUS'] == "ADDED" && !count($attrs['gosaApplicationParameter'])){
1014 unset($attrs['gosaApplicationParameter']);
1015 }
1016 }
1017 break;
1018 case "FOLDER" :
1019 {
1020 $attrs['objectClass'] = "gotoSubmenuEntry";
1021 $attrs['cn'] = $entry['NAME'];
1022 $attrs['gosaApplicationPriority'] = $prio;
1023 if($entry['STATUS'] != "ADDED"){
1024 $attrs['gosaApplicationIcon'] = array();
1025 }
1027 if(!empty($entry['ICON'])){
1028 $attrs['gosaApplicationIcon'] = $entry['ICON'];
1029 }
1030 }
1031 break;
1032 case "RELEASE" :
1033 {
1034 $attrs['ou'] = $entry['NAME'];
1035 $attrs['objectClass'] = array();
1036 $attrs['objectClass'][] = "top";
1037 $attrs['objectClass'][] = "organizationalUnit";
1038 $attrs['objectClass'][] = "FAIbranch";
1039 if(!empty($entry['FAIstate'])){
1040 $attrs['FAIstate'] = $entry['FAIstate'];
1041 }
1042 }
1043 break;
1044 }
1046 if($entry['STATUS'] == "LOADED"){
1047 continue;
1048 }
1049 if($entry['STATUS'] == "REMOVED"){
1050 $Actions['Remove'][$cur_dn] = $cur_dn;
1051 }
1052 if($entry['STATUS'] == "EDITED"){
1053 $Actions['Edit'][$cur_dn] = $attrs;
1054 }
1055 if($entry['STATUS'] == "ADDED"){
1056 $Actions['Add'][$cur_dn] = $attrs;
1057 }
1058 }
1060 $ldap = $this->config->get_ldap_link();
1061 $ldap->cd($this->config->current['BASE']);
1062 foreach($Actions['Remove'] as $dn){
1063 $ldap->cd($dn);
1064 $ldap->cat($dn);
1065 if($ldap->count()){
1066 $ldap->rmdir_recursive($dn);
1067 if (!$ldap->success()){
1068 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $dn, LDAP_DEL, get_class()));
1069 }
1070 }
1071 }
1072 foreach($Actions['Add'] as $dn => $data){
1073 $ldap->cd($dn);
1074 $ldap->cat($dn);
1075 if(!$ldap->count()){
1076 $ldap->add($data);
1077 if (!$ldap->success()){
1078 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $dn, LDAP_DEL, get_class()));
1079 }
1080 }
1081 }
1082 foreach($Actions['Edit'] as $dn => $data){
1083 $ldap->cd($dn);
1084 $ldap->cat($dn);
1085 if($ldap->count()){
1086 $ldap->modify($data);
1087 if (!$ldap->success()){
1088 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $dn, LDAP_DEL, get_class()));
1089 }
1090 }
1091 }
1092 $this->_load_menu_structure();
1093 }
1096 /* Return plugin informations for acl handling */
1097 static function plInfo()
1098 {
1099 return (array(
1100 "plShortName" => _("Applications"),
1101 "plDescription" => _("Group applications"),
1102 "plSelfModify" => FALSE,
1103 "plDepends" => array(),
1104 "plPriority" => 0,
1105 "plSection" => array("admin"),
1106 "plCategory" => array("groups"),
1107 "plProvidedAcls"=> array(
1108 "gosaMemberApplication" => _("Application"),
1109 "FAIrelease" => _("Release"),
1110 "gosaApplicationParameter" => _("Application parameter"))
1111 ));
1112 }
1115 function PrepareForCopyPaste($source)
1116 {
1117 }
1120 function multiple_save_object()
1121 {
1122 if(isset($_POST['group_apps_multi'])){
1123 $this->save_object();
1124 plugin::multiple_save_object();
1126 /* Get posts */
1127 foreach(array("apps") as $attr){
1128 if(isset($_POST['use_'.$attr])) {
1129 $this->multi_boxes[] = $attr;
1130 }
1131 }
1132 }
1133 }
1136 function get_multi_edit_values()
1137 {
1138 $ret = plugin::get_multi_edit_values();
1140 if(in_array("apps",$this->multi_boxes)){
1141 $ret['gosaApplicationParameter'] = $this->gosaApplicationParameter;
1142 $ret['Categories'] = $this->Categories;
1143 $ret['gosaMemberApplication'] = $this->gosaMemberApplication;
1144 $ret['FAIrelease'] = $this->FAIrelease;
1145 $ret['appoption'] = $this->appoption;
1146 }
1147 return($ret);
1148 }
1149 }
1150 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1151 ?>