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; //
25 var $Categories;
27 /* attribute list for save action */
28 var $attributes = array("gosaMemberApplication","gosaApplicationParameter");
29 var $objectclasses = array("gosaApplicationGroup");
31 var $FAIrelease = "/";
32 var $InitialFAIrelease = "/";
33 var $Releases = array();
34 var $enableReleaseManagement = false;
36 var $AllAppsForRelease = array();
37 var $AllAppsForReleaseParameter = array();
38 var $view_logged = FALSE;
39 var $CopyPasteVars = array("Categories");
40 var $gosaApplicationParameter ;
41 var $ui = NULL;
42 var $no_release_acls = false;
44 function appgroup (&$config, $dn= NULL, $parent= NULL)
45 {
47 /* Check if we have relase mangement enabled and prepare group application for release management */
48 $tmp = $config->search("faiManagement", "CLASS",array('menu','tabs'));
49 if(!empty($tmp)){
50 $this->enableReleaseManagement = true;
51 $this->objectclasses [] = "FAIreleaseTag";
52 $this->attributes [] = "FAIrelease";
53 }
55 plugin::plugin ($config, $dn, $parent);
57 /* set userinfo object */
58 $this->ui = get_userinfo();
60 /* Compatibility check
61 In some case of old applikations with old release tag saving,
62 we must reassign is_account state.
63 (Or if release management wasn't activated before creating this app) */
64 if($this->enableReleaseManagement){
66 /* Release management is activated && this is a valid group app account,
67 but no release class was found, so activate is_account flag */
68 if(isset($this->attrs['objectClass'])){
69 if($dn != "new" && ( in_array("gosaApplicationGroup",$this->attrs['objectClass'])) &&
70 (!in_array("FAIreleaseTag",$this->attrs['objectClass']))){
71 $this->is_account =true;
72 }
73 }
74 }
76 /* Load member applications */
77 if (isset ($this->attrs["gosaMemberApplication"][0])){
78 $this->gosaMemberApplication = array();
79 for ($i= 0; $i<$this->attrs["gosaMemberApplication"]["count"]; $i++){
80 $this->gosaMemberApplication[]=
81 $this->attrs["gosaMemberApplication"][$i];
82 }
83 }
85 /* Load application options */
86 if (isset($this->attrs['gosaApplicationParameter'])){
87 for ($i= 0; $i<$this->attrs['gosaApplicationParameter']['count']; $i++){
88 $option= preg_replace('/^[^:]+:/', '',
89 $this->attrs['gosaApplicationParameter'][$i]);
90 $name= preg_replace('/:.*$/', '',
91 $this->attrs['gosaApplicationParameter'][$i]);
92 $this->appoption[$name]= $option;
93 }
94 }
96 /* Parse MemberApplication*/
97 $tmp = array();
98 $tmp2 = array();
99 $prios = array();
100 $cats = array();
102 foreach($this->gosaMemberApplication as $memberApp){
103 if(preg_match("/\|/i",$memberApp)){
105 $tmp = split("\|",$memberApp);
107 if(!empty($tmp[0])){
108 $tmp2[$tmp[1]][$tmp[2]] = array("App"=>$tmp[0]);
109 }
110 if(!empty($tmp[1])){
111 $n = split("/",$tmp[1]);
112 $c = count($n);
113 $cats [$tmp[1]] = $n[$c-1];
114 }
115 $prios[$tmp[1]][$tmp[2]] = $tmp[2];
116 }else{
117 $tmp2[]['App'] = $memberApp;
118 }
119 }
121 /* Assign collected category and application settings */
122 $this->Categories = $cats;
123 $this->gosaMemberApplication = $tmp2;
125 /* Sort application by category */
126 $cats[""]="";
127 foreach($cats as $cat ){
128 if((isset($prios[$cat]))&&(count($prios[$cat]))){
129 $max = max($prios[$cat]);
130 $min = 1;//min($prios[$cat]);
131 $last = false;
132 for($i = $min ; $i < $max ; $i++){
133 if(!isset($prios[$cat][$i])){
134 if($last == false){
135 $this->gosaMemberApplication[$cat][$i]['App'] = "__SEPARATOR__".$i;
137 $last = true;
138 }
139 }else{
140 $last = false;
141 }
142 }
143 }
144 }
146 /* Sort application by priority */
147 $tmp = array();
148 foreach($this->gosaMemberApplication as $key => $entries){
149 ksort ($entries);
150 foreach($entries as $entry){
151 $tmp[$key][]= $entry;
152 }
153 }
154 $this->gosaMemberApplication = $tmp;
155 $this->curbase = $this->config->current['BASE'];
157 /* Get required release informations */
158 if($this->enableReleaseManagement){
159 $this->InitialFAIrelease = $this->FAIrelease;
160 $this->Releases = $this->getReleases();
161 }
163 }
166 /* Combine new array */
167 function combineArrays($ar0,$ar1,$ar2)
168 {
169 $ret = array();
170 if(is_array($ar0))
171 foreach($ar0 as $ar => $a){
172 $ret[$ar]=$a;
173 }
174 if(is_array($ar1))
175 foreach($ar1 as $ar => $a){
176 $ret[$ar]=$a;
177 }
178 if(is_array($ar2))
179 foreach($ar2 as $ar => $a){
180 $ret[$ar]=$a;
181 }
182 return($ret);
183 }
185 /* Returns element position within given array */
186 function getpos($atr,$attrs)
187 {
188 $i = 0;
189 foreach($attrs as $attr => $name) {
190 $i++;
191 if($attr == $atr){
192 return($i);
193 }
194 }
195 return(-1);
196 }
199 /* Check current combination of application && release
200 Are all application available?, application parameter changed? ... */
201 function diffAppsInReleases()
202 {
203 /* Only diff if it is required */
204 $ret =array();
206 /* If current release has changed */
207 if($this->FAIrelease != $this->InitialFAIrelease){
209 /* Walk through all apps which are currently displayed */
210 if(isset($this->gosaMemberApplication[$this->curCatDir])){
212 foreach($this->gosaMemberApplication[$this->curCatDir] as $entry){
214 /* If application is also available in new release, check if parameter differs */
215 if(in_array($entry['App'],$this->AllAppsForRelease)){
217 $old = array(); // Old application parameter
218 $new = array(); // New parameters
220 /* There are possibly no parameters specified */
221 if(isset($this->AllAppsForReleaseParameter[$this->InitialFAIrelease][$entry['App']])){
222 $old = $this->AllAppsForReleaseParameter[$this->InitialFAIrelease][$entry['App']];
223 }
225 if(isset($this->AllAppsForReleaseParameter[$this->FAIrelease][$entry['App']])){
226 $new = $this->AllAppsForReleaseParameter[$this->FAIrelease][$entry['App']];
227 }
229 /* Both (old & new) have no gosaApplicationParameter
230 */
231 if((!isset($old['gosaApplicationParameter'])) && (!isset($new['gosaApplicationParameter']))){
232 $ret[$entry['App']] = false;
234 /* Both got gosaApplicationParameter */
235 }elseif((isset($old['gosaApplicationParameter'])) && (isset($new['gosaApplicationParameter']))){
236 if(array_differs($old['gosaApplicationParameter'],$new['gosaApplicationParameter'])){
237 $ret[$entry['App']] = true;
238 }else{
239 $ret[$entry['App']] = false;
240 }
241 }
242 /* Initially had gosaApplicationParameter bot in new release not */
243 }elseif((isset($old['gosaApplicationParameter'])) && (!isset($new['gosaApplicationParameter']))){
244 $ret[$entry['App']] = true;
246 /* Old release had no gosaApplicationParameter but new got some */
247 }elseif((!isset($old['gosaApplicationParameter'])) && (isset($new['gosaApplicationParameter']))){
248 $ret[$entry['App']] = true;
249 }
250 }
251 }
252 }
253 return($ret);
254 }
256 /* TRansports the geiven Arraykey one position up*/
257 function ArrayUp($atr,$attrs)
258 {
259 $ret = $attrs;
260 $pos = $this->getpos($atr,$attrs) ;
261 $cn = count($attrs);
262 if(!(($pos == -1)||($pos == 1))){
263 $before = array_slice($attrs,0,($pos-2));
264 $mitte = array_reverse(array_slice($attrs,($pos-2),2));
265 $unten = array_slice($attrs,$pos);
266 $ret = array();
267 $ret = $this->combineArrays($before,$mitte,$unten);
268 }
269 return($ret);
270 }
273 /* TRansports the geiven Arraykey one position up*/
274 function ArrayDown($atr,$attrs)
275 {
276 $ret = $attrs;
277 $pos = $this->getpos($atr,$attrs) ;
278 $cn = count($attrs);
279 if(!(($pos == -1)||($pos == $cn))){
280 $before = array_slice($attrs,0,($pos-1));
281 $mitte = array_reverse(array_slice($attrs,($pos-1),2));
282 $unten = array_slice($attrs,($pos+1));
283 $ret = array();
284 $ret = $this->combineArrays($before,$mitte,$unten);
285 }
286 return($ret);
287 }
290 /* Sort category on position up */
291 function catUp($id)
292 {
293 /* Get all cats depinding on current dir */
294 $cats = $this->GetSubdirs($this->curCatDir);
295 $newcats =$this->ArrayUp($id,$cats);
296 foreach($newcats as $cat => $name){
297 unset($this->Categories[$cat]);
298 }
299 foreach($newcats as $cat => $name){
300 $this->Categories[$cat]=$name;
301 }
302 }
305 /* Sort category on position down */
306 function catDown($id)
307 {
308 /* Get all cats depinding on current dir */
309 $cats = $this->GetSubdirs($this->curCatDir);
310 $newcats =$this->ArrayDown($id,$cats);
311 foreach($newcats as $cat => $name){
312 unset($this->Categories[$cat]);
313 }
314 foreach($newcats as $cat => $name){
315 $this->Categories[$cat]=$name;
316 }
317 }
320 /* Increase application priority */
321 function getOneUp($appl)
322 {
323 $cat = $this->curCatDir;
324 $apps = $this->gosaMemberApplication[$cat];
325 $appsA = array();
326 foreach ($apps as $appkey => $name){
327 $appsA[$name['App']] =$name['App'];
328 }
329 $result = $this->ArrayUp($appl,$appsA);
330 $ret = array();
331 foreach($result as $app){
332 $ret[]=array("App"=>$app);
333 }
334 $this->gosaMemberApplication[$cat] = $ret;
335 }
338 /* Decrease application priority */
339 function getOneDown($appl)
340 {
341 $cat = $this->curCatDir;
342 $apps = $this->gosaMemberApplication[$cat];
343 $appsA = array();
344 foreach ($apps as $appkey => $name){
345 $appsA[$name['App']] =$name['App'];
346 }
347 $result = $this->ArrayDown($appl,$appsA);
348 $ret = array();
349 foreach($result as $app){
350 $ret[]=array("App"=>$app);
351 }
352 $this->gosaMemberApplication[$cat] = $ret;
353 }
356 /* Add seperator to application list */
357 function AddSeperator($id)
358 {
359 $found = false;
360 $cat = "";
361 $tmp = array();
362 foreach($this->gosaMemberApplication[$this->curCatDir] as $appID => $app){
363 $tmp[] = $app;
364 if(($app['App'] == $id)&&(!$found)){
365 $cnt = count($this->gosaMemberApplication[$this->curCatDir]);
366 $tmp[] = array("App" => "__SEPARATOR__".($cnt+1));
367 $found = true;
368 }
369 }
370 if($found){
371 $this->gosaMemberApplication[$this->curCatDir]=$tmp;
372 }
373 }
376 /* Check if application acls are readable */
377 function check_acls()
378 {
379 return(count($this->ui->get_module_departments("application")));
380 }
383 function execute()
384 {
385 /* Call parent execute */
386 plugin::execute();
388 /* Log view */
389 if($this->is_account && !$this->view_logged){
390 $this->view_logged = TRUE;
391 new log("view","groups/".get_class($this),$this->dn);
392 }
394 /* Check if department was selected */
395 if((isset($_GET['act']))&&($_GET['act']=="depopen")){
396 $dep = base64_decode($_GET['depid']);
397 $this->curbase =$dep;
398 }
400 /* Check if category was selected */
401 if((isset($_GET['act']))&&($_GET['act']=="open") && (empty($_GET['id']) || isset($this->Categories[base64_decode($_GET['id'])]))){
402 $this->curCatDir = base64_decode($_GET['id']);
403 }
405 /* Do we need to flip is_account state? */
406 if(isset($_POST['modify_state'])){
407 if($this->is_account && $this->acl_is_removeable()){
408 $this->is_account= FALSE;
409 }elseif(!$this->is_account && $this->acl_is_createable()){
410 $this->is_account= TRUE;
411 }
412 }
414 /* Do we represent a valid group? */
415 if (!$this->is_account && $this->parent === NULL){
416 $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\"> <b>".
417 _("This 'dn' is no appgroup.")."</b>";
418 return ($display);
419 }
421 /* Show tab dialog headers */
422 $display= "";
423 if ($this->parent !== NULL){
424 if ($this->is_account){
425 $display= $this->show_disable_header(_("Remove applications"),
426 _("This group has application features enabled. You can disable them by clicking below."));
427 } else {
428 $display.= $this->show_enable_header(_("Create applications"),
429 _("This group has application features disabled. You can enable them by clicking below."));
430 return ($display);
431 }
432 }
434 /* Check acl, applications must be readable */
435 if(!$this->check_acls()){
436 $display .= "<img src='images/button_cancel.png' alt='"._("ACL")."' class='center'>
437 <b>"._("Insufficient permissions")."</b>
438 <p>".
439 _("You do not have permission to query application entries. All your changes will not be saved.").
440 "</p><p class='seperator'> </p>";
441 $this->no_release_acls = true;
442 }
445 /* Add Categorie */
446 if((isset($_POST['AddCat']))&&(isset($_POST['CatName']))&&(!empty($_POST['CatName']))){
448 /* Only allow adding a category, if it is allowed */
449 if($this->acl_is_writeable("gosaMemberApplication",$this->no_release_acls)){
451 if(preg_match("/[\\\\\/]/i",$_POST['CatName'])){
452 print_red(_("Invalid character in category name."));
453 }elseif(!in_array($_POST['CatName'],$this->Categories)){
454 if(empty($this->curCatDir)){
455 $this->Categories[$_POST['CatName']]=$_POST['CatName'];
456 }else{
457 $this->Categories[$this->curCatDir."/".$_POST['CatName']]=$_POST['CatName'];
458 }
459 }else{
460 print_red(_("The specified category already exists."));
461 }
462 }
463 }
466 $this->reload();
467 $this->diffAppsInReleases();
469 /* Check POST variables for commands
470 to add/remove some applications */
471 $only_once = false;
472 if($this->acl_is_writeable("gosaMemberApplication",$this->no_release_acls)){
474 /* Walk through posts */
475 foreach($_POST as $name => $value){
477 /* Add a seperator to current category */
478 if((preg_match("/AddSep_/",$name))&&(!$only_once)){
479 $only_once = true;
480 $n = preg_replace("/AddSep_/","",$name);
481 $val= preg_replace("/_.*$/","",$n);
482 $this->AddSeperator($val);
483 }
485 /* Delete application | seperator entry */
486 if((preg_match("/DelApp_/",$name))&&(!$only_once)){
487 $only_once = true;
489 if(preg_match("/DelApp___SEPARATOR__/",$name)) {
490 $n= preg_replace("/DelApp___SEPARATOR__/","",$name);
491 $val= "__SEPARATOR__".preg_replace("/_.*$/","",$n);
492 }else{
493 $n = preg_replace("/DelApp_/","",$name);
494 $val= preg_replace("/_.*$/","",$n);
495 }
497 foreach($this->gosaMemberApplication as $key => $cat){
498 foreach($cat as $key2 => $app){
499 if($app['App'] == $val){
500 unset($this->gosaMemberApplication[$key][$key2]);
501 if(isset($this->used_apps[$val])){
502 foreach($this->getParameters($val) as $para){
503 if(isset($this->appoption[$para])){
504 unset($this->appoption[$para]);
505 }
506 }
507 unset($this->used_apps[$val]);
508 }
509 }
510 }
511 }
512 }
514 if(preg_match("/DelCat_/",$name) && !$only_once){
515 $only_once =TRUE;
516 $cat = preg_replace("/DelCat_/","",$name);
517 $cat = trim(base64_decode( preg_replace("/_.*$/","",$cat)));
519 $free_apps = array();
521 if(isset($this->gosaMemberApplication[$cat]) && is_array($this->gosaMemberApplication[$cat])){
522 foreach($this->gosaMemberApplication[$cat] as $app){
523 $free_apps[] = $app['App'];
524 }
525 unset($this->gosaMemberApplication[$cat]);
526 unset($this->Categories[$cat]);
527 }
528 foreach($this->Categories as $key => $name){
529 if(preg_match("/^".normalizePreg($cat)."\/.*/",$key)){
530 foreach($this->gosaMemberApplication[$key] as $app){
531 $free_apps[] = $app['App'];
532 }
533 unset($this->gosaMemberApplication[$key]);
534 unset($this->Categories[$key]);
535 }
536 }
537 foreach($free_apps as $app){
538 if(isset($this->used_apps[$app])){
539 unset($this->used_apps[$app]);
540 }
541 }
542 }
544 /* Edit application parameter */
545 if((preg_match("/EdiApp_/",$name))&&(!$only_once)){
547 $only_once = true;
548 $appname = $value;
549 $appname = preg_replace("/EdiApp_/","",$name);
550 $appname = preg_replace("/_.*$/","",$appname);
552 /* We've got the appname, get parameters from ldap */
553 $ldap= $this->config->get_ldap_link();
555 /* Check if we have release management enabled */
556 $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs'));
557 if(!empty($tmp)){
559 /* Get application parameter from ldap */
560 $tmp = array_flip($this->Releases);
561 $base = $tmp[$this->FAIrelease];
562 $ldap->cd($base);
563 $ldap->search("(&(objectClass=gosaApplication)(cn=$appname))",array("gosaApplicationParameter"));
564 $found = "";
565 while($attrs = $ldap->fetch()) {
566 if(preg_match("/cn=".$appname.",".$base."/",$attrs['dn'])){
567 $found = $attrs['dn'];
568 }
569 }
570 $ldap->cat($found, array("gosaApplicationParameter"));
571 }else{
573 /* Get application parameter from ldap */
574 $ldap->cd($this->config->current['BASE']);
575 $ldap->search("(&(objectClass=gosaApplication)(cn=$appname))",array("gosaApplicationParameter"));
576 }
578 /* Check if this application is unique */
579 if ($ldap->count() != 1){
580 print_red (_("The selected application name is not uniq. Please check your LDAP."));
581 } else {
583 /* Get parameter */
584 $attrs= $ldap->fetch();
585 if(isset($attrs['gosaApplicationParameter'])){
586 $this->dialog= TRUE;
588 /* Fill name and value arrays */
589 for ($i= 0; $i<$attrs['gosaApplicationParameter']['count']; $i++){
590 $option= preg_replace('/^[^:]+:/', '',
591 $attrs['gosaApplicationParameter'][$i]);
592 $name= preg_replace('/:.*$/', '',
593 $attrs['gosaApplicationParameter'][$i]);
594 $this->option_name[$i]= $name;
596 /* Fill with values from application, default should be
597 loaded by the external scripts */
598 if (isset($this->appoption[$name])){
599 $this->option_value[$i]= $this->appoption[$name];
600 }
601 }
603 /* Create edit field */
604 $table= "<table summary=\"\">";
605 for ($i= 0; $i < count($this->option_name); $i++){
606 if (isset($this->option_value[$i])){
607 $value= $this->option_value[$i];
608 } else {
609 $value= "";
610 }
611 $table.="<tr><td>".$this->option_name[$i]."</td><td>".
612 "<input name=\"value$i\" size=60 maxlength=250 ".
613 "value=\"".$value."\"><br></td></tr>";
614 }
615 $table.= "</table>";
616 $this->table= $table;
617 } else {
618 print_red (_("The selected application has no options."));
619 }
620 }
621 }
622 }
623 }
625 /* Add multiple */
626 if(isset($_POST['AddApps'])){
627 foreach($_POST as $name => $value){
628 if(preg_match("/AddApp_/",$name)){
629 $app = preg_replace("/AddApp_/","",$name);
630 $this->addApp($app);
631 }
632 }
633 }
635 /* Add application with post */
636 if((isset($_GET['act']))&&($_GET['act']=="add")){
637 $this->used_apps[$_GET['id']]= $_GET['id'];
638 asort($this->used_apps);
639 $this->addApp($_GET['id']);
640 }
642 /* Cancel edit options? */
643 if (isset($_POST['edit_options_cancel'])){
644 $this->dialog= FALSE;
645 }
647 /* Finish edit options? */
648 if (isset($_POST['edit_options_finish'])){
649 $this->dialog= FALSE;
651 /* Save informations passed by the user */
652 $this->option_value= array();
653 for ($i= 0; $i<count($this->option_name); $i++){
654 $this->appoption[$this->option_name[$i]]= $_POST["value$i"];
655 $this->is_modified= TRUE;
656 }
657 }
659 /* Prepare templating stuff */
660 $smarty= get_smarty();
661 $smarty->assign("used_apps", $this->used_apps);
662 $apps= array();
663 foreach ($this->apps as $key => $value){
664 if (!array_key_exists($key, $this->used_apps)){
665 $apps["$key"]= "$value";
666 }
667 }
670 /* Create application list */
671 $div = new divSelectBox("appgroup");
672 $div->SetHeight(300);
673 $departments = array();
674 $res = get_list("(objectClass=gosaDepartment)", "application", $this->curbase,array("description","cn","ou"),GL_SIZELIMIT);
675 foreach($res as $value){
676 $fdn = $value['dn'];
677 $fdn = preg_replace("/".normalizePreg($this->curbase)."/","",$fdn);
678 $fdn= @LDAP::fix($fdn);
679 if($value["description"][0]!=".."){
680 $departments[$value['dn']]= convert_department_dn($fdn)." - [".$value["description"][0]."]";
681 }else{
682 $departments[$value['dn']]=convert_department_dn($fdn)." ["._("Back")."]";
683 }
684 }
686 /* Create 'open' and 'add' links */
687 if($this->acl_is_writeable("gosaMemberApplication",$this->no_release_acls)){
688 $linkadd = "<a href='?plug=".$_GET['plug']."&act=add&id=%s'>%s</a>";
689 }else{
690 $linkadd = "%s";
691 }
692 $linkopen = "<a href='?plug=".$_GET['plug']."&act=depopen&depid=%s'>%s</a>";
694 /* Create base back entry */
695 $base_back = preg_replace("/^[^,]+,/","",$this->curbase);
696 if((strlen($base_back)>= strlen($this->config->current['BASE']))&&($this->curbase!=$this->config->current['BASE'])){
697 $div->AddEntry(array(
698 array("string"=>sprintf($linkopen,base64_encode($base_back),".. ["._("back")."]"),
699 "attach"=>"style='border:0px;'")
700 ));
701 }
703 /* Append departments for current base */
704 foreach($departments as $key => $app){
705 $div->AddEntry(array(
706 array("string"=>"<img class='center' src='images/folder.png' alt='"._("department")."'> ".sprintf($linkopen,base64_encode($key),$app),
707 "attach"=>"style='border:0px;'")
708 ));
709 }
711 /* Add applications found on this base */
712 foreach($apps as $key => $app){
713 $div->AddEntry(array(
714 array("string"=>sprintf("<input class='center' type='checkbox' value='1' name='AddApp_%s'>",$key).
715 "<img class='center' src='images/select_application.png' alt='"._("application")."'> ".sprintf($linkadd,$key,$app),
716 "attach"=>"style='border:0px;'")
717 ));
718 }
720 /* Create list of used/assigned applications */
721 $div2 = new divSelectBox("appgroup");
722 $div2->SetHeight(300);
724 /* Check acls to create "edit/remove" category links */
725 if(!$this->acl_is_writeable("gosaMemberApplication",$this->no_release_acls)){
726 $linkopen = "<img class='center' src='images/folder.png' alt=\"\"> <a href='?plug=".$_GET['plug']."&act=open&id=%s'>%s</a>";
727 $catremove = " <img src='images/empty.png' alt=' '>";
728 $catupdown = "";
729 }else{
730 $linkopen = "<img class='center' src='images/folder.png' alt=\"\"> <a href='?plug=".$_GET['plug']."&act=open&id=%s'>%s</a>";
731 $catremove = " <input type='image' src='images/edittrash.png' title='"._("Delete entry")."' name='DelCat_%s' value='%s'>";
732 $catupdown = "<a href='?plug=".$_GET['plug']."&act=cat_up&id=%s'>".
733 "<img align='top' alt=\"\" src='images/sort_up.png' border=0 title='"._("Move up")."'>".
734 "</a> ".
735 "<a href='?plug=".$_GET['plug']."&act=cat_down&id=%s'>".
736 "<img alt=\"\" src='images/sort_down.png' title='"._("Move down")."' border=0>".
737 "</a>";
738 }
740 /* Add back category for current category */
741 if(empty($this->curCatDir)){
742 $cnt =0;
743 }else{
744 $cnt = count(split("/",$this->curCatDir));
745 $tmp = split("/",$this->curCatDir);
746 $bbk = "";
747 for($i = 0 ; $i < ($cnt -1 ) ; $i++){
748 $bbk .= $tmp[$i]."/";
749 }
750 $bbk = preg_replace("/\/$/","",$bbk);
751 $div2 ->AddEntry(array(array("string"=>sprintf($linkopen,base64_encode($bbk),".. ["._("Back")."]")),array("string"=>" ","attach"=>"style='border-right:0px;'")));
752 }
754 /* Add sub categories */
755 $this->GetSubdirs($this->curCatDir);
756 foreach($this->GetSubdirs($this->curCatDir) as $path => $name){
757 $div2 ->AddEntry(array(
758 array("string"=>sprintf($linkopen,base64_encode($path),$name)),
759 array("string"=>preg_replace("/%s/",base64_encode($path),$catupdown.$catremove),
760 "attach"=>"align='right' style='width:80px;border-right:0px;'")));
761 }
763 /* Create priority & seperator links */
764 $separator ="<hr size=1>";
765 if($this->acl_is_writeable("gosaMemberApplication",$this->no_release_acls)){
766 $sep = "<input type='image' src='images/back.png' title='"._("Insert seperator")."' value='%s' name='AddSep_%s'>";
767 $upudown = "<a href='?plug=".$_GET['plug']."&act=one_up&id=%s'>".
768 " <img alt='{t}sort{/t}' align='top' src='images/sort_up.png' title='"._("Move up")."' border=0>".
769 "</a> ".
770 "<a href='?plug=".$_GET['plug']."&act=one_down&id=%s'>".
771 " <img alt='{t}sort{/t}' src='images/sort_down.png' title='"._("Move down")."' border=0>".
772 "</a> ".
773 "<input type='image' src='images/edittrash.png' title='"._("Delete entry")."' name='DelApp_%s' value='%s' alt='{t}delete{/t}' >";
774 }else{
775 $sep = "";
776 $upudown = "";
777 }
779 /* Create edit link */
780 if($this->acl_is_writeable("gosaApplicationParameter",$this->no_release_acls)){
781 $edit= " <input type='image' src='images/edit.png' title='"._("Edit entry")."' name='EdiApp_%s' value='%s' alt='{t}edit{/t}' >";
782 }else{
783 $edit= "";
784 }
786 /* Get differences to mark those entries that have changed from last edit. */
787 $Differences = $this->diffAppsInReleases();
789 /* Walk through entries an append them to list */
790 if(isset($this->gosaMemberApplication[$this->curCatDir])){
791 foreach($this->gosaMemberApplication[$this->curCatDir] as $cat => $entry){
793 /* Add seperator */
794 if(preg_match("/__SEPARATOR__/",$entry['App'])){
795 $div2 ->AddEntry(array(array("string"=>$separator),
796 array("string"=>preg_replace("/\%s/",htmlentities($entry['App']),$upudown),"attach"=>"align='right' style='border-right:0px;'")));
797 }else{
799 /* Add application */
801 $image = "";
802 /* Check if application was available within selected release
803 * or application list if release management is not active
804 */
805 if(!in_array($entry['App'],$this->AllAppsForRelease)){
807 /* release managent is active
808 */
809 if(!$this->enableReleaseManagement){
810 $image = "<img class='center' alt='R' src='images/select_invalid_application.png'
811 title='"._("This application is no longer available.")."'> ";
812 }else{
813 $image = "<img class='center' alt='F' src='images/select_invalid_application.png'
814 title=\"".sprintf(_("This application is not available in any release named %s."),$this->FAIrelease)."\"> ";
815 }
817 }elseif(isset($Differences[$entry['App']]) && ($Differences[$entry['App']] == true)) {
818 $entry['App'].=" <i>["._("Check parameter")."]</i>";
819 $image = "<img class='center' src='images/select_invalid_application.png'
820 title='"._("This application has changed parameters.")."'> ";
821 }else{
822 $image = "<img class='center' src='images/select_application.png' alt=\"\"> ";
823 }
825 $div2->AddEntry(array(array("string"=>sprintf($image."%s",$entry['App'])),
826 array("string"=>preg_replace("/\%s/",htmlentities($entry['App']),$sep.$edit.$upudown),
827 "attach"=>"align='right' style='width:100px;border-right:0px;'")));
828 }
829 }
830 }
832 /* Assign created div lists to template */
833 $smarty->assign("UsedApps", $div2->DrawList());
834 $smarty->assign("List", $div->DrawList());
835 $smarty->assign("apps", $apps);
837 $smarty->assign("enableReleaseManagement",$this->enableReleaseManagement);
839 $smarty->assign("ReleaseSelectAble", false);
840 $smarty->assign("Release", $this->FAIrelease);
842 if($this->enableReleaseManagement){
843 $smarty->assign("FAIrelease", $this->FAIrelease);
844 $smarty->assign("Releases", $this->Releases);
846 if(!$this->no_release_acls && count($this->Releases)){
847 $smarty->assign("ReleaseSelectAble", true);
848 }
849 }
851 /* Set acls to template */
852 $tmp = $this->plInfo();
853 foreach($tmp['plProvidedAcls'] as $acl => $translation){
854 $smarty->assign($acl."ACL",$this->getacl($acl,$this->no_release_acls));
855 }
857 /* Show main page */
858 if (is_object($this->dialog)){
859 $smarty->assign("table", $this->table);
860 $display.= $smarty->fetch (get_template_path('application_options.tpl', TRUE,dirname(__FILE__)));
861 } else {
862 $display.= $smarty->fetch (get_template_path('application.tpl', TRUE,dirname(__FILE__)));
863 }
865 return ($display);
866 }
869 function getReleases()
870 {
871 /* Only display those releases that we are able to read */
872 $dn = $this->config->current['BASE'];
873 $filter = "(&(objectClass=organizationalUnit)(objectClass=FAIbranch))";
874 $res = get_list($filter,"application", $dn, array("ou"), GL_SUBSEARCH);
876 $ret =array();
877 foreach($res as $attrs){
878 if(preg_match("/ou=apps,/",$attrs['dn'])){
879 $bb = preg_replace("/ou=apps,.*/","",$attrs['dn']);
880 $parts = array_reverse(split("ou=",$bb));
882 $str ="";
883 foreach($parts as $part){
884 if(empty($part)) {
885 continue;
886 }
887 $str .= str_replace(",","",$part)."/";
888 }
889 $name = preg_replace("/\/$/","",$str);
890 if(empty($name)) {
891 $name ="/";
892 }
893 $ret[$attrs['dn']] = $name;
894 }
895 }
896 return($ret);
897 }
899 function save_object()
900 {
902 /* Move category one position up or down */
903 if((isset($_GET['act']))&&(($_GET['act'] == "cat_up")||($_GET['act']=="cat_down"))){
904 if($_GET['act']=="cat_up"){
905 $this->catUp(base64_decode($_GET['id']));
906 }
907 if($_GET['act']=="cat_down"){
908 $this->catDown(base64_decode($_GET['id']));
909 }
910 }
912 /* Move application one position up or down */
913 if((isset($_GET['act']))&&(($_GET['act'] == "one_up")||($_GET['act']=="one_down"))){
914 if(isset($_GET['id'])){
915 $id = $_GET['id'];
916 $act = $_GET['act'];
918 if($act == "one_up"){
919 $this->getOneUp($id);
920 }elseif($act == "one_down") {
921 $this->getOneDown($id);
922 }
923 }
924 }
927 plugin::save_object();
928 }
931 function remove_from_parent()
932 {
933 if(!$this->initially_was_account){
934 return;
935 }
937 plugin::remove_from_parent();
939 $ldap= $this->config->get_ldap_link();
940 $ldap->cd($this->dn);
941 $this->cleanup();
943 $ldap->modify ($this->attrs);
944 new log("remove","group/".get_class($this),$use_dn,array_keys($this->attrs),$ldap->get_error());
945 show_ldap_error($ldap->get_error(), sprintf(_("Removing of groups/applications with dn '%s' failed."),$this->dn));
947 /* Optionally execute a command after we're done */
948 $this->handle_post_events("remove");
949 }
952 /* Save to LDAP */
953 function save()
954 {
955 /* Skip saving application settings, if we do not have release acls */
956 if($this->no_release_acls){
957 new log("security","groups/".get_class($this),$this->dn,array(),"Skip saving group application extension. Caused by insufficient acls");
959 return;
960 }
962 plugin::save();
966 /* Copy members */
967 $this->Categories[""]="";
968 $this->attrs["gosaMemberApplication"]= array();
969 $this->attrs["gosaApplicationParameter"]= array();
970 foreach($this->Categories as $name => $cats){
971 $i =0;
972 if(isset($this->gosaMemberApplication[$name])){
973 foreach($this->gosaMemberApplication[$name] as $entry){
974 if(!preg_match("/__SEPARATOR__/",$entry['App'])){
975 $this->attrs["gosaMemberApplication"][]= $entry['App']."|".$name."|".$i;
976 }
977 $i ++;
978 }
979 }
980 if(($i==0)&&(!empty($name))){
981 $this->attrs["gosaMemberApplication"][]= "|".$name."|".$i;
982 }
983 }
985 /* Are there application parameters to be saved */
986 $this->attrs['gosaApplicationParameter']= array();
987 foreach($this->appoption as $name => $value){
988 if ($value != ""){
989 $this->attrs['gosaApplicationParameter'][]= "$name:$value";
990 }
991 }
993 /* Write back to LDAP */
994 $ldap= $this->config->get_ldap_link();
995 $ldap->cd($this->dn);
996 $this->cleanup();
997 $ldap->modify ($this->attrs);
999 if($this->initially_was_account){
1000 new log("modify","group/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1001 }else{
1002 new log("create","group/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1003 }
1005 show_ldap_error($ldap->get_error(), sprintf(_("Saving of groups/applications with dn '%s' failed."),$this->dn));
1007 /* Optionally execute a command after we're done */
1008 if ($this->initially_was_account == $this->is_account){
1009 if ($this->is_modified){
1010 $this->handle_post_events("modify");
1011 }
1012 } else {
1013 $this->handle_post_events("add");
1014 }
1016 }
1018 function check()
1019 {
1020 /* Call common method to give check the hook */
1021 $message= plugin::check();
1023 return ($message);
1024 }
1027 function reload()
1028 {
1029 /* Generate applist */
1030 $this->apps= array();
1032 /* Special handling for release managed apps */
1033 $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs'));
1034 if(!empty($tmp) && count($this->Releases)){
1035 $this->enableReleaseManagement = true;
1037 /* Check if release is available */
1038 $tmp = array_flip($this->Releases);
1039 if(isset($tmp[$this->FAIrelease])){
1040 $base = $tmp[$this->FAIrelease];
1041 }else{
1043 /* Release is not available, check if there is an alternative */
1044 $old_r = $this->FAIrelease;
1045 $k = key($tmp);
1047 if(isset($tmp[$k])){
1049 /* We have found an alternative release name */
1050 $r = $tmp[$k];
1051 $this->FAIrelease = $k;
1052 $base = $r;
1054 /* Display msg */
1055 if(!(!$this->initially_was_account && $old_r =="/")){
1056 print_red(sprintf(_("Can't resolve the release name '%s', setting release name to '%s'. Possibly the objects base has changed."),$old_r,$k));
1057 }
1058 }else{
1060 /* There are no releases available ... */
1061 print_red(_("There are no releases available. You will not be able to select another release."));
1062 return;
1063 }
1064 }
1066 /* Get applications for this release */
1067 $base = preg_replace("/ou=apps,.*$/","ou=apps,".$this->curbase,$base);
1068 $res = get_list("(objectClass=gosaApplication)","application",$base,array("*"));
1069 }else{
1071 /* Get applications for this base */
1072 $res = get_list("(objectClass=gosaApplication)","application","ou=apps,".$this->curbase,array("*"));
1073 }
1075 /* Append applications */
1076 foreach($res as $attrs){
1077 if (isset($attrs["description"][0])){
1078 $this->apps[$attrs["cn"][0]]=
1079 $attrs["cn"][0]." (".
1080 $attrs["description"][0].")";
1081 } else {
1082 $this->apps[$attrs["cn"][0]]=
1083 $attrs["cn"][0];
1084 }
1085 }
1087 /* Get all apps ... */
1088 $res = get_list("objectClass=gosaApplication","application",$this->config->current['BASE'],array("gosaApplicationParameter","cn"),GL_SUBSEARCH);
1089 $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs'));
1090 $this->AllAppsForRelease = array();
1091 if(!empty($tmp)){
1092 $tmp = array_flip($this->Releases);
1093 foreach($res as $attrs){
1095 $testdn = preg_replace("/ou=apps,.*$/","ou=apps",$attrs['dn']);
1096 $testdn = preg_replace("/^[^,]+/","",$testdn);
1097 $testdn = preg_replace("/^,/","",$testdn);
1099 if($testdn == preg_replace("/ou=apps,.*$/","ou=apps",$tmp[$this->FAIrelease])){
1100 $this->AllAppsForRelease[$attrs['dn']] = $attrs['cn'][0];
1101 $this->AllAppsForReleaseParameter[$this->FAIrelease][$attrs['cn'][0]] = $attrs;
1102 }
1103 }
1104 }else{
1105 foreach($res as $attrs){
1106 $this->AllAppsForRelease[$attrs['dn']] = $attrs['cn'][0];
1107 }
1108 }
1110 natcasesort ($this->apps);
1111 reset ($this->apps);
1113 if(is_array($this->gosaMemberApplication))
1114 foreach ($this->gosaMemberApplication as $cat){
1115 if(is_array($cat))
1116 foreach($cat as $entry){
1117 $this->used_apps[$entry['App']]= $entry['App'];
1118 }
1119 }
1120 }
1123 function addApp($cn)
1124 {
1125 if((isset($this->gosaMemberApplication[$this->curCatDir]))&&(is_array($this->gosaMemberApplication[$this->curCatDir]))){
1126 foreach($this->gosaMemberApplication[$this->curCatDir] as $entry){
1127 if($entry['App'] == $cn) return;
1128 }
1129 }
1130 $this->gosaMemberApplication[$this->curCatDir][]= array("App"=>$cn);
1131 $this->used_apps[$cn]=$cn;
1132 $this->is_modified= TRUE;
1133 }
1136 function removeApp($cn)
1137 {
1138 $temp= array();
1139 foreach ($this->gosaMemberApplication as $value){
1140 if ($value != $cn){
1141 $temp[]= $value;
1142 }
1143 }
1144 $this->gosaMemberApplication= $temp;
1145 $this->is_modified= TRUE;
1146 }
1148 function getParameters($app)
1149 {
1150 $tmp = $this->getReleases();
1151 $ret = array();
1152 if(in_array($this->FAIrelease,$tmp)){
1153 $tmp2 = array_flip($tmp);
1154 $base = $tmp2[$this->FAIrelease];
1155 $ldap = $this->config->get_ldap_link();
1156 $ldap->cd($this->config->current['BASE']);
1157 $ldap->search("(&(objectClass=gosaApplication)(cn=".$app.")(gosaApplicationParameter=*))",array("gosaApplicationParameter"));
1158 if($ldap->count()){
1159 $attrs = $ldap->fetch();
1160 for($i = 0 ; $i < $attrs['gosaApplicationParameter']['count'] ; $i ++ ){
1161 $name = preg_replace("/:.*$/","",$attrs['gosaApplicationParameter'][$i]);
1162 $ret[$name] = $name;
1163 }
1164 }
1165 }
1166 return($ret);
1167 }
1169 function GetSubdirs($dir)
1170 {
1171 $ret = array();
1172 $tmp1 = split("/",$this->curCatDir);
1174 foreach($this->Categories as $path=>$cat){
1175 $tmp2 = split("/",$path);
1177 if((empty($this->curCatDir))&&(!preg_match("/\//",$path))){
1178 $abort = false;
1179 }elseif(((count($tmp1))+1) == (count($tmp2))){
1180 $abort = false;
1181 for($i = 0 ; $i < count($tmp1) ; $i++){
1182 if($tmp1[$i] != $tmp2[$i]){
1183 $abort = true;
1184 }
1185 }
1186 }else{
1187 $abort= true;
1188 }
1189 if(!$abort){
1190 $ret[$path]=$cat;
1191 }
1192 }
1193 return($ret);
1194 }
1197 function PrepareForCopyPaste($source)
1198 {
1199 $s = new appgroup($this->config,$source['dn']);
1200 $this->FAIrelease = $this->InitialFAIrelease = $s->FAIrelease;
1201 $this->gosaMemberApplication = $s->gosaMemberApplication;
1202 $this->appoption = $s->appoption;
1203 $this->Categories = $s->Categories;
1204 }
1207 /* Return plugin informations for acl handling */
1208 function plInfo()
1209 {
1210 return (array(
1211 "plShortName" => _("Applications"),
1212 "plDescription" => _("Group applications"),
1213 "plSelfModify" => FALSE,
1214 "plDepends" => array(),
1215 "plPriority" => 0,
1216 "plSection" => array("admin"),
1217 "plCategory" => array("groups"),
1218 "plProvidedAcls"=> array(
1219 "gosaMemberApplication" => _("Application"),
1220 "FAIrelease" => _("Release"),
1221 "gosaApplicationParameter" => _("Application parameter"))
1222 ));
1223 }
1224 }
1225 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1226 ?>