Code

Updated listing class
[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   }
259   function render()
260   {
261     // Check for exeeded sizelimit
262     if (($message= check_sizelimit()) != ""){
263       return($message);
264     }
266     // Initialize list
267     $result= "<input type='hidden' value='$this->pid' name='PID'>\n";
268     $height= 450;
269     if ($this->height != 0) {
270       $result.= "<input type='hidden' value='$this->height' id='d_height'>\n";
271       $height= $this->height;
272     }
273     
274     $result.= "<div class='contentboxb' id='listing_container' style='border-top:1px solid #B0B0B0;'>\n";
275     $result.= "<table summary='$this->headline' style='width:600px;height:".$height."px;' cellspacing='0' id='t_scrolltable'>
276 <tr><td class='scrollhead'><table summary='' style='width:100%;' cellspacing='0' id='t_scrollhead'>\n";
277     $this->numColumns= count($this->colprops) + ($this->multiSelect?1:0);
279     // Build list header
280     $result.= "<tr>\n";
281     if ($this->multiSelect) {
282       $result.= "<td class='listheader' style='width:20px;'><input type='checkbox' id='select_all' name='select_all' title='"._("Select all")."' onClick='toggle_all_(\"listing_selected_[0-9]*$\",\"select_all\");' ></td>\n";
283     }
284     foreach ($this->header as $header) {
285       $result.= $header;
286     }
288     // Add 13px for scroller
289     $result.= "<td class='listheader' style='width:13px;border-right:0px;'>&nbsp;</td></table></td></tr>\n";
291     // New table for the real list contents
292     $result.= "<tr><td colspan='$this->numColumns' class='scrollbody'><div style='width:600px;height:".($height-20)."px;' id='d_scrollbody' class='scrollbody'><table summary='' style='height:100%;width:581px;table-layout:fixed;overflow:hidden;word-wrap:break-word;' cellspacing='0' id='t_scrollbody'>\n";
294     // No results? Just take an empty colspanned row
295     if (count($this->entries) + count($this->departments) == 0) {
296       $result.= "<tr class='rowxp0'><td class='list1nohighlight' colspan='$this->numColumns' style='height:100%;border-right:0px;width:100%;'>&nbsp;</td></tr>";
297     }
299     // Line color alternation
300     $alt= 0;
301     $deps= 0;
303     // Draw department browser if configured and we're not in sub mode
304     $this->useSpan= false;
305     if ($this->departmentBrowser && $this->filter->scope != "sub") {
306       // Fill with department browser if configured this way
307       $departmentIterator= new departmentSortIterator($this->departments, $this->sortDirection[$this->sortColumn]);
308       foreach ($departmentIterator as $row => $entry){
309         $result.="<tr class='rowxp".($alt&1)."'>";
311         // Render multi select if needed
312         if ($this->multiSelect) {
313           $result.="<td style='text-align:center;width:20px;' class='list1'>&nbsp;</td>";
314         }
316         // Render defined department columns, fill the rest with some stuff
317         $rest= $this->numColumns - 1;
318         foreach ($this->xmlData['table']['department'] as $index => $config) {
319           $colspan= 1;
320           if (isset($config['span'])){
321             $colspan= $config['span'];
322             $this->useSpan= true;
323           }
324           $result.="<td colspan='$colspan' ".$this->colprops[$index]." class='list1'>".$this->renderCell($config['value'], $entry, $row)."</td>";
325           $rest-= $colspan;
326         }
328         // Fill remaining cols with nothing
329         $last= $this->numColumns - $rest;
330         for ($i= 0; $i<$rest; $i++){
331           $result.= "<td ".$this->colprops[$last+$i-1]." class='list1'>&nbsp;</td>";
332         }
333         $result.="</tr>";
335         $alt++;
336       }
337       $deps= $alt;
338     }
340     // Fill with contents, sort as configured
341     foreach ($this->entries as $row => $entry) {
342       $trow= "";
344       // Render multi select if needed
345       if ($this->multiSelect) {
346         $trow.="<td style='text-align:center;width:20px;' class='list0'><input type='checkbox' id='listing_selected_$row' name='listing_selected_$row'></td>\n";
347       }
349       foreach ($this->xmlData['table']['column'] as $index => $config) {
350         $renderedCell= $this->renderCell($config['value'], $entry, $row);
351         $trow.="<td ".$this->colprops[$index]." class='list0'>".$renderedCell."</td>\n";
353         // Save rendered column
354         $sort= preg_replace('/.*>([^<]+)<.*$/', '$1', $renderedCell);
355         $sort= preg_replace('/&nbsp;/', '', $sort);
356         if (preg_match('/</', $sort)){
357           $sort= "";
358         }
359         $this->entries[$row]["_sort$index"]= $sort;
360       }
362       // Save rendered entry
363       $this->entries[$row]['_rendered']= $trow;
364     }
366     // Complete list by sorting entries for _sort$index and appending them to the output
367     $entryIterator= new listingSortIterator($this->entries, $this->sortDirection[$this->sortColumn], "_sort".$this->sortColumn, $this->sortType);
368     foreach ($entryIterator as $row => $entry){
369       $alt++;
370       $result.="<tr class='rowxp".($alt&1)."'>\n";
371       $result.= $entry['_rendered'];
372       $result.="</tr>\n";
373     }
375     // Need to fill the list if it's not full (nobody knows why this is 22 ;-))
376     $emptyListStyle= (count($this->entries) + (($this->useSpan && count($this->entries))?$deps:0) == 0)?"border:0;":"";
377     if ((count($this->entries) + $deps) < 22) {
378       $result.= "<tr>";
379       for ($i= 0; $i<$this->numColumns; $i++) {
380         if ($i == 0) {
381           $result.= "<td class='list1nohighlight' style='$emptyListStyle height:100%;'>&nbsp;</td>";
382           continue;
383         }
384         if ($i != $this->numColumns-1) {
385           $result.= "<td class='list1nohighlight' style='$emptyListStyle'>&nbsp;</td>";
386         } else {
387           $result.= "<td class='list1nohighlight' style='border-right:1px solid #AAA;$emptyListStyle'>&nbsp;</td>";
388         }
389       }
390       $result.= "</tr>";
391     }
393     $result.= "</table></div></td></tr>";
395     // Add the footer if requested
396     if ($this->showFooter) {
397       $result.= "<tr><td class='scrollhead'><table summary='' style='width:100%' cellspacing='0' id='t_scrollfoot'><tr><td class='listfooter' style='border-bottom:0px;'>";
399       foreach ($this->objectTypes as $objectType) {
400         if (isset($this->objectTypeCount[$objectType['label']])) {
401           $label= _($objectType['label']);
402           $result.= "<img class='center' src='".$objectType['image']."' title='$label' alt='$label'>&nbsp;".$this->objectTypeCount[$objectType['label']]."&nbsp;&nbsp;&nbsp;&nbsp;";
403         }
404       }
406       $result.= "<td class='listfooter' style='width:13px;border-right:0px;'>&nbsp;</td></table></td></tr>";
407     }
409     $result.= "</table></div>";
411     $smarty= get_smarty();
412     $smarty->assign("usePrototype", "true");
413     $smarty->assign("FILTER", $this->filter->render());
414     $smarty->assign("SIZELIMIT", print_sizelimit_warning());
415     $smarty->assign("LIST", $result);
417     // Assign navigation elements
418     $nav= $this->renderNavigation();
419     foreach ($nav as $key => $html) {
420       $smarty->assign($key, $html);
421     }
423     // Assign action menu / base
424     $smarty->assign("ACTIONS", $this->renderActionMenu());
425     $smarty->assign("BASE", $this->renderBase());
427     // Assign separator
428     $smarty->assign("SEPARATOR", "<img src='images/lists/seperator.png' alt='-' align='middle' height='16' width='1' class='center'>");
430     // Assign summary
431     $smarty->assign("HEADLINE", $this->headline);
433     return ($smarty->fetch(get_template_path($this->xmlData['definition']['template'], true)));
434   }
437   function update()
438   {
439     global $config;
440     $ui= get_userinfo();
442     // Reset object counter / DN mapping
443     $this->objectTypeCount= array();
444     $this->objectDnMapping= array();
446     // Do not do anything if this is not our PID
447     if(isset($_REQUEST['PID']) && $_REQUEST['PID'] != $this->pid) {
448       return;
449     }
451     // Save base
452     if (isset($_POST['BASE']) && $this->baseMode) {
453       $base= get_post('BASE');
454       if (isset($this->bases[$base])) {
455         $this->base= $base;
456         session::global_set("CurrentMainBase", $this->base);
457       }
458     }
460     // Override the base if we got a message from the browser navigation
461     if ($this->departmentBrowser && isset($_GET['act'])) {
462       if (preg_match('/^department_([0-9]+)$/', validate($_GET['act']), $match)){
463         if (isset($this->departments[$match[1]])){
464           $this->base= $this->departments[$match[1]]['dn'];
465         }
466       }
467     }
469     // Filter POST with "act" attributes -> posted from action menu
470     if (isset($_POST['exec_act']) && $_POST['act'] != '') {
471       if (preg_match('/^export.*$/', $_POST['act']) && isset($this->exporter[$_POST['act']])) {
472         $exporter= $this->exporter[$_POST['act']];
473         $userinfo= ", "._("created by")." ".$ui->cn." - ".strftime('%A, %d. %B %Y, %H:%M:%S');
474         $entryIterator= new listingSortIterator($this->entries, $this->sortDirection[$this->sortColumn], "_sort".$this->sortColumn, $this->sortType);
475         $sortedEntries= array();
476         foreach ($entryIterator as $entry){
477           $sortedEntries[]= $entry;
478         }
479         $instance= new $exporter['class']($this->headline.$userinfo, $this->plainHeader, $sortedEntries, $this->exportColumns);
480         $type= call_user_func(array($exporter['class'], "getInfo"));
481         $type= $type[$_POST['act']];
482         send_binary_content($instance->query(), $type['filename'], $type= $type['mime']);
483       }
484     }
486     // Filter GET with "act" attributes
487     if (isset($_GET['act'])) {
488       $key= validate($_GET['act']);
489       if (preg_match('/^SORT_([0-9]+)$/', $key, $match)) {
490         // Switch to new column or invert search order?
491         $column= $match[1];
492         if ($this->sortColumn != $column) {
493           $this->sortColumn= $column;
494         } else {
495           $this->sortDirection[$column]= !$this->sortDirection[$column];
496         }
498         // Allow header to update itself according to the new sort settings
499         $this->renderHeader();
500       }
501     }
503     // Override base if we got signals from the navigation elements
504     $action= "";
505     foreach ($_POST as $key => $value) {
506       if (preg_match('/^(ROOT|BACK|HOME)_x$/', $key, $match)) {
507         $action= $match[1];
508         break;
509       }
510     }
512     // Navigation handling
513     if ($action == 'ROOT') {
514       $deps= $ui->get_module_departments($this->module);
515       $this->base= $deps[0];
516     }
517     if ($action == 'BACK') {
518       $deps= $ui->get_module_departments($this->module);
519       $base= preg_replace("/^[^,]+,/", "", $this->base);
520       if(in_array_ics($base, $deps)){
521         $this->base= $base;
522       }
523     }
524     if ($action == 'HOME') {
525       $ui= get_userinfo();
526       $this->base= $this->filter->getObjectBase($ui->dn);
527     }
529     // Reload departments
530     if ($this->departmentBrowser){
531       $this->departments= $this->getDepartments();
532     }
534     // Update filter and refresh entries
535     $this->filter->setBase($this->base);
536     $this->entries= $this->filter->query();
537   }
540   function setBase($base)
541   {
542     $this->base= $base;
543   }
546   function getBase()
547   {
548     return $this->base;
549   }
552   function parseLayout($layout)
553   {
554     $result= array();
555     $layout= preg_replace("/^\|/", "", $layout);
556     $layout= preg_replace("/\|$/", "", $layout);
557     $cols= split("\|", $layout);
559     foreach ($cols as $index => $config) {
560       if ($config != "") {
561         $res= "";
562         $components= split(';', $config);
563         foreach ($components as $part) {
564           if (preg_match("/^r$/", $part)) {
565             $res.= "text-align:right;";
566             continue;
567           }
568           if (preg_match("/^l$/", $part)) {
569             $res.= "text-align:left;";
570             continue;
571           }
572           if (preg_match("/^c$/", $part)) {
573             $res.= "text-align:center;";
574             continue;
575           }
576           if (preg_match("/^[0-9]+(|px|%)$/", $part)) {
577             $res.= "width:$part;min-width:$part;";
578             continue;
579           }
580         }
582         // Add minimum width for scalable columns
583         if (!preg_match('/width:/', $res)){
584           $res.= "min-width:200px;";
585         }
587         $result[$index]= " style='$res' ";
588       } else {
589         $result[$index]= " style='min-width:100px'";
590       }
591     }
593     // Save number of columns for later use
594     $this->numColumns= count($cols);
596     return $result;
597   }
600   function renderCell($data, $config, $row)
601   {
602     // Replace flat attributes in data string
603     for ($i= 0; $i<$config['count']; $i++) {
604       $attr= $config[$i];
605       $value= "";
606       if (is_array($config[$attr])) {
607         $value= $config[$attr][0];
608       } else {
609         $value= $config[$attr];
610       }
611       $data= preg_replace("/%\{$attr\}/", $value, $data);
612     }
614     // Watch out for filters and prepare to execute them
615     $data= $this->processElementFilter($data, $config, $row);
617     // Replace all non replaced %{...} instances because they
618     // are non resolved attributes or filters
619     $data= preg_replace('/%{[^}]+}/', '&nbsp;', $data);
621     return $data;
622   }
625   function renderBase()
626   {
627     if (!$this->baseMode) {
628       return;
629     }
631     $result= "<select name='BASE' onChange='mainform.submit()' size='1'>";
632     $firstDN= null;
633     $found= false;
635     foreach ($this->bases as $key=>$value) {
636       // Keep first entry to fall back eventually
637       if(!$firstDN) {
638         $firstDN= $key;
639       }
641       // Prepare to render entry
642       $selected= "";
643       if ($key == $this->base) {
644         $selected= " selected";
645         $found= true;
646       }
647       $key = htmlentities($key,ENT_QUOTES);
648       $result.= "\n<option value=\"".$key."\"$selected>".$value."</option>";
649     }
651     $result.= "</select>";
653     // Reset the currently used base to the first DN we found if there
654     // was no match.
655     if(!$found){
656       $this->base = $firstDN;
657     }
659     return $result;
660   }
663   function processElementFilter($data, $config, $row)
664   {
665     preg_match_all("/%\{filter:([^(]+)\((.*)\)\}/", $data, $matches, PREG_SET_ORDER);
667     foreach ($matches as $match) {
668       if (!isset($this->filters[$match[1]])) {
669         continue;
670       }
671       $cl= preg_replace('/::.*$/', '', $this->filters[$match[1]]);
672       $method= preg_replace('/^.*::/', '', $this->filters[$match[1]]);
674       // Prepare params for function call
675       $params= array();
676       preg_match_all('/"[^"]+"|[^,]+/', $match[2], $parts);
677       foreach ($parts[0] as $param) {
679         // Row is replaced by the row number
680         if ($param == "row") {
681           $params[]= $row;
682         }
684         // pid is replaced by the current PID
685         if ($param == "pid") {
686           $params[]= $this->pid;
687         }
689         // base is replaced by the current base
690         if ($param == "base") {
691           $params[]= $this->getBase();
692         }
694         // Fixie with "" is passed directly
695         if (preg_match('/^".*"$/', $param)){
696           $params[]= preg_replace('/"/', '', $param);
697         }
699         // LDAP variables get replaced by their objects
700         for ($i= 0; $i<$config['count']; $i++) {
701           if ($param == $config[$i]) {
702             $values= $config[$config[$i]];
703             if (is_array($values)){
704               unset($values['count']);
705             }
706             $params[]= $values;
707           }
708         }
710         // Move dn if needed
711         if ($param == "dn") {
712           $params[]= LDAP::fix($config["dn"]);
713         }
714       }
716       // Replace information
717       if ($cl == "listing") {
718         // Non static call - seems to result in errors
719         $data= @preg_replace('/'.preg_quote($match[0]).'/', call_user_func_array(array($this, "$method"), $params), $data);
720       } else {
721         // Static call
722         $data= preg_replace('/'.preg_quote($match[0]).'/', call_user_func_array(array($cl, $method), $params), $data);
723       }
724     }
726     return $data;
727   }
730   function getObjectType($types, $classes)
731   {
732     // Walk thru types and see if there's something matching
733     $types=array_reverse($types);
734     foreach ($types as $objectType) {
735       $ocs= $objectType['objectClass'];
736       if (!is_array($ocs)){
737         $ocs= array($ocs);
738       }
740       $found= true;
741       foreach ($ocs as $oc){
742         if (preg_match('/^!(.*)$/', $oc, $match)) {
743           $oc= $match[1];
744           if (in_array($oc, $classes)) {
745             $found= false;
746           }
747         } else {
748           if (!in_array($oc, $classes)) {
749             $found= false;
750           }
751         }
752       }
754       if ($found) {
755         return $objectType;
756       }
757     }
759     return null;
760   }
763   function filterObjectType($dn, $classes)
764   {
765     // Walk thru classes and return on first match
766     $result= "&nbsp;";
768     $objectType= $this->getObjectType($this->objectTypes, $classes);
769     if ($objectType) {
770       $this->objectDnMapping[$dn]= $objectType["objectClass"];
771       $result= "<img class='center' title='".LDAP::fix($dn)."' src='".$objectType["image"]."'>";
772       if (!isset($this->objectTypeCount[$objectType['label']])) {
773         $this->objectTypeCount[$objectType['label']]= 0;
774       }
775       $this->objectTypeCount[$objectType['label']]++;
776     }
778     return $result;
779   }
782   function filterActions($dn, $row, $classes)
783   {
784     // Do nothing if there's no menu defined
785     if (!isset($this->xmlData['actiontriggers']['action'])) {
786       return "&nbsp;";
787     }
789     // Go thru all actions
790     $result= "";
791     $actions= $this->xmlData['actiontriggers']['action'];
792     foreach($actions as $action) {
793       // Skip the entry completely if there's no permission to execute it
794       if (!$this->hasActionPermission($action, $dn)) {
795         $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
796         continue;
797       }
799       // Skip entry if the pseudo filter does not fit
800       if (isset($action['filter']) && preg_match('/^[a-z0-9_]+!?=[a-z0-9_]+$/i', $action['filter'])) {
801         list($fa, $fv)= split('=', $action['filter']);
802         if (preg_match('/^(.*)!$/', $fa, $m)){
803           $fa= $m[1];
804           if (isset($this->entries[$row][$fa]) && $this->entries[$row][$fa][0] == $fv) {
805             $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
806             continue;
807           }
808         } else {
809           if (!isset($this->entries[$row][$fa]) && !$this->entries[$row][$fa][0] == $fv) {
810             $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
811             continue;
812           }
813         }
814       }
817       // If there's an objectclass definition and we don't have it
818       // add an empty picture here.
819       if (isset($action['objectclass'])){
820         $objectclass= $action['objectclass'];
821         if (preg_match('/^!(.*)$/', $objectclass, $m)){
822           $objectclass= $m[1];
823           if(in_array($objectclass, $classes)) {
824             $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
825             continue;
826           }
827         } else {
828           if(!in_array($objectclass, $classes)) {
829             $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
830             continue;
831           }
832         }
833       }
835       // Render normal entries as usual
836       if ($action['type'] == "entry") {
837         $label= $this->processElementFilter($action['label'], $this->entries[$row], $row);
838         $image= $this->processElementFilter($action['image'], $this->entries[$row], $row);
839         $result.="<input class='center' type='image' src='$image' title='$label' ".
840                  "name='listing_".$action['name']."_$row' style='padding:1px'>";
841       }
843       // Handle special types
844       if ($action['type'] == "copypaste" || $action['type'] == "snapshot") {
846         $objectType= $this->getObjectType($this->objectTypes, $this->entries[$row]['objectClass']);
847         $category= $class= null;
848         if ($objectType) {
849           $category= $objectType['category'];
850           $class= $objectType['class'];
851         }
853         if ($action['type'] == "copypaste") {
854           $result.= $this->renderCopyPasteActions($row, $this->entries[$row]['dn'], $category, $class);
855         } else {
856           $result.= $this->renderSnapshotActions($row, $this->entries[$row]['dn'], $category, $class);
857         }
858       }
859     }
861     return $result;
862   }
865   function filterDepartmentLink($row, $dn, $description)
866   {
867     $attr= $this->departments[$row]['sort-attribute'];
868     $name= $this->departments[$row][$attr];
869     if (is_array($name)){
870       $name= $name[0];
871     }
872     $result= sprintf("%s [%s]", $name, $description[0]);
873     return("<a href='?plug=".$_GET['plug']."&amp;PID=$this->pid&amp;act=department_$row' title='$dn'>$result</a>");
874   }
877   function filterLink()
878   {
879     $result= "&nbsp;";
881     $row= func_get_arg(0);
882     $pid= $this->pid;
883     $dn= LDAP::fix(func_get_arg(1));
884     $params= array(func_get_arg(2));
886     // Collect sprintf params
887     for ($i = 3;$i < func_num_args();$i++) {
888       $val= func_get_arg($i);
889       if (is_array($val)){
890         $params[]= $val[0];
891         continue;
892       }
893       $params[]= $val;
894     }
896     $result= "&nbsp;";
897     $trans= call_user_func_array("sprintf", $params);
898     if ($trans != "") {
899       return("<a href='?plug=".$_GET['plug']."&amp;PID=$pid&amp;act=listing_edit_$row' title='$dn'>$trans</a>");
900     }
902     return $result;
903   }
906   function renderNavigation()
907   {
908     $result= array();
909     $enableBack = true;
910     $enableRoot = true;
911     $enableHome = true;
913     $ui = get_userinfo();
915     /* Check if base = first available base */
916     $deps = $ui->get_module_departments($this->module);
918     if(!count($deps) || $deps[0] == $this->filter->base){
919       $enableBack = false;
920       $enableRoot = false;
921     }
923     $listhead ="";
925     /* Check if we are in users home  department */
926     if(!count($deps) || $this->filter->base == $this->filter->getObjectBase($ui->dn)){
927       $enableHome = false;
928     }
930     /* Draw root button */
931     if($enableRoot){
932       $result["ROOT"]= "<input class='center' type='image' src='images/lists/root.png' align='middle' ".
933                        "title='"._("Go to root department")."' name='ROOT' alt='"._("Root")."'>";
934     }else{
935       $result["ROOT"]= "<img src='images/lists/root_grey.png' class='center' alt='"._("Root")."'>";
936     }
938     /* Draw back button */
939     if($enableBack){
940       $result["BACK"]= "<input class='center' type='image' align='middle' src='images/lists/back.png' ".
941                        "title='"._("Go up one department")."' alt='"._("Up")."' name='BACK'>";
942     }else{
943       $result["BACK"]= "<img src='images/lists/back_grey.png' class='center' alt='"._("Up")."'>";
944     }
946     /* Draw home button */
947     if($enableHome){
948       $result["HOME"]= "<input class='center' type='image' align='middle' src='images/lists/home.png' ".
949                        "title='"._("Go to users department")."' alt='"._("Home")."' name='HOME'>";
950     }else{
951       $result["HOME"]= "<img src='images/lists/home_grey.png' class='center' alt='"._("Home")."'>";
952     }
954     /* Draw reload button, this button is enabled everytime */
955     $result["RELOAD"]= "<input class='center' type='image' src='images/lists/reload.png' align='middle' ".
956                        "title='"._("Reload list")."' name='REFRESH' alt='"._("Submit")."'>";
958     return ($result);
959   }
962   function getAction()
963   {
964     // Do not do anything if this is not our PID, or there's even no PID available...
965     if(!isset($_REQUEST['PID']) || $_REQUEST['PID'] != $this->pid) {
966       return;
967     }
969     $result= array("targets" => array(), "action" => "");
971     // Filter GET with "act" attributes
972     if (isset($_GET['act'])) {
973       $key= validate($_GET['act']);
974       $target= preg_replace('/^listing_[a-zA-Z_]+_([0-9]+)$/', '$1', $key);
975       if (isset($this->entries[$target]['dn'])) {
976         $result['action']= preg_replace('/^listing_([a-zA-Z_]+)_[0-9]+$/', '$1', $key);
977         $result['targets'][]= $this->entries[$target]['dn'];
978       }
980       // Drop targets if empty
981       if (count($result['targets']) == 0) {
982         unset($result['targets']);
983       }
984       return $result;
985     }
987     // Filter POST with "listing_" attributes
988     foreach ($_POST as $key => $prop) {
990       // Capture selections
991       if (preg_match('/^listing_selected_[0-9]+$/', $key)) {
992         $target= preg_replace('/^listing_selected_([0-9]+)$/', '$1', $key);
993         if (isset($this->entries[$target]['dn'])) {
994           $result['targets'][]= $this->entries[$target]['dn'];
995         }
996         continue;
997       }
999       // Capture action with target - this is a one shot
1000       if (preg_match('/^listing_[a-zA-Z_]+_[0-9]+(|_x)$/', $key)) {
1001         $target= preg_replace('/^listing_[a-zA-Z_]+_([0-9]+)(|_x)$/', '$1', $key);
1002         if (isset($this->entries[$target]['dn'])) {
1003           $result['action']= preg_replace('/^listing_([a-zA-Z_]+)_[0-9]+(|_x)$/', '$1', $key);
1004           $result['targets']= array($this->entries[$target]['dn']);
1005         }
1006         break;
1007       }
1009       // Capture action without target
1010       if (preg_match('/^listing_[a-zA-Z_]+(|_x)$/', $key)) {
1011         $result['action']= preg_replace('/^listing_([a-zA-Z_]+)(|_x)$/', '$1', $key);
1012         continue;
1013       }
1014     }
1016     // Filter POST with "act" attributes -> posted from action menu
1017     if (isset($_POST['act']) && $_POST['act'] != '') {
1018       if (!preg_match('/^export.*$/', $_POST['act'])){
1019         $result['action']= validate($_POST['act']);
1020       }
1021     }
1023     // Drop targets if empty
1024     if (count($result['targets']) == 0) {
1025       unset($result['targets']);
1026     }
1027     return $result;
1028   }
1031   function renderActionMenu()
1032   {
1033     // Don't send anything if the menu is not defined
1034     if (!isset($this->xmlData['actionmenu']['action'])){
1035       return "";
1036     }
1038     // Array?
1039     if (isset($this->xmlData['actionmenu']['action']['type'])){
1040       $this->xmlData['actionmenu']['action']= array($this->xmlData['actionmenu']['action']);
1041     }
1043     // Load shortcut
1044     $actions= &$this->xmlData['actionmenu']['action'];
1045     $result= "<input type='hidden' name='act' id='actionmenu' value=''><div style='display:none'><input type='submit' name='exec_act' id='exec_act' value=''></div>".
1046              "<ul class='level1' id='root'><li><a href='#'>"._("Actions")."&nbsp;<img ".
1047              "border=0 class='center' src='images/lists/sort-down.png'></a>";
1049     // Build ul/li list
1050     $result.= $this->recurseActions($actions);
1052     return "<div id='pulldown'>".$result."</li></ul><div>";
1053   }
1056   function recurseActions($actions)
1057   {
1058     global $class_mapping;
1059     static $level= 2;
1060     $result= "<ul class='level$level'>";
1061     $separator= "";
1063     foreach ($actions as $action) {
1065       // Skip the entry completely if there's no permission to execute it
1066       if (!$this->hasActionPermission($action, $this->filter->base)) {
1067         continue;
1068       }
1070       // Skip entry if there're missing dependencies
1071       if (isset($action['depends'])) {
1072         $deps= is_array($action['depends'])?$action['depends']:array($action['depends']);
1073         foreach($deps as $clazz) {
1074           if (!isset($class_mapping[$clazz])){
1075             continue 2;
1076           }
1077         }
1078       }
1080       // Fill image if set
1081       $img= "";
1082       if (isset($action['image'])){
1083         $img= "<img border='0' class='center' src='".$action['image']."'>&nbsp;";
1084       }
1086       if ($action['type'] == "separator"){
1087         $separator= " style='border-top:1px solid #AAA' ";
1088         continue;
1089       }
1091       // Dive into subs
1092       if ($action['type'] == "sub" && isset($action['action'])) {
1093         $level++;
1094         if (isset($action['label'])){
1095           $result.= "<li$separator><a href='#'>$img"._($action['label'])."&nbsp;<img border='0' src='images/forward-arrow.png'></a>";
1096         }
1098         // Ensure we've an array of actions, this enables sub menus with only one action.
1099         if(isset($action['action']['type'])){
1100           $action['action'] = array($action['action']);
1101         }
1103         $result.= $this->recurseActions($action['action'])."</li>";
1104         $level--;
1105         $separator= "";
1106         continue;
1107       }
1109       // Render entry elseways
1110       if (isset($action['label'])){
1111         $result.= "<li$separator><a href='#' onClick='document.getElementById(\"actionmenu\").value= \"".$action['name']."\";mainform.submit();'>$img"._($action['label'])."</a></li>";
1112       }
1114       // Check for special types
1115       switch ($action['type']) {
1116         case 'copypaste':
1117           $result.= $this->renderCopyPasteMenu($separator);
1118           break;
1120         case 'snapshot':
1121           $result.= $this->renderSnapshotMenu($separator);
1122           break;
1124         case 'exporter':
1125           $result.= $this->renderExporterMenu($separator);
1126           break;
1128         case 'daemon':
1129           $result.= $this->renderDaemonMenu($separator);
1130           break;
1131       }
1133       $separator= "";
1134     }
1136     $result.= "</ul>";
1137     return $result;
1138   }
1141   function hasActionPermission($action, $dn)
1142   {
1143     $ui= get_userinfo();
1145     if (isset($action['acl'])) {
1146       $acls= $action['acl'];
1147       if (!is_array($acls)) {
1148         $acls= array($acls);
1149       }
1151       // Every ACL has to pass
1152       foreach ($acls as $acl) {
1153         $module= $this->module;
1154         $aclList= array();
1156         // Split for category and plugins if needed
1157         // match for "[rw]" style entries
1158         if (preg_match('/^\[([rwcdm]+)\]$/', $acl, $match)){
1159           $aclList= array($match[1]);
1160         }
1162         // match for "users[rw]" style entries
1163         if (preg_match('/^([a-zA-Z0-9]+)\[([rwcdm]+)\]$/', $acl, $match)){
1164           $module= $match[1];
1165           $aclList= array($match[2]);
1166         }
1168         // match for "users/user[rw]" style entries
1169         if (preg_match('/^([a-zA-Z0-9]+\/[a-zA-Z0-9]+)\[([rwcdm]+)\]$/', $acl, $match)){
1170           $module= $match[1];
1171           $aclList= array($match[2]);
1172         }
1174         // match "users/user[userPassword:rw(,...)*]" style entries
1175         if (preg_match('/^([a-zA-Z0-9]+\/[a-zA-Z0-9]+)\[([a-zA-Z0-9]+:[rwcdm]+(,[a-zA-Z0-9]+:[rwcdm]+)*)\]$/', $acl, $match)){
1176           $module= $match[1];
1177           $aclList= split(',', $match[2]);
1178         }
1180         // Walk thru prepared ACL by using $module
1181         foreach($aclList as $sAcl) {
1182           $checkAcl= "";
1184           // Category or detailed permission?
1185           if (strpos('/', $module) === false) {
1186             if (preg_match('/([a-zA-Z0-9]+):([rwcdm]+)/', $sAcl, $m) ) {
1187               $checkAcl= $ui->get_permissions($dn, $module, $m[1]);
1188               $sAcl= $m[2];
1189             } else {
1190               $checkAcl= $ui->get_permissions($dn, $module, '0');
1191             }
1192           } else {
1193             $checkAcl= $ui->get_category_permissions($dn, $module);
1194           }
1196           // Split up remaining part of the acl and check if it we're
1197           // allowed to do something...
1198           $parts= str_split($sAcl);
1199           foreach ($parts as $part) {
1200             if (strpos($checkAcl, $part) === false){
1201               return false;
1202             }
1203           }
1205         }
1206       }
1207     }
1209     return true;
1210   }
1213   function refreshBasesList()
1214   {
1215     global $config;
1216     $ui= get_userinfo();
1218     // Do some array munching to get it user friendly
1219     $ids= $config->idepartments;
1220     $d= $ui->get_module_departments($this->module);
1221     $k_ids= array_keys($ids);
1222     $deps= array_intersect($d,$k_ids);
1224     // Fill internal bases list
1225     $this->bases= array();
1226     foreach($k_ids as $department){
1227       $this->bases[$department] = $ids[$department];
1228     }
1229   }
1232   function getDepartments()
1233   {
1234     $departments= array();
1235     $ui= get_userinfo();
1237     // Get list of supported department types
1238     $types = departmentManagement::get_support_departments();
1240     // Load departments allowed by ACL
1241     $validDepartments = $ui->get_module_departments($this->module);
1243     // Build filter and look in the LDAP for possible sub departments
1244     // of current base
1245     $filter= "(&(objectClass=gosaDepartment)(|";
1246     $attrs= array("description", "objectClass");
1247     foreach($types as $name => $data){
1248       $filter.= "(objectClass=".$data['OC'].")";
1249       $attrs[]= $data['ATTR'];
1250     }
1251     $filter.= "))";
1252     $res= get_list($filter, $this->module, $this->base, $attrs, GL_NONE);
1254     // Analyze list of departments
1255     foreach ($res as $department) {
1256       if (!in_array($department['dn'], $validDepartments)) {
1257         continue;
1258       }
1260       // Add the attribute where we use for sorting
1261       $oc= null;
1262       foreach(array_keys($types) as $type) {
1263         if (in_array($type, $department['objectClass'])) {
1264           $oc= $type;
1265           break;
1266         }
1267       }
1268       $department['sort-attribute']= $types[$oc]['ATTR'];
1270       // Move to the result list
1271       $departments[]= $department;
1272     }
1274     return $departments;
1275   }
1278   function renderCopyPasteMenu($separator, $copy= true, $cut= true)
1279   {
1280     // We can only provide information if we've got a copypaste handler
1281     // instance
1282     if(!(isset($this->copyPasteHandler) && is_object($this->copyPasteHandler))){
1283       return "";
1284     }
1286     // Presets
1287     $result= "";
1288     $read= $paste= false;
1289     $ui= get_userinfo();
1291     // Switch flags to on if there's at least one category which allows read/paste
1292     foreach($this->categories as $category){
1293       $read= $read || preg_match('/r/', $ui->get_category_permissions($this->base, $category));
1294       $paste= $paste || $ui->is_pasteable($this->base, $category) == 1;
1295     }
1298     // Draw entries that allow copy and cut
1299     if($read){
1301       // Copy entry
1302       if($copy){
1303         $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>";
1304         $separator= "";
1305       }
1307       // Cut entry
1308       if($cut){
1309         $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>";
1310         $separator= "";
1311       }
1312     }
1314     // Draw entries that allow pasting entries
1315     if($paste){
1316       if($this->copyPasteHandler->entries_queued()){
1317         $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>";
1318       }else{
1319         $result.= "<li$separator><a href='#'><img src='images/lists/paste-grey.png' alt='' border='0' class='center'>&nbsp;"._("Paste")."</a></li>";
1320       }
1321     }
1322     
1323     return($result);
1324   }
1327   function renderCopyPasteActions($row, $dn, $category, $class, $copy= true, $cut= true)
1328   {
1329     // We can only provide information if we've got a copypaste handler
1330     // instance
1331     if(!(isset($this->copyPasteHandler) && is_object($this->copyPasteHandler))){
1332       return "";
1333     }
1335     // Presets
1336     $ui = get_userinfo();
1337     $result = "";
1339     // Render cut entries
1340     if($cut){
1341       if($ui->is_cutable($dn, $category, $class)){
1342         $result .= "<input class='center' type='image'
1343           src='images/lists/cut.png' alt='"._("Cut")."' name='listing_cut_$row' title='"._("Cut this entry")."' style='padding:1px'>";
1344       }else{
1345         $result.="<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
1346       }
1347     }
1349     // Render copy entries
1350     if($copy){
1351       if($ui->is_copyable($dn, $category, $class)){
1352         $result.= "<input class='center' type='image'
1353           src='images/lists/copy.png' alt='"._("Copy")."' name='listing_copy_$row' title='"._("Copy this entry")."' style='padding:1px'>";
1354       }else{
1355         $result.="<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
1356       }
1357     }
1359     return($result);
1360   }
1363   function renderSnapshotMenu($separator)
1364   {
1365     // We can only provide information if we've got a snapshot handler
1366     // instance
1367     if(!(isset($this->snapshotHandler) && is_object($this->snapshotHandler))){
1368       return "";
1369     }
1371     // Presets
1372     $result = "";
1373     $ui = get_userinfo();
1375     if($this->snapshotHandler->enabled() && $ui->allow_snapshot_restore($this->base, $this->module)){
1377       // Check if there is something to restore
1378       $restore= false;
1379       foreach($this->snapshotHandler->getSnapshotBases() as $base){
1380         $restore= $restore || count($this->snapshotHandler->getDeletedSnapshots($base)) > 0;
1381       }
1383       // Draw icons according to the restore flag
1384       if($restore){
1385         $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>";
1386       }else{
1387         $result.= "<li$separator><a href='#'><img src='images/lists/restore_grey.png' alt='' border='0' class='center'>&nbsp;"._("Restore snapshots")."</a></li>";
1388       }
1389     }
1391     return($result);
1392   }
1395   function renderExporterMenu($separator)
1396   {
1397     // Presets
1398     $result = "";
1400     // Draw entries
1401     $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'>";
1403     // Export CVS as build in exporter
1404     foreach ($this->exporter as $action => $exporter) {
1405       $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>";
1406     }
1408     // Finalize list
1409     $result.= "</ul></li>";
1411     return($result);
1412   }
1415   function renderSnapshotActions($row, $dn, $category, $class, $copy= true, $cut= true)
1416   {
1417     // We can only provide information if we've got a snapshot handler
1418     // instance
1419     if(!(isset($this->snapshotHandler) && is_object($this->snapshotHandler))){
1420       return "";
1421     }
1423     // Presets
1424     $result= "";
1425     $ui = get_userinfo();
1427     // Only act if enabled here
1428     if($this->snapshotHandler->enabled()){
1430       // Draw restore button
1431       if ($ui->allow_snapshot_restore($dn, $category)){
1433         // Do we have snapshots for this dn?
1434         if($this->snapshotHandler->hasSnapshots($dn)){
1435           $result.= "<input class='center' type='image' src='images/lists/restore.png' ".
1436                      "alt='"._("Restore snapshot")."' name='listing_restore_$row' title='".
1437                      _("Restore snapshot")."' style='padding:1px'>";
1438         } else {
1439           $result.= "<img src='images/lists/restore_grey.png' alt=' ' class='center' style='padding:1px'>";
1440         }
1441       }
1443       // Draw snapshot button
1444       if($ui->allow_snapshot_create($dn, $category)){
1445           $result.= "<input class='center' type='image' src='images/snapshot.png' ".
1446                      "alt='"._("Create snapshot")."' name='listing_snapshot_$row' title='".
1447                      _("Create a new snapshot from this object")."' style='padding:1px'>";
1448       }else{
1449           $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
1450       }
1451     }
1453     return($result);
1454   }
1457   function renderDaemonMenu($separator)
1458   {
1459     $result= "";
1461     // If there is a daemon registered, draw the menu entries
1462     if(class_available("DaemonEvent")){
1463       $events= DaemonEvent::get_event_types_by_category($this->categories);
1464       if(isset($events['BY_CLASS']) && count($events['BY_CLASS'])){
1465         foreach($events['BY_CLASS'] as $name => $event){
1466           $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>";
1467           $separator= "";
1468         }
1469       }
1470     }
1472     return $result;
1473   }
1476   function getType($dn)
1477   {
1478     if (isset($this->objectDnMapping[$dn])) {
1479       return $this->objectDnMapping[$dn];
1480     }
1481     return null;
1482   }
1486 ?>