Code

Updated list rendering
[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     // Initialize list
268     $result= "<input type='hidden' value='$this->pid' name='PID'>\n";
269     $height= 450;
270     if ($this->height != 0) {
271       $result.= "<input type='hidden' value='$this->height' id='d_height'>\n";
272       $height= $this->height;
273     }
274     
275     $result.= "<table cellpadding='0' cellspacing='0' border='0'><tr><td><div class='listContainer' id='d_scrollbody' style='border-top:1px solid #B0B0B0;width:700px;height:".($height+25)."px;'>\n";
277     $result.= "<table summary='$this->headline' style='width:100%; table-layout:fixed;' cellspacing='0' cellpadding='0' id='t_scrolltable'>\n";
278     $this->numColumns= count($this->colprops) + ($this->multiSelect?1:0);
280     // Build list header
281     $result.= "<thead class='fixedListHeader listHeaderFormat'><tr>\n";
282     if ($this->multiSelect) {
283       $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";
284     }
285     foreach ($this->header as $header) {
286       $result.= $header;
287     }
288     $result.= "</tr></thead>\n";
290     // Build list body
291     $result.= "<tbody class='listScrollContent listBodyFormat' id='t_nscrollbody' style='height:".$height."px;'>\n";
293 ###########################
295     // No results? Just take an empty colspanned row
296     if (count($this->entries) + count($this->departments) == 0) {
297       $result.= "<tr class='rowxp0'><td class='list1nohighlight' colspan='$this->numColumns' style='height:100%;border-right:0px;width:100%;'>&nbsp;</td></tr>";
298     }
300     // Line color alternation
301     $alt= 0;
302     $deps= 0;
304     // Draw department browser if configured and we're not in sub mode
305     $this->useSpan= false;
306     if ($this->departmentBrowser && $this->filter->scope != "sub") {
307       // Fill with department browser if configured this way
308       $departmentIterator= new departmentSortIterator($this->departments, $this->sortDirection[$this->sortColumn]);
309       foreach ($departmentIterator as $row => $entry){
310         $result.="<tr class='rowxp".($alt&1)."'>";
312         // Render multi select if needed
313         if ($this->multiSelect) {
314           $result.="<td style='text-align:center;width:20px;' class='list1'>&nbsp;</td>";
315         }
317         // Render defined department columns, fill the rest with some stuff
318         $rest= $this->numColumns - 1;
319         foreach ($this->xmlData['table']['department'] as $index => $config) {
320           $colspan= 1;
321           if (isset($config['span'])){
322             $colspan= $config['span'];
323             $this->useSpan= true;
324           }
325           $result.="<td colspan='$colspan' ".$this->colprops[$index]." class='list1'>".$this->renderCell($config['value'], $entry, $row)."</td>";
326           $rest-= $colspan;
327         }
329         // Fill remaining cols with nothing
330         $last= $this->numColumns - $rest;
331         for ($i= 0; $i<$rest; $i++){
332           $result.= "<td ".$this->colprops[$last+$i-1]." class='list1'>&nbsp;</td>";
333         }
334         $result.="</tr>";
336         $alt++;
337       }
338       $deps= $alt;
339     }
341     // Fill with contents, sort as configured
342     foreach ($this->entries as $row => $entry) {
343       $trow= "";
345       // Render multi select if needed
346       if ($this->multiSelect) {
347         $trow.="<td style='text-align:center;width:20px;' class='list0'><input type='checkbox' id='listing_selected_$row' name='listing_selected_$row'></td>\n";
348       }
350       foreach ($this->xmlData['table']['column'] as $index => $config) {
351         $renderedCell= $this->renderCell($config['value'], $entry, $row);
352         $trow.="<td ".$this->colprops[$index]." class='list0'>".$renderedCell."</td>\n";
354         // Save rendered column
355         $sort= preg_replace('/.*>([^<]+)<.*$/', '$1', $renderedCell);
356         $sort= preg_replace('/&nbsp;/', '', $sort);
357         if (preg_match('/</', $sort)){
358           $sort= "";
359         }
360         $this->entries[$row]["_sort$index"]= $sort;
361       }
363       // Save rendered entry
364       $this->entries[$row]['_rendered']= $trow;
365     }
367     // Complete list by sorting entries for _sort$index and appending them to the output
368     $entryIterator= new listingSortIterator($this->entries, $this->sortDirection[$this->sortColumn], "_sort".$this->sortColumn, $this->sortType);
369     foreach ($entryIterator as $row => $entry){
370       $alt++;
371       $result.="<tr class='rowxp".($alt&1)."'>\n";
372       $result.= $entry['_rendered'];
373       $result.="</tr>\n";
374     }
376     // Need to fill the list if it's not full (nobody knows why this is 22 ;-))
377     $emptyListStyle= (count($this->entries) + (($this->useSpan && count($this->entries))?$deps:0) == 0)?"border:0;":"";
378     if ((count($this->entries) + $deps) < 22) {
379       $result.= "<tr>";
380       for ($i= 0; $i<$this->numColumns; $i++) {
381         if ($i == 0) {
382           $result.= "<td class='list1nohighlight' style='$emptyListStyle height:100%;'>&nbsp;</td>";
383           continue;
384         }
385         if ($i != $this->numColumns-1) {
386           $result.= "<td class='list1nohighlight' style='$emptyListStyle'>&nbsp;</td>";
387         } else {
388           $result.= "<td class='list1nohighlight' style='border-right:1px solid #AAA;$emptyListStyle'>&nbsp;</td>";
389         }
390       }
391       $result.= "</tr>";
392     }
394     // Close list
395     $result.= "</tbody></table></div></td></tr></table>";
397     // Add the footer if requested
398 #################################
399     #if ($this->showFooter) {
400     #  $result.= "<tr><td class='scrollhead'><table summary='' style='width:100%' cellspacing='0' id='t_scrollfoot'><tr><td class='listfooter' style='border-bottom:0px;'>";
402     #  foreach ($this->objectTypes as $objectType) {
403     #    if (isset($this->objectTypeCount[$objectType['label']])) {
404     #      $label= _($objectType['label']);
405     #      $result.= "<img class='center' src='".$objectType['image']."' title='$label' alt='$label'>&nbsp;".$this->objectTypeCount[$objectType['label']]."&nbsp;&nbsp;&nbsp;&nbsp;";
406     #    }
407     #  }
409     #  $result.= "<td class='listfooter' style='width:13px;border-right:0px;'>&nbsp;</td></table></td></tr>";
410     #}
412     $smarty= get_smarty();
413     $smarty->assign("usePrototype", "true");
414     $smarty->assign("FILTER", $this->filter->render());
415     $smarty->assign("SIZELIMIT", print_sizelimit_warning());
416     $smarty->assign("LIST", $result);
418     // Assign navigation elements
419     $nav= $this->renderNavigation();
420     foreach ($nav as $key => $html) {
421       $smarty->assign($key, $html);
422     }
424     // Assign action menu / base
425     $smarty->assign("ACTIONS", $this->renderActionMenu());
426     $smarty->assign("BASE", $this->renderBase());
428     // Assign separator
429     $smarty->assign("SEPARATOR", "<img src='images/lists/seperator.png' alt='-' align='middle' height='16' width='1' class='center'>");
431     // Assign summary
432     $smarty->assign("HEADLINE", $this->headline);
434     return ($smarty->fetch(get_template_path($this->xmlData['definition']['template'], true)));
435   }
438   function update()
439   {
440     global $config;
441     $ui= get_userinfo();
443     // Reset object counter / DN mapping
444     $this->objectTypeCount= array();
445     $this->objectDnMapping= array();
447     // Do not do anything if this is not our PID
448     if(isset($_REQUEST['PID']) && $_REQUEST['PID'] != $this->pid) {
449       return;
450     }
452     // Save base
453     if (isset($_POST['BASE']) && $this->baseMode) {
454       $base= get_post('BASE');
455       if (isset($this->bases[$base])) {
456         $this->base= $base;
457         session::global_set("CurrentMainBase", $this->base);
458       }
459     }
461     // Override the base if we got a message from the browser navigation
462     if ($this->departmentBrowser && isset($_GET['act'])) {
463       if (preg_match('/^department_([0-9]+)$/', validate($_GET['act']), $match)){
464         if (isset($this->departments[$match[1]])){
465           $this->base= $this->departments[$match[1]]['dn'];
466         }
467       }
468     }
470     // Filter POST with "act" attributes -> posted from action menu
471     if (isset($_POST['exec_act']) && $_POST['act'] != '') {
472       if (preg_match('/^export.*$/', $_POST['act']) && isset($this->exporter[$_POST['act']])) {
473         $exporter= $this->exporter[$_POST['act']];
474         $userinfo= ", "._("created by")." ".$ui->cn." - ".strftime('%A, %d. %B %Y, %H:%M:%S');
475         $entryIterator= new listingSortIterator($this->entries, $this->sortDirection[$this->sortColumn], "_sort".$this->sortColumn, $this->sortType);
476         $sortedEntries= array();
477         foreach ($entryIterator as $entry){
478           $sortedEntries[]= $entry;
479         }
480         $instance= new $exporter['class']($this->headline.$userinfo, $this->plainHeader, $sortedEntries, $this->exportColumns);
481         $type= call_user_func(array($exporter['class'], "getInfo"));
482         $type= $type[$_POST['act']];
483         send_binary_content($instance->query(), $type['filename'], $type= $type['mime']);
484       }
485     }
487     // Filter GET with "act" attributes
488     if (isset($_GET['act'])) {
489       $key= validate($_GET['act']);
490       if (preg_match('/^SORT_([0-9]+)$/', $key, $match)) {
491         // Switch to new column or invert search order?
492         $column= $match[1];
493         if ($this->sortColumn != $column) {
494           $this->sortColumn= $column;
495         } else {
496           $this->sortDirection[$column]= !$this->sortDirection[$column];
497         }
499         // Allow header to update itself according to the new sort settings
500         $this->renderHeader();
501       }
502     }
504     // Override base if we got signals from the navigation elements
505     $action= "";
506     foreach ($_POST as $key => $value) {
507       if (preg_match('/^(ROOT|BACK|HOME)_x$/', $key, $match)) {
508         $action= $match[1];
509         break;
510       }
511     }
513     // Navigation handling
514     if ($action == 'ROOT') {
515       $deps= $ui->get_module_departments($this->module);
516       $this->base= $deps[0];
517     }
518     if ($action == 'BACK') {
519       $deps= $ui->get_module_departments($this->module);
520       $base= preg_replace("/^[^,]+,/", "", $this->base);
521       if(in_array_ics($base, $deps)){
522         $this->base= $base;
523       }
524     }
525     if ($action == 'HOME') {
526       $ui= get_userinfo();
527       $this->base= $this->filter->getObjectBase($ui->dn);
528     }
530     // Reload departments
531     if ($this->departmentBrowser){
532       $this->departments= $this->getDepartments();
533     }
535     // Update filter and refresh entries
536     $this->filter->setBase($this->base);
537     $this->entries= $this->filter->query();
538   }
541   function setBase($base)
542   {
543     $this->base= $base;
544   }
547   function getBase()
548   {
549     return $this->base;
550   }
553   function parseLayout($layout)
554   {
555     $result= array();
556     $layout= preg_replace("/^\|/", "", $layout);
557     $layout= preg_replace("/\|$/", "", $layout);
558     $cols= split("\|", $layout);
560     foreach ($cols as $index => $config) {
561       if ($config != "") {
562         $res= "";
563         $components= split(';', $config);
564         foreach ($components as $part) {
565           if (preg_match("/^r$/", $part)) {
566             $res.= "text-align:right;";
567             continue;
568           }
569           if (preg_match("/^l$/", $part)) {
570             $res.= "text-align:left;";
571             continue;
572           }
573           if (preg_match("/^c$/", $part)) {
574             $res.= "text-align:center;";
575             continue;
576           }
577           if (preg_match("/^[0-9]+(|px|%)$/", $part)) {
578             $res.= "width:$part;min-width:$part;";
579             continue;
580           }
581         }
583         // Add minimum width for scalable columns
584         if (!preg_match('/width:/', $res)){
585           $res.= "min-width:200px;";
586         }
588         $result[$index]= " style='$res' ";
589       } else {
590         $result[$index]= " style='min-width:100px'";
591       }
592     }
594     // Save number of columns for later use
595     $this->numColumns= count($cols);
597     return $result;
598   }
601   function renderCell($data, $config, $row)
602   {
603     // Replace flat attributes in data string
604     for ($i= 0; $i<$config['count']; $i++) {
605       $attr= $config[$i];
606       $value= "";
607       if (is_array($config[$attr])) {
608         $value= $config[$attr][0];
609       } else {
610         $value= $config[$attr];
611       }
612       $data= preg_replace("/%\{$attr\}/", $value, $data);
613     }
615     // Watch out for filters and prepare to execute them
616     $data= $this->processElementFilter($data, $config, $row);
618     // Replace all non replaced %{...} instances because they
619     // are non resolved attributes or filters
620     $data= preg_replace('/%{[^}]+}/', '&nbsp;', $data);
622     return $data;
623   }
626   function renderBase()
627   {
628     if (!$this->baseMode) {
629       return;
630     }
632     $result= "<select name='BASE' onChange='mainform.submit()' size='1'>";
633     $firstDN= null;
634     $found= false;
636     foreach ($this->bases as $key=>$value) {
637       // Keep first entry to fall back eventually
638       if(!$firstDN) {
639         $firstDN= $key;
640       }
642       // Prepare to render entry
643       $selected= "";
644       if ($key == $this->base) {
645         $selected= " selected";
646         $found= true;
647       }
648       $key = htmlentities($key,ENT_QUOTES);
649       $result.= "\n<option value=\"".$key."\"$selected>".$value."</option>";
650     }
652     $result.= "</select>";
654     // Reset the currently used base to the first DN we found if there
655     // was no match.
656     if(!$found){
657       $this->base = $firstDN;
658     }
660     return $result;
661   }
664   function processElementFilter($data, $config, $row)
665   {
666     preg_match_all("/%\{filter:([^(]+)\((.*)\)\}/", $data, $matches, PREG_SET_ORDER);
668     foreach ($matches as $match) {
669       $cl= "";
670       $method= "";
671       if (preg_match('/::/', $match[1])) {
672         $cl= preg_replace('/::.*$/', '', $match[1]);
673         $method= preg_replace('/^.*::/', '', $match[1]);
674       } else {
675         if (!isset($this->filters[$match[1]])) {
676           continue;
677         }
678         $cl= preg_replace('/::.*$/', '', $this->filters[$match[1]]);
679         $method= preg_replace('/^.*::/', '', $this->filters[$match[1]]);
680       }
682       // Prepare params for function call
683       $params= array();
684       preg_match_all('/"[^"]+"|[^,]+/', $match[2], $parts);
685       foreach ($parts[0] as $param) {
687         // Row is replaced by the row number
688         if ($param == "row") {
689           $params[]= $row;
690         }
692         // pid is replaced by the current PID
693         if ($param == "pid") {
694           $params[]= $this->pid;
695         }
697         // base is replaced by the current base
698         if ($param == "base") {
699           $params[]= $this->getBase();
700         }
702         // Fixie with "" is passed directly
703         if (preg_match('/^".*"$/', $param)){
704           $params[]= preg_replace('/"/', '', $param);
705         }
707         // LDAP variables get replaced by their objects
708         for ($i= 0; $i<$config['count']; $i++) {
709           if ($param == $config[$i]) {
710             $values= $config[$config[$i]];
711             if (is_array($values)){
712               unset($values['count']);
713             }
714             $params[]= $values;
715           }
716         }
718         // Move dn if needed
719         if ($param == "dn") {
720           $params[]= LDAP::fix($config["dn"]);
721         }
722       }
724       // Replace information
725       if ($cl == "listing") {
726         // Non static call - seems to result in errors
727         $data= @preg_replace('/'.preg_quote($match[0]).'/', call_user_func_array(array($this, "$method"), $params), $data);
728       } else {
729         // Static call
730         $data= preg_replace('/'.preg_quote($match[0]).'/', call_user_func_array(array($cl, $method), $params), $data);
731       }
732     }
734     return $data;
735   }
738   function getObjectType($types, $classes)
739   {
740     // Walk thru types and see if there's something matching
741     foreach ($types as $objectType) {
742       $ocs= $objectType['objectClass'];
743       if (!is_array($ocs)){
744         $ocs= array($ocs);
745       }
747       $found= true;
748       foreach ($ocs as $oc){
749         if (preg_match('/^!(.*)$/', $oc, $match)) {
750           $oc= $match[1];
751           if (in_array($oc, $classes)) {
752             $found= false;
753           }
754         } else {
755           if (!in_array($oc, $classes)) {
756             $found= false;
757           }
758         }
759       }
761       if ($found) {
762         return $objectType;
763       }
764     }
766     return null;
767   }
770   function filterObjectType($dn, $classes)
771   {
772     // Walk thru classes and return on first match
773     $result= "&nbsp;";
775     $objectType= $this->getObjectType($this->objectTypes, $classes);
776     if ($objectType) {
777       $this->objectDnMapping[$dn]= $objectType["objectClass"];
778       $result= "<img class='center' title='".LDAP::fix($dn)."' src='".$objectType["image"]."'>";
779       if (!isset($this->objectTypeCount[$objectType['label']])) {
780         $this->objectTypeCount[$objectType['label']]= 0;
781       }
782       $this->objectTypeCount[$objectType['label']]++;
783     }
785     return $result;
786   }
789   function filterActions($dn, $row, $classes)
790   {
791     // Do nothing if there's no menu defined
792     if (!isset($this->xmlData['actiontriggers']['action'])) {
793       return "&nbsp;";
794     }
796     // Go thru all actions
797     $result= "";
798     $actions= $this->xmlData['actiontriggers']['action'];
799     foreach($actions as $action) {
800       // Skip the entry completely if there's no permission to execute it
801       if (!$this->hasActionPermission($action, $dn)) {
802         $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
803         continue;
804       }
806       // Skip entry if the pseudo filter does not fit
807       if (isset($action['filter']) && preg_match('/^[a-z0-9_]+!?=[a-z0-9_]+$/i', $action['filter'])) {
808         list($fa, $fv)= split('=', $action['filter']);
809         if (preg_match('/^(.*)!$/', $fa, $m)){
810           $fa= $m[1];
811           if (isset($this->entries[$row][$fa]) && $this->entries[$row][$fa][0] == $fv) {
812             $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
813             continue;
814           }
815         } else {
816           if (!isset($this->entries[$row][$fa]) && !$this->entries[$row][$fa][0] == $fv) {
817             $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
818             continue;
819           }
820         }
821       }
824       // If there's an objectclass definition and we don't have it
825       // add an empty picture here.
826       if (isset($action['objectclass'])){
827         $objectclass= $action['objectclass'];
828         if (preg_match('/^!(.*)$/', $objectclass, $m)){
829           $objectclass= $m[1];
830           if(in_array($objectclass, $classes)) {
831             $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
832             continue;
833           }
834         } else {
835           if(!in_array($objectclass, $classes)) {
836             $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
837             continue;
838           }
839         }
840       }
842       // Render normal entries as usual
843       if ($action['type'] == "entry") {
844         $label= $this->processElementFilter($action['label'], $this->entries[$row], $row);
845         $image= $this->processElementFilter($action['image'], $this->entries[$row], $row);
846         $result.="<input class='center' type='image' src='$image' title='$label' ".
847                  "name='listing_".$action['name']."_$row' style='padding:1px'>";
848       }
850       // Handle special types
851       if ($action['type'] == "copypaste" || $action['type'] == "snapshot") {
853         $objectType= $this->getObjectType($this->objectTypes, $this->entries[$row]['objectClass']);
854         $category= $class= null;
855         if ($objectType) {
856           $category= $objectType['category'];
857           $class= $objectType['class'];
858         }
860         if ($action['type'] == "copypaste") {
861           $result.= $this->renderCopyPasteActions($row, $this->entries[$row]['dn'], $category, $class);
862         } else {
863           $result.= $this->renderSnapshotActions($row, $this->entries[$row]['dn'], $category, $class);
864         }
865       }
866     }
868     return $result;
869   }
872   function filterDepartmentLink($row, $dn, $description)
873   {
874     $attr= $this->departments[$row]['sort-attribute'];
875     $name= $this->departments[$row][$attr];
876     if (is_array($name)){
877       $name= $name[0];
878     }
879     $result= sprintf("%s [%s]", $name, $description[0]);
880     return("<a href='?plug=".$_GET['plug']."&amp;PID=$this->pid&amp;act=department_$row' title='$dn'>$result</a>");
881   }
884   function filterLink()
885   {
886     $result= "&nbsp;";
888     $row= func_get_arg(0);
889     $pid= $this->pid;
890     $dn= LDAP::fix(func_get_arg(1));
891     $params= array(func_get_arg(2));
893     // Collect sprintf params
894     for ($i = 3;$i < func_num_args();$i++) {
895       $val= func_get_arg($i);
896       if (is_array($val)){
897         $params[]= $val[0];
898         continue;
899       }
900       $params[]= $val;
901     }
903     $result= "&nbsp;";
904     $trans= call_user_func_array("sprintf", $params);
905     if ($trans != "") {
906       return("<a href='?plug=".$_GET['plug']."&amp;PID=$pid&amp;act=listing_edit_$row' title='$dn'>$trans</a>");
907     }
909     return $result;
910   }
913   function renderNavigation()
914   {
915     $result= array();
916     $enableBack = true;
917     $enableRoot = true;
918     $enableHome = true;
920     $ui = get_userinfo();
922     /* Check if base = first available base */
923     $deps = $ui->get_module_departments($this->module);
925     if(!count($deps) || $deps[0] == $this->filter->base){
926       $enableBack = false;
927       $enableRoot = false;
928     }
930     $listhead ="";
932     /* Check if we are in users home  department */
933     if(!count($deps) || $this->filter->base == $this->filter->getObjectBase($ui->dn)){
934       $enableHome = false;
935     }
937     /* Draw root button */
938     if($enableRoot){
939       $result["ROOT"]= "<input class='center' type='image' src='images/lists/root.png' align='middle' ".
940                        "title='"._("Go to root department")."' name='ROOT' alt='"._("Root")."'>";
941     }else{
942       $result["ROOT"]= "<img src='images/lists/root_grey.png' class='center' alt='"._("Root")."'>";
943     }
945     /* Draw back button */
946     if($enableBack){
947       $result["BACK"]= "<input class='center' type='image' align='middle' src='images/lists/back.png' ".
948                        "title='"._("Go up one department")."' alt='"._("Up")."' name='BACK'>";
949     }else{
950       $result["BACK"]= "<img src='images/lists/back_grey.png' class='center' alt='"._("Up")."'>";
951     }
953     /* Draw home button */
954     if($enableHome){
955       $result["HOME"]= "<input class='center' type='image' align='middle' src='images/lists/home.png' ".
956                        "title='"._("Go to users department")."' alt='"._("Home")."' name='HOME'>";
957     }else{
958       $result["HOME"]= "<img src='images/lists/home_grey.png' class='center' alt='"._("Home")."'>";
959     }
961     /* Draw reload button, this button is enabled everytime */
962     $result["RELOAD"]= "<input class='center' type='image' src='images/lists/reload.png' align='middle' ".
963                        "title='"._("Reload list")."' name='REFRESH' alt='"._("Submit")."'>";
965     return ($result);
966   }
969   function getAction()
970   {
971     // Do not do anything if this is not our PID, or there's even no PID available...
972     if(!isset($_REQUEST['PID']) || $_REQUEST['PID'] != $this->pid) {
973       return;
974     }
976     $result= array("targets" => array(), "action" => "");
978     // Filter GET with "act" attributes
979     if (isset($_GET['act'])) {
980       $key= validate($_GET['act']);
981       $target= preg_replace('/^listing_[a-zA-Z_]+_([0-9]+)$/', '$1', $key);
982       if (isset($this->entries[$target]['dn'])) {
983         $result['action']= preg_replace('/^listing_([a-zA-Z_]+)_[0-9]+$/', '$1', $key);
984         $result['targets'][]= $this->entries[$target]['dn'];
985       }
987       // Drop targets if empty
988       if (count($result['targets']) == 0) {
989         unset($result['targets']);
990       }
991       return $result;
992     }
994     // Filter POST with "listing_" attributes
995     foreach ($_POST as $key => $prop) {
997       // Capture selections
998       if (preg_match('/^listing_selected_[0-9]+$/', $key)) {
999         $target= preg_replace('/^listing_selected_([0-9]+)$/', '$1', $key);
1000         if (isset($this->entries[$target]['dn'])) {
1001           $result['targets'][]= $this->entries[$target]['dn'];
1002         }
1003         continue;
1004       }
1006       // Capture action with target - this is a one shot
1007       if (preg_match('/^listing_[a-zA-Z_]+_[0-9]+(|_x)$/', $key)) {
1008         $target= preg_replace('/^listing_[a-zA-Z_]+_([0-9]+)(|_x)$/', '$1', $key);
1009         if (isset($this->entries[$target]['dn'])) {
1010           $result['action']= preg_replace('/^listing_([a-zA-Z_]+)_[0-9]+(|_x)$/', '$1', $key);
1011           $result['targets']= array($this->entries[$target]['dn']);
1012         }
1013         break;
1014       }
1016       // Capture action without target
1017       if (preg_match('/^listing_[a-zA-Z_]+(|_x)$/', $key)) {
1018         $result['action']= preg_replace('/^listing_([a-zA-Z_]+)(|_x)$/', '$1', $key);
1019         continue;
1020       }
1021     }
1023     // Filter POST with "act" attributes -> posted from action menu
1024     if (isset($_POST['act']) && $_POST['act'] != '') {
1025       if (!preg_match('/^export.*$/', $_POST['act'])){
1026         $result['action']= validate($_POST['act']);
1027       }
1028     }
1030     // Drop targets if empty
1031     if (count($result['targets']) == 0) {
1032       unset($result['targets']);
1033     }
1034     return $result;
1035   }
1038   function renderActionMenu()
1039   {
1040     // Don't send anything if the menu is not defined
1041     if (!isset($this->xmlData['actionmenu']['action'])){
1042       return "";
1043     }
1045     // Array?
1046     if (isset($this->xmlData['actionmenu']['action']['type'])){
1047       $this->xmlData['actionmenu']['action']= array($this->xmlData['actionmenu']['action']);
1048     }
1050     // Load shortcut
1051     $actions= &$this->xmlData['actionmenu']['action'];
1052     $result= "<input type='hidden' name='act' id='actionmenu' value=''><div style='display:none'><input type='submit' name='exec_act' id='exec_act' value=''></div>".
1053              "<ul class='level1' id='root'><li><a href='#'>"._("Actions")."&nbsp;<img ".
1054              "border=0 class='center' src='images/lists/sort-down.png'></a>";
1056     // Build ul/li list
1057     $result.= $this->recurseActions($actions);
1059     return "<div id='pulldown'>".$result."</li></ul><div>";
1060   }
1063   function recurseActions($actions)
1064   {
1065     global $class_mapping;
1066     static $level= 2;
1067     $result= "<ul class='level$level'>";
1068     $separator= "";
1070     foreach ($actions as $action) {
1072       // Skip the entry completely if there's no permission to execute it
1073       if (!$this->hasActionPermission($action, $this->filter->base)) {
1074         continue;
1075       }
1077       // Skip entry if there're missing dependencies
1078       if (isset($action['depends'])) {
1079         $deps= is_array($action['depends'])?$action['depends']:array($action['depends']);
1080         foreach($deps as $clazz) {
1081           if (!isset($class_mapping[$clazz])){
1082             continue 2;
1083           }
1084         }
1085       }
1087       // Fill image if set
1088       $img= "";
1089       if (isset($action['image'])){
1090         $img= "<img border='0' class='center' src='".$action['image']."'>&nbsp;";
1091       }
1093       if ($action['type'] == "separator"){
1094         $separator= " style='border-top:1px solid #AAA' ";
1095         continue;
1096       }
1098       // Dive into subs
1099       if ($action['type'] == "sub" && isset($action['action'])) {
1100         $level++;
1101         if (isset($action['label'])){
1102           $result.= "<li$separator><a href='#'>$img"._($action['label'])."&nbsp;<img border='0' src='images/forward-arrow.png'></a>";
1103         }
1105         // Ensure we've an array of actions, this enables sub menus with only one action.
1106         if(isset($action['action']['type'])){
1107           $action['action'] = array($action['action']);
1108         }
1110         $result.= $this->recurseActions($action['action'])."</li>";
1111         $level--;
1112         $separator= "";
1113         continue;
1114       }
1116       // Render entry elseways
1117       if (isset($action['label'])){
1118         $result.= "<li$separator><a href='#' onClick='document.getElementById(\"actionmenu\").value= \"".$action['name']."\";mainform.submit();'>$img"._($action['label'])."</a></li>";
1119       }
1121       // Check for special types
1122       switch ($action['type']) {
1123         case 'copypaste':
1124           $result.= $this->renderCopyPasteMenu($separator);
1125           break;
1127         case 'snapshot':
1128           $result.= $this->renderSnapshotMenu($separator);
1129           break;
1131         case 'exporter':
1132           $result.= $this->renderExporterMenu($separator);
1133           break;
1135         case 'daemon':
1136           $result.= $this->renderDaemonMenu($separator);
1137           break;
1138       }
1140       $separator= "";
1141     }
1143     $result.= "</ul>";
1144     return $result;
1145   }
1148   function hasActionPermission($action, $dn)
1149   {
1150     $ui= get_userinfo();
1152     if (isset($action['acl'])) {
1153       $acls= $action['acl'];
1154       if (!is_array($acls)) {
1155         $acls= array($acls);
1156       }
1158       // Every ACL has to pass
1159       foreach ($acls as $acl) {
1160         $module= $this->module;
1161         $aclList= array();
1163         // Split for category and plugins if needed
1164         // match for "[rw]" style entries
1165         if (preg_match('/^\[([rwcdm]+)\]$/', $acl, $match)){
1166           $aclList= array($match[1]);
1167         }
1169         // match for "users[rw]" style entries
1170         if (preg_match('/^([a-zA-Z0-9]+)\[([rwcdm]+)\]$/', $acl, $match)){
1171           $module= $match[1];
1172           $aclList= array($match[2]);
1173         }
1175         // match for "users/user[rw]" style entries
1176         if (preg_match('/^([a-zA-Z0-9]+\/[a-zA-Z0-9]+)\[([rwcdm]+)\]$/', $acl, $match)){
1177           $module= $match[1];
1178           $aclList= array($match[2]);
1179         }
1181         // match "users/user[userPassword:rw(,...)*]" style entries
1182         if (preg_match('/^([a-zA-Z0-9]+\/[a-zA-Z0-9]+)\[([a-zA-Z0-9]+:[rwcdm]+(,[a-zA-Z0-9]+:[rwcdm]+)*)\]$/', $acl, $match)){
1183           $module= $match[1];
1184           $aclList= split(',', $match[2]);
1185         }
1187         // Walk thru prepared ACL by using $module
1188         foreach($aclList as $sAcl) {
1189           $checkAcl= "";
1191           // Category or detailed permission?
1192           if (strpos('/', $module) === false) {
1193             if (preg_match('/([a-zA-Z0-9]+):([rwcdm]+)/', $sAcl, $m) ) {
1194               $checkAcl= $ui->get_permissions($dn, $module, $m[1]);
1195               $sAcl= $m[2];
1196             } else {
1197               $checkAcl= $ui->get_permissions($dn, $module, '0');
1198             }
1199           } else {
1200             $checkAcl= $ui->get_category_permissions($dn, $module);
1201           }
1203           // Split up remaining part of the acl and check if it we're
1204           // allowed to do something...
1205           $parts= str_split($sAcl);
1206           foreach ($parts as $part) {
1207             if (strpos($checkAcl, $part) === false){
1208               return false;
1209             }
1210           }
1212         }
1213       }
1214     }
1216     return true;
1217   }
1220   function refreshBasesList()
1221   {
1222     global $config;
1223     $ui= get_userinfo();
1225     // Do some array munching to get it user friendly
1226     $ids= $config->idepartments;
1227     $d= $ui->get_module_departments($this->module);
1228     $k_ids= array_keys($ids);
1229     $deps= array_intersect($d,$k_ids);
1231     // Fill internal bases list
1232     $this->bases= array();
1233     foreach($k_ids as $department){
1234       $this->bases[$department] = $ids[$department];
1235     }
1236   }
1239   function getDepartments()
1240   {
1241     $departments= array();
1242     $ui= get_userinfo();
1244     // Get list of supported department types
1245     $types = departmentManagement::get_support_departments();
1247     // Load departments allowed by ACL
1248     $validDepartments = $ui->get_module_departments($this->module);
1250     // Build filter and look in the LDAP for possible sub departments
1251     // of current base
1252     $filter= "(&(objectClass=gosaDepartment)(|";
1253     $attrs= array("description", "objectClass");
1254     foreach($types as $name => $data){
1255       $filter.= "(objectClass=".$data['OC'].")";
1256       $attrs[]= $data['ATTR'];
1257     }
1258     $filter.= "))";
1259     $res= get_list($filter, $this->module, $this->base, $attrs, GL_NONE);
1261     // Analyze list of departments
1262     foreach ($res as $department) {
1263       if (!in_array($department['dn'], $validDepartments)) {
1264         continue;
1265       }
1267       // Add the attribute where we use for sorting
1268       $oc= null;
1269       foreach(array_keys($types) as $type) {
1270         if (in_array($type, $department['objectClass'])) {
1271           $oc= $type;
1272           break;
1273         }
1274       }
1275       $department['sort-attribute']= $types[$oc]['ATTR'];
1277       // Move to the result list
1278       $departments[]= $department;
1279     }
1281     return $departments;
1282   }
1285   function renderCopyPasteMenu($separator, $copy= true, $cut= true)
1286   {
1287     // We can only provide information if we've got a copypaste handler
1288     // instance
1289     if(!(isset($this->copyPasteHandler) && is_object($this->copyPasteHandler))){
1290       return "";
1291     }
1293     // Presets
1294     $result= "";
1295     $read= $paste= false;
1296     $ui= get_userinfo();
1298     // Switch flags to on if there's at least one category which allows read/paste
1299     foreach($this->categories as $category){
1300       $read= $read || preg_match('/r/', $ui->get_category_permissions($this->base, $category));
1301       $paste= $paste || $ui->is_pasteable($this->base, $category) == 1;
1302     }
1305     // Draw entries that allow copy and cut
1306     if($read){
1308       // Copy entry
1309       if($copy){
1310         $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>";
1311         $separator= "";
1312       }
1314       // Cut entry
1315       if($cut){
1316         $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>";
1317         $separator= "";
1318       }
1319     }
1321     // Draw entries that allow pasting entries
1322     if($paste){
1323       if($this->copyPasteHandler->entries_queued()){
1324         $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>";
1325       }else{
1326         $result.= "<li$separator><a href='#'><img src='images/lists/paste-grey.png' alt='' border='0' class='center'>&nbsp;"._("Paste")."</a></li>";
1327       }
1328     }
1329     
1330     return($result);
1331   }
1334   function renderCopyPasteActions($row, $dn, $category, $class, $copy= true, $cut= true)
1335   {
1336     // We can only provide information if we've got a copypaste handler
1337     // instance
1338     if(!(isset($this->copyPasteHandler) && is_object($this->copyPasteHandler))){
1339       return "";
1340     }
1342     // Presets
1343     $ui = get_userinfo();
1344     $result = "";
1346     // Render cut entries
1347     if($cut){
1348       if($ui->is_cutable($dn, $category, $class)){
1349         $result .= "<input class='center' type='image'
1350           src='images/lists/cut.png' alt='"._("Cut")."' name='listing_cut_$row' title='"._("Cut this entry")."' style='padding:1px'>";
1351       }else{
1352         $result.="<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
1353       }
1354     }
1356     // Render copy entries
1357     if($copy){
1358       if($ui->is_copyable($dn, $category, $class)){
1359         $result.= "<input class='center' type='image'
1360           src='images/lists/copy.png' alt='"._("Copy")."' name='listing_copy_$row' title='"._("Copy this entry")."' style='padding:1px'>";
1361       }else{
1362         $result.="<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
1363       }
1364     }
1366     return($result);
1367   }
1370   function renderSnapshotMenu($separator)
1371   {
1372     // We can only provide information if we've got a snapshot handler
1373     // instance
1374     if(!(isset($this->snapshotHandler) && is_object($this->snapshotHandler))){
1375       return "";
1376     }
1378     // Presets
1379     $result = "";
1380     $ui = get_userinfo();
1382     if($this->snapshotHandler->enabled() && $ui->allow_snapshot_restore($this->base, $this->module)){
1384       // Check if there is something to restore
1385       $restore= false;
1386       foreach($this->snapshotHandler->getSnapshotBases() as $base){
1387         $restore= $restore || count($this->snapshotHandler->getDeletedSnapshots($base)) > 0;
1388       }
1390       // Draw icons according to the restore flag
1391       if($restore){
1392         $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>";
1393       }else{
1394         $result.= "<li$separator><a href='#'><img src='images/lists/restore_grey.png' alt='' border='0' class='center'>&nbsp;"._("Restore snapshots")."</a></li>";
1395       }
1396     }
1398     return($result);
1399   }
1402   function renderExporterMenu($separator)
1403   {
1404     // Presets
1405     $result = "";
1407     // Draw entries
1408     $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'>";
1410     // Export CVS as build in exporter
1411     foreach ($this->exporter as $action => $exporter) {
1412       $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>";
1413     }
1415     // Finalize list
1416     $result.= "</ul></li>";
1418     return($result);
1419   }
1422   function renderSnapshotActions($row, $dn, $category, $class, $copy= true, $cut= true)
1423   {
1424     // We can only provide information if we've got a snapshot handler
1425     // instance
1426     if(!(isset($this->snapshotHandler) && is_object($this->snapshotHandler))){
1427       return "";
1428     }
1430     // Presets
1431     $result= "";
1432     $ui = get_userinfo();
1434     // Only act if enabled here
1435     if($this->snapshotHandler->enabled()){
1437       // Draw restore button
1438       if ($ui->allow_snapshot_restore($dn, $category)){
1440         // Do we have snapshots for this dn?
1441         if($this->snapshotHandler->hasSnapshots($dn)){
1442           $result.= "<input class='center' type='image' src='images/lists/restore.png' ".
1443                      "alt='"._("Restore snapshot")."' name='listing_restore_$row' title='".
1444                      _("Restore snapshot")."' style='padding:1px'>";
1445         } else {
1446           $result.= "<img src='images/lists/restore_grey.png' alt=' ' class='center' style='padding:1px'>";
1447         }
1448       }
1450       // Draw snapshot button
1451       if($ui->allow_snapshot_create($dn, $category)){
1452           $result.= "<input class='center' type='image' src='images/snapshot.png' ".
1453                      "alt='"._("Create snapshot")."' name='listing_snapshot_$row' title='".
1454                      _("Create a new snapshot from this object")."' style='padding:1px'>";
1455       }else{
1456           $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
1457       }
1458     }
1460     return($result);
1461   }
1464   function renderDaemonMenu($separator)
1465   {
1466     $result= "";
1468     // If there is a daemon registered, draw the menu entries
1469     if(class_available("DaemonEvent")){
1470       $events= DaemonEvent::get_event_types_by_category($this->categories);
1471       if(isset($events['BY_CLASS']) && count($events['BY_CLASS'])){
1472         foreach($events['BY_CLASS'] as $name => $event){
1473           $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>";
1474           $separator= "";
1475         }
1476       }
1477     }
1479     return $result;
1480   }
1483   function getType($dn)
1484   {
1485     if (isset($this->objectDnMapping[$dn])) {
1486       return $this->objectDnMapping[$dn];
1487     }
1488     return null;
1489   }
1493 ?>