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();
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();
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 }
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 {
190 /* Check for exeeded sizelimit */
191 if (($message= check_sizelimit()) != ""){
192 return($message);
193 }
195 $smarty = get_smarty();
197 $divlist = new divlist($this->string_Title);
198 $divlist->SetSummary($this->string_Summary);
199 $divlist->SetEntriesPerPage(0); // 0 for scrollable list
201 /* set Header informations
202 */
203 $header = array();
204 foreach($this->array_Header as $head){
205 $header[] = $head;
206 }
207 $divlist->SetHeader($header);
209 /* set Entries
210 */
211 $elements = array();
212 foreach($this->array_Elements as $element){
213 $divlist->AddEntry($element);
214 }
216 /* Create checkboxes fields
217 */
218 $boxes = "";
219 $boxClick = " onClick='document.mainform.submit();' ";
220 foreach($this->array_Checkboxes as $box){
222 if($box['name'] == SEPERATOR){
223 $boxes .= "</td></tr></table><table style='width:100%;border-top:1px solid #B0B0B0;'><tr><td>";
224 continue;
225 }
227 /* Skip disabled boxes */
228 if(!$box['enabled']) continue;
230 /* Check if box is checked */
231 if($box['default'] == true){
232 $boxes .="<input type='checkbox' name='".$box['name']."' value='1' title='".$box['value']."' checked ".$boxClick."> ".$box['string']."<br>";
233 }else{
234 $boxes .="<input type='checkbox' name='".$box['name']."' value='1' title='".$box['value']."'".$boxClick.";> ".$box['string']."<br>";
235 }
236 }
237 $smarty->assign("CheckBoxes", $boxes);
239 /* Assign regex fields
240 */
241 $regexes = "";
242 foreach($this->array_Regexes as $regex){
243 $regexes.="<table summary=\"\" style=\"width:100%;border-top:1px solid #B0B0B0;\">
244 <tr>
245 <td>
246 <label for=\"".$regex['name']."\">
247 <img alt=\"".$regex['string']."\" src=\"".$regex['image']."\" align=middle>
248 </label>
249 </td>
250 <td width=\"99%\">
251 <input type='text' style='width:99%' name='".$regex['name']."' maxlength='20'
252 value='".$regex['value']."' title=\"".$regex['string']."\">
253 </td>
254 </tr>
255 </table>";
256 }
257 $smarty->assign("regexes" , $regexes );
259 /* Assign alphabet and display it
260 */
261 $smarty->assign("Display_alphabet", $this->bool_DisplayAlpahabet);
262 $smarty->assign("alphabet", generate_alphabet());
263 $smarty->assign("Header" , $this->string_ListHeader );
264 $smarty->assign("Summary" , $this->string_Summary);
265 $smarty->assign("Title" , $this->string_Title);
266 $smarty->assign("Information" , $this->string_Information);
268 /* Check for exeeded sizelimit */
269 $smarty->assign("hint" , print_sizelimit_warning());
270 $smarty->assign("DivList" , $divlist->DrawList());
273 if($this->is_headpage){
274 $smarty->assign("tree_image", get_template_path('images/tree.png'));
275 $smarty->assign("infoimage", get_template_path('images/info.png'));
276 $smarty->assign("launchimage", get_template_path('images/launch.png'));
277 $smarty->assign("apply", apply_filter());
278 }else{
279 $smarty->assign("tree_image", get_template_path('images/tree.png'));
280 $smarty->assign("infoimage", get_template_path('images/info_small.png'));
281 $smarty->assign("launchimage", get_template_path('images/rocket.png'));
282 $smarty->assign("apply", apply_filter());
283 }
285 /* Button handling */
286 $smarty->assign("SaveButtonString" ,$this->SaveButtonString);
287 $smarty->assign("CloseButtonString",$this->CloseButtonString);
289 $smarty->assign("Display_Close", $this->bool_DisplayCloseButton);
290 $smarty->assign("Display_Save" , $this->bool_DisplaySaveButton);
292 $smarty->assign("filterName" , $this->filterName);
293 $smarty->assign("is_headpage" , $this->is_headpage);
295 $display = $smarty->fetch(get_template_path("MultiSelectWindow.tpl"));
296 return($display);
297 }
299 /* Set the close var, which simulates the close button is pressed */
300 function Close()
301 {
302 $this->is_closed = true;
303 }
305 function Save()
306 {
307 $this->is_saved = true;
308 }
310 /* Store all checkboxes/ regexes ...
311 Store data also into a session var, to keep the checkboxes check after reload */
312 function save_object()
313 {
314 if(isset($_POST['MultiSelectWindow'.$this->filterName])){
316 /* Check posts from checkboxes
317 */
318 foreach($this->array_Checkboxes as $key => $box){
319 if(isset($_POST[$box['name']])){
320 $this->array_Checkboxes[$key]['default'] = true;
321 $this->$box['name'] = true;
322 }else{
323 $this->array_Checkboxes[$key]['default'] = false;
324 $this->$box['name'] = false;
325 }
326 /* Save settings in out session */
327 $_SESSION['MultiDialogFilters'][$this->filterName][$box['name']] = $this->$box['name'];
328 }
330 /* Check regex posts */
331 foreach($this->array_Regexes as $key => $box){
332 $this->array_Regexes[$key]['value'] = $_POST[$box['name']];
333 $this->$box['name'] = $_POST[$box['name']];
334 $_SESSION['MultiDialogFilters'][$this->filterName][$box['name']] = $this->$box['name'];
335 }
337 /* call close/save if buttons are pressed */
338 if(isset($_POST['CloseMultiSelectWindow'])){
339 $this->Close();
340 }
342 if(isset($_POST['SaveMultiSelectWindow'])){
343 $this->Save();
344 }
345 }
347 /* check for alphabet selection
348 Check which regexes are connected to the alphabet
349 */
350 if(isset($_GET['search'])){
351 foreach($this->array_Regexes as $key => $box){
352 /* check if this regex is connected to the alphabet selection */
353 if(($box['connAlpha'])&&(isset($_GET['search']))){
354 $val = $_GET['search']."*";
355 $val = preg_replace("/\*\**/","*",$val);
356 $this->array_Regexes[$key]['value'] = $val;
357 $this->$box['name'] = $val;
358 }
359 }
360 }
362 }
364 /* this function adds the sub-departments of the current tree to the list */
365 function AddDepartments($base = false,$numtabs = 3)
366 {
367 /* check for a valid base */
368 if(!$base){
369 if(!isset($_SESSION['CurrentMainBase'])){
370 $_SESSION['CurrentMainBase'] = $this->config->current['BASE'];
371 }
372 $base = $_SESSION['CurrentMainBase'];
373 }
375 /* Create ldap obj and switch into base*/
376 $ldap = $this->config->get_ldap_link();
377 $ldap->cd($base);
379 /* reset current deps */
380 $this->departments = array();
382 /* Get all departments within this subtree */
383 $deps= get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->ui->subtreeACL,
384 $base, array("ou", "description"), GL_SIZELIMIT | GL_CONVERT);
386 /* Edit delete link for system types
387 */
388 $linkopen = "<a href='?plug=".$_GET['plug']."&act=dep_open&dep_id=%s'>%s</a>";
390 /* Create an array with all visible (in the list) departments */
391 $departments = array();
392 foreach($deps as $value){
393 if(isset($value['description'][0])){
394 $this->departments[$value['dn']]= get_sub_department($value['dn'])." - [".$value["description"][0]."]";
395 }else{
396 $this->departments[$value['dn']]= get_sub_department($value['dn']);
397 }
398 }
399 natcasesort($this->departments);
401 /* Add deps to this dialog object list */
402 foreach($this->departments as $key=> $val){
403 /* Add missing entries ... */
404 if(!isset($this->config->departments[trim($key)])){
405 $this->config->departments[trim($key)]="";
406 }
408 /* check if this department contains sub-departments
409 Display different image in this case
410 */
411 $non_empty="";
412 $nkey= normalizePreg($key);
413 foreach($this->config->departments as $keyd=>$vald ){
414 if(preg_match("/$nkey\/.*/",$keyd)){
415 $non_empty="full";
416 }
417 }
420 /* Add to divlist */
421 $row = array();
422 $row[] = $field1 = array("string" => "<img src='images/".$non_empty."folder.png' alt='department'>", "attach" => "style='text-align:center;width:20px;'");
423 $row[] = $field2 = array("string" => sprintf($linkopen,base64_encode($key),$val), "attach" => "style=''");
425 if($numtabs > 2){
426 for($i = 2 ; $i <$numtabs;$i++){
427 if($i ==($numtabs-1)){
428 $row[] = array("string"=>" ","attach" => "style='width:60px;border-right:0px;text-align:right;'");
429 }else{
430 $row[] = array("string"=>" ");
431 }
432 }
433 }
435 $this->AddElement($row);
436 }
437 }
438 }
440 ?>