Code

Added row labeling
[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 label to objecttype icon?
405        if (preg_match("/<objectType:([^:]+):(.*)\/>/i", $entry['_rendered'], $matches)){
406            if (preg_match("/<rowLabel:([a-z0-9_-]*)\/>/i", $entry['_rendered'], $m)) {
407                $objectType= image($matches[1]."[".$m[1]."]", null, LDAP::fix(base64_decode($matches[2])));
408            } else {
409                $objectType= image($matches[1], null, LDAP::fix(base64_decode($matches[2])));
410            }
411            $entry['_rendered']= preg_replace("/<objectType[^>]+>/", $objectType, $entry['_rendered']);
412       }
414       // Apply custom class to row?
415       if (preg_match("/<rowClass:([a-z0-9_-]*)\/>/i", $entry['_rendered'], $matches)) {
416         $result.="<tr class='".$matches[1]."'>\n";
417         $result.= preg_replace("/<rowClass[^>]+>/", '', $entry['_rendered']);
418       } else {
419         $result.="<tr>\n";
420         $result.= $entry['_rendered'];
421       }
423       $result.="</tr>\n";
424       $alt++;
425     }
427     // Need to fill the list if it's not full (nobody knows why this is 22 ;-))
428     $emptyListStyle= (count($this->entries) + (($this->useSpan && count($this->entries))?$deps:0) == 0)?"border:0;":"";
429     if ((count($this->entries) + $deps) < 22) {
430       $result.= "<tr>";
431       for ($i= 0; $i<$this->numColumns; $i++) {
432         if ($i == 0) {
433           $result.= "<td class='list1nohighlight' style='$emptyListStyle height:100%;'>&nbsp;</td>";
434           continue;
435         }
436         if ($i != $this->numColumns-1) {
437           $result.= "<td class='list1nohighlight' style='$emptyListStyle'>&nbsp;</td>";
438         } else {
439           $result.= "<td class='list1nohighlight' style='border-right:0;$emptyListStyle'>&nbsp;</td>";
440         }
441       }
443       $result.= "</tr>";
444     }
446     // Close list body
447     $result.= "</tbody></table></div>";
449     // Add the footer if requested
450     if ($this->showFooter) {
451       $result.= "<div class='nlistFooter'><div style='padding:3px'>";
453       foreach ($this->objectTypes as $objectType) {
454         if (isset($this->objectTypeCount[$objectType['label']])) {
455           $label= _($objectType['label']);
456           $result.= image($objectType['image'], null, $label)."&nbsp;".$this->objectTypeCount[$objectType['label']]."&nbsp;&nbsp;";
457         }
458       }
460       $result.= "</div></div>";
461     }
463     // Close list
464     $result.= $switch?"<input type='hidden' id='list_workaround'>":"";
466     // Add scroll positioner
467     $result.= '<script type="text/javascript" language="javascript">';
468     $result.= '$("t_nscrollbody").scrollTop= '.$this->scrollPosition.';';
469     $result.= 'var box = $("t_nscrollbody").onscroll= function() {$("position_'.$this->pid.'").value= this.scrollTop;}';
470     $result.= '</script>';
472     $smarty= get_smarty();
474     $smarty->assign("FILTER", $this->filter->render());
475     $smarty->assign("SIZELIMIT", print_sizelimit_warning());
476     $smarty->assign("LIST", $result);
478     // Assign navigation elements
479     $nav= $this->renderNavigation();
480     foreach ($nav as $key => $html) {
481       $smarty->assign($key, $html);
482     }
484     // Assign action menu / base
485     $smarty->assign("HEADLINE", $this->headline);
486     $smarty->assign("ACTIONS", $this->renderActionMenu());
487     $smarty->assign("BASE", $this->renderBase());
489     // Assign separator
490     $smarty->assign("SEPARATOR", "<img src='images/lists/seperator.png' alt='-' align='middle' height='16' width='1' class='center'>");
492     // Assign summary
493     $smarty->assign("HEADLINE", $this->headline);
495     // Try to load template from plugin the folder first...
496     $file = get_template_path($this->xmlData['definition']['template'], true);
498     // ... if this fails, try to load the file from the theme folder.
499     if(!file_exists($file)){
500       $file = get_template_path($this->xmlData['definition']['template']);
501     }
503     return ($smarty->fetch($file));
504   }
507   function update()
508   {
509     global $config;
510     $ui= get_userinfo();
512     // Take care of base selector
513     if ($this->baseMode) {
514       $this->baseSelector->update();
516       // Check if a wrong base was supplied
517       if(!$this->baseSelector->checkLastBaseUpdate()){
518          msg_dialog::display(_("Error"), msgPool::check_base(), ERROR_DIALOG);
519       }
520     }
522     // Save base
523     $refresh= false;
524     if ($this->baseMode) {
525       $this->base= $this->baseSelector->getBase();
526       session::global_set("CurrentMainBase", $this->base);
527       $refresh= true;
528     }
531     // Reset object counter / DN mapping
532     $this->objectTypeCount= array();
533     $this->objectDnMapping= array();
535     // Do not do anything if this is not our PID
536     if($refresh || !(isset($_REQUEST['PID']) && $_REQUEST['PID'] != $this->pid)) {
538       // Save position if set
539       if (isset($_POST['position_'.$this->pid]) && is_numeric($_POST['position_'.$this->pid])) {
540         $this->scrollPosition= $_POST['position_'.$this->pid];
541       }
543       // Override the base if we got a message from the browser navigation
544       if ($this->departmentBrowser && isset($_GET['act'])) {
545         if (preg_match('/^department_([0-9]+)$/', validate($_GET['act']), $match)){
546           if (isset($this->departments[$match[1]])){
547             $this->base= $this->departments[$match[1]]['dn'];
548             if ($this->baseMode) {
549               $this->baseSelector->setBase($this->base);
550             }
551             session::global_set("CurrentMainBase", $this->base);
552           }
553         }
554       }
556       // Filter POST with "act" attributes -> posted from action menu
557       if (isset($_POST['exec_act']) && $_POST['act'] != '') {
558         if (preg_match('/^export.*$/', $_POST['act']) && isset($this->exporter[$_POST['act']])) {
559           $exporter= $this->exporter[$_POST['act']];
560           $userinfo= ", "._("created by")." ".$ui->cn." - ".strftime('%A, %d. %B %Y, %H:%M:%S');
561           $entryIterator= new listingSortIterator($this->entries, $this->sortDirection[$this->sortColumn], "_sort".$this->sortColumn, $this->sortType);
562           $sortedEntries= array();
563           foreach ($entryIterator as $entry){
564             $sortedEntries[]= $entry;
565           }
566           $instance= new $exporter['class']($this->headline.$userinfo, $this->plainHeader, $sortedEntries, $this->exportColumns);
567           $type= call_user_func(array($exporter['class'], "getInfo"));
568           $type= $type[$_POST['act']];
569           send_binary_content($instance->query(), $type['filename'], $type= $type['mime']);
570         }
571       }
573       // Filter GET with "act" attributes
574       if (isset($_GET['act'])) {
575         $key= validate($_GET['act']);
576         if (preg_match('/^SORT_([0-9]+)$/', $key, $match)) {
577           // Switch to new column or invert search order?
578           $column= $match[1];
579           if ($this->sortColumn != $column) {
580             $this->sortColumn= $column;
581           } else {
582             $this->sortDirection[$column]= !$this->sortDirection[$column];
583           }
585           // Allow header to update itself according to the new sort settings
586           $this->renderHeader();
587         }
588       }
590       // Override base if we got signals from the navigation elements
591       $action= "";
592       foreach ($_POST as $key => $value) {
593         if (preg_match('/^(ROOT|BACK|HOME)(_x)?$/', $key, $match)) {
594           $action= $match[1];
595           break;
596         }
597       }
599       // Navigation handling
600       if ($action == 'ROOT') {
601         $deps= $ui->get_module_departments($this->categories);
602         $this->base= $deps[0];
603         $this->baseSelector->setBase($this->base);
604         session::global_set("CurrentMainBase", $this->base);
605       }
606       if ($action == 'BACK') {
607         $deps= $ui->get_module_departments($this->categories);
608         $base= preg_replace("/^[^,]+,/", "", $this->base);
609         if(in_array_ics($base, $deps)){
610           $this->base= $base;
611           $this->baseSelector->setBase($this->base);
612           session::global_set("CurrentMainBase", $this->base);
613         }
614       }
615       if ($action == 'HOME') {
616         $ui= get_userinfo();
617         $this->base= get_base_from_people($ui->dn);
618         $this->baseSelector->setBase($this->base);
619         session::global_set("CurrentMainBase", $this->base);
620       }
621     }
623     // Reload departments
624     if ($this->departmentBrowser){
625       $this->departments= $this->getDepartments();
626     }
628     // Update filter and refresh entries
629     $this->filter->setBase($this->base);
630     $this->entries= $this->filter->query();
632     // Fix filter if querie returns NULL
633     if ($this->entries == null) {
634       $this->entries= array();
635     }
636   }
639   function setBase($base)
640   {
641     $this->base= $base;
642     if ($this->baseMode) {
643       $this->baseSelector->setBase($this->base);
644     }
645   }
648   function getBase()
649   {
650     return $this->base;
651   }
654   function parseLayout($layout)
655   {
656     $result= array();
657     $layout= preg_replace("/^\|/", "", $layout);
658     $layout= preg_replace("/\|$/", "", $layout);
659     $cols= explode("|", $layout);
661     foreach ($cols as $index => $config) {
662       if ($config != "") {
663         $res= "";
664         $components= explode(';', $config);
665         foreach ($components as $part) {
666           if (preg_match("/^r$/", $part)) {
667             $res.= "text-align:right;";
668             continue;
669           }
670           if (preg_match("/^l$/", $part)) {
671             $res.= "text-align:left;";
672             continue;
673           }
674           if (preg_match("/^c$/", $part)) {
675             $res.= "text-align:center;";
676             continue;
677           }
678           if (preg_match("/^[0-9]+(|px|%)$/", $part)) {
679             $res.= "width:$part;min-width:$part;";
680             continue;
681           }
682         }
684         // Add minimum width for scalable columns
685         if (!preg_match('/width:/', $res)){
686           $res.= "min-width:200px;";
687         }
689         $result[$index]= " style='$res'";
690       } else {
691         $result[$index]= " style='min-width:100px;'";
692       }
693     }
695     // Save number of columns for later use
696     $this->numColumns= count($cols);
698     // Add no border to the last column
699     $result[$this->numColumns-1]= preg_replace("/'$/", "border-right:0;'", $result[$this->numColumns-1]);
701     return $result;
702   }
705   function renderCell($data, $config, $row)
706   {
707     // Replace flat attributes in data string
708     for ($i= 0; $i<$config['count']; $i++) {
709       $attr= $config[$i];
710       $value= "";
711       if (is_array($config[$attr])) {
712         $value= $config[$attr][0];
713       } else {
714         $value= $config[$attr];
715       }
716       $data= preg_replace("/%\{$attr\}/", $value, $data);
717     }
719     // Watch out for filters and prepare to execute them
720     $data= $this->processElementFilter($data, $config, $row);
722     // Replace all non replaced %{...} instances because they
723     // are non resolved attributes or filters
724     $data= preg_replace('/%{[^}]+}/', '&nbsp;', $data);
726     return $data;
727   }
730   function renderBase()
731   {
732     if (!$this->baseMode) {
733       return;
734     }
736     return $this->baseSelector->render();
737   }
740   function processElementFilter($data, $config, $row)
741   {
742     preg_match_all("/%\{filter:([^(]+)\((.*)\)\}/", $data, $matches, PREG_SET_ORDER);
744     foreach ($matches as $match) {
745       $cl= "";
746       $method= "";
747       if (preg_match('/::/', $match[1])) {
748         $cl= preg_replace('/::.*$/', '', $match[1]);
749         $method= preg_replace('/^.*::/', '', $match[1]);
750       } else {
751         if (!isset($this->filters[$match[1]])) {
752           continue;
753         }
754         $cl= preg_replace('/::.*$/', '', $this->filters[$match[1]]);
755         $method= preg_replace('/^.*::/', '', $this->filters[$match[1]]);
756       }
758       // Prepare params for function call
759       $params= array();
760       preg_match_all('/"[^"]+"|[^,]+/', $match[2], $parts);
761       foreach ($parts[0] as $param) {
763         // Row is replaced by the row number
764         if ($param == "row") {
765           $params[]= $row;
766           continue;
767         }
769         // pid is replaced by the current PID
770         if ($param == "pid") {
771           $params[]= $this->pid;
772           continue;
773         }
775         // base is replaced by the current base
776         if ($param == "base") {
777           $params[]= $this->getBase();
778           continue;
779         }
781         // Fixie with "" is passed directly
782         if (preg_match('/^".*"$/', $param)){
783           $params[]= preg_replace('/"/', '', $param);
784           continue;
785         }
787         // Move dn if needed
788         if ($param == "dn") {
789           $params[]= LDAP::fix($config["dn"]);
790           continue;
791         }
793         // LDAP variables get replaced by their objects
794         for ($i= 0; $i<$config['count']; $i++) {
795           if ($param == $config[$i]) {
796             $values= $config[$config[$i]];
797             if (is_array($values)){
798               unset($values['count']);
799             }
800             $params[]= $values;
801             break;
802           }
803         }
804       }
806       // Replace information
807       if ($cl == "listing") {
808         // Non static call - seems to result in errors
809         $data= @preg_replace('/'.preg_quote($match[0]).'/', call_user_func_array(array($this, "$method"), $params), $data);
810       } else {
811         // Static call
812         $data= preg_replace('/'.preg_quote($match[0]).'/', call_user_func_array(array($cl, $method), $params), $data);
813       }
814     }
816     return $data;
817   }
820   function getObjectType($types, $classes)
821   {
822     // Walk thru types and see if there's something matching
823     foreach ($types as $objectType) {
824       $ocs= $objectType['objectClass'];
825       if (!is_array($ocs)){
826         $ocs= array($ocs);
827       }
829       $found= true;
830       foreach ($ocs as $oc){
831         if (preg_match('/^!(.*)$/', $oc, $match)) {
832           $oc= $match[1];
833           if (in_array($oc, $classes)) {
834             $found= false;
835           }
836         } else {
837           if (!in_array($oc, $classes)) {
838             $found= false;
839           }
840         }
841       }
843       if ($found) {
844         return $objectType;
845       }
846     }
848     return null;
849   }
852   function filterObjectType($dn, $classes)
853   {
854     // Walk thru classes and return on first match
855     $result= "&nbsp;";
857     $objectType= $this->getObjectType($this->objectTypes, $classes);
858     if ($objectType) {
859       $this->objectDnMapping[$dn]= $objectType["objectClass"];
860       $result= "<objectType:".$objectType["image"].":".base64_encode(LDAP::fix($dn))."/>";
861       if (!isset($this->objectTypeCount[$objectType['label']])) {
862         $this->objectTypeCount[$objectType['label']]= 0;
863       }
864       $this->objectTypeCount[$objectType['label']]++;
865     }
867     return $result;
868   }
871   function filterActions($dn, $row, $classes)
872   {
873     // Do nothing if there's no menu defined
874     if (!isset($this->xmlData['actiontriggers']['action'])) {
875       return "&nbsp;";
876     }
878     // Go thru all actions
879     $result= "";
880     $actions= $this->xmlData['actiontriggers']['action'];
882     // Ensure we've a valid actions array, if there is only one action in the actiontriggers col
883     //  then we've to create a valid array here.
884     if(isset($actions['name'])) $actions = array($actions);
886     foreach($actions as $action) {
887       // Skip the entry completely if there's no permission to execute it
888       if (!$this->hasActionPermission($action, $dn, $classes)) {
889         $result.= image('images/empty.png');
890         continue;
891       }
893       // Skip entry if the pseudo filter does not fit
894       if (isset($action['filter']) && preg_match('/^[a-z0-9_]+!?=[a-z0-9_]+$/i', $action['filter'])) {
895         list($fa, $fv)= explode('=', $action['filter']);
896         if (preg_match('/^(.*)!$/', $fa, $m)){
897           $fa= $m[1];
898           if (isset($this->entries[$row][$fa]) && $this->entries[$row][$fa][0] == $fv) {
899             $result.= image('images/empty.png');
900             continue;
901           }
902         } else {
903           if (!isset($this->entries[$row][$fa]) && !$this->entries[$row][$fa][0] == $fv) {
904             $result.= image('images/empty.png');
905             continue;
906           }
907         }
908       }
911       // If there's an objectclass definition and we don't have it
912       // add an empty picture here.
913       if (isset($action['objectclass'])){
914         $objectclass= $action['objectclass'];
915         if (preg_match('/^!(.*)$/', $objectclass, $m)){
916           $objectclass= $m[1];
917           if(in_array($objectclass, $classes)) {
918             $result.= image('images/empty.png');
919             continue;
920           }
921         } elseif (is_string($objectclass)) {
922           if(!in_array($objectclass, $classes)) {
923             $result.= image('images/empty.png');
924             continue;
925           }
926         } elseif (is_array($objectclass)) {
927           if(count(array_intersect($objectclass, $classes)) != count($objectclass)){
928             $result.= image('images/empty.png');
929             continue;
930           }
931         }
932       }
934       // Render normal entries as usual
935       if ($action['type'] == "entry") {
936         $label= $this->processElementFilter($action['label'], $this->entries[$row], $row);
937         $image= $this->processElementFilter($action['image'], $this->entries[$row], $row);
938         $result.= image($image, "listing_".$action['name']."_$row", $label);
939       }
941       // Handle special types
942       if ($action['type'] == "copypaste" || $action['type'] == "snapshot") {
944         $objectType= $this->getObjectType($this->objectTypes, $this->entries[$row]['objectClass']);
945         $category= $class= null;
946         if ($objectType) {
947           $category= $objectType['category'];
948           $class= $objectType['class'];
949         }
951         if ($action['type'] == "copypaste") {
952           $copy = !isset($action['copy']) || $action['copy'] == "true";
953           $cut = !isset($action['cut']) || $action['cut'] == "true";
954           $result.= $this->renderCopyPasteActions($row, $this->entries[$row]['dn'], $category, $class,$copy,$cut);
955         } else {
956           $result.= $this->renderSnapshotActions($row, $this->entries[$row]['dn'], $category, $class);
957         }
958       }
959     }
961     return $result;
962   }
965   function filterDepartmentLink($row, $dn, $description)
966   {
967     $attr= $this->departments[$row]['sort-attribute'];
968     $name= $this->departments[$row][$attr];
969     if (is_array($name)){
970       $name= $name[0];
971     }
972     $result= sprintf("%s [%s]", $name, $description[0]);
973     return("<a href='?plug=".$_GET['plug']."&amp;PID=$this->pid&amp;act=department_$row' title='$dn'>$result</a>");
974   }
977   function filterLink()
978   {
979     $result= "&nbsp;";
981     $row= func_get_arg(0);
982     $pid= $this->pid;
983     $dn= LDAP::fix(func_get_arg(1));
984     $params= array(func_get_arg(2));
986     // Collect sprintf params
987     for ($i = 3;$i < func_num_args();$i++) {
988       $val= func_get_arg($i);
989       if (is_array($val)){
990         $params[]= $val[0];
991         continue;
992       }
993       $params[]= $val;
994     }
996     $result= "&nbsp;";
997     $trans= call_user_func_array("sprintf", $params);
998     if ($trans != "") {
999       return("<a href='?plug=".$_GET['plug']."&amp;PID=$pid&amp;act=listing_edit_$row' title='$dn'>$trans</a>");
1000     }
1002     return $result;
1003   }
1006   function renderNavigation()
1007   {
1008     $result= array();
1009     $enableBack = true;
1010     $enableRoot = true;
1011     $enableHome = true;
1013     $ui = get_userinfo();
1015     /* Check if base = first available base */
1016     $deps = $ui->get_module_departments($this->categories);
1018     if(!count($deps) || $deps[0] == $this->filter->base){
1019       $enableBack = false;
1020       $enableRoot = false;
1021     }
1023     $listhead ="";
1025     /* Check if we are in users home  department */
1026     if(!count($deps) || $this->filter->base == get_base_from_people($ui->dn)){
1027       $enableHome = false;
1028     }
1030     /* Draw root button */
1031     if($enableRoot){
1032       $result["ROOT"]= image('images/lists/root.png', 'ROOT', _("Root"));
1033     }else{
1034       $result["ROOT"]= image('images/lists/root-grey.png', null, _("Root"));
1035     }
1037     /* Draw back button */
1038     if($enableBack){
1039       $result["BACK"]= image('images/lists/back.png', 'BACK', _("Go to preceding level"));
1040     }else{
1041       $result["BACK"]= image('images/lists/back-grey.png', null, _("Go to preceding level"));
1042     }
1044     /* Draw home button */
1045    /* Draw home button */
1046     if($enableHome){
1047       $result["HOME"]= image('images/lists/home.png', 'HOME', _("Go to current users level"));
1048     }else{
1049       $result["HOME"]= image('images/lists/home-grey.png', null, _("Go to current users level"));
1050     }
1053     /* Draw reload button, this button is enabled everytime */
1054     $result["RELOAD"]= image('images/lists/reload.png', 'REFRESH', _("Reload list"));
1056     return ($result);
1057   }
1060   function getAction()
1061   {
1062     // Do not do anything if this is not our PID, or there's even no PID available...
1063     if(!isset($_REQUEST['PID']) || $_REQUEST['PID'] != $this->pid) {
1064       return;
1065     }
1067     // Save position if set
1068     if (isset($_POST['position_'.$this->pid]) && is_numeric($_POST['position_'.$this->pid])) {
1069       $this->scrollPosition= $_POST['position_'.$this->pid];
1070     }
1072     $result= array("targets" => array(), "action" => "");
1074     // Filter GET with "act" attributes
1075     if (isset($_GET['act'])) {
1076       $key= validate($_GET['act']);
1077       $target= preg_replace('/^listing_[a-zA-Z_]+_([0-9]+)$/', '$1', $key);
1078       if (isset($this->entries[$target]['dn'])) {
1079         $result['action']= preg_replace('/^listing_([a-zA-Z_]+)_[0-9]+$/', '$1', $key);
1080         $result['targets'][]= $this->entries[$target]['dn'];
1081       }
1083       // Drop targets if empty
1084       if (count($result['targets']) == 0) {
1085         unset($result['targets']);
1086       }
1087       return $result;
1088     }
1090     // Get single selection (radio box)
1091     if($this->singleSelect && isset($_POST['listing_radio_selected'])){
1092         $entry = $_POST['listing_radio_selected'];
1093         $result['targets']= array($this->entries[$entry]['dn']);
1094     }
1096     // Filter POST with "listing_" attributes
1097     foreach ($_POST as $key => $prop) {
1099       // Capture selections
1100       if (preg_match('/^listing_selected_[0-9]+$/', $key)) {
1101         $target= preg_replace('/^listing_selected_([0-9]+)$/', '$1', $key);
1102         if (isset($this->entries[$target]['dn'])) {
1103           $result['targets'][]= $this->entries[$target]['dn'];
1104         }
1105         continue;
1106       }
1108       // Capture action with target - this is a one shot
1109       if (preg_match('/^listing_[a-zA-Z_]+_[0-9]+(|_x)$/', $key)) {
1110         $target= preg_replace('/^listing_[a-zA-Z_]+_([0-9]+)(|_x)$/', '$1', $key);
1111         if (isset($this->entries[$target]['dn'])) {
1112           $result['action']= preg_replace('/^listing_([a-zA-Z_]+)_[0-9]+(|_x)$/', '$1', $key);
1113           $result['targets']= array($this->entries[$target]['dn']);
1114         }
1115         break;
1116       }
1118       // Capture action without target
1119       if (preg_match('/^listing_[a-zA-Z_]+(|_x)$/', $key)) {
1120         $result['action']= preg_replace('/^listing_([a-zA-Z_]+)(|_x)$/', '$1', $key);
1121         continue;
1122       }
1123     }
1125     // Filter POST with "act" attributes -> posted from action menu
1126     if (isset($_POST['act']) && $_POST['act'] != '') {
1127       if (!preg_match('/^export.*$/', $_POST['act'])){
1128         $result['action']= validate($_POST['act']);
1129       }
1130     }
1132     // Drop targets if empty
1133     if (count($result['targets']) == 0) {
1134       unset($result['targets']);
1135     }
1136     return $result;
1137   }
1140   function renderActionMenu()
1141   {
1142     $result= "<input type='hidden' name='act' id='act' value=''><div style='display:none'><input type='submit' name='exec_act' id='exec_act' value=''></div>";
1144     // Don't send anything if the menu is not defined
1145     if (!isset($this->xmlData['actionmenu']['action'])){
1146       return $result;
1147     }
1149     // Array?
1150     if (isset($this->xmlData['actionmenu']['action']['type'])){
1151       $this->xmlData['actionmenu']['action']= array($this->xmlData['actionmenu']['action']);
1152     }
1154     // Load shortcut
1155     $actions= &$this->xmlData['actionmenu']['action'];
1156     $result.= "<ul class='level1' id='root'><li><a href='#'>"._("Actions")."&nbsp;".image("images/lists/sort-down.png")."</a>";
1158     // Build ul/li list
1159     $result.= $this->recurseActions($actions);
1161     return "<div id='pulldown'>".$result."</li></ul></div>";
1162   }
1165   function recurseActions($actions)
1166   {
1167     global $class_mapping;
1168     static $level= 2;
1169     $result= "<ul class='level$level'>";
1170     $separator= "";
1172     foreach ($actions as $action) {
1174       // Skip the entry completely if there's no permission to execute it
1175       if (!$this->hasActionPermission($action, $this->filter->base)) {
1176         continue;
1177       }
1179       // Skip entry if there're missing dependencies
1180       if (isset($action['depends'])) {
1181         $deps= is_array($action['depends'])?$action['depends']:array($action['depends']);
1182         foreach($deps as $clazz) {
1183           if (!isset($class_mapping[$clazz])){
1184             continue 2;
1185           }
1186         }
1187       }
1189       // Fill image if set
1190       $img= "";
1191       if (isset($action['image'])){
1192         $img= image($action['image'])."&nbsp;";
1193       }
1195       if ($action['type'] == "separator"){
1196         $separator= " style='border-top:1px solid #AAA' ";
1197         continue;
1198       }
1200       // Dive into subs
1201       if ($action['type'] == "sub" && isset($action['action'])) {
1202         $level++;
1203         if (isset($action['label'])){
1204           $result.= "<li$separator><a href='#'>$img"._($action['label'])."&nbsp;".image('images/forward-arrow.png')."</a>";
1205         }
1207         // Ensure we've an array of actions, this enables sub menus with only one action.
1208         if(isset($action['action']['type'])){
1209           $action['action'] = array($action['action']);
1210         }
1212         $result.= $this->recurseActions($action['action'])."</li>";
1213         $level--;
1214         $separator= "";
1215         continue;
1216       }
1218       // Render entry elseways
1219       if (isset($action['label'])){
1220         $result.= "<li$separator><a href='#' onClick='\$(\"act\").value= \"".$action['name']."\";\$(\"exec_act\").click();'>$img"._($action['label'])."</a></li>";
1221       }
1223       // Check for special types
1224       switch ($action['type']) {
1225         case 'copypaste':
1226           $cut = !isset($action['cut']) || $action['cut'] != "false";
1227           $copy = !isset($action['copy']) || $action['copy'] != "false";
1228           $result.= $this->renderCopyPasteMenu($separator, $copy , $cut);
1229           break;
1231         case 'snapshot':
1232           $result.= $this->renderSnapshotMenu($separator);
1233           break;
1235         case 'exporter':
1236           $result.= $this->renderExporterMenu($separator);
1237           break;
1239         case 'daemon':
1240           $result.= $this->renderDaemonMenu($separator);
1241           break;
1242       }
1244       $separator= "";
1245     }
1247     $result.= "</ul>";
1248     return $result;
1249   }
1252   function hasActionPermission($action, $dn, $classes= null)
1253   {
1254     $ui= get_userinfo();
1256     if (isset($action['acl'])) {
1257       $acls= $action['acl'];
1258       if (!is_array($acls)) {
1259         $acls= array($acls);
1260       }
1262       // Every ACL has to pass
1263       foreach ($acls as $acl) {
1264         $module= $this->categories;
1265         $aclList= array();
1267         // Replace %acl if available
1268         if ($classes) {
1269           $otype= $this->getObjectType($this->objectTypes, $classes);
1270           $acl= str_replace('%acl', $otype['category']."/".$otype['class'], $acl);
1271         }
1273         // Split for category and plugins if needed
1274         // match for "[rw]" style entries
1275         if (preg_match('/^\[([rwcdm]+)\]$/', $acl, $match)){
1276           $aclList= array($match[1]);
1277         }
1279         // match for "users[rw]" style entries
1280         if (preg_match('/^([a-zA-Z0-9]+)\[([rwcdm]+)\]$/', $acl, $match)){
1281           $module= $match[1];
1282           $aclList= array($match[2]);
1283         }
1285         // match for "users/user[rw]" style entries
1286         if (preg_match('/^([a-zA-Z0-9]+\/[a-zA-Z0-9]+)\[([rwcdm]+)\]$/', $acl, $match)){
1287           $module= $match[1];
1288           $aclList= array($match[2]);
1289         }
1291         // match "users/user[userPassword:rw(,...)*]" style entries
1292         if (preg_match('/^([a-zA-Z0-9]+\/[a-zA-Z0-9]+)\[([a-zA-Z0-9]+:[rwcdm]+(,[a-zA-Z0-9]+:[rwcdm]+)*)\]$/', $acl, $match)){
1293           $module= $match[1];
1294           $aclList= explode(',', $match[2]);
1295         }
1297         // Walk thru prepared ACL by using $module
1298         foreach($aclList as $sAcl) {
1299           $checkAcl= "";
1301           // Category or detailed permission?
1302           if (strpos($module, '/') !== false) {
1303             if (preg_match('/([a-zA-Z0-9]+):([rwcdm]+)/', $sAcl, $m) ) {
1304               $checkAcl= $ui->get_permissions($dn, $module, $m[1]);
1305               $sAcl= $m[2];
1306             } else {
1307               $checkAcl= $ui->get_permissions($dn, $module, '0');
1308             }
1309           } else {
1310             $checkAcl= $ui->get_category_permissions($dn, $module);
1311           }
1313           // Split up remaining part of the acl and check if it we're
1314           // allowed to do something...
1315           $parts= str_split($sAcl);
1316           foreach ($parts as $part) {
1317             if (strpos($checkAcl, $part) === false){
1318               return false;
1319             }
1320           }
1322         }
1323       }
1324     }
1326     return true;
1327   }
1330   function refreshBasesList()
1331   {
1332     global $config;
1333     $ui= get_userinfo();
1335     // Do some array munching to get it user friendly
1336     $ids= $config->idepartments;
1337     $d= $ui->get_module_departments($this->categories);
1338     $k_ids= array_keys($ids);
1339     $deps= array_intersect($d,$k_ids);
1341     // Fill internal bases list
1342     $this->bases= array();
1343     foreach($k_ids as $department){
1344       $this->bases[$department] = $ids[$department];
1345     }
1347     // Populate base selector if already present
1348     if ($this->baseSelector && $this->baseMode) {
1349       $this->baseSelector->setBases($this->bases);
1350       $this->baseSelector->update(TRUE);
1351     }
1352   }
1355   function getDepartments()
1356   {
1357     $departments= array();
1358     $ui= get_userinfo();
1360     // Get list of supported department types
1361     $types = departmentManagement::get_support_departments();
1363     // Load departments allowed by ACL
1364     $validDepartments = $ui->get_module_departments($this->categories);
1366     // Build filter and look in the LDAP for possible sub departments
1367     // of current base
1368     $filter= "(&(objectClass=gosaDepartment)(|";
1369     $attrs= array("description", "objectClass");
1370     foreach($types as $name => $data){
1371       $filter.= "(objectClass=".$data['OC'].")";
1372       $attrs[]= $data['ATTR'];
1373     }
1374     $filter.= "))";
1375     $res= get_list($filter, $this->categories, $this->base, $attrs, GL_NONE);
1377     // Analyze list of departments
1378     foreach ($res as $department) {
1379       if (!in_array($department['dn'], $validDepartments)) {
1380         continue;
1381       }
1383       // Add the attribute where we use for sorting
1384       $oc= null;
1385       foreach(array_keys($types) as $type) {
1386         if (in_array($type, $department['objectClass'])) {
1387           $oc= $type;
1388           break;
1389         }
1390       }
1391       $department['sort-attribute']= $types[$oc]['ATTR'];
1393       // Move to the result list
1394       $departments[]= $department;
1395     }
1397     return $departments;
1398   }
1401   function renderCopyPasteMenu($separator, $copy= true, $cut= true)
1402   {
1403     // We can only provide information if we've got a copypaste handler
1404     // instance
1405     if(!(isset($this->copyPasteHandler) && is_object($this->copyPasteHandler))){
1406       return "";
1407     }
1409     // Presets
1410     $result= "";
1411     $read= $paste= false;
1412     $ui= get_userinfo();
1414     // Switch flags to on if there's at least one category which allows read/paste
1415     foreach($this->categories as $category){
1416       $read= $read || preg_match('/r/', $ui->get_category_permissions($this->base, $category));
1417       $paste= $paste || $ui->is_pasteable($this->base, $category) == 1;
1418     }
1421     // Draw entries that allow copy and cut
1422     if($read){
1424       // Copy entry
1425       if($copy){
1426         $result.= "<li$separator><a href='#' onClick='\$(\"act\").value= \"copy\";\$(\"exec_act\").click();'>".image('images/lists/copy.png')."&nbsp;"._("Copy")."</a></li>";
1427         $separator= "";
1428       }
1430       // Cut entry
1431       if($cut){
1432         $result.= "<li$separator><a href='#' onClick='\$(\"act\").value= \"cut\";\$(\"exec_act\").click();'>".image("images/lists/cut.png")."&nbsp;"._("Cut")."</a></li>";
1433         $separator= "";
1434       }
1435     }
1437     // Draw entries that allow pasting entries
1438     if($paste){
1439       if($this->copyPasteHandler->entries_queued()){
1440         $result.= "<li$separator><a href='#' onClick='\$(\"act\").value= \"paste\";\$(\"exec_act\").click();'>".image("images/lists/paste.png")."&nbsp;"._("Paste")."</a></li>";
1441       }else{
1442         $result.= "<li$separator><a href='#'>".image('images/lists/paste-grey.png')."&nbsp;"._("Paste")."</a></li>";
1443       }
1444     }
1445     
1446     return($result);
1447   }
1450   function renderCopyPasteActions($row, $dn, $category, $class, $copy= true, $cut= true)
1451   {
1452     // We can only provide information if we've got a copypaste handler
1453     // instance
1454     if(!(isset($this->copyPasteHandler) && is_object($this->copyPasteHandler))){
1455       return "";
1456     }
1458     // Presets
1459     $ui = get_userinfo();
1460     $result = "";
1462     // Render cut entries
1463     if($cut){
1464       if($ui->is_cutable($dn, $category, $class)){
1465         $result.= image('images/lists/cut.png', "listing_cut_$row", _("Cut this entry"));
1466       }else{
1467         $result.= image('images/empty.png');
1468       }
1469     }
1471     // Render copy entries
1472     if($copy){
1473       if($ui->is_copyable($dn, $category, $class)){
1474         $result.= image('images/lists/copy.png', "listing_copy_$row", _("Copy this entry"));
1475       }else{
1476         $result.= image('images/empty.png');
1477       }
1478     }
1480     return($result);
1481   }
1484   function renderSnapshotMenu($separator)
1485   {
1486     // We can only provide information if we've got a snapshot handler
1487     // instance
1488     if(!(isset($this->snapshotHandler) && is_object($this->snapshotHandler))){
1489       return "";
1490     }
1492     // Presets
1493     $result = "";
1494     $ui = get_userinfo();
1496     if($this->snapshotHandler->enabled() && $ui->allow_snapshot_restore($this->base, $this->categories)){
1498       // Check if there is something to restore
1499       $restore= false;
1500       foreach($this->snapshotHandler->getSnapshotBases() as $base){
1501         $restore= $restore || count($this->snapshotHandler->getDeletedSnapshots($base)) > 0;
1502       }
1504       // Draw icons according to the restore flag
1505       if($restore){
1506         $result.= "<li$separator><a href='#' onClick='\$(\"act\").value= \"restore\";\$(\"exec_act\").click();'>".image('images/lists/restore.png')."&nbsp;"._("Restore snapshots")."</a></li>";
1507       }else{
1508         $result.= "<li$separator><a href='#'>".image('images/lists/restore-grey.png')."&nbsp;"._("Restore snapshots")."</a></li>";
1509       }
1510     }
1512     return($result);
1513   }
1516   function renderExporterMenu($separator)
1517   {
1518     // Presets
1519     $result = "";
1521     // Draw entries
1522     $result.= "<li$separator><a href='#'>".image('images/lists/export.png')."&nbsp;"._("Export list")."&nbsp;".image("images/forward-arrow.png")."</a><ul class='level3'>";
1524     // Export CVS as build in exporter
1525     foreach ($this->exporter as $action => $exporter) {
1526       $result.= "<li><a href='#' onClick='\$(\"act\").value= \"$action\";\$(\"exec_act\").click();'>".image($exporter['image'])."&nbsp;".$exporter['label']."</a></li>";
1527     }
1529     // Finalize list
1530     $result.= "</ul></li>";
1532     return($result);
1533   }
1536   function renderSnapshotActions($row, $dn, $category, $class, $copy= true, $cut= true)
1537   {
1538     // We can only provide information if we've got a snapshot handler
1539     // instance
1540     if(!(isset($this->snapshotHandler) && is_object($this->snapshotHandler))){
1541       return "";
1542     }
1544     // Presets
1545     $result= "";
1546     $ui = get_userinfo();
1548     // Only act if enabled here
1549     if($this->snapshotHandler->enabled()){
1551       // Draw restore button
1552       if ($ui->allow_snapshot_restore($dn, $category)){
1554         // Do we have snapshots for this dn?
1555         if($this->snapshotHandler->hasSnapshots($dn)){
1556           $result.= image('images/lists/restore.png', "listing_restore_$row", _("Restore snapshot"));
1557         } else {
1558           $result.= image('images/lists/restore-grey.png');
1559         }
1560       }
1562       // Draw snapshot button
1563       if($ui->allow_snapshot_create($dn, $category)){
1564           $result.= image('images/snapshot.png', "listing_snapshot_$row", _("Create new snapshot for this object"));
1565       }else{
1566           $result.= image('images/empty.png');
1567       }
1568     }
1570     return($result);
1571   }
1574   function renderDaemonMenu($separator)
1575   {
1576     $result= "";
1578     // If there is a daemon registered, draw the menu entries
1579     if(class_available("DaemonEvent")){
1580       $events= DaemonEvent::get_event_types_by_category($this->categories);
1581       if(isset($events['BY_CLASS']) && count($events['BY_CLASS'])){
1582         foreach($events['BY_CLASS'] as $name => $event){
1583           $result.= "<li$separator><a href='#' onClick='\$(\"act\").value=\"$name\";\$(\"exec_act\").click();'>".$event['MenuImage']."&nbsp;".$event['s_Menu_Name']."</a></li>";
1584           $separator= "";
1585         }
1586       }
1587     }
1589     return $result;
1590   }
1593   function getEntry($dn)
1594   {
1595     foreach ($this->entries as $entry) {
1596       if (isset($entry['dn']) && strcasecmp($dn, $entry['dn']) == 0){
1597         return $entry;
1598       }
1599     }
1600     return null;
1601   }
1604   function getEntries()
1605   {
1606     return $this->entries;
1607   }
1610   function getType($dn)
1611   {
1612     $dn = LDAP::fix($dn);
1613     if (isset($this->objectDnMapping[$dn])) {
1614       return $this->objectDnMapping[$dn];
1615     }
1616     return null;
1617   }
1621 ?>