Code

finished jobs are set to 'done' and deleted from job queue
[gosa.git] / gosa-core / include / class_MultiSelectWindow.inc
1 <?php
2 /*
3  * This code is part of GOsa (http://www.gosa-project.org)
4  * Copyright (C) 2003-2008 GONICUS GmbH
5  *
6  * ID: $$Id$$
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
23 define ("SEPERATOR", 1002);
25 class MultiSelectWindow{
27         var $bool_DisplayAlpahabet      = false;
28         var $bool_DisplayCloseButton= true;     
29         var $bool_DisplaySaveButton = true;     
31         var $SaveButtonString           = "";
32         var $CloseButtonString  = "";
34         var $string_Title                         = "";
35         var $string_ListHeader  = "";
36   var $string_ListDropDown= "";
37         var $string_Summary                     = "";
38         var $string_Information = "";
40         var $array_Header                         = array();
41         var $array_Elements                     = array();      
42         var $array_Checkboxes           = array();      
43         var $array_Regexes                      = array();      
45         var $config                                         = array("");
46         var $is_closed                            = false;
47         var $is_saved                               = false;
48         var $is_headpage                          = false;      // if true the design changes
49         var $filterName                           = "Liste";
50         var $DepartmentsAdded           = false;
51   var $Added_Departments  = array();
52         var $selectedBase       = "";
54   var $DivHeight          = "";
56   var $HideFilterPart     = false;
57   var $List_Bottom_Info   = "";
58   var $SaveAdditionalVars = array();  // Additional Post vars to store 
59   var $module= "";
61   var $IgnoreAccount = TRUE;
63         function ClearElementsList()
64         {
65                 $this->array_Elements = array();
66         }
68   function HideFilterPart($bool = true)
69   {
70     $this->HideFilterPart = $bool;
71   }
73   function SetHeight($height)
74   { 
75     $this->DivHeight=$height;
76   }
78         /* Adds a regex input field to the current dialog */
79         function AddRegex($name,$string,$value,$conn,$image="images/search.png")
80         {
81                 $arr = array();
83                 /* Check if the given input field name was already used 
84                    for this type of dialog */   
85     $MultiDialogFilters = session::get('MultiDialogFilters');
86                 if(isset($MultiDialogFilters[$this->filterName][$name])){
87                         $arr['value']   = $MultiDialogFilters[$this->filterName][$name];
88                         $this->$name = $arr['value'];
89                 }else{
90                         $arr['value']   = $value;       
91                 }
93                 $arr['name']            = $name;
94                 $arr['string']          = $string;
95                 $arr['image']           = $image;       
96                 $arr['connAlpha']       = $conn;                // Connect with alphabet select 
97                 $this->array_Regexes[] = $arr;
98         }
101   function SetDropDownHeaderMenu($str)
102   {
103     $this->string_ListDropDown = $str;
104   }
106   function GetDropDownHeaderMenu()
107   {
108     if(!empty($this->string_ListDropDown)){
109       $mid = new LayersMenu(6, 7, 2, 1);
110       $mid->setImgwww("./images/");
111       $mid->setIcondir("./images/");
112       $mid->setDirroot("../include/utils/layer-menu/");
113       $mid->setHorizontalMenuTpl("../ihtml/".get_template_path("",FALSE).'GOsa_MultiSelectHeader.ihtml');
114       $mid->setSubMenuTpl("../ihtml/".get_template_path("",FALSE).'GOsa_MultiSelectHeaderSubEntry.ihtml');
115       $mid->setMenuStructureString($this->string_ListDropDown);
116       $mid->parseStructureForMenu('menu');
117       $mid->newHorizontalMenu('menu');
118       $s = $mid->getHeader();
119       $s.= $mid->getMenu('menu');
120       $s.= $mid->getFooter('menu');
121       return($s);
122     }else{
123       return("");
124     }
125   }
128         /* Contrucktion */
129         function MultiSelectWindow(&$config, $filterName, $module)
130         {
131                 $this->config = &$config;
132                 $this->module = $module;
133                 $this->SaveButtonString         = _("Save");
134                 $this->CloseButtonString        = _("Close");
135                 $this->filterName                       = $filterName;
136     $this->ui = get_userinfo();
137                 $this->selectedBase  = session::get('CurrentMainBase');
139     /* Check default values for SaveAdditionalVars */
140     $MultiDialogFilters = session::get('MultiDialogFilters');
141     foreach($this->SaveAdditionalVars as $name){
142       if(isset($MultiDialogFilters[$this->filterName][$name])){
143         $this->$name = $MultiDialogFilters[$this->filterName][$name];
144       }
145     }
146     
147         }
149         /* Enables the headpage mode, which changes the list look */
150         function SetHeadpageMode()
151         {
152                 $this->is_headpage = true;
153         }
155         /* Sets the List internal name (not displayed anywhere) 
156            it is used to identify every single list
157          */     
158         function SetTitle($str)
159         {
160                 $this->string_Title = $str;
161         }
163         /* Set the list header string  */
164         function SetListHeader($str)
165         {
166                 $this->string_ListHeader = $str;
167         }
169         /* This sets the list description which is the first gray bar on top of the list */
170         function SetSummary($str)
171         {
172                 $this->string_Summary = $str;
173         }
175         /* If the save button is enabled, you can change its caption with this function */      
176         function SetSaveButtonString($str)
177         {
178                 $this->SaveButtonString = $str;
179         }
181         /* If the close button is enabled, you can change its caption with this function */     
182         function SetCloseButtonString($str)
183         {
184                 $this->CloseButtonString = $str;
185         }
187         /* With this function you can change the text of the information box */
188         function SetInformation($str)
189         {
190                 $this->string_Information = $str;
191         }
193         /* Display the alphabet selection box*/
194         function EnableAplhabet($bool)
195         {
196                 $this->bool_DisplayAlpahabet = $bool;
197         }
199         /* Add additional header col */
200         function AddHeader($arr)
201         {
202                 $this->array_Header[] = $arr;
203         }
205         /* add additional List element */
206         function AddElement($arr)
207         {
208                 $this->array_Elements[] = $arr;
209         }
212   /* Return default header part. With back, home and root icons and department selection */
213   function get_default_header()
214   {
215     $enable_back = TRUE;
216     $enable_root = TRUE;
217     $enable_home = TRUE;
219     $ui = get_userinfo();
221     /* Check if selectedBase = first available base */
222     $deps = $ui->get_module_departments($this->module);
224     if(!count($deps) || $deps[0] == $this->selectedBase){
225       $enable_back = FALSE;
226       $enable_root = FALSE;
227     }
228   
229     $listhead ="";
230  
231     /* Check if we are in users home  department */ 
232     if(!count($deps) ||$this->selectedBase == get_base_from_people($ui->dn)){
233       $enable_home = FALSE;
234     }
236     /* Draw root button */
237     if($enable_root){
238       $listhead .= " <input class='center' type='image' src='images/list_root.png' align='middle'
239         title='"._("Go to root department")."' name='dep_root' alt='"._("Root")."'>&nbsp;";
240     }else{
241       $listhead .= " <img src='images/list_root_gray.png' class='center' alt='"._("Root")."'>&nbsp;";
242     }
244     /* Draw back button */
245     if($enable_back){
246       $listhead .= " <input class='center' type='image' align='middle' src='images/list_back.png'
247         title='"._("Go up one department")."' alt='"._("Up")."'                name='dep_back'>&nbsp;";
248     }else{
249       $listhead .= " <img src='images/list_back_gray.png' class='center' alt='"._("Up")."'>&nbsp;";
250     }
252     /* Draw home button */
253     if($enable_home){
254       $listhead .= " <input class='center' type='image' align='middle' src='images/list_home.png'
255         title='"._("Go to users department")."' alt='"._("Home")."'            name='dep_home'>&nbsp;";
256     }else{
257       $listhead .= " <img src='images/list_home_gray.png' class='center' alt='"._("Home")."'>&nbsp;";
258     }
259    
260     /* And at least draw reload button, this button is enabled everytime */ 
261     $listhead .=  " <input class='center' type='image' src='images/list_reload.png' align='middle'
262       title='"._("Reload list")."' name='submit_department' alt='"._("Submit")."'>&nbsp;".
263       " <img   class='center' src='images/list_seperator.png' align='middle' alt='-' height='16' width='1'>&nbsp;";
265     return ($listhead);
266   }
268         /* Add a checkbox to the filter element,
269            the name specifies an existing class var to store the 'selection' */
270         function AddCheckBox($name,$value="Unset",$string="Unset",$default=false)
271         {
272                 $arr = array();
274                 if($name == SEPERATOR){
275                         $arr['name'] = SEPERATOR;
276                 }else{
277                         /* Check if there was already a variable 
278                            for this dialog which we should use instead of the default*/
279       $MultiDialogFilters = session::get('MultiDialogFilters');
280                         if(isset($MultiDialogFilters[$this->filterName][$name])){
281                                 $arr['default'] = $MultiDialogFilters[$this->filterName][$name];
282                                 $this->$name = $arr['default'];
283                         }else{
284                                 $arr['default'] = $default; 
285         $this->$name = $default;
286                         }
287                         $arr['name']          = $name;
288                         $arr['string']      = $string;
289                         $arr['value']         = $value;
290                         $arr['enabled']     = true;
292                 }
293                 $this->array_Checkboxes[] = $arr;
294         }
297         /* Hides or unhides the checkbox with the given name */
298         function DisableCheckBox($name,$HideShow = false)
299         {
300                 foreach($this->array_Checkboxes as $key => $chkbox){
301                         if($chkbox['name'] == $name){
302                                 $this->array_Checkboxes[$key]['enabled'] = $HideShow;
303                         }
304                 }
305         }
308         /* Returns true if the close button was pressed */
309         function isClosed()
310         {
311                 return($this->is_closed);
312         }
314         /* Enable the close button */
315         function EnableCloseButton($bool)
316         {
317                 $this->bool_DisplayCloseButton = $bool;
318         }
320         /* Enable the save button on the bottom of the list*/
321         function EnableSaveButton ($bool)
322         {
323                 $this->bool_DisplaySaveButton = $bool;
324         }
326   /* Add a list specific filter object to position 
327       1 on top of Information 
328       2 Between Information && Filter
329       3 Below the Filter Part */
330   function AddUserBoxToFilter($position)
331   {
332     return("");
333   }
335   function EnableJSLeaveMsg($ignore = TRUE)
336   {
337     $this->IgnoreAccount = !$ignore;
338   }
340         /* Draw the list with all list elements and filters */
341         function Draw()
342         {
344                 /* Check for exeeded sizelimit */
345                 if (($message= check_sizelimit()) != ""){
346                         return($message);
347                 }
349                 $smarty = get_smarty();
350                 $smarty->assign("UserBox1",$this->AddUserBoxToFilter(1));
351                 $smarty->assign("UserBox2",$this->AddUserBoxToFilter(2));
352                 $smarty->assign("UserBox3",$this->AddUserBoxToFilter(3));
354                 $divlist = new divlist($this->string_Title);
355                 $divlist->SetSummary($this->string_Summary);
356                 $divlist->SetEntriesPerPage(0); // 0 for scrollable list
358     /* Display list footer with summary of all listed entries */
359     if(isset($this->config->data['MAIN']['LIST_SUMMARY']) && preg_match("/true/i",$this->config->data['MAIN']['LIST_SUMMARY'])){
360       $divlist->SetFooter($this->get_List_Bottom_Info());
361     }
362   
363     if($this->DivHeight != ""){
364       $divlist->SetHeight($this->DivHeight);
365     }
367                 /* set Header informations 
368                  */
369                 $header = array();
370                 foreach($this->array_Header as $head){
371                         $header[] = $head;
372                 }
373                 $divlist->SetHeader($header);
375                 /* set Entries 
376                  */
377                 $elements = array();
378                 foreach($this->array_Elements as $element){
379                         $divlist->AddEntry($element);
380                 }
382                 /* Create checkboxes fields 
383                  */
384                 $boxes = "";
385                 $boxClick = " onClick='document.mainform.submit();' ";
386                 foreach($this->array_Checkboxes as $box){
388                         if($box['name'] == SEPERATOR){
389                                 $boxes .= "</td></tr></table><table style='width:100%;border-top:1px solid #B0B0B0;'><tr><td>";
390                                 continue;
391                         }
393                         /* Skip disabled boxes */
394                         if(!$box['enabled']) continue;
396                         /* Check if box is checked */
397                         if($box['default'] == true){
398                                 $boxes .="<input type='checkbox' name=\"".$box['name']."\" value='1' title=\"".htmlentities($box['value'])."\" checked ".$boxClick.">&nbsp;".$box['string']."<br>";
399                         }else{
400                                 $boxes .="<input type='checkbox' name=\"".$box['name']."\" value='1' title=\"".htmlentities($box['value'])."\" ".$boxClick.">&nbsp;".$box['string']."<br>";
401                         }
402                 }
403                 $smarty->assign("CheckBoxes", $boxes);
405                 /* Assign regex fields 
406                  */
407                 $regexes = "";
408                 foreach($this->array_Regexes as $regex){
409                         $regexes.="<table summary=\"\" style=\"width:100%;border-top:1px solid #B0B0B0;\">
410                                 <tr>
411                                 <td>
412                                 <label for=\"".$regex['name']."\">
413                                 <img alt=\"".$regex['string']."\" src=\"".$regex['image']."\" align=middle>
414                                 </label>
415                                 </td>
416                                 <td width=\"99%\">
417                                 <input id=\"".$regex['name']."\" type=\"text\" style='width:99%' name=\"".$regex['name']."\" maxlength='20'
418                                 value=\"".htmlentities($regex['value'])."\" title=\"".htmlentities($regex['string'])."\"> 
419                                 </td>
420                                 </tr>
421                                 </table>";
422                 }
423                 $smarty->assign("regexes"                       , $regexes );
425     /* Hide Filter Part if Requested or empty */
426     if((empty($boxes)) && (empty($regexes)) || ($this->HideFilterPart)){
427                   $smarty->assign("Skip_Filter_Part",   true);
428     }else{ 
429                   $smarty->assign("Skip_Filter_Part",   false);
430     }
432                 /* Assign alphabet and display it 
433                  */     
434                 $smarty->assign("Display_alphabet",     $this->bool_DisplayAlpahabet);
435                 $smarty->assign("alphabet",             generate_alphabet());
436                 $smarty->assign("Header"                        , $this->string_ListHeader);
437                 $smarty->assign("HeaderDropDown", $this->GetDropDownHeaderMenu());
438                 $smarty->assign("Summary"                       , $this->string_Summary);
439                 $smarty->assign("Title"                         , $this->string_Title);
440                 $smarty->assign("Information"           , $this->string_Information);
441                 $smarty->assign("IgnoreAccount"         , $this->IgnoreAccount);
443                 /* Check for exeeded sizelimit */
444                 $smarty->assign("hint"                          , print_sizelimit_warning());
445                 $smarty->assign("DivList"                       , $divlist->DrawList());
448                 if($this->is_headpage){
449                         $smarty->assign("tree_image",           get_template_path('images/tree.png'));
450                         $smarty->assign("infoimage",            get_template_path('images/info.png'));
451                         $smarty->assign("launchimage",          get_template_path('images/launch.png'));
452                         $smarty->assign("apply",                        apply_filter());
453                 }else{
454                         $smarty->assign("tree_image",           get_template_path('images/tree.png'));
455                         $smarty->assign("infoimage",            get_template_path('images/info_small.png'));
456                         $smarty->assign("launchimage",          get_template_path('images/rocket.png'));
457                         $smarty->assign("apply",                        apply_filter());
458                 }
460                 /* Button handling */
461                 $smarty->assign("SaveButtonString" ,$this->SaveButtonString);
462                 $smarty->assign("CloseButtonString",$this->CloseButtonString);
464                 $smarty->assign("Display_Close",        $this->bool_DisplayCloseButton);
465                 $smarty->assign("Display_Save" ,        $this->bool_DisplaySaveButton);
467                 $smarty->assign("filterName"    ,       $this->filterName);
468                 $smarty->assign("is_headpage"   ,       $this->is_headpage);
470                 $display = $smarty->fetch(get_template_path("MultiSelectWindow.tpl"));
471                 return($display);
472         }
474         /* Set the close var, which simulates the close button is pressed */
475         function Close()
476         {
477                 $this->is_closed = true;
478         }
480         function Save()
481         {
482                 $this->is_saved = true;
483         }
485         /* Store all checkboxes/ regexes ... 
486            Store data also into a session var, to keep the checkboxes check after reload  */
487         function save_object()
488         {
489     /* Get up to date config */
490     if(isset($this->parent->config)){
491       $this->config = $this->parent->config;
492     }
494     /* Update current base */
495     $s_action ="";
496     foreach($_POST as $key => $value){
497       if(preg_match("/^dep_back.*/i",$key)){
498         $s_action="back";
499       }elseif(preg_match("/^dep_root.*/",$key)){
500         $s_action="root";
501       }elseif(preg_match("/^dep_home.*/i",$key)){
502         $s_action="home";
503       }
504     }
506     /* Save base selection from headpage selectbox*/
507     if(isset($_POST['CurrentMainBase'])){
508       $this->selectedBase = $_POST['CurrentMainBase'];
509     }
511     /* Homebutton is posted */
512     if($s_action=="home"){
513       $ui= get_userinfo();
514       $base = get_base_from_people($ui->dn);
515       $this->selectedBase= $base;
516     }
518     /* Open selected department
519        this is posted by the parent class MultiSelectWindow */
520     if(isset($_GET['act'])&& ($_GET['act'] == "dep_open")){
521       $s_entry = base64_decode($_GET['dep_id']);
522       if (!isset($this->config->departments[$s_entry])){
523         msg_dialog::display(_("LDAP error"), sprintf(_("Inconsistent DN encoding detected: '%s'"), LDAP::fix($s_entry)), ERROR_DIALOG);
524       } else {
525         $this->selectedBase = $this->config->departments[$s_entry];
526       }
527     }
529     /* back to the roots ^^ */
530     if($s_action=="root"){
531       $this->selectedBase=($this->config->current['BASE']);
532       $dep_id = $this->ui->get_module_departments($this->module);
533       if(isset($dep_id[key($dep_id)])){
534         $this->selectedBase = $dep_id[key($dep_id)];
535       }
536     }
539     /* If Back-button is pressed, move back one step in DN */
540     if($s_action=="back"){
542       /* Get parent deprtment and check if we are allowed to step in it */
543       $base_back= preg_replace("/^[^,]+,/", "", session::get('CurrentMainBase'));
544       $dep_id = $this->ui->get_module_departments($this->module);
545       if(in_array_ics($base_back,$dep_id)){
547         /* The department array keeps non DN entries as index. We need to convert
548            it before checking the existance. */
549         $base_back= trim(convert_department_dn($base_back));
551         /* Check if the department exists, otherwise revert to the configure base DN */
552         if(isset($this->config->departments[$base_back])){
553           $this->selectedBase= $this->config->departments[$base_back];
554         }else{
555           $this->selectedBase= $this->config->departments['/'];
556         }
557       }
558     }
559     session::set('CurrentMainBase',$this->selectedBase);
561                 if(isset($_POST['MultiSelectWindow'.$this->filterName])){
563       /* Save some additional vars */
564       $MultiDialogFilters = session::get('MultiDialogFilters');
565       foreach($this->SaveAdditionalVars as $name){
566         if(isset($_POST[$name])){
567           if(isset($this->$name)){
568             $this->$name = $_POST[$name];
569             $MultiDialogFilters[$this->filterName][$name] = $_POST[$name];
570           }
571         }
572       }
573       session::set('MultiDialogFilters',$MultiDialogFilters);
575                         /* Check posts from checkboxes 
576                          */
577                         foreach($this->array_Checkboxes as $key => $box){
578                                 if(isset($_POST[$box['name']])){
579                                         $this->array_Checkboxes[$key]['default'] = true;
580                                         $this->$box['name'] = true;
581                                 }else{
582                                         $this->array_Checkboxes[$key]['default'] = false;
583                                         $this->$box['name'] = false;
584                                 }
586                                 /* Save settings in out session */
587         $MultiDialogFilters = session::get('MultiDialogFilters');
588                                 $MultiDialogFilters[$this->filterName][$box['name']] = $this->$box['name'];
589         session::set('MultiDialogFilters',$MultiDialogFilters);
590                         }
592                         /* Check regex posts */
593                         foreach($this->array_Regexes as $key => $box){
594                                 $this->array_Regexes[$key]['value'] = $_POST[$box['name']];
595                                 $this->$box['name'] = $_POST[$box['name']];
596         $MultiDialogFilters = session::get('MultiDialogFilters');
597                                 $MultiDialogFilters[$this->filterName][$box['name']] = $this->$box['name'];
598         session::set('MultiDialogFilters',$MultiDialogFilters);
599                         }
601                         /* call close/save if buttons are pressed */
602                         if(isset($_POST['CloseMultiSelectWindow'])){
603                                 $this->Close();
604                         }
606                         if(isset($_POST['SaveMultiSelectWindow'])){
607                                 $this->Save();
608                         }
609                 }
611                 /* check for alphabet selection
612                    Check which regexes are connected to the alphabet 
613                  */     
614                 if(isset($_GET['search'])){
615                         foreach($this->array_Regexes as $key => $box){
616                                 /* check if this regex is connected to the alphabet selection */
617                                 if(($box['connAlpha'])&&(isset($_GET['search']))){
618                                         $val =  $_GET['search']."*";
619                                         $val = preg_replace("/\*\**/","*",$val);
620                                         $this->array_Regexes[$key]['value'] = $val;
621                                         $this->$box['name'] = $val;
622           $MultiDialogFilters = session::get('MultiDialogFilters');
623           $MultiDialogFilters[$this->filterName][$box['name']] =  $val;
624           session::set('MultiDialogFilters',$MultiDialogFilters);
625                                 }
626                         }
627                 }
628         }
631   /* Create header snapshot value */
632   function get_snapshot_header($layer_menu = FALSE)
633   {
634     $str = "";
635     if($this->parent->snapshotEnabled()){
636       $ok = false;
637       foreach($this->parent->get_used_snapshot_bases() as $base){
638         $ok |= count($this->parent->getAllDeletedSnapshots($base)) >= 1 ;
639       }
640       if($ok){
641         if($layer_menu){
642           $str = "..|<img class='center' src='images/restore.png' alt='"._("Restore")."'>&nbsp;"._("Restore")."|RestoreDeletedSnapShot|\n";
643         }else{
644           $str = "<input class='center' type='image' align='middle' src='images/restore.png'
645             title='"._("Restore snapshopts of already deleted objects")."' 
646             alt='"._("Restore")."' name='RestoreDeletedSnapShot'>&nbsp;"; 
647         }
648       }else{
649         if($layer_menu){
650           $str = "..|<img class='center' src='images/restore_grey.png' alt=''>&nbsp;"._("Restore")."||\n";
651         }else{
652           $str = "<img class='center' src='images/restore_grey.png' alt=''>&nbsp;";
653         }
654       }
655 #      $str .= "<img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;";
656     }
657     return($str);
658   }
661   function GetSnapShotActions($dn)
662   {
663     $str= "";
664     if($this->parent->snapshotEnabled()){
666       if(count($this->parent->Available_SnapsShots($dn))){
667         $str.= "<input class='center' type='image' src='images/restore.png'
668           alt='"._("Restore snapshot")."' name='RestoreSnapShotDialog_".base64_encode($dn)."' title='"._("Restore snapshot")."'>&nbsp;";
669       } else {
670         $str = "<img class='center' src='images/restore_grey.png' alt=''>&nbsp;";
671       }
673       $str.= "<input class='center' type='image' src='images/snapshot.png'
674         alt='"._("Create snapshot")."' name='CreateSnapShotDialog_".base64_encode($dn)."' title='"._("Create a new snapshot from this object")."'>&nbsp;";
675     }
677     return($str);
678   }
681         /* this function adds the sub-departments of the current tree to the list */
682         function AddDepartments($base = false,$numtabs = 3,$empty_tabs_in_front = 0)
683         {
684                 $this->DepartmentsAdded = true;
685     $this->Added_Departments = array();
687                 /* check for a valid base */
688                 if(!$base){
689                         if(!session::is_set('CurrentMainBase')){
690                                 session::set('CurrentMainBase',$this->config->current['BASE']);
691                         }
692                         $base  = session::get('CurrentMainBase');
693                 }
695                 /* Create ldap obj and switch into base*/
696                 $ldap = $this->config->get_ldap_link();
697                 $ldap->cd($base);
699                 /* reset current deps */
700                 $this->departments = array();
702                 /* Get all departments within this subtree */
703                 $deps= get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
704                     array("ou", "description"), GL_SIZELIMIT | GL_CONVERT);
706                 /* Edit delete link for system types
707                  */
708                 $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
710                 /* Create an array with all visible (in the list) departments */
711                 $departments = array();
712                 foreach($deps as $value){
713                         if(isset($value['description'][0])){
714                                 $this->departments[$value['dn']]= get_sub_department($value['dn'])." - [".$value["description"][0]."]";
715                         }else{
716                                 $this->departments[$value['dn']]= get_sub_department($value['dn']);
717                         }
718                 }
719                 natcasesort($this->departments);
722     if($empty_tabs_in_front){
723 #      $numtabs -= $empty_tabs_in_front;
724     }
725   
726                 /* Add deps to this dialog object list */
727                 foreach($this->departments as $key=> $val){
729                         /* Add missing entries ... */
730                         if(!isset($this->config->departments[trim($key)])){
731                                 $this->config->departments[trim($key)]="";
732                         }
734                         /* check if this department contains sub-departments
735                            Display different image in this case
736                          */
737                         $non_empty="";
738                         $nkey= normalizePreg($key);
739                         foreach($this->config->departments as $keyd=>$vald ){
740                                 if(preg_match('/$nkey\/.*/',$keyd)){
741                                         $non_empty="full";
742                                 }
743                         }
745                         /* Add to divlist */
746                         $row = array();
748       if($empty_tabs_in_front){
749         for($i = 0; $i < $empty_tabs_in_front ; $i ++){
750           $row[] = array("string"=>"&nbsp;", "attach" => "style='text-align:center;width:20px;'");
751         }
752       }
754                         $row[]=$field1=array("string"=>"<img src='images/".$non_empty."folder.png' alt='department'>","attach"=>"style='text-align:center;width:20px;'");
755                         $row[]=$field2=array("string"=>sprintf($linkopen,base64_encode($key),$val), "attach" => "style=''");
757                         if($numtabs > 2){       
758                                 for($i = 2 ; $i < $numtabs;$i++){
759           if(isset( $this->array_Header[$i + $empty_tabs_in_front]['attach'])){
760             $row[] = array("string"=>"&nbsp;","attach" => $this->array_Header[$i + $empty_tabs_in_front]['attach']);
761           }else{
762             $row[] = array("string"=>"&nbsp;");
763           }
764                                 }
765                         }
766                         $this->AddElement($row);
767       $this->Added_Departments[] = $row;
768                 }
769         }
771   function set_List_Bottom_Info($str)
772   {
773     $this->List_Bottom_Info = $str;
774   }
776   function get_List_Bottom_Info()
777   {
778     return($this->List_Bottom_Info); 
779   }
781 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
782 ?>