Code

Updated baseSelector
[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 $singleSelect= false;
32   var $template;
33   var $headline;
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 $filter= null;
46   var $pid;
47   var $objectTypes= array();
48   var $objectTypeCount= array();
49   var $objectDnMapping= array();
50   var $copyPasteHandler= null;
51   var $snapshotHandler= null;
52   var $exporter= array();
53   var $exportColumns= array();
54   var $useSpan= false;
55   var $height= 0;
56   var $scrollPosition= 0;
57   var $baseSelector;
60   function listing($filename)
61   {
62     global $config;
63     global $class_mapping;
65     // Initialize pid
66     $this->pid= preg_replace("/[^0-9]/", "", microtime(TRUE));
68     if (!$this->load($filename)) {
69       die("Cannot parse $filename!");
70     }
72     // Set base for filter
73     if ($this->baseMode) {
74       $this->base= session::global_get("CurrentMainBase");
75       if ($this->base == null) {
76         $this->base= $config->current['BASE'];
77       }
78       $this->refreshBasesList();
79     } else {
80       $this->base= $config->current['BASE'];
81     }
83     // Move footer information
84     $this->showFooter= ($config->get_cfg_value("listSummary") == "true");
86     // Register build in filters
87     $this->registerElementFilter("objectType", "listing::filterObjectType");
88     $this->registerElementFilter("departmentLink", "listing::filterDepartmentLink");
89     $this->registerElementFilter("link", "listing::filterLink");
90     $this->registerElementFilter("actions", "listing::filterActions");
92     // Load exporters
93     foreach($class_mapping as $class => $dummy) {
94       if (preg_match('/Exporter$/', $class)) {
95         $info= call_user_func(array($class, "getInfo"));
96         if ($info != null) {
97           $this->exporter= array_merge($this->exporter, $info);
98         }
99       }
100     }
102     // Instanciate base selector
103     $this->baseSelector= new baseSelector($this->bases, $this->base);
104   }
107   function setCopyPasteHandler($handler)
108   {
109     $this->copyPasteHandler= &$handler;
110   }
113   function setHeight($height)
114   {
115     $this->height= $height;
116   }
119   function setSnapshotHandler($handler)
120   {
121     $this->snapshotHandler= &$handler;
122   }
125   function getFilter()
126   { 
127     return($this->filter);
128   }  
131   function setFilter($filter)
132   {
133     $this->filter= &$filter;
134     if ($this->departmentBrowser){
135       $this->departments= $this->getDepartments();
136     }
137     $this->filter->setBase($this->base);
138   }
141   function registerElementFilter($name, $call)
142   {
143     if (!isset($this->filters[$name])) {
144       $this->filters[$name]= $call;
145       return true;
146     }
148     return false;
149   }
152   function load($filename)
153   {
154     $contents = file_get_contents($filename);
155     $this->xmlData= xml::xml2array($contents, 1);
157     if (!isset($this->xmlData['list'])) {
158       return false;
159     }
161     $this->xmlData= $this->xmlData["list"];
163     // Load some definition values
164     foreach (array("departmentBrowser", "departmentRootVisible", "multiSelect","singleSelect", "baseMode") as $token) {
165       if (isset($this->xmlData['definition'][$token]) &&
166           $this->xmlData['definition'][$token] == "true"){
167         $this->$token= true;
168       }
169     }
171     // Fill objectTypes from departments and xml definition
172     $types = departmentManagement::get_support_departments();
173     foreach ($types as $class => $data) {
174       $this->objectTypes[$data['OC']]= array("label" => $data['TITLE'],
175                                   "objectClass" => $data['OC'],
176                                   "image" => $data['IMG']);
177     }
178     $this->categories= array();
179     if (isset($this->xmlData['definition']['objectType'])) {
180       if(isset($this->xmlData['definition']['objectType']['label'])) {
181         $this->xmlData['definition']['objectType']= array($this->xmlData['definition']['objectType']);
182       }
183       foreach ($this->xmlData['definition']['objectType'] as $index => $otype) {
184         $tmp = $this->xmlData['definition']['objectType'][$index];
185         $this->objectTypes[$tmp['objectClass']]= $tmp;
186         if (isset($this->xmlData['definition']['objectType'][$index]['category'])){
187           $this->categories[]= $otype['category'];
188         }
189       }
190     }
191     $this->objectTypes = array_values($this->objectTypes);
193     // Parse layout per column
194     $this->colprops= $this->parseLayout($this->xmlData['table']['layout']);
196     // Prepare table headers
197     $this->renderHeader();
199     // Assign headline/Categories
200     $this->headline= _($this->xmlData['definition']['label']);
201     if (!is_array($this->categories)){
202       $this->categories= array($this->categories);
203     }
205     // Evaluate columns to be exported
206     if (isset($this->xmlData['table']['column'])){
207       foreach ($this->xmlData['table']['column'] as $index => $config) {
208         if (isset($config['export']) && $config['export'] == "true"){
209           $this->exportColumns[]= $index;
210         }
211       }
212     }
214     return true;  
215   }
218   function renderHeader()
219   {
220     $this->header= array();
221     $this->plainHeader= array();
223     // Initialize sort?
224     $sortInit= false;
225     if (!$this->sortDirection) {
226       $this->sortColumn= 0;
227       if (isset($this->xmlData['definition']['defaultSortColumn'])){
228         $this->sortColumn= $this->xmlData['definition']['defaultSortColumn'];
229       } else {
230         $this->sortAttribute= "";
231       }
232       $this->sortDirection= array();
233       $sortInit= true;
234     }
236     if (isset($this->xmlData['table']['column'])){
237       foreach ($this->xmlData['table']['column'] as $index => $config) {
238         // Initialize everything to one direction
239         if ($sortInit) {
240           $this->sortDirection[$index]= false;
241         }
243         $sorter= "";
244         if ($index == $this->sortColumn && isset($config['sortAttribute']) &&
245             isset($config['sortType'])) {
246           $this->sortAttribute= $config['sortAttribute'];
247           $this->sortType= $config['sortType'];
248           $sorter= "&nbsp;".image("images/lists/sort-".($this->sortDirection[$index]?"up":"down").".png", null, $this->sortDirection[$index]?_("Sort ascending"):_("Sort descending"), "text-top");
249         }
250         $sortable= (isset($config['sortAttribute']));
252         $link= "href='?plug=".$_GET['plug']."&amp;PID=".$this->pid."&amp;act=SORT_$index'";
253         if (isset($config['label'])) {
254           if ($sortable) {
255             $this->header[$index]= "<td class='listheader' ".$this->colprops[$index]."><a $link>"._($config['label'])."</a>$sorter</td>";
256           } else {
257             $this->header[$index]= "<td class='listheader' ".$this->colprops[$index].">"._($config['label'])."</td>";
258           }
259           $this->plainHeader[]= _($config['label']);
260         } else {
261           if ($sortable) {
262             $this->header[$index]= "<td class='listheader' ".$this->colprops[$index]."><a $link>&nbsp;</a>$sorter</td>";
263           } else {
264             $this->header[$index]= "<td class='listheader' ".$this->colprops[$index].">&nbsp;</td>";
265           }
266           $this->plainHeader[]= "";
267         }
268       }
269     }
270   }
273   function render()
274   {
275     // Check for exeeded sizelimit
276     if (($message= check_sizelimit()) != ""){
277       return($message);
278     }
280     // Some browsers don't have the ability do do scrollable table bodies, filter them
281     // here.
282     $switch= false;
283     if (preg_match('/(Opera|Konqueror|Safari)/i', $_SERVER['HTTP_USER_AGENT'])){
284       $switch= true;
285     }
287     // Initialize list
288     $result= "<input type='hidden' value='$this->pid' name='PID'>\n";
289     $result.= "<input type='hidden' name='position_".$this->pid."' id='position_".$this->pid."'>\n";
290     $height= 450;
291     if ($this->height != 0) {
292       $result.= "<input type='hidden' value='$this->height' id='d_height'>\n";
293       $height= $this->height;
294     }
295     
296     $result.= "<div class='listContainer' id='d_scrollbody' style='min-height:".($height+25)."px;'>\n";
297     $result.= "<table summary='$this->headline' style='width:100%;table-layout:fixed' cellspacing='0' cellpadding='0' id='t_scrolltable'>\n";
298     $this->numColumns= count($this->colprops) + (($this->multiSelect|$this->singleSelect)?1:0);
300     // Build list header
301     $result.= "<thead class='fixedListHeader listHeaderFormat'><tr>\n";
302     if ($this->multiSelect || $this->singleSelect) {
303       $width= "24px";
304       if (preg_match('/Konqueror/i', $_SERVER['HTTP_USER_AGENT'])){
305         $width= "28px";
306       }
307       $result.= "<td class='listheader' style='text-align:center;padding:0;width:$width;'>";
308       if($this->multiSelect){
309           $result.= "<input type='checkbox' id='select_all' name='select_all' 
310               title='"._("Select all")."' onClick='toggle_all_(\"listing_selected_[0-9]*$\",\"select_all\");' >";
311       }else{
312           $result.= "&nbsp;";
313       }
314       $result.="</td>\n";
315     }
316     foreach ($this->header as $header) {
317       $result.= $header;
318     }
319     $result.= "</tr></thead>\n";
321     // Build list body
322     $result.= "<tbody class='listScrollContent listBodyFormat' id='t_nscrollbody' style='height:".$height."px;'>\n";
324     // No results? Just take an empty colspanned row
325     if (count($this->entries) + count($this->departments) == 0) {
326       $result.= "<tr><td class='list1nohighlight' colspan='$this->numColumns' style='height:100%;border-right:0px;width:100%;'>&nbsp;</td></tr>";
327     }
329     // Line color alternation
330     $alt= 0;
331     $deps= 0;
333     // Draw department browser if configured and we're not in sub mode
334     $this->useSpan= false;
335     if ($this->departmentBrowser && $this->filter->scope != "sub") {
336       // Fill with department browser if configured this way
337       $departmentIterator= new departmentSortIterator($this->departments, $this->sortDirection[$this->sortColumn]);
338       foreach ($departmentIterator as $row => $entry){
339         $result.="<tr>";
341         // Render multi select if needed
342         if ($this->multiSelect || $this->singleSelect) {
343           $result.="<td style='text-align:center;padding:0;' class='list1'>&nbsp;</td>";
344         }
346         // Render defined department columns, fill the rest with some stuff
347         $rest= $this->numColumns - 1;
348         foreach ($this->xmlData['table']['department'] as $index => $config) {
349           $colspan= 1;
350           if (isset($config['span'])){
351             $colspan= $config['span'];
352             $this->useSpan= true;
353           }
354           $result.="<td colspan='$colspan' ".$this->colprops[$index]." class='list1'>".$this->renderCell($config['value'], $entry, $row)."</td>";
355           $rest-= $colspan;
356         }
358         // Fill remaining cols with nothing
359         $last= $this->numColumns - $rest;
360         for ($i= 0; $i<$rest; $i++){
361           $result.= "<td ".$this->colprops[$last+$i-1]." class='list1'>&nbsp;</td>";
362         }
363         $result.="</tr>";
365         $alt++;
366       }
367       $deps= $alt;
368     }
370     // Fill with contents, sort as configured
371     foreach ($this->entries as $row => $entry) {
372       $trow= "";
374       // Render multi select if needed
375       if ($this->multiSelect) {
376         $trow.="<td style='text-align:center;width:20px;' class='list0'><input type='checkbox' id='listing_selected_$row' name='listing_selected_$row'></td>\n";
377       }
379       if ($this->singleSelect) {
380         $trow.="<td style='text-align:center;width:20px;' class='list0'><input type='radio' id='listing_radio_selected_$row' name='listing_radio_selected' value='{$row}'></td>\n";
381       }
383       foreach ($this->xmlData['table']['column'] as $index => $config) {
384         $renderedCell= $this->renderCell($config['value'], $entry, $row);
385         $trow.="<td ".$this->colprops[$index]." class='list0'>".$renderedCell."</td>\n";
387         // Save rendered column
388         $sort= preg_replace('/.*>([^<]+)<.*$/', '$1', $renderedCell);
389         $sort= preg_replace('/&nbsp;/', '', $sort);
390         if (preg_match('/</', $sort)){
391           $sort= "";
392         }
393         $this->entries[$row]["_sort$index"]= $sort;
394       }
396       // Save rendered entry
397       $this->entries[$row]['_rendered']= $trow;
398     }
400     // Complete list by sorting entries for _sort$index and appending them to the output
401     $entryIterator= new listingSortIterator($this->entries, $this->sortDirection[$this->sortColumn], "_sort".$this->sortColumn, $this->sortType);
402     foreach ($entryIterator as $row => $entry){
404       // Apply custom class to row?
405       if (preg_match("/<rowClass:([a-z0-9_-]*)\/>/i", $entry['_rendered'], $matches)) {
406         $result.="<tr class='".$matches[1]."'>\n";
407         $result.= preg_replace("/<rowClass[^>]+>/", '', $entry['_rendered']);
408       } else {
409         $result.="<tr>\n";
410         $result.= $entry['_rendered'];
411       }
413       $result.="</tr>\n";
414       $alt++;
415     }
417     // Need to fill the list if it's not full (nobody knows why this is 22 ;-))
418     $emptyListStyle= (count($this->entries) + (($this->useSpan && count($this->entries))?$deps:0) == 0)?"border:0;":"";
419     if ((count($this->entries) + $deps) < 22) {
420       $result.= "<tr>";
421       for ($i= 0; $i<$this->numColumns; $i++) {
422         if ($i == 0) {
423           $result.= "<td class='list1nohighlight' style='$emptyListStyle height:100%;'>&nbsp;</td>";
424           continue;
425         }
426         if ($i != $this->numColumns-1) {
427           $result.= "<td class='list1nohighlight' style='$emptyListStyle'>&nbsp;</td>";
428         } else {
429           $result.= "<td class='list1nohighlight' style='border-right:0;$emptyListStyle'>&nbsp;</td>";
430         }
431       }
433       $result.= "</tr>";
434     }
436     // Close list body
437     $result.= "</tbody></table></div>";
439     // Add the footer if requested
440     if ($this->showFooter) {
441       $result.= "<div class='nlistFooter'><div style='padding:3px'>";
443       foreach ($this->objectTypes as $objectType) {
444         if (isset($this->objectTypeCount[$objectType['label']])) {
445           $label= _($objectType['label']);
446           $result.= image($objectType['image'], null, $label)."&nbsp;".$this->objectTypeCount[$objectType['label']]."&nbsp;&nbsp;";
447         }
448       }
450       $result.= "</div></div>";
451     }
453     // Close list
454     $result.= $switch?"<input type='hidden' id='list_workaround'>":"";
456     // Add scroll positioner
457     $result.= '<script type="text/javascript" language="javascript">';
458     $result.= '$("t_nscrollbody").scrollTop= '.$this->scrollPosition.';';
459     $result.= 'var box = $("t_nscrollbody").onscroll= function() {$("position_'.$this->pid.'").value= this.scrollTop;}';
460     $result.= '</script>';
462     $smarty= get_smarty();
463     $smarty->assign("usePrototype", "true");
464     $smarty->assign("FILTER", $this->filter->render());
465     $smarty->assign("SIZELIMIT", print_sizelimit_warning());
466     $smarty->assign("LIST", $result);
468     // Assign navigation elements
469     $nav= $this->renderNavigation();
470     foreach ($nav as $key => $html) {
471       $smarty->assign($key, $html);
472     }
474     // Assign action menu / base
475     $smarty->assign("HEADLINE", $this->headline);
476     $smarty->assign("ACTIONS", $this->renderActionMenu());
477     $smarty->assign("BASE", $this->renderBase());
479     // Assign separator
480     $smarty->assign("SEPARATOR", "<img src='images/lists/seperator.png' alt='-' align='middle' height='16' width='1' class='center'>");
482     // Assign summary
483     $smarty->assign("HEADLINE", $this->headline);
485     // Try to load template from plugin the folder first...
486     $file = get_template_path($this->xmlData['definition']['template'], true);
488     // ... if this fails, try to load the file from the theme folder.
489     if(!file_exists($file)){
490       $file = get_template_path($this->xmlData['definition']['template']);
491     }
493     return ($smarty->fetch($file));
494   }
497   function update()
498   {
499     global $config;
500     $ui= get_userinfo();
502     // Take care of base selector
503     if ($this->baseMode) {
504       $this->baseSelector->update();
506       // Check if a wrong base was supplied
507       if(!$this->baseSelector->checkLastBaseUpdate()){
508          msg_dialog::display(_("Error"), msgPool::check_base(), ERROR_DIALOG);
509       }
510     }
512     // Save base
513     $refresh= false;
514     if ($this->baseMode) {
515       $this->base= $this->baseSelector->getBase();
516       session::global_set("CurrentMainBase", $this->base);
517       $refresh= true;
518     }
521     // Reset object counter / DN mapping
522     $this->objectTypeCount= array();
523     $this->objectDnMapping= array();
525     // Do not do anything if this is not our PID
526     if($refresh || !(isset($_REQUEST['PID']) && $_REQUEST['PID'] != $this->pid)) {
528       // Save position if set
529       if (isset($_POST['position_'.$this->pid]) && is_numeric($_POST['position_'.$this->pid])) {
530         $this->scrollPosition= $_POST['position_'.$this->pid];
531       }
533       // Override the base if we got a message from the browser navigation
534       if ($this->departmentBrowser && isset($_GET['act'])) {
535         if (preg_match('/^department_([0-9]+)$/', validate($_GET['act']), $match)){
536           if (isset($this->departments[$match[1]])){
537             $this->base= $this->departments[$match[1]]['dn'];
538             if ($this->baseMode) {
539               $this->baseSelector->setBase($this->base);
540             }
541             session::global_set("CurrentMainBase", $this->base);
542           }
543         }
544       }
546       // Filter POST with "act" attributes -> posted from action menu
547       if (isset($_POST['exec_act']) && $_POST['act'] != '') {
548         if (preg_match('/^export.*$/', $_POST['act']) && isset($this->exporter[$_POST['act']])) {
549           $exporter= $this->exporter[$_POST['act']];
550           $userinfo= ", "._("created by")." ".$ui->cn." - ".strftime('%A, %d. %B %Y, %H:%M:%S');
551           $entryIterator= new listingSortIterator($this->entries, $this->sortDirection[$this->sortColumn], "_sort".$this->sortColumn, $this->sortType);
552           $sortedEntries= array();
553           foreach ($entryIterator as $entry){
554             $sortedEntries[]= $entry;
555           }
556           $instance= new $exporter['class']($this->headline.$userinfo, $this->plainHeader, $sortedEntries, $this->exportColumns);
557           $type= call_user_func(array($exporter['class'], "getInfo"));
558           $type= $type[$_POST['act']];
559           send_binary_content($instance->query(), $type['filename'], $type= $type['mime']);
560         }
561       }
563       // Filter GET with "act" attributes
564       if (isset($_GET['act'])) {
565         $key= validate($_GET['act']);
566         if (preg_match('/^SORT_([0-9]+)$/', $key, $match)) {
567           // Switch to new column or invert search order?
568           $column= $match[1];
569           if ($this->sortColumn != $column) {
570             $this->sortColumn= $column;
571           } else {
572             $this->sortDirection[$column]= !$this->sortDirection[$column];
573           }
575           // Allow header to update itself according to the new sort settings
576           $this->renderHeader();
577         }
578       }
580       // Override base if we got signals from the navigation elements
581       $action= "";
582       foreach ($_POST as $key => $value) {
583         if (preg_match('/^(ROOT|BACK|HOME)(_x)?$/', $key, $match)) {
584           $action= $match[1];
585           break;
586         }
587       }
589       // Navigation handling
590       if ($action == 'ROOT') {
591         $deps= $ui->get_module_departments($this->categories);
592         $this->base= $deps[0];
593         $this->baseSelector->setBase($this->base);
594         session::global_set("CurrentMainBase", $this->base);
595       }
596       if ($action == 'BACK') {
597         $deps= $ui->get_module_departments($this->categories);
598         $base= preg_replace("/^[^,]+,/", "", $this->base);
599         if(in_array_ics($base, $deps)){
600           $this->base= $base;
601           $this->baseSelector->setBase($this->base);
602           session::global_set("CurrentMainBase", $this->base);
603         }
604       }
605       if ($action == 'HOME') {
606         $ui= get_userinfo();
607         $this->base= get_base_from_people($ui->dn);
608         $this->baseSelector->setBase($this->base);
609         session::global_set("CurrentMainBase", $this->base);
610       }
611     }
613     // Reload departments
614     if ($this->departmentBrowser){
615       $this->departments= $this->getDepartments();
616     }
618     // Update filter and refresh entries
619     $this->filter->setBase($this->base);
620     $this->entries= $this->filter->query();
622     // Fix filter if querie returns NULL
623     if ($this->entries == null) {
624       $this->entries= array();
625     }
626   }
629   function setBase($base)
630   {
631     $this->base= $base;
632     if ($this->baseMode) {
633       $this->baseSelector->setBase($this->base);
634     }
635   }
638   function getBase()
639   {
640     return $this->base;
641   }
644   function parseLayout($layout)
645   {
646     $result= array();
647     $layout= preg_replace("/^\|/", "", $layout);
648     $layout= preg_replace("/\|$/", "", $layout);
649     $cols= explode("|", $layout);
651     foreach ($cols as $index => $config) {
652       if ($config != "") {
653         $res= "";
654         $components= explode(';', $config);
655         foreach ($components as $part) {
656           if (preg_match("/^r$/", $part)) {
657             $res.= "text-align:right;";
658             continue;
659           }
660           if (preg_match("/^l$/", $part)) {
661             $res.= "text-align:left;";
662             continue;
663           }
664           if (preg_match("/^c$/", $part)) {
665             $res.= "text-align:center;";
666             continue;
667           }
668           if (preg_match("/^[0-9]+(|px|%)$/", $part)) {
669             $res.= "width:$part;min-width:$part;";
670             continue;
671           }
672         }
674         // Add minimum width for scalable columns
675         if (!preg_match('/width:/', $res)){
676           $res.= "min-width:200px;";
677         }
679         $result[$index]= " style='$res'";
680       } else {
681         $result[$index]= " style='min-width:100px;'";
682       }
683     }
685     // Save number of columns for later use
686     $this->numColumns= count($cols);
688     // Add no border to the last column
689     $result[$this->numColumns-1]= preg_replace("/'$/", "border-right:0;'", $result[$this->numColumns-1]);
691     return $result;
692   }
695   function renderCell($data, $config, $row)
696   {
697     // Replace flat attributes in data string
698     for ($i= 0; $i<$config['count']; $i++) {
699       $attr= $config[$i];
700       $value= "";
701       if (is_array($config[$attr])) {
702         $value= $config[$attr][0];
703       } else {
704         $value= $config[$attr];
705       }
706       $data= preg_replace("/%\{$attr\}/", $value, $data);
707     }
709     // Watch out for filters and prepare to execute them
710     $data= $this->processElementFilter($data, $config, $row);
712     // Replace all non replaced %{...} instances because they
713     // are non resolved attributes or filters
714     $data= preg_replace('/%{[^}]+}/', '&nbsp;', $data);
716     return $data;
717   }
720   function renderBase()
721   {
722     if (!$this->baseMode) {
723       return;
724     }
726     return $this->baseSelector->render();
727   }
730   function processElementFilter($data, $config, $row)
731   {
732     preg_match_all("/%\{filter:([^(]+)\((.*)\)\}/", $data, $matches, PREG_SET_ORDER);
734     foreach ($matches as $match) {
735       $cl= "";
736       $method= "";
737       if (preg_match('/::/', $match[1])) {
738         $cl= preg_replace('/::.*$/', '', $match[1]);
739         $method= preg_replace('/^.*::/', '', $match[1]);
740       } else {
741         if (!isset($this->filters[$match[1]])) {
742           continue;
743         }
744         $cl= preg_replace('/::.*$/', '', $this->filters[$match[1]]);
745         $method= preg_replace('/^.*::/', '', $this->filters[$match[1]]);
746       }
748       // Prepare params for function call
749       $params= array();
750       preg_match_all('/"[^"]+"|[^,]+/', $match[2], $parts);
751       foreach ($parts[0] as $param) {
753         // Row is replaced by the row number
754         if ($param == "row") {
755           $params[]= $row;
756           continue;
757         }
759         // pid is replaced by the current PID
760         if ($param == "pid") {
761           $params[]= $this->pid;
762           continue;
763         }
765         // base is replaced by the current base
766         if ($param == "base") {
767           $params[]= $this->getBase();
768           continue;
769         }
771         // Fixie with "" is passed directly
772         if (preg_match('/^".*"$/', $param)){
773           $params[]= preg_replace('/"/', '', $param);
774           continue;
775         }
777         // Move dn if needed
778         if ($param == "dn") {
779           $params[]= LDAP::fix($config["dn"]);
780           continue;
781         }
783         // LDAP variables get replaced by their objects
784         for ($i= 0; $i<$config['count']; $i++) {
785           if ($param == $config[$i]) {
786             $values= $config[$config[$i]];
787             if (is_array($values)){
788               unset($values['count']);
789             }
790             $params[]= $values;
791             break;
792           }
793         }
794       }
796       // Replace information
797       if ($cl == "listing") {
798         // Non static call - seems to result in errors
799         $data= @preg_replace('/'.preg_quote($match[0]).'/', call_user_func_array(array($this, "$method"), $params), $data);
800       } else {
801         // Static call
802         $data= preg_replace('/'.preg_quote($match[0]).'/', call_user_func_array(array($cl, $method), $params), $data);
803       }
804     }
806     return $data;
807   }
810   function getObjectType($types, $classes)
811   {
812     // Walk thru types and see if there's something matching
813     foreach ($types as $objectType) {
814       $ocs= $objectType['objectClass'];
815       if (!is_array($ocs)){
816         $ocs= array($ocs);
817       }
819       $found= true;
820       foreach ($ocs as $oc){
821         if (preg_match('/^!(.*)$/', $oc, $match)) {
822           $oc= $match[1];
823           if (in_array($oc, $classes)) {
824             $found= false;
825           }
826         } else {
827           if (!in_array($oc, $classes)) {
828             $found= false;
829           }
830         }
831       }
833       if ($found) {
834         return $objectType;
835       }
836     }
838     return null;
839   }
842   function filterObjectType($dn, $classes)
843   {
844     // Walk thru classes and return on first match
845     $result= "&nbsp;";
847     $objectType= $this->getObjectType($this->objectTypes, $classes);
848     if ($objectType) {
849       $this->objectDnMapping[$dn]= $objectType["objectClass"];
850       $result= image($objectType["image"], null, LDAP::fix($dn));
851       if (!isset($this->objectTypeCount[$objectType['label']])) {
852         $this->objectTypeCount[$objectType['label']]= 0;
853       }
854       $this->objectTypeCount[$objectType['label']]++;
855     }
857     return $result;
858   }
861   function filterActions($dn, $row, $classes)
862   {
863     // Do nothing if there's no menu defined
864     if (!isset($this->xmlData['actiontriggers']['action'])) {
865       return "&nbsp;";
866     }
868     // Go thru all actions
869     $result= "";
870     $actions= $this->xmlData['actiontriggers']['action'];
872     // Ensure we've a valid actions array, if there is only one action in the actiontriggers col
873     //  then we've to create a valid array here.
874     if(isset($actions['name'])) $actions = array($actions);
876     foreach($actions as $action) {
877       // Skip the entry completely if there's no permission to execute it
878       if (!$this->hasActionPermission($action, $dn, $classes)) {
879         $result.= image('images/empty.png');
880         continue;
881       }
883       // Skip entry if the pseudo filter does not fit
884       if (isset($action['filter']) && preg_match('/^[a-z0-9_]+!?=[a-z0-9_]+$/i', $action['filter'])) {
885         list($fa, $fv)= explode('=', $action['filter']);
886         if (preg_match('/^(.*)!$/', $fa, $m)){
887           $fa= $m[1];
888           if (isset($this->entries[$row][$fa]) && $this->entries[$row][$fa][0] == $fv) {
889             $result.= image('images/empty.png');
890             continue;
891           }
892         } else {
893           if (!isset($this->entries[$row][$fa]) && !$this->entries[$row][$fa][0] == $fv) {
894             $result.= image('images/empty.png');
895             continue;
896           }
897         }
898       }
901       // If there's an objectclass definition and we don't have it
902       // add an empty picture here.
903       if (isset($action['objectclass'])){
904         $objectclass= $action['objectclass'];
905         if (preg_match('/^!(.*)$/', $objectclass, $m)){
906           $objectclass= $m[1];
907           if(in_array($objectclass, $classes)) {
908             $result.= image('images/empty.png');
909             continue;
910           }
911         } elseif (is_string($objectclass)) {
912           if(!in_array($objectclass, $classes)) {
913             $result.= image('images/empty.png');
914             continue;
915           }
916         } elseif (is_array($objectclass)) {
917           if(count(array_intersect($objectclass, $classes)) != count($objectclass)){
918             $result.= image('images/empty.png');
919             continue;
920           }
921         }
922       }
924       // Render normal entries as usual
925       if ($action['type'] == "entry") {
926         $label= $this->processElementFilter($action['label'], $this->entries[$row], $row);
927         $image= $this->processElementFilter($action['image'], $this->entries[$row], $row);
928         $result.= image($image, "listing_".$action['name']."_$row", $label);
929       }
931       // Handle special types
932       if ($action['type'] == "copypaste" || $action['type'] == "snapshot") {
934         $objectType= $this->getObjectType($this->objectTypes, $this->entries[$row]['objectClass']);
935         $category= $class= null;
936         if ($objectType) {
937           $category= $objectType['category'];
938           $class= $objectType['class'];
939         }
941         if ($action['type'] == "copypaste") {
942           $copy = !isset($action['copy']) || $action['copy'] == "true";
943           $cut = !isset($action['cut']) || $action['cut'] == "true";
944           $result.= $this->renderCopyPasteActions($row, $this->entries[$row]['dn'], $category, $class,$copy,$cut);
945         } else {
946           $result.= $this->renderSnapshotActions($row, $this->entries[$row]['dn'], $category, $class);
947         }
948       }
949     }
951     return $result;
952   }
955   function filterDepartmentLink($row, $dn, $description)
956   {
957     $attr= $this->departments[$row]['sort-attribute'];
958     $name= $this->departments[$row][$attr];
959     if (is_array($name)){
960       $name= $name[0];
961     }
962     $result= sprintf("%s [%s]", $name, $description[0]);
963     return("<a href='?plug=".$_GET['plug']."&amp;PID=$this->pid&amp;act=department_$row' title='$dn'>$result</a>");
964   }
967   function filterLink()
968   {
969     $result= "&nbsp;";
971     $row= func_get_arg(0);
972     $pid= $this->pid;
973     $dn= LDAP::fix(func_get_arg(1));
974     $params= array(func_get_arg(2));
976     // Collect sprintf params
977     for ($i = 3;$i < func_num_args();$i++) {
978       $val= func_get_arg($i);
979       if (is_array($val)){
980         $params[]= $val[0];
981         continue;
982       }
983       $params[]= $val;
984     }
986     $result= "&nbsp;";
987     $trans= call_user_func_array("sprintf", $params);
988     if ($trans != "") {
989       return("<a href='?plug=".$_GET['plug']."&amp;PID=$pid&amp;act=listing_edit_$row' title='$dn'>$trans</a>");
990     }
992     return $result;
993   }
996   function renderNavigation()
997   {
998     $result= array();
999     $enableBack = true;
1000     $enableRoot = true;
1001     $enableHome = true;
1003     $ui = get_userinfo();
1005     /* Check if base = first available base */
1006     $deps = $ui->get_module_departments($this->categories);
1008     if(!count($deps) || $deps[0] == $this->filter->base){
1009       $enableBack = false;
1010       $enableRoot = false;
1011     }
1013     $listhead ="";
1015     /* Check if we are in users home  department */
1016     if(!count($deps) || $this->filter->base == get_base_from_people($ui->dn)){
1017       $enableHome = false;
1018     }
1020     /* Draw root button */
1021     if($enableRoot){
1022       $result["ROOT"]= image('images/lists/root.png', 'ROOT', _("Root"));
1023     }else{
1024       $result["ROOT"]= image('images/lists/root-grey.png', null, _("Root"));
1025     }
1027     /* Draw back button */
1028     if($enableBack){
1029       $result["BACK"]= image('images/lists/back.png', 'BACK', _("Go to preceding level"));
1030     }else{
1031       $result["BACK"]= image('images/lists/back-grey.png', null, _("Go to preceding level"));
1032     }
1034     /* Draw home button */
1035    /* Draw home button */
1036     if($enableHome){
1037       $result["HOME"]= image('images/lists/home.png', 'HOME', _("Go to current users level"));
1038     }else{
1039       $result["HOME"]= image('images/lists/home-grey.png', null, _("Go to current users level"));
1040     }
1043     /* Draw reload button, this button is enabled everytime */
1044     $result["RELOAD"]= image('images/lists/reload.png', 'REFRESH', _("Reload list"));
1046     return ($result);
1047   }
1050   function getAction()
1051   {
1052     // Do not do anything if this is not our PID, or there's even no PID available...
1053     if(!isset($_REQUEST['PID']) || $_REQUEST['PID'] != $this->pid) {
1054       return;
1055     }
1057     // Save position if set
1058     if (isset($_POST['position_'.$this->pid]) && is_numeric($_POST['position_'.$this->pid])) {
1059       $this->scrollPosition= $_POST['position_'.$this->pid];
1060     }
1062     $result= array("targets" => array(), "action" => "");
1064     // Filter GET with "act" attributes
1065     if (isset($_GET['act'])) {
1066       $key= validate($_GET['act']);
1067       $target= preg_replace('/^listing_[a-zA-Z_]+_([0-9]+)$/', '$1', $key);
1068       if (isset($this->entries[$target]['dn'])) {
1069         $result['action']= preg_replace('/^listing_([a-zA-Z_]+)_[0-9]+$/', '$1', $key);
1070         $result['targets'][]= $this->entries[$target]['dn'];
1071       }
1073       // Drop targets if empty
1074       if (count($result['targets']) == 0) {
1075         unset($result['targets']);
1076       }
1077       return $result;
1078     }
1080     // Get single selection (radio box)
1081     if($this->singleSelect && isset($_POST['listing_radio_selected'])){
1082         $entry = $_POST['listing_radio_selected'];
1083         $result['targets']= array($this->entries[$entry]['dn']);
1084     }
1086     // Filter POST with "listing_" attributes
1087     foreach ($_POST as $key => $prop) {
1089       // Capture selections
1090       if (preg_match('/^listing_selected_[0-9]+$/', $key)) {
1091         $target= preg_replace('/^listing_selected_([0-9]+)$/', '$1', $key);
1092         if (isset($this->entries[$target]['dn'])) {
1093           $result['targets'][]= $this->entries[$target]['dn'];
1094         }
1095         continue;
1096       }
1098       // Capture action with target - this is a one shot
1099       if (preg_match('/^listing_[a-zA-Z_]+_[0-9]+(|_x)$/', $key)) {
1100         $target= preg_replace('/^listing_[a-zA-Z_]+_([0-9]+)(|_x)$/', '$1', $key);
1101         if (isset($this->entries[$target]['dn'])) {
1102           $result['action']= preg_replace('/^listing_([a-zA-Z_]+)_[0-9]+(|_x)$/', '$1', $key);
1103           $result['targets']= array($this->entries[$target]['dn']);
1104         }
1105         break;
1106       }
1108       // Capture action without target
1109       if (preg_match('/^listing_[a-zA-Z_]+(|_x)$/', $key)) {
1110         $result['action']= preg_replace('/^listing_([a-zA-Z_]+)(|_x)$/', '$1', $key);
1111         continue;
1112       }
1113     }
1115     // Filter POST with "act" attributes -> posted from action menu
1116     if (isset($_POST['act']) && $_POST['act'] != '') {
1117       if (!preg_match('/^export.*$/', $_POST['act'])){
1118         $result['action']= validate($_POST['act']);
1119       }
1120     }
1122     // Drop targets if empty
1123     if (count($result['targets']) == 0) {
1124       unset($result['targets']);
1125     }
1126     return $result;
1127   }
1130   function renderActionMenu()
1131   {
1132     $result= "<input type='hidden' name='act' id='act' value=''><div style='display:none'><input type='submit' name='exec_act' id='exec_act' value=''></div>";
1134     // Don't send anything if the menu is not defined
1135     if (!isset($this->xmlData['actionmenu']['action'])){
1136       return $result;
1137     }
1139     // Array?
1140     if (isset($this->xmlData['actionmenu']['action']['type'])){
1141       $this->xmlData['actionmenu']['action']= array($this->xmlData['actionmenu']['action']);
1142     }
1144     // Load shortcut
1145     $actions= &$this->xmlData['actionmenu']['action'];
1146     $result.= "<ul class='level1' id='root'><li><a href='#'>"._("Actions")."&nbsp;".image("images/lists/sort-down.png")."</a>";
1148     // Build ul/li list
1149     $result.= $this->recurseActions($actions);
1151     return "<div id='pulldown'>".$result."</li></ul></div>";
1152   }
1155   function recurseActions($actions)
1156   {
1157     global $class_mapping;
1158     static $level= 2;
1159     $result= "<ul class='level$level'>";
1160     $separator= "";
1162     foreach ($actions as $action) {
1164       // Skip the entry completely if there's no permission to execute it
1165       if (!$this->hasActionPermission($action, $this->filter->base)) {
1166         continue;
1167       }
1169       // Skip entry if there're missing dependencies
1170       if (isset($action['depends'])) {
1171         $deps= is_array($action['depends'])?$action['depends']:array($action['depends']);
1172         foreach($deps as $clazz) {
1173           if (!isset($class_mapping[$clazz])){
1174             continue 2;
1175           }
1176         }
1177       }
1179       // Fill image if set
1180       $img= "";
1181       if (isset($action['image'])){
1182         $img= image($action['image'])."&nbsp;";
1183       }
1185       if ($action['type'] == "separator"){
1186         $separator= " style='border-top:1px solid #AAA' ";
1187         continue;
1188       }
1190       // Dive into subs
1191       if ($action['type'] == "sub" && isset($action['action'])) {
1192         $level++;
1193         if (isset($action['label'])){
1194           $result.= "<li$separator><a href='#'>$img"._($action['label'])."&nbsp;".image('images/forward-arrow.png')."</a>";
1195         }
1197         // Ensure we've an array of actions, this enables sub menus with only one action.
1198         if(isset($action['action']['type'])){
1199           $action['action'] = array($action['action']);
1200         }
1202         $result.= $this->recurseActions($action['action'])."</li>";
1203         $level--;
1204         $separator= "";
1205         continue;
1206       }
1208       // Render entry elseways
1209       if (isset($action['label'])){
1210         $result.= "<li$separator><a href='#' onClick='\$(\"act\").value= \"".$action['name']."\";\$(\"exec_act\").click();'>$img"._($action['label'])."</a></li>";
1211       }
1213       // Check for special types
1214       switch ($action['type']) {
1215         case 'copypaste':
1216           $cut = !isset($action['cut']) || $action['cut'] != "false";
1217           $copy = !isset($action['copy']) || $action['copy'] != "false";
1218           $result.= $this->renderCopyPasteMenu($separator, $copy , $cut);
1219           break;
1221         case 'snapshot':
1222           $result.= $this->renderSnapshotMenu($separator);
1223           break;
1225         case 'exporter':
1226           $result.= $this->renderExporterMenu($separator);
1227           break;
1229         case 'daemon':
1230           $result.= $this->renderDaemonMenu($separator);
1231           break;
1232       }
1234       $separator= "";
1235     }
1237     $result.= "</ul>";
1238     return $result;
1239   }
1242   function hasActionPermission($action, $dn, $classes= null)
1243   {
1244     $ui= get_userinfo();
1246     if (isset($action['acl'])) {
1247       $acls= $action['acl'];
1248       if (!is_array($acls)) {
1249         $acls= array($acls);
1250       }
1252       // Every ACL has to pass
1253       foreach ($acls as $acl) {
1254         $module= $this->categories;
1255         $aclList= array();
1257         // Replace %acl if available
1258         if ($classes) {
1259           $otype= $this->getObjectType($this->objectTypes, $classes);
1260           $acl= str_replace('%acl', $otype['category']."/".$otype['class'], $acl);
1261         }
1263         // Split for category and plugins if needed
1264         // match for "[rw]" style entries
1265         if (preg_match('/^\[([rwcdm]+)\]$/', $acl, $match)){
1266           $aclList= array($match[1]);
1267         }
1269         // match for "users[rw]" style entries
1270         if (preg_match('/^([a-zA-Z0-9]+)\[([rwcdm]+)\]$/', $acl, $match)){
1271           $module= $match[1];
1272           $aclList= array($match[2]);
1273         }
1275         // match for "users/user[rw]" style entries
1276         if (preg_match('/^([a-zA-Z0-9]+\/[a-zA-Z0-9]+)\[([rwcdm]+)\]$/', $acl, $match)){
1277           $module= $match[1];
1278           $aclList= array($match[2]);
1279         }
1281         // match "users/user[userPassword:rw(,...)*]" style entries
1282         if (preg_match('/^([a-zA-Z0-9]+\/[a-zA-Z0-9]+)\[([a-zA-Z0-9]+:[rwcdm]+(,[a-zA-Z0-9]+:[rwcdm]+)*)\]$/', $acl, $match)){
1283           $module= $match[1];
1284           $aclList= explode(',', $match[2]);
1285         }
1287         // Walk thru prepared ACL by using $module
1288         foreach($aclList as $sAcl) {
1289           $checkAcl= "";
1291           // Category or detailed permission?
1292           if (strpos($module, '/') !== false) {
1293             if (preg_match('/([a-zA-Z0-9]+):([rwcdm]+)/', $sAcl, $m) ) {
1294               $checkAcl= $ui->get_permissions($dn, $module, $m[1]);
1295               $sAcl= $m[2];
1296             } else {
1297               $checkAcl= $ui->get_permissions($dn, $module, '0');
1298             }
1299           } else {
1300             $checkAcl= $ui->get_category_permissions($dn, $module);
1301           }
1303           // Split up remaining part of the acl and check if it we're
1304           // allowed to do something...
1305           $parts= str_split($sAcl);
1306           foreach ($parts as $part) {
1307             if (strpos($checkAcl, $part) === false){
1308               return false;
1309             }
1310           }
1312         }
1313       }
1314     }
1316     return true;
1317   }
1320   function refreshBasesList()
1321   {
1322     global $config;
1323     $ui= get_userinfo();
1325     // Do some array munching to get it user friendly
1326     $ids= $config->idepartments;
1327     $d= $ui->get_module_departments($this->categories);
1328     $k_ids= array_keys($ids);
1329     $deps= array_intersect($d,$k_ids);
1331     // Fill internal bases list
1332     $this->bases= array();
1333     foreach($k_ids as $department){
1334       $this->bases[$department] = $ids[$department];
1335     }
1337     // Populate base selector if already present
1338     if ($this->baseSelector && $this->baseMode) {
1339       $this->baseSelector->setBases($this->bases);
1340       $this->baseSelector->update(TRUE);
1341     }
1342   }
1345   function getDepartments()
1346   {
1347     $departments= array();
1348     $ui= get_userinfo();
1350     // Get list of supported department types
1351     $types = departmentManagement::get_support_departments();
1353     // Load departments allowed by ACL
1354     $validDepartments = $ui->get_module_departments($this->categories);
1356     // Build filter and look in the LDAP for possible sub departments
1357     // of current base
1358     $filter= "(&(objectClass=gosaDepartment)(|";
1359     $attrs= array("description", "objectClass");
1360     foreach($types as $name => $data){
1361       $filter.= "(objectClass=".$data['OC'].")";
1362       $attrs[]= $data['ATTR'];
1363     }
1364     $filter.= "))";
1365     $res= get_list($filter, $this->categories, $this->base, $attrs, GL_NONE);
1367     // Analyze list of departments
1368     foreach ($res as $department) {
1369       if (!in_array($department['dn'], $validDepartments)) {
1370         continue;
1371       }
1373       // Add the attribute where we use for sorting
1374       $oc= null;
1375       foreach(array_keys($types) as $type) {
1376         if (in_array($type, $department['objectClass'])) {
1377           $oc= $type;
1378           break;
1379         }
1380       }
1381       $department['sort-attribute']= $types[$oc]['ATTR'];
1383       // Move to the result list
1384       $departments[]= $department;
1385     }
1387     return $departments;
1388   }
1391   function renderCopyPasteMenu($separator, $copy= true, $cut= true)
1392   {
1393     // We can only provide information if we've got a copypaste handler
1394     // instance
1395     if(!(isset($this->copyPasteHandler) && is_object($this->copyPasteHandler))){
1396       return "";
1397     }
1399     // Presets
1400     $result= "";
1401     $read= $paste= false;
1402     $ui= get_userinfo();
1404     // Switch flags to on if there's at least one category which allows read/paste
1405     foreach($this->categories as $category){
1406       $read= $read || preg_match('/r/', $ui->get_category_permissions($this->base, $category));
1407       $paste= $paste || $ui->is_pasteable($this->base, $category) == 1;
1408     }
1411     // Draw entries that allow copy and cut
1412     if($read){
1414       // Copy entry
1415       if($copy){
1416         $result.= "<li$separator><a href='#' onClick='\$(\"act\").value= \"copy\";\$(\"exec_act\").click();'>".image('images/lists/copy.png')."&nbsp;"._("Copy")."</a></li>";
1417         $separator= "";
1418       }
1420       // Cut entry
1421       if($cut){
1422         $result.= "<li$separator><a href='#' onClick='\$(\"act\").value= \"cut\";\$(\"exec_act\").click();'>".image("images/lists/cut.png")."&nbsp;"._("Cut")."</a></li>";
1423         $separator= "";
1424       }
1425     }
1427     // Draw entries that allow pasting entries
1428     if($paste){
1429       if($this->copyPasteHandler->entries_queued()){
1430         $result.= "<li$separator><a href='#' onClick='\$(\"act\").value= \"paste\";\$(\"exec_act\").click();'>".image("images/lists/paste.png")."&nbsp;"._("Paste")."</a></li>";
1431       }else{
1432         $result.= "<li$separator><a href='#'>".image('images/lists/paste-grey.png')."&nbsp;"._("Paste")."</a></li>";
1433       }
1434     }
1435     
1436     return($result);
1437   }
1440   function renderCopyPasteActions($row, $dn, $category, $class, $copy= true, $cut= true)
1441   {
1442     // We can only provide information if we've got a copypaste handler
1443     // instance
1444     if(!(isset($this->copyPasteHandler) && is_object($this->copyPasteHandler))){
1445       return "";
1446     }
1448     // Presets
1449     $ui = get_userinfo();
1450     $result = "";
1452     // Render cut entries
1453     if($cut){
1454       if($ui->is_cutable($dn, $category, $class)){
1455         $result.= image('images/lists/cut.png', "listing_cut_$row", _("Cut this entry"));
1456       }else{
1457         $result.= image('images/empty.png');
1458       }
1459     }
1461     // Render copy entries
1462     if($copy){
1463       if($ui->is_copyable($dn, $category, $class)){
1464         $result.= image('images/lists/copy.png', "listing_copy_$row", _("Copy this entry"));
1465       }else{
1466         $result.= image('images/empty.png');
1467       }
1468     }
1470     return($result);
1471   }
1474   function renderSnapshotMenu($separator)
1475   {
1476     // We can only provide information if we've got a snapshot handler
1477     // instance
1478     if(!(isset($this->snapshotHandler) && is_object($this->snapshotHandler))){
1479       return "";
1480     }
1482     // Presets
1483     $result = "";
1484     $ui = get_userinfo();
1486     if($this->snapshotHandler->enabled() && $ui->allow_snapshot_restore($this->base, $this->categories)){
1488       // Check if there is something to restore
1489       $restore= false;
1490       foreach($this->snapshotHandler->getSnapshotBases() as $base){
1491         $restore= $restore || count($this->snapshotHandler->getDeletedSnapshots($base)) > 0;
1492       }
1494       // Draw icons according to the restore flag
1495       if($restore){
1496         $result.= "<li$separator><a href='#' onClick='\$(\"act\").value= \"restore\";\$(\"exec_act\").click();'>".image('images/lists/restore.png')."&nbsp;"._("Restore snapshots")."</a></li>";
1497       }else{
1498         $result.= "<li$separator><a href='#'>".image('images/lists/restore-grey.png')."&nbsp;"._("Restore snapshots")."</a></li>";
1499       }
1500     }
1502     return($result);
1503   }
1506   function renderExporterMenu($separator)
1507   {
1508     // Presets
1509     $result = "";
1511     // Draw entries
1512     $result.= "<li$separator><a href='#'>".image('images/lists/export.png')."&nbsp;"._("Export list")."&nbsp;".image("images/forward-arrow.png")."</a><ul class='level3'>";
1514     // Export CVS as build in exporter
1515     foreach ($this->exporter as $action => $exporter) {
1516       $result.= "<li><a href='#' onClick='\$(\"act\").value= \"$action\";\$(\"exec_act\").click();'>".image($exporter['image'])."&nbsp;".$exporter['label']."</a></li>";
1517     }
1519     // Finalize list
1520     $result.= "</ul></li>";
1522     return($result);
1523   }
1526   function renderSnapshotActions($row, $dn, $category, $class, $copy= true, $cut= true)
1527   {
1528     // We can only provide information if we've got a snapshot handler
1529     // instance
1530     if(!(isset($this->snapshotHandler) && is_object($this->snapshotHandler))){
1531       return "";
1532     }
1534     // Presets
1535     $result= "";
1536     $ui = get_userinfo();
1538     // Only act if enabled here
1539     if($this->snapshotHandler->enabled()){
1541       // Draw restore button
1542       if ($ui->allow_snapshot_restore($dn, $category)){
1544         // Do we have snapshots for this dn?
1545         if($this->snapshotHandler->hasSnapshots($dn)){
1546           $result.= image('images/lists/restore.png', "listing_restore_$row", _("Restore snapshot"));
1547         } else {
1548           $result.= image('images/lists/restore-grey.png');
1549         }
1550       }
1552       // Draw snapshot button
1553       if($ui->allow_snapshot_create($dn, $category)){
1554           $result.= image('images/snapshot.png', "listing_snapshot_$row", _("Create new snapshot for this object"));
1555       }else{
1556           $result.= image('images/empty.png');
1557       }
1558     }
1560     return($result);
1561   }
1564   function renderDaemonMenu($separator)
1565   {
1566     $result= "";
1568     // If there is a daemon registered, draw the menu entries
1569     if(class_available("DaemonEvent")){
1570       $events= DaemonEvent::get_event_types_by_category($this->categories);
1571       if(isset($events['BY_CLASS']) && count($events['BY_CLASS'])){
1572         foreach($events['BY_CLASS'] as $name => $event){
1573           $result.= "<li$separator><a href='#' onClick='\$(\"act\").value=\"$name\";\$(\"exec_act\").click();'>".$event['MenuImage']."&nbsp;".$event['s_Menu_Name']."</a></li>";
1574           $separator= "";
1575         }
1576       }
1577     }
1579     return $result;
1580   }
1583   function getEntry($dn)
1584   {
1585     $dn = LDAP::fix($dn);
1586     foreach ($this->entries as $entry) {
1587       if (isset($entry['dn']) && strcasecmp($dn, $entry['dn']) == 0){
1588         return $entry;
1589       }
1590     }
1591     return null;
1592   }
1595   function getEntries()
1596   {
1597     return $this->entries;
1598   }
1601   function getType($dn)
1602   {
1603     $dn = LDAP::fix($dn);
1604     if (isset($this->objectDnMapping[$dn])) {
1605       return $this->objectDnMapping[$dn];
1606     }
1607     return null;
1608   }
1612 ?>