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 ;
40 var $ui ;
43 function appgroup ($config, $dn= NULL, $parent= NULL)
44 {
45 $this->ui = get_userinfo();
47 /* prepare group app for release management */
48 $tmp = search_config($config->data,"faiManagement","CLASS");
49 if(!empty($tmp)){
50 $this->enableReleaseManagement = true;
51 $this->objectclasses [] = "FAIreleaseTag";
52 $this->attributes[] = "FAIrelease";
53 }
55 plugin::plugin ($config, $dn, $parent);
57 /* In some case of old applikations with old release tag saving, we
58 must reassign is_account state.
59 (Or if release management wasn't activated before creating this app) */
60 if($this->enableReleaseManagement){
62 /* Release management is activated && this is a valid group app account,
63 but no release class was found, so activate is_account flag */
64 if($dn != "new" && ( in_array("gosaApplicationGroup",$this->attrs['objectClass'])) &&
65 (!in_array("FAIreleaseTag",$this->attrs['objectClass']))){
66 $this->is_account =true;
67 }
68 }
71 /* Load member applications */
72 if (isset ($this->attrs["gosaMemberApplication"][0])){
73 $this->gosaMemberApplication = array();
74 for ($i= 0; $i<$this->attrs["gosaMemberApplication"]["count"]; $i++){
75 $this->gosaMemberApplication[]=
76 $this->attrs["gosaMemberApplication"][$i];
77 }
78 }
80 /* Load application options */
81 if (isset($this->attrs['gosaApplicationParameter'])){
82 for ($i= 0; $i<$this->attrs['gosaApplicationParameter']['count']; $i++){
83 $option= preg_replace('/^[^:]+:/', '',
84 $this->attrs['gosaApplicationParameter'][$i]);
85 $name= preg_replace('/:.*$/', '',
86 $this->attrs['gosaApplicationParameter'][$i]);
87 $this->appoption[$name]= $option;
88 }
89 }
91 /* Parse MemberApplication*/
92 $tmp = array();
93 $tmp2 = array();
94 $prios = array();
95 $cats = array();
97 foreach($this->gosaMemberApplication as $memberApp){
98 if(preg_match("/\|/i",$memberApp)){
100 $tmp = split("\|",$memberApp);
102 if(!empty($tmp[0])){
103 $tmp2[$tmp[1]][$tmp[2]] = array("App"=>$tmp[0]);
104 }
105 if(!empty($tmp[1])){
106 $n = split("/",$tmp[1]);
107 $c = count($n);
108 $cats [$tmp[1]] = $n[$c-1];
109 }
110 $prios[$tmp[1]][$tmp[2]] = $tmp[2];
111 }else{
112 $tmp2[]['App'] = $memberApp;
113 }
114 }
116 $this->Categories = $cats;
118 $this->gosaMemberApplication = $tmp2;
119 $cats[""]="";
120 foreach($cats as $cat ){
121 if((isset($prios[$cat]))&&(count($prios[$cat]))){
122 $max = max($prios[$cat]);
123 $min = 1;//min($prios[$cat]);
124 $last = false;
125 for($i = $min ; $i < $max ; $i++){
126 if(!isset($prios[$cat][$i])){
127 if($last == false){
128 $this->gosaMemberApplication[$cat][$i]['App'] = "__SEPARATOR__".$i;
130 $last = true;
131 }
132 }else{
133 $last = false;
134 }
135 }
136 }
137 }
139 $tmp = array();
140 foreach($this->gosaMemberApplication as $key => $entries){
141 ksort ($entries);
142 foreach($entries as $entry){
143 $tmp[$key][]= $entry;
144 }
145 }
146 $this->gosaMemberApplication = $tmp;
147 $this->curbase = $this->config->current['BASE'];
149 /* Get required release informations */
150 if($this->enableReleaseManagement){
151 $this->InitialFAIrelease = $this->FAIrelease;
152 $this->Releases = $this->getReleases();
153 }
154 }
157 /* Combine new array */
158 function combineArrays($ar0,$ar1,$ar2)
159 {
160 $ret = array();
161 if(is_array($ar0))
162 foreach($ar0 as $ar => $a){
163 $ret[$ar]=$a;
164 }
165 if(is_array($ar1))
166 foreach($ar1 as $ar => $a){
167 $ret[$ar]=$a;
168 }
169 if(is_array($ar2))
170 foreach($ar2 as $ar => $a){
171 $ret[$ar]=$a;
172 }
173 return($ret);
174 }
176 function getpos($atr,$attrs)
177 {
178 $i = 0;
179 foreach($attrs as $attr => $name) {
180 $i++;
181 if($attr == $atr){
182 return($i);
183 }
184 }
185 return(-1);
186 }
188 function diffAppsInReleases()
189 {
190 /* Only diff if it is required
191 */
192 $ret =array();
194 /* If current release has changed */
195 if($this->FAIrelease != $this->InitialFAIrelease){
197 /* Walk through all apps which are currently displayed */
198 if(isset($this->gosaMemberApplication[$this->curCatDir])){
200 foreach($this->gosaMemberApplication[$this->curCatDir] as $entry){
202 /* If application is also available in new release, check if parameter differs */
203 if(in_array($entry['App'],$this->AllAppsForRelease)){
205 $old = array(); // Old application parameter
206 $new = array(); // New parameters
208 /* There are possibly no parameters specified */
209 if(isset($this->AllAppsForReleaseParameter[$this->InitialFAIrelease][$entry['App']])){
210 $old = $this->AllAppsForReleaseParameter[$this->InitialFAIrelease][$entry['App']];
211 }
213 if(isset($this->AllAppsForReleaseParameter[$this->FAIrelease][$entry['App']])){
214 $new = $this->AllAppsForReleaseParameter[$this->FAIrelease][$entry['App']];
215 }
217 /* Both (old & new) have no gosaApplicationParameter
218 */
219 if((!isset($old['gosaApplicationParameter'])) && (!isset($new['gosaApplicationParameter']))){
220 $ret[$entry['App']] = false;
222 /* Both got gosaApplicationParameter
223 */
224 }elseif((isset($old['gosaApplicationParameter'])) && (isset($new['gosaApplicationParameter']))){
225 if(array_differs($old['gosaApplicationParameter'],$new['gosaApplicationParameter'])){
226 $ret[$entry['App']] = true;
227 }else{
228 $ret[$entry['App']] = false;
229 }
230 }
231 /* Initialy had gosaApplicationParameter bot in new release not
232 */
233 }elseif((isset($old['gosaApplicationParameter'])) && (!isset($new['gosaApplicationParameter']))){
234 $ret[$entry['App']] = true;
236 /* Old release had no gosaApplicationParameter but new got some
237 */
238 }elseif((!isset($old['gosaApplicationParameter'])) && (isset($new['gosaApplicationParameter']))){
239 $ret[$entry['App']] = true;
240 }
241 }
242 }
243 }
244 return($ret);
245 }
247 /* TRansports the geiven Arraykey one position up*/
248 function ArrayUp($atr,$attrs)
249 {
250 $ret = $attrs;
251 $pos = $this->getpos($atr,$attrs) ;
252 $cn = count($attrs);
253 if(!(($pos == -1)||($pos == 1))){
254 $before = array_slice($attrs,0,($pos-2));
255 $mitte = array_reverse(array_slice($attrs,($pos-2),2));
256 $unten = array_slice($attrs,$pos);
257 $ret = array();
258 $ret = $this->combineArrays($before,$mitte,$unten);
259 }
260 return($ret);
261 }
264 /* TRansports the geiven Arraykey one position up*/
265 function ArrayDown($atr,$attrs)
266 {
267 $ret = $attrs;
268 $pos = $this->getpos($atr,$attrs) ;
269 $cn = count($attrs);
270 if(!(($pos == -1)||($pos == $cn))){
271 $before = array_slice($attrs,0,($pos-1));
272 $mitte = array_reverse(array_slice($attrs,($pos-1),2));
273 $unten = array_slice($attrs,($pos+1));
274 $ret = array();
275 $ret = $this->combineArrays($before,$mitte,$unten);
276 }
277 return($ret);
278 }
281 function catUp($id)
282 {
283 /* Get all cats depinding on current dir */
284 $cats = $this->GetSubdirs($this->curCatDir);
285 $newcats =$this->ArrayUp($id,$cats);
287 foreach($newcats as $cat => $name){
288 unset($this->Categories[$cat]);
289 }
290 foreach($newcats as $cat => $name){
291 $this->Categories[$cat]=$name;
292 }
293 }
296 function catDown($id)
297 {
298 /* Get all cats depinding on current dir */
299 $cats = $this->GetSubdirs($this->curCatDir);
301 $newcats =$this->ArrayDown($id,$cats);
303 foreach($newcats as $cat => $name){
304 unset($this->Categories[$cat]);
305 }
306 foreach($newcats as $cat => $name){
307 $this->Categories[$cat]=$name;
308 }
309 }
312 function getOneUp($appl)
313 {
314 $cat = $this->curCatDir;
315 $apps = $this->gosaMemberApplication[$cat];
317 $appsA = array();
318 foreach ($apps as $appkey => $name){
319 $appsA[$name['App']] =$name['App'];
320 }
322 $result = $this->ArrayUp($appl,$appsA);
324 $ret = array();
325 foreach($result as $app){
326 $ret[]=array("App"=>$app);
327 }
328 $this->gosaMemberApplication[$cat] = $ret;
329 }
332 function getOneDown($appl)
333 {
334 $cat = $this->curCatDir;
335 $apps = $this->gosaMemberApplication[$cat];
337 $appsA = array();
338 foreach ($apps as $appkey => $name){
339 $appsA[$name['App']] =$name['App'];
340 }
342 $result = $this->ArrayDown($appl,$appsA);
344 $ret = array();
345 foreach($result as $app){
346 $ret[]=array("App"=>$app);
347 }
348 $this->gosaMemberApplication[$cat] = $ret;
349 }
353 function AddSeperator($id)
354 {
355 $found = false;
356 $cat = "";
357 $tmp = array();
358 foreach($this->gosaMemberApplication[$this->curCatDir] as $appID => $app){
359 $tmp[] = $app;
360 if(($app['App'] == $id)&&(!$found)){
361 $cnt = count($this->gosaMemberApplication[$this->curCatDir]);
362 $tmp[] = array("App" => "__SEPARATOR__".($cnt+1));
363 $found = true;
364 }
365 }
366 if($found){
367 $this->gosaMemberApplication[$this->curCatDir]=$tmp;
368 }
369 }
371 function execute()
372 {
373 /* Call parent execute */
374 plugin::execute();
376 if((isset($_GET['act']))&&($_GET['act']=="depopen")){
377 $dep = base64_decode($_GET['depid']);
378 if(isset($this->config->idepartments[$dep])){
379 $this->curbase =$dep;
380 }
381 }
383 if((isset($_GET['act']))&&($_GET['act']=="open")){
384 $this->curCatDir = base64_decode($_GET['id']);
385 }
387 /* Do we need to flip is_account state? */
388 if (isset($_POST['modify_state'])){
390 /* Onyl change account state if allowed */
391 if($this->is_account && $this->acl == "#all#"){
392 $this->is_account= !$this->is_account;
393 }elseif(!$this->is_account && chkacl($this->acl,"create") == ""){
394 $this->is_account= !$this->is_account;
395 }
396 }
398 /* Do we represent a valid group? */
399 if (!$this->is_account && $this->parent == NULL){
400 $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\"> <b>".
401 _("This 'dn' is no appgroup.")."</b>";
402 return ($display);
403 }
405 /* Show tab dialog headers */
406 $display= "";
407 if ($this->parent != NULL){
408 if ($this->is_account){
409 $display= $this->show_header(_("Remove applications"),
410 _("This group has application features enabled. You can disable them by clicking below."));
411 } else {
412 $display.= $this->show_header(_("Create applications"),
413 _("This group has application features disabled. You can enable them by clicking below."));
414 return ($display);
415 }
416 }
419 /* Add Categorie */
422 if((isset($_POST['AddCat']))&&(isset($_POST['CatName']))&&(!empty($_POST['CatName']))){
424 if(preg_match("/[\\\\\/]/i",$_POST['CatName'])){
425 print_red(_("Invalid character in category name."));
426 }elseif(!in_array($_POST['CatName'],$this->Categories)){
427 if(empty($this->curCatDir)){
428 $this->Categories[$_POST['CatName']]=$_POST['CatName'];
429 }else{
430 $this->Categories[$this->curCatDir."/".$_POST['CatName']]=$_POST['CatName'];
431 }
432 }else{
433 print_red(_("The specified category already exists."));
434 }
435 }
438 $this->reload();
440 $this->diffAppsInReleases();
441 $only_once = false;
442 foreach($_POST as $name => $value){
444 if((preg_match("/AddSep_/",$name))&&(!$only_once)){
445 $only_once = true;
446 $n = preg_replace("/AddSep_/","",$name);
447 $val= preg_replace("/_.*$/","",$n);
448 $this->AddSeperator($val);
449 }
451 if((preg_match("/DelApp_/",$name))&&(!$only_once)){
452 $only_once = true;
455 if(preg_match("/DelApp___SEPARATOR__/",$name)) {
456 $n= preg_replace("/DelApp___SEPARATOR__/","",$name);
457 $val= "__SEPARATOR__".preg_replace("/_.*$/","",$n);
458 }else{
459 $n = preg_replace("/DelApp_/","",$name);
460 $val= preg_replace("/_.*$/","",$n);
461 }
463 foreach($this->gosaMemberApplication as $key => $cat){
464 foreach($cat as $key2 => $app){
466 if($app['App'] == $val){
467 unset($this->gosaMemberApplication[$key][$key2]);
468 if(isset($this->used_apps[$val])){
469 foreach($this->getParameters($val) as $para){
470 if(isset($this->appoption[$para])){
471 unset($this->appoption[$para]);
472 }
473 }
474 unset($this->used_apps[$val]);
475 }
476 }
477 }
478 }
479 }
481 if(preg_match("/DelCat_/",$name)){
482 $n = preg_replace("/DelCat_/","",$name);
483 $app = base64_decode( preg_replace("/_.*$/","",$n));
484 foreach($this->Categories as $key => $cat){
485 if($cat == $app){
486 foreach($this->Categories as $p => $n){
487 if(preg_match("/^".$key."\/.*/",$p)){
488 unset($this->Categories[$p]);
489 }
490 }
491 unset($this->Categories[$key]);
492 }
493 }
494 }
496 if((preg_match("/EdiApp_/",$name))&&(!$only_once)){
498 $only_once = true;
499 $appname = $value;
500 $appname = preg_replace("/EdiApp_/","",$name);
501 $appname = preg_replace("/_.*$/","",$appname);
503 /* We've got the appname, get parameters from ldap
504 */
505 $ldap= $this->config->get_ldap_link();
507 $tmp = search_config($this->config->data,"faiManagement","CLASS");
508 if(!empty($tmp)){
509 $tmp = array_flip($this->Releases);
510 $base = $tmp[$this->FAIrelease];
512 $ldap->cd($this->config->current['BASE']);
513 $ldap->search("(&(objectClass=gosaApplication)(cn=$appname))",array("gosaApplicationParameter"));
514 $found = "";
515 while($attrs = $ldap->fetch()) {
516 if(preg_match("/cn=".$appname.",".$base."/",$attrs['dn'])){
517 $found = $attrs['dn'];
518 }
519 }
520 $ldap->cat($found, array("gosaApplicationParameter"));
521 }else{
522 $ldap->cd($this->config->current['BASE']);
523 $ldap->search("(&(objectClass=gosaApplication)(cn=$appname))",array("gosaApplicationParameter"));
524 }
527 if ($ldap->count() != 1){
528 print_red (_("The selected application name is not uniq. Please check your LDAP."));
529 } else {
530 $attrs= $ldap->fetch();
531 if(isset($attrs['gosaApplicationParameter'])){
532 $this->dialog= TRUE;
534 /* Fill name and value arrays */
535 for ($i= 0; $i<$attrs['gosaApplicationParameter']['count']; $i++){
536 $option= preg_replace('/^[^:]+:/', '',
537 $attrs['gosaApplicationParameter'][$i]);
538 $name= preg_replace('/:.*$/', '',
539 $attrs['gosaApplicationParameter'][$i]);
540 $this->option_name[$i]= $name;
542 /* Fill with values from application, default should be
543 loaded by the external scripts */
544 if (isset($this->appoption[$name])){
545 $this->option_value[$i]= $this->appoption[$name];
546 }
547 }
549 /* Create edit field */
550 $table= "<table summary=\"\">";
551 for ($i= 0; $i < count($this->option_name); $i++){
552 if (isset($this->option_value[$i])){
553 $value= $this->option_value[$i];
554 } else {
555 $value= "";
556 }
557 $table.="<tr><td>".$this->option_name[$i]."</td><td>".
558 "<input name=\"value$i\" size=60 maxlength=250 ".
559 "value=\"".$value."\"><br></td></tr>";
560 }
561 $table.= "</table>";
562 $this->table= $table;
563 } else {
564 print_red (_("The selected application has no options."));
565 }
566 }
567 }
568 }
570 $this->reload();
572 /* Add group with post */
573 if((isset($_GET['act']))&&($_GET['act']=="add")){
574 $this->used_apps[$_GET['id']]= $_GET['id'];
575 asort($this->used_apps);
576 $this->addApp($_GET['id']);
577 }
579 /* Add multiple */
580 if(isset($_POST['AddApps'])){
581 foreach($_POST as $name => $value){
582 if(preg_match("/AddApp_/",$name)){
583 $app = preg_replace("/AddApp_/","",$name);
584 $this->addApp($app);
585 }
586 }
587 }
590 /* Cancel edit options? */
591 if (isset($_POST['edit_options_cancel'])){
592 $this->dialog= FALSE;
593 }
595 /* Finish edit options? */
596 if (isset($_POST['edit_options_finish'])){
597 $this->dialog= FALSE;
599 /* Save informations passed by the user */
600 $this->option_value= array();
601 for ($i= 0; $i<count($this->option_name); $i++){
602 $this->appoption[$this->option_name[$i]]= $_POST["value$i"];
603 $this->is_modified= TRUE;
604 }
605 }
607 /* Prepare templating stuff */
608 $smarty= get_smarty();
609 $smarty->assign("used_apps", $this->used_apps);
610 $apps= array();
611 foreach ($this->apps as $key => $value){
612 if (!array_key_exists($key, $this->used_apps)){
613 $apps["$key"]= "$value";
614 }
615 }
617 $div = new DivSelectBox("appgroup");
619 $div->SetHeight(300);
621 /* get departments */
622 $ui = get_userinfo();
623 $departments = array();
624 $res = get_list("(objectClass=gosaDepartment)",$ui->subtreeACL,$this->curbase,array("description","cn","ou"),GL_SIZELIMIT);
625 foreach($res as $value){
627 $fdn = $value['dn'];
628 $fdn = preg_replace("/".normalizePreg($this->curbase)."/","",$fdn);
629 $fdn= @LDAP::fix($fdn);
630 if($value["description"][0]!=".."){
631 $departments[$value['dn']]= convert_department_dn($fdn)." - [".$value["description"][0]."]";
632 }else{
633 $departments[$value['dn']]= convert_department_dn($fdn);
634 }
635 }
637 $linkopen = "<a href='?plug=".$_GET['plug']."&act=depopen&depid=%s'>%s</a>";
638 $linkadd = "<a href='?plug=".$_GET['plug']."&act=add&id=%s'>%s</a>";
640 $base_back = preg_replace("/^[^,]+,/","",$this->curbase);
641 if((strlen($base_back)>= strlen($this->config->current['BASE']))&&($this->curbase!=$this->config->current['BASE'])){
642 $div->AddEntry(array(
643 array("string"=>sprintf($linkopen,base64_encode($base_back),".. ["._("back")."]"),
644 "attach"=>"style='border:0px;'")
645 ));
646 }
647 foreach($departments as $key => $app){
648 $div->AddEntry(array(
649 array("string"=>"<img class='center' src='images/folder.png' alt='"._("department")."'> ".sprintf($linkopen,base64_encode($key),$app),
650 "attach"=>"style='border:0px;'")
651 ));
652 }
654 foreach($apps as $key => $app){
655 $div->AddEntry(array(
656 array("string"=>sprintf("<input class='center' type='checkbox' value='1' name='AddApp_%s'>",$key).
657 "<img class='center' src='images/select_application.png' alt='"._("application")."'> ".sprintf($linkadd,$key,$app),
658 "attach"=>"style='border:0px;'")
659 ));
660 }
662 if((isset($_GET['act']))&&(($_GET['act'] == "cat_up")||($_GET['act']=="cat_down"))){
663 if($_GET['act']=="cat_up"){
664 $this->catUp(base64_decode($_GET['id']));
665 }
666 if($_GET['act']=="cat_down"){
667 $this->catDown(base64_decode($_GET['id']));
668 }
669 }
671 if((isset($_GET['act']))&&(($_GET['act'] == "one_up")||($_GET['act']=="one_down"))){
672 if(isset($_GET['id'])){
673 $id = $_GET['id'];
674 $act = $_GET['act'];
676 if($act == "one_up"){
677 $this->getOneUp($id);
678 }elseif($act == "one_down") {
679 $this->getOneDown($id);
680 }
681 }
682 }
684 $div2 = new DivSelectBox("appgroup");
685 $div2->SetHeight(300);
687 $linkopen = "<img class='center' src='images/folder.png' alt=\"\"> <a href='?plug=".$_GET['plug']."&act=open&id=%s'>%s</a>";
688 $catremove = " <input type='image' src='images/edittrash.png' title='"._("Delete entry")."' name='DelCat_%s' value='%s'>";
689 $app = "<img class='center' src='images/select_application.png' alt=\"\"> %s";
691 $catupdown = "<a href='?plug=".$_GET['plug']."&act=cat_up&id=%s'>
692 <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'>
693 <img alt=\"\" src='images/sort_down.png' title='"._("Move down")."' border=0></a>";
695 if(empty($this->curCatDir)){
696 $cnt =0;
697 }else{
698 $cnt = count(split("/",$this->curCatDir));
699 $tmp = split("/",$this->curCatDir);
700 $bbk = "";
701 for($i = 0 ; $i < ($cnt -1 ) ; $i++){
702 $bbk .= $tmp[$i];
703 }
704 $div2 ->AddEntry(array(array("string"=>sprintf($linkopen,base64_encode($bbk),"..")),array("string"=>" ","attach"=>"style='border-right:0px;'")));
705 }
707 $this->GetSubdirs($this->curCatDir);
709 foreach($this->GetSubdirs($this->curCatDir) as $path => $name){
710 $div2 ->AddEntry(array(
711 array("string"=>sprintf($linkopen,base64_encode($path),$name)),
712 array("string"=>preg_replace("/%s/",base64_encode($path),$catupdown.$catremove),
713 "attach"=>"align='right' style='width:80px;border-right:0px;'")));
714 }
716 /* Append entries */
718 $separator ="<hr size=1>";
720 $sep = "<input type='image' src='images/back.png' title='"._("Insert seperator")."' value='%s' name='AddSep_%s'>";
722 $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>".
723 " <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>".
724 " <input type='image' src='images/edittrash.png' title='"._("Delete entry")."' name='DelApp_%s' value='%s' alt='{t}delete{/t}' >";
725 $edit= " <input type='image' src='images/edit.png' title='"._("Edit entry")."' name='EdiApp_%s' value='%s' alt='{t}edit{/t}' >";
727 $Differences = $this->diffAppsInReleases();
729 if(isset($this->gosaMemberApplication[$this->curCatDir])){
730 foreach($this->gosaMemberApplication[$this->curCatDir] as $cat => $entry){
733 if(preg_match("/__SEPARATOR__/",$entry['App'])){
734 $div2 ->AddEntry(array(array("string"=>$separator),
735 array("string"=>preg_replace("/\%s/",htmlentities($entry['App']),$upudown),"attach"=>"align='right' style='border-right:0px;'")));
736 }else{
738 $image = "";
739 /* Check if application was available within selected release
740 * or application list if release management is not active
741 */
742 if(!in_array($entry['App'],$this->AllAppsForRelease)){
744 /* release managent is active
745 */
746 if(!$this->enableReleaseManagement){
747 $image = "<img class='center' alt='R' src='images/select_invalid_application.png'
748 title='"._("This application is no longer available.")."'> ";
749 }else{
750 $image = "<img class='center' alt='F' src='images/select_invalid_application.png'
751 title=\"".sprintf(_("This application is not available in any release named %s."),$this->FAIrelease)."\"> ";
752 }
754 }elseif(isset($Differences[$entry['App']]) && ($Differences[$entry['App']] == true)) {
755 $entry['App'].=" <i>["._("Check parameter")."]</i>";
756 $image = "<img class='center' src='images/select_invalid_application.png'
757 title='"._("This application has changed parameters.")."'> ";
758 }else{
759 $image = "<img class='center' src='images/select_application.png' alt=\"\"> ";
760 }
762 $div2->AddEntry(array(array("string"=>sprintf($image."%s",$entry['App'])),
763 array("string"=>preg_replace("/\%s/",htmlentities($entry['App']),$sep.$edit.$upudown),
764 "attach"=>"align='right' style='width:100px;border-right:0px;'")));
765 }
766 }
767 }
769 $smarty->assign("UsedApps", $div2->DrawList());
770 $smarty->assign("List", $div->DrawList());
771 $smarty->assign("apps", $apps);
773 $smarty->assign("enableReleaseManagement",$this->enableReleaseManagement);
775 if($this->enableReleaseManagement){
776 $smarty->assign("FAIrelease", $this->FAIrelease);
777 $smarty->assign("Releases", $this->Releases);
779 if(count($this->used_apps)){
780 $smarty->assign("ReleaseSelectAble", false);
781 }else{
782 $smarty->assign("ReleaseSelectAble", true);
783 }
784 }
785 $smarty->assign("ReleaseSelectAble", true);
787 /* Show main page */
788 if ($this->dialog){
789 $smarty->assign("table", $this->table);
790 $display.= $smarty->fetch (get_template_path('application_options.tpl', TRUE));
791 } else {
792 $display.= $smarty->fetch (get_template_path('application.tpl', TRUE));
793 }
794 return ($display);
795 }
798 function getReleases()
799 {
800 $dn = $this->config->current['BASE'];
801 $ldap = $this->config->get_ldap_link();
802 $ldap->cd($dn);
803 $ldap->search("(&(objectClass=organizationalUnit)(objectClass=FAIbranch))",array("ou"));
804 $ret =array();
805 while($attrs = $ldap->fetch()){
806 if(preg_match("/ou=apps,/",$attrs['dn'])){
807 $bb = preg_replace("/ou=apps,.*/","",$attrs['dn']);
808 $parts = array_reverse(split("ou=",$bb));
810 $str ="";
811 foreach($parts as $part){
812 if(empty($part)) {
813 continue;
814 }
815 $str .= str_replace(",","",$part)."/";
816 }
817 $name = preg_replace("/\/$/","",$str);
818 if(empty($name)) {
819 $name ="/";
820 }
821 $ret[$attrs['dn']] = $name;
822 }
823 }
825 /* Set releases to / id nor presenet */
826 if (!count($ret)){
827 $ret['/']= '/';
828 }
830 return($ret);
831 }
833 function save_object()
834 {
835 plugin::save_object();
836 }
839 function remove_from_parent()
840 {
841 plugin::remove_from_parent();
843 $ldap= $this->config->get_ldap_link();
844 $ldap->cd($this->dn);
845 $this->cleanup();
847 $ldap->modify ($this->attrs);
849 show_ldap_error($ldap->get_error(), _("Removing application information failed"));
851 /* Optionally execute a command after we're done */
852 $this->handle_post_events("remove");
853 }
856 /* Save to LDAP */
857 function save()
858 {
859 plugin::save();
861 /* Copy members */
862 $this->Categories[""]="";
863 $this->attrs["gosaMemberApplication"]= array();
864 $this->attrs["gosaApplicationParameter"]= array();
865 foreach($this->Categories as $name => $cats){
866 $i =0;
867 if(isset($this->gosaMemberApplication[$name])){
868 foreach($this->gosaMemberApplication[$name] as $entry){
869 if(!preg_match("/__SEPARATOR__/",$entry['App'])){
870 $this->attrs["gosaMemberApplication"][]= $entry['App']."|".$name."|".$i;
871 }
872 $i ++;
873 }
874 }
875 if(($i==0)&&(!empty($name))){
876 $this->attrs["gosaMemberApplication"][]= "|".$name."|".$i;
877 }
878 }
880 /* Are there application parameters to be saved */
881 $this->attrs['gosaApplicationParameter']= array();
882 foreach($this->appoption as $name => $value){
883 if ($value != ""){
884 $this->attrs['gosaApplicationParameter'][]= "$name:$value";
885 }
886 }
888 /* Write back to LDAP */
889 $ldap= $this->config->get_ldap_link();
890 $ldap->cd($this->dn);
891 $this->cleanup();
892 $ldap->modify ($this->attrs);
894 show_ldap_error($ldap->get_error(), _("Saving application information failed"));
896 /* Optionally execute a command after we're done */
897 if ($this->initially_was_account == $this->is_account){
898 if ($this->is_modified){
899 $this->handle_post_events("mofify");
900 }
901 } else {
902 $this->handle_post_events("add");
903 }
905 }
907 function check()
908 {
909 /* Call common method to give check the hook */
910 $message= plugin::check();
912 return ($message);
913 }
916 function reload()
917 {
918 /* Generate applist */
919 $this->apps= array();
921 /* Special handling for release managed apps
922 */
923 $tmp = search_config($this->config->data,"faiManagement","CLASS");
924 if(!empty($tmp) && count($this->Releases)){
925 $this->enableReleaseManagement = true;
927 $tmp = array_flip($this->Releases);
928 if(isset($tmp[$this->FAIrelease])){
929 $base = $tmp[$this->FAIrelease];
930 }else{
931 $old_r = $this->FAIrelease;
932 $k = key($tmp);
933 $r = $tmp[$k];
934 $this->FAIrelease = $k;
935 $base = $r;
937 print_red(sprintf(_("Can't resolve the release name '%s', setting release name to '%s'. Possibly the objects base has changed."),$old_r,$k));
938 }
940 $base = preg_replace("/ou=apps,.*$/","ou=apps,".$this->curbase,$base);
941 $app_res = get_list("(objectClass=gosaApplication)", $this->ui->subtreeACL, $base,array("cn","description"));
942 }else{
943 $app_res = get_list("(objectClass=gosaApplication)", $this->ui->subtreeACL, "ou=apps,".$this->curbase,array("cn","description"));
944 }
946 foreach($app_res as $attrs){
947 if (isset($attrs["description"][0])){
948 $this->apps[$attrs["cn"][0]]=
949 $attrs["cn"][0]." (".
950 $attrs["description"][0].")";
951 } else {
952 $this->apps[$attrs["cn"][0]]=
953 $attrs["cn"][0];
954 }
955 }
957 $ldap = $this->config->get_ldap_link();
958 $ldap->cd($this->config->current['BASE']);
959 $ldap->search("objectClass=gosaApplication",array("gosaApplicationParameter","cn"));
960 $tmp = search_config($this->config->data,"faiManagement","CLASS");
961 $this->AllAppsForRelease = array();
962 if(!empty($tmp)){
964 $tmp = array_flip($this->Releases);
966 while($attrs = $ldap->fetch()){
968 $testdn = preg_replace("/ou=apps,.*$/","ou=apps",$attrs['dn']);
969 $testdn = preg_replace("/^[^,]+/","",$testdn);
970 $testdn = preg_replace("/^,/","",$testdn);
972 if($testdn == preg_replace("/ou=apps,.*$/","ou=apps",$tmp[$this->FAIrelease])){
973 $this->AllAppsForRelease[$attrs['dn']] = $attrs['cn'][0];
974 $this->AllAppsForReleaseParameter[$this->FAIrelease][$attrs['cn'][0]] = $attrs;
975 }
976 }
977 }else{
978 while($attrs = $ldap->fetch()){
979 $this->AllAppsForRelease[$attrs['dn']] = $attrs['cn'][0];
980 }
981 }
983 natcasesort ($this->apps);
984 reset ($this->apps);
986 if(is_array($this->gosaMemberApplication))
987 foreach ($this->gosaMemberApplication as $cat){
988 if(is_array($cat))
989 foreach($cat as $entry){
990 $this->used_apps[$entry['App']]= $entry['App'];
991 }
992 }
993 }
996 function addApp($cn)
997 {
998 if((isset($this->gosaMemberApplication[$this->curCatDir]))&&(is_array($this->gosaMemberApplication[$this->curCatDir]))){
999 foreach($this->gosaMemberApplication[$this->curCatDir] as $entry){
1000 if($entry['App'] == $cn) return;
1001 }
1002 }
1003 $this->gosaMemberApplication[$this->curCatDir][]= array("App"=>$cn);
1004 $this->used_apps[$cn]=$cn;
1005 $this->is_modified= TRUE;
1006 }
1009 function removeApp($cn)
1010 {
1011 $temp= array();
1012 foreach ($this->gosaMemberApplication as $value){
1013 if ($value != $cn){
1014 $temp[]= $value;
1015 }
1016 }
1017 $this->gosaMemberApplication= $temp;
1018 $this->is_modified= TRUE;
1019 }
1021 function getParameters($app)
1022 {
1023 $tmp = $this->getReleases();
1024 $ret = array();
1025 if(in_array($this->FAIrelease,$tmp)){
1026 $tmp2 = array_flip($tmp);
1027 $base = $tmp2[$this->FAIrelease];
1028 $ldap = $this->config->get_ldap_link();
1029 $ldap->cd($this->config->current['BASE']);
1030 $ldap->search("(&(objectClass=gosaApplication)(cn=".$app.")(gosaApplicationParameter=*))",array("gosaApplicationParameter"));
1031 if($ldap->count()){
1032 $attrs = $ldap->fetch();
1033 for($i = 0 ; $i < $attrs['gosaApplicationParameter']['count'] ; $i ++ ){
1034 $name = preg_replace("/:.*$/","",$attrs['gosaApplicationParameter'][$i]);
1035 $ret[$name] = $name;
1036 }
1037 }
1038 }
1039 return($ret);
1040 }
1042 function GetSubdirs($dir)
1043 {
1044 $ret = array();
1045 $tmp1 = split("/",$this->curCatDir);
1047 foreach($this->Categories as $path=>$cat){
1048 $tmp2 = split("/",$path);
1050 if((empty($this->curCatDir))&&(!preg_match("/\//",$path))){
1051 $abort = false;
1052 }elseif(((count($tmp1))+1) == (count($tmp2))){
1053 $abort = false;
1054 for($i = 0 ; $i < count($tmp1) ; $i++){
1055 if($tmp1[$i] != $tmp2[$i]){
1056 $abort = true;
1057 }
1058 }
1059 }else{
1060 $abort= true;
1061 }
1062 if(!$abort){
1063 $ret[$path]=$cat;
1064 }
1065 }
1066 return($ret);
1067 }
1068 }
1070 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1071 ?>