Code

Update acl stuff
[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['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 dn if needed
750         if ($param == "dn") {
751           $params[]= LDAP::fix($config["dn"]);
752           continue;
753         }
755         // LDAP variables get replaced by their objects
756         for ($i= 0; $i<$config['count']; $i++) {
757           if ($param == $config[$i]) {
758             $values= $config[$config[$i]];
759             if (is_array($values)){
760               unset($values['count']);
761             }
762             $params[]= $values;
763             break;
764           }
765         }
766       }
768       // Replace information
769       if ($cl == "listing") {
770         // Non static call - seems to result in errors
771         $data= @preg_replace('/'.preg_quote($match[0]).'/', call_user_func_array(array($this, "$method"), $params), $data);
772       } else {
773         // Static call
774         $data= preg_replace('/'.preg_quote($match[0]).'/', call_user_func_array(array($cl, $method), $params), $data);
775       }
776     }
778     return $data;
779   }
782   function getObjectType($types, $classes)
783   {
784     // Walk thru types and see if there's something matching
785     foreach ($types as $objectType) {
786       $ocs= $objectType['objectClass'];
787       if (!is_array($ocs)){
788         $ocs= array($ocs);
789       }
791       $found= true;
792       foreach ($ocs as $oc){
793         if (preg_match('/^!(.*)$/', $oc, $match)) {
794           $oc= $match[1];
795           if (in_array($oc, $classes)) {
796             $found= false;
797           }
798         } else {
799           if (!in_array($oc, $classes)) {
800             $found= false;
801           }
802         }
803       }
805       if ($found) {
806         return $objectType;
807       }
808     }
810     return null;
811   }
814   function filterObjectType($dn, $classes)
815   {
816     // Walk thru classes and return on first match
817     $result= "&nbsp;";
819     $objectType= $this->getObjectType($this->objectTypes, $classes);
820     if ($objectType) {
821       $this->objectDnMapping[$dn]= $objectType["objectClass"];
822       $result= "<img class='center' title='".LDAP::fix($dn)."' src='".$objectType["image"]."'>";
823       if (!isset($this->objectTypeCount[$objectType['label']])) {
824         $this->objectTypeCount[$objectType['label']]= 0;
825       }
826       $this->objectTypeCount[$objectType['label']]++;
827     }
829     return $result;
830   }
833   function filterActions($dn, $row, $classes)
834   {
835     // Do nothing if there's no menu defined
836     if (!isset($this->xmlData['actiontriggers']['action'])) {
837       return "&nbsp;";
838     }
840     // Go thru all actions
841     $result= "";
842     $actions= $this->xmlData['actiontriggers']['action'];
843     foreach($actions as $action) {
844       // Skip the entry completely if there's no permission to execute it
845       if (!$this->hasActionPermission($action, $dn, $classes)) {
846         $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
847         continue;
848       }
850       // Skip entry if the pseudo filter does not fit
851       if (isset($action['filter']) && preg_match('/^[a-z0-9_]+!?=[a-z0-9_]+$/i', $action['filter'])) {
852         list($fa, $fv)= split('=', $action['filter']);
853         if (preg_match('/^(.*)!$/', $fa, $m)){
854           $fa= $m[1];
855           if (isset($this->entries[$row][$fa]) && $this->entries[$row][$fa][0] == $fv) {
856             $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
857             continue;
858           }
859         } else {
860           if (!isset($this->entries[$row][$fa]) && !$this->entries[$row][$fa][0] == $fv) {
861             $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
862             continue;
863           }
864         }
865       }
868       // If there's an objectclass definition and we don't have it
869       // add an empty picture here.
870       if (isset($action['objectclass'])){
871         $objectclass= $action['objectclass'];
872         if (preg_match('/^!(.*)$/', $objectclass, $m)){
873           $objectclass= $m[1];
874           if(in_array($objectclass, $classes)) {
875             $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
876             continue;
877           }
878         } elseif (is_string($objectclass)) {
879           if(!in_array($objectclass, $classes)) {
880             $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
881             continue;
882           }
883         } elseif (is_array($objectclass)) {
884           if(count(array_intersect($objectclass, $classes)) != count($objectclass)){
885             $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
886             continue;
887           }
888         }
889       }
891       // Render normal entries as usual
892       if ($action['type'] == "entry") {
893         $label= $this->processElementFilter($action['label'], $this->entries[$row], $row);
894         $image= $this->processElementFilter($action['image'], $this->entries[$row], $row);
895         $result.="<input class='center' type='image' src='$image' title='$label' ".
896                  "name='listing_".$action['name']."_$row' style='padding:1px'>";
897       }
899       // Handle special types
900       if ($action['type'] == "copypaste" || $action['type'] == "snapshot") {
902         $objectType= $this->getObjectType($this->objectTypes, $this->entries[$row]['objectClass']);
903         $category= $class= null;
904         if ($objectType) {
905           $category= $objectType['category'];
906           $class= $objectType['class'];
907         }
909         if ($action['type'] == "copypaste") {
910           $copy = !isset($action['copy']) || $action['copy'] == "true";
911           $cut = !isset($action['cut']) || $action['cut'] == "true";
912           $result.= $this->renderCopyPasteActions($row, $this->entries[$row]['dn'], $category, $class,$copy,$cut);
913         } else {
914           $result.= $this->renderSnapshotActions($row, $this->entries[$row]['dn'], $category, $class);
915         }
916       }
917     }
919     return $result;
920   }
923   function filterDepartmentLink($row, $dn, $description)
924   {
925     $attr= $this->departments[$row]['sort-attribute'];
926     $name= $this->departments[$row][$attr];
927     if (is_array($name)){
928       $name= $name[0];
929     }
930     $result= sprintf("%s [%s]", $name, $description[0]);
931     return("<a href='?plug=".$_GET['plug']."&amp;PID=$this->pid&amp;act=department_$row' title='$dn'>$result</a>");
932   }
935   function filterLink()
936   {
937     $result= "&nbsp;";
939     $row= func_get_arg(0);
940     $pid= $this->pid;
941     $dn= LDAP::fix(func_get_arg(1));
942     $params= array(func_get_arg(2));
944     // Collect sprintf params
945     for ($i = 3;$i < func_num_args();$i++) {
946       $val= func_get_arg($i);
947       if (is_array($val)){
948         $params[]= $val[0];
949         continue;
950       }
951       $params[]= $val;
952     }
954     $result= "&nbsp;";
955     $trans= call_user_func_array("sprintf", $params);
956     if ($trans != "") {
957       return("<a href='?plug=".$_GET['plug']."&amp;PID=$pid&amp;act=listing_edit_$row' title='$dn'>$trans</a>");
958     }
960     return $result;
961   }
964   function renderNavigation()
965   {
966     $result= array();
967     $enableBack = true;
968     $enableRoot = true;
969     $enableHome = true;
971     $ui = get_userinfo();
973     /* Check if base = first available base */
974     $deps = $ui->get_module_departments($this->module);
976     if(!count($deps) || $deps[0] == $this->filter->base){
977       $enableBack = false;
978       $enableRoot = false;
979     }
981     $listhead ="";
983     /* Check if we are in users home  department */
984     if(!count($deps) || $this->filter->base == $this->filter->getObjectBase($ui->dn)){
985       $enableHome = false;
986     }
988     /* Draw root button */
989     if($enableRoot){
990       $result["ROOT"]= "<input class='center' type='image' src='images/lists/root.png' align='middle' ".
991                        "title='"._("Go to root department")."' name='ROOT' alt='"._("Root")."'>";
992     }else{
993       $result["ROOT"]= "<img src='images/lists/root_grey.png' class='center' alt='"._("Root")."'>";
994     }
996     /* Draw back button */
997     if($enableBack){
998       $result["BACK"]= "<input class='center' type='image' align='middle' src='images/lists/back.png' ".
999                        "title='"._("Go up one department")."' alt='"._("Up")."' name='BACK'>";
1000     }else{
1001       $result["BACK"]= "<img src='images/lists/back_grey.png' class='center' alt='"._("Up")."'>";
1002     }
1004     /* Draw home button */
1005     if($enableHome){
1006       $result["HOME"]= "<input class='center' type='image' align='middle' src='images/lists/home.png' ".
1007                        "title='"._("Go to users department")."' alt='"._("Home")."' name='HOME'>";
1008     }else{
1009       $result["HOME"]= "<img src='images/lists/home_grey.png' class='center' alt='"._("Home")."'>";
1010     }
1012     /* Draw reload button, this button is enabled everytime */
1013     $result["RELOAD"]= "<input class='center' type='image' src='images/lists/reload.png' align='middle' ".
1014                        "title='"._("Reload list")."' name='REFRESH' alt='"._("Submit")."'>";
1016     return ($result);
1017   }
1020   function getAction()
1021   {
1022     // Do not do anything if this is not our PID, or there's even no PID available...
1023     if(!isset($_REQUEST['PID']) || $_REQUEST['PID'] != $this->pid) {
1024       return;
1025     }
1027     // Save position if set
1028     if (isset($_POST['position_'.$this->pid]) && is_numeric($_POST['position_'.$this->pid])) {
1029       $this->scrollPosition= $_POST['position_'.$this->pid];
1030     }
1032     $result= array("targets" => array(), "action" => "");
1034     // Filter GET with "act" attributes
1035     if (isset($_GET['act'])) {
1036       $key= validate($_GET['act']);
1037       $target= preg_replace('/^listing_[a-zA-Z_]+_([0-9]+)$/', '$1', $key);
1038       if (isset($this->entries[$target]['dn'])) {
1039         $result['action']= preg_replace('/^listing_([a-zA-Z_]+)_[0-9]+$/', '$1', $key);
1040         $result['targets'][]= $this->entries[$target]['dn'];
1041       }
1043       // Drop targets if empty
1044       if (count($result['targets']) == 0) {
1045         unset($result['targets']);
1046       }
1047       return $result;
1048     }
1050     // Filter POST with "listing_" attributes
1051     foreach ($_POST as $key => $prop) {
1053       // Capture selections
1054       if (preg_match('/^listing_selected_[0-9]+$/', $key)) {
1055         $target= preg_replace('/^listing_selected_([0-9]+)$/', '$1', $key);
1056         if (isset($this->entries[$target]['dn'])) {
1057           $result['targets'][]= $this->entries[$target]['dn'];
1058         }
1059         continue;
1060       }
1062       // Capture action with target - this is a one shot
1063       if (preg_match('/^listing_[a-zA-Z_]+_[0-9]+(|_x)$/', $key)) {
1064         $target= preg_replace('/^listing_[a-zA-Z_]+_([0-9]+)(|_x)$/', '$1', $key);
1065         if (isset($this->entries[$target]['dn'])) {
1066           $result['action']= preg_replace('/^listing_([a-zA-Z_]+)_[0-9]+(|_x)$/', '$1', $key);
1067           $result['targets']= array($this->entries[$target]['dn']);
1068         }
1069         break;
1070       }
1072       // Capture action without target
1073       if (preg_match('/^listing_[a-zA-Z_]+(|_x)$/', $key)) {
1074         $result['action']= preg_replace('/^listing_([a-zA-Z_]+)(|_x)$/', '$1', $key);
1075         continue;
1076       }
1077     }
1079     // Filter POST with "act" attributes -> posted from action menu
1080     if (isset($_POST['act']) && $_POST['act'] != '') {
1081       if (!preg_match('/^export.*$/', $_POST['act'])){
1082         $result['action']= validate($_POST['act']);
1083       }
1084     }
1086     // Drop targets if empty
1087     if (count($result['targets']) == 0) {
1088       unset($result['targets']);
1089     }
1090     return $result;
1091   }
1094   function renderActionMenu()
1095   {
1096     // Don't send anything if the menu is not defined
1097     if (!isset($this->xmlData['actionmenu']['action'])){
1098       return "";
1099     }
1101     // Array?
1102     if (isset($this->xmlData['actionmenu']['action']['type'])){
1103       $this->xmlData['actionmenu']['action']= array($this->xmlData['actionmenu']['action']);
1104     }
1106     // Load shortcut
1107     $actions= &$this->xmlData['actionmenu']['action'];
1108     $result= "<input type='hidden' name='act' id='actionmenu' value=''><div style='display:none'><input type='submit' name='exec_act' id='exec_act' value=''></div>".
1109              "<ul class='level1' id='root'><li><a href='#'>"._("Actions")."&nbsp;<img ".
1110              "border=0 class='center' src='images/lists/sort-down.png'></a>";
1112     // Build ul/li list
1113     $result.= $this->recurseActions($actions);
1115     return "<div id='pulldown'>".$result."</li></ul><div>";
1116   }
1119   function recurseActions($actions)
1120   {
1121     global $class_mapping;
1122     static $level= 2;
1123     $result= "<ul class='level$level'>";
1124     $separator= "";
1126     foreach ($actions as $action) {
1128       // Skip the entry completely if there's no permission to execute it
1129       if (!$this->hasActionPermission($action, $this->filter->base)) {
1130         continue;
1131       }
1133       // Skip entry if there're missing dependencies
1134       if (isset($action['depends'])) {
1135         $deps= is_array($action['depends'])?$action['depends']:array($action['depends']);
1136         foreach($deps as $clazz) {
1137           if (!isset($class_mapping[$clazz])){
1138             continue 2;
1139           }
1140         }
1141       }
1143       // Fill image if set
1144       $img= "";
1145       if (isset($action['image'])){
1146         $img= "<img border='0' class='center' src='".$action['image']."'>&nbsp;";
1147       }
1149       if ($action['type'] == "separator"){
1150         $separator= " style='border-top:1px solid #AAA' ";
1151         continue;
1152       }
1154       // Dive into subs
1155       if ($action['type'] == "sub" && isset($action['action'])) {
1156         $level++;
1157         if (isset($action['label'])){
1158           $result.= "<li$separator><a href='#'>$img"._($action['label'])."&nbsp;<img border='0' src='images/forward-arrow.png'></a>";
1159         }
1161         // Ensure we've an array of actions, this enables sub menus with only one action.
1162         if(isset($action['action']['type'])){
1163           $action['action'] = array($action['action']);
1164         }
1166         $result.= $this->recurseActions($action['action'])."</li>";
1167         $level--;
1168         $separator= "";
1169         continue;
1170       }
1172       // Render entry elseways
1173       if (isset($action['label'])){
1174         $result.= "<li$separator><a href='#' onClick='document.getElementById(\"actionmenu\").value= \"".$action['name']."\";mainform.submit();'>$img"._($action['label'])."</a></li>";
1175       }
1177       // Check for special types
1178       switch ($action['type']) {
1179         case 'copypaste':
1180           $cut = !isset($action['cut']) || $action['cut'] != "false";
1181           $copy = !isset($action['copy']) || $action['copy'] != "false";
1182           $result.= $this->renderCopyPasteMenu($separator, $copy , $cut);
1183           break;
1185         case 'snapshot':
1186           $result.= $this->renderSnapshotMenu($separator);
1187           break;
1189         case 'exporter':
1190           $result.= $this->renderExporterMenu($separator);
1191           break;
1193         case 'daemon':
1194           $result.= $this->renderDaemonMenu($separator);
1195           break;
1196       }
1198       $separator= "";
1199     }
1201     $result.= "</ul>";
1202     return $result;
1203   }
1206   function hasActionPermission($action, $dn, $classes= null)
1207   {
1208     $ui= get_userinfo();
1210 ############# MARKER
1211     if ($classes) {
1212       $otype= $this->getObjectType($this->objectTypes, $classes);
1213       echo "Type: $otype<br>";
1214       #$category= $this->category[$otype];
1215       #$params[]= $ui->get_category_permissions($dn, $category);
1216     }
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 ?>