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") && (empty($_GET['id']) || 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 multiple */
602 if(isset($_POST['AddApps'])){
603 foreach($_POST as $name => $value){
604 if(preg_match("/AddApp_/",$name)){
605 $app = preg_replace("/AddApp_/","",$name);
606 $this->addApp($app);
607 }
608 }
609 }
611 /* Add application with post */
612 if((isset($_GET['act']))&&($_GET['act']=="add")){
613 $this->used_apps[$_GET['id']]= $_GET['id'];
614 asort($this->used_apps);
615 $this->addApp($_GET['id']);
616 }
618 /* Cancel edit options? */
619 if (isset($_POST['edit_options_cancel'])){
620 $this->dialog= FALSE;
621 }
623 /* Finish edit options? */
624 if (isset($_POST['edit_options_finish'])){
625 $this->dialog= FALSE;
627 /* Save informations passed by the user */
628 $this->option_value= array();
629 for ($i= 0; $i<count($this->option_name); $i++){
630 $this->appoption[$this->option_name[$i]]= $_POST["value$i"];
631 $this->is_modified= TRUE;
632 }
633 }
635 /* Prepare templating stuff */
636 $smarty= get_smarty();
637 $smarty->assign("used_apps", $this->used_apps);
638 $apps= array();
639 foreach ($this->apps as $key => $value){
640 if (!array_key_exists($key, $this->used_apps)){
641 $apps["$key"]= "$value";
642 }
643 }
646 /* Create application list */
647 $div = new DivSelectBox("appgroup");
648 $div->SetHeight(300);
649 $departments = array();
650 $res = get_list("(objectClass=gosaDepartment)", "application", $this->curbase,array("description","cn","ou"),GL_SIZELIMIT);
651 foreach($res as $value){
652 $fdn = $value['dn'];
653 $fdn = preg_replace("/".normalizePreg($this->curbase)."/","",$fdn);
654 $fdn= @LDAP::fix($fdn);
655 if($value["description"][0]!=".."){
656 $departments[$value['dn']]= convert_department_dn($fdn)." - [".$value["description"][0]."]";
657 }else{
658 $departments[$value['dn']]=convert_department_dn($fdn);
659 }
660 }
662 /* Create 'open' and 'add' links */
663 if($this->acl_is_writeable("gosaMemberApplication",$this->no_release_acls)){
664 $linkadd = "<a href='?plug=".$_GET['plug']."&act=add&id=%s'>%s</a>";
665 }else{
666 $linkadd = "%s";
667 }
668 $linkopen = "<a href='?plug=".$_GET['plug']."&act=depopen&depid=%s'>%s</a>";
670 /* Create base back entry */
671 $base_back = preg_replace("/^[^,]+,/","",$this->curbase);
672 if((strlen($base_back)>= strlen($this->config->current['BASE']))&&($this->curbase!=$this->config->current['BASE'])){
673 $div->AddEntry(array(
674 array("string"=>sprintf($linkopen,base64_encode($base_back),".. ["._("back")."]"),
675 "attach"=>"style='border:0px;'")
676 ));
677 }
679 /* Append departments for current base */
680 foreach($departments as $key => $app){
681 $div->AddEntry(array(
682 array("string"=>"<img class='center' src='images/folder.png' alt='"._("department")."'> ".sprintf($linkopen,base64_encode($key),$app),
683 "attach"=>"style='border:0px;'")
684 ));
685 }
687 /* Add applications found on this base */
688 foreach($apps as $key => $app){
689 $div->AddEntry(array(
690 array("string"=>sprintf("<input class='center' type='checkbox' value='1' name='AddApp_%s'>",$key).
691 "<img class='center' src='images/select_application.png' alt='"._("application")."'> ".sprintf($linkadd,$key,$app),
692 "attach"=>"style='border:0px;'")
693 ));
694 }
696 /* Create list of used/assigned applications */
697 $div2 = new DivSelectBox("appgroup");
698 $div2->SetHeight(300);
700 /* Check acls to create "edit/remove" category links */
701 if(!$this->acl_is_writeable("gosaMemberApplication",$this->no_release_acls)){
702 $linkopen = "<img class='center' src='images/folder.png' alt=\"\"> <a href='?plug=".$_GET['plug']."&act=open&id=%s'>%s</a>";
703 $catremove = " <img src='images/empty.png' alt=' '>";
704 $catupdown = "";
705 }else{
706 $linkopen = "<img class='center' src='images/folder.png' alt=\"\"> <a href='?plug=".$_GET['plug']."&act=open&id=%s'>%s</a>";
707 $catremove = " <input type='image' src='images/edittrash.png' title='"._("Delete entry")."' name='DelCat_%s' value='%s'>";
708 $catupdown = "<a href='?plug=".$_GET['plug']."&act=cat_up&id=%s'>".
709 "<img align='top' alt=\"\" src='images/sort_up.png' border=0 title='"._("Move up")."'>".
710 "</a> ".
711 "<a href='?plug=".$_GET['plug']."&act=cat_down&id=%s'>".
712 "<img alt=\"\" src='images/sort_down.png' title='"._("Move down")."' border=0>".
713 "</a>";
714 }
716 /* Add back category for current category */
717 if(empty($this->curCatDir)){
718 $cnt =0;
719 }else{
720 $cnt = count(split("/",$this->curCatDir));
721 $tmp = split("/",$this->curCatDir);
722 $bbk = "";
723 for($i = 0 ; $i < ($cnt -1 ) ; $i++){
724 $bbk .= $tmp[$i];
725 }
726 $div2 ->AddEntry(array(array("string"=>sprintf($linkopen,base64_encode($bbk),"..")),array("string"=>" ","attach"=>"style='border-right:0px;'")));
727 }
729 /* Add sub categories */
730 $this->GetSubdirs($this->curCatDir);
731 foreach($this->GetSubdirs($this->curCatDir) as $path => $name){
732 $div2 ->AddEntry(array(
733 array("string"=>sprintf($linkopen,base64_encode($path),$name)),
734 array("string"=>preg_replace("/%s/",base64_encode($path),$catupdown.$catremove),
735 "attach"=>"align='right' style='width:80px;border-right:0px;'")));
736 }
738 /* Create priority & seperator links */
739 $separator ="<hr size=1>";
740 if($this->acl_is_writeable("gosaMemberApplication",$this->no_release_acls)){
741 $sep = "<input type='image' src='images/back.png' title='"._("Insert seperator")."' value='%s' name='AddSep_%s'>";
742 $upudown = "<a href='?plug=".$_GET['plug']."&act=one_up&id=%s'>".
743 " <img alt='{t}sort{/t}' align='top' src='images/sort_up.png' title='"._("Move up")."' border=0>".
744 "</a> ".
745 "<a href='?plug=".$_GET['plug']."&act=one_down&id=%s'>".
746 " <img alt='{t}sort{/t}' src='images/sort_down.png' title='"._("Move down")."' border=0>".
747 "</a> ".
748 "<input type='image' src='images/edittrash.png' title='"._("Delete entry")."' name='DelApp_%s' value='%s' alt='{t}delete{/t}' >";
749 }else{
750 $sep = "";
751 $upudown = "";
752 }
754 /* Create edit link */
755 if($this->acl_is_writeable("gosaApplicationParameter",$this->no_release_acls)){
756 $edit= " <input type='image' src='images/edit.png' title='"._("Edit entry")."' name='EdiApp_%s' value='%s' alt='{t}edit{/t}' >";
757 }else{
758 $edit= "";
759 }
761 /* Get differences to mark those entries that have changed from last edit. */
762 $Differences = $this->diffAppsInReleases();
764 /* Walk through entries an append them to list */
765 if(isset($this->gosaMemberApplication[$this->curCatDir])){
766 foreach($this->gosaMemberApplication[$this->curCatDir] as $cat => $entry){
768 /* Add seperator */
769 if(preg_match("/__SEPARATOR__/",$entry['App'])){
770 $div2 ->AddEntry(array(array("string"=>$separator),
771 array("string"=>preg_replace("/\%s/",htmlentities($entry['App']),$upudown),"attach"=>"align='right' style='border-right:0px;'")));
772 }else{
774 /* Add application */
776 $image = "";
777 /* Check if application was available within selected release
778 * or application list if release management is not active
779 */
780 if(!in_array($entry['App'],$this->AllAppsForRelease)){
782 /* release managent is active
783 */
784 if(!$this->enableReleaseManagement){
785 $image = "<img class='center' alt='R' src='images/select_invalid_application.png'
786 title='"._("This application is no longer available.")."'> ";
787 }else{
788 $image = "<img class='center' alt='F' src='images/select_invalid_application.png'
789 title=\"".sprintf(_("This application is not available in any release named %s."),$this->FAIrelease)."\"> ";
790 }
792 }elseif(isset($Differences[$entry['App']]) && ($Differences[$entry['App']] == true)) {
793 $entry['App'].=" <i>["._("Check parameter")."]</i>";
794 $image = "<img class='center' src='images/select_invalid_application.png'
795 title='"._("This application has changed parameters.")."'> ";
796 }else{
797 $image = "<img class='center' src='images/select_application.png' alt=\"\"> ";
798 }
800 $div2->AddEntry(array(array("string"=>sprintf($image."%s",$entry['App'])),
801 array("string"=>preg_replace("/\%s/",htmlentities($entry['App']),$sep.$edit.$upudown),
802 "attach"=>"align='right' style='width:100px;border-right:0px;'")));
803 }
804 }
805 }
807 /* Assign created div lists to template */
808 $smarty->assign("UsedApps", $div2->DrawList());
809 $smarty->assign("List", $div->DrawList());
810 $smarty->assign("apps", $apps);
812 $smarty->assign("enableReleaseManagement",$this->enableReleaseManagement);
814 $smarty->assign("ReleaseSelectAble", false);
815 $smarty->assign("Release", $this->FAIrelease);
817 if($this->enableReleaseManagement){
818 $smarty->assign("FAIrelease", $this->FAIrelease);
819 $smarty->assign("Releases", $this->Releases);
821 if(!$this->no_release_acls && count($this->Releases)){
822 $smarty->assign("ReleaseSelectAble", true);
823 }
824 }
826 /* Set acls to template */
827 $tmp = $this->plInfo();
828 foreach($tmp['plProvidedAcls'] as $acl => $translation){
829 $smarty->assign($acl."ACL",$this->getacl($acl,$this->no_release_acls));
830 }
832 /* Show main page */
833 if ($this->dialog){
834 $smarty->assign("table", $this->table);
835 $display.= $smarty->fetch (get_template_path('application_options.tpl', TRUE));
836 } else {
837 $display.= $smarty->fetch (get_template_path('application.tpl', TRUE));
838 }
840 return ($display);
841 }
844 function getReleases()
845 {
846 /* Only display those releases that we are able to read */
847 $dn = $this->config->current['BASE'];
848 $filter = "(&(objectClass=organizationalUnit)(objectClass=FAIbranch))";
849 $res = get_list($filter,"application", $dn, array("ou"), GL_SUBSEARCH);
851 $ret =array();
852 foreach($res as $attrs){
853 if(preg_match("/ou=apps,/",$attrs['dn'])){
854 $bb = preg_replace("/ou=apps,.*/","",$attrs['dn']);
855 $parts = array_reverse(split("ou=",$bb));
857 $str ="";
858 foreach($parts as $part){
859 if(empty($part)) {
860 continue;
861 }
862 $str .= str_replace(",","",$part)."/";
863 }
864 $name = preg_replace("/\/$/","",$str);
865 if(empty($name)) {
866 $name ="/";
867 }
868 $ret[$attrs['dn']] = $name;
869 }
870 }
871 return($ret);
872 }
874 function save_object()
875 {
877 /* Move category one position up or down */
878 if((isset($_GET['act']))&&(($_GET['act'] == "cat_up")||($_GET['act']=="cat_down"))){
879 if($_GET['act']=="cat_up"){
880 $this->catUp(base64_decode($_GET['id']));
881 }
882 if($_GET['act']=="cat_down"){
883 $this->catDown(base64_decode($_GET['id']));
884 }
885 }
887 /* Move application one position up or down */
888 if((isset($_GET['act']))&&(($_GET['act'] == "one_up")||($_GET['act']=="one_down"))){
889 if(isset($_GET['id'])){
890 $id = $_GET['id'];
891 $act = $_GET['act'];
893 if($act == "one_up"){
894 $this->getOneUp($id);
895 }elseif($act == "one_down") {
896 $this->getOneDown($id);
897 }
898 }
899 }
902 plugin::save_object();
903 }
906 function remove_from_parent()
907 {
908 plugin::remove_from_parent();
910 $ldap= $this->config->get_ldap_link();
911 $ldap->cd($this->dn);
912 $this->cleanup();
914 $ldap->modify ($this->attrs);
916 show_ldap_error($ldap->get_error(), sprintf(_("Removing of groups/applications with dn '%s' failed."),$this->dn));
918 /* Optionally execute a command after we're done */
919 $this->handle_post_events("remove");
920 }
923 /* Save to LDAP */
924 function save()
925 {
926 /* Skip saving application settings, if we do not have release acls */
927 if($this->no_release_acls){
928 gosa_log("Skip saving group application extension. Caused by insufficient acls");
929 return;
930 }
932 plugin::save();
936 /* Copy members */
937 $this->Categories[""]="";
938 $this->attrs["gosaMemberApplication"]= array();
939 $this->attrs["gosaApplicationParameter"]= array();
940 foreach($this->Categories as $name => $cats){
941 $i =0;
942 if(isset($this->gosaMemberApplication[$name])){
943 foreach($this->gosaMemberApplication[$name] as $entry){
944 if(!preg_match("/__SEPARATOR__/",$entry['App'])){
945 $this->attrs["gosaMemberApplication"][]= $entry['App']."|".$name."|".$i;
946 }
947 $i ++;
948 }
949 }
950 if(($i==0)&&(!empty($name))){
951 $this->attrs["gosaMemberApplication"][]= "|".$name."|".$i;
952 }
953 }
955 /* Are there application parameters to be saved */
956 $this->attrs['gosaApplicationParameter']= array();
957 foreach($this->appoption as $name => $value){
958 if ($value != ""){
959 $this->attrs['gosaApplicationParameter'][]= "$name:$value";
960 }
961 }
963 /* Write back to LDAP */
964 $ldap= $this->config->get_ldap_link();
965 $ldap->cd($this->dn);
966 $this->cleanup();
967 $ldap->modify ($this->attrs);
969 show_ldap_error($ldap->get_error(), sprintf(_("Saving of groups/applications with dn '%s' failed."),$this->dn));
971 /* Optionally execute a command after we're done */
972 if ($this->initially_was_account == $this->is_account){
973 if ($this->is_modified){
974 $this->handle_post_events("modify");
975 }
976 } else {
977 $this->handle_post_events("add");
978 }
980 }
982 function check()
983 {
984 /* Call common method to give check the hook */
985 $message= plugin::check();
987 return ($message);
988 }
991 function reload()
992 {
993 /* Generate applist */
994 $this->apps= array();
996 /* Special handling for release managed apps */
997 $tmp = search_config($this->config->data,"faiManagement","CLASS");
998 if(!empty($tmp) && count($this->Releases)){
999 $this->enableReleaseManagement = true;
1001 /* Check if release is available */
1002 $tmp = array_flip($this->Releases);
1003 if(isset($tmp[$this->FAIrelease])){
1004 $base = $tmp[$this->FAIrelease];
1005 }else{
1007 /* Release is not available, check if there is an alternative */
1008 $old_r = $this->FAIrelease;
1009 $k = key($tmp);
1011 if(isset($tmp[$k])){
1013 /* We have found an alternative release name */
1014 $r = $tmp[$k];
1015 $this->FAIrelease = $k;
1016 $base = $r;
1018 /* Display msg */
1019 if(!(!$this->initially_was_account && $old_r =="/")){
1020 print_red(sprintf(_("Can't resolve the release name '%s', setting release name to '%s'. Possibly the objects base has changed."),$old_r,$k));
1021 }
1022 }else{
1024 /* There are no releases available ... */
1025 print_red(_("There are no releases available. You will not be able to select another release."));
1026 return;
1027 }
1028 }
1030 /* Get applications for this release */
1031 $base = preg_replace("/ou=apps,.*$/","ou=apps,".$this->curbase,$base);
1032 $res = get_list("(objectClass=gosaApplication)","application",$base,array("*"));
1033 }else{
1035 /* Get applications for this base */
1036 $res = get_list("(objectClass=gosaApplication)","application","ou=apps,".$this->curbase,array("*"));
1037 }
1039 /* Append applications */
1040 foreach($res as $attrs){
1041 if (isset($attrs["description"][0])){
1042 $this->apps[$attrs["cn"][0]]=
1043 $attrs["cn"][0]." (".
1044 $attrs["description"][0].")";
1045 } else {
1046 $this->apps[$attrs["cn"][0]]=
1047 $attrs["cn"][0];
1048 }
1049 }
1051 /* Get all apps ... */
1052 $res = get_list("objectClass=gosaApplication","application",$this->config->current['BASE'],array("gosaApplicationParameter","cn"),GL_SUBSEARCH);
1053 $tmp = search_config($this->config->data,"faiManagement","CLASS");
1054 $this->AllAppsForRelease = array();
1055 if(!empty($tmp)){
1056 $tmp = array_flip($this->Releases);
1057 foreach($res as $attrs){
1059 $testdn = preg_replace("/ou=apps,.*$/","ou=apps",$attrs['dn']);
1060 $testdn = preg_replace("/^[^,]+/","",$testdn);
1061 $testdn = preg_replace("/^,/","",$testdn);
1063 if($testdn == preg_replace("/ou=apps,.*$/","ou=apps",$tmp[$this->FAIrelease])){
1064 $this->AllAppsForRelease[$attrs['dn']] = $attrs['cn'][0];
1065 $this->AllAppsForReleaseParameter[$this->FAIrelease][$attrs['cn'][0]] = $attrs;
1066 }
1067 }
1068 }else{
1069 foreach($res as $attrs){
1070 $this->AllAppsForRelease[$attrs['dn']] = $attrs['cn'][0];
1071 }
1072 }
1074 natcasesort ($this->apps);
1075 reset ($this->apps);
1077 if(is_array($this->gosaMemberApplication))
1078 foreach ($this->gosaMemberApplication as $cat){
1079 if(is_array($cat))
1080 foreach($cat as $entry){
1081 $this->used_apps[$entry['App']]= $entry['App'];
1082 }
1083 }
1084 }
1087 function addApp($cn)
1088 {
1089 if((isset($this->gosaMemberApplication[$this->curCatDir]))&&(is_array($this->gosaMemberApplication[$this->curCatDir]))){
1090 foreach($this->gosaMemberApplication[$this->curCatDir] as $entry){
1091 if($entry['App'] == $cn) return;
1092 }
1093 }
1094 $this->gosaMemberApplication[$this->curCatDir][]= array("App"=>$cn);
1095 $this->used_apps[$cn]=$cn;
1096 $this->is_modified= TRUE;
1097 }
1100 function removeApp($cn)
1101 {
1102 $temp= array();
1103 foreach ($this->gosaMemberApplication as $value){
1104 if ($value != $cn){
1105 $temp[]= $value;
1106 }
1107 }
1108 $this->gosaMemberApplication= $temp;
1109 $this->is_modified= TRUE;
1110 }
1112 function getParameters($app)
1113 {
1114 $tmp = $this->getReleases();
1115 $ret = array();
1116 if(in_array($this->FAIrelease,$tmp)){
1117 $tmp2 = array_flip($tmp);
1118 $base = $tmp2[$this->FAIrelease];
1119 $ldap = $this->config->get_ldap_link();
1120 $ldap->cd($this->config->current['BASE']);
1121 $ldap->search("(&(objectClass=gosaApplication)(cn=".$app.")(gosaApplicationParameter=*))",array("gosaApplicationParameter"));
1122 if($ldap->count()){
1123 $attrs = $ldap->fetch();
1124 for($i = 0 ; $i < $attrs['gosaApplicationParameter']['count'] ; $i ++ ){
1125 $name = preg_replace("/:.*$/","",$attrs['gosaApplicationParameter'][$i]);
1126 $ret[$name] = $name;
1127 }
1128 }
1129 }
1130 return($ret);
1131 }
1133 function GetSubdirs($dir)
1134 {
1135 $ret = array();
1136 $tmp1 = split("/",$this->curCatDir);
1138 foreach($this->Categories as $path=>$cat){
1139 $tmp2 = split("/",$path);
1141 if((empty($this->curCatDir))&&(!preg_match("/\//",$path))){
1142 $abort = false;
1143 }elseif(((count($tmp1))+1) == (count($tmp2))){
1144 $abort = false;
1145 for($i = 0 ; $i < count($tmp1) ; $i++){
1146 if($tmp1[$i] != $tmp2[$i]){
1147 $abort = true;
1148 }
1149 }
1150 }else{
1151 $abort= true;
1152 }
1153 if(!$abort){
1154 $ret[$path]=$cat;
1155 }
1156 }
1157 return($ret);
1158 }
1161 function PrepareForCopyPaste($source)
1162 {
1163 $this->FAIrelease = $this->InitialFAIrelease = $source->FAIrelease;
1164 $this->gosaMemberApplication = $source->gosaMemberApplication;
1165 $this->appoption = $source->appoption;
1166 }
1169 /* Return plugin informations for acl handling */
1170 function plInfo()
1171 {
1172 return (array(
1173 "plShortName" => _("Applications"),
1174 "plDescription" => _("Group applications"),
1175 "plSelfModify" => FALSE,
1176 "plDepends" => array(),
1177 "plPriority" => 0,
1178 "plSection" => array("admin"),
1179 "plCategory" => array("groups"),
1180 "plProvidedAcls"=> array(
1181 "gosaMemberApplication" => _("Application"),
1182 "FAIrelease" => _("Release"),
1183 "gosaApplicationParameter" => _("Application parameter"))
1184 ));
1185 }
1186 }
1187 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1188 ?>