Code

Reverted filter editor changes. will move the editor into the listing.
[gosa.git] / gosa-core / include / class_listing.inc
1 <?php
2 /*
3  * This code is part of GOsa (http://www.gosa-project.org)
4  * Copyright (C) 2003-2008 GONICUS GmbH
5  *
6  * ID: $$Id$$
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
23 class listing {
25   var $xmlData;
26   var $entries;
27   var $departments= array();
28   var $departmentBrowser= false;
29   var $departmentRootVisible= false;
30   var $multiSelect= false;
31   var $template;
32   var $headline;
33   var $base;
34   var $sortDirection= null;
35   var $sortColumn= null;
36   var $sortAttribute;
37   var $sortType;
38   var $numColumns;
39   var $baseMode= false;
40   var $bases= array();
41   var $header= array();
42   var $colprops= array();
43   var $filters= array();
44   var $filter= null;
45   var $pid;
46   var $objectTypes= array();
47   var $objectTypeCount= array();
48   var $objectDnMapping= array();
49   var $copyPasteHandler= null;
50   var $snapshotHandler= null;
51   var $exporter= array();
52   var $exportColumns= array();
53   var $useSpan= false;
54   var $height= 0;
55   var $scrollPosition= 0;
56   var $baseSelector;
59   function listing($filename)
60   {
61     global $config;
62     global $class_mapping;
64     // Initialize pid
65     $this->pid= preg_replace("/[^0-9]/", "", microtime(TRUE));
67     if (!$this->load($filename)) {
68       die("Cannot parse $filename!");
69     }
71     // Set base for filter
72     if ($this->baseMode) {
73       $this->base= session::global_get("CurrentMainBase");
74       if ($this->base == null) {
75         $this->base= $config->current['BASE'];
76       }
77       $this->refreshBasesList();
78     } else {
79       $this->base= $config->current['BASE'];
80     }
82     // Move footer information
83     $this->showFooter= ($config->get_cfg_value("listSummary") == "true");
85     // Register build in filters
86     $this->registerElementFilter("objectType", "listing::filterObjectType");
87     $this->registerElementFilter("departmentLink", "listing::filterDepartmentLink");
88     $this->registerElementFilter("link", "listing::filterLink");
89     $this->registerElementFilter("actions", "listing::filterActions");
91     // Load exporters
92     foreach($class_mapping as $class => $dummy) {
93       if (preg_match('/Exporter$/', $class)) {
94         $info= call_user_func(array($class, "getInfo"));
95         if ($info != null) {
96           $this->exporter= array_merge($this->exporter, $info);
97         }
98       }
99     }
101     // Instanciate base selector
102     $this->baseSelector= new baseSelector($this->bases, $this->base);
103   }
106   function setCopyPasteHandler($handler)
107   {
108     $this->copyPasteHandler= &$handler;
109   }
112   function setHeight($height)
113   {
114     $this->height= $height;
115   }
118   function setSnapshotHandler($handler)
119   {
120     $this->snapshotHandler= &$handler;
121   }
124   function setFilter($filter)
125   {
126     $filter->setCategories($this->categories);
127     $this->filter= &$filter;
128     if ($this->departmentBrowser){
129       $this->departments= $this->getDepartments();
130     }
131     $this->filter->setBase($this->base);
132   }
135   function registerElementFilter($name, $call)
136   {
137     if (!isset($this->filters[$name])) {
138       $this->filters[$name]= $call;
139       return true;
140     }
142     return false;
143   }
146   function load($filename)
147   {
148     $contents = file_get_contents($filename);
149     $this->xmlData= xml::xml2array($contents, 1);
151     if (!isset($this->xmlData['list'])) {
152       return false;
153     }
155     $this->xmlData= $this->xmlData["list"];
157     // Load some definition values
158     foreach (array("departmentBrowser", "departmentRootVisible", "multiSelect", "baseMode") as $token) {
159       if (isset($this->xmlData['definition'][$token]) &&
160           $this->xmlData['definition'][$token] == "true"){
161         $this->$token= true;
162       }
163     }
165     // Fill objectTypes from departments and xml definition
166     $types = departmentManagement::get_support_departments();
167     foreach ($types as $class => $data) {
168       $this->objectTypes[$data['OC']]= array("label" => $data['TITLE'],
169                                   "objectClass" => $data['OC'],
170                                   "image" => $data['IMG']);
171     }
172     $this->categories= array();
173     if (isset($this->xmlData['definition']['objectType'])) {
174       if(isset($this->xmlData['definition']['objectType']['label'])) {
175         $this->xmlData['definition']['objectType']= array($this->xmlData['definition']['objectType']);
176       }
177       foreach ($this->xmlData['definition']['objectType'] as $index => $otype) {
178         $tmp = $this->xmlData['definition']['objectType'][$index];
179         $this->objectTypes[$tmp['objectClass']]= $tmp;
180         if (isset($this->xmlData['definition']['objectType'][$index]['category'])){
181           $this->categories[]= $otype['category'];
182         }
183       }
184     }
185     $this->objectTypes = array_values($this->objectTypes);
187     // Parse layout per column
188     $this->colprops= $this->parseLayout($this->xmlData['table']['layout']);
190     // Prepare table headers
191     $this->renderHeader();
193     // Assign headline/Categories
194     $this->headline= _($this->xmlData['definition']['label']);
195     if (!is_array($this->categories)){
196       $this->categories= array($this->categories);
197     }
199     // Evaluate columns to be exported
200     if (isset($this->xmlData['table']['column'])){
201       foreach ($this->xmlData['table']['column'] as $index => $config) {
202         if (isset($config['export']) && $config['export'] == "true"){
203           $this->exportColumns[]= $index;
204         }
205       }
206     }
208     return true;  
209   }
212   function renderHeader()
213   {
214     $this->header= array();
215     $this->plainHeader= array();
217     // Initialize sort?
218     $sortInit= false;
219     if (!$this->sortDirection) {
220       $this->sortColumn= 0;
221       if (isset($this->xmlData['definition']['defaultSortColumn'])){
222         $this->sortColumn= $this->xmlData['definition']['defaultSortColumn'];
223       } else {
224         $this->sortAttribute= "";
225       }
226       $this->sortDirection= array();
227       $sortInit= true;
228     }
230     if (isset($this->xmlData['table']['column'])){
231       foreach ($this->xmlData['table']['column'] as $index => $config) {
232         // Initialize everything to one direction
233         if ($sortInit) {
234           $this->sortDirection[$index]= false;
235         }
237         $sorter= "";
238         if ($index == $this->sortColumn && isset($config['sortAttribute']) &&
239             isset($config['sortType'])) {
240           $this->sortAttribute= $config['sortAttribute'];
241           $this->sortType= $config['sortType'];
242           $sorter= "&nbsp;".image("images/lists/sort-".($this->sortDirection[$index]?"up":"down").".png", null, $this->sortDirection[$index]?_("Up"):_("Down"), "text-top");
243         }
244         $sortable= (isset($config['sortAttribute']));
246         $link= "href='?plug=".$_GET['plug']."&amp;PID=".$this->pid."&amp;act=SORT_$index'";
247         if (isset($config['label'])) {
248           if ($sortable) {
249             $this->header[$index]= "<td class='listheader' ".$this->colprops[$index]."><a $link>"._($config['label'])."</a>$sorter</td>";
250           } else {
251             $this->header[$index]= "<td class='listheader' ".$this->colprops[$index].">"._($config['label'])."</td>";
252           }
253           $this->plainHeader[]= _($config['label']);
254         } else {
255           if ($sortable) {
256             $this->header[$index]= "<td class='listheader' ".$this->colprops[$index]."><a $link>&nbsp;</a>$sorter</td>";
257           } else {
258             $this->header[$index]= "<td class='listheader' ".$this->colprops[$index].">&nbsp;</td>";
259           }
260           $this->plainHeader[]= "";
261         }
262       }
263     }
264   }
267   function render()
268   {
269     // Check for exeeded sizelimit
270     if (($message= check_sizelimit()) != ""){
271       return($message);
272     }
274     // Display filter editor
275     if(0) 
276     return($this->filter->filterEditor->execute());
278     // Some browsers don't have the ability do do scrollable table bodies, filter them
279     // here.
280     $switch= false;
281     if (preg_match('/(Opera|Konqueror|Safari)/i', $_SERVER['HTTP_USER_AGENT'])){
282       $switch= true;
283     }
285     // Initialize list
286     $result= "<input type='hidden' value='$this->pid' name='PID'>\n";
287     $result.= "<input type='hidden' name='position_".$this->pid."' id='position_".$this->pid."'>\n";
288     $height= 450;
289     if ($this->height != 0) {
290       $result.= "<input type='hidden' value='$this->height' id='d_height'>\n";
291       $height= $this->height;
292     }
293     
294     $result.= "<div class='listContainer' id='d_scrollbody' style='min-height:".($height+25)."px;'>\n";
295     $result.= "<table summary='$this->headline' style='width:100%;table-layout:fixed' cellspacing='0' cellpadding='0' id='t_scrolltable'>\n";
296     $this->numColumns= count($this->colprops) + ($this->multiSelect?1:0);
298     // Build list header
299     $result.= "<thead class='fixedListHeader listHeaderFormat'><tr>\n";
300     if ($this->multiSelect) {
301       $width= "24px";
302       if (preg_match('/Konqueror/i', $_SERVER['HTTP_USER_AGENT'])){
303         $width= "28px";
304       }
305       $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";
306     }
307     foreach ($this->header as $header) {
308       $result.= $header;
309     }
310     $result.= "</tr></thead>\n";
312     // Build list body
313     $result.= "<tbody class='listScrollContent listBodyFormat' id='t_nscrollbody' style='height:".$height."px;'>\n";
315     // No results? Just take an empty colspanned row
316     if (count($this->entries) + count($this->departments) == 0) {
317       $result.= "<tr><td class='list1nohighlight' colspan='$this->numColumns' style='height:100%;border-right:0px;width:100%;'>&nbsp;</td></tr>";
318     }
320     // Line color alternation
321     $alt= 0;
322     $deps= 0;
324     // Draw department browser if configured and we're not in sub mode
325     $this->useSpan= false;
326     if ($this->departmentBrowser && $this->filter->scope != "sub") {
327       // Fill with department browser if configured this way
328       $departmentIterator= new departmentSortIterator($this->departments, $this->sortDirection[$this->sortColumn]);
329       foreach ($departmentIterator as $row => $entry){
330         $result.="<tr>";
332         // Render multi select if needed
333         if ($this->multiSelect) {
334           $result.="<td style='text-align:center;padding:0;' class='list1'>&nbsp;</td>";
335         }
337         // Render defined department columns, fill the rest with some stuff
338         $rest= $this->numColumns - 1;
339         foreach ($this->xmlData['table']['department'] as $index => $config) {
340           $colspan= 1;
341           if (isset($config['span'])){
342             $colspan= $config['span'];
343             $this->useSpan= true;
344           }
345           $result.="<td colspan='$colspan' ".$this->colprops[$index]." class='list1'>".$this->renderCell($config['value'], $entry, $row)."</td>";
346           $rest-= $colspan;
347         }
349         // Fill remaining cols with nothing
350         $last= $this->numColumns - $rest;
351         for ($i= 0; $i<$rest; $i++){
352           $result.= "<td ".$this->colprops[$last+$i-1]." class='list1'>&nbsp;</td>";
353         }
354         $result.="</tr>";
356         $alt++;
357       }
358       $deps= $alt;
359     }
361     // Fill with contents, sort as configured
362     foreach ($this->entries as $row => $entry) {
363       $trow= "";
365       // Render multi select if needed
366       if ($this->multiSelect) {
367         $trow.="<td style='text-align:center;width:20px;' class='list0'><input type='checkbox' id='listing_selected_$row' name='listing_selected_$row'></td>\n";
368       }
370       foreach ($this->xmlData['table']['column'] as $index => $config) {
371         $renderedCell= $this->renderCell($config['value'], $entry, $row);
372         $trow.="<td ".$this->colprops[$index]." class='list0'>".$renderedCell."</td>\n";
374         // Save rendered column
375         $sort= preg_replace('/.*>([^<]+)<.*$/', '$1', $renderedCell);
376         $sort= preg_replace('/&nbsp;/', '', $sort);
377         if (preg_match('/</', $sort)){
378           $sort= "";
379         }
380         $this->entries[$row]["_sort$index"]= $sort;
381       }
383       // Save rendered entry
384       $this->entries[$row]['_rendered']= $trow;
385     }
387     // Complete list by sorting entries for _sort$index and appending them to the output
388     $entryIterator= new listingSortIterator($this->entries, $this->sortDirection[$this->sortColumn], "_sort".$this->sortColumn, $this->sortType);
389     foreach ($entryIterator as $row => $entry){
390       $result.="<tr>\n";
391       $result.= $entry['_rendered'];
392       $result.="</tr>\n";
393       $alt++;
394     }
396     // Need to fill the list if it's not full (nobody knows why this is 22 ;-))
397     $emptyListStyle= (count($this->entries) + (($this->useSpan && count($this->entries))?$deps:0) == 0)?"border:0;":"";
398     if ((count($this->entries) + $deps) < 22) {
399       $result.= "<tr>";
400       for ($i= 0; $i<$this->numColumns; $i++) {
401         if ($i == 0) {
402           $result.= "<td class='list1nohighlight' style='$emptyListStyle height:100%;'>&nbsp;</td>";
403           continue;
404         }
405         if ($i != $this->numColumns-1) {
406           $result.= "<td class='list1nohighlight' style='$emptyListStyle'>&nbsp;</td>";
407         } else {
408           $result.= "<td class='list1nohighlight' style='border-right:0;$emptyListStyle'>&nbsp;</td>";
409         }
410       }
411       $result.= "</tr>";
412     }
414     // Close list body
415     $result.= "</tbody></table></div>";
417     // Add the footer if requested
418     if ($this->showFooter) {
419       $result.= "<div class='nlistFooter'><div style='padding:3px'>";
421       foreach ($this->objectTypes as $objectType) {
422         if (isset($this->objectTypeCount[$objectType['label']])) {
423           $label= _($objectType['label']);
424           $result.= image($objectType['image'], null, $label)."&nbsp;".$this->objectTypeCount[$objectType['label']]."&nbsp;&nbsp;";
425         }
426       }
428       $result.= "</div></div>";
429     }
431     // Close list
432     $result.= $switch?"<input type='hidden' id='list_workaround'>":"";
434     // Add scroll positioner
435     $result.= '<script type="text/javascript" language="javascript">';
436     $result.= '$("t_nscrollbody").scrollTop= '.$this->scrollPosition.';';
437     $result.= 'var box = $("t_nscrollbody").onscroll= function() {$("position_'.$this->pid.'").value= this.scrollTop;}';
438     $result.= '</script>';
440     $smarty= get_smarty();
441     $smarty->assign("usePrototype", "true");
442     $smarty->assign("FILTER", $this->filter->render());
443     $smarty->assign("SIZELIMIT", print_sizelimit_warning());
444     $smarty->assign("LIST", $result);
446     // Assign navigation elements
447     $nav= $this->renderNavigation();
448     foreach ($nav as $key => $html) {
449       $smarty->assign($key, $html);
450     }
452     // Assign action menu / base
453     $smarty->assign("ACTIONS", $this->renderActionMenu());
454     $smarty->assign("BASE", $this->renderBase());
456     // Assign separator
457     $smarty->assign("SEPARATOR", "<img src='images/lists/seperator.png' alt='-' align='middle' height='16' width='1' class='center'>");
459     // Assign summary
460     $smarty->assign("HEADLINE", $this->headline);
462     // Try to load template from plugin the folder first...
463     $file = get_template_path($this->xmlData['definition']['template'], true);
465     // ... if this fails, try to load the file from the theme folder.
466     if(!file_exists($file)){
467       $file = get_template_path($this->xmlData['definition']['template']);
468     }
470     return ($smarty->fetch($file));
471   }
474   function update()
475   {
476     global $config;
477     $ui= get_userinfo();
479     // Take care of base selector
480     if ($this->baseMode) {
481       $this->baseSelector->update();
482       // Check if a wrong base was supplied
483       if(!$this->baseSelector->checkLastBaseUpdate()){
484          msg_dialog::display(_("Error"), msgPool::check_base(), ERROR_DIALOG);
485       }
486     }
488     // Save base
489     $refresh= false;
490     if ($this->baseMode) {
491       $this->base= $this->baseSelector->getBase();
492       session::global_set("CurrentMainBase", $this->base);
493       $refresh= true;
494     }
497     // Reset object counter / DN mapping
498     $this->objectTypeCount= array();
499     $this->objectDnMapping= array();
501     // Do not do anything if this is not our PID
502     if($refresh || !(isset($_REQUEST['PID']) && $_REQUEST['PID'] != $this->pid)) {
504       // Save position if set
505       if (isset($_POST['position_'.$this->pid]) && is_numeric($_POST['position_'.$this->pid])) {
506         $this->scrollPosition= $_POST['position_'.$this->pid];
507       }
509       // Override the base if we got a message from the browser navigation
510       if ($this->departmentBrowser && isset($_GET['act'])) {
511         if (preg_match('/^department_([0-9]+)$/', validate($_GET['act']), $match)){
512           if (isset($this->departments[$match[1]])){
513             $this->base= $this->departments[$match[1]]['dn'];
514             if ($this->baseMode) {
515               $this->baseSelector->setBase($this->base);
516             }
517             session::global_set("CurrentMainBase", $this->base);
518           }
519         }
520       }
522       // Filter POST with "act" attributes -> posted from action menu
523       if (isset($_POST['exec_act']) && $_POST['act'] != '') {
524         if (preg_match('/^export.*$/', $_POST['act']) && isset($this->exporter[$_POST['act']])) {
525           $exporter= $this->exporter[$_POST['act']];
526           $userinfo= ", "._("created by")." ".$ui->cn." - ".strftime('%A, %d. %B %Y, %H:%M:%S');
527           $entryIterator= new listingSortIterator($this->entries, $this->sortDirection[$this->sortColumn], "_sort".$this->sortColumn, $this->sortType);
528           $sortedEntries= array();
529           foreach ($entryIterator as $entry){
530             $sortedEntries[]= $entry;
531           }
532           $instance= new $exporter['class']($this->headline.$userinfo, $this->plainHeader, $sortedEntries, $this->exportColumns);
533           $type= call_user_func(array($exporter['class'], "getInfo"));
534           $type= $type[$_POST['act']];
535           send_binary_content($instance->query(), $type['filename'], $type= $type['mime']);
536         }
537       }
539       // Filter GET with "act" attributes
540       if (isset($_GET['act'])) {
541         $key= validate($_GET['act']);
542         if (preg_match('/^SORT_([0-9]+)$/', $key, $match)) {
543           // Switch to new column or invert search order?
544           $column= $match[1];
545           if ($this->sortColumn != $column) {
546             $this->sortColumn= $column;
547           } else {
548             $this->sortDirection[$column]= !$this->sortDirection[$column];
549           }
551           // Allow header to update itself according to the new sort settings
552           $this->renderHeader();
553         }
554       }
556       // Override base if we got signals from the navigation elements
557       $action= "";
558       foreach ($_POST as $key => $value) {
559         if (preg_match('/^(ROOT|BACK|HOME)(_x)?$/', $key, $match)) {
560           $action= $match[1];
561           break;
562         }
563       }
565       // Navigation handling
566       if ($action == 'ROOT') {
567         $deps= $ui->get_module_departments($this->categories);
568         $this->base= $deps[0];
569         $this->baseSelector->setBase($this->base);
570         session::global_set("CurrentMainBase", $this->base);
571       }
572       if ($action == 'BACK') {
573         $deps= $ui->get_module_departments($this->categories);
574         $base= preg_replace("/^[^,]+,/", "", $this->base);
575         if(in_array_ics($base, $deps)){
576           $this->base= $base;
577           $this->baseSelector->setBase($this->base);
578           session::global_set("CurrentMainBase", $this->base);
579         }
580       }
581       if ($action == 'HOME') {
582         $ui= get_userinfo();
583         $this->base= get_base_from_people($ui->dn);
584         $this->baseSelector->setBase($this->base);
585         session::global_set("CurrentMainBase", $this->base);
586       }
587     }
589     // Reload departments
590     if ($this->departmentBrowser){
591       $this->departments= $this->getDepartments();
592     }
594     // Update filter and refresh entries
595     $this->filter->setBase($this->base);
596     $this->entries= $this->filter->query();
598     // Fix filter if querie returns NULL
599     if ($this->entries == null) {
600       $this->entries= array();
601     }
602   }
605   function setBase($base)
606   {
607     $this->base= $base;
608     if ($this->baseMode) {
609       $this->baseSelector->setBase($this->base);
610     }
611   }
614   function getBase()
615   {
616     return $this->base;
617   }
620   function parseLayout($layout)
621   {
622     $result= array();
623     $layout= preg_replace("/^\|/", "", $layout);
624     $layout= preg_replace("/\|$/", "", $layout);
625     $cols= explode("|", $layout);
627     foreach ($cols as $index => $config) {
628       if ($config != "") {
629         $res= "";
630         $components= explode(';', $config);
631         foreach ($components as $part) {
632           if (preg_match("/^r$/", $part)) {
633             $res.= "text-align:right;";
634             continue;
635           }
636           if (preg_match("/^l$/", $part)) {
637             $res.= "text-align:left;";
638             continue;
639           }
640           if (preg_match("/^c$/", $part)) {
641             $res.= "text-align:center;";
642             continue;
643           }
644           if (preg_match("/^[0-9]+(|px|%)$/", $part)) {
645             $res.= "width:$part;min-width:$part;";
646             continue;
647           }
648         }
650         // Add minimum width for scalable columns
651         if (!preg_match('/width:/', $res)){
652           $res.= "min-width:200px;";
653         }
655         $result[$index]= " style='$res'";
656       } else {
657         $result[$index]= " style='min-width:100px;'";
658       }
659     }
661     // Save number of columns for later use
662     $this->numColumns= count($cols);
664     // Add no border to the last column
665     $result[$this->numColumns-1]= preg_replace("/'$/", "border-right:0;'", $result[$this->numColumns-1]);
667     return $result;
668   }
671   function renderCell($data, $config, $row)
672   {
673     // Replace flat attributes in data string
674     for ($i= 0; $i<$config['count']; $i++) {
675       $attr= $config[$i];
676       $value= "";
677       if (is_array($config[$attr])) {
678         $value= $config[$attr][0];
679       } else {
680         $value= $config[$attr];
681       }
682       $data= preg_replace("/%\{$attr\}/", $value, $data);
683     }
685     // Watch out for filters and prepare to execute them
686     $data= $this->processElementFilter($data, $config, $row);
688     // Replace all non replaced %{...} instances because they
689     // are non resolved attributes or filters
690     $data= preg_replace('/%{[^}]+}/', '&nbsp;', $data);
692     return $data;
693   }
696   function renderBase()
697   {
698     if (!$this->baseMode) {
699       return;
700     }
702     return $this->baseSelector->render();
703   }
706   function processElementFilter($data, $config, $row)
707   {
708     preg_match_all("/%\{filter:([^(]+)\((.*)\)\}/", $data, $matches, PREG_SET_ORDER);
710     foreach ($matches as $match) {
711       $cl= "";
712       $method= "";
713       if (preg_match('/::/', $match[1])) {
714         $cl= preg_replace('/::.*$/', '', $match[1]);
715         $method= preg_replace('/^.*::/', '', $match[1]);
716       } else {
717         if (!isset($this->filters[$match[1]])) {
718           continue;
719         }
720         $cl= preg_replace('/::.*$/', '', $this->filters[$match[1]]);
721         $method= preg_replace('/^.*::/', '', $this->filters[$match[1]]);
722       }
724       // Prepare params for function call
725       $params= array();
726       preg_match_all('/"[^"]+"|[^,]+/', $match[2], $parts);
727       foreach ($parts[0] as $param) {
729         // Row is replaced by the row number
730         if ($param == "row") {
731           $params[]= $row;
732           continue;
733         }
735         // pid is replaced by the current PID
736         if ($param == "pid") {
737           $params[]= $this->pid;
738           continue;
739         }
741         // base is replaced by the current base
742         if ($param == "base") {
743           $params[]= $this->getBase();
744           continue;
745         }
747         // Fixie with "" is passed directly
748         if (preg_match('/^".*"$/', $param)){
749           $params[]= preg_replace('/"/', '', $param);
750           continue;
751         }
753         // Move dn if needed
754         if ($param == "dn") {
755           $params[]= LDAP::fix($config["dn"]);
756           continue;
757         }
759         // LDAP variables get replaced by their objects
760         for ($i= 0; $i<$config['count']; $i++) {
761           if ($param == $config[$i]) {
762             $values= $config[$config[$i]];
763             if (is_array($values)){
764               unset($values['count']);
765             }
766             $params[]= $values;
767             break;
768           }
769         }
770       }
772       // Replace information
773       if ($cl == "listing") {
774         // Non static call - seems to result in errors
775         $data= @preg_replace('/'.preg_quote($match[0]).'/', call_user_func_array(array($this, "$method"), $params), $data);
776       } else {
777         // Static call
778         $data= preg_replace('/'.preg_quote($match[0]).'/', call_user_func_array(array($cl, $method), $params), $data);
779       }
780     }
782     return $data;
783   }
786   function getObjectType($types, $classes)
787   {
788     // Walk thru types and see if there's something matching
789     foreach ($types as $objectType) {
790       $ocs= $objectType['objectClass'];
791       if (!is_array($ocs)){
792         $ocs= array($ocs);
793       }
795       $found= true;
796       foreach ($ocs as $oc){
797         if (preg_match('/^!(.*)$/', $oc, $match)) {
798           $oc= $match[1];
799           if (in_array($oc, $classes)) {
800             $found= false;
801           }
802         } else {
803           if (!in_array($oc, $classes)) {
804             $found= false;
805           }
806         }
807       }
809       if ($found) {
810         return $objectType;
811       }
812     }
814     return null;
815   }
818   function filterObjectType($dn, $classes)
819   {
820     // Walk thru classes and return on first match
821     $result= "&nbsp;";
823     $objectType= $this->getObjectType($this->objectTypes, $classes);
824     if ($objectType) {
825       $this->objectDnMapping[$dn]= $objectType["objectClass"];
826       $result= image($objectType["image"], null, LDAP::fix($dn));
827       if (!isset($this->objectTypeCount[$objectType['label']])) {
828         $this->objectTypeCount[$objectType['label']]= 0;
829       }
830       $this->objectTypeCount[$objectType['label']]++;
831     }
833     return $result;
834   }
837   function filterActions($dn, $row, $classes)
838   {
839     // Do nothing if there's no menu defined
840     if (!isset($this->xmlData['actiontriggers']['action'])) {
841       return "&nbsp;";
842     }
844     // Go thru all actions
845     $result= "";
846     $actions= $this->xmlData['actiontriggers']['action'];
848     // Ensure we've a valid actions array, if there is only one action in the actiontriggers col
849     //  then we've to create a valid array here.
850     if(isset($actions['name'])) $actions = array($actions);
852     foreach($actions as $action) {
853       // Skip the entry completely if there's no permission to execute it
854       if (!$this->hasActionPermission($action, $dn, $classes)) {
855         $result.= image('images/empty.png');
856         continue;
857       }
859       // Skip entry if the pseudo filter does not fit
860       if (isset($action['filter']) && preg_match('/^[a-z0-9_]+!?=[a-z0-9_]+$/i', $action['filter'])) {
861         list($fa, $fv)= explode('=', $action['filter']);
862         if (preg_match('/^(.*)!$/', $fa, $m)){
863           $fa= $m[1];
864           if (isset($this->entries[$row][$fa]) && $this->entries[$row][$fa][0] == $fv) {
865             $result.= image('images/empty.png');
866             continue;
867           }
868         } else {
869           if (!isset($this->entries[$row][$fa]) && !$this->entries[$row][$fa][0] == $fv) {
870             $result.= image('images/empty.png');
871             continue;
872           }
873         }
874       }
877       // If there's an objectclass definition and we don't have it
878       // add an empty picture here.
879       if (isset($action['objectclass'])){
880         $objectclass= $action['objectclass'];
881         if (preg_match('/^!(.*)$/', $objectclass, $m)){
882           $objectclass= $m[1];
883           if(in_array($objectclass, $classes)) {
884             $result.= image('images/empty.png');
885             continue;
886           }
887         } elseif (is_string($objectclass)) {
888           if(!in_array($objectclass, $classes)) {
889             $result.= image('images/empty.png');
890             continue;
891           }
892         } elseif (is_array($objectclass)) {
893           if(count(array_intersect($objectclass, $classes)) != count($objectclass)){
894             $result.= image('images/empty.png');
895             continue;
896           }
897         }
898       }
900       // Render normal entries as usual
901       if ($action['type'] == "entry") {
902         $label= $this->processElementFilter($action['label'], $this->entries[$row], $row);
903         $image= $this->processElementFilter($action['image'], $this->entries[$row], $row);
904         $result.= image($image, "listing_".$action['name']."_$row", $label);
905       }
907       // Handle special types
908       if ($action['type'] == "copypaste" || $action['type'] == "snapshot") {
910         $objectType= $this->getObjectType($this->objectTypes, $this->entries[$row]['objectClass']);
911         $category= $class= null;
912         if ($objectType) {
913           $category= $objectType['category'];
914           $class= $objectType['class'];
915         }
917         if ($action['type'] == "copypaste") {
918           $copy = !isset($action['copy']) || $action['copy'] == "true";
919           $cut = !isset($action['cut']) || $action['cut'] == "true";
920           $result.= $this->renderCopyPasteActions($row, $this->entries[$row]['dn'], $category, $class,$copy,$cut);
921         } else {
922           $result.= $this->renderSnapshotActions($row, $this->entries[$row]['dn'], $category, $class);
923         }
924       }
925     }
927     return $result;
928   }
931   function filterDepartmentLink($row, $dn, $description)
932   {
933     $attr= $this->departments[$row]['sort-attribute'];
934     $name= $this->departments[$row][$attr];
935     if (is_array($name)){
936       $name= $name[0];
937     }
938     $result= sprintf("%s [%s]", $name, $description[0]);
939     return("<a href='?plug=".$_GET['plug']."&amp;PID=$this->pid&amp;act=department_$row' title='$dn'>$result</a>");
940   }
943   function filterLink()
944   {
945     $result= "&nbsp;";
947     $row= func_get_arg(0);
948     $pid= $this->pid;
949     $dn= LDAP::fix(func_get_arg(1));
950     $params= array(func_get_arg(2));
952     // Collect sprintf params
953     for ($i = 3;$i < func_num_args();$i++) {
954       $val= func_get_arg($i);
955       if (is_array($val)){
956         $params[]= $val[0];
957         continue;
958       }
959       $params[]= $val;
960     }
962     $result= "&nbsp;";
963     $trans= call_user_func_array("sprintf", $params);
964     if ($trans != "") {
965       return("<a href='?plug=".$_GET['plug']."&amp;PID=$pid&amp;act=listing_edit_$row' title='$dn'>$trans</a>");
966     }
968     return $result;
969   }
972   function renderNavigation()
973   {
974     $result= array();
975     $enableBack = true;
976     $enableRoot = true;
977     $enableHome = true;
979     $ui = get_userinfo();
981     /* Check if base = first available base */
982     $deps = $ui->get_module_departments($this->categories);
984     if(!count($deps) || $deps[0] == $this->filter->base){
985       $enableBack = false;
986       $enableRoot = false;
987     }
989     $listhead ="";
991     /* Check if we are in users home  department */
992     if(!count($deps) || $this->filter->base == get_base_from_people($ui->dn)){
993       $enableHome = false;
994     }
996     /* Draw root button */
997     if($enableRoot){
998       $result["ROOT"]= image('images/lists/root.png', 'ROOT', _("Root"));
999     }else{
1000       $result["ROOT"]= image('images/lists/root-grey.png', null, _("Root"));
1001     }
1003     /* Draw back button */
1004     if($enableBack){
1005       $result["BACK"]= image('images/lists/back.png', 'BACK', _("Go up one department"));
1006     }else{
1007       $result["BACK"]= image('images/lists/back-grey.png', null, _("Go up one department"));
1008     }
1010     /* Draw home button */
1011    /* Draw home button */
1012     if($enableHome){
1013       $result["HOME"]= image('images/lists/home.png', 'HOME', _("Go to users department"));
1014     }else{
1015       $result["HOME"]= image('images/lists/home-grey.png', null, _("Go to users department"));
1016     }
1019     /* Draw reload button, this button is enabled everytime */
1020     $result["RELOAD"]= image('images/lists/reload.png', 'REFRESH', _("Reload list"));
1022     return ($result);
1023   }
1026   function getAction()
1027   {
1028     // Do not do anything if this is not our PID, or there's even no PID available...
1029     if(!isset($_REQUEST['PID']) || $_REQUEST['PID'] != $this->pid) {
1030       return;
1031     }
1033     // Save position if set
1034     if (isset($_POST['position_'.$this->pid]) && is_numeric($_POST['position_'.$this->pid])) {
1035       $this->scrollPosition= $_POST['position_'.$this->pid];
1036     }
1038     $result= array("targets" => array(), "action" => "");
1040     // Filter GET with "act" attributes
1041     if (isset($_GET['act'])) {
1042       $key= validate($_GET['act']);
1043       $target= preg_replace('/^listing_[a-zA-Z_]+_([0-9]+)$/', '$1', $key);
1044       if (isset($this->entries[$target]['dn'])) {
1045         $result['action']= preg_replace('/^listing_([a-zA-Z_]+)_[0-9]+$/', '$1', $key);
1046         $result['targets'][]= $this->entries[$target]['dn'];
1047       }
1049       // Drop targets if empty
1050       if (count($result['targets']) == 0) {
1051         unset($result['targets']);
1052       }
1053       return $result;
1054     }
1056     // Filter POST with "listing_" attributes
1057     foreach ($_POST as $key => $prop) {
1059       // Capture selections
1060       if (preg_match('/^listing_selected_[0-9]+$/', $key)) {
1061         $target= preg_replace('/^listing_selected_([0-9]+)$/', '$1', $key);
1062         if (isset($this->entries[$target]['dn'])) {
1063           $result['targets'][]= $this->entries[$target]['dn'];
1064         }
1065         continue;
1066       }
1068       // Capture action with target - this is a one shot
1069       if (preg_match('/^listing_[a-zA-Z_]+_[0-9]+(|_x)$/', $key)) {
1070         $target= preg_replace('/^listing_[a-zA-Z_]+_([0-9]+)(|_x)$/', '$1', $key);
1071         if (isset($this->entries[$target]['dn'])) {
1072           $result['action']= preg_replace('/^listing_([a-zA-Z_]+)_[0-9]+(|_x)$/', '$1', $key);
1073           $result['targets']= array($this->entries[$target]['dn']);
1074         }
1075         break;
1076       }
1078       // Capture action without target
1079       if (preg_match('/^listing_[a-zA-Z_]+(|_x)$/', $key)) {
1080         $result['action']= preg_replace('/^listing_([a-zA-Z_]+)(|_x)$/', '$1', $key);
1081         continue;
1082       }
1083     }
1085     // Filter POST with "act" attributes -> posted from action menu
1086     if (isset($_POST['act']) && $_POST['act'] != '') {
1087       if (!preg_match('/^export.*$/', $_POST['act'])){
1088         $result['action']= validate($_POST['act']);
1089       }
1090     }
1092     // Drop targets if empty
1093     if (count($result['targets']) == 0) {
1094       unset($result['targets']);
1095     }
1096     return $result;
1097   }
1100   function renderActionMenu()
1101   {
1102     // Don't send anything if the menu is not defined
1103     if (!isset($this->xmlData['actionmenu']['action'])){
1104       return "";
1105     }
1107     // Array?
1108     if (isset($this->xmlData['actionmenu']['action']['type'])){
1109       $this->xmlData['actionmenu']['action']= array($this->xmlData['actionmenu']['action']);
1110     }
1112     // Load shortcut
1113     $actions= &$this->xmlData['actionmenu']['action'];
1114     $result= "<input type='hidden' name='act' id='actionmenu' value=''><div style='display:none'><input type='submit' name='exec_act' id='exec_act' value=''></div>".
1115              "<ul class='level1' id='root'><li><a href='#'>"._("Actions")."&nbsp;".image("images/lists/sort-down.png")."</a>";
1117     // Build ul/li list
1118     $result.= $this->recurseActions($actions);
1120     return "<div id='pulldown'>".$result."</li></ul><div>";
1121   }
1124   function recurseActions($actions)
1125   {
1126     global $class_mapping;
1127     static $level= 2;
1128     $result= "<ul class='level$level'>";
1129     $separator= "";
1131     foreach ($actions as $action) {
1133       // Skip the entry completely if there's no permission to execute it
1134       if (!$this->hasActionPermission($action, $this->filter->base)) {
1135         continue;
1136       }
1138       // Skip entry if there're missing dependencies
1139       if (isset($action['depends'])) {
1140         $deps= is_array($action['depends'])?$action['depends']:array($action['depends']);
1141         foreach($deps as $clazz) {
1142           if (!isset($class_mapping[$clazz])){
1143             continue 2;
1144           }
1145         }
1146       }
1148       // Fill image if set
1149       $img= "";
1150       if (isset($action['image'])){
1151         $img= image($action['image'])."&nbsp;";
1152       }
1154       if ($action['type'] == "separator"){
1155         $separator= " style='border-top:1px solid #AAA' ";
1156         continue;
1157       }
1159       // Dive into subs
1160       if ($action['type'] == "sub" && isset($action['action'])) {
1161         $level++;
1162         if (isset($action['label'])){
1163           $result.= "<li$separator><a href='#'>$img"._($action['label'])."&nbsp;".image('images/forward-arrow.png')."</a>";
1164         }
1166         // Ensure we've an array of actions, this enables sub menus with only one action.
1167         if(isset($action['action']['type'])){
1168           $action['action'] = array($action['action']);
1169         }
1171         $result.= $this->recurseActions($action['action'])."</li>";
1172         $level--;
1173         $separator= "";
1174         continue;
1175       }
1177       // Render entry elseways
1178       if (isset($action['label'])){
1179         $result.= "<li$separator><a href='#' onClick='document.getElementById(\"actionmenu\").value= \"".$action['name']."\";mainform.submit();'>$img"._($action['label'])."</a></li>";
1180       }
1182       // Check for special types
1183       switch ($action['type']) {
1184         case 'copypaste':
1185           $cut = !isset($action['cut']) || $action['cut'] != "false";
1186           $copy = !isset($action['copy']) || $action['copy'] != "false";
1187           $result.= $this->renderCopyPasteMenu($separator, $copy , $cut);
1188           break;
1190         case 'snapshot':
1191           $result.= $this->renderSnapshotMenu($separator);
1192           break;
1194         case 'exporter':
1195           $result.= $this->renderExporterMenu($separator);
1196           break;
1198         case 'daemon':
1199           $result.= $this->renderDaemonMenu($separator);
1200           break;
1201       }
1203       $separator= "";
1204     }
1206     $result.= "</ul>";
1207     return $result;
1208   }
1211   function hasActionPermission($action, $dn, $classes= null)
1212   {
1213     $ui= get_userinfo();
1215     if (isset($action['acl'])) {
1216       $acls= $action['acl'];
1217       if (!is_array($acls)) {
1218         $acls= array($acls);
1219       }
1221       // Every ACL has to pass
1222       foreach ($acls as $acl) {
1223         $module= $this->categories;
1224         $aclList= array();
1226         // Replace %acl if available
1227         if ($classes) {
1228           $otype= $this->getObjectType($this->objectTypes, $classes);
1229           $acl= str_replace('%acl', $otype['category']."/".$otype['class'], $acl);
1230         }
1232         // Split for category and plugins if needed
1233         // match for "[rw]" style entries
1234         if (preg_match('/^\[([rwcdm]+)\]$/', $acl, $match)){
1235           $aclList= array($match[1]);
1236         }
1238         // match for "users[rw]" style entries
1239         if (preg_match('/^([a-zA-Z0-9]+)\[([rwcdm]+)\]$/', $acl, $match)){
1240           $module= $match[1];
1241           $aclList= array($match[2]);
1242         }
1244         // match for "users/user[rw]" style entries
1245         if (preg_match('/^([a-zA-Z0-9]+\/[a-zA-Z0-9]+)\[([rwcdm]+)\]$/', $acl, $match)){
1246           $module= $match[1];
1247           $aclList= array($match[2]);
1248         }
1250         // match "users/user[userPassword:rw(,...)*]" style entries
1251         if (preg_match('/^([a-zA-Z0-9]+\/[a-zA-Z0-9]+)\[([a-zA-Z0-9]+:[rwcdm]+(,[a-zA-Z0-9]+:[rwcdm]+)*)\]$/', $acl, $match)){
1252           $module= $match[1];
1253           $aclList= explode(',', $match[2]);
1254         }
1256         // Walk thru prepared ACL by using $module
1257         foreach($aclList as $sAcl) {
1258           $checkAcl= "";
1260           // Category or detailed permission?
1261           if (strpos($module, '/') !== false) {
1262             if (preg_match('/([a-zA-Z0-9]+):([rwcdm]+)/', $sAcl, $m) ) {
1263               $checkAcl= $ui->get_permissions($dn, $module, $m[1]);
1264               $sAcl= $m[2];
1265             } else {
1266               $checkAcl= $ui->get_permissions($dn, $module, '0');
1267             }
1268           } else {
1269             $checkAcl= $ui->get_category_permissions($dn, $module);
1270           }
1272           // Split up remaining part of the acl and check if it we're
1273           // allowed to do something...
1274           $parts= str_split($sAcl);
1275           foreach ($parts as $part) {
1276             if (strpos($checkAcl, $part) === false){
1277               return false;
1278             }
1279           }
1281         }
1282       }
1283     }
1285     return true;
1286   }
1289   function refreshBasesList()
1290   {
1291     global $config;
1292     $ui= get_userinfo();
1294     // Do some array munching to get it user friendly
1295     $ids= $config->idepartments;
1296     $d= $ui->get_module_departments($this->categories);
1297     $k_ids= array_keys($ids);
1298     $deps= array_intersect($d,$k_ids);
1300     // Fill internal bases list
1301     $this->bases= array();
1302     foreach($k_ids as $department){
1303       $this->bases[$department] = $ids[$department];
1304     }
1306     // Populate base selector if already present
1307     if ($this->baseSelector && $this->baseMode) {
1308       $this->baseSelector->setBases($this->bases);
1309       $this->baseSelector->update(TRUE);
1310     }
1311   }
1314   function getDepartments()
1315   {
1316     $departments= array();
1317     $ui= get_userinfo();
1319     // Get list of supported department types
1320     $types = departmentManagement::get_support_departments();
1322     // Load departments allowed by ACL
1323     $validDepartments = $ui->get_module_departments($this->categories);
1325     // Build filter and look in the LDAP for possible sub departments
1326     // of current base
1327     $filter= "(&(objectClass=gosaDepartment)(|";
1328     $attrs= array("description", "objectClass");
1329     foreach($types as $name => $data){
1330       $filter.= "(objectClass=".$data['OC'].")";
1331       $attrs[]= $data['ATTR'];
1332     }
1333     $filter.= "))";
1334     $res= get_list($filter, $this->categories, $this->base, $attrs, GL_NONE);
1336     // Analyze list of departments
1337     foreach ($res as $department) {
1338       if (!in_array($department['dn'], $validDepartments)) {
1339         continue;
1340       }
1342       // Add the attribute where we use for sorting
1343       $oc= null;
1344       foreach(array_keys($types) as $type) {
1345         if (in_array($type, $department['objectClass'])) {
1346           $oc= $type;
1347           break;
1348         }
1349       }
1350       $department['sort-attribute']= $types[$oc]['ATTR'];
1352       // Move to the result list
1353       $departments[]= $department;
1354     }
1356     return $departments;
1357   }
1360   function renderCopyPasteMenu($separator, $copy= true, $cut= true)
1361   {
1362     // We can only provide information if we've got a copypaste handler
1363     // instance
1364     if(!(isset($this->copyPasteHandler) && is_object($this->copyPasteHandler))){
1365       return "";
1366     }
1368     // Presets
1369     $result= "";
1370     $read= $paste= false;
1371     $ui= get_userinfo();
1373     // Switch flags to on if there's at least one category which allows read/paste
1374     foreach($this->categories as $category){
1375       $read= $read || preg_match('/r/', $ui->get_category_permissions($this->base, $category));
1376       $paste= $paste || $ui->is_pasteable($this->base, $category) == 1;
1377     }
1380     // Draw entries that allow copy and cut
1381     if($read){
1383       // Copy entry
1384       if($copy){
1385         $result.= "<li$separator><a href='#' onClick='document.getElementById(\"actionmenu\").value= \"copy\";document.getElementById(\"exec_act\").click();'>".image('images/lists/copy.png')."&nbsp;"._("Copy")."</a></li>";
1386         $separator= "";
1387       }
1389       // Cut entry
1390       if($cut){
1391         $result.= "<li$separator><a href='#' onClick='document.getElementById(\"actionmenu\").value= \"cut\";document.getElementById(\"exec_act\").click();'>".image("images/lists/cut.png")."&nbsp;"._("Cut")."</a></li>";
1392         $separator= "";
1393       }
1394     }
1396     // Draw entries that allow pasting entries
1397     if($paste){
1398       if($this->copyPasteHandler->entries_queued()){
1399         $result.= "<li$separator><a href='#' onClick='document.getElementById(\"actionmenu\").value= \"paste\";document.getElementById(\"exec_act\").click();'>".image("images/lists/paste.png")."&nbsp;"._("Paste")."</a></li>";
1400       }else{
1401         $result.= "<li$separator><a href='#'>".image('images/lists/paste-grey.png')."&nbsp;"._("Paste")."</a></li>";
1402       }
1403     }
1404     
1405     return($result);
1406   }
1409   function renderCopyPasteActions($row, $dn, $category, $class, $copy= true, $cut= true)
1410   {
1411     // We can only provide information if we've got a copypaste handler
1412     // instance
1413     if(!(isset($this->copyPasteHandler) && is_object($this->copyPasteHandler))){
1414       return "";
1415     }
1417     // Presets
1418     $ui = get_userinfo();
1419     $result = "";
1421     // Render cut entries
1422     if($cut){
1423       if($ui->is_cutable($dn, $category, $class)){
1424         $result.= image('images/lists/cut.png', "listing_cut_$row", _("Cut this entry"));
1425       }else{
1426         $result.= image('images/empty.png');
1427       }
1428     }
1430     // Render copy entries
1431     if($copy){
1432       if($ui->is_copyable($dn, $category, $class)){
1433         $result.= image('images/lists/copy.png', "listing_copy_$row", _("Copy this entry"));
1434       }else{
1435         $result.= image('images/empty.png');
1436       }
1437     }
1439     return($result);
1440   }
1443   function renderSnapshotMenu($separator)
1444   {
1445     // We can only provide information if we've got a snapshot handler
1446     // instance
1447     if(!(isset($this->snapshotHandler) && is_object($this->snapshotHandler))){
1448       return "";
1449     }
1451     // Presets
1452     $result = "";
1453     $ui = get_userinfo();
1455     if($this->snapshotHandler->enabled() && $ui->allow_snapshot_restore($this->base, $this->categories)){
1457       // Check if there is something to restore
1458       $restore= false;
1459       foreach($this->snapshotHandler->getSnapshotBases() as $base){
1460         $restore= $restore || count($this->snapshotHandler->getDeletedSnapshots($base)) > 0;
1461       }
1463       // Draw icons according to the restore flag
1464       if($restore){
1465         $result.= "<li$separator><a href='#' onClick='document.getElementById(\"actionmenu\").value= \"restore\";document.getElementById(\"exec_act\").click();'>".image('images/lists/restore.png')."&nbsp;"._("Restore snapshots")."</a></li>";
1466       }else{
1467         $result.= "<li$separator><a href='#'>".image('images/lists/restore-grey.png')."&nbsp;"._("Restore snapshots")."</a></li>";
1468       }
1469     }
1471     return($result);
1472   }
1475   function renderExporterMenu($separator)
1476   {
1477     // Presets
1478     $result = "";
1480     // Draw entries
1481     $result.= "<li$separator><a href='#'>".image('images/lists/export.png')."&nbsp;"._("Export list")."&nbsp;".image("images/forward-arrow.png")."</a><ul class='level3'>";
1483     // Export CVS as build in exporter
1484     foreach ($this->exporter as $action => $exporter) {
1485       $result.= "<li><a href='#' onClick='document.getElementById(\"actionmenu\").value= \"$action\";document.getElementById(\"exec_act\").click();'>".image($exporter['image'])."&nbsp;".$exporter['label']."</a></li>";
1486     }
1488     // Finalize list
1489     $result.= "</ul></li>";
1491     return($result);
1492   }
1495   function renderSnapshotActions($row, $dn, $category, $class, $copy= true, $cut= true)
1496   {
1497     // We can only provide information if we've got a snapshot handler
1498     // instance
1499     if(!(isset($this->snapshotHandler) && is_object($this->snapshotHandler))){
1500       return "";
1501     }
1503     // Presets
1504     $result= "";
1505     $ui = get_userinfo();
1507     // Only act if enabled here
1508     if($this->snapshotHandler->enabled()){
1510       // Draw restore button
1511       if ($ui->allow_snapshot_restore($dn, $category)){
1513         // Do we have snapshots for this dn?
1514         if($this->snapshotHandler->hasSnapshots($dn)){
1515           $result.= image('images/lists/restore.png', "listing_restore_$row", _("Restore snapshot"));
1516         } else {
1517           $result.= image('images/lists/restore-grey.png');
1518         }
1519       }
1521       // Draw snapshot button
1522       if($ui->allow_snapshot_create($dn, $category)){
1523           $result.= image('images/snapshot.png', "listing_snapshot_$row", _("Create a new snapshot from this object"));
1524       }else{
1525           $result.= image('images/empty.png');
1526       }
1527     }
1529     return($result);
1530   }
1533   function renderDaemonMenu($separator)
1534   {
1535     $result= "";
1537     // If there is a daemon registered, draw the menu entries
1538     if(class_available("DaemonEvent")){
1539       $events= DaemonEvent::get_event_types_by_category($this->categories);
1540       if(isset($events['BY_CLASS']) && count($events['BY_CLASS'])){
1541         foreach($events['BY_CLASS'] as $name => $event){
1542           $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>";
1543           $separator= "";
1544         }
1545       }
1546     }
1548     return $result;
1549   }
1552   function getEntry($dn)
1553   {
1554     foreach ($this->entries as $entry) {
1555       if (isset($entry['dn']) && strcasecmp($dn, $entry['dn']) == 0){
1556         return $entry;
1557       }
1558     }
1559     return null;
1560   }
1563   function getEntries()
1564   {
1565     return $this->entries;
1566   }
1569   function getType($dn)
1570   {
1571     if (isset($this->objectDnMapping[$dn])) {
1572       return $this->objectDnMapping[$dn];
1573     }
1574     return null;
1575   }
1579 ?>