Code

Corrected acl check
[gosa.git] / gosa-core / include / class_listing.inc
1 <?php
2 /*
3  * This code is part of GOsa (http://www.gosa-project.org)
4  * Copyright (C) 2003-2008 GONICUS GmbH
5  *
6  * ID: $$Id$$
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
23 class listing {
25   var $xmlData;
26   var $entries;
27   var $departments= array();
28   var $departmentBrowser= false;
29   var $departmentRootVisible= false;
30   var $multiSelect= false;
31   var $template;
32   var $headline;
33   var $base;
34   var $sortDirection= null;
35   var $sortColumn= null;
36   var $sortAttribute;
37   var $sortType;
38   var $numColumns;
39   var $baseMode= false;
40   var $bases= array();
41   var $header= array();
42   var $colprops= array();
43   var $filters= array();
44   var $filter= null;
45   var $pid;
46   var $objectTypes= array();
47   var $objectTypeCount= array();
48   var $objectDnMapping= array();
49   var $copyPasteHandler= null;
50   var $snapshotHandler= null;
51   var $exporter= array();
52   var $exportColumns= array();
53   var $useSpan= false;
54   var $height= 0;
55   var $scrollPosition= 0;
56   var $baseSelector;
59   function listing($filename)
60   {
61     global $config;
62     global $class_mapping;
64     // Initialize pid
65     $this->pid= preg_replace("/[^0-9]/", "", microtime(TRUE));
67     if (!$this->load($filename)) {
68       die("Cannot parse $filename!");
69     }
71     // Set base for filter
72     if ($this->baseMode) {
73       $this->base= session::global_get("CurrentMainBase");
74       if ($this->base == null) {
75         $this->base= $config->current['BASE'];
76       }
77       $this->refreshBasesList();
78     } else {
79       $this->base= $config->current['BASE'];
80     }
82     // Move footer information
83     $this->showFooter= ($config->get_cfg_value("listSummary") == "true");
85     // Register build in filters
86     $this->registerElementFilter("objectType", "listing::filterObjectType");
87     $this->registerElementFilter("departmentLink", "listing::filterDepartmentLink");
88     $this->registerElementFilter("link", "listing::filterLink");
89     $this->registerElementFilter("actions", "listing::filterActions");
91     // Load exporters
92     foreach($class_mapping as $class => $dummy) {
93       if (preg_match('/Exporter$/', $class)) {
94         $info= call_user_func(array($class, "getInfo"));
95         if ($info != null) {
96           $this->exporter= array_merge($this->exporter, $info);
97         }
98       }
99     }
101     // Instanciate base selector
102     $this->baseSelector= new baseSelector($this->bases, $this->base);
103   }
106   function setCopyPasteHandler($handler)
107   {
108     $this->copyPasteHandler= &$handler;
109   }
112   function setHeight($height)
113   {
114     $this->height= $height;
115   }
118   function setSnapshotHandler($handler)
119   {
120     $this->snapshotHandler= &$handler;
121   }
124   function setFilter($filter)
125   {
126     $this->filter= &$filter;
127     if ($this->departmentBrowser){
128       $this->departments= $this->getDepartments();
129     }
130     $this->filter->setBase($this->base);
131   }
134   function registerElementFilter($name, $call)
135   {
136     if (!isset($this->filters[$name])) {
137       $this->filters[$name]= $call;
138       return true;
139     }
141     return false;
142   }
145   function load($filename)
146   {
147     $contents = file_get_contents($filename);
148     $this->xmlData= xml::xml2array($contents, 1);
150     if (!isset($this->xmlData['list'])) {
151       return false;
152     }
154     $this->xmlData= $this->xmlData["list"];
156     // Load some definition values
157     foreach (array("departmentBrowser", "departmentRootVisible", "multiSelect", "baseMode") as $token) {
158       if (isset($this->xmlData['definition'][$token]) &&
159           $this->xmlData['definition'][$token] == "true"){
160         $this->$token= true;
161       }
162     }
164     // Fill objectTypes from departments and xml definition
165     $types = departmentManagement::get_support_departments();
166     foreach ($types as $class => $data) {
167       $this->objectTypes[]= array("label" => $data['TITLE'],
168                                   "objectClass" => $data['OC'],
169                                   "image" => $data['IMG']);
170     }
171     $this->categories= array();
172     if (isset($this->xmlData['definition']['objectType'])) {
173       if(isset($this->xmlData['definition']['objectType']['label'])) {
174         $this->xmlData['definition']['objectType']= array($this->xmlData['definition']['objectType']);
175       }
176       foreach ($this->xmlData['definition']['objectType'] as $index => $otype) {
177         $this->objectTypes[]= $this->xmlData['definition']['objectType'][$index];
178         if (isset($this->xmlData['definition']['objectType'][$index]['category'])){
179           $this->categories[]= $otype['category'];
180         }
181       }
182     }
184     // Parse layout per column
185     $this->colprops= $this->parseLayout($this->xmlData['table']['layout']);
187     // Prepare table headers
188     $this->renderHeader();
190     // Assign headline/Categories
191     $this->headline= _($this->xmlData['definition']['label']);
192     if (!is_array($this->categories)){
193       $this->categories= array($this->categories);
194     }
196     // Evaluate columns to be exported
197     if (isset($this->xmlData['table']['column'])){
198       foreach ($this->xmlData['table']['column'] as $index => $config) {
199         if (isset($config['export']) && $config['export'] == "true"){
200           $this->exportColumns[]= $index;
201         }
202       }
203     }
205     return true;  
206   }
209   function renderHeader()
210   {
211     $this->header= array();
212     $this->plainHeader= array();
214     // Initialize sort?
215     $sortInit= false;
216     if (!$this->sortDirection) {
217       $this->sortColumn= 0;
218       if (isset($this->xmlData['definition']['defaultSortColumn'])){
219         $this->sortColumn= $this->xmlData['definition']['defaultSortColumn'];
220       } else {
221         $this->sortAttribute= "";
222       }
223       $this->sortDirection= array();
224       $sortInit= true;
225     }
227     if (isset($this->xmlData['table']['column'])){
228       foreach ($this->xmlData['table']['column'] as $index => $config) {
229         // Initialize everything to one direction
230         if ($sortInit) {
231           $this->sortDirection[$index]= false;
232         }
234         $sorter= "";
235         if ($index == $this->sortColumn && isset($config['sortAttribute']) &&
236             isset($config['sortType'])) {
237           $this->sortAttribute= $config['sortAttribute'];
238           $this->sortType= $config['sortType'];
239           $sorter= "&nbsp;<img border='0' title='".($this->sortDirection[$index]?_("Up"):_("Down"))."' src='images/lists/sort-".($this->sortDirection[$index]?"up":"down").".png' align='top'>";
240         }
241         $sortable= (isset($config['sortAttribute']));
243         $link= "href='?plug=".$_GET['plug']."&amp;PID=".$this->pid."&amp;act=SORT_$index'";
244         if (isset($config['label'])) {
245           if ($sortable) {
246             $this->header[$index]= "<td class='listheader' ".$this->colprops[$index]."><a $link>"._($config['label'])."$sorter</a></td>";
247           } else {
248             $this->header[$index]= "<td class='listheader' ".$this->colprops[$index].">"._($config['label'])."</td>";
249           }
250           $this->plainHeader[]= _($config['label']);
251         } else {
252           if ($sortable) {
253             $this->header[$index]= "<td class='listheader' ".$this->colprops[$index]."><a $link>&nbsp;$sorter</a></td>";
254           } else {
255             $this->header[$index]= "<td class='listheader' ".$this->colprops[$index].">&nbsp;</td>";
256           }
257           $this->plainHeader[]= "";
258         }
259       }
260     }
261   }
264   function render()
265   {
266     // Check for exeeded sizelimit
267     if (($message= check_sizelimit()) != ""){
268       return($message);
269     }
271     // Some browsers don't have the ability do do scrollable table bodies, filter them
272     // here.
273     $switch= false;
274     if (preg_match('/(Opera|Konqueror|Safari)/i', $_SERVER['HTTP_USER_AGENT'])){
275       $switch= true;
276     }
278     // Initialize list
279     $result= "<input type='hidden' value='$this->pid' name='PID'>\n";
280     $result.= "<input type='hidden' name='position_".$this->pid."' id='position_".$this->pid."'>\n";
281     $height= 450;
282     if ($this->height != 0) {
283       $result.= "<input type='hidden' value='$this->height' id='d_height'>\n";
284       $height= $this->height;
285     }
286     
287     $result.= "<div class='listContainer' id='d_scrollbody' style='border-top:1px solid #B0B0B0;border-right:1px solid #B0B0B0;width:100%;min-height:".($height+25)."px;'>\n";
288     $result.= "<table summary='$this->headline' style='width:100%; table-layout:fixed' cellspacing='0' cellpadding='0' id='t_scrolltable'>\n";
289     $this->numColumns= count($this->colprops) + ($this->multiSelect?1:0);
291     // Build list header
292     $result.= "<thead class='fixedListHeader listHeaderFormat'><tr>\n";
293     if ($this->multiSelect) {
294       $width= "24px";
295       if (preg_match('/Konqueror/i', $_SERVER['HTTP_USER_AGENT'])){
296         $width= "28px";
297       }
298       $result.= "<td class='listheader' style='text-align:center;padding:0;width:$width;'><input type='checkbox' id='select_all' name='select_all' title='"._("Select all")."' onClick='toggle_all_(\"listing_selected_[0-9]*$\",\"select_all\");' ></td>\n";
299     }
300     foreach ($this->header as $header) {
301       $result.= $header;
302     }
303     $result.= "</tr></thead>\n";
305     // Build list body
306     $result.= "<tbody class='listScrollContent listBodyFormat' id='t_nscrollbody' style='height:".$height."px;'>\n";
308     // No results? Just take an empty colspanned row
309     if (count($this->entries) + count($this->departments) == 0) {
310       $result.= "<tr class='rowxp0'><td class='list1nohighlight' colspan='$this->numColumns' style='height:100%;border-right:0px;width:100%;'>&nbsp;</td></tr>";
311     }
313     // Line color alternation
314     $alt= 0;
315     $deps= 0;
317     // Draw department browser if configured and we're not in sub mode
318     $this->useSpan= false;
319     if ($this->departmentBrowser && $this->filter->scope != "sub") {
320       // Fill with department browser if configured this way
321       $departmentIterator= new departmentSortIterator($this->departments, $this->sortDirection[$this->sortColumn]);
322       foreach ($departmentIterator as $row => $entry){
323         $result.="<tr class='rowxp".($alt&1)."'>";
325         // Render multi select if needed
326         if ($this->multiSelect) {
327           $result.="<td style='text-align:center;padding:0;' class='list1'>&nbsp;</td>";
328         }
330         // Render defined department columns, fill the rest with some stuff
331         $rest= $this->numColumns - 1;
332         foreach ($this->xmlData['table']['department'] as $index => $config) {
333           $colspan= 1;
334           if (isset($config['span'])){
335             $colspan= $config['span'];
336             $this->useSpan= true;
337           }
338           $result.="<td colspan='$colspan' ".$this->colprops[$index]." class='list1'>".$this->renderCell($config['value'], $entry, $row)."</td>";
339           $rest-= $colspan;
340         }
342         // Fill remaining cols with nothing
343         $last= $this->numColumns - $rest;
344         for ($i= 0; $i<$rest; $i++){
345           $result.= "<td ".$this->colprops[$last+$i-1]." class='list1'>&nbsp;</td>";
346         }
347         $result.="</tr>";
349         $alt++;
350       }
351       $deps= $alt;
352     }
354     // Fill with contents, sort as configured
355     foreach ($this->entries as $row => $entry) {
356       $trow= "";
358       // Render multi select if needed
359       if ($this->multiSelect) {
360         $trow.="<td style='text-align:center;width:20px;' class='list0'><input type='checkbox' id='listing_selected_$row' name='listing_selected_$row'></td>\n";
361       }
363       foreach ($this->xmlData['table']['column'] as $index => $config) {
364         $renderedCell= $this->renderCell($config['value'], $entry, $row);
365         $trow.="<td ".$this->colprops[$index]." class='list0'>".$renderedCell."</td>\n";
367         // Save rendered column
368         $sort= preg_replace('/.*>([^<]+)<.*$/', '$1', $renderedCell);
369         $sort= preg_replace('/&nbsp;/', '', $sort);
370         if (preg_match('/</', $sort)){
371           $sort= "";
372         }
373         $this->entries[$row]["_sort$index"]= $sort;
374       }
376       // Save rendered entry
377       $this->entries[$row]['_rendered']= $trow;
378     }
380     // Complete list by sorting entries for _sort$index and appending them to the output
381     $entryIterator= new listingSortIterator($this->entries, $this->sortDirection[$this->sortColumn], "_sort".$this->sortColumn, $this->sortType);
382     foreach ($entryIterator as $row => $entry){
383       $result.="<tr class='rowxp".($alt&1)."'>\n";
384       $result.= $entry['_rendered'];
385       $result.="</tr>\n";
386       $alt++;
387     }
389     // Need to fill the list if it's not full (nobody knows why this is 22 ;-))
390     $emptyListStyle= (count($this->entries) + (($this->useSpan && count($this->entries))?$deps:0) == 0)?"border:0;":"";
391     if ((count($this->entries) + $deps) < 22) {
392       $result.= "<tr>";
393       for ($i= 0; $i<$this->numColumns; $i++) {
394         if ($i == 0) {
395           $result.= "<td class='list1nohighlight' style='$emptyListStyle height:100%;'>&nbsp;</td>";
396           continue;
397         }
398         if ($i != $this->numColumns-1) {
399           $result.= "<td class='list1nohighlight' style='$emptyListStyle'>&nbsp;</td>";
400         } else {
401           $result.= "<td class='list1nohighlight' style='border-right:0;$emptyListStyle'>&nbsp;</td>";
402         }
403       }
404       $result.= "</tr>";
405     }
407     // Close list body
408     $result.= "</tbody></table></div>";
410     // Add the footer if requested
411     if ($this->showFooter) {
412       $result.= "<div class='nlistFooter'><div style='padding:3px'>";
414       foreach ($this->objectTypes as $objectType) {
415         if (isset($this->objectTypeCount[$objectType['label']])) {
416           $label= _($objectType['label']);
417           $result.= "<img class='center' src='".$objectType['image']."' title='$label' alt='$label'>&nbsp;".$this->objectTypeCount[$objectType['label']]."&nbsp;&nbsp;&nbsp;&nbsp;";
418         }
419       }
421       $result.= "</div></div>";
422     }
424     // Close list
425     $result.= $switch?"<input type='hidden' id='list_workaround'>":"";
427     // Add scroll positioner
428     $result.= '<script type="text/javascript" language="javascript">';
429     $result.= '$("t_nscrollbody").scrollTop= '.$this->scrollPosition.';';
430     $result.= 'var box = $("t_nscrollbody").onscroll= function() {$("position_'.$this->pid.'").value= this.scrollTop;}';
431     $result.= '</script>';
433     $smarty= get_smarty();
434     $smarty->assign("usePrototype", "true");
435     $smarty->assign("FILTER", $this->filter->render());
436     $smarty->assign("SIZELIMIT", print_sizelimit_warning());
437     $smarty->assign("LIST", $result);
439     // Assign navigation elements
440     $nav= $this->renderNavigation();
441     foreach ($nav as $key => $html) {
442       $smarty->assign($key, $html);
443     }
445     // Assign action menu / base
446     $smarty->assign("ACTIONS", $this->renderActionMenu());
447     $smarty->assign("BASE", $this->renderBase());
449     // Assign separator
450     $smarty->assign("SEPARATOR", "<img src='images/lists/seperator.png' alt='-' align='middle' height='16' width='1' class='center'>");
452     // Assign summary
453     $smarty->assign("HEADLINE", $this->headline);
455     // Try to load template from plugin the folder first...
456     $file = get_template_path($this->xmlData['definition']['template'], true);
458     // ... if this fails, try to load the file from the theme folder.
459     if(!file_exists($file)){
460       $file = get_template_path($this->xmlData['definition']['template']);
461     }
463     return ($smarty->fetch($file));
464   }
467   function update()
468   {
469     global $config;
470     $ui= get_userinfo();
472     // Take care of base selector
473     if ($this->baseMode) {
474       $this->baseSelector->update();
475       // Check if a wrong base was supplied
476       if(!$this->baseSelector->checkLastBaseUpdate()){
477          msg_dialog::display(_("Error"), msgPool::check_base(), ERROR_DIALOG);
478       }
479     }
481     // Save base
482     $refresh= false;
483     if ($this->baseMode) {
484       $this->base= $this->baseSelector->getBase();
485       session::global_set("CurrentMainBase", $this->base);
486       $refresh= true;
487     }
490     // Reset object counter / DN mapping
491     $this->objectTypeCount= array();
492     $this->objectDnMapping= array();
494     // Do not do anything if this is not our PID
495     if($refresh || !(isset($_REQUEST['PID']) && $_REQUEST['PID'] != $this->pid)) {
497       // Save position if set
498       if (isset($_POST['position_'.$this->pid]) && is_numeric($_POST['position_'.$this->pid])) {
499         $this->scrollPosition= $_POST['position_'.$this->pid];
500       }
502       // Override the base if we got a message from the browser navigation
503       if ($this->departmentBrowser && isset($_GET['act'])) {
504         if (preg_match('/^department_([0-9]+)$/', validate($_GET['act']), $match)){
505           if (isset($this->departments[$match[1]])){
506             $this->base= $this->departments[$match[1]]['dn'];
507             if ($this->baseMode) {
508               $this->baseSelector->setBase($this->base);
509             }
510             session::global_set("CurrentMainBase", $this->base);
511           }
512         }
513       }
515       // Filter POST with "act" attributes -> posted from action menu
516       if (isset($_POST['exec_act']) && $_POST['act'] != '') {
517         if (preg_match('/^export.*$/', $_POST['act']) && isset($this->exporter[$_POST['act']])) {
518           $exporter= $this->exporter[$_POST['act']];
519           $userinfo= ", "._("created by")." ".$ui->cn." - ".strftime('%A, %d. %B %Y, %H:%M:%S');
520           $entryIterator= new listingSortIterator($this->entries, $this->sortDirection[$this->sortColumn], "_sort".$this->sortColumn, $this->sortType);
521           $sortedEntries= array();
522           foreach ($entryIterator as $entry){
523             $sortedEntries[]= $entry;
524           }
525           $instance= new $exporter['class']($this->headline.$userinfo, $this->plainHeader, $sortedEntries, $this->exportColumns);
526           $type= call_user_func(array($exporter['class'], "getInfo"));
527           $type= $type[$_POST['act']];
528           send_binary_content($instance->query(), $type['filename'], $type= $type['mime']);
529         }
530       }
532       // Filter GET with "act" attributes
533       if (isset($_GET['act'])) {
534         $key= validate($_GET['act']);
535         if (preg_match('/^SORT_([0-9]+)$/', $key, $match)) {
536           // Switch to new column or invert search order?
537           $column= $match[1];
538           if ($this->sortColumn != $column) {
539             $this->sortColumn= $column;
540           } else {
541             $this->sortDirection[$column]= !$this->sortDirection[$column];
542           }
544           // Allow header to update itself according to the new sort settings
545           $this->renderHeader();
546         }
547       }
549       // Override base if we got signals from the navigation elements
550       $action= "";
551       foreach ($_POST as $key => $value) {
552         if (preg_match('/^(ROOT|BACK|HOME)_x$/', $key, $match)) {
553           $action= $match[1];
554           break;
555         }
556       }
558       // Navigation handling
559       if ($action == 'ROOT') {
560         $deps= $ui->get_module_departments($this->categories);
561         $this->base= $deps[0];
562         $this->baseSelector->setBase($this->base);
563         session::global_set("CurrentMainBase", $this->base);
564       }
565       if ($action == 'BACK') {
566         $deps= $ui->get_module_departments($this->categories);
567         $base= preg_replace("/^[^,]+,/", "", $this->base);
568         if(in_array_ics($base, $deps)){
569           $this->base= $base;
570           $this->baseSelector->setBase($this->base);
571           session::global_set("CurrentMainBase", $this->base);
572         }
573       }
574       if ($action == 'HOME') {
575         $ui= get_userinfo();
576         $this->base= get_base_from_people($ui->dn);
577         $this->baseSelector->setBase($this->base);
578         session::global_set("CurrentMainBase", $this->base);
579       }
580     }
582     // Reload departments
583     if ($this->departmentBrowser){
584       $this->departments= $this->getDepartments();
585     }
587     // Update filter and refresh entries
588     $this->filter->setBase($this->base);
589     $this->entries= $this->filter->query();
591     // Fix filter if querie returns NULL
592     if ($this->entries == null) {
593       $this->entries= array();
594     }
595   }
598   function setBase($base)
599   {
600     $this->base= $base;
601     if ($this->baseMode) {
602       $this->baseSelector->setBase($this->base);
603     }
604   }
607   function getBase()
608   {
609     return $this->base;
610   }
613   function parseLayout($layout)
614   {
615     $result= array();
616     $layout= preg_replace("/^\|/", "", $layout);
617     $layout= preg_replace("/\|$/", "", $layout);
618     $cols= explode("|", $layout);
620     foreach ($cols as $index => $config) {
621       if ($config != "") {
622         $res= "";
623         $components= explode(';', $config);
624         foreach ($components as $part) {
625           if (preg_match("/^r$/", $part)) {
626             $res.= "text-align:right;";
627             continue;
628           }
629           if (preg_match("/^l$/", $part)) {
630             $res.= "text-align:left;";
631             continue;
632           }
633           if (preg_match("/^c$/", $part)) {
634             $res.= "text-align:center;";
635             continue;
636           }
637           if (preg_match("/^[0-9]+(|px|%)$/", $part)) {
638             $res.= "width:$part;min-width:$part;";
639             continue;
640           }
641         }
643         // Add minimum width for scalable columns
644         if (!preg_match('/width:/', $res)){
645           $res.= "min-width:200px;";
646         }
648         $result[$index]= " style='$res'";
649       } else {
650         $result[$index]= " style='min-width:100px;'";
651       }
652     }
654     // Save number of columns for later use
655     $this->numColumns= count($cols);
657     // Add no border to the last column
658     $result[$this->numColumns-1]= preg_replace("/'$/", "border-right:0;'", $result[$this->numColumns-1]);
660     return $result;
661   }
664   function renderCell($data, $config, $row)
665   {
666     // Replace flat attributes in data string
667     for ($i= 0; $i<$config['count']; $i++) {
668       $attr= $config[$i];
669       $value= "";
670       if (is_array($config[$attr])) {
671         $value= $config[$attr][0];
672       } else {
673         $value= $config[$attr];
674       }
675       $data= preg_replace("/%\{$attr\}/", $value, $data);
676     }
678     // Watch out for filters and prepare to execute them
679     $data= $this->processElementFilter($data, $config, $row);
681     // Replace all non replaced %{...} instances because they
682     // are non resolved attributes or filters
683     $data= preg_replace('/%{[^}]+}/', '&nbsp;', $data);
685     return $data;
686   }
689   function renderBase()
690   {
691     if (!$this->baseMode) {
692       return;
693     }
695     return $this->baseSelector->render();
696   }
699   function processElementFilter($data, $config, $row)
700   {
701     preg_match_all("/%\{filter:([^(]+)\((.*)\)\}/", $data, $matches, PREG_SET_ORDER);
703     foreach ($matches as $match) {
704       $cl= "";
705       $method= "";
706       if (preg_match('/::/', $match[1])) {
707         $cl= preg_replace('/::.*$/', '', $match[1]);
708         $method= preg_replace('/^.*::/', '', $match[1]);
709       } else {
710         if (!isset($this->filters[$match[1]])) {
711           continue;
712         }
713         $cl= preg_replace('/::.*$/', '', $this->filters[$match[1]]);
714         $method= preg_replace('/^.*::/', '', $this->filters[$match[1]]);
715       }
717       // Prepare params for function call
718       $params= array();
719       preg_match_all('/"[^"]+"|[^,]+/', $match[2], $parts);
720       foreach ($parts[0] as $param) {
722         // Row is replaced by the row number
723         if ($param == "row") {
724           $params[]= $row;
725           continue;
726         }
728         // pid is replaced by the current PID
729         if ($param == "pid") {
730           $params[]= $this->pid;
731           continue;
732         }
734         // base is replaced by the current base
735         if ($param == "base") {
736           $params[]= $this->getBase();
737           continue;
738         }
740         // Fixie with "" is passed directly
741         if (preg_match('/^".*"$/', $param)){
742           $params[]= preg_replace('/"/', '', $param);
743           continue;
744         }
746         // Move dn if needed
747         if ($param == "dn") {
748           $params[]= LDAP::fix($config["dn"]);
749           continue;
750         }
752         // LDAP variables get replaced by their objects
753         for ($i= 0; $i<$config['count']; $i++) {
754           if ($param == $config[$i]) {
755             $values= $config[$config[$i]];
756             if (is_array($values)){
757               unset($values['count']);
758             }
759             $params[]= $values;
760             break;
761           }
762         }
763       }
765       // Replace information
766       if ($cl == "listing") {
767         // Non static call - seems to result in errors
768         $data= @preg_replace('/'.preg_quote($match[0]).'/', call_user_func_array(array($this, "$method"), $params), $data);
769       } else {
770         // Static call
771         $data= preg_replace('/'.preg_quote($match[0]).'/', call_user_func_array(array($cl, $method), $params), $data);
772       }
773     }
775     return $data;
776   }
779   function getObjectType($types, $classes)
780   {
781     // Walk thru types and see if there's something matching
782     foreach ($types as $objectType) {
783       $ocs= $objectType['objectClass'];
784       if (!is_array($ocs)){
785         $ocs= array($ocs);
786       }
788       $found= true;
789       foreach ($ocs as $oc){
790         if (preg_match('/^!(.*)$/', $oc, $match)) {
791           $oc= $match[1];
792           if (in_array($oc, $classes)) {
793             $found= false;
794           }
795         } else {
796           if (!in_array($oc, $classes)) {
797             $found= false;
798           }
799         }
800       }
802       if ($found) {
803         return $objectType;
804       }
805     }
807     return null;
808   }
811   function filterObjectType($dn, $classes)
812   {
813     // Walk thru classes and return on first match
814     $result= "&nbsp;";
816     $objectType= $this->getObjectType($this->objectTypes, $classes);
817     if ($objectType) {
818       $this->objectDnMapping[$dn]= $objectType["objectClass"];
819       $result= "<img class='center' title='".LDAP::fix($dn)."' src='".$objectType["image"]."'>";
820       if (!isset($this->objectTypeCount[$objectType['label']])) {
821         $this->objectTypeCount[$objectType['label']]= 0;
822       }
823       $this->objectTypeCount[$objectType['label']]++;
824     }
826     return $result;
827   }
830   function filterActions($dn, $row, $classes)
831   {
832     // Do nothing if there's no menu defined
833     if (!isset($this->xmlData['actiontriggers']['action'])) {
834       return "&nbsp;";
835     }
837     // Go thru all actions
838     $result= "";
839     $actions= $this->xmlData['actiontriggers']['action'];
840     foreach($actions as $action) {
841       // Skip the entry completely if there's no permission to execute it
842       if (!$this->hasActionPermission($action, $dn, $classes)) {
843         $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
844         continue;
845       }
847       // Skip entry if the pseudo filter does not fit
848       if (isset($action['filter']) && preg_match('/^[a-z0-9_]+!?=[a-z0-9_]+$/i', $action['filter'])) {
849         list($fa, $fv)= explode('=', $action['filter']);
850         if (preg_match('/^(.*)!$/', $fa, $m)){
851           $fa= $m[1];
852           if (isset($this->entries[$row][$fa]) && $this->entries[$row][$fa][0] == $fv) {
853             $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
854             continue;
855           }
856         } else {
857           if (!isset($this->entries[$row][$fa]) && !$this->entries[$row][$fa][0] == $fv) {
858             $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
859             continue;
860           }
861         }
862       }
865       // If there's an objectclass definition and we don't have it
866       // add an empty picture here.
867       if (isset($action['objectclass'])){
868         $objectclass= $action['objectclass'];
869         if (preg_match('/^!(.*)$/', $objectclass, $m)){
870           $objectclass= $m[1];
871           if(in_array($objectclass, $classes)) {
872             $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
873             continue;
874           }
875         } elseif (is_string($objectclass)) {
876           if(!in_array($objectclass, $classes)) {
877             $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
878             continue;
879           }
880         } elseif (is_array($objectclass)) {
881           if(count(array_intersect($objectclass, $classes)) != count($objectclass)){
882             $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
883             continue;
884           }
885         }
886       }
888       // Render normal entries as usual
889       if ($action['type'] == "entry") {
890         $label= $this->processElementFilter($action['label'], $this->entries[$row], $row);
891         $image= $this->processElementFilter($action['image'], $this->entries[$row], $row);
892         $result.="<input class='center' type='image' src='$image' title='$label' ".
893                  "name='listing_".$action['name']."_$row' style='padding:1px'>";
894       }
896       // Handle special types
897       if ($action['type'] == "copypaste" || $action['type'] == "snapshot") {
899         $objectType= $this->getObjectType($this->objectTypes, $this->entries[$row]['objectClass']);
900         $category= $class= null;
901         if ($objectType) {
902           $category= $objectType['category'];
903           $class= $objectType['class'];
904         }
906         if ($action['type'] == "copypaste") {
907           $copy = !isset($action['copy']) || $action['copy'] == "true";
908           $cut = !isset($action['cut']) || $action['cut'] == "true";
909           $result.= $this->renderCopyPasteActions($row, $this->entries[$row]['dn'], $category, $class,$copy,$cut);
910         } else {
911           $result.= $this->renderSnapshotActions($row, $this->entries[$row]['dn'], $category, $class);
912         }
913       }
914     }
916     return $result;
917   }
920   function filterDepartmentLink($row, $dn, $description)
921   {
922     $attr= $this->departments[$row]['sort-attribute'];
923     $name= $this->departments[$row][$attr];
924     if (is_array($name)){
925       $name= $name[0];
926     }
927     $result= sprintf("%s [%s]", $name, $description[0]);
928     return("<a href='?plug=".$_GET['plug']."&amp;PID=$this->pid&amp;act=department_$row' title='$dn'>$result</a>");
929   }
932   function filterLink()
933   {
934     $result= "&nbsp;";
936     $row= func_get_arg(0);
937     $pid= $this->pid;
938     $dn= LDAP::fix(func_get_arg(1));
939     $params= array(func_get_arg(2));
941     // Collect sprintf params
942     for ($i = 3;$i < func_num_args();$i++) {
943       $val= func_get_arg($i);
944       if (is_array($val)){
945         $params[]= $val[0];
946         continue;
947       }
948       $params[]= $val;
949     }
951     $result= "&nbsp;";
952     $trans= call_user_func_array("sprintf", $params);
953     if ($trans != "") {
954       return("<a href='?plug=".$_GET['plug']."&amp;PID=$pid&amp;act=listing_edit_$row' title='$dn'>$trans</a>");
955     }
957     return $result;
958   }
961   function renderNavigation()
962   {
963     $result= array();
964     $enableBack = true;
965     $enableRoot = true;
966     $enableHome = true;
968     $ui = get_userinfo();
970     /* Check if base = first available base */
971     $deps = $ui->get_module_departments($this->categories);
973     if(!count($deps) || $deps[0] == $this->filter->base){
974       $enableBack = false;
975       $enableRoot = false;
976     }
978     $listhead ="";
980     /* Check if we are in users home  department */
981     if(!count($deps) || $this->filter->base == get_base_from_people($ui->dn)){
982       $enableHome = false;
983     }
985     /* Draw root button */
986     if($enableRoot){
987       $result["ROOT"]= "<input class='center' type='image' src='images/lists/root.png' align='middle' ".
988                        "title='"._("Go to root department")."' name='ROOT' alt='"._("Root")."'>";
989     }else{
990       $result["ROOT"]= "<img src='images/lists/root_grey.png' class='center' alt='"._("Root")."'>";
991     }
993     /* Draw back button */
994     if($enableBack){
995       $result["BACK"]= "<input class='center' type='image' align='middle' src='images/lists/back.png' ".
996                        "title='"._("Go up one department")."' alt='"._("Up")."' name='BACK'>";
997     }else{
998       $result["BACK"]= "<img src='images/lists/back_grey.png' class='center' alt='"._("Up")."'>";
999     }
1001     /* Draw home button */
1002     if($enableHome){
1003       $result["HOME"]= "<input class='center' type='image' align='middle' src='images/lists/home.png' ".
1004                        "title='"._("Go to users department")."' alt='"._("Home")."' name='HOME'>";
1005     }else{
1006       $result["HOME"]= "<img src='images/lists/home_grey.png' class='center' alt='"._("Home")."'>";
1007     }
1009     /* Draw reload button, this button is enabled everytime */
1010     $result["RELOAD"]= "<input class='center' type='image' src='images/lists/reload.png' align='middle' ".
1011                        "title='"._("Reload list")."' name='REFRESH' alt='"._("Submit")."'>";
1013     return ($result);
1014   }
1017   function getAction()
1018   {
1019     // Do not do anything if this is not our PID, or there's even no PID available...
1020     if(!isset($_REQUEST['PID']) || $_REQUEST['PID'] != $this->pid) {
1021       return;
1022     }
1024     // Save position if set
1025     if (isset($_POST['position_'.$this->pid]) && is_numeric($_POST['position_'.$this->pid])) {
1026       $this->scrollPosition= $_POST['position_'.$this->pid];
1027     }
1029     $result= array("targets" => array(), "action" => "");
1031     // Filter GET with "act" attributes
1032     if (isset($_GET['act'])) {
1033       $key= validate($_GET['act']);
1034       $target= preg_replace('/^listing_[a-zA-Z_]+_([0-9]+)$/', '$1', $key);
1035       if (isset($this->entries[$target]['dn'])) {
1036         $result['action']= preg_replace('/^listing_([a-zA-Z_]+)_[0-9]+$/', '$1', $key);
1037         $result['targets'][]= $this->entries[$target]['dn'];
1038       }
1040       // Drop targets if empty
1041       if (count($result['targets']) == 0) {
1042         unset($result['targets']);
1043       }
1044       return $result;
1045     }
1047     // Filter POST with "listing_" attributes
1048     foreach ($_POST as $key => $prop) {
1050       // Capture selections
1051       if (preg_match('/^listing_selected_[0-9]+$/', $key)) {
1052         $target= preg_replace('/^listing_selected_([0-9]+)$/', '$1', $key);
1053         if (isset($this->entries[$target]['dn'])) {
1054           $result['targets'][]= $this->entries[$target]['dn'];
1055         }
1056         continue;
1057       }
1059       // Capture action with target - this is a one shot
1060       if (preg_match('/^listing_[a-zA-Z_]+_[0-9]+(|_x)$/', $key)) {
1061         $target= preg_replace('/^listing_[a-zA-Z_]+_([0-9]+)(|_x)$/', '$1', $key);
1062         if (isset($this->entries[$target]['dn'])) {
1063           $result['action']= preg_replace('/^listing_([a-zA-Z_]+)_[0-9]+(|_x)$/', '$1', $key);
1064           $result['targets']= array($this->entries[$target]['dn']);
1065         }
1066         break;
1067       }
1069       // Capture action without target
1070       if (preg_match('/^listing_[a-zA-Z_]+(|_x)$/', $key)) {
1071         $result['action']= preg_replace('/^listing_([a-zA-Z_]+)(|_x)$/', '$1', $key);
1072         continue;
1073       }
1074     }
1076     // Filter POST with "act" attributes -> posted from action menu
1077     if (isset($_POST['act']) && $_POST['act'] != '') {
1078       if (!preg_match('/^export.*$/', $_POST['act'])){
1079         $result['action']= validate($_POST['act']);
1080       }
1081     }
1083     // Drop targets if empty
1084     if (count($result['targets']) == 0) {
1085       unset($result['targets']);
1086     }
1087     return $result;
1088   }
1091   function renderActionMenu()
1092   {
1093     // Don't send anything if the menu is not defined
1094     if (!isset($this->xmlData['actionmenu']['action'])){
1095       return "";
1096     }
1098     // Array?
1099     if (isset($this->xmlData['actionmenu']['action']['type'])){
1100       $this->xmlData['actionmenu']['action']= array($this->xmlData['actionmenu']['action']);
1101     }
1103     // Load shortcut
1104     $actions= &$this->xmlData['actionmenu']['action'];
1105     $result= "<input type='hidden' name='act' id='actionmenu' value=''><div style='display:none'><input type='submit' name='exec_act' id='exec_act' value=''></div>".
1106              "<ul class='level1' id='root'><li><a href='#'>"._("Actions")."&nbsp;<img ".
1107              "border=0 class='center' src='images/lists/sort-down.png'></a>";
1109     // Build ul/li list
1110     $result.= $this->recurseActions($actions);
1112     return "<div id='pulldown'>".$result."</li></ul><div>";
1113   }
1116   function recurseActions($actions)
1117   {
1118     global $class_mapping;
1119     static $level= 2;
1120     $result= "<ul class='level$level'>";
1121     $separator= "";
1123     foreach ($actions as $action) {
1125       // Skip the entry completely if there's no permission to execute it
1126       if (!$this->hasActionPermission($action, $this->filter->base)) {
1127         continue;
1128       }
1130       // Skip entry if there're missing dependencies
1131       if (isset($action['depends'])) {
1132         $deps= is_array($action['depends'])?$action['depends']:array($action['depends']);
1133         foreach($deps as $clazz) {
1134           if (!isset($class_mapping[$clazz])){
1135             continue 2;
1136           }
1137         }
1138       }
1140       // Fill image if set
1141       $img= "";
1142       if (isset($action['image'])){
1143         $img= "<img border='0' class='center' src='".$action['image']."'>&nbsp;";
1144       }
1146       if ($action['type'] == "separator"){
1147         $separator= " style='border-top:1px solid #AAA' ";
1148         continue;
1149       }
1151       // Dive into subs
1152       if ($action['type'] == "sub" && isset($action['action'])) {
1153         $level++;
1154         if (isset($action['label'])){
1155           $result.= "<li$separator><a href='#'>$img"._($action['label'])."&nbsp;<img border='0' src='images/forward-arrow.png'></a>";
1156         }
1158         // Ensure we've an array of actions, this enables sub menus with only one action.
1159         if(isset($action['action']['type'])){
1160           $action['action'] = array($action['action']);
1161         }
1163         $result.= $this->recurseActions($action['action'])."</li>";
1164         $level--;
1165         $separator= "";
1166         continue;
1167       }
1169       // Render entry elseways
1170       if (isset($action['label'])){
1171         $result.= "<li$separator><a href='#' onClick='document.getElementById(\"actionmenu\").value= \"".$action['name']."\";mainform.submit();'>$img"._($action['label'])."</a></li>";
1172       }
1174       // Check for special types
1175       switch ($action['type']) {
1176         case 'copypaste':
1177           $cut = !isset($action['cut']) || $action['cut'] != "false";
1178           $copy = !isset($action['copy']) || $action['copy'] != "false";
1179           $result.= $this->renderCopyPasteMenu($separator, $copy , $cut);
1180           break;
1182         case 'snapshot':
1183           $result.= $this->renderSnapshotMenu($separator);
1184           break;
1186         case 'exporter':
1187           $result.= $this->renderExporterMenu($separator);
1188           break;
1190         case 'daemon':
1191           $result.= $this->renderDaemonMenu($separator);
1192           break;
1193       }
1195       $separator= "";
1196     }
1198     $result.= "</ul>";
1199     return $result;
1200   }
1203   function hasActionPermission($action, $dn, $classes= null)
1204   {
1205     $ui= get_userinfo();
1207     if (isset($action['acl'])) {
1208       $acls= $action['acl'];
1209       if (!is_array($acls)) {
1210         $acls= array($acls);
1211       }
1213       // Every ACL has to pass
1214       foreach ($acls as $acl) {
1215         $module= $this->categories;
1216         $aclList= array();
1218         // Replace %acl if available
1219         if ($classes) {
1220           $otype= $this->getObjectType($this->objectTypes, $classes);
1221           $acl= str_replace('%acl', $otype['category']."/".$otype['class'], $acl);
1222         }
1224         // Split for category and plugins if needed
1225         // match for "[rw]" style entries
1226         if (preg_match('/^\[([rwcdm]+)\]$/', $acl, $match)){
1227           $aclList= array($match[1]);
1228         }
1230         // match for "users[rw]" style entries
1231         if (preg_match('/^([a-zA-Z0-9]+)\[([rwcdm]+)\]$/', $acl, $match)){
1232           $module= $match[1];
1233           $aclList= array($match[2]);
1234         }
1236         // match for "users/user[rw]" style entries
1237         if (preg_match('/^([a-zA-Z0-9]+\/[a-zA-Z0-9]+)\[([rwcdm]+)\]$/', $acl, $match)){
1238           $module= $match[1];
1239           $aclList= array($match[2]);
1240         }
1242         // match "users/user[userPassword:rw(,...)*]" style entries
1243         if (preg_match('/^([a-zA-Z0-9]+\/[a-zA-Z0-9]+)\[([a-zA-Z0-9]+:[rwcdm]+(,[a-zA-Z0-9]+:[rwcdm]+)*)\]$/', $acl, $match)){
1244           $module= $match[1];
1245           $aclList= explode(',', $match[2]);
1246         }
1248         // Walk thru prepared ACL by using $module
1249         foreach($aclList as $sAcl) {
1250           $checkAcl= "";
1252           // Category or detailed permission?
1253           if (strpos($module, '/') !== false) {
1254             if (preg_match('/([a-zA-Z0-9]+):([rwcdm]+)/', $sAcl, $m) ) {
1255               $checkAcl= $ui->get_permissions($dn, $module, $m[1]);
1256               $sAcl= $m[2];
1257             } else {
1258               $checkAcl= $ui->get_permissions($dn, $module, '0');
1259             }
1260           } else {
1261             $checkAcl= $ui->get_category_permissions($dn, $module);
1262           }
1264           // Split up remaining part of the acl and check if it we're
1265           // allowed to do something...
1266           $parts= str_split($sAcl);
1267           foreach ($parts as $part) {
1268             if (strpos($checkAcl, $part) === false){
1269               return false;
1270             }
1271           }
1273         }
1274       }
1275     }
1277     return true;
1278   }
1281   function refreshBasesList()
1282   {
1283     global $config;
1284     $ui= get_userinfo();
1286     // Do some array munching to get it user friendly
1287     $ids= $config->idepartments;
1288     $d= $ui->get_module_departments($this->categories);
1289     $k_ids= array_keys($ids);
1290     $deps= array_intersect($d,$k_ids);
1292     // Fill internal bases list
1293     $this->bases= array();
1294     foreach($k_ids as $department){
1295       $this->bases[$department] = $ids[$department];
1296     }
1298     // Populate base selector if already present
1299     if ($this->baseSelector && $this->baseMode) {
1300       $this->baseSelector->setBases($this->bases);
1301     }
1302   }
1305   function getDepartments()
1306   {
1307     $departments= array();
1308     $ui= get_userinfo();
1310     // Get list of supported department types
1311     $types = departmentManagement::get_support_departments();
1313     // Load departments allowed by ACL
1314     $validDepartments = $ui->get_module_departments($this->categories);
1316     // Build filter and look in the LDAP for possible sub departments
1317     // of current base
1318     $filter= "(&(objectClass=gosaDepartment)(|";
1319     $attrs= array("description", "objectClass");
1320     foreach($types as $name => $data){
1321       $filter.= "(objectClass=".$data['OC'].")";
1322       $attrs[]= $data['ATTR'];
1323     }
1324     $filter.= "))";
1325     $res= get_list($filter, $this->categories, $this->base, $attrs, GL_NONE);
1327     // Analyze list of departments
1328     foreach ($res as $department) {
1329       if (!in_array($department['dn'], $validDepartments)) {
1330         continue;
1331       }
1333       // Add the attribute where we use for sorting
1334       $oc= null;
1335       foreach(array_keys($types) as $type) {
1336         if (in_array($type, $department['objectClass'])) {
1337           $oc= $type;
1338           break;
1339         }
1340       }
1341       $department['sort-attribute']= $types[$oc]['ATTR'];
1343       // Move to the result list
1344       $departments[]= $department;
1345     }
1347     return $departments;
1348   }
1351   function renderCopyPasteMenu($separator, $copy= true, $cut= true)
1352   {
1353     // We can only provide information if we've got a copypaste handler
1354     // instance
1355     if(!(isset($this->copyPasteHandler) && is_object($this->copyPasteHandler))){
1356       return "";
1357     }
1359     // Presets
1360     $result= "";
1361     $read= $paste= false;
1362     $ui= get_userinfo();
1364     // Switch flags to on if there's at least one category which allows read/paste
1365     foreach($this->categories as $category){
1366       $read= $read || preg_match('/r/', $ui->get_category_permissions($this->base, $category));
1367       $paste= $paste || $ui->is_pasteable($this->base, $category) == 1;
1368     }
1371     // Draw entries that allow copy and cut
1372     if($read){
1374       // Copy entry
1375       if($copy){
1376         $result.= "<li$separator><a href='#' onClick='document.getElementById(\"actionmenu\").value= \"copy\";document.getElementById(\"exec_act\").click();'><img src='images/lists/copy.png' alt='' border='0' class='center'>&nbsp;"._("Copy")."</a></li>";
1377         $separator= "";
1378       }
1380       // Cut entry
1381       if($cut){
1382         $result.= "<li$separator><a href='#' onClick='document.getElementById(\"actionmenu\").value= \"cut\";document.getElementById(\"exec_act\").click();'><img src='images/lists/cut.png' alt='' border='0' class='center'>&nbsp;"._("Cut")."</a></li>";
1383         $separator= "";
1384       }
1385     }
1387     // Draw entries that allow pasting entries
1388     if($paste){
1389       if($this->copyPasteHandler->entries_queued()){
1390         $result.= "<li$separator><a href='#' onClick='document.getElementById(\"actionmenu\").value= \"paste\";document.getElementById(\"exec_act\").click();'><img src='images/lists/paste.png' alt='' border='0' class='center'>&nbsp;"._("Paste")."</a></li>";
1391       }else{
1392         $result.= "<li$separator><a href='#'><img src='images/lists/paste-grey.png' alt='' border='0' class='center'>&nbsp;"._("Paste")."</a></li>";
1393       }
1394     }
1395     
1396     return($result);
1397   }
1400   function renderCopyPasteActions($row, $dn, $category, $class, $copy= true, $cut= true)
1401   {
1402     // We can only provide information if we've got a copypaste handler
1403     // instance
1404     if(!(isset($this->copyPasteHandler) && is_object($this->copyPasteHandler))){
1405       return "";
1406     }
1408     // Presets
1409     $ui = get_userinfo();
1410     $result = "";
1412     // Render cut entries
1413     if($cut){
1414       if($ui->is_cutable($dn, $category, $class)){
1415         $result .= "<input class='center' type='image'
1416           src='images/lists/cut.png' alt='"._("Cut")."' name='listing_cut_$row' title='"._("Cut this entry")."' style='padding:1px'>";
1417       }else{
1418         $result.="<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
1419       }
1420     }
1422     // Render copy entries
1423     if($copy){
1424       if($ui->is_copyable($dn, $category, $class)){
1425         $result.= "<input class='center' type='image'
1426           src='images/lists/copy.png' alt='"._("Copy")."' name='listing_copy_$row' title='"._("Copy this entry")."' style='padding:1px'>";
1427       }else{
1428         $result.="<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
1429       }
1430     }
1432     return($result);
1433   }
1436   function renderSnapshotMenu($separator)
1437   {
1438     // We can only provide information if we've got a snapshot handler
1439     // instance
1440     if(!(isset($this->snapshotHandler) && is_object($this->snapshotHandler))){
1441       return "";
1442     }
1444     // Presets
1445     $result = "";
1446     $ui = get_userinfo();
1448     if($this->snapshotHandler->enabled() && $ui->allow_snapshot_restore($this->base, $this->categories)){
1450       // Check if there is something to restore
1451       $restore= false;
1452       foreach($this->snapshotHandler->getSnapshotBases() as $base){
1453         $restore= $restore || count($this->snapshotHandler->getDeletedSnapshots($base)) > 0;
1454       }
1456       // Draw icons according to the restore flag
1457       if($restore){
1458         $result.= "<li$separator><a href='#' onClick='document.getElementById(\"actionmenu\").value= \"restore\";document.getElementById(\"exec_act\").click();'><img src='images/lists/restore.png' alt='' border='0' class='center'>&nbsp;"._("Restore snapshots")."</a></li>";
1459       }else{
1460         $result.= "<li$separator><a href='#'><img src='images/lists/restore_grey.png' alt='' border='0' class='center'>&nbsp;"._("Restore snapshots")."</a></li>";
1461       }
1462     }
1464     return($result);
1465   }
1468   function renderExporterMenu($separator)
1469   {
1470     // Presets
1471     $result = "";
1473     // Draw entries
1474     $result.= "<li$separator><a href='#'><img border='0' class='center' src='images/lists/export.png'>&nbsp;"._("Export list")."&nbsp;<img border='0' src='images/forward-arrow.png'></a><ul class='level3'>";
1476     // Export CVS as build in exporter
1477     foreach ($this->exporter as $action => $exporter) {
1478       $result.= "<li><a href='#' onClick='document.getElementById(\"actionmenu\").value= \"$action\";document.getElementById(\"exec_act\").click();'><img border='0' class='center' src='".$exporter['image']."'>&nbsp;".$exporter['label']."</a></li>";
1479     }
1481     // Finalize list
1482     $result.= "</ul></li>";
1484     return($result);
1485   }
1488   function renderSnapshotActions($row, $dn, $category, $class, $copy= true, $cut= true)
1489   {
1490     // We can only provide information if we've got a snapshot handler
1491     // instance
1492     if(!(isset($this->snapshotHandler) && is_object($this->snapshotHandler))){
1493       return "";
1494     }
1496     // Presets
1497     $result= "";
1498     $ui = get_userinfo();
1500     // Only act if enabled here
1501     if($this->snapshotHandler->enabled()){
1503       // Draw restore button
1504       if ($ui->allow_snapshot_restore($dn, $category)){
1506         // Do we have snapshots for this dn?
1507         if($this->snapshotHandler->hasSnapshots($dn)){
1508           $result.= "<input class='center' type='image' src='images/lists/restore.png' ".
1509                      "alt='"._("Restore snapshot")."' name='listing_restore_$row' title='".
1510                      _("Restore snapshot")."' style='padding:1px'>";
1511         } else {
1512           $result.= "<img src='images/lists/restore_grey.png' alt=' ' class='center' style='padding:1px'>";
1513         }
1514       }
1516       // Draw snapshot button
1517       if($ui->allow_snapshot_create($dn, $category)){
1518           $result.= "<input class='center' type='image' src='images/snapshot.png' ".
1519                      "alt='"._("Create snapshot")."' name='listing_snapshot_$row' title='".
1520                      _("Create a new snapshot from this object")."' style='padding:1px'>";
1521       }else{
1522           $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
1523       }
1524     }
1526     return($result);
1527   }
1530   function renderDaemonMenu($separator)
1531   {
1532     $result= "";
1534     // If there is a daemon registered, draw the menu entries
1535     if(class_available("DaemonEvent")){
1536       $events= DaemonEvent::get_event_types_by_category($this->categories);
1537       if(isset($events['BY_CLASS']) && count($events['BY_CLASS'])){
1538         foreach($events['BY_CLASS'] as $name => $event){
1539           $result.= "<li$separator><a href='#' onClick='document.getElementById(\"actionmenu\").value=\"$name\";document.getElementById(\"exec_act\").click();'>".$event['MenuImage']."&nbsp;".$event['s_Menu_Name']."</a></li>";
1540           $separator= "";
1541         }
1542       }
1543     }
1545     return $result;
1546   }
1549   function getEntry($dn)
1550   {
1551     foreach ($this->entries as $entry) {
1552       if (isset($entry['dn']) && strcasecmp($dn, $entry['dn']) == 0){
1553         return $entry;
1554       }
1555     }
1556     return null;
1557   }
1560   function getEntries()
1561   {
1562     return $this->entries;
1563   }
1566   function getType($dn)
1567   {
1568     if (isset($this->objectDnMapping[$dn])) {
1569       return $this->objectDnMapping[$dn];
1570     }
1571     return null;
1572   }
1576 ?>