133717d6c59ea57244a7a040dafe50b729e8d47d
1 <?php
2 class appgroup extends plugin
3 {
4 /* CLI vars */
5 var $cli_summary= "Manage application groups";
6 var $cli_description= "Some longer text\nfor help";
7 var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
9 /* Appgroup attributes */
10 var $gosaMemberApplication= array();
12 /* Helpers */
13 var $departments = ""; // All departments within $this->curbase;
14 var $apps = array(); // All available applications
15 var $used_apps = array(); // Specifies which applications are currently assigned
17 var $option_name = array();
18 var $option_value = array();
19 var $appoption = array();
21 var $table = "";
22 var $curbase = "";
23 var $curCatDir ;
24 var $curCatDepth =0; //
26 /* attribute list for save action */
27 var $attributes = array("gosaMemberApplication","gosaApplicationParameter");
28 var $objectclasses = array("gosaApplicationGroup");
30 var $FAIrelease = "/";
31 var $InitialFAIrelease = "/";
32 var $Releases = array();
33 var $enableReleaseManagement = false;
35 var $AllAppsForRelease = array();
36 var $AllAppsForReleaseParameter = array();
38 var $CopyPasteVars = array("Categories");
39 var $gosaApplicationParameter ;
42 function appgroup ($config, $dn= NULL)
43 {
45 /* prepare group app for release management */
46 $tmp = search_config($config->data,"faiManagement","CLASS");
47 if(!empty($tmp)){
48 $this->enableReleaseManagement = true;
49 $this->objectclasses [] = "FAIreleaseTag";
50 $this->attributes[] = "FAIrelease";
51 }
53 plugin::plugin ($config, $dn);
55 /* In some case of old applikations with old release tag saving, we
56 must reassign is_account state.
57 (Or if release management wasn't activated before creating this app) */
58 if($this->enableReleaseManagement){
60 /* Release management is activated && this is a valid group app account,
61 but no release class was found, so activate is_account flag */
62 if($dn != "new" && ( in_array("gosaApplicationGroup",$this->attrs['objectClass'])) &&
63 (!in_array("FAIreleaseTag",$this->attrs['objectClass']))){
64 $this->is_account =true;
65 }
66 }
69 /* Load member applications */
70 if (isset ($this->attrs["gosaMemberApplication"][0])){
71 $this->gosaMemberApplication = array();
72 for ($i= 0; $i<$this->attrs["gosaMemberApplication"]["count"]; $i++){
73 $this->gosaMemberApplication[]=
74 $this->attrs["gosaMemberApplication"][$i];
75 }
76 }
78 /* Load application options */
79 if (isset($this->attrs['gosaApplicationParameter'])){
80 for ($i= 0; $i<$this->attrs['gosaApplicationParameter']['count']; $i++){
81 $option= preg_replace('/^[^:]+:/', '',
82 $this->attrs['gosaApplicationParameter'][$i]);
83 $name= preg_replace('/:.*$/', '',
84 $this->attrs['gosaApplicationParameter'][$i]);
85 $this->appoption[$name]= $option;
86 }
87 }
89 /* Parse MemberApplication*/
90 $tmp = array();
91 $tmp2 = array();
92 $prios = array();
93 $cats = array();
95 foreach($this->gosaMemberApplication as $memberApp){
96 if(preg_match("/\|/i",$memberApp)){
98 $tmp = split("\|",$memberApp);
100 if(!empty($tmp[0])){
101 $tmp2[$tmp[1]][$tmp[2]] = array("App"=>$tmp[0]);
102 }
103 if(!empty($tmp[1])){
104 $n = split("/",$tmp[1]);
105 $c = count($n);
106 $cats [$tmp[1]] = $n[$c-1];
107 }
108 $prios[$tmp[1]][$tmp[2]] = $tmp[2];
109 }else{
110 $tmp2[]['App'] = $memberApp;
111 }
112 }
114 $this->Categories = $cats;
116 $this->gosaMemberApplication = $tmp2;
117 $cats[""]="";
118 foreach($cats as $cat ){
119 if((isset($prios[$cat]))&&(count($prios[$cat]))){
120 $max = max($prios[$cat]);
121 $min = 1;//min($prios[$cat]);
122 $last = false;
123 for($i = $min ; $i < $max ; $i++){
124 if(!isset($prios[$cat][$i])){
125 if($last == false){
126 $this->gosaMemberApplication[$cat][$i]['App'] = "__SEPARATOR__".$i;
128 $last = true;
129 }
130 }else{
131 $last = false;
132 }
133 }
134 }
135 }
137 $tmp = array();
138 foreach($this->gosaMemberApplication as $key => $entries){
139 ksort ($entries);
140 foreach($entries as $entry){
141 $tmp[$key][]= $entry;
142 }
143 }
144 $this->gosaMemberApplication = $tmp;
145 $this->curbase = $this->config->current['BASE'];
147 /* Get required release informations */
148 if($this->enableReleaseManagement){
149 $this->InitialFAIrelease = $this->FAIrelease;
150 $this->Releases = $this->getReleases();
151 }
152 }
155 /* Combine new array */
156 function combineArrays($ar0,$ar1,$ar2)
157 {
158 $ret = array();
159 if(is_array($ar0))
160 foreach($ar0 as $ar => $a){
161 $ret[$ar]=$a;
162 }
163 if(is_array($ar1))
164 foreach($ar1 as $ar => $a){
165 $ret[$ar]=$a;
166 }
167 if(is_array($ar2))
168 foreach($ar2 as $ar => $a){
169 $ret[$ar]=$a;
170 }
171 return($ret);
172 }
174 function getpos($atr,$attrs)
175 {
176 $i = 0;
177 foreach($attrs as $attr => $name) {
178 $i++;
179 if($attr == $atr){
180 return($i);
181 }
182 }
183 return(-1);
184 }
186 function diffAppsInReleases()
187 {
188 /* Only diff if it is required
189 */
190 $ret =array();
192 /* If current release has changed */
193 if($this->FAIrelease != $this->InitialFAIrelease){
195 /* Walk through all apps which are currently displayed */
196 if(isset($this->gosaMemberApplication[$this->curCatDir])){
198 foreach($this->gosaMemberApplication[$this->curCatDir] as $entry){
200 /* If application is also available in new release, check if parameter differs */
201 if(in_array($entry['App'],$this->AllAppsForRelease)){
203 $old = array(); // Old application parameter
204 $new = array(); // New parameters
206 /* There are possibly no parameters specified */
207 if(isset($this->AllAppsForReleaseParameter[$this->InitialFAIrelease][$entry['App']])){
208 $old = $this->AllAppsForReleaseParameter[$this->InitialFAIrelease][$entry['App']];
209 }
211 if(isset($this->AllAppsForReleaseParameter[$this->FAIrelease][$entry['App']])){
212 $new = $this->AllAppsForReleaseParameter[$this->FAIrelease][$entry['App']];
213 }
215 /* Both (old & new) have no gosaApplicationParameter
216 */
217 if((!isset($old['gosaApplicationParameter'])) && (!isset($new['gosaApplicationParameter']))){
218 $ret[$entry['App']] = false;
220 /* Both got gosaApplicationParameter
221 */
222 }elseif((isset($old['gosaApplicationParameter'])) && (isset($new['gosaApplicationParameter']))){
223 if(array_differs($old['gosaApplicationParameter'],$new['gosaApplicationParameter'])){
224 $ret[$entry['App']] = true;
225 }else{
226 $ret[$entry['App']] = false;
227 }
228 }
229 /* Initialy had gosaApplicationParameter bot in new release not
230 */
231 }elseif((isset($old['gosaApplicationParameter'])) && (!isset($new['gosaApplicationParameter']))){
232 $ret[$entry['App']] = true;
234 /* Old release had no gosaApplicationParameter but new got some
235 */
236 }elseif((!isset($old['gosaApplicationParameter'])) && (isset($new['gosaApplicationParameter']))){
237 $ret[$entry['App']] = true;
238 }
239 }
240 }
241 }
242 return($ret);
243 }
245 /* TRansports the geiven Arraykey one position up*/
246 function ArrayUp($atr,$attrs)
247 {
248 $ret = $attrs;
249 $pos = $this->getpos($atr,$attrs) ;
250 $cn = count($attrs);
251 if(!(($pos == -1)||($pos == 1))){
252 $before = array_slice($attrs,0,($pos-2));
253 $mitte = array_reverse(array_slice($attrs,($pos-2),2));
254 $unten = array_slice($attrs,$pos);
255 $ret = array();
256 $ret = $this->combineArrays($before,$mitte,$unten);
257 }
258 return($ret);
259 }
262 /* TRansports the geiven Arraykey one position up*/
263 function ArrayDown($atr,$attrs)
264 {
265 $ret = $attrs;
266 $pos = $this->getpos($atr,$attrs) ;
267 $cn = count($attrs);
268 if(!(($pos == -1)||($pos == $cn))){
269 $before = array_slice($attrs,0,($pos-1));
270 $mitte = array_reverse(array_slice($attrs,($pos-1),2));
271 $unten = array_slice($attrs,($pos+1));
272 $ret = array();
273 $ret = $this->combineArrays($before,$mitte,$unten);
274 }
275 return($ret);
276 }
279 function catUp($id)
280 {
281 /* Get all cats depinding on current dir */
282 $cats = $this->GetSubdirs($this->curCatDir);
283 $newcats =$this->ArrayUp($id,$cats);
285 foreach($newcats as $cat => $name){
286 unset($this->Categories[$cat]);
287 }
288 foreach($newcats as $cat => $name){
289 $this->Categories[$cat]=$name;
290 }
291 }
294 function catDown($id)
295 {
296 /* Get all cats depinding on current dir */
297 $cats = $this->GetSubdirs($this->curCatDir);
299 $newcats =$this->ArrayDown($id,$cats);
301 foreach($newcats as $cat => $name){
302 unset($this->Categories[$cat]);
303 }
304 foreach($newcats as $cat => $name){
305 $this->Categories[$cat]=$name;
306 }
307 }
310 function getOneUp($appl)
311 {
312 $cat = $this->curCatDir;
313 $apps = $this->gosaMemberApplication[$cat];
315 $appsA = array();
316 foreach ($apps as $appkey => $name){
317 $appsA[$name['App']] =$name['App'];
318 }
320 $result = $this->ArrayUp($appl,$appsA);
322 $ret = array();
323 foreach($result as $app){
324 $ret[]=array("App"=>$app);
325 }
326 $this->gosaMemberApplication[$cat] = $ret;
327 }
330 function getOneDown($appl)
331 {
332 $cat = $this->curCatDir;
333 $apps = $this->gosaMemberApplication[$cat];
335 $appsA = array();
336 foreach ($apps as $appkey => $name){
337 $appsA[$name['App']] =$name['App'];
338 }
340 $result = $this->ArrayDown($appl,$appsA);
342 $ret = array();
343 foreach($result as $app){
344 $ret[]=array("App"=>$app);
345 }
346 $this->gosaMemberApplication[$cat] = $ret;
347 }
351 function AddSeperator($id)
352 {
353 $found = false;
354 $cat = "";
355 $tmp = array();
356 foreach($this->gosaMemberApplication[$this->curCatDir] as $appID => $app){
357 $tmp[] = $app;
358 if(($app['App'] == $id)&&(!$found)){
359 $cnt = count($this->gosaMemberApplication[$this->curCatDir]);
360 $tmp[] = array("App" => "__SEPARATOR__".($cnt+1));
361 $found = true;
362 }
363 }
364 if($found){
365 $this->gosaMemberApplication[$this->curCatDir]=$tmp;
366 }
367 }
369 function execute()
370 {
371 /* Call parent execute */
372 plugin::execute();
374 if((isset($_GET['act']))&&($_GET['act']=="depopen")){
375 $dep = base64_decode($_GET['depid']);
376 if(isset($this->config->idepartments[$dep])){
377 $this->curbase =$dep;
378 }
379 }
381 if((isset($_GET['act']))&&($_GET['act']=="open")){
382 $this->curCatDir = base64_decode($_GET['id']);
383 }
385 /* Do we need to flip is_account state? */
386 if(isset($_POST['modify_state'])){
387 if($this->is_account && $this->acl_is_removeable()){
388 $this->is_account= FALSE;
389 }elseif(!$this->is_account && $this->acl_is_createable()){
390 $this->is_account= TRUE;
391 }
392 }
394 /* Do we represent a valid group? */
395 if (!$this->is_account && $this->parent == NULL){
396 $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\"> <b>".
397 _("This 'dn' is no appgroup.")."</b>";
398 return ($display);
399 }
401 /* Show tab dialog headers */
402 $display= "";
403 if ($this->parent != NULL){
404 if ($this->is_account){
405 $display= $this->show_disable_header(_("Remove applications"),
406 _("This group has application features enabled. You can disable them by clicking below."));
407 } else {
408 $display.= $this->show_enable_header(_("Create applications"),
409 _("This group has application features disabled. You can enable them by clicking below."));
410 return ($display);
411 }
412 }
415 /* Add Categorie */
418 if((isset($_POST['AddCat']))&&(isset($_POST['CatName']))&&(!empty($_POST['CatName']))){
420 if(preg_match("/[\\\\\/]/i",$_POST['CatName'])){
421 print_red(_("Invalid character in category name."));
422 }elseif(!in_array($_POST['CatName'],$this->Categories)){
423 if(empty($this->curCatDir)){
424 $this->Categories[$_POST['CatName']]=$_POST['CatName'];
425 }else{
426 $this->Categories[$this->curCatDir."/".$_POST['CatName']]=$_POST['CatName'];
427 }
428 }else{
429 print_red(_("The specified category already exists."));
430 }
431 }
434 $this->reload();
436 $this->diffAppsInReleases();
437 $only_once = false;
438 foreach($_POST as $name => $value){
440 if((preg_match("/AddSep_/",$name))&&(!$only_once)){
441 $only_once = true;
442 $n = preg_replace("/AddSep_/","",$name);
443 $val= preg_replace("/_.*$/","",$n);
444 $this->AddSeperator($val);
445 }
447 if((preg_match("/DelApp_/",$name))&&(!$only_once)){
448 $only_once = true;
451 if(preg_match("/DelApp___SEPARATOR__/",$name)) {
452 $n= preg_replace("/DelApp___SEPARATOR__/","",$name);
453 $val= "__SEPARATOR__".preg_replace("/_.*$/","",$n);
454 }else{
455 $n = preg_replace("/DelApp_/","",$name);
456 $val= preg_replace("/_.*$/","",$n);
457 }
459 foreach($this->gosaMemberApplication as $key => $cat){
460 foreach($cat as $key2 => $app){
462 if($app['App'] == $val){
463 unset($this->gosaMemberApplication[$key][$key2]);
464 if(isset($this->used_apps[$val])){
465 foreach($this->getParameters($val) as $para){
466 if(isset($this->appoption[$para])){
467 unset($this->appoption[$para]);
468 }
469 }
470 unset($this->used_apps[$val]);
471 }
472 }
473 }
474 }
475 }
477 if(preg_match("/DelCat_/",$name)){
478 $n = preg_replace("/DelCat_/","",$name);
479 $app = base64_decode( preg_replace("/_.*$/","",$n));
480 foreach($this->Categories as $key => $cat){
481 if($cat == $app){
482 foreach($this->Categories as $p => $n){
483 if(preg_match("/^".$key."\/.*/",$p)){
484 unset($this->Categories[$p]);
485 }
486 }
487 unset($this->Categories[$key]);
488 }
489 }
490 }
492 if((preg_match("/EdiApp_/",$name))&&(!$only_once)){
494 $only_once = true;
495 $appname = $value;
496 $appname = preg_replace("/EdiApp_/","",$name);
497 $appname = preg_replace("/_.*$/","",$appname);
499 /* We've got the appname, get parameters from ldap
500 */
501 $ldap= $this->config->get_ldap_link();
503 $tmp = search_config($this->config->data,"faiManagement","CLASS");
504 if(!empty($tmp)){
505 $tmp = array_flip($this->Releases);
506 $base = $tmp[$this->FAIrelease];
508 $ldap->cd($this->config->current['BASE']);
509 $ldap->search("(&(objectClass=gosaApplication)(cn=$appname))",array("gosaApplicationParameter"));
510 $found = "";
511 while($attrs = $ldap->fetch()) {
512 if(preg_match("/cn=".$appname.",".$base."/",$attrs['dn'])){
513 $found = $attrs['dn'];
514 }
515 }
516 $ldap->cat($found, array("gosaApplicationParameter"));
517 }else{
518 $ldap->cd($this->config->current['BASE']);
519 $ldap->search("(&(objectClass=gosaApplication)(cn=$appname))",array("gosaApplicationParameter"));
520 }
523 if ($ldap->count() != 1){
524 print_red (_("The selected application name is not uniq. Please check your LDAP."));
525 } else {
526 $attrs= $ldap->fetch();
527 if(isset($attrs['gosaApplicationParameter'])){
528 $this->dialog= TRUE;
530 /* Fill name and value arrays */
531 for ($i= 0; $i<$attrs['gosaApplicationParameter']['count']; $i++){
532 $option= preg_replace('/^[^:]+:/', '',
533 $attrs['gosaApplicationParameter'][$i]);
534 $name= preg_replace('/:.*$/', '',
535 $attrs['gosaApplicationParameter'][$i]);
536 $this->option_name[$i]= $name;
538 /* Fill with values from application, default should be
539 loaded by the external scripts */
540 if (isset($this->appoption[$name])){
541 $this->option_value[$i]= $this->appoption[$name];
542 }
543 }
545 /* Create edit field */
546 $table= "<table summary=\"\">";
547 for ($i= 0; $i < count($this->option_name); $i++){
548 if (isset($this->option_value[$i])){
549 $value= $this->option_value[$i];
550 } else {
551 $value= "";
552 }
553 $table.="<tr><td>".$this->option_name[$i]."</td><td>".
554 "<input name=\"value$i\" size=60 maxlength=250 ".
555 "value=\"".$value."\"><br></td></tr>";
556 }
557 $table.= "</table>";
558 $this->table= $table;
559 } else {
560 print_red (_("The selected application has no options."));
561 }
562 }
563 }
564 }
566 $this->reload();
568 /* Add group with post */
569 if((isset($_GET['act']))&&($_GET['act']=="add")){
570 $this->used_apps[$_GET['id']]= $_GET['id'];
571 asort($this->used_apps);
572 $this->addApp($_GET['id']);
573 }
575 /* Add multiple */
576 if(isset($_POST['AddApps'])){
577 foreach($_POST as $name => $value){
578 if(preg_match("/AddApp_/",$name)){
579 $app = preg_replace("/AddApp_/","",$name);
580 $this->addApp($app);
581 }
582 }
583 }
586 /* Cancel edit options? */
587 if (isset($_POST['edit_options_cancel'])){
588 $this->dialog= FALSE;
589 }
591 /* Finish edit options? */
592 if (isset($_POST['edit_options_finish'])){
593 $this->dialog= FALSE;
595 /* Save informations passed by the user */
596 $this->option_value= array();
597 for ($i= 0; $i<count($this->option_name); $i++){
598 $this->appoption[$this->option_name[$i]]= $_POST["value$i"];
599 $this->is_modified= TRUE;
600 }
601 }
603 /* Prepare templating stuff */
604 $smarty= get_smarty();
605 $smarty->assign("used_apps", $this->used_apps);
606 $apps= array();
607 foreach ($this->apps as $key => $value){
608 if (!array_key_exists($key, $this->used_apps)){
609 $apps["$key"]= "$value";
610 }
611 }
613 $div = new DivSelectBox("appgroup");
615 $div->SetHeight(300);
617 /* get departments */
618 $ui = get_userinfo();
619 $departments = array();
620 $res = get_list("(objectClass=gosaDepartment)", "department", $this->curbase,array("description","cn","ou"),GL_SIZELIMIT);
621 foreach($res as $value){
622 $fdn= @LDAP::fix($value['dn']);
623 if($value["description"][0]!=".."){
624 $departments[$value['dn']]= convert_department_dn($fdn)." - [".$value["description"][0]."]";
625 }else{
626 $departments[$value['dn']]=convert_department_dn($fdn);
627 }
628 }
630 $linkopen = "<a href='?plug=".$_GET['plug']."&act=depopen&depid=%s'>%s</a>";
631 $linkadd = "<a href='?plug=".$_GET['plug']."&act=add&id=%s'>%s</a>";
633 $base_back = preg_replace("/^[^,]+,/","",$this->curbase);
634 if((strlen($base_back)>= strlen($this->config->current['BASE']))&&($this->curbase!=$this->config->current['BASE'])){
635 $div->AddEntry(array(
636 array("string"=>sprintf($linkopen,base64_encode($base_back),".. ["._("back")."]"),
637 "attach"=>"style='border:0px;'")
638 ));
639 }
640 foreach($departments as $key => $app){
641 $div->AddEntry(array(
642 array("string"=>"<img class='center' src='images/folder.png' alt='"._("department")."'> ".sprintf($linkopen,base64_encode($key),$app),
643 "attach"=>"style='border:0px;'")
644 ));
645 }
647 foreach($apps as $key => $app){
648 $div->AddEntry(array(
649 array("string"=>sprintf("<input class='center' type='checkbox' value='1' name='AddApp_%s'>",$key).
650 "<img class='center' src='images/select_application.png' alt='"._("application")."'> ".sprintf($linkadd,$key,$app),
651 "attach"=>"style='border:0px;'")
652 ));
653 }
655 if((isset($_GET['act']))&&(($_GET['act'] == "cat_up")||($_GET['act']=="cat_down"))){
656 if($_GET['act']=="cat_up"){
657 $this->catUp(base64_decode($_GET['id']));
658 }
659 if($_GET['act']=="cat_down"){
660 $this->catDown(base64_decode($_GET['id']));
661 }
662 }
664 if((isset($_GET['act']))&&(($_GET['act'] == "one_up")||($_GET['act']=="one_down"))){
665 if(isset($_GET['id'])){
666 $id = $_GET['id'];
667 $act = $_GET['act'];
669 if($act == "one_up"){
670 $this->getOneUp($id);
671 }elseif($act == "one_down") {
672 $this->getOneDown($id);
673 }
674 }
675 }
677 $div2 = new DivSelectBox("appgroup");
678 $div2->SetHeight(300);
680 $linkopen = "<img class='center' src='images/folder.png' alt=\"\"> <a href='?plug=".$_GET['plug']."&act=open&id=%s'>%s</a>";
681 $catremove = " <input type='image' src='images/edittrash.png' title='"._("Delete entry")."' name='DelCat_%s' value='%s'>";
682 $app = "<img class='center' src='images/select_application.png' alt=\"\"> %s";
684 $catupdown = "<a href='?plug=".$_GET['plug']."&act=cat_up&id=%s'>
685 <img align='top' alt=\"\" src='images/sort_up.png' border=0 title='"._("Move up")."'></a> <a href='?plug=".$_GET['plug']."&act=cat_down&id=%s'>
686 <img alt=\"\" src='images/sort_down.png' title='"._("Move down")."' border=0></a>";
688 if(empty($this->curCatDir)){
689 $cnt =0;
690 }else{
691 $cnt = count(split("/",$this->curCatDir));
692 $tmp = split("/",$this->curCatDir);
693 $bbk = "";
694 for($i = 0 ; $i < ($cnt -1 ) ; $i++){
695 $bbk .= $tmp[$i];
696 }
697 $div2 ->AddEntry(array(array("string"=>sprintf($linkopen,base64_encode($bbk),"..")),array("string"=>" ","attach"=>"style='border-right:0px;'")));
698 }
700 $this->GetSubdirs($this->curCatDir);
702 foreach($this->GetSubdirs($this->curCatDir) as $path => $name){
703 $div2 ->AddEntry(array(
704 array("string"=>sprintf($linkopen,base64_encode($path),$name)),
705 array("string"=>preg_replace("/%s/",base64_encode($path),$catupdown.$catremove),
706 "attach"=>"align='right' style='width:80px;border-right:0px;'")));
707 }
709 /* Append entries */
711 $separator ="<hr size=1>";
713 $sep = "<input type='image' src='images/back.png' title='"._("Insert seperator")."' value='%s' name='AddSep_%s'>";
715 $upudown ="<a href='?plug=".$_GET['plug']."&act=one_up&id=%s'> <img alt='{t}sort{/t}' align='top' src='images/sort_up.png' title='"._("Move up")."' border=0></a>".
716 " <a href='?plug=".$_GET['plug']."&act=one_down&id=%s'> <img alt='{t}sort{/t}' src='images/sort_down.png' title='"._("Move down")."' border=0></a>".
717 " <input type='image' src='images/edittrash.png' title='"._("Delete entry")."' name='DelApp_%s' value='%s' alt='{t}delete{/t}' >";
718 $edit= " <input type='image' src='images/edit.png' title='"._("Edit entry")."' name='EdiApp_%s' value='%s' alt='{t}edit{/t}' >";
720 $Differences = $this->diffAppsInReleases();
722 if(isset($this->gosaMemberApplication[$this->curCatDir])){
723 foreach($this->gosaMemberApplication[$this->curCatDir] as $cat => $entry){
726 if(preg_match("/__SEPARATOR__/",$entry['App'])){
727 $div2 ->AddEntry(array(array("string"=>$separator),
728 array("string"=>preg_replace("/\%s/",htmlentities($entry['App']),$upudown),"attach"=>"align='right' style='border-right:0px;'")));
729 }else{
731 $image = "";
732 /* Check if application was available within selected release
733 * or application list if release management is not active
734 */
735 if(!in_array($entry['App'],$this->AllAppsForRelease)){
737 /* release managent is active
738 */
739 if(!$this->enableReleaseManagement){
740 $image = "<img class='center' src='images/select_invalid_application.png'
741 title='"._("This application is no longer available.")."'> ";
742 }else{
743 $image = "<img class='center' src='images/select_invalid_application.png'
744 title='".sprintf(_("This application is not available in any release named %s."),$this->FAIrelease)."'> ";
745 }
747 }elseif(isset($Differences[$entry['App']]) && ($Differences[$entry['App']] == true)) {
748 $entry['App'].=" <i>["._("Check parameter")."]</i>";
749 $image = "<img class='center' src='images/select_invalid_application.png'
750 title='"._("This application has changed parameters.")."'> ";
751 }else{
752 $image = "<img class='center' src='images/select_application.png' alt=\"\"> ";
753 }
755 $div2->AddEntry(array(array("string"=>sprintf($image."%s",$entry['App'])),
756 array("string"=>preg_replace("/\%s/",htmlentities($entry['App']),$sep.$edit.$upudown),
757 "attach"=>"align='right' style='width:100px;border-right:0px;'")));
758 }
759 }
760 }
762 $smarty->assign("UsedApps", $div2->DrawList());
763 $smarty->assign("List", $div->DrawList());
764 $smarty->assign("apps", $apps);
766 $smarty->assign("enableReleaseManagement",$this->enableReleaseManagement);
768 if($this->enableReleaseManagement){
769 $smarty->assign("FAIrelease", $this->FAIrelease);
770 $smarty->assign("Releases", $this->Releases);
772 if(count($this->used_apps)){
773 $smarty->assign("ReleaseSelectAble", false);
774 }else{
775 $smarty->assign("ReleaseSelectAble", true);
776 }
777 }
778 $smarty->assign("ReleaseSelectAble", true);
780 /* Show main page */
781 if ($this->dialog){
782 $smarty->assign("table", $this->table);
783 $display.= $smarty->fetch (get_template_path('application_options.tpl', TRUE));
784 } else {
785 $display.= $smarty->fetch (get_template_path('application.tpl', TRUE));
786 }
787 return ($display);
788 }
791 function getReleases()
792 {
793 $dn = $this->config->current['BASE'];
794 $filter = "(&(objectClass=organizationalUnit)(objectClass=FAIbranch))";
795 $res = get_list($filter,"groups", $dn, array("ou"), GL_SUBSEARCH);
797 $ret =array();
798 foreach($res as $attrs){
799 if(preg_match("/ou=apps,/",$attrs['dn'])){
800 $bb = preg_replace("/ou=apps,.*/","",$attrs['dn']);
801 $parts = array_reverse(split("ou=",$bb));
803 $str ="";
804 foreach($parts as $part){
805 if(empty($part)) {
806 continue;
807 }
808 $str .= str_replace(",","",$part)."/";
809 }
810 $name = preg_replace("/\/$/","",$str);
811 if(empty($name)) {
812 $name ="/";
813 }
814 $ret[$attrs['dn']] = $name;
815 }
816 }
817 return($ret);
818 }
820 function save_object()
821 {
822 plugin::save_object();
823 }
826 function remove_from_parent()
827 {
828 plugin::remove_from_parent();
830 $ldap= $this->config->get_ldap_link();
831 $ldap->cd($this->dn);
832 $this->cleanup();
834 $ldap->modify ($this->attrs);
836 show_ldap_error($ldap->get_error(), sprintf(_("Removing of groups/applications with dn '%s' failed."),$this->dn));
838 /* Optionally execute a command after we're done */
839 $this->handle_post_events("remove");
840 }
843 /* Save to LDAP */
844 function save()
845 {
846 plugin::save();
848 /* Copy members */
849 $this->Categories[""]="";
850 $this->attrs["gosaMemberApplication"]= array();
851 $this->attrs["gosaApplicationParameter"]= array();
852 foreach($this->Categories as $name => $cats){
853 $i =0;
854 if(isset($this->gosaMemberApplication[$name])){
855 foreach($this->gosaMemberApplication[$name] as $entry){
856 if(!preg_match("/__SEPARATOR__/",$entry['App'])){
857 $this->attrs["gosaMemberApplication"][]= $entry['App']."|".$name."|".$i;
858 }
859 $i ++;
860 }
861 }
862 if(($i==0)&&(!empty($name))){
863 $this->attrs["gosaMemberApplication"][]= "|".$name."|".$i;
864 }
865 }
867 /* Are there application parameters to be saved */
868 $this->attrs['gosaApplicationParameter']= array();
869 foreach($this->appoption as $name => $value){
870 if ($value != ""){
871 $this->attrs['gosaApplicationParameter'][]= "$name:$value";
872 }
873 }
875 /* Write back to LDAP */
876 $ldap= $this->config->get_ldap_link();
877 $ldap->cd($this->dn);
878 $this->cleanup();
879 $ldap->modify ($this->attrs);
881 show_ldap_error($ldap->get_error(), sprintf(_("Saving of groups/applications with dn '%s' failed."),$this->dn));
883 /* Optionally execute a command after we're done */
884 if ($this->initially_was_account == $this->is_account){
885 if ($this->is_modified){
886 $this->handle_post_events("mofify");
887 }
888 } else {
889 $this->handle_post_events("add");
890 }
892 }
894 function check()
895 {
896 /* Call common method to give check the hook */
897 $message= plugin::check();
899 return ($message);
900 }
903 function reload()
904 {
905 /* Generate applist */
906 $this->apps= array();
908 /* Special handling for release managed apps
909 */
910 $tmp = search_config($this->config->data,"faiManagement","CLASS");
911 if(!empty($tmp)){
912 $this->enableReleaseManagement = true;
914 $tmp = array_flip($this->Releases);
915 if(isset($tmp[$this->FAIrelease])){
916 $base = $tmp[$this->FAIrelease];
917 }else{
918 $k = key($tmp);
919 $r = $tmp[$k];
920 $this->FAIrelease = $k;
921 $base = $r;
923 print_red(sprintf(_("Can't resolve the release name '%s', setting release name to '%s'. Possibly the objects base has changed."),$this->FAIrelease,$k));
924 }
926 $base = preg_replace("/ou=apps,.*$/","ou=apps,".$this->curbase,$base);
928 $ldap = $this->config->get_ldap_link();
929 $ldap->cd ($base);
930 $ldap->ls ("(objectClass=gosaApplication)",$base);
931 }else{
932 $ldap = $this->config->get_ldap_link();
933 $ldap->cd ("ou=apps,".$this->curbase);
934 $ldap->ls ("(objectClass=gosaApplication)","ou=apps,".$this->curbase);
935 }
937 while ($attrs= $ldap->fetch()){
938 if (isset($attrs["description"][0])){
939 $this->apps[$attrs["cn"][0]]=
940 $attrs["cn"][0]." (".
941 $attrs["description"][0].")";
942 } else {
943 $this->apps[$attrs["cn"][0]]=
944 $attrs["cn"][0];
945 }
946 }
948 $ldap->cd($this->config->current['BASE']);
949 $ldap->search("objectClass=gosaApplication",array("gosaApplicationParameter","cn"));
950 $tmp = search_config($this->config->data,"faiManagement","CLASS");
951 $this->AllAppsForRelease = array();
952 if(!empty($tmp)){
954 $tmp = array_flip($this->Releases);
956 while($attrs = $ldap->fetch()){
958 $testdn = preg_replace("/ou=apps,.*$/","ou=apps",$attrs['dn']);
959 $testdn = preg_replace("/^[^,]+/","",$testdn);
960 $testdn = preg_replace("/^,/","",$testdn);
962 if($testdn == preg_replace("/ou=apps,.*$/","ou=apps",$tmp[$this->FAIrelease])){
963 $this->AllAppsForRelease[$attrs['dn']] = $attrs['cn'][0];
964 $this->AllAppsForReleaseParameter[$this->FAIrelease][$attrs['cn'][0]] = $attrs;
965 }
966 }
967 }else{
968 while($attrs = $ldap->fetch()){
969 $this->AllAppsForRelease[$attrs['dn']] = $attrs['cn'][0];
970 }
971 }
973 natcasesort ($this->apps);
974 reset ($this->apps);
976 if(is_array($this->gosaMemberApplication))
977 foreach ($this->gosaMemberApplication as $cat){
978 if(is_array($cat))
979 foreach($cat as $entry){
980 $this->used_apps[$entry['App']]= $entry['App'];
981 }
982 }
983 }
986 function addApp($cn)
987 {
988 if((isset($this->gosaMemberApplication[$this->curCatDir]))&&(is_array($this->gosaMemberApplication[$this->curCatDir]))){
989 foreach($this->gosaMemberApplication[$this->curCatDir] as $entry){
990 if($entry['App'] == $cn) return;
991 }
992 }
993 $this->gosaMemberApplication[$this->curCatDir][]= array("App"=>$cn);
994 $this->used_apps[$cn]=$cn;
995 $this->is_modified= TRUE;
996 }
999 function removeApp($cn)
1000 {
1001 $temp= array();
1002 foreach ($this->gosaMemberApplication as $value){
1003 if ($value != $cn){
1004 $temp[]= $value;
1005 }
1006 }
1007 $this->gosaMemberApplication= $temp;
1008 $this->is_modified= TRUE;
1009 }
1011 function getParameters($app)
1012 {
1013 $tmp = $this->getReleases();
1014 $ret = array();
1015 if(in_array($this->FAIrelease,$tmp)){
1016 $tmp2 = array_flip($tmp);
1017 $base = $tmp2[$this->FAIrelease];
1018 $ldap = $this->config->get_ldap_link();
1019 $ldap->cd($this->config->current['BASE']);
1020 $ldap->search("(&(objectClass=gosaApplication)(cn=".$app.")(gosaApplicationParameter=*))",array("gosaApplicationParameter"));
1021 if($ldap->count()){
1022 $attrs = $ldap->fetch();
1023 for($i = 0 ; $i < $attrs['gosaApplicationParameter']['count'] ; $i ++ ){
1024 $name = preg_replace("/:.*$/","",$attrs['gosaApplicationParameter'][$i]);
1025 $ret[$name] = $name;
1026 }
1027 }
1028 }
1029 return($ret);
1030 }
1032 function GetSubdirs($dir)
1033 {
1034 $ret = array();
1035 $tmp1 = split("/",$this->curCatDir);
1037 foreach($this->Categories as $path=>$cat){
1038 $tmp2 = split("/",$path);
1040 if((empty($this->curCatDir))&&(!preg_match("/\//",$path))){
1041 $abort = false;
1042 }elseif(((count($tmp1))+1) == (count($tmp2))){
1043 $abort = false;
1044 for($i = 0 ; $i < count($tmp1) ; $i++){
1045 if($tmp1[$i] != $tmp2[$i]){
1046 $abort = true;
1047 }
1048 }
1049 }else{
1050 $abort= true;
1051 }
1052 if(!$abort){
1053 $ret[$path]=$cat;
1054 }
1055 }
1056 return($ret);
1057 }
1060 /* Return plugin informations for acl handling */
1061 function plInfo()
1062 {
1063 return (array(
1064 "plShortName" => _("Applications"),
1065 "plDescription" => _("Group applications"),
1066 "plSelfModify" => FALSE,
1067 "plDepends" => array(),
1068 "plPriority" => 0,
1069 "plSection" => array("administration"),
1070 "plCategory" => array("groups"),
1071 "plProvidedAcls"=> array(
1072 "gosaMemberApplication" => _("Application"),
1073 "gosaApplicationParameter" => _("Application parameter"))
1074 ));
1075 }
1076 }
1077 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1078 ?>