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("/storage/hickert/gosa/include/php_layers_menu/");
90 $mid->setHorizontalMenuTpl('GOsa_MultiSelectHeader.ihtml');
91 $mid->setMenuStructureString($this->string_ListDropDown);
92 $mid->parseStructureForMenu('menu');
93 $mid->newHorizontalMenu('menu');
94 $s = $mid->getHeader();
95 $s.= $mid->getMenu('menu');
96 $s.= $mid->getFooter('menu');
97 return($s);
98 }else{
99 return("");
100 }
101 }
104 /* Contrucktion */
105 function MultiSelectWindow(&$config, $filterName, $module)
106 {
107 $this->config = &$config;
108 $this->module = $module;
109 $this->SaveButtonString = _("Save");
110 $this->CloseButtonString = _("Close");
111 $this->filterName = $filterName;
112 $this->ui = get_userinfo();
113 $this->selectedBase = $_SESSION['CurrentMainBase'];
115 /* Check default values for SaveAdditionalVars */
116 foreach($this->SaveAdditionalVars as $name){
117 if(isset($_SESSION['MultiDialogFilters'][$this->filterName][$name])){
118 $this->$name = $_SESSION['MultiDialogFilters'][$this->filterName][$name];
119 }
120 }
122 }
124 /* Enables the headpage mode, which changes the list look */
125 function SetHeadpageMode()
126 {
127 $this->is_headpage = true;
128 }
130 /* Sets the List internal name (not displayed anywhere)
131 it is used to identify every single list
132 */
133 function SetTitle($str)
134 {
135 $this->string_Title = $str;
136 }
138 /* Set the list header string */
139 function SetListHeader($str)
140 {
141 $this->string_ListHeader = $str;
142 }
144 /* This sets the list description which is the first gray bar on top of the list */
145 function SetSummary($str)
146 {
147 $this->string_Summary = $str;
148 }
150 /* If the save button is enabled, you can change its caption with this function */
151 function SetSaveButtonString($str)
152 {
153 $this->SaveButtonString = $str;
154 }
156 /* If the close button is enabled, you can change its caption with this function */
157 function SetCloseButtonString($str)
158 {
159 $this->CloseButtonString = $str;
160 }
162 /* With this function you can change the text of the information box */
163 function SetInformation($str)
164 {
165 $this->string_Information = $str;
166 }
168 /* Display the alphabet selection box*/
169 function EnableAplhabet($bool)
170 {
171 $this->bool_DisplayAlpahabet = $bool;
172 }
174 /* Add additional header col */
175 function AddHeader($arr)
176 {
177 $this->array_Header[] = $arr;
178 }
180 /* add additional List element */
181 function AddElement($arr)
182 {
183 $this->array_Elements[] = $arr;
184 }
187 /* Return default header part. With back, home and root icons and department selection */
188 function get_default_header()
189 {
190 $enable_back = TRUE;
191 $enable_root = TRUE;
192 $enable_home = TRUE;
194 $ui = get_userinfo();
196 /* Check if selectedBase = first available base */
197 $deps = $ui->get_module_departments($this->module);
199 if(!count($deps) || $deps[0] == $this->selectedBase){
200 $enable_back = FALSE;
201 $enable_root = FALSE;
202 }
204 $listhead ="";
206 /* Check if we are in users home department */
207 if(!count($deps) ||$this->selectedBase == get_base_from_people($ui->dn)){
208 $enable_home = FALSE;
209 }
211 /* Draw root button */
212 if($enable_root){
213 $listhead .= " <input class='center' type='image' src='images/list_root.png' align='middle'
214 title='"._("Go to root department")."' name='dep_root' alt='"._("Root")."'> ";
215 }else{
216 $listhead .= " <img src='images/list_root_gray.png' class='center' alt='"._("Root")."'> ";
217 }
219 /* Draw back button */
220 if($enable_back){
221 $listhead .= " <input class='center' type='image' align='middle' src='images/list_back.png'
222 title='"._("Go up one department")."' alt='"._("Up")."' name='dep_back'> ";
223 }else{
224 $listhead .= " <img src='images/list_back_gray.png' class='center' alt='"._("Up")."'> ";
225 }
227 /* Draw home button */
228 if($enable_home){
229 $listhead .= " <input class='center' type='image' align='middle' src='images/list_home.png'
230 title='"._("Go to users department")."' alt='"._("Home")."' name='dep_home'> ";
231 }else{
232 $listhead .= " <img src='images/list_home_gray.png' class='center' alt='"._("Home")."'> ";
233 }
235 /* And at least draw reload button, this button is enabled everytime */
236 $listhead .= " <input class='center' type='image' src='images/list_reload.png' align='middle'
237 title='"._("Reload list")."' name='submit_department' alt='"._("Submit")."'> ".
238 " <img class='center' src='images/list_seperator.png' align='middle' alt='-' height='16' width='1'> ";
240 return ($listhead);
241 }
243 /* Add a checkbox to the filter element,
244 the name specifies an existing class var to store the 'selection' */
245 function AddCheckBox($name,$value="Unset",$string="Unset",$default=false)
246 {
247 $arr = array();
249 if($name == SEPERATOR){
250 $arr['name'] = SEPERATOR;
251 }else{
252 /* Check if there was already a variable
253 for this dialog which we should use instead of the default*/
254 if(isset($_SESSION['MultiDialogFilters'][$this->filterName][$name])){
255 $arr['default'] = $_SESSION['MultiDialogFilters'][$this->filterName][$name];
256 $this->$name = $arr['default'];
257 }else{
258 $arr['default'] = $default;
259 $this->$name = $default;
260 }
261 $arr['name'] = $name;
262 $arr['string'] = $string;
263 $arr['value'] = $value;
264 $arr['enabled'] = true;
266 }
267 $this->array_Checkboxes[] = $arr;
268 }
271 /* Hides or unhides the checkbox with the given name */
272 function DisableCheckBox($name,$HideShow = false)
273 {
274 foreach($this->array_Checkboxes as $key => $chkbox){
275 if($chkbox['name'] == $name){
276 $this->array_Checkboxes[$key]['enabled'] = $HideShow;
277 }
278 }
279 }
282 /* Returns true if the close button was pressed */
283 function isClosed()
284 {
285 return($this->is_closed);
286 }
288 /* Enable the close button */
289 function EnableCloseButton($bool)
290 {
291 $this->bool_DisplayCloseButton = $bool;
292 }
294 /* Enable the save button on the bottom of the list*/
295 function EnableSaveButton ($bool)
296 {
297 $this->bool_DisplaySaveButton = $bool;
298 }
300 /* Add a list specific filter object to position
301 1 on top of Information
302 2 Between Information && Filter
303 3 Below the Filter Part */
304 function AddUserBoxToFilter($position)
305 {
306 return("");
307 }
309 /* Draw the list with all list elements and filters */
310 function Draw()
311 {
313 /* Check for exeeded sizelimit */
314 if (($message= check_sizelimit()) != ""){
315 return($message);
316 }
318 $smarty = get_smarty();
319 $smarty->assign("UserBox1",$this->AddUserBoxToFilter(1));
320 $smarty->assign("UserBox2",$this->AddUserBoxToFilter(2));
321 $smarty->assign("UserBox3",$this->AddUserBoxToFilter(3));
323 $divlist = new divlist($this->string_Title);
324 $divlist->SetSummary($this->string_Summary);
325 $divlist->SetEntriesPerPage(0); // 0 for scrollable list
327 /* Display list footer with summary of all listed entries */
328 if(isset($this->config->data['MAIN']['LIST_SUMMARY']) && preg_match("/true/i",$this->config->data['MAIN']['LIST_SUMMARY'])){
329 $divlist->SetFooter($this->get_List_Bottom_Info());
330 }
332 if($this->DivHeight != ""){
333 $divlist->SetHeight($this->DivHeight);
334 }
336 /* set Header informations
337 */
338 $header = array();
339 foreach($this->array_Header as $head){
340 $header[] = $head;
341 }
342 $divlist->SetHeader($header);
344 /* set Entries
345 */
346 $elements = array();
347 foreach($this->array_Elements as $element){
348 $divlist->AddEntry($element);
349 }
351 /* Create checkboxes fields
352 */
353 $boxes = "";
354 $boxClick = " onClick='document.mainform.submit();' ";
355 foreach($this->array_Checkboxes as $box){
357 if($box['name'] == SEPERATOR){
358 $boxes .= "</td></tr></table><table style='width:100%;border-top:1px solid #B0B0B0;'><tr><td>";
359 continue;
360 }
362 /* Skip disabled boxes */
363 if(!$box['enabled']) continue;
365 /* Check if box is checked */
366 if($box['default'] == true){
367 $boxes .="<input type='checkbox' name=\"".$box['name']."\" value='1' title=\"".htmlentities($box['value'])."\" checked ".$boxClick."> ".$box['string']."<br>";
368 }else{
369 $boxes .="<input type='checkbox' name=\"".$box['name']."\" value='1' title=\"".htmlentities($box['value'])."\" ".$boxClick."> ".$box['string']."<br>";
370 }
371 }
372 $smarty->assign("CheckBoxes", $boxes);
374 /* Assign regex fields
375 */
376 $regexes = "";
377 foreach($this->array_Regexes as $regex){
378 $regexes.="<table summary=\"\" style=\"width:100%;border-top:1px solid #B0B0B0;\">
379 <tr>
380 <td>
381 <label for=\"".$regex['name']."\">
382 <img alt=\"".$regex['string']."\" src=\"".$regex['image']."\" align=middle>
383 </label>
384 </td>
385 <td width=\"99%\">
386 <input id=\"".$regex['name']."\" type=\"text\" style='width:99%' name=\"".$regex['name']."\" maxlength='20'
387 value=\"".htmlentities($regex['value'])."\" title=\"".htmlentities($regex['string'])."\">
388 </td>
389 </tr>
390 </table>";
391 }
392 $smarty->assign("regexes" , $regexes );
394 /* Hide Filter Part if Requested or empty */
395 if((empty($boxes)) && (empty($regexes)) || ($this->HideFilterPart)){
396 $smarty->assign("Skip_Filter_Part", true);
397 }else{
398 $smarty->assign("Skip_Filter_Part", false);
399 }
401 /* Assign alphabet and display it
402 */
403 $smarty->assign("Display_alphabet", $this->bool_DisplayAlpahabet);
404 $smarty->assign("alphabet", generate_alphabet());
405 $smarty->assign("Header" , $this->string_ListHeader);
406 $smarty->assign("HeaderDropDown", $this->GetDropDownHeaderMenu());
407 $smarty->assign("Summary" , $this->string_Summary);
408 $smarty->assign("Title" , $this->string_Title);
409 $smarty->assign("Information" , $this->string_Information);
411 /* Check for exeeded sizelimit */
412 $smarty->assign("hint" , print_sizelimit_warning());
413 $smarty->assign("DivList" , $divlist->DrawList());
416 if($this->is_headpage){
417 $smarty->assign("tree_image", get_template_path('images/tree.png'));
418 $smarty->assign("infoimage", get_template_path('images/info.png'));
419 $smarty->assign("launchimage", get_template_path('images/launch.png'));
420 $smarty->assign("apply", apply_filter());
421 }else{
422 $smarty->assign("tree_image", get_template_path('images/tree.png'));
423 $smarty->assign("infoimage", get_template_path('images/info_small.png'));
424 $smarty->assign("launchimage", get_template_path('images/rocket.png'));
425 $smarty->assign("apply", apply_filter());
426 }
428 /* Button handling */
429 $smarty->assign("SaveButtonString" ,$this->SaveButtonString);
430 $smarty->assign("CloseButtonString",$this->CloseButtonString);
432 $smarty->assign("Display_Close", $this->bool_DisplayCloseButton);
433 $smarty->assign("Display_Save" , $this->bool_DisplaySaveButton);
435 $smarty->assign("filterName" , $this->filterName);
436 $smarty->assign("is_headpage" , $this->is_headpage);
438 $display = $smarty->fetch(get_template_path("MultiSelectWindow.tpl"));
439 return($display);
440 }
442 /* Set the close var, which simulates the close button is pressed */
443 function Close()
444 {
445 $this->is_closed = true;
446 }
448 function Save()
449 {
450 $this->is_saved = true;
451 }
453 /* Store all checkboxes/ regexes ...
454 Store data also into a session var, to keep the checkboxes check after reload */
455 function save_object()
456 {
457 /* Get up to date config */
458 if(isset($this->parent->config)){
459 $this->config = $this->parent->config;
460 }
462 /* Update current base */
463 $s_action ="";
464 foreach($_POST as $key => $value){
465 if(preg_match("/^dep_back.*/i",$key)){
466 $s_action="back";
467 }elseif(preg_match("/^dep_root.*/",$key)){
468 $s_action="root";
469 }elseif(preg_match("/^dep_home.*/i",$key)){
470 $s_action="home";
471 }
472 }
474 /* Save base selection from headpage selectbox*/
475 if(isset($_POST['CurrentMainBase'])){
476 $this->selectedBase = $_POST['CurrentMainBase'];
477 }
479 /* Homebutton is posted */
480 if($s_action=="home"){
481 $ui= get_userinfo();
482 $base = get_base_from_people($ui->dn);
483 $this->selectedBase= $base;
484 }
486 /* Open selected department
487 this is posted by the parent class MultiSelectWindow */
488 if(isset($_GET['act'])&& ($_GET['act'] == "dep_open")){
489 $s_entry = base64_decode($_GET['dep_id']);
490 if (!isset($this->config->departments[$s_entry])){
491 print_red(_("Error: The requested subtree has an inconsistent DN encoding, check your LDAP!"));
492 } else {
493 $this->selectedBase = $this->config->departments[$s_entry];
494 }
495 }
497 /* back to the roots ^^ */
498 if($s_action=="root"){
499 $this->selectedBase=($this->config->current['BASE']);
500 $dep_id = $this->ui->get_module_departments($this->module);
501 if(isset($dep_id[key($dep_id)])){
502 $this->selectedBase = $dep_id[key($dep_id)];
503 }
504 }
507 /* If Back-button is pressed, move back one step in DN */
508 if($s_action=="back"){
510 /* Get parent deprtment and check if we are allowed to step in it */
511 $base_back= preg_replace("/^[^,]+,/", "", $_SESSION['CurrentMainBase']);
512 $dep_id = $this->ui->get_module_departments($this->module);
513 if(in_array_ics($base_back,$dep_id)){
515 /* The department array keeps non DN entries as index. We need to convert
516 it before checking the existance. */
517 $base_back= trim(convert_department_dn($base_back));
519 /* Check if the department exists, otherwise revert to the configure base DN */
520 if(isset($this->config->departments[$base_back])){
521 $this->selectedBase= $this->config->departments[$base_back];
522 }else{
523 $this->selectedBase= $this->config->departments['/'];
524 }
525 }
526 }
527 $_SESSION['CurrentMainBase'] = $this->selectedBase;
529 if(isset($_POST['MultiSelectWindow'.$this->filterName])){
531 /* Save some additional vars */
532 foreach($this->SaveAdditionalVars as $name){
533 if(isset($_POST[$name])){
534 if(isset($this->$name)){
535 $this->$name = $_POST[$name];
536 $_SESSION['MultiDialogFilters'][$this->filterName][$name] = $_POST[$name];
537 }
538 }
539 }
541 /* Check posts from checkboxes
542 */
543 foreach($this->array_Checkboxes as $key => $box){
544 if(isset($_POST[$box['name']])){
545 $this->array_Checkboxes[$key]['default'] = true;
546 $this->$box['name'] = true;
547 }else{
548 $this->array_Checkboxes[$key]['default'] = false;
549 $this->$box['name'] = false;
550 }
551 /* Save settings in out session */
552 $_SESSION['MultiDialogFilters'][$this->filterName][$box['name']] = $this->$box['name'];
553 }
555 /* Check regex posts */
556 foreach($this->array_Regexes as $key => $box){
557 $this->array_Regexes[$key]['value'] = $_POST[$box['name']];
558 $this->$box['name'] = $_POST[$box['name']];
559 $_SESSION['MultiDialogFilters'][$this->filterName][$box['name']] = $this->$box['name'];
560 }
562 /* call close/save if buttons are pressed */
563 if(isset($_POST['CloseMultiSelectWindow'])){
564 $this->Close();
565 }
567 if(isset($_POST['SaveMultiSelectWindow'])){
568 $this->Save();
569 }
570 }
572 /* check for alphabet selection
573 Check which regexes are connected to the alphabet
574 */
575 if(isset($_GET['search'])){
576 foreach($this->array_Regexes as $key => $box){
577 /* check if this regex is connected to the alphabet selection */
578 if(($box['connAlpha'])&&(isset($_GET['search']))){
579 $val = $_GET['search']."*";
580 $val = preg_replace("/\*\**/","*",$val);
581 $this->array_Regexes[$key]['value'] = $val;
582 $this->$box['name'] = $val;
583 $_SESSION['MultiDialogFilters'][$this->filterName][$box['name']] = $val;
584 }
585 }
586 }
587 }
590 /* Create header snapshot value */
591 function get_snapshot_header()
592 {
593 $str = " ";
594 if($this->parent->snapshotEnabled()){
595 $ok = false;
596 foreach($this->parent->get_used_snapshot_bases() as $base){
597 $ok |= count($this->parent->getAllDeletedSnapshots($base)) >= 1 ;
598 }
599 if($ok){
600 $str = "<input class='center' type='image' align='middle' src='images/restore.png'
601 title='"._("Restore snapshopts of already deleted objects")."'
602 alt='"._("Restore")."' name='RestoreDeletedSnapShot'> ";
603 }else{
604 $str = "<img class='center' src='images/restore_grey.png' alt=''> ";
605 }
607 # $str .= "<img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ";
608 }
609 return($str);
610 }
613 function GetSnapShotActions($dn)
614 {
615 $str= "";
616 if($this->parent->snapshotEnabled()){
618 if(count($this->parent->Available_SnapsShots($dn))){
619 $str.= "<input class='center' type='image' src='images/restore.png'
620 alt='"._("Restore snapshot")."' name='RestoreSnapShotDialog_".base64_encode($dn)."' title='"._("Restore snapshot")."'> ";
621 } else {
622 $str = "<img class='center' src='images/restore_grey.png' alt=''> ";
623 }
625 $str.= "<input class='center' type='image' src='images/snapshot.png'
626 alt='"._("Create snapshot")."' name='CreateSnapShotDialog_".base64_encode($dn)."' title='"._("Create a new snapshot from this object")."'> ";
627 }
629 return($str);
630 }
633 /* this function adds the sub-departments of the current tree to the list */
634 function AddDepartments($base = false,$numtabs = 3,$empty_tabs_in_front = 0)
635 {
636 $this->DepartmentsAdded = true;
637 $this->Added_Departments = array();
639 /* check for a valid base */
640 if(!$base){
641 if(!isset($_SESSION['CurrentMainBase'])){
642 $_SESSION['CurrentMainBase'] = $this->config->current['BASE'];
643 }
644 $base = $_SESSION['CurrentMainBase'];
645 }
647 /* Create ldap obj and switch into base*/
648 $ldap = $this->config->get_ldap_link();
649 $ldap->cd($base);
651 /* reset current deps */
652 $this->departments = array();
654 /* Get all departments within this subtree */
655 $deps= get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
656 array("ou", "description"), GL_SIZELIMIT | GL_CONVERT);
658 /* Edit delete link for system types
659 */
660 $linkopen = "<a href='?plug=".$_GET['plug']."&act=dep_open&dep_id=%s'>%s</a>";
662 /* Create an array with all visible (in the list) departments */
663 $departments = array();
664 foreach($deps as $value){
665 if(isset($value['description'][0])){
666 $this->departments[$value['dn']]= get_sub_department($value['dn'])." - [".$value["description"][0]."]";
667 }else{
668 $this->departments[$value['dn']]= get_sub_department($value['dn']);
669 }
670 }
671 natcasesort($this->departments);
674 if($empty_tabs_in_front){
675 # $numtabs -= $empty_tabs_in_front;
676 }
678 /* Add deps to this dialog object list */
679 foreach($this->departments as $key=> $val){
681 /* Add missing entries ... */
682 if(!isset($this->config->departments[trim($key)])){
683 $this->config->departments[trim($key)]="";
684 }
686 /* check if this department contains sub-departments
687 Display different image in this case
688 */
689 $non_empty="";
690 $nkey= normalizePreg($key);
691 foreach($this->config->departments as $keyd=>$vald ){
692 if(preg_match('/$nkey\/.*/',$keyd)){
693 $non_empty="full";
694 }
695 }
697 /* Add to divlist */
698 $row = array();
700 if($empty_tabs_in_front){
701 for($i = 0; $i < $empty_tabs_in_front ; $i ++){
702 $row[] = array("string"=>" ", "attach" => "style='text-align:center;width:20px;'");
703 }
704 }
706 $row[]=$field1=array("string"=>"<img src='images/".$non_empty."folder.png' alt='department'>","attach"=>"style='text-align:center;width:20px;'");
707 $row[]=$field2=array("string"=>sprintf($linkopen,base64_encode($key),$val), "attach" => "style=''");
709 if($numtabs > 2){
710 for($i = 2 ; $i < $numtabs;$i++){
711 if(isset( $this->array_Header[$i + $empty_tabs_in_front]['attach'])){
712 $row[] = array("string"=>" ","attach" => $this->array_Header[$i + $empty_tabs_in_front]['attach']);
713 }else{
714 $row[] = array("string"=>" ");
715 }
716 }
717 }
718 $this->AddElement($row);
719 $this->Added_Departments[] = $row;
720 }
721 }
723 function set_List_Bottom_Info($str)
724 {
725 $this->List_Bottom_Info = $str;
726 }
728 function get_List_Bottom_Info()
729 {
730 return($this->List_Bottom_Info);
731 }
732 }
733 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
734 ?>