Code

Do not display selectAll checkbox while using singleSelect
[gosa.git] / gosa-core / include / class_listing.inc
1 <?php
2 /*
3  * This code is part of GOsa (http://www.gosa-project.org)
4  * Copyright (C) 2003-2008 GONICUS GmbH
5  *
6  * ID: $$Id$$
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
23 class listing {
25   var $xmlData;
26   var $entries;
27   var $departments= array();
28   var $departmentBrowser= false;
29   var $departmentRootVisible= false;
30   var $multiSelect= false;
31   var $singleSelect= false;
32   var $template;
33   var $headline;
34   var $base;
35   var $sortDirection= null;
36   var $sortColumn= null;
37   var $sortAttribute;
38   var $sortType;
39   var $numColumns;
40   var $baseMode= false;
41   var $bases= array();
42   var $header= array();
43   var $colprops= array();
44   var $filters= array();
45   var $filter= null;
46   var $pid;
47   var $objectTypes= array();
48   var $objectTypeCount= array();
49   var $objectDnMapping= array();
50   var $copyPasteHandler= null;
51   var $snapshotHandler= null;
52   var $exporter= array();
53   var $exportColumns= array();
54   var $useSpan= false;
55   var $height= 0;
56   var $scrollPosition= 0;
57   var $baseSelector;
60   function listing($filename)
61   {
62     global $config;
63     global $class_mapping;
65     // Initialize pid
66     $this->pid= preg_replace("/[^0-9]/", "", microtime(TRUE));
68     if (!$this->load($filename)) {
69       die("Cannot parse $filename!");
70     }
72     // Set base for filter
73     if ($this->baseMode) {
74       $this->base= session::global_get("CurrentMainBase");
75       if ($this->base == null) {
76         $this->base= $config->current['BASE'];
77       }
78       $this->refreshBasesList();
79     } else {
80       $this->base= $config->current['BASE'];
81     }
83     // Move footer information
84     $this->showFooter= ($config->get_cfg_value("listSummary") == "true");
86     // Register build in filters
87     $this->registerElementFilter("objectType", "listing::filterObjectType");
88     $this->registerElementFilter("departmentLink", "listing::filterDepartmentLink");
89     $this->registerElementFilter("link", "listing::filterLink");
90     $this->registerElementFilter("actions", "listing::filterActions");
92     // Load exporters
93     foreach($class_mapping as $class => $dummy) {
94       if (preg_match('/Exporter$/', $class)) {
95         $info= call_user_func(array($class, "getInfo"));
96         if ($info != null) {
97           $this->exporter= array_merge($this->exporter, $info);
98         }
99       }
100     }
102     // Instanciate base selector
103     $this->baseSelector= new baseSelector($this->bases, $this->base);
104   }
107   function setCopyPasteHandler($handler)
108   {
109     $this->copyPasteHandler= &$handler;
110   }
113   function setHeight($height)
114   {
115     $this->height= $height;
116   }
119   function setSnapshotHandler($handler)
120   {
121     $this->snapshotHandler= &$handler;
122   }
125   function getFilter()
126   { 
127     return($this->filter);
128   }  
131   function setFilter($filter)
132   {
133     $this->filter= &$filter;
134     if ($this->departmentBrowser){
135       $this->departments= $this->getDepartments();
136     }
137     $this->filter->setBase($this->base);
138   }
141   function registerElementFilter($name, $call)
142   {
143     if (!isset($this->filters[$name])) {
144       $this->filters[$name]= $call;
145       return true;
146     }
148     return false;
149   }
152   function load($filename)
153   {
154     $contents = file_get_contents($filename);
155     $this->xmlData= xml::xml2array($contents, 1);
157     if (!isset($this->xmlData['list'])) {
158       return false;
159     }
161     $this->xmlData= $this->xmlData["list"];
163     // Load some definition values
164     foreach (array("departmentBrowser", "departmentRootVisible", "multiSelect","singleSelect", "baseMode") as $token) {
165       if (isset($this->xmlData['definition'][$token]) &&
166           $this->xmlData['definition'][$token] == "true"){
167         $this->$token= true;
168       }
169     }
171     // Fill objectTypes from departments and xml definition
172     $types = departmentManagement::get_support_departments();
173     foreach ($types as $class => $data) {
174       $this->objectTypes[$data['OC']]= array("label" => $data['TITLE'],
175                                   "objectClass" => $data['OC'],
176                                   "image" => $data['IMG']);
177     }
178     $this->categories= array();
179     if (isset($this->xmlData['definition']['objectType'])) {
180       if(isset($this->xmlData['definition']['objectType']['label'])) {
181         $this->xmlData['definition']['objectType']= array($this->xmlData['definition']['objectType']);
182       }
183       foreach ($this->xmlData['definition']['objectType'] as $index => $otype) {
184         $tmp = $this->xmlData['definition']['objectType'][$index];
185         $this->objectTypes[$tmp['objectClass']]= $tmp;
186         if (isset($this->xmlData['definition']['objectType'][$index]['category'])){
187           $this->categories[]= $otype['category'];
188         }
189       }
190     }
191     $this->objectTypes = array_values($this->objectTypes);
193     // Parse layout per column
194     $this->colprops= $this->parseLayout($this->xmlData['table']['layout']);
196     // Prepare table headers
197     $this->renderHeader();
199     // Assign headline/Categories
200     $this->headline= _($this->xmlData['definition']['label']);
201     if (!is_array($this->categories)){
202       $this->categories= array($this->categories);
203     }
205     // Evaluate columns to be exported
206     if (isset($this->xmlData['table']['column'])){
207       foreach ($this->xmlData['table']['column'] as $index => $config) {
208         if (isset($config['export']) && $config['export'] == "true"){
209           $this->exportColumns[]= $index;
210         }
211       }
212     }
214     return true;  
215   }
218   function renderHeader()
219   {
220     $this->header= array();
221     $this->plainHeader= array();
223     // Initialize sort?
224     $sortInit= false;
225     if (!$this->sortDirection) {
226       $this->sortColumn= 0;
227       if (isset($this->xmlData['definition']['defaultSortColumn'])){
228         $this->sortColumn= $this->xmlData['definition']['defaultSortColumn'];
229       } else {
230         $this->sortAttribute= "";
231       }
232       $this->sortDirection= array();
233       $sortInit= true;
234     }
236     if (isset($this->xmlData['table']['column'])){
237       foreach ($this->xmlData['table']['column'] as $index => $config) {
238         // Initialize everything to one direction
239         if ($sortInit) {
240           $this->sortDirection[$index]= false;
241         }
243         $sorter= "";
244         if ($index == $this->sortColumn && isset($config['sortAttribute']) &&
245             isset($config['sortType'])) {
246           $this->sortAttribute= $config['sortAttribute'];
247           $this->sortType= $config['sortType'];
248           $sorter= "&nbsp;".image("images/lists/sort-".($this->sortDirection[$index]?"up":"down").".png", null, $this->sortDirection[$index]?_("Up"):_("Down"), "text-top");
249         }
250         $sortable= (isset($config['sortAttribute']));
252         $link= "href='?plug=".$_GET['plug']."&amp;PID=".$this->pid."&amp;act=SORT_$index'";
253         if (isset($config['label'])) {
254           if ($sortable) {
255             $this->header[$index]= "<td class='listheader' ".$this->colprops[$index]."><a $link>"._($config['label'])."</a>$sorter</td>";
256           } else {
257             $this->header[$index]= "<td class='listheader' ".$this->colprops[$index].">"._($config['label'])."</td>";
258           }
259           $this->plainHeader[]= _($config['label']);
260         } else {
261           if ($sortable) {
262             $this->header[$index]= "<td class='listheader' ".$this->colprops[$index]."><a $link>&nbsp;</a>$sorter</td>";
263           } else {
264             $this->header[$index]= "<td class='listheader' ".$this->colprops[$index].">&nbsp;</td>";
265           }
266           $this->plainHeader[]= "";
267         }
268       }
269     }
270   }
273   function render()
274   {
275     // Check for exeeded sizelimit
276     if (($message= check_sizelimit()) != ""){
277       return($message);
278     }
280     // Some browsers don't have the ability do do scrollable table bodies, filter them
281     // here.
282     $switch= false;
283     if (preg_match('/(Opera|Konqueror|Safari)/i', $_SERVER['HTTP_USER_AGENT'])){
284       $switch= true;
285     }
287     // Initialize list
288     $result= "<input type='hidden' value='$this->pid' name='PID'>\n";
289     $result.= "<input type='hidden' name='position_".$this->pid."' id='position_".$this->pid."'>\n";
290     $height= 450;
291     if ($this->height != 0) {
292       $result.= "<input type='hidden' value='$this->height' id='d_height'>\n";
293       $height= $this->height;
294     }
295     
296     $result.= "<div class='listContainer' id='d_scrollbody' style='min-height:".($height+25)."px;'>\n";
297     $result.= "<table summary='$this->headline' style='width:100%;table-layout:fixed' cellspacing='0' cellpadding='0' id='t_scrolltable'>\n";
298     $this->numColumns= count($this->colprops) + (($this->multiSelect|$this->singleSelect)?1:0);
300     // Build list header
301     $result.= "<thead class='fixedListHeader listHeaderFormat'><tr>\n";
302     if ($this->multiSelect || $this->singleSelect) {
303       $width= "24px";
304       if (preg_match('/Konqueror/i', $_SERVER['HTTP_USER_AGENT'])){
305         $width= "28px";
306       }
307       $result.= "<td class='listheader' style='text-align:center;padding:0;width:$width;'>";
308       if($this->multiSelect){
309           $result.= "<input type='checkbox' id='select_all' name='select_all' 
310               title='"._("Select all")."' onClick='toggle_all_(\"listing_selected_[0-9]*$\",\"select_all\");' >";
311       }else{
312           $result.= "&nbsp;";
313       }
314       $result.="</td>\n";
315     }
316     foreach ($this->header as $header) {
317       $result.= $header;
318     }
319     $result.= "</tr></thead>\n";
321     // Build list body
322     $result.= "<tbody class='listScrollContent listBodyFormat' id='t_nscrollbody' style='height:".$height."px;'>\n";
324     // No results? Just take an empty colspanned row
325     if (count($this->entries) + count($this->departments) == 0) {
326       $result.= "<tr><td class='list1nohighlight' colspan='$this->numColumns' style='height:100%;border-right:0px;width:100%;'>&nbsp;</td></tr>";
327     }
329     // Line color alternation
330     $alt= 0;
331     $deps= 0;
333     // Draw department browser if configured and we're not in sub mode
334     $this->useSpan= false;
335     if ($this->departmentBrowser && $this->filter->scope != "sub") {
336       // Fill with department browser if configured this way
337       $departmentIterator= new departmentSortIterator($this->departments, $this->sortDirection[$this->sortColumn]);
338       foreach ($departmentIterator as $row => $entry){
339         $result.="<tr>";
341         // Render multi select if needed
342         if ($this->multiSelect || $this->singleSelect) {
343           $result.="<td style='text-align:center;padding:0;' class='list1'>&nbsp;</td>";
344         }
346         // Render defined department columns, fill the rest with some stuff
347         $rest= $this->numColumns - 1;
348         foreach ($this->xmlData['table']['department'] as $index => $config) {
349           $colspan= 1;
350           if (isset($config['span'])){
351             $colspan= $config['span'];
352             $this->useSpan= true;
353           }
354           $result.="<td colspan='$colspan' ".$this->colprops[$index]." class='list1'>".$this->renderCell($config['value'], $entry, $row)."</td>";
355           $rest-= $colspan;
356         }
358         // Fill remaining cols with nothing
359         $last= $this->numColumns - $rest;
360         for ($i= 0; $i<$rest; $i++){
361           $result.= "<td ".$this->colprops[$last+$i-1]." class='list1'>&nbsp;</td>";
362         }
363         $result.="</tr>";
365         $alt++;
366       }
367       $deps= $alt;
368     }
370     // Fill with contents, sort as configured
371     foreach ($this->entries as $row => $entry) {
372       $trow= "";
374       // Render multi select if needed
375       if ($this->multiSelect) {
376         $trow.="<td style='text-align:center;width:20px;' class='list0'><input type='checkbox' id='listing_selected_$row' name='listing_selected_$row'></td>\n";
377       }
379       if ($this->singleSelect) {
380         $trow.="<td style='text-align:center;width:20px;' class='list0'><input type='radio' id='listing_radio_selected_$row' name='listing_radio_selected' value='{$row}'></td>\n";
381       }
383       foreach ($this->xmlData['table']['column'] as $index => $config) {
384         $renderedCell= $this->renderCell($config['value'], $entry, $row);
385         $trow.="<td ".$this->colprops[$index]." class='list0'>".$renderedCell."</td>\n";
387         // Save rendered column
388         $sort= preg_replace('/.*>([^<]+)<.*$/', '$1', $renderedCell);
389         $sort= preg_replace('/&nbsp;/', '', $sort);
390         if (preg_match('/</', $sort)){
391           $sort= "";
392         }
393         $this->entries[$row]["_sort$index"]= $sort;
394       }
396       // Save rendered entry
397       $this->entries[$row]['_rendered']= $trow;
398     }
400     // Complete list by sorting entries for _sort$index and appending them to the output
401     $entryIterator= new listingSortIterator($this->entries, $this->sortDirection[$this->sortColumn], "_sort".$this->sortColumn, $this->sortType);
402     foreach ($entryIterator as $row => $entry){
404       // Apply custom class to row?
405       if (preg_match("/<rowClass:([a-z0-9_-]*)\/>/i", $entry['_rendered'], $matches)) {
406         $result.="<tr class='".$matches[1]."'>\n";
407         $result.= preg_replace("/<rowClass[^>]+>/", '', $entry['_rendered']);
408       } else {
409         $result.="<tr>\n";
410         $result.= $entry['_rendered'];
411       }
413       $result.="</tr>\n";
414       $alt++;
415     }
417     // Need to fill the list if it's not full (nobody knows why this is 22 ;-))
418     $emptyListStyle= (count($this->entries) + (($this->useSpan && count($this->entries))?$deps:0) == 0)?"border:0;":"";
419     if ((count($this->entries) + $deps) < 22) {
420       $result.= "<tr>";
421       for ($i= 0; $i<$this->numColumns; $i++) {
422         if ($i == 0) {
423           $result.= "<td class='list1nohighlight' style='$emptyListStyle height:100%;'>&nbsp;</td>";
424           continue;
425         }
426         if ($i != $this->numColumns-1) {
427           $result.= "<td class='list1nohighlight' style='$emptyListStyle'>&nbsp;</td>";
428         } else {
429           $result.= "<td class='list1nohighlight' style='border-right:0;$emptyListStyle'>&nbsp;</td>";
430         }
431       }
433       $result.= "</tr>";
434     }
436     // Close list body
437     $result.= "</tbody></table></div>";
439     // Add the footer if requested
440     if ($this->showFooter) {
441       $result.= "<div class='nlistFooter'><div style='padding:3px'>";
443       foreach ($this->objectTypes as $objectType) {
444         if (isset($this->objectTypeCount[$objectType['label']])) {
445           $label= _($objectType['label']);
446           $result.= image($objectType['image'], null, $label)."&nbsp;".$this->objectTypeCount[$objectType['label']]."&nbsp;&nbsp;";
447         }
448       }
450       $result.= "</div></div>";
451     }
453     // Close list
454     $result.= $switch?"<input type='hidden' id='list_workaround'>":"";
456     // Add scroll positioner
457     $result.= '<script type="text/javascript" language="javascript">';
458     $result.= '$("t_nscrollbody").scrollTop= '.$this->scrollPosition.';';
459     $result.= 'var box = $("t_nscrollbody").onscroll= function() {$("position_'.$this->pid.'").value= this.scrollTop;}';
460     $result.= '</script>';
462     $smarty= get_smarty();
463     $smarty->assign("usePrototype", "true");
464     $smarty->assign("FILTER", $this->filter->render());
465     $smarty->assign("SIZELIMIT", print_sizelimit_warning());
466     $smarty->assign("LIST", $result);
468     // Assign navigation elements
469     $nav= $this->renderNavigation();
470     foreach ($nav as $key => $html) {
471       $smarty->assign($key, $html);
472     }
474     // Assign action menu / base
475     $smarty->assign("HEADLINE", $this->headline);
476     $smarty->assign("ACTIONS", $this->renderActionMenu());
477     $smarty->assign("BASE", $this->renderBase());
479     // Assign separator
480     $smarty->assign("SEPARATOR", "<img src='images/lists/seperator.png' alt='-' align='middle' height='16' width='1' class='center'>");
482     // Assign summary
483     $smarty->assign("HEADLINE", $this->headline);
485     // Try to load template from plugin the folder first...
486     $file = get_template_path($this->xmlData['definition']['template'], true);
488     // ... if this fails, try to load the file from the theme folder.
489     if(!file_exists($file)){
490       $file = get_template_path($this->xmlData['definition']['template']);
491     }
493     return ($smarty->fetch($file));
494   }
497   function update()
498   {
499     global $config;
500     $ui= get_userinfo();
502     // Take care of base selector
503     if ($this->baseMode) {
504       $this->baseSelector->update();
505       // Check if a wrong base was supplied
506       if(!$this->baseSelector->checkLastBaseUpdate()){
507          msg_dialog::display(_("Error"), msgPool::check_base(), ERROR_DIALOG);
508       }
509     }
511     // Save base
512     $refresh= false;
513     if ($this->baseMode) {
514       $this->base= $this->baseSelector->getBase();
515       session::global_set("CurrentMainBase", $this->base);
516       $refresh= true;
517     }
520     // Reset object counter / DN mapping
521     $this->objectTypeCount= array();
522     $this->objectDnMapping= array();
524     // Do not do anything if this is not our PID
525     if($refresh || !(isset($_REQUEST['PID']) && $_REQUEST['PID'] != $this->pid)) {
527       // Save position if set
528       if (isset($_POST['position_'.$this->pid]) && is_numeric($_POST['position_'.$this->pid])) {
529         $this->scrollPosition= $_POST['position_'.$this->pid];
530       }
532       // Override the base if we got a message from the browser navigation
533       if ($this->departmentBrowser && isset($_GET['act'])) {
534         if (preg_match('/^department_([0-9]+)$/', validate($_GET['act']), $match)){
535           if (isset($this->departments[$match[1]])){
536             $this->base= $this->departments[$match[1]]['dn'];
537             if ($this->baseMode) {
538               $this->baseSelector->setBase($this->base);
539             }
540             session::global_set("CurrentMainBase", $this->base);
541           }
542         }
543       }
545       // Filter POST with "act" attributes -> posted from action menu
546       if (isset($_POST['exec_act']) && $_POST['act'] != '') {
547         if (preg_match('/^export.*$/', $_POST['act']) && isset($this->exporter[$_POST['act']])) {
548           $exporter= $this->exporter[$_POST['act']];
549           $userinfo= ", "._("created by")." ".$ui->cn." - ".strftime('%A, %d. %B %Y, %H:%M:%S');
550           $entryIterator= new listingSortIterator($this->entries, $this->sortDirection[$this->sortColumn], "_sort".$this->sortColumn, $this->sortType);
551           $sortedEntries= array();
552           foreach ($entryIterator as $entry){
553             $sortedEntries[]= $entry;
554           }
555           $instance= new $exporter['class']($this->headline.$userinfo, $this->plainHeader, $sortedEntries, $this->exportColumns);
556           $type= call_user_func(array($exporter['class'], "getInfo"));
557           $type= $type[$_POST['act']];
558           send_binary_content($instance->query(), $type['filename'], $type= $type['mime']);
559         }
560       }
562       // Filter GET with "act" attributes
563       if (isset($_GET['act'])) {
564         $key= validate($_GET['act']);
565         if (preg_match('/^SORT_([0-9]+)$/', $key, $match)) {
566           // Switch to new column or invert search order?
567           $column= $match[1];
568           if ($this->sortColumn != $column) {
569             $this->sortColumn= $column;
570           } else {
571             $this->sortDirection[$column]= !$this->sortDirection[$column];
572           }
574           // Allow header to update itself according to the new sort settings
575           $this->renderHeader();
576         }
577       }
579       // Override base if we got signals from the navigation elements
580       $action= "";
581       foreach ($_POST as $key => $value) {
582         if (preg_match('/^(ROOT|BACK|HOME)(_x)?$/', $key, $match)) {
583           $action= $match[1];
584           break;
585         }
586       }
588       // Navigation handling
589       if ($action == 'ROOT') {
590         $deps= $ui->get_module_departments($this->categories);
591         $this->base= $deps[0];
592         $this->baseSelector->setBase($this->base);
593         session::global_set("CurrentMainBase", $this->base);
594       }
595       if ($action == 'BACK') {
596         $deps= $ui->get_module_departments($this->categories);
597         $base= preg_replace("/^[^,]+,/", "", $this->base);
598         if(in_array_ics($base, $deps)){
599           $this->base= $base;
600           $this->baseSelector->setBase($this->base);
601           session::global_set("CurrentMainBase", $this->base);
602         }
603       }
604       if ($action == 'HOME') {
605         $ui= get_userinfo();
606         $this->base= get_base_from_people($ui->dn);
607         $this->baseSelector->setBase($this->base);
608         session::global_set("CurrentMainBase", $this->base);
609       }
610     }
612     // Reload departments
613     if ($this->departmentBrowser){
614       $this->departments= $this->getDepartments();
615     }
617     // Update filter and refresh entries
618     $this->filter->setBase($this->base);
619     $this->entries= $this->filter->query();
621     // Fix filter if querie returns NULL
622     if ($this->entries == null) {
623       $this->entries= array();
624     }
625   }
628   function setBase($base)
629   {
630     $this->base= $base;
631     if ($this->baseMode) {
632       $this->baseSelector->setBase($this->base);
633     }
634   }
637   function getBase()
638   {
639     return $this->base;
640   }
643   function parseLayout($layout)
644   {
645     $result= array();
646     $layout= preg_replace("/^\|/", "", $layout);
647     $layout= preg_replace("/\|$/", "", $layout);
648     $cols= explode("|", $layout);
650     foreach ($cols as $index => $config) {
651       if ($config != "") {
652         $res= "";
653         $components= explode(';', $config);
654         foreach ($components as $part) {
655           if (preg_match("/^r$/", $part)) {
656             $res.= "text-align:right;";
657             continue;
658           }
659           if (preg_match("/^l$/", $part)) {
660             $res.= "text-align:left;";
661             continue;
662           }
663           if (preg_match("/^c$/", $part)) {
664             $res.= "text-align:center;";
665             continue;
666           }
667           if (preg_match("/^[0-9]+(|px|%)$/", $part)) {
668             $res.= "width:$part;min-width:$part;";
669             continue;
670           }
671         }
673         // Add minimum width for scalable columns
674         if (!preg_match('/width:/', $res)){
675           $res.= "min-width:200px;";
676         }
678         $result[$index]= " style='$res'";
679       } else {
680         $result[$index]= " style='min-width:100px;'";
681       }
682     }
684     // Save number of columns for later use
685     $this->numColumns= count($cols);
687     // Add no border to the last column
688     $result[$this->numColumns-1]= preg_replace("/'$/", "border-right:0;'", $result[$this->numColumns-1]);
690     return $result;
691   }
694   function renderCell($data, $config, $row)
695   {
696     // Replace flat attributes in data string
697     for ($i= 0; $i<$config['count']; $i++) {
698       $attr= $config[$i];
699       $value= "";
700       if (is_array($config[$attr])) {
701         $value= $config[$attr][0];
702       } else {
703         $value= $config[$attr];
704       }
705       $data= preg_replace("/%\{$attr\}/", $value, $data);
706     }
708     // Watch out for filters and prepare to execute them
709     $data= $this->processElementFilter($data, $config, $row);
711     // Replace all non replaced %{...} instances because they
712     // are non resolved attributes or filters
713     $data= preg_replace('/%{[^}]+}/', '&nbsp;', $data);
715     return $data;
716   }
719   function renderBase()
720   {
721     if (!$this->baseMode) {
722       return;
723     }
725     return $this->baseSelector->render();
726   }
729   function processElementFilter($data, $config, $row)
730   {
731     preg_match_all("/%\{filter:([^(]+)\((.*)\)\}/", $data, $matches, PREG_SET_ORDER);
733     foreach ($matches as $match) {
734       $cl= "";
735       $method= "";
736       if (preg_match('/::/', $match[1])) {
737         $cl= preg_replace('/::.*$/', '', $match[1]);
738         $method= preg_replace('/^.*::/', '', $match[1]);
739       } else {
740         if (!isset($this->filters[$match[1]])) {
741           continue;
742         }
743         $cl= preg_replace('/::.*$/', '', $this->filters[$match[1]]);
744         $method= preg_replace('/^.*::/', '', $this->filters[$match[1]]);
745       }
747       // Prepare params for function call
748       $params= array();
749       preg_match_all('/"[^"]+"|[^,]+/', $match[2], $parts);
750       foreach ($parts[0] as $param) {
752         // Row is replaced by the row number
753         if ($param == "row") {
754           $params[]= $row;
755           continue;
756         }
758         // pid is replaced by the current PID
759         if ($param == "pid") {
760           $params[]= $this->pid;
761           continue;
762         }
764         // base is replaced by the current base
765         if ($param == "base") {
766           $params[]= $this->getBase();
767           continue;
768         }
770         // Fixie with "" is passed directly
771         if (preg_match('/^".*"$/', $param)){
772           $params[]= preg_replace('/"/', '', $param);
773           continue;
774         }
776         // Move dn if needed
777         if ($param == "dn") {
778           $params[]= LDAP::fix($config["dn"]);
779           continue;
780         }
782         // LDAP variables get replaced by their objects
783         for ($i= 0; $i<$config['count']; $i++) {
784           if ($param == $config[$i]) {
785             $values= $config[$config[$i]];
786             if (is_array($values)){
787               unset($values['count']);
788             }
789             $params[]= $values;
790             break;
791           }
792         }
793       }
795       // Replace information
796       if ($cl == "listing") {
797         // Non static call - seems to result in errors
798         $data= @preg_replace('/'.preg_quote($match[0]).'/', call_user_func_array(array($this, "$method"), $params), $data);
799       } else {
800         // Static call
801         $data= preg_replace('/'.preg_quote($match[0]).'/', call_user_func_array(array($cl, $method), $params), $data);
802       }
803     }
805     return $data;
806   }
809   function getObjectType($types, $classes)
810   {
811     // Walk thru types and see if there's something matching
812     foreach ($types as $objectType) {
813       $ocs= $objectType['objectClass'];
814       if (!is_array($ocs)){
815         $ocs= array($ocs);
816       }
818       $found= true;
819       foreach ($ocs as $oc){
820         if (preg_match('/^!(.*)$/', $oc, $match)) {
821           $oc= $match[1];
822           if (in_array($oc, $classes)) {
823             $found= false;
824           }
825         } else {
826           if (!in_array($oc, $classes)) {
827             $found= false;
828           }
829         }
830       }
832       if ($found) {
833         return $objectType;
834       }
835     }
837     return null;
838   }
841   function filterObjectType($dn, $classes)
842   {
843     // Walk thru classes and return on first match
844     $result= "&nbsp;";
846     $objectType= $this->getObjectType($this->objectTypes, $classes);
847     if ($objectType) {
848       $this->objectDnMapping[$dn]= $objectType["objectClass"];
849       $result= image($objectType["image"], null, LDAP::fix($dn));
850       if (!isset($this->objectTypeCount[$objectType['label']])) {
851         $this->objectTypeCount[$objectType['label']]= 0;
852       }
853       $this->objectTypeCount[$objectType['label']]++;
854     }
856     return $result;
857   }
860   function filterActions($dn, $row, $classes)
861   {
862     // Do nothing if there's no menu defined
863     if (!isset($this->xmlData['actiontriggers']['action'])) {
864       return "&nbsp;";
865     }
867     // Go thru all actions
868     $result= "";
869     $actions= $this->xmlData['actiontriggers']['action'];
871     // Ensure we've a valid actions array, if there is only one action in the actiontriggers col
872     //  then we've to create a valid array here.
873     if(isset($actions['name'])) $actions = array($actions);
875     foreach($actions as $action) {
876       // Skip the entry completely if there's no permission to execute it
877       if (!$this->hasActionPermission($action, $dn, $classes)) {
878         $result.= image('images/empty.png');
879         continue;
880       }
882       // Skip entry if the pseudo filter does not fit
883       if (isset($action['filter']) && preg_match('/^[a-z0-9_]+!?=[a-z0-9_]+$/i', $action['filter'])) {
884         list($fa, $fv)= explode('=', $action['filter']);
885         if (preg_match('/^(.*)!$/', $fa, $m)){
886           $fa= $m[1];
887           if (isset($this->entries[$row][$fa]) && $this->entries[$row][$fa][0] == $fv) {
888             $result.= image('images/empty.png');
889             continue;
890           }
891         } else {
892           if (!isset($this->entries[$row][$fa]) && !$this->entries[$row][$fa][0] == $fv) {
893             $result.= image('images/empty.png');
894             continue;
895           }
896         }
897       }
900       // If there's an objectclass definition and we don't have it
901       // add an empty picture here.
902       if (isset($action['objectclass'])){
903         $objectclass= $action['objectclass'];
904         if (preg_match('/^!(.*)$/', $objectclass, $m)){
905           $objectclass= $m[1];
906           if(in_array($objectclass, $classes)) {
907             $result.= image('images/empty.png');
908             continue;
909           }
910         } elseif (is_string($objectclass)) {
911           if(!in_array($objectclass, $classes)) {
912             $result.= image('images/empty.png');
913             continue;
914           }
915         } elseif (is_array($objectclass)) {
916           if(count(array_intersect($objectclass, $classes)) != count($objectclass)){
917             $result.= image('images/empty.png');
918             continue;
919           }
920         }
921       }
923       // Render normal entries as usual
924       if ($action['type'] == "entry") {
925         $label= $this->processElementFilter($action['label'], $this->entries[$row], $row);
926         $image= $this->processElementFilter($action['image'], $this->entries[$row], $row);
927         $result.= image($image, "listing_".$action['name']."_$row", $label);
928       }
930       // Handle special types
931       if ($action['type'] == "copypaste" || $action['type'] == "snapshot") {
933         $objectType= $this->getObjectType($this->objectTypes, $this->entries[$row]['objectClass']);
934         $category= $class= null;
935         if ($objectType) {
936           $category= $objectType['category'];
937           $class= $objectType['class'];
938         }
940         if ($action['type'] == "copypaste") {
941           $copy = !isset($action['copy']) || $action['copy'] == "true";
942           $cut = !isset($action['cut']) || $action['cut'] == "true";
943           $result.= $this->renderCopyPasteActions($row, $this->entries[$row]['dn'], $category, $class,$copy,$cut);
944         } else {
945           $result.= $this->renderSnapshotActions($row, $this->entries[$row]['dn'], $category, $class);
946         }
947       }
948     }
950     return $result;
951   }
954   function filterDepartmentLink($row, $dn, $description)
955   {
956     $attr= $this->departments[$row]['sort-attribute'];
957     $name= $this->departments[$row][$attr];
958     if (is_array($name)){
959       $name= $name[0];
960     }
961     $result= sprintf("%s [%s]", $name, $description[0]);
962     return("<a href='?plug=".$_GET['plug']."&amp;PID=$this->pid&amp;act=department_$row' title='$dn'>$result</a>");
963   }
966   function filterLink()
967   {
968     $result= "&nbsp;";
970     $row= func_get_arg(0);
971     $pid= $this->pid;
972     $dn= LDAP::fix(func_get_arg(1));
973     $params= array(func_get_arg(2));
975     // Collect sprintf params
976     for ($i = 3;$i < func_num_args();$i++) {
977       $val= func_get_arg($i);
978       if (is_array($val)){
979         $params[]= $val[0];
980         continue;
981       }
982       $params[]= $val;
983     }
985     $result= "&nbsp;";
986     $trans= call_user_func_array("sprintf", $params);
987     if ($trans != "") {
988       return("<a href='?plug=".$_GET['plug']."&amp;PID=$pid&amp;act=listing_edit_$row' title='$dn'>$trans</a>");
989     }
991     return $result;
992   }
995   function renderNavigation()
996   {
997     $result= array();
998     $enableBack = true;
999     $enableRoot = true;
1000     $enableHome = true;
1002     $ui = get_userinfo();
1004     /* Check if base = first available base */
1005     $deps = $ui->get_module_departments($this->categories);
1007     if(!count($deps) || $deps[0] == $this->filter->base){
1008       $enableBack = false;
1009       $enableRoot = false;
1010     }
1012     $listhead ="";
1014     /* Check if we are in users home  department */
1015     if(!count($deps) || $this->filter->base == get_base_from_people($ui->dn)){
1016       $enableHome = false;
1017     }
1019     /* Draw root button */
1020     if($enableRoot){
1021       $result["ROOT"]= image('images/lists/root.png', 'ROOT', _("Root"));
1022     }else{
1023       $result["ROOT"]= image('images/lists/root-grey.png', null, _("Root"));
1024     }
1026     /* Draw back button */
1027     if($enableBack){
1028       $result["BACK"]= image('images/lists/back.png', 'BACK', _("Go up one department"));
1029     }else{
1030       $result["BACK"]= image('images/lists/back-grey.png', null, _("Go up one department"));
1031     }
1033     /* Draw home button */
1034    /* Draw home button */
1035     if($enableHome){
1036       $result["HOME"]= image('images/lists/home.png', 'HOME', _("Go to users department"));
1037     }else{
1038       $result["HOME"]= image('images/lists/home-grey.png', null, _("Go to users department"));
1039     }
1042     /* Draw reload button, this button is enabled everytime */
1043     $result["RELOAD"]= image('images/lists/reload.png', 'REFRESH', _("Reload list"));
1045     return ($result);
1046   }
1049   function getAction()
1050   {
1051     // Do not do anything if this is not our PID, or there's even no PID available...
1052     if(!isset($_REQUEST['PID']) || $_REQUEST['PID'] != $this->pid) {
1053       return;
1054     }
1056     // Save position if set
1057     if (isset($_POST['position_'.$this->pid]) && is_numeric($_POST['position_'.$this->pid])) {
1058       $this->scrollPosition= $_POST['position_'.$this->pid];
1059     }
1061     $result= array("targets" => array(), "action" => "");
1063     // Filter GET with "act" attributes
1064     if (isset($_GET['act'])) {
1065       $key= validate($_GET['act']);
1066       $target= preg_replace('/^listing_[a-zA-Z_]+_([0-9]+)$/', '$1', $key);
1067       if (isset($this->entries[$target]['dn'])) {
1068         $result['action']= preg_replace('/^listing_([a-zA-Z_]+)_[0-9]+$/', '$1', $key);
1069         $result['targets'][]= $this->entries[$target]['dn'];
1070       }
1072       // Drop targets if empty
1073       if (count($result['targets']) == 0) {
1074         unset($result['targets']);
1075       }
1076       return $result;
1077     }
1079     // Get single selection (radio box)
1080     if($this->singleSelect && isset($_POST['listing_radio_selected'])){
1081         $entry = $_POST['listing_radio_selected'];
1082         $result['targets']= array($this->entries[$entry]['dn']);
1083     }
1085     // Filter POST with "listing_" attributes
1086     foreach ($_POST as $key => $prop) {
1088       // Capture selections
1089       if (preg_match('/^listing_selected_[0-9]+$/', $key)) {
1090         $target= preg_replace('/^listing_selected_([0-9]+)$/', '$1', $key);
1091         if (isset($this->entries[$target]['dn'])) {
1092           $result['targets'][]= $this->entries[$target]['dn'];
1093         }
1094         continue;
1095       }
1097       // Capture action with target - this is a one shot
1098       if (preg_match('/^listing_[a-zA-Z_]+_[0-9]+(|_x)$/', $key)) {
1099         $target= preg_replace('/^listing_[a-zA-Z_]+_([0-9]+)(|_x)$/', '$1', $key);
1100         if (isset($this->entries[$target]['dn'])) {
1101           $result['action']= preg_replace('/^listing_([a-zA-Z_]+)_[0-9]+(|_x)$/', '$1', $key);
1102           $result['targets']= array($this->entries[$target]['dn']);
1103         }
1104         break;
1105       }
1107       // Capture action without target
1108       if (preg_match('/^listing_[a-zA-Z_]+(|_x)$/', $key)) {
1109         $result['action']= preg_replace('/^listing_([a-zA-Z_]+)(|_x)$/', '$1', $key);
1110         continue;
1111       }
1112     }
1114     // Filter POST with "act" attributes -> posted from action menu
1115     if (isset($_POST['act']) && $_POST['act'] != '') {
1116       if (!preg_match('/^export.*$/', $_POST['act'])){
1117         $result['action']= validate($_POST['act']);
1118       }
1119     }
1121     // Drop targets if empty
1122     if (count($result['targets']) == 0) {
1123       unset($result['targets']);
1124     }
1125     return $result;
1126   }
1129   function renderActionMenu()
1130   {
1131     $result= "<input type='hidden' name='act' id='act' value=''><div style='display:none'><input type='submit' name='exec_act' id='exec_act' value=''></div>";
1133     // Don't send anything if the menu is not defined
1134     if (!isset($this->xmlData['actionmenu']['action'])){
1135       return $result;
1136     }
1138     // Array?
1139     if (isset($this->xmlData['actionmenu']['action']['type'])){
1140       $this->xmlData['actionmenu']['action']= array($this->xmlData['actionmenu']['action']);
1141     }
1143     // Load shortcut
1144     $actions= &$this->xmlData['actionmenu']['action'];
1145     $result.= "<ul class='level1' id='root'><li><a href='#'>"._("Actions")."&nbsp;".image("images/lists/sort-down.png")."</a>";
1147     // Build ul/li list
1148     $result.= $this->recurseActions($actions);
1150     return "<div id='pulldown'>".$result."</li></ul></div>";
1151   }
1154   function recurseActions($actions)
1155   {
1156     global $class_mapping;
1157     static $level= 2;
1158     $result= "<ul class='level$level'>";
1159     $separator= "";
1161     foreach ($actions as $action) {
1163       // Skip the entry completely if there's no permission to execute it
1164       if (!$this->hasActionPermission($action, $this->filter->base)) {
1165         continue;
1166       }
1168       // Skip entry if there're missing dependencies
1169       if (isset($action['depends'])) {
1170         $deps= is_array($action['depends'])?$action['depends']:array($action['depends']);
1171         foreach($deps as $clazz) {
1172           if (!isset($class_mapping[$clazz])){
1173             continue 2;
1174           }
1175         }
1176       }
1178       // Fill image if set
1179       $img= "";
1180       if (isset($action['image'])){
1181         $img= image($action['image'])."&nbsp;";
1182       }
1184       if ($action['type'] == "separator"){
1185         $separator= " style='border-top:1px solid #AAA' ";
1186         continue;
1187       }
1189       // Dive into subs
1190       if ($action['type'] == "sub" && isset($action['action'])) {
1191         $level++;
1192         if (isset($action['label'])){
1193           $result.= "<li$separator><a href='#'>$img"._($action['label'])."&nbsp;".image('images/forward-arrow.png')."</a>";
1194         }
1196         // Ensure we've an array of actions, this enables sub menus with only one action.
1197         if(isset($action['action']['type'])){
1198           $action['action'] = array($action['action']);
1199         }
1201         $result.= $this->recurseActions($action['action'])."</li>";
1202         $level--;
1203         $separator= "";
1204         continue;
1205       }
1207       // Render entry elseways
1208       if (isset($action['label'])){
1209         $result.= "<li$separator><a href='#' onClick='\$(\"act\").value= \"".$action['name']."\";\$(\"exec_act\").click();'>$img"._($action['label'])."</a></li>";
1210       }
1212       // Check for special types
1213       switch ($action['type']) {
1214         case 'copypaste':
1215           $cut = !isset($action['cut']) || $action['cut'] != "false";
1216           $copy = !isset($action['copy']) || $action['copy'] != "false";
1217           $result.= $this->renderCopyPasteMenu($separator, $copy , $cut);
1218           break;
1220         case 'snapshot':
1221           $result.= $this->renderSnapshotMenu($separator);
1222           break;
1224         case 'exporter':
1225           $result.= $this->renderExporterMenu($separator);
1226           break;
1228         case 'daemon':
1229           $result.= $this->renderDaemonMenu($separator);
1230           break;
1231       }
1233       $separator= "";
1234     }
1236     $result.= "</ul>";
1237     return $result;
1238   }
1241   function hasActionPermission($action, $dn, $classes= null)
1242   {
1243     $ui= get_userinfo();
1245     if (isset($action['acl'])) {
1246       $acls= $action['acl'];
1247       if (!is_array($acls)) {
1248         $acls= array($acls);
1249       }
1251       // Every ACL has to pass
1252       foreach ($acls as $acl) {
1253         $module= $this->categories;
1254         $aclList= array();
1256         // Replace %acl if available
1257         if ($classes) {
1258           $otype= $this->getObjectType($this->objectTypes, $classes);
1259           $acl= str_replace('%acl', $otype['category']."/".$otype['class'], $acl);
1260         }
1262         // Split for category and plugins if needed
1263         // match for "[rw]" style entries
1264         if (preg_match('/^\[([rwcdm]+)\]$/', $acl, $match)){
1265           $aclList= array($match[1]);
1266         }
1268         // match for "users[rw]" style entries
1269         if (preg_match('/^([a-zA-Z0-9]+)\[([rwcdm]+)\]$/', $acl, $match)){
1270           $module= $match[1];
1271           $aclList= array($match[2]);
1272         }
1274         // match for "users/user[rw]" style entries
1275         if (preg_match('/^([a-zA-Z0-9]+\/[a-zA-Z0-9]+)\[([rwcdm]+)\]$/', $acl, $match)){
1276           $module= $match[1];
1277           $aclList= array($match[2]);
1278         }
1280         // match "users/user[userPassword:rw(,...)*]" style entries
1281         if (preg_match('/^([a-zA-Z0-9]+\/[a-zA-Z0-9]+)\[([a-zA-Z0-9]+:[rwcdm]+(,[a-zA-Z0-9]+:[rwcdm]+)*)\]$/', $acl, $match)){
1282           $module= $match[1];
1283           $aclList= explode(',', $match[2]);
1284         }
1286         // Walk thru prepared ACL by using $module
1287         foreach($aclList as $sAcl) {
1288           $checkAcl= "";
1290           // Category or detailed permission?
1291           if (strpos($module, '/') !== false) {
1292             if (preg_match('/([a-zA-Z0-9]+):([rwcdm]+)/', $sAcl, $m) ) {
1293               $checkAcl= $ui->get_permissions($dn, $module, $m[1]);
1294               $sAcl= $m[2];
1295             } else {
1296               $checkAcl= $ui->get_permissions($dn, $module, '0');
1297             }
1298           } else {
1299             $checkAcl= $ui->get_category_permissions($dn, $module);
1300           }
1302           // Split up remaining part of the acl and check if it we're
1303           // allowed to do something...
1304           $parts= str_split($sAcl);
1305           foreach ($parts as $part) {
1306             if (strpos($checkAcl, $part) === false){
1307               return false;
1308             }
1309           }
1311         }
1312       }
1313     }
1315     return true;
1316   }
1319   function refreshBasesList()
1320   {
1321     global $config;
1322     $ui= get_userinfo();
1324     // Do some array munching to get it user friendly
1325     $ids= $config->idepartments;
1326     $d= $ui->get_module_departments($this->categories);
1327     $k_ids= array_keys($ids);
1328     $deps= array_intersect($d,$k_ids);
1330     // Fill internal bases list
1331     $this->bases= array();
1332     foreach($k_ids as $department){
1333       $this->bases[$department] = $ids[$department];
1334     }
1336     // Populate base selector if already present
1337     if ($this->baseSelector && $this->baseMode) {
1338       $this->baseSelector->setBases($this->bases);
1339       $this->baseSelector->update(TRUE);
1340     }
1341   }
1344   function getDepartments()
1345   {
1346     $departments= array();
1347     $ui= get_userinfo();
1349     // Get list of supported department types
1350     $types = departmentManagement::get_support_departments();
1352     // Load departments allowed by ACL
1353     $validDepartments = $ui->get_module_departments($this->categories);
1355     // Build filter and look in the LDAP for possible sub departments
1356     // of current base
1357     $filter= "(&(objectClass=gosaDepartment)(|";
1358     $attrs= array("description", "objectClass");
1359     foreach($types as $name => $data){
1360       $filter.= "(objectClass=".$data['OC'].")";
1361       $attrs[]= $data['ATTR'];
1362     }
1363     $filter.= "))";
1364     $res= get_list($filter, $this->categories, $this->base, $attrs, GL_NONE);
1366     // Analyze list of departments
1367     foreach ($res as $department) {
1368       if (!in_array($department['dn'], $validDepartments)) {
1369         continue;
1370       }
1372       // Add the attribute where we use for sorting
1373       $oc= null;
1374       foreach(array_keys($types) as $type) {
1375         if (in_array($type, $department['objectClass'])) {
1376           $oc= $type;
1377           break;
1378         }
1379       }
1380       $department['sort-attribute']= $types[$oc]['ATTR'];
1382       // Move to the result list
1383       $departments[]= $department;
1384     }
1386     return $departments;
1387   }
1390   function renderCopyPasteMenu($separator, $copy= true, $cut= true)
1391   {
1392     // We can only provide information if we've got a copypaste handler
1393     // instance
1394     if(!(isset($this->copyPasteHandler) && is_object($this->copyPasteHandler))){
1395       return "";
1396     }
1398     // Presets
1399     $result= "";
1400     $read= $paste= false;
1401     $ui= get_userinfo();
1403     // Switch flags to on if there's at least one category which allows read/paste
1404     foreach($this->categories as $category){
1405       $read= $read || preg_match('/r/', $ui->get_category_permissions($this->base, $category));
1406       $paste= $paste || $ui->is_pasteable($this->base, $category) == 1;
1407     }
1410     // Draw entries that allow copy and cut
1411     if($read){
1413       // Copy entry
1414       if($copy){
1415         $result.= "<li$separator><a href='#' onClick='\$(\"act\").value= \"copy\";\$(\"exec_act\").click();'>".image('images/lists/copy.png')."&nbsp;"._("Copy")."</a></li>";
1416         $separator= "";
1417       }
1419       // Cut entry
1420       if($cut){
1421         $result.= "<li$separator><a href='#' onClick='\$(\"act\").value= \"cut\";\$(\"exec_act\").click();'>".image("images/lists/cut.png")."&nbsp;"._("Cut")."</a></li>";
1422         $separator= "";
1423       }
1424     }
1426     // Draw entries that allow pasting entries
1427     if($paste){
1428       if($this->copyPasteHandler->entries_queued()){
1429         $result.= "<li$separator><a href='#' onClick='\$(\"act\").value= \"paste\";\$(\"exec_act\").click();'>".image("images/lists/paste.png")."&nbsp;"._("Paste")."</a></li>";
1430       }else{
1431         $result.= "<li$separator><a href='#'>".image('images/lists/paste-grey.png')."&nbsp;"._("Paste")."</a></li>";
1432       }
1433     }
1434     
1435     return($result);
1436   }
1439   function renderCopyPasteActions($row, $dn, $category, $class, $copy= true, $cut= true)
1440   {
1441     // We can only provide information if we've got a copypaste handler
1442     // instance
1443     if(!(isset($this->copyPasteHandler) && is_object($this->copyPasteHandler))){
1444       return "";
1445     }
1447     // Presets
1448     $ui = get_userinfo();
1449     $result = "";
1451     // Render cut entries
1452     if($cut){
1453       if($ui->is_cutable($dn, $category, $class)){
1454         $result.= image('images/lists/cut.png', "listing_cut_$row", _("Cut this entry"));
1455       }else{
1456         $result.= image('images/empty.png');
1457       }
1458     }
1460     // Render copy entries
1461     if($copy){
1462       if($ui->is_copyable($dn, $category, $class)){
1463         $result.= image('images/lists/copy.png', "listing_copy_$row", _("Copy this entry"));
1464       }else{
1465         $result.= image('images/empty.png');
1466       }
1467     }
1469     return($result);
1470   }
1473   function renderSnapshotMenu($separator)
1474   {
1475     // We can only provide information if we've got a snapshot handler
1476     // instance
1477     if(!(isset($this->snapshotHandler) && is_object($this->snapshotHandler))){
1478       return "";
1479     }
1481     // Presets
1482     $result = "";
1483     $ui = get_userinfo();
1485     if($this->snapshotHandler->enabled() && $ui->allow_snapshot_restore($this->base, $this->categories)){
1487       // Check if there is something to restore
1488       $restore= false;
1489       foreach($this->snapshotHandler->getSnapshotBases() as $base){
1490         $restore= $restore || count($this->snapshotHandler->getDeletedSnapshots($base)) > 0;
1491       }
1493       // Draw icons according to the restore flag
1494       if($restore){
1495         $result.= "<li$separator><a href='#' onClick='\$(\"act\").value= \"restore\";\$(\"exec_act\").click();'>".image('images/lists/restore.png')."&nbsp;"._("Restore snapshots")."</a></li>";
1496       }else{
1497         $result.= "<li$separator><a href='#'>".image('images/lists/restore-grey.png')."&nbsp;"._("Restore snapshots")."</a></li>";
1498       }
1499     }
1501     return($result);
1502   }
1505   function renderExporterMenu($separator)
1506   {
1507     // Presets
1508     $result = "";
1510     // Draw entries
1511     $result.= "<li$separator><a href='#'>".image('images/lists/export.png')."&nbsp;"._("Export list")."&nbsp;".image("images/forward-arrow.png")."</a><ul class='level3'>";
1513     // Export CVS as build in exporter
1514     foreach ($this->exporter as $action => $exporter) {
1515       $result.= "<li><a href='#' onClick='\$(\"act\").value= \"$action\";\$(\"exec_act\").click();'>".image($exporter['image'])."&nbsp;".$exporter['label']."</a></li>";
1516     }
1518     // Finalize list
1519     $result.= "</ul></li>";
1521     return($result);
1522   }
1525   function renderSnapshotActions($row, $dn, $category, $class, $copy= true, $cut= true)
1526   {
1527     // We can only provide information if we've got a snapshot handler
1528     // instance
1529     if(!(isset($this->snapshotHandler) && is_object($this->snapshotHandler))){
1530       return "";
1531     }
1533     // Presets
1534     $result= "";
1535     $ui = get_userinfo();
1537     // Only act if enabled here
1538     if($this->snapshotHandler->enabled()){
1540       // Draw restore button
1541       if ($ui->allow_snapshot_restore($dn, $category)){
1543         // Do we have snapshots for this dn?
1544         if($this->snapshotHandler->hasSnapshots($dn)){
1545           $result.= image('images/lists/restore.png', "listing_restore_$row", _("Restore snapshot"));
1546         } else {
1547           $result.= image('images/lists/restore-grey.png');
1548         }
1549       }
1551       // Draw snapshot button
1552       if($ui->allow_snapshot_create($dn, $category)){
1553           $result.= image('images/snapshot.png', "listing_snapshot_$row", _("Create a new snapshot from this object"));
1554       }else{
1555           $result.= image('images/empty.png');
1556       }
1557     }
1559     return($result);
1560   }
1563   function renderDaemonMenu($separator)
1564   {
1565     $result= "";
1567     // If there is a daemon registered, draw the menu entries
1568     if(class_available("DaemonEvent")){
1569       $events= DaemonEvent::get_event_types_by_category($this->categories);
1570       if(isset($events['BY_CLASS']) && count($events['BY_CLASS'])){
1571         foreach($events['BY_CLASS'] as $name => $event){
1572           $result.= "<li$separator><a href='#' onClick='\$(\"act\").value=\"$name\";\$(\"exec_act\").click();'>".$event['MenuImage']."&nbsp;".$event['s_Menu_Name']."</a></li>";
1573           $separator= "";
1574         }
1575       }
1576     }
1578     return $result;
1579   }
1582   function getEntry($dn)
1583   {
1584     foreach ($this->entries as $entry) {
1585       if (isset($entry['dn']) && strcasecmp($dn, $entry['dn']) == 0){
1586         return $entry;
1587       }
1588     }
1589     return null;
1590   }
1593   function getEntries()
1594   {
1595     return $this->entries;
1596   }
1599   function getType($dn)
1600   {
1601     if (isset($this->objectDnMapping[$dn])) {
1602       return $this->objectDnMapping[$dn];
1603     }
1604     return null;
1605   }
1609 ?>