Code

Added method to return list of configured filters
[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 $template;
32   var $headline;
33   var $base;
34   var $sortDirection= null;
35   var $sortColumn= null;
36   var $sortAttribute;
37   var $sortType;
38   var $numColumns;
39   var $baseMode= false;
40   var $bases= array();
41   var $header= array();
42   var $colprops= array();
43   var $filters= array();
44   var $filter= null;
45   var $pid;
46   var $objectTypes= array();
47   var $objectTypeCount= array();
48   var $objectDnMapping= array();
49   var $copyPasteHandler= null;
50   var $snapshotHandler= null;
51   var $exporter= array();
52   var $exportColumns= array();
53   var $useSpan= false;
54   var $height= 0;
55   var $scrollPosition= 0;
56   var $baseSelector;
59   function listing($filename)
60   {
61     global $config;
62     global $class_mapping;
64     // Initialize pid
65     $this->pid= preg_replace("/[^0-9]/", "", microtime(TRUE));
67     if (!$this->load($filename)) {
68       die("Cannot parse $filename!");
69     }
71     // Set base for filter
72     if ($this->baseMode) {
73       $this->base= session::global_get("CurrentMainBase");
74       if ($this->base == null) {
75         $this->base= $config->current['BASE'];
76       }
77       $this->refreshBasesList();
78     } else {
79       $this->base= $config->current['BASE'];
80     }
82     // Move footer information
83     $this->showFooter= ($config->get_cfg_value("listSummary") == "true");
85     // Register build in filters
86     $this->registerElementFilter("objectType", "listing::filterObjectType");
87     $this->registerElementFilter("departmentLink", "listing::filterDepartmentLink");
88     $this->registerElementFilter("link", "listing::filterLink");
89     $this->registerElementFilter("actions", "listing::filterActions");
91     // Load exporters
92     foreach($class_mapping as $class => $dummy) {
93       if (preg_match('/Exporter$/', $class)) {
94         $info= call_user_func(array($class, "getInfo"));
95         if ($info != null) {
96           $this->exporter= array_merge($this->exporter, $info);
97         }
98       }
99     }
101     // Instanciate base selector
102     $this->baseSelector= new baseSelector($this->bases, $this->base);
103   }
106   function setCopyPasteHandler($handler)
107   {
108     $this->copyPasteHandler= &$handler;
109   }
112   function setHeight($height)
113   {
114     $this->height= $height;
115   }
118   function setSnapshotHandler($handler)
119   {
120     $this->snapshotHandler= &$handler;
121   }
124   function setFilter($filter)
125   {
126     $this->filter= &$filter;
127     if ($this->departmentBrowser){
128       $this->departments= $this->getDepartments();
129     }
130     $this->filter->setBase($this->base);
131   }
134   function registerElementFilter($name, $call)
135   {
136     if (!isset($this->filters[$name])) {
137       $this->filters[$name]= $call;
138       return true;
139     }
141     return false;
142   }
145   function load($filename)
146   {
147     $contents = file_get_contents($filename);
148     $this->xmlData= xml::xml2array($contents, 1);
150     if (!isset($this->xmlData['list'])) {
151       return false;
152     }
154     $this->xmlData= $this->xmlData["list"];
156     // Load some definition values
157     foreach (array("departmentBrowser", "departmentRootVisible", "multiSelect", "baseMode") as $token) {
158       if (isset($this->xmlData['definition'][$token]) &&
159           $this->xmlData['definition'][$token] == "true"){
160         $this->$token= true;
161       }
162     }
164     // Fill objectTypes from departments and xml definition
165     $types = departmentManagement::get_support_departments();
166     foreach ($types as $class => $data) {
167       $this->objectTypes[$data['OC']]= array("label" => $data['TITLE'],
168                                   "objectClass" => $data['OC'],
169                                   "image" => $data['IMG']);
170     }
171     $this->categories= array();
172     if (isset($this->xmlData['definition']['objectType'])) {
173       if(isset($this->xmlData['definition']['objectType']['label'])) {
174         $this->xmlData['definition']['objectType']= array($this->xmlData['definition']['objectType']);
175       }
176       foreach ($this->xmlData['definition']['objectType'] as $index => $otype) {
177         $tmp = $this->xmlData['definition']['objectType'][$index];
178         $this->objectTypes[$tmp['objectClass']]= $tmp;
179         if (isset($this->xmlData['definition']['objectType'][$index]['category'])){
180           $this->categories[]= $otype['category'];
181         }
182       }
183     }
184     $this->objectTypes = array_values($this->objectTypes);
186     // Parse layout per column
187     $this->colprops= $this->parseLayout($this->xmlData['table']['layout']);
189     // Prepare table headers
190     $this->renderHeader();
192     // Assign headline/Categories
193     $this->headline= _($this->xmlData['definition']['label']);
194     if (!is_array($this->categories)){
195       $this->categories= array($this->categories);
196     }
198     // Evaluate columns to be exported
199     if (isset($this->xmlData['table']['column'])){
200       foreach ($this->xmlData['table']['column'] as $index => $config) {
201         if (isset($config['export']) && $config['export'] == "true"){
202           $this->exportColumns[]= $index;
203         }
204       }
205     }
207     return true;  
208   }
211   function renderHeader()
212   {
213     $this->header= array();
214     $this->plainHeader= array();
216     // Initialize sort?
217     $sortInit= false;
218     if (!$this->sortDirection) {
219       $this->sortColumn= 0;
220       if (isset($this->xmlData['definition']['defaultSortColumn'])){
221         $this->sortColumn= $this->xmlData['definition']['defaultSortColumn'];
222       } else {
223         $this->sortAttribute= "";
224       }
225       $this->sortDirection= array();
226       $sortInit= true;
227     }
229     if (isset($this->xmlData['table']['column'])){
230       foreach ($this->xmlData['table']['column'] as $index => $config) {
231         // Initialize everything to one direction
232         if ($sortInit) {
233           $this->sortDirection[$index]= false;
234         }
236         $sorter= "";
237         if ($index == $this->sortColumn && isset($config['sortAttribute']) &&
238             isset($config['sortType'])) {
239           $this->sortAttribute= $config['sortAttribute'];
240           $this->sortType= $config['sortType'];
241           $sorter= "&nbsp;".image("images/lists/sort-".($this->sortDirection[$index]?"up":"down").".png", null, $this->sortDirection[$index]?_("Up"):_("Down"), "text-top");
242         }
243         $sortable= (isset($config['sortAttribute']));
245         $link= "href='?plug=".$_GET['plug']."&amp;PID=".$this->pid."&amp;act=SORT_$index'";
246         if (isset($config['label'])) {
247           if ($sortable) {
248             $this->header[$index]= "<td class='listheader' ".$this->colprops[$index]."><a $link>"._($config['label'])."</a>$sorter</td>";
249           } else {
250             $this->header[$index]= "<td class='listheader' ".$this->colprops[$index].">"._($config['label'])."</td>";
251           }
252           $this->plainHeader[]= _($config['label']);
253         } else {
254           if ($sortable) {
255             $this->header[$index]= "<td class='listheader' ".$this->colprops[$index]."><a $link>&nbsp;</a>$sorter</td>";
256           } else {
257             $this->header[$index]= "<td class='listheader' ".$this->colprops[$index].">&nbsp;</td>";
258           }
259           $this->plainHeader[]= "";
260         }
261       }
262     }
263   }
266   function render()
267   {
268     // Check for exeeded sizelimit
269     if (($message= check_sizelimit()) != ""){
270       return($message);
271     }
273     // Some browsers don't have the ability do do scrollable table bodies, filter them
274     // here.
275     $switch= false;
276     if (preg_match('/(Opera|Konqueror|Safari)/i', $_SERVER['HTTP_USER_AGENT'])){
277       $switch= true;
278     }
280     // Initialize list
281     $result= "<input type='hidden' value='$this->pid' name='PID'>\n";
282     $result.= "<input type='hidden' name='position_".$this->pid."' id='position_".$this->pid."'>\n";
283     $height= 450;
284     if ($this->height != 0) {
285       $result.= "<input type='hidden' value='$this->height' id='d_height'>\n";
286       $height= $this->height;
287     }
288     
289     $result.= "<div class='listContainer' id='d_scrollbody' style='min-height:".($height+25)."px;'>\n";
290     $result.= "<table summary='$this->headline' style='width:100%;table-layout:fixed' cellspacing='0' cellpadding='0' id='t_scrolltable'>\n";
291     $this->numColumns= count($this->colprops) + ($this->multiSelect?1:0);
293     // Build list header
294     $result.= "<thead class='fixedListHeader listHeaderFormat'><tr>\n";
295     if ($this->multiSelect) {
296       $width= "24px";
297       if (preg_match('/Konqueror/i', $_SERVER['HTTP_USER_AGENT'])){
298         $width= "28px";
299       }
300       $result.= "<td class='listheader' style='text-align:center;padding:0;width:$width;'><input type='checkbox' id='select_all' name='select_all' title='"._("Select all")."' onClick='toggle_all_(\"listing_selected_[0-9]*$\",\"select_all\");' ></td>\n";
301     }
302     foreach ($this->header as $header) {
303       $result.= $header;
304     }
305     $result.= "</tr></thead>\n";
307     // Build list body
308     $result.= "<tbody class='listScrollContent listBodyFormat' id='t_nscrollbody' style='height:".$height."px;'>\n";
310     // No results? Just take an empty colspanned row
311     if (count($this->entries) + count($this->departments) == 0) {
312       $result.= "<tr><td class='list1nohighlight' colspan='$this->numColumns' style='height:100%;border-right:0px;width:100%;'>&nbsp;</td></tr>";
313     }
315     // Line color alternation
316     $alt= 0;
317     $deps= 0;
319     // Draw department browser if configured and we're not in sub mode
320     $this->useSpan= false;
321     if ($this->departmentBrowser && $this->filter->scope != "sub") {
322       // Fill with department browser if configured this way
323       $departmentIterator= new departmentSortIterator($this->departments, $this->sortDirection[$this->sortColumn]);
324       foreach ($departmentIterator as $row => $entry){
325         $result.="<tr>";
327         // Render multi select if needed
328         if ($this->multiSelect) {
329           $result.="<td style='text-align:center;padding:0;' class='list1'>&nbsp;</td>";
330         }
332         // Render defined department columns, fill the rest with some stuff
333         $rest= $this->numColumns - 1;
334         foreach ($this->xmlData['table']['department'] as $index => $config) {
335           $colspan= 1;
336           if (isset($config['span'])){
337             $colspan= $config['span'];
338             $this->useSpan= true;
339           }
340           $result.="<td colspan='$colspan' ".$this->colprops[$index]." class='list1'>".$this->renderCell($config['value'], $entry, $row)."</td>";
341           $rest-= $colspan;
342         }
344         // Fill remaining cols with nothing
345         $last= $this->numColumns - $rest;
346         for ($i= 0; $i<$rest; $i++){
347           $result.= "<td ".$this->colprops[$last+$i-1]." class='list1'>&nbsp;</td>";
348         }
349         $result.="</tr>";
351         $alt++;
352       }
353       $deps= $alt;
354     }
356     // Fill with contents, sort as configured
357     foreach ($this->entries as $row => $entry) {
358       $trow= "";
360       // Render multi select if needed
361       if ($this->multiSelect) {
362         $trow.="<td style='text-align:center;width:20px;' class='list0'><input type='checkbox' id='listing_selected_$row' name='listing_selected_$row'></td>\n";
363       }
365       foreach ($this->xmlData['table']['column'] as $index => $config) {
366         $renderedCell= $this->renderCell($config['value'], $entry, $row);
367         $trow.="<td ".$this->colprops[$index]." class='list0'>".$renderedCell."</td>\n";
369         // Save rendered column
370         $sort= preg_replace('/.*>([^<]+)<.*$/', '$1', $renderedCell);
371         $sort= preg_replace('/&nbsp;/', '', $sort);
372         if (preg_match('/</', $sort)){
373           $sort= "";
374         }
375         $this->entries[$row]["_sort$index"]= $sort;
376       }
378       // Save rendered entry
379       $this->entries[$row]['_rendered']= $trow;
380     }
382     // Complete list by sorting entries for _sort$index and appending them to the output
383     $entryIterator= new listingSortIterator($this->entries, $this->sortDirection[$this->sortColumn], "_sort".$this->sortColumn, $this->sortType);
384     foreach ($entryIterator as $row => $entry){
385       $result.="<tr>\n";
386       $result.= $entry['_rendered'];
387       $result.="</tr>\n";
388       $alt++;
389     }
391     // Need to fill the list if it's not full (nobody knows why this is 22 ;-))
392     $emptyListStyle= (count($this->entries) + (($this->useSpan && count($this->entries))?$deps:0) == 0)?"border:0;":"";
393     if ((count($this->entries) + $deps) < 22) {
394       $result.= "<tr>";
395       for ($i= 0; $i<$this->numColumns; $i++) {
396         if ($i == 0) {
397           $result.= "<td class='list1nohighlight' style='$emptyListStyle height:100%;'>&nbsp;</td>";
398           continue;
399         }
400         if ($i != $this->numColumns-1) {
401           $result.= "<td class='list1nohighlight' style='$emptyListStyle'>&nbsp;</td>";
402         } else {
403           $result.= "<td class='list1nohighlight' style='border-right:0;$emptyListStyle'>&nbsp;</td>";
404         }
405       }
406       $result.= "</tr>";
407     }
409     // Close list body
410     $result.= "</tbody></table></div>";
412     // Add the footer if requested
413     if ($this->showFooter) {
414       $result.= "<div class='nlistFooter'><div style='padding:3px'>";
416       foreach ($this->objectTypes as $objectType) {
417         if (isset($this->objectTypeCount[$objectType['label']])) {
418           $label= _($objectType['label']);
419           $result.= image($objectType['image'], null, $label)."&nbsp;".$this->objectTypeCount[$objectType['label']]."&nbsp;&nbsp;";
420         }
421       }
423       $result.= "</div></div>";
424     }
426     // Close list
427     $result.= $switch?"<input type='hidden' id='list_workaround'>":"";
429     // Add scroll positioner
430     $result.= '<script type="text/javascript" language="javascript">';
431     $result.= '$("t_nscrollbody").scrollTop= '.$this->scrollPosition.';';
432     $result.= 'var box = $("t_nscrollbody").onscroll= function() {$("position_'.$this->pid.'").value= this.scrollTop;}';
433     $result.= '</script>';
435     $smarty= get_smarty();
436     $smarty->assign("usePrototype", "true");
437     $smarty->assign("FILTER", $this->filter->render());
438     $smarty->assign("SIZELIMIT", print_sizelimit_warning());
439     $smarty->assign("LIST", $result);
441     // Assign navigation elements
442     $nav= $this->renderNavigation();
443     foreach ($nav as $key => $html) {
444       $smarty->assign($key, $html);
445     }
447     // Assign action menu / base
448     $smarty->assign("ACTIONS", $this->renderActionMenu());
449     $smarty->assign("BASE", $this->renderBase());
451     // Assign separator
452     $smarty->assign("SEPARATOR", "<img src='images/lists/seperator.png' alt='-' align='middle' height='16' width='1' class='center'>");
454     // Assign summary
455     $smarty->assign("HEADLINE", $this->headline);
457     // Try to load template from plugin the folder first...
458     $file = get_template_path($this->xmlData['definition']['template'], true);
460     // ... if this fails, try to load the file from the theme folder.
461     if(!file_exists($file)){
462       $file = get_template_path($this->xmlData['definition']['template']);
463     }
465     return ($smarty->fetch($file));
466   }
469   function update()
470   {
471     global $config;
472     $ui= get_userinfo();
474     // Take care of base selector
475     if ($this->baseMode) {
476       $this->baseSelector->update();
477       // Check if a wrong base was supplied
478       if(!$this->baseSelector->checkLastBaseUpdate()){
479          msg_dialog::display(_("Error"), msgPool::check_base(), ERROR_DIALOG);
480       }
481     }
483     // Save base
484     $refresh= false;
485     if ($this->baseMode) {
486       $this->base= $this->baseSelector->getBase();
487       session::global_set("CurrentMainBase", $this->base);
488       $refresh= true;
489     }
492     // Reset object counter / DN mapping
493     $this->objectTypeCount= array();
494     $this->objectDnMapping= array();
496     // Do not do anything if this is not our PID
497     if($refresh || !(isset($_REQUEST['PID']) && $_REQUEST['PID'] != $this->pid)) {
499       // Save position if set
500       if (isset($_POST['position_'.$this->pid]) && is_numeric($_POST['position_'.$this->pid])) {
501         $this->scrollPosition= $_POST['position_'.$this->pid];
502       }
504       // Override the base if we got a message from the browser navigation
505       if ($this->departmentBrowser && isset($_GET['act'])) {
506         if (preg_match('/^department_([0-9]+)$/', validate($_GET['act']), $match)){
507           if (isset($this->departments[$match[1]])){
508             $this->base= $this->departments[$match[1]]['dn'];
509             if ($this->baseMode) {
510               $this->baseSelector->setBase($this->base);
511             }
512             session::global_set("CurrentMainBase", $this->base);
513           }
514         }
515       }
517       // Filter POST with "act" attributes -> posted from action menu
518       if (isset($_POST['exec_act']) && $_POST['act'] != '') {
519         if (preg_match('/^export.*$/', $_POST['act']) && isset($this->exporter[$_POST['act']])) {
520           $exporter= $this->exporter[$_POST['act']];
521           $userinfo= ", "._("created by")." ".$ui->cn." - ".strftime('%A, %d. %B %Y, %H:%M:%S');
522           $entryIterator= new listingSortIterator($this->entries, $this->sortDirection[$this->sortColumn], "_sort".$this->sortColumn, $this->sortType);
523           $sortedEntries= array();
524           foreach ($entryIterator as $entry){
525             $sortedEntries[]= $entry;
526           }
527           $instance= new $exporter['class']($this->headline.$userinfo, $this->plainHeader, $sortedEntries, $this->exportColumns);
528           $type= call_user_func(array($exporter['class'], "getInfo"));
529           $type= $type[$_POST['act']];
530           send_binary_content($instance->query(), $type['filename'], $type= $type['mime']);
531         }
532       }
534       // Filter GET with "act" attributes
535       if (isset($_GET['act'])) {
536         $key= validate($_GET['act']);
537         if (preg_match('/^SORT_([0-9]+)$/', $key, $match)) {
538           // Switch to new column or invert search order?
539           $column= $match[1];
540           if ($this->sortColumn != $column) {
541             $this->sortColumn= $column;
542           } else {
543             $this->sortDirection[$column]= !$this->sortDirection[$column];
544           }
546           // Allow header to update itself according to the new sort settings
547           $this->renderHeader();
548         }
549       }
551       // Override base if we got signals from the navigation elements
552       $action= "";
553       foreach ($_POST as $key => $value) {
554         if (preg_match('/^(ROOT|BACK|HOME)(_x)?$/', $key, $match)) {
555           $action= $match[1];
556           break;
557         }
558       }
560       // Navigation handling
561       if ($action == 'ROOT') {
562         $deps= $ui->get_module_departments($this->categories);
563         $this->base= $deps[0];
564         $this->baseSelector->setBase($this->base);
565         session::global_set("CurrentMainBase", $this->base);
566       }
567       if ($action == 'BACK') {
568         $deps= $ui->get_module_departments($this->categories);
569         $base= preg_replace("/^[^,]+,/", "", $this->base);
570         if(in_array_ics($base, $deps)){
571           $this->base= $base;
572           $this->baseSelector->setBase($this->base);
573           session::global_set("CurrentMainBase", $this->base);
574         }
575       }
576       if ($action == 'HOME') {
577         $ui= get_userinfo();
578         $this->base= get_base_from_people($ui->dn);
579         $this->baseSelector->setBase($this->base);
580         session::global_set("CurrentMainBase", $this->base);
581       }
582     }
584     // Reload departments
585     if ($this->departmentBrowser){
586       $this->departments= $this->getDepartments();
587     }
589     // Update filter and refresh entries
590     $this->filter->setBase($this->base);
591     $this->entries= $this->filter->query();
593     // Fix filter if querie returns NULL
594     if ($this->entries == null) {
595       $this->entries= array();
596     }
597   }
600   function setBase($base)
601   {
602     $this->base= $base;
603     if ($this->baseMode) {
604       $this->baseSelector->setBase($this->base);
605     }
606   }
609   function getBase()
610   {
611     return $this->base;
612   }
615   function parseLayout($layout)
616   {
617     $result= array();
618     $layout= preg_replace("/^\|/", "", $layout);
619     $layout= preg_replace("/\|$/", "", $layout);
620     $cols= explode("|", $layout);
622     foreach ($cols as $index => $config) {
623       if ($config != "") {
624         $res= "";
625         $components= explode(';', $config);
626         foreach ($components as $part) {
627           if (preg_match("/^r$/", $part)) {
628             $res.= "text-align:right;";
629             continue;
630           }
631           if (preg_match("/^l$/", $part)) {
632             $res.= "text-align:left;";
633             continue;
634           }
635           if (preg_match("/^c$/", $part)) {
636             $res.= "text-align:center;";
637             continue;
638           }
639           if (preg_match("/^[0-9]+(|px|%)$/", $part)) {
640             $res.= "width:$part;min-width:$part;";
641             continue;
642           }
643         }
645         // Add minimum width for scalable columns
646         if (!preg_match('/width:/', $res)){
647           $res.= "min-width:200px;";
648         }
650         $result[$index]= " style='$res'";
651       } else {
652         $result[$index]= " style='min-width:100px;'";
653       }
654     }
656     // Save number of columns for later use
657     $this->numColumns= count($cols);
659     // Add no border to the last column
660     $result[$this->numColumns-1]= preg_replace("/'$/", "border-right:0;'", $result[$this->numColumns-1]);
662     return $result;
663   }
666   function renderCell($data, $config, $row)
667   {
668     // Replace flat attributes in data string
669     for ($i= 0; $i<$config['count']; $i++) {
670       $attr= $config[$i];
671       $value= "";
672       if (is_array($config[$attr])) {
673         $value= $config[$attr][0];
674       } else {
675         $value= $config[$attr];
676       }
677       $data= preg_replace("/%\{$attr\}/", $value, $data);
678     }
680     // Watch out for filters and prepare to execute them
681     $data= $this->processElementFilter($data, $config, $row);
683     // Replace all non replaced %{...} instances because they
684     // are non resolved attributes or filters
685     $data= preg_replace('/%{[^}]+}/', '&nbsp;', $data);
687     return $data;
688   }
691   function renderBase()
692   {
693     if (!$this->baseMode) {
694       return;
695     }
697     return $this->baseSelector->render();
698   }
701   function processElementFilter($data, $config, $row)
702   {
703     preg_match_all("/%\{filter:([^(]+)\((.*)\)\}/", $data, $matches, PREG_SET_ORDER);
705     foreach ($matches as $match) {
706       $cl= "";
707       $method= "";
708       if (preg_match('/::/', $match[1])) {
709         $cl= preg_replace('/::.*$/', '', $match[1]);
710         $method= preg_replace('/^.*::/', '', $match[1]);
711       } else {
712         if (!isset($this->filters[$match[1]])) {
713           continue;
714         }
715         $cl= preg_replace('/::.*$/', '', $this->filters[$match[1]]);
716         $method= preg_replace('/^.*::/', '', $this->filters[$match[1]]);
717       }
719       // Prepare params for function call
720       $params= array();
721       preg_match_all('/"[^"]+"|[^,]+/', $match[2], $parts);
722       foreach ($parts[0] as $param) {
724         // Row is replaced by the row number
725         if ($param == "row") {
726           $params[]= $row;
727           continue;
728         }
730         // pid is replaced by the current PID
731         if ($param == "pid") {
732           $params[]= $this->pid;
733           continue;
734         }
736         // base is replaced by the current base
737         if ($param == "base") {
738           $params[]= $this->getBase();
739           continue;
740         }
742         // Fixie with "" is passed directly
743         if (preg_match('/^".*"$/', $param)){
744           $params[]= preg_replace('/"/', '', $param);
745           continue;
746         }
748         // Move dn if needed
749         if ($param == "dn") {
750           $params[]= LDAP::fix($config["dn"]);
751           continue;
752         }
754         // LDAP variables get replaced by their objects
755         for ($i= 0; $i<$config['count']; $i++) {
756           if ($param == $config[$i]) {
757             $values= $config[$config[$i]];
758             if (is_array($values)){
759               unset($values['count']);
760             }
761             $params[]= $values;
762             break;
763           }
764         }
765       }
767       // Replace information
768       if ($cl == "listing") {
769         // Non static call - seems to result in errors
770         $data= @preg_replace('/'.preg_quote($match[0]).'/', call_user_func_array(array($this, "$method"), $params), $data);
771       } else {
772         // Static call
773         $data= preg_replace('/'.preg_quote($match[0]).'/', call_user_func_array(array($cl, $method), $params), $data);
774       }
775     }
777     return $data;
778   }
781   function getObjectType($types, $classes)
782   {
783     // Walk thru types and see if there's something matching
784     foreach ($types as $objectType) {
785       $ocs= $objectType['objectClass'];
786       if (!is_array($ocs)){
787         $ocs= array($ocs);
788       }
790       $found= true;
791       foreach ($ocs as $oc){
792         if (preg_match('/^!(.*)$/', $oc, $match)) {
793           $oc= $match[1];
794           if (in_array($oc, $classes)) {
795             $found= false;
796           }
797         } else {
798           if (!in_array($oc, $classes)) {
799             $found= false;
800           }
801         }
802       }
804       if ($found) {
805         return $objectType;
806       }
807     }
809     return null;
810   }
813   function filterObjectType($dn, $classes)
814   {
815     // Walk thru classes and return on first match
816     $result= "&nbsp;";
818     $objectType= $this->getObjectType($this->objectTypes, $classes);
819     if ($objectType) {
820       $this->objectDnMapping[$dn]= $objectType["objectClass"];
821       $result= image($objectType["image"], null, LDAP::fix($dn));
822       if (!isset($this->objectTypeCount[$objectType['label']])) {
823         $this->objectTypeCount[$objectType['label']]= 0;
824       }
825       $this->objectTypeCount[$objectType['label']]++;
826     }
828     return $result;
829   }
832   function filterActions($dn, $row, $classes)
833   {
834     // Do nothing if there's no menu defined
835     if (!isset($this->xmlData['actiontriggers']['action'])) {
836       return "&nbsp;";
837     }
839     // Go thru all actions
840     $result= "";
841     $actions= $this->xmlData['actiontriggers']['action'];
843     // Ensure we've a valid actions array, if there is only one action in the actiontriggers col
844     //  then we've to create a valid array here.
845     if(isset($actions['name'])) $actions = array($actions);
847     foreach($actions as $action) {
848       // Skip the entry completely if there's no permission to execute it
849       if (!$this->hasActionPermission($action, $dn, $classes)) {
850         $result.= image('images/empty.png');
851         continue;
852       }
854       // Skip entry if the pseudo filter does not fit
855       if (isset($action['filter']) && preg_match('/^[a-z0-9_]+!?=[a-z0-9_]+$/i', $action['filter'])) {
856         list($fa, $fv)= explode('=', $action['filter']);
857         if (preg_match('/^(.*)!$/', $fa, $m)){
858           $fa= $m[1];
859           if (isset($this->entries[$row][$fa]) && $this->entries[$row][$fa][0] == $fv) {
860             $result.= image('images/empty.png');
861             continue;
862           }
863         } else {
864           if (!isset($this->entries[$row][$fa]) && !$this->entries[$row][$fa][0] == $fv) {
865             $result.= image('images/empty.png');
866             continue;
867           }
868         }
869       }
872       // If there's an objectclass definition and we don't have it
873       // add an empty picture here.
874       if (isset($action['objectclass'])){
875         $objectclass= $action['objectclass'];
876         if (preg_match('/^!(.*)$/', $objectclass, $m)){
877           $objectclass= $m[1];
878           if(in_array($objectclass, $classes)) {
879             $result.= image('images/empty.png');
880             continue;
881           }
882         } elseif (is_string($objectclass)) {
883           if(!in_array($objectclass, $classes)) {
884             $result.= image('images/empty.png');
885             continue;
886           }
887         } elseif (is_array($objectclass)) {
888           if(count(array_intersect($objectclass, $classes)) != count($objectclass)){
889             $result.= image('images/empty.png');
890             continue;
891           }
892         }
893       }
895       // Render normal entries as usual
896       if ($action['type'] == "entry") {
897         $label= $this->processElementFilter($action['label'], $this->entries[$row], $row);
898         $image= $this->processElementFilter($action['image'], $this->entries[$row], $row);
899         $result.= image($image, "listing_".$action['name']."_$row", $label);
900       }
902       // Handle special types
903       if ($action['type'] == "copypaste" || $action['type'] == "snapshot") {
905         $objectType= $this->getObjectType($this->objectTypes, $this->entries[$row]['objectClass']);
906         $category= $class= null;
907         if ($objectType) {
908           $category= $objectType['category'];
909           $class= $objectType['class'];
910         }
912         if ($action['type'] == "copypaste") {
913           $copy = !isset($action['copy']) || $action['copy'] == "true";
914           $cut = !isset($action['cut']) || $action['cut'] == "true";
915           $result.= $this->renderCopyPasteActions($row, $this->entries[$row]['dn'], $category, $class,$copy,$cut);
916         } else {
917           $result.= $this->renderSnapshotActions($row, $this->entries[$row]['dn'], $category, $class);
918         }
919       }
920     }
922     return $result;
923   }
926   function filterDepartmentLink($row, $dn, $description)
927   {
928     $attr= $this->departments[$row]['sort-attribute'];
929     $name= $this->departments[$row][$attr];
930     if (is_array($name)){
931       $name= $name[0];
932     }
933     $result= sprintf("%s [%s]", $name, $description[0]);
934     return("<a href='?plug=".$_GET['plug']."&amp;PID=$this->pid&amp;act=department_$row' title='$dn'>$result</a>");
935   }
938   function filterLink()
939   {
940     $result= "&nbsp;";
942     $row= func_get_arg(0);
943     $pid= $this->pid;
944     $dn= LDAP::fix(func_get_arg(1));
945     $params= array(func_get_arg(2));
947     // Collect sprintf params
948     for ($i = 3;$i < func_num_args();$i++) {
949       $val= func_get_arg($i);
950       if (is_array($val)){
951         $params[]= $val[0];
952         continue;
953       }
954       $params[]= $val;
955     }
957     $result= "&nbsp;";
958     $trans= call_user_func_array("sprintf", $params);
959     if ($trans != "") {
960       return("<a href='?plug=".$_GET['plug']."&amp;PID=$pid&amp;act=listing_edit_$row' title='$dn'>$trans</a>");
961     }
963     return $result;
964   }
967   function renderNavigation()
968   {
969     $result= array();
970     $enableBack = true;
971     $enableRoot = true;
972     $enableHome = true;
974     $ui = get_userinfo();
976     /* Check if base = first available base */
977     $deps = $ui->get_module_departments($this->categories);
979     if(!count($deps) || $deps[0] == $this->filter->base){
980       $enableBack = false;
981       $enableRoot = false;
982     }
984     $listhead ="";
986     /* Check if we are in users home  department */
987     if(!count($deps) || $this->filter->base == get_base_from_people($ui->dn)){
988       $enableHome = false;
989     }
991     /* Draw root button */
992     if($enableRoot){
993       $result["ROOT"]= image('images/lists/root.png', 'ROOT', _("Root"));
994     }else{
995       $result["ROOT"]= image('images/lists/root-grey.png', null, _("Root"));
996     }
998     /* Draw back button */
999     if($enableBack){
1000       $result["BACK"]= image('images/lists/back.png', 'BACK', _("Go up one department"));
1001     }else{
1002       $result["BACK"]= image('images/lists/back-grey.png', null, _("Go up one department"));
1003     }
1005     /* Draw home button */
1006    /* Draw home button */
1007     if($enableHome){
1008       $result["HOME"]= image('images/lists/home.png', 'HOME', _("Go to users department"));
1009     }else{
1010       $result["HOME"]= image('images/lists/home-grey.png', null, _("Go to users department"));
1011     }
1014     /* Draw reload button, this button is enabled everytime */
1015     $result["RELOAD"]= image('images/lists/reload.png', 'REFRESH', _("Reload list"));
1017     return ($result);
1018   }
1021   function getAction()
1022   {
1023     // Do not do anything if this is not our PID, or there's even no PID available...
1024     if(!isset($_REQUEST['PID']) || $_REQUEST['PID'] != $this->pid) {
1025       return;
1026     }
1028     // Save position if set
1029     if (isset($_POST['position_'.$this->pid]) && is_numeric($_POST['position_'.$this->pid])) {
1030       $this->scrollPosition= $_POST['position_'.$this->pid];
1031     }
1033     $result= array("targets" => array(), "action" => "");
1035     // Filter GET with "act" attributes
1036     if (isset($_GET['act'])) {
1037       $key= validate($_GET['act']);
1038       $target= preg_replace('/^listing_[a-zA-Z_]+_([0-9]+)$/', '$1', $key);
1039       if (isset($this->entries[$target]['dn'])) {
1040         $result['action']= preg_replace('/^listing_([a-zA-Z_]+)_[0-9]+$/', '$1', $key);
1041         $result['targets'][]= $this->entries[$target]['dn'];
1042       }
1044       // Drop targets if empty
1045       if (count($result['targets']) == 0) {
1046         unset($result['targets']);
1047       }
1048       return $result;
1049     }
1051     // Filter POST with "listing_" attributes
1052     foreach ($_POST as $key => $prop) {
1054       // Capture selections
1055       if (preg_match('/^listing_selected_[0-9]+$/', $key)) {
1056         $target= preg_replace('/^listing_selected_([0-9]+)$/', '$1', $key);
1057         if (isset($this->entries[$target]['dn'])) {
1058           $result['targets'][]= $this->entries[$target]['dn'];
1059         }
1060         continue;
1061       }
1063       // Capture action with target - this is a one shot
1064       if (preg_match('/^listing_[a-zA-Z_]+_[0-9]+(|_x)$/', $key)) {
1065         $target= preg_replace('/^listing_[a-zA-Z_]+_([0-9]+)(|_x)$/', '$1', $key);
1066         if (isset($this->entries[$target]['dn'])) {
1067           $result['action']= preg_replace('/^listing_([a-zA-Z_]+)_[0-9]+(|_x)$/', '$1', $key);
1068           $result['targets']= array($this->entries[$target]['dn']);
1069         }
1070         break;
1071       }
1073       // Capture action without target
1074       if (preg_match('/^listing_[a-zA-Z_]+(|_x)$/', $key)) {
1075         $result['action']= preg_replace('/^listing_([a-zA-Z_]+)(|_x)$/', '$1', $key);
1076         continue;
1077       }
1078     }
1080     // Filter POST with "act" attributes -> posted from action menu
1081     if (isset($_POST['act']) && $_POST['act'] != '') {
1082       if (!preg_match('/^export.*$/', $_POST['act'])){
1083         $result['action']= validate($_POST['act']);
1084       }
1085     }
1087     // Drop targets if empty
1088     if (count($result['targets']) == 0) {
1089       unset($result['targets']);
1090     }
1091     return $result;
1092   }
1095   function renderActionMenu()
1096   {
1097     // Don't send anything if the menu is not defined
1098     if (!isset($this->xmlData['actionmenu']['action'])){
1099       return "";
1100     }
1102     // Array?
1103     if (isset($this->xmlData['actionmenu']['action']['type'])){
1104       $this->xmlData['actionmenu']['action']= array($this->xmlData['actionmenu']['action']);
1105     }
1107     // Load shortcut
1108     $actions= &$this->xmlData['actionmenu']['action'];
1109     $result= "<input type='hidden' name='act' id='actionmenu' value=''><div style='display:none'><input type='submit' name='exec_act' id='exec_act' value=''></div>".
1110              "<ul class='level1' id='root'><li><a href='#'>"._("Actions")."&nbsp;".image("images/lists/sort-down.png")."</a>";
1112     // Build ul/li list
1113     $result.= $this->recurseActions($actions);
1115     return "<div id='pulldown'>".$result."</li></ul><div>";
1116   }
1119   function recurseActions($actions)
1120   {
1121     global $class_mapping;
1122     static $level= 2;
1123     $result= "<ul class='level$level'>";
1124     $separator= "";
1126     foreach ($actions as $action) {
1128       // Skip the entry completely if there's no permission to execute it
1129       if (!$this->hasActionPermission($action, $this->filter->base)) {
1130         continue;
1131       }
1133       // Skip entry if there're missing dependencies
1134       if (isset($action['depends'])) {
1135         $deps= is_array($action['depends'])?$action['depends']:array($action['depends']);
1136         foreach($deps as $clazz) {
1137           if (!isset($class_mapping[$clazz])){
1138             continue 2;
1139           }
1140         }
1141       }
1143       // Fill image if set
1144       $img= "";
1145       if (isset($action['image'])){
1146         $img= image($action['image'])."&nbsp;";
1147       }
1149       if ($action['type'] == "separator"){
1150         $separator= " style='border-top:1px solid #AAA' ";
1151         continue;
1152       }
1154       // Dive into subs
1155       if ($action['type'] == "sub" && isset($action['action'])) {
1156         $level++;
1157         if (isset($action['label'])){
1158           $result.= "<li$separator><a href='#'>$img"._($action['label'])."&nbsp;".image('images/forward-arrow.png')."</a>";
1159         }
1161         // Ensure we've an array of actions, this enables sub menus with only one action.
1162         if(isset($action['action']['type'])){
1163           $action['action'] = array($action['action']);
1164         }
1166         $result.= $this->recurseActions($action['action'])."</li>";
1167         $level--;
1168         $separator= "";
1169         continue;
1170       }
1172       // Render entry elseways
1173       if (isset($action['label'])){
1174         $result.= "<li$separator><a href='#' onClick='document.getElementById(\"actionmenu\").value= \"".$action['name']."\";mainform.submit();'>$img"._($action['label'])."</a></li>";
1175       }
1177       // Check for special types
1178       switch ($action['type']) {
1179         case 'copypaste':
1180           $cut = !isset($action['cut']) || $action['cut'] != "false";
1181           $copy = !isset($action['copy']) || $action['copy'] != "false";
1182           $result.= $this->renderCopyPasteMenu($separator, $copy , $cut);
1183           break;
1185         case 'snapshot':
1186           $result.= $this->renderSnapshotMenu($separator);
1187           break;
1189         case 'exporter':
1190           $result.= $this->renderExporterMenu($separator);
1191           break;
1193         case 'daemon':
1194           $result.= $this->renderDaemonMenu($separator);
1195           break;
1196       }
1198       $separator= "";
1199     }
1201     $result.= "</ul>";
1202     return $result;
1203   }
1206   function hasActionPermission($action, $dn, $classes= null)
1207   {
1208     $ui= get_userinfo();
1210     if (isset($action['acl'])) {
1211       $acls= $action['acl'];
1212       if (!is_array($acls)) {
1213         $acls= array($acls);
1214       }
1216       // Every ACL has to pass
1217       foreach ($acls as $acl) {
1218         $module= $this->categories;
1219         $aclList= array();
1221         // Replace %acl if available
1222         if ($classes) {
1223           $otype= $this->getObjectType($this->objectTypes, $classes);
1224           $acl= str_replace('%acl', $otype['category']."/".$otype['class'], $acl);
1225         }
1227         // Split for category and plugins if needed
1228         // match for "[rw]" style entries
1229         if (preg_match('/^\[([rwcdm]+)\]$/', $acl, $match)){
1230           $aclList= array($match[1]);
1231         }
1233         // match for "users[rw]" style entries
1234         if (preg_match('/^([a-zA-Z0-9]+)\[([rwcdm]+)\]$/', $acl, $match)){
1235           $module= $match[1];
1236           $aclList= array($match[2]);
1237         }
1239         // match for "users/user[rw]" style entries
1240         if (preg_match('/^([a-zA-Z0-9]+\/[a-zA-Z0-9]+)\[([rwcdm]+)\]$/', $acl, $match)){
1241           $module= $match[1];
1242           $aclList= array($match[2]);
1243         }
1245         // match "users/user[userPassword:rw(,...)*]" style entries
1246         if (preg_match('/^([a-zA-Z0-9]+\/[a-zA-Z0-9]+)\[([a-zA-Z0-9]+:[rwcdm]+(,[a-zA-Z0-9]+:[rwcdm]+)*)\]$/', $acl, $match)){
1247           $module= $match[1];
1248           $aclList= explode(',', $match[2]);
1249         }
1251         // Walk thru prepared ACL by using $module
1252         foreach($aclList as $sAcl) {
1253           $checkAcl= "";
1255           // Category or detailed permission?
1256           if (strpos($module, '/') !== false) {
1257             if (preg_match('/([a-zA-Z0-9]+):([rwcdm]+)/', $sAcl, $m) ) {
1258               $checkAcl= $ui->get_permissions($dn, $module, $m[1]);
1259               $sAcl= $m[2];
1260             } else {
1261               $checkAcl= $ui->get_permissions($dn, $module, '0');
1262             }
1263           } else {
1264             $checkAcl= $ui->get_category_permissions($dn, $module);
1265           }
1267           // Split up remaining part of the acl and check if it we're
1268           // allowed to do something...
1269           $parts= str_split($sAcl);
1270           foreach ($parts as $part) {
1271             if (strpos($checkAcl, $part) === false){
1272               return false;
1273             }
1274           }
1276         }
1277       }
1278     }
1280     return true;
1281   }
1284   function refreshBasesList()
1285   {
1286     global $config;
1287     $ui= get_userinfo();
1289     // Do some array munching to get it user friendly
1290     $ids= $config->idepartments;
1291     $d= $ui->get_module_departments($this->categories);
1292     $k_ids= array_keys($ids);
1293     $deps= array_intersect($d,$k_ids);
1295     // Fill internal bases list
1296     $this->bases= array();
1297     foreach($k_ids as $department){
1298       $this->bases[$department] = $ids[$department];
1299     }
1301     // Populate base selector if already present
1302     if ($this->baseSelector && $this->baseMode) {
1303       $this->baseSelector->setBases($this->bases);
1304       $this->baseSelector->update(TRUE);
1305     }
1306   }
1309   function getDepartments()
1310   {
1311     $departments= array();
1312     $ui= get_userinfo();
1314     // Get list of supported department types
1315     $types = departmentManagement::get_support_departments();
1317     // Load departments allowed by ACL
1318     $validDepartments = $ui->get_module_departments($this->categories);
1320     // Build filter and look in the LDAP for possible sub departments
1321     // of current base
1322     $filter= "(&(objectClass=gosaDepartment)(|";
1323     $attrs= array("description", "objectClass");
1324     foreach($types as $name => $data){
1325       $filter.= "(objectClass=".$data['OC'].")";
1326       $attrs[]= $data['ATTR'];
1327     }
1328     $filter.= "))";
1329     $res= get_list($filter, $this->categories, $this->base, $attrs, GL_NONE);
1331     // Analyze list of departments
1332     foreach ($res as $department) {
1333       if (!in_array($department['dn'], $validDepartments)) {
1334         continue;
1335       }
1337       // Add the attribute where we use for sorting
1338       $oc= null;
1339       foreach(array_keys($types) as $type) {
1340         if (in_array($type, $department['objectClass'])) {
1341           $oc= $type;
1342           break;
1343         }
1344       }
1345       $department['sort-attribute']= $types[$oc]['ATTR'];
1347       // Move to the result list
1348       $departments[]= $department;
1349     }
1351     return $departments;
1352   }
1355   function renderCopyPasteMenu($separator, $copy= true, $cut= true)
1356   {
1357     // We can only provide information if we've got a copypaste handler
1358     // instance
1359     if(!(isset($this->copyPasteHandler) && is_object($this->copyPasteHandler))){
1360       return "";
1361     }
1363     // Presets
1364     $result= "";
1365     $read= $paste= false;
1366     $ui= get_userinfo();
1368     // Switch flags to on if there's at least one category which allows read/paste
1369     foreach($this->categories as $category){
1370       $read= $read || preg_match('/r/', $ui->get_category_permissions($this->base, $category));
1371       $paste= $paste || $ui->is_pasteable($this->base, $category) == 1;
1372     }
1375     // Draw entries that allow copy and cut
1376     if($read){
1378       // Copy entry
1379       if($copy){
1380         $result.= "<li$separator><a href='#' onClick='document.getElementById(\"actionmenu\").value= \"copy\";document.getElementById(\"exec_act\").click();'>".image('images/lists/copy.png')."&nbsp;"._("Copy")."</a></li>";
1381         $separator= "";
1382       }
1384       // Cut entry
1385       if($cut){
1386         $result.= "<li$separator><a href='#' onClick='document.getElementById(\"actionmenu\").value= \"cut\";document.getElementById(\"exec_act\").click();'>".image("images/lists/cut.png")."&nbsp;"._("Cut")."</a></li>";
1387         $separator= "";
1388       }
1389     }
1391     // Draw entries that allow pasting entries
1392     if($paste){
1393       if($this->copyPasteHandler->entries_queued()){
1394         $result.= "<li$separator><a href='#' onClick='document.getElementById(\"actionmenu\").value= \"paste\";document.getElementById(\"exec_act\").click();'>".image("images/lists/paste.png")."&nbsp;"._("Paste")."</a></li>";
1395       }else{
1396         $result.= "<li$separator><a href='#'>".image('images/lists/paste-grey.png')."&nbsp;"._("Paste")."</a></li>";
1397       }
1398     }
1399     
1400     return($result);
1401   }
1404   function renderCopyPasteActions($row, $dn, $category, $class, $copy= true, $cut= true)
1405   {
1406     // We can only provide information if we've got a copypaste handler
1407     // instance
1408     if(!(isset($this->copyPasteHandler) && is_object($this->copyPasteHandler))){
1409       return "";
1410     }
1412     // Presets
1413     $ui = get_userinfo();
1414     $result = "";
1416     // Render cut entries
1417     if($cut){
1418       if($ui->is_cutable($dn, $category, $class)){
1419         $result.= image('images/lists/cut.png', "listing_cut_$row", _("Cut this entry"));
1420       }else{
1421         $result.= image('images/empty.png');
1422       }
1423     }
1425     // Render copy entries
1426     if($copy){
1427       if($ui->is_copyable($dn, $category, $class)){
1428         $result.= image('images/lists/copy.png', "listing_copy_$row", _("Copy this entry"));
1429       }else{
1430         $result.= image('images/empty.png');
1431       }
1432     }
1434     return($result);
1435   }
1438   function renderSnapshotMenu($separator)
1439   {
1440     // We can only provide information if we've got a snapshot handler
1441     // instance
1442     if(!(isset($this->snapshotHandler) && is_object($this->snapshotHandler))){
1443       return "";
1444     }
1446     // Presets
1447     $result = "";
1448     $ui = get_userinfo();
1450     if($this->snapshotHandler->enabled() && $ui->allow_snapshot_restore($this->base, $this->categories)){
1452       // Check if there is something to restore
1453       $restore= false;
1454       foreach($this->snapshotHandler->getSnapshotBases() as $base){
1455         $restore= $restore || count($this->snapshotHandler->getDeletedSnapshots($base)) > 0;
1456       }
1458       // Draw icons according to the restore flag
1459       if($restore){
1460         $result.= "<li$separator><a href='#' onClick='document.getElementById(\"actionmenu\").value= \"restore\";document.getElementById(\"exec_act\").click();'>".image('images/lists/restore.png')."&nbsp;"._("Restore snapshots")."</a></li>";
1461       }else{
1462         $result.= "<li$separator><a href='#'>".image('images/lists/restore-grey.png')."&nbsp;"._("Restore snapshots")."</a></li>";
1463       }
1464     }
1466     return($result);
1467   }
1470   function renderExporterMenu($separator)
1471   {
1472     // Presets
1473     $result = "";
1475     // Draw entries
1476     $result.= "<li$separator><a href='#'>".image('images/lists/export.png')."&nbsp;"._("Export list")."&nbsp;".image("images/forward-arrow.png")."</a><ul class='level3'>";
1478     // Export CVS as build in exporter
1479     foreach ($this->exporter as $action => $exporter) {
1480       $result.= "<li><a href='#' onClick='document.getElementById(\"actionmenu\").value= \"$action\";document.getElementById(\"exec_act\").click();'>".image($exporter['image'])."&nbsp;".$exporter['label']."</a></li>";
1481     }
1483     // Finalize list
1484     $result.= "</ul></li>";
1486     return($result);
1487   }
1490   function renderSnapshotActions($row, $dn, $category, $class, $copy= true, $cut= true)
1491   {
1492     // We can only provide information if we've got a snapshot handler
1493     // instance
1494     if(!(isset($this->snapshotHandler) && is_object($this->snapshotHandler))){
1495       return "";
1496     }
1498     // Presets
1499     $result= "";
1500     $ui = get_userinfo();
1502     // Only act if enabled here
1503     if($this->snapshotHandler->enabled()){
1505       // Draw restore button
1506       if ($ui->allow_snapshot_restore($dn, $category)){
1508         // Do we have snapshots for this dn?
1509         if($this->snapshotHandler->hasSnapshots($dn)){
1510           $result.= image('images/lists/restore.png', "listing_restore_$row", _("Restore snapshot"));
1511         } else {
1512           $result.= image('images/lists/restore-grey.png');
1513         }
1514       }
1516       // Draw snapshot button
1517       if($ui->allow_snapshot_create($dn, $category)){
1518           $result.= image('images/snapshot.png', "listing_snapshot_$row", _("Create a new snapshot from this object"));
1519       }else{
1520           $result.= image('images/empty.png');
1521       }
1522     }
1524     return($result);
1525   }
1528   function renderDaemonMenu($separator)
1529   {
1530     $result= "";
1532     // If there is a daemon registered, draw the menu entries
1533     if(class_available("DaemonEvent")){
1534       $events= DaemonEvent::get_event_types_by_category($this->categories);
1535       if(isset($events['BY_CLASS']) && count($events['BY_CLASS'])){
1536         foreach($events['BY_CLASS'] as $name => $event){
1537           $result.= "<li$separator><a href='#' onClick='document.getElementById(\"actionmenu\").value=\"$name\";document.getElementById(\"exec_act\").click();'>".$event['MenuImage']."&nbsp;".$event['s_Menu_Name']."</a></li>";
1538           $separator= "";
1539         }
1540       }
1541     }
1543     return $result;
1544   }
1547   function getEntry($dn)
1548   {
1549     foreach ($this->entries as $entry) {
1550       if (isset($entry['dn']) && strcasecmp($dn, $entry['dn']) == 0){
1551         return $entry;
1552       }
1553     }
1554     return null;
1555   }
1558   function getEntries()
1559   {
1560     return $this->entries;
1561   }
1564   function getType($dn)
1565   {
1566     if (isset($this->objectDnMapping[$dn])) {
1567       return $this->objectDnMapping[$dn];
1568     }
1569     return null;
1570   }
1574 ?>