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 print_a($this);
390 /* Log view */
391 if($this->is_account && !$this->view_logged){
392 $this->view_logged = TRUE;
393 new log("view","groups/".get_class($this),$this->dn);
394 }
396 /* Check if department was selected */
397 if((isset($_GET['act']))&&($_GET['act']=="depopen")){
398 $dep = base64_decode($_GET['depid']);
399 $this->curbase =$dep;
400 }
402 /* Check if category was selected */
403 if((isset($_GET['act']))&&($_GET['act']=="open") && (empty($_GET['id']) || isset($this->Categories[base64_decode($_GET['id'])]))){
404 $this->curCatDir = base64_decode($_GET['id']);
405 }
407 /* Do we need to flip is_account state? */
408 if(isset($_POST['modify_state'])){
409 if($this->is_account && $this->acl_is_removeable()){
410 $this->is_account= FALSE;
411 }elseif(!$this->is_account && $this->acl_is_createable()){
412 $this->is_account= TRUE;
413 }
414 }
416 /* Do we represent a valid group? */
417 if (!$this->is_account && $this->parent === NULL){
418 $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\"> <b>".
419 _("This 'dn' is no appgroup.")."</b>";
420 return ($display);
421 }
423 /* Show tab dialog headers */
424 $display= "";
425 if ($this->parent !== NULL){
426 if ($this->is_account){
427 $display= $this->show_disable_header(_("Remove applications"),
428 _("This group has application features enabled. You can disable them by clicking below."));
429 } else {
430 $display.= $this->show_enable_header(_("Create applications"),
431 _("This group has application features disabled. You can enable them by clicking below."));
432 return ($display);
433 }
434 }
436 /* Check acl, applications must be readable */
437 if(!$this->check_acls()){
438 $display .= "<img src='images/button_cancel.png' alt='"._("ACL")."' class='center'>
439 <b>"._("Insufficient permissions")."</b>
440 <p>".
441 _("You do not have permission to query application entries. All your changes will not be saved.").
442 "</p><p class='seperator'> </p>";
443 $this->no_release_acls = true;
444 }
447 /* Add Categorie */
448 if((isset($_POST['AddCat']))&&(isset($_POST['CatName']))&&(!empty($_POST['CatName']))){
450 /* Only allow adding a category, if it is allowed */
451 if($this->acl_is_writeable("gosaMemberApplication",$this->no_release_acls)){
453 if(preg_match("/[\\\\\/]/i",$_POST['CatName'])){
454 print_red(_("Invalid character in category name."));
455 }elseif(!in_array($_POST['CatName'],$this->Categories)){
456 if(empty($this->curCatDir)){
457 $this->Categories[$_POST['CatName']]=$_POST['CatName'];
458 }else{
459 $this->Categories[$this->curCatDir."/".$_POST['CatName']]=$_POST['CatName'];
460 }
461 }else{
462 print_red(_("The specified category already exists."));
463 }
464 }
465 }
468 $this->reload();
469 $this->diffAppsInReleases();
471 /* Check POST variables for commands
472 to add/remove some applications */
473 $only_once = false;
474 if($this->acl_is_writeable("gosaMemberApplication",$this->no_release_acls)){
476 /* Walk through posts */
477 foreach($_POST as $name => $value){
479 /* Add a seperator to current category */
480 if((preg_match("/AddSep_/",$name))&&(!$only_once)){
481 $only_once = true;
482 $n = preg_replace("/AddSep_/","",$name);
483 $val= preg_replace("/_.*$/","",$n);
484 $this->AddSeperator($val);
485 }
487 /* Delete application | seperator entry */
488 if((preg_match("/DelApp_/",$name))&&(!$only_once)){
489 $only_once = true;
491 if(preg_match("/DelApp___SEPARATOR__/",$name)) {
492 $n= preg_replace("/DelApp___SEPARATOR__/","",$name);
493 $val= "__SEPARATOR__".preg_replace("/_.*$/","",$n);
494 }else{
495 $n = preg_replace("/DelApp_/","",$name);
496 $val= preg_replace("/_.*$/","",$n);
497 }
499 foreach($this->gosaMemberApplication as $key => $cat){
500 foreach($cat as $key2 => $app){
501 if($app['App'] == $val){
502 unset($this->gosaMemberApplication[$key][$key2]);
503 if(isset($this->used_apps[$val])){
504 foreach($this->getParameters($val) as $para){
505 if(isset($this->appoption[$para])){
506 unset($this->appoption[$para]);
507 }
508 }
509 unset($this->used_apps[$val]);
510 }
511 }
512 }
513 }
514 }
516 if(preg_match("/DelCat_/",$name) && !$only_once){
517 $only_once =TRUE;
518 $cat = preg_replace("/DelCat_/","",$name);
519 $cat = trim(base64_decode( preg_replace("/_.*$/","",$cat)));
521 $free_apps = array();
523 if(isset($this->gosaMemberApplication[$cat]) && is_array($this->gosaMemberApplication[$cat])){
524 foreach($this->gosaMemberApplication[$cat] as $app){
525 $free_apps[] = $app['App'];
526 }
527 unset($this->gosaMemberApplication[$cat]);
528 unset($this->Categories[$cat]);
529 }
530 foreach($this->Categories as $key => $name){
531 if(preg_match("/^".normalizePreg($cat)."\/.*/",$key)){
532 foreach($this->gosaMemberApplication[$key] as $app){
533 $free_apps[] = $app['App'];
534 }
535 unset($this->gosaMemberApplication[$key]);
536 unset($this->Categories[$key]);
537 }
538 }
539 foreach($free_apps as $app){
540 if(isset($this->used_apps[$app])){
541 unset($this->used_apps[$app]);
542 }
543 }
544 }
546 /* Edit application parameter */
547 if((preg_match("/EdiApp_/",$name))&&(!$only_once)){
549 $only_once = true;
550 $appname = $value;
551 $appname = preg_replace("/EdiApp_/","",$name);
552 $appname = preg_replace("/_.*$/","",$appname);
554 /* We've got the appname, get parameters from ldap */
555 $ldap= $this->config->get_ldap_link();
557 /* Check if we have release management enabled */
558 $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs'));
559 if(!empty($tmp)){
561 /* Get application parameter from ldap */
562 $tmp = array_flip($this->Releases);
563 $base = $tmp[$this->FAIrelease];
564 $ldap->cd($base);
565 $ldap->search("(&(objectClass=gosaApplication)(cn=$appname))",array("gosaApplicationParameter"));
566 $found = "";
567 while($attrs = $ldap->fetch()) {
568 if(preg_match("/cn=".$appname.",".$base."/",$attrs['dn'])){
569 $found = $attrs['dn'];
570 }
571 }
572 $ldap->cat($found, array("gosaApplicationParameter"));
573 }else{
575 /* Get application parameter from ldap */
576 $ldap->cd($this->config->current['BASE']);
577 $ldap->search("(&(objectClass=gosaApplication)(cn=$appname))",array("gosaApplicationParameter"));
578 }
580 /* Check if this application is unique */
581 if ($ldap->count() != 1){
582 print_red (_("The selected application name is not uniq. Please check your LDAP."));
583 } else {
585 /* Get parameter */
586 $attrs= $ldap->fetch();
587 if(isset($attrs['gosaApplicationParameter'])){
588 $this->dialog= TRUE;
590 /* Fill name and value arrays */
591 for ($i= 0; $i<$attrs['gosaApplicationParameter']['count']; $i++){
592 $option= preg_replace('/^[^:]+:/', '',
593 $attrs['gosaApplicationParameter'][$i]);
594 $name= preg_replace('/:.*$/', '',
595 $attrs['gosaApplicationParameter'][$i]);
596 $this->option_name[$i]= $name;
598 /* Fill with values from application, default should be
599 loaded by the external scripts */
600 if (isset($this->appoption[$name])){
601 $this->option_value[$i]= $this->appoption[$name];
602 }
603 }
605 /* Create edit field */
606 $table= "<table summary=\"\">";
607 for ($i= 0; $i < count($this->option_name); $i++){
608 if (isset($this->option_value[$i])){
609 $value= $this->option_value[$i];
610 } else {
611 $value= "";
612 }
613 $table.="<tr><td>".$this->option_name[$i]."</td><td>".
614 "<input name=\"value$i\" size=60 maxlength=250 ".
615 "value=\"".$value."\"><br></td></tr>";
616 }
617 $table.= "</table>";
618 $this->table= $table;
619 } else {
620 print_red (_("The selected application has no options."));
621 }
622 }
623 }
624 }
625 }
627 /* Add multiple */
628 if(isset($_POST['AddApps'])){
629 foreach($_POST as $name => $value){
630 if(preg_match("/AddApp_/",$name)){
631 $app = preg_replace("/AddApp_/","",$name);
632 $this->addApp($app);
633 }
634 }
635 }
637 /* Add application with post */
638 if((isset($_GET['act']))&&($_GET['act']=="add")){
639 $this->used_apps[$_GET['id']]= $_GET['id'];
640 asort($this->used_apps);
641 $this->addApp($_GET['id']);
642 }
644 /* Cancel edit options? */
645 if (isset($_POST['edit_options_cancel'])){
646 $this->dialog= FALSE;
647 }
649 /* Finish edit options? */
650 if (isset($_POST['edit_options_finish'])){
651 $this->dialog= FALSE;
653 /* Save informations passed by the user */
654 $this->option_value= array();
655 for ($i= 0; $i<count($this->option_name); $i++){
656 $this->appoption[$this->option_name[$i]]= $_POST["value$i"];
657 $this->is_modified= TRUE;
658 }
659 }
661 /* Prepare templating stuff */
662 $smarty= get_smarty();
663 $smarty->assign("used_apps", $this->used_apps);
664 $apps= array();
665 foreach ($this->apps as $key => $value){
666 if (!array_key_exists($key, $this->used_apps)){
667 $apps["$key"]= "$value";
668 }
669 }
672 /* Create application list */
673 $div = new divSelectBox("appgroup");
674 $div->SetHeight(300);
675 $departments = array();
676 $res = get_list("(objectClass=gosaDepartment)", "application", $this->curbase,array("description","cn","ou"),GL_SIZELIMIT);
677 foreach($res as $value){
678 $fdn = $value['dn'];
679 $fdn = preg_replace("/".normalizePreg($this->curbase)."/","",$fdn);
680 $fdn= @LDAP::fix($fdn);
681 if($value["description"][0]!=".."){
682 $departments[$value['dn']]= convert_department_dn($fdn)." - [".$value["description"][0]."]";
683 }else{
684 $departments[$value['dn']]=convert_department_dn($fdn)." ["._("Back")."]";
685 }
686 }
688 /* Create 'open' and 'add' links */
689 if($this->acl_is_writeable("gosaMemberApplication",$this->no_release_acls)){
690 $linkadd = "<a href='?plug=".$_GET['plug']."&act=add&id=%s'>%s</a>";
691 }else{
692 $linkadd = "%s";
693 }
694 $linkopen = "<a href='?plug=".$_GET['plug']."&act=depopen&depid=%s'>%s</a>";
696 /* Create base back entry */
697 $base_back = preg_replace("/^[^,]+,/","",$this->curbase);
698 if((strlen($base_back)>= strlen($this->config->current['BASE']))&&($this->curbase!=$this->config->current['BASE'])){
699 $div->AddEntry(array(
700 array("string"=>sprintf($linkopen,base64_encode($base_back),".. ["._("back")."]"),
701 "attach"=>"style='border:0px;'")
702 ));
703 }
705 /* Append departments for current base */
706 foreach($departments as $key => $app){
707 $div->AddEntry(array(
708 array("string"=>"<img class='center' src='images/folder.png' alt='"._("department")."'> ".sprintf($linkopen,base64_encode($key),$app),
709 "attach"=>"style='border:0px;'")
710 ));
711 }
713 /* Add applications found on this base */
714 foreach($apps as $key => $app){
715 $div->AddEntry(array(
716 array("string"=>sprintf("<input class='center' type='checkbox' value='1' name='AddApp_%s'>",$key).
717 "<img class='center' src='images/select_application.png' alt='"._("application")."'> ".sprintf($linkadd,$key,$app),
718 "attach"=>"style='border:0px;'")
719 ));
720 }
722 /* Create list of used/assigned applications */
723 $div2 = new divSelectBox("appgroup");
724 $div2->SetHeight(300);
726 /* Check acls to create "edit/remove" category links */
727 if(!$this->acl_is_writeable("gosaMemberApplication",$this->no_release_acls)){
728 $linkopen = "<img class='center' src='images/folder.png' alt=\"\"> <a href='?plug=".$_GET['plug']."&act=open&id=%s'>%s</a>";
729 $catremove = " <img src='images/empty.png' alt=' '>";
730 $catupdown = "";
731 }else{
732 $linkopen = "<img class='center' src='images/folder.png' alt=\"\"> <a href='?plug=".$_GET['plug']."&act=open&id=%s'>%s</a>";
733 $catremove = " <input type='image' src='images/edittrash.png' title='"._("Delete entry")."' name='DelCat_%s' value='%s'>";
734 $catupdown = "<a href='?plug=".$_GET['plug']."&act=cat_up&id=%s'>".
735 "<img align='top' alt=\"\" src='images/sort_up.png' border=0 title='"._("Move up")."'>".
736 "</a> ".
737 "<a href='?plug=".$_GET['plug']."&act=cat_down&id=%s'>".
738 "<img alt=\"\" src='images/sort_down.png' title='"._("Move down")."' border=0>".
739 "</a>";
740 }
742 /* Add back category for current category */
743 if(empty($this->curCatDir)){
744 $cnt =0;
745 }else{
746 $cnt = count(split("/",$this->curCatDir));
747 $tmp = split("/",$this->curCatDir);
748 $bbk = "";
749 for($i = 0 ; $i < ($cnt -1 ) ; $i++){
750 $bbk .= $tmp[$i]."/";
751 }
752 $bbk = preg_replace("/\/$/","",$bbk);
753 $div2 ->AddEntry(array(array("string"=>sprintf($linkopen,base64_encode($bbk),".. ["._("Back")."]")),array("string"=>" ","attach"=>"style='border-right:0px;'")));
754 }
756 /* Add sub categories */
757 $this->GetSubdirs($this->curCatDir);
758 foreach($this->GetSubdirs($this->curCatDir) as $path => $name){
759 $div2 ->AddEntry(array(
760 array("string"=>sprintf($linkopen,base64_encode($path),$name)),
761 array("string"=>preg_replace("/%s/",base64_encode($path),$catupdown.$catremove),
762 "attach"=>"align='right' style='width:80px;border-right:0px;'")));
763 }
765 /* Create priority & seperator links */
766 $separator ="<hr size=1>";
767 if($this->acl_is_writeable("gosaMemberApplication",$this->no_release_acls)){
768 $sep = "<input type='image' src='images/back.png' title='"._("Insert seperator")."' value='%s' name='AddSep_%s'>";
769 $upudown = "<a href='?plug=".$_GET['plug']."&act=one_up&id=%s'>".
770 " <img alt='{t}sort{/t}' align='top' src='images/sort_up.png' title='"._("Move up")."' border=0>".
771 "</a> ".
772 "<a href='?plug=".$_GET['plug']."&act=one_down&id=%s'>".
773 " <img alt='{t}sort{/t}' src='images/sort_down.png' title='"._("Move down")."' border=0>".
774 "</a> ".
775 "<input type='image' src='images/edittrash.png' title='"._("Delete entry")."' name='DelApp_%s' value='%s' alt='{t}delete{/t}' >";
776 }else{
777 $sep = "";
778 $upudown = "";
779 }
781 /* Create edit link */
782 if($this->acl_is_writeable("gosaApplicationParameter",$this->no_release_acls)){
783 $edit= " <input type='image' src='images/edit.png' title='"._("Edit entry")."' name='EdiApp_%s' value='%s' alt='{t}edit{/t}' >";
784 }else{
785 $edit= "";
786 }
788 /* Get differences to mark those entries that have changed from last edit. */
789 $Differences = $this->diffAppsInReleases();
791 /* Walk through entries an append them to list */
792 if(isset($this->gosaMemberApplication[$this->curCatDir])){
793 foreach($this->gosaMemberApplication[$this->curCatDir] as $cat => $entry){
795 /* Add seperator */
796 if(preg_match("/__SEPARATOR__/",$entry['App'])){
797 $div2 ->AddEntry(array(array("string"=>$separator),
798 array("string"=>preg_replace("/\%s/",htmlentities($entry['App']),$upudown),"attach"=>"align='right' style='border-right:0px;'")));
799 }else{
801 /* Add application */
803 $image = "";
804 /* Check if application was available within selected release
805 * or application list if release management is not active
806 */
807 if(!in_array($entry['App'],$this->AllAppsForRelease)){
809 /* release managent is active
810 */
811 if(!$this->enableReleaseManagement){
812 $image = "<img class='center' alt='R' src='images/select_invalid_application.png'
813 title='"._("This application is no longer available.")."'> ";
814 }else{
815 $image = "<img class='center' alt='F' src='images/select_invalid_application.png'
816 title=\"".sprintf(_("This application is not available in any release named %s."),$this->FAIrelease)."\"> ";
817 }
819 }elseif(isset($Differences[$entry['App']]) && ($Differences[$entry['App']] == true)) {
820 $entry['App'].=" <i>["._("Check parameter")."]</i>";
821 $image = "<img class='center' src='images/select_invalid_application.png'
822 title='"._("This application has changed parameters.")."'> ";
823 }else{
824 $image = "<img class='center' src='images/select_application.png' alt=\"\"> ";
825 }
827 $div2->AddEntry(array(array("string"=>sprintf($image."%s",$entry['App'])),
828 array("string"=>preg_replace("/\%s/",htmlentities($entry['App']),$sep.$edit.$upudown),
829 "attach"=>"align='right' style='width:100px;border-right:0px;'")));
830 }
831 }
832 }
834 /* Assign created div lists to template */
835 $smarty->assign("UsedApps", $div2->DrawList());
836 $smarty->assign("List", $div->DrawList());
837 $smarty->assign("apps", $apps);
839 $smarty->assign("enableReleaseManagement",$this->enableReleaseManagement);
841 $smarty->assign("ReleaseSelectAble", false);
842 $smarty->assign("Release", $this->FAIrelease);
844 if($this->enableReleaseManagement){
845 $smarty->assign("FAIrelease", $this->FAIrelease);
846 $smarty->assign("Releases", $this->Releases);
848 if(!$this->no_release_acls && count($this->Releases)){
849 $smarty->assign("ReleaseSelectAble", true);
850 }
851 }
853 /* Set acls to template */
854 $tmp = $this->plInfo();
855 foreach($tmp['plProvidedAcls'] as $acl => $translation){
856 $smarty->assign($acl."ACL",$this->getacl($acl,$this->no_release_acls));
857 }
859 /* Show main page */
860 if (is_object($this->dialog)){
861 $smarty->assign("table", $this->table);
862 $display.= $smarty->fetch (get_template_path('application_options.tpl', TRUE,dirname(__FILE__)));
863 } else {
864 $display.= $smarty->fetch (get_template_path('application.tpl', TRUE,dirname(__FILE__)));
865 }
867 return ($display);
868 }
871 function getReleases()
872 {
873 /* Only display those releases that we are able to read */
874 $dn = $this->config->current['BASE'];
875 $filter = "(&(objectClass=organizationalUnit)(objectClass=FAIbranch))";
876 $res = get_list($filter,"application", $dn, array("ou"), GL_SUBSEARCH);
878 $ret =array();
879 foreach($res as $attrs){
880 if(preg_match("/ou=apps,/",$attrs['dn'])){
881 $bb = preg_replace("/ou=apps,.*/","",$attrs['dn']);
882 $parts = array_reverse(split("ou=",$bb));
884 $str ="";
885 foreach($parts as $part){
886 if(empty($part)) {
887 continue;
888 }
889 $str .= str_replace(",","",$part)."/";
890 }
891 $name = preg_replace("/\/$/","",$str);
892 if(empty($name)) {
893 $name ="/";
894 }
895 $ret[$attrs['dn']] = $name;
896 }
897 }
898 return($ret);
899 }
901 function save_object()
902 {
904 /* Move category one position up or down */
905 if((isset($_GET['act']))&&(($_GET['act'] == "cat_up")||($_GET['act']=="cat_down"))){
906 if($_GET['act']=="cat_up"){
907 $this->catUp(base64_decode($_GET['id']));
908 }
909 if($_GET['act']=="cat_down"){
910 $this->catDown(base64_decode($_GET['id']));
911 }
912 }
914 /* Move application one position up or down */
915 if((isset($_GET['act']))&&(($_GET['act'] == "one_up")||($_GET['act']=="one_down"))){
916 if(isset($_GET['id'])){
917 $id = $_GET['id'];
918 $act = $_GET['act'];
920 if($act == "one_up"){
921 $this->getOneUp($id);
922 }elseif($act == "one_down") {
923 $this->getOneDown($id);
924 }
925 }
926 }
929 plugin::save_object();
930 }
933 function remove_from_parent()
934 {
935 if(!$this->initially_was_account){
936 return;
937 }
939 plugin::remove_from_parent();
941 $ldap= $this->config->get_ldap_link();
942 $ldap->cd($this->dn);
943 $this->cleanup();
945 $ldap->modify ($this->attrs);
946 new log("remove","group/".get_class($this),$use_dn,array_keys($this->attrs),$ldap->get_error());
947 show_ldap_error($ldap->get_error(), sprintf(_("Removing of groups/applications with dn '%s' failed."),$this->dn));
949 /* Optionally execute a command after we're done */
950 $this->handle_post_events("remove");
951 }
954 /* Save to LDAP */
955 function save()
956 {
957 /* Skip saving application settings, if we do not have release acls */
958 if($this->no_release_acls){
959 new log("security","groups/".get_class($this),$this->dn,array(),"Skip saving group application extension. Caused by insufficient acls");
961 return;
962 }
964 plugin::save();
968 /* Copy members */
969 $this->Categories[""]="";
970 $this->attrs["gosaMemberApplication"]= array();
971 $this->attrs["gosaApplicationParameter"]= array();
972 $cat_id= 0 ;
973 foreach($this->Categories as $name => $cats){
974 $i =0;
975 if(isset($this->gosaMemberApplication[$name])){
976 foreach($this->gosaMemberApplication[$name] as $entry){
977 if(!preg_match("/__SEPARATOR__/",$entry['App'])){
978 $this->attrs["gosaMemberApplication"][]= $entry['App']."|".$name."|".$i;
979 $i ++;
980 }
981 }
982 }
983 if(($i==0)&&(!empty($name))){
984 $this->attrs["gosaMemberApplication"][]= "|".$name."|".$cat_id;
985 }
986 $cat_id++;
987 }
991 /* Are there application parameters to be saved */
992 $this->attrs['gosaApplicationParameter']= array();
993 foreach($this->appoption as $name => $value){
994 if ($value != ""){
995 $this->attrs['gosaApplicationParameter'][]= "$name:$value";
996 }
997 }
999 /* Write back to LDAP */
1000 $ldap= $this->config->get_ldap_link();
1001 $ldap->cd($this->dn);
1002 $this->cleanup();
1003 $ldap->modify ($this->attrs);
1005 if($this->initially_was_account){
1006 new log("modify","group/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1007 }else{
1008 new log("create","group/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1009 }
1011 show_ldap_error($ldap->get_error(), sprintf(_("Saving of groups/applications with dn '%s' failed."),$this->dn));
1013 /* Optionally execute a command after we're done */
1014 if ($this->initially_was_account == $this->is_account){
1015 if ($this->is_modified){
1016 $this->handle_post_events("modify");
1017 }
1018 } else {
1019 $this->handle_post_events("add");
1020 }
1022 }
1024 function check()
1025 {
1026 /* Call common method to give check the hook */
1027 $message= plugin::check();
1029 return ($message);
1030 }
1033 function reload()
1034 {
1035 /* Generate applist */
1036 $this->apps= array();
1038 /* Special handling for release managed apps */
1039 $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs'));
1040 if(!empty($tmp) && count($this->Releases)){
1041 $this->enableReleaseManagement = true;
1043 /* Check if release is available */
1044 $tmp = array_flip($this->Releases);
1045 if(isset($tmp[$this->FAIrelease])){
1046 $base = $tmp[$this->FAIrelease];
1047 }else{
1049 /* Release is not available, check if there is an alternative */
1050 $old_r = $this->FAIrelease;
1051 $k = key($tmp);
1053 if(isset($tmp[$k])){
1055 /* We have found an alternative release name */
1056 $r = $tmp[$k];
1057 $this->FAIrelease = $k;
1058 $base = $r;
1060 /* Display msg */
1061 if(!(!$this->initially_was_account && $old_r =="/")){
1062 print_red(sprintf(_("Can't resolve the release name '%s', setting release name to '%s'. Possibly the objects base has changed."),$old_r,$k));
1063 }
1064 }else{
1066 /* There are no releases available ... */
1067 print_red(_("There are no releases available. You will not be able to select another release."));
1068 return;
1069 }
1070 }
1072 /* Get applications for this release */
1073 $base = preg_replace("/ou=apps,.*$/","ou=apps,".$this->curbase,$base);
1074 $res = get_list("(objectClass=gosaApplication)","application",$base,array("*"));
1075 }else{
1077 /* Get applications for this base */
1078 $res = get_list("(objectClass=gosaApplication)","application","ou=apps,".$this->curbase,array("*"));
1079 }
1081 /* Append applications */
1082 foreach($res as $attrs){
1083 if (isset($attrs["description"][0])){
1084 $this->apps[$attrs["cn"][0]]=
1085 $attrs["cn"][0]." (".
1086 $attrs["description"][0].")";
1087 } else {
1088 $this->apps[$attrs["cn"][0]]=
1089 $attrs["cn"][0];
1090 }
1091 }
1093 /* Get all apps ... */
1094 $res = get_list("objectClass=gosaApplication","application",$this->config->current['BASE'],array("gosaApplicationParameter","cn"),GL_SUBSEARCH);
1095 $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs'));
1096 $this->AllAppsForRelease = array();
1097 if(!empty($tmp)){
1098 $tmp = array_flip($this->Releases);
1099 foreach($res as $attrs){
1101 $testdn = preg_replace("/ou=apps,.*$/","ou=apps",$attrs['dn']);
1102 $testdn = preg_replace("/^[^,]+/","",$testdn);
1103 $testdn = preg_replace("/^,/","",$testdn);
1105 if($testdn == preg_replace("/ou=apps,.*$/","ou=apps",$tmp[$this->FAIrelease])){
1106 $this->AllAppsForRelease[$attrs['dn']] = $attrs['cn'][0];
1107 $this->AllAppsForReleaseParameter[$this->FAIrelease][$attrs['cn'][0]] = $attrs;
1108 }
1109 }
1110 }else{
1111 foreach($res as $attrs){
1112 $this->AllAppsForRelease[$attrs['dn']] = $attrs['cn'][0];
1113 }
1114 }
1116 natcasesort ($this->apps);
1117 reset ($this->apps);
1119 if(is_array($this->gosaMemberApplication))
1120 foreach ($this->gosaMemberApplication as $cat){
1121 if(is_array($cat))
1122 foreach($cat as $entry){
1123 $this->used_apps[$entry['App']]= $entry['App'];
1124 }
1125 }
1126 }
1129 function addApp($cn)
1130 {
1131 if((isset($this->gosaMemberApplication[$this->curCatDir]))&&(is_array($this->gosaMemberApplication[$this->curCatDir]))){
1132 foreach($this->gosaMemberApplication[$this->curCatDir] as $entry){
1133 if($entry['App'] == $cn) return;
1134 }
1135 }
1136 $this->gosaMemberApplication[$this->curCatDir][]= array("App"=>$cn);
1137 $this->used_apps[$cn]=$cn;
1138 $this->is_modified= TRUE;
1139 }
1142 function removeApp($cn)
1143 {
1144 $temp= array();
1145 foreach ($this->gosaMemberApplication as $value){
1146 if ($value != $cn){
1147 $temp[]= $value;
1148 }
1149 }
1150 $this->gosaMemberApplication= $temp;
1151 $this->is_modified= TRUE;
1152 }
1154 function getParameters($app)
1155 {
1156 $tmp = $this->getReleases();
1157 $ret = array();
1158 if(in_array($this->FAIrelease,$tmp)){
1159 $tmp2 = array_flip($tmp);
1160 $base = $tmp2[$this->FAIrelease];
1161 $ldap = $this->config->get_ldap_link();
1162 $ldap->cd($this->config->current['BASE']);
1163 $ldap->search("(&(objectClass=gosaApplication)(cn=".$app.")(gosaApplicationParameter=*))",array("gosaApplicationParameter"));
1164 if($ldap->count()){
1165 $attrs = $ldap->fetch();
1166 for($i = 0 ; $i < $attrs['gosaApplicationParameter']['count'] ; $i ++ ){
1167 $name = preg_replace("/:.*$/","",$attrs['gosaApplicationParameter'][$i]);
1168 $ret[$name] = $name;
1169 }
1170 }
1171 }
1172 return($ret);
1173 }
1175 function GetSubdirs($dir)
1176 {
1177 $ret = array();
1178 $tmp1 = split("/",$this->curCatDir);
1180 foreach($this->Categories as $path=>$cat){
1181 $tmp2 = split("/",$path);
1183 if((empty($this->curCatDir))&&(!preg_match("/\//",$path))){
1184 $abort = false;
1185 }elseif(((count($tmp1))+1) == (count($tmp2))){
1186 $abort = false;
1187 for($i = 0 ; $i < count($tmp1) ; $i++){
1188 if($tmp1[$i] != $tmp2[$i]){
1189 $abort = true;
1190 }
1191 }
1192 }else{
1193 $abort= true;
1194 }
1195 if(!$abort){
1196 $ret[$path]=$cat;
1197 }
1198 }
1199 return($ret);
1200 }
1203 function PrepareForCopyPaste($source)
1204 {
1205 $s = new appgroup($this->config,$source['dn']);
1206 $this->FAIrelease = $this->InitialFAIrelease = $s->FAIrelease;
1207 $this->gosaMemberApplication = $s->gosaMemberApplication;
1208 $this->appoption = $s->appoption;
1209 $this->Categories = $s->Categories;
1210 }
1213 /* Return plugin informations for acl handling */
1214 function plInfo()
1215 {
1216 return (array(
1217 "plShortName" => _("Applications"),
1218 "plDescription" => _("Group applications"),
1219 "plSelfModify" => FALSE,
1220 "plDepends" => array(),
1221 "plPriority" => 0,
1222 "plSection" => array("admin"),
1223 "plCategory" => array("groups"),
1224 "plProvidedAcls"=> array(
1225 "gosaMemberApplication" => _("Application"),
1226 "FAIrelease" => _("Release"),
1227 "gosaApplicationParameter" => _("Application parameter"))
1228 ));
1229 }
1230 }
1231 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1232 ?>