ebcaf46f89d37e862753e8434a95db0aaefae04a
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 }
515 $this->reload();
516 /* Add group with post */
517 if((isset($_GET['act']))&&($_GET['act']=="add")){
518 $this->used_apps[$_GET['id']]= $_GET['id'];
519 asort($this->used_apps);
520 $this->addApp($_GET['id']);
521 }
523 /* Add multiple */
524 if(isset($_POST['AddApps'])){
525 foreach($_POST as $name => $value){
526 if(preg_match("/AddApp_/",$name)){
527 $app = preg_replace("/AddApp_/","",$name);
528 $this->addApp($app);
529 }
530 }
531 }
534 /* Cancel edit options? */
535 if (isset($_POST['edit_options_cancel'])){
536 $this->dialog= FALSE;
537 }
539 /* Finish edit options? */
540 if (isset($_POST['edit_options_finish'])){
541 $this->dialog= FALSE;
543 /* Save informations passed by the user */
544 $this->option_value= array();
545 for ($i= 0; $i<count($this->option_name); $i++){
546 $this->appoption[$this->option_name[$i]]= $_POST["value$i"];
547 $this->is_modified= TRUE;
548 }
549 }
551 /* Prepare templating stuff */
552 $smarty= get_smarty();
553 $smarty->assign("used_apps", $this->used_apps);
554 $apps= array();
555 foreach ($this->apps as $key => $value){
556 if (!array_key_exists($key, $this->used_apps)){
557 $apps["$key"]= "$value";
558 }
559 }
561 $div = new DivSelectBox("appgroup");
563 $div->SetHeight(400);
565 /* NEW LIST MANAGMENT
566 * We also need to search for the departments
567 * So we are able to navigate like in konquerer
568 */
570 $ldap = $this->config->get_ldap_link();
571 $ldap->cd($this->curbase) ;
572 $ldap->ls("(objectClass=gosaDepartment)");
573 $departments= array();
574 $tmp = array();
575 while ($value = $ldap->fetch()){
576 $tmp[strtolower($value['dn']).$value['dn']]=$value;
577 }
578 ksort($tmp);
579 foreach($tmp as $value){
580 if($value["description"][0]!=".."){
581 $departments[$value['dn']]=convert_department_dn($value['dn'])." - [".$value["description"][0]."]";
582 }else{
583 $departments[$value['dn']]=convert_department_dn($value['dn']);
584 }
585 }
587 /* END NEW LIST MANAGMENT
588 */
590 $linkopen = "<a href='?plug=".$_GET['plug']."&act=depopen&depid=%s'>%s</a>";
591 $linkadd = "<a href='?plug=".$_GET['plug']."&act=add&id=%s'>%s</a>";
593 $base_back = preg_replace("/^[^,]+,/","",$this->curbase);
594 if((strlen($base_back)>= strlen($this->config->current['BASE']))&&($this->curbase!=$this->config->current['BASE'])){
595 $div->AddEntry(array(
596 array("string"=>sprintf($linkopen,base64_encode($base_back),".. ["._("back")."]"),
597 "attach"=>"style='border:0px;'")
598 ));
599 }
600 foreach($departments as $key => $app){
601 $div->AddEntry(array(
602 array("string"=>"<img class='center' src='images/folder.png' alt='"._("department")."'> ".sprintf($linkopen,base64_encode($key),$app),
603 "attach"=>"style='border:0px;'")
604 ));
605 }
607 foreach($apps as $key => $app){
608 $div->AddEntry(array(
609 array("string"=>sprintf("<input class='center' type='checkbox' value='1' name='AddApp_%s'>",$key).
610 "<img class='center' src='images/select_application.png' alt='"._("application")."'> ".sprintf($linkadd,$key,$app),
611 "attach"=>"style='border:0px;'")
612 ));
613 }
615 if((isset($_GET['act']))&&(($_GET['act'] == "cat_up")||($_GET['act']=="cat_down"))){
616 if($_GET['act']=="cat_up"){
617 $this->catUp(base64_decode($_GET['id']));
618 }
619 if($_GET['act']=="cat_down"){
620 $this->catDown(base64_decode($_GET['id']));
621 }
622 }
624 if((isset($_GET['act']))&&(($_GET['act'] == "one_up")||($_GET['act']=="one_down"))){
625 if(isset($_GET['id'])){
626 $id = $_GET['id'];
627 $act = $_GET['act'];
629 if($act == "one_up"){
630 $this->getOneUp($id);
631 }elseif($act == "one_down") {
632 $this->getOneDown($id);
633 }
634 }
635 }
637 $div2 = new DivSelectBox("appgroup");
638 $div2->SetHeight(400);
640 $linkopen = "<img class='center' src='images/folder.png' alt=\"\"> <a href='?plug=".$_GET['plug']."&act=open&id=%s'>%s</a>";
641 $catremove = " <input type='image' src='images/edittrash.png' title='"._("Delete entry")."' name='DelCat_%s' value='%s'>";
642 $app = "<img class='center' src='images/select_application.png' alt=\"\"> %s";
644 $catupdown = "<a href='?plug=".$_GET['plug']."&act=cat_up&id=%s'>
645 <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'>
646 <img alt=\"\" src='images/sort_down.png' title='"._("Move down")."' border=0></a>";
648 if(empty($this->curCatDir)){
649 $cnt =0;
650 }else{
651 $cnt = count(split("/",$this->curCatDir));
652 $tmp = split("/",$this->curCatDir);
653 $bbk = "";
654 for($i = 0 ; $i < ($cnt -1 ) ; $i++){
655 $bbk .= $tmp[$i];
656 }
657 $div2 ->AddEntry(array(array("string"=>sprintf($linkopen,base64_encode($bbk),"..")),array("string"=>" ","attach"=>"style='border-right:0px;'")));
658 }
660 $this->GetSubdirs($this->curCatDir);
662 foreach($this->GetSubdirs($this->curCatDir) as $path => $name){
663 $div2 ->AddEntry(array(
664 array("string"=>sprintf($linkopen,base64_encode($path),$name)),
665 array("string"=>preg_replace("/%s/",base64_encode($path),$catupdown.$catremove),
666 "attach"=>"align='right' style='width:80px;border-right:0px;'")));
667 }
669 /* Append entries */
671 $separator ="<hr size=1>";
673 $sep = "<input type='image' src='images/back.png' title='"._("Insert seperator")."' value='%s' name='AddSep_%s'>";
675 $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>".
676 " <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>".
677 " <input type='image' src='images/edittrash.png' title='"._("Delete entry")."' name='DelApp_%s' value='%s' alt='{t}delete{/t}' >";
678 $edit= " <input type='image' src='images/edit.png' title='"._("Edit entry")."' name='EdiApp_%s' value='%s' alt='{t}edit{/t}' >";
680 $Differences = $this->diffAppsInReleases();
682 if(isset($this->gosaMemberApplication[$this->curCatDir])){
683 foreach($this->gosaMemberApplication[$this->curCatDir] as $cat => $entry){
686 if(preg_match("/__SEPARATOR__/",$entry['App'])){
687 $div2 ->AddEntry(array(array("string"=>$separator),
688 array("string"=>preg_replace("/\%s/",htmlentities($entry['App']),$upudown),"attach"=>"align='right' style='border-right:0px;'")));
689 }else{
691 $image = "";
692 /* Check if application was available within selected release
693 * or application list if release management is not active
694 */
695 if(!in_array($entry['App'],$this->AllAppsForRelease)){
697 /* release managent is active
698 */
699 if(!$this->enableReleaseManagement){
700 $image = "<img class='center' src='images/select_invalid_application.png'
701 title='"._("This application is no longer available.")."'> ";
702 }else{
703 $image = "<img class='center' src='images/select_invalid_application.png'
704 title='".sprintf(_("This application is not available in any release named %s."),$this->Release)."'> ";
705 }
707 }elseif(isset($Differences[$entry['App']]) && ($Differences[$entry['App']] == true)) {
708 $entry['App'].=" <i>["._("Check parameter")."]</i>";
709 $image = "<img class='center' src='images/select_invalid_application.png'
710 title='"._("This application has changed parameters.")."'> ";
711 }else{
712 $image = "<img class='center' src='images/select_application.png' alt=\"\"> ";
713 }
715 $div2 ->AddEntry(array(array("string"=>sprintf($image."%s",$entry['App'])),
716 array("string"=>preg_replace("/\%s/",htmlentities($entry['App']),$sep.$edit.$upudown),
717 "attach"=>"align='right' style='width:100px;border-right:0px;'")));
718 }
719 }
720 }
722 $smarty->assign("UsedApps", $div2->DrawList());
723 $smarty->assign("List", $div->DrawList());
724 $smarty->assign("apps", $apps);
726 $smarty->assign("enableReleaseManagement",$this->enableReleaseManagement);
728 if($this->enableReleaseManagement){
729 $smarty->assign("Release", $this->Release);
730 $smarty->assign("Releases", $this->Releases);
732 if(count($this->used_apps)){
733 $smarty->assign("ReleaseSelectAble", false);
734 }else{
735 $smarty->assign("ReleaseSelectAble", true);
736 }
737 }
738 $smarty->assign("ReleaseSelectAble", true);
740 /* Show main page */
741 if ($this->dialog){
742 $smarty->assign("table", $this->table);
743 $display.= $smarty->fetch (get_template_path('application_options.tpl', TRUE));
744 } else {
745 $display.= $smarty->fetch (get_template_path('application.tpl', TRUE));
746 }
747 return ($display);
748 }
751 function getReleases()
752 {
753 $dn = "ou=apps,".$this->config->current['BASE'];
754 $ldap = $this->config->get_ldap_link();
755 $ldap->cd($dn);
756 $ldap->search("objectClass=organizationalUnit",array("ou"));
757 $ret =array();
758 while($attrs = $ldap->fetch()){
759 if(preg_match("/ou=apps,/",$attrs['dn'])){
760 $bb = preg_replace("/ou=apps,.*/","",$attrs['dn']);
761 $parts = array_reverse(split("ou=",$bb));
763 $str ="";
764 foreach($parts as $part){
765 if(empty($part)) {
766 continue;
767 }
768 $str .= str_replace(",","",$part)."/";
769 }
770 $name = preg_replace("/\/$/","",$str);
771 if(empty($name)) {
772 $name ="/";
773 }
774 $ret[$attrs['dn']] = $name;
775 }
776 }
777 return($ret);
778 }
780 function save_object()
781 {
782 if(isset($_POST ['Release'])){
783 $this->Release = $_POST['Release'];
784 }
785 }
788 function remove_from_parent()
789 {
790 plugin::remove_from_parent();
792 $this->attrs["gosaMemberApplication"]= array();
794 $ldap= $this->config->get_ldap_link();
795 $ldap->cd($this->dn);
796 $this->cleanup();
797 $ldap->modify ($this->attrs);
799 show_ldap_error($ldap->get_error());
801 /* Optionally execute a command after we're done */
802 $this->handle_post_events("remove");
803 }
806 /* Save to LDAP */
807 function save()
808 {
809 plugin::save();
811 /* Copy members */
812 $this->Categories[""]="";
813 $this->attrs["gosaMemberApplication"]= array();
814 foreach($this->Categories as $name => $cats){
815 $i =0;
816 if(isset($this->gosaMemberApplication[$name])){
817 foreach($this->gosaMemberApplication[$name] as $entry){
818 if(!preg_match("/__SEPARATOR__/",$entry['App'])){
819 $this->attrs["gosaMemberApplication"][]= $entry['App']."|".$name."|".$i;
820 }
821 $i ++;
822 }
823 }
824 if(($i==0)&&(!empty($name))){
825 $this->attrs["gosaMemberApplication"][]= "|".$name."|".$i;
826 }
827 }
829 /* Are there application parameters to be saved */
830 $this->attrs['gosaApplicationParameter']= array();
831 foreach($this->appoption as $name => $value){
832 if ($value != ""){
833 $this->attrs['gosaApplicationParameter'][]= "$name:$value";
834 }
835 }
837 /* Write back to LDAP */
838 $ldap= $this->config->get_ldap_link();
839 $ldap->cd($this->dn);
840 $this->cleanup();
841 $ldap->modify ($this->attrs);
843 show_ldap_error($ldap->get_error());
845 /* Optionally execute a command after we're done */
846 if ($this->initially_was_account == $this->is_account){
847 if ($this->is_modified){
848 $this->handle_post_events("mofify");
849 }
850 } else {
851 $this->handle_post_events("add");
852 }
854 }
856 function check()
857 {
858 /* Call common method to give check the hook */
859 $message= plugin::check();
861 return ($message);
862 }
865 function reload()
866 {
867 /* Generate applist */
868 $this->apps= array();
870 /* Special handling for release managed apps
871 */
872 $tmp = search_config($this->config->data,"faiManagement","CLASS");
873 if(!empty($tmp)){
874 $this->enableReleaseManagement = true;
876 $tmp = array_flip($this->Releases);
877 if(isset($tmp[$this->Release])){
878 $base = $tmp[$this->Release];
879 }else{
880 $k = key($tmp);
881 $r = $tmp[$k];
882 $this->Release = $k;
883 $base = $r;
885 print_red(sprintf(_("Can't resolve the release name '%s', setting release name to '%s'. Possibly the objects base has changed."),$this->Release,$k));
886 }
888 $base = preg_replace("/ou=apps,.*$/","ou=apps,".$this->curbase,$base);
890 $ldap = $this->config->get_ldap_link();
891 $ldap->cd ($base);
892 $ldap->ls ("(objectClass=gosaApplication)",$base);
893 }else{
894 $ldap = $this->config->get_ldap_link();
895 $ldap->cd ("ou=apps,".$this->curbase);
896 $ldap->ls ("(objectClass=gosaApplication)","ou=apps,".$this->curbase);
897 }
899 while ($attrs= $ldap->fetch()){
900 if (isset($attrs["description"][0])){
901 $this->apps[$attrs["cn"][0]]=
902 $attrs["cn"][0]." (".
903 $attrs["description"][0].")";
904 } else {
905 $this->apps[$attrs["cn"][0]]=
906 $attrs["cn"][0];
907 }
908 }
910 $ldap->cd($this->config->current['BASE']);
911 $ldap->search("objectClass=gosaApplication",array("gosaApplicationParameter","cn"));
912 $tmp = search_config($this->config->data,"faiManagement","CLASS");
913 $this->AllAppsForRelease = array();
914 if(!empty($tmp)){
916 $tmp = array_flip($this->Releases);
918 while($attrs = $ldap->fetch()){
920 $testdn = preg_replace("/ou=apps,.*$/","ou=apps",$attrs['dn']);
921 $testdn = preg_replace("/^[^,]+/","",$testdn);
922 $testdn = preg_replace("/^,/","",$testdn);
924 if($testdn == preg_replace("/ou=apps,.*$/","ou=apps",$tmp[$this->Release])){
925 $this->AllAppsForRelease[$attrs['dn']] = $attrs['cn'][0];
926 $this->AllAppsForReleaseParameter[$this->Release][$attrs['cn'][0]] = $attrs;
927 }
928 }
929 }else{
930 while($attrs = $ldap->fetch()){
931 $this->AllAppsForRelease[$attrs['dn']] = $attrs['cn'][0];
932 }
933 }
935 natcasesort ($this->apps);
936 reset ($this->apps);
938 if(is_array($this->gosaMemberApplication))
939 foreach ($this->gosaMemberApplication as $cat){
940 if(is_array($cat))
941 foreach($cat as $entry){
942 $this->used_apps[$entry['App']]= $entry['App'];
943 }
944 }
945 }
948 function addApp($cn)
949 {
950 if((isset($this->gosaMemberApplication[$this->curCatDir]))&&(is_array($this->gosaMemberApplication[$this->curCatDir]))){
951 foreach($this->gosaMemberApplication[$this->curCatDir] as $entry){
952 if($entry['App'] == $cn) return;
953 }
954 }
955 $this->gosaMemberApplication[$this->curCatDir][]= array("App"=>$cn);
956 $this->used_apps[$cn]=$cn;
957 $this->is_modified= TRUE;
958 }
961 function removeApp($cn)
962 {
963 $temp= array();
964 foreach ($this->gosaMemberApplication as $value){
965 if ($value != $cn){
966 $temp[]= $value;
967 }
968 }
969 $this->gosaMemberApplication= $temp;
970 $this->is_modified= TRUE;
971 }
973 function GetSubdirs($dir)
974 {
975 $ret = array();
976 $tmp1 = split("/",$this->curCatDir);
978 foreach($this->Categories as $path=>$cat){
979 $tmp2 = split("/",$path);
981 if((empty($this->curCatDir))&&(!preg_match("/\//",$path))){
982 $abort = false;
983 }elseif(((count($tmp1))+1) == (count($tmp2))){
984 $abort = false;
985 for($i = 0 ; $i < count($tmp1) ; $i++){
986 if($tmp1[$i] != $tmp2[$i]){
987 $abort = true;
988 }
989 }
990 }else{
991 $abort= true;
992 }
993 if(!$abort){
994 $ret[$path]=$cat;
995 }
996 }
997 return($ret);
998 }
1001 /* Get selected release name.
1002 * it is written in the description tag
1003 * within ... (.*)$
1004 */
1005 function getReleaseName()
1006 {
1008 if(isset($this->parent)){
1009 $base = $this->parent->by_object['group'];
1010 }else{
1011 $base = $this;
1012 }
1014 if(isset($base->attrs['description'][0])){
1015 $desc = $base->attrs['description'][0];
1016 }else{
1017 $desc = "";
1018 }
1020 if(preg_match("/\(.*\)$/",$desc)){
1021 $str = preg_replace("/^.*\((.*)\)$/","\\1",$desc);
1022 }else{
1023 $str = "/";
1024 }
1025 return($str);
1026 }
1027 }
1029 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1030 ?>