4727a3ea3d736320f2dd2625108c673f91e273c1
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 $enableReleaseManagement = false;
34 function appgroup ($config, $dn= NULL)
35 {
36 plugin::plugin ($config, $dn);
38 /* Load member applications */
39 if (isset ($this->attrs["gosaMemberApplication"][0])){
40 $this->gosaMemberApplication = array();
41 for ($i= 0; $i<$this->attrs["gosaMemberApplication"]["count"]; $i++){
42 $this->gosaMemberApplication[]=
43 $this->attrs["gosaMemberApplication"][$i];
44 }
45 }
47 /* Load application options */
48 if (isset($this->attrs['gosaApplicationParameter'])){
49 for ($i= 0; $i<$this->attrs['gosaApplicationParameter']['count']; $i++){
50 $option= preg_replace('/^[^:]+:/', '',
51 $this->attrs['gosaApplicationParameter'][$i]);
52 $name= preg_replace('/:.*$/', '',
53 $this->attrs['gosaApplicationParameter'][$i]);
54 $this->appoption[$name]= $option;
55 }
56 }
58 /* Parse MemberApplication*/
59 $tmp = array();
60 $tmp2 = array();
61 $prios = array();
62 $cats = array();
64 foreach($this->gosaMemberApplication as $memberApp){
65 if(preg_match("/\|/i",$memberApp)){
67 $tmp = split("\|",$memberApp);
69 if(!empty($tmp[0])){
70 $tmp2[$tmp[1]][$tmp[2]] = array("App"=>$tmp[0]);
71 }
72 if(!empty($tmp[1])){
73 $n = split("/",$tmp[1]);
74 $c = count($n);
75 $cats [$tmp[1]] = $n[$c-1];
76 }
77 $prios[$tmp[1]][$tmp[2]] = $tmp[2];
78 }else{
79 $tmp2[]['App'] = $memberApp;
80 }
81 }
83 $this->Categories = $cats;
85 $this->gosaMemberApplication = $tmp2;
86 $cats[""]="";
87 foreach($cats as $cat ){
88 if((isset($prios[$cat]))&&(count($prios[$cat]))){
89 $max = max($prios[$cat]);
90 $min = 1;//min($prios[$cat]);
91 $last = false;
92 for($i = $min ; $i < $max ; $i++){
93 if(!isset($prios[$cat][$i])){
94 if($last == false){
95 $this->gosaMemberApplication[$cat][$i]['App'] = "__SEPARATOR__".$i;
97 $last = true;
98 }
99 }else{
100 $last = false;
101 }
102 }
103 }
104 }
106 $tmp = array();
107 foreach($this->gosaMemberApplication as $key => $entries){
108 ksort ($entries);
109 foreach($entries as $entry){
110 $tmp[$key][]= $entry;
111 }
112 }
113 $this->gosaMemberApplication = $tmp;
114 $this->curbase = $this->config->current['BASE'];
116 /* Check if we should enable the release selection
117 */
118 $tmp = search_config($config->data,"faiManagement","CLASS");
119 if(!empty($tmp)){
120 $this->enableReleaseManagement = true;
121 $this->Release = $this->getReleaseName();
122 }
123 }
126 /* Combine new array */
127 function combineArrays($ar0,$ar1,$ar2)
128 {
129 $ret = array();
130 if(is_array($ar0))
131 foreach($ar0 as $ar => $a){
132 $ret[$ar]=$a;
133 }
134 if(is_array($ar1))
135 foreach($ar1 as $ar => $a){
136 $ret[$ar]=$a;
137 }
138 if(is_array($ar2))
139 foreach($ar2 as $ar => $a){
140 $ret[$ar]=$a;
141 }
142 return($ret);
143 }
145 function getpos($atr,$attrs)
146 {
147 $i = 0;
148 foreach($attrs as $attr => $name) {
149 $i++;
150 if($attr == $atr){
151 return($i);
152 }
153 }
154 return(-1);
155 }
158 /* TRansports the geiven Arraykey one position up*/
159 function ArrayUp($atr,$attrs)
160 {
161 $ret = $attrs;
162 $pos = $this->getpos($atr,$attrs) ;
163 $cn = count($attrs);
164 if(!(($pos == -1)||($pos == 1))){
165 $before = array_slice($attrs,0,($pos-2));
166 $mitte = array_reverse(array_slice($attrs,($pos-2),2));
167 $unten = array_slice($attrs,$pos);
168 $ret = array();
169 $ret = $this->combineArrays($before,$mitte,$unten);
170 }
171 return($ret);
172 }
175 /* TRansports the geiven Arraykey one position up*/
176 function ArrayDown($atr,$attrs)
177 {
178 $ret = $attrs;
179 $pos = $this->getpos($atr,$attrs) ;
180 $cn = count($attrs);
181 if(!(($pos == -1)||($pos == $cn))){
182 $before = array_slice($attrs,0,($pos-1));
183 $mitte = array_reverse(array_slice($attrs,($pos-1),2));
184 $unten = array_slice($attrs,($pos+1));
185 $ret = array();
186 $ret = $this->combineArrays($before,$mitte,$unten);
187 }
188 return($ret);
189 }
192 function catUp($id)
193 {
194 /* Get all cats depinding on current dir */
195 $cats = $this->GetSubdirs($this->curCatDir);
196 $newcats =$this->ArrayUp($id,$cats);
198 foreach($newcats as $cat => $name){
199 unset($this->Categories[$cat]);
200 }
201 foreach($newcats as $cat => $name){
202 $this->Categories[$cat]=$name;
203 }
204 }
207 function catDown($id)
208 {
209 /* Get all cats depinding on current dir */
210 $cats = $this->GetSubdirs($this->curCatDir);
212 $newcats =$this->ArrayDown($id,$cats);
214 foreach($newcats as $cat => $name){
215 unset($this->Categories[$cat]);
216 }
217 foreach($newcats as $cat => $name){
218 $this->Categories[$cat]=$name;
219 }
220 }
223 function getOneUp($appl)
224 {
225 $cat = $this->curCatDir;
226 $apps = $this->gosaMemberApplication[$cat];
228 $appsA = array();
229 foreach ($apps as $appkey => $name){
230 $appsA[$name['App']] =$name['App'];
231 }
233 $result = $this->ArrayUp($appl,$appsA);
235 $ret = array();
236 foreach($result as $app){
237 $ret[]=array("App"=>$app);
238 }
239 $this->gosaMemberApplication[$cat] = $ret;
240 }
243 function getOneDown($appl)
244 {
245 $cat = $this->curCatDir;
246 $apps = $this->gosaMemberApplication[$cat];
248 $appsA = array();
249 foreach ($apps as $appkey => $name){
250 $appsA[$name['App']] =$name['App'];
251 }
253 $result = $this->ArrayDown($appl,$appsA);
255 $ret = array();
256 foreach($result as $app){
257 $ret[]=array("App"=>$app);
258 }
259 $this->gosaMemberApplication[$cat] = $ret;
260 }
264 function AddSeperator($id)
265 {
266 $found = false;
267 $cat = "";
268 $tmp = array();
269 foreach($this->gosaMemberApplication[$this->curCatDir] as $appID => $app){
270 $tmp[] = $app;
271 if(($app['App'] == $id)&&(!$found)){
272 $cnt = count($this->gosaMemberApplication[$this->curCatDir]);
273 $tmp[] = array("App" => "__SEPARATOR__".($cnt+1));
274 $found = true;
275 }
276 }
277 if($found){
278 $this->gosaMemberApplication[$this->curCatDir]=$tmp;
279 }
280 }
282 function execute()
283 {
284 /* Call parent execute */
285 plugin::execute();
287 if((isset($_GET['act']))&&($_GET['act']=="depopen")){
288 $dep = base64_decode($_GET['depid']);
289 if(isset($this->config->idepartments[$dep])){
290 $this->curbase =$dep;
291 }
292 }
294 if((isset($_GET['act']))&&($_GET['act']=="open")){
295 $this->curCatDir = base64_decode($_GET['id']);
296 }
298 /* Do we need to flip is_account state? */
299 if (isset($_POST['modify_state'])){
300 $this->is_account= !$this->is_account;
301 }
303 /* Do we represent a valid group? */
304 if (!$this->is_account && $this->parent == NULL){
305 $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\"> <b>".
306 _("This 'dn' is no appgroup.")."</b>";
307 return ($display);
308 }
310 /* Show tab dialog headers */
311 $display= "";
312 if ($this->parent != NULL){
313 if ($this->is_account){
314 $display= $this->show_header(_("Remove applications"),
315 _("This group has application features enabled. You can disable them by clicking below."));
316 } else {
317 $display.= $this->show_header(_("Create applications"),
318 _("This group has application features disabled. You can enable them by clicking below."));
319 return ($display);
320 }
321 }
324 /* Add Categorie */
327 if((isset($_POST['AddCat']))&&(isset($_POST['CatName']))&&(!empty($_POST['CatName']))){
329 if(preg_match("/[\\\\\/]/i",$_POST['CatName'])){
330 print_red(_("Invalid character in category name."));
331 }elseif(!in_array($_POST['CatName'],$this->Categories)){
332 if(empty($this->curCatDir)){
333 $this->Categories[$_POST['CatName']]=$_POST['CatName'];
334 }else{
335 $this->Categories[$this->curCatDir."/".$_POST['CatName']]=$_POST['CatName'];
336 }
337 }else{
338 print_red(_("The specified category already exists."));
339 }
340 }
343 $this->reload();
344 $only_once = false;
345 foreach($_POST as $name => $value){
347 if((preg_match("/AddSep_/",$name))&&(!$only_once)){
348 $only_once = true;
349 $n = preg_replace("/AddSep_/","",$name);
350 $val= preg_replace("/_.*$/","",$n);
351 $this->AddSeperator($val);
352 }
354 if((preg_match("/DelApp_/",$name))&&(!$only_once)){
355 $only_once = true;
358 if(preg_match("/DelApp___SEPARATOR__/",$name)) {
359 $n= preg_replace("/DelApp___SEPARATOR__/","",$name);
360 $val= "__SEPARATOR__".preg_replace("/_.*$/","",$n);
361 }else{
362 $n = preg_replace("/DelApp_/","",$name);
363 $val= preg_replace("/_.*$/","",$n);
364 }
366 foreach($this->gosaMemberApplication as $key => $cat){
367 foreach($cat as $key2 => $app){
368 if($app['App'] == $val){
369 unset($this->gosaMemberApplication[$key][$key2]);
370 if(isset($this->used_apps[$val])){
371 unset($this->used_apps[$val]);
372 }
373 }
374 }
375 }
376 }
378 if(preg_match("/DelCat_/",$name)){
379 $n = preg_replace("/DelCat_/","",$name);
380 $app = base64_decode( preg_replace("/_.*$/","",$n));
381 foreach($this->Categories as $key => $cat){
382 if($cat == $app){
383 foreach($this->Categories as $p => $n){
384 if(preg_match("/^".$key."\/.*/",$p)){
385 unset($this->Categories[$p]);
386 }
387 }
388 unset($this->Categories[$key]);
389 }
390 }
391 }
393 if((preg_match("/EdiApp_/",$name))&&(!$only_once)){
395 $only_once = true;
396 $appname = $value;
397 $appname = preg_replace("/EdiApp_/","",$name);
398 $appname = preg_replace("/_.*$/","",$appname);
400 /* We've got the appname, get parameters from ldap
401 */
402 $ldap= $this->config->get_ldap_link();
404 $tmp = search_config($this->config->data,"faiManagement","CLASS");
405 if(!empty($tmp)){
406 $tmp = array_flip($this->getReleases());
407 $base = $tmp[$this->Release];
409 $ldap->cd($this->config->current['BASE']);
410 $ldap->search("(&(objectClass=gosaApplication)(cn=$appname))",array("gosaApplicationParameter"));
411 $found = "";
412 while($attrs = $ldap->fetch()) {
413 if(preg_match("/cn=".$appname.",".$base."/",$attrs['dn'])){
414 $found = $attrs['dn'];
415 }
416 }
417 $ldap->cat($found);
418 }else{
419 $ldap->cd($this->config->current['BASE']);
420 $ldap->search("(&(objectClass=gosaApplication)(cn=$appname))",array("gosaApplicationParameter"));
422 }
425 if ($ldap->count() != 1){
426 print_red (_("The selected application name is not uniq. Please check your LDAP."));
427 } else {
428 $attrs= $ldap->fetch();
429 if(isset($attrs['gosaApplicationParameter'])){
430 $this->dialog= TRUE;
432 /* Fill name and value arrays */
433 for ($i= 0; $i<$attrs['gosaApplicationParameter']['count']; $i++){
434 $option= preg_replace('/^[^:]+:/', '',
435 $attrs['gosaApplicationParameter'][$i]);
436 $name= preg_replace('/:.*$/', '',
437 $attrs['gosaApplicationParameter'][$i]);
438 $this->option_name[$i]= $name;
440 /* Fill with values from application, default should be
441 loaded by the external scripts */
442 if (isset($this->appoption[$name])){
443 $this->option_value[$i]= $this->appoption[$name];
444 }
445 }
447 /* Create edit field */
448 $table= "<table summary=\"\">";
449 for ($i= 0; $i < count($this->option_name); $i++){
450 if (isset($this->option_value[$i])){
451 $value= $this->option_value[$i];
452 } else {
453 $value= "";
454 }
455 $table.="<tr><td>".$this->option_name[$i]."</td><td>".
456 "<input name=\"value$i\" size=60 maxlength=250 ".
457 "value=\"".$value."\"><br></td></tr>";
458 }
459 $table.= "</table>";
460 $this->table= $table;
461 } else {
462 print_red (_("The selected application has no options."));
463 }
464 }
465 }
466 }
467 $this->reload();
468 /* Add group with post */
469 if((isset($_GET['act']))&&($_GET['act']=="add")){
470 $this->used_apps[$_GET['id']]= $_GET['id'];
471 asort($this->used_apps);
472 $this->addApp($_GET['id']);
473 }
475 /* Add multiple */
476 if(isset($_POST['AddApps'])){
477 foreach($_POST as $name => $value){
478 if(preg_match("/AddApp_/",$name)){
479 $app = preg_replace("/AddApp_/","",$name);
480 $this->addApp($app);
481 }
482 }
483 }
486 /* Cancel edit options? */
487 if (isset($_POST['edit_options_cancel'])){
488 $this->dialog= FALSE;
489 }
491 /* Finish edit options? */
492 if (isset($_POST['edit_options_finish'])){
493 $this->dialog= FALSE;
495 /* Save informations passed by the user */
496 $this->option_value= array();
497 for ($i= 0; $i<count($this->option_name); $i++){
498 $this->appoption[$this->option_name[$i]]= $_POST["value$i"];
499 $this->is_modified= TRUE;
500 }
501 }
503 /* Prepare templating stuff */
504 $smarty= get_smarty();
505 $smarty->assign("used_apps", $this->used_apps);
506 $apps= array();
507 foreach ($this->apps as $key => $value){
508 if (!array_key_exists($key, $this->used_apps)){
509 $apps["$key"]= "$value";
510 }
511 }
513 $div = new DivSelectBox("appgroup");
515 $div->SetHeight(400);
517 /* NEW LIST MANAGMENT
518 * We also need to search for the departments
519 * So we are able to navigate like in konquerer
520 */
522 $ldap = $this->config->get_ldap_link();
523 $ldap->cd($this->curbase) ;
524 $ldap->ls("(objectClass=gosaDepartment)");
525 $departments= array();
526 $tmp = array();
527 while ($value = $ldap->fetch()){
528 $tmp[strtolower($value['dn']).$value['dn']]=$value;
529 }
530 ksort($tmp);
531 foreach($tmp as $value){
532 if($value["description"][0]!=".."){
533 $departments[$value['dn']]=convert_department_dn($value['dn'])." - [".$value["description"][0]."]";
534 }else{
535 $departments[$value['dn']]=convert_department_dn($value['dn']);
536 }
537 }
539 /* END NEW LIST MANAGMENT
540 */
542 $linkopen = "<a href='?plug=".$_GET['plug']."&act=depopen&depid=%s'>%s</a>";
543 $linkadd = "<a href='?plug=".$_GET['plug']."&act=add&id=%s'>%s</a>";
545 $base_back = preg_replace("/^[^,]+,/","",$this->curbase);
546 if((strlen($base_back)>= strlen($this->config->current['BASE']))&&($this->curbase!=$this->config->current['BASE'])){
547 $div->AddEntry(array(
548 array("string"=>sprintf($linkopen,base64_encode($base_back),".. ["._("back")."]"),
549 "attach"=>"style='border:0px;'")
550 ));
551 }
552 foreach($departments as $key => $app){
553 $div->AddEntry(array(
554 array("string"=>"<img class='center' src='images/folder.png' alt='"._("department")."'> ".sprintf($linkopen,base64_encode($key),$app),
555 "attach"=>"style='border:0px;'")
556 ));
557 }
559 foreach($apps as $key => $app){
560 $div->AddEntry(array(
561 array("string"=>sprintf("<input class='center' type='checkbox' value='1' name='AddApp_%s'>",$key).
562 "<img class='center' src='images/select_application.png' alt='"._("application")."'> ".sprintf($linkadd,$key,$app),
563 "attach"=>"style='border:0px;'")
564 ));
565 }
567 if((isset($_GET['act']))&&(($_GET['act'] == "cat_up")||($_GET['act']=="cat_down"))){
568 if($_GET['act']=="cat_up"){
569 $this->catUp(base64_decode($_GET['id']));
570 }
571 if($_GET['act']=="cat_down"){
572 $this->catDown(base64_decode($_GET['id']));
573 }
574 }
576 if((isset($_GET['act']))&&(($_GET['act'] == "one_up")||($_GET['act']=="one_down"))){
577 if(isset($_GET['id'])){
578 $id = $_GET['id'];
579 $act = $_GET['act'];
581 if($act == "one_up"){
582 $this->getOneUp($id);
583 }elseif($act == "one_down") {
584 $this->getOneDown($id);
585 }
586 }
587 }
589 $div2 = new DivSelectBox("appgroup");
590 $div2->SetHeight(400);
592 $linkopen = "<img class='center' src='images/folder.png' alt=\"\"> <a href='?plug=".$_GET['plug']."&act=open&id=%s'>%s</a>";
593 $catremove = " <input type='image' src='images/edittrash.png' title='"._("Delete entry")."' name='DelCat_%s' value='%s'>";
594 $app = "<img class='center' src='images/select_application.png' alt=\"\"> %s";
596 $catupdown = "<a href='?plug=".$_GET['plug']."&act=cat_up&id=%s'>
597 <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'>
598 <img alt=\"\" src='images/sort_down.png' title='"._("Move down")."' border=0></a>";
600 if(empty($this->curCatDir)){
601 $cnt =0;
602 }else{
603 $cnt = count(split("/",$this->curCatDir));
604 $tmp = split("/",$this->curCatDir);
605 $bbk = "";
606 for($i = 0 ; $i < ($cnt -1 ) ; $i++){
607 $bbk .= $tmp[$i];
608 }
609 $div2 ->AddEntry(array(array("string"=>sprintf($linkopen,base64_encode($bbk),"..")),array("string"=>" ","attach"=>"style='border-right:0px;'")));
610 }
612 $this->GetSubdirs($this->curCatDir);
614 foreach($this->GetSubdirs($this->curCatDir) as $path => $name){
615 $div2 ->AddEntry(array(
616 array("string"=>sprintf($linkopen,base64_encode($path),$name)),
617 array("string"=>preg_replace("/%s/",base64_encode($path),$catupdown.$catremove),
618 "attach"=>"align='right' style='width:80px;border-right:0px;'")));
619 }
621 /* Append entries */
623 $separator ="<hr size=1>";
625 $sep = "<input type='image' src='images/back.png' title='"._("Insert seperator")."' value='%s' name='AddSep_%s'>";
627 $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>".
628 " <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>".
629 " <input type='image' src='images/edittrash.png' title='"._("Delete entry")."' name='DelApp_%s' value='%s' alt='{t}delete{/t}' >";
630 $edit= " <input type='image' src='images/edit.png' title='"._("Edit entry")."' name='EdiApp_%s' value='%s' alt='{t}edit{/t}' >";
632 if(isset($this->gosaMemberApplication[$this->curCatDir])){
633 foreach($this->gosaMemberApplication[$this->curCatDir] as $cat => $entry){
634 if(preg_match("/__SEPARATOR__/",$entry['App'])){
635 $div2 ->AddEntry(array(array("string"=>$separator),
636 array("string"=>preg_replace("/\%s/",htmlentities($entry['App']),$upudown),"attach"=>"align='right' style='border-right:0px;'")));
637 }else{
638 $div2 ->AddEntry(array(array("string"=>sprintf($app,$entry['App'])),
639 array("string"=>preg_replace("/\%s/",htmlentities($entry['App']),$sep.$edit.$upudown),"attach"=>"align='right' style='border-right:0px;'")));
640 }
641 }
642 }
644 $smarty->assign("UsedApps", $div2->DrawList());
645 $smarty->assign("List", $div->DrawList());
646 $smarty->assign("apps", $apps);
648 $smarty->assign("enableReleaseManagement",$this->enableReleaseManagement);
650 if($this->enableReleaseManagement){
651 $smarty->assign("Release", $this->Release);
653 $tmp = $this->getReleases();
655 $smarty->assign("Releases", $tmp);
657 if(count($this->used_apps)){
658 $smarty->assign("ReleaseSelectAble", false);
659 }else{
660 $smarty->assign("ReleaseSelectAble", true);
661 }
662 }
664 /* Show main page */
665 if ($this->dialog){
666 $smarty->assign("table", $this->table);
667 $display.= $smarty->fetch (get_template_path('application_options.tpl', TRUE));
668 } else {
669 $display.= $smarty->fetch (get_template_path('application.tpl', TRUE));
670 }
671 return ($display);
672 }
674 function getReleases()
675 {
677 if(isset($this->base)){
678 $base = $this->base;
679 }else{
680 $base = $this->parent->by_object['group']->base;
681 }
683 $dn = "ou=apps,".$base;
684 $ret = array();
686 $ret ["ou=apps,".$base] = "/";
688 $ldap = $this->config->get_ldap_link();
689 $ldap->cd($dn);
691 $ldap->search("objectClass=organizationalUnit",array("ou"));
693 while($attrs = $ldap->fetch()){
694 $str = str_replace($dn,"",$attrs['dn']);
695 $tmp = array_reverse( split("ou=",$str));
696 $str = "";
697 foreach($tmp as $val){
698 $val = trim(preg_replace("/,/","",$val));
699 if(empty($val)) break;
700 $str .= "/".$val;
701 }
702 if(!empty($str)){
703 $ret[$attrs['dn']]= preg_replace("/^\//","",$str);
704 }
705 }
706 return($ret);
707 }
709 function save_object()
710 {
711 if(isset($_POST ['Release'])){
712 $this->Release = $_POST['Release'];
713 }
714 }
717 function remove_from_parent()
718 {
719 plugin::remove_from_parent();
721 $this->attrs["gosaMemberApplication"]= array();
723 $ldap= $this->config->get_ldap_link();
724 $ldap->cd($this->dn);
725 $this->cleanup();
726 $ldap->modify ($this->attrs);
728 show_ldap_error($ldap->get_error());
730 /* Optionally execute a command after we're done */
731 $this->handle_post_events("remove");
732 }
735 /* Save to LDAP */
736 function save()
737 {
738 plugin::save();
740 /* Copy members */
741 $this->Categories[""]="";
742 $this->attrs["gosaMemberApplication"]= array();
743 foreach($this->Categories as $name => $cats){
744 $i =0;
745 if(isset($this->gosaMemberApplication[$name])){
746 foreach($this->gosaMemberApplication[$name] as $entry){
747 if(!preg_match("/__SEPARATOR__/",$entry['App'])){
748 $this->attrs["gosaMemberApplication"][]= $entry['App']."|".$name."|".$i;
749 }
750 $i ++;
751 }
752 }
753 if(($i==0)&&(!empty($name))){
754 $this->attrs["gosaMemberApplication"][]= "|".$name."|".$i;
755 }
756 }
758 /* Are there application parameters to be saved */
759 $this->attrs['gosaApplicationParameter']= array();
760 foreach($this->appoption as $name => $value){
761 if ($value != ""){
762 $this->attrs['gosaApplicationParameter'][]= "$name:$value";
763 }
764 }
766 /* Write back to LDAP */
767 $ldap= $this->config->get_ldap_link();
768 $ldap->cd($this->dn);
769 $this->cleanup();
770 $ldap->modify ($this->attrs);
772 show_ldap_error($ldap->get_error());
774 /* Optionally execute a command after we're done */
775 if ($this->initially_was_account == $this->is_account){
776 if ($this->is_modified){
777 $this->handle_post_events("mofify");
778 }
779 } else {
780 $this->handle_post_events("add");
781 }
783 }
785 function check()
786 {
787 /* Call common method to give check the hook */
788 $message= plugin::check();
790 return ($message);
791 }
794 function reload()
795 {
796 /* Generate applist */
797 $this->apps= array();
799 /* Special handling for release managed apps
800 */
801 $tmp = search_config($this->config->data,"faiManagement","CLASS");
802 if(!empty($tmp)){
803 $this->enableReleaseManagement = true;
805 $tmp = array_flip($this->getReleases());
806 if(isset($tmp[$this->Release])){
807 $base = $tmp[$this->Release];
808 }else{
810 $k = key($tmp);
811 $r = $tmp[$k];
813 print_red(sprintf(_("Can't resolve the release name '%s', setting release name to '%s'. "),$this->Release,$k));
814 $this->Release = $k;
815 $base = $r;
816 }
818 $base = preg_replace("/ou=apps,.*$/","ou=apps,".$this->curbase,$base);
820 $ldap = $this->config->get_ldap_link();
821 $ldap->cd ($base);
822 $ldap->ls ("(objectClass=gosaApplication)",$base);
823 }else{
824 $ldap = $this->config->get_ldap_link();
825 $ldap->cd ("ou=apps,".$this->curbase);
826 $ldap->ls ("(objectClass=gosaApplication)","ou=apps,".$this->curbase);
827 }
829 while ($attrs= $ldap->fetch()){
830 if (isset($attrs["description"][0])){
831 $this->apps[$attrs["cn"][0]]=
832 $attrs["cn"][0]." (".
833 $attrs["description"][0].")";
834 } else {
835 $this->apps[$attrs["cn"][0]]=
836 $attrs["cn"][0];
837 }
838 }
839 natcasesort ($this->apps);
840 reset ($this->apps);
842 if(is_array($this->gosaMemberApplication))
843 foreach ($this->gosaMemberApplication as $cat){
844 if(is_array($cat))
845 foreach($cat as $entry){
846 $this->used_apps[$entry['App']]= $entry['App'];
847 }
848 }
849 }
852 function addApp($cn)
853 {
854 if((isset($this->gosaMemberApplication[$this->curCatDir]))&&(is_array($this->gosaMemberApplication[$this->curCatDir]))){
855 foreach($this->gosaMemberApplication[$this->curCatDir] as $entry){
856 if($entry['App'] == $cn) return;
857 }
858 }
859 $this->gosaMemberApplication[$this->curCatDir][]= array("App"=>$cn);
860 $this->used_apps[$cn]=$cn;
861 $this->is_modified= TRUE;
862 }
865 function removeApp($cn)
866 {
867 $temp= array();
868 foreach ($this->gosaMemberApplication as $value){
869 if ($value != $cn){
870 $temp[]= $value;
871 }
872 }
873 $this->gosaMemberApplication= $temp;
874 $this->is_modified= TRUE;
875 }
877 function GetSubdirs($dir)
878 {
879 $ret = array();
880 $tmp1 = split("/",$this->curCatDir);
882 foreach($this->Categories as $path=>$cat){
883 $tmp2 = split("/",$path);
885 if((empty($this->curCatDir))&&(!preg_match("/\//",$path))){
886 $abort = false;
887 }elseif(((count($tmp1))+1) == (count($tmp2))){
888 $abort = false;
889 for($i = 0 ; $i < count($tmp1) ; $i++){
890 if($tmp1[$i] != $tmp2[$i]){
891 $abort = true;
892 }
893 }
894 }else{
895 $abort= true;
896 }
897 if(!$abort){
898 $ret[$path]=$cat;
899 }
900 }
901 return($ret);
902 }
905 /* Get selected release name.
906 * it is written in the description tag
907 * within ... (.*)$
908 */
909 function getReleaseName()
910 {
912 if(isset($this->parent)){
913 $base = $this->parent->by_object['group'];
914 }else{
915 $base = $this;
916 }
918 if(isset($base->attrs['description'][0])){
919 $desc = $base->attrs['description'][0];
920 }else{
921 $desc = "";
922 }
924 if(preg_match("/\(.*\)$/",$desc)){
925 $str = preg_replace("/^.*\((.*)\)$/","\\1",$desc);
926 }else{
927 $str = "/";
928 }
929 return($str);
930 }
931 }
933 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
934 ?>