Code

b91c063ee4d1ec22aa87760937008a6358458369
[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[]= 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         $this->objectTypes[]= $this->xmlData['definition']['objectType'][$index];
178         if (isset($this->xmlData['definition']['objectType'][$index]['category'])){
179           $this->categories[]= $otype['category'];
180         }
181       }
182     }
184     // Parse layout per column
185     $this->colprops= $this->parseLayout($this->xmlData['table']['layout']);
187     // Prepare table headers
188     $this->renderHeader();
190     // Assign headline/Categories
191     $this->headline= _($this->xmlData['definition']['label']);
192     if (!is_array($this->categories)){
193       $this->categories= array($this->categories);
194     }
196     // Evaluate columns to be exported
197     if (isset($this->xmlData['table']['column'])){
198       foreach ($this->xmlData['table']['column'] as $index => $config) {
199         if (isset($config['export']) && $config['export'] == "true"){
200           $this->exportColumns[]= $index;
201         }
202       }
203     }
205     return true;  
206   }
209   function renderHeader()
210   {
211     $this->header= array();
212     $this->plainHeader= array();
214     // Initialize sort?
215     $sortInit= false;
216     if (!$this->sortDirection) {
217       $this->sortColumn= 0;
218       if (isset($this->xmlData['definition']['defaultSortColumn'])){
219         $this->sortColumn= $this->xmlData['definition']['defaultSortColumn'];
220       } else {
221         $this->sortAttribute= "";
222       }
223       $this->sortDirection= array();
224       $sortInit= true;
225     }
227     if (isset($this->xmlData['table']['column'])){
228       foreach ($this->xmlData['table']['column'] as $index => $config) {
229         // Initialize everything to one direction
230         if ($sortInit) {
231           $this->sortDirection[$index]= false;
232         }
234         $sorter= "";
235         if ($index == $this->sortColumn && isset($config['sortAttribute']) &&
236             isset($config['sortType'])) {
237           $this->sortAttribute= $config['sortAttribute'];
238           $this->sortType= $config['sortType'];
239           $sorter= "&nbsp;<img border='0' title='".($this->sortDirection[$index]?_("Up"):_("Down"))."' src='images/lists/sort-".($this->sortDirection[$index]?"up":"down").".png' align='top'>";
240         }
241         $sortable= (isset($config['sortAttribute']));
243         $link= "href='?plug=".$_GET['plug']."&amp;PID=".$this->pid."&amp;act=SORT_$index'";
244         if (isset($config['label'])) {
245           if ($sortable) {
246             $this->header[$index]= "<td class='listheader' ".$this->colprops[$index]."><a $link>"._($config['label'])."$sorter</a></td>";
247           } else {
248             $this->header[$index]= "<td class='listheader' ".$this->colprops[$index].">"._($config['label'])."</td>";
249           }
250           $this->plainHeader[]= _($config['label']);
251         } else {
252           if ($sortable) {
253             $this->header[$index]= "<td class='listheader' ".$this->colprops[$index]."><a $link>&nbsp;$sorter</a></td>";
254           } else {
255             $this->header[$index]= "<td class='listheader' ".$this->colprops[$index].">&nbsp;</td>";
256           }
257           $this->plainHeader[]= "";
258         }
259       }
260     }
261   }
264   function render()
265   {
266     // Check for exeeded sizelimit
267     if (($message= check_sizelimit()) != ""){
268       return($message);
269     }
271     // Some browsers don't have the ability do do scrollable table bodies, filter them
272     // here.
273     $switch= false;
274     if (preg_match('/(Opera|Konqueror|Safari|msie)/i', $_SERVER['HTTP_USER_AGENT'])){
275       $switch= true;
276     }
278     // Initialize list
279     $result= "<input type='hidden' value='$this->pid' name='PID'>\n";
280     $result.= "<input type='hidden' name='position_".$this->pid."' id='position_".$this->pid."'>\n";
281     $height= 450;
282     if ($this->height != 0) {
283       $result.= "<input type='hidden' value='$this->height' id='d_height'>\n";
284       $height= $this->height;
285     }
286     
287     $result.= "<table cellpadding='0' cellspacing='0' border='0'><tr><td><div class='listContainer' id='d_scrollbody' style='border-top:1px solid #B0B0B0;border-right:1px solid #B0B0B0;width:700px;min-height:".($height+25)."px;'>\n";
289     $height= "";
290     if ($switch){
291       $height= "height:100%;";
292     }
293     $result.= "<table summary='$this->headline' style='${height}width:100%; table-layout:fixed;' cellspacing='0' cellpadding='0' id='t_scrolltable'>\n";
294     $this->numColumns= count($this->colprops) + ($this->multiSelect?1:0);
296     // Build list header
297     $result.= "<thead class='fixedListHeader listHeaderFormat'><tr>\n";
298     if ($this->multiSelect) {
299       $width= "24px";
300       if (preg_match('/Konqueror/i', $_SERVER['HTTP_USER_AGENT'])){
301         $width= "28px";
302       }
303       $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";
304     }
305     foreach ($this->header as $header) {
306       $result.= $header;
307     }
308     $result.= "</tr></thead>\n";
310     // Build list body
311     $result.= "<tbody class='listScrollContent listBodyFormat' id='t_nscrollbody' style='height:".$height."px;'>\n";
313     // No results? Just take an empty colspanned row
314     if (count($this->entries) + count($this->departments) == 0) {
315       $result.= "<tr class='rowxp0'><td class='list1nohighlight' colspan='$this->numColumns' style='height:100%;border-right:0px;width:100%;'>&nbsp;</td></tr>";
316     }
318     // Line color alternation
319     $alt= 0;
320     $deps= 0;
322     // Draw department browser if configured and we're not in sub mode
323     $this->useSpan= false;
324     if ($this->departmentBrowser && $this->filter->scope != "sub") {
325       // Fill with department browser if configured this way
326       $departmentIterator= new departmentSortIterator($this->departments, $this->sortDirection[$this->sortColumn]);
327       foreach ($departmentIterator as $row => $entry){
328         $result.="<tr class='rowxp".($alt&1)."'>";
330         // Render multi select if needed
331         if ($this->multiSelect) {
332           $result.="<td style='text-align:center;padding:0;' class='list1'>&nbsp;</td>";
333         }
335         // Render defined department columns, fill the rest with some stuff
336         $rest= $this->numColumns - 1;
337         foreach ($this->xmlData['table']['department'] as $index => $config) {
338           $colspan= 1;
339           if (isset($config['span'])){
340             $colspan= $config['span'];
341             $this->useSpan= true;
342           }
343           $result.="<td colspan='$colspan' ".$this->colprops[$index]." class='list1'>".$this->renderCell($config['value'], $entry, $row)."</td>";
344           $rest-= $colspan;
345         }
347         // Fill remaining cols with nothing
348         $last= $this->numColumns - $rest;
349         for ($i= 0; $i<$rest; $i++){
350           $result.= "<td ".$this->colprops[$last+$i-1]." class='list1'>&nbsp;</td>";
351         }
352         $result.="</tr>";
354         $alt++;
355       }
356       $deps= $alt;
357     }
359     // Fill with contents, sort as configured
360     foreach ($this->entries as $row => $entry) {
361       $trow= "";
363       // Render multi select if needed
364       if ($this->multiSelect) {
365         $trow.="<td style='text-align:center;width:20px;' class='list0'><input type='checkbox' id='listing_selected_$row' name='listing_selected_$row'></td>\n";
366       }
368       foreach ($this->xmlData['table']['column'] as $index => $config) {
369         $renderedCell= $this->renderCell($config['value'], $entry, $row);
370         $trow.="<td ".$this->colprops[$index]." class='list0'>".$renderedCell."</td>\n";
372         // Save rendered column
373         $sort= preg_replace('/.*>([^<]+)<.*$/', '$1', $renderedCell);
374         $sort= preg_replace('/&nbsp;/', '', $sort);
375         if (preg_match('/</', $sort)){
376           $sort= "";
377         }
378         $this->entries[$row]["_sort$index"]= $sort;
379       }
381       // Save rendered entry
382       $this->entries[$row]['_rendered']= $trow;
383     }
385     // Complete list by sorting entries for _sort$index and appending them to the output
386     $entryIterator= new listingSortIterator($this->entries, $this->sortDirection[$this->sortColumn], "_sort".$this->sortColumn, $this->sortType);
387     foreach ($entryIterator as $row => $entry){
388       $alt++;
389       $result.="<tr class='rowxp".($alt&1)."'>\n";
390       $result.= $entry['_rendered'];
391       $result.="</tr>\n";
392     }
394     // Need to fill the list if it's not full (nobody knows why this is 22 ;-))
395     $emptyListStyle= (count($this->entries) + (($this->useSpan && count($this->entries))?$deps:0) == 0)?"border:0;":"";
396     if ((count($this->entries) + $deps) < 22) {
397       $result.= "<tr>";
398       for ($i= 0; $i<$this->numColumns; $i++) {
399         if ($i == 0) {
400           $result.= "<td class='list1nohighlight' style='$emptyListStyle height:100%;'>&nbsp;</td>";
401           continue;
402         }
403         if ($i != $this->numColumns-1) {
404           $result.= "<td class='list1nohighlight' style='$emptyListStyle'>&nbsp;</td>";
405         } else {
406           $result.= "<td class='list1nohighlight' style='border-right:0;$emptyListStyle'>&nbsp;</td>";
407         }
408       }
409       $result.= "</tr>";
410     }
412     // Close list body
413     $result.= "</tbody></table></div></td></tr>";
415     // Add the footer if requested
416     if ($this->showFooter) {
417       $result.= "<tr><td class='nlistFooter'>";
419       foreach ($this->objectTypes as $objectType) {
420         if (isset($this->objectTypeCount[$objectType['label']])) {
421           $label= _($objectType['label']);
422           $result.= "<img class='center' src='".$objectType['image']."' title='$label' alt='$label'>&nbsp;".$this->objectTypeCount[$objectType['label']]."&nbsp;&nbsp;&nbsp;&nbsp;";
423         }
424       }
426       $result.= "</td></tr>";
427     }
429     // Close list
430     $result.= "</table>";
431     $result.= $switch?"<input type='hidden' id='list_workaround'>":"";
433     // Add scroll positioner
434     $result.= '<script type="text/javascript" language="javascript">';
435     $result.= '$("t_nscrollbody").scrollTop= '.$this->scrollPosition.';';
436     $result.= 'var box = $("t_nscrollbody").onscroll= function() {$("position_'.$this->pid.'").value= this.scrollTop;}';
437     $result.= '</script>';
439     $smarty= get_smarty();
440     $smarty->assign("usePrototype", "true");
441     $smarty->assign("FILTER", $this->filter->render());
442     $smarty->assign("SIZELIMIT", print_sizelimit_warning());
443     $smarty->assign("LIST", $result);
445     // Assign navigation elements
446     $nav= $this->renderNavigation();
447     foreach ($nav as $key => $html) {
448       $smarty->assign($key, $html);
449     }
451     // Assign action menu / base
452     $smarty->assign("ACTIONS", $this->renderActionMenu());
453     $smarty->assign("BASE", $this->renderBase());
455     // Assign separator
456     $smarty->assign("SEPARATOR", "<img src='images/lists/seperator.png' alt='-' align='middle' height='16' width='1' class='center'>");
458     // Assign summary
459     $smarty->assign("HEADLINE", $this->headline);
461     // Try to load template from plugin the folder first...
462     $file = get_template_path($this->xmlData['definition']['template'], true);
464     // ... if this fails, try to load the file from the theme folder.
465     if(!file_exists($file)){
466       $file = get_template_path($this->xmlData['definition']['template']);
467     }
469     return ($smarty->fetch($file));
470   }
473   function update()
474   {
475     global $config;
476     $ui= get_userinfo();
478     // Take care of base selector
479     $this->baseSelector->update();
481     // Save base
482     $refresh= false;
483     if ($this->baseMode) {
484       $this->base= $this->baseSelector->getBase();
485       session::global_set("CurrentMainBase", $this->base);
486       $refresh= true;
487     }
490     // Reset object counter / DN mapping
491     $this->objectTypeCount= array();
492     $this->objectDnMapping= array();
494     // Do not do anything if this is not our PID
495     if($refresh || !(isset($_REQUEST['PID']) && $_REQUEST['PID'] != $this->pid)) {
497       // Save position if set
498       if (isset($_POST['position_'.$this->pid]) && is_numeric($_POST['position_'.$this->pid])) {
499         $this->scrollPosition= $_POST['position_'.$this->pid];
500       }
502       // Override the base if we got a message from the browser navigation
503       if ($this->departmentBrowser && isset($_GET['act'])) {
504         if (preg_match('/^department_([0-9]+)$/', validate($_GET['act']), $match)){
505           if (isset($this->departments[$match[1]])){
506             $this->base= $this->departments[$match[1]]['dn'];
507             if ($this->baseMode) {
508               $this->baseSelector->setBase($this->base);
509             }
510             session::global_set("CurrentMainBase", $this->base);
511           }
512         }
513       }
515       // Filter POST with "act" attributes -> posted from action menu
516       if (isset($_POST['exec_act']) && $_POST['act'] != '') {
517         if (preg_match('/^export.*$/', $_POST['act']) && isset($this->exporter[$_POST['act']])) {
518           $exporter= $this->exporter[$_POST['act']];
519           $userinfo= ", "._("created by")." ".$ui->cn." - ".strftime('%A, %d. %B %Y, %H:%M:%S');
520           $entryIterator= new listingSortIterator($this->entries, $this->sortDirection[$this->sortColumn], "_sort".$this->sortColumn, $this->sortType);
521           $sortedEntries= array();
522           foreach ($entryIterator as $entry){
523             $sortedEntries[]= $entry;
524           }
525           $instance= new $exporter['class']($this->headline.$userinfo, $this->plainHeader, $sortedEntries, $this->exportColumns);
526           $type= call_user_func(array($exporter['class'], "getInfo"));
527           $type= $type[$_POST['act']];
528           send_binary_content($instance->query(), $type['filename'], $type= $type['mime']);
529         }
530       }
532       // Filter GET with "act" attributes
533       if (isset($_GET['act'])) {
534         $key= validate($_GET['act']);
535         if (preg_match('/^SORT_([0-9]+)$/', $key, $match)) {
536           // Switch to new column or invert search order?
537           $column= $match[1];
538           if ($this->sortColumn != $column) {
539             $this->sortColumn= $column;
540           } else {
541             $this->sortDirection[$column]= !$this->sortDirection[$column];
542           }
544           // Allow header to update itself according to the new sort settings
545           $this->renderHeader();
546         }
547       }
549       // Override base if we got signals from the navigation elements
550       $action= "";
551       foreach ($_POST as $key => $value) {
552         if (preg_match('/^(ROOT|BACK|HOME)_x$/', $key, $match)) {
553           $action= $match[1];
554           break;
555         }
556       }
558       // Navigation handling
559       if ($action == 'ROOT') {
560         $deps= $ui->get_module_departments($this->categories);
561         $this->base= $deps[0];
562         $this->baseSelector->setBase($this->base);
563       }
564       if ($action == 'BACK') {
565         $deps= $ui->get_module_departments($this->categories);
566         $base= preg_replace("/^[^,]+,/", "", $this->base);
567         if(in_array_ics($base, $deps)){
568           $this->base= $base;
569           $this->baseSelector->setBase($this->base);
570         }
571       }
572       if ($action == 'HOME') {
573         $ui= get_userinfo();
574         $this->base= $this->filter->getObjectBase($ui->dn);
575         $this->baseSelector->setBase($this->base);
576       }
577     }
579     // Reload departments
580     if ($this->departmentBrowser){
581       $this->departments= $this->getDepartments();
582     }
584     // Update filter and refresh entries
585     $this->filter->setBase($this->base);
586     $this->entries= $this->filter->query();
588     // Fix filter if querie returns NULL
589     if ($this->entries == null) {
590       $this->entries= array();
591     }
592   }
595   function setBase($base)
596   {
597     $this->base= $base;
598     if ($this->baseMode) {
599       $this->baseSelector->setBase($this->base);
600     }
601   }
604   function getBase()
605   {
606     return $this->base;
607   }
610   function parseLayout($layout)
611   {
612     $result= array();
613     $layout= preg_replace("/^\|/", "", $layout);
614     $layout= preg_replace("/\|$/", "", $layout);
615     $cols= explode("|", $layout);
617     foreach ($cols as $index => $config) {
618       if ($config != "") {
619         $res= "";
620         $components= explode(';', $config);
621         foreach ($components as $part) {
622           if (preg_match("/^r$/", $part)) {
623             $res.= "text-align:right;";
624             continue;
625           }
626           if (preg_match("/^l$/", $part)) {
627             $res.= "text-align:left;";
628             continue;
629           }
630           if (preg_match("/^c$/", $part)) {
631             $res.= "text-align:center;";
632             continue;
633           }
634           if (preg_match("/^[0-9]+(|px|%)$/", $part)) {
635             $res.= "width:$part;min-width:$part;";
636             continue;
637           }
638         }
640         // Add minimum width for scalable columns
641         if (!preg_match('/width:/', $res)){
642           $res.= "min-width:200px;";
643         }
645         $result[$index]= " style='$res'";
646       } else {
647         $result[$index]= " style='min-width:100px;'";
648       }
649     }
651     // Save number of columns for later use
652     $this->numColumns= count($cols);
654     // Add no border to the last column
655     $result[$this->numColumns-1]= preg_replace("/'$/", "border-right:0;'", $result[$this->numColumns-1]);
657     return $result;
658   }
661   function renderCell($data, $config, $row)
662   {
663     // Replace flat attributes in data string
664     for ($i= 0; $i<$config['count']; $i++) {
665       $attr= $config[$i];
666       $value= "";
667       if (is_array($config[$attr])) {
668         $value= $config[$attr][0];
669       } else {
670         $value= $config[$attr];
671       }
672       $data= preg_replace("/%\{$attr\}/", $value, $data);
673     }
675     // Watch out for filters and prepare to execute them
676     $data= $this->processElementFilter($data, $config, $row);
678     // Replace all non replaced %{...} instances because they
679     // are non resolved attributes or filters
680     $data= preg_replace('/%{[^}]+}/', '&nbsp;', $data);
682     return $data;
683   }
686   function renderBase()
687   {
688     if (!$this->baseMode) {
689       return;
690     }
692     return $this->baseSelector->render();
693   }
696   function processElementFilter($data, $config, $row)
697   {
698     preg_match_all("/%\{filter:([^(]+)\((.*)\)\}/", $data, $matches, PREG_SET_ORDER);
700     foreach ($matches as $match) {
701       $cl= "";
702       $method= "";
703       if (preg_match('/::/', $match[1])) {
704         $cl= preg_replace('/::.*$/', '', $match[1]);
705         $method= preg_replace('/^.*::/', '', $match[1]);
706       } else {
707         if (!isset($this->filters[$match[1]])) {
708           continue;
709         }
710         $cl= preg_replace('/::.*$/', '', $this->filters[$match[1]]);
711         $method= preg_replace('/^.*::/', '', $this->filters[$match[1]]);
712       }
714       // Prepare params for function call
715       $params= array();
716       preg_match_all('/"[^"]+"|[^,]+/', $match[2], $parts);
717       foreach ($parts[0] as $param) {
719         // Row is replaced by the row number
720         if ($param == "row") {
721           $params[]= $row;
722           continue;
723         }
725         // pid is replaced by the current PID
726         if ($param == "pid") {
727           $params[]= $this->pid;
728           continue;
729         }
731         // base is replaced by the current base
732         if ($param == "base") {
733           $params[]= $this->getBase();
734           continue;
735         }
737         // Fixie with "" is passed directly
738         if (preg_match('/^".*"$/', $param)){
739           $params[]= preg_replace('/"/', '', $param);
740           continue;
741         }
743         // Move dn if needed
744         if ($param == "dn") {
745           $params[]= LDAP::fix($config["dn"]);
746           continue;
747         }
749         // LDAP variables get replaced by their objects
750         for ($i= 0; $i<$config['count']; $i++) {
751           if ($param == $config[$i]) {
752             $values= $config[$config[$i]];
753             if (is_array($values)){
754               unset($values['count']);
755             }
756             $params[]= $values;
757             break;
758           }
759         }
760       }
762       // Replace information
763       if ($cl == "listing") {
764         // Non static call - seems to result in errors
765         $data= @preg_replace('/'.preg_quote($match[0]).'/', call_user_func_array(array($this, "$method"), $params), $data);
766       } else {
767         // Static call
768         $data= preg_replace('/'.preg_quote($match[0]).'/', call_user_func_array(array($cl, $method), $params), $data);
769       }
770     }
772     return $data;
773   }
776   function getObjectType($types, $classes)
777   {
778     // Walk thru types and see if there's something matching
779     foreach ($types as $objectType) {
780       $ocs= $objectType['objectClass'];
781       if (!is_array($ocs)){
782         $ocs= array($ocs);
783       }
785       $found= true;
786       foreach ($ocs as $oc){
787         if (preg_match('/^!(.*)$/', $oc, $match)) {
788           $oc= $match[1];
789           if (in_array($oc, $classes)) {
790             $found= false;
791           }
792         } else {
793           if (!in_array($oc, $classes)) {
794             $found= false;
795           }
796         }
797       }
799       if ($found) {
800         return $objectType;
801       }
802     }
804     return null;
805   }
808   function filterObjectType($dn, $classes)
809   {
810     // Walk thru classes and return on first match
811     $result= "&nbsp;";
813     $objectType= $this->getObjectType($this->objectTypes, $classes);
814     if ($objectType) {
815       $this->objectDnMapping[$dn]= $objectType["objectClass"];
816       $result= "<img class='center' title='".LDAP::fix($dn)."' src='".$objectType["image"]."'>";
817       if (!isset($this->objectTypeCount[$objectType['label']])) {
818         $this->objectTypeCount[$objectType['label']]= 0;
819       }
820       $this->objectTypeCount[$objectType['label']]++;
821     }
823     return $result;
824   }
827   function filterActions($dn, $row, $classes)
828   {
829     // Do nothing if there's no menu defined
830     if (!isset($this->xmlData['actiontriggers']['action'])) {
831       return "&nbsp;";
832     }
834     // Go thru all actions
835     $result= "";
836     $actions= $this->xmlData['actiontriggers']['action'];
837     foreach($actions as $action) {
838       // Skip the entry completely if there's no permission to execute it
839       if (!$this->hasActionPermission($action, $dn, $classes)) {
840         $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
841         continue;
842       }
844       // Skip entry if the pseudo filter does not fit
845       if (isset($action['filter']) && preg_match('/^[a-z0-9_]+!?=[a-z0-9_]+$/i', $action['filter'])) {
846         list($fa, $fv)= explode('=', $action['filter']);
847         if (preg_match('/^(.*)!$/', $fa, $m)){
848           $fa= $m[1];
849           if (isset($this->entries[$row][$fa]) && $this->entries[$row][$fa][0] == $fv) {
850             $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
851             continue;
852           }
853         } else {
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         }
859       }
862       // If there's an objectclass definition and we don't have it
863       // add an empty picture here.
864       if (isset($action['objectclass'])){
865         $objectclass= $action['objectclass'];
866         if (preg_match('/^!(.*)$/', $objectclass, $m)){
867           $objectclass= $m[1];
868           if(in_array($objectclass, $classes)) {
869             $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
870             continue;
871           }
872         } elseif (is_string($objectclass)) {
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_array($objectclass)) {
878           if(count(array_intersect($objectclass, $classes)) != count($objectclass)){
879             $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
880             continue;
881           }
882         }
883       }
885       // Render normal entries as usual
886       if ($action['type'] == "entry") {
887         $label= $this->processElementFilter($action['label'], $this->entries[$row], $row);
888         $image= $this->processElementFilter($action['image'], $this->entries[$row], $row);
889         $result.="<input class='center' type='image' src='$image' title='$label' ".
890                  "name='listing_".$action['name']."_$row' style='padding:1px'>";
891       }
893       // Handle special types
894       if ($action['type'] == "copypaste" || $action['type'] == "snapshot") {
896         $objectType= $this->getObjectType($this->objectTypes, $this->entries[$row]['objectClass']);
897         $category= $class= null;
898         if ($objectType) {
899           $category= $objectType['category'];
900           $class= $objectType['class'];
901         }
903         if ($action['type'] == "copypaste") {
904           $copy = !isset($action['copy']) || $action['copy'] == "true";
905           $cut = !isset($action['cut']) || $action['cut'] == "true";
906           $result.= $this->renderCopyPasteActions($row, $this->entries[$row]['dn'], $category, $class,$copy,$cut);
907         } else {
908           $result.= $this->renderSnapshotActions($row, $this->entries[$row]['dn'], $category, $class);
909         }
910       }
911     }
913     return $result;
914   }
917   function filterDepartmentLink($row, $dn, $description)
918   {
919     $attr= $this->departments[$row]['sort-attribute'];
920     $name= $this->departments[$row][$attr];
921     if (is_array($name)){
922       $name= $name[0];
923     }
924     $result= sprintf("%s [%s]", $name, $description[0]);
925     return("<a href='?plug=".$_GET['plug']."&amp;PID=$this->pid&amp;act=department_$row' title='$dn'>$result</a>");
926   }
929   function filterLink()
930   {
931     $result= "&nbsp;";
933     $row= func_get_arg(0);
934     $pid= $this->pid;
935     $dn= LDAP::fix(func_get_arg(1));
936     $params= array(func_get_arg(2));
938     // Collect sprintf params
939     for ($i = 3;$i < func_num_args();$i++) {
940       $val= func_get_arg($i);
941       if (is_array($val)){
942         $params[]= $val[0];
943         continue;
944       }
945       $params[]= $val;
946     }
948     $result= "&nbsp;";
949     $trans= call_user_func_array("sprintf", $params);
950     if ($trans != "") {
951       return("<a href='?plug=".$_GET['plug']."&amp;PID=$pid&amp;act=listing_edit_$row' title='$dn'>$trans</a>");
952     }
954     return $result;
955   }
958   function renderNavigation()
959   {
960     $result= array();
961     $enableBack = true;
962     $enableRoot = true;
963     $enableHome = true;
965     $ui = get_userinfo();
967     /* Check if base = first available base */
968     $deps = $ui->get_module_departments($this->categories);
970     if(!count($deps) || $deps[0] == $this->filter->base){
971       $enableBack = false;
972       $enableRoot = false;
973     }
975     $listhead ="";
977     /* Check if we are in users home  department */
978     if(!count($deps) || $this->filter->base == $this->filter->getObjectBase($ui->dn)){
979       $enableHome = false;
980     }
982     /* Draw root button */
983     if($enableRoot){
984       $result["ROOT"]= "<input class='center' type='image' src='images/lists/root.png' align='middle' ".
985                        "title='"._("Go to root department")."' name='ROOT' alt='"._("Root")."'>";
986     }else{
987       $result["ROOT"]= "<img src='images/lists/root_grey.png' class='center' alt='"._("Root")."'>";
988     }
990     /* Draw back button */
991     if($enableBack){
992       $result["BACK"]= "<input class='center' type='image' align='middle' src='images/lists/back.png' ".
993                        "title='"._("Go up one department")."' alt='"._("Up")."' name='BACK'>";
994     }else{
995       $result["BACK"]= "<img src='images/lists/back_grey.png' class='center' alt='"._("Up")."'>";
996     }
998     /* Draw home button */
999     if($enableHome){
1000       $result["HOME"]= "<input class='center' type='image' align='middle' src='images/lists/home.png' ".
1001                        "title='"._("Go to users department")."' alt='"._("Home")."' name='HOME'>";
1002     }else{
1003       $result["HOME"]= "<img src='images/lists/home_grey.png' class='center' alt='"._("Home")."'>";
1004     }
1006     /* Draw reload button, this button is enabled everytime */
1007     $result["RELOAD"]= "<input class='center' type='image' src='images/lists/reload.png' align='middle' ".
1008                        "title='"._("Reload list")."' name='REFRESH' alt='"._("Submit")."'>";
1010     return ($result);
1011   }
1014   function getAction()
1015   {
1016     // Do not do anything if this is not our PID, or there's even no PID available...
1017     if(!isset($_REQUEST['PID']) || $_REQUEST['PID'] != $this->pid) {
1018       return;
1019     }
1021     // Save position if set
1022     if (isset($_POST['position_'.$this->pid]) && is_numeric($_POST['position_'.$this->pid])) {
1023       $this->scrollPosition= $_POST['position_'.$this->pid];
1024     }
1026     $result= array("targets" => array(), "action" => "");
1028     // Filter GET with "act" attributes
1029     if (isset($_GET['act'])) {
1030       $key= validate($_GET['act']);
1031       $target= preg_replace('/^listing_[a-zA-Z_]+_([0-9]+)$/', '$1', $key);
1032       if (isset($this->entries[$target]['dn'])) {
1033         $result['action']= preg_replace('/^listing_([a-zA-Z_]+)_[0-9]+$/', '$1', $key);
1034         $result['targets'][]= $this->entries[$target]['dn'];
1035       }
1037       // Drop targets if empty
1038       if (count($result['targets']) == 0) {
1039         unset($result['targets']);
1040       }
1041       return $result;
1042     }
1044     // Filter POST with "listing_" attributes
1045     foreach ($_POST as $key => $prop) {
1047       // Capture selections
1048       if (preg_match('/^listing_selected_[0-9]+$/', $key)) {
1049         $target= preg_replace('/^listing_selected_([0-9]+)$/', '$1', $key);
1050         if (isset($this->entries[$target]['dn'])) {
1051           $result['targets'][]= $this->entries[$target]['dn'];
1052         }
1053         continue;
1054       }
1056       // Capture action with target - this is a one shot
1057       if (preg_match('/^listing_[a-zA-Z_]+_[0-9]+(|_x)$/', $key)) {
1058         $target= preg_replace('/^listing_[a-zA-Z_]+_([0-9]+)(|_x)$/', '$1', $key);
1059         if (isset($this->entries[$target]['dn'])) {
1060           $result['action']= preg_replace('/^listing_([a-zA-Z_]+)_[0-9]+(|_x)$/', '$1', $key);
1061           $result['targets']= array($this->entries[$target]['dn']);
1062         }
1063         break;
1064       }
1066       // Capture action without target
1067       if (preg_match('/^listing_[a-zA-Z_]+(|_x)$/', $key)) {
1068         $result['action']= preg_replace('/^listing_([a-zA-Z_]+)(|_x)$/', '$1', $key);
1069         continue;
1070       }
1071     }
1073     // Filter POST with "act" attributes -> posted from action menu
1074     if (isset($_POST['act']) && $_POST['act'] != '') {
1075       if (!preg_match('/^export.*$/', $_POST['act'])){
1076         $result['action']= validate($_POST['act']);
1077       }
1078     }
1080     // Drop targets if empty
1081     if (count($result['targets']) == 0) {
1082       unset($result['targets']);
1083     }
1084     return $result;
1085   }
1088   function renderActionMenu()
1089   {
1090     // Don't send anything if the menu is not defined
1091     if (!isset($this->xmlData['actionmenu']['action'])){
1092       return "";
1093     }
1095     // Array?
1096     if (isset($this->xmlData['actionmenu']['action']['type'])){
1097       $this->xmlData['actionmenu']['action']= array($this->xmlData['actionmenu']['action']);
1098     }
1100     // Load shortcut
1101     $actions= &$this->xmlData['actionmenu']['action'];
1102     $result= "<input type='hidden' name='act' id='actionmenu' value=''><div style='display:none'><input type='submit' name='exec_act' id='exec_act' value=''></div>".
1103              "<ul class='level1' id='root'><li><a href='#'>"._("Actions")."&nbsp;<img ".
1104              "border=0 class='center' src='images/lists/sort-down.png'></a>";
1106     // Build ul/li list
1107     $result.= $this->recurseActions($actions);
1109     return "<div id='pulldown'>".$result."</li></ul><div>";
1110   }
1113   function recurseActions($actions)
1114   {
1115     global $class_mapping;
1116     static $level= 2;
1117     $result= "<ul class='level$level'>";
1118     $separator= "";
1120     foreach ($actions as $action) {
1122       // Skip the entry completely if there's no permission to execute it
1123       if (!$this->hasActionPermission($action, $this->filter->base)) {
1124         continue;
1125       }
1127       // Skip entry if there're missing dependencies
1128       if (isset($action['depends'])) {
1129         $deps= is_array($action['depends'])?$action['depends']:array($action['depends']);
1130         foreach($deps as $clazz) {
1131           if (!isset($class_mapping[$clazz])){
1132             continue 2;
1133           }
1134         }
1135       }
1137       // Fill image if set
1138       $img= "";
1139       if (isset($action['image'])){
1140         $img= "<img border='0' class='center' src='".$action['image']."'>&nbsp;";
1141       }
1143       if ($action['type'] == "separator"){
1144         $separator= " style='border-top:1px solid #AAA' ";
1145         continue;
1146       }
1148       // Dive into subs
1149       if ($action['type'] == "sub" && isset($action['action'])) {
1150         $level++;
1151         if (isset($action['label'])){
1152           $result.= "<li$separator><a href='#'>$img"._($action['label'])."&nbsp;<img border='0' src='images/forward-arrow.png'></a>";
1153         }
1155         // Ensure we've an array of actions, this enables sub menus with only one action.
1156         if(isset($action['action']['type'])){
1157           $action['action'] = array($action['action']);
1158         }
1160         $result.= $this->recurseActions($action['action'])."</li>";
1161         $level--;
1162         $separator= "";
1163         continue;
1164       }
1166       // Render entry elseways
1167       if (isset($action['label'])){
1168         $result.= "<li$separator><a href='#' onClick='document.getElementById(\"actionmenu\").value= \"".$action['name']."\";mainform.submit();'>$img"._($action['label'])."</a></li>";
1169       }
1171       // Check for special types
1172       switch ($action['type']) {
1173         case 'copypaste':
1174           $cut = !isset($action['cut']) || $action['cut'] != "false";
1175           $copy = !isset($action['copy']) || $action['copy'] != "false";
1176           $result.= $this->renderCopyPasteMenu($separator, $copy , $cut);
1177           break;
1179         case 'snapshot':
1180           $result.= $this->renderSnapshotMenu($separator);
1181           break;
1183         case 'exporter':
1184           $result.= $this->renderExporterMenu($separator);
1185           break;
1187         case 'daemon':
1188           $result.= $this->renderDaemonMenu($separator);
1189           break;
1190       }
1192       $separator= "";
1193     }
1195     $result.= "</ul>";
1196     return $result;
1197   }
1200   function hasActionPermission($action, $dn, $classes= null)
1201   {
1202     $ui= get_userinfo();
1204     if (isset($action['acl'])) {
1205       $acls= $action['acl'];
1206       if (!is_array($acls)) {
1207         $acls= array($acls);
1208       }
1210       // Every ACL has to pass
1211       foreach ($acls as $acl) {
1212         $module= $this->categories;
1213         $aclList= array();
1215         // Replace %acl if available
1216         if ($classes) {
1217           $otype= $this->getObjectType($this->objectTypes, $classes);
1218           $acl= str_replace('%acl', $otype['category']."/".$otype['class'], $acl);
1219         }
1221         // Split for category and plugins if needed
1222         // match for "[rw]" style entries
1223         if (preg_match('/^\[([rwcdm]+)\]$/', $acl, $match)){
1224           $aclList= array($match[1]);
1225         }
1227         // match for "users[rw]" style entries
1228         if (preg_match('/^([a-zA-Z0-9]+)\[([rwcdm]+)\]$/', $acl, $match)){
1229           $module= $match[1];
1230           $aclList= array($match[2]);
1231         }
1233         // match for "users/user[rw]" style entries
1234         if (preg_match('/^([a-zA-Z0-9]+\/[a-zA-Z0-9]+)\[([rwcdm]+)\]$/', $acl, $match)){
1235           $module= $match[1];
1236           $aclList= array($match[2]);
1237         }
1239         // match "users/user[userPassword:rw(,...)*]" style entries
1240         if (preg_match('/^([a-zA-Z0-9]+\/[a-zA-Z0-9]+)\[([a-zA-Z0-9]+:[rwcdm]+(,[a-zA-Z0-9]+:[rwcdm]+)*)\]$/', $acl, $match)){
1241           $module= $match[1];
1242           $aclList= explode(',', $match[2]);
1243         }
1245         // Walk thru prepared ACL by using $module
1246         foreach($aclList as $sAcl) {
1247           $checkAcl= "";
1249           // Category or detailed permission?
1250           if (strpos('/', $module) === false) {
1251             if (preg_match('/([a-zA-Z0-9]+):([rwcdm]+)/', $sAcl, $m) ) {
1252               $checkAcl= $ui->get_permissions($dn, $module, $m[1]);
1253               $sAcl= $m[2];
1254             } else {
1255               $checkAcl= $ui->get_permissions($dn, $module, '0');
1256             }
1257           } else {
1258             $checkAcl= $ui->get_category_permissions($dn, $module);
1259           }
1261           // Split up remaining part of the acl and check if it we're
1262           // allowed to do something...
1263           $parts= str_split($sAcl);
1264           foreach ($parts as $part) {
1265             if (strpos($checkAcl, $part) === false){
1266               return false;
1267             }
1268           }
1270         }
1271       }
1272     }
1274     return true;
1275   }
1278   function refreshBasesList()
1279   {
1280     global $config;
1281     $ui= get_userinfo();
1283     // Do some array munching to get it user friendly
1284     $ids= $config->idepartments;
1285     $d= $ui->get_module_departments($this->categories);
1286     $k_ids= array_keys($ids);
1287     $deps= array_intersect($d,$k_ids);
1289     // Fill internal bases list
1290     $this->bases= array();
1291     foreach($k_ids as $department){
1292       $this->bases[$department] = $ids[$department];
1293     }
1295     // Populate base selector if already present
1296     if ($this->baseSelector && $this->baseMode) {
1297       $this->baseSelector->setBases($this->bases);
1298     }
1299   }
1302   function getDepartments()
1303   {
1304     $departments= array();
1305     $ui= get_userinfo();
1307     // Get list of supported department types
1308     $types = departmentManagement::get_support_departments();
1310     // Load departments allowed by ACL
1311     $validDepartments = $ui->get_module_departments($this->categories);
1313     // Build filter and look in the LDAP for possible sub departments
1314     // of current base
1315     $filter= "(&(objectClass=gosaDepartment)(|";
1316     $attrs= array("description", "objectClass");
1317     foreach($types as $name => $data){
1318       $filter.= "(objectClass=".$data['OC'].")";
1319       $attrs[]= $data['ATTR'];
1320     }
1321     $filter.= "))";
1322     $res= get_list($filter, $this->categories, $this->base, $attrs, GL_NONE);
1324     // Analyze list of departments
1325     foreach ($res as $department) {
1326       if (!in_array($department['dn'], $validDepartments)) {
1327         continue;
1328       }
1330       // Add the attribute where we use for sorting
1331       $oc= null;
1332       foreach(array_keys($types) as $type) {
1333         if (in_array($type, $department['objectClass'])) {
1334           $oc= $type;
1335           break;
1336         }
1337       }
1338       $department['sort-attribute']= $types[$oc]['ATTR'];
1340       // Move to the result list
1341       $departments[]= $department;
1342     }
1344     return $departments;
1345   }
1348   function renderCopyPasteMenu($separator, $copy= true, $cut= true)
1349   {
1350     // We can only provide information if we've got a copypaste handler
1351     // instance
1352     if(!(isset($this->copyPasteHandler) && is_object($this->copyPasteHandler))){
1353       return "";
1354     }
1356     // Presets
1357     $result= "";
1358     $read= $paste= false;
1359     $ui= get_userinfo();
1361     // Switch flags to on if there's at least one category which allows read/paste
1362     foreach($this->categories as $category){
1363       $read= $read || preg_match('/r/', $ui->get_category_permissions($this->base, $category));
1364       $paste= $paste || $ui->is_pasteable($this->base, $category) == 1;
1365     }
1368     // Draw entries that allow copy and cut
1369     if($read){
1371       // Copy entry
1372       if($copy){
1373         $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>";
1374         $separator= "";
1375       }
1377       // Cut entry
1378       if($cut){
1379         $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>";
1380         $separator= "";
1381       }
1382     }
1384     // Draw entries that allow pasting entries
1385     if($paste){
1386       if($this->copyPasteHandler->entries_queued()){
1387         $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>";
1388       }else{
1389         $result.= "<li$separator><a href='#'><img src='images/lists/paste-grey.png' alt='' border='0' class='center'>&nbsp;"._("Paste")."</a></li>";
1390       }
1391     }
1392     
1393     return($result);
1394   }
1397   function renderCopyPasteActions($row, $dn, $category, $class, $copy= true, $cut= true)
1398   {
1399     // We can only provide information if we've got a copypaste handler
1400     // instance
1401     if(!(isset($this->copyPasteHandler) && is_object($this->copyPasteHandler))){
1402       return "";
1403     }
1405     // Presets
1406     $ui = get_userinfo();
1407     $result = "";
1409     // Render cut entries
1410     if($cut){
1411       if($ui->is_cutable($dn, $category, $class)){
1412         $result .= "<input class='center' type='image'
1413           src='images/lists/cut.png' alt='"._("Cut")."' name='listing_cut_$row' title='"._("Cut this entry")."' style='padding:1px'>";
1414       }else{
1415         $result.="<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
1416       }
1417     }
1419     // Render copy entries
1420     if($copy){
1421       if($ui->is_copyable($dn, $category, $class)){
1422         $result.= "<input class='center' type='image'
1423           src='images/lists/copy.png' alt='"._("Copy")."' name='listing_copy_$row' title='"._("Copy this entry")."' style='padding:1px'>";
1424       }else{
1425         $result.="<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
1426       }
1427     }
1429     return($result);
1430   }
1433   function renderSnapshotMenu($separator)
1434   {
1435     // We can only provide information if we've got a snapshot handler
1436     // instance
1437     if(!(isset($this->snapshotHandler) && is_object($this->snapshotHandler))){
1438       return "";
1439     }
1441     // Presets
1442     $result = "";
1443     $ui = get_userinfo();
1445     if($this->snapshotHandler->enabled() && $ui->allow_snapshot_restore($this->base, $this->categories)){
1447       // Check if there is something to restore
1448       $restore= false;
1449       foreach($this->snapshotHandler->getSnapshotBases() as $base){
1450         $restore= $restore || count($this->snapshotHandler->getDeletedSnapshots($base)) > 0;
1451       }
1453       // Draw icons according to the restore flag
1454       if($restore){
1455         $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>";
1456       }else{
1457         $result.= "<li$separator><a href='#'><img src='images/lists/restore_grey.png' alt='' border='0' class='center'>&nbsp;"._("Restore snapshots")."</a></li>";
1458       }
1459     }
1461     return($result);
1462   }
1465   function renderExporterMenu($separator)
1466   {
1467     // Presets
1468     $result = "";
1470     // Draw entries
1471     $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'>";
1473     // Export CVS as build in exporter
1474     foreach ($this->exporter as $action => $exporter) {
1475       $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>";
1476     }
1478     // Finalize list
1479     $result.= "</ul></li>";
1481     return($result);
1482   }
1485   function renderSnapshotActions($row, $dn, $category, $class, $copy= true, $cut= true)
1486   {
1487     // We can only provide information if we've got a snapshot handler
1488     // instance
1489     if(!(isset($this->snapshotHandler) && is_object($this->snapshotHandler))){
1490       return "";
1491     }
1493     // Presets
1494     $result= "";
1495     $ui = get_userinfo();
1497     // Only act if enabled here
1498     if($this->snapshotHandler->enabled()){
1500       // Draw restore button
1501       if ($ui->allow_snapshot_restore($dn, $category)){
1503         // Do we have snapshots for this dn?
1504         if($this->snapshotHandler->hasSnapshots($dn)){
1505           $result.= "<input class='center' type='image' src='images/lists/restore.png' ".
1506                      "alt='"._("Restore snapshot")."' name='listing_restore_$row' title='".
1507                      _("Restore snapshot")."' style='padding:1px'>";
1508         } else {
1509           $result.= "<img src='images/lists/restore_grey.png' alt=' ' class='center' style='padding:1px'>";
1510         }
1511       }
1513       // Draw snapshot button
1514       if($ui->allow_snapshot_create($dn, $category)){
1515           $result.= "<input class='center' type='image' src='images/snapshot.png' ".
1516                      "alt='"._("Create snapshot")."' name='listing_snapshot_$row' title='".
1517                      _("Create a new snapshot from this object")."' style='padding:1px'>";
1518       }else{
1519           $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
1520       }
1521     }
1523     return($result);
1524   }
1527   function renderDaemonMenu($separator)
1528   {
1529     $result= "";
1531     // If there is a daemon registered, draw the menu entries
1532     if(class_available("DaemonEvent")){
1533       $events= DaemonEvent::get_event_types_by_category($this->categories);
1534       if(isset($events['BY_CLASS']) && count($events['BY_CLASS'])){
1535         foreach($events['BY_CLASS'] as $name => $event){
1536           $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>";
1537           $separator= "";
1538         }
1539       }
1540     }
1542     return $result;
1543   }
1546   function getEntry($dn)
1547   {
1548     foreach ($this->entries as $entry) {
1549       if (isset($entry['dn']) && strcasecmp($dn, $entry['dn']) == 0){
1550         return $entry;
1551       }
1552     }
1553     return null;
1554   }
1557   function getType($dn)
1558   {
1559     if (isset($this->objectDnMapping[$dn])) {
1560       return $this->objectDnMapping[$dn];
1561     }
1562     return null;
1563   }
1567 ?>