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