Code

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