fee7d60acab6d7f8873f1729ecf0a30ab45d4e30
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_Summary = "";
17 var $string_Information = "";
19 var $array_Header = array();
20 var $array_Elements = array();
21 var $array_Checkboxes = array();
22 var $array_Regexes = array();
24 var $config = array("");
25 var $is_closed = false;
26 var $is_saved = false;
27 var $is_headpage = false; // if true the design changes
28 var $filterName = "Liste";
29 var $DepartmentsAdded = false;
30 var $selectedBase = "";
32 var $DivHeight = "";
34 var $HideFilterPart = false;
36 var $SaveAdditionalVars = array(); // Additional Post vars to store
37 var $module= "";
39 function ClearElementsList()
40 {
41 $this->array_Elements = array();
42 }
44 function HideFilterPart($bool = true)
45 {
46 $this->HideFilterPart = $bool;
47 }
49 function SetHeight($height)
50 {
51 $this->DivHeight=$height;
52 }
54 /* Adds a regex input field to the current dialog */
55 function AddRegex($name,$string,$value,$conn,$image="images/search.png")
56 {
57 $arr = array();
59 /* Check if the given input field name was already used
60 for this type of dialog */
61 if(isset($_SESSION['MultiDialogFilters'][$this->filterName][$name])){
62 $arr['value'] = $_SESSION['MultiDialogFilters'][$this->filterName][$name];
63 $this->$name = $arr['value'];
64 }else{
65 $arr['value'] = $value;
66 }
68 $arr['name'] = $name;
69 $arr['string'] = $string;
70 $arr['image'] = $image;
71 $arr['connAlpha'] = $conn; // Connect with alphabet select
72 $this->array_Regexes[] = $arr;
73 }
75 /* Contrucktion */
76 function MultiSelectWindow($config, $filterName, $module)
77 {
78 $this->config = $config;
79 $this->module = $module;
80 $this->SaveButtonString = _("Save");
81 $this->CloseButtonString = _("Close");
82 $this->filterName = $filterName;
84 $this->selectedBase = $_SESSION['CurrentMainBase'];
86 /* Check default values for SaveAdditionalVars */
87 foreach($this->SaveAdditionalVars as $name){
88 if(isset($_SESSION['MultiDialogFilters'][$this->filterName][$name])){
89 $this->$name = $_SESSION['MultiDialogFilters'][$this->filterName][$name];
90 }
91 }
93 }
95 /* Enables the headpage mode, which changes the list look */
96 function SetHeadpageMode()
97 {
98 $this->is_headpage = true;
99 }
101 /* Sets the List internal name (not displayed anywhere)
102 it is used to identify every single list
103 */
104 function SetTitle($str)
105 {
106 $this->string_Title = $str;
107 }
109 /* Set the list header string */
110 function SetListHeader($str)
111 {
112 $this->string_ListHeader = $str;
113 }
115 /* This sets the list description which is the first gray bar on top of the list */
116 function SetSummary($str)
117 {
118 $this->string_Summary = $str;
119 }
121 /* If the save button is enabled, you can change its caption with this function */
122 function SetSaveButtonString($str)
123 {
124 $this->SaveButtonString = $str;
125 }
127 /* If the close button is enabled, you can change its caption with this function */
128 function SetCloseButtonString($str)
129 {
130 $this->CloseButtonString = $str;
131 }
133 /* With this function you can change the text of the information box */
134 function SetInformation($str)
135 {
136 $this->string_Information = $str;
137 }
139 /* Display the alphabet selection box*/
140 function EnableAplhabet($bool)
141 {
142 $this->bool_DisplayAlpahabet = $bool;
143 }
145 /* Add additional header col */
146 function AddHeader($arr)
147 {
148 $this->array_Header[] = $arr;
149 }
151 /* add additional List element */
152 function AddElement($arr)
153 {
154 $this->array_Elements[] = $arr;
155 }
157 /* Add a checkbox to the filter element,
158 the name specifies an existing class var to store the 'selection' */
159 function AddCheckBox($name,$value="Unset",$string="Unset",$default=false)
160 {
161 $arr = array();
163 if($name == SEPERATOR){
164 $arr['name'] = SEPERATOR;
165 }else{
166 /* Check if there was already a variable
167 for this dialog which we should use instead of the default*/
168 if(isset($_SESSION['MultiDialogFilters'][$this->filterName][$name])){
169 $arr['default'] = $_SESSION['MultiDialogFilters'][$this->filterName][$name];
170 $this->$name = $arr['default'];
171 }else{
172 $arr['default'] = $default;
173 $this->$name = $default;
174 }
175 $arr['name'] = $name;
176 $arr['string'] = $string;
177 $arr['value'] = $value;
178 $arr['enabled'] = true;
180 }
181 $this->array_Checkboxes[] = $arr;
182 }
185 /* Hides or unhides the checkbox with the given name */
186 function DisableCheckBox($name,$HideShow = false)
187 {
188 foreach($this->array_Checkboxes as $key => $chkbox){
189 if($chkbox['name'] == $name){
190 $this->array_Checkboxes[$key]['enabled'] = $HideShow;
191 }
192 }
193 }
196 /* Returns true if the close button was pressed */
197 function isClosed()
198 {
199 return($this->is_closed);
200 }
202 /* Enable the close button */
203 function EnableCloseButton($bool)
204 {
205 $this->bool_DisplayCloseButton = $bool;
206 }
208 /* Enable the save button on the bottom of the list*/
209 function EnableSaveButton ($bool)
210 {
211 $this->bool_DisplaySaveButton = $bool;
212 }
214 /* Add a list specific filter object to position
215 1 on top of Information
216 2 Between Information && Filter
217 3 Below the Filter Part */
218 function AddUserBoxToFilter($position)
219 {
220 return("");
221 }
223 /* Draw the list with all list elements and filters */
224 function Draw()
225 {
227 /* Check for exeeded sizelimit */
228 if (($message= check_sizelimit()) != ""){
229 return($message);
230 }
232 $smarty = get_smarty();
233 $smarty->assign("UserBox1",$this->AddUserBoxToFilter(1));
234 $smarty->assign("UserBox2",$this->AddUserBoxToFilter(2));
235 $smarty->assign("UserBox3",$this->AddUserBoxToFilter(3));
237 $divlist = new divlist($this->string_Title);
238 $divlist->SetSummary($this->string_Summary);
239 $divlist->SetEntriesPerPage(0); // 0 for scrollable list
241 if($this->DivHeight != ""){
242 $divlist->SetHeight($this->DivHeight);
243 }
245 /* set Header informations
246 */
247 $header = array();
248 foreach($this->array_Header as $head){
249 $header[] = $head;
250 }
251 $divlist->SetHeader($header);
253 /* set Entries
254 */
255 $elements = array();
256 foreach($this->array_Elements as $element){
257 $divlist->AddEntry($element);
258 }
260 /* Create checkboxes fields
261 */
262 $boxes = "";
263 $boxClick = " onClick='document.mainform.submit();' ";
264 foreach($this->array_Checkboxes as $box){
266 if($box['name'] == SEPERATOR){
267 $boxes .= "</td></tr></table><table style='width:100%;border-top:1px solid #B0B0B0;'><tr><td>";
268 continue;
269 }
271 /* Skip disabled boxes */
272 if(!$box['enabled']) continue;
274 /* Check if box is checked */
275 if($box['default'] == true){
276 $boxes .="<input type='checkbox' name=\"".$box['name']."\" value='1' title=\"".htmlentities($box['value'])."\" checked ".$boxClick."> ".$box['string']."<br>";
277 }else{
278 $boxes .="<input type='checkbox' name=\"".$box['name']."\" value='1' title=\"".htmlentities($box['value'])."\" ".$boxClick."> ".$box['string']."<br>";
279 }
280 }
281 $smarty->assign("CheckBoxes", $boxes);
283 /* Assign regex fields
284 */
285 $regexes = "";
286 foreach($this->array_Regexes as $regex){
287 $regexes.="<table summary=\"\" style=\"width:100%;border-top:1px solid #B0B0B0;\">
288 <tr>
289 <td>
290 <label for=\"".$regex['name']."\">
291 <img alt=\"".$regex['string']."\" src=\"".$regex['image']."\" align=middle>
292 </label>
293 </td>
294 <td width=\"99%\">
295 <input type=\"text\" style='width:99%' name=\"".$regex['name']."\" maxlength='20'
296 value=\"".htmlentities($regex['value'])."\" title=\"".htmlentities($regex['string'])."\">
297 </td>
298 </tr>
299 </table>";
300 }
301 $smarty->assign("regexes" , $regexes );
303 /* Hide Filter Part if Requested or empty */
304 if((empty($boxes)) && (empty($regexes)) || ($this->HideFilterPart)){
305 $smarty->assign("Skip_Filter_Part", true);
306 }else{
307 $smarty->assign("Skip_Filter_Part", false);
308 }
310 /* Assign alphabet and display it
311 */
312 $smarty->assign("Display_alphabet", $this->bool_DisplayAlpahabet);
313 $smarty->assign("alphabet", generate_alphabet());
314 $smarty->assign("Header" , $this->string_ListHeader );
315 $smarty->assign("Summary" , $this->string_Summary);
316 $smarty->assign("Title" , $this->string_Title);
317 $smarty->assign("Information" , $this->string_Information);
319 /* Check for exeeded sizelimit */
320 $smarty->assign("hint" , print_sizelimit_warning());
321 $smarty->assign("DivList" , $divlist->DrawList());
324 if($this->is_headpage){
325 $smarty->assign("tree_image", get_template_path('images/tree.png'));
326 $smarty->assign("infoimage", get_template_path('images/info.png'));
327 $smarty->assign("launchimage", get_template_path('images/launch.png'));
328 $smarty->assign("apply", apply_filter());
329 }else{
330 $smarty->assign("tree_image", get_template_path('images/tree.png'));
331 $smarty->assign("infoimage", get_template_path('images/info_small.png'));
332 $smarty->assign("launchimage", get_template_path('images/rocket.png'));
333 $smarty->assign("apply", apply_filter());
334 }
336 /* Button handling */
337 $smarty->assign("SaveButtonString" ,$this->SaveButtonString);
338 $smarty->assign("CloseButtonString",$this->CloseButtonString);
340 $smarty->assign("Display_Close", $this->bool_DisplayCloseButton);
341 $smarty->assign("Display_Save" , $this->bool_DisplaySaveButton);
343 $smarty->assign("filterName" , $this->filterName);
344 $smarty->assign("is_headpage" , $this->is_headpage);
346 $display = $smarty->fetch(get_template_path("MultiSelectWindow.tpl"));
347 return($display);
348 }
350 /* Set the close var, which simulates the close button is pressed */
351 function Close()
352 {
353 $this->is_closed = true;
354 }
356 function Save()
357 {
358 $this->is_saved = true;
359 }
361 /* Store all checkboxes/ regexes ...
362 Store data also into a session var, to keep the checkboxes check after reload */
363 function save_object()
364 {
365 /* Get up to date config */
366 if(isset($this->parent->config)){
367 $this->config = $this->parent->config;
368 }
370 /* Update current base */
371 if($this->DepartmentsAdded){
372 $s_action ="";
373 foreach($_POST as $key => $value){
374 if(preg_match("/^dep_back.*/i",$key)){
375 $s_action="back";
376 }elseif(preg_match("/^dep_root.*/",$key)){
377 $s_action="root";
378 }elseif(preg_match("/^dep_home.*/i",$key)){
379 $s_action="home";
380 }
381 }
383 /* Save base selection from headpage selectbox*/
384 if(isset($_POST['CurrentMainBase'])){
385 $this->selectedBase = $_POST['CurrentMainBase'];
386 }
388 /* Homebutton is posted */
389 if($s_action=="home"){
390 $ui= get_userinfo();
391 $base = get_base_from_people($ui->dn);
392 $this->selectedBase= $base;
393 }
395 /* Open selected department
396 this is posted by the parent class MultiSelectWindow */
397 if(isset($_GET['act'])&& ($_GET['act'] == "dep_open")){
398 $s_entry = base64_decode($_GET['dep_id']);
399 if (!isset($this->config->departments[$s_entry])){
400 print_red(_("Error: The requested subtree has an inconsistent DN encoding, check your LDAP!"));
401 } else {
402 $this->selectedBase = $this->config->departments[$s_entry];
403 }
404 }
406 /* back to the roots ^^ */
407 if($s_action=="root"){
408 $this->selectedBase=($this->config->current['BASE']);
409 $dep_id = $this->ui->get_module_departments($this->module);
410 $this->selectedBase = $dep_id[key($dep_id)];
411 }
414 /* If Back-button is pressed, move back one step in DN */
415 if($s_action=="back"){
417 /* Get parent deprtment and check if we are allowed to step in it */
418 $base_back= preg_replace("/^[^,]+,/", "", $_SESSION['CurrentMainBase']);
419 $dep_id = $this->ui->get_module_departments($this->module);
420 if(in_array_ics($base_back,$dep_id)){
422 /* The department array keeps non DN entries as index. We need to convert
423 it before checking the existance. */
424 $base_back= trim(convert_department_dn($base_back));
426 /* Check if the department exists, otherwise revert to the configure base DN */
427 if(isset($this->config->departments[$base_back])){
428 $this->selectedBase= $this->config->departments[$base_back];
429 }else{
430 $this->selectedBase= $this->config->departments['/'];
431 }
432 }
433 }
434 $_SESSION['CurrentMainBase'] = $this->selectedBase;
435 }
437 if(isset($_POST['MultiSelectWindow'.$this->filterName])){
439 /* Save some additional vars */
440 foreach($this->SaveAdditionalVars as $name){
441 if(isset($_POST[$name])){
442 if(isset($this->$name)){
443 $this->$name = $_POST[$name];
444 $_SESSION['MultiDialogFilters'][$this->filterName][$name] = $_POST[$name];
445 }
446 }
447 }
449 /* Check posts from checkboxes
450 */
451 foreach($this->array_Checkboxes as $key => $box){
452 if(isset($_POST[$box['name']])){
453 $this->array_Checkboxes[$key]['default'] = true;
454 $this->$box['name'] = true;
455 }else{
456 $this->array_Checkboxes[$key]['default'] = false;
457 $this->$box['name'] = false;
458 }
459 /* Save settings in out session */
460 $_SESSION['MultiDialogFilters'][$this->filterName][$box['name']] = $this->$box['name'];
461 }
463 /* Check regex posts */
464 foreach($this->array_Regexes as $key => $box){
465 $this->array_Regexes[$key]['value'] = $_POST[$box['name']];
466 $this->$box['name'] = $_POST[$box['name']];
467 $_SESSION['MultiDialogFilters'][$this->filterName][$box['name']] = $this->$box['name'];
468 }
470 /* call close/save if buttons are pressed */
471 if(isset($_POST['CloseMultiSelectWindow'])){
472 $this->Close();
473 }
475 if(isset($_POST['SaveMultiSelectWindow'])){
476 $this->Save();
477 }
478 }
480 /* check for alphabet selection
481 Check which regexes are connected to the alphabet
482 */
483 if(isset($_GET['search'])){
484 foreach($this->array_Regexes as $key => $box){
485 /* check if this regex is connected to the alphabet selection */
486 if(($box['connAlpha'])&&(isset($_GET['search']))){
487 $val = $_GET['search']."*";
488 $val = preg_replace("/\*\**/","*",$val);
489 $this->array_Regexes[$key]['value'] = $val;
490 $this->$box['name'] = $val;
491 $_SESSION['MultiDialogFilters'][$this->filterName][$box['name']] = $val;
492 }
493 }
494 }
495 }
498 /* Create header snapshot value */
499 function get_snapshot_header()
500 {
501 $str = " ";
502 if($this->parent->snapshotEnabled()){
503 $ok = false;
504 foreach($this->parent->get_used_snapshot_bases() as $base){
505 $ok |= count($this->parent->getAllDeletedSnapshots($base)) >= 1 ;
506 }
507 if($ok){
508 $str = "<input class='center' type='image' align='middle' src='images/restore.png'
509 title='"._("Restore snapshopts of already deleted objects")."'
510 alt='"._("Restore")."' name='RestoreDeletedSnapShot'> ";
511 }else{
512 $str = "<img class='center' src='images/restore_grey.png' alt=''> ";
513 }
515 # $str .= "<img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ";
516 }
517 return($str);
518 }
521 function GetSnapShotActions($dn)
522 {
523 $str= "";
524 if($this->parent->snapshotEnabled()){
526 if(count($this->parent->Available_SnapsShots($dn))){
527 $str.= "<input class='center' type='image' src='images/restore.png'
528 alt='"._("Restore snapshot")."' name='RestoreSnapShotDialog_".base64_encode($dn)."' title='"._("Restore snapshot")."'> ";
529 } else {
530 $str = "<img class='center' src='images/restore_grey.png' alt=''> ";
531 }
533 $str.= "<input class='center' type='image' src='images/snapshot.png'
534 alt='"._("Create snapshot")."' name='CreateSnapShotDialog_".base64_encode($dn)."' title='"._("Create a new snapshot from this object")."'> ";
535 }
537 return($str);
538 }
541 /* this function adds the sub-departments of the current tree to the list */
542 function AddDepartments($base = false,$numtabs = 3)
543 {
544 $this->DepartmentsAdded = true;
546 /* check for a valid base */
547 if(!$base){
548 if(!isset($_SESSION['CurrentMainBase'])){
549 $_SESSION['CurrentMainBase'] = $this->config->current['BASE'];
550 }
551 $base = $_SESSION['CurrentMainBase'];
552 }
554 /* Create ldap obj and switch into base*/
555 $ldap = $this->config->get_ldap_link();
556 $ldap->cd($base);
558 /* reset current deps */
559 $this->departments = array();
561 /* Get all departments within this subtree */
562 $deps= get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
563 array("ou", "description"), GL_SIZELIMIT | GL_CONVERT);
565 /* Edit delete link for system types
566 */
567 $linkopen = "<a href='?plug=".$_GET['plug']."&act=dep_open&dep_id=%s'>%s</a>";
569 /* Create an array with all visible (in the list) departments */
570 $departments = array();
571 foreach($deps as $value){
572 if(isset($value['description'][0])){
573 $this->departments[$value['dn']]= get_sub_department($value['dn'])." - [".$value["description"][0]."]";
574 }else{
575 $this->departments[$value['dn']]= get_sub_department($value['dn']);
576 }
577 }
578 natcasesort($this->departments);
580 /* Add deps to this dialog object list */
581 foreach($this->departments as $key=> $val){
583 /* Add missing entries ... */
584 if(!isset($this->config->departments[trim($key)])){
585 $this->config->departments[trim($key)]="";
586 }
588 /* check if this department contains sub-departments
589 Display different image in this case
590 */
591 $non_empty="";
592 $nkey= normalizePreg($key);
593 foreach($this->config->departments as $keyd=>$vald ){
594 if(preg_match("/$nkey\/.*/",$keyd)){
595 $non_empty="full";
596 }
597 }
599 /* Add to divlist */
600 $row = array();
601 $row[]=$field1=array("string"=>"<img src='images/".$non_empty."folder.png' alt='department'>","attach"=>"style='text-align:center;width:20px;'");
602 $row[]=$field2=array("string"=>sprintf($linkopen,base64_encode($key),$val), "attach" => "style=''");
604 if($numtabs > 2){
605 for($i = 2 ; $i <$numtabs;$i++){
606 if(isset( $this->array_Header[$i]['attach'])){
607 $row[] = array("string"=>" ","attach" => $this->array_Header[$i]['attach']);
608 }else{
609 $row[] = array("string"=>" ");
610 }
611 }
612 }
614 $this->AddElement($row);
615 }
616 }
617 }
618 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
619 ?>