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");
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");
41 function appgroup ($config, $dn= NULL)
42 {
44 /* prepare group app for release management */
45 $tmp = search_config($config->data,"faiManagement","CLASS");
46 if(!empty($tmp)){
47 $this->enableReleaseManagement = true;
48 $this->objectclasses [] = "FAIreleaseTag";
49 $this->attributes[] = "FAIrelease";
50 }
52 plugin::plugin ($config, $dn);
54 /* In some case of old applikations with old release tag saving, we
55 must reassign is_account state.
56 (Or if release management wasn't activated before creating this app) */
57 if($this->enableReleaseManagement){
59 /* Release management is activated && this is a valid group app account,
60 but no release class was found, so activate is_account flag */
61 if(( in_array("gosaApplicationGroup",$this->attrs['objectClass'])) &&
62 (!in_array("FAIreleaseTag",$this->attrs['objectClass']))){
63 $this->is_account =true;
64 }
65 }
68 /* Load member applications */
69 if (isset ($this->attrs["gosaMemberApplication"][0])){
70 $this->gosaMemberApplication = array();
71 for ($i= 0; $i<$this->attrs["gosaMemberApplication"]["count"]; $i++){
72 $this->gosaMemberApplication[]=
73 $this->attrs["gosaMemberApplication"][$i];
74 }
75 }
77 /* Load application options */
78 if (isset($this->attrs['gosaApplicationParameter'])){
79 for ($i= 0; $i<$this->attrs['gosaApplicationParameter']['count']; $i++){
80 $option= preg_replace('/^[^:]+:/', '',
81 $this->attrs['gosaApplicationParameter'][$i]);
82 $name= preg_replace('/:.*$/', '',
83 $this->attrs['gosaApplicationParameter'][$i]);
84 $this->appoption[$name]= $option;
85 }
86 }
88 /* Parse MemberApplication*/
89 $tmp = array();
90 $tmp2 = array();
91 $prios = array();
92 $cats = array();
94 foreach($this->gosaMemberApplication as $memberApp){
95 if(preg_match("/\|/i",$memberApp)){
97 $tmp = split("\|",$memberApp);
99 if(!empty($tmp[0])){
100 $tmp2[$tmp[1]][$tmp[2]] = array("App"=>$tmp[0]);
101 }
102 if(!empty($tmp[1])){
103 $n = split("/",$tmp[1]);
104 $c = count($n);
105 $cats [$tmp[1]] = $n[$c-1];
106 }
107 $prios[$tmp[1]][$tmp[2]] = $tmp[2];
108 }else{
109 $tmp2[]['App'] = $memberApp;
110 }
111 }
113 $this->Categories = $cats;
115 $this->gosaMemberApplication = $tmp2;
116 $cats[""]="";
117 foreach($cats as $cat ){
118 if((isset($prios[$cat]))&&(count($prios[$cat]))){
119 $max = max($prios[$cat]);
120 $min = 1;//min($prios[$cat]);
121 $last = false;
122 for($i = $min ; $i < $max ; $i++){
123 if(!isset($prios[$cat][$i])){
124 if($last == false){
125 $this->gosaMemberApplication[$cat][$i]['App'] = "__SEPARATOR__".$i;
127 $last = true;
128 }
129 }else{
130 $last = false;
131 }
132 }
133 }
134 }
136 $tmp = array();
137 foreach($this->gosaMemberApplication as $key => $entries){
138 ksort ($entries);
139 foreach($entries as $entry){
140 $tmp[$key][]= $entry;
141 }
142 }
143 $this->gosaMemberApplication = $tmp;
144 $this->curbase = $this->config->current['BASE'];
146 /* Get required release informations */
147 if($this->enableReleaseManagement){
148 $this->InitialFAIrelease = $this->FAIrelease;
149 $this->Releases = $this->getReleases();
150 }
151 }
154 /* Combine new array */
155 function combineArrays($ar0,$ar1,$ar2)
156 {
157 $ret = array();
158 if(is_array($ar0))
159 foreach($ar0 as $ar => $a){
160 $ret[$ar]=$a;
161 }
162 if(is_array($ar1))
163 foreach($ar1 as $ar => $a){
164 $ret[$ar]=$a;
165 }
166 if(is_array($ar2))
167 foreach($ar2 as $ar => $a){
168 $ret[$ar]=$a;
169 }
170 return($ret);
171 }
173 function getpos($atr,$attrs)
174 {
175 $i = 0;
176 foreach($attrs as $attr => $name) {
177 $i++;
178 if($attr == $atr){
179 return($i);
180 }
181 }
182 return(-1);
183 }
185 function diffAppsInReleases()
186 {
187 /* Only diff if it is required
188 */
189 $ret =array();
191 /* If current release has changed */
192 if($this->FAIrelease != $this->InitialFAIrelease){
194 /* Walk through all apps which are currently displayed */
195 if(isset($this->gosaMemberApplication[$this->curCatDir])){
197 foreach($this->gosaMemberApplication[$this->curCatDir] as $entry){
199 /* If application is also available in new release, check if parameter differs */
200 if(in_array($entry['App'],$this->AllAppsForRelease)){
202 $old = array(); // Old application parameter
203 $new = array(); // New parameters
205 /* There are possibly no parameters specified */
206 if(isset($this->AllAppsForReleaseParameter[$this->InitialFAIrelease][$entry['App']])){
207 $old = $this->AllAppsForReleaseParameter[$this->InitialFAIrelease][$entry['App']];
208 }
210 if(isset($this->AllAppsForReleaseParameter[$this->FAIrelease][$entry['App']])){
211 $new = $this->AllAppsForReleaseParameter[$this->FAIrelease][$entry['App']];
212 }
214 /* Both (old & new) have no gosaApplicationParameter
215 */
216 if((!isset($old['gosaApplicationParameter'])) && (!isset($new['gosaApplicationParameter']))){
217 $ret[$entry['App']] = false;
219 /* Both got gosaApplicationParameter
220 */
221 }elseif((isset($old['gosaApplicationParameter'])) && (isset($new['gosaApplicationParameter']))){
222 if(array_differs($old['gosaApplicationParameter'],$new['gosaApplicationParameter'])){
223 $ret[$entry['App']] = true;
224 }else{
225 $ret[$entry['App']] = false;
226 }
227 }
228 /* Initialy had gosaApplicationParameter bot in new release not
229 */
230 }elseif((isset($old['gosaApplicationParameter'])) && (!isset($new['gosaApplicationParameter']))){
231 $ret[$entry['App']] = true;
233 /* Old release had no gosaApplicationParameter but new got some
234 */
235 }elseif((!isset($old['gosaApplicationParameter'])) && (isset($new['gosaApplicationParameter']))){
236 $ret[$entry['App']] = true;
237 }
238 }
239 }
240 }
241 return($ret);
242 }
244 /* TRansports the geiven Arraykey one position up*/
245 function ArrayUp($atr,$attrs)
246 {
247 $ret = $attrs;
248 $pos = $this->getpos($atr,$attrs) ;
249 $cn = count($attrs);
250 if(!(($pos == -1)||($pos == 1))){
251 $before = array_slice($attrs,0,($pos-2));
252 $mitte = array_reverse(array_slice($attrs,($pos-2),2));
253 $unten = array_slice($attrs,$pos);
254 $ret = array();
255 $ret = $this->combineArrays($before,$mitte,$unten);
256 }
257 return($ret);
258 }
261 /* TRansports the geiven Arraykey one position up*/
262 function ArrayDown($atr,$attrs)
263 {
264 $ret = $attrs;
265 $pos = $this->getpos($atr,$attrs) ;
266 $cn = count($attrs);
267 if(!(($pos == -1)||($pos == $cn))){
268 $before = array_slice($attrs,0,($pos-1));
269 $mitte = array_reverse(array_slice($attrs,($pos-1),2));
270 $unten = array_slice($attrs,($pos+1));
271 $ret = array();
272 $ret = $this->combineArrays($before,$mitte,$unten);
273 }
274 return($ret);
275 }
278 function catUp($id)
279 {
280 /* Get all cats depinding on current dir */
281 $cats = $this->GetSubdirs($this->curCatDir);
282 $newcats =$this->ArrayUp($id,$cats);
284 foreach($newcats as $cat => $name){
285 unset($this->Categories[$cat]);
286 }
287 foreach($newcats as $cat => $name){
288 $this->Categories[$cat]=$name;
289 }
290 }
293 function catDown($id)
294 {
295 /* Get all cats depinding on current dir */
296 $cats = $this->GetSubdirs($this->curCatDir);
298 $newcats =$this->ArrayDown($id,$cats);
300 foreach($newcats as $cat => $name){
301 unset($this->Categories[$cat]);
302 }
303 foreach($newcats as $cat => $name){
304 $this->Categories[$cat]=$name;
305 }
306 }
309 function getOneUp($appl)
310 {
311 $cat = $this->curCatDir;
312 $apps = $this->gosaMemberApplication[$cat];
314 $appsA = array();
315 foreach ($apps as $appkey => $name){
316 $appsA[$name['App']] =$name['App'];
317 }
319 $result = $this->ArrayUp($appl,$appsA);
321 $ret = array();
322 foreach($result as $app){
323 $ret[]=array("App"=>$app);
324 }
325 $this->gosaMemberApplication[$cat] = $ret;
326 }
329 function getOneDown($appl)
330 {
331 $cat = $this->curCatDir;
332 $apps = $this->gosaMemberApplication[$cat];
334 $appsA = array();
335 foreach ($apps as $appkey => $name){
336 $appsA[$name['App']] =$name['App'];
337 }
339 $result = $this->ArrayDown($appl,$appsA);
341 $ret = array();
342 foreach($result as $app){
343 $ret[]=array("App"=>$app);
344 }
345 $this->gosaMemberApplication[$cat] = $ret;
346 }
350 function AddSeperator($id)
351 {
352 $found = false;
353 $cat = "";
354 $tmp = array();
355 foreach($this->gosaMemberApplication[$this->curCatDir] as $appID => $app){
356 $tmp[] = $app;
357 if(($app['App'] == $id)&&(!$found)){
358 $cnt = count($this->gosaMemberApplication[$this->curCatDir]);
359 $tmp[] = array("App" => "__SEPARATOR__".($cnt+1));
360 $found = true;
361 }
362 }
363 if($found){
364 $this->gosaMemberApplication[$this->curCatDir]=$tmp;
365 }
366 }
368 function execute()
369 {
370 /* Call parent execute */
371 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 $this->is_account= !$this->is_account;
388 }
390 /* Do we represent a valid group? */
391 if (!$this->is_account && $this->parent == NULL){
392 $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\"> <b>".
393 _("This 'dn' is no appgroup.")."</b>";
394 return ($display);
395 }
397 /* Show tab dialog headers */
398 $display= "";
399 if ($this->parent != NULL){
400 if ($this->is_account){
401 $display= $this->show_header(_("Remove applications"),
402 _("This group has application features enabled. You can disable them by clicking below."));
403 } else {
404 $display.= $this->show_header(_("Create applications"),
405 _("This group has application features disabled. You can enable them by clicking below."));
406 return ($display);
407 }
408 }
411 /* Add Categorie */
414 if((isset($_POST['AddCat']))&&(isset($_POST['CatName']))&&(!empty($_POST['CatName']))){
416 if(preg_match("/[\\\\\/]/i",$_POST['CatName'])){
417 print_red(_("Invalid character in category name."));
418 }elseif(!in_array($_POST['CatName'],$this->Categories)){
419 if(empty($this->curCatDir)){
420 $this->Categories[$_POST['CatName']]=$_POST['CatName'];
421 }else{
422 $this->Categories[$this->curCatDir."/".$_POST['CatName']]=$_POST['CatName'];
423 }
424 }else{
425 print_red(_("The specified category already exists."));
426 }
427 }
430 $this->reload();
432 $this->diffAppsInReleases();
433 $only_once = false;
434 foreach($_POST as $name => $value){
436 if((preg_match("/AddSep_/",$name))&&(!$only_once)){
437 $only_once = true;
438 $n = preg_replace("/AddSep_/","",$name);
439 $val= preg_replace("/_.*$/","",$n);
440 $this->AddSeperator($val);
441 }
443 if((preg_match("/DelApp_/",$name))&&(!$only_once)){
444 $only_once = true;
447 if(preg_match("/DelApp___SEPARATOR__/",$name)) {
448 $n= preg_replace("/DelApp___SEPARATOR__/","",$name);
449 $val= "__SEPARATOR__".preg_replace("/_.*$/","",$n);
450 }else{
451 $n = preg_replace("/DelApp_/","",$name);
452 $val= preg_replace("/_.*$/","",$n);
453 }
455 foreach($this->gosaMemberApplication as $key => $cat){
456 foreach($cat as $key2 => $app){
457 if($app['App'] == $val){
458 unset($this->gosaMemberApplication[$key][$key2]);
459 if(isset($this->used_apps[$val])){
460 unset($this->used_apps[$val]);
461 }
462 }
463 }
464 }
465 }
467 if(preg_match("/DelCat_/",$name)){
468 $n = preg_replace("/DelCat_/","",$name);
469 $app = base64_decode( preg_replace("/_.*$/","",$n));
470 foreach($this->Categories as $key => $cat){
471 if($cat == $app){
472 foreach($this->Categories as $p => $n){
473 if(preg_match("/^".$key."\/.*/",$p)){
474 unset($this->Categories[$p]);
475 }
476 }
477 unset($this->Categories[$key]);
478 }
479 }
480 }
482 if((preg_match("/EdiApp_/",$name))&&(!$only_once)){
484 $only_once = true;
485 $appname = $value;
486 $appname = preg_replace("/EdiApp_/","",$name);
487 $appname = preg_replace("/_.*$/","",$appname);
489 /* We've got the appname, get parameters from ldap
490 */
491 $ldap= $this->config->get_ldap_link();
493 $tmp = search_config($this->config->data,"faiManagement","CLASS");
494 if(!empty($tmp)){
495 $tmp = array_flip($this->Releases);
496 $base = $tmp[$this->FAIrelease];
498 $ldap->cd($this->config->current['BASE']);
499 $ldap->search("(&(objectClass=gosaApplication)(cn=$appname))",array("gosaApplicationParameter"));
500 $found = "";
501 while($attrs = $ldap->fetch()) {
502 if(preg_match("/cn=".$appname.",".$base."/",$attrs['dn'])){
503 $found = $attrs['dn'];
504 }
505 }
506 $ldap->cat($found);
507 }else{
508 $ldap->cd($this->config->current['BASE']);
509 $ldap->search("(&(objectClass=gosaApplication)(cn=$appname))",array("gosaApplicationParameter"));
511 }
514 if ($ldap->count() != 1){
515 print_red (_("The selected application name is not uniq. Please check your LDAP."));
516 } else {
517 $attrs= $ldap->fetch();
518 if(isset($attrs['gosaApplicationParameter'])){
519 $this->dialog= TRUE;
521 /* Fill name and value arrays */
522 for ($i= 0; $i<$attrs['gosaApplicationParameter']['count']; $i++){
523 $option= preg_replace('/^[^:]+:/', '',
524 $attrs['gosaApplicationParameter'][$i]);
525 $name= preg_replace('/:.*$/', '',
526 $attrs['gosaApplicationParameter'][$i]);
527 $this->option_name[$i]= $name;
529 /* Fill with values from application, default should be
530 loaded by the external scripts */
531 if (isset($this->appoption[$name])){
532 $this->option_value[$i]= $this->appoption[$name];
533 }
534 }
536 /* Create edit field */
537 $table= "<table summary=\"\">";
538 for ($i= 0; $i < count($this->option_name); $i++){
539 if (isset($this->option_value[$i])){
540 $value= $this->option_value[$i];
541 } else {
542 $value= "";
543 }
544 $table.="<tr><td>".$this->option_name[$i]."</td><td>".
545 "<input name=\"value$i\" size=60 maxlength=250 ".
546 "value=\"".$value."\"><br></td></tr>";
547 }
548 $table.= "</table>";
549 $this->table= $table;
550 } else {
551 print_red (_("The selected application has no options."));
552 }
553 }
554 }
555 }
557 $this->reload();
559 /* Add group with post */
560 if((isset($_GET['act']))&&($_GET['act']=="add")){
561 $this->used_apps[$_GET['id']]= $_GET['id'];
562 asort($this->used_apps);
563 $this->addApp($_GET['id']);
564 }
566 /* Add multiple */
567 if(isset($_POST['AddApps'])){
568 foreach($_POST as $name => $value){
569 if(preg_match("/AddApp_/",$name)){
570 $app = preg_replace("/AddApp_/","",$name);
571 $this->addApp($app);
572 }
573 }
574 }
577 /* Cancel edit options? */
578 if (isset($_POST['edit_options_cancel'])){
579 $this->dialog= FALSE;
580 }
582 /* Finish edit options? */
583 if (isset($_POST['edit_options_finish'])){
584 $this->dialog= FALSE;
586 /* Save informations passed by the user */
587 $this->option_value= array();
588 for ($i= 0; $i<count($this->option_name); $i++){
589 $this->appoption[$this->option_name[$i]]= $_POST["value$i"];
590 $this->is_modified= TRUE;
591 }
592 }
594 /* Prepare templating stuff */
595 $smarty= get_smarty();
596 $smarty->assign("used_apps", $this->used_apps);
597 $apps= array();
598 foreach ($this->apps as $key => $value){
599 if (!array_key_exists($key, $this->used_apps)){
600 $apps["$key"]= "$value";
601 }
602 }
604 $div = new DivSelectBox("appgroup");
606 $div->SetHeight(300);
608 /* NEW LIST MANAGMENT
609 * We also need to search for the departments
610 * So we are able to navigate like in konquerer
611 */
613 //FIXME: Why do we not use get_list here? It's the same code all over the time...
614 $ldap = $this->config->get_ldap_link();
615 $ldap->cd($this->curbase) ;
616 $ldap->ls("(objectClass=gosaDepartment)");
617 $departments= array();
618 $tmp = array();
619 while ($value = $ldap->fetch()){
620 $tmp[strtolower($value['dn']).$value['dn']]=$value;
621 }
622 ksort($tmp);
623 foreach($tmp as $value){
624 $fdn= @LDAP::fix($value['dn']);
625 if($value["description"][0]!=".."){
626 $departments[$value['dn']]= convert_department_dn($fdn)." - [".$value["description"][0]."]";
627 }else{
628 $departments[$value['dn']]=convert_department_dn($fdn);
629 }
630 }
632 /* END NEW LIST MANAGMENT
633 */
635 $linkopen = "<a href='?plug=".$_GET['plug']."&act=depopen&depid=%s'>%s</a>";
636 $linkadd = "<a href='?plug=".$_GET['plug']."&act=add&id=%s'>%s</a>";
638 $base_back = preg_replace("/^[^,]+,/","",$this->curbase);
639 if((strlen($base_back)>= strlen($this->config->current['BASE']))&&($this->curbase!=$this->config->current['BASE'])){
640 $div->AddEntry(array(
641 array("string"=>sprintf($linkopen,base64_encode($base_back),".. ["._("back")."]"),
642 "attach"=>"style='border:0px;'")
643 ));
644 }
645 foreach($departments as $key => $app){
646 $div->AddEntry(array(
647 array("string"=>"<img class='center' src='images/folder.png' alt='"._("department")."'> ".sprintf($linkopen,base64_encode($key),$app),
648 "attach"=>"style='border:0px;'")
649 ));
650 }
652 foreach($apps as $key => $app){
653 $div->AddEntry(array(
654 array("string"=>sprintf("<input class='center' type='checkbox' value='1' name='AddApp_%s'>",$key).
655 "<img class='center' src='images/select_application.png' alt='"._("application")."'> ".sprintf($linkadd,$key,$app),
656 "attach"=>"style='border:0px;'")
657 ));
658 }
660 if((isset($_GET['act']))&&(($_GET['act'] == "cat_up")||($_GET['act']=="cat_down"))){
661 if($_GET['act']=="cat_up"){
662 $this->catUp(base64_decode($_GET['id']));
663 }
664 if($_GET['act']=="cat_down"){
665 $this->catDown(base64_decode($_GET['id']));
666 }
667 }
669 if((isset($_GET['act']))&&(($_GET['act'] == "one_up")||($_GET['act']=="one_down"))){
670 if(isset($_GET['id'])){
671 $id = $_GET['id'];
672 $act = $_GET['act'];
674 if($act == "one_up"){
675 $this->getOneUp($id);
676 }elseif($act == "one_down") {
677 $this->getOneDown($id);
678 }
679 }
680 }
682 $div2 = new DivSelectBox("appgroup");
683 $div2->SetHeight(300);
685 $linkopen = "<img class='center' src='images/folder.png' alt=\"\"> <a href='?plug=".$_GET['plug']."&act=open&id=%s'>%s</a>";
686 $catremove = " <input type='image' src='images/edittrash.png' title='"._("Delete entry")."' name='DelCat_%s' value='%s'>";
687 $app = "<img class='center' src='images/select_application.png' alt=\"\"> %s";
689 $catupdown = "<a href='?plug=".$_GET['plug']."&act=cat_up&id=%s'>
690 <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'>
691 <img alt=\"\" src='images/sort_down.png' title='"._("Move down")."' border=0></a>";
693 if(empty($this->curCatDir)){
694 $cnt =0;
695 }else{
696 $cnt = count(split("/",$this->curCatDir));
697 $tmp = split("/",$this->curCatDir);
698 $bbk = "";
699 for($i = 0 ; $i < ($cnt -1 ) ; $i++){
700 $bbk .= $tmp[$i];
701 }
702 $div2 ->AddEntry(array(array("string"=>sprintf($linkopen,base64_encode($bbk),"..")),array("string"=>" ","attach"=>"style='border-right:0px;'")));
703 }
705 $this->GetSubdirs($this->curCatDir);
707 foreach($this->GetSubdirs($this->curCatDir) as $path => $name){
708 $div2 ->AddEntry(array(
709 array("string"=>sprintf($linkopen,base64_encode($path),$name)),
710 array("string"=>preg_replace("/%s/",base64_encode($path),$catupdown.$catremove),
711 "attach"=>"align='right' style='width:80px;border-right:0px;'")));
712 }
714 /* Append entries */
716 $separator ="<hr size=1>";
718 $sep = "<input type='image' src='images/back.png' title='"._("Insert seperator")."' value='%s' name='AddSep_%s'>";
720 $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>".
721 " <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>".
722 " <input type='image' src='images/edittrash.png' title='"._("Delete entry")."' name='DelApp_%s' value='%s' alt='{t}delete{/t}' >";
723 $edit= " <input type='image' src='images/edit.png' title='"._("Edit entry")."' name='EdiApp_%s' value='%s' alt='{t}edit{/t}' >";
725 $Differences = $this->diffAppsInReleases();
727 if(isset($this->gosaMemberApplication[$this->curCatDir])){
728 foreach($this->gosaMemberApplication[$this->curCatDir] as $cat => $entry){
731 if(preg_match("/__SEPARATOR__/",$entry['App'])){
732 $div2 ->AddEntry(array(array("string"=>$separator),
733 array("string"=>preg_replace("/\%s/",htmlentities($entry['App']),$upudown),"attach"=>"align='right' style='border-right:0px;'")));
734 }else{
736 $image = "";
737 /* Check if application was available within selected release
738 * or application list if release management is not active
739 */
740 if(!in_array($entry['App'],$this->AllAppsForRelease)){
742 /* release managent is active
743 */
744 if(!$this->enableReleaseManagement){
745 $image = "<img class='center' src='images/select_invalid_application.png'
746 title='"._("This application is no longer available.")."'> ";
747 }else{
748 $image = "<img class='center' src='images/select_invalid_application.png'
749 title='".sprintf(_("This application is not available in any release named %s."),$this->FAIrelease)."'> ";
750 }
752 }elseif(isset($Differences[$entry['App']]) && ($Differences[$entry['App']] == true)) {
753 $entry['App'].=" <i>["._("Check parameter")."]</i>";
754 $image = "<img class='center' src='images/select_invalid_application.png'
755 title='"._("This application has changed parameters.")."'> ";
756 }else{
757 $image = "<img class='center' src='images/select_application.png' alt=\"\"> ";
758 }
760 $div2->AddEntry(array(array("string"=>sprintf($image."%s",$entry['App'])),
761 array("string"=>preg_replace("/\%s/",htmlentities($entry['App']),$sep.$edit.$upudown),
762 "attach"=>"align='right' style='width:100px;border-right:0px;'")));
763 }
764 }
765 }
767 $smarty->assign("UsedApps", $div2->DrawList());
768 $smarty->assign("List", $div->DrawList());
769 $smarty->assign("apps", $apps);
771 $smarty->assign("enableReleaseManagement",$this->enableReleaseManagement);
773 if($this->enableReleaseManagement){
774 $smarty->assign("FAIrelease", $this->FAIrelease);
775 $smarty->assign("Releases", $this->Releases);
777 if(count($this->used_apps)){
778 $smarty->assign("ReleaseSelectAble", false);
779 }else{
780 $smarty->assign("ReleaseSelectAble", true);
781 }
782 }
783 $smarty->assign("ReleaseSelectAble", true);
785 /* Show main page */
786 if ($this->dialog){
787 $smarty->assign("table", $this->table);
788 $display.= $smarty->fetch (get_template_path('application_options.tpl', TRUE));
789 } else {
790 $display.= $smarty->fetch (get_template_path('application.tpl', TRUE));
791 }
792 return ($display);
793 }
796 function getReleases()
797 {
798 $dn = "ou=apps,".$this->config->current['BASE'];
799 $ldap = $this->config->get_ldap_link();
800 $ldap->cd($dn);
801 $ldap->search("objectClass=organizationalUnit",array("ou"));
802 $ret =array();
803 while($attrs = $ldap->fetch()){
804 if(preg_match("/ou=apps,/",$attrs['dn'])){
805 $bb = preg_replace("/ou=apps,.*/","",$attrs['dn']);
806 $parts = array_reverse(split("ou=",$bb));
808 $str ="";
809 foreach($parts as $part){
810 if(empty($part)) {
811 continue;
812 }
813 $str .= str_replace(",","",$part)."/";
814 }
815 $name = preg_replace("/\/$/","",$str);
816 if(empty($name)) {
817 $name ="/";
818 }
819 $ret[$attrs['dn']] = $name;
820 }
821 }
822 return($ret);
823 }
825 function save_object()
826 {
827 plugin::save_object();
828 }
831 function remove_from_parent()
832 {
833 plugin::remove_from_parent();
835 $this->attrs["gosaMemberApplication"]= array();
837 $ldap= $this->config->get_ldap_link();
838 $ldap->cd($this->dn);
839 $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 ?>