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 /*! \brief If this is set to TRUE the Draw() function returns a smarty object */
74 var $DrawReturnsSmartyObject = FALSE;
77 function ClearElementsList()
78 {
79 $ui =get_userinfo();
80 $deps = $ui->get_module_departments($this->module);
81 if(!in_array($this->selectedBase, $deps)){
82 $this->selectedBase = array_shift($deps);
83 }
84 $this->array_Elements = array();
85 }
87 function HideFilterPart($bool = true)
88 {
89 $this->HideFilterPart = $bool;
90 }
92 /*! \brief Set the height of the divlist */
93 function SetHeight($height)
94 {
95 $this->DivHeight=$height;
96 }
98 /* Adds a regex input field to the current dialog */
99 function AddRegex($name,$string,$value,$conn,$image="images/lists/search.png", $return_array=FALSE)
100 {
101 $arr = array();
103 /* Check if the given input field name was already used
104 for this type of dialog */
105 $MultiDialogFilters = session::get('MultiDialogFilters');
106 if(isset($MultiDialogFilters[$this->filterName][$name])){
107 $arr['value'] = $MultiDialogFilters[$this->filterName][$name];
108 $this->$name = $arr['value'];
109 }else{
110 $arr['value'] = $value;
111 }
113 $arr['name'] = $name;
114 $arr['string'] = $string;
115 $arr['image'] = $image;
116 $arr['connAlpha'] = $conn; // Connect with alphabet select
117 if (!$return_array) {
118 $this->array_Regexes[] = $arr;
119 }
120 else {
121 return($arr);
122 }
123 }
126 function SetDropDownHeaderMenu($str)
127 {
128 $this->string_ListDropDown = $str;
129 }
131 function GetDropDownHeaderMenu()
132 {
133 if(!empty($this->string_ListDropDown)){
134 $mid = new LayersMenu(6, 7, 2, 1);
135 $mid->setImgwww("./images/layer_menu/");
136 $mid->setIcondir("./images/layer_menu/");
137 $mid->setDirroot("../include/utils/layer-menu/");
138 $mid->setHorizontalMenuTpl("../ihtml/".get_template_path("",FALSE).'GOsa_MultiSelectHeader.ihtml');
139 $mid->setSubMenuTpl("../ihtml/".get_template_path("",FALSE).'GOsa_MultiSelectHeaderSubEntry.ihtml');
140 $mid->setMenuStructureString($this->string_ListDropDown);
141 $mid->parseStructureForMenu('menu');
142 $mid->newHorizontalMenu('menu');
143 $s = $mid->getHeader();
144 $s.= $mid->getMenu('menu');
145 $s.= $mid->getFooter('menu');
146 return($s);
147 }else{
148 return("");
149 }
150 }
153 /* Contrucktion */
154 function MultiSelectWindow(&$config, $filterName, $module)
155 {
156 $this->config = &$config;
157 $this->module = $module;
158 $this->SaveButtonString = _("Save");
159 $this->CloseButtonString = _("Close");
160 $this->filterName = $filterName;
161 $this->ui = get_userinfo();
162 $this->post_id = preg_replace("/[^0-9]/","",microtime(TRUE));
163 $this->selectedBase = session::get('CurrentMainBase');
165 /* Check default values for SaveAdditionalVars */
166 $MultiDialogFilters = session::get('MultiDialogFilters');
167 foreach($this->SaveAdditionalVars as $name){
168 if(isset($MultiDialogFilters[$this->filterName][$name])){
169 $this->$name = $MultiDialogFilters[$this->filterName][$name];
170 }
171 }
173 }
175 /* Enables the headpage mode, which changes the list look */
176 function SetHeadpageMode()
177 {
178 $this->is_headpage = true;
179 }
181 /* \brief Sets the List internal name (not displayed anywhere)
183 It is used to identify every single list.
184 */
185 function SetTitle($str)
186 {
187 $this->string_Title = $str;
188 }
190 /*! \brief Set the list header string */
191 function SetListHeader($str)
192 {
193 $this->string_ListHeader = $str;
194 }
196 /*! \brief This sets the list description which is the first gray bar on top of the list */
197 function SetSummary($str)
198 {
199 $this->string_Summary = $str;
200 }
202 /*! \brief Change the caption of the save button (if it is enabled) */
203 function SetSaveButtonString($str)
204 {
205 $this->SaveButtonString = $str;
206 }
208 /*! \brief Change the caption of the close button (if it is enabled) */
209 function SetCloseButtonString($str)
210 {
211 $this->CloseButtonString = $str;
212 }
214 /*! \brief Change the text of the information box */
215 function SetInformation($str)
216 {
217 $this->string_Information = $str;
218 }
220 /*! \brief Toggle the alphabet selection display */
221 function EnableAplhabet($bool)
222 {
223 $this->bool_DisplayAlpahabet = $bool;
224 }
226 /*! \brief Add additional header col */
227 function AddHeader($arr)
228 {
229 $this->array_Header[] = $arr;
230 }
232 /*! \brief Add additional List element */
233 function AddElement($arr)
234 {
235 $this->array_Elements[] = $arr;
236 }
239 /*! \brief Return default header part.
240 * Returns the default header part (with back, home and root icons and
241 * department selection)
242 *
243 * \param boolean 'seperator' Show a seperator between each button (default: true)
244 * */
245 function get_default_header($seperator= TRUE)
246 {
247 $enable_back = TRUE;
248 $enable_root = TRUE;
249 $enable_home = TRUE;
251 $ui = get_userinfo();
253 /* Check if selectedBase = first available base */
254 $deps = $ui->get_module_departments($this->module);
256 if(!count($deps) || $deps[0] == $this->selectedBase){
257 $enable_back = FALSE;
258 $enable_root = FALSE;
259 }
261 $listhead ="";
263 /* Check if we are in users home department */
264 if(!count($deps) ||$this->selectedBase == get_base_from_people($ui->dn)){
265 $enable_home = FALSE;
266 }
268 /* Draw root button */
269 if($enable_root){
270 $listhead .= " <input class='center' type='image' src='images/lists/root.png' align='middle'
271 title='"._("Go to root department")."' name='dep_root' alt='"._("Root")."'> ";
272 }else{
273 $listhead .= " <img src='images/lists/root_grey.png' class='center' alt='"._("Root")."'> ";
274 }
276 /* Draw back button */
277 if($enable_back){
278 $listhead .= " <input class='center' type='image' align='middle' src='images/lists/back.png'
279 title='"._("Go up one department")."' alt='"._("Up")."' name='dep_back'> ";
280 }else{
281 $listhead .= " <img src='images/lists/back_grey.png' class='center' alt='"._("Up")."'> ";
282 }
284 /* Draw home button */
285 if($enable_home){
286 $listhead .= " <input class='center' type='image' align='middle' src='images/lists/home.png'
287 title='"._("Go to users department")."' alt='"._("Home")."' name='dep_home'> ";
288 }else{
289 $listhead .= " <img src='images/lists/home_grey.png' class='center' alt='"._("Home")."'> ";
290 }
292 /* And at least draw reload button, this button is enabled everytime */
293 $listhead .= " <input class='center' type='image' src='images/lists/reload.png' align='middle'
294 title='"._("Reload list")."' name='submit_department' alt='"._("Submit")."'> ";
295 if ($seperator){
296 $listhead.= " <img class='center' src='images/lists/seperator.png' align='middle' alt='-' height='16' width='1'> ";
297 }
298 return ($listhead);
299 }
301 /*! \brief Add a checkbox to the filter element
302 *
303 * \param string 'name' specifies an existing class var to store the 'selection'
304 * */
305 function AddCheckBox($name,$value="Unset",$string="Unset",$default=false)
306 {
307 $arr = array();
309 if($name == SEPERATOR){
310 $arr['name'] = SEPERATOR;
311 }else{
312 /* Check if there was already a variable
313 for this dialog which we should use instead of the default*/
314 $MultiDialogFilters = session::get('MultiDialogFilters');
315 if(isset($MultiDialogFilters[$this->filterName][$name])){
316 $arr['default'] = $MultiDialogFilters[$this->filterName][$name];
317 $this->$name = $arr['default'];
318 }else{
319 $arr['default'] = $default;
320 $this->$name = $default;
321 }
322 $arr['name'] = $name;
323 $arr['string'] = $string;
324 $arr['value'] = $value;
325 $arr['enabled'] = true;
327 }
328 $this->array_Checkboxes[] = $arr;
329 }
332 /*! \brief Hides or unhides the checkbox with the given name */
333 function DisableCheckBox($name,$HideShow = false)
334 {
335 foreach($this->array_Checkboxes as $key => $chkbox){
336 if($chkbox['name'] == $name){
337 $this->array_Checkboxes[$key]['enabled'] = $HideShow;
338 }
339 }
340 }
343 /*! \brief Returns true if the close button was pressed */
344 function isClosed()
345 {
346 return($this->is_closed);
347 }
350 function SetListFooter($str){
351 $this->footer = $str;
352 }
355 /*! \brief Enable the close button */
356 function EnableCloseButton($bool)
357 {
358 $this->bool_DisplayCloseButton = $bool;
359 }
361 /*! \brief Enable the save button on the bottom of the list*/
362 function EnableSaveButton ($bool)
363 {
364 $this->bool_DisplaySaveButton = $bool;
365 }
367 /*! \brief Add a list specific filter object to position
368 1 on top of Information
369 2 Between Information && Filter
370 3 Below the Filter Part */
371 function AddUserBoxToFilter($position)
372 {
373 return("");
374 }
376 function EnableJSLeaveMsg($ignore = TRUE)
377 {
378 $this->IgnoreAccount = !$ignore;
379 }
381 function GetCheckbox($box, $start_table=FALSE)
382 {
383 $ret = "";
384 $boxClick = " onClick='document.mainform.submit();' ";
385 if($box['name'] == SEPERATOR){
386 $ret = "</td></tr></table><table style='width:100%;border-top:1px solid #B0B0B0;'><tr><td>";
387 return($ret);
388 }
391 /* Skip disabled boxes */
392 if(!$box['enabled']) return;
394 /* Check if box is checked */
395 if($box['default'] == true){
396 $ret .="<input type='checkbox' name=\"".$box['name']."\" value='1' title=\"".htmlspecialchars($box['value'])."\" checked ".$boxClick."> ".$box['string']."<br>";
397 }else{
398 $ret .="<input type='checkbox' name=\"".$box['name']."\" value='1' title=\"".htmlspecialchars($box['value'])."\" ".$boxClick."> ".$box['string']."<br>";
399 }
401 return($ret);
402 }
404 function GetRegex($regex, $draw_line=TRUE)
405 {
406 $ret = "";
407 $line_css = "";
408 if ($draw_line) {
409 $line_css = "solid #B0B0B0;";
410 }
411 $ret="<table summary=\"\" style=\"width:100%;border-top:1px $line_css\">
412 <tr>
413 <td>
414 <label for=\"".$regex['name']."\">
415 <img alt=\"".$regex['string']."\" src=\"".$regex['image']."\" align=middle>
416 </label>
417 </td>
418 <td width=\"99%\">
419 <input id=\"".$regex['name']."\" type=\"text\" style='width:99%' name=\"".$regex['name']."\" maxlength='20'
420 value=\"".htmlspecialchars($regex['value'])."\" title=\"".htmlspecialchars($regex['string'])."\">
421 </td>
422 </tr>
423 </table>";
425 return($ret);
426 }
429 /*! \brief Draw the list with all list elements and filters
430 *
431 * Returns a string with the HTML code that should be displayed.
432 * If this->DrawReturnsSmartyObject is TRUE (default: FALSE) it
433 * returns a smarty object.
434 * */
435 function Draw()
436 {
438 /* Check for exeeded sizelimit */
439 if (($message= check_sizelimit()) != ""){
440 return($message);
441 }
443 $smarty = get_smarty();
444 $smarty->assign("UserBox1",$this->AddUserBoxToFilter(1));
445 $smarty->assign("UserBox2",$this->AddUserBoxToFilter(2));
446 $smarty->assign("UserBox3",$this->AddUserBoxToFilter(3));
448 $divlist = new divlist($this->string_Title);
449 $divlist->SetSummary($this->string_Summary);
450 $divlist->SetEntriesPerPage(0); // 0 for scrollable list
452 /* Display list footer with summary of all listed entries */
453 if ($this->config->get_cfg_value("listSummary") == "true"){
454 $divlist->SetFooter($this->get_List_Bottom_Info());
455 }
457 if($this->DivHeight != ""){
458 $divlist->SetHeight($this->DivHeight);
459 }
461 /* set Header informations
462 */
463 $header = array();
464 foreach($this->array_Header as $head){
465 $header[] = $head;
466 }
467 $divlist->SetHeader($header);
469 /* set Entries
470 */
471 $elements = array();
472 foreach($this->array_Elements as $element){
473 $divlist->AddEntry($element);
474 }
476 /* Create checkboxes fields
477 */
478 $boxes = "";
479 foreach($this->array_Checkboxes as $box){
480 $boxes .= $this->GetCheckbox($box);
481 }
482 $smarty->assign("CheckBoxes", $boxes);
484 /* Assign regex fields
485 */
486 $regexes = "";
487 foreach($this->array_Regexes as $regex){
488 $regexes .= $this->GetRegex($regex);
489 }
490 $smarty->assign("regexes" , $regexes );
492 /* Hide Filter Part if Requested or empty */
493 if((empty($boxes)) && (empty($regexes)) || ($this->HideFilterPart)){
494 $smarty->assign("Skip_Filter_Part", true);
495 }else{
496 $smarty->assign("Skip_Filter_Part", false);
497 }
499 /* Assign alphabet and display it
500 */
501 $smarty->assign("Display_alphabet", $this->bool_DisplayAlpahabet);
502 $smarty->assign("alphabet", generate_alphabet());
503 $smarty->assign("Header" , $this->string_ListHeader);
504 $smarty->assign("HeaderDropDown", $this->GetDropDownHeaderMenu());
505 $smarty->assign("Summary" , $this->string_Summary);
506 $smarty->assign("Title" , $this->string_Title);
507 $smarty->assign("Information" , $this->string_Information);
508 $smarty->assign("IgnoreAccount" , $this->IgnoreAccount);
509 $smarty->assign("POST_ID", $this->post_id);
511 /* Check for exeeded sizelimit */
512 $smarty->assign("hint" , print_sizelimit_warning());
513 $smarty->assign("DivList" , $divlist->DrawList()."\n\n\n\n\n".$this->footer."\n\n\n\n\n");
515 if($this->is_headpage){
516 $smarty->assign("tree_image", get_template_path('images/lists/search-subtree.png'));
517 $smarty->assign("infoimage", get_template_path('images/info.png'));
518 $smarty->assign("launchimage", get_template_path('images/launch.png'));
519 $smarty->assign("apply", apply_filter());
520 }else{
521 $smarty->assign("tree_image", get_template_path('images/lists/search-subtree.png'));
522 $smarty->assign("infoimage", get_template_path('images/info_small.png'));
523 $smarty->assign("launchimage", get_template_path('images/rocket.png'));
524 $smarty->assign("apply", apply_filter());
525 }
527 /* Button handling */
528 $smarty->assign("SaveButtonString" ,$this->SaveButtonString);
529 $smarty->assign("CloseButtonString",$this->CloseButtonString);
531 $smarty->assign("Display_Close", $this->bool_DisplayCloseButton);
532 $smarty->assign("Display_Save" , $this->bool_DisplaySaveButton);
534 $smarty->assign("filterName" , $this->filterName);
535 $smarty->assign("is_headpage" , $this->is_headpage);
537 if (!$this->DrawReturnsSmartyObject) {
538 $display = $smarty->fetch(get_template_path("MultiSelectWindow.tpl"));
539 return($display);
540 }
541 else {
542 return($smarty);
543 }
544 }
546 /*! \brief Set the close var (simulates a press of the the close button) */
547 function Close()
548 {
549 $this->is_closed = true;
550 }
552 function Save()
553 {
554 $this->is_saved = true;
555 }
557 /*! \brief Store all checkboxes/ regexes ...
558 *
559 * Store data also into a session var, to keep the checkboxes check after reload
560 */
561 function save_object()
562 {
564 /* Ensure that we do not handle posts for other dialogs
565 */
566 if((isset($_POST['POST_ID']) && $_POST['POST_ID'] != $this->post_id) ||
567 (isset($_GET['post_id']) && $_GET['post_id'] != $this->post_id)){
568 return;
569 }
571 /* Get up to date config */
572 if(isset($this->parent->config)){
573 $this->config = $this->parent->config;
574 }
576 /* Update current base */
577 $s_action ="";
578 foreach($_POST as $key => $value){
579 if(preg_match("/^dep_back.*/i",$key)){
580 $s_action="back";
581 }elseif(preg_match("/^dep_root.*/",$key)){
582 $s_action="root";
583 }elseif(preg_match("/^dep_home.*/i",$key)){
584 $s_action="home";
585 }
586 }
588 /* Save base selection from headpage selectbox*/
589 if(isset($_POST['CurrentMainBase'])){
590 $this->selectedBase = $_POST['CurrentMainBase'];
591 }
593 /* Homebutton is posted */
594 if($s_action=="home"){
595 $ui= get_userinfo();
596 $base = get_base_from_people($ui->dn);
597 $this->selectedBase= $base;
598 }
600 /* Open selected department
601 this is posted by the parent class MultiSelectWindow */
602 if(isset($_GET['act'])&& ($_GET['act'] == "dep_open")){
603 $s_entry = $_GET['dep_id'];
604 if (!isset($this->departments[$s_entry])){
606 msg_dialog::display(_("LDAP error"), sprintf(_("Inconsistent DN encoding detected: '%s'"), LDAP::fix($s_entry)), ERROR_DIALOG);
607 } else {
608 $this->selectedBase = $this->departments[$s_entry]['dn'];
609 }
610 }
612 /* back to the roots ^^ */
613 if($s_action=="root"){
614 $this->selectedBase=($this->config->current['BASE']);
615 $dep_id = $this->ui->get_module_departments($this->module);
616 if(isset($dep_id[key($dep_id)])){
617 $this->selectedBase = $dep_id[key($dep_id)];
618 }
619 }
621 /* If Back-button is pressed, move back one step in DN */
622 if($s_action=="back"){
625 /* Get parent deprtment and check if we are allowed to step in it */
626 $base_back= preg_replace("/^[^,]+,/", "", $this->selectedBase);
627 $dep_id = $this->ui->get_module_departments($this->module);
628 if(in_array_ics($base_back,$dep_id)){
629 if(in_array($base_back,$this->config->departments)){
630 $this->selectedBase = $base_back;
631 }
632 }
633 }
635 if(isset($_POST['MultiSelectWindow'.$this->filterName])){
637 /* Save some additional vars */
638 $MultiDialogFilters = session::get('MultiDialogFilters');
639 foreach($this->SaveAdditionalVars as $name){
640 if(isset($_POST[$name])){
641 if(isset($this->$name)){
642 $this->$name = $_POST[$name];
643 $MultiDialogFilters[$this->filterName][$name] = $_POST[$name];
644 }
645 }
646 }
647 session::set('MultiDialogFilters',$MultiDialogFilters);
649 /* Check posts from checkboxes
650 */
651 foreach($this->array_Checkboxes as $key => $box){
652 if(isset($_POST[$box['name']])){
653 $this->array_Checkboxes[$key]['default'] = true;
654 $this->$box['name'] = true;
655 }else{
656 $this->array_Checkboxes[$key]['default'] = false;
657 $this->$box['name'] = false;
658 }
660 /* Save settings in out session */
661 $MultiDialogFilters = session::get('MultiDialogFilters');
662 $MultiDialogFilters[$this->filterName][$box['name']] = $this->$box['name'];
663 session::set('MultiDialogFilters',$MultiDialogFilters);
664 }
666 /* Check regex posts */
667 foreach($this->array_Regexes as $key => $box){
668 $this->array_Regexes[$key]['value'] = $_POST[$box['name']];
669 $this->$box['name'] = $_POST[$box['name']];
670 $MultiDialogFilters = session::get('MultiDialogFilters');
671 $MultiDialogFilters[$this->filterName][$box['name']] = $this->$box['name'];
672 session::set('MultiDialogFilters',$MultiDialogFilters);
673 }
675 /* call close/save if buttons are pressed */
676 if(isset($_POST['CloseMultiSelectWindow'])){
677 $this->Close();
678 }
680 if(isset($_POST['SaveMultiSelectWindow'])){
681 $this->Save();
682 }
683 }
685 /* check for alphabet selection
686 Check which regexes are connected to the alphabet
687 */
688 if(isset($_GET['search'])){
689 foreach($this->array_Regexes as $key => $box){
690 /* check if this regex is connected to the alphabet selection */
691 if(($box['connAlpha'])&&(isset($_GET['search']))){
692 $val = $_GET['search']."*";
693 $val = preg_replace("/\*\**/","*",$val);
694 $this->array_Regexes[$key]['value'] = $val;
695 $this->$box['name'] = $val;
696 $MultiDialogFilters = session::get('MultiDialogFilters');
697 $MultiDialogFilters[$this->filterName][$box['name']] = $val;
698 session::set('MultiDialogFilters',$MultiDialogFilters);
699 }
700 }
701 }
703 /* Save currenlty selected base in session */
704 session::global_set("CurrentMainBase",$this->selectedBase);
705 }
708 /*! \brief Adds the sub-departments of the current tree to the list
709 *
710 *
711 * \param mixed 'base' use a certain base or FALSE if $this->selectedBase should
712 * be used (default).
713 */
714 function AddDepartments($base = false,$numtabs = 3,$empty_tabs_in_front = 0)
715 {
716 $this->DepartmentsAdded = true;
717 $this->Added_Departments = array();
718 $this->departments = array();
720 if(isset($this->Regex)){
721 $this->base_selection_regex = $this->Regex;
722 }
724 $linkopen = "<a href='?plug=".$_GET['plug']."&post_id=".$this->post_id."&act=dep_open&dep_id=%s'>%s</a>";
725 $types = departmentManagement::get_support_departments();
726 $ui = get_userinfo();
727 $module_deps = $ui->get_module_departments($this->module);
728 $found_deps = array();
730 /* check for a valid base */
731 if(!$base){
732 $base = $this->selectedBase;
733 }
735 /* Create ldap obj and switch into base*/
736 $ldap = $this->config->get_ldap_link();
737 $ldap->cd($base);
739 /* Get all departments within this subtree */
740 $s_filter = "";
741 $s_attrs = array("description","objectClass");
742 $s_acls = $this->module;
743 foreach($types as $name => $data){
744 $s_filter.= "(&(objectClass=gosaDepartment)(objectClass=".$data['OC'].")(".$data['ATTR']."=".$this->base_selection_regex."))";
745 $s_attrs[]= $data['ATTR'];
746 }
748 $tmp = get_list("(|".$s_filter.")",$s_acls,$this->selectedBase,$s_attrs,GL_NONE | GL_SIZELIMIT);
749 foreach($tmp as $attrs){
750 foreach($types as $name => $data){
751 if(in_array($data['OC'],$attrs['objectClass']) && isset($attrs[$data['ATTR']][0])){
752 $attrs['NAME'] = $attrs[$data['ATTR']][0];
753 $attrs['TYPE'] = $data;
754 $name = $attrs['NAME']." ".$attrs['dn'];
755 $departments[$name] = $attrs;
756 $found_deps[$name] = $attrs['dn'];
757 break;
758 }
759 }
760 }
762 /* Detect allowed departments
763 */
764 $deps = array_intersect($found_deps,$module_deps);
765 uksort($deps, 'strnatcasecmp');
766 $key = 0;
767 foreach($deps as $name => $dn){
768 $key ++;
769 $val = $departments[$name];
770 $this->departments[$key] = $val;
771 $img = "<image src='".$val['TYPE']['IMG']."' class='center'>";
773 /* Add spacer cols to divlist
774 */
775 $row = array();
776 if($empty_tabs_in_front){
777 for($i = 0; $i < $empty_tabs_in_front ; $i ++){
778 $row[] = array("string"=>" ", "attach" => "style='text-align:center;width:20px;'");
779 }
780 }
782 /* Create entry name
783 */
784 $name = $val['NAME'];
785 if(isset($val['description'])){
786 $name .= " - [".$val["description"][0]."]";
787 }
789 /* Add departments
790 */
791 $row[]=array("string"=> $img,"attach"=>"style='text-align:center;width:20px;'");
792 $row[]=array("string"=>sprintf($linkopen,$key,$name), "attach" => "style=''");
794 /* Add spacer tabs
795 */
796 if($numtabs > 2){
797 for($i = 2 ; $i < $numtabs;$i++){
798 if(isset( $this->array_Header[$i + $empty_tabs_in_front]['attach'])){
799 $row[] = array("string"=>" ","attach" => $this->array_Header[$i + $empty_tabs_in_front]['attach']);
800 }else{
801 $row[] = array("string"=>" ");
802 }
803 }
804 }
805 $this->AddElement($row);
806 $this->Added_Departments[] = $row;
807 }
808 }
811 function create_department_list($modules)
812 {
813 $departments = array();
814 $ui= get_userinfo();
815 $first = "";
816 $found = FALSE;
817 $options ="";
819 $ids = $this->config->idepartments;
820 $d = $ui->get_module_departments($modules);
821 $k_ids = array_keys($ids);
822 $deps = array_intersect($d,$k_ids);
823 foreach($k_ids as $department){
824 $departments[$department] = $ids[$department];
825 }
827 foreach($departments as $value => $name){
829 /* Keep first base dn in mind, we could need this
830 * info if no valid base was found
831 */
832 if(empty($first)) {
833 $first = $value;
834 }
836 if ($this->selectedBase == $value){
837 $found = TRUE;
838 $options.= "<option selected='selected' value='".$value."'>$name</option>";
839 } else {
840 $options.= "<option value='".$value."'>$name</option>";
841 }
842 }
844 /* The currently used base is not visible with your acl setup.
845 * Set base to first useable base.
846 */
847 if(!$found){
848 $this->selectedBase = $first;
849 }
851 return($options);
852 }
854 function set_List_Bottom_Info($str)
855 {
856 $this->List_Bottom_Info = $str;
857 }
859 function get_List_Bottom_Info()
860 {
861 return($this->List_Bottom_Info);
862 }
863 }
864 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
865 ?>