Code

Added possibililty to hide the | character
[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;
62   var $footer = "";
64         function ClearElementsList()
65         {
66                 $this->array_Elements = array();
67         }
69   function HideFilterPart($bool = true)
70   {
71     $this->HideFilterPart = $bool;
72   }
74   function SetHeight($height)
75   { 
76     $this->DivHeight=$height;
77   }
79         /* Adds a regex input field to the current dialog */
80         function AddRegex($name,$string,$value,$conn,$image="images/lists/search.png")
81         {
82                 $arr = array();
84                 /* Check if the given input field name was already used 
85                    for this type of dialog */   
86     $MultiDialogFilters = session::get('MultiDialogFilters');
87                 if(isset($MultiDialogFilters[$this->filterName][$name])){
88                         $arr['value']   = $MultiDialogFilters[$this->filterName][$name];
89                         $this->$name = $arr['value'];
90                 }else{
91                         $arr['value']   = $value;       
92                 }
94                 $arr['name']            = $name;
95                 $arr['string']          = $string;
96                 $arr['image']           = $image;       
97                 $arr['connAlpha']       = $conn;                // Connect with alphabet select 
98                 $this->array_Regexes[] = $arr;
99         }
102   function SetDropDownHeaderMenu($str)
103   {
104     $this->string_ListDropDown = $str;
105   }
107   function GetDropDownHeaderMenu()
108   {
109     if(!empty($this->string_ListDropDown)){
110       $mid = new LayersMenu(6, 7, 2, 1);
111       $mid->setImgwww("./images/");
112       $mid->setIcondir("./images/");
113       $mid->setDirroot("../include/utils/layer-menu/");
114       $mid->setHorizontalMenuTpl("../ihtml/".get_template_path("",FALSE).'GOsa_MultiSelectHeader.ihtml');
115       $mid->setSubMenuTpl("../ihtml/".get_template_path("",FALSE).'GOsa_MultiSelectHeaderSubEntry.ihtml');
116       $mid->setMenuStructureString($this->string_ListDropDown);
117       $mid->parseStructureForMenu('menu');
118       $mid->newHorizontalMenu('menu');
119       $s = $mid->getHeader();
120       $s.= $mid->getMenu('menu');
121       $s.= $mid->getFooter('menu');
122       return($s);
123     }else{
124       return("");
125     }
126   }
129         /* Contrucktion */
130         function MultiSelectWindow(&$config, $filterName, $module)
131         {
132                 $this->config = &$config;
133                 $this->module = $module;
134                 $this->SaveButtonString         = _("Save");
135                 $this->CloseButtonString        = _("Close");
136                 $this->filterName                       = $filterName;
137     $this->ui = get_userinfo();
138                 $this->selectedBase  = session::get('CurrentMainBase');
140     /* Check default values for SaveAdditionalVars */
141     $MultiDialogFilters = session::get('MultiDialogFilters');
142     foreach($this->SaveAdditionalVars as $name){
143       if(isset($MultiDialogFilters[$this->filterName][$name])){
144         $this->$name = $MultiDialogFilters[$this->filterName][$name];
145       }
146     }
147     
148         }
150         /* Enables the headpage mode, which changes the list look */
151         function SetHeadpageMode()
152         {
153                 $this->is_headpage = true;
154         }
156         /* Sets the List internal name (not displayed anywhere) 
157            it is used to identify every single list
158          */     
159         function SetTitle($str)
160         {
161                 $this->string_Title = $str;
162         }
164         /* Set the list header string  */
165         function SetListHeader($str)
166         {
167                 $this->string_ListHeader = $str;
168         }
170         /* This sets the list description which is the first gray bar on top of the list */
171         function SetSummary($str)
172         {
173                 $this->string_Summary = $str;
174         }
176         /* If the save button is enabled, you can change its caption with this function */      
177         function SetSaveButtonString($str)
178         {
179                 $this->SaveButtonString = $str;
180         }
182         /* If the close button is enabled, you can change its caption with this function */     
183         function SetCloseButtonString($str)
184         {
185                 $this->CloseButtonString = $str;
186         }
188         /* With this function you can change the text of the information box */
189         function SetInformation($str)
190         {
191                 $this->string_Information = $str;
192         }
194         /* Display the alphabet selection box*/
195         function EnableAplhabet($bool)
196         {
197                 $this->bool_DisplayAlpahabet = $bool;
198         }
200         /* Add additional header col */
201         function AddHeader($arr)
202         {
203                 $this->array_Header[] = $arr;
204         }
206         /* add additional List element */
207         function AddElement($arr)
208         {
209                 $this->array_Elements[] = $arr;
210         }
213   /* Return default header part. With back, home and root icons and department selection */
214   function get_default_header($seperator= TRUE)
215   {
216     $enable_back = TRUE;
217     $enable_root = TRUE;
218     $enable_home = TRUE;
220     $ui = get_userinfo();
222     /* Check if selectedBase = first available base */
223     $deps = $ui->get_module_departments($this->module);
225     if(!count($deps) || $deps[0] == $this->selectedBase){
226       $enable_back = FALSE;
227       $enable_root = FALSE;
228     }
229   
230     $listhead ="";
231  
232     /* Check if we are in users home  department */ 
233     if(!count($deps) ||$this->selectedBase == get_base_from_people($ui->dn)){
234       $enable_home = FALSE;
235     }
237     /* Draw root button */
238     if($enable_root){
239       $listhead .= " <input class='center' type='image' src='images/lists/root.png' align='middle'
240         title='"._("Go to root department")."' name='dep_root' alt='"._("Root")."'>&nbsp;";
241     }else{
242       $listhead .= " <img src='images/lists/root_grey.png' class='center' alt='"._("Root")."'>&nbsp;";
243     }
245     /* Draw back button */
246     if($enable_back){
247       $listhead .= " <input class='center' type='image' align='middle' src='images/lists/back.png'
248         title='"._("Go up one department")."' alt='"._("Up")."'                name='dep_back'>&nbsp;";
249     }else{
250       $listhead .= " <img src='images/lists/back_grey.png' class='center' alt='"._("Up")."'>&nbsp;";
251     }
253     /* Draw home button */
254     if($enable_home){
255       $listhead .= " <input class='center' type='image' align='middle' src='images/lists/home.png'
256         title='"._("Go to users department")."' alt='"._("Home")."'            name='dep_home'>&nbsp;";
257     }else{
258       $listhead .= " <img src='images/lists/home_grey.png' class='center' alt='"._("Home")."'>&nbsp;";
259     }
260    
261     /* And at least draw reload button, this button is enabled everytime */ 
262     $listhead .=  " <input class='center' type='image' src='images/lists/reload.png' align='middle'
263       title='"._("Reload list")."' name='submit_department' alt='"._("Submit")."'>&nbsp;";
264     if ($seperator){
265       $listhead.= " <img   class='center' src='images/lists/seperator.png' align='middle' alt='-' height='16' width='1'>&nbsp;";
266     }
267     return ($listhead);
268   }
270         /* Add a checkbox to the filter element,
271            the name specifies an existing class var to store the 'selection' */
272         function AddCheckBox($name,$value="Unset",$string="Unset",$default=false)
273         {
274                 $arr = array();
276                 if($name == SEPERATOR){
277                         $arr['name'] = SEPERATOR;
278                 }else{
279                         /* Check if there was already a variable 
280                            for this dialog which we should use instead of the default*/
281       $MultiDialogFilters = session::get('MultiDialogFilters');
282                         if(isset($MultiDialogFilters[$this->filterName][$name])){
283                                 $arr['default'] = $MultiDialogFilters[$this->filterName][$name];
284                                 $this->$name = $arr['default'];
285                         }else{
286                                 $arr['default'] = $default; 
287         $this->$name = $default;
288                         }
289                         $arr['name']          = $name;
290                         $arr['string']      = $string;
291                         $arr['value']         = $value;
292                         $arr['enabled']     = true;
294                 }
295                 $this->array_Checkboxes[] = $arr;
296         }
299         /* Hides or unhides the checkbox with the given name */
300         function DisableCheckBox($name,$HideShow = false)
301         {
302                 foreach($this->array_Checkboxes as $key => $chkbox){
303                         if($chkbox['name'] == $name){
304                                 $this->array_Checkboxes[$key]['enabled'] = $HideShow;
305                         }
306                 }
307         }
310         /* Returns true if the close button was pressed */
311         function isClosed()
312         {
313                 return($this->is_closed);
314         }
316   
317   function SetListFooter($str){
318     $this->footer = $str;
319   }
322         /* Enable the close button */
323         function EnableCloseButton($bool)
324         {
325                 $this->bool_DisplayCloseButton = $bool;
326         }
328         /* Enable the save button on the bottom of the list*/
329         function EnableSaveButton ($bool)
330         {
331                 $this->bool_DisplaySaveButton = $bool;
332         }
334   /* Add a list specific filter object to position 
335       1 on top of Information 
336       2 Between Information && Filter
337       3 Below the Filter Part */
338   function AddUserBoxToFilter($position)
339   {
340     return("");
341   }
343   function EnableJSLeaveMsg($ignore = TRUE)
344   {
345     $this->IgnoreAccount = !$ignore;
346   }
348         /* Draw the list with all list elements and filters */
349         function Draw()
350         {
352                 /* Check for exeeded sizelimit */
353                 if (($message= check_sizelimit()) != ""){
354                         return($message);
355                 }
357                 $smarty = get_smarty();
358                 $smarty->assign("UserBox1",$this->AddUserBoxToFilter(1));
359                 $smarty->assign("UserBox2",$this->AddUserBoxToFilter(2));
360                 $smarty->assign("UserBox3",$this->AddUserBoxToFilter(3));
362                 $divlist = new divlist($this->string_Title);
363                 $divlist->SetSummary($this->string_Summary);
364                 $divlist->SetEntriesPerPage(0); // 0 for scrollable list
366     /* Display list footer with summary of all listed entries */
367     if(isset($this->config->data['MAIN']['LIST_SUMMARY']) && preg_match("/true/i",$this->config->data['MAIN']['LIST_SUMMARY'])){
368       $divlist->SetFooter($this->get_List_Bottom_Info());
369     }
370   
371     if($this->DivHeight != ""){
372       $divlist->SetHeight($this->DivHeight);
373     }
375                 /* set Header informations 
376                  */
377                 $header = array();
378                 foreach($this->array_Header as $head){
379                         $header[] = $head;
380                 }
381                 $divlist->SetHeader($header);
383                 /* set Entries 
384                  */
385                 $elements = array();
386                 foreach($this->array_Elements as $element){
387                         $divlist->AddEntry($element);
388                 }
390                 /* Create checkboxes fields 
391                  */
392                 $boxes = "";
393                 $boxClick = " onClick='document.mainform.submit();' ";
394                 foreach($this->array_Checkboxes as $box){
396                         if($box['name'] == SEPERATOR){
397                                 $boxes .= "</td></tr></table><table style='width:100%;border-top:1px solid #B0B0B0;'><tr><td>";
398                                 continue;
399                         }
401                         /* Skip disabled boxes */
402                         if(!$box['enabled']) continue;
404                         /* Check if box is checked */
405                         if($box['default'] == true){
406                                 $boxes .="<input type='checkbox' name=\"".$box['name']."\" value='1' title=\"".htmlspecialchars($box['value'])."\" checked ".$boxClick.">&nbsp;".$box['string']."<br>";
407                         }else{
408                                 $boxes .="<input type='checkbox' name=\"".$box['name']."\" value='1' title=\"".htmlspecialchars($box['value'])."\" ".$boxClick.">&nbsp;".$box['string']."<br>";
409                         }
410                 }
411                 $smarty->assign("CheckBoxes", $boxes);
413                 /* Assign regex fields 
414                  */
415                 $regexes = "";
416                 foreach($this->array_Regexes as $regex){
417                         $regexes.="<table summary=\"\" style=\"width:100%;border-top:1px solid #B0B0B0;\">
418                                 <tr>
419                                 <td>
420                                 <label for=\"".$regex['name']."\">
421                                 <img alt=\"".$regex['string']."\" src=\"".$regex['image']."\" align=middle>
422                                 </label>
423                                 </td>
424                                 <td width=\"99%\">
425                                 <input id=\"".$regex['name']."\" type=\"text\" style='width:99%' name=\"".$regex['name']."\" maxlength='20'
426                                 value=\"".htmlspecialchars($regex['value'])."\" title=\"".htmlspecialchars($regex['string'])."\"> 
427                                 </td>
428                                 </tr>
429                                 </table>";
430                 }
431                 $smarty->assign("regexes"                       , $regexes );
433     /* Hide Filter Part if Requested or empty */
434     if((empty($boxes)) && (empty($regexes)) || ($this->HideFilterPart)){
435                   $smarty->assign("Skip_Filter_Part",   true);
436     }else{ 
437                   $smarty->assign("Skip_Filter_Part",   false);
438     }
440                 /* Assign alphabet and display it 
441                  */     
442                 $smarty->assign("Display_alphabet",     $this->bool_DisplayAlpahabet);
443                 $smarty->assign("alphabet",             generate_alphabet());
444                 $smarty->assign("Header"                        , $this->string_ListHeader);
445                 $smarty->assign("HeaderDropDown", $this->GetDropDownHeaderMenu());
446                 $smarty->assign("Summary"                       , $this->string_Summary);
447                 $smarty->assign("Title"                         , $this->string_Title);
448                 $smarty->assign("Information"           , $this->string_Information);
449                 $smarty->assign("IgnoreAccount"         , $this->IgnoreAccount);
451                 /* Check for exeeded sizelimit */
452                 $smarty->assign("hint"                          , print_sizelimit_warning());
453                 $smarty->assign("DivList"                       , $divlist->DrawList()."\n\n\n\n\n".$this->footer."\n\n\n\n\n");
455                 if($this->is_headpage){
456                         $smarty->assign("tree_image",           get_template_path('images/lists/search-subtree.png'));
457                         $smarty->assign("infoimage",            get_template_path('images/info.png'));
458                         $smarty->assign("launchimage",          get_template_path('images/launch.png'));
459                         $smarty->assign("apply",                        apply_filter());
460                 }else{
461                         $smarty->assign("tree_image",           get_template_path('images/lists/search-subtree.png'));
462                         $smarty->assign("infoimage",            get_template_path('images/info_small.png'));
463                         $smarty->assign("launchimage",          get_template_path('images/rocket.png'));
464                         $smarty->assign("apply",                        apply_filter());
465                 }
467                 /* Button handling */
468                 $smarty->assign("SaveButtonString" ,$this->SaveButtonString);
469                 $smarty->assign("CloseButtonString",$this->CloseButtonString);
471                 $smarty->assign("Display_Close",        $this->bool_DisplayCloseButton);
472                 $smarty->assign("Display_Save" ,        $this->bool_DisplaySaveButton);
474                 $smarty->assign("filterName"    ,       $this->filterName);
475                 $smarty->assign("is_headpage"   ,       $this->is_headpage);
477                 $display = $smarty->fetch(get_template_path("MultiSelectWindow.tpl"));
478                 return($display);
479         }
481         /* Set the close var, which simulates the close button is pressed */
482         function Close()
483         {
484                 $this->is_closed = true;
485         }
487         function Save()
488         {
489                 $this->is_saved = true;
490         }
492         /* Store all checkboxes/ regexes ... 
493            Store data also into a session var, to keep the checkboxes check after reload  */
494         function save_object()
495         {
496     /* Get up to date config */
497     if(isset($this->parent->config)){
498       $this->config = $this->parent->config;
499     }
501     /* Update current base */
502     $s_action ="";
503     foreach($_POST as $key => $value){
504       if(preg_match("/^dep_back.*/i",$key)){
505         $s_action="back";
506       }elseif(preg_match("/^dep_root.*/",$key)){
507         $s_action="root";
508       }elseif(preg_match("/^dep_home.*/i",$key)){
509         $s_action="home";
510       }
511     }
513     /* Save base selection from headpage selectbox*/
514     if(isset($_POST['CurrentMainBase'])){
515       $this->selectedBase = $_POST['CurrentMainBase'];
516     }
518     /* Homebutton is posted */
519     if($s_action=="home"){
520       $ui= get_userinfo();
521       $base = get_base_from_people($ui->dn);
522       $this->selectedBase= $base;
523     }
525     /* Open selected department
526        this is posted by the parent class MultiSelectWindow */
527     if(isset($_GET['act'])&& ($_GET['act'] == "dep_open")){
528       $s_entry = base64_decode($_GET['dep_id']);
529       if (!isset($this->config->departments[$s_entry])){
530         msg_dialog::display(_("LDAP error"), sprintf(_("Inconsistent DN encoding detected: '%s'"), LDAP::fix($s_entry)), ERROR_DIALOG);
531       } else {
532         $this->selectedBase = $this->config->departments[$s_entry];
533       }
534     }
536     /* back to the roots ^^ */
537     if($s_action=="root"){
538       $this->selectedBase=($this->config->current['BASE']);
539       $dep_id = $this->ui->get_module_departments($this->module);
540       if(isset($dep_id[key($dep_id)])){
541         $this->selectedBase = $dep_id[key($dep_id)];
542       }
543     }
546     /* If Back-button is pressed, move back one step in DN */
547     if($s_action=="back"){
549       /* Get parent deprtment and check if we are allowed to step in it */
550       $base_back= preg_replace("/^[^,]+,/", "", session::get('CurrentMainBase'));
551       $dep_id = $this->ui->get_module_departments($this->module);
552       if(in_array_ics($base_back,$dep_id)){
554         /* The department array keeps non DN entries as index. We need to convert
555            it before checking the existance. */
556         $base_back= trim(convert_department_dn($base_back));
558         /* Check if the department exists, otherwise revert to the configure base DN */
559         if(isset($this->config->departments[$base_back])){
560           $this->selectedBase= $this->config->departments[$base_back];
561         }else{
562           $this->selectedBase= $this->config->departments['/'];
563         }
564       }
565     }
566     session::set('CurrentMainBase',$this->selectedBase);
568                 if(isset($_POST['MultiSelectWindow'.$this->filterName])){
570       /* Save some additional vars */
571       $MultiDialogFilters = session::get('MultiDialogFilters');
572       foreach($this->SaveAdditionalVars as $name){
573         if(isset($_POST[$name])){
574           if(isset($this->$name)){
575             $this->$name = $_POST[$name];
576             $MultiDialogFilters[$this->filterName][$name] = $_POST[$name];
577           }
578         }
579       }
580       session::set('MultiDialogFilters',$MultiDialogFilters);
582                         /* Check posts from checkboxes 
583                          */
584                         foreach($this->array_Checkboxes as $key => $box){
585                                 if(isset($_POST[$box['name']])){
586                                         $this->array_Checkboxes[$key]['default'] = true;
587                                         $this->$box['name'] = true;
588                                 }else{
589                                         $this->array_Checkboxes[$key]['default'] = false;
590                                         $this->$box['name'] = false;
591                                 }
593                                 /* Save settings in out session */
594         $MultiDialogFilters = session::get('MultiDialogFilters');
595                                 $MultiDialogFilters[$this->filterName][$box['name']] = $this->$box['name'];
596         session::set('MultiDialogFilters',$MultiDialogFilters);
597                         }
599                         /* Check regex posts */
600                         foreach($this->array_Regexes as $key => $box){
601                                 $this->array_Regexes[$key]['value'] = $_POST[$box['name']];
602                                 $this->$box['name'] = $_POST[$box['name']];
603         $MultiDialogFilters = session::get('MultiDialogFilters');
604                                 $MultiDialogFilters[$this->filterName][$box['name']] = $this->$box['name'];
605         session::set('MultiDialogFilters',$MultiDialogFilters);
606                         }
608                         /* call close/save if buttons are pressed */
609                         if(isset($_POST['CloseMultiSelectWindow'])){
610                                 $this->Close();
611                         }
613                         if(isset($_POST['SaveMultiSelectWindow'])){
614                                 $this->Save();
615                         }
616                 }
618                 /* check for alphabet selection
619                    Check which regexes are connected to the alphabet 
620                  */     
621                 if(isset($_GET['search'])){
622                         foreach($this->array_Regexes as $key => $box){
623                                 /* check if this regex is connected to the alphabet selection */
624                                 if(($box['connAlpha'])&&(isset($_GET['search']))){
625                                         $val =  $_GET['search']."*";
626                                         $val = preg_replace("/\*\**/","*",$val);
627                                         $this->array_Regexes[$key]['value'] = $val;
628                                         $this->$box['name'] = $val;
629           $MultiDialogFilters = session::get('MultiDialogFilters');
630           $MultiDialogFilters[$this->filterName][$box['name']] =  $val;
631           session::set('MultiDialogFilters',$MultiDialogFilters);
632                                 }
633                         }
634                 }
635         }
638   /* Create header snapshot value */
639   function get_snapshot_header($layer_menu = FALSE)
640   {
641     $str = "";
642     if($this->parent->snapshotEnabled()){
643       $ok = false;
644       foreach($this->parent->get_used_snapshot_bases() as $base){
645         $ok |= count($this->parent->getAllDeletedSnapshots($base)) >= 1 ;
646       }
647       if($ok){
648         if($layer_menu){
649           $str = "..|<img class='center' src='images/lists/restore.png' alt='"._("Restore")."'>&nbsp;"._("Restore")."|RestoreDeletedSnapShot|\n";
650         }else{
651           $str = "<input class='center' type='image' align='middle' src='images/lists/restore.png'
652             title='"._("Restore snapshopts of already deleted objects")."' 
653             alt='"._("Restore")."' name='RestoreDeletedSnapShot'>&nbsp;"; 
654         }
655       }else{
656         if($layer_menu){
657           $str = "..|<img class='center' src='images/lists/restore_grey.png' alt=''>&nbsp;"._("Restore")."||\n";
658         }else{
659           $str = "<img class='center' src='images/lists/restore_grey.png' alt=''>&nbsp;";
660         }
661       }
662     }
663     return($str);
664   }
667   function GetSnapShotActions($dn)
668   {
669     $str= "";
670     if($this->parent->snapshotEnabled()){
672       if(count($this->parent->Available_SnapsShots($dn))){
673         $str.= "<input class='center' type='image' src='images/lists/restore.png'
674           alt='"._("Restore snapshot")."' name='RestoreSnapShotDialog_".base64_encode($dn)."' title='"._("Restore snapshot")."'>&nbsp;";
675       } else {
676         $str = "<img class='center' src='images/lists/restore_grey.png' alt=''>&nbsp;";
677       }
679       $str.= "<input class='center' type='image' src='images/snapshot.png'
680         alt='"._("Create snapshot")."' name='CreateSnapShotDialog_".base64_encode($dn)."' title='"._("Create a new snapshot from this object")."'>&nbsp;";
681     }
683     return($str);
684   }
687         /* this function adds the sub-departments of the current tree to the list */
688         function AddDepartments($base = false,$numtabs = 3,$empty_tabs_in_front = 0)
689         {
690                 $this->DepartmentsAdded = true;
691     $this->Added_Departments = array();
693                 /* check for a valid base */
694                 if(!$base){
695                         if(!session::is_set('CurrentMainBase')){
696                                 session::set('CurrentMainBase',$this->config->current['BASE']);
697                         }
698                         $base  = session::get('CurrentMainBase');
699                 }
701                 /* Create ldap obj and switch into base*/
702                 $ldap = $this->config->get_ldap_link();
703                 $ldap->cd($base);
705                 /* reset current deps */
706                 $this->departments = array();
708                 /* Get all departments within this subtree */
709                 $deps= get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
710                     array("ou", "description"), GL_SIZELIMIT | GL_CONVERT);
712                 /* Edit delete link for system types
713                  */
714                 $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
716                 /* Create an array with all visible (in the list) departments */
717                 $departments = array();
718                 foreach($deps as $value){
719                         if(isset($value['description'][0])){
720                                 $this->departments[$value['dn']]= get_sub_department($value['dn'])." - [".$value["description"][0]."]";
721                         }else{
722                                 $this->departments[$value['dn']]= get_sub_department($value['dn']);
723                         }
724                 }
725                 natcasesort($this->departments);
728     if($empty_tabs_in_front){
729 #      $numtabs -= $empty_tabs_in_front;
730     }
731   
732                 /* Add deps to this dialog object list */
733                 foreach($this->departments as $key=> $val){
735                         /* Add missing entries ... */
736                         if(!isset($this->config->departments[trim($key)])){
737                                 $this->config->departments[trim($key)]="";
738                         }
740                         /* check if this department contains sub-departments
741                            Display different image in this case
742                          */
743                         $non_empty="";
744                         $nkey= normalizePreg($key);
745                         foreach($this->config->departments as $keyd=>$vald ){
746                                 if(preg_match('/$nkey\/.*/',$keyd)){
747                                         $non_empty="-full";
748                                 }
749                         }
751                         /* Add to divlist */
752                         $row = array();
754       if($empty_tabs_in_front){
755         for($i = 0; $i < $empty_tabs_in_front ; $i ++){
756           $row[] = array("string"=>"&nbsp;", "attach" => "style='text-align:center;width:20px;'");
757         }
758       }
760                         $row[]=$field1=array("string"=>"<img src='images/lists/folder".$non_empty.".png' alt='department'>","attach"=>"style='text-align:center;width:20px;'");
761                         $row[]=$field2=array("string"=>sprintf($linkopen,base64_encode($key),$val), "attach" => "style=''");
763                         if($numtabs > 2){       
764                                 for($i = 2 ; $i < $numtabs;$i++){
765           if(isset( $this->array_Header[$i + $empty_tabs_in_front]['attach'])){
766             $row[] = array("string"=>"&nbsp;","attach" => $this->array_Header[$i + $empty_tabs_in_front]['attach']);
767           }else{
768             $row[] = array("string"=>"&nbsp;");
769           }
770                                 }
771                         }
772                         $this->AddElement($row);
773       $this->Added_Departments[] = $row;
774                 }
775         }
777   function set_List_Bottom_Info($str)
778   {
779     $this->List_Bottom_Info = $str;
780   }
782   function get_List_Bottom_Info()
783   {
784     return($this->List_Bottom_Info); 
785   }
787 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
788 ?>