Code

ba2e4629a04a57e417b7c82d907514c66d0192a8
[gosa.git] / trunk / 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 /*! \brief Class to generate MultiSelectWindow
26  *
27  * Base class for multi selection/divList classes in a plugin.
28  */
29 class MultiSelectWindow{
31         var $bool_DisplayAlpahabet      = false;
32         var $bool_DisplayCloseButton= true;     
33         var $bool_DisplaySaveButton = true;     
35         var $SaveButtonString           = "";
36         var $CloseButtonString  = "";
38         var $string_Title                         = "";
39         var $string_ListHeader  = "";
40         var $string_ListDropDown= "";
41         var $string_Summary                     = "";
42         var $string_Information = "";
44         var $array_Header                         = array();
45         var $array_Elements                     = array();      
46         var $array_Checkboxes           = array();      
47         var $array_Regexes                      = array();      
49         var $config                                         = array("");
50         var $is_closed                            = false;
51         var $is_saved                               = false;
52         var $is_headpage                          = false;      // if true the design changes
53         var $filterName                           = "Liste";
54         var $DepartmentsAdded           = false;
55         var $Added_Departments  = array();
56         var $selectedBase       = "";
58         var $departments= array();
60   var $DivHeight          = "";
62   var $HideFilterPart     = false;
63   var $List_Bottom_Info   = "";
64   var $SaveAdditionalVars = array();  // Additional Post vars to store 
65   var $module= "";
67   var $base_selection_regex = "*";
69   var $IgnoreAccount = TRUE;
70   var $footer = "";
71   var $post_id    = "1 2 3";
73         function ClearElementsList()
74         {
75     $ui =get_userinfo();
76     $deps = $ui->get_module_departments($this->module);
77     if(!in_array($this->selectedBase, $deps)){
78       $this->selectedBase = array_shift($deps);
79     }
80                 $this->array_Elements = array();
81         }
83   function HideFilterPart($bool = true)
84   {
85     $this->HideFilterPart = $bool;
86   }
88   /*! \brief Set the height of the divlist */
89   function SetHeight($height)
90   { 
91     $this->DivHeight=$height;
92   }
94         /* Adds a regex input field to the current dialog */
95         function AddRegex($name,$string,$value,$conn,$image="images/lists/search.png")
96         {
97                 $arr = array();
99                 /* Check if the given input field name was already used 
100                    for this type of dialog */   
101     $MultiDialogFilters = session::get('MultiDialogFilters');
102                 if(isset($MultiDialogFilters[$this->filterName][$name])){
103                         $arr['value']   = $MultiDialogFilters[$this->filterName][$name];
104                         $this->$name = $arr['value'];
105                 }else{
106                         $arr['value']   = $value;       
107                 }
109                 $arr['name']            = $name;
110                 $arr['string']          = $string;
111                 $arr['image']           = $image;       
112                 $arr['connAlpha']       = $conn;                // Connect with alphabet select 
113                 $this->array_Regexes[] = $arr;
114         }
117   function SetDropDownHeaderMenu($str)
118   {
119     $this->string_ListDropDown = $str;
120   }
122   function GetDropDownHeaderMenu()
123   {
124     if(!empty($this->string_ListDropDown)){
125       $mid = new LayersMenu(6, 7, 2, 1);
126       $mid->setImgwww("./images/layer_menu/");
127       $mid->setIcondir("./images/layer_menu/");
128       $mid->setDirroot("../include/utils/layer-menu/");
129       $mid->setHorizontalMenuTpl("../ihtml/".get_template_path("",FALSE).'GOsa_MultiSelectHeader.ihtml');
130       $mid->setSubMenuTpl("../ihtml/".get_template_path("",FALSE).'GOsa_MultiSelectHeaderSubEntry.ihtml');
131       $mid->setMenuStructureString($this->string_ListDropDown);
132       $mid->parseStructureForMenu('menu');
133       $mid->newHorizontalMenu('menu');
134       $s = $mid->getHeader();
135       $s.= $mid->getMenu('menu');
136       $s.= $mid->getFooter('menu');
137       return($s);
138     }else{
139       return("");
140     }
141   }
144         /* Contrucktion */
145         function MultiSelectWindow(&$config, $filterName, $module)
146         {
147                 $this->config = &$config;
148                 $this->module = $module;
149                 $this->SaveButtonString         = _("Save");
150                 $this->CloseButtonString        = _("Close");
151                 $this->filterName                       = $filterName;
152     $this->ui = get_userinfo();
153     $this->post_id = preg_replace("/[^0-9]/","",microtime(TRUE));
154     $this->selectedBase  = session::get('CurrentMainBase');
156     /* Check default values for SaveAdditionalVars */
157     $MultiDialogFilters = session::get('MultiDialogFilters');
158     foreach($this->SaveAdditionalVars as $name){
159       if(isset($MultiDialogFilters[$this->filterName][$name])){
160         $this->$name = $MultiDialogFilters[$this->filterName][$name];
161       }
162     }
163     
164         }
166         /* Enables the headpage mode, which changes the list look */
167         function SetHeadpageMode()
168         {
169                 $this->is_headpage = true;
170         }
172         /* \brief Sets the List internal name (not displayed anywhere) 
173     
174      It is used to identify every single list.
175          */     
176         function SetTitle($str)
177         {
178                 $this->string_Title = $str;
179         }
181         /*! \brief Set the list header string  */
182         function SetListHeader($str)
183         {
184                 $this->string_ListHeader = $str;
185         }
187         /*! \brief This sets the list description which is the first gray bar on top of the list */
188         function SetSummary($str)
189         {
190                 $this->string_Summary = $str;
191         }
193   /*! \brief Change the caption of the save button (if it is enabled) */
194         function SetSaveButtonString($str)
195         {
196                 $this->SaveButtonString = $str;
197         }
199   /*! \brief Change the caption of the close button (if it is enabled) */
200         function SetCloseButtonString($str)
201         {
202                 $this->CloseButtonString = $str;
203         }
205   /*! \brief Change the text of the information box */
206         function SetInformation($str)
207         {
208                 $this->string_Information = $str;
209         }
211   /*! \brief Toggle the alphabet selection display */
212         function EnableAplhabet($bool)
213         {
214                 $this->bool_DisplayAlpahabet = $bool;
215         }
217         /*! \brief Add additional header col */
218         function AddHeader($arr)
219         {
220                 $this->array_Header[] = $arr;
221         }
223         /*! \brief Add additional List element */
224         function AddElement($arr)
225         {
226                 $this->array_Elements[] = $arr;
227         }
230   /*! \brief Return default header part.
231    * Returns the default header part (with back, home and root icons and
232    * department selection)
233    *
234    * \param boolean 'seperator' Show a seperator between each button (default: true)
235    * */
236   function get_default_header($seperator= TRUE)
237   {
238     $enable_back = TRUE;
239     $enable_root = TRUE;
240     $enable_home = TRUE;
242     $ui = get_userinfo();
244     /* Check if selectedBase = first available base */
245     $deps = $ui->get_module_departments($this->module);
247     if(!count($deps) || $deps[0] == $this->selectedBase){
248       $enable_back = FALSE;
249       $enable_root = FALSE;
250     }
251   
252     $listhead ="";
253  
254     /* Check if we are in users home  department */ 
255     if(!count($deps) ||$this->selectedBase == get_base_from_people($ui->dn)){
256       $enable_home = FALSE;
257     }
259     /* Draw root button */
260     if($enable_root){
261       $listhead .= " <input class='center' type='image' src='images/lists/root.png' align='middle'
262         title='"._("Go to root department")."' name='dep_root' alt='"._("Root")."'>&nbsp;";
263     }else{
264       $listhead .= " <img src='images/lists/root_grey.png' class='center' alt='"._("Root")."'>&nbsp;";
265     }
267     /* Draw back button */
268     if($enable_back){
269       $listhead .= " <input class='center' type='image' align='middle' src='images/lists/back.png'
270         title='"._("Go up one department")."' alt='"._("Up")."'                name='dep_back'>&nbsp;";
271     }else{
272       $listhead .= " <img src='images/lists/back_grey.png' class='center' alt='"._("Up")."'>&nbsp;";
273     }
275     /* Draw home button */
276     if($enable_home){
277       $listhead .= " <input class='center' type='image' align='middle' src='images/lists/home.png'
278         title='"._("Go to users department")."' alt='"._("Home")."'            name='dep_home'>&nbsp;";
279     }else{
280       $listhead .= " <img src='images/lists/home_grey.png' class='center' alt='"._("Home")."'>&nbsp;";
281     }
282    
283     /* And at least draw reload button, this button is enabled everytime */ 
284     $listhead .=  " <input class='center' type='image' src='images/lists/reload.png' align='middle'
285       title='"._("Reload list")."' name='submit_department' alt='"._("Submit")."'>&nbsp;";
286     if ($seperator){
287       $listhead.= " <img   class='center' src='images/lists/seperator.png' align='middle' alt='-' height='16' width='1'>&nbsp;";
288     }
289     return ($listhead);
290   }
292   /*! \brief Add a checkbox to the filter element
293    *
294    * \param string 'name' specifies an existing class var to store the 'selection'
295    * */
296         function AddCheckBox($name,$value="Unset",$string="Unset",$default=false)
297         {
298                 $arr = array();
300                 if($name == SEPERATOR){
301                         $arr['name'] = SEPERATOR;
302                 }else{
303                         /* Check if there was already a variable 
304                            for this dialog which we should use instead of the default*/
305       $MultiDialogFilters = session::get('MultiDialogFilters');
306                         if(isset($MultiDialogFilters[$this->filterName][$name])){
307                                 $arr['default'] = $MultiDialogFilters[$this->filterName][$name];
308                                 $this->$name = $arr['default'];
309                         }else{
310                                 $arr['default'] = $default; 
311         $this->$name = $default;
312                         }
313                         $arr['name']          = $name;
314                         $arr['string']      = $string;
315                         $arr['value']         = $value;
316                         $arr['enabled']     = true;
318                 }
319                 $this->array_Checkboxes[] = $arr;
320         }
323         /*! \brief Hides or unhides the checkbox with the given name */
324         function DisableCheckBox($name,$HideShow = false)
325         {
326                 foreach($this->array_Checkboxes as $key => $chkbox){
327                         if($chkbox['name'] == $name){
328                                 $this->array_Checkboxes[$key]['enabled'] = $HideShow;
329                         }
330                 }
331         }
334         /*! \brief Returns true if the close button was pressed */
335         function isClosed()
336         {
337                 return($this->is_closed);
338         }
340   
341   function SetListFooter($str){
342     $this->footer = $str;
343   }
346         /*! \brief Enable the close button */
347         function EnableCloseButton($bool)
348         {
349                 $this->bool_DisplayCloseButton = $bool;
350         }
352         /*! \brief Enable the save button on the bottom of the list*/
353         function EnableSaveButton ($bool)
354         {
355                 $this->bool_DisplaySaveButton = $bool;
356         }
358   /*! \brief Add a list specific filter object to position 
359       1 on top of Information 
360       2 Between Information && Filter
361       3 Below the Filter Part */
362   function AddUserBoxToFilter($position)
363   {
364     return("");
365   }
367   function EnableJSLeaveMsg($ignore = TRUE)
368   {
369     $this->IgnoreAccount = !$ignore;
370   }
372         /*! \brief Draw the list with all list elements and filters */
373         function Draw()
374         {
376                 /* Check for exeeded sizelimit */
377                 if (($message= check_sizelimit()) != ""){
378                         return($message);
379                 }
381                 $smarty = get_smarty();
382                 $smarty->assign("UserBox1",$this->AddUserBoxToFilter(1));
383                 $smarty->assign("UserBox2",$this->AddUserBoxToFilter(2));
384                 $smarty->assign("UserBox3",$this->AddUserBoxToFilter(3));
386                 $divlist = new divlist($this->string_Title);
387                 $divlist->SetSummary($this->string_Summary);
388                 $divlist->SetEntriesPerPage(0); // 0 for scrollable list
390     /* Display list footer with summary of all listed entries */
391     if ($this->config->get_cfg_value("listSummary") == "true"){
392       $divlist->SetFooter($this->get_List_Bottom_Info());
393     }
394   
395     if($this->DivHeight != ""){
396       $divlist->SetHeight($this->DivHeight);
397     }
399                 /* set Header informations 
400                  */
401                 $header = array();
402                 foreach($this->array_Header as $head){
403                         $header[] = $head;
404                 }
405                 $divlist->SetHeader($header);
407                 /* set Entries 
408                  */
409                 $elements = array();
410                 foreach($this->array_Elements as $element){
411                         $divlist->AddEntry($element);
412                 }
414                 /* Create checkboxes fields 
415                  */
416                 $boxes = "";
417                 $boxClick = " onClick='document.mainform.submit();' ";
418                 foreach($this->array_Checkboxes as $box){
420                         if($box['name'] == SEPERATOR){
421                                 $boxes .= "</td></tr></table><table style='width:100%;border-top:1px solid #B0B0B0;'><tr><td>";
422                                 continue;
423                         }
425                         /* Skip disabled boxes */
426                         if(!$box['enabled']) continue;
428                         /* Check if box is checked */
429                         if($box['default'] == true){
430                                 $boxes .="<input type='checkbox' name=\"".$box['name']."\" value='1' title=\"".htmlspecialchars($box['value'])."\" checked ".$boxClick.">&nbsp;".$box['string']."<br>";
431                         }else{
432                                 $boxes .="<input type='checkbox' name=\"".$box['name']."\" value='1' title=\"".htmlspecialchars($box['value'])."\" ".$boxClick.">&nbsp;".$box['string']."<br>";
433                         }
434                 }
435                 $smarty->assign("CheckBoxes", $boxes);
437                 /* Assign regex fields 
438                  */
439                 $regexes = "";
440                 foreach($this->array_Regexes as $regex){
441                         $regexes.="<table summary=\"\" style=\"width:100%;border-top:1px solid #B0B0B0;\">
442                                 <tr>
443                                 <td>
444                                 <label for=\"".$regex['name']."\">
445                                 <img alt=\"".$regex['string']."\" src=\"".$regex['image']."\" align=middle>
446                                 </label>
447                                 </td>
448                                 <td width=\"99%\">
449                                 <input id=\"".$regex['name']."\" type=\"text\" style='width:99%' name=\"".$regex['name']."\" maxlength='20'
450                                 value=\"".htmlspecialchars($regex['value'])."\" title=\"".htmlspecialchars($regex['string'])."\"> 
451                                 </td>
452                                 </tr>
453                                 </table>";
454                 }
455                 $smarty->assign("regexes"                       , $regexes );
457     /* Hide Filter Part if Requested or empty */
458     if((empty($boxes)) && (empty($regexes)) || ($this->HideFilterPart)){
459                   $smarty->assign("Skip_Filter_Part",   true);
460     }else{ 
461                   $smarty->assign("Skip_Filter_Part",   false);
462     }
464                 /* Assign alphabet and display it 
465                  */     
466                 $smarty->assign("Display_alphabet",     $this->bool_DisplayAlpahabet);
467                 $smarty->assign("alphabet",             generate_alphabet());
468                 $smarty->assign("Header"                        , $this->string_ListHeader);
469                 $smarty->assign("HeaderDropDown", $this->GetDropDownHeaderMenu());
470                 $smarty->assign("Summary"                       , $this->string_Summary);
471                 $smarty->assign("Title"                         , $this->string_Title);
472                 $smarty->assign("Information"           , $this->string_Information);
473                 $smarty->assign("IgnoreAccount"         , $this->IgnoreAccount);
474     $smarty->assign("POST_ID", $this->post_id);
476                 /* Check for exeeded sizelimit */
477                 $smarty->assign("hint"                          , print_sizelimit_warning());
478                 $smarty->assign("DivList"                       , $divlist->DrawList()."\n\n\n\n\n".$this->footer."\n\n\n\n\n");
480                 if($this->is_headpage){
481                         $smarty->assign("tree_image",           get_template_path('images/lists/search-subtree.png'));
482                         $smarty->assign("infoimage",            get_template_path('images/info.png'));
483                         $smarty->assign("launchimage",          get_template_path('images/launch.png'));
484                         $smarty->assign("apply",                        apply_filter());
485                 }else{
486                         $smarty->assign("tree_image",           get_template_path('images/lists/search-subtree.png'));
487                         $smarty->assign("infoimage",            get_template_path('images/info_small.png'));
488                         $smarty->assign("launchimage",          get_template_path('images/rocket.png'));
489                         $smarty->assign("apply",                        apply_filter());
490                 }
492                 /* Button handling */
493                 $smarty->assign("SaveButtonString" ,$this->SaveButtonString);
494                 $smarty->assign("CloseButtonString",$this->CloseButtonString);
496                 $smarty->assign("Display_Close",        $this->bool_DisplayCloseButton);
497                 $smarty->assign("Display_Save" ,        $this->bool_DisplaySaveButton);
499                 $smarty->assign("filterName"    ,       $this->filterName);
500                 $smarty->assign("is_headpage"   ,       $this->is_headpage);
502                 $display = $smarty->fetch(get_template_path("MultiSelectWindow.tpl"));
503                 return($display);
504         }
506   /*! \brief Set the close var (simulates a press of the the close button) */
507         function Close()
508         {
509                 $this->is_closed = true;
510         }
512         function Save()
513         {
514                 $this->is_saved = true;
515         }
517   /*! \brief Store all checkboxes/ regexes ... 
518    *
519    * Store data also into a session var, to keep the checkboxes check after reload
520    */
521         function save_object()
522         {
524     /* Ensure that we do not handle posts for other dialogs 
525      */
526     if((isset($_POST['POST_ID']) && $_POST['POST_ID'] != $this->post_id) || 
527        (isset($_GET['post_id']) && $_GET['post_id'] != $this->post_id)){
528       return;
529     }
531     /* Get up to date config */
532     if(isset($this->parent->config)){
533       $this->config = $this->parent->config;
534     }
536     /* Update current base */
537     $s_action ="";
538     foreach($_POST as $key => $value){
539       if(preg_match("/^dep_back.*/i",$key)){
540         $s_action="back";
541       }elseif(preg_match("/^dep_root.*/",$key)){
542         $s_action="root";
543       }elseif(preg_match("/^dep_home.*/i",$key)){
544         $s_action="home";
545       }
546     }
548     /* Save base selection from headpage selectbox*/
549     if(isset($_POST['CurrentMainBase'])){
550       $this->selectedBase = $_POST['CurrentMainBase'];
551     }
553     /* Homebutton is posted */
554     if($s_action=="home"){
555       $ui= get_userinfo();
556       $base = get_base_from_people($ui->dn);
557       $this->selectedBase= $base;
558     }
560     /* Open selected department
561        this is posted by the parent class MultiSelectWindow */
562     if(isset($_GET['act'])&& ($_GET['act'] == "dep_open")){
563       $s_entry = $_GET['dep_id'];
564       if (!isset($this->departments[$s_entry])){
566         msg_dialog::display(_("LDAP error"), sprintf(_("Inconsistent DN encoding detected: '%s'"), LDAP::fix($s_entry)), ERROR_DIALOG);
567       } else {
568         $this->selectedBase = $this->departments[$s_entry]['dn'];
569       }
570     }
572     /* back to the roots ^^ */
573     if($s_action=="root"){
574       $this->selectedBase=($this->config->current['BASE']);
575       $dep_id = $this->ui->get_module_departments($this->module);
576       if(isset($dep_id[key($dep_id)])){
577         $this->selectedBase = $dep_id[key($dep_id)];
578       }
579     }
581     /* If Back-button is pressed, move back one step in DN */
582     if($s_action=="back"){
585       /* Get parent deprtment and check if we are allowed to step in it */
586       $base_back= preg_replace("/^[^,]+,/", "", $this->selectedBase);
587       $dep_id = $this->ui->get_module_departments($this->module);
588       if(in_array_ics($base_back,$dep_id)){
589         if(in_array($base_back,$this->config->departments)){
590           $this->selectedBase = $base_back;
591         }
592       }
593     }
595                 if(isset($_POST['MultiSelectWindow'.$this->filterName])){
597       /* Save some additional vars */
598       $MultiDialogFilters = session::get('MultiDialogFilters');
599       foreach($this->SaveAdditionalVars as $name){
600         if(isset($_POST[$name])){
601           if(isset($this->$name)){
602             $this->$name = $_POST[$name];
603             $MultiDialogFilters[$this->filterName][$name] = $_POST[$name];
604           }
605         }
606       }
607       session::set('MultiDialogFilters',$MultiDialogFilters);
609                         /* Check posts from checkboxes 
610                          */
611                         foreach($this->array_Checkboxes as $key => $box){
612                                 if(isset($_POST[$box['name']])){
613                                         $this->array_Checkboxes[$key]['default'] = true;
614                                         $this->$box['name'] = true;
615                                 }else{
616                                         $this->array_Checkboxes[$key]['default'] = false;
617                                         $this->$box['name'] = false;
618                                 }
620                                 /* Save settings in out session */
621         $MultiDialogFilters = session::get('MultiDialogFilters');
622                                 $MultiDialogFilters[$this->filterName][$box['name']] = $this->$box['name'];
623         session::set('MultiDialogFilters',$MultiDialogFilters);
624                         }
626                         /* Check regex posts */
627                         foreach($this->array_Regexes as $key => $box){
628                                 $this->array_Regexes[$key]['value'] = $_POST[$box['name']];
629                                 $this->$box['name'] = $_POST[$box['name']];
630         $MultiDialogFilters = session::get('MultiDialogFilters');
631                                 $MultiDialogFilters[$this->filterName][$box['name']] = $this->$box['name'];
632         session::set('MultiDialogFilters',$MultiDialogFilters);
633                         }
635                         /* call close/save if buttons are pressed */
636                         if(isset($_POST['CloseMultiSelectWindow'])){
637                                 $this->Close();
638                         }
640                         if(isset($_POST['SaveMultiSelectWindow'])){
641                                 $this->Save();
642                         }
643                 }
645                 /* check for alphabet selection
646                    Check which regexes are connected to the alphabet 
647                  */     
648                 if(isset($_GET['search'])){
649                         foreach($this->array_Regexes as $key => $box){
650                                 /* check if this regex is connected to the alphabet selection */
651                                 if(($box['connAlpha'])&&(isset($_GET['search']))){
652                                         $val =  $_GET['search']."*";
653                                         $val = preg_replace("/\*\**/","*",$val);
654                                         $this->array_Regexes[$key]['value'] = $val;
655                                         $this->$box['name'] = $val;
656           $MultiDialogFilters = session::get('MultiDialogFilters');
657           $MultiDialogFilters[$this->filterName][$box['name']] =  $val;
658           session::set('MultiDialogFilters',$MultiDialogFilters);
659                                 }
660                         }
661                 }
663     /* Save currenlty selected base in session */
664     session::global_set("CurrentMainBase",$this->selectedBase);
665         }
668   /*! \brief Adds the sub-departments of the current tree to the list
669    *
670    *
671    * \param mixed 'base' use a certain base or FALSE if $this->selectedBase should
672    * be used (default).
673    */
674         function AddDepartments($base = false,$numtabs = 3,$empty_tabs_in_front = 0)
675         {
676                 $this->DepartmentsAdded = true;
677     $this->Added_Departments = array();
678     $this->departments = array();
680     if(isset($this->Regex)){
681       $this->base_selection_regex = $this->Regex;
682     }
684                 $linkopen = "<a href='?plug=".$_GET['plug']."&amp;post_id=".$this->post_id."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
685     $types = departmentManagement::get_support_departments();
686     $ui = get_userinfo();
687     $module_deps = $ui->get_module_departments($this->module);
688     $found_deps = array();
690                 /* check for a valid base */
691                 if(!$base){
692       $base = $this->selectedBase;
693                 }
695                 /* Create ldap obj and switch into base*/
696                 $ldap = $this->config->get_ldap_link();
697                 $ldap->cd($base);
699                 /* Get all departments within this subtree */
700     $s_filter = "";
701     $s_attrs  = array("description","objectClass");
702     $s_acls   = $this->module;
703     foreach($types as $name => $data){
704       $s_filter.= "(&(objectClass=gosaDepartment)(objectClass=".$data['OC'].")(".$data['ATTR']."=".$this->base_selection_regex."))";
705       $s_attrs[]= $data['ATTR']; 
706     }
708     $tmp = get_list("(|".$s_filter.")",$s_acls,$this->selectedBase,$s_attrs,GL_NONE | GL_SIZELIMIT);
709     foreach($tmp as $attrs){
710       foreach($types as $name => $data){
711         if(in_array($data['OC'],$attrs['objectClass']) && isset($attrs[$data['ATTR']][0])){
712           $attrs['NAME'] = $attrs[$data['ATTR']][0];
713           $attrs['TYPE'] = $data;
714           $name = $attrs['NAME']." ".$attrs['dn'];
715           $departments[$name] = $attrs;
716           $found_deps[$name] = $attrs['dn'];
717           break;
718         }
719       }
720     }
722     /* Detect allowed departments 
723      */
724     $deps = array_intersect($found_deps,$module_deps);
725     uksort($deps, 'strnatcasecmp');
726     $key = 0;
727     foreach($deps as $name => $dn){
728       $key ++;
729       $val = $departments[$name];
730       $this->departments[$key] = $val;
731       $img = "<image src='".$val['TYPE']['IMG']."' class='center'>";
733                         /* Add spacer cols to divlist 
734        */
735                         $row = array();
736       if($empty_tabs_in_front){
737         for($i = 0; $i < $empty_tabs_in_front ; $i ++){
738           $row[] = array("string"=>"&nbsp;", "attach" => "style='text-align:center;width:20px;'");
739         }
740       }
742       /* Create entry name 
743        */
744       $name = $val['NAME'];
745       if(isset($val['description'])){
746         $name .=  " - [".$val["description"][0]."]";
747       }
749       /* Add departments
750        */
751                         $row[]=array("string"=> $img,"attach"=>"style='text-align:center;width:20px;'");
752                         $row[]=array("string"=>sprintf($linkopen,$key,$name), "attach" => "style=''");
754       /* Add spacer tabs 
755        */
756                         if($numtabs > 2){       
757                                 for($i = 2 ; $i < $numtabs;$i++){
758           if(isset( $this->array_Header[$i + $empty_tabs_in_front]['attach'])){
759             $row[] = array("string"=>"&nbsp;","attach" => $this->array_Header[$i + $empty_tabs_in_front]['attach']);
760           }else{
761             $row[] = array("string"=>"&nbsp;");
762           }
763                                 }
764                         }
765                         $this->AddElement($row);
766       $this->Added_Departments[] = $row;
767                 }
768         }
771   function create_department_list($modules)
772   { 
773     $departments = array();
774     $ui= get_userinfo();
775     $first = "";
776     $found = FALSE;
777     $options ="";
779     $ids = $this->config->idepartments;
780     $d   = $ui->get_module_departments($modules);
781     $k_ids = array_keys($ids);
782     $deps = array_intersect($d,$k_ids);
783     foreach($k_ids as $department){
784       $departments[$department] = $ids[$department];
785     }
787     foreach($departments as $value => $name){
789       /* Keep first base dn in mind, we could need this
790        *  info if no valid base was found
791        */
792       if(empty($first)) {
793         $first = $value;
794       }
796       if ($this->selectedBase == $value){
797         $found = TRUE;
798         $options.= "<option selected='selected' value='".$value."'>$name</option>";
799       } else {
800         $options.= "<option value='".$value."'>$name</option>";
801       }
802     }
804     /* The currently used base is not visible with your acl setup.
805      * Set base to first useable base.
806      */
807     if(!$found){
808       $this->selectedBase = $first;
809     }
811     return($options);
812   }
814   function set_List_Bottom_Info($str)
815   {
816     $this->List_Bottom_Info = $str;
817   }
819   function get_List_Bottom_Info()
820   {
821     return($this->List_Bottom_Info); 
822   }
824 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
825 ?>