Code

Fixed application freezing
[gosa.git] / include / class_MultiSelectWindow.inc
1 <?php
3 class MultiSelectWindow{
5         var $bool_DisplayAlpahabet      = false;
6         var $bool_DisplayCloseButton= true;     
7         var $bool_DisplaySaveButton = true;     
9         var $SaveButtonString           = "";
10         var $CloseButtonString          = "";
12         var $string_Title                       = "";
13         var $string_ListHeader          = "";
14         var $string_Summary                     = "";
15         var $string_Information         = "";
17         var $array_Header                       = array();
18         var $array_Elements                     = array();      
19         var $array_Checkboxes           = array();      
20         var $array_Regexes                      = array();      
22         var $config                                     = "";
24         var $is_closed                          = false;
25         var $is_saved                           = false;
27         function ClearElementsList()
28         {
29                 $this->array_Elements = array();
30         }
32         function AddRegex($name,$string,$value,$conn)
33         {
34                 $arr = array();
35                 $arr['name']            = $name;
36                 $arr['string']          = $string;
37                 $arr['value']           = $value;       
38                 $arr['connAlpha']       = $conn;                // Connect with alphabet select 
39                 $this->array_Regexes[] = $arr;
40         }
42         function MultiSelectWindow($config){
43                 $this->config = $config;
44                 $this->SaveButtonString         = _("Save");
45                 $this->CloseButtonString        = _("Close");
46         }
48         function SetTitle($str){
49                 $this->string_Title = $str;
50         }
52         function SetListHeader($str){
53                 $this->string_ListHeader = $str;
54         }
56         function SetSummary($str){
57                 $this->string_Summary = $str;
58         }
60         function SetSaveButtonString($str){
61                 $this->SaveButtonString = $str;
62         }
64         function SetCloseButtonString($str){
65                 $this->CloseButtonString = $str;
66         }
68         function SetInformation($str){
69                 $this->string_Information = $str;
70         }
72         function EnableAplhabet($bool){
73                 $this->bool_DisplayAlpahabet = $bool;
74         }
76         function AddHeader($arr){
77                 $this->array_Header[] = $arr;
78         }
80         function AddElement($arr){
81                 $this->array_Elements[] = $arr;
82         }
84         function AddCheckBox($name,$value,$string,$default){
85                 $arr = array();
86                 $arr['name']    = $name;
87                 $arr['string']  = $string;
88                 $arr['value']   = $value;
89                 $arr['default'] = $default;
90                 $this->array_Checkboxes[] = $arr;
91         }
93         function isClosed()
94         {
95                 return($this->is_closed);
96         }
98         function EnableCloseButton($bool)
99         {
100                 $this->bool_DisplayCloseButton = $bool;
101         }
103         function EnableSaveButton ($bool)
104         {
105                 $this->bool_DisplaySaveButton = $bool;
106         }
108         function Draw()
109         {
110                 $smarty = get_smarty();
112                 $divlist = new divlist($this->string_Title);
113                 $divlist->SetSummary($this->string_Summary);
114                 $divlist->SetEntriesPerPage(0); // 0 for scrollable list 
116                 /* set Header informations 
117                  */
118                 $header = array();
119                 foreach($this->array_Header as $head){
120                         $header[] = $head;
121                 }
122                 $divlist->SetHeader($header);
124                 /* set Entries 
125                  */
126                 $elements = array();
127                 foreach($this->array_Elements as $element){
128                         $divlist->AddEntry($element);
129                 }
131                 /* Create checkboxes fields 
132                  */
133                 $boxes = "";
134                 $boxClick = " onClick='document.mainform.submit();' ";
135                 foreach($this->array_Checkboxes as $box){
136                         if($box['default'] == true){
137                                 $boxes .="<input type='checkbox' name='".$box['name']."' value='".$box['value']."' checked ".$boxClick.">&nbsp;".$box['string']."<br>";
138                         }else{
139                                 $boxes .="<input type='checkbox' name='".$box['name']."' value='".$box['value']."'".$boxClick.";>&nbsp;".$box['string']."<br>";
140                         }
141                 }
142                 $smarty->assign("CheckBoxes", $boxes);
144                 /* Assign regex fields 
145                  */
146                 $regexes = "";
147                 foreach($this->array_Regexes as $regex){
148                         $regexes.="<table summary=\"\" style=\"width:100%;border-top:1px solid #B0B0B0;\">
149                                 <tr>
150                                 <td>
151                                 <label for=\"".$regex['name']."\">
152                                 <img alt=\"".$regex['string']."\" src=\"images/search.png\" align=middle>
153                                 </label>
154                                 </td>
155                                 <td width=\"99%\">
156                                 <input type='text' style='width:99%' name='".$regex['name']."' maxlength='20'
157                                 value='".$regex['value']."' title=\"".$regex['string']."\"> 
158                                 </td>
159                                 </tr>
160                                 </table>";
161                 }
162                 $smarty->assign("regexes"                       , $regexes );
163                 
164                 /* Assign alphabet and display it 
165          */     
166                 $smarty->assign("Display_alphabet",     $this->bool_DisplayAlpahabet);
167                 $smarty->assign("alphabet",             generate_alphabet());
169                 $smarty->assign("Header"                        , $this->string_ListHeader );
170                 $smarty->assign("Summary"                       , $this->string_Summary);
171                 $smarty->assign("Title"                         , $this->string_Title);
172                 $smarty->assign("Information"           , $this->string_Information);
174                 $smarty->assign("DivList"                       , $divlist->DrawList());
176                 $smarty->assign("search_image",         get_template_path('images/search.png'));
177                 $smarty->assign("searchu_image",        get_template_path('images/search_user.png'));
178                 $smarty->assign("tree_image",           get_template_path('images/tree.png'));
179                 $smarty->assign("infoimage",            get_template_path('images/info_small.png'));
180                 $smarty->assign("launchimage",          get_template_path('images/rocket.png'));
181                 $smarty->assign("apply",                        apply_filter());
183                 /* Button handling */
184                 $smarty->assign("SaveButtonString" ,$this->SaveButtonString);
185                 $smarty->assign("CloseButtonString",$this->CloseButtonString);
186         
187                 $smarty->assign("Display_Close",        $this->bool_DisplayCloseButton);
188                 $smarty->assign("Display_Save" ,        $this->bool_DisplaySaveButton);
190                 $display = $smarty->fetch(get_template_path("MultiSelectWindow.tpl"));
191                 return($display);
192         }
194         function Close()
195         {
196                 $this->is_closed = true;
197         }
199         function Save()
200         {
201                 $this->is_saved = true;
202         }
204         function save_object()
205         {
206                 if(isset($_POST['MultiSelectWindow'])){
208                         /* Check posts from checkboxes 
209              */
210                         foreach($this->array_Checkboxes as $key => $box){
211                                 if(isset($_POST[$box['name']])){
212                                         $this->array_Checkboxes[$key]['default'] = true;
213                                         $this->$box['name'] = true;
214                                 }else{
215                                         $this->array_Checkboxes[$key]['default'] = false;
216                                         $this->$box['name'] = false;
217                                 }
218                         }
220                         /* Check regex posts */
221                         foreach($this->array_Regexes as $key => $box){
222                                 $this->array_Regexes[$key]['value'] = $_POST[$box['name']];
223                                 $this->$box['name'] = $_POST[$box['name']];
224                         }
226                         /* call close/save if buttons are pressed */
227                         if(isset($_POST['CloseMultiSelectWindow'])){
228                                 $this->Close();
229                         }
230                         
231                         if(isset($_POST['SaveMultiSelectWindow'])){
232                                 $this->Save();
233                         }
234                 }
236                 /* check for alphabet selection
237            Check which regexes are connected to the alphabet 
238          */     
239                 if(isset($_GET['search'])){
240                         foreach($this->array_Regexes as $key => $box){
241                                 /* check if this regex is connected to the alphabet selection */
242                                 if(($box['connAlpha'])&&(isset($_GET['search']))){
243                                         $val =  $_GET['search']."*";
244                                         $val = preg_replace("/\*\**/","*",$val);
245                                         $this->array_Regexes[$key]['value'] = $val;
246                                         $this->$box['name'] = $val;
247                                 }
248                         }
249                 }
251         }
254 ?>