Code

Removed headpage
[gosa.git] / include / class_MultiSelectWindow.inc
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     }
82     
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.">&nbsp;".$box['string']."<br>";
263                         }else{
264                                 $boxes .="<input type='checkbox' name='".$box['name']."' value='1' title='".$box['value']."'".$boxClick.";>&nbsp;".$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         if (!isset($this->config->departments[$s_entry])){
374           print_red(_("Error: The requested subtree has an inconsistent DN encoding, check your LDAP!"));
375         } else {
376                                 $this->selectedBase = $this->config->departments[$s_entry];
377         }
378                         }
380                         /* back to the roots ^^ */
381                         if($s_action=="root"){
382                                 $this->selectedBase=($this->config->current['BASE']);
383                         }
386                         /* If Back-button is pressed, move back one step in DN */
387                         if($s_action=="back"){
388                                 //FIXME: This is not 100% correct. We'll only display ou's, but there may be
389                                 //       a step between. You'll stumble in a "hidden" department in this case.
390                                 $base_back= preg_replace("/^[^,]+,/", "", $_SESSION['CurrentMainBase']);
392                                 /* The department array keeps non DN entries as index. We need to convert
393                                    it before checking the existance. */
394                                 $base_back= trim(convert_department_dn($base_back));
396                                 /* Check if the department exists, otherwise revert to the configure base DN */
397                                 if(isset($this->config->departments[$base_back])){
398                                         $this->selectedBase= $this->config->departments[$base_back];
399                                 }else{
400                                         $this->selectedBase= $this->config->departments['/'];
401                                 }
402                         }
403       $_SESSION['CurrentMainBase'] = $this->selectedBase;
404                 }
406                 if(isset($_POST['MultiSelectWindow'.$this->filterName])){
408       /* Save some additional vars */
409       foreach($this->SaveAdditionalVars as $name){
410         if(isset($_POST[$name])){
411           if(isset($this->$name)){
412             $this->$name = $_POST[$name];
413             $_SESSION['MultiDialogFilters'][$this->filterName][$name] = $_POST[$name];
414           }
415         }
416       }
418                         /* Check posts from checkboxes 
419                          */
420                         foreach($this->array_Checkboxes as $key => $box){
421                                 if(isset($_POST[$box['name']])){
422                                         $this->array_Checkboxes[$key]['default'] = true;
423                                         $this->$box['name'] = true;
424                                 }else{
425                                         $this->array_Checkboxes[$key]['default'] = false;
426                                         $this->$box['name'] = false;
427                                 }
428                                 /* Save settings in out session */
429                                 $_SESSION['MultiDialogFilters'][$this->filterName][$box['name']] = $this->$box['name'];
430                         }
432                         /* Check regex posts */
433                         foreach($this->array_Regexes as $key => $box){
434                                 $this->array_Regexes[$key]['value'] = $_POST[$box['name']];
435                                 $this->$box['name'] = $_POST[$box['name']];
436                                 $_SESSION['MultiDialogFilters'][$this->filterName][$box['name']] = $this->$box['name'];
437                         }
439                         /* call close/save if buttons are pressed */
440                         if(isset($_POST['CloseMultiSelectWindow'])){
441                                 $this->Close();
442                         }
444                         if(isset($_POST['SaveMultiSelectWindow'])){
445                                 $this->Save();
446                         }
447                 }
449                 /* check for alphabet selection
450                    Check which regexes are connected to the alphabet 
451                  */     
452                 if(isset($_GET['search'])){
453                         foreach($this->array_Regexes as $key => $box){
454                                 /* check if this regex is connected to the alphabet selection */
455                                 if(($box['connAlpha'])&&(isset($_GET['search']))){
456                                         $val =  $_GET['search']."*";
457                                         $val = preg_replace("/\*\**/","*",$val);
458                                         $this->array_Regexes[$key]['value'] = $val;
459                                         $this->$box['name'] = $val;
460                                 }
461                         }
462                 }
464         }
466         /* this function adds the sub-departments of the current tree to the list */
467         function AddDepartments($base = false,$numtabs = 3)
468         {
469                 $this->DepartmentsAdded = true;
471                 /* check for a valid base */
472                 if(!$base){
473                         if(!isset($_SESSION['CurrentMainBase'])){
474                                 $_SESSION['CurrentMainBase'] = $this->config->current['BASE'];
475                         }
476                         $base = $_SESSION['CurrentMainBase'];
477                 }
479                 /* Create ldap obj and switch into base*/
480                 $ldap = $this->config->get_ldap_link();
481                 $ldap->cd($base);
483                 /* reset current deps */
484                 $this->departments = array();
486                 /* Get all departments within this subtree */
487                 $deps= get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->ui->subtreeACL,
488                                 $base, array("ou", "description"), GL_SIZELIMIT | GL_CONVERT);
490                 /* Edit delete link for system types
491                  */
492                 $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
494                 /* Create an array with all visible (in the list) departments */
495                 $departments = array();
496                 foreach($deps as $value){
497                         if(isset($value['description'][0])){
498                                 $this->departments[$value['dn']]= get_sub_department($value['dn'])." - [".$value["description"][0]."]";
499                         }else{
500                                 $this->departments[$value['dn']]= get_sub_department($value['dn']);
501                         }
502                 }
503                 natcasesort($this->departments);
505                 /* Add deps to this dialog object list */
506                 foreach($this->departments as $key=> $val){
507                         /* Add missing entries ... */
508                         if(!isset($this->config->departments[trim($key)])){
509                                 $this->config->departments[trim($key)]="";
510                         }
512                         /* check if this department contains sub-departments
513                            Display different image in this case
514                          */
515                         $non_empty="";
516                         $nkey= normalizePreg($key);
517                         foreach($this->config->departments as $keyd=>$vald ){
518                                 if(preg_match("/$nkey\/.*/",$keyd)){
519                                         $non_empty="full";
520                                 }
521                         }
523                         /* Add to divlist */
524                         $row = array();
525                         $row[]=$field1=array("string"=>"<img src='images/".$non_empty."folder.png' alt='department'>","attach"=>"style='text-align:center;width:20px;'");
526                         $row[]=$field2=array("string"=>sprintf($linkopen,base64_encode($key),$val), "attach" => "style=''");
528                         if($numtabs > 2){       
529                                 for($i = 2 ; $i <$numtabs;$i++){
530           if(isset( $this->array_Header[$i]['attach'])){
531             $row[] = array("string"=>"&nbsp;","attach" => $this->array_Header[$i]['attach']);
532           }else{
533             $row[] = array("string"=>"&nbsp;");
534           }
535                                 }
536                         }
538                         $this->AddElement($row);
539                 }
540         }
542 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
543 ?>