f255c697e4e5ad8b03eca82dc83e3c59872e27f1
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 $Release = "/";
31 var $InitialRelease = "/";
32 var $Releases = array();
33 var $enableReleaseManagement = false;
35 var $AllAppsForRelease = array();
36 var $AllAppsForReleaseParameter = array();
38 function appgroup ($config, $dn= NULL)
39 {
40 plugin::plugin ($config, $dn);
42 /* Load member applications */
43 if (isset ($this->attrs["gosaMemberApplication"][0])){
44 $this->gosaMemberApplication = array();
45 for ($i= 0; $i<$this->attrs["gosaMemberApplication"]["count"]; $i++){
46 $this->gosaMemberApplication[]=
47 $this->attrs["gosaMemberApplication"][$i];
48 }
49 }
51 /* Load application options */
52 if (isset($this->attrs['gosaApplicationParameter'])){
53 for ($i= 0; $i<$this->attrs['gosaApplicationParameter']['count']; $i++){
54 $option= preg_replace('/^[^:]+:/', '',
55 $this->attrs['gosaApplicationParameter'][$i]);
56 $name= preg_replace('/:.*$/', '',
57 $this->attrs['gosaApplicationParameter'][$i]);
58 $this->appoption[$name]= $option;
59 }
60 }
62 /* Parse MemberApplication*/
63 $tmp = array();
64 $tmp2 = array();
65 $prios = array();
66 $cats = array();
68 foreach($this->gosaMemberApplication as $memberApp){
69 if(preg_match("/\|/i",$memberApp)){
71 $tmp = split("\|",$memberApp);
73 if(!empty($tmp[0])){
74 $tmp2[$tmp[1]][$tmp[2]] = array("App"=>$tmp[0]);
75 }
76 if(!empty($tmp[1])){
77 $n = split("/",$tmp[1]);
78 $c = count($n);
79 $cats [$tmp[1]] = $n[$c-1];
80 }
81 $prios[$tmp[1]][$tmp[2]] = $tmp[2];
82 }else{
83 $tmp2[]['App'] = $memberApp;
84 }
85 }
87 $this->Categories = $cats;
89 $this->gosaMemberApplication = $tmp2;
90 $cats[""]="";
91 foreach($cats as $cat ){
92 if((isset($prios[$cat]))&&(count($prios[$cat]))){
93 $max = max($prios[$cat]);
94 $min = 1;//min($prios[$cat]);
95 $last = false;
96 for($i = $min ; $i < $max ; $i++){
97 if(!isset($prios[$cat][$i])){
98 if($last == false){
99 $this->gosaMemberApplication[$cat][$i]['App'] = "__SEPARATOR__".$i;
101 $last = true;
102 }
103 }else{
104 $last = false;
105 }
106 }
107 }
108 }
110 $tmp = array();
111 foreach($this->gosaMemberApplication as $key => $entries){
112 ksort ($entries);
113 foreach($entries as $entry){
114 $tmp[$key][]= $entry;
115 }
116 }
117 $this->gosaMemberApplication = $tmp;
118 $this->curbase = $this->config->current['BASE'];
120 /* Check if we should enable the release selection
121 */
122 $tmp = search_config($config->data,"faiManagement","CLASS");
123 if(!empty($tmp)){
124 $this->enableReleaseManagement = true;
125 $this->Release = $this->getReleaseName();
126 $this->InitialRelease = $this->Release;
127 $this->Releases = $this->getReleases();
128 }
129 }
132 /* Combine new array */
133 function combineArrays($ar0,$ar1,$ar2)
134 {
135 $ret = array();
136 if(is_array($ar0))
137 foreach($ar0 as $ar => $a){
138 $ret[$ar]=$a;
139 }
140 if(is_array($ar1))
141 foreach($ar1 as $ar => $a){
142 $ret[$ar]=$a;
143 }
144 if(is_array($ar2))
145 foreach($ar2 as $ar => $a){
146 $ret[$ar]=$a;
147 }
148 return($ret);
149 }
151 function getpos($atr,$attrs)
152 {
153 $i = 0;
154 foreach($attrs as $attr => $name) {
155 $i++;
156 if($attr == $atr){
157 return($i);
158 }
159 }
160 return(-1);
161 }
163 function diffAppsInReleases()
164 {
165 /* Only diff if it is required
166 */
167 $ret =array();
168 if($this->Release != $this->InitialRelease){
169 foreach($this->gosaMemberApplication[$this->curCatDir] as $entry){
170 if(in_array($entry['App'],$this->AllAppsForRelease)){
171 $old = $this->AllAppsForReleaseParameter[$this->InitialRelease][$entry['App']];
172 $new = $this->AllAppsForReleaseParameter[$this->Release][$entry['App']];
174 /* Both (old & new) have no gosaApplicationParameter
175 */
176 if((!isset($old['gosaApplicationParameter'])) && (!isset($new['gosaApplicationParameter']))){
177 $ret[$entry['App']] = false;
179 /* Both got gosaApplicationParameter
180 */
181 }elseif((isset($old['gosaApplicationParameter'])) && (isset($new['gosaApplicationParameter'])))
182 if(array_differs($old['gosaApplicationParameter'],$new['gosaApplicationParameter'])){
183 $ret[$entry['App']] = true;
184 }else{
185 $ret[$entry['App']] = false;
186 }
188 /* Initialy had gosaApplicationParameter bot in new release not
189 */
190 }elseif((isset($old['gosaApplicationParameter'])) && (!isset($new['gosaApplicationParameter']))){
191 $ret[$entry['App']] = true;
193 /* Old release had no gosaApplicationParameter but new got some
194 */
195 }elseif((!isset($old['gosaApplicationParameter'])) && (isset($new['gosaApplicationParameter']))){
196 $ret[$entry['App']] = true;
197 }
198 }
199 }
200 return($ret);
201 }
203 /* TRansports the geiven Arraykey one position up*/
204 function ArrayUp($atr,$attrs)
205 {
206 $ret = $attrs;
207 $pos = $this->getpos($atr,$attrs) ;
208 $cn = count($attrs);
209 if(!(($pos == -1)||($pos == 1))){
210 $before = array_slice($attrs,0,($pos-2));
211 $mitte = array_reverse(array_slice($attrs,($pos-2),2));
212 $unten = array_slice($attrs,$pos);
213 $ret = array();
214 $ret = $this->combineArrays($before,$mitte,$unten);
215 }
216 return($ret);
217 }
220 /* TRansports the geiven Arraykey one position up*/
221 function ArrayDown($atr,$attrs)
222 {
223 $ret = $attrs;
224 $pos = $this->getpos($atr,$attrs) ;
225 $cn = count($attrs);
226 if(!(($pos == -1)||($pos == $cn))){
227 $before = array_slice($attrs,0,($pos-1));
228 $mitte = array_reverse(array_slice($attrs,($pos-1),2));
229 $unten = array_slice($attrs,($pos+1));
230 $ret = array();
231 $ret = $this->combineArrays($before,$mitte,$unten);
232 }
233 return($ret);
234 }
237 function catUp($id)
238 {
239 /* Get all cats depinding on current dir */
240 $cats = $this->GetSubdirs($this->curCatDir);
241 $newcats =$this->ArrayUp($id,$cats);
243 foreach($newcats as $cat => $name){
244 unset($this->Categories[$cat]);
245 }
246 foreach($newcats as $cat => $name){
247 $this->Categories[$cat]=$name;
248 }
249 }
252 function catDown($id)
253 {
254 /* Get all cats depinding on current dir */
255 $cats = $this->GetSubdirs($this->curCatDir);
257 $newcats =$this->ArrayDown($id,$cats);
259 foreach($newcats as $cat => $name){
260 unset($this->Categories[$cat]);
261 }
262 foreach($newcats as $cat => $name){
263 $this->Categories[$cat]=$name;
264 }
265 }
268 function getOneUp($appl)
269 {
270 $cat = $this->curCatDir;
271 $apps = $this->gosaMemberApplication[$cat];
273 $appsA = array();
274 foreach ($apps as $appkey => $name){
275 $appsA[$name['App']] =$name['App'];
276 }
278 $result = $this->ArrayUp($appl,$appsA);
280 $ret = array();
281 foreach($result as $app){
282 $ret[]=array("App"=>$app);
283 }
284 $this->gosaMemberApplication[$cat] = $ret;
285 }
288 function getOneDown($appl)
289 {
290 $cat = $this->curCatDir;
291 $apps = $this->gosaMemberApplication[$cat];
293 $appsA = array();
294 foreach ($apps as $appkey => $name){
295 $appsA[$name['App']] =$name['App'];
296 }
298 $result = $this->ArrayDown($appl,$appsA);
300 $ret = array();
301 foreach($result as $app){
302 $ret[]=array("App"=>$app);
303 }
304 $this->gosaMemberApplication[$cat] = $ret;
305 }
309 function AddSeperator($id)
310 {
311 $found = false;
312 $cat = "";
313 $tmp = array();
314 foreach($this->gosaMemberApplication[$this->curCatDir] as $appID => $app){
315 $tmp[] = $app;
316 if(($app['App'] == $id)&&(!$found)){
317 $cnt = count($this->gosaMemberApplication[$this->curCatDir]);
318 $tmp[] = array("App" => "__SEPARATOR__".($cnt+1));
319 $found = true;
320 }
321 }
322 if($found){
323 $this->gosaMemberApplication[$this->curCatDir]=$tmp;
324 }
325 }
327 function execute()
328 {
329 /* Call parent execute */
330 plugin::execute();
333 if((isset($_GET['act']))&&($_GET['act']=="depopen")){
334 $dep = base64_decode($_GET['depid']);
335 if(isset($this->config->idepartments[$dep])){
336 $this->curbase =$dep;
337 }
338 }
340 if((isset($_GET['act']))&&($_GET['act']=="open")){
341 $this->curCatDir = base64_decode($_GET['id']);
342 }
344 /* Do we need to flip is_account state? */
345 if (isset($_POST['modify_state'])){
346 $this->is_account= !$this->is_account;
347 }
349 /* Do we represent a valid group? */
350 if (!$this->is_account && $this->parent == NULL){
351 $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\"> <b>".
352 _("This 'dn' is no appgroup.")."</b>";
353 return ($display);
354 }
356 /* Show tab dialog headers */
357 $display= "";
358 if ($this->parent != NULL){
359 if ($this->is_account){
360 $display= $this->show_header(_("Remove applications"),
361 _("This group has application features enabled. You can disable them by clicking below."));
362 } else {
363 $display.= $this->show_header(_("Create applications"),
364 _("This group has application features disabled. You can enable them by clicking below."));
365 return ($display);
366 }
367 }
370 /* Add Categorie */
373 if((isset($_POST['AddCat']))&&(isset($_POST['CatName']))&&(!empty($_POST['CatName']))){
375 if(preg_match("/[\\\\\/]/i",$_POST['CatName'])){
376 print_red(_("Invalid character in category name."));
377 }elseif(!in_array($_POST['CatName'],$this->Categories)){
378 if(empty($this->curCatDir)){
379 $this->Categories[$_POST['CatName']]=$_POST['CatName'];
380 }else{
381 $this->Categories[$this->curCatDir."/".$_POST['CatName']]=$_POST['CatName'];
382 }
383 }else{
384 print_red(_("The specified category already exists."));
385 }
386 }
389 $this->reload();
391 $this->diffAppsInReleases();
392 $only_once = false;
393 foreach($_POST as $name => $value){
395 if((preg_match("/AddSep_/",$name))&&(!$only_once)){
396 $only_once = true;
397 $n = preg_replace("/AddSep_/","",$name);
398 $val= preg_replace("/_.*$/","",$n);
399 $this->AddSeperator($val);
400 }
402 if((preg_match("/DelApp_/",$name))&&(!$only_once)){
403 $only_once = true;
406 if(preg_match("/DelApp___SEPARATOR__/",$name)) {
407 $n= preg_replace("/DelApp___SEPARATOR__/","",$name);
408 $val= "__SEPARATOR__".preg_replace("/_.*$/","",$n);
409 }else{
410 $n = preg_replace("/DelApp_/","",$name);
411 $val= preg_replace("/_.*$/","",$n);
412 }
414 foreach($this->gosaMemberApplication as $key => $cat){
415 foreach($cat as $key2 => $app){
416 if($app['App'] == $val){
417 unset($this->gosaMemberApplication[$key][$key2]);
418 if(isset($this->used_apps[$val])){
419 unset($this->used_apps[$val]);
420 }
421 }
422 }
423 }
424 }
426 if(preg_match("/DelCat_/",$name)){
427 $n = preg_replace("/DelCat_/","",$name);
428 $app = base64_decode( preg_replace("/_.*$/","",$n));
429 foreach($this->Categories as $key => $cat){
430 if($cat == $app){
431 foreach($this->Categories as $p => $n){
432 if(preg_match("/^".$key."\/.*/",$p)){
433 unset($this->Categories[$p]);
434 }
435 }
436 unset($this->Categories[$key]);
437 }
438 }
439 }
441 if((preg_match("/EdiApp_/",$name))&&(!$only_once)){
443 $only_once = true;
444 $appname = $value;
445 $appname = preg_replace("/EdiApp_/","",$name);
446 $appname = preg_replace("/_.*$/","",$appname);
448 /* We've got the appname, get parameters from ldap
449 */
450 $ldap= $this->config->get_ldap_link();
452 $tmp = search_config($this->config->data,"faiManagement","CLASS");
453 if(!empty($tmp)){
454 $tmp = array_flip($this->Releases);
455 $base = $tmp[$this->Release];
457 $ldap->cd($this->config->current['BASE']);
458 $ldap->search("(&(objectClass=gosaApplication)(cn=$appname))",array("gosaApplicationParameter"));
459 $found = "";
460 while($attrs = $ldap->fetch()) {
461 if(preg_match("/cn=".$appname.",".$base."/",$attrs['dn'])){
462 $found = $attrs['dn'];
463 }
464 }
465 $ldap->cat($found);
466 }else{
467 $ldap->cd($this->config->current['BASE']);
468 $ldap->search("(&(objectClass=gosaApplication)(cn=$appname))",array("gosaApplicationParameter"));
470 }
473 if ($ldap->count() != 1){
474 print_red (_("The selected application name is not uniq. Please check your LDAP."));
475 } else {
476 $attrs= $ldap->fetch();
477 if(isset($attrs['gosaApplicationParameter'])){
478 $this->dialog= TRUE;
480 /* Fill name and value arrays */
481 for ($i= 0; $i<$attrs['gosaApplicationParameter']['count']; $i++){
482 $option= preg_replace('/^[^:]+:/', '',
483 $attrs['gosaApplicationParameter'][$i]);
484 $name= preg_replace('/:.*$/', '',
485 $attrs['gosaApplicationParameter'][$i]);
486 $this->option_name[$i]= $name;
488 /* Fill with values from application, default should be
489 loaded by the external scripts */
490 if (isset($this->appoption[$name])){
491 $this->option_value[$i]= $this->appoption[$name];
492 }
493 }
495 /* Create edit field */
496 $table= "<table summary=\"\">";
497 for ($i= 0; $i < count($this->option_name); $i++){
498 if (isset($this->option_value[$i])){
499 $value= $this->option_value[$i];
500 } else {
501 $value= "";
502 }
503 $table.="<tr><td>".$this->option_name[$i]."</td><td>".
504 "<input name=\"value$i\" size=60 maxlength=250 ".
505 "value=\"".$value."\"><br></td></tr>";
506 }
507 $table.= "</table>";
508 $this->table= $table;
509 } else {
510 print_red (_("The selected application has no options."));
511 }
512 }
513 }
514 }
516 $this->reload();
518 /* Add group with post */
519 if((isset($_GET['act']))&&($_GET['act']=="add")){
520 $this->used_apps[$_GET['id']]= $_GET['id'];
521 asort($this->used_apps);
522 $this->addApp($_GET['id']);
523 }
525 /* Add multiple */
526 if(isset($_POST['AddApps'])){
527 foreach($_POST as $name => $value){
528 if(preg_match("/AddApp_/",$name)){
529 $app = preg_replace("/AddApp_/","",$name);
530 $this->addApp($app);
531 }
532 }
533 }
536 /* Cancel edit options? */
537 if (isset($_POST['edit_options_cancel'])){
538 $this->dialog= FALSE;
539 }
541 /* Finish edit options? */
542 if (isset($_POST['edit_options_finish'])){
543 $this->dialog= FALSE;
545 /* Save informations passed by the user */
546 $this->option_value= array();
547 for ($i= 0; $i<count($this->option_name); $i++){
548 $this->appoption[$this->option_name[$i]]= $_POST["value$i"];
549 $this->is_modified= TRUE;
550 }
551 }
553 /* Prepare templating stuff */
554 $smarty= get_smarty();
555 $smarty->assign("used_apps", $this->used_apps);
556 $apps= array();
557 foreach ($this->apps as $key => $value){
558 if (!array_key_exists($key, $this->used_apps)){
559 $apps["$key"]= "$value";
560 }
561 }
563 $div = new DivSelectBox("appgroup");
565 $div->SetHeight(300);
567 /* NEW LIST MANAGMENT
568 * We also need to search for the departments
569 * So we are able to navigate like in konquerer
570 */
572 //FIXME: Why do we not use get_list here? It's the same code all over the time...
573 $ldap = $this->config->get_ldap_link();
574 $ldap->cd($this->curbase) ;
575 $ldap->ls("(objectClass=gosaDepartment)");
576 $departments= array();
577 $tmp = array();
578 while ($value = $ldap->fetch()){
579 $tmp[strtolower($value['dn']).$value['dn']]=$value;
580 }
581 ksort($tmp);
582 foreach($tmp as $value){
583 $fdn= @LDAP::fix($value['dn']);
584 if($value["description"][0]!=".."){
585 $departments[$value['dn']]= convert_department_dn($fdn)." - [".$value["description"][0]."]";
586 }else{
587 $departments[$value['dn']]=convert_department_dn($fdn);
588 }
589 }
591 /* END NEW LIST MANAGMENT
592 */
594 $linkopen = "<a href='?plug=".$_GET['plug']."&act=depopen&depid=%s'>%s</a>";
595 $linkadd = "<a href='?plug=".$_GET['plug']."&act=add&id=%s'>%s</a>";
597 $base_back = preg_replace("/^[^,]+,/","",$this->curbase);
598 if((strlen($base_back)>= strlen($this->config->current['BASE']))&&($this->curbase!=$this->config->current['BASE'])){
599 $div->AddEntry(array(
600 array("string"=>sprintf($linkopen,base64_encode($base_back),".. ["._("back")."]"),
601 "attach"=>"style='border:0px;'")
602 ));
603 }
604 foreach($departments as $key => $app){
605 $div->AddEntry(array(
606 array("string"=>"<img class='center' src='images/folder.png' alt='"._("department")."'> ".sprintf($linkopen,base64_encode($key),$app),
607 "attach"=>"style='border:0px;'")
608 ));
609 }
611 foreach($apps as $key => $app){
612 $div->AddEntry(array(
613 array("string"=>sprintf("<input class='center' type='checkbox' value='1' name='AddApp_%s'>",$key).
614 "<img class='center' src='images/select_application.png' alt='"._("application")."'> ".sprintf($linkadd,$key,$app),
615 "attach"=>"style='border:0px;'")
616 ));
617 }
619 if((isset($_GET['act']))&&(($_GET['act'] == "cat_up")||($_GET['act']=="cat_down"))){
620 if($_GET['act']=="cat_up"){
621 $this->catUp(base64_decode($_GET['id']));
622 }
623 if($_GET['act']=="cat_down"){
624 $this->catDown(base64_decode($_GET['id']));
625 }
626 }
628 if((isset($_GET['act']))&&(($_GET['act'] == "one_up")||($_GET['act']=="one_down"))){
629 if(isset($_GET['id'])){
630 $id = $_GET['id'];
631 $act = $_GET['act'];
633 if($act == "one_up"){
634 $this->getOneUp($id);
635 }elseif($act == "one_down") {
636 $this->getOneDown($id);
637 }
638 }
639 }
641 $div2 = new DivSelectBox("appgroup");
642 $div2->SetHeight(300);
644 $linkopen = "<img class='center' src='images/folder.png' alt=\"\"> <a href='?plug=".$_GET['plug']."&act=open&id=%s'>%s</a>";
645 $catremove = " <input type='image' src='images/edittrash.png' title='"._("Delete entry")."' name='DelCat_%s' value='%s'>";
646 $app = "<img class='center' src='images/select_application.png' alt=\"\"> %s";
648 $catupdown = "<a href='?plug=".$_GET['plug']."&act=cat_up&id=%s'>
649 <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'>
650 <img alt=\"\" src='images/sort_down.png' title='"._("Move down")."' border=0></a>";
652 if(empty($this->curCatDir)){
653 $cnt =0;
654 }else{
655 $cnt = count(split("/",$this->curCatDir));
656 $tmp = split("/",$this->curCatDir);
657 $bbk = "";
658 for($i = 0 ; $i < ($cnt -1 ) ; $i++){
659 $bbk .= $tmp[$i];
660 }
661 $div2 ->AddEntry(array(array("string"=>sprintf($linkopen,base64_encode($bbk),"..")),array("string"=>" ","attach"=>"style='border-right:0px;'")));
662 }
664 $this->GetSubdirs($this->curCatDir);
666 foreach($this->GetSubdirs($this->curCatDir) as $path => $name){
667 $div2 ->AddEntry(array(
668 array("string"=>sprintf($linkopen,base64_encode($path),$name)),
669 array("string"=>preg_replace("/%s/",base64_encode($path),$catupdown.$catremove),
670 "attach"=>"align='right' style='width:80px;border-right:0px;'")));
671 }
673 /* Append entries */
675 $separator ="<hr size=1>";
677 $sep = "<input type='image' src='images/back.png' title='"._("Insert seperator")."' value='%s' name='AddSep_%s'>";
679 $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>".
680 " <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>".
681 " <input type='image' src='images/edittrash.png' title='"._("Delete entry")."' name='DelApp_%s' value='%s' alt='{t}delete{/t}' >";
682 $edit= " <input type='image' src='images/edit.png' title='"._("Edit entry")."' name='EdiApp_%s' value='%s' alt='{t}edit{/t}' >";
684 $Differences = $this->diffAppsInReleases();
686 if(isset($this->gosaMemberApplication[$this->curCatDir])){
687 foreach($this->gosaMemberApplication[$this->curCatDir] as $cat => $entry){
690 if(preg_match("/__SEPARATOR__/",$entry['App'])){
691 $div2 ->AddEntry(array(array("string"=>$separator),
692 array("string"=>preg_replace("/\%s/",htmlentities($entry['App']),$upudown),"attach"=>"align='right' style='border-right:0px;'")));
693 }else{
695 $image = "";
696 /* Check if application was available within selected release
697 * or application list if release management is not active
698 */
699 if(!in_array($entry['App'],$this->AllAppsForRelease)){
701 /* release managent is active
702 */
703 if(!$this->enableReleaseManagement){
704 $image = "<img class='center' src='images/select_invalid_application.png'
705 title='"._("This application is no longer available.")."'> ";
706 }else{
707 $image = "<img class='center' src='images/select_invalid_application.png'
708 title='".sprintf(_("This application is not available in any release named %s."),$this->Release)."'> ";
709 }
711 }elseif(isset($Differences[$entry['App']]) && ($Differences[$entry['App']] == true)) {
712 $entry['App'].=" <i>["._("Check parameter")."]</i>";
713 $image = "<img class='center' src='images/select_invalid_application.png'
714 title='"._("This application has changed parameters.")."'> ";
715 }else{
716 $image = "<img class='center' src='images/select_application.png' alt=\"\"> ";
717 }
719 $div2->AddEntry(array(array("string"=>sprintf($image."%s",$entry['App'])),
720 array("string"=>preg_replace("/\%s/",htmlentities($entry['App']),$sep.$edit.$upudown),
721 "attach"=>"align='right' style='width:100px;border-right:0px;'")));
722 }
723 }
724 }
726 $smarty->assign("UsedApps", $div2->DrawList());
727 $smarty->assign("List", $div->DrawList());
728 $smarty->assign("apps", $apps);
730 $smarty->assign("enableReleaseManagement",$this->enableReleaseManagement);
732 if($this->enableReleaseManagement){
733 $smarty->assign("Release", $this->Release);
734 $smarty->assign("Releases", $this->Releases);
736 if(count($this->used_apps)){
737 $smarty->assign("ReleaseSelectAble", false);
738 }else{
739 $smarty->assign("ReleaseSelectAble", true);
740 }
741 }
742 $smarty->assign("ReleaseSelectAble", true);
744 /* Show main page */
745 if ($this->dialog){
746 $smarty->assign("table", $this->table);
747 $display.= $smarty->fetch (get_template_path('application_options.tpl', TRUE));
748 } else {
749 $display.= $smarty->fetch (get_template_path('application.tpl', TRUE));
750 }
751 return ($display);
752 }
755 function getReleases()
756 {
757 $dn = "ou=apps,".$this->config->current['BASE'];
758 $ldap = $this->config->get_ldap_link();
759 $ldap->cd($dn);
760 $ldap->search("objectClass=organizationalUnit",array("ou"));
761 $ret =array();
762 while($attrs = $ldap->fetch()){
763 if(preg_match("/ou=apps,/",$attrs['dn'])){
764 $bb = preg_replace("/ou=apps,.*/","",$attrs['dn']);
765 $parts = array_reverse(split("ou=",$bb));
767 $str ="";
768 foreach($parts as $part){
769 if(empty($part)) {
770 continue;
771 }
772 $str .= str_replace(",","",$part)."/";
773 }
774 $name = preg_replace("/\/$/","",$str);
775 if(empty($name)) {
776 $name ="/";
777 }
778 $ret[$attrs['dn']] = $name;
779 }
780 }
781 return($ret);
782 }
784 function save_object()
785 {
786 if(isset($_POST ['Release'])){
787 $this->Release = $_POST['Release'];
788 }
789 }
792 function remove_from_parent()
793 {
794 plugin::remove_from_parent();
796 $this->attrs["gosaMemberApplication"]= array();
798 $ldap= $this->config->get_ldap_link();
799 $ldap->cd($this->dn);
800 $this->cleanup();
801 $ldap->modify ($this->attrs);
803 show_ldap_error($ldap->get_error());
805 /* Optionally execute a command after we're done */
806 $this->handle_post_events("remove");
807 }
810 /* Save to LDAP */
811 function save()
812 {
813 plugin::save();
815 /* Copy members */
816 $this->Categories[""]="";
817 $this->attrs["gosaMemberApplication"]= array();
818 foreach($this->Categories as $name => $cats){
819 $i =0;
820 if(isset($this->gosaMemberApplication[$name])){
821 foreach($this->gosaMemberApplication[$name] as $entry){
822 if(!preg_match("/__SEPARATOR__/",$entry['App'])){
823 $this->attrs["gosaMemberApplication"][]= $entry['App']."|".$name."|".$i;
824 }
825 $i ++;
826 }
827 }
828 if(($i==0)&&(!empty($name))){
829 $this->attrs["gosaMemberApplication"][]= "|".$name."|".$i;
830 }
831 }
833 /* Are there application parameters to be saved */
834 $this->attrs['gosaApplicationParameter']= array();
835 foreach($this->appoption as $name => $value){
836 if ($value != ""){
837 $this->attrs['gosaApplicationParameter'][]= "$name:$value";
838 }
839 }
841 /* Write back to LDAP */
842 $ldap= $this->config->get_ldap_link();
843 $ldap->cd($this->dn);
844 $this->cleanup();
845 $ldap->modify ($this->attrs);
847 show_ldap_error($ldap->get_error());
849 /* Optionally execute a command after we're done */
850 if ($this->initially_was_account == $this->is_account){
851 if ($this->is_modified){
852 $this->handle_post_events("mofify");
853 }
854 } else {
855 $this->handle_post_events("add");
856 }
858 }
860 function check()
861 {
862 /* Call common method to give check the hook */
863 $message= plugin::check();
865 return ($message);
866 }
869 function reload()
870 {
871 /* Generate applist */
872 $this->apps= array();
874 /* Special handling for release managed apps
875 */
876 $tmp = search_config($this->config->data,"faiManagement","CLASS");
877 if(!empty($tmp)){
878 $this->enableReleaseManagement = true;
880 $tmp = array_flip($this->Releases);
881 if(isset($tmp[$this->Release])){
882 $base = $tmp[$this->Release];
883 }else{
884 $k = key($tmp);
885 $r = $tmp[$k];
886 $this->Release = $k;
887 $base = $r;
889 print_red(sprintf(_("Can't resolve the release name '%s', setting release name to '%s'. Possibly the objects base has changed."),$this->Release,$k));
890 }
892 $base = preg_replace("/ou=apps,.*$/","ou=apps,".$this->curbase,$base);
894 $ldap = $this->config->get_ldap_link();
895 $ldap->cd ($base);
896 $ldap->ls ("(objectClass=gosaApplication)",$base);
897 }else{
898 $ldap = $this->config->get_ldap_link();
899 $ldap->cd ("ou=apps,".$this->curbase);
900 $ldap->ls ("(objectClass=gosaApplication)","ou=apps,".$this->curbase);
901 }
903 while ($attrs= $ldap->fetch()){
904 if (isset($attrs["description"][0])){
905 $this->apps[$attrs["cn"][0]]=
906 $attrs["cn"][0]." (".
907 $attrs["description"][0].")";
908 } else {
909 $this->apps[$attrs["cn"][0]]=
910 $attrs["cn"][0];
911 }
912 }
914 $ldap->cd($this->config->current['BASE']);
915 $ldap->search("objectClass=gosaApplication",array("gosaApplicationParameter","cn"));
916 $tmp = search_config($this->config->data,"faiManagement","CLASS");
917 $this->AllAppsForRelease = array();
918 if(!empty($tmp)){
920 $tmp = array_flip($this->Releases);
922 while($attrs = $ldap->fetch()){
924 $testdn = preg_replace("/ou=apps,.*$/","ou=apps",$attrs['dn']);
925 $testdn = preg_replace("/^[^,]+/","",$testdn);
926 $testdn = preg_replace("/^,/","",$testdn);
928 if($testdn == preg_replace("/ou=apps,.*$/","ou=apps",$tmp[$this->Release])){
929 $this->AllAppsForRelease[$attrs['dn']] = $attrs['cn'][0];
930 $this->AllAppsForReleaseParameter[$this->Release][$attrs['cn'][0]] = $attrs;
931 }
932 }
933 }else{
934 while($attrs = $ldap->fetch()){
935 $this->AllAppsForRelease[$attrs['dn']] = $attrs['cn'][0];
936 }
937 }
939 natcasesort ($this->apps);
940 reset ($this->apps);
942 if(is_array($this->gosaMemberApplication))
943 foreach ($this->gosaMemberApplication as $cat){
944 if(is_array($cat))
945 foreach($cat as $entry){
946 $this->used_apps[$entry['App']]= $entry['App'];
947 }
948 }
949 }
952 function addApp($cn)
953 {
954 if((isset($this->gosaMemberApplication[$this->curCatDir]))&&(is_array($this->gosaMemberApplication[$this->curCatDir]))){
955 foreach($this->gosaMemberApplication[$this->curCatDir] as $entry){
956 if($entry['App'] == $cn) return;
957 }
958 }
959 $this->gosaMemberApplication[$this->curCatDir][]= array("App"=>$cn);
960 $this->used_apps[$cn]=$cn;
961 $this->is_modified= TRUE;
962 }
965 function removeApp($cn)
966 {
967 $temp= array();
968 foreach ($this->gosaMemberApplication as $value){
969 if ($value != $cn){
970 $temp[]= $value;
971 }
972 }
973 $this->gosaMemberApplication= $temp;
974 $this->is_modified= TRUE;
975 }
977 function GetSubdirs($dir)
978 {
979 $ret = array();
980 $tmp1 = split("/",$this->curCatDir);
982 foreach($this->Categories as $path=>$cat){
983 $tmp2 = split("/",$path);
985 if((empty($this->curCatDir))&&(!preg_match("/\//",$path))){
986 $abort = false;
987 }elseif(((count($tmp1))+1) == (count($tmp2))){
988 $abort = false;
989 for($i = 0 ; $i < count($tmp1) ; $i++){
990 if($tmp1[$i] != $tmp2[$i]){
991 $abort = true;
992 }
993 }
994 }else{
995 $abort= true;
996 }
997 if(!$abort){
998 $ret[$path]=$cat;
999 }
1000 }
1001 return($ret);
1002 }
1005 /* Get selected release name.
1006 * it is written in the description tag
1007 * within ... (.*)$
1008 */
1009 function getReleaseName()
1010 {
1012 if(isset($this->parent)){
1013 $base = $this->parent->by_object['group'];
1014 }else{
1015 $base = $this;
1016 }
1018 if(isset($base->attrs['description'][0])){
1019 $desc = $base->attrs['description'][0];
1020 }else{
1021 $desc = "";
1022 }
1024 if(preg_match("/\(.*\)$/",$desc)){
1025 $str = preg_replace("/^.*\((.*)\)$/","\\1",$desc);
1026 }else{
1027 $str = "/";
1028 }
1029 return($str);
1030 }
1031 }
1033 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1034 ?>