Code

Remove double border on the right in some cases
[gosa.git] / gosa-core / include / class_listing.inc
1 <?php
2 /*
3  * This code is part of GOsa (http://www.gosa-project.org)
4  * Copyright (C) 2003-2008 GONICUS GmbH
5  *
6  * ID: $$Id$$
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
23 class listing {
25   var $xmlData;
26   var $entries;
27   var $departments= array();
28   var $departmentBrowser= false;
29   var $departmentRootVisible= false;
30   var $multiSelect= false;
31   var $template;
32   var $headline;
33   var $base;
34   var $sortDirection= null;
35   var $sortColumn= null;
36   var $sortAttribute;
37   var $sortType;
38   var $numColumns;
39   var $baseMode= false;
40   var $bases= array();
41   var $header= array();
42   var $colprops= array();
43   var $filters= array();
44   var $pid;
45   var $objectTypes= array();
46   var $objectTypeCount= array();
47   var $objectDnMapping= array();
48   var $copyPasteHandler= null;
49   var $snapshotHandler= null;
50   var $exporter= array();
51   var $exportColumns= array();
52   var $useSpan= false;
53   var $height= 0;
54   var $scrollPosition= 0;
57   function listing($filename)
58   {
59     global $config;
60     global $class_mapping;
62     // Initialize pid
63     $this->pid= preg_replace("/[^0-9]/", "", microtime(TRUE));
65     if (!$this->load($filename)) {
66       die("Cannot parse $filename!");
67     }
69     // Set base for filter
70     if ($this->baseMode) {
71       $this->base= session::global_get("CurrentMainBase");
72       if ($this->base == null) {
73         $this->base= $config->current['BASE'];
74       }
75       $this->refreshBasesList();
76     } else {
77       $this->base= $config->current['BASE'];
78     }
80     // Move footer information
81     $this->showFooter= ($config->get_cfg_value("listSummary") == "true");
83     // Register build in filters
84     $this->registerElementFilter("objectType", "listing::filterObjectType");
85     $this->registerElementFilter("departmentLink", "listing::filterDepartmentLink");
86     $this->registerElementFilter("link", "listing::filterLink");
87     $this->registerElementFilter("actions", "listing::filterActions");
89     // Load exporters
90     foreach($class_mapping as $class => $dummy) {
91       if (preg_match('/Exporter$/', $class)) {
92         $info= call_user_func(array($class, "getInfo"));
93         if ($info != null) {
94           $this->exporter= array_merge($this->exporter, $info);
95         }
96       }
97     }
98   }
101   function setCopyPasteHandler($handler)
102   {
103     $this->copyPasteHandler= &$handler;
104   }
107   function setHeight($height)
108   {
109     $this->height= $height;
110   }
113   function setSnapshotHandler($handler)
114   {
115     $this->snapshotHandler= &$handler;
116   }
119   function setFilter($filter)
120   {
121     $this->filter= &$filter;
122     if ($this->departmentBrowser){
123       $this->departments= $this->getDepartments();
124     }
125     $this->filter->setBase($this->base);
126   }
129   function registerElementFilter($name, $call)
130   {
131     if (!isset($this->filters[$name])) {
132       $this->filters[$name]= $call;
133       return true;
134     }
136     return false;
137   }
140   function load($filename)
141   {
142     $contents = file_get_contents($filename);
143     $this->xmlData= xml::xml2array($contents, 1);
145     if (!isset($this->xmlData['list'])) {
146       return false;
147     }
149     $this->xmlData= $this->xmlData["list"];
151     // Load some definition values
152     foreach (array("departmentBrowser", "departmentRootVisible", "multiSelect", "baseMode") as $token) {
153       if (isset($this->xmlData['definition'][$token]) &&
154           $this->xmlData['definition'][$token] == "true"){
155         $this->$token= true;
156       }
157     }
159     // Fill objectTypes from departments and xml definition
160     $types = departmentManagement::get_support_departments();
161     foreach ($types as $class => $data) {
162       $this->objectTypes[]= array("label" => $data['TITLE'],
163                                   "objectClass" => $data['OC'],
164                                   "image" => $data['IMG']);
165     }
166     $this->categories= array();
167     if (isset($this->xmlData['definition']['objectType'])) {
168       if(isset($this->xmlData['definition']['objectType']['label'])) {
169         $this->xmlData['definition']['objectType']= array($this->xmlData['definition']['objectType']);
170       }
171       foreach ($this->xmlData['definition']['objectType'] as $index => $otype) {
172         $this->objectTypes[]= $this->xmlData['definition']['objectType'][$index];
173         if (isset($this->xmlData['definition']['objectType'][$index]['category'])){
174           $this->categories[]= $otype['category'];
175         }
176       }
177     }
179     // Parse layout per column
180     $this->colprops= $this->parseLayout($this->xmlData['table']['layout']);
182     // Prepare table headers
183     $this->renderHeader();
185     // Assign headline/Categories
186     $this->headline= _($this->xmlData['definition']['label']);
187     if (!is_array($this->categories)){
188       $this->categories= array($this->categories);
189     }
191     // Evaluate columns to be exported
192     if (isset($this->xmlData['table']['column'])){
193       foreach ($this->xmlData['table']['column'] as $index => $config) {
194         if (isset($config['export']) && $config['export'] == "true"){
195           $this->exportColumns[]= $index;
196         }
197       }
198     }
200     return true;  
201   }
204   function renderHeader()
205   {
206     $this->header= array();
207     $this->plainHeader= array();
209     // Initialize sort?
210     $sortInit= false;
211     if (!$this->sortDirection) {
212       $this->sortColumn= 0;
213       if (isset($this->xmlData['definition']['defaultSortColumn'])){
214         $this->sortColumn= $this->xmlData['definition']['defaultSortColumn'];
215       } else {
216         $this->sortAttribute= "";
217       }
218       $this->sortDirection= array();
219       $sortInit= true;
220     }
222     if (isset($this->xmlData['table']['column'])){
223       foreach ($this->xmlData['table']['column'] as $index => $config) {
224         // Initialize everything to one direction
225         if ($sortInit) {
226           $this->sortDirection[$index]= false;
227         }
229         $sorter= "";
230         if ($index == $this->sortColumn && isset($config['sortAttribute']) &&
231             isset($config['sortType'])) {
232           $this->sortAttribute= $config['sortAttribute'];
233           $this->sortType= $config['sortType'];
234           $sorter= "&nbsp;<img border='0' title='".($this->sortDirection[$index]?_("Up"):_("Down"))."' src='images/lists/sort-".($this->sortDirection[$index]?"up":"down").".png' align='top'>";
235         }
236         $sortable= (isset($config['sortAttribute']));
238         $link= "href='?plug=".$_GET['plug']."&amp;PID=".$this->pid."&amp;act=SORT_$index'";
239         if (isset($config['label'])) {
240           if ($sortable) {
241             $this->header[$index]= "<td class='listheader' ".$this->colprops[$index]."><a $link>"._($config['label'])."$sorter</a></td>";
242           } else {
243             $this->header[$index]= "<td class='listheader' ".$this->colprops[$index].">"._($config['label'])."</td>";
244           }
245           $this->plainHeader[]= _($config['label']);
246         } else {
247           if ($sortable) {
248             $this->header[$index]= "<td class='listheader' ".$this->colprops[$index]."><a $link>&nbsp;$sorter</a></td>";
249           } else {
250             $this->header[$index]= "<td class='listheader' ".$this->colprops[$index].">&nbsp;</td>";
251           }
252           $this->plainHeader[]= "";
253         }
254       }
255     }
256   }
259   function render()
260   {
261     // Check for exeeded sizelimit
262     if (($message= check_sizelimit()) != ""){
263       return($message);
264     }
266     // Some browsers don't have the ability do do scrollable table bodies, filter them
267     // here.
268     $switch= false;
269     if (preg_match('/(Opera|Konqueror|Safari|msie)/i', $_SERVER['HTTP_USER_AGENT'])){
270       $switch= true;
271     }
273     // Initialize list
274     $result= "<input type='hidden' value='$this->pid' name='PID'>\n";
275     $result.= "<input type='hidden' name='position_".$this->pid."' id='position_".$this->pid."'>\n";
276     $height= 450;
277     if ($this->height != 0) {
278       $result.= "<input type='hidden' value='$this->height' id='d_height'>\n";
279       $height= $this->height;
280     }
281     
282     $result.= "<table cellpadding='0' cellspacing='0' border='0'><tr><td><div class='listContainer' id='d_scrollbody' style='border-top:1px solid #B0B0B0;border-right:1px solid #B0B0B0;width:700px;min-height:".($height+25)."px;'>\n";
284     $height= "";
285     if ($switch){
286       $height= "height:100%;";
287     }
288     $result.= "<table summary='$this->headline' style='${height}width:100%; table-layout:fixed;' cellspacing='0' cellpadding='0' id='t_scrolltable'>\n";
289     $this->numColumns= count($this->colprops) + ($this->multiSelect?1:0);
291     // Build list header
292     $result.= "<thead class='fixedListHeader listHeaderFormat'><tr>\n";
293     if ($this->multiSelect) {
294       $width= "24px";
295       if (preg_match('/Konqueror/i', $_SERVER['HTTP_USER_AGENT'])){
296         $width= "28px";
297       }
298       $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";
299     }
300     foreach ($this->header as $header) {
301       $result.= $header;
302     }
303     $result.= "</tr></thead>\n";
305     // Build list body
306     $result.= "<tbody class='listScrollContent listBodyFormat' id='t_nscrollbody' style='height:".$height."px;'>\n";
308     // No results? Just take an empty colspanned row
309     if (count($this->entries) + count($this->departments) == 0) {
310       $result.= "<tr class='rowxp0'><td class='list1nohighlight' colspan='$this->numColumns' style='height:100%;border-right:0px;width:100%;'>&nbsp;</td></tr>";
311     }
313     // Line color alternation
314     $alt= 0;
315     $deps= 0;
317     // Draw department browser if configured and we're not in sub mode
318     $this->useSpan= false;
319     if ($this->departmentBrowser && $this->filter->scope != "sub") {
320       // Fill with department browser if configured this way
321       $departmentIterator= new departmentSortIterator($this->departments, $this->sortDirection[$this->sortColumn]);
322       foreach ($departmentIterator as $row => $entry){
323         $result.="<tr class='rowxp".($alt&1)."'>";
325         // Render multi select if needed
326         if ($this->multiSelect) {
327           $result.="<td style='text-align:center;padding:0;' class='list1'>&nbsp;</td>";
328         }
330         // Render defined department columns, fill the rest with some stuff
331         $rest= $this->numColumns - 1;
332         foreach ($this->xmlData['table']['department'] as $index => $config) {
333           $colspan= 1;
334           if (isset($config['span'])){
335             $colspan= $config['span'];
336             $this->useSpan= true;
337           }
338           $result.="<td colspan='$colspan' ".$this->colprops[$index]." class='list1'>".$this->renderCell($config['value'], $entry, $row)."</td>";
339           $rest-= $colspan;
340         }
342         // Fill remaining cols with nothing
343         $last= $this->numColumns - $rest;
344         for ($i= 0; $i<$rest; $i++){
345           $result.= "<td ".$this->colprops[$last+$i-1]." class='list1'>&nbsp;</td>";
346         }
347         $result.="</tr>";
349         $alt++;
350       }
351       $deps= $alt;
352     }
354     // Fill with contents, sort as configured
355     foreach ($this->entries as $row => $entry) {
356       $trow= "";
358       // Render multi select if needed
359       if ($this->multiSelect) {
360         $trow.="<td style='text-align:center;width:20px;' class='list0'><input type='checkbox' id='listing_selected_$row' name='listing_selected_$row'></td>\n";
361       }
363       foreach ($this->xmlData['table']['column'] as $index => $config) {
364         $renderedCell= $this->renderCell($config['value'], $entry, $row);
365         $trow.="<td ".$this->colprops[$index]." class='list0'>".$renderedCell."</td>\n";
367         // Save rendered column
368         $sort= preg_replace('/.*>([^<]+)<.*$/', '$1', $renderedCell);
369         $sort= preg_replace('/&nbsp;/', '', $sort);
370         if (preg_match('/</', $sort)){
371           $sort= "";
372         }
373         $this->entries[$row]["_sort$index"]= $sort;
374       }
376       // Save rendered entry
377       $this->entries[$row]['_rendered']= $trow;
378     }
380     // Complete list by sorting entries for _sort$index and appending them to the output
381     $entryIterator= new listingSortIterator($this->entries, $this->sortDirection[$this->sortColumn], "_sort".$this->sortColumn, $this->sortType);
382     foreach ($entryIterator as $row => $entry){
383       $alt++;
384       $result.="<tr class='rowxp".($alt&1)."'>\n";
385       $result.= $entry['_rendered'];
386       $result.="</tr>\n";
387     }
389     // Need to fill the list if it's not full (nobody knows why this is 22 ;-))
390     $emptyListStyle= (count($this->entries) + (($this->useSpan && count($this->entries))?$deps:0) == 0)?"border:0;":"";
391     if ((count($this->entries) + $deps) < 22) {
392       $result.= "<tr>";
393       for ($i= 0; $i<$this->numColumns; $i++) {
394         if ($i == 0) {
395           $result.= "<td class='list1nohighlight' style='$emptyListStyle height:100%;'>&nbsp;</td>";
396           continue;
397         }
398         if ($i != $this->numColumns-1) {
399           $result.= "<td class='list1nohighlight' style='$emptyListStyle'>&nbsp;</td>";
400         } else {
401           $result.= "<td class='list1nohighlight' style='border-right:0;$emptyListStyle'>&nbsp;</td>";
402         }
403       }
404       $result.= "</tr>";
405     }
407     // Close list body
408     $result.= "</tbody></table></div></td></tr>";
410     // Add the footer if requested
411     if ($this->showFooter) {
412       $result.= "<tr><td class='nlistFooter'>";
414       foreach ($this->objectTypes as $objectType) {
415         if (isset($this->objectTypeCount[$objectType['label']])) {
416           $label= _($objectType['label']);
417           $result.= "<img class='center' src='".$objectType['image']."' title='$label' alt='$label'>&nbsp;".$this->objectTypeCount[$objectType['label']]."&nbsp;&nbsp;&nbsp;&nbsp;";
418         }
419       }
421       $result.= "</td></tr>";
422     }
424     // Close list
425     $result.= "</table>";
426     $result.= $switch?"<input type='hidden' id='list_workaround'>":"";
428     // Add scroll positioner
429     $result.= '<script type="text/javascript" language="javascript">';
430     $result.= '$("t_nscrollbody").scrollTop= '.$this->scrollPosition.';';
431     $result.= 'var box = $("t_nscrollbody").onscroll= function() {$("position_'.$this->pid.'").value= this.scrollTop;}';
432     $result.= '</script>';
434     $smarty= get_smarty();
435     $smarty->assign("usePrototype", "true");
436     $smarty->assign("FILTER", $this->filter->render());
437     $smarty->assign("SIZELIMIT", print_sizelimit_warning());
438     $smarty->assign("LIST", $result);
440     // Assign navigation elements
441     $nav= $this->renderNavigation();
442     foreach ($nav as $key => $html) {
443       $smarty->assign($key, $html);
444     }
446     // Assign action menu / base
447     $smarty->assign("ACTIONS", $this->renderActionMenu());
448     $smarty->assign("BASE", $this->renderBase());
450     // Assign separator
451     $smarty->assign("SEPARATOR", "<img src='images/lists/seperator.png' alt='-' align='middle' height='16' width='1' class='center'>");
453     // Assign summary
454     $smarty->assign("HEADLINE", $this->headline);
456     // Try to load template from plugin the folder first...
457     $file = get_template_path($this->xmlData['definition']['template'], true);
459     // ... if this fails, try to load the file from the theme folder.
460     if(!file_exists($file)){
461       $file = get_template_path($this->xmlData['definition']['template']);
462     }
464     return ($smarty->fetch($file));
465   }
468   function update()
469   {
470     global $config;
471     $ui= get_userinfo();
473     // Reset object counter / DN mapping
474     $this->objectTypeCount= array();
475     $this->objectDnMapping= array();
477     // Do not do anything if this is not our PID
478     if(isset($_REQUEST['PID']) && $_REQUEST['PID'] != $this->pid) {
479       return;
480     }
482     // Save position if set
483     if (isset($_POST['position_'.$this->pid]) && is_numeric($_POST['position_'.$this->pid])) {
484       $this->scrollPosition= $_POST['position_'.$this->pid];
485     }
487     // Save base
488     if (isset($_POST['BASE']) && $this->baseMode) {
489       $base= base64_decode(get_post('BASE'));
490       if (isset($this->bases[$base])) {
491         $this->base= $base;
492         session::global_set("CurrentMainBase", $this->base);
493       }
494     }
496     // Override the base if we got a message from the browser navigation
497     if ($this->departmentBrowser && isset($_GET['act'])) {
498       if (preg_match('/^department_([0-9]+)$/', validate($_GET['act']), $match)){
499         if (isset($this->departments[$match[1]])){
500           $this->base= $this->departments[$match[1]]['dn'];
501           session::global_set("CurrentMainBase", $this->base);
502         }
503       }
504     }
506     // Filter POST with "act" attributes -> posted from action menu
507     if (isset($_POST['exec_act']) && $_POST['act'] != '') {
508       if (preg_match('/^export.*$/', $_POST['act']) && isset($this->exporter[$_POST['act']])) {
509         $exporter= $this->exporter[$_POST['act']];
510         $userinfo= ", "._("created by")." ".$ui->cn." - ".strftime('%A, %d. %B %Y, %H:%M:%S');
511         $entryIterator= new listingSortIterator($this->entries, $this->sortDirection[$this->sortColumn], "_sort".$this->sortColumn, $this->sortType);
512         $sortedEntries= array();
513         foreach ($entryIterator as $entry){
514           $sortedEntries[]= $entry;
515         }
516         $instance= new $exporter['class']($this->headline.$userinfo, $this->plainHeader, $sortedEntries, $this->exportColumns);
517         $type= call_user_func(array($exporter['class'], "getInfo"));
518         $type= $type[$_POST['act']];
519         send_binary_content($instance->query(), $type['filename'], $type= $type['mime']);
520       }
521     }
523     // Filter GET with "act" attributes
524     if (isset($_GET['act'])) {
525       $key= validate($_GET['act']);
526       if (preg_match('/^SORT_([0-9]+)$/', $key, $match)) {
527         // Switch to new column or invert search order?
528         $column= $match[1];
529         if ($this->sortColumn != $column) {
530           $this->sortColumn= $column;
531         } else {
532           $this->sortDirection[$column]= !$this->sortDirection[$column];
533         }
535         // Allow header to update itself according to the new sort settings
536         $this->renderHeader();
537       }
538     }
540     // Override base if we got signals from the navigation elements
541     $action= "";
542     foreach ($_POST as $key => $value) {
543       if (preg_match('/^(ROOT|BACK|HOME)_x$/', $key, $match)) {
544         $action= $match[1];
545         break;
546       }
547     }
549     // Navigation handling
550     if ($action == 'ROOT') {
551       $deps= $ui->get_module_departments($this->categories);
552       $this->base= $deps[0];
553     }
554     if ($action == 'BACK') {
555       $deps= $ui->get_module_departments($this->categories);
556       $base= preg_replace("/^[^,]+,/", "", $this->base);
557       if(in_array_ics($base, $deps)){
558         $this->base= $base;
559       }
560     }
561     if ($action == 'HOME') {
562       $ui= get_userinfo();
563       $this->base= $this->filter->getObjectBase($ui->dn);
564     }
566     // Reload departments
567     if ($this->departmentBrowser){
568       $this->departments= $this->getDepartments();
569     }
571     // Update filter and refresh entries
572     $this->filter->setBase($this->base);
573     $this->entries= $this->filter->query();
574   }
577   function setBase($base)
578   {
579     $this->base= $base;
580   }
583   function getBase()
584   {
585     return $this->base;
586   }
589   function parseLayout($layout)
590   {
591     $result= array();
592     $layout= preg_replace("/^\|/", "", $layout);
593     $layout= preg_replace("/\|$/", "", $layout);
594     $cols= split("\|", $layout);
596     foreach ($cols as $index => $config) {
597       if ($config != "") {
598         $res= "";
599         $components= split(';', $config);
600         foreach ($components as $part) {
601           if (preg_match("/^r$/", $part)) {
602             $res.= "text-align:right;";
603             continue;
604           }
605           if (preg_match("/^l$/", $part)) {
606             $res.= "text-align:left;";
607             continue;
608           }
609           if (preg_match("/^c$/", $part)) {
610             $res.= "text-align:center;";
611             continue;
612           }
613           if (preg_match("/^[0-9]+(|px|%)$/", $part)) {
614             $res.= "width:$part;min-width:$part;";
615             continue;
616           }
617         }
619         // Add minimum width for scalable columns
620         if (!preg_match('/width:/', $res)){
621           $res.= "min-width:200px;";
622         }
624         $result[$index]= " style='$res'";
625       } else {
626         $result[$index]= " style='min-width:100px;'";
627       }
628     }
630     // Save number of columns for later use
631     $this->numColumns= count($cols);
633     // Add no border to the last column
634     $result[$this->numColumns-1]= preg_replace("/'$/", "border-right:0;'", $result[$this->numColumns-1]);
636     return $result;
637   }
640   function renderCell($data, $config, $row)
641   {
642     // Replace flat attributes in data string
643     for ($i= 0; $i<$config['count']; $i++) {
644       $attr= $config[$i];
645       $value= "";
646       if (is_array($config[$attr])) {
647         $value= $config[$attr][0];
648       } else {
649         $value= $config[$attr];
650       }
651       $data= preg_replace("/%\{$attr\}/", $value, $data);
652     }
654     // Watch out for filters and prepare to execute them
655     $data= $this->processElementFilter($data, $config, $row);
657     // Replace all non replaced %{...} instances because they
658     // are non resolved attributes or filters
659     $data= preg_replace('/%{[^}]+}/', '&nbsp;', $data);
661     return $data;
662   }
665   function renderBase()
666   {
667     if (!$this->baseMode) {
668       return;
669     }
671     $result= "<select name='BASE' onChange='mainform.submit()' size='1'>";
672     $firstDN= null;
673     $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       // Encode key in b64 to avoid strange characters
687       $result.= "\n<option value=\"".base64_encode($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->categories);
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     if (isset($action['acl'])) {
1211       $acls= $action['acl'];
1212       if (!is_array($acls)) {
1213         $acls= array($acls);
1214       }
1216       // Every ACL has to pass
1217       foreach ($acls as $acl) {
1218         $module= $this->categories;
1219         $aclList= array();
1221         // Replace %acl if available
1222         if ($classes) {
1223           $otype= $this->getObjectType($this->objectTypes, $classes);
1224           $acl= str_replace('%acl', $otype['category']."/".$otype['class'], $acl);
1225         }
1227         // Split for category and plugins if needed
1228         // match for "[rw]" style entries
1229         if (preg_match('/^\[([rwcdm]+)\]$/', $acl, $match)){
1230           $aclList= array($match[1]);
1231         }
1233         // match for "users[rw]" style entries
1234         if (preg_match('/^([a-zA-Z0-9]+)\[([rwcdm]+)\]$/', $acl, $match)){
1235           $module= $match[1];
1236           $aclList= array($match[2]);
1237         }
1239         // match for "users/user[rw]" style entries
1240         if (preg_match('/^([a-zA-Z0-9]+\/[a-zA-Z0-9]+)\[([rwcdm]+)\]$/', $acl, $match)){
1241           $module= $match[1];
1242           $aclList= array($match[2]);
1243         }
1245         // match "users/user[userPassword:rw(,...)*]" style entries
1246         if (preg_match('/^([a-zA-Z0-9]+\/[a-zA-Z0-9]+)\[([a-zA-Z0-9]+:[rwcdm]+(,[a-zA-Z0-9]+:[rwcdm]+)*)\]$/', $acl, $match)){
1247           $module= $match[1];
1248           $aclList= split(',', $match[2]);
1249         }
1251         // Walk thru prepared ACL by using $module
1252         foreach($aclList as $sAcl) {
1253           $checkAcl= "";
1255           // Category or detailed permission?
1256           if (strpos('/', $module) === false) {
1257             if (preg_match('/([a-zA-Z0-9]+):([rwcdm]+)/', $sAcl, $m) ) {
1258               $checkAcl= $ui->get_permissions($dn, $module, $m[1]);
1259               $sAcl= $m[2];
1260             } else {
1261               $checkAcl= $ui->get_permissions($dn, $module, '0');
1262             }
1263           } else {
1264             $checkAcl= $ui->get_category_permissions($dn, $module);
1265           }
1267           // Split up remaining part of the acl and check if it we're
1268           // allowed to do something...
1269           $parts= str_split($sAcl);
1270           foreach ($parts as $part) {
1271             if (strpos($checkAcl, $part) === false){
1272               return false;
1273             }
1274           }
1276         }
1277       }
1278     }
1280     return true;
1281   }
1284   function refreshBasesList()
1285   {
1286     global $config;
1287     $ui= get_userinfo();
1289     // Do some array munching to get it user friendly
1290     $ids= $config->idepartments;
1291     $d= $ui->get_module_departments($this->categories);
1292     $k_ids= array_keys($ids);
1293     $deps= array_intersect($d,$k_ids);
1295     // Fill internal bases list
1296     $this->bases= array();
1297     foreach($k_ids as $department){
1298       $this->bases[$department] = $ids[$department];
1299     }
1300   }
1303   function getDepartments()
1304   {
1305     $departments= array();
1306     $ui= get_userinfo();
1308     // Get list of supported department types
1309     $types = departmentManagement::get_support_departments();
1311     // Load departments allowed by ACL
1312     $validDepartments = $ui->get_module_departments($this->categories);
1314     // Build filter and look in the LDAP for possible sub departments
1315     // of current base
1316     $filter= "(&(objectClass=gosaDepartment)(|";
1317     $attrs= array("description", "objectClass");
1318     foreach($types as $name => $data){
1319       $filter.= "(objectClass=".$data['OC'].")";
1320       $attrs[]= $data['ATTR'];
1321     }
1322     $filter.= "))";
1323     $res= get_list($filter, $this->categories, $this->base, $attrs, GL_NONE);
1325     // Analyze list of departments
1326     foreach ($res as $department) {
1327       if (!in_array($department['dn'], $validDepartments)) {
1328         continue;
1329       }
1331       // Add the attribute where we use for sorting
1332       $oc= null;
1333       foreach(array_keys($types) as $type) {
1334         if (in_array($type, $department['objectClass'])) {
1335           $oc= $type;
1336           break;
1337         }
1338       }
1339       $department['sort-attribute']= $types[$oc]['ATTR'];
1341       // Move to the result list
1342       $departments[]= $department;
1343     }
1345     return $departments;
1346   }
1349   function renderCopyPasteMenu($separator, $copy= true, $cut= true)
1350   {
1351     // We can only provide information if we've got a copypaste handler
1352     // instance
1353     if(!(isset($this->copyPasteHandler) && is_object($this->copyPasteHandler))){
1354       return "";
1355     }
1357     // Presets
1358     $result= "";
1359     $read= $paste= false;
1360     $ui= get_userinfo();
1362     // Switch flags to on if there's at least one category which allows read/paste
1363     foreach($this->categories as $category){
1364       $read= $read || preg_match('/r/', $ui->get_category_permissions($this->base, $category));
1365       $paste= $paste || $ui->is_pasteable($this->base, $category) == 1;
1366     }
1369     // Draw entries that allow copy and cut
1370     if($read){
1372       // Copy entry
1373       if($copy){
1374         $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>";
1375         $separator= "";
1376       }
1378       // Cut entry
1379       if($cut){
1380         $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>";
1381         $separator= "";
1382       }
1383     }
1385     // Draw entries that allow pasting entries
1386     if($paste){
1387       if($this->copyPasteHandler->entries_queued()){
1388         $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>";
1389       }else{
1390         $result.= "<li$separator><a href='#'><img src='images/lists/paste-grey.png' alt='' border='0' class='center'>&nbsp;"._("Paste")."</a></li>";
1391       }
1392     }
1393     
1394     return($result);
1395   }
1398   function renderCopyPasteActions($row, $dn, $category, $class, $copy= true, $cut= true)
1399   {
1400     // We can only provide information if we've got a copypaste handler
1401     // instance
1402     if(!(isset($this->copyPasteHandler) && is_object($this->copyPasteHandler))){
1403       return "";
1404     }
1406     // Presets
1407     $ui = get_userinfo();
1408     $result = "";
1410     // Render cut entries
1411     if($cut){
1412       if($ui->is_cutable($dn, $category, $class)){
1413         $result .= "<input class='center' type='image'
1414           src='images/lists/cut.png' alt='"._("Cut")."' name='listing_cut_$row' title='"._("Cut this entry")."' style='padding:1px'>";
1415       }else{
1416         $result.="<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
1417       }
1418     }
1420     // Render copy entries
1421     if($copy){
1422       if($ui->is_copyable($dn, $category, $class)){
1423         $result.= "<input class='center' type='image'
1424           src='images/lists/copy.png' alt='"._("Copy")."' name='listing_copy_$row' title='"._("Copy this entry")."' style='padding:1px'>";
1425       }else{
1426         $result.="<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
1427       }
1428     }
1430     return($result);
1431   }
1434   function renderSnapshotMenu($separator)
1435   {
1436     // We can only provide information if we've got a snapshot handler
1437     // instance
1438     if(!(isset($this->snapshotHandler) && is_object($this->snapshotHandler))){
1439       return "";
1440     }
1442     // Presets
1443     $result = "";
1444     $ui = get_userinfo();
1446     if($this->snapshotHandler->enabled() && $ui->allow_snapshot_restore($this->base, $this->categories)){
1448       // Check if there is something to restore
1449       $restore= false;
1450       foreach($this->snapshotHandler->getSnapshotBases() as $base){
1451         $restore= $restore || count($this->snapshotHandler->getDeletedSnapshots($base)) > 0;
1452       }
1454       // Draw icons according to the restore flag
1455       if($restore){
1456         $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>";
1457       }else{
1458         $result.= "<li$separator><a href='#'><img src='images/lists/restore_grey.png' alt='' border='0' class='center'>&nbsp;"._("Restore snapshots")."</a></li>";
1459       }
1460     }
1462     return($result);
1463   }
1466   function renderExporterMenu($separator)
1467   {
1468     // Presets
1469     $result = "";
1471     // Draw entries
1472     $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'>";
1474     // Export CVS as build in exporter
1475     foreach ($this->exporter as $action => $exporter) {
1476       $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>";
1477     }
1479     // Finalize list
1480     $result.= "</ul></li>";
1482     return($result);
1483   }
1486   function renderSnapshotActions($row, $dn, $category, $class, $copy= true, $cut= true)
1487   {
1488     // We can only provide information if we've got a snapshot handler
1489     // instance
1490     if(!(isset($this->snapshotHandler) && is_object($this->snapshotHandler))){
1491       return "";
1492     }
1494     // Presets
1495     $result= "";
1496     $ui = get_userinfo();
1498     // Only act if enabled here
1499     if($this->snapshotHandler->enabled()){
1501       // Draw restore button
1502       if ($ui->allow_snapshot_restore($dn, $category)){
1504         // Do we have snapshots for this dn?
1505         if($this->snapshotHandler->hasSnapshots($dn)){
1506           $result.= "<input class='center' type='image' src='images/lists/restore.png' ".
1507                      "alt='"._("Restore snapshot")."' name='listing_restore_$row' title='".
1508                      _("Restore snapshot")."' style='padding:1px'>";
1509         } else {
1510           $result.= "<img src='images/lists/restore_grey.png' alt=' ' class='center' style='padding:1px'>";
1511         }
1512       }
1514       // Draw snapshot button
1515       if($ui->allow_snapshot_create($dn, $category)){
1516           $result.= "<input class='center' type='image' src='images/snapshot.png' ".
1517                      "alt='"._("Create snapshot")."' name='listing_snapshot_$row' title='".
1518                      _("Create a new snapshot from this object")."' style='padding:1px'>";
1519       }else{
1520           $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
1521       }
1522     }
1524     return($result);
1525   }
1528   function renderDaemonMenu($separator)
1529   {
1530     $result= "";
1532     // If there is a daemon registered, draw the menu entries
1533     if(class_available("DaemonEvent")){
1534       $events= DaemonEvent::get_event_types_by_category($this->categories);
1535       if(isset($events['BY_CLASS']) && count($events['BY_CLASS'])){
1536         foreach($events['BY_CLASS'] as $name => $event){
1537           $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>";
1538           $separator= "";
1539         }
1540       }
1541     }
1543     return $result;
1544   }
1547   function getEntry($dn)
1548   {
1549     foreach ($this->entries as $entry) {
1550       if (isset($entry['dn']) && strcasecmp($dn, $entry['dn']) == 0){
1551         return $entry;
1552       }
1553     }
1554     return null;
1555   }
1558   function getType($dn)
1559   {
1560     if (isset($this->objectDnMapping[$dn])) {
1561       return $this->objectDnMapping[$dn];
1562     }
1563     return null;
1564   }
1568 ?>