Code

Don't handle "dn" as attribute
[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 $module;
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 $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;
57   function listing($filename)
58   {
59     global $config;
60     global $class_mapping;
62     // Initialize pid
63     $this->pid= preg_replace("/[^0-9]/", "", microtime(TRUE));
65     if (!$this->load($filename)) {
66       die("Cannot parse $filename!");
67     }
69     // Set base for filter
70     if ($this->baseMode) {
71       $this->base= session::global_get("CurrentMainBase");
72       if ($this->base == null) {
73         $this->base= $config->current['BASE'];
74       }
75       $this->refreshBasesList();
76     } else {
77       $this->base= $config->current['BASE'];
78     }
80     // Move footer information
81     $this->showFooter= ($config->get_cfg_value("listSummary") == "true");
83     // Register build in filters
84     $this->registerElementFilter("objectType", "listing::filterObjectType");
85     $this->registerElementFilter("departmentLink", "listing::filterDepartmentLink");
86     $this->registerElementFilter("link", "listing::filterLink");
87     $this->registerElementFilter("actions", "listing::filterActions");
89     // Load exporters
90     foreach($class_mapping as $class => $dummy) {
91       if (preg_match('/Exporter$/', $class)) {
92         $info= call_user_func(array($class, "getInfo"));
93         if ($info != null) {
94           $this->exporter= array_merge($this->exporter, $info);
95         }
96       }
97     }
98   }
101   function setCopyPasteHandler($handler)
102   {
103     $this->copyPasteHandler= &$handler;
104   }
107   function setHeight($height)
108   {
109     $this->height= $height;
110   }
113   function setSnapshotHandler($handler)
114   {
115     $this->snapshotHandler= &$handler;
116   }
119   function setFilter($filter)
120   {
121     $this->filter= &$filter;
122     if ($this->departmentBrowser){
123       $this->departments= $this->getDepartments();
124     }
125     $this->filter->setBase($this->base);
126   }
129   function registerElementFilter($name, $call)
130   {
131     if (!isset($this->filters[$name])) {
132       $this->filters[$name]= $call;
133       return true;
134     }
136     return false;
137   }
140   function load($filename)
141   {
142     $contents = file_get_contents($filename);
143     $this->xmlData= xml::xml2array($contents, 1);
145     if (!isset($this->xmlData['list'])) {
146       return false;
147     }
149     $this->xmlData= $this->xmlData["list"];
151     // Load some definition values
152     foreach (array("departmentBrowser", "departmentRootVisible", "multiSelect", "baseMode") as $token) {
153       if (isset($this->xmlData['definition'][$token]) &&
154           $this->xmlData['definition'][$token] == "true"){
155         $this->$token= true;
156       }
157     }
159     // Fill objectTypes from departments and xml definition
160     $types = departmentManagement::get_support_departments();
161     foreach ($types as $class => $data) {
162       $this->objectTypes[]= array("label" => $data['TITLE'],
163                                   "objectClass" => $data['OC'],
164                                   "image" => $data['IMG']);
165     }
166     $this->categories= array();
167     if (isset($this->xmlData['definition']['objectType'])) {
168       if(isset($this->xmlData['definition']['objectType']['label'])) {
169         $this->xmlData['definition']['objectType']= array($this->xmlData['definition']['objectType']);
170       }
171       foreach ($this->xmlData['definition']['objectType'] as $index => $otype) {
172         $this->objectTypes[]= $this->xmlData['definition']['objectType'][$index];
173         if (isset($this->xmlData['definition']['objectType'][$index]['category'])){
174           $this->categories[]= $this->xmlData['definition']['objectType'][$index]['category'];
175         }
176       }
177     }
179     // Parse layout per column
180     $this->colprops= $this->parseLayout($this->xmlData['table']['layout']);
182     // Prepare table headers
183     $this->renderHeader();
185     // Assign headline/module
186     $this->headline= _($this->xmlData['definition']['label']);
187     $this->module= $this->xmlData['definition']['module'];
188     if (!is_array($this->categories)){
189       $this->categories= array($this->categories);
190     }
192     // Evaluate columns to be exported
193     if (isset($this->xmlData['table']['column'])){
194       foreach ($this->xmlData['table']['column'] as $index => $config) {
195         if (isset($config['export']) && $config['export'] == "true"){
196           $this->exportColumns[]= $index;
197         }
198       }
199     }
201     return true;  
202   }
205   function renderHeader()
206   {
207     $this->header= array();
208     $this->plainHeader= array();
210     // Initialize sort?
211     $sortInit= false;
212     if (!$this->sortDirection) {
213       $this->sortColumn= 0;
214       if (isset($this->xmlData['definition']['defaultSortColumn'])){
215         $this->sortColumn= $this->xmlData['definition']['defaultSortColumn'];
216       } else {
217         $this->sortAttribute= "";
218       }
219       $this->sortDirection= array();
220       $sortInit= true;
221     }
223     if (isset($this->xmlData['table']['column'])){
224       foreach ($this->xmlData['table']['column'] as $index => $config) {
225         // Initialize everything to one direction
226         if ($sortInit) {
227           $this->sortDirection[$index]= false;
228         }
230         $sorter= "";
231         if ($index == $this->sortColumn && isset($config['sortAttribute']) &&
232             isset($config['sortType'])) {
233           $this->sortAttribute= $config['sortAttribute'];
234           $this->sortType= $config['sortType'];
235           $sorter= "&nbsp;<img border='0' title='".($this->sortDirection[$index]?_("Up"):_("Down"))."' src='images/lists/sort-".($this->sortDirection[$index]?"up":"down").".png' align='top'>";
236         }
237         $sortable= (isset($config['sortAttribute']));
239         $link= "href='?plug=".$_GET['plug']."&amp;PID=".$this->pid."&amp;act=SORT_$index'";
240         if (isset($config['label'])) {
241           if ($sortable) {
242             $this->header[$index]= "<td class='listheader' ".$this->colprops[$index]."><a $link>"._($config['label'])."$sorter</a></td>";
243           } else {
244             $this->header[$index]= "<td class='listheader' ".$this->colprops[$index].">"._($config['label'])."</td>";
245           }
246           $this->plainHeader[]= _($config['label']);
247         } else {
248           if ($sortable) {
249             $this->header[$index]= "<td class='listheader' ".$this->colprops[$index]."><a $link>&nbsp;$sorter</a></td>";
250           } else {
251             $this->header[$index]= "<td class='listheader' ".$this->colprops[$index].">&nbsp;</td>";
252           }
253           $this->plainHeader[]= "";
254         }
255       }
256     }
257   }
260   function render()
261   {
262     // Check for exeeded sizelimit
263     if (($message= check_sizelimit()) != ""){
264       return($message);
265     }
267     // Some browsers don't have the ability do do scrollable table bodies, filter them
268     // here.
269     $switch= false;
270     if (preg_match('/(Opera|Konqueror|Safari|msie)/i', $_SERVER['HTTP_USER_AGENT'])){
271       $switch= true;
272     }
274     // Initialize list
275     $result= "<input type='hidden' value='$this->pid' name='PID'>\n";
276     $height= 450;
277     if ($this->height != 0) {
278       $result.= "<input type='hidden' value='$this->height' id='d_height'>\n";
279       $height= $this->height;
280     }
281     
282     $result.= "<table cellpadding='0' cellspacing='0' border='0'><tr><td><div class='listContainer' id='d_scrollbody' style='border-top:1px solid #B0B0B0;width:700px;min-height:".($height+25)."px;'>\n";
284     $height= "";
285     if ($switch){
286       $height= "height:100%;";
287     }
288     $result.= "<table summary='$this->headline' style='${height}width:100%; table-layout:fixed;' cellspacing='0' cellpadding='0' id='t_scrolltable'>\n";
289     $this->numColumns= count($this->colprops) + ($this->multiSelect?1:0);
291     // Build list header
292     $result.= "<thead class='fixedListHeader listHeaderFormat'><tr>\n";
293     if ($this->multiSelect) {
294       $width= "24px";
295       if (preg_match('/Konqueror/i', $_SERVER['HTTP_USER_AGENT'])){
296         $width= "28px";
297       }
298       $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";
299     }
300     foreach ($this->header as $header) {
301       $result.= $header;
302     }
303     $result.= "</tr></thead>\n";
305     // Build list body
306     $result.= "<tbody class='listScrollContent listBodyFormat' id='t_nscrollbody' style='height:".$height."px;'>\n";
308     // No results? Just take an empty colspanned row
309     if (count($this->entries) + count($this->departments) == 0) {
310       $result.= "<tr class='rowxp0'><td class='list1nohighlight' colspan='$this->numColumns' style='height:100%;border-right:0px;width:100%;'>&nbsp;</td></tr>";
311     }
313     // Line color alternation
314     $alt= 0;
315     $deps= 0;
317     // Draw department browser if configured and we're not in sub mode
318     $this->useSpan= false;
319     if ($this->departmentBrowser && $this->filter->scope != "sub") {
320       // Fill with department browser if configured this way
321       $departmentIterator= new departmentSortIterator($this->departments, $this->sortDirection[$this->sortColumn]);
322       foreach ($departmentIterator as $row => $entry){
323         $result.="<tr class='rowxp".($alt&1)."'>";
325         // Render multi select if needed
326         if ($this->multiSelect) {
327           $result.="<td style='text-align:center;padding:0;' class='list1'>&nbsp;</td>";
328         }
330         // Render defined department columns, fill the rest with some stuff
331         $rest= $this->numColumns - 1;
332         foreach ($this->xmlData['table']['department'] as $index => $config) {
333           $colspan= 1;
334           if (isset($config['span'])){
335             $colspan= $config['span'];
336             $this->useSpan= true;
337           }
338           $result.="<td colspan='$colspan' ".$this->colprops[$index]." class='list1'>".$this->renderCell($config['value'], $entry, $row)."</td>";
339           $rest-= $colspan;
340         }
342         // Fill remaining cols with nothing
343         $last= $this->numColumns - $rest;
344         for ($i= 0; $i<$rest; $i++){
345           $result.= "<td ".$this->colprops[$last+$i-1]." class='list1'>&nbsp;</td>";
346         }
347         $result.="</tr>";
349         $alt++;
350       }
351       $deps= $alt;
352     }
354     // Fill with contents, sort as configured
355     foreach ($this->entries as $row => $entry) {
356       $trow= "";
358       // Render multi select if needed
359       if ($this->multiSelect) {
360         $trow.="<td style='text-align:center;width:20px;' class='list0'><input type='checkbox' id='listing_selected_$row' name='listing_selected_$row'></td>\n";
361       }
363       foreach ($this->xmlData['table']['column'] as $index => $config) {
364         $renderedCell= $this->renderCell($config['value'], $entry, $row);
365         $trow.="<td ".$this->colprops[$index]." class='list0'>".$renderedCell."</td>\n";
367         // Save rendered column
368         $sort= preg_replace('/.*>([^<]+)<.*$/', '$1', $renderedCell);
369         $sort= preg_replace('/&nbsp;/', '', $sort);
370         if (preg_match('/</', $sort)){
371           $sort= "";
372         }
373         $this->entries[$row]["_sort$index"]= $sort;
374       }
376       // Save rendered entry
377       $this->entries[$row]['_rendered']= $trow;
378     }
380     // Complete list by sorting entries for _sort$index and appending them to the output
381     $entryIterator= new listingSortIterator($this->entries, $this->sortDirection[$this->sortColumn], "_sort".$this->sortColumn, $this->sortType);
382     foreach ($entryIterator as $row => $entry){
383       $alt++;
384       $result.="<tr class='rowxp".($alt&1)."'>\n";
385       $result.= $entry['_rendered'];
386       $result.="</tr>\n";
387     }
389     // Need to fill the list if it's not full (nobody knows why this is 22 ;-))
390     $emptyListStyle= (count($this->entries) + (($this->useSpan && count($this->entries))?$deps:0) == 0)?"border:0;":"";
391     if ((count($this->entries) + $deps) < 22) {
392       $result.= "<tr>";
393       for ($i= 0; $i<$this->numColumns; $i++) {
394         if ($i == 0) {
395           $result.= "<td class='list1nohighlight' style='$emptyListStyle height:100%;'>&nbsp;</td>";
396           continue;
397         }
398         if ($i != $this->numColumns-1) {
399           $result.= "<td class='list1nohighlight' style='$emptyListStyle'>&nbsp;</td>";
400         } else {
401           $result.= "<td class='list1nohighlight' style='border-right:1px solid #AAA;$emptyListStyle'>&nbsp;</td>";
402         }
403       }
404       $result.= "</tr>";
405     }
407     // Close list body
408     $result.= "</tbody></table></div></td></tr>";
410     // Add the footer if requested
411     if ($this->showFooter) {
412       $result.= "<tr><td class='nlistFooter'>";
414       foreach ($this->objectTypes as $objectType) {
415         if (isset($this->objectTypeCount[$objectType['label']])) {
416           $label= _($objectType['label']);
417           $result.= "<img class='center' src='".$objectType['image']."' title='$label' alt='$label'>&nbsp;".$this->objectTypeCount[$objectType['label']]."&nbsp;&nbsp;&nbsp;&nbsp;";
418         }
419       }
421       $result.= "</td></tr>";
422     }
424     // Close list
425     $result.= "</table>";
426     $result.= $switch?"<input type='hidden' id='list_workaround'>":"";
428     $smarty= get_smarty();
429     $smarty->assign("usePrototype", "true");
430     $smarty->assign("FILTER", $this->filter->render());
431     $smarty->assign("SIZELIMIT", print_sizelimit_warning());
432     $smarty->assign("LIST", $result);
434     // Assign navigation elements
435     $nav= $this->renderNavigation();
436     foreach ($nav as $key => $html) {
437       $smarty->assign($key, $html);
438     }
440     // Assign action menu / base
441     $smarty->assign("ACTIONS", $this->renderActionMenu());
442     $smarty->assign("BASE", $this->renderBase());
444     // Assign separator
445     $smarty->assign("SEPARATOR", "<img src='images/lists/seperator.png' alt='-' align='middle' height='16' width='1' class='center'>");
447     // Assign summary
448     $smarty->assign("HEADLINE", $this->headline);
450     return ($smarty->fetch(get_template_path($this->xmlData['definition']['template'], true)));
451   }
454   function update()
455   {
456     global $config;
457     $ui= get_userinfo();
459     // Reset object counter / DN mapping
460     $this->objectTypeCount= array();
461     $this->objectDnMapping= array();
463     // Do not do anything if this is not our PID
464     if(isset($_REQUEST['PID']) && $_REQUEST['PID'] != $this->pid) {
465       return;
466     }
468     // Save base
469     if (isset($_POST['BASE']) && $this->baseMode) {
470       $base= get_post('BASE');
471       if (isset($this->bases[$base])) {
472         $this->base= $base;
473         session::global_set("CurrentMainBase", $this->base);
474       }
475     }
477     // Override the base if we got a message from the browser navigation
478     if ($this->departmentBrowser && isset($_GET['act'])) {
479       if (preg_match('/^department_([0-9]+)$/', validate($_GET['act']), $match)){
480         if (isset($this->departments[$match[1]])){
481           $this->base= $this->departments[$match[1]]['dn'];
482           session::global_set("CurrentMainBase", $this->base);
483         }
484       }
485     }
487     // Filter POST with "act" attributes -> posted from action menu
488     if (isset($_POST['exec_act']) && $_POST['act'] != '') {
489       if (preg_match('/^export.*$/', $_POST['act']) && isset($this->exporter[$_POST['act']])) {
490         $exporter= $this->exporter[$_POST['act']];
491         $userinfo= ", "._("created by")." ".$ui->cn." - ".strftime('%A, %d. %B %Y, %H:%M:%S');
492         $entryIterator= new listingSortIterator($this->entries, $this->sortDirection[$this->sortColumn], "_sort".$this->sortColumn, $this->sortType);
493         $sortedEntries= array();
494         foreach ($entryIterator as $entry){
495           $sortedEntries[]= $entry;
496         }
497         $instance= new $exporter['class']($this->headline.$userinfo, $this->plainHeader, $sortedEntries, $this->exportColumns);
498         $type= call_user_func(array($exporter['class'], "getInfo"));
499         $type= $type[$_POST['act']];
500         send_binary_content($instance->query(), $type['filename'], $type= $type['mime']);
501       }
502     }
504     // Filter GET with "act" attributes
505     if (isset($_GET['act'])) {
506       $key= validate($_GET['act']);
507       if (preg_match('/^SORT_([0-9]+)$/', $key, $match)) {
508         // Switch to new column or invert search order?
509         $column= $match[1];
510         if ($this->sortColumn != $column) {
511           $this->sortColumn= $column;
512         } else {
513           $this->sortDirection[$column]= !$this->sortDirection[$column];
514         }
516         // Allow header to update itself according to the new sort settings
517         $this->renderHeader();
518       }
519     }
521     // Override base if we got signals from the navigation elements
522     $action= "";
523     foreach ($_POST as $key => $value) {
524       if (preg_match('/^(ROOT|BACK|HOME)_x$/', $key, $match)) {
525         $action= $match[1];
526         break;
527       }
528     }
530     // Navigation handling
531     if ($action == 'ROOT') {
532       $deps= $ui->get_module_departments($this->module);
533       $this->base= $deps[0];
534     }
535     if ($action == 'BACK') {
536       $deps= $ui->get_module_departments($this->module);
537       $base= preg_replace("/^[^,]+,/", "", $this->base);
538       if(in_array_ics($base, $deps)){
539         $this->base= $base;
540       }
541     }
542     if ($action == 'HOME') {
543       $ui= get_userinfo();
544       $this->base= $this->filter->getObjectBase($ui->dn);
545     }
547     // Reload departments
548     if ($this->departmentBrowser){
549       $this->departments= $this->getDepartments();
550     }
552     // Update filter and refresh entries
553     $this->filter->setBase($this->base);
554     $this->entries= $this->filter->query();
555   }
558   function setBase($base)
559   {
560     $this->base= $base;
561   }
564   function getBase()
565   {
566     return $this->base;
567   }
570   function parseLayout($layout)
571   {
572     $result= array();
573     $layout= preg_replace("/^\|/", "", $layout);
574     $layout= preg_replace("/\|$/", "", $layout);
575     $cols= split("\|", $layout);
577     foreach ($cols as $index => $config) {
578       if ($config != "") {
579         $res= "";
580         $components= split(';', $config);
581         foreach ($components as $part) {
582           if (preg_match("/^r$/", $part)) {
583             $res.= "text-align:right;";
584             continue;
585           }
586           if (preg_match("/^l$/", $part)) {
587             $res.= "text-align:left;";
588             continue;
589           }
590           if (preg_match("/^c$/", $part)) {
591             $res.= "text-align:center;";
592             continue;
593           }
594           if (preg_match("/^[0-9]+(|px|%)$/", $part)) {
595             $res.= "width:$part;min-width:$part;";
596             continue;
597           }
598         }
600         // Add minimum width for scalable columns
601         if (!preg_match('/width:/', $res)){
602           $res.= "min-width:200px;";
603         }
605         $result[$index]= " style='$res' ";
606       } else {
607         $result[$index]= " style='min-width:100px'";
608       }
609     }
611     // Save number of columns for later use
612     $this->numColumns= count($cols);
614     return $result;
615   }
618   function renderCell($data, $config, $row)
619   {
620     // Replace flat attributes in data string
621     for ($i= 0; $i<$config['count']; $i++) {
622       $attr= $config[$i];
623       $value= "";
624       if (is_array($config[$attr])) {
625         $value= $config[$attr][0];
626       } else {
627         $value= $config[$attr];
628       }
629       $data= preg_replace("/%\{$attr\}/", $value, $data);
630     }
632     // Watch out for filters and prepare to execute them
633     $data= $this->processElementFilter($data, $config, $row);
635     // Replace all non replaced %{...} instances because they
636     // are non resolved attributes or filters
637     $data= preg_replace('/%{[^}]+}/', '&nbsp;', $data);
639     return $data;
640   }
643   function renderBase()
644   {
645     if (!$this->baseMode) {
646       return;
647     }
649     $result= "<select name='BASE' onChange='mainform.submit()' size='1'>";
650     $firstDN= null;
651     $found= false;
653     foreach ($this->bases as $key=>$value) {
654       // Keep first entry to fall back eventually
655       if(!$firstDN) {
656         $firstDN= $key;
657       }
659       // Prepare to render entry
660       $selected= "";
661       if ($key == $this->base) {
662         $selected= " selected";
663         $found= true;
664       }
665       $key = htmlentities($key,ENT_QUOTES);
666       $result.= "\n<option value=\"".$key."\"$selected>".$value."</option>";
667     }
669     $result.= "</select>";
671     // Reset the currently used base to the first DN we found if there
672     // was no match.
673     if(!$found){
674       $this->base = $firstDN;
675     }
677     return $result;
678   }
681   function processElementFilter($data, $config, $row)
682   {
683     preg_match_all("/%\{filter:([^(]+)\((.*)\)\}/", $data, $matches, PREG_SET_ORDER);
685     foreach ($matches as $match) {
686       $cl= "";
687       $method= "";
688       if (preg_match('/::/', $match[1])) {
689         $cl= preg_replace('/::.*$/', '', $match[1]);
690         $method= preg_replace('/^.*::/', '', $match[1]);
691       } else {
692         if (!isset($this->filters[$match[1]])) {
693           continue;
694         }
695         $cl= preg_replace('/::.*$/', '', $this->filters[$match[1]]);
696         $method= preg_replace('/^.*::/', '', $this->filters[$match[1]]);
697       }
699       // Prepare params for function call
700       $params= array();
701       preg_match_all('/"[^"]+"|[^,]+/', $match[2], $parts);
702       foreach ($parts[0] as $param) {
704         // Row is replaced by the row number
705         if ($param == "row") {
706           $params[]= $row;
707         }
709         // pid is replaced by the current PID
710         if ($param == "pid") {
711           $params[]= $this->pid;
712         }
714         // base is replaced by the current base
715         if ($param == "base") {
716           $params[]= $this->getBase();
717         }
719         // Fixie with "" is passed directly
720         if (preg_match('/^".*"$/', $param)){
721           $params[]= preg_replace('/"/', '', $param);
722         }
724         // LDAP variables get replaced by their objects
725         for ($i= 0; $i<$config['count']; $i++) {
726           if ($config[$i] == 'dn') {
727             continue;
728           }
729           if ($param == $config[$i]) {
730             $values= $config[$config[$i]];
731             if (is_array($values)){
732               unset($values['count']);
733             }
734             $params[]= $values;
735           }
736         }
738         // Move dn if needed
739         if ($param == "dn") {
740           $params[]= LDAP::fix($config["dn"]);
741         }
742       }
744       // Replace information
745       if ($cl == "listing") {
746         // Non static call - seems to result in errors
747         $data= @preg_replace('/'.preg_quote($match[0]).'/', call_user_func_array(array($this, "$method"), $params), $data);
748       } else {
749         // Static call
750         $data= preg_replace('/'.preg_quote($match[0]).'/', call_user_func_array(array($cl, $method), $params), $data);
751       }
752     }
754     return $data;
755   }
758   function getObjectType($types, $classes)
759   {
760     // Walk thru types and see if there's something matching
761     foreach ($types as $objectType) {
762       $ocs= $objectType['objectClass'];
763       if (!is_array($ocs)){
764         $ocs= array($ocs);
765       }
767       $found= true;
768       foreach ($ocs as $oc){
769         if (preg_match('/^!(.*)$/', $oc, $match)) {
770           $oc= $match[1];
771           if (in_array($oc, $classes)) {
772             $found= false;
773           }
774         } else {
775           if (!in_array($oc, $classes)) {
776             $found= false;
777           }
778         }
779       }
781       if ($found) {
782         return $objectType;
783       }
784     }
786     return null;
787   }
790   function filterObjectType($dn, $classes)
791   {
792     // Walk thru classes and return on first match
793     $result= "&nbsp;";
795     $objectType= $this->getObjectType($this->objectTypes, $classes);
796     if ($objectType) {
797       $this->objectDnMapping[$dn]= $objectType["objectClass"];
798       $result= "<img class='center' title='".LDAP::fix($dn)."' src='".$objectType["image"]."'>";
799       if (!isset($this->objectTypeCount[$objectType['label']])) {
800         $this->objectTypeCount[$objectType['label']]= 0;
801       }
802       $this->objectTypeCount[$objectType['label']]++;
803     }
805     return $result;
806   }
809   function filterActions($dn, $row, $classes)
810   {
811     // Do nothing if there's no menu defined
812     if (!isset($this->xmlData['actiontriggers']['action'])) {
813       return "&nbsp;";
814     }
816     // Go thru all actions
817     $result= "";
818     $actions= $this->xmlData['actiontriggers']['action'];
819     foreach($actions as $action) {
820       // Skip the entry completely if there's no permission to execute it
821       if (!$this->hasActionPermission($action, $dn)) {
822         $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
823         continue;
824       }
826       // Skip entry if the pseudo filter does not fit
827       if (isset($action['filter']) && preg_match('/^[a-z0-9_]+!?=[a-z0-9_]+$/i', $action['filter'])) {
828         list($fa, $fv)= split('=', $action['filter']);
829         if (preg_match('/^(.*)!$/', $fa, $m)){
830           $fa= $m[1];
831           if (isset($this->entries[$row][$fa]) && $this->entries[$row][$fa][0] == $fv) {
832             $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
833             continue;
834           }
835         } else {
836           if (!isset($this->entries[$row][$fa]) && !$this->entries[$row][$fa][0] == $fv) {
837             $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
838             continue;
839           }
840         }
841       }
844       // If there's an objectclass definition and we don't have it
845       // add an empty picture here.
846       if (isset($action['objectclass'])){
847         $objectclass= $action['objectclass'];
848         if (preg_match('/^!(.*)$/', $objectclass, $m)){
849           $objectclass= $m[1];
850           if(in_array($objectclass, $classes)) {
851             $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
852             continue;
853           }
854         } else {
855           if(!in_array($objectclass, $classes)) {
856             $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
857             continue;
858           }
859         }
860       }
862       // Render normal entries as usual
863       if ($action['type'] == "entry") {
864         $label= $this->processElementFilter($action['label'], $this->entries[$row], $row);
865         $image= $this->processElementFilter($action['image'], $this->entries[$row], $row);
866         $result.="<input class='center' type='image' src='$image' title='$label' ".
867                  "name='listing_".$action['name']."_$row' style='padding:1px'>";
868       }
870       // Handle special types
871       if ($action['type'] == "copypaste" || $action['type'] == "snapshot") {
873         $objectType= $this->getObjectType($this->objectTypes, $this->entries[$row]['objectClass']);
874         $category= $class= null;
875         if ($objectType) {
876           $category= $objectType['category'];
877           $class= $objectType['class'];
878         }
880         if ($action['type'] == "copypaste") {
881           $result.= $this->renderCopyPasteActions($row, $this->entries[$row]['dn'], $category, $class);
882         } else {
883           $result.= $this->renderSnapshotActions($row, $this->entries[$row]['dn'], $category, $class);
884         }
885       }
886     }
888     return $result;
889   }
892   function filterDepartmentLink($row, $dn, $description)
893   {
894     $attr= $this->departments[$row]['sort-attribute'];
895     $name= $this->departments[$row][$attr];
896     if (is_array($name)){
897       $name= $name[0];
898     }
899     $result= sprintf("%s [%s]", $name, $description[0]);
900     return("<a href='?plug=".$_GET['plug']."&amp;PID=$this->pid&amp;act=department_$row' title='$dn'>$result</a>");
901   }
904   function filterLink()
905   {
906     $result= "&nbsp;";
908     $row= func_get_arg(0);
909     $pid= $this->pid;
910     $dn= LDAP::fix(func_get_arg(1));
911     $params= array(func_get_arg(2));
913     // Collect sprintf params
914     for ($i = 3;$i < func_num_args();$i++) {
915       $val= func_get_arg($i);
916       if (is_array($val)){
917         $params[]= $val[0];
918         continue;
919       }
920       $params[]= $val;
921     }
923     $result= "&nbsp;";
924     $trans= call_user_func_array("sprintf", $params);
925     if ($trans != "") {
926       return("<a href='?plug=".$_GET['plug']."&amp;PID=$pid&amp;act=listing_edit_$row' title='$dn'>$trans</a>");
927     }
929     return $result;
930   }
933   function renderNavigation()
934   {
935     $result= array();
936     $enableBack = true;
937     $enableRoot = true;
938     $enableHome = true;
940     $ui = get_userinfo();
942     /* Check if base = first available base */
943     $deps = $ui->get_module_departments($this->module);
945     if(!count($deps) || $deps[0] == $this->filter->base){
946       $enableBack = false;
947       $enableRoot = false;
948     }
950     $listhead ="";
952     /* Check if we are in users home  department */
953     if(!count($deps) || $this->filter->base == $this->filter->getObjectBase($ui->dn)){
954       $enableHome = false;
955     }
957     /* Draw root button */
958     if($enableRoot){
959       $result["ROOT"]= "<input class='center' type='image' src='images/lists/root.png' align='middle' ".
960                        "title='"._("Go to root department")."' name='ROOT' alt='"._("Root")."'>";
961     }else{
962       $result["ROOT"]= "<img src='images/lists/root_grey.png' class='center' alt='"._("Root")."'>";
963     }
965     /* Draw back button */
966     if($enableBack){
967       $result["BACK"]= "<input class='center' type='image' align='middle' src='images/lists/back.png' ".
968                        "title='"._("Go up one department")."' alt='"._("Up")."' name='BACK'>";
969     }else{
970       $result["BACK"]= "<img src='images/lists/back_grey.png' class='center' alt='"._("Up")."'>";
971     }
973     /* Draw home button */
974     if($enableHome){
975       $result["HOME"]= "<input class='center' type='image' align='middle' src='images/lists/home.png' ".
976                        "title='"._("Go to users department")."' alt='"._("Home")."' name='HOME'>";
977     }else{
978       $result["HOME"]= "<img src='images/lists/home_grey.png' class='center' alt='"._("Home")."'>";
979     }
981     /* Draw reload button, this button is enabled everytime */
982     $result["RELOAD"]= "<input class='center' type='image' src='images/lists/reload.png' align='middle' ".
983                        "title='"._("Reload list")."' name='REFRESH' alt='"._("Submit")."'>";
985     return ($result);
986   }
989   function getAction()
990   {
991     // Do not do anything if this is not our PID, or there's even no PID available...
992     if(!isset($_REQUEST['PID']) || $_REQUEST['PID'] != $this->pid) {
993       return;
994     }
996     $result= array("targets" => array(), "action" => "");
998     // Filter GET with "act" attributes
999     if (isset($_GET['act'])) {
1000       $key= validate($_GET['act']);
1001       $target= preg_replace('/^listing_[a-zA-Z_]+_([0-9]+)$/', '$1', $key);
1002       if (isset($this->entries[$target]['dn'])) {
1003         $result['action']= preg_replace('/^listing_([a-zA-Z_]+)_[0-9]+$/', '$1', $key);
1004         $result['targets'][]= $this->entries[$target]['dn'];
1005       }
1007       // Drop targets if empty
1008       if (count($result['targets']) == 0) {
1009         unset($result['targets']);
1010       }
1011       return $result;
1012     }
1014     // Filter POST with "listing_" attributes
1015     foreach ($_POST as $key => $prop) {
1017       // Capture selections
1018       if (preg_match('/^listing_selected_[0-9]+$/', $key)) {
1019         $target= preg_replace('/^listing_selected_([0-9]+)$/', '$1', $key);
1020         if (isset($this->entries[$target]['dn'])) {
1021           $result['targets'][]= $this->entries[$target]['dn'];
1022         }
1023         continue;
1024       }
1026       // Capture action with target - this is a one shot
1027       if (preg_match('/^listing_[a-zA-Z_]+_[0-9]+(|_x)$/', $key)) {
1028         $target= preg_replace('/^listing_[a-zA-Z_]+_([0-9]+)(|_x)$/', '$1', $key);
1029         if (isset($this->entries[$target]['dn'])) {
1030           $result['action']= preg_replace('/^listing_([a-zA-Z_]+)_[0-9]+(|_x)$/', '$1', $key);
1031           $result['targets']= array($this->entries[$target]['dn']);
1032         }
1033         break;
1034       }
1036       // Capture action without target
1037       if (preg_match('/^listing_[a-zA-Z_]+(|_x)$/', $key)) {
1038         $result['action']= preg_replace('/^listing_([a-zA-Z_]+)(|_x)$/', '$1', $key);
1039         continue;
1040       }
1041     }
1043     // Filter POST with "act" attributes -> posted from action menu
1044     if (isset($_POST['act']) && $_POST['act'] != '') {
1045       if (!preg_match('/^export.*$/', $_POST['act'])){
1046         $result['action']= validate($_POST['act']);
1047       }
1048     }
1050     // Drop targets if empty
1051     if (count($result['targets']) == 0) {
1052       unset($result['targets']);
1053     }
1054     return $result;
1055   }
1058   function renderActionMenu()
1059   {
1060     // Don't send anything if the menu is not defined
1061     if (!isset($this->xmlData['actionmenu']['action'])){
1062       return "";
1063     }
1065     // Array?
1066     if (isset($this->xmlData['actionmenu']['action']['type'])){
1067       $this->xmlData['actionmenu']['action']= array($this->xmlData['actionmenu']['action']);
1068     }
1070     // Load shortcut
1071     $actions= &$this->xmlData['actionmenu']['action'];
1072     $result= "<input type='hidden' name='act' id='actionmenu' value=''><div style='display:none'><input type='submit' name='exec_act' id='exec_act' value=''></div>".
1073              "<ul class='level1' id='root'><li><a href='#'>"._("Actions")."&nbsp;<img ".
1074              "border=0 class='center' src='images/lists/sort-down.png'></a>";
1076     // Build ul/li list
1077     $result.= $this->recurseActions($actions);
1079     return "<div id='pulldown'>".$result."</li></ul><div>";
1080   }
1083   function recurseActions($actions)
1084   {
1085     global $class_mapping;
1086     static $level= 2;
1087     $result= "<ul class='level$level'>";
1088     $separator= "";
1090     foreach ($actions as $action) {
1092       // Skip the entry completely if there's no permission to execute it
1093       if (!$this->hasActionPermission($action, $this->filter->base)) {
1094         continue;
1095       }
1097       // Skip entry if there're missing dependencies
1098       if (isset($action['depends'])) {
1099         $deps= is_array($action['depends'])?$action['depends']:array($action['depends']);
1100         foreach($deps as $clazz) {
1101           if (!isset($class_mapping[$clazz])){
1102             continue 2;
1103           }
1104         }
1105       }
1107       // Fill image if set
1108       $img= "";
1109       if (isset($action['image'])){
1110         $img= "<img border='0' class='center' src='".$action['image']."'>&nbsp;";
1111       }
1113       if ($action['type'] == "separator"){
1114         $separator= " style='border-top:1px solid #AAA' ";
1115         continue;
1116       }
1118       // Dive into subs
1119       if ($action['type'] == "sub" && isset($action['action'])) {
1120         $level++;
1121         if (isset($action['label'])){
1122           $result.= "<li$separator><a href='#'>$img"._($action['label'])."&nbsp;<img border='0' src='images/forward-arrow.png'></a>";
1123         }
1125         // Ensure we've an array of actions, this enables sub menus with only one action.
1126         if(isset($action['action']['type'])){
1127           $action['action'] = array($action['action']);
1128         }
1130         $result.= $this->recurseActions($action['action'])."</li>";
1131         $level--;
1132         $separator= "";
1133         continue;
1134       }
1136       // Render entry elseways
1137       if (isset($action['label'])){
1138         $result.= "<li$separator><a href='#' onClick='document.getElementById(\"actionmenu\").value= \"".$action['name']."\";mainform.submit();'>$img"._($action['label'])."</a></li>";
1139       }
1141       // Check for special types
1142       switch ($action['type']) {
1143         case 'copypaste':
1144           $result.= $this->renderCopyPasteMenu($separator);
1145           break;
1147         case 'snapshot':
1148           $result.= $this->renderSnapshotMenu($separator);
1149           break;
1151         case 'exporter':
1152           $result.= $this->renderExporterMenu($separator);
1153           break;
1155         case 'daemon':
1156           $result.= $this->renderDaemonMenu($separator);
1157           break;
1158       }
1160       $separator= "";
1161     }
1163     $result.= "</ul>";
1164     return $result;
1165   }
1168   function hasActionPermission($action, $dn)
1169   {
1170     $ui= get_userinfo();
1172     if (isset($action['acl'])) {
1173       $acls= $action['acl'];
1174       if (!is_array($acls)) {
1175         $acls= array($acls);
1176       }
1178       // Every ACL has to pass
1179       foreach ($acls as $acl) {
1180         $module= $this->module;
1181         $aclList= array();
1183         // Split for category and plugins if needed
1184         // match for "[rw]" style entries
1185         if (preg_match('/^\[([rwcdm]+)\]$/', $acl, $match)){
1186           $aclList= array($match[1]);
1187         }
1189         // match for "users[rw]" style entries
1190         if (preg_match('/^([a-zA-Z0-9]+)\[([rwcdm]+)\]$/', $acl, $match)){
1191           $module= $match[1];
1192           $aclList= array($match[2]);
1193         }
1195         // match for "users/user[rw]" style entries
1196         if (preg_match('/^([a-zA-Z0-9]+\/[a-zA-Z0-9]+)\[([rwcdm]+)\]$/', $acl, $match)){
1197           $module= $match[1];
1198           $aclList= array($match[2]);
1199         }
1201         // match "users/user[userPassword:rw(,...)*]" style entries
1202         if (preg_match('/^([a-zA-Z0-9]+\/[a-zA-Z0-9]+)\[([a-zA-Z0-9]+:[rwcdm]+(,[a-zA-Z0-9]+:[rwcdm]+)*)\]$/', $acl, $match)){
1203           $module= $match[1];
1204           $aclList= split(',', $match[2]);
1205         }
1207         // Walk thru prepared ACL by using $module
1208         foreach($aclList as $sAcl) {
1209           $checkAcl= "";
1211           // Category or detailed permission?
1212           if (strpos('/', $module) === false) {
1213             if (preg_match('/([a-zA-Z0-9]+):([rwcdm]+)/', $sAcl, $m) ) {
1214               $checkAcl= $ui->get_permissions($dn, $module, $m[1]);
1215               $sAcl= $m[2];
1216             } else {
1217               $checkAcl= $ui->get_permissions($dn, $module, '0');
1218             }
1219           } else {
1220             $checkAcl= $ui->get_category_permissions($dn, $module);
1221           }
1223           // Split up remaining part of the acl and check if it we're
1224           // allowed to do something...
1225           $parts= str_split($sAcl);
1226           foreach ($parts as $part) {
1227             if (strpos($checkAcl, $part) === false){
1228               return false;
1229             }
1230           }
1232         }
1233       }
1234     }
1236     return true;
1237   }
1240   function refreshBasesList()
1241   {
1242     global $config;
1243     $ui= get_userinfo();
1245     // Do some array munching to get it user friendly
1246     $ids= $config->idepartments;
1247     $d= $ui->get_module_departments($this->module);
1248     $k_ids= array_keys($ids);
1249     $deps= array_intersect($d,$k_ids);
1251     // Fill internal bases list
1252     $this->bases= array();
1253     foreach($k_ids as $department){
1254       $this->bases[$department] = $ids[$department];
1255     }
1256   }
1259   function getDepartments()
1260   {
1261     $departments= array();
1262     $ui= get_userinfo();
1264     // Get list of supported department types
1265     $types = departmentManagement::get_support_departments();
1267     // Load departments allowed by ACL
1268     $validDepartments = $ui->get_module_departments($this->module);
1270     // Build filter and look in the LDAP for possible sub departments
1271     // of current base
1272     $filter= "(&(objectClass=gosaDepartment)(|";
1273     $attrs= array("description", "objectClass");
1274     foreach($types as $name => $data){
1275       $filter.= "(objectClass=".$data['OC'].")";
1276       $attrs[]= $data['ATTR'];
1277     }
1278     $filter.= "))";
1279     $res= get_list($filter, $this->module, $this->base, $attrs, GL_NONE);
1281     // Analyze list of departments
1282     foreach ($res as $department) {
1283       if (!in_array($department['dn'], $validDepartments)) {
1284         continue;
1285       }
1287       // Add the attribute where we use for sorting
1288       $oc= null;
1289       foreach(array_keys($types) as $type) {
1290         if (in_array($type, $department['objectClass'])) {
1291           $oc= $type;
1292           break;
1293         }
1294       }
1295       $department['sort-attribute']= $types[$oc]['ATTR'];
1297       // Move to the result list
1298       $departments[]= $department;
1299     }
1301     return $departments;
1302   }
1305   function renderCopyPasteMenu($separator, $copy= true, $cut= true)
1306   {
1307     // We can only provide information if we've got a copypaste handler
1308     // instance
1309     if(!(isset($this->copyPasteHandler) && is_object($this->copyPasteHandler))){
1310       return "";
1311     }
1313     // Presets
1314     $result= "";
1315     $read= $paste= false;
1316     $ui= get_userinfo();
1318     // Switch flags to on if there's at least one category which allows read/paste
1319     foreach($this->categories as $category){
1320       $read= $read || preg_match('/r/', $ui->get_category_permissions($this->base, $category));
1321       $paste= $paste || $ui->is_pasteable($this->base, $category) == 1;
1322     }
1325     // Draw entries that allow copy and cut
1326     if($read){
1328       // Copy entry
1329       if($copy){
1330         $result.= "<li$separator><a href='#' onClick='document.getElementById(\"actionmenu\").value= \"copy\";document.getElementById(\"exec_act\").click();'><img src='images/lists/copy.png' alt='' border='0' class='center'>&nbsp;"._("Copy")."</a></li>";
1331         $separator= "";
1332       }
1334       // Cut entry
1335       if($cut){
1336         $result.= "<li$separator><a href='#' onClick='document.getElementById(\"actionmenu\").value= \"cut\";document.getElementById(\"exec_act\").click();'><img src='images/lists/cut.png' alt='' border='0' class='center'>&nbsp;"._("Cut")."</a></li>";
1337         $separator= "";
1338       }
1339     }
1341     // Draw entries that allow pasting entries
1342     if($paste){
1343       if($this->copyPasteHandler->entries_queued()){
1344         $result.= "<li$separator><a href='#' onClick='document.getElementById(\"actionmenu\").value= \"paste\";document.getElementById(\"exec_act\").click();'><img src='images/lists/paste.png' alt='' border='0' class='center'>&nbsp;"._("Paste")."</a></li>";
1345       }else{
1346         $result.= "<li$separator><a href='#'><img src='images/lists/paste-grey.png' alt='' border='0' class='center'>&nbsp;"._("Paste")."</a></li>";
1347       }
1348     }
1349     
1350     return($result);
1351   }
1354   function renderCopyPasteActions($row, $dn, $category, $class, $copy= true, $cut= true)
1355   {
1356     // We can only provide information if we've got a copypaste handler
1357     // instance
1358     if(!(isset($this->copyPasteHandler) && is_object($this->copyPasteHandler))){
1359       return "";
1360     }
1362     // Presets
1363     $ui = get_userinfo();
1364     $result = "";
1366     // Render cut entries
1367     if($cut){
1368       if($ui->is_cutable($dn, $category, $class)){
1369         $result .= "<input class='center' type='image'
1370           src='images/lists/cut.png' alt='"._("Cut")."' name='listing_cut_$row' title='"._("Cut this entry")."' style='padding:1px'>";
1371       }else{
1372         $result.="<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
1373       }
1374     }
1376     // Render copy entries
1377     if($copy){
1378       if($ui->is_copyable($dn, $category, $class)){
1379         $result.= "<input class='center' type='image'
1380           src='images/lists/copy.png' alt='"._("Copy")."' name='listing_copy_$row' title='"._("Copy this entry")."' style='padding:1px'>";
1381       }else{
1382         $result.="<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
1383       }
1384     }
1386     return($result);
1387   }
1390   function renderSnapshotMenu($separator)
1391   {
1392     // We can only provide information if we've got a snapshot handler
1393     // instance
1394     if(!(isset($this->snapshotHandler) && is_object($this->snapshotHandler))){
1395       return "";
1396     }
1398     // Presets
1399     $result = "";
1400     $ui = get_userinfo();
1402     if($this->snapshotHandler->enabled() && $ui->allow_snapshot_restore($this->base, $this->module)){
1404       // Check if there is something to restore
1405       $restore= false;
1406       foreach($this->snapshotHandler->getSnapshotBases() as $base){
1407         $restore= $restore || count($this->snapshotHandler->getDeletedSnapshots($base)) > 0;
1408       }
1410       // Draw icons according to the restore flag
1411       if($restore){
1412         $result.= "<li$separator><a href='#' onClick='document.getElementById(\"actionmenu\").value= \"restore\";document.getElementById(\"exec_act\").click();'><img src='images/lists/restore.png' alt='' border='0' class='center'>&nbsp;"._("Restore snapshots")."</a></li>";
1413       }else{
1414         $result.= "<li$separator><a href='#'><img src='images/lists/restore_grey.png' alt='' border='0' class='center'>&nbsp;"._("Restore snapshots")."</a></li>";
1415       }
1416     }
1418     return($result);
1419   }
1422   function renderExporterMenu($separator)
1423   {
1424     // Presets
1425     $result = "";
1427     // Draw entries
1428     $result.= "<li$separator><a href='#'><img border='0' class='center' src='images/lists/export.png'>&nbsp;"._("Export list")."&nbsp;<img border='0' src='images/forward-arrow.png'></a><ul class='level3'>";
1430     // Export CVS as build in exporter
1431     foreach ($this->exporter as $action => $exporter) {
1432       $result.= "<li><a href='#' onClick='document.getElementById(\"actionmenu\").value= \"$action\";document.getElementById(\"exec_act\").click();'><img border='0' class='center' src='".$exporter['image']."'>&nbsp;".$exporter['label']."</a></li>";
1433     }
1435     // Finalize list
1436     $result.= "</ul></li>";
1438     return($result);
1439   }
1442   function renderSnapshotActions($row, $dn, $category, $class, $copy= true, $cut= true)
1443   {
1444     // We can only provide information if we've got a snapshot handler
1445     // instance
1446     if(!(isset($this->snapshotHandler) && is_object($this->snapshotHandler))){
1447       return "";
1448     }
1450     // Presets
1451     $result= "";
1452     $ui = get_userinfo();
1454     // Only act if enabled here
1455     if($this->snapshotHandler->enabled()){
1457       // Draw restore button
1458       if ($ui->allow_snapshot_restore($dn, $category)){
1460         // Do we have snapshots for this dn?
1461         if($this->snapshotHandler->hasSnapshots($dn)){
1462           $result.= "<input class='center' type='image' src='images/lists/restore.png' ".
1463                      "alt='"._("Restore snapshot")."' name='listing_restore_$row' title='".
1464                      _("Restore snapshot")."' style='padding:1px'>";
1465         } else {
1466           $result.= "<img src='images/lists/restore_grey.png' alt=' ' class='center' style='padding:1px'>";
1467         }
1468       }
1470       // Draw snapshot button
1471       if($ui->allow_snapshot_create($dn, $category)){
1472           $result.= "<input class='center' type='image' src='images/snapshot.png' ".
1473                      "alt='"._("Create snapshot")."' name='listing_snapshot_$row' title='".
1474                      _("Create a new snapshot from this object")."' style='padding:1px'>";
1475       }else{
1476           $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
1477       }
1478     }
1480     return($result);
1481   }
1484   function renderDaemonMenu($separator)
1485   {
1486     $result= "";
1488     // If there is a daemon registered, draw the menu entries
1489     if(class_available("DaemonEvent")){
1490       $events= DaemonEvent::get_event_types_by_category($this->categories);
1491       if(isset($events['BY_CLASS']) && count($events['BY_CLASS'])){
1492         foreach($events['BY_CLASS'] as $name => $event){
1493           $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>";
1494           $separator= "";
1495         }
1496       }
1497     }
1499     return $result;
1500   }
1503   function getType($dn)
1504   {
1505     if (isset($this->objectDnMapping[$dn])) {
1506       return $this->objectDnMapping[$dn];
1507     }
1508     return null;
1509   }
1513 ?>