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();
375 if((isset($_GET['act']))&&($_GET['act']=="depopen")){
376 $dep = base64_decode($_GET['depid']);
377 if(isset($this->config->idepartments[$dep])){
378 $this->curbase =$dep;
379 }
380 }
382 if((isset($_GET['act']))&&($_GET['act']=="open")){
383 $this->curCatDir = base64_decode($_GET['id']);
384 }
386 /* Do we need to flip is_account state? */
387 if (isset($_POST['modify_state'])){
388 $this->is_account= !$this->is_account;
389 }
391 /* Do we represent a valid group? */
392 if (!$this->is_account && $this->parent == NULL){
393 $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\"> <b>".
394 _("This 'dn' is no appgroup.")."</b>";
395 return ($display);
396 }
398 /* Show tab dialog headers */
399 $display= "";
400 if ($this->parent != NULL){
401 if ($this->is_account){
402 $display= $this->show_header(_("Remove applications"),
403 _("This group has application features enabled. You can disable them by clicking below."));
404 } else {
405 $display.= $this->show_header(_("Create applications"),
406 _("This group has application features disabled. You can enable them by clicking below."));
407 return ($display);
408 }
409 }
412 /* Add Categorie */
415 if((isset($_POST['AddCat']))&&(isset($_POST['CatName']))&&(!empty($_POST['CatName']))){
417 if(preg_match("/[\\\\\/]/i",$_POST['CatName'])){
418 print_red(_("Invalid character in category name."));
419 }elseif(!in_array($_POST['CatName'],$this->Categories)){
420 if(empty($this->curCatDir)){
421 $this->Categories[$_POST['CatName']]=$_POST['CatName'];
422 }else{
423 $this->Categories[$this->curCatDir."/".$_POST['CatName']]=$_POST['CatName'];
424 }
425 }else{
426 print_red(_("The specified category already exists."));
427 }
428 }
431 $this->reload();
433 $this->diffAppsInReleases();
434 $only_once = false;
435 foreach($_POST as $name => $value){
437 if((preg_match("/AddSep_/",$name))&&(!$only_once)){
438 $only_once = true;
439 $n = preg_replace("/AddSep_/","",$name);
440 $val= preg_replace("/_.*$/","",$n);
441 $this->AddSeperator($val);
442 }
444 if((preg_match("/DelApp_/",$name))&&(!$only_once)){
445 $only_once = true;
448 if(preg_match("/DelApp___SEPARATOR__/",$name)) {
449 $n= preg_replace("/DelApp___SEPARATOR__/","",$name);
450 $val= "__SEPARATOR__".preg_replace("/_.*$/","",$n);
451 }else{
452 $n = preg_replace("/DelApp_/","",$name);
453 $val= preg_replace("/_.*$/","",$n);
454 }
456 foreach($this->gosaMemberApplication as $key => $cat){
457 foreach($cat as $key2 => $app){
458 if($app['App'] == $val){
459 unset($this->gosaMemberApplication[$key][$key2]);
460 if(isset($this->used_apps[$val])){
461 unset($this->used_apps[$val]);
462 }
463 }
464 }
465 }
466 }
468 if(preg_match("/DelCat_/",$name)){
469 $n = preg_replace("/DelCat_/","",$name);
470 $app = base64_decode( preg_replace("/_.*$/","",$n));
471 foreach($this->Categories as $key => $cat){
472 if($cat == $app){
473 foreach($this->Categories as $p => $n){
474 if(preg_match("/^".$key."\/.*/",$p)){
475 unset($this->Categories[$p]);
476 }
477 }
478 unset($this->Categories[$key]);
479 }
480 }
481 }
483 if((preg_match("/EdiApp_/",$name))&&(!$only_once)){
485 $only_once = true;
486 $appname = $value;
487 $appname = preg_replace("/EdiApp_/","",$name);
488 $appname = preg_replace("/_.*$/","",$appname);
490 /* We've got the appname, get parameters from ldap
491 */
492 $ldap= $this->config->get_ldap_link();
494 $tmp = search_config($this->config->data,"faiManagement","CLASS");
495 if(!empty($tmp)){
496 $tmp = array_flip($this->Releases);
497 $base = $tmp[$this->FAIrelease];
499 $ldap->cd($this->config->current['BASE']);
500 $ldap->search("(&(objectClass=gosaApplication)(cn=$appname))",array("gosaApplicationParameter"));
501 $found = "";
502 while($attrs = $ldap->fetch()) {
503 if(preg_match("/cn=".$appname.",".$base."/",$attrs['dn'])){
504 $found = $attrs['dn'];
505 }
506 }
507 $ldap->cat($found);
508 }else{
509 $ldap->cd($this->config->current['BASE']);
510 $ldap->search("(&(objectClass=gosaApplication)(cn=$appname))",array("gosaApplicationParameter"));
512 }
515 if ($ldap->count() != 1){
516 print_red (_("The selected application name is not uniq. Please check your LDAP."));
517 } else {
518 $attrs= $ldap->fetch();
519 if(isset($attrs['gosaApplicationParameter'])){
520 $this->dialog= TRUE;
522 /* Fill name and value arrays */
523 for ($i= 0; $i<$attrs['gosaApplicationParameter']['count']; $i++){
524 $option= preg_replace('/^[^:]+:/', '',
525 $attrs['gosaApplicationParameter'][$i]);
526 $name= preg_replace('/:.*$/', '',
527 $attrs['gosaApplicationParameter'][$i]);
528 $this->option_name[$i]= $name;
530 /* Fill with values from application, default should be
531 loaded by the external scripts */
532 if (isset($this->appoption[$name])){
533 $this->option_value[$i]= $this->appoption[$name];
534 }
535 }
537 /* Create edit field */
538 $table= "<table summary=\"\">";
539 for ($i= 0; $i < count($this->option_name); $i++){
540 if (isset($this->option_value[$i])){
541 $value= $this->option_value[$i];
542 } else {
543 $value= "";
544 }
545 $table.="<tr><td>".$this->option_name[$i]."</td><td>".
546 "<input name=\"value$i\" size=60 maxlength=250 ".
547 "value=\"".$value."\"><br></td></tr>";
548 }
549 $table.= "</table>";
550 $this->table= $table;
551 } else {
552 print_red (_("The selected application has no options."));
553 }
554 }
555 }
556 }
558 $this->reload();
560 /* Add group with post */
561 if((isset($_GET['act']))&&($_GET['act']=="add")){
562 $this->used_apps[$_GET['id']]= $_GET['id'];
563 asort($this->used_apps);
564 $this->addApp($_GET['id']);
565 }
567 /* Add multiple */
568 if(isset($_POST['AddApps'])){
569 foreach($_POST as $name => $value){
570 if(preg_match("/AddApp_/",$name)){
571 $app = preg_replace("/AddApp_/","",$name);
572 $this->addApp($app);
573 }
574 }
575 }
578 /* Cancel edit options? */
579 if (isset($_POST['edit_options_cancel'])){
580 $this->dialog= FALSE;
581 }
583 /* Finish edit options? */
584 if (isset($_POST['edit_options_finish'])){
585 $this->dialog= FALSE;
587 /* Save informations passed by the user */
588 $this->option_value= array();
589 for ($i= 0; $i<count($this->option_name); $i++){
590 $this->appoption[$this->option_name[$i]]= $_POST["value$i"];
591 $this->is_modified= TRUE;
592 }
593 }
595 /* Prepare templating stuff */
596 $smarty= get_smarty();
597 $smarty->assign("used_apps", $this->used_apps);
598 $apps= array();
599 foreach ($this->apps as $key => $value){
600 if (!array_key_exists($key, $this->used_apps)){
601 $apps["$key"]= "$value";
602 }
603 }
605 $div = new DivSelectBox("appgroup");
607 $div->SetHeight(300);
609 /* NEW LIST MANAGMENT
610 * We also need to search for the departments
611 * So we are able to navigate like in konquerer
612 */
614 //FIXME: Why do we not use get_list here? It's the same code all over the time...
615 $ldap = $this->config->get_ldap_link();
616 $ldap->cd($this->curbase) ;
617 $ldap->ls("(objectClass=gosaDepartment)");
618 $departments= array();
619 $tmp = array();
620 while ($value = $ldap->fetch()){
621 $tmp[strtolower($value['dn']).$value['dn']]=$value;
622 }
623 ksort($tmp);
624 foreach($tmp as $value){
625 $fdn= @LDAP::fix($value['dn']);
626 if($value["description"][0]!=".."){
627 $departments[$value['dn']]= convert_department_dn($fdn)." - [".$value["description"][0]."]";
628 }else{
629 $departments[$value['dn']]=convert_department_dn($fdn);
630 }
631 }
633 /* END NEW LIST MANAGMENT
634 */
636 $linkopen = "<a href='?plug=".$_GET['plug']."&act=depopen&depid=%s'>%s</a>";
637 $linkadd = "<a href='?plug=".$_GET['plug']."&act=add&id=%s'>%s</a>";
639 $base_back = preg_replace("/^[^,]+,/","",$this->curbase);
640 if((strlen($base_back)>= strlen($this->config->current['BASE']))&&($this->curbase!=$this->config->current['BASE'])){
641 $div->AddEntry(array(
642 array("string"=>sprintf($linkopen,base64_encode($base_back),".. ["._("back")."]"),
643 "attach"=>"style='border:0px;'")
644 ));
645 }
646 foreach($departments as $key => $app){
647 $div->AddEntry(array(
648 array("string"=>"<img class='center' src='images/folder.png' alt='"._("department")."'> ".sprintf($linkopen,base64_encode($key),$app),
649 "attach"=>"style='border:0px;'")
650 ));
651 }
653 foreach($apps as $key => $app){
654 $div->AddEntry(array(
655 array("string"=>sprintf("<input class='center' type='checkbox' value='1' name='AddApp_%s'>",$key).
656 "<img class='center' src='images/select_application.png' alt='"._("application")."'> ".sprintf($linkadd,$key,$app),
657 "attach"=>"style='border:0px;'")
658 ));
659 }
661 if((isset($_GET['act']))&&(($_GET['act'] == "cat_up")||($_GET['act']=="cat_down"))){
662 if($_GET['act']=="cat_up"){
663 $this->catUp(base64_decode($_GET['id']));
664 }
665 if($_GET['act']=="cat_down"){
666 $this->catDown(base64_decode($_GET['id']));
667 }
668 }
670 if((isset($_GET['act']))&&(($_GET['act'] == "one_up")||($_GET['act']=="one_down"))){
671 if(isset($_GET['id'])){
672 $id = $_GET['id'];
673 $act = $_GET['act'];
675 if($act == "one_up"){
676 $this->getOneUp($id);
677 }elseif($act == "one_down") {
678 $this->getOneDown($id);
679 }
680 }
681 }
683 $div2 = new DivSelectBox("appgroup");
684 $div2->SetHeight(300);
686 $linkopen = "<img class='center' src='images/folder.png' alt=\"\"> <a href='?plug=".$_GET['plug']."&act=open&id=%s'>%s</a>";
687 $catremove = " <input type='image' src='images/edittrash.png' title='"._("Delete entry")."' name='DelCat_%s' value='%s'>";
688 $app = "<img class='center' src='images/select_application.png' alt=\"\"> %s";
690 $catupdown = "<a href='?plug=".$_GET['plug']."&act=cat_up&id=%s'>
691 <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'>
692 <img alt=\"\" src='images/sort_down.png' title='"._("Move down")."' border=0></a>";
694 if(empty($this->curCatDir)){
695 $cnt =0;
696 }else{
697 $cnt = count(split("/",$this->curCatDir));
698 $tmp = split("/",$this->curCatDir);
699 $bbk = "";
700 for($i = 0 ; $i < ($cnt -1 ) ; $i++){
701 $bbk .= $tmp[$i];
702 }
703 $div2 ->AddEntry(array(array("string"=>sprintf($linkopen,base64_encode($bbk),"..")),array("string"=>" ","attach"=>"style='border-right:0px;'")));
704 }
706 $this->GetSubdirs($this->curCatDir);
708 foreach($this->GetSubdirs($this->curCatDir) as $path => $name){
709 $div2 ->AddEntry(array(
710 array("string"=>sprintf($linkopen,base64_encode($path),$name)),
711 array("string"=>preg_replace("/%s/",base64_encode($path),$catupdown.$catremove),
712 "attach"=>"align='right' style='width:80px;border-right:0px;'")));
713 }
715 /* Append entries */
717 $separator ="<hr size=1>";
719 $sep = "<input type='image' src='images/back.png' title='"._("Insert seperator")."' value='%s' name='AddSep_%s'>";
721 $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>".
722 " <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>".
723 " <input type='image' src='images/edittrash.png' title='"._("Delete entry")."' name='DelApp_%s' value='%s' alt='{t}delete{/t}' >";
724 $edit= " <input type='image' src='images/edit.png' title='"._("Edit entry")."' name='EdiApp_%s' value='%s' alt='{t}edit{/t}' >";
726 $Differences = $this->diffAppsInReleases();
728 if(isset($this->gosaMemberApplication[$this->curCatDir])){
729 foreach($this->gosaMemberApplication[$this->curCatDir] as $cat => $entry){
732 if(preg_match("/__SEPARATOR__/",$entry['App'])){
733 $div2 ->AddEntry(array(array("string"=>$separator),
734 array("string"=>preg_replace("/\%s/",htmlentities($entry['App']),$upudown),"attach"=>"align='right' style='border-right:0px;'")));
735 }else{
737 $image = "";
738 /* Check if application was available within selected release
739 * or application list if release management is not active
740 */
741 if(!in_array($entry['App'],$this->AllAppsForRelease)){
743 /* release managent is active
744 */
745 if(!$this->enableReleaseManagement){
746 $image = "<img class='center' src='images/select_invalid_application.png'
747 title='"._("This application is no longer available.")."'> ";
748 }else{
749 $image = "<img class='center' src='images/select_invalid_application.png'
750 title='".sprintf(_("This application is not available in any release named %s."),$this->FAIrelease)."'> ";
751 }
753 }elseif(isset($Differences[$entry['App']]) && ($Differences[$entry['App']] == true)) {
754 $entry['App'].=" <i>["._("Check parameter")."]</i>";
755 $image = "<img class='center' src='images/select_invalid_application.png'
756 title='"._("This application has changed parameters.")."'> ";
757 }else{
758 $image = "<img class='center' src='images/select_application.png' alt=\"\"> ";
759 }
761 $div2->AddEntry(array(array("string"=>sprintf($image."%s",$entry['App'])),
762 array("string"=>preg_replace("/\%s/",htmlentities($entry['App']),$sep.$edit.$upudown),
763 "attach"=>"align='right' style='width:100px;border-right:0px;'")));
764 }
765 }
766 }
768 $smarty->assign("UsedApps", $div2->DrawList());
769 $smarty->assign("List", $div->DrawList());
770 $smarty->assign("apps", $apps);
772 $smarty->assign("enableReleaseManagement",$this->enableReleaseManagement);
774 if($this->enableReleaseManagement){
775 $smarty->assign("FAIrelease", $this->FAIrelease);
776 $smarty->assign("Releases", $this->Releases);
778 if(count($this->used_apps)){
779 $smarty->assign("ReleaseSelectAble", false);
780 }else{
781 $smarty->assign("ReleaseSelectAble", true);
782 }
783 }
784 $smarty->assign("ReleaseSelectAble", true);
786 /* Show main page */
787 if ($this->dialog){
788 $smarty->assign("table", $this->table);
789 $display.= $smarty->fetch (get_template_path('application_options.tpl', TRUE));
790 } else {
791 $display.= $smarty->fetch (get_template_path('application.tpl', TRUE));
792 }
793 return ($display);
794 }
797 function getReleases()
798 {
799 $dn = "ou=apps,".$this->config->current['BASE'];
800 $ldap = $this->config->get_ldap_link();
801 $ldap->cd($dn);
802 $ldap->search("objectClass=organizationalUnit",array("ou"));
803 $ret =array();
804 while($attrs = $ldap->fetch()){
805 if(preg_match("/ou=apps,/",$attrs['dn'])){
806 $bb = preg_replace("/ou=apps,.*/","",$attrs['dn']);
807 $parts = array_reverse(split("ou=",$bb));
809 $str ="";
810 foreach($parts as $part){
811 if(empty($part)) {
812 continue;
813 }
814 $str .= str_replace(",","",$part)."/";
815 }
816 $name = preg_replace("/\/$/","",$str);
817 if(empty($name)) {
818 $name ="/";
819 }
820 $ret[$attrs['dn']] = $name;
821 }
822 }
823 return($ret);
824 }
826 function save_object()
827 {
828 plugin::save_object();
829 }
832 function remove_from_parent()
833 {
834 plugin::remove_from_parent();
836 $ldap= $this->config->get_ldap_link();
837 $ldap->cd($this->dn);
838 $this->cleanup();
840 $ldap->modify ($this->attrs);
842 show_ldap_error($ldap->get_error());
844 /* Optionally execute a command after we're done */
845 $this->handle_post_events("remove");
846 }
849 /* Save to LDAP */
850 function save()
851 {
852 plugin::save();
854 /* Copy members */
855 $this->Categories[""]="";
856 $this->attrs["gosaMemberApplication"]= array();
857 foreach($this->Categories as $name => $cats){
858 $i =0;
859 if(isset($this->gosaMemberApplication[$name])){
860 foreach($this->gosaMemberApplication[$name] as $entry){
861 if(!preg_match("/__SEPARATOR__/",$entry['App'])){
862 $this->attrs["gosaMemberApplication"][]= $entry['App']."|".$name."|".$i;
863 }
864 $i ++;
865 }
866 }
867 if(($i==0)&&(!empty($name))){
868 $this->attrs["gosaMemberApplication"][]= "|".$name."|".$i;
869 }
870 }
872 /* Are there application parameters to be saved */
873 $this->attrs['gosaApplicationParameter']= array();
874 foreach($this->appoption as $name => $value){
875 if ($value != ""){
876 $this->attrs['gosaApplicationParameter'][]= "$name:$value";
877 }
878 }
880 /* Write back to LDAP */
881 $ldap= $this->config->get_ldap_link();
882 $ldap->cd($this->dn);
883 $this->cleanup();
884 $ldap->modify ($this->attrs);
886 show_ldap_error($ldap->get_error());
888 /* Optionally execute a command after we're done */
889 if ($this->initially_was_account == $this->is_account){
890 if ($this->is_modified){
891 $this->handle_post_events("mofify");
892 }
893 } else {
894 $this->handle_post_events("add");
895 }
897 }
899 function check()
900 {
901 /* Call common method to give check the hook */
902 $message= plugin::check();
904 return ($message);
905 }
908 function reload()
909 {
910 /* Generate applist */
911 $this->apps= array();
913 /* Special handling for release managed apps
914 */
915 $tmp = search_config($this->config->data,"faiManagement","CLASS");
916 if(!empty($tmp)){
917 $this->enableReleaseManagement = true;
919 $tmp = array_flip($this->Releases);
920 if(isset($tmp[$this->FAIrelease])){
921 $base = $tmp[$this->FAIrelease];
922 }else{
923 $k = key($tmp);
924 $r = $tmp[$k];
925 $this->FAIrelease = $k;
926 $base = $r;
928 print_red(sprintf(_("Can't resolve the release name '%s', setting release name to '%s'. Possibly the objects base has changed."),$this->FAIrelease,$k));
929 }
931 $base = preg_replace("/ou=apps,.*$/","ou=apps,".$this->curbase,$base);
933 $ldap = $this->config->get_ldap_link();
934 $ldap->cd ($base);
935 $ldap->ls ("(objectClass=gosaApplication)",$base);
936 }else{
937 $ldap = $this->config->get_ldap_link();
938 $ldap->cd ("ou=apps,".$this->curbase);
939 $ldap->ls ("(objectClass=gosaApplication)","ou=apps,".$this->curbase);
940 }
942 while ($attrs= $ldap->fetch()){
943 if (isset($attrs["description"][0])){
944 $this->apps[$attrs["cn"][0]]=
945 $attrs["cn"][0]." (".
946 $attrs["description"][0].")";
947 } else {
948 $this->apps[$attrs["cn"][0]]=
949 $attrs["cn"][0];
950 }
951 }
953 $ldap->cd($this->config->current['BASE']);
954 $ldap->search("objectClass=gosaApplication",array("gosaApplicationParameter","cn"));
955 $tmp = search_config($this->config->data,"faiManagement","CLASS");
956 $this->AllAppsForRelease = array();
957 if(!empty($tmp)){
959 $tmp = array_flip($this->Releases);
961 while($attrs = $ldap->fetch()){
963 $testdn = preg_replace("/ou=apps,.*$/","ou=apps",$attrs['dn']);
964 $testdn = preg_replace("/^[^,]+/","",$testdn);
965 $testdn = preg_replace("/^,/","",$testdn);
967 if($testdn == preg_replace("/ou=apps,.*$/","ou=apps",$tmp[$this->FAIrelease])){
968 $this->AllAppsForRelease[$attrs['dn']] = $attrs['cn'][0];
969 $this->AllAppsForReleaseParameter[$this->FAIrelease][$attrs['cn'][0]] = $attrs;
970 }
971 }
972 }else{
973 while($attrs = $ldap->fetch()){
974 $this->AllAppsForRelease[$attrs['dn']] = $attrs['cn'][0];
975 }
976 }
978 natcasesort ($this->apps);
979 reset ($this->apps);
981 if(is_array($this->gosaMemberApplication))
982 foreach ($this->gosaMemberApplication as $cat){
983 if(is_array($cat))
984 foreach($cat as $entry){
985 $this->used_apps[$entry['App']]= $entry['App'];
986 }
987 }
988 }
991 function addApp($cn)
992 {
993 if((isset($this->gosaMemberApplication[$this->curCatDir]))&&(is_array($this->gosaMemberApplication[$this->curCatDir]))){
994 foreach($this->gosaMemberApplication[$this->curCatDir] as $entry){
995 if($entry['App'] == $cn) return;
996 }
997 }
998 $this->gosaMemberApplication[$this->curCatDir][]= array("App"=>$cn);
999 $this->used_apps[$cn]=$cn;
1000 $this->is_modified= TRUE;
1001 }
1004 function removeApp($cn)
1005 {
1006 $temp= array();
1007 foreach ($this->gosaMemberApplication as $value){
1008 if ($value != $cn){
1009 $temp[]= $value;
1010 }
1011 }
1012 $this->gosaMemberApplication= $temp;
1013 $this->is_modified= TRUE;
1014 }
1016 function GetSubdirs($dir)
1017 {
1018 $ret = array();
1019 $tmp1 = split("/",$this->curCatDir);
1021 foreach($this->Categories as $path=>$cat){
1022 $tmp2 = split("/",$path);
1024 if((empty($this->curCatDir))&&(!preg_match("/\//",$path))){
1025 $abort = false;
1026 }elseif(((count($tmp1))+1) == (count($tmp2))){
1027 $abort = false;
1028 for($i = 0 ; $i < count($tmp1) ; $i++){
1029 if($tmp1[$i] != $tmp2[$i]){
1030 $abort = true;
1031 }
1032 }
1033 }else{
1034 $abort= true;
1035 }
1036 if(!$abort){
1037 $ret[$path]=$cat;
1038 }
1039 }
1040 return($ret);
1041 }
1042 }
1044 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1045 ?>