f726bcddb4a61f113b926a30087120d8829174a0
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 $Releases = array();
32 var $enableReleaseManagement = false;
34 var $AllAppsForRelease = array();
36 function appgroup ($config, $dn= NULL)
37 {
38 plugin::plugin ($config, $dn);
40 /* Load member applications */
41 if (isset ($this->attrs["gosaMemberApplication"][0])){
42 $this->gosaMemberApplication = array();
43 for ($i= 0; $i<$this->attrs["gosaMemberApplication"]["count"]; $i++){
44 $this->gosaMemberApplication[]=
45 $this->attrs["gosaMemberApplication"][$i];
46 }
47 }
49 /* Load application options */
50 if (isset($this->attrs['gosaApplicationParameter'])){
51 for ($i= 0; $i<$this->attrs['gosaApplicationParameter']['count']; $i++){
52 $option= preg_replace('/^[^:]+:/', '',
53 $this->attrs['gosaApplicationParameter'][$i]);
54 $name= preg_replace('/:.*$/', '',
55 $this->attrs['gosaApplicationParameter'][$i]);
56 $this->appoption[$name]= $option;
57 }
58 }
60 /* Parse MemberApplication*/
61 $tmp = array();
62 $tmp2 = array();
63 $prios = array();
64 $cats = array();
66 foreach($this->gosaMemberApplication as $memberApp){
67 if(preg_match("/\|/i",$memberApp)){
69 $tmp = split("\|",$memberApp);
71 if(!empty($tmp[0])){
72 $tmp2[$tmp[1]][$tmp[2]] = array("App"=>$tmp[0]);
73 }
74 if(!empty($tmp[1])){
75 $n = split("/",$tmp[1]);
76 $c = count($n);
77 $cats [$tmp[1]] = $n[$c-1];
78 }
79 $prios[$tmp[1]][$tmp[2]] = $tmp[2];
80 }else{
81 $tmp2[]['App'] = $memberApp;
82 }
83 }
85 $this->Categories = $cats;
87 $this->gosaMemberApplication = $tmp2;
88 $cats[""]="";
89 foreach($cats as $cat ){
90 if((isset($prios[$cat]))&&(count($prios[$cat]))){
91 $max = max($prios[$cat]);
92 $min = 1;//min($prios[$cat]);
93 $last = false;
94 for($i = $min ; $i < $max ; $i++){
95 if(!isset($prios[$cat][$i])){
96 if($last == false){
97 $this->gosaMemberApplication[$cat][$i]['App'] = "__SEPARATOR__".$i;
99 $last = true;
100 }
101 }else{
102 $last = false;
103 }
104 }
105 }
106 }
108 $tmp = array();
109 foreach($this->gosaMemberApplication as $key => $entries){
110 ksort ($entries);
111 foreach($entries as $entry){
112 $tmp[$key][]= $entry;
113 }
114 }
115 $this->gosaMemberApplication = $tmp;
116 $this->curbase = $this->config->current['BASE'];
118 /* Check if we should enable the release selection
119 */
120 $tmp = search_config($config->data,"faiManagement","CLASS");
121 if(!empty($tmp)){
122 $this->enableReleaseManagement = true;
123 $this->Release = $this->getReleaseName();
124 $this->Releases= $this->getReleases();
125 }
126 }
129 /* Combine new array */
130 function combineArrays($ar0,$ar1,$ar2)
131 {
132 $ret = array();
133 if(is_array($ar0))
134 foreach($ar0 as $ar => $a){
135 $ret[$ar]=$a;
136 }
137 if(is_array($ar1))
138 foreach($ar1 as $ar => $a){
139 $ret[$ar]=$a;
140 }
141 if(is_array($ar2))
142 foreach($ar2 as $ar => $a){
143 $ret[$ar]=$a;
144 }
145 return($ret);
146 }
148 function getpos($atr,$attrs)
149 {
150 $i = 0;
151 foreach($attrs as $attr => $name) {
152 $i++;
153 if($attr == $atr){
154 return($i);
155 }
156 }
157 return(-1);
158 }
161 /* TRansports the geiven Arraykey one position up*/
162 function ArrayUp($atr,$attrs)
163 {
164 $ret = $attrs;
165 $pos = $this->getpos($atr,$attrs) ;
166 $cn = count($attrs);
167 if(!(($pos == -1)||($pos == 1))){
168 $before = array_slice($attrs,0,($pos-2));
169 $mitte = array_reverse(array_slice($attrs,($pos-2),2));
170 $unten = array_slice($attrs,$pos);
171 $ret = array();
172 $ret = $this->combineArrays($before,$mitte,$unten);
173 }
174 return($ret);
175 }
178 /* TRansports the geiven Arraykey one position up*/
179 function ArrayDown($atr,$attrs)
180 {
181 $ret = $attrs;
182 $pos = $this->getpos($atr,$attrs) ;
183 $cn = count($attrs);
184 if(!(($pos == -1)||($pos == $cn))){
185 $before = array_slice($attrs,0,($pos-1));
186 $mitte = array_reverse(array_slice($attrs,($pos-1),2));
187 $unten = array_slice($attrs,($pos+1));
188 $ret = array();
189 $ret = $this->combineArrays($before,$mitte,$unten);
190 }
191 return($ret);
192 }
195 function catUp($id)
196 {
197 /* Get all cats depinding on current dir */
198 $cats = $this->GetSubdirs($this->curCatDir);
199 $newcats =$this->ArrayUp($id,$cats);
201 foreach($newcats as $cat => $name){
202 unset($this->Categories[$cat]);
203 }
204 foreach($newcats as $cat => $name){
205 $this->Categories[$cat]=$name;
206 }
207 }
210 function catDown($id)
211 {
212 /* Get all cats depinding on current dir */
213 $cats = $this->GetSubdirs($this->curCatDir);
215 $newcats =$this->ArrayDown($id,$cats);
217 foreach($newcats as $cat => $name){
218 unset($this->Categories[$cat]);
219 }
220 foreach($newcats as $cat => $name){
221 $this->Categories[$cat]=$name;
222 }
223 }
226 function getOneUp($appl)
227 {
228 $cat = $this->curCatDir;
229 $apps = $this->gosaMemberApplication[$cat];
231 $appsA = array();
232 foreach ($apps as $appkey => $name){
233 $appsA[$name['App']] =$name['App'];
234 }
236 $result = $this->ArrayUp($appl,$appsA);
238 $ret = array();
239 foreach($result as $app){
240 $ret[]=array("App"=>$app);
241 }
242 $this->gosaMemberApplication[$cat] = $ret;
243 }
246 function getOneDown($appl)
247 {
248 $cat = $this->curCatDir;
249 $apps = $this->gosaMemberApplication[$cat];
251 $appsA = array();
252 foreach ($apps as $appkey => $name){
253 $appsA[$name['App']] =$name['App'];
254 }
256 $result = $this->ArrayDown($appl,$appsA);
258 $ret = array();
259 foreach($result as $app){
260 $ret[]=array("App"=>$app);
261 }
262 $this->gosaMemberApplication[$cat] = $ret;
263 }
267 function AddSeperator($id)
268 {
269 $found = false;
270 $cat = "";
271 $tmp = array();
272 foreach($this->gosaMemberApplication[$this->curCatDir] as $appID => $app){
273 $tmp[] = $app;
274 if(($app['App'] == $id)&&(!$found)){
275 $cnt = count($this->gosaMemberApplication[$this->curCatDir]);
276 $tmp[] = array("App" => "__SEPARATOR__".($cnt+1));
277 $found = true;
278 }
279 }
280 if($found){
281 $this->gosaMemberApplication[$this->curCatDir]=$tmp;
282 }
283 }
285 function execute()
286 {
287 /* Call parent execute */
288 plugin::execute();
290 if((isset($_GET['act']))&&($_GET['act']=="depopen")){
291 $dep = base64_decode($_GET['depid']);
292 if(isset($this->config->idepartments[$dep])){
293 $this->curbase =$dep;
294 }
295 }
297 if((isset($_GET['act']))&&($_GET['act']=="open")){
298 $this->curCatDir = base64_decode($_GET['id']);
299 }
301 /* Do we need to flip is_account state? */
302 if (isset($_POST['modify_state'])){
303 $this->is_account= !$this->is_account;
304 }
306 /* Do we represent a valid group? */
307 if (!$this->is_account && $this->parent == NULL){
308 $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\"> <b>".
309 _("This 'dn' is no appgroup.")."</b>";
310 return ($display);
311 }
313 /* Show tab dialog headers */
314 $display= "";
315 if ($this->parent != NULL){
316 if ($this->is_account){
317 $display= $this->show_header(_("Remove applications"),
318 _("This group has application features enabled. You can disable them by clicking below."));
319 } else {
320 $display.= $this->show_header(_("Create applications"),
321 _("This group has application features disabled. You can enable them by clicking below."));
322 return ($display);
323 }
324 }
327 /* Add Categorie */
330 if((isset($_POST['AddCat']))&&(isset($_POST['CatName']))&&(!empty($_POST['CatName']))){
332 if(preg_match("/[\\\\\/]/i",$_POST['CatName'])){
333 print_red(_("Invalid character in category name."));
334 }elseif(!in_array($_POST['CatName'],$this->Categories)){
335 if(empty($this->curCatDir)){
336 $this->Categories[$_POST['CatName']]=$_POST['CatName'];
337 }else{
338 $this->Categories[$this->curCatDir."/".$_POST['CatName']]=$_POST['CatName'];
339 }
340 }else{
341 print_red(_("The specified category already exists."));
342 }
343 }
346 $this->reload();
347 $only_once = false;
348 foreach($_POST as $name => $value){
350 if((preg_match("/AddSep_/",$name))&&(!$only_once)){
351 $only_once = true;
352 $n = preg_replace("/AddSep_/","",$name);
353 $val= preg_replace("/_.*$/","",$n);
354 $this->AddSeperator($val);
355 }
357 if((preg_match("/DelApp_/",$name))&&(!$only_once)){
358 $only_once = true;
361 if(preg_match("/DelApp___SEPARATOR__/",$name)) {
362 $n= preg_replace("/DelApp___SEPARATOR__/","",$name);
363 $val= "__SEPARATOR__".preg_replace("/_.*$/","",$n);
364 }else{
365 $n = preg_replace("/DelApp_/","",$name);
366 $val= preg_replace("/_.*$/","",$n);
367 }
369 foreach($this->gosaMemberApplication as $key => $cat){
370 foreach($cat as $key2 => $app){
371 if($app['App'] == $val){
372 unset($this->gosaMemberApplication[$key][$key2]);
373 if(isset($this->used_apps[$val])){
374 unset($this->used_apps[$val]);
375 }
376 }
377 }
378 }
379 }
381 if(preg_match("/DelCat_/",$name)){
382 $n = preg_replace("/DelCat_/","",$name);
383 $app = base64_decode( preg_replace("/_.*$/","",$n));
384 foreach($this->Categories as $key => $cat){
385 if($cat == $app){
386 foreach($this->Categories as $p => $n){
387 if(preg_match("/^".$key."\/.*/",$p)){
388 unset($this->Categories[$p]);
389 }
390 }
391 unset($this->Categories[$key]);
392 }
393 }
394 }
396 if((preg_match("/EdiApp_/",$name))&&(!$only_once)){
398 $only_once = true;
399 $appname = $value;
400 $appname = preg_replace("/EdiApp_/","",$name);
401 $appname = preg_replace("/_.*$/","",$appname);
403 /* We've got the appname, get parameters from ldap
404 */
405 $ldap= $this->config->get_ldap_link();
407 $tmp = search_config($this->config->data,"faiManagement","CLASS");
408 if(!empty($tmp)){
409 $base = $this->Releases[$this->Release];
411 $ldap->cd($this->config->current['BASE']);
412 $ldap->search("(&(objectClass=gosaApplication)(cn=$appname))",array("gosaApplicationParameter"));
413 $found = "";
414 while($attrs = $ldap->fetch()) {
415 if(preg_match("/cn=".$appname.",".$base."/",$attrs['dn'])){
416 $found = $attrs['dn'];
417 }
418 }
419 $ldap->cat($found);
420 }else{
421 $ldap->cd($this->config->current['BASE']);
422 $ldap->search("(&(objectClass=gosaApplication)(cn=$appname))",array("gosaApplicationParameter"));
424 }
427 if ($ldap->count() != 1){
428 print_red (_("The selected application name is not uniq. Please check your LDAP."));
429 } else {
430 $attrs= $ldap->fetch();
431 if(isset($attrs['gosaApplicationParameter'])){
432 $this->dialog= TRUE;
434 /* Fill name and value arrays */
435 for ($i= 0; $i<$attrs['gosaApplicationParameter']['count']; $i++){
436 $option= preg_replace('/^[^:]+:/', '',
437 $attrs['gosaApplicationParameter'][$i]);
438 $name= preg_replace('/:.*$/', '',
439 $attrs['gosaApplicationParameter'][$i]);
440 $this->option_name[$i]= $name;
442 /* Fill with values from application, default should be
443 loaded by the external scripts */
444 if (isset($this->appoption[$name])){
445 $this->option_value[$i]= $this->appoption[$name];
446 }
447 }
449 /* Create edit field */
450 $table= "<table summary=\"\">";
451 for ($i= 0; $i < count($this->option_name); $i++){
452 if (isset($this->option_value[$i])){
453 $value= $this->option_value[$i];
454 } else {
455 $value= "";
456 }
457 $table.="<tr><td>".$this->option_name[$i]."</td><td>".
458 "<input name=\"value$i\" size=60 maxlength=250 ".
459 "value=\"".$value."\"><br></td></tr>";
460 }
461 $table.= "</table>";
462 $this->table= $table;
463 } else {
464 print_red (_("The selected application has no options."));
465 }
466 }
467 }
468 }
469 $this->reload();
470 /* Add group with post */
471 if((isset($_GET['act']))&&($_GET['act']=="add")){
472 $this->used_apps[$_GET['id']]= $_GET['id'];
473 asort($this->used_apps);
474 $this->addApp($_GET['id']);
475 }
477 /* Add multiple */
478 if(isset($_POST['AddApps'])){
479 foreach($_POST as $name => $value){
480 if(preg_match("/AddApp_/",$name)){
481 $app = preg_replace("/AddApp_/","",$name);
482 $this->addApp($app);
483 }
484 }
485 }
488 /* Cancel edit options? */
489 if (isset($_POST['edit_options_cancel'])){
490 $this->dialog= FALSE;
491 }
493 /* Finish edit options? */
494 if (isset($_POST['edit_options_finish'])){
495 $this->dialog= FALSE;
497 /* Save informations passed by the user */
498 $this->option_value= array();
499 for ($i= 0; $i<count($this->option_name); $i++){
500 $this->appoption[$this->option_name[$i]]= $_POST["value$i"];
501 $this->is_modified= TRUE;
502 }
503 }
505 /* Prepare templating stuff */
506 $smarty= get_smarty();
507 $smarty->assign("used_apps", $this->used_apps);
508 $apps= array();
509 foreach ($this->apps as $key => $value){
510 if (!array_key_exists($key, $this->used_apps)){
511 $apps["$key"]= "$value";
512 }
513 }
515 $div = new DivSelectBox("appgroup");
517 $div->SetHeight(400);
519 /* NEW LIST MANAGMENT
520 * We also need to search for the departments
521 * So we are able to navigate like in konquerer
522 */
524 $ldap = $this->config->get_ldap_link();
525 $ldap->cd($this->curbase) ;
526 $ldap->ls("(objectClass=gosaDepartment)");
527 $departments= array();
528 $tmp = array();
529 while ($value = $ldap->fetch()){
530 $tmp[strtolower($value['dn']).$value['dn']]=$value;
531 }
532 ksort($tmp);
533 foreach($tmp as $value){
534 if($value["description"][0]!=".."){
535 $departments[$value['dn']]=convert_department_dn($value['dn'])." - [".$value["description"][0]."]";
536 }else{
537 $departments[$value['dn']]=convert_department_dn($value['dn']);
538 }
539 }
541 /* END NEW LIST MANAGMENT
542 */
544 $linkopen = "<a href='?plug=".$_GET['plug']."&act=depopen&depid=%s'>%s</a>";
545 $linkadd = "<a href='?plug=".$_GET['plug']."&act=add&id=%s'>%s</a>";
547 $base_back = preg_replace("/^[^,]+,/","",$this->curbase);
548 if((strlen($base_back)>= strlen($this->config->current['BASE']))&&($this->curbase!=$this->config->current['BASE'])){
549 $div->AddEntry(array(
550 array("string"=>sprintf($linkopen,base64_encode($base_back),".. ["._("back")."]"),
551 "attach"=>"style='border:0px;'")
552 ));
553 }
554 foreach($departments as $key => $app){
555 $div->AddEntry(array(
556 array("string"=>"<img class='center' src='images/folder.png' alt='"._("department")."'> ".sprintf($linkopen,base64_encode($key),$app),
557 "attach"=>"style='border:0px;'")
558 ));
559 }
561 foreach($apps as $key => $app){
562 $div->AddEntry(array(
563 array("string"=>sprintf("<input class='center' type='checkbox' value='1' name='AddApp_%s'>",$key).
564 "<img class='center' src='images/select_application.png' alt='"._("application")."'> ".sprintf($linkadd,$key,$app),
565 "attach"=>"style='border:0px;'")
566 ));
567 }
569 if((isset($_GET['act']))&&(($_GET['act'] == "cat_up")||($_GET['act']=="cat_down"))){
570 if($_GET['act']=="cat_up"){
571 $this->catUp(base64_decode($_GET['id']));
572 }
573 if($_GET['act']=="cat_down"){
574 $this->catDown(base64_decode($_GET['id']));
575 }
576 }
578 if((isset($_GET['act']))&&(($_GET['act'] == "one_up")||($_GET['act']=="one_down"))){
579 if(isset($_GET['id'])){
580 $id = $_GET['id'];
581 $act = $_GET['act'];
583 if($act == "one_up"){
584 $this->getOneUp($id);
585 }elseif($act == "one_down") {
586 $this->getOneDown($id);
587 }
588 }
589 }
591 $div2 = new DivSelectBox("appgroup");
592 $div2->SetHeight(400);
594 $linkopen = "<img class='center' src='images/folder.png' alt=\"\"> <a href='?plug=".$_GET['plug']."&act=open&id=%s'>%s</a>";
595 $catremove = " <input type='image' src='images/edittrash.png' title='"._("Delete entry")."' name='DelCat_%s' value='%s'>";
596 $app = "<img class='center' src='images/select_application.png' alt=\"\"> %s";
598 $catupdown = "<a href='?plug=".$_GET['plug']."&act=cat_up&id=%s'>
599 <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'>
600 <img alt=\"\" src='images/sort_down.png' title='"._("Move down")."' border=0></a>";
602 if(empty($this->curCatDir)){
603 $cnt =0;
604 }else{
605 $cnt = count(split("/",$this->curCatDir));
606 $tmp = split("/",$this->curCatDir);
607 $bbk = "";
608 for($i = 0 ; $i < ($cnt -1 ) ; $i++){
609 $bbk .= $tmp[$i];
610 }
611 $div2 ->AddEntry(array(array("string"=>sprintf($linkopen,base64_encode($bbk),"..")),array("string"=>" ","attach"=>"style='border-right:0px;'")));
612 }
614 $this->GetSubdirs($this->curCatDir);
616 foreach($this->GetSubdirs($this->curCatDir) as $path => $name){
617 $div2 ->AddEntry(array(
618 array("string"=>sprintf($linkopen,base64_encode($path),$name)),
619 array("string"=>preg_replace("/%s/",base64_encode($path),$catupdown.$catremove),
620 "attach"=>"align='right' style='width:80px;border-right:0px;'")));
621 }
623 /* Append entries */
625 $separator ="<hr size=1>";
627 $sep = "<input type='image' src='images/back.png' title='"._("Insert seperator")."' value='%s' name='AddSep_%s'>";
629 $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>".
630 " <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>".
631 " <input type='image' src='images/edittrash.png' title='"._("Delete entry")."' name='DelApp_%s' value='%s' alt='{t}delete{/t}' >";
632 $edit= " <input type='image' src='images/edit.png' title='"._("Edit entry")."' name='EdiApp_%s' value='%s' alt='{t}edit{/t}' >";
634 if(isset($this->gosaMemberApplication[$this->curCatDir])){
635 foreach($this->gosaMemberApplication[$this->curCatDir] as $cat => $entry){
638 if(preg_match("/__SEPARATOR__/",$entry['App'])){
639 $div2 ->AddEntry(array(array("string"=>$separator),
640 array("string"=>preg_replace("/\%s/",htmlentities($entry['App']),$upudown),"attach"=>"align='right' style='border-right:0px;'")));
641 }else{
643 $image = "";
644 /* Check if application was available within selected release
645 * or application list if release management is not active
646 */
647 if(!in_array($entry['App'],$this->AllAppsForRelease)){
649 /* release managent is active
650 */
651 if(!$this->enableReleaseManagement){
652 $image = "<img class='center' src='images/select_invalid_application.png'
653 title='"._("This application is no longer available.")."'> ";
654 }else{
655 $image = "<img class='center' src='images/select_invalid_application.png'
656 title='".sprintf(_("This application is not available in any release named %s."),$this->Release)."'> ";
657 }
659 }else{
660 $image = "<img class='center' src='images/select_application.png' alt=\"\"> ";
661 }
663 $div2 ->AddEntry(array(array("string"=>sprintf($image."%s",$entry['App'])),
664 array("string"=>preg_replace("/\%s/",htmlentities($entry['App']),$sep.$edit.$upudown),
665 "attach"=>"align='right' style='width:100px;border-right:0px;'")));
666 }
667 }
668 }
670 $smarty->assign("UsedApps", $div2->DrawList());
671 $smarty->assign("List", $div->DrawList());
672 $smarty->assign("apps", $apps);
674 $smarty->assign("enableReleaseManagement",$this->enableReleaseManagement);
676 if($this->enableReleaseManagement){
677 $smarty->assign("Release", $this->Release);
678 $smarty->assign("Releases", $this->Releases);
680 if(count($this->used_apps)){
681 $smarty->assign("ReleaseSelectAble", false);
682 }else{
683 $smarty->assign("ReleaseSelectAble", true);
684 }
685 }
686 $smarty->assign("ReleaseSelectAble", true);
688 /* Show main page */
689 if ($this->dialog){
690 $smarty->assign("table", $this->table);
691 $display.= $smarty->fetch (get_template_path('application_options.tpl', TRUE));
692 } else {
693 $display.= $smarty->fetch (get_template_path('application.tpl', TRUE));
694 }
695 return ($display);
696 }
699 function getReleases()
700 {
701 $dn = "ou=apps,".$this->config->current['BASE'];
702 $ldap = $this->config->get_ldap_link();
703 $ldap->cd($dn);
704 $ldap->search("objectClass=organizationalUnit",array("ou"));
705 $ret =array();
706 while($attrs = $ldap->fetch()){
707 if(preg_match("/ou=apps,/",$attrs['dn'])){
708 $bb = preg_replace("/ou=apps,.*/","",$attrs['dn']);
709 $parts = array_reverse(split("ou=",$bb));
711 $str ="";
712 foreach($parts as $part){
713 if(empty($part)) {
714 continue;
715 }
716 $str .= str_replace(",","",$part)."/";
717 }
718 $name = preg_replace("/\/$/","",$str);
719 if(empty($name)) {
720 $name ="/";
721 }
722 $ret[$attrs['dn']] = $name;
723 }
724 }
725 return($ret);
726 }
728 function save_object()
729 {
730 if(isset($_POST ['Release'])){
731 $this->Release = $_POST['Release'];
732 }
733 }
736 function remove_from_parent()
737 {
738 plugin::remove_from_parent();
740 $this->attrs["gosaMemberApplication"]= array();
742 $ldap= $this->config->get_ldap_link();
743 $ldap->cd($this->dn);
744 $this->cleanup();
745 $ldap->modify ($this->attrs);
747 show_ldap_error($ldap->get_error());
749 /* Optionally execute a command after we're done */
750 $this->handle_post_events("remove");
751 }
754 /* Save to LDAP */
755 function save()
756 {
757 plugin::save();
759 /* Copy members */
760 $this->Categories[""]="";
761 $this->attrs["gosaMemberApplication"]= array();
762 foreach($this->Categories as $name => $cats){
763 $i =0;
764 if(isset($this->gosaMemberApplication[$name])){
765 foreach($this->gosaMemberApplication[$name] as $entry){
766 if(!preg_match("/__SEPARATOR__/",$entry['App'])){
767 $this->attrs["gosaMemberApplication"][]= $entry['App']."|".$name."|".$i;
768 }
769 $i ++;
770 }
771 }
772 if(($i==0)&&(!empty($name))){
773 $this->attrs["gosaMemberApplication"][]= "|".$name."|".$i;
774 }
775 }
777 /* Are there application parameters to be saved */
778 $this->attrs['gosaApplicationParameter']= array();
779 foreach($this->appoption as $name => $value){
780 if ($value != ""){
781 $this->attrs['gosaApplicationParameter'][]= "$name:$value";
782 }
783 }
785 /* Write back to LDAP */
786 $ldap= $this->config->get_ldap_link();
787 $ldap->cd($this->dn);
788 $this->cleanup();
789 $ldap->modify ($this->attrs);
791 show_ldap_error($ldap->get_error());
793 /* Optionally execute a command after we're done */
794 if ($this->initially_was_account == $this->is_account){
795 if ($this->is_modified){
796 $this->handle_post_events("mofify");
797 }
798 } else {
799 $this->handle_post_events("add");
800 }
802 }
804 function check()
805 {
806 /* Call common method to give check the hook */
807 $message= plugin::check();
809 return ($message);
810 }
813 function reload()
814 {
815 /* Generate applist */
816 $this->apps= array();
818 /* Special handling for release managed apps
819 */
820 $tmp = search_config($this->config->data,"faiManagement","CLASS");
821 if(!empty($tmp)){
822 $this->enableReleaseManagement = true;
824 $tmp = array_flip($this->Releases);
825 if(isset($tmp[$this->Release])){
826 $base = $tmp[$this->Release];
827 }else{
828 $k = key($tmp);
829 $r = $tmp[$k];
830 $this->Release = $k;
831 $base = $r;
833 print_red(sprintf(_("Can't resolve the release name '%s', setting release name to '%s'. Possibly the objects base has changed."),$this->Release,$k));
834 }
836 $base = preg_replace("/ou=apps,.*$/","ou=apps,".$this->curbase,$base);
838 $ldap = $this->config->get_ldap_link();
839 $ldap->cd ($base);
840 $ldap->ls ("(objectClass=gosaApplication)",$base);
841 }else{
842 $ldap = $this->config->get_ldap_link();
843 $ldap->cd ("ou=apps,".$this->curbase);
844 $ldap->ls ("(objectClass=gosaApplication)","ou=apps,".$this->curbase);
845 }
847 while ($attrs= $ldap->fetch()){
848 if (isset($attrs["description"][0])){
849 $this->apps[$attrs["cn"][0]]=
850 $attrs["cn"][0]." (".
851 $attrs["description"][0].")";
852 } else {
853 $this->apps[$attrs["cn"][0]]=
854 $attrs["cn"][0];
855 }
856 }
858 $ldap->cd($this->config->current['BASE']);
859 $ldap->search("objectClass=gosaApplication",array("cn"));
860 $tmp = search_config($this->config->data,"faiManagement","CLASS");
861 $this->AllAppsForRelease = array();
862 if(!empty($tmp)){
864 $tmp = array_flip($this->Releases);
866 while($attrs = $ldap->fetch()){
867 $testdn = preg_replace("/ou=apps,.*$/","ou=apps",$attrs['dn']);
868 $testdn = preg_replace("/^[^,]+/","",$testdn);
869 $testdn = preg_replace("/^,/","",$testdn);
871 if($testdn == preg_replace("/ou=apps,.*$/","ou=apps",$tmp[$this->Release])){
872 $this->AllAppsForRelease[$attrs['dn']] = $attrs['cn'][0];
873 }
874 }
875 }else{
876 while($attrs = $ldap->fetch()){
877 $this->AllAppsForRelease[$attrs['dn']] = $attrs['cn'][0];
878 }
879 }
881 natcasesort ($this->apps);
882 reset ($this->apps);
884 if(is_array($this->gosaMemberApplication))
885 foreach ($this->gosaMemberApplication as $cat){
886 if(is_array($cat))
887 foreach($cat as $entry){
888 $this->used_apps[$entry['App']]= $entry['App'];
889 }
890 }
891 }
894 function addApp($cn)
895 {
896 if((isset($this->gosaMemberApplication[$this->curCatDir]))&&(is_array($this->gosaMemberApplication[$this->curCatDir]))){
897 foreach($this->gosaMemberApplication[$this->curCatDir] as $entry){
898 if($entry['App'] == $cn) return;
899 }
900 }
901 $this->gosaMemberApplication[$this->curCatDir][]= array("App"=>$cn);
902 $this->used_apps[$cn]=$cn;
903 $this->is_modified= TRUE;
904 }
907 function removeApp($cn)
908 {
909 $temp= array();
910 foreach ($this->gosaMemberApplication as $value){
911 if ($value != $cn){
912 $temp[]= $value;
913 }
914 }
915 $this->gosaMemberApplication= $temp;
916 $this->is_modified= TRUE;
917 }
919 function GetSubdirs($dir)
920 {
921 $ret = array();
922 $tmp1 = split("/",$this->curCatDir);
924 foreach($this->Categories as $path=>$cat){
925 $tmp2 = split("/",$path);
927 if((empty($this->curCatDir))&&(!preg_match("/\//",$path))){
928 $abort = false;
929 }elseif(((count($tmp1))+1) == (count($tmp2))){
930 $abort = false;
931 for($i = 0 ; $i < count($tmp1) ; $i++){
932 if($tmp1[$i] != $tmp2[$i]){
933 $abort = true;
934 }
935 }
936 }else{
937 $abort= true;
938 }
939 if(!$abort){
940 $ret[$path]=$cat;
941 }
942 }
943 return($ret);
944 }
947 /* Get selected release name.
948 * it is written in the description tag
949 * within ... (.*)$
950 */
951 function getReleaseName()
952 {
954 if(isset($this->parent)){
955 $base = $this->parent->by_object['group'];
956 }else{
957 $base = $this;
958 }
960 if(isset($base->attrs['description'][0])){
961 $desc = $base->attrs['description'][0];
962 }else{
963 $desc = "";
964 }
966 if(preg_match("/\(.*\)$/",$desc)){
967 $str = preg_replace("/^.*\((.*)\)$/","\\1",$desc);
968 }else{
969 $str = "/";
970 }
971 return($str);
972 }
973 }
975 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
976 ?>