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