8e9f0feda64735c37b1cb5c1104530083c0d712e
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 $SaveAdditionalVars = array(); // Additional Post vars to store
35 function ClearElementsList()
36 {
37 $this->array_Elements = array();
38 }
41 /* Adds a regex input field to the current dialog */
42 function AddRegex($name,$string,$value,$conn,$image="images/search.png")
43 {
44 $arr = array();
46 /* Check if the given input field name was already used
47 for this type of dialog */
48 if(isset($_SESSION['MultiDialogFilters'][$this->filterName][$name])){
49 $arr['value'] = $_SESSION['MultiDialogFilters'][$this->filterName][$name];
50 $this->$name = $arr['value'];
51 }else{
52 $arr['value'] = $value;
53 }
55 $arr['name'] = $name;
56 $arr['string'] = $string;
57 $arr['image'] = $image;
58 $arr['connAlpha'] = $conn; // Connect with alphabet select
59 $this->array_Regexes[] = $arr;
60 }
62 /* Contrucktion */
63 function MultiSelectWindow($config,$filterName)
64 {
65 $this->config = $config;
66 $this->SaveButtonString = _("Save");
67 $this->CloseButtonString = _("Close");
68 $this->filterName = $filterName;
70 /* Set default base */
71 if(!isset($_SESSION['CurrentMainBase'])){
72 $_SESSION['CurrentMainBase'] = $this->config->current['BASE'];
73 }
74 $this->selectedBase = $_SESSION['CurrentMainBase'];
76 /* Check default values for SaveAdditionalVars */
77 foreach($this->SaveAdditionalVars as $name){
78 if(isset($_SESSION['MultiDialogFilters'][$this->filterName][$name])){
79 $this->$name = $_SESSION['MultiDialogFilters'][$this->filterName][$name];
80 }
81 }
83 }
85 /* Enables the headpage mode, which changes the list look */
86 function SetHeadpageMode()
87 {
88 $this->is_headpage = true;
89 }
91 /* Sets the List internal name (not displayed anywhere)
92 it is used to identify every single list
93 */
94 function SetTitle($str)
95 {
96 $this->string_Title = $str;
97 }
99 /* Set the list header string */
100 function SetListHeader($str)
101 {
102 $this->string_ListHeader = $str;
103 }
105 /* This sets the list description which is the first gray bar on top of the list */
106 function SetSummary($str)
107 {
108 $this->string_Summary = $str;
109 }
111 /* If the save button is enabled, you can change its caption with this function */
112 function SetSaveButtonString($str)
113 {
114 $this->SaveButtonString = $str;
115 }
117 /* If the close button is enabled, you can change its caption with this function */
118 function SetCloseButtonString($str)
119 {
120 $this->CloseButtonString = $str;
121 }
123 /* With this function you can change the text of the information box */
124 function SetInformation($str)
125 {
126 $this->string_Information = $str;
127 }
129 /* Display the alphabet selection box*/
130 function EnableAplhabet($bool)
131 {
132 $this->bool_DisplayAlpahabet = $bool;
133 }
135 /* Add additional header col */
136 function AddHeader($arr)
137 {
138 $this->array_Header[] = $arr;
139 }
141 /* add additional List element */
142 function AddElement($arr)
143 {
144 $this->array_Elements[] = $arr;
145 }
147 /* Add a checkbox to the filter element,
148 the name specifies an existing class var to store the 'selection' */
149 function AddCheckBox($name,$value="Unset",$string="Unset",$default=false)
150 {
151 $arr = array();
153 if($name == SEPERATOR){
154 $arr['name'] = SEPERATOR;
155 }else{
156 /* Check if there was already a variable
157 for this dialog which we should use instead of the default*/
158 if(isset($_SESSION['MultiDialogFilters'][$this->filterName][$name])){
159 $arr['default'] = $_SESSION['MultiDialogFilters'][$this->filterName][$name];
160 $this->$name = $arr['default'];
161 }else{
162 $arr['default'] = $default;
163 $this->$name = $default;
164 }
165 $arr['name'] = $name;
166 $arr['string'] = $string;
167 $arr['value'] = $value;
168 $arr['enabled'] = true;
170 }
171 $this->array_Checkboxes[] = $arr;
172 }
175 /* Hides or unhides the checkbox with the given name */
176 function DisableCheckBox($name,$HideShow = false)
177 {
178 foreach($this->array_Checkboxes as $key => $chkbox){
179 if($chkbox['name'] == $name){
180 $this->array_Checkboxes[$key]['enabled'] = $HideShow;
181 }
182 }
183 }
186 /* Returns true if the close button was pressed */
187 function isClosed()
188 {
189 return($this->is_closed);
190 }
192 /* Enable the close button */
193 function EnableCloseButton($bool)
194 {
195 $this->bool_DisplayCloseButton = $bool;
196 }
198 /* Enable the save button on the bottom of the list*/
199 function EnableSaveButton ($bool)
200 {
201 $this->bool_DisplaySaveButton = $bool;
202 }
204 /* Add a list specific filter object to position
205 1 on top of Information
206 2 Between Information && Filter
207 3 Below the Filter Part */
208 function AddUserBoxToFilter($position)
209 {
210 return("");
211 }
213 /* Draw the list with all list elements and filters */
214 function Draw()
215 {
217 /* Check for exeeded sizelimit */
218 if (($message= check_sizelimit()) != ""){
219 return($message);
220 }
222 $smarty = get_smarty();
223 $smarty->assign("UserBox1",$this->AddUserBoxToFilter(1));
224 $smarty->assign("UserBox2",$this->AddUserBoxToFilter(2));
225 $smarty->assign("UserBox3",$this->AddUserBoxToFilter(3));
227 $divlist = new divlist($this->string_Title);
228 $divlist->SetSummary($this->string_Summary);
229 $divlist->SetEntriesPerPage(0); // 0 for scrollable list
231 /* set Header informations
232 */
233 $header = array();
234 foreach($this->array_Header as $head){
235 $header[] = $head;
236 }
237 $divlist->SetHeader($header);
239 /* set Entries
240 */
241 $elements = array();
242 foreach($this->array_Elements as $element){
243 $divlist->AddEntry($element);
244 }
246 /* Create checkboxes fields
247 */
248 $boxes = "";
249 $boxClick = " onClick='document.mainform.submit();' ";
250 foreach($this->array_Checkboxes as $box){
252 if($box['name'] == SEPERATOR){
253 $boxes .= "</td></tr></table><table style='width:100%;border-top:1px solid #B0B0B0;'><tr><td>";
254 continue;
255 }
257 /* Skip disabled boxes */
258 if(!$box['enabled']) continue;
260 /* Check if box is checked */
261 if($box['default'] == true){
262 $boxes .="<input type='checkbox' name='".$box['name']."' value='1' title='".$box['value']."' checked ".$boxClick."> ".$box['string']."<br>";
263 }else{
264 $boxes .="<input type='checkbox' name='".$box['name']."' value='1' title='".$box['value']."'".$boxClick.";> ".$box['string']."<br>";
265 }
266 }
267 $smarty->assign("CheckBoxes", $boxes);
269 /* Assign regex fields
270 */
271 $regexes = "";
272 foreach($this->array_Regexes as $regex){
273 $regexes.="<table summary=\"\" style=\"width:100%;border-top:1px solid #B0B0B0;\">
274 <tr>
275 <td>
276 <label for=\"".$regex['name']."\">
277 <img alt=\"".$regex['string']."\" src=\"".$regex['image']."\" align=middle>
278 </label>
279 </td>
280 <td width=\"99%\">
281 <input type='text' style='width:99%' name='".$regex['name']."' maxlength='20'
282 value='".$regex['value']."' title=\"".$regex['string']."\">
283 </td>
284 </tr>
285 </table>";
286 }
287 $smarty->assign("regexes" , $regexes );
289 /* Assign alphabet and display it
290 */
291 $smarty->assign("Display_alphabet", $this->bool_DisplayAlpahabet);
292 $smarty->assign("alphabet", generate_alphabet());
293 $smarty->assign("Header" , $this->string_ListHeader );
294 $smarty->assign("Summary" , $this->string_Summary);
295 $smarty->assign("Title" , $this->string_Title);
296 $smarty->assign("Information" , $this->string_Information);
298 /* Check for exeeded sizelimit */
299 $smarty->assign("hint" , print_sizelimit_warning());
300 $smarty->assign("DivList" , $divlist->DrawList());
303 if($this->is_headpage){
304 $smarty->assign("tree_image", get_template_path('images/tree.png'));
305 $smarty->assign("infoimage", get_template_path('images/info.png'));
306 $smarty->assign("launchimage", get_template_path('images/launch.png'));
307 $smarty->assign("apply", apply_filter());
308 }else{
309 $smarty->assign("tree_image", get_template_path('images/tree.png'));
310 $smarty->assign("infoimage", get_template_path('images/info_small.png'));
311 $smarty->assign("launchimage", get_template_path('images/rocket.png'));
312 $smarty->assign("apply", apply_filter());
313 }
315 /* Button handling */
316 $smarty->assign("SaveButtonString" ,$this->SaveButtonString);
317 $smarty->assign("CloseButtonString",$this->CloseButtonString);
319 $smarty->assign("Display_Close", $this->bool_DisplayCloseButton);
320 $smarty->assign("Display_Save" , $this->bool_DisplaySaveButton);
322 $smarty->assign("filterName" , $this->filterName);
323 $smarty->assign("is_headpage" , $this->is_headpage);
325 $display = $smarty->fetch(get_template_path("MultiSelectWindow.tpl"));
326 return($display);
327 }
329 /* Set the close var, which simulates the close button is pressed */
330 function Close()
331 {
332 $this->is_closed = true;
333 }
335 function Save()
336 {
337 $this->is_saved = true;
338 }
340 /* Store all checkboxes/ regexes ...
341 Store data also into a session var, to keep the checkboxes check after reload */
342 function save_object()
343 {
344 /* Update current base */
345 if($this->DepartmentsAdded){
346 $s_action ="";
347 foreach($_POST as $key => $value){
348 if(preg_match("/^dep_back.*/i",$key)){
349 $s_action="back";
350 }elseif(preg_match("/^dep_root.*/",$key)){
351 $s_action="root";
352 }elseif(preg_match("/^dep_home.*/i",$key)){
353 $s_action="home";
354 }
355 }
357 /* Save base selection from headpage selectbox*/
358 if(isset($_POST['CurrentMainBase'])){
359 $this->selectedBase = $_POST['CurrentMainBase'];
360 }
362 /* Homebutton is posted */
363 if($s_action=="home"){
364 $ui= get_userinfo();
365 $this->selectedBase=(preg_replace("/^[^,]+,/","",$ui->dn));
366 $this->selectedBase=(preg_replace("/^[^,]+,/","",$this->selectedBase));
367 }
369 /* Open selected department
370 this is posted by the parent class MultiSelectWindow */
371 if(isset($_GET['act'])&& ($_GET['act'] == "dep_open")){
372 $s_entry = base64_decode($_GET['dep_id']);
373 $this->selectedBase = $this->config->departments[trim($s_entry)];
374 }
376 /* back to the roots ^^ */
377 if($s_action=="root"){
378 $this->selectedBase=($this->config->current['BASE']);
379 }
382 /* If Back-button is pressed, move back one step in DN */
383 if($s_action=="back"){
384 //FIXME: This is not 100% correct. We'll only display ou's, but there may be
385 // a step between. You'll stumble in a "hidden" department in this case.
386 $base_back= preg_replace("/^[^,]+,/", "", $_SESSION['CurrentMainBase']);
388 /* The department array keeps non DN entries as index. We need to convert
389 it before checking the existance. */
390 $base_back= trim(convert_department_dn($base_back));
392 /* Check if the department exists, otherwise revert to the configure base DN */
393 if(isset($this->config->departments[$base_back])){
394 $this->selectedBase= $this->config->departments[$base_back];
395 }else{
396 $this->selectedBase= $this->config->departments['/'];
397 }
398 }
399 $_SESSION['CurrentMainBase'] = $this->selectedBase;
400 }
402 if(isset($_POST['MultiSelectWindow'.$this->filterName])){
404 /* Save some additional vars */
405 foreach($this->SaveAdditionalVars as $name){
406 if(isset($_POST[$name])){
407 if(isset($this->$name)){
408 $this->$name = $_POST[$name];
409 $_SESSION['MultiDialogFilters'][$this->filterName][$name] = $_POST[$name];
410 }
411 }
412 }
414 /* Check posts from checkboxes
415 */
416 foreach($this->array_Checkboxes as $key => $box){
417 if(isset($_POST[$box['name']])){
418 $this->array_Checkboxes[$key]['default'] = true;
419 $this->$box['name'] = true;
420 }else{
421 $this->array_Checkboxes[$key]['default'] = false;
422 $this->$box['name'] = false;
423 }
424 /* Save settings in out session */
425 $_SESSION['MultiDialogFilters'][$this->filterName][$box['name']] = $this->$box['name'];
426 }
428 /* Check regex posts */
429 foreach($this->array_Regexes as $key => $box){
430 $this->array_Regexes[$key]['value'] = $_POST[$box['name']];
431 $this->$box['name'] = $_POST[$box['name']];
432 $_SESSION['MultiDialogFilters'][$this->filterName][$box['name']] = $this->$box['name'];
433 }
435 /* call close/save if buttons are pressed */
436 if(isset($_POST['CloseMultiSelectWindow'])){
437 $this->Close();
438 }
440 if(isset($_POST['SaveMultiSelectWindow'])){
441 $this->Save();
442 }
443 }
445 /* check for alphabet selection
446 Check which regexes are connected to the alphabet
447 */
448 if(isset($_GET['search'])){
449 foreach($this->array_Regexes as $key => $box){
450 /* check if this regex is connected to the alphabet selection */
451 if(($box['connAlpha'])&&(isset($_GET['search']))){
452 $val = $_GET['search']."*";
453 $val = preg_replace("/\*\**/","*",$val);
454 $this->array_Regexes[$key]['value'] = $val;
455 $this->$box['name'] = $val;
456 }
457 }
458 }
460 }
462 /* this function adds the sub-departments of the current tree to the list */
463 function AddDepartments($base = false,$numtabs = 3)
464 {
465 $this->DepartmentsAdded = true;
467 /* check for a valid base */
468 if(!$base){
469 if(!isset($_SESSION['CurrentMainBase'])){
470 $_SESSION['CurrentMainBase'] = $this->config->current['BASE'];
471 }
472 $base = $_SESSION['CurrentMainBase'];
473 }
475 /* Create ldap obj and switch into base*/
476 $ldap = $this->config->get_ldap_link();
477 $ldap->cd($base);
479 /* reset current deps */
480 $this->departments = array();
482 /* Get all departments within this subtree */
483 $deps= get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->ui->subtreeACL,
484 $base, array("ou", "description"), GL_SIZELIMIT | GL_CONVERT);
486 /* Edit delete link for system types
487 */
488 $linkopen = "<a href='?plug=".$_GET['plug']."&act=dep_open&dep_id=%s'>%s</a>";
490 /* Create an array with all visible (in the list) departments */
491 $departments = array();
492 foreach($deps as $value){
493 if(isset($value['description'][0])){
494 $this->departments[$value['dn']]= get_sub_department($value['dn'])." - [".$value["description"][0]."]";
495 }else{
496 $this->departments[$value['dn']]= get_sub_department($value['dn']);
497 }
498 }
499 natcasesort($this->departments);
501 /* Add deps to this dialog object list */
502 foreach($this->departments as $key=> $val){
503 /* Add missing entries ... */
504 if(!isset($this->config->departments[trim($key)])){
505 $this->config->departments[trim($key)]="";
506 }
508 /* check if this department contains sub-departments
509 Display different image in this case
510 */
511 $non_empty="";
512 $nkey= normalizePreg($key);
513 foreach($this->config->departments as $keyd=>$vald ){
514 if(preg_match("/$nkey\/.*/",$keyd)){
515 $non_empty="full";
516 }
517 }
519 /* Add to divlist */
520 $row = array();
521 $row[]=$field1=array("string"=>"<img src='images/".$non_empty."folder.png' alt='department'>","attach"=>"style='text-align:center;width:20px;'");
522 $row[]=$field2=array("string"=>sprintf($linkopen,base64_encode($key),$val), "attach" => "style=''");
524 if($numtabs > 2){
525 for($i = 2 ; $i <$numtabs;$i++){
526 if(isset( $this->array_Header[$i]['attach'])){
527 $row[] = array("string"=>" ","attach" => $this->array_Header[$i]['attach']);
528 }else{
529 $row[] = array("string"=>" ");
530 }
531 }
532 }
534 $this->AddElement($row);
535 }
536 }
537 }
538 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
539 ?>