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();
37 var $view_logged = FALSE;
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 }
160 }
163 /* Combine new array */
164 function combineArrays($ar0,$ar1,$ar2)
165 {
166 $ret = array();
167 if(is_array($ar0))
168 foreach($ar0 as $ar => $a){
169 $ret[$ar]=$a;
170 }
171 if(is_array($ar1))
172 foreach($ar1 as $ar => $a){
173 $ret[$ar]=$a;
174 }
175 if(is_array($ar2))
176 foreach($ar2 as $ar => $a){
177 $ret[$ar]=$a;
178 }
179 return($ret);
180 }
182 /* Returns element position within given array */
183 function getpos($atr,$attrs)
184 {
185 $i = 0;
186 foreach($attrs as $attr => $name) {
187 $i++;
188 if($attr == $atr){
189 return($i);
190 }
191 }
192 return(-1);
193 }
196 /* Check current combination of application && release
197 Are all application available?, application parameter changed? ... */
198 function diffAppsInReleases()
199 {
200 /* Only diff if it is required */
201 $ret =array();
203 /* If current release has changed */
204 if($this->FAIrelease != $this->InitialFAIrelease){
206 /* Walk through all apps which are currently displayed */
207 if(isset($this->gosaMemberApplication[$this->curCatDir])){
209 foreach($this->gosaMemberApplication[$this->curCatDir] as $entry){
211 /* If application is also available in new release, check if parameter differs */
212 if(in_array($entry['App'],$this->AllAppsForRelease)){
214 $old = array(); // Old application parameter
215 $new = array(); // New parameters
217 /* There are possibly no parameters specified */
218 if(isset($this->AllAppsForReleaseParameter[$this->InitialFAIrelease][$entry['App']])){
219 $old = $this->AllAppsForReleaseParameter[$this->InitialFAIrelease][$entry['App']];
220 }
222 if(isset($this->AllAppsForReleaseParameter[$this->FAIrelease][$entry['App']])){
223 $new = $this->AllAppsForReleaseParameter[$this->FAIrelease][$entry['App']];
224 }
226 /* Both (old & new) have no gosaApplicationParameter
227 */
228 if((!isset($old['gosaApplicationParameter'])) && (!isset($new['gosaApplicationParameter']))){
229 $ret[$entry['App']] = false;
231 /* Both got gosaApplicationParameter */
232 }elseif((isset($old['gosaApplicationParameter'])) && (isset($new['gosaApplicationParameter']))){
233 if(array_differs($old['gosaApplicationParameter'],$new['gosaApplicationParameter'])){
234 $ret[$entry['App']] = true;
235 }else{
236 $ret[$entry['App']] = false;
237 }
238 }
239 /* Initially had gosaApplicationParameter bot in new release not */
240 }elseif((isset($old['gosaApplicationParameter'])) && (!isset($new['gosaApplicationParameter']))){
241 $ret[$entry['App']] = true;
243 /* Old release had no gosaApplicationParameter but new got some */
244 }elseif((!isset($old['gosaApplicationParameter'])) && (isset($new['gosaApplicationParameter']))){
245 $ret[$entry['App']] = true;
246 }
247 }
248 }
249 }
250 return($ret);
251 }
253 /* TRansports the geiven Arraykey one position up*/
254 function ArrayUp($atr,$attrs)
255 {
256 $ret = $attrs;
257 $pos = $this->getpos($atr,$attrs) ;
258 $cn = count($attrs);
259 if(!(($pos == -1)||($pos == 1))){
260 $before = array_slice($attrs,0,($pos-2));
261 $mitte = array_reverse(array_slice($attrs,($pos-2),2));
262 $unten = array_slice($attrs,$pos);
263 $ret = array();
264 $ret = $this->combineArrays($before,$mitte,$unten);
265 }
266 return($ret);
267 }
270 /* TRansports the geiven Arraykey one position up*/
271 function ArrayDown($atr,$attrs)
272 {
273 $ret = $attrs;
274 $pos = $this->getpos($atr,$attrs) ;
275 $cn = count($attrs);
276 if(!(($pos == -1)||($pos == $cn))){
277 $before = array_slice($attrs,0,($pos-1));
278 $mitte = array_reverse(array_slice($attrs,($pos-1),2));
279 $unten = array_slice($attrs,($pos+1));
280 $ret = array();
281 $ret = $this->combineArrays($before,$mitte,$unten);
282 }
283 return($ret);
284 }
287 /* Sort category on position up */
288 function catUp($id)
289 {
290 /* Get all cats depinding on current dir */
291 $cats = $this->GetSubdirs($this->curCatDir);
292 $newcats =$this->ArrayUp($id,$cats);
293 foreach($newcats as $cat => $name){
294 unset($this->Categories[$cat]);
295 }
296 foreach($newcats as $cat => $name){
297 $this->Categories[$cat]=$name;
298 }
299 }
302 /* Sort category on position down */
303 function catDown($id)
304 {
305 /* Get all cats depinding on current dir */
306 $cats = $this->GetSubdirs($this->curCatDir);
307 $newcats =$this->ArrayDown($id,$cats);
308 foreach($newcats as $cat => $name){
309 unset($this->Categories[$cat]);
310 }
311 foreach($newcats as $cat => $name){
312 $this->Categories[$cat]=$name;
313 }
314 }
317 /* Increase application priority */
318 function getOneUp($appl)
319 {
320 $cat = $this->curCatDir;
321 $apps = $this->gosaMemberApplication[$cat];
322 $appsA = array();
323 foreach ($apps as $appkey => $name){
324 $appsA[$name['App']] =$name['App'];
325 }
326 $result = $this->ArrayUp($appl,$appsA);
327 $ret = array();
328 foreach($result as $app){
329 $ret[]=array("App"=>$app);
330 }
331 $this->gosaMemberApplication[$cat] = $ret;
332 }
335 /* Decrease application priority */
336 function getOneDown($appl)
337 {
338 $cat = $this->curCatDir;
339 $apps = $this->gosaMemberApplication[$cat];
340 $appsA = array();
341 foreach ($apps as $appkey => $name){
342 $appsA[$name['App']] =$name['App'];
343 }
344 $result = $this->ArrayDown($appl,$appsA);
345 $ret = array();
346 foreach($result as $app){
347 $ret[]=array("App"=>$app);
348 }
349 $this->gosaMemberApplication[$cat] = $ret;
350 }
353 /* Add seperator to application list */
354 function AddSeperator($id)
355 {
356 $found = false;
357 $cat = "";
358 $tmp = array();
359 foreach($this->gosaMemberApplication[$this->curCatDir] as $appID => $app){
360 $tmp[] = $app;
361 if(($app['App'] == $id)&&(!$found)){
362 $cnt = count($this->gosaMemberApplication[$this->curCatDir]);
363 $tmp[] = array("App" => "__SEPARATOR__".($cnt+1));
364 $found = true;
365 }
366 }
367 if($found){
368 $this->gosaMemberApplication[$this->curCatDir]=$tmp;
369 }
370 }
373 /* Check if application acls are readable */
374 function check_acls()
375 {
376 return(count($this->ui->get_module_departments("application")));
377 }
380 function execute()
381 {
382 /* Call parent execute */
383 plugin::execute();
385 /* Log view */
386 if($this->is_account && !$this->view_logged){
387 $this->view_logged = TRUE;
388 @log::log("view","groups/".get_class($this),$this->dn);
389 }
391 /* Check if department was selected */
392 if((isset($_GET['act']))&&($_GET['act']=="depopen")){
393 $dep = base64_decode($_GET['depid']);
394 $this->curbase =$dep;
395 }
397 /* Check if category was selected */
398 if((isset($_GET['act']))&&($_GET['act']=="open") && (empty($_GET['id']) || isset($this->Categories[base64_decode($_GET['id'])]))){
399 $this->curCatDir = base64_decode($_GET['id']);
400 }
402 /* Do we need to flip is_account state? */
403 if(isset($_POST['modify_state'])){
404 if($this->is_account && $this->acl_is_removeable()){
405 $this->is_account= FALSE;
406 }elseif(!$this->is_account && $this->acl_is_createable()){
407 $this->is_account= TRUE;
408 }
409 }
411 /* Do we represent a valid group? */
412 if (!$this->is_account && $this->parent == NULL){
413 $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\"> <b>".
414 _("This 'dn' is no appgroup.")."</b>";
415 return ($display);
416 }
418 /* Show tab dialog headers */
419 $display= "";
420 if ($this->parent != NULL){
421 if ($this->is_account){
422 $display= $this->show_disable_header(_("Remove applications"),
423 _("This group has application features enabled. You can disable them by clicking below."));
424 } else {
425 $display.= $this->show_enable_header(_("Create applications"),
426 _("This group has application features disabled. You can enable them by clicking below."));
427 return ($display);
428 }
429 }
431 /* Check acl, applications must be readable */
432 if(!$this->check_acls()){
433 $display .= "<img src='images/button_cancel.png' alt='"._("ACL")."' class='center'>
434 <b>"._("Insufficient permissions")."</b>
435 <p>".
436 _("You do not have permission to query application entries. All your changes will not be saved.").
437 "</p><p class='seperator'> </p>";
438 $this->no_release_acls = true;
439 }
442 /* Add Categorie */
443 if((isset($_POST['AddCat']))&&(isset($_POST['CatName']))&&(!empty($_POST['CatName']))){
445 /* Only allow adding a category, if it is allowed */
446 if($this->acl_is_writeable("gosaMemberApplication",$this->no_release_acls)){
448 if(preg_match("/[\\\\\/]/i",$_POST['CatName'])){
449 print_red(_("Invalid character in category name."));
450 }elseif(!in_array($_POST['CatName'],$this->Categories)){
451 if(empty($this->curCatDir)){
452 $this->Categories[$_POST['CatName']]=$_POST['CatName'];
453 }else{
454 $this->Categories[$this->curCatDir."/".$_POST['CatName']]=$_POST['CatName'];
455 }
456 }else{
457 print_red(_("The specified category already exists."));
458 }
459 }
460 }
463 $this->reload();
464 $this->diffAppsInReleases();
466 /* Check POST variables for commands
467 to add/remove some applications */
468 $only_once = false;
469 if($this->acl_is_writeable("gosaMemberApplication",$this->no_release_acls)){
471 /* Walk through posts */
472 foreach($_POST as $name => $value){
474 /* Add a seperator to current category */
475 if((preg_match("/AddSep_/",$name))&&(!$only_once)){
476 $only_once = true;
477 $n = preg_replace("/AddSep_/","",$name);
478 $val= preg_replace("/_.*$/","",$n);
479 $this->AddSeperator($val);
480 }
482 /* Delete application | seperator entry */
483 if((preg_match("/DelApp_/",$name))&&(!$only_once)){
484 $only_once = true;
486 if(preg_match("/DelApp___SEPARATOR__/",$name)) {
487 $n= preg_replace("/DelApp___SEPARATOR__/","",$name);
488 $val= "__SEPARATOR__".preg_replace("/_.*$/","",$n);
489 }else{
490 $n = preg_replace("/DelApp_/","",$name);
491 $val= preg_replace("/_.*$/","",$n);
492 }
494 foreach($this->gosaMemberApplication as $key => $cat){
495 foreach($cat as $key2 => $app){
496 if($app['App'] == $val){
497 unset($this->gosaMemberApplication[$key][$key2]);
498 if(isset($this->used_apps[$val])){
499 foreach($this->getParameters($val) as $para){
500 if(isset($this->appoption[$para])){
501 unset($this->appoption[$para]);
502 }
503 }
504 unset($this->used_apps[$val]);
505 }
506 }
507 }
508 }
509 }
511 /* Remove category entry */
512 if(preg_match("/DelCat_/",$name)){
513 $n = preg_replace("/DelCat_/","",$name);
514 $app = base64_decode( preg_replace("/_.*$/","",$n));
515 foreach($this->Categories as $key => $cat){
516 if($cat == $app){
517 foreach($this->Categories as $p => $n){
518 if(preg_match("/^".$key."\/.*/",$p)){
519 unset($this->Categories[$p]);
520 }
521 }
522 unset($this->Categories[$key]);
523 }
524 }
525 }
527 /* Edit application parameter */
528 if((preg_match("/EdiApp_/",$name))&&(!$only_once)){
530 $only_once = true;
531 $appname = $value;
532 $appname = preg_replace("/EdiApp_/","",$name);
533 $appname = preg_replace("/_.*$/","",$appname);
535 /* We've got the appname, get parameters from ldap */
536 $ldap= $this->config->get_ldap_link();
538 /* Check if we have release management enabled */
539 $tmp = search_config($this->config->data,"faiManagement","CLASS");
540 if(!empty($tmp)){
542 /* Get application parameter from ldap */
543 $tmp = array_flip($this->Releases);
544 $base = $tmp[$this->FAIrelease];
545 $ldap->cd($base);
546 $ldap->search("(&(objectClass=gosaApplication)(cn=$appname))",array("gosaApplicationParameter"));
547 $found = "";
548 while($attrs = $ldap->fetch()) {
549 if(preg_match("/cn=".$appname.",".$base."/",$attrs['dn'])){
550 $found = $attrs['dn'];
551 }
552 }
553 $ldap->cat($found, array("gosaApplicationParameter"));
554 }else{
556 /* Get application parameter from ldap */
557 $ldap->cd($this->config->current['BASE']);
558 $ldap->search("(&(objectClass=gosaApplication)(cn=$appname))",array("gosaApplicationParameter"));
559 }
561 /* Check if this application is unique */
562 if ($ldap->count() != 1){
563 print_red (_("The selected application name is not uniq. Please check your LDAP."));
564 } else {
566 /* Get parameter */
567 $attrs= $ldap->fetch();
568 if(isset($attrs['gosaApplicationParameter'])){
569 $this->dialog= TRUE;
571 /* Fill name and value arrays */
572 for ($i= 0; $i<$attrs['gosaApplicationParameter']['count']; $i++){
573 $option= preg_replace('/^[^:]+:/', '',
574 $attrs['gosaApplicationParameter'][$i]);
575 $name= preg_replace('/:.*$/', '',
576 $attrs['gosaApplicationParameter'][$i]);
577 $this->option_name[$i]= $name;
579 /* Fill with values from application, default should be
580 loaded by the external scripts */
581 if (isset($this->appoption[$name])){
582 $this->option_value[$i]= $this->appoption[$name];
583 }
584 }
586 /* Create edit field */
587 $table= "<table summary=\"\">";
588 for ($i= 0; $i < count($this->option_name); $i++){
589 if (isset($this->option_value[$i])){
590 $value= $this->option_value[$i];
591 } else {
592 $value= "";
593 }
594 $table.="<tr><td>".$this->option_name[$i]."</td><td>".
595 "<input name=\"value$i\" size=60 maxlength=250 ".
596 "value=\"".$value."\"><br></td></tr>";
597 }
598 $table.= "</table>";
599 $this->table= $table;
600 } else {
601 print_red (_("The selected application has no options."));
602 }
603 }
604 }
605 }
606 }
608 /* Add multiple */
609 if(isset($_POST['AddApps'])){
610 foreach($_POST as $name => $value){
611 if(preg_match("/AddApp_/",$name)){
612 $app = preg_replace("/AddApp_/","",$name);
613 $this->addApp($app);
614 }
615 }
616 }
618 /* Add application with post */
619 if((isset($_GET['act']))&&($_GET['act']=="add")){
620 $this->used_apps[$_GET['id']]= $_GET['id'];
621 asort($this->used_apps);
622 $this->addApp($_GET['id']);
623 }
625 /* Cancel edit options? */
626 if (isset($_POST['edit_options_cancel'])){
627 $this->dialog= FALSE;
628 }
630 /* Finish edit options? */
631 if (isset($_POST['edit_options_finish'])){
632 $this->dialog= FALSE;
634 /* Save informations passed by the user */
635 $this->option_value= array();
636 for ($i= 0; $i<count($this->option_name); $i++){
637 $this->appoption[$this->option_name[$i]]= $_POST["value$i"];
638 $this->is_modified= TRUE;
639 }
640 }
642 /* Prepare templating stuff */
643 $smarty= get_smarty();
644 $smarty->assign("used_apps", $this->used_apps);
645 $apps= array();
646 foreach ($this->apps as $key => $value){
647 if (!array_key_exists($key, $this->used_apps)){
648 $apps["$key"]= "$value";
649 }
650 }
653 /* Create application list */
654 $div = new DivSelectBox("appgroup");
655 $div->SetHeight(300);
656 $departments = array();
657 $res = get_list("(objectClass=gosaDepartment)", "application", $this->curbase,array("description","cn","ou"),GL_SIZELIMIT);
658 foreach($res as $value){
659 $fdn = $value['dn'];
660 $fdn = preg_replace("/".normalizePreg($this->curbase)."/","",$fdn);
661 $fdn= @LDAP::fix($fdn);
662 if($value["description"][0]!=".."){
663 $departments[$value['dn']]= convert_department_dn($fdn)." - [".$value["description"][0]."]";
664 }else{
665 $departments[$value['dn']]=convert_department_dn($fdn);
666 }
667 }
669 /* Create 'open' and 'add' links */
670 if($this->acl_is_writeable("gosaMemberApplication",$this->no_release_acls)){
671 $linkadd = "<a href='?plug=".$_GET['plug']."&act=add&id=%s'>%s</a>";
672 }else{
673 $linkadd = "%s";
674 }
675 $linkopen = "<a href='?plug=".$_GET['plug']."&act=depopen&depid=%s'>%s</a>";
677 /* Create base back entry */
678 $base_back = preg_replace("/^[^,]+,/","",$this->curbase);
679 if((strlen($base_back)>= strlen($this->config->current['BASE']))&&($this->curbase!=$this->config->current['BASE'])){
680 $div->AddEntry(array(
681 array("string"=>sprintf($linkopen,base64_encode($base_back),".. ["._("back")."]"),
682 "attach"=>"style='border:0px;'")
683 ));
684 }
686 /* Append departments for current base */
687 foreach($departments as $key => $app){
688 $div->AddEntry(array(
689 array("string"=>"<img class='center' src='images/folder.png' alt='"._("department")."'> ".sprintf($linkopen,base64_encode($key),$app),
690 "attach"=>"style='border:0px;'")
691 ));
692 }
694 /* Add applications found on this base */
695 foreach($apps as $key => $app){
696 $div->AddEntry(array(
697 array("string"=>sprintf("<input class='center' type='checkbox' value='1' name='AddApp_%s'>",$key).
698 "<img class='center' src='images/select_application.png' alt='"._("application")."'> ".sprintf($linkadd,$key,$app),
699 "attach"=>"style='border:0px;'")
700 ));
701 }
703 /* Create list of used/assigned applications */
704 $div2 = new DivSelectBox("appgroup");
705 $div2->SetHeight(300);
707 /* Check acls to create "edit/remove" category links */
708 if(!$this->acl_is_writeable("gosaMemberApplication",$this->no_release_acls)){
709 $linkopen = "<img class='center' src='images/folder.png' alt=\"\"> <a href='?plug=".$_GET['plug']."&act=open&id=%s'>%s</a>";
710 $catremove = " <img src='images/empty.png' alt=' '>";
711 $catupdown = "";
712 }else{
713 $linkopen = "<img class='center' src='images/folder.png' alt=\"\"> <a href='?plug=".$_GET['plug']."&act=open&id=%s'>%s</a>";
714 $catremove = " <input type='image' src='images/edittrash.png' title='"._("Delete entry")."' name='DelCat_%s' value='%s'>";
715 $catupdown = "<a href='?plug=".$_GET['plug']."&act=cat_up&id=%s'>".
716 "<img align='top' alt=\"\" src='images/sort_up.png' border=0 title='"._("Move up")."'>".
717 "</a> ".
718 "<a href='?plug=".$_GET['plug']."&act=cat_down&id=%s'>".
719 "<img alt=\"\" src='images/sort_down.png' title='"._("Move down")."' border=0>".
720 "</a>";
721 }
723 /* Add back category for current category */
724 if(empty($this->curCatDir)){
725 $cnt =0;
726 }else{
727 $cnt = count(split("/",$this->curCatDir));
728 $tmp = split("/",$this->curCatDir);
729 $bbk = "";
730 for($i = 0 ; $i < ($cnt -1 ) ; $i++){
731 $bbk .= $tmp[$i];
732 }
733 $div2 ->AddEntry(array(array("string"=>sprintf($linkopen,base64_encode($bbk),"..")),array("string"=>" ","attach"=>"style='border-right:0px;'")));
734 }
736 /* Add sub categories */
737 $this->GetSubdirs($this->curCatDir);
738 foreach($this->GetSubdirs($this->curCatDir) as $path => $name){
739 $div2 ->AddEntry(array(
740 array("string"=>sprintf($linkopen,base64_encode($path),$name)),
741 array("string"=>preg_replace("/%s/",base64_encode($path),$catupdown.$catremove),
742 "attach"=>"align='right' style='width:80px;border-right:0px;'")));
743 }
745 /* Create priority & seperator links */
746 $separator ="<hr size=1>";
747 if($this->acl_is_writeable("gosaMemberApplication",$this->no_release_acls)){
748 $sep = "<input type='image' src='images/back.png' title='"._("Insert seperator")."' value='%s' name='AddSep_%s'>";
749 $upudown = "<a href='?plug=".$_GET['plug']."&act=one_up&id=%s'>".
750 " <img alt='{t}sort{/t}' align='top' src='images/sort_up.png' title='"._("Move up")."' border=0>".
751 "</a> ".
752 "<a href='?plug=".$_GET['plug']."&act=one_down&id=%s'>".
753 " <img alt='{t}sort{/t}' src='images/sort_down.png' title='"._("Move down")."' border=0>".
754 "</a> ".
755 "<input type='image' src='images/edittrash.png' title='"._("Delete entry")."' name='DelApp_%s' value='%s' alt='{t}delete{/t}' >";
756 }else{
757 $sep = "";
758 $upudown = "";
759 }
761 /* Create edit link */
762 if($this->acl_is_writeable("gosaApplicationParameter",$this->no_release_acls)){
763 $edit= " <input type='image' src='images/edit.png' title='"._("Edit entry")."' name='EdiApp_%s' value='%s' alt='{t}edit{/t}' >";
764 }else{
765 $edit= "";
766 }
768 /* Get differences to mark those entries that have changed from last edit. */
769 $Differences = $this->diffAppsInReleases();
771 /* Walk through entries an append them to list */
772 if(isset($this->gosaMemberApplication[$this->curCatDir])){
773 foreach($this->gosaMemberApplication[$this->curCatDir] as $cat => $entry){
775 /* Add seperator */
776 if(preg_match("/__SEPARATOR__/",$entry['App'])){
777 $div2 ->AddEntry(array(array("string"=>$separator),
778 array("string"=>preg_replace("/\%s/",htmlentities($entry['App']),$upudown),"attach"=>"align='right' style='border-right:0px;'")));
779 }else{
781 /* Add application */
783 $image = "";
784 /* Check if application was available within selected release
785 * or application list if release management is not active
786 */
787 if(!in_array($entry['App'],$this->AllAppsForRelease)){
789 /* release managent is active
790 */
791 if(!$this->enableReleaseManagement){
792 $image = "<img class='center' alt='R' src='images/select_invalid_application.png'
793 title='"._("This application is no longer available.")."'> ";
794 }else{
795 $image = "<img class='center' alt='F' src='images/select_invalid_application.png'
796 title=\"".sprintf(_("This application is not available in any release named %s."),$this->FAIrelease)."\"> ";
797 }
799 }elseif(isset($Differences[$entry['App']]) && ($Differences[$entry['App']] == true)) {
800 $entry['App'].=" <i>["._("Check parameter")."]</i>";
801 $image = "<img class='center' src='images/select_invalid_application.png'
802 title='"._("This application has changed parameters.")."'> ";
803 }else{
804 $image = "<img class='center' src='images/select_application.png' alt=\"\"> ";
805 }
807 $div2->AddEntry(array(array("string"=>sprintf($image."%s",$entry['App'])),
808 array("string"=>preg_replace("/\%s/",htmlentities($entry['App']),$sep.$edit.$upudown),
809 "attach"=>"align='right' style='width:100px;border-right:0px;'")));
810 }
811 }
812 }
814 /* Assign created div lists to template */
815 $smarty->assign("UsedApps", $div2->DrawList());
816 $smarty->assign("List", $div->DrawList());
817 $smarty->assign("apps", $apps);
819 $smarty->assign("enableReleaseManagement",$this->enableReleaseManagement);
821 $smarty->assign("ReleaseSelectAble", false);
822 $smarty->assign("Release", $this->FAIrelease);
824 if($this->enableReleaseManagement){
825 $smarty->assign("FAIrelease", $this->FAIrelease);
826 $smarty->assign("Releases", $this->Releases);
828 if(!$this->no_release_acls && count($this->Releases)){
829 $smarty->assign("ReleaseSelectAble", true);
830 }
831 }
833 /* Set acls to template */
834 $tmp = $this->plInfo();
835 foreach($tmp['plProvidedAcls'] as $acl => $translation){
836 $smarty->assign($acl."ACL",$this->getacl($acl,$this->no_release_acls));
837 }
839 /* Show main page */
840 if ($this->dialog){
841 $smarty->assign("table", $this->table);
842 $display.= $smarty->fetch (get_template_path('application_options.tpl', TRUE));
843 } else {
844 $display.= $smarty->fetch (get_template_path('application.tpl', TRUE));
845 }
847 return ($display);
848 }
851 function getReleases()
852 {
853 /* Only display those releases that we are able to read */
854 $dn = $this->config->current['BASE'];
855 $filter = "(&(objectClass=organizationalUnit)(objectClass=FAIbranch))";
856 $res = get_list($filter,"application", $dn, array("ou"), GL_SUBSEARCH);
858 $ret =array();
859 foreach($res as $attrs){
860 if(preg_match("/ou=apps,/",$attrs['dn'])){
861 $bb = preg_replace("/ou=apps,.*/","",$attrs['dn']);
862 $parts = array_reverse(split("ou=",$bb));
864 $str ="";
865 foreach($parts as $part){
866 if(empty($part)) {
867 continue;
868 }
869 $str .= str_replace(",","",$part)."/";
870 }
871 $name = preg_replace("/\/$/","",$str);
872 if(empty($name)) {
873 $name ="/";
874 }
875 $ret[$attrs['dn']] = $name;
876 }
877 }
878 return($ret);
879 }
881 function save_object()
882 {
884 /* Move category one position up or down */
885 if((isset($_GET['act']))&&(($_GET['act'] == "cat_up")||($_GET['act']=="cat_down"))){
886 if($_GET['act']=="cat_up"){
887 $this->catUp(base64_decode($_GET['id']));
888 }
889 if($_GET['act']=="cat_down"){
890 $this->catDown(base64_decode($_GET['id']));
891 }
892 }
894 /* Move application one position up or down */
895 if((isset($_GET['act']))&&(($_GET['act'] == "one_up")||($_GET['act']=="one_down"))){
896 if(isset($_GET['id'])){
897 $id = $_GET['id'];
898 $act = $_GET['act'];
900 if($act == "one_up"){
901 $this->getOneUp($id);
902 }elseif($act == "one_down") {
903 $this->getOneDown($id);
904 }
905 }
906 }
909 plugin::save_object();
910 }
913 function remove_from_parent()
914 {
915 plugin::remove_from_parent();
917 $ldap= $this->config->get_ldap_link();
918 $ldap->cd($this->dn);
919 $this->cleanup();
921 $ldap->modify ($this->attrs);
922 @log::log("remove","group/".get_class($this),$use_dn,array_keys($this->attrs),$ldap->get_error());
923 show_ldap_error($ldap->get_error(), sprintf(_("Removing of groups/applications with dn '%s' failed."),$this->dn));
925 /* Optionally execute a command after we're done */
926 $this->handle_post_events("remove");
927 }
930 /* Save to LDAP */
931 function save()
932 {
933 /* Skip saving application settings, if we do not have release acls */
934 if($this->no_release_acls){
935 gosa_log("Skip saving group application extension. Caused by insufficient acls");
936 return;
937 }
939 plugin::save();
943 /* Copy members */
944 $this->Categories[""]="";
945 $this->attrs["gosaMemberApplication"]= array();
946 $this->attrs["gosaApplicationParameter"]= array();
947 foreach($this->Categories as $name => $cats){
948 $i =0;
949 if(isset($this->gosaMemberApplication[$name])){
950 foreach($this->gosaMemberApplication[$name] as $entry){
951 if(!preg_match("/__SEPARATOR__/",$entry['App'])){
952 $this->attrs["gosaMemberApplication"][]= $entry['App']."|".$name."|".$i;
953 }
954 $i ++;
955 }
956 }
957 if(($i==0)&&(!empty($name))){
958 $this->attrs["gosaMemberApplication"][]= "|".$name."|".$i;
959 }
960 }
962 /* Are there application parameters to be saved */
963 $this->attrs['gosaApplicationParameter']= array();
964 foreach($this->appoption as $name => $value){
965 if ($value != ""){
966 $this->attrs['gosaApplicationParameter'][]= "$name:$value";
967 }
968 }
970 /* Write back to LDAP */
971 $ldap= $this->config->get_ldap_link();
972 $ldap->cd($this->dn);
973 $this->cleanup();
974 $ldap->modify ($this->attrs);
976 if($this->initially_was_account){
977 @log::log("modify","group/".get_class($this),$use_dn,array_keys($this->attrs),$ldap->get_error());
978 }else{
979 @log::log("create","group/".get_class($this),$use_dn,array_keys($this->attrs),$ldap->get_error());
980 }
982 show_ldap_error($ldap->get_error(), sprintf(_("Saving of groups/applications with dn '%s' failed."),$this->dn));
984 /* Optionally execute a command after we're done */
985 if ($this->initially_was_account == $this->is_account){
986 if ($this->is_modified){
987 $this->handle_post_events("modify");
988 }
989 } else {
990 $this->handle_post_events("add");
991 }
993 }
995 function check()
996 {
997 /* Call common method to give check the hook */
998 $message= plugin::check();
1000 return ($message);
1001 }
1004 function reload()
1005 {
1006 /* Generate applist */
1007 $this->apps= array();
1009 /* Special handling for release managed apps */
1010 $tmp = search_config($this->config->data,"faiManagement","CLASS");
1011 if(!empty($tmp) && count($this->Releases)){
1012 $this->enableReleaseManagement = true;
1014 /* Check if release is available */
1015 $tmp = array_flip($this->Releases);
1016 if(isset($tmp[$this->FAIrelease])){
1017 $base = $tmp[$this->FAIrelease];
1018 }else{
1020 /* Release is not available, check if there is an alternative */
1021 $old_r = $this->FAIrelease;
1022 $k = key($tmp);
1024 if(isset($tmp[$k])){
1026 /* We have found an alternative release name */
1027 $r = $tmp[$k];
1028 $this->FAIrelease = $k;
1029 $base = $r;
1031 /* Display msg */
1032 if(!(!$this->initially_was_account && $old_r =="/")){
1033 print_red(sprintf(_("Can't resolve the release name '%s', setting release name to '%s'. Possibly the objects base has changed."),$old_r,$k));
1034 }
1035 }else{
1037 /* There are no releases available ... */
1038 print_red(_("There are no releases available. You will not be able to select another release."));
1039 return;
1040 }
1041 }
1043 /* Get applications for this release */
1044 $base = preg_replace("/ou=apps,.*$/","ou=apps,".$this->curbase,$base);
1045 $res = get_list("(objectClass=gosaApplication)","application",$base,array("*"));
1046 }else{
1048 /* Get applications for this base */
1049 $res = get_list("(objectClass=gosaApplication)","application","ou=apps,".$this->curbase,array("*"));
1050 }
1052 /* Append applications */
1053 foreach($res as $attrs){
1054 if (isset($attrs["description"][0])){
1055 $this->apps[$attrs["cn"][0]]=
1056 $attrs["cn"][0]." (".
1057 $attrs["description"][0].")";
1058 } else {
1059 $this->apps[$attrs["cn"][0]]=
1060 $attrs["cn"][0];
1061 }
1062 }
1064 /* Get all apps ... */
1065 $res = get_list("objectClass=gosaApplication","application",$this->config->current['BASE'],array("gosaApplicationParameter","cn"),GL_SUBSEARCH);
1066 $tmp = search_config($this->config->data,"faiManagement","CLASS");
1067 $this->AllAppsForRelease = array();
1068 if(!empty($tmp)){
1069 $tmp = array_flip($this->Releases);
1070 foreach($res as $attrs){
1072 $testdn = preg_replace("/ou=apps,.*$/","ou=apps",$attrs['dn']);
1073 $testdn = preg_replace("/^[^,]+/","",$testdn);
1074 $testdn = preg_replace("/^,/","",$testdn);
1076 if($testdn == preg_replace("/ou=apps,.*$/","ou=apps",$tmp[$this->FAIrelease])){
1077 $this->AllAppsForRelease[$attrs['dn']] = $attrs['cn'][0];
1078 $this->AllAppsForReleaseParameter[$this->FAIrelease][$attrs['cn'][0]] = $attrs;
1079 }
1080 }
1081 }else{
1082 foreach($res as $attrs){
1083 $this->AllAppsForRelease[$attrs['dn']] = $attrs['cn'][0];
1084 }
1085 }
1087 natcasesort ($this->apps);
1088 reset ($this->apps);
1090 if(is_array($this->gosaMemberApplication))
1091 foreach ($this->gosaMemberApplication as $cat){
1092 if(is_array($cat))
1093 foreach($cat as $entry){
1094 $this->used_apps[$entry['App']]= $entry['App'];
1095 }
1096 }
1097 }
1100 function addApp($cn)
1101 {
1102 if((isset($this->gosaMemberApplication[$this->curCatDir]))&&(is_array($this->gosaMemberApplication[$this->curCatDir]))){
1103 foreach($this->gosaMemberApplication[$this->curCatDir] as $entry){
1104 if($entry['App'] == $cn) return;
1105 }
1106 }
1107 $this->gosaMemberApplication[$this->curCatDir][]= array("App"=>$cn);
1108 $this->used_apps[$cn]=$cn;
1109 $this->is_modified= TRUE;
1110 }
1113 function removeApp($cn)
1114 {
1115 $temp= array();
1116 foreach ($this->gosaMemberApplication as $value){
1117 if ($value != $cn){
1118 $temp[]= $value;
1119 }
1120 }
1121 $this->gosaMemberApplication= $temp;
1122 $this->is_modified= TRUE;
1123 }
1125 function getParameters($app)
1126 {
1127 $tmp = $this->getReleases();
1128 $ret = array();
1129 if(in_array($this->FAIrelease,$tmp)){
1130 $tmp2 = array_flip($tmp);
1131 $base = $tmp2[$this->FAIrelease];
1132 $ldap = $this->config->get_ldap_link();
1133 $ldap->cd($this->config->current['BASE']);
1134 $ldap->search("(&(objectClass=gosaApplication)(cn=".$app.")(gosaApplicationParameter=*))",array("gosaApplicationParameter"));
1135 if($ldap->count()){
1136 $attrs = $ldap->fetch();
1137 for($i = 0 ; $i < $attrs['gosaApplicationParameter']['count'] ; $i ++ ){
1138 $name = preg_replace("/:.*$/","",$attrs['gosaApplicationParameter'][$i]);
1139 $ret[$name] = $name;
1140 }
1141 }
1142 }
1143 return($ret);
1144 }
1146 function GetSubdirs($dir)
1147 {
1148 $ret = array();
1149 $tmp1 = split("/",$this->curCatDir);
1151 foreach($this->Categories as $path=>$cat){
1152 $tmp2 = split("/",$path);
1154 if((empty($this->curCatDir))&&(!preg_match("/\//",$path))){
1155 $abort = false;
1156 }elseif(((count($tmp1))+1) == (count($tmp2))){
1157 $abort = false;
1158 for($i = 0 ; $i < count($tmp1) ; $i++){
1159 if($tmp1[$i] != $tmp2[$i]){
1160 $abort = true;
1161 }
1162 }
1163 }else{
1164 $abort= true;
1165 }
1166 if(!$abort){
1167 $ret[$path]=$cat;
1168 }
1169 }
1170 return($ret);
1171 }
1174 function PrepareForCopyPaste($source)
1175 {
1176 $this->FAIrelease = $this->InitialFAIrelease = $source->FAIrelease;
1177 $this->gosaMemberApplication = $source->gosaMemberApplication;
1178 $this->appoption = $source->appoption;
1179 }
1182 /* Return plugin informations for acl handling */
1183 function plInfo()
1184 {
1185 return (array(
1186 "plShortName" => _("Applications"),
1187 "plDescription" => _("Group applications"),
1188 "plSelfModify" => FALSE,
1189 "plDepends" => array(),
1190 "plPriority" => 0,
1191 "plSection" => array("admin"),
1192 "plCategory" => array("groups"),
1193 "plProvidedAcls"=> array(
1194 "gosaMemberApplication" => _("Application"),
1195 "FAIrelease" => _("Release"),
1196 "gosaApplicationParameter" => _("Application parameter"))
1197 ));
1198 }
1199 }
1200 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1201 ?>