1 <?php
3 define ("SEPERATOR", 1002);
5 class MultiSelectWindow{
7 var $bool_DisplayAlpahabet = false;
8 var $bool_DisplayCloseButton= true;
9 var $bool_DisplaySaveButton = true;
11 var $SaveButtonString = "";
12 var $CloseButtonString = "";
14 var $string_Title = "";
15 var $string_ListHeader = "";
16 var $string_ListDropDown= "";
17 var $string_Summary = "";
18 var $string_Information = "";
20 var $array_Header = array();
21 var $array_Elements = array();
22 var $array_Checkboxes = array();
23 var $array_Regexes = array();
25 var $config = array("");
26 var $is_closed = false;
27 var $is_saved = false;
28 var $is_headpage = false; // if true the design changes
29 var $filterName = "Liste";
30 var $DepartmentsAdded = false;
31 var $Added_Departments = array();
32 var $selectedBase = "";
34 var $DivHeight = "";
36 var $HideFilterPart = false;
37 var $List_Bottom_Info = "";
38 var $SaveAdditionalVars = array(); // Additional Post vars to store
39 var $module= "";
41 function ClearElementsList()
42 {
43 $this->array_Elements = array();
44 }
46 function HideFilterPart($bool = true)
47 {
48 $this->HideFilterPart = $bool;
49 }
51 function SetHeight($height)
52 {
53 $this->DivHeight=$height;
54 }
56 /* Adds a regex input field to the current dialog */
57 function AddRegex($name,$string,$value,$conn,$image="images/search.png")
58 {
59 $arr = array();
61 /* Check if the given input field name was already used
62 for this type of dialog */
63 if(isset($_SESSION['MultiDialogFilters'][$this->filterName][$name])){
64 $arr['value'] = $_SESSION['MultiDialogFilters'][$this->filterName][$name];
65 $this->$name = $arr['value'];
66 }else{
67 $arr['value'] = $value;
68 }
70 $arr['name'] = $name;
71 $arr['string'] = $string;
72 $arr['image'] = $image;
73 $arr['connAlpha'] = $conn; // Connect with alphabet select
74 $this->array_Regexes[] = $arr;
75 }
78 function SetDropDownHeaderMenu($str)
79 {
80 $this->string_ListDropDown = $str;
81 }
83 function GetDropDownHeaderMenu()
84 {
85 if(!empty($this->string_ListDropDown)){
86 $mid = new LayersMenu(6, 7, 2, 1);
87 $mid->setImgwww("./images/");
88 $mid->setIcondir("./images/");
89 $mid->setDirroot("../include/php_layers_menu/");
90 $mid->setHorizontalMenuTpl("../ihtml/".get_template_path("",FALSE).'GOsa_MultiSelectHeader.ihtml');
91 $mid->setSubMenuTpl("../ihtml/".get_template_path("",FALSE).'GOsa_MultiSelectHeaderSubEntry.ihtml');
92 $mid->setMenuStructureString($this->string_ListDropDown);
93 $mid->parseStructureForMenu('menu');
94 $mid->newHorizontalMenu('menu');
95 $s = $mid->getHeader();
96 $s.= $mid->getMenu('menu');
97 $s.= $mid->getFooter('menu');
98 return($s);
99 }else{
100 return("");
101 }
102 }
105 /* Contrucktion */
106 function MultiSelectWindow(&$config, $filterName, $module)
107 {
108 $this->config = &$config;
109 $this->module = $module;
110 $this->SaveButtonString = _("Save");
111 $this->CloseButtonString = _("Close");
112 $this->filterName = $filterName;
113 $this->ui = get_userinfo();
114 $this->selectedBase = $_SESSION['CurrentMainBase'];
116 /* Check default values for SaveAdditionalVars */
117 foreach($this->SaveAdditionalVars as $name){
118 if(isset($_SESSION['MultiDialogFilters'][$this->filterName][$name])){
119 $this->$name = $_SESSION['MultiDialogFilters'][$this->filterName][$name];
120 }
121 }
123 }
125 /* Enables the headpage mode, which changes the list look */
126 function SetHeadpageMode()
127 {
128 $this->is_headpage = true;
129 }
131 /* Sets the List internal name (not displayed anywhere)
132 it is used to identify every single list
133 */
134 function SetTitle($str)
135 {
136 $this->string_Title = $str;
137 }
139 /* Set the list header string */
140 function SetListHeader($str)
141 {
142 $this->string_ListHeader = $str;
143 }
145 /* This sets the list description which is the first gray bar on top of the list */
146 function SetSummary($str)
147 {
148 $this->string_Summary = $str;
149 }
151 /* If the save button is enabled, you can change its caption with this function */
152 function SetSaveButtonString($str)
153 {
154 $this->SaveButtonString = $str;
155 }
157 /* If the close button is enabled, you can change its caption with this function */
158 function SetCloseButtonString($str)
159 {
160 $this->CloseButtonString = $str;
161 }
163 /* With this function you can change the text of the information box */
164 function SetInformation($str)
165 {
166 $this->string_Information = $str;
167 }
169 /* Display the alphabet selection box*/
170 function EnableAplhabet($bool)
171 {
172 $this->bool_DisplayAlpahabet = $bool;
173 }
175 /* Add additional header col */
176 function AddHeader($arr)
177 {
178 $this->array_Header[] = $arr;
179 }
181 /* add additional List element */
182 function AddElement($arr)
183 {
184 $this->array_Elements[] = $arr;
185 }
188 /* Return default header part. With back, home and root icons and department selection */
189 function get_default_header()
190 {
191 $enable_back = TRUE;
192 $enable_root = TRUE;
193 $enable_home = TRUE;
195 $ui = get_userinfo();
197 /* Check if selectedBase = first available base */
198 $deps = $ui->get_module_departments($this->module);
200 if(!count($deps) || $deps[0] == $this->selectedBase){
201 $enable_back = FALSE;
202 $enable_root = FALSE;
203 }
205 $listhead ="";
207 /* Check if we are in users home department */
208 if(!count($deps) ||$this->selectedBase == get_base_from_people($ui->dn)){
209 $enable_home = FALSE;
210 }
212 /* Draw root button */
213 if($enable_root){
214 $listhead .= " <input class='center' type='image' src='images/list_root.png' align='middle'
215 title='"._("Go to root department")."' name='dep_root' alt='"._("Root")."'> ";
216 }else{
217 $listhead .= " <img src='images/list_root_gray.png' class='center' alt='"._("Root")."'> ";
218 }
220 /* Draw back button */
221 if($enable_back){
222 $listhead .= " <input class='center' type='image' align='middle' src='images/list_back.png'
223 title='"._("Go up one department")."' alt='"._("Up")."' name='dep_back'> ";
224 }else{
225 $listhead .= " <img src='images/list_back_gray.png' class='center' alt='"._("Up")."'> ";
226 }
228 /* Draw home button */
229 if($enable_home){
230 $listhead .= " <input class='center' type='image' align='middle' src='images/list_home.png'
231 title='"._("Go to users department")."' alt='"._("Home")."' name='dep_home'> ";
232 }else{
233 $listhead .= " <img src='images/list_home_gray.png' class='center' alt='"._("Home")."'> ";
234 }
236 /* And at least draw reload button, this button is enabled everytime */
237 $listhead .= " <input class='center' type='image' src='images/list_reload.png' align='middle'
238 title='"._("Reload list")."' name='submit_department' alt='"._("Submit")."'> ".
239 " <img class='center' src='images/list_seperator.png' align='middle' alt='-' height='16' width='1'> ";
241 return ($listhead);
242 }
244 /* Add a checkbox to the filter element,
245 the name specifies an existing class var to store the 'selection' */
246 function AddCheckBox($name,$value="Unset",$string="Unset",$default=false)
247 {
248 $arr = array();
250 if($name == SEPERATOR){
251 $arr['name'] = SEPERATOR;
252 }else{
253 /* Check if there was already a variable
254 for this dialog which we should use instead of the default*/
255 if(isset($_SESSION['MultiDialogFilters'][$this->filterName][$name])){
256 $arr['default'] = $_SESSION['MultiDialogFilters'][$this->filterName][$name];
257 $this->$name = $arr['default'];
258 }else{
259 $arr['default'] = $default;
260 $this->$name = $default;
261 }
262 $arr['name'] = $name;
263 $arr['string'] = $string;
264 $arr['value'] = $value;
265 $arr['enabled'] = true;
267 }
268 $this->array_Checkboxes[] = $arr;
269 }
272 /* Hides or unhides the checkbox with the given name */
273 function DisableCheckBox($name,$HideShow = false)
274 {
275 foreach($this->array_Checkboxes as $key => $chkbox){
276 if($chkbox['name'] == $name){
277 $this->array_Checkboxes[$key]['enabled'] = $HideShow;
278 }
279 }
280 }
283 /* Returns true if the close button was pressed */
284 function isClosed()
285 {
286 return($this->is_closed);
287 }
289 /* Enable the close button */
290 function EnableCloseButton($bool)
291 {
292 $this->bool_DisplayCloseButton = $bool;
293 }
295 /* Enable the save button on the bottom of the list*/
296 function EnableSaveButton ($bool)
297 {
298 $this->bool_DisplaySaveButton = $bool;
299 }
301 /* Add a list specific filter object to position
302 1 on top of Information
303 2 Between Information && Filter
304 3 Below the Filter Part */
305 function AddUserBoxToFilter($position)
306 {
307 return("");
308 }
310 /* Draw the list with all list elements and filters */
311 function Draw()
312 {
314 /* Check for exeeded sizelimit */
315 if (($message= check_sizelimit()) != ""){
316 return($message);
317 }
319 $smarty = get_smarty();
320 $smarty->assign("UserBox1",$this->AddUserBoxToFilter(1));
321 $smarty->assign("UserBox2",$this->AddUserBoxToFilter(2));
322 $smarty->assign("UserBox3",$this->AddUserBoxToFilter(3));
324 $divlist = new divlist($this->string_Title);
325 $divlist->SetSummary($this->string_Summary);
326 $divlist->SetEntriesPerPage(0); // 0 for scrollable list
328 /* Display list footer with summary of all listed entries */
329 if(isset($this->config->data['MAIN']['LIST_SUMMARY']) && preg_match("/true/i",$this->config->data['MAIN']['LIST_SUMMARY'])){
330 $divlist->SetFooter($this->get_List_Bottom_Info());
331 }
333 if($this->DivHeight != ""){
334 $divlist->SetHeight($this->DivHeight);
335 }
337 /* set Header informations
338 */
339 $header = array();
340 foreach($this->array_Header as $head){
341 $header[] = $head;
342 }
343 $divlist->SetHeader($header);
345 /* set Entries
346 */
347 $elements = array();
348 foreach($this->array_Elements as $element){
349 $divlist->AddEntry($element);
350 }
352 /* Create checkboxes fields
353 */
354 $boxes = "";
355 $boxClick = " onClick='document.mainform.submit();' ";
356 foreach($this->array_Checkboxes as $box){
358 if($box['name'] == SEPERATOR){
359 $boxes .= "</td></tr></table><table style='width:100%;border-top:1px solid #B0B0B0;'><tr><td>";
360 continue;
361 }
363 /* Skip disabled boxes */
364 if(!$box['enabled']) continue;
366 /* Check if box is checked */
367 if($box['default'] == true){
368 $boxes .="<input type='checkbox' name=\"".$box['name']."\" value='1' title=\"".htmlentities($box['value'])."\" checked ".$boxClick."> ".$box['string']."<br>";
369 }else{
370 $boxes .="<input type='checkbox' name=\"".$box['name']."\" value='1' title=\"".htmlentities($box['value'])."\" ".$boxClick."> ".$box['string']."<br>";
371 }
372 }
373 $smarty->assign("CheckBoxes", $boxes);
375 /* Assign regex fields
376 */
377 $regexes = "";
378 foreach($this->array_Regexes as $regex){
379 $regexes.="<table summary=\"\" style=\"width:100%;border-top:1px solid #B0B0B0;\">
380 <tr>
381 <td>
382 <label for=\"".$regex['name']."\">
383 <img alt=\"".$regex['string']."\" src=\"".$regex['image']."\" align=middle>
384 </label>
385 </td>
386 <td width=\"99%\">
387 <input id=\"".$regex['name']."\" type=\"text\" style='width:99%' name=\"".$regex['name']."\" maxlength='20'
388 value=\"".htmlentities($regex['value'])."\" title=\"".htmlentities($regex['string'])."\">
389 </td>
390 </tr>
391 </table>";
392 }
393 $smarty->assign("regexes" , $regexes );
395 /* Hide Filter Part if Requested or empty */
396 if((empty($boxes)) && (empty($regexes)) || ($this->HideFilterPart)){
397 $smarty->assign("Skip_Filter_Part", true);
398 }else{
399 $smarty->assign("Skip_Filter_Part", false);
400 }
402 /* Assign alphabet and display it
403 */
404 $smarty->assign("Display_alphabet", $this->bool_DisplayAlpahabet);
405 $smarty->assign("alphabet", generate_alphabet());
406 $smarty->assign("Header" , $this->string_ListHeader);
407 $smarty->assign("HeaderDropDown", $this->GetDropDownHeaderMenu());
408 $smarty->assign("Summary" , $this->string_Summary);
409 $smarty->assign("Title" , $this->string_Title);
410 $smarty->assign("Information" , $this->string_Information);
412 /* Check for exeeded sizelimit */
413 $smarty->assign("hint" , print_sizelimit_warning());
414 $smarty->assign("DivList" , $divlist->DrawList());
417 if($this->is_headpage){
418 $smarty->assign("tree_image", get_template_path('images/tree.png'));
419 $smarty->assign("infoimage", get_template_path('images/info.png'));
420 $smarty->assign("launchimage", get_template_path('images/launch.png'));
421 $smarty->assign("apply", apply_filter());
422 }else{
423 $smarty->assign("tree_image", get_template_path('images/tree.png'));
424 $smarty->assign("infoimage", get_template_path('images/info_small.png'));
425 $smarty->assign("launchimage", get_template_path('images/rocket.png'));
426 $smarty->assign("apply", apply_filter());
427 }
429 /* Button handling */
430 $smarty->assign("SaveButtonString" ,$this->SaveButtonString);
431 $smarty->assign("CloseButtonString",$this->CloseButtonString);
433 $smarty->assign("Display_Close", $this->bool_DisplayCloseButton);
434 $smarty->assign("Display_Save" , $this->bool_DisplaySaveButton);
436 $smarty->assign("filterName" , $this->filterName);
437 $smarty->assign("is_headpage" , $this->is_headpage);
439 $display = $smarty->fetch(get_template_path("MultiSelectWindow.tpl"));
440 return($display);
441 }
443 /* Set the close var, which simulates the close button is pressed */
444 function Close()
445 {
446 $this->is_closed = true;
447 }
449 function Save()
450 {
451 $this->is_saved = true;
452 }
454 /* Store all checkboxes/ regexes ...
455 Store data also into a session var, to keep the checkboxes check after reload */
456 function save_object()
457 {
458 /* Get up to date config */
459 if(isset($this->parent->config)){
460 $this->config = $this->parent->config;
461 }
463 /* Update current base */
464 $s_action ="";
465 foreach($_POST as $key => $value){
466 if(preg_match("/^dep_back.*/i",$key)){
467 $s_action="back";
468 }elseif(preg_match("/^dep_root.*/",$key)){
469 $s_action="root";
470 }elseif(preg_match("/^dep_home.*/i",$key)){
471 $s_action="home";
472 }
473 }
475 /* Save base selection from headpage selectbox*/
476 if(isset($_POST['CurrentMainBase'])){
477 $this->selectedBase = $_POST['CurrentMainBase'];
478 }
480 /* Homebutton is posted */
481 if($s_action=="home"){
482 $ui= get_userinfo();
483 $base = get_base_from_people($ui->dn);
484 $this->selectedBase= $base;
485 }
487 /* Open selected department
488 this is posted by the parent class MultiSelectWindow */
489 if(isset($_GET['act'])&& ($_GET['act'] == "dep_open")){
490 $s_entry = base64_decode($_GET['dep_id']);
491 if (!isset($this->config->departments[$s_entry])){
492 print_red(_("Error: The requested subtree has an inconsistent DN encoding, check your LDAP!"));
493 } else {
494 $this->selectedBase = $this->config->departments[$s_entry];
495 }
496 }
498 /* back to the roots ^^ */
499 if($s_action=="root"){
500 $this->selectedBase=($this->config->current['BASE']);
501 $dep_id = $this->ui->get_module_departments($this->module);
502 if(isset($dep_id[key($dep_id)])){
503 $this->selectedBase = $dep_id[key($dep_id)];
504 }
505 }
508 /* If Back-button is pressed, move back one step in DN */
509 if($s_action=="back"){
511 /* Get parent deprtment and check if we are allowed to step in it */
512 $base_back= preg_replace("/^[^,]+,/", "", $_SESSION['CurrentMainBase']);
513 $dep_id = $this->ui->get_module_departments($this->module);
514 if(in_array_ics($base_back,$dep_id)){
516 /* The department array keeps non DN entries as index. We need to convert
517 it before checking the existance. */
518 $base_back= trim(convert_department_dn($base_back));
520 /* Check if the department exists, otherwise revert to the configure base DN */
521 if(isset($this->config->departments[$base_back])){
522 $this->selectedBase= $this->config->departments[$base_back];
523 }else{
524 $this->selectedBase= $this->config->departments['/'];
525 }
526 }
527 }
528 $_SESSION['CurrentMainBase'] = $this->selectedBase;
530 if(isset($_POST['MultiSelectWindow'.$this->filterName])){
532 /* Save some additional vars */
533 foreach($this->SaveAdditionalVars as $name){
534 if(isset($_POST[$name])){
535 if(isset($this->$name)){
536 $this->$name = $_POST[$name];
537 $_SESSION['MultiDialogFilters'][$this->filterName][$name] = $_POST[$name];
538 }
539 }
540 }
542 /* Check posts from checkboxes
543 */
544 foreach($this->array_Checkboxes as $key => $box){
545 if(isset($_POST[$box['name']])){
546 $this->array_Checkboxes[$key]['default'] = true;
547 $this->$box['name'] = true;
548 }else{
549 $this->array_Checkboxes[$key]['default'] = false;
550 $this->$box['name'] = false;
551 }
552 /* Save settings in out session */
553 $_SESSION['MultiDialogFilters'][$this->filterName][$box['name']] = $this->$box['name'];
554 }
556 /* Check regex posts */
557 foreach($this->array_Regexes as $key => $box){
558 $this->array_Regexes[$key]['value'] = $_POST[$box['name']];
559 $this->$box['name'] = $_POST[$box['name']];
560 $_SESSION['MultiDialogFilters'][$this->filterName][$box['name']] = $this->$box['name'];
561 }
563 /* call close/save if buttons are pressed */
564 if(isset($_POST['CloseMultiSelectWindow'])){
565 $this->Close();
566 }
568 if(isset($_POST['SaveMultiSelectWindow'])){
569 $this->Save();
570 }
571 }
573 /* check for alphabet selection
574 Check which regexes are connected to the alphabet
575 */
576 if(isset($_GET['search'])){
577 foreach($this->array_Regexes as $key => $box){
578 /* check if this regex is connected to the alphabet selection */
579 if(($box['connAlpha'])&&(isset($_GET['search']))){
580 $val = $_GET['search']."*";
581 $val = preg_replace("/\*\**/","*",$val);
582 $this->array_Regexes[$key]['value'] = $val;
583 $this->$box['name'] = $val;
584 $_SESSION['MultiDialogFilters'][$this->filterName][$box['name']] = $val;
585 }
586 }
587 }
588 }
591 /* Create header snapshot value */
592 function get_snapshot_header()
593 {
594 $str = " ";
595 if($this->parent->snapshotEnabled()){
596 $ok = false;
597 foreach($this->parent->get_used_snapshot_bases() as $base){
598 $ok |= count($this->parent->getAllDeletedSnapshots($base)) >= 1 ;
599 }
600 if($ok){
601 $str = "<input class='center' type='image' align='middle' src='images/restore.png'
602 title='"._("Restore snapshopts of already deleted objects")."'
603 alt='"._("Restore")."' name='RestoreDeletedSnapShot'> ";
604 }else{
605 $str = "<img class='center' src='images/restore_grey.png' alt=''> ";
606 }
608 # $str .= "<img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ";
609 }
610 return($str);
611 }
614 function GetSnapShotActions($dn)
615 {
616 $str= "";
617 if($this->parent->snapshotEnabled()){
619 if(count($this->parent->Available_SnapsShots($dn))){
620 $str.= "<input class='center' type='image' src='images/restore.png'
621 alt='"._("Restore snapshot")."' name='RestoreSnapShotDialog_".base64_encode($dn)."' title='"._("Restore snapshot")."'> ";
622 } else {
623 $str = "<img class='center' src='images/restore_grey.png' alt=''> ";
624 }
626 $str.= "<input class='center' type='image' src='images/snapshot.png'
627 alt='"._("Create snapshot")."' name='CreateSnapShotDialog_".base64_encode($dn)."' title='"._("Create a new snapshot from this object")."'> ";
628 }
630 return($str);
631 }
634 /* this function adds the sub-departments of the current tree to the list */
635 function AddDepartments($base = false,$numtabs = 3,$empty_tabs_in_front = 0)
636 {
637 $this->DepartmentsAdded = true;
638 $this->Added_Departments = array();
640 /* check for a valid base */
641 if(!$base){
642 if(!isset($_SESSION['CurrentMainBase'])){
643 $_SESSION['CurrentMainBase'] = $this->config->current['BASE'];
644 }
645 $base = $_SESSION['CurrentMainBase'];
646 }
648 /* Create ldap obj and switch into base*/
649 $ldap = $this->config->get_ldap_link();
650 $ldap->cd($base);
652 /* reset current deps */
653 $this->departments = array();
655 /* Get all departments within this subtree */
656 $deps= get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
657 array("ou", "description"), GL_SIZELIMIT | GL_CONVERT);
659 /* Edit delete link for system types
660 */
661 $linkopen = "<a href='?plug=".$_GET['plug']."&act=dep_open&dep_id=%s'>%s</a>";
663 /* Create an array with all visible (in the list) departments */
664 $departments = array();
665 foreach($deps as $value){
666 if(isset($value['description'][0])){
667 $this->departments[$value['dn']]= get_sub_department($value['dn'])." - [".$value["description"][0]."]";
668 }else{
669 $this->departments[$value['dn']]= get_sub_department($value['dn']);
670 }
671 }
672 natcasesort($this->departments);
675 if($empty_tabs_in_front){
676 # $numtabs -= $empty_tabs_in_front;
677 }
679 /* Add deps to this dialog object list */
680 foreach($this->departments as $key=> $val){
682 /* Add missing entries ... */
683 if(!isset($this->config->departments[trim($key)])){
684 $this->config->departments[trim($key)]="";
685 }
687 /* check if this department contains sub-departments
688 Display different image in this case
689 */
690 $non_empty="";
691 $nkey= normalizePreg($key);
692 foreach($this->config->departments as $keyd=>$vald ){
693 if(preg_match('/$nkey\/.*/',$keyd)){
694 $non_empty="full";
695 }
696 }
698 /* Add to divlist */
699 $row = array();
701 if($empty_tabs_in_front){
702 for($i = 0; $i < $empty_tabs_in_front ; $i ++){
703 $row[] = array("string"=>" ", "attach" => "style='text-align:center;width:20px;'");
704 }
705 }
707 $row[]=$field1=array("string"=>"<img src='images/".$non_empty."folder.png' alt='department'>","attach"=>"style='text-align:center;width:20px;'");
708 $row[]=$field2=array("string"=>sprintf($linkopen,base64_encode($key),$val), "attach" => "style=''");
710 if($numtabs > 2){
711 for($i = 2 ; $i < $numtabs;$i++){
712 if(isset( $this->array_Header[$i + $empty_tabs_in_front]['attach'])){
713 $row[] = array("string"=>" ","attach" => $this->array_Header[$i + $empty_tabs_in_front]['attach']);
714 }else{
715 $row[] = array("string"=>" ");
716 }
717 }
718 }
719 $this->AddElement($row);
720 $this->Added_Departments[] = $row;
721 }
722 }
724 function set_List_Bottom_Info($str)
725 {
726 $this->List_Bottom_Info = $str;
727 }
729 function get_List_Bottom_Info()
730 {
731 return($this->List_Bottom_Info);
732 }
733 }
734 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
735 ?>