Code

Static acl
[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 acl information if needed
750         if ($param == "acl") {
751           $otype= $this->getObjectType($this->objectTypes, $config["objectClass"]);
752           echo "Type: $otype<br>";
753           #$category= $this->category[$otype];
754           #$params[]= $ui->get_category_permissions($config["dn"], $category);
755           $params[]= 'rwcdm';
756           continue;
757         }
759         // Move dn if needed
760         if ($param == "dn") {
761           $params[]= LDAP::fix($config["dn"]);
762           continue;
763         }
765         // LDAP variables get replaced by their objects
766         for ($i= 0; $i<$config['count']; $i++) {
767           if ($param == $config[$i]) {
768             $values= $config[$config[$i]];
769             if (is_array($values)){
770               unset($values['count']);
771             }
772             $params[]= $values;
773             break;
774           }
775         }
776       }
778       // Replace information
779       if ($cl == "listing") {
780         // Non static call - seems to result in errors
781         $data= @preg_replace('/'.preg_quote($match[0]).'/', call_user_func_array(array($this, "$method"), $params), $data);
782       } else {
783         // Static call
784         $data= preg_replace('/'.preg_quote($match[0]).'/', call_user_func_array(array($cl, $method), $params), $data);
785       }
786     }
788     return $data;
789   }
792   function getObjectType($types, $classes)
793   {
794     // Walk thru types and see if there's something matching
795     foreach ($types as $objectType) {
796       $ocs= $objectType['objectClass'];
797       if (!is_array($ocs)){
798         $ocs= array($ocs);
799       }
801       $found= true;
802       foreach ($ocs as $oc){
803         if (preg_match('/^!(.*)$/', $oc, $match)) {
804           $oc= $match[1];
805           if (in_array($oc, $classes)) {
806             $found= false;
807           }
808         } else {
809           if (!in_array($oc, $classes)) {
810             $found= false;
811           }
812         }
813       }
815       if ($found) {
816         return $objectType;
817       }
818     }
820     return null;
821   }
824   function filterObjectType($dn, $classes)
825   {
826     // Walk thru classes and return on first match
827     $result= "&nbsp;";
829     $objectType= $this->getObjectType($this->objectTypes, $classes);
830     if ($objectType) {
831       $this->objectDnMapping[$dn]= $objectType["objectClass"];
832       $result= "<img class='center' title='".LDAP::fix($dn)."' src='".$objectType["image"]."'>";
833       if (!isset($this->objectTypeCount[$objectType['label']])) {
834         $this->objectTypeCount[$objectType['label']]= 0;
835       }
836       $this->objectTypeCount[$objectType['label']]++;
837     }
839     return $result;
840   }
843   function filterActions($dn, $row, $classes)
844   {
845     // Do nothing if there's no menu defined
846     if (!isset($this->xmlData['actiontriggers']['action'])) {
847       return "&nbsp;";
848     }
850     // Go thru all actions
851     $result= "";
852     $actions= $this->xmlData['actiontriggers']['action'];
853     foreach($actions as $action) {
854       // Skip the entry completely if there's no permission to execute it
855       if (!$this->hasActionPermission($action, $dn)) {
856         $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
857         continue;
858       }
860       // Skip entry if the pseudo filter does not fit
861       if (isset($action['filter']) && preg_match('/^[a-z0-9_]+!?=[a-z0-9_]+$/i', $action['filter'])) {
862         list($fa, $fv)= split('=', $action['filter']);
863         if (preg_match('/^(.*)!$/', $fa, $m)){
864           $fa= $m[1];
865           if (isset($this->entries[$row][$fa]) && $this->entries[$row][$fa][0] == $fv) {
866             $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
867             continue;
868           }
869         } else {
870           if (!isset($this->entries[$row][$fa]) && !$this->entries[$row][$fa][0] == $fv) {
871             $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
872             continue;
873           }
874         }
875       }
878       // If there's an objectclass definition and we don't have it
879       // add an empty picture here.
880       if (isset($action['objectclass'])){
881         $objectclass= $action['objectclass'];
882         if (preg_match('/^!(.*)$/', $objectclass, $m)){
883           $objectclass= $m[1];
884           if(in_array($objectclass, $classes)) {
885             $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
886             continue;
887           }
888         } elseif (is_string($objectclass)) {
889           if(!in_array($objectclass, $classes)) {
890             $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
891             continue;
892           }
893         } elseif (is_array($objectclass)) {
894           if(count(array_intersect($objectclass, $classes)) != count($objectclass)){
895             $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
896             continue;
897           }
898         }
899       }
901       // Render normal entries as usual
902       if ($action['type'] == "entry") {
903         $label= $this->processElementFilter($action['label'], $this->entries[$row], $row);
904         $image= $this->processElementFilter($action['image'], $this->entries[$row], $row);
905         $result.="<input class='center' type='image' src='$image' title='$label' ".
906                  "name='listing_".$action['name']."_$row' style='padding:1px'>";
907       }
909       // Handle special types
910       if ($action['type'] == "copypaste" || $action['type'] == "snapshot") {
912         $objectType= $this->getObjectType($this->objectTypes, $this->entries[$row]['objectClass']);
913         $category= $class= null;
914         if ($objectType) {
915           $category= $objectType['category'];
916           $class= $objectType['class'];
917         }
919         if ($action['type'] == "copypaste") {
920           $copy = !isset($action['copy']) || $action['copy'] == "true";
921           $cut = !isset($action['cut']) || $action['cut'] == "true";
922           $result.= $this->renderCopyPasteActions($row, $this->entries[$row]['dn'], $category, $class,$copy,$cut);
923         } else {
924           $result.= $this->renderSnapshotActions($row, $this->entries[$row]['dn'], $category, $class);
925         }
926       }
927     }
929     return $result;
930   }
933   function filterDepartmentLink($row, $dn, $description)
934   {
935     $attr= $this->departments[$row]['sort-attribute'];
936     $name= $this->departments[$row][$attr];
937     if (is_array($name)){
938       $name= $name[0];
939     }
940     $result= sprintf("%s [%s]", $name, $description[0]);
941     return("<a href='?plug=".$_GET['plug']."&amp;PID=$this->pid&amp;act=department_$row' title='$dn'>$result</a>");
942   }
945   function filterLink()
946   {
947     $result= "&nbsp;";
949     $row= func_get_arg(0);
950     $pid= $this->pid;
951     $dn= LDAP::fix(func_get_arg(1));
952     $params= array(func_get_arg(2));
954     // Collect sprintf params
955     for ($i = 3;$i < func_num_args();$i++) {
956       $val= func_get_arg($i);
957       if (is_array($val)){
958         $params[]= $val[0];
959         continue;
960       }
961       $params[]= $val;
962     }
964     $result= "&nbsp;";
965     $trans= call_user_func_array("sprintf", $params);
966     if ($trans != "") {
967       return("<a href='?plug=".$_GET['plug']."&amp;PID=$pid&amp;act=listing_edit_$row' title='$dn'>$trans</a>");
968     }
970     return $result;
971   }
974   function renderNavigation()
975   {
976     $result= array();
977     $enableBack = true;
978     $enableRoot = true;
979     $enableHome = true;
981     $ui = get_userinfo();
983     /* Check if base = first available base */
984     $deps = $ui->get_module_departments($this->module);
986     if(!count($deps) || $deps[0] == $this->filter->base){
987       $enableBack = false;
988       $enableRoot = false;
989     }
991     $listhead ="";
993     /* Check if we are in users home  department */
994     if(!count($deps) || $this->filter->base == $this->filter->getObjectBase($ui->dn)){
995       $enableHome = false;
996     }
998     /* Draw root button */
999     if($enableRoot){
1000       $result["ROOT"]= "<input class='center' type='image' src='images/lists/root.png' align='middle' ".
1001                        "title='"._("Go to root department")."' name='ROOT' alt='"._("Root")."'>";
1002     }else{
1003       $result["ROOT"]= "<img src='images/lists/root_grey.png' class='center' alt='"._("Root")."'>";
1004     }
1006     /* Draw back button */
1007     if($enableBack){
1008       $result["BACK"]= "<input class='center' type='image' align='middle' src='images/lists/back.png' ".
1009                        "title='"._("Go up one department")."' alt='"._("Up")."' name='BACK'>";
1010     }else{
1011       $result["BACK"]= "<img src='images/lists/back_grey.png' class='center' alt='"._("Up")."'>";
1012     }
1014     /* Draw home button */
1015     if($enableHome){
1016       $result["HOME"]= "<input class='center' type='image' align='middle' src='images/lists/home.png' ".
1017                        "title='"._("Go to users department")."' alt='"._("Home")."' name='HOME'>";
1018     }else{
1019       $result["HOME"]= "<img src='images/lists/home_grey.png' class='center' alt='"._("Home")."'>";
1020     }
1022     /* Draw reload button, this button is enabled everytime */
1023     $result["RELOAD"]= "<input class='center' type='image' src='images/lists/reload.png' align='middle' ".
1024                        "title='"._("Reload list")."' name='REFRESH' alt='"._("Submit")."'>";
1026     return ($result);
1027   }
1030   function getAction()
1031   {
1032     // Do not do anything if this is not our PID, or there's even no PID available...
1033     if(!isset($_REQUEST['PID']) || $_REQUEST['PID'] != $this->pid) {
1034       return;
1035     }
1037     // Save position if set
1038     if (isset($_POST['position_'.$this->pid]) && is_numeric($_POST['position_'.$this->pid])) {
1039       $this->scrollPosition= $_POST['position_'.$this->pid];
1040     }
1042     $result= array("targets" => array(), "action" => "");
1044     // Filter GET with "act" attributes
1045     if (isset($_GET['act'])) {
1046       $key= validate($_GET['act']);
1047       $target= preg_replace('/^listing_[a-zA-Z_]+_([0-9]+)$/', '$1', $key);
1048       if (isset($this->entries[$target]['dn'])) {
1049         $result['action']= preg_replace('/^listing_([a-zA-Z_]+)_[0-9]+$/', '$1', $key);
1050         $result['targets'][]= $this->entries[$target]['dn'];
1051       }
1053       // Drop targets if empty
1054       if (count($result['targets']) == 0) {
1055         unset($result['targets']);
1056       }
1057       return $result;
1058     }
1060     // Filter POST with "listing_" attributes
1061     foreach ($_POST as $key => $prop) {
1063       // Capture selections
1064       if (preg_match('/^listing_selected_[0-9]+$/', $key)) {
1065         $target= preg_replace('/^listing_selected_([0-9]+)$/', '$1', $key);
1066         if (isset($this->entries[$target]['dn'])) {
1067           $result['targets'][]= $this->entries[$target]['dn'];
1068         }
1069         continue;
1070       }
1072       // Capture action with target - this is a one shot
1073       if (preg_match('/^listing_[a-zA-Z_]+_[0-9]+(|_x)$/', $key)) {
1074         $target= preg_replace('/^listing_[a-zA-Z_]+_([0-9]+)(|_x)$/', '$1', $key);
1075         if (isset($this->entries[$target]['dn'])) {
1076           $result['action']= preg_replace('/^listing_([a-zA-Z_]+)_[0-9]+(|_x)$/', '$1', $key);
1077           $result['targets']= array($this->entries[$target]['dn']);
1078         }
1079         break;
1080       }
1082       // Capture action without target
1083       if (preg_match('/^listing_[a-zA-Z_]+(|_x)$/', $key)) {
1084         $result['action']= preg_replace('/^listing_([a-zA-Z_]+)(|_x)$/', '$1', $key);
1085         continue;
1086       }
1087     }
1089     // Filter POST with "act" attributes -> posted from action menu
1090     if (isset($_POST['act']) && $_POST['act'] != '') {
1091       if (!preg_match('/^export.*$/', $_POST['act'])){
1092         $result['action']= validate($_POST['act']);
1093       }
1094     }
1096     // Drop targets if empty
1097     if (count($result['targets']) == 0) {
1098       unset($result['targets']);
1099     }
1100     return $result;
1101   }
1104   function renderActionMenu()
1105   {
1106     // Don't send anything if the menu is not defined
1107     if (!isset($this->xmlData['actionmenu']['action'])){
1108       return "";
1109     }
1111     // Array?
1112     if (isset($this->xmlData['actionmenu']['action']['type'])){
1113       $this->xmlData['actionmenu']['action']= array($this->xmlData['actionmenu']['action']);
1114     }
1116     // Load shortcut
1117     $actions= &$this->xmlData['actionmenu']['action'];
1118     $result= "<input type='hidden' name='act' id='actionmenu' value=''><div style='display:none'><input type='submit' name='exec_act' id='exec_act' value=''></div>".
1119              "<ul class='level1' id='root'><li><a href='#'>"._("Actions")."&nbsp;<img ".
1120              "border=0 class='center' src='images/lists/sort-down.png'></a>";
1122     // Build ul/li list
1123     $result.= $this->recurseActions($actions);
1125     return "<div id='pulldown'>".$result."</li></ul><div>";
1126   }
1129   function recurseActions($actions)
1130   {
1131     global $class_mapping;
1132     static $level= 2;
1133     $result= "<ul class='level$level'>";
1134     $separator= "";
1136     foreach ($actions as $action) {
1138       // Skip the entry completely if there's no permission to execute it
1139       if (!$this->hasActionPermission($action, $this->filter->base)) {
1140         continue;
1141       }
1143       // Skip entry if there're missing dependencies
1144       if (isset($action['depends'])) {
1145         $deps= is_array($action['depends'])?$action['depends']:array($action['depends']);
1146         foreach($deps as $clazz) {
1147           if (!isset($class_mapping[$clazz])){
1148             continue 2;
1149           }
1150         }
1151       }
1153       // Fill image if set
1154       $img= "";
1155       if (isset($action['image'])){
1156         $img= "<img border='0' class='center' src='".$action['image']."'>&nbsp;";
1157       }
1159       if ($action['type'] == "separator"){
1160         $separator= " style='border-top:1px solid #AAA' ";
1161         continue;
1162       }
1164       // Dive into subs
1165       if ($action['type'] == "sub" && isset($action['action'])) {
1166         $level++;
1167         if (isset($action['label'])){
1168           $result.= "<li$separator><a href='#'>$img"._($action['label'])."&nbsp;<img border='0' src='images/forward-arrow.png'></a>";
1169         }
1171         // Ensure we've an array of actions, this enables sub menus with only one action.
1172         if(isset($action['action']['type'])){
1173           $action['action'] = array($action['action']);
1174         }
1176         $result.= $this->recurseActions($action['action'])."</li>";
1177         $level--;
1178         $separator= "";
1179         continue;
1180       }
1182       // Render entry elseways
1183       if (isset($action['label'])){
1184         $result.= "<li$separator><a href='#' onClick='document.getElementById(\"actionmenu\").value= \"".$action['name']."\";mainform.submit();'>$img"._($action['label'])."</a></li>";
1185       }
1187       // Check for special types
1188       switch ($action['type']) {
1189         case 'copypaste':
1190           $cut = !isset($action['cut']) || $action['cut'] != "false";
1191           $copy = !isset($action['copy']) || $action['copy'] != "false";
1192           $result.= $this->renderCopyPasteMenu($separator, $copy , $cut);
1193           break;
1195         case 'snapshot':
1196           $result.= $this->renderSnapshotMenu($separator);
1197           break;
1199         case 'exporter':
1200           $result.= $this->renderExporterMenu($separator);
1201           break;
1203         case 'daemon':
1204           $result.= $this->renderDaemonMenu($separator);
1205           break;
1206       }
1208       $separator= "";
1209     }
1211     $result.= "</ul>";
1212     return $result;
1213   }
1216   function hasActionPermission($action, $dn)
1217   {
1218     $ui= get_userinfo();
1220     if (isset($action['acl'])) {
1221       $acls= $action['acl'];
1222       if (!is_array($acls)) {
1223         $acls= array($acls);
1224       }
1226       // Every ACL has to pass
1227       foreach ($acls as $acl) {
1228         $module= $this->module;
1229         $aclList= array();
1231         // Split for category and plugins if needed
1232         // match for "[rw]" style entries
1233         if (preg_match('/^\[([rwcdm]+)\]$/', $acl, $match)){
1234           $aclList= array($match[1]);
1235         }
1237         // match for "users[rw]" style entries
1238         if (preg_match('/^([a-zA-Z0-9]+)\[([rwcdm]+)\]$/', $acl, $match)){
1239           $module= $match[1];
1240           $aclList= array($match[2]);
1241         }
1243         // match for "users/user[rw]" style entries
1244         if (preg_match('/^([a-zA-Z0-9]+\/[a-zA-Z0-9]+)\[([rwcdm]+)\]$/', $acl, $match)){
1245           $module= $match[1];
1246           $aclList= array($match[2]);
1247         }
1249         // match "users/user[userPassword:rw(,...)*]" style entries
1250         if (preg_match('/^([a-zA-Z0-9]+\/[a-zA-Z0-9]+)\[([a-zA-Z0-9]+:[rwcdm]+(,[a-zA-Z0-9]+:[rwcdm]+)*)\]$/', $acl, $match)){
1251           $module= $match[1];
1252           $aclList= split(',', $match[2]);
1253         }
1255         // Walk thru prepared ACL by using $module
1256         foreach($aclList as $sAcl) {
1257           $checkAcl= "";
1259           // Category or detailed permission?
1260           if (strpos('/', $module) === false) {
1261             if (preg_match('/([a-zA-Z0-9]+):([rwcdm]+)/', $sAcl, $m) ) {
1262               $checkAcl= $ui->get_permissions($dn, $module, $m[1]);
1263               $sAcl= $m[2];
1264             } else {
1265               $checkAcl= $ui->get_permissions($dn, $module, '0');
1266             }
1267           } else {
1268             $checkAcl= $ui->get_category_permissions($dn, $module);
1269           }
1271           // Split up remaining part of the acl and check if it we're
1272           // allowed to do something...
1273           $parts= str_split($sAcl);
1274           foreach ($parts as $part) {
1275             if (strpos($checkAcl, $part) === false){
1276               return false;
1277             }
1278           }
1280         }
1281       }
1282     }
1284     return true;
1285   }
1288   function refreshBasesList()
1289   {
1290     global $config;
1291     $ui= get_userinfo();
1293     // Do some array munching to get it user friendly
1294     $ids= $config->idepartments;
1295     $d= $ui->get_module_departments($this->module);
1296     $k_ids= array_keys($ids);
1297     $deps= array_intersect($d,$k_ids);
1299     // Fill internal bases list
1300     $this->bases= array();
1301     foreach($k_ids as $department){
1302       $this->bases[$department] = $ids[$department];
1303     }
1304   }
1307   function getDepartments()
1308   {
1309     $departments= array();
1310     $ui= get_userinfo();
1312     // Get list of supported department types
1313     $types = departmentManagement::get_support_departments();
1315     // Load departments allowed by ACL
1316     $validDepartments = $ui->get_module_departments($this->module);
1318     // Build filter and look in the LDAP for possible sub departments
1319     // of current base
1320     $filter= "(&(objectClass=gosaDepartment)(|";
1321     $attrs= array("description", "objectClass");
1322     foreach($types as $name => $data){
1323       $filter.= "(objectClass=".$data['OC'].")";
1324       $attrs[]= $data['ATTR'];
1325     }
1326     $filter.= "))";
1327     $res= get_list($filter, $this->module, $this->base, $attrs, GL_NONE);
1329     // Analyze list of departments
1330     foreach ($res as $department) {
1331       if (!in_array($department['dn'], $validDepartments)) {
1332         continue;
1333       }
1335       // Add the attribute where we use for sorting
1336       $oc= null;
1337       foreach(array_keys($types) as $type) {
1338         if (in_array($type, $department['objectClass'])) {
1339           $oc= $type;
1340           break;
1341         }
1342       }
1343       $department['sort-attribute']= $types[$oc]['ATTR'];
1345       // Move to the result list
1346       $departments[]= $department;
1347     }
1349     return $departments;
1350   }
1353   function renderCopyPasteMenu($separator, $copy= true, $cut= true)
1354   {
1355     // We can only provide information if we've got a copypaste handler
1356     // instance
1357     if(!(isset($this->copyPasteHandler) && is_object($this->copyPasteHandler))){
1358       return "";
1359     }
1361     // Presets
1362     $result= "";
1363     $read= $paste= false;
1364     $ui= get_userinfo();
1366     // Switch flags to on if there's at least one category which allows read/paste
1367     foreach($this->categories as $category){
1368       $read= $read || preg_match('/r/', $ui->get_category_permissions($this->base, $category));
1369       $paste= $paste || $ui->is_pasteable($this->base, $category) == 1;
1370     }
1373     // Draw entries that allow copy and cut
1374     if($read){
1376       // Copy entry
1377       if($copy){
1378         $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>";
1379         $separator= "";
1380       }
1382       // Cut entry
1383       if($cut){
1384         $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>";
1385         $separator= "";
1386       }
1387     }
1389     // Draw entries that allow pasting entries
1390     if($paste){
1391       if($this->copyPasteHandler->entries_queued()){
1392         $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>";
1393       }else{
1394         $result.= "<li$separator><a href='#'><img src='images/lists/paste-grey.png' alt='' border='0' class='center'>&nbsp;"._("Paste")."</a></li>";
1395       }
1396     }
1397     
1398     return($result);
1399   }
1402   function renderCopyPasteActions($row, $dn, $category, $class, $copy= true, $cut= true)
1403   {
1404     // We can only provide information if we've got a copypaste handler
1405     // instance
1406     if(!(isset($this->copyPasteHandler) && is_object($this->copyPasteHandler))){
1407       return "";
1408     }
1410     // Presets
1411     $ui = get_userinfo();
1412     $result = "";
1414     // Render cut entries
1415     if($cut){
1416       if($ui->is_cutable($dn, $category, $class)){
1417         $result .= "<input class='center' type='image'
1418           src='images/lists/cut.png' alt='"._("Cut")."' name='listing_cut_$row' title='"._("Cut this entry")."' style='padding:1px'>";
1419       }else{
1420         $result.="<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
1421       }
1422     }
1424     // Render copy entries
1425     if($copy){
1426       if($ui->is_copyable($dn, $category, $class)){
1427         $result.= "<input class='center' type='image'
1428           src='images/lists/copy.png' alt='"._("Copy")."' name='listing_copy_$row' title='"._("Copy this entry")."' style='padding:1px'>";
1429       }else{
1430         $result.="<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
1431       }
1432     }
1434     return($result);
1435   }
1438   function renderSnapshotMenu($separator)
1439   {
1440     // We can only provide information if we've got a snapshot handler
1441     // instance
1442     if(!(isset($this->snapshotHandler) && is_object($this->snapshotHandler))){
1443       return "";
1444     }
1446     // Presets
1447     $result = "";
1448     $ui = get_userinfo();
1450     if($this->snapshotHandler->enabled() && $ui->allow_snapshot_restore($this->base, $this->module)){
1452       // Check if there is something to restore
1453       $restore= false;
1454       foreach($this->snapshotHandler->getSnapshotBases() as $base){
1455         $restore= $restore || count($this->snapshotHandler->getDeletedSnapshots($base)) > 0;
1456       }
1458       // Draw icons according to the restore flag
1459       if($restore){
1460         $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>";
1461       }else{
1462         $result.= "<li$separator><a href='#'><img src='images/lists/restore_grey.png' alt='' border='0' class='center'>&nbsp;"._("Restore snapshots")."</a></li>";
1463       }
1464     }
1466     return($result);
1467   }
1470   function renderExporterMenu($separator)
1471   {
1472     // Presets
1473     $result = "";
1475     // Draw entries
1476     $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'>";
1478     // Export CVS as build in exporter
1479     foreach ($this->exporter as $action => $exporter) {
1480       $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>";
1481     }
1483     // Finalize list
1484     $result.= "</ul></li>";
1486     return($result);
1487   }
1490   function renderSnapshotActions($row, $dn, $category, $class, $copy= true, $cut= true)
1491   {
1492     // We can only provide information if we've got a snapshot handler
1493     // instance
1494     if(!(isset($this->snapshotHandler) && is_object($this->snapshotHandler))){
1495       return "";
1496     }
1498     // Presets
1499     $result= "";
1500     $ui = get_userinfo();
1502     // Only act if enabled here
1503     if($this->snapshotHandler->enabled()){
1505       // Draw restore button
1506       if ($ui->allow_snapshot_restore($dn, $category)){
1508         // Do we have snapshots for this dn?
1509         if($this->snapshotHandler->hasSnapshots($dn)){
1510           $result.= "<input class='center' type='image' src='images/lists/restore.png' ".
1511                      "alt='"._("Restore snapshot")."' name='listing_restore_$row' title='".
1512                      _("Restore snapshot")."' style='padding:1px'>";
1513         } else {
1514           $result.= "<img src='images/lists/restore_grey.png' alt=' ' class='center' style='padding:1px'>";
1515         }
1516       }
1518       // Draw snapshot button
1519       if($ui->allow_snapshot_create($dn, $category)){
1520           $result.= "<input class='center' type='image' src='images/snapshot.png' ".
1521                      "alt='"._("Create snapshot")."' name='listing_snapshot_$row' title='".
1522                      _("Create a new snapshot from this object")."' style='padding:1px'>";
1523       }else{
1524           $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
1525       }
1526     }
1528     return($result);
1529   }
1532   function renderDaemonMenu($separator)
1533   {
1534     $result= "";
1536     // If there is a daemon registered, draw the menu entries
1537     if(class_available("DaemonEvent")){
1538       $events= DaemonEvent::get_event_types_by_category($this->categories);
1539       if(isset($events['BY_CLASS']) && count($events['BY_CLASS'])){
1540         foreach($events['BY_CLASS'] as $name => $event){
1541           $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>";
1542           $separator= "";
1543         }
1544       }
1545     }
1547     return $result;
1548   }
1551   function getEntry($dn)
1552   {
1553     foreach ($this->entries as $entry) {
1554       if (isset($entry['dn']) && strcasecmp($dn, $entry['dn']) == 0){
1555         return $entry;
1556       }
1557     }
1558     return null;
1559   }
1562   function getType($dn)
1563   {
1564     if (isset($this->objectDnMapping[$dn])) {
1565       return $this->objectDnMapping[$dn];
1566     }
1567     return null;
1568   }
1572 ?>