edc3239b34d1a8465448bdaa888a90dc36caa1f2
1 <?php
2 class appgroup extends plugin
3 {
4 /* CLI vars */
5 var $cli_summary= "Manage application groups";
6 var $cli_description= "Some longer text\nfor help";
7 var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
9 /* Appgroup attributes */
10 var $gosaMemberApplication= array();
12 /* Helpers */
13 var $departments = ""; // All departments within $this->curbase;
14 var $apps = array(); // All available applications
15 var $used_apps = array(); // Specifies which applications are currently assigned
17 var $option_name = array();
18 var $option_value = array();
19 var $appoption = array();
21 var $table = "";
22 var $curbase = "";
23 var $curCatDir ;
24 var $curCatDepth =0; //
26 /* attribute list for save action */
27 var $attributes = array("gosaMemberApplication","gosaApplicationParameter");
28 var $objectclasses = array("gosaApplicationGroup");
30 var $FAIrelease = "/";
31 var $InitialFAIrelease = "/";
32 var $Releases = array();
33 var $enableReleaseManagement = false;
35 var $AllAppsForRelease = array();
36 var $AllAppsForReleaseParameter = array();
38 var $CopyPasteVars = array("Categories");
39 var $gosaApplicationParameter ;
40 var $ui = NULL;
41 var $no_release_acls = false;
43 function appgroup ($config, $dn= NULL, $parent= NULL)
44 {
46 /* Check if we have relase mangement enabled and prepare group application for release management */
47 $tmp = search_config($config->data,"faiManagement","CLASS");
48 if(!empty($tmp)){
49 $this->enableReleaseManagement = true;
50 $this->objectclasses [] = "FAIreleaseTag";
51 $this->attributes [] = "FAIrelease";
52 }
54 plugin::plugin ($config, $dn, $parent);
56 /* set userinfo object */
57 $this->ui = get_userinfo();
59 /* Compatibility check
60 In some case of old applikations with old release tag saving,
61 we must reassign is_account state.
62 (Or if release management wasn't activated before creating this app) */
63 if($this->enableReleaseManagement){
65 /* Release management is activated && this is a valid group app account,
66 but no release class was found, so activate is_account flag */
67 if($dn != "new" && ( in_array("gosaApplicationGroup",$this->attrs['objectClass'])) &&
68 (!in_array("FAIreleaseTag",$this->attrs['objectClass']))){
69 $this->is_account =true;
70 }
71 }
73 /* Load member applications */
74 if (isset ($this->attrs["gosaMemberApplication"][0])){
75 $this->gosaMemberApplication = array();
76 for ($i= 0; $i<$this->attrs["gosaMemberApplication"]["count"]; $i++){
77 $this->gosaMemberApplication[]=
78 $this->attrs["gosaMemberApplication"][$i];
79 }
80 }
82 /* Load application options */
83 if (isset($this->attrs['gosaApplicationParameter'])){
84 for ($i= 0; $i<$this->attrs['gosaApplicationParameter']['count']; $i++){
85 $option= preg_replace('/^[^:]+:/', '',
86 $this->attrs['gosaApplicationParameter'][$i]);
87 $name= preg_replace('/:.*$/', '',
88 $this->attrs['gosaApplicationParameter'][$i]);
89 $this->appoption[$name]= $option;
90 }
91 }
93 /* Parse MemberApplication*/
94 $tmp = array();
95 $tmp2 = array();
96 $prios = array();
97 $cats = array();
99 foreach($this->gosaMemberApplication as $memberApp){
100 if(preg_match("/\|/i",$memberApp)){
102 $tmp = split("\|",$memberApp);
104 if(!empty($tmp[0])){
105 $tmp2[$tmp[1]][$tmp[2]] = array("App"=>$tmp[0]);
106 }
107 if(!empty($tmp[1])){
108 $n = split("/",$tmp[1]);
109 $c = count($n);
110 $cats [$tmp[1]] = $n[$c-1];
111 }
112 $prios[$tmp[1]][$tmp[2]] = $tmp[2];
113 }else{
114 $tmp2[]['App'] = $memberApp;
115 }
116 }
118 /* Assign collected category and application settings */
119 $this->Categories = $cats;
120 $this->gosaMemberApplication = $tmp2;
122 /* Sort application by category */
123 $cats[""]="";
124 foreach($cats as $cat ){
125 if((isset($prios[$cat]))&&(count($prios[$cat]))){
126 $max = max($prios[$cat]);
127 $min = 1;//min($prios[$cat]);
128 $last = false;
129 for($i = $min ; $i < $max ; $i++){
130 if(!isset($prios[$cat][$i])){
131 if($last == false){
132 $this->gosaMemberApplication[$cat][$i]['App'] = "__SEPARATOR__".$i;
134 $last = true;
135 }
136 }else{
137 $last = false;
138 }
139 }
140 }
141 }
143 /* Sort application by priority */
144 $tmp = array();
145 foreach($this->gosaMemberApplication as $key => $entries){
146 ksort ($entries);
147 foreach($entries as $entry){
148 $tmp[$key][]= $entry;
149 }
150 }
151 $this->gosaMemberApplication = $tmp;
152 $this->curbase = $this->config->current['BASE'];
154 /* Get required release informations */
155 if($this->enableReleaseManagement){
156 $this->InitialFAIrelease = $this->FAIrelease;
157 $this->Releases = $this->getReleases();
158 }
159 }
162 /* Combine new array */
163 function combineArrays($ar0,$ar1,$ar2)
164 {
165 $ret = array();
166 if(is_array($ar0))
167 foreach($ar0 as $ar => $a){
168 $ret[$ar]=$a;
169 }
170 if(is_array($ar1))
171 foreach($ar1 as $ar => $a){
172 $ret[$ar]=$a;
173 }
174 if(is_array($ar2))
175 foreach($ar2 as $ar => $a){
176 $ret[$ar]=$a;
177 }
178 return($ret);
179 }
181 /* Returns element position within given array */
182 function getpos($atr,$attrs)
183 {
184 $i = 0;
185 foreach($attrs as $attr => $name) {
186 $i++;
187 if($attr == $atr){
188 return($i);
189 }
190 }
191 return(-1);
192 }
195 /* Check current combination of application && release
196 Are all application available?, application parameter changed? ... */
197 function diffAppsInReleases()
198 {
199 /* Only diff if it is required */
200 $ret =array();
202 /* If current release has changed */
203 if($this->FAIrelease != $this->InitialFAIrelease){
205 /* Walk through all apps which are currently displayed */
206 if(isset($this->gosaMemberApplication[$this->curCatDir])){
208 foreach($this->gosaMemberApplication[$this->curCatDir] as $entry){
210 /* If application is also available in new release, check if parameter differs */
211 if(in_array($entry['App'],$this->AllAppsForRelease)){
213 $old = array(); // Old application parameter
214 $new = array(); // New parameters
216 /* There are possibly no parameters specified */
217 if(isset($this->AllAppsForReleaseParameter[$this->InitialFAIrelease][$entry['App']])){
218 $old = $this->AllAppsForReleaseParameter[$this->InitialFAIrelease][$entry['App']];
219 }
221 if(isset($this->AllAppsForReleaseParameter[$this->FAIrelease][$entry['App']])){
222 $new = $this->AllAppsForReleaseParameter[$this->FAIrelease][$entry['App']];
223 }
225 /* Both (old & new) have no gosaApplicationParameter
226 */
227 if((!isset($old['gosaApplicationParameter'])) && (!isset($new['gosaApplicationParameter']))){
228 $ret[$entry['App']] = false;
230 /* Both got gosaApplicationParameter */
231 }elseif((isset($old['gosaApplicationParameter'])) && (isset($new['gosaApplicationParameter']))){
232 if(array_differs($old['gosaApplicationParameter'],$new['gosaApplicationParameter'])){
233 $ret[$entry['App']] = true;
234 }else{
235 $ret[$entry['App']] = false;
236 }
237 }
238 /* Initially had gosaApplicationParameter bot in new release not */
239 }elseif((isset($old['gosaApplicationParameter'])) && (!isset($new['gosaApplicationParameter']))){
240 $ret[$entry['App']] = true;
242 /* Old release had no gosaApplicationParameter but new got some */
243 }elseif((!isset($old['gosaApplicationParameter'])) && (isset($new['gosaApplicationParameter']))){
244 $ret[$entry['App']] = true;
245 }
246 }
247 }
248 }
249 return($ret);
250 }
252 /* TRansports the geiven Arraykey one position up*/
253 function ArrayUp($atr,$attrs)
254 {
255 $ret = $attrs;
256 $pos = $this->getpos($atr,$attrs) ;
257 $cn = count($attrs);
258 if(!(($pos == -1)||($pos == 1))){
259 $before = array_slice($attrs,0,($pos-2));
260 $mitte = array_reverse(array_slice($attrs,($pos-2),2));
261 $unten = array_slice($attrs,$pos);
262 $ret = array();
263 $ret = $this->combineArrays($before,$mitte,$unten);
264 }
265 return($ret);
266 }
269 /* TRansports the geiven Arraykey one position up*/
270 function ArrayDown($atr,$attrs)
271 {
272 $ret = $attrs;
273 $pos = $this->getpos($atr,$attrs) ;
274 $cn = count($attrs);
275 if(!(($pos == -1)||($pos == $cn))){
276 $before = array_slice($attrs,0,($pos-1));
277 $mitte = array_reverse(array_slice($attrs,($pos-1),2));
278 $unten = array_slice($attrs,($pos+1));
279 $ret = array();
280 $ret = $this->combineArrays($before,$mitte,$unten);
281 }
282 return($ret);
283 }
286 /* Sort category on position up */
287 function catUp($id)
288 {
289 /* Get all cats depinding on current dir */
290 $cats = $this->GetSubdirs($this->curCatDir);
291 $newcats =$this->ArrayUp($id,$cats);
292 foreach($newcats as $cat => $name){
293 unset($this->Categories[$cat]);
294 }
295 foreach($newcats as $cat => $name){
296 $this->Categories[$cat]=$name;
297 }
298 }
301 /* Sort category on position down */
302 function catDown($id)
303 {
304 /* Get all cats depinding on current dir */
305 $cats = $this->GetSubdirs($this->curCatDir);
306 $newcats =$this->ArrayDown($id,$cats);
307 foreach($newcats as $cat => $name){
308 unset($this->Categories[$cat]);
309 }
310 foreach($newcats as $cat => $name){
311 $this->Categories[$cat]=$name;
312 }
313 }
316 /* Increase application priority */
317 function getOneUp($appl)
318 {
319 $cat = $this->curCatDir;
320 $apps = $this->gosaMemberApplication[$cat];
321 $appsA = array();
322 foreach ($apps as $appkey => $name){
323 $appsA[$name['App']] =$name['App'];
324 }
325 $result = $this->ArrayUp($appl,$appsA);
326 $ret = array();
327 foreach($result as $app){
328 $ret[]=array("App"=>$app);
329 }
330 $this->gosaMemberApplication[$cat] = $ret;
331 }
334 /* Decrease application priority */
335 function getOneDown($appl)
336 {
337 $cat = $this->curCatDir;
338 $apps = $this->gosaMemberApplication[$cat];
339 $appsA = array();
340 foreach ($apps as $appkey => $name){
341 $appsA[$name['App']] =$name['App'];
342 }
343 $result = $this->ArrayDown($appl,$appsA);
344 $ret = array();
345 foreach($result as $app){
346 $ret[]=array("App"=>$app);
347 }
348 $this->gosaMemberApplication[$cat] = $ret;
349 }
352 /* Add seperator to application list */
353 function AddSeperator($id)
354 {
355 $found = false;
356 $cat = "";
357 $tmp = array();
358 foreach($this->gosaMemberApplication[$this->curCatDir] as $appID => $app){
359 $tmp[] = $app;
360 if(($app['App'] == $id)&&(!$found)){
361 $cnt = count($this->gosaMemberApplication[$this->curCatDir]);
362 $tmp[] = array("App" => "__SEPARATOR__".($cnt+1));
363 $found = true;
364 }
365 }
366 if($found){
367 $this->gosaMemberApplication[$this->curCatDir]=$tmp;
368 }
369 }
372 /* Check if application acls are readable */
373 function check_acls()
374 {
375 return(count($this->ui->get_module_departments("application")));
376 }
379 function execute()
380 {
381 /* Call parent execute */
382 plugin::execute();
384 /* Check if department was selected */
385 if((isset($_GET['act']))&&($_GET['act']=="depopen")){
386 $dep = base64_decode($_GET['depid']);
387 $this->curbase =$dep;
388 }
390 /* Check if category was selected */
391 if((isset($_GET['act']))&&($_GET['act']=="open") && isset($this->Categories[base64_decode($_GET['id'])])){
392 $this->curCatDir = base64_decode($_GET['id']);
393 }
395 /* Do we need to flip is_account state? */
396 if(isset($_POST['modify_state'])){
397 if($this->is_account && $this->acl_is_removeable()){
398 $this->is_account= FALSE;
399 }elseif(!$this->is_account && $this->acl_is_createable()){
400 $this->is_account= TRUE;
401 }
402 }
404 /* Do we represent a valid group? */
405 if (!$this->is_account && $this->parent == NULL){
406 $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\"> <b>".
407 _("This 'dn' is no appgroup.")."</b>";
408 return ($display);
409 }
411 /* Show tab dialog headers */
412 $display= "";
413 if ($this->parent != NULL){
414 if ($this->is_account){
415 $display= $this->show_disable_header(_("Remove applications"),
416 _("This group has application features enabled. You can disable them by clicking below."));
417 } else {
418 $display.= $this->show_enable_header(_("Create applications"),
419 _("This group has application features disabled. You can enable them by clicking below."));
420 return ($display);
421 }
422 }
424 /* Check acl, applications must be readable */
425 if(!$this->check_acls()){
426 $display .= "<img src='images/button_cancel.png' alt='"._("ACL")."' class='center'>
427 <b>"._("Insufficient permissions")."</b>
428 <p>".
429 _("You do not have permission to query application entries. All your changes will not be saved.").
430 "</p><p class='seperator'> </p>";
431 $this->no_release_acls = true;
432 }
435 /* Add Categorie */
436 if((isset($_POST['AddCat']))&&(isset($_POST['CatName']))&&(!empty($_POST['CatName']))){
438 /* Only allow adding a category, if it is allowed */
439 if($this->acl_is_writeable("gosaMemberApplication",$this->no_release_acls)){
441 if(preg_match("/[\\\\\/]/i",$_POST['CatName'])){
442 print_red(_("Invalid character in category name."));
443 }elseif(!in_array($_POST['CatName'],$this->Categories)){
444 if(empty($this->curCatDir)){
445 $this->Categories[$_POST['CatName']]=$_POST['CatName'];
446 }else{
447 $this->Categories[$this->curCatDir."/".$_POST['CatName']]=$_POST['CatName'];
448 }
449 }else{
450 print_red(_("The specified category already exists."));
451 }
452 }
453 }
456 $this->reload();
457 $this->diffAppsInReleases();
459 /* Check POST variables for commands
460 to add/remove some applications */
461 $only_once = false;
462 if($this->acl_is_writeable("gosaMemberApplication",$this->no_release_acls)){
464 /* Walk through posts */
465 foreach($_POST as $name => $value){
467 /* Add a seperator to current category */
468 if((preg_match("/AddSep_/",$name))&&(!$only_once)){
469 $only_once = true;
470 $n = preg_replace("/AddSep_/","",$name);
471 $val= preg_replace("/_.*$/","",$n);
472 $this->AddSeperator($val);
473 }
475 /* Delete application | seperator entry */
476 if((preg_match("/DelApp_/",$name))&&(!$only_once)){
477 $only_once = true;
479 if(preg_match("/DelApp___SEPARATOR__/",$name)) {
480 $n= preg_replace("/DelApp___SEPARATOR__/","",$name);
481 $val= "__SEPARATOR__".preg_replace("/_.*$/","",$n);
482 }else{
483 $n = preg_replace("/DelApp_/","",$name);
484 $val= preg_replace("/_.*$/","",$n);
485 }
487 foreach($this->gosaMemberApplication as $key => $cat){
488 foreach($cat as $key2 => $app){
489 if($app['App'] == $val){
490 unset($this->gosaMemberApplication[$key][$key2]);
491 if(isset($this->used_apps[$val])){
492 foreach($this->getParameters($val) as $para){
493 if(isset($this->appoption[$para])){
494 unset($this->appoption[$para]);
495 }
496 }
497 unset($this->used_apps[$val]);
498 }
499 }
500 }
501 }
502 }
504 /* Remove category entry */
505 if(preg_match("/DelCat_/",$name)){
506 $n = preg_replace("/DelCat_/","",$name);
507 $app = base64_decode( preg_replace("/_.*$/","",$n));
508 foreach($this->Categories as $key => $cat){
509 if($cat == $app){
510 foreach($this->Categories as $p => $n){
511 if(preg_match("/^".$key."\/.*/",$p)){
512 unset($this->Categories[$p]);
513 }
514 }
515 unset($this->Categories[$key]);
516 }
517 }
518 }
520 /* Edit application parameter */
521 if((preg_match("/EdiApp_/",$name))&&(!$only_once)){
523 $only_once = true;
524 $appname = $value;
525 $appname = preg_replace("/EdiApp_/","",$name);
526 $appname = preg_replace("/_.*$/","",$appname);
528 /* We've got the appname, get parameters from ldap */
529 $ldap= $this->config->get_ldap_link();
531 /* Check if we have release management enabled */
532 $tmp = search_config($this->config->data,"faiManagement","CLASS");
533 if(!empty($tmp)){
535 /* Get application parameter from ldap */
536 $tmp = array_flip($this->Releases);
537 $base = $tmp[$this->FAIrelease];
538 $ldap->cd($base);
539 $ldap->search("(&(objectClass=gosaApplication)(cn=$appname))",array("gosaApplicationParameter"));
540 $found = "";
541 while($attrs = $ldap->fetch()) {
542 if(preg_match("/cn=".$appname.",".$base."/",$attrs['dn'])){
543 $found = $attrs['dn'];
544 }
545 }
546 $ldap->cat($found, array("gosaApplicationParameter"));
547 }else{
549 /* Get application parameter from ldap */
550 $ldap->cd($this->config->current['BASE']);
551 $ldap->search("(&(objectClass=gosaApplication)(cn=$appname))",array("gosaApplicationParameter"));
552 }
554 /* Check if this application is unique */
555 if ($ldap->count() != 1){
556 print_red (_("The selected application name is not uniq. Please check your LDAP."));
557 } else {
559 /* Get parameter */
560 $attrs= $ldap->fetch();
561 if(isset($attrs['gosaApplicationParameter'])){
562 $this->dialog= TRUE;
564 /* Fill name and value arrays */
565 for ($i= 0; $i<$attrs['gosaApplicationParameter']['count']; $i++){
566 $option= preg_replace('/^[^:]+:/', '',
567 $attrs['gosaApplicationParameter'][$i]);
568 $name= preg_replace('/:.*$/', '',
569 $attrs['gosaApplicationParameter'][$i]);
570 $this->option_name[$i]= $name;
572 /* Fill with values from application, default should be
573 loaded by the external scripts */
574 if (isset($this->appoption[$name])){
575 $this->option_value[$i]= $this->appoption[$name];
576 }
577 }
579 /* Create edit field */
580 $table= "<table summary=\"\">";
581 for ($i= 0; $i < count($this->option_name); $i++){
582 if (isset($this->option_value[$i])){
583 $value= $this->option_value[$i];
584 } else {
585 $value= "";
586 }
587 $table.="<tr><td>".$this->option_name[$i]."</td><td>".
588 "<input name=\"value$i\" size=60 maxlength=250 ".
589 "value=\"".$value."\"><br></td></tr>";
590 }
591 $table.= "</table>";
592 $this->table= $table;
593 } else {
594 print_red (_("The selected application has no options."));
595 }
596 }
597 }
598 }
599 }
601 /* Add application with post */
602 if((isset($_GET['act']))&&($_GET['act']=="add")){
603 $this->used_apps[$_GET['id']]= $_GET['id'];
604 asort($this->used_apps);
605 $this->addApp($_GET['id']);
606 }
608 /* Cancel edit options? */
609 if (isset($_POST['edit_options_cancel'])){
610 $this->dialog= FALSE;
611 }
613 /* Finish edit options? */
614 if (isset($_POST['edit_options_finish'])){
615 $this->dialog= FALSE;
617 /* Save informations passed by the user */
618 $this->option_value= array();
619 for ($i= 0; $i<count($this->option_name); $i++){
620 $this->appoption[$this->option_name[$i]]= $_POST["value$i"];
621 $this->is_modified= TRUE;
622 }
623 }
625 /* Prepare templating stuff */
626 $smarty= get_smarty();
627 $smarty->assign("used_apps", $this->used_apps);
628 $apps= array();
629 foreach ($this->apps as $key => $value){
630 if (!array_key_exists($key, $this->used_apps)){
631 $apps["$key"]= "$value";
632 }
633 }
636 /* Create application list */
637 $div = new DivSelectBox("appgroup");
638 $div->SetHeight(300);
639 $departments = array();
640 $res = get_list("(objectClass=gosaDepartment)", "application", $this->curbase,array("description","cn","ou"),GL_SIZELIMIT);
641 foreach($res as $value){
642 $fdn= @LDAP::fix(str_replace($this->curbase,"",$value['dn']));
643 if($value["description"][0]!=".."){
644 $departments[$value['dn']]= convert_department_dn($fdn)." - [".$value["description"][0]."]";
645 }else{
646 $departments[$value['dn']]=convert_department_dn($fdn);
647 }
648 }
650 /* Create 'open' and 'add' links */
651 if($this->acl_is_writeable("gosaMemberApplication",$this->no_release_acls)){
652 $linkadd = "<a href='?plug=".$_GET['plug']."&act=add&id=%s'>%s</a>";
653 }else{
654 $linkadd = "%s";
655 }
656 $linkopen = "<a href='?plug=".$_GET['plug']."&act=depopen&depid=%s'>%s</a>";
658 /* Create base back entry */
659 $base_back = preg_replace("/^[^,]+,/","",$this->curbase);
660 if((strlen($base_back)>= strlen($this->config->current['BASE']))&&($this->curbase!=$this->config->current['BASE'])){
661 $div->AddEntry(array(
662 array("string"=>sprintf($linkopen,base64_encode($base_back),".. ["._("back")."]"),
663 "attach"=>"style='border:0px;'")
664 ));
665 }
667 /* Append departments for current base */
668 foreach($departments as $key => $app){
669 $div->AddEntry(array(
670 array("string"=>"<img class='center' src='images/folder.png' alt='"._("department")."'> ".sprintf($linkopen,base64_encode($key),$app),
671 "attach"=>"style='border:0px;'")
672 ));
673 }
675 /* Add applications found on this base */
676 foreach($apps as $key => $app){
677 $div->AddEntry(array(
678 array("string"=>sprintf("<input class='center' type='checkbox' value='1' name='AddApp_%s'>",$key).
679 "<img class='center' src='images/select_application.png' alt='"._("application")."'> ".sprintf($linkadd,$key,$app),
680 "attach"=>"style='border:0px;'")
681 ));
682 }
684 /* Create list of used/assigned applications */
685 $div2 = new DivSelectBox("appgroup");
686 $div2->SetHeight(300);
688 /* Check acls to create "edit/remove" category links */
689 if(!$this->acl_is_writeable("gosaMemberApplication",$this->no_release_acls)){
690 $linkopen = "<img class='center' src='images/folder.png' alt=\"\"> <a href='?plug=".$_GET['plug']."&act=open&id=%s'>%s</a>";
691 $catremove = " <img src='images/empty.png' alt=' '>";
692 $catupdown = "";
693 }else{
694 $linkopen = "<img class='center' src='images/folder.png' alt=\"\"> <a href='?plug=".$_GET['plug']."&act=open&id=%s'>%s</a>";
695 $catremove = " <input type='image' src='images/edittrash.png' title='"._("Delete entry")."' name='DelCat_%s' value='%s'>";
696 $catupdown = "<a href='?plug=".$_GET['plug']."&act=cat_up&id=%s'>".
697 "<img align='top' alt=\"\" src='images/sort_up.png' border=0 title='"._("Move up")."'>".
698 "</a> ".
699 "<a href='?plug=".$_GET['plug']."&act=cat_down&id=%s'>".
700 "<img alt=\"\" src='images/sort_down.png' title='"._("Move down")."' border=0>".
701 "</a>";
702 }
704 /* Add back category for current category */
705 if(empty($this->curCatDir)){
706 $cnt =0;
707 }else{
708 $cnt = count(split("/",$this->curCatDir));
709 $tmp = split("/",$this->curCatDir);
710 $bbk = "";
711 for($i = 0 ; $i < ($cnt -1 ) ; $i++){
712 $bbk .= $tmp[$i];
713 }
714 $div2 ->AddEntry(array(array("string"=>sprintf($linkopen,base64_encode($bbk),"..")),array("string"=>" ","attach"=>"style='border-right:0px;'")));
715 }
717 /* Add sub categories */
718 $this->GetSubdirs($this->curCatDir);
719 foreach($this->GetSubdirs($this->curCatDir) as $path => $name){
720 $div2 ->AddEntry(array(
721 array("string"=>sprintf($linkopen,base64_encode($path),$name)),
722 array("string"=>preg_replace("/%s/",base64_encode($path),$catupdown.$catremove),
723 "attach"=>"align='right' style='width:80px;border-right:0px;'")));
724 }
726 /* Create priority & seperator links */
727 $separator ="<hr size=1>";
728 if($this->acl_is_writeable("gosaMemberApplication",$this->no_release_acls)){
729 $sep = "<input type='image' src='images/back.png' title='"._("Insert seperator")."' value='%s' name='AddSep_%s'>";
730 $upudown = "<a href='?plug=".$_GET['plug']."&act=one_up&id=%s'>".
731 " <img alt='{t}sort{/t}' align='top' src='images/sort_up.png' title='"._("Move up")."' border=0>".
732 "</a> ".
733 "<a href='?plug=".$_GET['plug']."&act=one_down&id=%s'>".
734 " <img alt='{t}sort{/t}' src='images/sort_down.png' title='"._("Move down")."' border=0>".
735 "</a> ".
736 "<input type='image' src='images/edittrash.png' title='"._("Delete entry")."' name='DelApp_%s' value='%s' alt='{t}delete{/t}' >";
737 }else{
738 $sep = "";
739 $upudown = "";
740 }
742 /* Create edit link */
743 if($this->acl_is_writeable("gosaApplicationParameter",$this->no_release_acls)){
744 $edit= " <input type='image' src='images/edit.png' title='"._("Edit entry")."' name='EdiApp_%s' value='%s' alt='{t}edit{/t}' >";
745 }else{
746 $edit= "";
747 }
749 /* Get differences to mark those entries that have changed from last edit. */
750 $Differences = $this->diffAppsInReleases();
752 /* Walk through entries an append them to list */
753 if(isset($this->gosaMemberApplication[$this->curCatDir])){
754 foreach($this->gosaMemberApplication[$this->curCatDir] as $cat => $entry){
756 /* Add seperator */
757 if(preg_match("/__SEPARATOR__/",$entry['App'])){
758 $div2 ->AddEntry(array(array("string"=>$separator),
759 array("string"=>preg_replace("/\%s/",htmlentities($entry['App']),$upudown),"attach"=>"align='right' style='border-right:0px;'")));
760 }else{
762 /* Add application */
764 $image = "";
765 /* Check if application was available within selected release
766 * or application list if release management is not active
767 */
768 if(!in_array($entry['App'],$this->AllAppsForRelease)){
770 /* release managent is active
771 */
772 if(!$this->enableReleaseManagement){
773 $image = "<img class='center' src='images/select_invalid_application.png'
774 title='"._("This application is no longer available.")."'> ";
775 }else{
776 $image = "<img class='center' src='images/select_invalid_application.png'
777 title='".sprintf(_("This application is not available in any release named %s."),$this->FAIrelease)."'> ";
778 }
780 }elseif(isset($Differences[$entry['App']]) && ($Differences[$entry['App']] == true)) {
781 $entry['App'].=" <i>["._("Check parameter")."]</i>";
782 $image = "<img class='center' src='images/select_invalid_application.png'
783 title='"._("This application has changed parameters.")."'> ";
784 }else{
785 $image = "<img class='center' src='images/select_application.png' alt=\"\"> ";
786 }
788 $div2->AddEntry(array(array("string"=>sprintf($image."%s",$entry['App'])),
789 array("string"=>preg_replace("/\%s/",htmlentities($entry['App']),$sep.$edit.$upudown),
790 "attach"=>"align='right' style='width:100px;border-right:0px;'")));
791 }
792 }
793 }
795 /* Assign created div lists to template */
796 $smarty->assign("UsedApps", $div2->DrawList());
797 $smarty->assign("List", $div->DrawList());
798 $smarty->assign("apps", $apps);
800 $smarty->assign("enableReleaseManagement",$this->enableReleaseManagement);
802 $smarty->assign("ReleaseSelectAble", false);
803 $smarty->assign("Release", $this->FAIrelease);
805 if($this->enableReleaseManagement){
806 $smarty->assign("FAIrelease", $this->FAIrelease);
807 $smarty->assign("Releases", $this->Releases);
809 if(!$this->no_release_acls && count($this->Releases)){
810 $smarty->assign("ReleaseSelectAble", true);
811 }
812 }
814 /* Set acls to template */
815 $tmp = $this->plInfo();
816 foreach($tmp['plProvidedAcls'] as $acl => $translation){
817 $smarty->assign($acl."ACL",$this->getacl($acl,$this->no_release_acls));
818 }
820 /* Show main page */
821 if ($this->dialog){
822 $smarty->assign("table", $this->table);
823 $display.= $smarty->fetch (get_template_path('application_options.tpl', TRUE));
824 } else {
825 $display.= $smarty->fetch (get_template_path('application.tpl', TRUE));
826 }
828 return ($display);
829 }
832 function getReleases()
833 {
834 /* Only display those releases that we are able to read */
835 $dn = $this->config->current['BASE'];
836 $filter = "(&(objectClass=organizationalUnit)(objectClass=FAIbranch))";
837 $res = get_list($filter,"application", $dn, array("ou"), GL_SUBSEARCH);
839 $ret =array();
840 foreach($res as $attrs){
841 if(preg_match("/ou=apps,/",$attrs['dn'])){
842 $bb = preg_replace("/ou=apps,.*/","",$attrs['dn']);
843 $parts = array_reverse(split("ou=",$bb));
845 $str ="";
846 foreach($parts as $part){
847 if(empty($part)) {
848 continue;
849 }
850 $str .= str_replace(",","",$part)."/";
851 }
852 $name = preg_replace("/\/$/","",$str);
853 if(empty($name)) {
854 $name ="/";
855 }
856 $ret[$attrs['dn']] = $name;
857 }
858 }
859 return($ret);
860 }
862 function save_object()
863 {
865 /* Move category one position up or down */
866 if((isset($_GET['act']))&&(($_GET['act'] == "cat_up")||($_GET['act']=="cat_down"))){
867 if($_GET['act']=="cat_up"){
868 $this->catUp(base64_decode($_GET['id']));
869 }
870 if($_GET['act']=="cat_down"){
871 $this->catDown(base64_decode($_GET['id']));
872 }
873 }
875 /* Move application one position up or down */
876 if((isset($_GET['act']))&&(($_GET['act'] == "one_up")||($_GET['act']=="one_down"))){
877 if(isset($_GET['id'])){
878 $id = $_GET['id'];
879 $act = $_GET['act'];
881 if($act == "one_up"){
882 $this->getOneUp($id);
883 }elseif($act == "one_down") {
884 $this->getOneDown($id);
885 }
886 }
887 }
890 plugin::save_object();
891 }
894 function remove_from_parent()
895 {
896 plugin::remove_from_parent();
898 $ldap= $this->config->get_ldap_link();
899 $ldap->cd($this->dn);
900 $this->cleanup();
902 $ldap->modify ($this->attrs);
904 show_ldap_error($ldap->get_error(), sprintf(_("Removing of groups/applications with dn '%s' failed."),$this->dn));
906 /* Optionally execute a command after we're done */
907 $this->handle_post_events("remove");
908 }
911 /* Save to LDAP */
912 function save()
913 {
914 /* Skip saving application settings, if we do not have release acls */
915 if($this->no_release_acls){
916 gosa_log("Skip saving group application extension. Caused by insufficient acls");
917 return;
918 }
920 plugin::save();
924 /* Copy members */
925 $this->Categories[""]="";
926 $this->attrs["gosaMemberApplication"]= array();
927 $this->attrs["gosaApplicationParameter"]= array();
928 foreach($this->Categories as $name => $cats){
929 $i =0;
930 if(isset($this->gosaMemberApplication[$name])){
931 foreach($this->gosaMemberApplication[$name] as $entry){
932 if(!preg_match("/__SEPARATOR__/",$entry['App'])){
933 $this->attrs["gosaMemberApplication"][]= $entry['App']."|".$name."|".$i;
934 }
935 $i ++;
936 }
937 }
938 if(($i==0)&&(!empty($name))){
939 $this->attrs["gosaMemberApplication"][]= "|".$name."|".$i;
940 }
941 }
943 /* Are there application parameters to be saved */
944 $this->attrs['gosaApplicationParameter']= array();
945 foreach($this->appoption as $name => $value){
946 if ($value != ""){
947 $this->attrs['gosaApplicationParameter'][]= "$name:$value";
948 }
949 }
951 /* Write back to LDAP */
952 $ldap= $this->config->get_ldap_link();
953 $ldap->cd($this->dn);
954 $this->cleanup();
955 $ldap->modify ($this->attrs);
957 show_ldap_error($ldap->get_error(), sprintf(_("Saving of groups/applications with dn '%s' failed."),$this->dn));
959 /* Optionally execute a command after we're done */
960 if ($this->initially_was_account == $this->is_account){
961 if ($this->is_modified){
962 $this->handle_post_events("modify");
963 }
964 } else {
965 $this->handle_post_events("add");
966 }
968 }
970 function check()
971 {
972 /* Call common method to give check the hook */
973 $message= plugin::check();
975 return ($message);
976 }
979 function reload()
980 {
981 /* Generate applist */
982 $this->apps= array();
984 /* Special handling for release managed apps */
985 $tmp = search_config($this->config->data,"faiManagement","CLASS");
986 if(!empty($tmp)){
987 $this->enableReleaseManagement = true;
989 /* Check if release is available */
990 $tmp = array_flip($this->Releases);
991 if(isset($tmp[$this->FAIrelease])){
992 $base = $tmp[$this->FAIrelease];
993 }else{
995 /* Release is not available, check if there is an alternative */
996 $old_r = $this->FAIrelease;
997 $k = key($tmp);
999 if(isset($tmp[$k])){
1001 /* We have found an alternative release name */
1002 $r = $tmp[$k];
1003 $this->FAIrelease = $k;
1004 $base = $r;
1006 /* Display msg */
1007 if(!(!$this->initially_was_account && $old_r =="/")){
1008 print_red(sprintf(_("Can't resolve the release name '%s', setting release name to '%s'. Possibly the objects base has changed."),$old_r,$k));
1009 }
1010 }else{
1012 /* There are no releases available ... */
1013 print_red(_("There are no releases available. You will not be able to select another release."));
1014 return;
1015 }
1016 }
1018 /* Get applications for this release */
1019 $base = preg_replace("/ou=apps,.*$/","ou=apps,".$this->curbase,$base);
1020 $res = get_list("(objectClass=gosaApplication)","application",$base,array("*"));
1021 }else{
1023 /* Get applications for this base */
1024 $res = get_list("(objectClass=gosaApplication)","application","ou=apps,".$this->curbase,array("*"));
1025 }
1027 /* Append applications */
1028 foreach($res as $attrs){
1029 if (isset($attrs["description"][0])){
1030 $this->apps[$attrs["cn"][0]]=
1031 $attrs["cn"][0]." (".
1032 $attrs["description"][0].")";
1033 } else {
1034 $this->apps[$attrs["cn"][0]]=
1035 $attrs["cn"][0];
1036 }
1037 }
1039 /* Get all apps ... */
1040 $res = get_list("objectClass=gosaApplication","application",$this->config->current['BASE'],array("gosaApplicationParameter","cn"));
1041 $tmp = search_config($this->config->data,"faiManagement","CLASS");
1042 $this->AllAppsForRelease = array();
1043 if(!empty($tmp)){
1044 $tmp = array_flip($this->Releases);
1045 foreach($res as $attrs){
1047 $testdn = preg_replace("/ou=apps,.*$/","ou=apps",$attrs['dn']);
1048 $testdn = preg_replace("/^[^,]+/","",$testdn);
1049 $testdn = preg_replace("/^,/","",$testdn);
1051 if($testdn == preg_replace("/ou=apps,.*$/","ou=apps",$tmp[$this->FAIrelease])){
1052 $this->AllAppsForRelease[$attrs['dn']] = $attrs['cn'][0];
1053 $this->AllAppsForReleaseParameter[$this->FAIrelease][$attrs['cn'][0]] = $attrs;
1054 }
1055 }
1056 }else{
1057 foreach($res as $attrs){
1058 $this->AllAppsForRelease[$attrs['dn']] = $attrs['cn'][0];
1059 }
1060 }
1062 natcasesort ($this->apps);
1063 reset ($this->apps);
1065 if(is_array($this->gosaMemberApplication))
1066 foreach ($this->gosaMemberApplication as $cat){
1067 if(is_array($cat))
1068 foreach($cat as $entry){
1069 $this->used_apps[$entry['App']]= $entry['App'];
1070 }
1071 }
1072 }
1075 function addApp($cn)
1076 {
1077 if((isset($this->gosaMemberApplication[$this->curCatDir]))&&(is_array($this->gosaMemberApplication[$this->curCatDir]))){
1078 foreach($this->gosaMemberApplication[$this->curCatDir] as $entry){
1079 if($entry['App'] == $cn) return;
1080 }
1081 }
1082 $this->gosaMemberApplication[$this->curCatDir][]= array("App"=>$cn);
1083 $this->used_apps[$cn]=$cn;
1084 $this->is_modified= TRUE;
1085 }
1088 function removeApp($cn)
1089 {
1090 $temp= array();
1091 foreach ($this->gosaMemberApplication as $value){
1092 if ($value != $cn){
1093 $temp[]= $value;
1094 }
1095 }
1096 $this->gosaMemberApplication= $temp;
1097 $this->is_modified= TRUE;
1098 }
1100 function getParameters($app)
1101 {
1102 $tmp = $this->getReleases();
1103 $ret = array();
1104 if(in_array($this->FAIrelease,$tmp)){
1105 $tmp2 = array_flip($tmp);
1106 $base = $tmp2[$this->FAIrelease];
1107 $ldap = $this->config->get_ldap_link();
1108 $ldap->cd($this->config->current['BASE']);
1109 $ldap->search("(&(objectClass=gosaApplication)(cn=".$app.")(gosaApplicationParameter=*))",array("gosaApplicationParameter"));
1110 if($ldap->count()){
1111 $attrs = $ldap->fetch();
1112 for($i = 0 ; $i < $attrs['gosaApplicationParameter']['count'] ; $i ++ ){
1113 $name = preg_replace("/:.*$/","",$attrs['gosaApplicationParameter'][$i]);
1114 $ret[$name] = $name;
1115 }
1116 }
1117 }
1118 return($ret);
1119 }
1121 function GetSubdirs($dir)
1122 {
1123 $ret = array();
1124 $tmp1 = split("/",$this->curCatDir);
1126 foreach($this->Categories as $path=>$cat){
1127 $tmp2 = split("/",$path);
1129 if((empty($this->curCatDir))&&(!preg_match("/\//",$path))){
1130 $abort = false;
1131 }elseif(((count($tmp1))+1) == (count($tmp2))){
1132 $abort = false;
1133 for($i = 0 ; $i < count($tmp1) ; $i++){
1134 if($tmp1[$i] != $tmp2[$i]){
1135 $abort = true;
1136 }
1137 }
1138 }else{
1139 $abort= true;
1140 }
1141 if(!$abort){
1142 $ret[$path]=$cat;
1143 }
1144 }
1145 return($ret);
1146 }
1149 /* Return plugin informations for acl handling */
1150 function plInfo()
1151 {
1152 return (array(
1153 "plShortName" => _("Applications"),
1154 "plDescription" => _("Group applications"),
1155 "plSelfModify" => FALSE,
1156 "plDepends" => array(),
1157 "plPriority" => 0,
1158 "plSection" => array("admin"),
1159 "plCategory" => array("groups"),
1160 "plProvidedAcls"=> array(
1161 "gosaMemberApplication" => _("Application"),
1162 "FAIrelease" => _("Release"),
1163 "gosaApplicationParameter" => _("Application parameter"))
1164 ));
1165 }
1166 }
1167 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1168 ?>