Code

d2f2ce91193eeb8a65e305293a76e33e63906e45
[gosa.git] / gosa-core / include / class_listing.inc
1 <?php
2 /*
3  * This code is part of GOsa (http://www.gosa-project.org)
4  * Copyright (C) 2003-2008 GONICUS GmbH
5  *
6  * ID: $$Id$$
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
23 class listing {
25   var $xmlData;
26   var $entries;
27   var $departments= array();
28   var $departmentBrowser= false;
29   var $departmentRootVisible= false;
30   var $multiSelect= false;
31   var $template;
32   var $headline;
33   var $module;
34   var $base;
35   var $sortDirection= null;
36   var $sortColumn= null;
37   var $sortAttribute;
38   var $sortType;
39   var $numColumns;
40   var $baseMode= false;
41   var $bases= array();
42   var $header= array();
43   var $colprops= array();
44   var $filters= array();
45   var $pid;
46   var $objectTypes= array();
47   var $objectTypeCount= array();
48   var $objectDnMapping= array();
49   var $copyPasteHandler= null;
50   var $snapshotHandler= null;
51   var $exporter= array();
52   var $exportColumns= array();
53   var $useSpan= false;
54   var $height= 0;
55   var $scrollPosition= 0;
58   function listing($filename)
59   {
60     global $config;
61     global $class_mapping;
63     // Initialize pid
64     $this->pid= preg_replace("/[^0-9]/", "", microtime(TRUE));
66     if (!$this->load($filename)) {
67       die("Cannot parse $filename!");
68     }
70     // Set base for filter
71     if ($this->baseMode) {
72       $this->base= session::global_get("CurrentMainBase");
73       if ($this->base == null) {
74         $this->base= $config->current['BASE'];
75       }
76       $this->refreshBasesList();
77     } else {
78       $this->base= $config->current['BASE'];
79     }
81     // Move footer information
82     $this->showFooter= ($config->get_cfg_value("listSummary") == "true");
84     // Register build in filters
85     $this->registerElementFilter("objectType", "listing::filterObjectType");
86     $this->registerElementFilter("departmentLink", "listing::filterDepartmentLink");
87     $this->registerElementFilter("link", "listing::filterLink");
88     $this->registerElementFilter("actions", "listing::filterActions");
90     // Load exporters
91     foreach($class_mapping as $class => $dummy) {
92       if (preg_match('/Exporter$/', $class)) {
93         $info= call_user_func(array($class, "getInfo"));
94         if ($info != null) {
95           $this->exporter= array_merge($this->exporter, $info);
96         }
97       }
98     }
99   }
102   function setCopyPasteHandler($handler)
103   {
104     $this->copyPasteHandler= &$handler;
105   }
108   function setHeight($height)
109   {
110     $this->height= $height;
111   }
114   function setSnapshotHandler($handler)
115   {
116     $this->snapshotHandler= &$handler;
117   }
120   function setFilter($filter)
121   {
122     $this->filter= &$filter;
123     if ($this->departmentBrowser){
124       $this->departments= $this->getDepartments();
125     }
126     $this->filter->setBase($this->base);
127   }
130   function registerElementFilter($name, $call)
131   {
132     if (!isset($this->filters[$name])) {
133       $this->filters[$name]= $call;
134       return true;
135     }
137     return false;
138   }
141   function load($filename)
142   {
143     $contents = file_get_contents($filename);
144     $this->xmlData= xml::xml2array($contents, 1);
146     if (!isset($this->xmlData['list'])) {
147       return false;
148     }
150     $this->xmlData= $this->xmlData["list"];
152     // Load some definition values
153     foreach (array("departmentBrowser", "departmentRootVisible", "multiSelect", "baseMode") as $token) {
154       if (isset($this->xmlData['definition'][$token]) &&
155           $this->xmlData['definition'][$token] == "true"){
156         $this->$token= true;
157       }
158     }
160     // Fill objectTypes from departments and xml definition
161     $types = departmentManagement::get_support_departments();
162     foreach ($types as $class => $data) {
163       $this->objectTypes[]= array("label" => $data['TITLE'],
164                                   "objectClass" => $data['OC'],
165                                   "image" => $data['IMG']);
166     }
167     $this->categories= array();
168     if (isset($this->xmlData['definition']['objectType'])) {
169       if(isset($this->xmlData['definition']['objectType']['label'])) {
170         $this->xmlData['definition']['objectType']= array($this->xmlData['definition']['objectType']);
171       }
172       foreach ($this->xmlData['definition']['objectType'] as $index => $otype) {
173         $this->objectTypes[]= $this->xmlData['definition']['objectType'][$index];
174         if (isset($this->xmlData['definition']['objectType'][$index]['category'])){
175           $this->categories[$otype]= $this->xmlData['definition']['objectType'][$index]['category'];
176         }
177       }
178     }
180     // Parse layout per column
181     $this->colprops= $this->parseLayout($this->xmlData['table']['layout']);
183     // Prepare table headers
184     $this->renderHeader();
186     // Assign headline/module
187     $this->headline= _($this->xmlData['definition']['label']);
188     $this->module= $this->xmlData['definition']['module'];
189     if (!is_array($this->categories)){
190       $this->categories= array($this->categories);
191     }
193     // Evaluate columns to be exported
194     if (isset($this->xmlData['table']['column'])){
195       foreach ($this->xmlData['table']['column'] as $index => $config) {
196         if (isset($config['export']) && $config['export'] == "true"){
197           $this->exportColumns[]= $index;
198         }
199       }
200     }
202     return true;  
203   }
206   function renderHeader()
207   {
208     $this->header= array();
209     $this->plainHeader= array();
211     // Initialize sort?
212     $sortInit= false;
213     if (!$this->sortDirection) {
214       $this->sortColumn= 0;
215       if (isset($this->xmlData['definition']['defaultSortColumn'])){
216         $this->sortColumn= $this->xmlData['definition']['defaultSortColumn'];
217       } else {
218         $this->sortAttribute= "";
219       }
220       $this->sortDirection= array();
221       $sortInit= true;
222     }
224     if (isset($this->xmlData['table']['column'])){
225       foreach ($this->xmlData['table']['column'] as $index => $config) {
226         // Initialize everything to one direction
227         if ($sortInit) {
228           $this->sortDirection[$index]= false;
229         }
231         $sorter= "";
232         if ($index == $this->sortColumn && isset($config['sortAttribute']) &&
233             isset($config['sortType'])) {
234           $this->sortAttribute= $config['sortAttribute'];
235           $this->sortType= $config['sortType'];
236           $sorter= "&nbsp;<img border='0' title='".($this->sortDirection[$index]?_("Up"):_("Down"))."' src='images/lists/sort-".($this->sortDirection[$index]?"up":"down").".png' align='top'>";
237         }
238         $sortable= (isset($config['sortAttribute']));
240         $link= "href='?plug=".$_GET['plug']."&amp;PID=".$this->pid."&amp;act=SORT_$index'";
241         if (isset($config['label'])) {
242           if ($sortable) {
243             $this->header[$index]= "<td class='listheader' ".$this->colprops[$index]."><a $link>"._($config['label'])."$sorter</a></td>";
244           } else {
245             $this->header[$index]= "<td class='listheader' ".$this->colprops[$index].">"._($config['label'])."</td>";
246           }
247           $this->plainHeader[]= _($config['label']);
248         } else {
249           if ($sortable) {
250             $this->header[$index]= "<td class='listheader' ".$this->colprops[$index]."><a $link>&nbsp;$sorter</a></td>";
251           } else {
252             $this->header[$index]= "<td class='listheader' ".$this->colprops[$index].">&nbsp;</td>";
253           }
254           $this->plainHeader[]= "";
255         }
256       }
257     }
258   }
261   function render()
262   {
263     // Check for exeeded sizelimit
264     if (($message= check_sizelimit()) != ""){
265       return($message);
266     }
268     // Some browsers don't have the ability do do scrollable table bodies, filter them
269     // here.
270     $switch= false;
271     if (preg_match('/(Opera|Konqueror|Safari|msie)/i', $_SERVER['HTTP_USER_AGENT'])){
272       $switch= true;
273     }
275     // Initialize list
276     $result= "<input type='hidden' value='$this->pid' name='PID'>\n";
277     $result.= "<input type='hidden' name='position_".$this->pid."' id='position_".$this->pid."'>\n";
278     $height= 450;
279     if ($this->height != 0) {
280       $result.= "<input type='hidden' value='$this->height' id='d_height'>\n";
281       $height= $this->height;
282     }
283     
284     $result.= "<table cellpadding='0' cellspacing='0' border='0'><tr><td><div class='listContainer' id='d_scrollbody' style='border-top:1px solid #B0B0B0;width:700px;min-height:".($height+25)."px;'>\n";
286     $height= "";
287     if ($switch){
288       $height= "height:100%;";
289     }
290     $result.= "<table summary='$this->headline' style='${height}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 class='rowxp0'><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 class='rowxp".($alt&1)."'>";
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       $alt++;
386       $result.="<tr class='rowxp".($alt&1)."'>\n";
387       $result.= $entry['_rendered'];
388       $result.="</tr>\n";
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:1px solid #AAA;$emptyListStyle'>&nbsp;</td>";
404         }
405       }
406       $result.= "</tr>";
407     }
409     // Close list body
410     $result.= "</tbody></table></div></td></tr>";
412     // Add the footer if requested
413     if ($this->showFooter) {
414       $result.= "<tr><td class='nlistFooter'>";
416       foreach ($this->objectTypes as $objectType) {
417         if (isset($this->objectTypeCount[$objectType['label']])) {
418           $label= _($objectType['label']);
419           $result.= "<img class='center' src='".$objectType['image']."' title='$label' alt='$label'>&nbsp;".$this->objectTypeCount[$objectType['label']]."&nbsp;&nbsp;&nbsp;&nbsp;";
420         }
421       }
423       $result.= "</td></tr>";
424     }
426     // Close list
427     $result.= "</table>";
428     $result.= $switch?"<input type='hidden' id='list_workaround'>":"";
430     // Add scroll positioner
431     $result.= '<script type="text/javascript" language="javascript">';
432     $result.= '$("t_nscrollbody").scrollTop= '.$this->scrollPosition.';';
433     $result.= 'var box = $("t_nscrollbody").onscroll= function() {$("position_'.$this->pid.'").value= this.scrollTop;}';
434     $result.= '</script>';
436     $smarty= get_smarty();
437     $smarty->assign("usePrototype", "true");
438     $smarty->assign("FILTER", $this->filter->render());
439     $smarty->assign("SIZELIMIT", print_sizelimit_warning());
440     $smarty->assign("LIST", $result);
442     // Assign navigation elements
443     $nav= $this->renderNavigation();
444     foreach ($nav as $key => $html) {
445       $smarty->assign($key, $html);
446     }
448     // Assign action menu / base
449     $smarty->assign("ACTIONS", $this->renderActionMenu());
450     $smarty->assign("BASE", $this->renderBase());
452     // Assign separator
453     $smarty->assign("SEPARATOR", "<img src='images/lists/seperator.png' alt='-' align='middle' height='16' width='1' class='center'>");
455     // Assign summary
456     $smarty->assign("HEADLINE", $this->headline);
458     // Try to load template from plugin the folder first...
459     $file = get_template_path($this->xmlData['definition']['template'], true);
461     // ... if this fails, try to load the file from the theme folder.
462     if(!file_exists($file)){
463       $file = get_template_path($this->xmlData['definition']['template']);
464     }
466     return ($smarty->fetch($file));
467   }
470   function update()
471   {
472     global $config;
473     $ui= get_userinfo();
475     // Reset object counter / DN mapping
476     $this->objectTypeCount= array();
477     $this->objectDnMapping= array();
479     // Do not do anything if this is not our PID
480     if(isset($_REQUEST['PID']) && $_REQUEST['PID'] != $this->pid) {
481       return;
482     }
484     // Save position if set
485     if (isset($_POST['position_'.$this->pid]) && is_numeric($_POST['position_'.$this->pid])) {
486       $this->scrollPosition= $_POST['position_'.$this->pid];
487     }
489     // Save base
490     if (isset($_POST['BASE']) && $this->baseMode) {
491       $base= get_post('BASE');
492       if (isset($this->bases[$base])) {
493         $this->base= $base;
494         session::global_set("CurrentMainBase", $this->base);
495       }
496     }
498     // Override the base if we got a message from the browser navigation
499     if ($this->departmentBrowser && isset($_GET['act'])) {
500       if (preg_match('/^department_([0-9]+)$/', validate($_GET['act']), $match)){
501         if (isset($this->departments[$match[1]])){
502           $this->base= $this->departments[$match[1]]['dn'];
503           session::global_set("CurrentMainBase", $this->base);
504         }
505       }
506     }
508     // Filter POST with "act" attributes -> posted from action menu
509     if (isset($_POST['exec_act']) && $_POST['act'] != '') {
510       if (preg_match('/^export.*$/', $_POST['act']) && isset($this->exporter[$_POST['act']])) {
511         $exporter= $this->exporter[$_POST['act']];
512         $userinfo= ", "._("created by")." ".$ui->cn." - ".strftime('%A, %d. %B %Y, %H:%M:%S');
513         $entryIterator= new listingSortIterator($this->entries, $this->sortDirection[$this->sortColumn], "_sort".$this->sortColumn, $this->sortType);
514         $sortedEntries= array();
515         foreach ($entryIterator as $entry){
516           $sortedEntries[]= $entry;
517         }
518         $instance= new $exporter['class']($this->headline.$userinfo, $this->plainHeader, $sortedEntries, $this->exportColumns);
519         $type= call_user_func(array($exporter['class'], "getInfo"));
520         $type= $type[$_POST['act']];
521         send_binary_content($instance->query(), $type['filename'], $type= $type['mime']);
522       }
523     }
525     // Filter GET with "act" attributes
526     if (isset($_GET['act'])) {
527       $key= validate($_GET['act']);
528       if (preg_match('/^SORT_([0-9]+)$/', $key, $match)) {
529         // Switch to new column or invert search order?
530         $column= $match[1];
531         if ($this->sortColumn != $column) {
532           $this->sortColumn= $column;
533         } else {
534           $this->sortDirection[$column]= !$this->sortDirection[$column];
535         }
537         // Allow header to update itself according to the new sort settings
538         $this->renderHeader();
539       }
540     }
542     // Override base if we got signals from the navigation elements
543     $action= "";
544     foreach ($_POST as $key => $value) {
545       if (preg_match('/^(ROOT|BACK|HOME)_x$/', $key, $match)) {
546         $action= $match[1];
547         break;
548       }
549     }
551     // Navigation handling
552     if ($action == 'ROOT') {
553       $deps= $ui->get_module_departments($this->module);
554       $this->base= $deps[0];
555     }
556     if ($action == 'BACK') {
557       $deps= $ui->get_module_departments($this->module);
558       $base= preg_replace("/^[^,]+,/", "", $this->base);
559       if(in_array_ics($base, $deps)){
560         $this->base= $base;
561       }
562     }
563     if ($action == 'HOME') {
564       $ui= get_userinfo();
565       $this->base= $this->filter->getObjectBase($ui->dn);
566     }
568     // Reload departments
569     if ($this->departmentBrowser){
570       $this->departments= $this->getDepartments();
571     }
573     // Update filter and refresh entries
574     $this->filter->setBase($this->base);
575     $this->entries= $this->filter->query();
576   }
579   function setBase($base)
580   {
581     $this->base= $base;
582   }
585   function getBase()
586   {
587     return $this->base;
588   }
591   function parseLayout($layout)
592   {
593     $result= array();
594     $layout= preg_replace("/^\|/", "", $layout);
595     $layout= preg_replace("/\|$/", "", $layout);
596     $cols= split("\|", $layout);
598     foreach ($cols as $index => $config) {
599       if ($config != "") {
600         $res= "";
601         $components= split(';', $config);
602         foreach ($components as $part) {
603           if (preg_match("/^r$/", $part)) {
604             $res.= "text-align:right;";
605             continue;
606           }
607           if (preg_match("/^l$/", $part)) {
608             $res.= "text-align:left;";
609             continue;
610           }
611           if (preg_match("/^c$/", $part)) {
612             $res.= "text-align:center;";
613             continue;
614           }
615           if (preg_match("/^[0-9]+(|px|%)$/", $part)) {
616             $res.= "width:$part;min-width:$part;";
617             continue;
618           }
619         }
621         // Add minimum width for scalable columns
622         if (!preg_match('/width:/', $res)){
623           $res.= "min-width:200px;";
624         }
626         $result[$index]= " style='$res' ";
627       } else {
628         $result[$index]= " style='min-width:100px'";
629       }
630     }
632     // Save number of columns for later use
633     $this->numColumns= count($cols);
635     return $result;
636   }
639   function renderCell($data, $config, $row)
640   {
641     // Replace flat attributes in data string
642     for ($i= 0; $i<$config['count']; $i++) {
643       $attr= $config[$i];
644       $value= "";
645       if (is_array($config[$attr])) {
646         $value= $config[$attr][0];
647       } else {
648         $value= $config[$attr];
649       }
650       $data= preg_replace("/%\{$attr\}/", $value, $data);
651     }
653     // Watch out for filters and prepare to execute them
654     $data= $this->processElementFilter($data, $config, $row);
656     // Replace all non replaced %{...} instances because they
657     // are non resolved attributes or filters
658     $data= preg_replace('/%{[^}]+}/', '&nbsp;', $data);
660     return $data;
661   }
664   function renderBase()
665   {
666     if (!$this->baseMode) {
667       return;
668     }
670     $result= "<select name='BASE' onChange='mainform.submit()' size='1'>";
671     $firstDN= null;
672     $found= false;
674     foreach ($this->bases as $key=>$value) {
675       // Keep first entry to fall back eventually
676       if(!$firstDN) {
677         $firstDN= $key;
678       }
680       // Prepare to render entry
681       $selected= "";
682       if ($key == $this->base) {
683         $selected= " selected";
684         $found= true;
685       }
686       $key = htmlentities($key,ENT_QUOTES);
687       $result.= "\n<option value=\"".$key."\"$selected>".$value."</option>";
688     }
690     $result.= "</select>";
692     // Reset the currently used base to the first DN we found if there
693     // was no match.
694     if(!$found){
695       $this->base = $firstDN;
696     }
698     return $result;
699   }
702   function processElementFilter($data, $config, $row)
703   {
704     preg_match_all("/%\{filter:([^(]+)\((.*)\)\}/", $data, $matches, PREG_SET_ORDER);
706     foreach ($matches as $match) {
707       $cl= "";
708       $method= "";
709       if (preg_match('/::/', $match[1])) {
710         $cl= preg_replace('/::.*$/', '', $match[1]);
711         $method= preg_replace('/^.*::/', '', $match[1]);
712       } else {
713         if (!isset($this->filters[$match[1]])) {
714           continue;
715         }
716         $cl= preg_replace('/::.*$/', '', $this->filters[$match[1]]);
717         $method= preg_replace('/^.*::/', '', $this->filters[$match[1]]);
718       }
720       // Prepare params for function call
721       $params= array();
722       preg_match_all('/"[^"]+"|[^,]+/', $match[2], $parts);
723       foreach ($parts[0] as $param) {
725         // Row is replaced by the row number
726         if ($param == "row") {
727           $params[]= $row;
728           continue;
729         }
731         // pid is replaced by the current PID
732         if ($param == "pid") {
733           $params[]= $this->pid;
734           continue;
735         }
737         // base is replaced by the current base
738         if ($param == "base") {
739           $params[]= $this->getBase();
740           continue;
741         }
743         // Fixie with "" is passed directly
744         if (preg_match('/^".*"$/', $param)){
745           $params[]= preg_replace('/"/', '', $param);
746           continue;
747         }
749         // Move acl information if needed
750         if ($param == "acl") {
751           $otype= $this->getObjectType($this->objectTypes, $config["objectClass"]);
752           $category= $this->category[$otype];
753           $params[]= $ui->get_category_permissions($config["dn"], $category);
754           continue;
755         }
757         // Move dn if needed
758         if ($param == "dn") {
759           $params[]= LDAP::fix($config["dn"]);
760           continue;
761         }
763         // LDAP variables get replaced by their objects
764         for ($i= 0; $i<$config['count']; $i++) {
765           if ($param == $config[$i]) {
766             $values= $config[$config[$i]];
767             if (is_array($values)){
768               unset($values['count']);
769             }
770             $params[]= $values;
771             break;
772           }
773         }
774       }
776       // Replace information
777       if ($cl == "listing") {
778         // Non static call - seems to result in errors
779         $data= @preg_replace('/'.preg_quote($match[0]).'/', call_user_func_array(array($this, "$method"), $params), $data);
780       } else {
781         // Static call
782         $data= preg_replace('/'.preg_quote($match[0]).'/', call_user_func_array(array($cl, $method), $params), $data);
783       }
784     }
786     return $data;
787   }
790   function getObjectType($types, $classes)
791   {
792     // Walk thru types and see if there's something matching
793     foreach ($types as $objectType) {
794       $ocs= $objectType['objectClass'];
795       if (!is_array($ocs)){
796         $ocs= array($ocs);
797       }
799       $found= true;
800       foreach ($ocs as $oc){
801         if (preg_match('/^!(.*)$/', $oc, $match)) {
802           $oc= $match[1];
803           if (in_array($oc, $classes)) {
804             $found= false;
805           }
806         } else {
807           if (!in_array($oc, $classes)) {
808             $found= false;
809           }
810         }
811       }
813       if ($found) {
814         return $objectType;
815       }
816     }
818     return null;
819   }
822   function filterObjectType($dn, $classes)
823   {
824     // Walk thru classes and return on first match
825     $result= "&nbsp;";
827     $objectType= $this->getObjectType($this->objectTypes, $classes);
828     if ($objectType) {
829       $this->objectDnMapping[$dn]= $objectType["objectClass"];
830       $result= "<img class='center' title='".LDAP::fix($dn)."' src='".$objectType["image"]."'>";
831       if (!isset($this->objectTypeCount[$objectType['label']])) {
832         $this->objectTypeCount[$objectType['label']]= 0;
833       }
834       $this->objectTypeCount[$objectType['label']]++;
835     }
837     return $result;
838   }
841   function filterActions($dn, $row, $classes)
842   {
843     // Do nothing if there's no menu defined
844     if (!isset($this->xmlData['actiontriggers']['action'])) {
845       return "&nbsp;";
846     }
848     // Go thru all actions
849     $result= "";
850     $actions= $this->xmlData['actiontriggers']['action'];
851     foreach($actions as $action) {
852       // Skip the entry completely if there's no permission to execute it
853       if (!$this->hasActionPermission($action, $dn)) {
854         $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
855         continue;
856       }
858       // Skip entry if the pseudo filter does not fit
859       if (isset($action['filter']) && preg_match('/^[a-z0-9_]+!?=[a-z0-9_]+$/i', $action['filter'])) {
860         list($fa, $fv)= split('=', $action['filter']);
861         if (preg_match('/^(.*)!$/', $fa, $m)){
862           $fa= $m[1];
863           if (isset($this->entries[$row][$fa]) && $this->entries[$row][$fa][0] == $fv) {
864             $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
865             continue;
866           }
867         } else {
868           if (!isset($this->entries[$row][$fa]) && !$this->entries[$row][$fa][0] == $fv) {
869             $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
870             continue;
871           }
872         }
873       }
876       // If there's an objectclass definition and we don't have it
877       // add an empty picture here.
878       if (isset($action['objectclass'])){
879         $objectclass= $action['objectclass'];
880         if (preg_match('/^!(.*)$/', $objectclass, $m)){
881           $objectclass= $m[1];
882           if(in_array($objectclass, $classes)) {
883             $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
884             continue;
885           }
886         } elseif (is_string($objectclass)) {
887           if(!in_array($objectclass, $classes)) {
888             $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
889             continue;
890           }
891         } elseif (is_array($objectclass)) {
892           if(count(array_intersect($objectclass, $classes)) != count($objectclass)){
893             $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
894             continue;
895           }
896         }
897       }
899       // Render normal entries as usual
900       if ($action['type'] == "entry") {
901         $label= $this->processElementFilter($action['label'], $this->entries[$row], $row);
902         $image= $this->processElementFilter($action['image'], $this->entries[$row], $row);
903         $result.="<input class='center' type='image' src='$image' title='$label' ".
904                  "name='listing_".$action['name']."_$row' style='padding:1px'>";
905       }
907       // Handle special types
908       if ($action['type'] == "copypaste" || $action['type'] == "snapshot") {
910         $objectType= $this->getObjectType($this->objectTypes, $this->entries[$row]['objectClass']);
911         $category= $class= null;
912         if ($objectType) {
913           $category= $objectType['category'];
914           $class= $objectType['class'];
915         }
917         if ($action['type'] == "copypaste") {
918           $copy = !isset($action['copy']) || $action['copy'] == "true";
919           $cut = !isset($action['cut']) || $action['cut'] == "true";
920           $result.= $this->renderCopyPasteActions($row, $this->entries[$row]['dn'], $category, $class,$copy,$cut);
921         } else {
922           $result.= $this->renderSnapshotActions($row, $this->entries[$row]['dn'], $category, $class);
923         }
924       }
925     }
927     return $result;
928   }
931   function filterDepartmentLink($row, $dn, $description)
932   {
933     $attr= $this->departments[$row]['sort-attribute'];
934     $name= $this->departments[$row][$attr];
935     if (is_array($name)){
936       $name= $name[0];
937     }
938     $result= sprintf("%s [%s]", $name, $description[0]);
939     return("<a href='?plug=".$_GET['plug']."&amp;PID=$this->pid&amp;act=department_$row' title='$dn'>$result</a>");
940   }
943   function filterLink()
944   {
945     $result= "&nbsp;";
947     $row= func_get_arg(0);
948     $pid= $this->pid;
949     $dn= LDAP::fix(func_get_arg(1));
950     $params= array(func_get_arg(2));
952     // Collect sprintf params
953     for ($i = 3;$i < func_num_args();$i++) {
954       $val= func_get_arg($i);
955       if (is_array($val)){
956         $params[]= $val[0];
957         continue;
958       }
959       $params[]= $val;
960     }
962     $result= "&nbsp;";
963     $trans= call_user_func_array("sprintf", $params);
964     if ($trans != "") {
965       return("<a href='?plug=".$_GET['plug']."&amp;PID=$pid&amp;act=listing_edit_$row' title='$dn'>$trans</a>");
966     }
968     return $result;
969   }
972   function renderNavigation()
973   {
974     $result= array();
975     $enableBack = true;
976     $enableRoot = true;
977     $enableHome = true;
979     $ui = get_userinfo();
981     /* Check if base = first available base */
982     $deps = $ui->get_module_departments($this->module);
984     if(!count($deps) || $deps[0] == $this->filter->base){
985       $enableBack = false;
986       $enableRoot = false;
987     }
989     $listhead ="";
991     /* Check if we are in users home  department */
992     if(!count($deps) || $this->filter->base == $this->filter->getObjectBase($ui->dn)){
993       $enableHome = false;
994     }
996     /* Draw root button */
997     if($enableRoot){
998       $result["ROOT"]= "<input class='center' type='image' src='images/lists/root.png' align='middle' ".
999                        "title='"._("Go to root department")."' name='ROOT' alt='"._("Root")."'>";
1000     }else{
1001       $result["ROOT"]= "<img src='images/lists/root_grey.png' class='center' alt='"._("Root")."'>";
1002     }
1004     /* Draw back button */
1005     if($enableBack){
1006       $result["BACK"]= "<input class='center' type='image' align='middle' src='images/lists/back.png' ".
1007                        "title='"._("Go up one department")."' alt='"._("Up")."' name='BACK'>";
1008     }else{
1009       $result["BACK"]= "<img src='images/lists/back_grey.png' class='center' alt='"._("Up")."'>";
1010     }
1012     /* Draw home button */
1013     if($enableHome){
1014       $result["HOME"]= "<input class='center' type='image' align='middle' src='images/lists/home.png' ".
1015                        "title='"._("Go to users department")."' alt='"._("Home")."' name='HOME'>";
1016     }else{
1017       $result["HOME"]= "<img src='images/lists/home_grey.png' class='center' alt='"._("Home")."'>";
1018     }
1020     /* Draw reload button, this button is enabled everytime */
1021     $result["RELOAD"]= "<input class='center' type='image' src='images/lists/reload.png' align='middle' ".
1022                        "title='"._("Reload list")."' name='REFRESH' alt='"._("Submit")."'>";
1024     return ($result);
1025   }
1028   function getAction()
1029   {
1030     // Do not do anything if this is not our PID, or there's even no PID available...
1031     if(!isset($_REQUEST['PID']) || $_REQUEST['PID'] != $this->pid) {
1032       return;
1033     }
1035     // Save position if set
1036     if (isset($_POST['position_'.$this->pid]) && is_numeric($_POST['position_'.$this->pid])) {
1037       $this->scrollPosition= $_POST['position_'.$this->pid];
1038     }
1040     $result= array("targets" => array(), "action" => "");
1042     // Filter GET with "act" attributes
1043     if (isset($_GET['act'])) {
1044       $key= validate($_GET['act']);
1045       $target= preg_replace('/^listing_[a-zA-Z_]+_([0-9]+)$/', '$1', $key);
1046       if (isset($this->entries[$target]['dn'])) {
1047         $result['action']= preg_replace('/^listing_([a-zA-Z_]+)_[0-9]+$/', '$1', $key);
1048         $result['targets'][]= $this->entries[$target]['dn'];
1049       }
1051       // Drop targets if empty
1052       if (count($result['targets']) == 0) {
1053         unset($result['targets']);
1054       }
1055       return $result;
1056     }
1058     // Filter POST with "listing_" attributes
1059     foreach ($_POST as $key => $prop) {
1061       // Capture selections
1062       if (preg_match('/^listing_selected_[0-9]+$/', $key)) {
1063         $target= preg_replace('/^listing_selected_([0-9]+)$/', '$1', $key);
1064         if (isset($this->entries[$target]['dn'])) {
1065           $result['targets'][]= $this->entries[$target]['dn'];
1066         }
1067         continue;
1068       }
1070       // Capture action with target - this is a one shot
1071       if (preg_match('/^listing_[a-zA-Z_]+_[0-9]+(|_x)$/', $key)) {
1072         $target= preg_replace('/^listing_[a-zA-Z_]+_([0-9]+)(|_x)$/', '$1', $key);
1073         if (isset($this->entries[$target]['dn'])) {
1074           $result['action']= preg_replace('/^listing_([a-zA-Z_]+)_[0-9]+(|_x)$/', '$1', $key);
1075           $result['targets']= array($this->entries[$target]['dn']);
1076         }
1077         break;
1078       }
1080       // Capture action without target
1081       if (preg_match('/^listing_[a-zA-Z_]+(|_x)$/', $key)) {
1082         $result['action']= preg_replace('/^listing_([a-zA-Z_]+)(|_x)$/', '$1', $key);
1083         continue;
1084       }
1085     }
1087     // Filter POST with "act" attributes -> posted from action menu
1088     if (isset($_POST['act']) && $_POST['act'] != '') {
1089       if (!preg_match('/^export.*$/', $_POST['act'])){
1090         $result['action']= validate($_POST['act']);
1091       }
1092     }
1094     // Drop targets if empty
1095     if (count($result['targets']) == 0) {
1096       unset($result['targets']);
1097     }
1098     return $result;
1099   }
1102   function renderActionMenu()
1103   {
1104     // Don't send anything if the menu is not defined
1105     if (!isset($this->xmlData['actionmenu']['action'])){
1106       return "";
1107     }
1109     // Array?
1110     if (isset($this->xmlData['actionmenu']['action']['type'])){
1111       $this->xmlData['actionmenu']['action']= array($this->xmlData['actionmenu']['action']);
1112     }
1114     // Load shortcut
1115     $actions= &$this->xmlData['actionmenu']['action'];
1116     $result= "<input type='hidden' name='act' id='actionmenu' value=''><div style='display:none'><input type='submit' name='exec_act' id='exec_act' value=''></div>".
1117              "<ul class='level1' id='root'><li><a href='#'>"._("Actions")."&nbsp;<img ".
1118              "border=0 class='center' src='images/lists/sort-down.png'></a>";
1120     // Build ul/li list
1121     $result.= $this->recurseActions($actions);
1123     return "<div id='pulldown'>".$result."</li></ul><div>";
1124   }
1127   function recurseActions($actions)
1128   {
1129     global $class_mapping;
1130     static $level= 2;
1131     $result= "<ul class='level$level'>";
1132     $separator= "";
1134     foreach ($actions as $action) {
1136       // Skip the entry completely if there's no permission to execute it
1137       if (!$this->hasActionPermission($action, $this->filter->base)) {
1138         continue;
1139       }
1141       // Skip entry if there're missing dependencies
1142       if (isset($action['depends'])) {
1143         $deps= is_array($action['depends'])?$action['depends']:array($action['depends']);
1144         foreach($deps as $clazz) {
1145           if (!isset($class_mapping[$clazz])){
1146             continue 2;
1147           }
1148         }
1149       }
1151       // Fill image if set
1152       $img= "";
1153       if (isset($action['image'])){
1154         $img= "<img border='0' class='center' src='".$action['image']."'>&nbsp;";
1155       }
1157       if ($action['type'] == "separator"){
1158         $separator= " style='border-top:1px solid #AAA' ";
1159         continue;
1160       }
1162       // Dive into subs
1163       if ($action['type'] == "sub" && isset($action['action'])) {
1164         $level++;
1165         if (isset($action['label'])){
1166           $result.= "<li$separator><a href='#'>$img"._($action['label'])."&nbsp;<img border='0' src='images/forward-arrow.png'></a>";
1167         }
1169         // Ensure we've an array of actions, this enables sub menus with only one action.
1170         if(isset($action['action']['type'])){
1171           $action['action'] = array($action['action']);
1172         }
1174         $result.= $this->recurseActions($action['action'])."</li>";
1175         $level--;
1176         $separator= "";
1177         continue;
1178       }
1180       // Render entry elseways
1181       if (isset($action['label'])){
1182         $result.= "<li$separator><a href='#' onClick='document.getElementById(\"actionmenu\").value= \"".$action['name']."\";mainform.submit();'>$img"._($action['label'])."</a></li>";
1183       }
1185       // Check for special types
1186       switch ($action['type']) {
1187         case 'copypaste':
1188           $cut = !isset($action['cut']) || $action['cut'] != "false";
1189           $copy = !isset($action['copy']) || $action['copy'] != "false";
1190           $result.= $this->renderCopyPasteMenu($separator, $copy , $cut);
1191           break;
1193         case 'snapshot':
1194           $result.= $this->renderSnapshotMenu($separator);
1195           break;
1197         case 'exporter':
1198           $result.= $this->renderExporterMenu($separator);
1199           break;
1201         case 'daemon':
1202           $result.= $this->renderDaemonMenu($separator);
1203           break;
1204       }
1206       $separator= "";
1207     }
1209     $result.= "</ul>";
1210     return $result;
1211   }
1214   function hasActionPermission($action, $dn)
1215   {
1216     $ui= get_userinfo();
1218     if (isset($action['acl'])) {
1219       $acls= $action['acl'];
1220       if (!is_array($acls)) {
1221         $acls= array($acls);
1222       }
1224       // Every ACL has to pass
1225       foreach ($acls as $acl) {
1226         $module= $this->module;
1227         $aclList= array();
1229         // Split for category and plugins if needed
1230         // match for "[rw]" style entries
1231         if (preg_match('/^\[([rwcdm]+)\]$/', $acl, $match)){
1232           $aclList= array($match[1]);
1233         }
1235         // match for "users[rw]" style entries
1236         if (preg_match('/^([a-zA-Z0-9]+)\[([rwcdm]+)\]$/', $acl, $match)){
1237           $module= $match[1];
1238           $aclList= array($match[2]);
1239         }
1241         // match for "users/user[rw]" style entries
1242         if (preg_match('/^([a-zA-Z0-9]+\/[a-zA-Z0-9]+)\[([rwcdm]+)\]$/', $acl, $match)){
1243           $module= $match[1];
1244           $aclList= array($match[2]);
1245         }
1247         // match "users/user[userPassword:rw(,...)*]" style entries
1248         if (preg_match('/^([a-zA-Z0-9]+\/[a-zA-Z0-9]+)\[([a-zA-Z0-9]+:[rwcdm]+(,[a-zA-Z0-9]+:[rwcdm]+)*)\]$/', $acl, $match)){
1249           $module= $match[1];
1250           $aclList= split(',', $match[2]);
1251         }
1253         // Walk thru prepared ACL by using $module
1254         foreach($aclList as $sAcl) {
1255           $checkAcl= "";
1257           // Category or detailed permission?
1258           if (strpos('/', $module) === false) {
1259             if (preg_match('/([a-zA-Z0-9]+):([rwcdm]+)/', $sAcl, $m) ) {
1260               $checkAcl= $ui->get_permissions($dn, $module, $m[1]);
1261               $sAcl= $m[2];
1262             } else {
1263               $checkAcl= $ui->get_permissions($dn, $module, '0');
1264             }
1265           } else {
1266             $checkAcl= $ui->get_category_permissions($dn, $module);
1267           }
1269           // Split up remaining part of the acl and check if it we're
1270           // allowed to do something...
1271           $parts= str_split($sAcl);
1272           foreach ($parts as $part) {
1273             if (strpos($checkAcl, $part) === false){
1274               return false;
1275             }
1276           }
1278         }
1279       }
1280     }
1282     return true;
1283   }
1286   function refreshBasesList()
1287   {
1288     global $config;
1289     $ui= get_userinfo();
1291     // Do some array munching to get it user friendly
1292     $ids= $config->idepartments;
1293     $d= $ui->get_module_departments($this->module);
1294     $k_ids= array_keys($ids);
1295     $deps= array_intersect($d,$k_ids);
1297     // Fill internal bases list
1298     $this->bases= array();
1299     foreach($k_ids as $department){
1300       $this->bases[$department] = $ids[$department];
1301     }
1302   }
1305   function getDepartments()
1306   {
1307     $departments= array();
1308     $ui= get_userinfo();
1310     // Get list of supported department types
1311     $types = departmentManagement::get_support_departments();
1313     // Load departments allowed by ACL
1314     $validDepartments = $ui->get_module_departments($this->module);
1316     // Build filter and look in the LDAP for possible sub departments
1317     // of current base
1318     $filter= "(&(objectClass=gosaDepartment)(|";
1319     $attrs= array("description", "objectClass");
1320     foreach($types as $name => $data){
1321       $filter.= "(objectClass=".$data['OC'].")";
1322       $attrs[]= $data['ATTR'];
1323     }
1324     $filter.= "))";
1325     $res= get_list($filter, $this->module, $this->base, $attrs, GL_NONE);
1327     // Analyze list of departments
1328     foreach ($res as $department) {
1329       if (!in_array($department['dn'], $validDepartments)) {
1330         continue;
1331       }
1333       // Add the attribute where we use for sorting
1334       $oc= null;
1335       foreach(array_keys($types) as $type) {
1336         if (in_array($type, $department['objectClass'])) {
1337           $oc= $type;
1338           break;
1339         }
1340       }
1341       $department['sort-attribute']= $types[$oc]['ATTR'];
1343       // Move to the result list
1344       $departments[]= $department;
1345     }
1347     return $departments;
1348   }
1351   function renderCopyPasteMenu($separator, $copy= true, $cut= true)
1352   {
1353     // We can only provide information if we've got a copypaste handler
1354     // instance
1355     if(!(isset($this->copyPasteHandler) && is_object($this->copyPasteHandler))){
1356       return "";
1357     }
1359     // Presets
1360     $result= "";
1361     $read= $paste= false;
1362     $ui= get_userinfo();
1364     // Switch flags to on if there's at least one category which allows read/paste
1365     foreach($this->categories as $category){
1366       $read= $read || preg_match('/r/', $ui->get_category_permissions($this->base, $category));
1367       $paste= $paste || $ui->is_pasteable($this->base, $category) == 1;
1368     }
1371     // Draw entries that allow copy and cut
1372     if($read){
1374       // Copy entry
1375       if($copy){
1376         $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>";
1377         $separator= "";
1378       }
1380       // Cut entry
1381       if($cut){
1382         $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>";
1383         $separator= "";
1384       }
1385     }
1387     // Draw entries that allow pasting entries
1388     if($paste){
1389       if($this->copyPasteHandler->entries_queued()){
1390         $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>";
1391       }else{
1392         $result.= "<li$separator><a href='#'><img src='images/lists/paste-grey.png' alt='' border='0' class='center'>&nbsp;"._("Paste")."</a></li>";
1393       }
1394     }
1395     
1396     return($result);
1397   }
1400   function renderCopyPasteActions($row, $dn, $category, $class, $copy= true, $cut= true)
1401   {
1402     // We can only provide information if we've got a copypaste handler
1403     // instance
1404     if(!(isset($this->copyPasteHandler) && is_object($this->copyPasteHandler))){
1405       return "";
1406     }
1408     // Presets
1409     $ui = get_userinfo();
1410     $result = "";
1412     // Render cut entries
1413     if($cut){
1414       if($ui->is_cutable($dn, $category, $class)){
1415         $result .= "<input class='center' type='image'
1416           src='images/lists/cut.png' alt='"._("Cut")."' name='listing_cut_$row' title='"._("Cut this entry")."' style='padding:1px'>";
1417       }else{
1418         $result.="<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
1419       }
1420     }
1422     // Render copy entries
1423     if($copy){
1424       if($ui->is_copyable($dn, $category, $class)){
1425         $result.= "<input class='center' type='image'
1426           src='images/lists/copy.png' alt='"._("Copy")."' name='listing_copy_$row' title='"._("Copy this entry")."' style='padding:1px'>";
1427       }else{
1428         $result.="<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
1429       }
1430     }
1432     return($result);
1433   }
1436   function renderSnapshotMenu($separator)
1437   {
1438     // We can only provide information if we've got a snapshot handler
1439     // instance
1440     if(!(isset($this->snapshotHandler) && is_object($this->snapshotHandler))){
1441       return "";
1442     }
1444     // Presets
1445     $result = "";
1446     $ui = get_userinfo();
1448     if($this->snapshotHandler->enabled() && $ui->allow_snapshot_restore($this->base, $this->module)){
1450       // Check if there is something to restore
1451       $restore= false;
1452       foreach($this->snapshotHandler->getSnapshotBases() as $base){
1453         $restore= $restore || count($this->snapshotHandler->getDeletedSnapshots($base)) > 0;
1454       }
1456       // Draw icons according to the restore flag
1457       if($restore){
1458         $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>";
1459       }else{
1460         $result.= "<li$separator><a href='#'><img src='images/lists/restore_grey.png' alt='' border='0' class='center'>&nbsp;"._("Restore snapshots")."</a></li>";
1461       }
1462     }
1464     return($result);
1465   }
1468   function renderExporterMenu($separator)
1469   {
1470     // Presets
1471     $result = "";
1473     // Draw entries
1474     $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'>";
1476     // Export CVS as build in exporter
1477     foreach ($this->exporter as $action => $exporter) {
1478       $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>";
1479     }
1481     // Finalize list
1482     $result.= "</ul></li>";
1484     return($result);
1485   }
1488   function renderSnapshotActions($row, $dn, $category, $class, $copy= true, $cut= true)
1489   {
1490     // We can only provide information if we've got a snapshot handler
1491     // instance
1492     if(!(isset($this->snapshotHandler) && is_object($this->snapshotHandler))){
1493       return "";
1494     }
1496     // Presets
1497     $result= "";
1498     $ui = get_userinfo();
1500     // Only act if enabled here
1501     if($this->snapshotHandler->enabled()){
1503       // Draw restore button
1504       if ($ui->allow_snapshot_restore($dn, $category)){
1506         // Do we have snapshots for this dn?
1507         if($this->snapshotHandler->hasSnapshots($dn)){
1508           $result.= "<input class='center' type='image' src='images/lists/restore.png' ".
1509                      "alt='"._("Restore snapshot")."' name='listing_restore_$row' title='".
1510                      _("Restore snapshot")."' style='padding:1px'>";
1511         } else {
1512           $result.= "<img src='images/lists/restore_grey.png' alt=' ' class='center' style='padding:1px'>";
1513         }
1514       }
1516       // Draw snapshot button
1517       if($ui->allow_snapshot_create($dn, $category)){
1518           $result.= "<input class='center' type='image' src='images/snapshot.png' ".
1519                      "alt='"._("Create snapshot")."' name='listing_snapshot_$row' title='".
1520                      _("Create a new snapshot from this object")."' style='padding:1px'>";
1521       }else{
1522           $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
1523       }
1524     }
1526     return($result);
1527   }
1530   function renderDaemonMenu($separator)
1531   {
1532     $result= "";
1534     // If there is a daemon registered, draw the menu entries
1535     if(class_available("DaemonEvent")){
1536       $events= DaemonEvent::get_event_types_by_category($this->categories);
1537       if(isset($events['BY_CLASS']) && count($events['BY_CLASS'])){
1538         foreach($events['BY_CLASS'] as $name => $event){
1539           $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>";
1540           $separator= "";
1541         }
1542       }
1543     }
1545     return $result;
1546   }
1549   function getEntry($dn)
1550   {
1551     foreach ($this->entries as $entry) {
1552       if (isset($entry['dn']) && strcasecmp($dn, $entry['dn']) == 0){
1553         return $entry;
1554       }
1555     }
1556     return null;
1557   }
1560   function getType($dn)
1561   {
1562     if (isset($this->objectDnMapping[$dn])) {
1563       return $this->objectDnMapping[$dn];
1564     }
1565     return null;
1566   }
1570 ?>