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('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 /* Remove category entry */
515 if(preg_match("/DelCat_/",$name)){
516 $n = preg_replace("/DelCat_/","",$name);
517 $app = base64_decode( preg_replace("/_.*$/","",$n));
518 foreach($this->Categories as $key => $cat){
519 if($cat == $app){
520 foreach($this->Categories as $p => $n){
521 if(preg_match("/^".$key."\/.*/",$p)){
522 unset($this->Categories[$p]);
523 }
524 }
525 unset($this->Categories[$key]);
526 }
527 }
528 }
530 /* Edit application parameter */
531 if((preg_match("/EdiApp_/",$name))&&(!$only_once)){
533 $only_once = true;
534 $appname = $value;
535 $appname = preg_replace("/EdiApp_/","",$name);
536 $appname = preg_replace("/_.*$/","",$appname);
538 /* We've got the appname, get parameters from ldap */
539 $ldap= $this->config->get_ldap_link();
541 /* Check if we have release management enabled */
542 $tmp = $this->config->search("faiManagement", "CLASS",array('tabs'));
543 if(!empty($tmp)){
545 /* Get application parameter from ldap */
546 $tmp = array_flip($this->Releases);
547 $base = $tmp[$this->FAIrelease];
548 $ldap->cd($base);
549 $ldap->search("(&(objectClass=gosaApplication)(cn=$appname))",array("gosaApplicationParameter"));
550 $found = "";
551 while($attrs = $ldap->fetch()) {
552 if(preg_match("/cn=".$appname.",".$base."/",$attrs['dn'])){
553 $found = $attrs['dn'];
554 }
555 }
556 $ldap->cat($found, array("gosaApplicationParameter"));
557 }else{
559 /* Get application parameter from ldap */
560 $ldap->cd($this->config->current['BASE']);
561 $ldap->search("(&(objectClass=gosaApplication)(cn=$appname))",array("gosaApplicationParameter"));
562 }
564 /* Check if this application is unique */
565 if ($ldap->count() != 1){
566 print_red (_("The selected application name is not uniq. Please check your LDAP."));
567 } else {
569 /* Get parameter */
570 $attrs= $ldap->fetch();
571 if(isset($attrs['gosaApplicationParameter'])){
572 $this->dialog= TRUE;
574 /* Fill name and value arrays */
575 for ($i= 0; $i<$attrs['gosaApplicationParameter']['count']; $i++){
576 $option= preg_replace('/^[^:]+:/', '',
577 $attrs['gosaApplicationParameter'][$i]);
578 $name= preg_replace('/:.*$/', '',
579 $attrs['gosaApplicationParameter'][$i]);
580 $this->option_name[$i]= $name;
582 /* Fill with values from application, default should be
583 loaded by the external scripts */
584 if (isset($this->appoption[$name])){
585 $this->option_value[$i]= $this->appoption[$name];
586 }
587 }
589 /* Create edit field */
590 $table= "<table summary=\"\">";
591 for ($i= 0; $i < count($this->option_name); $i++){
592 if (isset($this->option_value[$i])){
593 $value= $this->option_value[$i];
594 } else {
595 $value= "";
596 }
597 $table.="<tr><td>".$this->option_name[$i]."</td><td>".
598 "<input name=\"value$i\" size=60 maxlength=250 ".
599 "value=\"".$value."\"><br></td></tr>";
600 }
601 $table.= "</table>";
602 $this->table= $table;
603 } else {
604 print_red (_("The selected application has no options."));
605 }
606 }
607 }
608 }
609 }
611 /* Add multiple */
612 if(isset($_POST['AddApps'])){
613 foreach($_POST as $name => $value){
614 if(preg_match("/AddApp_/",$name)){
615 $app = preg_replace("/AddApp_/","",$name);
616 $this->addApp($app);
617 }
618 }
619 }
621 /* Add application with post */
622 if((isset($_GET['act']))&&($_GET['act']=="add")){
623 $this->used_apps[$_GET['id']]= $_GET['id'];
624 asort($this->used_apps);
625 $this->addApp($_GET['id']);
626 }
628 /* Cancel edit options? */
629 if (isset($_POST['edit_options_cancel'])){
630 $this->dialog= FALSE;
631 }
633 /* Finish edit options? */
634 if (isset($_POST['edit_options_finish'])){
635 $this->dialog= FALSE;
637 /* Save informations passed by the user */
638 $this->option_value= array();
639 for ($i= 0; $i<count($this->option_name); $i++){
640 $this->appoption[$this->option_name[$i]]= $_POST["value$i"];
641 $this->is_modified= TRUE;
642 }
643 }
645 /* Prepare templating stuff */
646 $smarty= get_smarty();
647 $smarty->assign("used_apps", $this->used_apps);
648 $apps= array();
649 foreach ($this->apps as $key => $value){
650 if (!array_key_exists($key, $this->used_apps)){
651 $apps["$key"]= "$value";
652 }
653 }
656 /* Create application list */
657 $div = new divSelectBox("appgroup");
658 $div->SetHeight(300);
659 $departments = array();
660 $res = get_list("(objectClass=gosaDepartment)", "application", $this->curbase,array("description","cn","ou"),GL_SIZELIMIT);
661 foreach($res as $value){
662 $fdn = $value['dn'];
663 $fdn = preg_replace("/".normalizePreg($this->curbase)."/","",$fdn);
664 $fdn= @LDAP::fix($fdn);
665 if($value["description"][0]!=".."){
666 $departments[$value['dn']]= convert_department_dn($fdn)." - [".$value["description"][0]."]";
667 }else{
668 $departments[$value['dn']]=convert_department_dn($fdn);
669 }
670 }
672 /* Create 'open' and 'add' links */
673 if($this->acl_is_writeable("gosaMemberApplication",$this->no_release_acls)){
674 $linkadd = "<a href='?plug=".$_GET['plug']."&act=add&id=%s'>%s</a>";
675 }else{
676 $linkadd = "%s";
677 }
678 $linkopen = "<a href='?plug=".$_GET['plug']."&act=depopen&depid=%s'>%s</a>";
680 /* Create base back entry */
681 $base_back = preg_replace("/^[^,]+,/","",$this->curbase);
682 if((strlen($base_back)>= strlen($this->config->current['BASE']))&&($this->curbase!=$this->config->current['BASE'])){
683 $div->AddEntry(array(
684 array("string"=>sprintf($linkopen,base64_encode($base_back),".. ["._("back")."]"),
685 "attach"=>"style='border:0px;'")
686 ));
687 }
689 /* Append departments for current base */
690 foreach($departments as $key => $app){
691 $div->AddEntry(array(
692 array("string"=>"<img class='center' src='images/folder.png' alt='"._("department")."'> ".sprintf($linkopen,base64_encode($key),$app),
693 "attach"=>"style='border:0px;'")
694 ));
695 }
697 /* Add applications found on this base */
698 foreach($apps as $key => $app){
699 $div->AddEntry(array(
700 array("string"=>sprintf("<input class='center' type='checkbox' value='1' name='AddApp_%s'>",$key).
701 "<img class='center' src='images/select_application.png' alt='"._("application")."'> ".sprintf($linkadd,$key,$app),
702 "attach"=>"style='border:0px;'")
703 ));
704 }
706 /* Create list of used/assigned applications */
707 $div2 = new divSelectBox("appgroup");
708 $div2->SetHeight(300);
710 /* Check acls to create "edit/remove" category links */
711 if(!$this->acl_is_writeable("gosaMemberApplication",$this->no_release_acls)){
712 $linkopen = "<img class='center' src='images/folder.png' alt=\"\"> <a href='?plug=".$_GET['plug']."&act=open&id=%s'>%s</a>";
713 $catremove = " <img src='images/empty.png' alt=' '>";
714 $catupdown = "";
715 }else{
716 $linkopen = "<img class='center' src='images/folder.png' alt=\"\"> <a href='?plug=".$_GET['plug']."&act=open&id=%s'>%s</a>";
717 $catremove = " <input type='image' src='images/edittrash.png' title='"._("Delete entry")."' name='DelCat_%s' value='%s'>";
718 $catupdown = "<a href='?plug=".$_GET['plug']."&act=cat_up&id=%s'>".
719 "<img align='top' alt=\"\" src='images/sort_up.png' border=0 title='"._("Move up")."'>".
720 "</a> ".
721 "<a href='?plug=".$_GET['plug']."&act=cat_down&id=%s'>".
722 "<img alt=\"\" src='images/sort_down.png' title='"._("Move down")."' border=0>".
723 "</a>";
724 }
726 /* Add back category for current category */
727 if(empty($this->curCatDir)){
728 $cnt =0;
729 }else{
730 $cnt = count(split("/",$this->curCatDir));
731 $tmp = split("/",$this->curCatDir);
732 $bbk = "";
733 for($i = 0 ; $i < ($cnt -1 ) ; $i++){
734 $bbk .= $tmp[$i];
735 }
736 $div2 ->AddEntry(array(array("string"=>sprintf($linkopen,base64_encode($bbk),"..")),array("string"=>" ","attach"=>"style='border-right:0px;'")));
737 }
739 /* Add sub categories */
740 $this->GetSubdirs($this->curCatDir);
741 foreach($this->GetSubdirs($this->curCatDir) as $path => $name){
742 $div2 ->AddEntry(array(
743 array("string"=>sprintf($linkopen,base64_encode($path),$name)),
744 array("string"=>preg_replace("/%s/",base64_encode($path),$catupdown.$catremove),
745 "attach"=>"align='right' style='width:80px;border-right:0px;'")));
746 }
748 /* Create priority & seperator links */
749 $separator ="<hr size=1>";
750 if($this->acl_is_writeable("gosaMemberApplication",$this->no_release_acls)){
751 $sep = "<input type='image' src='images/back.png' title='"._("Insert seperator")."' value='%s' name='AddSep_%s'>";
752 $upudown = "<a href='?plug=".$_GET['plug']."&act=one_up&id=%s'>".
753 " <img alt='{t}sort{/t}' align='top' src='images/sort_up.png' title='"._("Move up")."' border=0>".
754 "</a> ".
755 "<a href='?plug=".$_GET['plug']."&act=one_down&id=%s'>".
756 " <img alt='{t}sort{/t}' src='images/sort_down.png' title='"._("Move down")."' border=0>".
757 "</a> ".
758 "<input type='image' src='images/edittrash.png' title='"._("Delete entry")."' name='DelApp_%s' value='%s' alt='{t}delete{/t}' >";
759 }else{
760 $sep = "";
761 $upudown = "";
762 }
764 /* Create edit link */
765 if($this->acl_is_writeable("gosaApplicationParameter",$this->no_release_acls)){
766 $edit= " <input type='image' src='images/edit.png' title='"._("Edit entry")."' name='EdiApp_%s' value='%s' alt='{t}edit{/t}' >";
767 }else{
768 $edit= "";
769 }
771 /* Get differences to mark those entries that have changed from last edit. */
772 $Differences = $this->diffAppsInReleases();
774 /* Walk through entries an append them to list */
775 if(isset($this->gosaMemberApplication[$this->curCatDir])){
776 foreach($this->gosaMemberApplication[$this->curCatDir] as $cat => $entry){
778 /* Add seperator */
779 if(preg_match("/__SEPARATOR__/",$entry['App'])){
780 $div2 ->AddEntry(array(array("string"=>$separator),
781 array("string"=>preg_replace("/\%s/",htmlentities($entry['App']),$upudown),"attach"=>"align='right' style='border-right:0px;'")));
782 }else{
784 /* Add application */
786 $image = "";
787 /* Check if application was available within selected release
788 * or application list if release management is not active
789 */
790 if(!in_array($entry['App'],$this->AllAppsForRelease)){
792 /* release managent is active
793 */
794 if(!$this->enableReleaseManagement){
795 $image = "<img class='center' alt='R' src='images/select_invalid_application.png'
796 title='"._("This application is no longer available.")."'> ";
797 }else{
798 $image = "<img class='center' alt='F' src='images/select_invalid_application.png'
799 title=\"".sprintf(_("This application is not available in any release named %s."),$this->FAIrelease)."\"> ";
800 }
802 }elseif(isset($Differences[$entry['App']]) && ($Differences[$entry['App']] == true)) {
803 $entry['App'].=" <i>["._("Check parameter")."]</i>";
804 $image = "<img class='center' src='images/select_invalid_application.png'
805 title='"._("This application has changed parameters.")."'> ";
806 }else{
807 $image = "<img class='center' src='images/select_application.png' alt=\"\"> ";
808 }
810 $div2->AddEntry(array(array("string"=>sprintf($image."%s",$entry['App'])),
811 array("string"=>preg_replace("/\%s/",htmlentities($entry['App']),$sep.$edit.$upudown),
812 "attach"=>"align='right' style='width:100px;border-right:0px;'")));
813 }
814 }
815 }
817 /* Assign created div lists to template */
818 $smarty->assign("UsedApps", $div2->DrawList());
819 $smarty->assign("List", $div->DrawList());
820 $smarty->assign("apps", $apps);
822 $smarty->assign("enableReleaseManagement",$this->enableReleaseManagement);
824 $smarty->assign("ReleaseSelectAble", false);
825 $smarty->assign("Release", $this->FAIrelease);
827 if($this->enableReleaseManagement){
828 $smarty->assign("FAIrelease", $this->FAIrelease);
829 $smarty->assign("Releases", $this->Releases);
831 if(!$this->no_release_acls && count($this->Releases)){
832 $smarty->assign("ReleaseSelectAble", true);
833 }
834 }
836 /* Set acls to template */
837 $tmp = $this->plInfo();
838 foreach($tmp['plProvidedAcls'] as $acl => $translation){
839 $smarty->assign($acl."ACL",$this->getacl($acl,$this->no_release_acls));
840 }
842 /* Show main page */
843 if ($this->dialog){
844 $smarty->assign("table", $this->table);
845 $display.= $smarty->fetch (get_template_path('application_options.tpl', TRUE,dirname(__FILE__)));
846 } else {
847 $display.= $smarty->fetch (get_template_path('application.tpl', TRUE,dirname(__FILE__)));
848 }
850 return ($display);
851 }
854 function getReleases()
855 {
856 /* Only display those releases that we are able to read */
857 $dn = $this->config->current['BASE'];
858 $filter = "(&(objectClass=organizationalUnit)(objectClass=FAIbranch))";
859 $res = get_list($filter,"application", $dn, array("ou"), GL_SUBSEARCH);
861 $ret =array();
862 foreach($res as $attrs){
863 if(preg_match("/ou=apps,/",$attrs['dn'])){
864 $bb = preg_replace("/ou=apps,.*/","",$attrs['dn']);
865 $parts = array_reverse(split("ou=",$bb));
867 $str ="";
868 foreach($parts as $part){
869 if(empty($part)) {
870 continue;
871 }
872 $str .= str_replace(",","",$part)."/";
873 }
874 $name = preg_replace("/\/$/","",$str);
875 if(empty($name)) {
876 $name ="/";
877 }
878 $ret[$attrs['dn']] = $name;
879 }
880 }
881 return($ret);
882 }
884 function save_object()
885 {
887 /* Move category one position up or down */
888 if((isset($_GET['act']))&&(($_GET['act'] == "cat_up")||($_GET['act']=="cat_down"))){
889 if($_GET['act']=="cat_up"){
890 $this->catUp(base64_decode($_GET['id']));
891 }
892 if($_GET['act']=="cat_down"){
893 $this->catDown(base64_decode($_GET['id']));
894 }
895 }
897 /* Move application one position up or down */
898 if((isset($_GET['act']))&&(($_GET['act'] == "one_up")||($_GET['act']=="one_down"))){
899 if(isset($_GET['id'])){
900 $id = $_GET['id'];
901 $act = $_GET['act'];
903 if($act == "one_up"){
904 $this->getOneUp($id);
905 }elseif($act == "one_down") {
906 $this->getOneDown($id);
907 }
908 }
909 }
912 plugin::save_object();
913 }
916 function remove_from_parent()
917 {
918 if(!$this->initially_was_account){
919 return;
920 }
922 plugin::remove_from_parent();
924 $ldap= $this->config->get_ldap_link();
925 $ldap->cd($this->dn);
926 $this->cleanup();
928 $ldap->modify ($this->attrs);
929 new log("remove","group/".get_class($this),$use_dn,array_keys($this->attrs),$ldap->get_error());
930 show_ldap_error($ldap->get_error(), sprintf(_("Removing of groups/applications with dn '%s' failed."),$this->dn));
932 /* Optionally execute a command after we're done */
933 $this->handle_post_events("remove");
934 }
937 /* Save to LDAP */
938 function save()
939 {
940 /* Skip saving application settings, if we do not have release acls */
941 if($this->no_release_acls){
942 new log("security","groups/".get_class($this),$this->dn,array(),"Skip saving group application extension. Caused by insufficient acls");
944 return;
945 }
947 plugin::save();
951 /* Copy members */
952 $this->Categories[""]="";
953 $this->attrs["gosaMemberApplication"]= array();
954 $this->attrs["gosaApplicationParameter"]= array();
955 foreach($this->Categories as $name => $cats){
956 $i =0;
957 if(isset($this->gosaMemberApplication[$name])){
958 foreach($this->gosaMemberApplication[$name] as $entry){
959 if(!preg_match("/__SEPARATOR__/",$entry['App'])){
960 $this->attrs["gosaMemberApplication"][]= $entry['App']."|".$name."|".$i;
961 }
962 $i ++;
963 }
964 }
965 if(($i==0)&&(!empty($name))){
966 $this->attrs["gosaMemberApplication"][]= "|".$name."|".$i;
967 }
968 }
970 /* Are there application parameters to be saved */
971 $this->attrs['gosaApplicationParameter']= array();
972 foreach($this->appoption as $name => $value){
973 if ($value != ""){
974 $this->attrs['gosaApplicationParameter'][]= "$name:$value";
975 }
976 }
978 /* Write back to LDAP */
979 $ldap= $this->config->get_ldap_link();
980 $ldap->cd($this->dn);
981 $this->cleanup();
982 $ldap->modify ($this->attrs);
984 if($this->initially_was_account){
985 new log("modify","group/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
986 }else{
987 new log("create","group/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
988 }
990 show_ldap_error($ldap->get_error(), sprintf(_("Saving of groups/applications with dn '%s' failed."),$this->dn));
992 /* Optionally execute a command after we're done */
993 if ($this->initially_was_account == $this->is_account){
994 if ($this->is_modified){
995 $this->handle_post_events("modify");
996 }
997 } else {
998 $this->handle_post_events("add");
999 }
1001 }
1003 function check()
1004 {
1005 /* Call common method to give check the hook */
1006 $message= plugin::check();
1008 return ($message);
1009 }
1012 function reload()
1013 {
1014 /* Generate applist */
1015 $this->apps= array();
1017 /* Special handling for release managed apps */
1018 $tmp = $this->config->search("faiManagement", "CLASS",array('tabs'));
1019 if(!empty($tmp) && count($this->Releases)){
1020 $this->enableReleaseManagement = true;
1022 /* Check if release is available */
1023 $tmp = array_flip($this->Releases);
1024 if(isset($tmp[$this->FAIrelease])){
1025 $base = $tmp[$this->FAIrelease];
1026 }else{
1028 /* Release is not available, check if there is an alternative */
1029 $old_r = $this->FAIrelease;
1030 $k = key($tmp);
1032 if(isset($tmp[$k])){
1034 /* We have found an alternative release name */
1035 $r = $tmp[$k];
1036 $this->FAIrelease = $k;
1037 $base = $r;
1039 /* Display msg */
1040 if(!(!$this->initially_was_account && $old_r =="/")){
1041 print_red(sprintf(_("Can't resolve the release name '%s', setting release name to '%s'. Possibly the objects base has changed."),$old_r,$k));
1042 }
1043 }else{
1045 /* There are no releases available ... */
1046 print_red(_("There are no releases available. You will not be able to select another release."));
1047 return;
1048 }
1049 }
1051 /* Get applications for this release */
1052 $base = preg_replace("/ou=apps,.*$/","ou=apps,".$this->curbase,$base);
1053 $res = get_list("(objectClass=gosaApplication)","application",$base,array("*"));
1054 }else{
1056 /* Get applications for this base */
1057 $res = get_list("(objectClass=gosaApplication)","application","ou=apps,".$this->curbase,array("*"));
1058 }
1060 /* Append applications */
1061 foreach($res as $attrs){
1062 if (isset($attrs["description"][0])){
1063 $this->apps[$attrs["cn"][0]]=
1064 $attrs["cn"][0]." (".
1065 $attrs["description"][0].")";
1066 } else {
1067 $this->apps[$attrs["cn"][0]]=
1068 $attrs["cn"][0];
1069 }
1070 }
1072 /* Get all apps ... */
1073 $res = get_list("objectClass=gosaApplication","application",$this->config->current['BASE'],array("gosaApplicationParameter","cn"),GL_SUBSEARCH);
1074 $tmp = $this->config->search("faiManagement", "CLASS",array('tabs'));
1075 $this->AllAppsForRelease = array();
1076 if(!empty($tmp)){
1077 $tmp = array_flip($this->Releases);
1078 foreach($res as $attrs){
1080 $testdn = preg_replace("/ou=apps,.*$/","ou=apps",$attrs['dn']);
1081 $testdn = preg_replace("/^[^,]+/","",$testdn);
1082 $testdn = preg_replace("/^,/","",$testdn);
1084 if($testdn == preg_replace("/ou=apps,.*$/","ou=apps",$tmp[$this->FAIrelease])){
1085 $this->AllAppsForRelease[$attrs['dn']] = $attrs['cn'][0];
1086 $this->AllAppsForReleaseParameter[$this->FAIrelease][$attrs['cn'][0]] = $attrs;
1087 }
1088 }
1089 }else{
1090 foreach($res as $attrs){
1091 $this->AllAppsForRelease[$attrs['dn']] = $attrs['cn'][0];
1092 }
1093 }
1095 natcasesort ($this->apps);
1096 reset ($this->apps);
1098 if(is_array($this->gosaMemberApplication))
1099 foreach ($this->gosaMemberApplication as $cat){
1100 if(is_array($cat))
1101 foreach($cat as $entry){
1102 $this->used_apps[$entry['App']]= $entry['App'];
1103 }
1104 }
1105 }
1108 function addApp($cn)
1109 {
1110 if((isset($this->gosaMemberApplication[$this->curCatDir]))&&(is_array($this->gosaMemberApplication[$this->curCatDir]))){
1111 foreach($this->gosaMemberApplication[$this->curCatDir] as $entry){
1112 if($entry['App'] == $cn) return;
1113 }
1114 }
1115 $this->gosaMemberApplication[$this->curCatDir][]= array("App"=>$cn);
1116 $this->used_apps[$cn]=$cn;
1117 $this->is_modified= TRUE;
1118 }
1121 function removeApp($cn)
1122 {
1123 $temp= array();
1124 foreach ($this->gosaMemberApplication as $value){
1125 if ($value != $cn){
1126 $temp[]= $value;
1127 }
1128 }
1129 $this->gosaMemberApplication= $temp;
1130 $this->is_modified= TRUE;
1131 }
1133 function getParameters($app)
1134 {
1135 $tmp = $this->getReleases();
1136 $ret = array();
1137 if(in_array($this->FAIrelease,$tmp)){
1138 $tmp2 = array_flip($tmp);
1139 $base = $tmp2[$this->FAIrelease];
1140 $ldap = $this->config->get_ldap_link();
1141 $ldap->cd($this->config->current['BASE']);
1142 $ldap->search("(&(objectClass=gosaApplication)(cn=".$app.")(gosaApplicationParameter=*))",array("gosaApplicationParameter"));
1143 if($ldap->count()){
1144 $attrs = $ldap->fetch();
1145 for($i = 0 ; $i < $attrs['gosaApplicationParameter']['count'] ; $i ++ ){
1146 $name = preg_replace("/:.*$/","",$attrs['gosaApplicationParameter'][$i]);
1147 $ret[$name] = $name;
1148 }
1149 }
1150 }
1151 return($ret);
1152 }
1154 function GetSubdirs($dir)
1155 {
1156 $ret = array();
1157 $tmp1 = split("/",$this->curCatDir);
1159 foreach($this->Categories as $path=>$cat){
1160 $tmp2 = split("/",$path);
1162 if((empty($this->curCatDir))&&(!preg_match("/\//",$path))){
1163 $abort = false;
1164 }elseif(((count($tmp1))+1) == (count($tmp2))){
1165 $abort = false;
1166 for($i = 0 ; $i < count($tmp1) ; $i++){
1167 if($tmp1[$i] != $tmp2[$i]){
1168 $abort = true;
1169 }
1170 }
1171 }else{
1172 $abort= true;
1173 }
1174 if(!$abort){
1175 $ret[$path]=$cat;
1176 }
1177 }
1178 return($ret);
1179 }
1182 function PrepareForCopyPaste($source)
1183 {
1184 $s = new appgroup($this->config,$source['dn']);
1185 $this->FAIrelease = $this->InitialFAIrelease = $s->FAIrelease;
1186 $this->gosaMemberApplication = $s->gosaMemberApplication;
1187 $this->appoption = $s->appoption;
1188 $this->Categories = $s->Categories;
1189 }
1192 /* Return plugin informations for acl handling */
1193 function plInfo()
1194 {
1195 return (array(
1196 "plShortName" => _("Applications"),
1197 "plDescription" => _("Group applications"),
1198 "plSelfModify" => FALSE,
1199 "plDepends" => array(),
1200 "plPriority" => 0,
1201 "plSection" => array("admin"),
1202 "plCategory" => array("groups"),
1203 "plProvidedAcls"=> array(
1204 "gosaMemberApplication" => _("Application"),
1205 "FAIrelease" => _("Release"),
1206 "gosaApplicationParameter" => _("Application parameter"))
1207 ));
1208 }
1209 }
1210 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1211 ?>