Code

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