Code

087a0ef86a2826aae3a64feb275672e1620c08e1
[gosa.git] / plugins / admin / groups / class_groupApplication.inc
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)){
68     
69         $tmp = split("\|",$memberApp);
70  
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;
98             
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'];
117     
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   }
209   
210   function catDown($id)
211   {
212    /* Get all cats depinding on current dir */
213     $cats = $this->GetSubdirs($this->curCatDir);
214      
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     }
235  
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   } 
265    
266   
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\">&nbsp;<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 */ 
328   
329     
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){
349       
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;
359    
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       }
380   
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       }
395       
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']."&amp;act=depopen&amp;depid=%s'>%s</a>";
545     $linkadd  = "<a href='?plug=".$_GET['plug']."&amp;act=add&amp;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")."'>&nbsp;".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")."'>&nbsp;".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=\"\">&nbsp;<a href='?plug=".$_GET['plug']."&amp;act=open&amp;id=%s'>%s</a>";
595     $catremove      = "&nbsp;<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=\"\">&nbsp;%s";
597     
598     $catupdown        = "<a href='?plug=".$_GET['plug']."&amp;act=cat_up&amp;id=%s'>
599                        <img align='top' alt=\"\" src='images/sort_up.png' border=0 title='"._("Move up")."'></a>&nbsp;<a href='?plug=".$_GET['plug']."&amp;act=cat_down&amp;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"=>"&nbsp;","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'>";
628   
629     $upudown ="<a href='?plug=".$_GET['plug']."&amp;act=one_up&amp;id=%s'>   <img alt='{t}sort{/t}' align='top' src='images/sort_up.png' title='"._("Move up")."' border=0></a>".
630       "&nbsp;<a href='?plug=".$_GET['plug']."&amp;act=one_down&amp;id=%s'> <img alt='{t}sort{/t}' src='images/sort_down.png' title='"._("Move down")."' border=0></a>".
631       "&nbsp;<input type='image' src='images/edittrash.png' title='"._("Delete entry")."' name='DelApp_%s' value='%s' alt='{t}delete{/t}' >";
632     $edit=      "&nbsp;<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){
637         
639         if(preg_match("/__SEPARATOR__/",$entry['App'])){
640           $div2 ->AddEntry(array(array("string"=>$separator),
641                 array("string"=>preg_replace("/\%s/",htmlentities($entry['App']),$upudown),"attach"=>"align='right' style='border-right:0px;'")));
642         }else{
644           $broken = "";
645           if(!in_array($entry['App'],$this->AllAppsForRelease)){
646             if(!$this->enableReleaseManagement){
647               $broken = "<img src='images/false.png' title='"._("This application is no longer available.")."'>&nbsp;";
648             }else{
649               $broken = "<img src='images/false.png' title='".sprintf(_("This application is not available in any release named %s."),$this->Release)."'>&nbsp;";
650             }
651           }
652           
653           $div2 ->AddEntry(array(array("string"=>sprintf($app,$entry['App'])),
654                                  array("string"=>$broken,"attach"=>"style='width:28px;'"),
655                 array("string"=>preg_replace("/\%s/",htmlentities($entry['App']),$sep.$edit.$upudown),"attach"=>"align='right' style='width:100px;border-right:0px;'")));
656         }
657       }
658     }
660     $smarty->assign("UsedApps", $div2->DrawList());
661     $smarty->assign("List", $div->DrawList());
662     $smarty->assign("apps", $apps);
663    
664     $smarty->assign("enableReleaseManagement",$this->enableReleaseManagement);
665  
666     if($this->enableReleaseManagement){
667       $smarty->assign("Release",  $this->Release);
668       $smarty->assign("Releases", $this->Releases);
670       if(count($this->used_apps)){
671         $smarty->assign("ReleaseSelectAble", false);
672       }else{
673         $smarty->assign("ReleaseSelectAble", true);
674       }
675     }
676         $smarty->assign("ReleaseSelectAble", true);
678     /* Show main page */
679     if ($this->dialog){
680       $smarty->assign("table", $this->table);
681       $display.= $smarty->fetch (get_template_path('application_options.tpl', TRUE));
682     } else {
683       $display.= $smarty->fetch (get_template_path('application.tpl', TRUE));
684     }
685     return ($display);
686   }
689   function getReleases()
690   {
691     $dn   = "ou=apps,".$this->config->current['BASE'];
692     $ldap = $this->config->get_ldap_link();
693     $ldap->cd($dn);
694     $ldap->search("objectClass=organizationalUnit",array("ou"));
695     $ret =array();
696     while($attrs = $ldap->fetch()){
697       if(preg_match("/ou=apps,/",$attrs['dn'])){
698         $bb = preg_replace("/ou=apps,.*/","",$attrs['dn']);
699         $parts = array_reverse(split("ou=",$bb));
701         $str ="";
702         foreach($parts as $part){
703           if(empty($part)) {
704             continue;
705           }
706           $str .= str_replace(",","",$part)."/";
707         }    
708         $name = preg_replace("/\/$/","",$str);
709         if(empty($name)) {
710           $name ="/";
711         }
712         $ret[$attrs['dn']] = $name;
713       }
714     }
715     return($ret);
716   }
718   function save_object()
719   {
720     if(isset($_POST ['Release'])){
721       $this->Release = $_POST['Release'];
722     }
723   }
724  
726   function remove_from_parent()
727   {
728     plugin::remove_from_parent();
730     $this->attrs["gosaMemberApplication"]= array();
732     $ldap= $this->config->get_ldap_link();
733     $ldap->cd($this->dn);
734     $this->cleanup();
735 $ldap->modify ($this->attrs); 
737     show_ldap_error($ldap->get_error());
739     /* Optionally execute a command after we're done */
740     $this->handle_post_events("remove");
741   }
744   /* Save to LDAP */
745   function save()
746   {
747     plugin::save();
749     /* Copy members */
750     $this->Categories[""]=""; 
751     $this->attrs["gosaMemberApplication"]= array();
752     foreach($this->Categories as $name => $cats){
753       $i =0;
754       if(isset($this->gosaMemberApplication[$name])){
755         foreach($this->gosaMemberApplication[$name] as $entry){
756           if(!preg_match("/__SEPARATOR__/",$entry['App'])){
757             $this->attrs["gosaMemberApplication"][]= $entry['App']."|".$name."|".$i;
758           }
759           $i ++;
760         }
761       }
762       if(($i==0)&&(!empty($name))){
763         $this->attrs["gosaMemberApplication"][]= "|".$name."|".$i;
764       }
765     }
767     /* Are there application parameters to be saved */
768     $this->attrs['gosaApplicationParameter']= array();
769     foreach($this->appoption as $name => $value){
770       if ($value != ""){
771         $this->attrs['gosaApplicationParameter'][]= "$name:$value";
772       }
773     }
775     /* Write back to LDAP */
776     $ldap= $this->config->get_ldap_link();
777     $ldap->cd($this->dn);
778     $this->cleanup();
779 $ldap->modify ($this->attrs); 
781     show_ldap_error($ldap->get_error());
783     /* Optionally execute a command after we're done */
784     if ($this->initially_was_account == $this->is_account){
785       if ($this->is_modified){
786         $this->handle_post_events("mofify");
787       }
788     } else {
789       $this->handle_post_events("add");
790     }
792   }
794   function check()
795   {
796     /* Call common method to give check the hook */
797     $message= plugin::check();
799     return ($message);
800   }
803   function reload()
804   {
805     /* Generate applist */
806     $this->apps= array();
808     /* Special handling for release managed apps 
809      */
810     $tmp = search_config($this->config->data,"faiManagement","CLASS");
811     if(!empty($tmp)){
812       $this->enableReleaseManagement = true;
814       $tmp = array_flip($this->Releases);
815       if(isset($tmp[$this->Release])){
816         $base =  $tmp[$this->Release];
817       }else{
818         $k = key($tmp);
819         $r = $tmp[$k];
820         $this->Release = $k;
821         $base = $r; 
822     
823         print_red(sprintf(_("Can't resolve the release name '%s', setting release name to '%s'. Possibly the objects base has changed."),$this->Release,$k));
824       }
826       $base = preg_replace("/ou=apps,.*$/","ou=apps,".$this->curbase,$base);
827     
828       $ldap   = $this->config->get_ldap_link();
829       $ldap->cd ($base);
830       $ldap->ls ("(objectClass=gosaApplication)",$base);
831     }else{
832       $ldap   = $this->config->get_ldap_link();
833       $ldap->cd ("ou=apps,".$this->curbase);
834       $ldap->ls ("(objectClass=gosaApplication)","ou=apps,".$this->curbase);
835     }
836     
837     while ($attrs= $ldap->fetch()){
838       if (isset($attrs["description"][0])){    
839         $this->apps[$attrs["cn"][0]]=
840           $attrs["cn"][0]." (".
841           $attrs["description"][0].")";
842       } else {
843         $this->apps[$attrs["cn"][0]]=
844           $attrs["cn"][0];
845       }
846     }
848     $ldap->cd($this->config->current['BASE']);
849     $ldap->search("objectClass=gosaApplication",array("cn"));
850     $tmp = search_config($this->config->data,"faiManagement","CLASS");
851     $this->AllAppsForRelease = array();
852     if(!empty($tmp)){
854       $tmp = array_flip($this->Releases);
856       while($attrs = $ldap->fetch()){
857         $testdn = preg_replace("/ou=apps,.*$/","ou=apps",$attrs['dn']);
858         $testdn = preg_replace("/^[^,]+/","",$testdn);
859         $testdn = preg_replace("/^,/","",$testdn);
861         if($testdn == preg_replace("/ou=apps,.*$/","ou=apps",$tmp[$this->Release])){
862           $this->AllAppsForRelease[$attrs['dn']] = $attrs['cn'][0];
863         }
864       }
865     }else{
866       while($attrs = $ldap->fetch()){
867         $this->AllAppsForRelease[$attrs['dn']] = $attrs['cn'][0];
868       }
869     }
871     natcasesort ($this->apps);
872     reset ($this->apps);
874     if(is_array($this->gosaMemberApplication))
875       foreach ($this->gosaMemberApplication as $cat){   
876         if(is_array($cat))
877           foreach($cat as $entry){
878             $this->used_apps[$entry['App']]= $entry['App'];
879           }
880       }
881   }
884   function addApp($cn)
885   {
886     if((isset($this->gosaMemberApplication[$this->curCatDir]))&&(is_array($this->gosaMemberApplication[$this->curCatDir]))){
887       foreach($this->gosaMemberApplication[$this->curCatDir] as $entry){
888         if($entry['App'] == $cn) return;
889       }
890     }
891     $this->gosaMemberApplication[$this->curCatDir][]= array("App"=>$cn);
892     $this->used_apps[$cn]=$cn;
893     $this->is_modified= TRUE;
894   }
897   function removeApp($cn)
898   {
899     $temp= array();
900     foreach ($this->gosaMemberApplication as $value){
901       if ($value != $cn){
902         $temp[]= $value;
903       }
904     }
905     $this->gosaMemberApplication= $temp;
906     $this->is_modified= TRUE;
907   }
909   function GetSubdirs($dir)
910   {
911     $ret = array();
912     $tmp1 = split("/",$this->curCatDir);
913  
914     foreach($this->Categories as $path=>$cat){
915       $tmp2 = split("/",$path);
916       
917       if((empty($this->curCatDir))&&(!preg_match("/\//",$path))){
918         $abort = false;
919       }elseif(((count($tmp1))+1) == (count($tmp2))){
920         $abort = false;
921         for($i = 0 ; $i < count($tmp1) ; $i++){
922           if($tmp1[$i] != $tmp2[$i]){
923             $abort = true;
924           }
925         }
926       }else{
927         $abort= true;
928       }
929       if(!$abort){
930         $ret[$path]=$cat;
931       } 
932     }
933   return($ret);
934   }
937   /* Get selected release name.
938    *  it is written in the description tag 
939    *  within ... (.*)$
940    */
941   function getReleaseName()
942   {
943   
944     if(isset($this->parent)){
945       $base = $this->parent->by_object['group'];
946     }else{
947       $base = $this;
948     }
950     if(isset($base->attrs['description'][0])){
951       $desc = $base->attrs['description'][0];
952     }else{
953       $desc = "";
954     }
955  
956     if(preg_match("/\(.*\)$/",$desc)){
957       $str = preg_replace("/^.*\((.*)\)$/","\\1",$desc);
958     }else{
959       $str = "/";
960     }
961     return($str);  
962   }
965 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
966 ?>