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 = array("");
24 var $is_closed = false;
25 var $is_saved = false;
27 var $is_headpage = false; // if true the design changes
29 var $filterName = "Liste";
31 function ClearElementsList()
32 {
33 $this->array_Elements = array();
34 }
36 /* Adds a regex input field to the current dialog */
37 function AddRegex($name,$string,$value,$conn,$image="images/search.png")
38 {
39 $arr = array();
41 /* Check if the given input field name was already used
42 for this type of dialog */
43 if(isset($_SESSION['MultiDialogFilters'][$this->filterName][$name])){
44 $arr['value'] = $_SESSION['MultiDialogFilters'][$this->filterName][$name];
45 $this->$name = $arr['value'];
46 }else{
47 $arr['value'] = $value;
48 }
50 $arr['name'] = $name;
51 $arr['string'] = $string;
52 $arr['image'] = $image;
53 $arr['connAlpha'] = $conn; // Connect with alphabet select
54 $this->array_Regexes[] = $arr;
55 }
57 /* Contrucktion */
58 function MultiSelectWindow($config,$filterName)
59 {
60 $this->config = $config;
61 $this->SaveButtonString = _("Save");
62 $this->CloseButtonString = _("Close");
63 $this->filterName = $filterName;
64 }
66 /* Enables the headpage mode, which changes the list look */
67 function SetHeadpageMode()
68 {
69 $this->is_headpage = true;
70 }
72 /* Sets the List internal name (not displayed anywhere)
73 it is used to identify every single list
74 */
75 function SetTitle($str)
76 {
77 $this->string_Title = $str;
78 }
80 /* Set the list header string */
81 function SetListHeader($str)
82 {
83 $this->string_ListHeader = $str;
84 }
86 /* This sets the list description which is the first gray bar on top of the list */
87 function SetSummary($str)
88 {
89 $this->string_Summary = $str;
90 }
92 /* If the save button is enabled, you can change its caption with this function */
93 function SetSaveButtonString($str)
94 {
95 $this->SaveButtonString = $str;
96 }
98 /* If the close button is enabled, you can change its caption with this function */
99 function SetCloseButtonString($str)
100 {
101 $this->CloseButtonString = $str;
102 }
104 /* With this function you can change the text of the information box */
105 function SetInformation($str)
106 {
107 $this->string_Information = $str;
108 }
110 /* Display the alphabet selection box*/
111 function EnableAplhabet($bool)
112 {
113 $this->bool_DisplayAlpahabet = $bool;
114 }
116 /* Add additional header col */
117 function AddHeader($arr)
118 {
119 $this->array_Header[] = $arr;
120 }
122 /* add additional List element */
123 function AddElement($arr)
124 {
125 $this->array_Elements[] = $arr;
126 }
128 /* Add a checkbox to the filter element,
129 the name specifies an existing class var to store the 'selection' */
130 function AddCheckBox($name,$value,$string,$default)
131 {
132 $arr = array();
134 /* Check if there was already a variable
135 for this dialog which we should use instead of the default*/
136 if(isset($_SESSION['MultiDialogFilters'][$this->filterName][$name])){
137 $arr['default'] = $_SESSION['MultiDialogFilters'][$this->filterName][$name];
138 $this->$name = $arr['default'];
139 }else{
140 $arr['default'] = $default;
141 }
143 $arr['name'] = $name;
144 $arr['string'] = $string;
145 $arr['value'] = $value;
146 $this->array_Checkboxes[] = $arr;
147 }
149 /* Returns true if the close button was pressed */
150 function isClosed()
151 {
152 return($this->is_closed);
153 }
155 /* Enable the close button */
156 function EnableCloseButton($bool)
157 {
158 $this->bool_DisplayCloseButton = $bool;
159 }
161 /* Enable the save button on the bottom of the list*/
162 function EnableSaveButton ($bool)
163 {
164 $this->bool_DisplaySaveButton = $bool;
165 }
167 /* Draw the list with all list elements and filters */
168 function Draw()
169 {
170 $smarty = get_smarty();
172 $divlist = new divlist($this->string_Title);
173 $divlist->SetSummary($this->string_Summary);
174 $divlist->SetEntriesPerPage(0); // 0 for scrollable list
176 /* set Header informations
177 */
178 $header = array();
179 foreach($this->array_Header as $head){
180 $header[] = $head;
181 }
182 $divlist->SetHeader($header);
184 /* set Entries
185 */
186 $elements = array();
187 foreach($this->array_Elements as $element){
188 $divlist->AddEntry($element);
189 }
191 /* Create checkboxes fields
192 */
193 $boxes = "";
194 $boxClick = " onClick='document.mainform.submit();' ";
195 foreach($this->array_Checkboxes as $box){
196 if($box['default'] == true){
197 $boxes .="<input type='checkbox' name='".$box['name']."' value='1' title='".$box['value']."' checked ".$boxClick."> ".$box['string']."<br>";
198 }else{
199 $boxes .="<input type='checkbox' name='".$box['name']."' value='1' title='".$box['value']."'".$boxClick.";> ".$box['string']."<br>";
200 }
201 }
202 $smarty->assign("CheckBoxes", $boxes);
204 /* Assign regex fields
205 */
206 $regexes = "";
207 foreach($this->array_Regexes as $regex){
208 $regexes.="<table summary=\"\" style=\"width:100%;border-top:1px solid #B0B0B0;\">
209 <tr>
210 <td>
211 <label for=\"".$regex['name']."\">
212 <img alt=\"".$regex['string']."\" src=\"images/search.png\" align=middle>
213 </label>
214 </td>
215 <td width=\"99%\">
216 <input type='text' style='width:99%' name='".$regex['name']."' maxlength='20'
217 value='".$regex['value']."' title=\"".$regex['string']."\">
218 </td>
219 </tr>
220 </table>";
221 }
222 $smarty->assign("regexes" , $regexes );
224 /* Assign alphabet and display it
225 */
226 $smarty->assign("Display_alphabet", $this->bool_DisplayAlpahabet);
227 $smarty->assign("alphabet", generate_alphabet());
229 $smarty->assign("Header" , $this->string_ListHeader );
230 $smarty->assign("Summary" , $this->string_Summary);
231 $smarty->assign("Title" , $this->string_Title);
232 $smarty->assign("Information" , $this->string_Information);
234 $smarty->assign("DivList" , $divlist->DrawList());
237 if($this->is_headpage){
238 $smarty->assign("tree_image", get_template_path('images/tree.png'));
239 $smarty->assign("infoimage", get_template_path('images/info.png'));
240 $smarty->assign("launchimage", get_template_path('images/launch.png'));
241 $smarty->assign("apply", apply_filter());
242 }else{
243 $smarty->assign("tree_image", get_template_path('images/tree.png'));
244 $smarty->assign("infoimage", get_template_path('images/info_small.png'));
245 $smarty->assign("launchimage", get_template_path('images/rocket.png'));
246 $smarty->assign("apply", apply_filter());
247 }
249 /* Button handling */
250 $smarty->assign("SaveButtonString" ,$this->SaveButtonString);
251 $smarty->assign("CloseButtonString",$this->CloseButtonString);
253 $smarty->assign("Display_Close", $this->bool_DisplayCloseButton);
254 $smarty->assign("Display_Save" , $this->bool_DisplaySaveButton);
256 $smarty->assign("filterName" , $this->filterName);
257 $smarty->assign("is_headpage" , $this->is_headpage);
259 $display = $smarty->fetch(get_template_path("MultiSelectWindow.tpl"));
260 return($display);
261 }
263 /* Set the close var, which simulates the close button is pressed */
264 function Close()
265 {
266 $this->is_closed = true;
267 }
269 function Save()
270 {
271 $this->is_saved = true;
272 }
274 /* Store all checkboxes/ regexes ...
275 Store data also into a session var, to keep the checkboxes check after reload */
276 function save_object()
277 {
278 if(isset($_POST['MultiSelectWindow'.$this->filterName])){
280 /* Check posts from checkboxes
281 */
282 foreach($this->array_Checkboxes as $key => $box){
283 if(isset($_POST[$box['name']])){
284 $this->array_Checkboxes[$key]['default'] = true;
285 $this->$box['name'] = true;
286 }else{
287 $this->array_Checkboxes[$key]['default'] = false;
288 $this->$box['name'] = false;
289 }
290 /* Save settings in out session */
291 $_SESSION['MultiDialogFilters'][$this->filterName][$box['name']] = $this->$box['name'];
292 }
294 /* Check regex posts */
295 foreach($this->array_Regexes as $key => $box){
296 $this->array_Regexes[$key]['value'] = $_POST[$box['name']];
297 $this->$box['name'] = $_POST[$box['name']];
298 $_SESSION['MultiDialogFilters'][$this->filterName][$box['name']] = $this->$box['name'];
299 }
301 /* call close/save if buttons are pressed */
302 if(isset($_POST['CloseMultiSelectWindow'])){
303 $this->Close();
304 }
306 if(isset($_POST['SaveMultiSelectWindow'])){
307 $this->Save();
308 }
309 }
311 /* check for alphabet selection
312 Check which regexes are connected to the alphabet
313 */
314 if(isset($_GET['search'])){
315 foreach($this->array_Regexes as $key => $box){
316 /* check if this regex is connected to the alphabet selection */
317 if(($box['connAlpha'])&&(isset($_GET['search']))){
318 $val = $_GET['search']."*";
319 $val = preg_replace("/\*\**/","*",$val);
320 $this->array_Regexes[$key]['value'] = $val;
321 $this->$box['name'] = $val;
322 }
323 }
324 }
326 }
328 /* this function adds the sub-departments of the current tree to the list */
329 function AddDepartments($base = false)
330 {
332 #FIXME the num of header cols must match the num of entry cols .
334 /* check for a valid base */
335 if(!$base){
336 if(!isset($_SESSION['CurrentMainBase'])){
337 $_SESSION['CurrentMainBase'] = $this->config->current['BASE'];
338 }
339 $base = $_SESSION['CurrentMainBase'];
340 }
342 /* Create ldap obj and switch into base*/
343 $ldap = $this->config->get_ldap_link();
344 $ldap->cd($base);
346 /* reset current deps */
347 $this->departments = array();
349 /* Get all departments within this subtree */
350 $deps= get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->ui->subtreeACL,
351 $base, array("ou", "description"), GL_SIZELIMIT | GL_CONVERT);
353 /* Edit delete link for system types
354 */
355 $linkopen = "<a href='?plug=".$_GET['plug']."&act=dep_open&dep_id=%s'>%s</a>";
357 /* Create an array with all visible (in the list) departments */
358 $departments = array();
359 foreach($deps as $value){
360 if(isset($value['description'][0])){
361 $this->departments[$value['dn']]= get_sub_department($value['dn'])." - [".$value["description"][0]."]";
362 }else{
363 $this->departments[$value['dn']]= get_sub_department($value['dn']);
364 }
365 }
366 natcasesort($this->departments);
368 /* Add deps to this dialog object list */
369 foreach($this->departments as $key=> $val){
370 /* Add missing entries ... */
371 if(!isset($this->config->departments[trim($key)])){
372 $this->config->departments[trim($key)]="";
373 }
375 /* check if this department contains sub-departments
376 Display different image in this case
377 */
378 $non_empty="";
379 $nkey= normalizePreg($key);
380 foreach($this->config->departments as $keyd=>$vald ){
381 if(preg_match("/$nkey\/.*/",$keyd)){
382 $non_empty="full";
383 }
384 }
386 /* Add to divlist */
387 $field1 = array("string" => "<img src='images/".$non_empty."folder.png' alt='department'>", "attach" => "style='text-align:center;width:20px;'");
388 $field2 = array("string" => sprintf($linkopen,base64_encode($key),$val), "attach" => "style=''");
389 $field3 = array("string" => " ", "attach" => "style='width:60px;border-right:0px;text-align:right;'");
390 $this->AddElement(array($field1,$field2,$field3));
391 }
392 }
393 }
395 ?>