Code

565de251a6886bf06e1ee33c963882ab934ee692
[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 $departments= array();
56   var $DivHeight          = "";
58   var $HideFilterPart     = false;
59   var $List_Bottom_Info   = "";
60   var $SaveAdditionalVars = array();  // Additional Post vars to store 
61   var $module= "";
63   var $base_selection_regex = "*";
65   var $IgnoreAccount = TRUE;
66   var $footer = "";
67   var $post_id    = "1 2 3";
69         function ClearElementsList()
70         {
71     $ui =get_userinfo();
72     $deps = $ui->get_module_departments($this->module);
73     if(!in_array($this->selectedBase, $deps)){
74       $this->selectedBase = array_shift($deps);
75     }
76                 $this->array_Elements = array();
77         }
79   function HideFilterPart($bool = true)
80   {
81     $this->HideFilterPart = $bool;
82   }
84   function SetHeight($height)
85   { 
86     $this->DivHeight=$height;
87   }
89         /* Adds a regex input field to the current dialog */
90         function AddRegex($name,$string,$value,$conn,$image="images/lists/search.png")
91         {
92                 $arr = array();
94                 /* Check if the given input field name was already used 
95                    for this type of dialog */   
96     $MultiDialogFilters = session::get('MultiDialogFilters');
97                 if(isset($MultiDialogFilters[$this->filterName][$name])){
98                         $arr['value']   = $MultiDialogFilters[$this->filterName][$name];
99                         $this->$name = $arr['value'];
100                 }else{
101                         $arr['value']   = $value;       
102                 }
104                 $arr['name']            = $name;
105                 $arr['string']          = $string;
106                 $arr['image']           = $image;       
107                 $arr['connAlpha']       = $conn;                // Connect with alphabet select 
108                 $this->array_Regexes[] = $arr;
109         }
112   function SetDropDownHeaderMenu($str)
113   {
114     $this->string_ListDropDown = $str;
115   }
117   function GetDropDownHeaderMenu()
118   {
119     if(!empty($this->string_ListDropDown)){
120       $mid = new LayersMenu(6, 7, 2, 1);
121       $mid->setImgwww("./images/layer_menu/");
122       $mid->setIcondir("./images/layer_menu/");
123       $mid->setDirroot("../include/utils/layer-menu/");
124       $mid->setHorizontalMenuTpl("../ihtml/".get_template_path("",FALSE).'GOsa_MultiSelectHeader.ihtml');
125       $mid->setSubMenuTpl("../ihtml/".get_template_path("",FALSE).'GOsa_MultiSelectHeaderSubEntry.ihtml');
126       $mid->setMenuStructureString($this->string_ListDropDown);
127       $mid->parseStructureForMenu('menu');
128       $mid->newHorizontalMenu('menu');
129       $s = $mid->getHeader();
130       $s.= $mid->getMenu('menu');
131       $s.= $mid->getFooter('menu');
132       return($s);
133     }else{
134       return("");
135     }
136   }
139         /* Contrucktion */
140         function MultiSelectWindow(&$config, $filterName, $module)
141         {
142                 $this->config = &$config;
143                 $this->module = $module;
144                 $this->SaveButtonString         = _("Save");
145                 $this->CloseButtonString        = _("Close");
146                 $this->filterName                       = $filterName;
147     $this->ui = get_userinfo();
148     $this->post_id = preg_replace("/[^0-9]/","",microtime(TRUE));
150     /* Check default values for SaveAdditionalVars */
151     $MultiDialogFilters = session::get('MultiDialogFilters');
152     foreach($this->SaveAdditionalVars as $name){
153       if(isset($MultiDialogFilters[$this->filterName][$name])){
154         $this->$name = $MultiDialogFilters[$this->filterName][$name];
155       }
156     }
157     
158         }
160         /* Enables the headpage mode, which changes the list look */
161         function SetHeadpageMode()
162         {
163                 $this->is_headpage = true;
164         }
166         /* Sets the List internal name (not displayed anywhere) 
167            it is used to identify every single list
168          */     
169         function SetTitle($str)
170         {
171                 $this->string_Title = $str;
172         }
174         /* Set the list header string  */
175         function SetListHeader($str)
176         {
177                 $this->string_ListHeader = $str;
178         }
180         /* This sets the list description which is the first gray bar on top of the list */
181         function SetSummary($str)
182         {
183                 $this->string_Summary = $str;
184         }
186         /* If the save button is enabled, you can change its caption with this function */      
187         function SetSaveButtonString($str)
188         {
189                 $this->SaveButtonString = $str;
190         }
192         /* If the close button is enabled, you can change its caption with this function */     
193         function SetCloseButtonString($str)
194         {
195                 $this->CloseButtonString = $str;
196         }
198         /* With this function you can change the text of the information box */
199         function SetInformation($str)
200         {
201                 $this->string_Information = $str;
202         }
204         /* Display the alphabet selection box*/
205         function EnableAplhabet($bool)
206         {
207                 $this->bool_DisplayAlpahabet = $bool;
208         }
210         /* Add additional header col */
211         function AddHeader($arr)
212         {
213                 $this->array_Header[] = $arr;
214         }
216         /* add additional List element */
217         function AddElement($arr)
218         {
219                 $this->array_Elements[] = $arr;
220         }
223   /* Return default header part. With back, home and root icons and department selection */
224   function get_default_header($seperator= TRUE)
225   {
226     $enable_back = TRUE;
227     $enable_root = TRUE;
228     $enable_home = TRUE;
230     $ui = get_userinfo();
232     /* Check if selectedBase = first available base */
233     $deps = $ui->get_module_departments($this->module);
235     if(!count($deps) || $deps[0] == $this->selectedBase){
236       $enable_back = FALSE;
237       $enable_root = FALSE;
238     }
239   
240     $listhead ="";
241  
242     /* Check if we are in users home  department */ 
243     if(!count($deps) ||$this->selectedBase == get_base_from_people($ui->dn)){
244       $enable_home = FALSE;
245     }
247     /* Draw root button */
248     if($enable_root){
249       $listhead .= " <input class='center' type='image' src='images/lists/root.png' align='middle'
250         title='"._("Go to root department")."' name='dep_root' alt='"._("Root")."'>&nbsp;";
251     }else{
252       $listhead .= " <img src='images/lists/root_grey.png' class='center' alt='"._("Root")."'>&nbsp;";
253     }
255     /* Draw back button */
256     if($enable_back){
257       $listhead .= " <input class='center' type='image' align='middle' src='images/lists/back.png'
258         title='"._("Go up one department")."' alt='"._("Up")."'                name='dep_back'>&nbsp;";
259     }else{
260       $listhead .= " <img src='images/lists/back_grey.png' class='center' alt='"._("Up")."'>&nbsp;";
261     }
263     /* Draw home button */
264     if($enable_home){
265       $listhead .= " <input class='center' type='image' align='middle' src='images/lists/home.png'
266         title='"._("Go to users department")."' alt='"._("Home")."'            name='dep_home'>&nbsp;";
267     }else{
268       $listhead .= " <img src='images/lists/home_grey.png' class='center' alt='"._("Home")."'>&nbsp;";
269     }
270    
271     /* And at least draw reload button, this button is enabled everytime */ 
272     $listhead .=  " <input class='center' type='image' src='images/lists/reload.png' align='middle'
273       title='"._("Reload list")."' name='submit_department' alt='"._("Submit")."'>&nbsp;";
274     if ($seperator){
275       $listhead.= " <img   class='center' src='images/lists/seperator.png' align='middle' alt='-' height='16' width='1'>&nbsp;";
276     }
277     return ($listhead);
278   }
280         /* Add a checkbox to the filter element,
281            the name specifies an existing class var to store the 'selection' */
282         function AddCheckBox($name,$value="Unset",$string="Unset",$default=false)
283         {
284                 $arr = array();
286                 if($name == SEPERATOR){
287                         $arr['name'] = SEPERATOR;
288                 }else{
289                         /* Check if there was already a variable 
290                            for this dialog which we should use instead of the default*/
291       $MultiDialogFilters = session::get('MultiDialogFilters');
292                         if(isset($MultiDialogFilters[$this->filterName][$name])){
293                                 $arr['default'] = $MultiDialogFilters[$this->filterName][$name];
294                                 $this->$name = $arr['default'];
295                         }else{
296                                 $arr['default'] = $default; 
297         $this->$name = $default;
298                         }
299                         $arr['name']          = $name;
300                         $arr['string']      = $string;
301                         $arr['value']         = $value;
302                         $arr['enabled']     = true;
304                 }
305                 $this->array_Checkboxes[] = $arr;
306         }
309         /* Hides or unhides the checkbox with the given name */
310         function DisableCheckBox($name,$HideShow = false)
311         {
312                 foreach($this->array_Checkboxes as $key => $chkbox){
313                         if($chkbox['name'] == $name){
314                                 $this->array_Checkboxes[$key]['enabled'] = $HideShow;
315                         }
316                 }
317         }
320         /* Returns true if the close button was pressed */
321         function isClosed()
322         {
323                 return($this->is_closed);
324         }
326   
327   function SetListFooter($str){
328     $this->footer = $str;
329   }
332         /* Enable the close button */
333         function EnableCloseButton($bool)
334         {
335                 $this->bool_DisplayCloseButton = $bool;
336         }
338         /* Enable the save button on the bottom of the list*/
339         function EnableSaveButton ($bool)
340         {
341                 $this->bool_DisplaySaveButton = $bool;
342         }
344   /* Add a list specific filter object to position 
345       1 on top of Information 
346       2 Between Information && Filter
347       3 Below the Filter Part */
348   function AddUserBoxToFilter($position)
349   {
350     return("");
351   }
353   function EnableJSLeaveMsg($ignore = TRUE)
354   {
355     $this->IgnoreAccount = !$ignore;
356   }
358         /* Draw the list with all list elements and filters */
359         function Draw()
360         {
362                 /* Check for exeeded sizelimit */
363                 if (($message= check_sizelimit()) != ""){
364                         return($message);
365                 }
367                 $smarty = get_smarty();
368                 $smarty->assign("UserBox1",$this->AddUserBoxToFilter(1));
369                 $smarty->assign("UserBox2",$this->AddUserBoxToFilter(2));
370                 $smarty->assign("UserBox3",$this->AddUserBoxToFilter(3));
372                 $divlist = new divlist($this->string_Title);
373                 $divlist->SetSummary($this->string_Summary);
374                 $divlist->SetEntriesPerPage(0); // 0 for scrollable list
376     /* Display list footer with summary of all listed entries */
377     if ($this->config->get_cfg_value("list_summary") == "true"){
378       $divlist->SetFooter($this->get_List_Bottom_Info());
379     }
380   
381     if($this->DivHeight != ""){
382       $divlist->SetHeight($this->DivHeight);
383     }
385                 /* set Header informations 
386                  */
387                 $header = array();
388                 foreach($this->array_Header as $head){
389                         $header[] = $head;
390                 }
391                 $divlist->SetHeader($header);
393                 /* set Entries 
394                  */
395                 $elements = array();
396                 foreach($this->array_Elements as $element){
397                         $divlist->AddEntry($element);
398                 }
400                 /* Create checkboxes fields 
401                  */
402                 $boxes = "";
403                 $boxClick = " onClick='document.mainform.submit();' ";
404                 foreach($this->array_Checkboxes as $box){
406                         if($box['name'] == SEPERATOR){
407                                 $boxes .= "</td></tr></table><table style='width:100%;border-top:1px solid #B0B0B0;'><tr><td>";
408                                 continue;
409                         }
411                         /* Skip disabled boxes */
412                         if(!$box['enabled']) continue;
414                         /* Check if box is checked */
415                         if($box['default'] == true){
416                                 $boxes .="<input type='checkbox' name=\"".$box['name']."\" value='1' title=\"".htmlspecialchars($box['value'])."\" checked ".$boxClick.">&nbsp;".$box['string']."<br>";
417                         }else{
418                                 $boxes .="<input type='checkbox' name=\"".$box['name']."\" value='1' title=\"".htmlspecialchars($box['value'])."\" ".$boxClick.">&nbsp;".$box['string']."<br>";
419                         }
420                 }
421                 $smarty->assign("CheckBoxes", $boxes);
423                 /* Assign regex fields 
424                  */
425                 $regexes = "";
426                 foreach($this->array_Regexes as $regex){
427                         $regexes.="<table summary=\"\" style=\"width:100%;border-top:1px solid #B0B0B0;\">
428                                 <tr>
429                                 <td>
430                                 <label for=\"".$regex['name']."\">
431                                 <img alt=\"".$regex['string']."\" src=\"".$regex['image']."\" align=middle>
432                                 </label>
433                                 </td>
434                                 <td width=\"99%\">
435                                 <input id=\"".$regex['name']."\" type=\"text\" style='width:99%' name=\"".$regex['name']."\" maxlength='20'
436                                 value=\"".htmlspecialchars($regex['value'])."\" title=\"".htmlspecialchars($regex['string'])."\"> 
437                                 </td>
438                                 </tr>
439                                 </table>";
440                 }
441                 $smarty->assign("regexes"                       , $regexes );
443     /* Hide Filter Part if Requested or empty */
444     if((empty($boxes)) && (empty($regexes)) || ($this->HideFilterPart)){
445                   $smarty->assign("Skip_Filter_Part",   true);
446     }else{ 
447                   $smarty->assign("Skip_Filter_Part",   false);
448     }
450                 /* Assign alphabet and display it 
451                  */     
452                 $smarty->assign("Display_alphabet",     $this->bool_DisplayAlpahabet);
453                 $smarty->assign("alphabet",             generate_alphabet());
454                 $smarty->assign("Header"                        , $this->string_ListHeader);
455                 $smarty->assign("HeaderDropDown", $this->GetDropDownHeaderMenu());
456                 $smarty->assign("Summary"                       , $this->string_Summary);
457                 $smarty->assign("Title"                         , $this->string_Title);
458                 $smarty->assign("Information"           , $this->string_Information);
459                 $smarty->assign("IgnoreAccount"         , $this->IgnoreAccount);
460     $smarty->assign("POST_ID", $this->post_id);
462                 /* Check for exeeded sizelimit */
463                 $smarty->assign("hint"                          , print_sizelimit_warning());
464                 $smarty->assign("DivList"                       , $divlist->DrawList()."\n\n\n\n\n".$this->footer."\n\n\n\n\n");
466                 if($this->is_headpage){
467                         $smarty->assign("tree_image",           get_template_path('images/lists/search-subtree.png'));
468                         $smarty->assign("infoimage",            get_template_path('images/info.png'));
469                         $smarty->assign("launchimage",          get_template_path('images/launch.png'));
470                         $smarty->assign("apply",                        apply_filter());
471                 }else{
472                         $smarty->assign("tree_image",           get_template_path('images/lists/search-subtree.png'));
473                         $smarty->assign("infoimage",            get_template_path('images/info_small.png'));
474                         $smarty->assign("launchimage",          get_template_path('images/rocket.png'));
475                         $smarty->assign("apply",                        apply_filter());
476                 }
478                 /* Button handling */
479                 $smarty->assign("SaveButtonString" ,$this->SaveButtonString);
480                 $smarty->assign("CloseButtonString",$this->CloseButtonString);
482                 $smarty->assign("Display_Close",        $this->bool_DisplayCloseButton);
483                 $smarty->assign("Display_Save" ,        $this->bool_DisplaySaveButton);
485                 $smarty->assign("filterName"    ,       $this->filterName);
486                 $smarty->assign("is_headpage"   ,       $this->is_headpage);
488                 $display = $smarty->fetch(get_template_path("MultiSelectWindow.tpl"));
489                 return($display);
490         }
492         /* Set the close var, which simulates the close button is pressed */
493         function Close()
494         {
495                 $this->is_closed = true;
496         }
498         function Save()
499         {
500                 $this->is_saved = true;
501         }
503         /* Store all checkboxes/ regexes ... 
504            Store data also into a session var, to keep the checkboxes check after reload  */
505         function save_object()
506         {
508     /* Ensure that we do not handle posts for other dialogs 
509      */
510     if((isset($_POST['POST_ID']) && $_POST['POST_ID'] != $this->post_id) || 
511        (isset($_GET['post_id']) && $_GET['post_id'] != $this->post_id)){
512       return;
513     }
515     /* Get up to date config */
516     if(isset($this->parent->config)){
517       $this->config = $this->parent->config;
518     }
520     /* Update current base */
521     $s_action ="";
522     foreach($_POST as $key => $value){
523       if(preg_match("/^dep_back.*/i",$key)){
524         $s_action="back";
525       }elseif(preg_match("/^dep_root.*/",$key)){
526         $s_action="root";
527       }elseif(preg_match("/^dep_home.*/i",$key)){
528         $s_action="home";
529       }
530     }
532     /* Save base selection from headpage selectbox*/
533     if(isset($_POST['CurrentMainBase'])){
534       $this->selectedBase = $_POST['CurrentMainBase'];
535     }
537     /* Homebutton is posted */
538     if($s_action=="home"){
539       $ui= get_userinfo();
540       $base = get_base_from_people($ui->dn);
541       $this->selectedBase= $base;
542     }
544     /* Open selected department
545        this is posted by the parent class MultiSelectWindow */
546     if(isset($_GET['act'])&& ($_GET['act'] == "dep_open")){
547       $s_entry = $_GET['dep_id'];
548       if (!isset($this->departments[$s_entry])){
550         msg_dialog::display(_("LDAP error"), sprintf(_("Inconsistent DN encoding detected: '%s'"), LDAP::fix($s_entry)), ERROR_DIALOG);
551       } else {
552         $this->selectedBase = $this->departments[$s_entry]['dn'];
553       }
554     }
556     /* back to the roots ^^ */
557     if($s_action=="root"){
558       $this->selectedBase=($this->config->current['BASE']);
559       $dep_id = $this->ui->get_module_departments($this->module);
560       if(isset($dep_id[key($dep_id)])){
561         $this->selectedBase = $dep_id[key($dep_id)];
562       }
563     }
565     /* If Back-button is pressed, move back one step in DN */
566     if($s_action=="back"){
569       /* Get parent deprtment and check if we are allowed to step in it */
570       $base_back= preg_replace("/^[^,]+,/", "", $this->selectedBase);
571       $dep_id = $this->ui->get_module_departments($this->module);
572       if(in_array_ics($base_back,$dep_id)){
573         if(in_array($base_back,$this->config->departments)){
574           $this->selectedBase = $base_back;
575         }
576       }
577     }
579                 if(isset($_POST['MultiSelectWindow'.$this->filterName])){
581       /* Save some additional vars */
582       $MultiDialogFilters = session::get('MultiDialogFilters');
583       foreach($this->SaveAdditionalVars as $name){
584         if(isset($_POST[$name])){
585           if(isset($this->$name)){
586             $this->$name = $_POST[$name];
587             $MultiDialogFilters[$this->filterName][$name] = $_POST[$name];
588           }
589         }
590       }
591       session::set('MultiDialogFilters',$MultiDialogFilters);
593                         /* Check posts from checkboxes 
594                          */
595                         foreach($this->array_Checkboxes as $key => $box){
596                                 if(isset($_POST[$box['name']])){
597                                         $this->array_Checkboxes[$key]['default'] = true;
598                                         $this->$box['name'] = true;
599                                 }else{
600                                         $this->array_Checkboxes[$key]['default'] = false;
601                                         $this->$box['name'] = false;
602                                 }
604                                 /* Save settings in out session */
605         $MultiDialogFilters = session::get('MultiDialogFilters');
606                                 $MultiDialogFilters[$this->filterName][$box['name']] = $this->$box['name'];
607         session::set('MultiDialogFilters',$MultiDialogFilters);
608                         }
610                         /* Check regex posts */
611                         foreach($this->array_Regexes as $key => $box){
612                                 $this->array_Regexes[$key]['value'] = $_POST[$box['name']];
613                                 $this->$box['name'] = $_POST[$box['name']];
614         $MultiDialogFilters = session::get('MultiDialogFilters');
615                                 $MultiDialogFilters[$this->filterName][$box['name']] = $this->$box['name'];
616         session::set('MultiDialogFilters',$MultiDialogFilters);
617                         }
619                         /* call close/save if buttons are pressed */
620                         if(isset($_POST['CloseMultiSelectWindow'])){
621                                 $this->Close();
622                         }
624                         if(isset($_POST['SaveMultiSelectWindow'])){
625                                 $this->Save();
626                         }
627                 }
629                 /* check for alphabet selection
630                    Check which regexes are connected to the alphabet 
631                  */     
632                 if(isset($_GET['search'])){
633                         foreach($this->array_Regexes as $key => $box){
634                                 /* check if this regex is connected to the alphabet selection */
635                                 if(($box['connAlpha'])&&(isset($_GET['search']))){
636                                         $val =  $_GET['search']."*";
637                                         $val = preg_replace("/\*\**/","*",$val);
638                                         $this->array_Regexes[$key]['value'] = $val;
639                                         $this->$box['name'] = $val;
640           $MultiDialogFilters = session::get('MultiDialogFilters');
641           $MultiDialogFilters[$this->filterName][$box['name']] =  $val;
642           session::set('MultiDialogFilters',$MultiDialogFilters);
643                                 }
644                         }
645                 }
647     /* Save currenlty selected base in session */
648     session::set("CurrentMainBase",$this->selectedBase);
649         }
652         /* this function adds the sub-departments of the current tree to the list */
653         function AddDepartments($base = false,$numtabs = 3,$empty_tabs_in_front = 0)
654         {
655                 $this->DepartmentsAdded = true;
656     $this->Added_Departments = array();
658                 /* check for a valid base */
659                 if(!$base){
660       $base = $this->selectedBase;
661                 }
663                 /* Create ldap obj and switch into base*/
664                 $ldap = $this->config->get_ldap_link();
665                 $ldap->cd($base);
667                 /* reset current deps */
668                 $this->departments = array();
670                 /* Get all departments within this subtree */
671                 $deps= get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
672                     array("ou", "description","objectClass"), GL_SIZELIMIT );
674                 /* Edit delete link for system types
675                  */
676                 $linkopen = "<a href='?plug=".$_GET['plug']."&amp;post_id=".$this->post_id."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
678                 /* Create an array with all visible (in the list) departments */
679     $types = departmentManagement::get_support_departments();
682     /* Create search filter
683      */
684     $this->departments = array();
685     foreach($types as $name => $data){
686       $filter = "(&(objectClass=gosaDepartment)(objectClass=".$data['OC'].")
687                   (".$data['ATTR']."=".$this->base_selection_regex."))";
688       $tmp = get_list($filter,"department/".$data['ACL'],$this->selectedBase,array($data['ATTR'],"description"),GL_NONE);
689       foreach($tmp as $attrs){
690         $attrs['NAME'] = $attrs[$data['ATTR']][0];
691         $attrs['TYPE'] = $data;
692         $name = $attrs['NAME']." -".$attrs['dn'];
693         $this->departments[$name] = $attrs;
694       }
695     }
697     uksort($this->departments, 'strnatcasecmp');
699     $ui = get_userinfo();
700     $module_deps = $ui->get_module_departments($this->module);
701   
702                 /* Add deps to this dialog object list */
703     $this->departments = array_values($this->departments);
704                 foreach($this->departments as $key=> $val){
706       if(!in_array($val['dn'],$module_deps)) continue;
708       /* Check if this department contains sub-departments
709          Display different image in this case
710        */
711       $img = $val['TYPE']['IMG'];
712       foreach($this->config->departments as $keyd){
713         if(preg_match("/,".normalizePreg($val['dn'])."$/",$keyd)){
714           $img = $val['TYPE']['IMG_FULL'];
715         }
716       }
718       $img = "<image src='".$img."' class='center'>";
720                         /* Add spacer cols to divlist 
721        */
722                         $row = array();
723       if($empty_tabs_in_front){
724         for($i = 0; $i < $empty_tabs_in_front ; $i ++){
725           $row[] = array("string"=>"&nbsp;", "attach" => "style='text-align:center;width:20px;'");
726         }
727       }
729       /* Create entry name 
730        */
731       $name = $val['NAME'];
732       if(isset($val['description'])){
733         $name .=  " - [".$val["description"][0]."]";
734       }
736       /* Add departments
737        */
738                         $row[]=$field1=array("string"=> $img,"attach"=>"style='text-align:center;width:20px;'");
739                         $row[]=$field2=array("string"=>sprintf($linkopen,$key,$name), "attach" => "style=''");
741       /* Add spacer tabs 
742        */
743                         if($numtabs > 2){       
744                                 for($i = 2 ; $i < $numtabs;$i++){
745           if(isset( $this->array_Header[$i + $empty_tabs_in_front]['attach'])){
746             $row[] = array("string"=>"&nbsp;","attach" => $this->array_Header[$i + $empty_tabs_in_front]['attach']);
747           }else{
748             $row[] = array("string"=>"&nbsp;");
749           }
750                                 }
751                         }
752                         $this->AddElement($row);
753       $this->Added_Departments[] = $row;
754                 }
755         }
758   function create_department_list($modules)
759   { 
760      /* Load possible departments */
761     $ui= get_userinfo();
762     $first = "";
763     $found = FALSE;
765     if(!is_array($modules)){
766       $modules = array($modules);
767     }
769     $department = $departments = array();
770     $ids = $this->config->idepartments;
771     foreach($modules as $module){
772       $d = $ui->get_module_departments($module);
774       foreach($ids as $department => $desc){
775         if(in_array($department,$d)){
776           $departments[$department] = $department;
777         }
778       }
779     }
781     $first = "";
782     $found = FALSE;
783     $options ="";
784     foreach($departments as $dep => $name){
786       /* Keep first base dn in mind, we could need this
787        *  info if no valid base was found
788        */
789       if(empty($first)) {
790         $first = $dep['dn'];
791       }
793       $value = $ids[$dep];
794       if ($this->selectedBase == $dep){
795         $found = TRUE;
796         $options.= "<option selected='selected' value='".$dep."'>$value</option>";
797       } else {
798         $options.= "<option value='".$dep."'>$value</option>";
799       }
800     }
802     /* The currently used base is not visible with your acl setup.
803      * Set base to first useable base.
804      */
805     if(!$found){
806       $this->selectedBase = $first;
807     }
809     return($options);
810   }
812   function set_List_Bottom_Info($str)
813   {
814     $this->List_Bottom_Info = $str;
815   }
817   function get_List_Bottom_Info()
818   {
819     return($this->List_Bottom_Info); 
820   }
822 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
823 ?>