Code

Fixed multi query editor
[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 getFilter()
125   { 
126     return($this->filter);
127   }  
130   function setFilter($filter)
131   {
132     $this->filter= &$filter;
133     if ($this->departmentBrowser){
134       $this->departments= $this->getDepartments();
135     }
136     $this->filter->setBase($this->base);
137   }
140   function registerElementFilter($name, $call)
141   {
142     if (!isset($this->filters[$name])) {
143       $this->filters[$name]= $call;
144       return true;
145     }
147     return false;
148   }
151   function load($filename)
152   {
153     $contents = file_get_contents($filename);
154     $this->xmlData= xml::xml2array($contents, 1);
156     if (!isset($this->xmlData['list'])) {
157       return false;
158     }
160     $this->xmlData= $this->xmlData["list"];
162     // Load some definition values
163     foreach (array("departmentBrowser", "departmentRootVisible", "multiSelect", "baseMode") as $token) {
164       if (isset($this->xmlData['definition'][$token]) &&
165           $this->xmlData['definition'][$token] == "true"){
166         $this->$token= true;
167       }
168     }
170     // Fill objectTypes from departments and xml definition
171     $types = departmentManagement::get_support_departments();
172     foreach ($types as $class => $data) {
173       $this->objectTypes[$data['OC']]= array("label" => $data['TITLE'],
174                                   "objectClass" => $data['OC'],
175                                   "image" => $data['IMG']);
176     }
177     $this->categories= array();
178     if (isset($this->xmlData['definition']['objectType'])) {
179       if(isset($this->xmlData['definition']['objectType']['label'])) {
180         $this->xmlData['definition']['objectType']= array($this->xmlData['definition']['objectType']);
181       }
182       foreach ($this->xmlData['definition']['objectType'] as $index => $otype) {
183         $tmp = $this->xmlData['definition']['objectType'][$index];
184         $this->objectTypes[$tmp['objectClass']]= $tmp;
185         if (isset($this->xmlData['definition']['objectType'][$index]['category'])){
186           $this->categories[]= $otype['category'];
187         }
188       }
189     }
190     $this->objectTypes = array_values($this->objectTypes);
192     // Parse layout per column
193     $this->colprops= $this->parseLayout($this->xmlData['table']['layout']);
195     // Prepare table headers
196     $this->renderHeader();
198     // Assign headline/Categories
199     $this->headline= _($this->xmlData['definition']['label']);
200     if (!is_array($this->categories)){
201       $this->categories= array($this->categories);
202     }
204     // Evaluate columns to be exported
205     if (isset($this->xmlData['table']['column'])){
206       foreach ($this->xmlData['table']['column'] as $index => $config) {
207         if (isset($config['export']) && $config['export'] == "true"){
208           $this->exportColumns[]= $index;
209         }
210       }
211     }
213     return true;  
214   }
217   function renderHeader()
218   {
219     $this->header= array();
220     $this->plainHeader= array();
222     // Initialize sort?
223     $sortInit= false;
224     if (!$this->sortDirection) {
225       $this->sortColumn= 0;
226       if (isset($this->xmlData['definition']['defaultSortColumn'])){
227         $this->sortColumn= $this->xmlData['definition']['defaultSortColumn'];
228       } else {
229         $this->sortAttribute= "";
230       }
231       $this->sortDirection= array();
232       $sortInit= true;
233     }
235     if (isset($this->xmlData['table']['column'])){
236       foreach ($this->xmlData['table']['column'] as $index => $config) {
237         // Initialize everything to one direction
238         if ($sortInit) {
239           $this->sortDirection[$index]= false;
240         }
242         $sorter= "";
243         if ($index == $this->sortColumn && isset($config['sortAttribute']) &&
244             isset($config['sortType'])) {
245           $this->sortAttribute= $config['sortAttribute'];
246           $this->sortType= $config['sortType'];
247           $sorter= "&nbsp;".image("images/lists/sort-".($this->sortDirection[$index]?"up":"down").".png", null, $this->sortDirection[$index]?_("Up"):_("Down"), "text-top");
248         }
249         $sortable= (isset($config['sortAttribute']));
251         $link= "href='?plug=".$_GET['plug']."&amp;PID=".$this->pid."&amp;act=SORT_$index'";
252         if (isset($config['label'])) {
253           if ($sortable) {
254             $this->header[$index]= "<td class='listheader' ".$this->colprops[$index]."><a $link>"._($config['label'])."</a>$sorter</td>";
255           } else {
256             $this->header[$index]= "<td class='listheader' ".$this->colprops[$index].">"._($config['label'])."</td>";
257           }
258           $this->plainHeader[]= _($config['label']);
259         } else {
260           if ($sortable) {
261             $this->header[$index]= "<td class='listheader' ".$this->colprops[$index]."><a $link>&nbsp;</a>$sorter</td>";
262           } else {
263             $this->header[$index]= "<td class='listheader' ".$this->colprops[$index].">&nbsp;</td>";
264           }
265           $this->plainHeader[]= "";
266         }
267       }
268     }
269   }
272   function render()
273   {
274     // Check for exeeded sizelimit
275     if (($message= check_sizelimit()) != ""){
276       return($message);
277     }
279     // Some browsers don't have the ability do do scrollable table bodies, filter them
280     // here.
281     $switch= false;
282     if (preg_match('/(Opera|Konqueror|Safari)/i', $_SERVER['HTTP_USER_AGENT'])){
283       $switch= true;
284     }
286     // Initialize list
287     $result= "<input type='hidden' value='$this->pid' name='PID'>\n";
288     $result.= "<input type='hidden' name='position_".$this->pid."' id='position_".$this->pid."'>\n";
289     $height= 450;
290     if ($this->height != 0) {
291       $result.= "<input type='hidden' value='$this->height' id='d_height'>\n";
292       $height= $this->height;
293     }
294     
295     $result.= "<div class='listContainer' id='d_scrollbody' style='min-height:".($height+25)."px;'>\n";
296     $result.= "<table summary='$this->headline' style='width:100%;table-layout:fixed' cellspacing='0' cellpadding='0' id='t_scrolltable'>\n";
297     $this->numColumns= count($this->colprops) + ($this->multiSelect?1:0);
299     // Build list header
300     $result.= "<thead class='fixedListHeader listHeaderFormat'><tr>\n";
301     if ($this->multiSelect) {
302       $width= "24px";
303       if (preg_match('/Konqueror/i', $_SERVER['HTTP_USER_AGENT'])){
304         $width= "28px";
305       }
306       $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";
307     }
308     foreach ($this->header as $header) {
309       $result.= $header;
310     }
311     $result.= "</tr></thead>\n";
313     // Build list body
314     $result.= "<tbody class='listScrollContent listBodyFormat' id='t_nscrollbody' style='height:".$height."px;'>\n";
316     // No results? Just take an empty colspanned row
317     if (count($this->entries) + count($this->departments) == 0) {
318       $result.= "<tr><td class='list1nohighlight' colspan='$this->numColumns' style='height:100%;border-right:0px;width:100%;'>&nbsp;</td></tr>";
319     }
321     // Line color alternation
322     $alt= 0;
323     $deps= 0;
325     // Draw department browser if configured and we're not in sub mode
326     $this->useSpan= false;
327     if ($this->departmentBrowser && $this->filter->scope != "sub") {
328       // Fill with department browser if configured this way
329       $departmentIterator= new departmentSortIterator($this->departments, $this->sortDirection[$this->sortColumn]);
330       foreach ($departmentIterator as $row => $entry){
331         $result.="<tr>";
333         // Render multi select if needed
334         if ($this->multiSelect) {
335           $result.="<td style='text-align:center;padding:0;' class='list1'>&nbsp;</td>";
336         }
338         // Render defined department columns, fill the rest with some stuff
339         $rest= $this->numColumns - 1;
340         foreach ($this->xmlData['table']['department'] as $index => $config) {
341           $colspan= 1;
342           if (isset($config['span'])){
343             $colspan= $config['span'];
344             $this->useSpan= true;
345           }
346           $result.="<td colspan='$colspan' ".$this->colprops[$index]." class='list1'>".$this->renderCell($config['value'], $entry, $row)."</td>";
347           $rest-= $colspan;
348         }
350         // Fill remaining cols with nothing
351         $last= $this->numColumns - $rest;
352         for ($i= 0; $i<$rest; $i++){
353           $result.= "<td ".$this->colprops[$last+$i-1]." class='list1'>&nbsp;</td>";
354         }
355         $result.="</tr>";
357         $alt++;
358       }
359       $deps= $alt;
360     }
362     // Fill with contents, sort as configured
363     foreach ($this->entries as $row => $entry) {
364       $trow= "";
366       // Render multi select if needed
367       if ($this->multiSelect) {
368         $trow.="<td style='text-align:center;width:20px;' class='list0'><input type='checkbox' id='listing_selected_$row' name='listing_selected_$row'></td>\n";
369       }
371       foreach ($this->xmlData['table']['column'] as $index => $config) {
372         $renderedCell= $this->renderCell($config['value'], $entry, $row);
373         $trow.="<td ".$this->colprops[$index]." class='list0'>".$renderedCell."</td>\n";
375         // Save rendered column
376         $sort= preg_replace('/.*>([^<]+)<.*$/', '$1', $renderedCell);
377         $sort= preg_replace('/&nbsp;/', '', $sort);
378         if (preg_match('/</', $sort)){
379           $sort= "";
380         }
381         $this->entries[$row]["_sort$index"]= $sort;
382       }
384       // Save rendered entry
385       $this->entries[$row]['_rendered']= $trow;
386     }
388     // Complete list by sorting entries for _sort$index and appending them to the output
389     $entryIterator= new listingSortIterator($this->entries, $this->sortDirection[$this->sortColumn], "_sort".$this->sortColumn, $this->sortType);
390     foreach ($entryIterator as $row => $entry){
391       $result.="<tr>\n";
392       $result.= $entry['_rendered'];
393       $result.="</tr>\n";
394       $alt++;
395     }
397     // Need to fill the list if it's not full (nobody knows why this is 22 ;-))
398     $emptyListStyle= (count($this->entries) + (($this->useSpan && count($this->entries))?$deps:0) == 0)?"border:0;":"";
399     if ((count($this->entries) + $deps) < 22) {
400       $result.= "<tr>";
401       for ($i= 0; $i<$this->numColumns; $i++) {
402         if ($i == 0) {
403           $result.= "<td class='list1nohighlight' style='$emptyListStyle height:100%;'>&nbsp;</td>";
404           continue;
405         }
406         if ($i != $this->numColumns-1) {
407           $result.= "<td class='list1nohighlight' style='$emptyListStyle'>&nbsp;</td>";
408         } else {
409           $result.= "<td class='list1nohighlight' style='border-right:0;$emptyListStyle'>&nbsp;</td>";
410         }
411       }
412       $result.= "</tr>";
413     }
415     // Close list body
416     $result.= "</tbody></table></div>";
418     // Add the footer if requested
419     if ($this->showFooter) {
420       $result.= "<div class='nlistFooter'><div style='padding:3px'>";
422       foreach ($this->objectTypes as $objectType) {
423         if (isset($this->objectTypeCount[$objectType['label']])) {
424           $label= _($objectType['label']);
425           $result.= image($objectType['image'], null, $label)."&nbsp;".$this->objectTypeCount[$objectType['label']]."&nbsp;&nbsp;";
426         }
427       }
429       $result.= "</div></div>";
430     }
432     // Close list
433     $result.= $switch?"<input type='hidden' id='list_workaround'>":"";
435     // Add scroll positioner
436     $result.= '<script type="text/javascript" language="javascript">';
437     $result.= '$("t_nscrollbody").scrollTop= '.$this->scrollPosition.';';
438     $result.= 'var box = $("t_nscrollbody").onscroll= function() {$("position_'.$this->pid.'").value= this.scrollTop;}';
439     $result.= '</script>';
441     $smarty= get_smarty();
442     $smarty->assign("usePrototype", "true");
443     $smarty->assign("FILTER", $this->filter->render());
444     $smarty->assign("SIZELIMIT", print_sizelimit_warning());
445     $smarty->assign("LIST", $result);
447     // Assign navigation elements
448     $nav= $this->renderNavigation();
449     foreach ($nav as $key => $html) {
450       $smarty->assign($key, $html);
451     }
453     // Assign action menu / base
454     $smarty->assign("ACTIONS", $this->renderActionMenu());
455     $smarty->assign("BASE", $this->renderBase());
457     // Assign separator
458     $smarty->assign("SEPARATOR", "<img src='images/lists/seperator.png' alt='-' align='middle' height='16' width='1' class='center'>");
460     // Assign summary
461     $smarty->assign("HEADLINE", $this->headline);
463     // Try to load template from plugin the folder first...
464     $file = get_template_path($this->xmlData['definition']['template'], true);
466     // ... if this fails, try to load the file from the theme folder.
467     if(!file_exists($file)){
468       $file = get_template_path($this->xmlData['definition']['template']);
469     }
471     return ($smarty->fetch($file));
472   }
475   function update()
476   {
477     global $config;
478     $ui= get_userinfo();
480     // Take care of base selector
481     if ($this->baseMode) {
482       $this->baseSelector->update();
483       // Check if a wrong base was supplied
484       if(!$this->baseSelector->checkLastBaseUpdate()){
485          msg_dialog::display(_("Error"), msgPool::check_base(), ERROR_DIALOG);
486       }
487     }
489     // Save base
490     $refresh= false;
491     if ($this->baseMode) {
492       $this->base= $this->baseSelector->getBase();
493       session::global_set("CurrentMainBase", $this->base);
494       $refresh= true;
495     }
498     // Reset object counter / DN mapping
499     $this->objectTypeCount= array();
500     $this->objectDnMapping= array();
502     // Do not do anything if this is not our PID
503     if($refresh || !(isset($_REQUEST['PID']) && $_REQUEST['PID'] != $this->pid)) {
505       // Save position if set
506       if (isset($_POST['position_'.$this->pid]) && is_numeric($_POST['position_'.$this->pid])) {
507         $this->scrollPosition= $_POST['position_'.$this->pid];
508       }
510       // Override the base if we got a message from the browser navigation
511       if ($this->departmentBrowser && isset($_GET['act'])) {
512         if (preg_match('/^department_([0-9]+)$/', validate($_GET['act']), $match)){
513           if (isset($this->departments[$match[1]])){
514             $this->base= $this->departments[$match[1]]['dn'];
515             if ($this->baseMode) {
516               $this->baseSelector->setBase($this->base);
517             }
518             session::global_set("CurrentMainBase", $this->base);
519           }
520         }
521       }
523       // Filter POST with "act" attributes -> posted from action menu
524       if (isset($_POST['exec_act']) && $_POST['act'] != '') {
525         if (preg_match('/^export.*$/', $_POST['act']) && isset($this->exporter[$_POST['act']])) {
526           $exporter= $this->exporter[$_POST['act']];
527           $userinfo= ", "._("created by")." ".$ui->cn." - ".strftime('%A, %d. %B %Y, %H:%M:%S');
528           $entryIterator= new listingSortIterator($this->entries, $this->sortDirection[$this->sortColumn], "_sort".$this->sortColumn, $this->sortType);
529           $sortedEntries= array();
530           foreach ($entryIterator as $entry){
531             $sortedEntries[]= $entry;
532           }
533           $instance= new $exporter['class']($this->headline.$userinfo, $this->plainHeader, $sortedEntries, $this->exportColumns);
534           $type= call_user_func(array($exporter['class'], "getInfo"));
535           $type= $type[$_POST['act']];
536           send_binary_content($instance->query(), $type['filename'], $type= $type['mime']);
537         }
538       }
540       // Filter GET with "act" attributes
541       if (isset($_GET['act'])) {
542         $key= validate($_GET['act']);
543         if (preg_match('/^SORT_([0-9]+)$/', $key, $match)) {
544           // Switch to new column or invert search order?
545           $column= $match[1];
546           if ($this->sortColumn != $column) {
547             $this->sortColumn= $column;
548           } else {
549             $this->sortDirection[$column]= !$this->sortDirection[$column];
550           }
552           // Allow header to update itself according to the new sort settings
553           $this->renderHeader();
554         }
555       }
557       // Override base if we got signals from the navigation elements
558       $action= "";
559       foreach ($_POST as $key => $value) {
560         if (preg_match('/^(ROOT|BACK|HOME)(_x)?$/', $key, $match)) {
561           $action= $match[1];
562           break;
563         }
564       }
566       // Navigation handling
567       if ($action == 'ROOT') {
568         $deps= $ui->get_module_departments($this->categories);
569         $this->base= $deps[0];
570         $this->baseSelector->setBase($this->base);
571         session::global_set("CurrentMainBase", $this->base);
572       }
573       if ($action == 'BACK') {
574         $deps= $ui->get_module_departments($this->categories);
575         $base= preg_replace("/^[^,]+,/", "", $this->base);
576         if(in_array_ics($base, $deps)){
577           $this->base= $base;
578           $this->baseSelector->setBase($this->base);
579           session::global_set("CurrentMainBase", $this->base);
580         }
581       }
582       if ($action == 'HOME') {
583         $ui= get_userinfo();
584         $this->base= get_base_from_people($ui->dn);
585         $this->baseSelector->setBase($this->base);
586         session::global_set("CurrentMainBase", $this->base);
587       }
588     }
590     // Reload departments
591     if ($this->departmentBrowser){
592       $this->departments= $this->getDepartments();
593     }
595     // Update filter and refresh entries
596     $this->filter->setBase($this->base);
597     $this->entries= $this->filter->query();
599     // Fix filter if querie returns NULL
600     if ($this->entries == null) {
601       $this->entries= array();
602     }
603   }
606   function setBase($base)
607   {
608     $this->base= $base;
609     if ($this->baseMode) {
610       $this->baseSelector->setBase($this->base);
611     }
612   }
615   function getBase()
616   {
617     return $this->base;
618   }
621   function parseLayout($layout)
622   {
623     $result= array();
624     $layout= preg_replace("/^\|/", "", $layout);
625     $layout= preg_replace("/\|$/", "", $layout);
626     $cols= explode("|", $layout);
628     foreach ($cols as $index => $config) {
629       if ($config != "") {
630         $res= "";
631         $components= explode(';', $config);
632         foreach ($components as $part) {
633           if (preg_match("/^r$/", $part)) {
634             $res.= "text-align:right;";
635             continue;
636           }
637           if (preg_match("/^l$/", $part)) {
638             $res.= "text-align:left;";
639             continue;
640           }
641           if (preg_match("/^c$/", $part)) {
642             $res.= "text-align:center;";
643             continue;
644           }
645           if (preg_match("/^[0-9]+(|px|%)$/", $part)) {
646             $res.= "width:$part;min-width:$part;";
647             continue;
648           }
649         }
651         // Add minimum width for scalable columns
652         if (!preg_match('/width:/', $res)){
653           $res.= "min-width:200px;";
654         }
656         $result[$index]= " style='$res'";
657       } else {
658         $result[$index]= " style='min-width:100px;'";
659       }
660     }
662     // Save number of columns for later use
663     $this->numColumns= count($cols);
665     // Add no border to the last column
666     $result[$this->numColumns-1]= preg_replace("/'$/", "border-right:0;'", $result[$this->numColumns-1]);
668     return $result;
669   }
672   function renderCell($data, $config, $row)
673   {
674     // Replace flat attributes in data string
675     for ($i= 0; $i<$config['count']; $i++) {
676       $attr= $config[$i];
677       $value= "";
678       if (is_array($config[$attr])) {
679         $value= $config[$attr][0];
680       } else {
681         $value= $config[$attr];
682       }
683       $data= preg_replace("/%\{$attr\}/", $value, $data);
684     }
686     // Watch out for filters and prepare to execute them
687     $data= $this->processElementFilter($data, $config, $row);
689     // Replace all non replaced %{...} instances because they
690     // are non resolved attributes or filters
691     $data= preg_replace('/%{[^}]+}/', '&nbsp;', $data);
693     return $data;
694   }
697   function renderBase()
698   {
699     if (!$this->baseMode) {
700       return;
701     }
703     return $this->baseSelector->render();
704   }
707   function processElementFilter($data, $config, $row)
708   {
709     preg_match_all("/%\{filter:([^(]+)\((.*)\)\}/", $data, $matches, PREG_SET_ORDER);
711     foreach ($matches as $match) {
712       $cl= "";
713       $method= "";
714       if (preg_match('/::/', $match[1])) {
715         $cl= preg_replace('/::.*$/', '', $match[1]);
716         $method= preg_replace('/^.*::/', '', $match[1]);
717       } else {
718         if (!isset($this->filters[$match[1]])) {
719           continue;
720         }
721         $cl= preg_replace('/::.*$/', '', $this->filters[$match[1]]);
722         $method= preg_replace('/^.*::/', '', $this->filters[$match[1]]);
723       }
725       // Prepare params for function call
726       $params= array();
727       preg_match_all('/"[^"]+"|[^,]+/', $match[2], $parts);
728       foreach ($parts[0] as $param) {
730         // Row is replaced by the row number
731         if ($param == "row") {
732           $params[]= $row;
733           continue;
734         }
736         // pid is replaced by the current PID
737         if ($param == "pid") {
738           $params[]= $this->pid;
739           continue;
740         }
742         // base is replaced by the current base
743         if ($param == "base") {
744           $params[]= $this->getBase();
745           continue;
746         }
748         // Fixie with "" is passed directly
749         if (preg_match('/^".*"$/', $param)){
750           $params[]= preg_replace('/"/', '', $param);
751           continue;
752         }
754         // Move dn if needed
755         if ($param == "dn") {
756           $params[]= LDAP::fix($config["dn"]);
757           continue;
758         }
760         // LDAP variables get replaced by their objects
761         for ($i= 0; $i<$config['count']; $i++) {
762           if ($param == $config[$i]) {
763             $values= $config[$config[$i]];
764             if (is_array($values)){
765               unset($values['count']);
766             }
767             $params[]= $values;
768             break;
769           }
770         }
771       }
773       // Replace information
774       if ($cl == "listing") {
775         // Non static call - seems to result in errors
776         $data= @preg_replace('/'.preg_quote($match[0]).'/', call_user_func_array(array($this, "$method"), $params), $data);
777       } else {
778         // Static call
779         $data= preg_replace('/'.preg_quote($match[0]).'/', call_user_func_array(array($cl, $method), $params), $data);
780       }
781     }
783     return $data;
784   }
787   function getObjectType($types, $classes)
788   {
789     // Walk thru types and see if there's something matching
790     foreach ($types as $objectType) {
791       $ocs= $objectType['objectClass'];
792       if (!is_array($ocs)){
793         $ocs= array($ocs);
794       }
796       $found= true;
797       foreach ($ocs as $oc){
798         if (preg_match('/^!(.*)$/', $oc, $match)) {
799           $oc= $match[1];
800           if (in_array($oc, $classes)) {
801             $found= false;
802           }
803         } else {
804           if (!in_array($oc, $classes)) {
805             $found= false;
806           }
807         }
808       }
810       if ($found) {
811         return $objectType;
812       }
813     }
815     return null;
816   }
819   function filterObjectType($dn, $classes)
820   {
821     // Walk thru classes and return on first match
822     $result= "&nbsp;";
824     $objectType= $this->getObjectType($this->objectTypes, $classes);
825     if ($objectType) {
826       $this->objectDnMapping[$dn]= $objectType["objectClass"];
827       $result= image($objectType["image"], null, LDAP::fix($dn));
828       if (!isset($this->objectTypeCount[$objectType['label']])) {
829         $this->objectTypeCount[$objectType['label']]= 0;
830       }
831       $this->objectTypeCount[$objectType['label']]++;
832     }
834     return $result;
835   }
838   function filterActions($dn, $row, $classes)
839   {
840     // Do nothing if there's no menu defined
841     if (!isset($this->xmlData['actiontriggers']['action'])) {
842       return "&nbsp;";
843     }
845     // Go thru all actions
846     $result= "";
847     $actions= $this->xmlData['actiontriggers']['action'];
849     // Ensure we've a valid actions array, if there is only one action in the actiontriggers col
850     //  then we've to create a valid array here.
851     if(isset($actions['name'])) $actions = array($actions);
853     foreach($actions as $action) {
854       // Skip the entry completely if there's no permission to execute it
855       if (!$this->hasActionPermission($action, $dn, $classes)) {
856         $result.= image('images/empty.png');
857         continue;
858       }
860       // Skip entry if the pseudo filter does not fit
861       if (isset($action['filter']) && preg_match('/^[a-z0-9_]+!?=[a-z0-9_]+$/i', $action['filter'])) {
862         list($fa, $fv)= explode('=', $action['filter']);
863         if (preg_match('/^(.*)!$/', $fa, $m)){
864           $fa= $m[1];
865           if (isset($this->entries[$row][$fa]) && $this->entries[$row][$fa][0] == $fv) {
866             $result.= image('images/empty.png');
867             continue;
868           }
869         } else {
870           if (!isset($this->entries[$row][$fa]) && !$this->entries[$row][$fa][0] == $fv) {
871             $result.= image('images/empty.png');
872             continue;
873           }
874         }
875       }
878       // If there's an objectclass definition and we don't have it
879       // add an empty picture here.
880       if (isset($action['objectclass'])){
881         $objectclass= $action['objectclass'];
882         if (preg_match('/^!(.*)$/', $objectclass, $m)){
883           $objectclass= $m[1];
884           if(in_array($objectclass, $classes)) {
885             $result.= image('images/empty.png');
886             continue;
887           }
888         } elseif (is_string($objectclass)) {
889           if(!in_array($objectclass, $classes)) {
890             $result.= image('images/empty.png');
891             continue;
892           }
893         } elseif (is_array($objectclass)) {
894           if(count(array_intersect($objectclass, $classes)) != count($objectclass)){
895             $result.= image('images/empty.png');
896             continue;
897           }
898         }
899       }
901       // Render normal entries as usual
902       if ($action['type'] == "entry") {
903         $label= $this->processElementFilter($action['label'], $this->entries[$row], $row);
904         $image= $this->processElementFilter($action['image'], $this->entries[$row], $row);
905         $result.= image($image, "listing_".$action['name']."_$row", $label);
906       }
908       // Handle special types
909       if ($action['type'] == "copypaste" || $action['type'] == "snapshot") {
911         $objectType= $this->getObjectType($this->objectTypes, $this->entries[$row]['objectClass']);
912         $category= $class= null;
913         if ($objectType) {
914           $category= $objectType['category'];
915           $class= $objectType['class'];
916         }
918         if ($action['type'] == "copypaste") {
919           $copy = !isset($action['copy']) || $action['copy'] == "true";
920           $cut = !isset($action['cut']) || $action['cut'] == "true";
921           $result.= $this->renderCopyPasteActions($row, $this->entries[$row]['dn'], $category, $class,$copy,$cut);
922         } else {
923           $result.= $this->renderSnapshotActions($row, $this->entries[$row]['dn'], $category, $class);
924         }
925       }
926     }
928     return $result;
929   }
932   function filterDepartmentLink($row, $dn, $description)
933   {
934     $attr= $this->departments[$row]['sort-attribute'];
935     $name= $this->departments[$row][$attr];
936     if (is_array($name)){
937       $name= $name[0];
938     }
939     $result= sprintf("%s [%s]", $name, $description[0]);
940     return("<a href='?plug=".$_GET['plug']."&amp;PID=$this->pid&amp;act=department_$row' title='$dn'>$result</a>");
941   }
944   function filterLink()
945   {
946     $result= "&nbsp;";
948     $row= func_get_arg(0);
949     $pid= $this->pid;
950     $dn= LDAP::fix(func_get_arg(1));
951     $params= array(func_get_arg(2));
953     // Collect sprintf params
954     for ($i = 3;$i < func_num_args();$i++) {
955       $val= func_get_arg($i);
956       if (is_array($val)){
957         $params[]= $val[0];
958         continue;
959       }
960       $params[]= $val;
961     }
963     $result= "&nbsp;";
964     $trans= call_user_func_array("sprintf", $params);
965     if ($trans != "") {
966       return("<a href='?plug=".$_GET['plug']."&amp;PID=$pid&amp;act=listing_edit_$row' title='$dn'>$trans</a>");
967     }
969     return $result;
970   }
973   function renderNavigation()
974   {
975     $result= array();
976     $enableBack = true;
977     $enableRoot = true;
978     $enableHome = true;
980     $ui = get_userinfo();
982     /* Check if base = first available base */
983     $deps = $ui->get_module_departments($this->categories);
985     if(!count($deps) || $deps[0] == $this->filter->base){
986       $enableBack = false;
987       $enableRoot = false;
988     }
990     $listhead ="";
992     /* Check if we are in users home  department */
993     if(!count($deps) || $this->filter->base == get_base_from_people($ui->dn)){
994       $enableHome = false;
995     }
997     /* Draw root button */
998     if($enableRoot){
999       $result["ROOT"]= image('images/lists/root.png', 'ROOT', _("Root"));
1000     }else{
1001       $result["ROOT"]= image('images/lists/root-grey.png', null, _("Root"));
1002     }
1004     /* Draw back button */
1005     if($enableBack){
1006       $result["BACK"]= image('images/lists/back.png', 'BACK', _("Go up one department"));
1007     }else{
1008       $result["BACK"]= image('images/lists/back-grey.png', null, _("Go up one department"));
1009     }
1011     /* Draw home button */
1012    /* Draw home button */
1013     if($enableHome){
1014       $result["HOME"]= image('images/lists/home.png', 'HOME', _("Go to users department"));
1015     }else{
1016       $result["HOME"]= image('images/lists/home-grey.png', null, _("Go to users department"));
1017     }
1020     /* Draw reload button, this button is enabled everytime */
1021     $result["RELOAD"]= image('images/lists/reload.png', 'REFRESH', _("Reload list"));
1023     return ($result);
1024   }
1027   function getAction()
1028   {
1029     // Do not do anything if this is not our PID, or there's even no PID available...
1030     if(!isset($_REQUEST['PID']) || $_REQUEST['PID'] != $this->pid) {
1031       return;
1032     }
1034     // Save position if set
1035     if (isset($_POST['position_'.$this->pid]) && is_numeric($_POST['position_'.$this->pid])) {
1036       $this->scrollPosition= $_POST['position_'.$this->pid];
1037     }
1039     $result= array("targets" => array(), "action" => "");
1041     // Filter GET with "act" attributes
1042     if (isset($_GET['act'])) {
1043       $key= validate($_GET['act']);
1044       $target= preg_replace('/^listing_[a-zA-Z_]+_([0-9]+)$/', '$1', $key);
1045       if (isset($this->entries[$target]['dn'])) {
1046         $result['action']= preg_replace('/^listing_([a-zA-Z_]+)_[0-9]+$/', '$1', $key);
1047         $result['targets'][]= $this->entries[$target]['dn'];
1048       }
1050       // Drop targets if empty
1051       if (count($result['targets']) == 0) {
1052         unset($result['targets']);
1053       }
1054       return $result;
1055     }
1057     // Filter POST with "listing_" attributes
1058     foreach ($_POST as $key => $prop) {
1060       // Capture selections
1061       if (preg_match('/^listing_selected_[0-9]+$/', $key)) {
1062         $target= preg_replace('/^listing_selected_([0-9]+)$/', '$1', $key);
1063         if (isset($this->entries[$target]['dn'])) {
1064           $result['targets'][]= $this->entries[$target]['dn'];
1065         }
1066         continue;
1067       }
1069       // Capture action with target - this is a one shot
1070       if (preg_match('/^listing_[a-zA-Z_]+_[0-9]+(|_x)$/', $key)) {
1071         $target= preg_replace('/^listing_[a-zA-Z_]+_([0-9]+)(|_x)$/', '$1', $key);
1072         if (isset($this->entries[$target]['dn'])) {
1073           $result['action']= preg_replace('/^listing_([a-zA-Z_]+)_[0-9]+(|_x)$/', '$1', $key);
1074           $result['targets']= array($this->entries[$target]['dn']);
1075         }
1076         break;
1077       }
1079       // Capture action without target
1080       if (preg_match('/^listing_[a-zA-Z_]+(|_x)$/', $key)) {
1081         $result['action']= preg_replace('/^listing_([a-zA-Z_]+)(|_x)$/', '$1', $key);
1082         continue;
1083       }
1084     }
1086     // Filter POST with "act" attributes -> posted from action menu
1087     if (isset($_POST['act']) && $_POST['act'] != '') {
1088       if (!preg_match('/^export.*$/', $_POST['act'])){
1089         $result['action']= validate($_POST['act']);
1090       }
1091     }
1093     // Drop targets if empty
1094     if (count($result['targets']) == 0) {
1095       unset($result['targets']);
1096     }
1097     return $result;
1098   }
1101   function renderActionMenu()
1102   {
1103     // Don't send anything if the menu is not defined
1104     if (!isset($this->xmlData['actionmenu']['action'])){
1105       return "";
1106     }
1108     // Array?
1109     if (isset($this->xmlData['actionmenu']['action']['type'])){
1110       $this->xmlData['actionmenu']['action']= array($this->xmlData['actionmenu']['action']);
1111     }
1113     // Load shortcut
1114     $actions= &$this->xmlData['actionmenu']['action'];
1115     $result= "<input type='hidden' name='act' id='actionmenu' value=''><div style='display:none'><input type='submit' name='exec_act' id='exec_act' value=''></div>".
1116              "<ul class='level1' id='root'><li><a href='#'>"._("Actions")."&nbsp;".image("images/lists/sort-down.png")."</a>";
1118     // Build ul/li list
1119     $result.= $this->recurseActions($actions);
1121     return "<div id='pulldown'>".$result."</li></ul><div>";
1122   }
1125   function recurseActions($actions)
1126   {
1127     global $class_mapping;
1128     static $level= 2;
1129     $result= "<ul class='level$level'>";
1130     $separator= "";
1132     foreach ($actions as $action) {
1134       // Skip the entry completely if there's no permission to execute it
1135       if (!$this->hasActionPermission($action, $this->filter->base)) {
1136         continue;
1137       }
1139       // Skip entry if there're missing dependencies
1140       if (isset($action['depends'])) {
1141         $deps= is_array($action['depends'])?$action['depends']:array($action['depends']);
1142         foreach($deps as $clazz) {
1143           if (!isset($class_mapping[$clazz])){
1144             continue 2;
1145           }
1146         }
1147       }
1149       // Fill image if set
1150       $img= "";
1151       if (isset($action['image'])){
1152         $img= image($action['image'])."&nbsp;";
1153       }
1155       if ($action['type'] == "separator"){
1156         $separator= " style='border-top:1px solid #AAA' ";
1157         continue;
1158       }
1160       // Dive into subs
1161       if ($action['type'] == "sub" && isset($action['action'])) {
1162         $level++;
1163         if (isset($action['label'])){
1164           $result.= "<li$separator><a href='#'>$img"._($action['label'])."&nbsp;".image('images/forward-arrow.png')."</a>";
1165         }
1167         // Ensure we've an array of actions, this enables sub menus with only one action.
1168         if(isset($action['action']['type'])){
1169           $action['action'] = array($action['action']);
1170         }
1172         $result.= $this->recurseActions($action['action'])."</li>";
1173         $level--;
1174         $separator= "";
1175         continue;
1176       }
1178       // Render entry elseways
1179       if (isset($action['label'])){
1180         $result.= "<li$separator><a href='#' onClick='document.getElementById(\"actionmenu\").value= \"".$action['name']."\";mainform.submit();'>$img"._($action['label'])."</a></li>";
1181       }
1183       // Check for special types
1184       switch ($action['type']) {
1185         case 'copypaste':
1186           $cut = !isset($action['cut']) || $action['cut'] != "false";
1187           $copy = !isset($action['copy']) || $action['copy'] != "false";
1188           $result.= $this->renderCopyPasteMenu($separator, $copy , $cut);
1189           break;
1191         case 'snapshot':
1192           $result.= $this->renderSnapshotMenu($separator);
1193           break;
1195         case 'exporter':
1196           $result.= $this->renderExporterMenu($separator);
1197           break;
1199         case 'daemon':
1200           $result.= $this->renderDaemonMenu($separator);
1201           break;
1202       }
1204       $separator= "";
1205     }
1207     $result.= "</ul>";
1208     return $result;
1209   }
1212   function hasActionPermission($action, $dn, $classes= null)
1213   {
1214     $ui= get_userinfo();
1216     if (isset($action['acl'])) {
1217       $acls= $action['acl'];
1218       if (!is_array($acls)) {
1219         $acls= array($acls);
1220       }
1222       // Every ACL has to pass
1223       foreach ($acls as $acl) {
1224         $module= $this->categories;
1225         $aclList= array();
1227         // Replace %acl if available
1228         if ($classes) {
1229           $otype= $this->getObjectType($this->objectTypes, $classes);
1230           $acl= str_replace('%acl', $otype['category']."/".$otype['class'], $acl);
1231         }
1233         // Split for category and plugins if needed
1234         // match for "[rw]" style entries
1235         if (preg_match('/^\[([rwcdm]+)\]$/', $acl, $match)){
1236           $aclList= array($match[1]);
1237         }
1239         // match for "users[rw]" style entries
1240         if (preg_match('/^([a-zA-Z0-9]+)\[([rwcdm]+)\]$/', $acl, $match)){
1241           $module= $match[1];
1242           $aclList= array($match[2]);
1243         }
1245         // match for "users/user[rw]" style entries
1246         if (preg_match('/^([a-zA-Z0-9]+\/[a-zA-Z0-9]+)\[([rwcdm]+)\]$/', $acl, $match)){
1247           $module= $match[1];
1248           $aclList= array($match[2]);
1249         }
1251         // match "users/user[userPassword:rw(,...)*]" style entries
1252         if (preg_match('/^([a-zA-Z0-9]+\/[a-zA-Z0-9]+)\[([a-zA-Z0-9]+:[rwcdm]+(,[a-zA-Z0-9]+:[rwcdm]+)*)\]$/', $acl, $match)){
1253           $module= $match[1];
1254           $aclList= explode(',', $match[2]);
1255         }
1257         // Walk thru prepared ACL by using $module
1258         foreach($aclList as $sAcl) {
1259           $checkAcl= "";
1261           // Category or detailed permission?
1262           if (strpos($module, '/') !== false) {
1263             if (preg_match('/([a-zA-Z0-9]+):([rwcdm]+)/', $sAcl, $m) ) {
1264               $checkAcl= $ui->get_permissions($dn, $module, $m[1]);
1265               $sAcl= $m[2];
1266             } else {
1267               $checkAcl= $ui->get_permissions($dn, $module, '0');
1268             }
1269           } else {
1270             $checkAcl= $ui->get_category_permissions($dn, $module);
1271           }
1273           // Split up remaining part of the acl and check if it we're
1274           // allowed to do something...
1275           $parts= str_split($sAcl);
1276           foreach ($parts as $part) {
1277             if (strpos($checkAcl, $part) === false){
1278               return false;
1279             }
1280           }
1282         }
1283       }
1284     }
1286     return true;
1287   }
1290   function refreshBasesList()
1291   {
1292     global $config;
1293     $ui= get_userinfo();
1295     // Do some array munching to get it user friendly
1296     $ids= $config->idepartments;
1297     $d= $ui->get_module_departments($this->categories);
1298     $k_ids= array_keys($ids);
1299     $deps= array_intersect($d,$k_ids);
1301     // Fill internal bases list
1302     $this->bases= array();
1303     foreach($k_ids as $department){
1304       $this->bases[$department] = $ids[$department];
1305     }
1307     // Populate base selector if already present
1308     if ($this->baseSelector && $this->baseMode) {
1309       $this->baseSelector->setBases($this->bases);
1310       $this->baseSelector->update(TRUE);
1311     }
1312   }
1315   function getDepartments()
1316   {
1317     $departments= array();
1318     $ui= get_userinfo();
1320     // Get list of supported department types
1321     $types = departmentManagement::get_support_departments();
1323     // Load departments allowed by ACL
1324     $validDepartments = $ui->get_module_departments($this->categories);
1326     // Build filter and look in the LDAP for possible sub departments
1327     // of current base
1328     $filter= "(&(objectClass=gosaDepartment)(|";
1329     $attrs= array("description", "objectClass");
1330     foreach($types as $name => $data){
1331       $filter.= "(objectClass=".$data['OC'].")";
1332       $attrs[]= $data['ATTR'];
1333     }
1334     $filter.= "))";
1335     $res= get_list($filter, $this->categories, $this->base, $attrs, GL_NONE);
1337     // Analyze list of departments
1338     foreach ($res as $department) {
1339       if (!in_array($department['dn'], $validDepartments)) {
1340         continue;
1341       }
1343       // Add the attribute where we use for sorting
1344       $oc= null;
1345       foreach(array_keys($types) as $type) {
1346         if (in_array($type, $department['objectClass'])) {
1347           $oc= $type;
1348           break;
1349         }
1350       }
1351       $department['sort-attribute']= $types[$oc]['ATTR'];
1353       // Move to the result list
1354       $departments[]= $department;
1355     }
1357     return $departments;
1358   }
1361   function renderCopyPasteMenu($separator, $copy= true, $cut= true)
1362   {
1363     // We can only provide information if we've got a copypaste handler
1364     // instance
1365     if(!(isset($this->copyPasteHandler) && is_object($this->copyPasteHandler))){
1366       return "";
1367     }
1369     // Presets
1370     $result= "";
1371     $read= $paste= false;
1372     $ui= get_userinfo();
1374     // Switch flags to on if there's at least one category which allows read/paste
1375     foreach($this->categories as $category){
1376       $read= $read || preg_match('/r/', $ui->get_category_permissions($this->base, $category));
1377       $paste= $paste || $ui->is_pasteable($this->base, $category) == 1;
1378     }
1381     // Draw entries that allow copy and cut
1382     if($read){
1384       // Copy entry
1385       if($copy){
1386         $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>";
1387         $separator= "";
1388       }
1390       // Cut entry
1391       if($cut){
1392         $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>";
1393         $separator= "";
1394       }
1395     }
1397     // Draw entries that allow pasting entries
1398     if($paste){
1399       if($this->copyPasteHandler->entries_queued()){
1400         $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>";
1401       }else{
1402         $result.= "<li$separator><a href='#'>".image('images/lists/paste-grey.png')."&nbsp;"._("Paste")."</a></li>";
1403       }
1404     }
1405     
1406     return($result);
1407   }
1410   function renderCopyPasteActions($row, $dn, $category, $class, $copy= true, $cut= true)
1411   {
1412     // We can only provide information if we've got a copypaste handler
1413     // instance
1414     if(!(isset($this->copyPasteHandler) && is_object($this->copyPasteHandler))){
1415       return "";
1416     }
1418     // Presets
1419     $ui = get_userinfo();
1420     $result = "";
1422     // Render cut entries
1423     if($cut){
1424       if($ui->is_cutable($dn, $category, $class)){
1425         $result.= image('images/lists/cut.png', "listing_cut_$row", _("Cut this entry"));
1426       }else{
1427         $result.= image('images/empty.png');
1428       }
1429     }
1431     // Render copy entries
1432     if($copy){
1433       if($ui->is_copyable($dn, $category, $class)){
1434         $result.= image('images/lists/copy.png', "listing_copy_$row", _("Copy this entry"));
1435       }else{
1436         $result.= image('images/empty.png');
1437       }
1438     }
1440     return($result);
1441   }
1444   function renderSnapshotMenu($separator)
1445   {
1446     // We can only provide information if we've got a snapshot handler
1447     // instance
1448     if(!(isset($this->snapshotHandler) && is_object($this->snapshotHandler))){
1449       return "";
1450     }
1452     // Presets
1453     $result = "";
1454     $ui = get_userinfo();
1456     if($this->snapshotHandler->enabled() && $ui->allow_snapshot_restore($this->base, $this->categories)){
1458       // Check if there is something to restore
1459       $restore= false;
1460       foreach($this->snapshotHandler->getSnapshotBases() as $base){
1461         $restore= $restore || count($this->snapshotHandler->getDeletedSnapshots($base)) > 0;
1462       }
1464       // Draw icons according to the restore flag
1465       if($restore){
1466         $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>";
1467       }else{
1468         $result.= "<li$separator><a href='#'>".image('images/lists/restore-grey.png')."&nbsp;"._("Restore snapshots")."</a></li>";
1469       }
1470     }
1472     return($result);
1473   }
1476   function renderExporterMenu($separator)
1477   {
1478     // Presets
1479     $result = "";
1481     // Draw entries
1482     $result.= "<li$separator><a href='#'>".image('images/lists/export.png')."&nbsp;"._("Export list")."&nbsp;".image("images/forward-arrow.png")."</a><ul class='level3'>";
1484     // Export CVS as build in exporter
1485     foreach ($this->exporter as $action => $exporter) {
1486       $result.= "<li><a href='#' onClick='document.getElementById(\"actionmenu\").value= \"$action\";document.getElementById(\"exec_act\").click();'>".image($exporter['image'])."&nbsp;".$exporter['label']."</a></li>";
1487     }
1489     // Finalize list
1490     $result.= "</ul></li>";
1492     return($result);
1493   }
1496   function renderSnapshotActions($row, $dn, $category, $class, $copy= true, $cut= true)
1497   {
1498     // We can only provide information if we've got a snapshot handler
1499     // instance
1500     if(!(isset($this->snapshotHandler) && is_object($this->snapshotHandler))){
1501       return "";
1502     }
1504     // Presets
1505     $result= "";
1506     $ui = get_userinfo();
1508     // Only act if enabled here
1509     if($this->snapshotHandler->enabled()){
1511       // Draw restore button
1512       if ($ui->allow_snapshot_restore($dn, $category)){
1514         // Do we have snapshots for this dn?
1515         if($this->snapshotHandler->hasSnapshots($dn)){
1516           $result.= image('images/lists/restore.png', "listing_restore_$row", _("Restore snapshot"));
1517         } else {
1518           $result.= image('images/lists/restore-grey.png');
1519         }
1520       }
1522       // Draw snapshot button
1523       if($ui->allow_snapshot_create($dn, $category)){
1524           $result.= image('images/snapshot.png', "listing_snapshot_$row", _("Create a new snapshot from this object"));
1525       }else{
1526           $result.= image('images/empty.png');
1527       }
1528     }
1530     return($result);
1531   }
1534   function renderDaemonMenu($separator)
1535   {
1536     $result= "";
1538     // If there is a daemon registered, draw the menu entries
1539     if(class_available("DaemonEvent")){
1540       $events= DaemonEvent::get_event_types_by_category($this->categories);
1541       if(isset($events['BY_CLASS']) && count($events['BY_CLASS'])){
1542         foreach($events['BY_CLASS'] as $name => $event){
1543           $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>";
1544           $separator= "";
1545         }
1546       }
1547     }
1549     return $result;
1550   }
1553   function getEntry($dn)
1554   {
1555     foreach ($this->entries as $entry) {
1556       if (isset($entry['dn']) && strcasecmp($dn, $entry['dn']) == 0){
1557         return $entry;
1558       }
1559     }
1560     return null;
1561   }
1564   function getEntries()
1565   {
1566     return $this->entries;
1567   }
1570   function getType($dn)
1571   {
1572     if (isset($this->objectDnMapping[$dn])) {
1573       return $this->objectDnMapping[$dn];
1574     }
1575     return null;
1576   }
1580 ?>