9a5c862ff049c1b6d438d6596e4f4dfbc25a6fb0
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 var $DepartmentsAdded = false;
34 var $selectedBase = "";
36 function ClearElementsList()
37 {
38 $this->array_Elements = array();
39 }
42 /* Adds a regex input field to the current dialog */
43 function AddRegex($name,$string,$value,$conn,$image="images/search.png")
44 {
45 $arr = array();
47 /* Check if the given input field name was already used
48 for this type of dialog */
49 if(isset($_SESSION['MultiDialogFilters'][$this->filterName][$name])){
50 $arr['value'] = $_SESSION['MultiDialogFilters'][$this->filterName][$name];
51 $this->$name = $arr['value'];
52 }else{
53 $arr['value'] = $value;
54 }
56 $arr['name'] = $name;
57 $arr['string'] = $string;
58 $arr['image'] = $image;
59 $arr['connAlpha'] = $conn; // Connect with alphabet select
60 $this->array_Regexes[] = $arr;
61 }
63 /* Contrucktion */
64 function MultiSelectWindow($config,$filterName)
65 {
66 $this->config = $config;
67 $this->SaveButtonString = _("Save");
68 $this->CloseButtonString = _("Close");
69 $this->filterName = $filterName;
71 /* Set default base */
72 if(!isset($_SESSION['CurrentMainBase'])){
73 $_SESSION['CurrentMainBase'] = $this->config->current['BASE'];
74 }
75 $this->selectedBase = $_SESSION['CurrentMainBase'];
76 }
78 /* Enables the headpage mode, which changes the list look */
79 function SetHeadpageMode()
80 {
81 $this->is_headpage = true;
82 }
84 /* Sets the List internal name (not displayed anywhere)
85 it is used to identify every single list
86 */
87 function SetTitle($str)
88 {
89 $this->string_Title = $str;
90 }
92 /* Set the list header string */
93 function SetListHeader($str)
94 {
95 $this->string_ListHeader = $str;
96 }
98 /* This sets the list description which is the first gray bar on top of the list */
99 function SetSummary($str)
100 {
101 $this->string_Summary = $str;
102 }
104 /* If the save button is enabled, you can change its caption with this function */
105 function SetSaveButtonString($str)
106 {
107 $this->SaveButtonString = $str;
108 }
110 /* If the close button is enabled, you can change its caption with this function */
111 function SetCloseButtonString($str)
112 {
113 $this->CloseButtonString = $str;
114 }
116 /* With this function you can change the text of the information box */
117 function SetInformation($str)
118 {
119 $this->string_Information = $str;
120 }
122 /* Display the alphabet selection box*/
123 function EnableAplhabet($bool)
124 {
125 $this->bool_DisplayAlpahabet = $bool;
126 }
128 /* Add additional header col */
129 function AddHeader($arr)
130 {
131 $this->array_Header[] = $arr;
132 }
134 /* add additional List element */
135 function AddElement($arr)
136 {
137 $this->array_Elements[] = $arr;
138 }
140 /* Add a checkbox to the filter element,
141 the name specifies an existing class var to store the 'selection' */
142 function AddCheckBox($name,$value="Unset",$string="Unset",$default=false)
143 {
144 $arr = array();
146 if($name == SEPERATOR){
147 $arr['name'] = SEPERATOR;
148 }else{
149 /* Check if there was already a variable
150 for this dialog which we should use instead of the default*/
151 if(isset($_SESSION['MultiDialogFilters'][$this->filterName][$name])){
152 $arr['default'] = $_SESSION['MultiDialogFilters'][$this->filterName][$name];
153 $this->$name = $arr['default'];
154 }else{
155 $arr['default'] = $default;
156 }
157 $arr['name'] = $name;
158 $arr['string'] = $string;
159 $arr['value'] = $value;
160 $arr['enabled'] = true;
161 }
162 $this->array_Checkboxes[] = $arr;
163 }
165 /* Hides or unhides the checkbox with the given name */
166 function DisableCheckBox($name,$HideShow = false)
167 {
168 foreach($this->array_Checkboxes as $key => $chkbox){
169 if($chkbox['name'] == $name){
170 $this->array_Checkboxes[$key]['enabled'] = $HideShow;
171 }
172 }
173 }
177 /* Returns true if the close button was pressed */
178 function isClosed()
179 {
180 return($this->is_closed);
181 }
183 /* Enable the close button */
184 function EnableCloseButton($bool)
185 {
186 $this->bool_DisplayCloseButton = $bool;
187 }
189 /* Enable the save button on the bottom of the list*/
190 function EnableSaveButton ($bool)
191 {
192 $this->bool_DisplaySaveButton = $bool;
193 }
195 /* Draw the list with all list elements and filters */
196 function Draw()
197 {
199 /* Check for exeeded sizelimit */
200 if (($message= check_sizelimit()) != ""){
201 return($message);
202 }
204 $smarty = get_smarty();
206 $divlist = new divlist($this->string_Title);
207 $divlist->SetSummary($this->string_Summary);
208 $divlist->SetEntriesPerPage(0); // 0 for scrollable list
210 /* set Header informations
211 */
212 $header = array();
213 foreach($this->array_Header as $head){
214 $header[] = $head;
215 }
216 $divlist->SetHeader($header);
218 /* set Entries
219 */
220 $elements = array();
221 foreach($this->array_Elements as $element){
222 $divlist->AddEntry($element);
223 }
225 /* Create checkboxes fields
226 */
227 $boxes = "";
228 $boxClick = " onClick='document.mainform.submit();' ";
229 foreach($this->array_Checkboxes as $box){
231 if($box['name'] == SEPERATOR){
232 $boxes .= "</td></tr></table><table style='width:100%;border-top:1px solid #B0B0B0;'><tr><td>";
233 continue;
234 }
236 /* Skip disabled boxes */
237 if(!$box['enabled']) continue;
239 /* Check if box is checked */
240 if($box['default'] == true){
241 $boxes .="<input type='checkbox' name='".$box['name']."' value='1' title='".$box['value']."' checked ".$boxClick."> ".$box['string']."<br>";
242 }else{
243 $boxes .="<input type='checkbox' name='".$box['name']."' value='1' title='".$box['value']."'".$boxClick.";> ".$box['string']."<br>";
244 }
245 }
246 $smarty->assign("CheckBoxes", $boxes);
248 /* Assign regex fields
249 */
250 $regexes = "";
251 foreach($this->array_Regexes as $regex){
252 $regexes.="<table summary=\"\" style=\"width:100%;border-top:1px solid #B0B0B0;\">
253 <tr>
254 <td>
255 <label for=\"".$regex['name']."\">
256 <img alt=\"".$regex['string']."\" src=\"".$regex['image']."\" align=middle>
257 </label>
258 </td>
259 <td width=\"99%\">
260 <input type='text' style='width:99%' name='".$regex['name']."' maxlength='20'
261 value='".$regex['value']."' title=\"".$regex['string']."\">
262 </td>
263 </tr>
264 </table>";
265 }
266 $smarty->assign("regexes" , $regexes );
268 /* Assign alphabet and display it
269 */
270 $smarty->assign("Display_alphabet", $this->bool_DisplayAlpahabet);
271 $smarty->assign("alphabet", generate_alphabet());
272 $smarty->assign("Header" , $this->string_ListHeader );
273 $smarty->assign("Summary" , $this->string_Summary);
274 $smarty->assign("Title" , $this->string_Title);
275 $smarty->assign("Information" , $this->string_Information);
277 /* Check for exeeded sizelimit */
278 $smarty->assign("hint" , print_sizelimit_warning());
279 $smarty->assign("DivList" , $divlist->DrawList());
282 if($this->is_headpage){
283 $smarty->assign("tree_image", get_template_path('images/tree.png'));
284 $smarty->assign("infoimage", get_template_path('images/info.png'));
285 $smarty->assign("launchimage", get_template_path('images/launch.png'));
286 $smarty->assign("apply", apply_filter());
287 }else{
288 $smarty->assign("tree_image", get_template_path('images/tree.png'));
289 $smarty->assign("infoimage", get_template_path('images/info_small.png'));
290 $smarty->assign("launchimage", get_template_path('images/rocket.png'));
291 $smarty->assign("apply", apply_filter());
292 }
294 /* Button handling */
295 $smarty->assign("SaveButtonString" ,$this->SaveButtonString);
296 $smarty->assign("CloseButtonString",$this->CloseButtonString);
298 $smarty->assign("Display_Close", $this->bool_DisplayCloseButton);
299 $smarty->assign("Display_Save" , $this->bool_DisplaySaveButton);
301 $smarty->assign("filterName" , $this->filterName);
302 $smarty->assign("is_headpage" , $this->is_headpage);
304 $display = $smarty->fetch(get_template_path("MultiSelectWindow.tpl"));
305 return($display);
306 }
308 /* Set the close var, which simulates the close button is pressed */
309 function Close()
310 {
311 $this->is_closed = true;
312 }
314 function Save()
315 {
316 $this->is_saved = true;
317 }
319 /* Store all checkboxes/ regexes ...
320 Store data also into a session var, to keep the checkboxes check after reload */
321 function save_object()
322 {
323 /* Update current base */
324 if($this->DepartmentsAdded){
325 $s_action ="";
326 foreach($_POST as $key => $value){
327 if(preg_match("/^dep_back.*/i",$key)){
328 $s_action="back";
329 }elseif(preg_match("/^dep_root.*/",$key)){
330 $s_action="root";
331 }elseif(preg_match("/^dep_home.*/i",$key)){
332 $s_action="home";
333 }
334 }
336 /* Save base selection from headpage selectbox*/
337 if(isset($_POST['CurrentMainBase'])){
338 $this->selectedBase = $_POST['CurrentMainBase'];
339 }
341 /* Homebutton is posted */
342 if($s_action=="home"){
343 $ui= get_userinfo();
344 $this->selectedBase=(preg_replace("/^[^,]+,/","",$ui->dn));
345 $this->selectedBase=(preg_replace("/^[^,]+,/","",$this->selectedBase));
346 }
348 /* Open selected department
349 this is posted by the parent class MultiSelectWindow */
350 if(isset($_GET['act'])&& ($_GET['act'] == "dep_open")){
351 $s_entry = base64_decode($_GET['dep_id']);
352 $this->selectedBase = $this->config->departments[trim($s_entry)];
353 }
355 /* back to the roots ^^ */
356 if($s_action=="root"){
357 $this->selectedBase=($this->config->current['BASE']);
358 }
361 /* If Back-button is pressed, move back one step in DN */
362 if($s_action=="back"){
363 //FIXME: This is not 100% correct. We'll only display ou's, but there may be
364 // a step between. You'll stumble in a "hidden" department in this case.
365 $base_back= preg_replace("/^[^,]+,/", "", $_SESSION['CurrentMainBase']);
367 /* The department array keeps non DN entries as index. We need to convert
368 it before checking the existance. */
369 $base_back= trim(convert_department_dn($base_back));
371 /* Check if the department exists, otherwise revert to the configure base DN */
372 if(isset($this->config->departments[$base_back])){
373 $this->selectedBase= $this->config->departments[$base_back];
374 }else{
375 $this->selectedBase= $this->config->departments['/'];
376 }
377 }
378 }
379 if(isset($_POST['MultiSelectWindow'.$this->filterName])){
381 /* Check posts from checkboxes
382 */
383 foreach($this->array_Checkboxes as $key => $box){
384 if(isset($_POST[$box['name']])){
385 $this->array_Checkboxes[$key]['default'] = true;
386 $this->$box['name'] = true;
387 }else{
388 $this->array_Checkboxes[$key]['default'] = false;
389 $this->$box['name'] = false;
390 }
391 /* Save settings in out session */
392 $_SESSION['MultiDialogFilters'][$this->filterName][$box['name']] = $this->$box['name'];
393 }
395 /* Check regex posts */
396 foreach($this->array_Regexes as $key => $box){
397 $this->array_Regexes[$key]['value'] = $_POST[$box['name']];
398 $this->$box['name'] = $_POST[$box['name']];
399 $_SESSION['MultiDialogFilters'][$this->filterName][$box['name']] = $this->$box['name'];
400 }
402 /* call close/save if buttons are pressed */
403 if(isset($_POST['CloseMultiSelectWindow'])){
404 $this->Close();
405 }
407 if(isset($_POST['SaveMultiSelectWindow'])){
408 $this->Save();
409 }
410 }
412 /* check for alphabet selection
413 Check which regexes are connected to the alphabet
414 */
415 if(isset($_GET['search'])){
416 foreach($this->array_Regexes as $key => $box){
417 /* check if this regex is connected to the alphabet selection */
418 if(($box['connAlpha'])&&(isset($_GET['search']))){
419 $val = $_GET['search']."*";
420 $val = preg_replace("/\*\**/","*",$val);
421 $this->array_Regexes[$key]['value'] = $val;
422 $this->$box['name'] = $val;
423 }
424 }
425 }
427 }
429 /* this function adds the sub-departments of the current tree to the list */
430 function AddDepartments($base = false,$numtabs = 3)
431 {
432 $this->DepartmentsAdded = true;
434 /* check for a valid base */
435 if(!$base){
436 if(!isset($_SESSION['CurrentMainBase'])){
437 $_SESSION['CurrentMainBase'] = $this->config->current['BASE'];
438 }
439 $base = $_SESSION['CurrentMainBase'];
440 }
442 /* Create ldap obj and switch into base*/
443 $ldap = $this->config->get_ldap_link();
444 $ldap->cd($base);
446 /* reset current deps */
447 $this->departments = array();
449 /* Get all departments within this subtree */
450 $deps= get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->ui->subtreeACL,
451 $base, array("ou", "description"), GL_SIZELIMIT | GL_CONVERT);
453 /* Edit delete link for system types
454 */
455 $linkopen = "<a href='?plug=".$_GET['plug']."&act=dep_open&dep_id=%s'>%s</a>";
457 /* Create an array with all visible (in the list) departments */
458 $departments = array();
459 foreach($deps as $value){
460 if(isset($value['description'][0])){
461 $this->departments[$value['dn']]= get_sub_department($value['dn'])." - [".$value["description"][0]."]";
462 }else{
463 $this->departments[$value['dn']]= get_sub_department($value['dn']);
464 }
465 }
466 natcasesort($this->departments);
468 /* Add deps to this dialog object list */
469 foreach($this->departments as $key=> $val){
470 /* Add missing entries ... */
471 if(!isset($this->config->departments[trim($key)])){
472 $this->config->departments[trim($key)]="";
473 }
475 /* check if this department contains sub-departments
476 Display different image in this case
477 */
478 $non_empty="";
479 $nkey= normalizePreg($key);
480 foreach($this->config->departments as $keyd=>$vald ){
481 if(preg_match("/$nkey\/.*/",$keyd)){
482 $non_empty="full";
483 }
484 }
487 /* Add to divlist */
488 $row = array();
489 $row[] = $field1 = array("string" => "<img src='images/".$non_empty."folder.png' alt='department'>", "attach" => "style='text-align:center;width:20px;'");
490 $row[] = $field2 = array("string" => sprintf($linkopen,base64_encode($key),$val), "attach" => "style=''");
492 if($numtabs > 2){
493 for($i = 2 ; $i <$numtabs;$i++){
494 if($i ==($numtabs-1)){
495 $row[] = array("string"=>" ","attach" => "style='width:60px;border-right:0px;text-align:right;'");
496 }else{
497 $row[] = array("string"=>" ");
498 }
499 }
500 }
502 $this->AddElement($row);
503 }
504 }
505 }
507 ?>