Code

Removed fixme
[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("");
26         var $is_closed                          = false;
27         var $is_saved                           = false;
29         var $is_headpage                        = false;        // if true the design changes
31         var $filterName                         = "Liste";
33         function ClearElementsList()
34         {
35                 $this->array_Elements = array();
36         }
39         /* Adds a regex input field to the current dialog */
40         function AddRegex($name,$string,$value,$conn,$image="images/search.png")
41         {
42                 $arr = array();
43         
44                 /* Check if the given input field name was already used 
45             for this type of dialog */  
46                 if(isset($_SESSION['MultiDialogFilters'][$this->filterName][$name])){
47                         $arr['value']   = $_SESSION['MultiDialogFilters'][$this->filterName][$name];
48                         $this->$name = $arr['value'];
49                 }else{
50                         $arr['value']   = $value;       
51                 }
53                 $arr['name']            = $name;
54                 $arr['string']          = $string;
55                 $arr['image']           = $image;       
56                 $arr['connAlpha']       = $conn;                // Connect with alphabet select 
57                 $this->array_Regexes[] = $arr;
58         }
60         /* Contrucktion */
61         function MultiSelectWindow($config,$filterName)
62         {
63                 $this->config = $config;
64                 $this->SaveButtonString         = _("Save");
65                 $this->CloseButtonString        = _("Close");
66                 $this->filterName                       = $filterName;
67         }
69         /* Enables the headpage mode, which changes the list look */
70         function SetHeadpageMode()
71         {
72                 $this->is_headpage = true;
73         }
75         /* Sets the List internal name (not displayed anywhere) 
76        it is used to identify every single list
77      */ 
78         function SetTitle($str)
79         {
80                 $this->string_Title = $str;
81         }
83         /* Set the list header string  */
84         function SetListHeader($str)
85         {
86                 $this->string_ListHeader = $str;
87         }
89         /* This sets the list description which is the first gray bar on top of the list */
90         function SetSummary($str)
91         {
92                 $this->string_Summary = $str;
93         }
95         /* If the save button is enabled, you can change its caption with this function */      
96         function SetSaveButtonString($str)
97         {
98                 $this->SaveButtonString = $str;
99         }
101         /* If the close button is enabled, you can change its caption with this function */     
102         function SetCloseButtonString($str)
103         {
104                 $this->CloseButtonString = $str;
105         }
107         /* With this function you can change the text of the information box */
108         function SetInformation($str)
109         {
110                 $this->string_Information = $str;
111         }
113         /* Display the alphabet selection box*/
114         function EnableAplhabet($bool)
115         {
116                 $this->bool_DisplayAlpahabet = $bool;
117         }
119         /* Add additional header col */
120         function AddHeader($arr)
121         {
122                 $this->array_Header[] = $arr;
123         }
125         /* add additional List element */
126         function AddElement($arr)
127         {
128                 $this->array_Elements[] = $arr;
129         }
131         /* Add a checkbox to the filter element,
132         the name specifies an existing class var to store the 'selection' */
133         function AddCheckBox($name,$value="Unset",$string="Unset",$default=false)
134         {
135                 $arr = array();
136         
137                 if($name == SEPERATOR){
138                         $arr['name'] = SEPERATOR;
139                 }else{
140                         /* Check if there was already a variable 
141                            for this dialog which we should use instead of the default*/
142                         if(isset($_SESSION['MultiDialogFilters'][$this->filterName][$name])){
143                                 $arr['default'] = $_SESSION['MultiDialogFilters'][$this->filterName][$name];
144                                 $this->$name = $arr['default'];
145                         }else{
146                                 $arr['default'] = $default;
147                         }
148                         $arr['name']    = $name;
149                         $arr['string']  = $string;
150                         $arr['value']   = $value;
151                         $arr['enabled'] = true;
152                 }
153                 $this->array_Checkboxes[] = $arr;
154         }
156         /* Hides or unhides the checkbox with the given name */
157         function DisableCheckBox($name,$HideShow = false)
158         {
159                 foreach($this->array_Checkboxes as $key => $chkbox){
160                         if($chkbox['name'] == $name){
161                                 $this->array_Checkboxes[$key]['enabled'] = $HideShow;
162                         }
163                 }
164         }
166         
168         /* Returns true if the close button was pressed */
169         function isClosed()
170         {
171                 return($this->is_closed);
172         }
174         /* Enable the close button */
175         function EnableCloseButton($bool)
176         {
177                 $this->bool_DisplayCloseButton = $bool;
178         }
180         /* Enable the save button on the bottom of the list*/
181         function EnableSaveButton ($bool)
182         {
183                 $this->bool_DisplaySaveButton = $bool;
184         }
186         /* Draw the list with all list elements and filters */
187         function Draw()
188         {
189                 $smarty = get_smarty();
191                 $divlist = new divlist($this->string_Title);
192                 $divlist->SetSummary($this->string_Summary);
193                 $divlist->SetEntriesPerPage(0); // 0 for scrollable list 
195                 /* set Header informations 
196                  */
197                 $header = array();
198                 foreach($this->array_Header as $head){
199                         $header[] = $head;
200                 }
201                 $divlist->SetHeader($header);
203                 /* set Entries 
204                  */
205                 $elements = array();
206                 foreach($this->array_Elements as $element){
207                         $divlist->AddEntry($element);
208                 }
210                 /* Create checkboxes fields 
211                  */
212                 $boxes = "";
213                 $boxClick = " onClick='document.mainform.submit();' ";
214                 foreach($this->array_Checkboxes as $box){
216                         if($box['name'] == SEPERATOR){
217                                 $boxes .= "</td></tr></table><table style='width:100%;border-top:1px solid #B0B0B0;'><tr><td>";
218                                 continue;
219                         }
221                         /* Skip disabled boxes */
222                         if(!$box['enabled']) continue;
224                         /* Check if box is checked */
225                         if($box['default'] == true){
226                                 $boxes .="<input type='checkbox' name='".$box['name']."' value='1' title='".$box['value']."' checked ".$boxClick.">&nbsp;".$box['string']."<br>";
227                         }else{
228                                 $boxes .="<input type='checkbox' name='".$box['name']."' value='1' title='".$box['value']."'".$boxClick.";>&nbsp;".$box['string']."<br>";
229                         }
230                 }
231                 $smarty->assign("CheckBoxes", $boxes);
233                 /* Assign regex fields 
234                  */
235                 $regexes = "";
236                 foreach($this->array_Regexes as $regex){
237                         $regexes.="<table summary=\"\" style=\"width:100%;border-top:1px solid #B0B0B0;\">
238                                 <tr>
239                                 <td>
240                                 <label for=\"".$regex['name']."\">
241                                 <img alt=\"".$regex['string']."\" src=\"".$regex['image']."\" align=middle>
242                                 </label>
243                                 </td>
244                                 <td width=\"99%\">
245                                 <input type='text' style='width:99%' name='".$regex['name']."' maxlength='20'
246                                 value='".$regex['value']."' title=\"".$regex['string']."\"> 
247                                 </td>
248                                 </tr>
249                                 </table>";
250                 }
251                 $smarty->assign("regexes"                       , $regexes );
252                 
253                 /* Assign alphabet and display it 
254          */     
255                 $smarty->assign("Display_alphabet",     $this->bool_DisplayAlpahabet);
256                 $smarty->assign("alphabet",             generate_alphabet());
257                 $smarty->assign("Header"                        , $this->string_ListHeader );
258                 $smarty->assign("Summary"                       , $this->string_Summary);
259                 $smarty->assign("Title"                         , $this->string_Title);
260                 $smarty->assign("Information"           , $this->string_Information);
261                 
262                 /* Check for exeeded sizelimit */
263                 $smarty->assign("hint"                          , print_sizelimit_warning());
264                 $smarty->assign("DivList"                       , $divlist->DrawList());
267                 if($this->is_headpage){
268                         $smarty->assign("tree_image",           get_template_path('images/tree.png'));
269                         $smarty->assign("infoimage",            get_template_path('images/info.png'));
270                         $smarty->assign("launchimage",          get_template_path('images/launch.png'));
271                         $smarty->assign("apply",                        apply_filter());
272                 }else{
273                         $smarty->assign("tree_image",           get_template_path('images/tree.png'));
274                         $smarty->assign("infoimage",            get_template_path('images/info_small.png'));
275                         $smarty->assign("launchimage",          get_template_path('images/rocket.png'));
276                         $smarty->assign("apply",                        apply_filter());
277                 }
279                 /* Button handling */
280                 $smarty->assign("SaveButtonString" ,$this->SaveButtonString);
281                 $smarty->assign("CloseButtonString",$this->CloseButtonString);
282         
283                 $smarty->assign("Display_Close",        $this->bool_DisplayCloseButton);
284                 $smarty->assign("Display_Save" ,        $this->bool_DisplaySaveButton);
286                 $smarty->assign("filterName"    ,       $this->filterName);
287                 $smarty->assign("is_headpage"   ,       $this->is_headpage);
288                         
289                 $display = $smarty->fetch(get_template_path("MultiSelectWindow.tpl"));
290                 return($display);
291         }
293         /* Set the close var, which simulates the close button is pressed */
294         function Close()
295         {
296                 $this->is_closed = true;
297         }
299         function Save()
300         {
301                 $this->is_saved = true;
302         }
304         /* Store all checkboxes/ regexes ... 
305         Store data also into a session var, to keep the checkboxes check after reload  */
306         function save_object()
307         {
308                 if(isset($_POST['MultiSelectWindow'.$this->filterName])){
310                         /* Check posts from checkboxes 
311              */
312                         foreach($this->array_Checkboxes as $key => $box){
313                                 if(isset($_POST[$box['name']])){
314                                         $this->array_Checkboxes[$key]['default'] = true;
315                                         $this->$box['name'] = true;
316                                 }else{
317                                         $this->array_Checkboxes[$key]['default'] = false;
318                                         $this->$box['name'] = false;
319                                 }
320                                 /* Save settings in out session */
321                                 $_SESSION['MultiDialogFilters'][$this->filterName][$box['name']] = $this->$box['name'];
322                         }
324                         /* Check regex posts */
325                         foreach($this->array_Regexes as $key => $box){
326                                 $this->array_Regexes[$key]['value'] = $_POST[$box['name']];
327                                 $this->$box['name'] = $_POST[$box['name']];
328                                 $_SESSION['MultiDialogFilters'][$this->filterName][$box['name']] = $this->$box['name'];
329                         }
331                         /* call close/save if buttons are pressed */
332                         if(isset($_POST['CloseMultiSelectWindow'])){
333                                 $this->Close();
334                         }
335                         
336                         if(isset($_POST['SaveMultiSelectWindow'])){
337                                 $this->Save();
338                         }
339                 }
341                 /* check for alphabet selection
342            Check which regexes are connected to the alphabet 
343          */     
344                 if(isset($_GET['search'])){
345                         foreach($this->array_Regexes as $key => $box){
346                                 /* check if this regex is connected to the alphabet selection */
347                                 if(($box['connAlpha'])&&(isset($_GET['search']))){
348                                         $val =  $_GET['search']."*";
349                                         $val = preg_replace("/\*\**/","*",$val);
350                                         $this->array_Regexes[$key]['value'] = $val;
351                                         $this->$box['name'] = $val;
352                                 }
353                         }
354                 }
356         }
358         /* this function adds the sub-departments of the current tree to the list */
359         function AddDepartments($base = false,$numtabs = 3)
360         {
361                 /* check for a valid base */
362                 if(!$base){
363                         if(!isset($_SESSION['CurrentMainBase'])){
364                                 $_SESSION['CurrentMainBase'] = $this->config->current['BASE'];
365                         }
366                         $base = $_SESSION['CurrentMainBase'];
367                 }
369                 /* Create ldap obj and switch into base*/
370                 $ldap = $this->config->get_ldap_link();
371                 $ldap->cd($base);
373                 /* reset current deps */
374                 $this->departments = array();
376                 /* Get all departments within this subtree */
377                 $deps= get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->ui->subtreeACL,
378                                 $base, array("ou", "description"), GL_SIZELIMIT | GL_CONVERT);
380                 /* Edit delete link for system types
381                  */
382                 $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
384                 /* Create an array with all visible (in the list) departments */
385                 $departments = array();
386                 foreach($deps as $value){
387                         if(isset($value['description'][0])){
388                                 $this->departments[$value['dn']]= get_sub_department($value['dn'])." - [".$value["description"][0]."]";
389                         }else{
390                                 $this->departments[$value['dn']]= get_sub_department($value['dn']);
391                         }
392                 }
393                 natcasesort($this->departments);
395                 /* Add deps to this dialog object list */
396                 foreach($this->departments as $key=> $val){
397                         /* Add missing entries ... */
398                         if(!isset($this->config->departments[trim($key)])){
399                                 $this->config->departments[trim($key)]="";
400                         }
402                         /* check if this department contains sub-departments
403                            Display different image in this case
404                          */
405                         $non_empty="";
406                         $nkey= normalizePreg($key);
407                         foreach($this->config->departments as $keyd=>$vald ){
408                                 if(preg_match("/$nkey\/.*/",$keyd)){
409                                         $non_empty="full";
410                                 }
411                         }
413                         
414                         /* Add to divlist */
415                         $row = array();
416                         $row[] = $field1 = array("string" => "<img src='images/".$non_empty."folder.png' alt='department'>", "attach" => "style='text-align:center;width:20px;'");
417                         $row[] = $field2 = array("string" => sprintf($linkopen,base64_encode($key),$val), "attach" => "style=''");
419                         if($numtabs > 2){       
420                                 for($i = 2 ; $i <$numtabs;$i++){
421                                         if($i ==($numtabs-1)){
422                                                 $row[] = array("string"=>"&nbsp;","attach" => "style='width:60px;border-right:0px;text-align:right;'");
423                                         }else{
424                                                 $row[] = array("string"=>"&nbsp;");
425                                         }
426                                 }
427                         }
429                         $this->AddElement($row);
430                 }
431         }
434 ?>