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= " <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']."&PID=".$this->pid."&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> $sorter</a></td>";
254 } else {
255 $this->header[$index]= "<td class='listheader' ".$this->colprops[$index]."> </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|msie)/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 }
287 $result.= "<table cellpadding='0' cellspacing='0' border='0'><tr><td><div class='listContainer' id='d_scrollbody' style='border-top:1px solid #B0B0B0;border-right:1px solid #B0B0B0;width:700px;min-height:".($height+25)."px;'>\n";
289 $height= "";
290 if ($switch){
291 $height= "height:100%;";
292 }
293 $result.= "<table summary='$this->headline' style='${height}width:100%; table-layout:fixed;' cellspacing='0' cellpadding='0' id='t_scrolltable'>\n";
294 $this->numColumns= count($this->colprops) + ($this->multiSelect?1:0);
296 // Build list header
297 $result.= "<thead class='fixedListHeader listHeaderFormat'><tr>\n";
298 if ($this->multiSelect) {
299 $width= "24px";
300 if (preg_match('/Konqueror/i', $_SERVER['HTTP_USER_AGENT'])){
301 $width= "28px";
302 }
303 $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";
304 }
305 foreach ($this->header as $header) {
306 $result.= $header;
307 }
308 $result.= "</tr></thead>\n";
310 // Build list body
311 $result.= "<tbody class='listScrollContent listBodyFormat' id='t_nscrollbody' style='height:".$height."px;'>\n";
313 // No results? Just take an empty colspanned row
314 if (count($this->entries) + count($this->departments) == 0) {
315 $result.= "<tr class='rowxp0'><td class='list1nohighlight' colspan='$this->numColumns' style='height:100%;border-right:0px;width:100%;'> </td></tr>";
316 }
318 // Line color alternation
319 $alt= 0;
320 $deps= 0;
322 // Draw department browser if configured and we're not in sub mode
323 $this->useSpan= false;
324 if ($this->departmentBrowser && $this->filter->scope != "sub") {
325 // Fill with department browser if configured this way
326 $departmentIterator= new departmentSortIterator($this->departments, $this->sortDirection[$this->sortColumn]);
327 foreach ($departmentIterator as $row => $entry){
328 $result.="<tr class='rowxp".($alt&1)."'>";
330 // Render multi select if needed
331 if ($this->multiSelect) {
332 $result.="<td style='text-align:center;padding:0;' class='list1'> </td>";
333 }
335 // Render defined department columns, fill the rest with some stuff
336 $rest= $this->numColumns - 1;
337 foreach ($this->xmlData['table']['department'] as $index => $config) {
338 $colspan= 1;
339 if (isset($config['span'])){
340 $colspan= $config['span'];
341 $this->useSpan= true;
342 }
343 $result.="<td colspan='$colspan' ".$this->colprops[$index]." class='list1'>".$this->renderCell($config['value'], $entry, $row)."</td>";
344 $rest-= $colspan;
345 }
347 // Fill remaining cols with nothing
348 $last= $this->numColumns - $rest;
349 for ($i= 0; $i<$rest; $i++){
350 $result.= "<td ".$this->colprops[$last+$i-1]." class='list1'> </td>";
351 }
352 $result.="</tr>";
354 $alt++;
355 }
356 $deps= $alt;
357 }
359 // Fill with contents, sort as configured
360 foreach ($this->entries as $row => $entry) {
361 $trow= "";
363 // Render multi select if needed
364 if ($this->multiSelect) {
365 $trow.="<td style='text-align:center;width:20px;' class='list0'><input type='checkbox' id='listing_selected_$row' name='listing_selected_$row'></td>\n";
366 }
368 foreach ($this->xmlData['table']['column'] as $index => $config) {
369 $renderedCell= $this->renderCell($config['value'], $entry, $row);
370 $trow.="<td ".$this->colprops[$index]." class='list0'>".$renderedCell."</td>\n";
372 // Save rendered column
373 $sort= preg_replace('/.*>([^<]+)<.*$/', '$1', $renderedCell);
374 $sort= preg_replace('/ /', '', $sort);
375 if (preg_match('/</', $sort)){
376 $sort= "";
377 }
378 $this->entries[$row]["_sort$index"]= $sort;
379 }
381 // Save rendered entry
382 $this->entries[$row]['_rendered']= $trow;
383 }
385 // Complete list by sorting entries for _sort$index and appending them to the output
386 $entryIterator= new listingSortIterator($this->entries, $this->sortDirection[$this->sortColumn], "_sort".$this->sortColumn, $this->sortType);
387 foreach ($entryIterator as $row => $entry){
388 $alt++;
389 $result.="<tr class='rowxp".($alt&1)."'>\n";
390 $result.= $entry['_rendered'];
391 $result.="</tr>\n";
392 }
394 // Need to fill the list if it's not full (nobody knows why this is 22 ;-))
395 $emptyListStyle= (count($this->entries) + (($this->useSpan && count($this->entries))?$deps:0) == 0)?"border:0;":"";
396 if ((count($this->entries) + $deps) < 22) {
397 $result.= "<tr>";
398 for ($i= 0; $i<$this->numColumns; $i++) {
399 if ($i == 0) {
400 $result.= "<td class='list1nohighlight' style='$emptyListStyle height:100%;'> </td>";
401 continue;
402 }
403 if ($i != $this->numColumns-1) {
404 $result.= "<td class='list1nohighlight' style='$emptyListStyle'> </td>";
405 } else {
406 $result.= "<td class='list1nohighlight' style='border-right:0;$emptyListStyle'> </td>";
407 }
408 }
409 $result.= "</tr>";
410 }
412 // Close list body
413 $result.= "</tbody></table></div></td></tr>";
415 // Add the footer if requested
416 if ($this->showFooter) {
417 $result.= "<tr><td class='nlistFooter'>";
419 foreach ($this->objectTypes as $objectType) {
420 if (isset($this->objectTypeCount[$objectType['label']])) {
421 $label= _($objectType['label']);
422 $result.= "<img class='center' src='".$objectType['image']."' title='$label' alt='$label'> ".$this->objectTypeCount[$objectType['label']]." ";
423 }
424 }
426 $result.= "</td></tr>";
427 }
429 // Close list
430 $result.= "</table>";
431 $result.= $switch?"<input type='hidden' id='list_workaround'>":"";
433 // Add scroll positioner
434 $result.= '<script type="text/javascript" language="javascript">';
435 $result.= '$("t_nscrollbody").scrollTop= '.$this->scrollPosition.';';
436 $result.= 'var box = $("t_nscrollbody").onscroll= function() {$("position_'.$this->pid.'").value= this.scrollTop;}';
437 $result.= '</script>';
439 $smarty= get_smarty();
440 $smarty->assign("usePrototype", "true");
441 $smarty->assign("FILTER", $this->filter->render());
442 $smarty->assign("SIZELIMIT", print_sizelimit_warning());
443 $smarty->assign("LIST", $result);
445 // Assign navigation elements
446 $nav= $this->renderNavigation();
447 foreach ($nav as $key => $html) {
448 $smarty->assign($key, $html);
449 }
451 // Assign action menu / base
452 $smarty->assign("ACTIONS", $this->renderActionMenu());
453 $smarty->assign("BASE", $this->renderBase());
455 // Assign separator
456 $smarty->assign("SEPARATOR", "<img src='images/lists/seperator.png' alt='-' align='middle' height='16' width='1' class='center'>");
458 // Assign summary
459 $smarty->assign("HEADLINE", $this->headline);
461 // Try to load template from plugin the folder first...
462 $file = get_template_path($this->xmlData['definition']['template'], true);
464 // ... if this fails, try to load the file from the theme folder.
465 if(!file_exists($file)){
466 $file = get_template_path($this->xmlData['definition']['template']);
467 }
469 return ($smarty->fetch($file));
470 }
473 function update()
474 {
475 global $config;
476 $ui= get_userinfo();
478 // Take care of base selector
479 if ($this->baseMode) {
480 $this->baseSelector->update();
481 }
483 // Save base
484 $refresh= false;
485 if ($this->baseMode) {
486 $this->base= $this->baseSelector->getBase();
487 session::global_set("CurrentMainBase", $this->base);
488 $refresh= true;
489 }
492 // Reset object counter / DN mapping
493 $this->objectTypeCount= array();
494 $this->objectDnMapping= array();
496 // Do not do anything if this is not our PID
497 if($refresh || !(isset($_REQUEST['PID']) && $_REQUEST['PID'] != $this->pid)) {
499 // Save position if set
500 if (isset($_POST['position_'.$this->pid]) && is_numeric($_POST['position_'.$this->pid])) {
501 $this->scrollPosition= $_POST['position_'.$this->pid];
502 }
504 // Override the base if we got a message from the browser navigation
505 if ($this->departmentBrowser && isset($_GET['act'])) {
506 if (preg_match('/^department_([0-9]+)$/', validate($_GET['act']), $match)){
507 if (isset($this->departments[$match[1]])){
508 $this->base= $this->departments[$match[1]]['dn'];
509 if ($this->baseMode) {
510 $this->baseSelector->setBase($this->base);
511 }
512 session::global_set("CurrentMainBase", $this->base);
513 }
514 }
515 }
517 // Filter POST with "act" attributes -> posted from action menu
518 if (isset($_POST['exec_act']) && $_POST['act'] != '') {
519 if (preg_match('/^export.*$/', $_POST['act']) && isset($this->exporter[$_POST['act']])) {
520 $exporter= $this->exporter[$_POST['act']];
521 $userinfo= ", "._("created by")." ".$ui->cn." - ".strftime('%A, %d. %B %Y, %H:%M:%S');
522 $entryIterator= new listingSortIterator($this->entries, $this->sortDirection[$this->sortColumn], "_sort".$this->sortColumn, $this->sortType);
523 $sortedEntries= array();
524 foreach ($entryIterator as $entry){
525 $sortedEntries[]= $entry;
526 }
527 $instance= new $exporter['class']($this->headline.$userinfo, $this->plainHeader, $sortedEntries, $this->exportColumns);
528 $type= call_user_func(array($exporter['class'], "getInfo"));
529 $type= $type[$_POST['act']];
530 send_binary_content($instance->query(), $type['filename'], $type= $type['mime']);
531 }
532 }
534 // Filter GET with "act" attributes
535 if (isset($_GET['act'])) {
536 $key= validate($_GET['act']);
537 if (preg_match('/^SORT_([0-9]+)$/', $key, $match)) {
538 // Switch to new column or invert search order?
539 $column= $match[1];
540 if ($this->sortColumn != $column) {
541 $this->sortColumn= $column;
542 } else {
543 $this->sortDirection[$column]= !$this->sortDirection[$column];
544 }
546 // Allow header to update itself according to the new sort settings
547 $this->renderHeader();
548 }
549 }
551 // Override base if we got signals from the navigation elements
552 $action= "";
553 foreach ($_POST as $key => $value) {
554 if (preg_match('/^(ROOT|BACK|HOME)_x$/', $key, $match)) {
555 $action= $match[1];
556 break;
557 }
558 }
560 // Navigation handling
561 if ($action == 'ROOT') {
562 $deps= $ui->get_module_departments($this->categories);
563 $this->base= $deps[0];
564 $this->baseSelector->setBase($this->base);
565 }
566 if ($action == 'BACK') {
567 $deps= $ui->get_module_departments($this->categories);
568 $base= preg_replace("/^[^,]+,/", "", $this->base);
569 if(in_array_ics($base, $deps)){
570 $this->base= $base;
571 $this->baseSelector->setBase($this->base);
572 }
573 }
574 if ($action == 'HOME') {
575 $ui= get_userinfo();
576 $this->base= $this->filter->getObjectBase($ui->dn);
577 $this->baseSelector->setBase($this->base);
578 }
579 }
581 // Reload departments
582 if ($this->departmentBrowser){
583 $this->departments= $this->getDepartments();
584 }
586 // Update filter and refresh entries
587 $this->filter->setBase($this->base);
588 $this->entries= $this->filter->query();
590 // Fix filter if querie returns NULL
591 if ($this->entries == null) {
592 $this->entries= array();
593 }
594 }
597 function setBase($base)
598 {
599 $this->base= $base;
600 if ($this->baseMode) {
601 $this->baseSelector->setBase($this->base);
602 }
603 }
606 function getBase()
607 {
608 return $this->base;
609 }
612 function parseLayout($layout)
613 {
614 $result= array();
615 $layout= preg_replace("/^\|/", "", $layout);
616 $layout= preg_replace("/\|$/", "", $layout);
617 $cols= explode("|", $layout);
619 foreach ($cols as $index => $config) {
620 if ($config != "") {
621 $res= "";
622 $components= explode(';', $config);
623 foreach ($components as $part) {
624 if (preg_match("/^r$/", $part)) {
625 $res.= "text-align:right;";
626 continue;
627 }
628 if (preg_match("/^l$/", $part)) {
629 $res.= "text-align:left;";
630 continue;
631 }
632 if (preg_match("/^c$/", $part)) {
633 $res.= "text-align:center;";
634 continue;
635 }
636 if (preg_match("/^[0-9]+(|px|%)$/", $part)) {
637 $res.= "width:$part;min-width:$part;";
638 continue;
639 }
640 }
642 // Add minimum width for scalable columns
643 if (!preg_match('/width:/', $res)){
644 $res.= "min-width:200px;";
645 }
647 $result[$index]= " style='$res'";
648 } else {
649 $result[$index]= " style='min-width:100px;'";
650 }
651 }
653 // Save number of columns for later use
654 $this->numColumns= count($cols);
656 // Add no border to the last column
657 $result[$this->numColumns-1]= preg_replace("/'$/", "border-right:0;'", $result[$this->numColumns-1]);
659 return $result;
660 }
663 function renderCell($data, $config, $row)
664 {
665 // Replace flat attributes in data string
666 for ($i= 0; $i<$config['count']; $i++) {
667 $attr= $config[$i];
668 $value= "";
669 if (is_array($config[$attr])) {
670 $value= $config[$attr][0];
671 } else {
672 $value= $config[$attr];
673 }
674 $data= preg_replace("/%\{$attr\}/", $value, $data);
675 }
677 // Watch out for filters and prepare to execute them
678 $data= $this->processElementFilter($data, $config, $row);
680 // Replace all non replaced %{...} instances because they
681 // are non resolved attributes or filters
682 $data= preg_replace('/%{[^}]+}/', ' ', $data);
684 return $data;
685 }
688 function renderBase()
689 {
690 if (!$this->baseMode) {
691 return;
692 }
694 return $this->baseSelector->render();
695 }
698 function processElementFilter($data, $config, $row)
699 {
700 preg_match_all("/%\{filter:([^(]+)\((.*)\)\}/", $data, $matches, PREG_SET_ORDER);
702 foreach ($matches as $match) {
703 $cl= "";
704 $method= "";
705 if (preg_match('/::/', $match[1])) {
706 $cl= preg_replace('/::.*$/', '', $match[1]);
707 $method= preg_replace('/^.*::/', '', $match[1]);
708 } else {
709 if (!isset($this->filters[$match[1]])) {
710 continue;
711 }
712 $cl= preg_replace('/::.*$/', '', $this->filters[$match[1]]);
713 $method= preg_replace('/^.*::/', '', $this->filters[$match[1]]);
714 }
716 // Prepare params for function call
717 $params= array();
718 preg_match_all('/"[^"]+"|[^,]+/', $match[2], $parts);
719 foreach ($parts[0] as $param) {
721 // Row is replaced by the row number
722 if ($param == "row") {
723 $params[]= $row;
724 continue;
725 }
727 // pid is replaced by the current PID
728 if ($param == "pid") {
729 $params[]= $this->pid;
730 continue;
731 }
733 // base is replaced by the current base
734 if ($param == "base") {
735 $params[]= $this->getBase();
736 continue;
737 }
739 // Fixie with "" is passed directly
740 if (preg_match('/^".*"$/', $param)){
741 $params[]= preg_replace('/"/', '', $param);
742 continue;
743 }
745 // Move dn if needed
746 if ($param == "dn") {
747 $params[]= LDAP::fix($config["dn"]);
748 continue;
749 }
751 // LDAP variables get replaced by their objects
752 for ($i= 0; $i<$config['count']; $i++) {
753 if ($param == $config[$i]) {
754 $values= $config[$config[$i]];
755 if (is_array($values)){
756 unset($values['count']);
757 }
758 $params[]= $values;
759 break;
760 }
761 }
762 }
764 // Replace information
765 if ($cl == "listing") {
766 // Non static call - seems to result in errors
767 $data= @preg_replace('/'.preg_quote($match[0]).'/', call_user_func_array(array($this, "$method"), $params), $data);
768 } else {
769 // Static call
770 $data= preg_replace('/'.preg_quote($match[0]).'/', call_user_func_array(array($cl, $method), $params), $data);
771 }
772 }
774 return $data;
775 }
778 function getObjectType($types, $classes)
779 {
780 // Walk thru types and see if there's something matching
781 foreach ($types as $objectType) {
782 $ocs= $objectType['objectClass'];
783 if (!is_array($ocs)){
784 $ocs= array($ocs);
785 }
787 $found= true;
788 foreach ($ocs as $oc){
789 if (preg_match('/^!(.*)$/', $oc, $match)) {
790 $oc= $match[1];
791 if (in_array($oc, $classes)) {
792 $found= false;
793 }
794 } else {
795 if (!in_array($oc, $classes)) {
796 $found= false;
797 }
798 }
799 }
801 if ($found) {
802 return $objectType;
803 }
804 }
806 return null;
807 }
810 function filterObjectType($dn, $classes)
811 {
812 // Walk thru classes and return on first match
813 $result= " ";
815 $objectType= $this->getObjectType($this->objectTypes, $classes);
816 if ($objectType) {
817 $this->objectDnMapping[$dn]= $objectType["objectClass"];
818 $result= "<img class='center' title='".LDAP::fix($dn)."' src='".$objectType["image"]."'>";
819 if (!isset($this->objectTypeCount[$objectType['label']])) {
820 $this->objectTypeCount[$objectType['label']]= 0;
821 }
822 $this->objectTypeCount[$objectType['label']]++;
823 }
825 return $result;
826 }
829 function filterActions($dn, $row, $classes)
830 {
831 // Do nothing if there's no menu defined
832 if (!isset($this->xmlData['actiontriggers']['action'])) {
833 return " ";
834 }
836 // Go thru all actions
837 $result= "";
838 $actions= $this->xmlData['actiontriggers']['action'];
839 foreach($actions as $action) {
840 // Skip the entry completely if there's no permission to execute it
841 if (!$this->hasActionPermission($action, $dn, $classes)) {
842 $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
843 continue;
844 }
846 // Skip entry if the pseudo filter does not fit
847 if (isset($action['filter']) && preg_match('/^[a-z0-9_]+!?=[a-z0-9_]+$/i', $action['filter'])) {
848 list($fa, $fv)= explode('=', $action['filter']);
849 if (preg_match('/^(.*)!$/', $fa, $m)){
850 $fa= $m[1];
851 if (isset($this->entries[$row][$fa]) && $this->entries[$row][$fa][0] == $fv) {
852 $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
853 continue;
854 }
855 } else {
856 if (!isset($this->entries[$row][$fa]) && !$this->entries[$row][$fa][0] == $fv) {
857 $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
858 continue;
859 }
860 }
861 }
864 // If there's an objectclass definition and we don't have it
865 // add an empty picture here.
866 if (isset($action['objectclass'])){
867 $objectclass= $action['objectclass'];
868 if (preg_match('/^!(.*)$/', $objectclass, $m)){
869 $objectclass= $m[1];
870 if(in_array($objectclass, $classes)) {
871 $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
872 continue;
873 }
874 } elseif (is_string($objectclass)) {
875 if(!in_array($objectclass, $classes)) {
876 $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
877 continue;
878 }
879 } elseif (is_array($objectclass)) {
880 if(count(array_intersect($objectclass, $classes)) != count($objectclass)){
881 $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
882 continue;
883 }
884 }
885 }
887 // Render normal entries as usual
888 if ($action['type'] == "entry") {
889 $label= $this->processElementFilter($action['label'], $this->entries[$row], $row);
890 $image= $this->processElementFilter($action['image'], $this->entries[$row], $row);
891 $result.="<input class='center' type='image' src='$image' title='$label' ".
892 "name='listing_".$action['name']."_$row' style='padding:1px'>";
893 }
895 // Handle special types
896 if ($action['type'] == "copypaste" || $action['type'] == "snapshot") {
898 $objectType= $this->getObjectType($this->objectTypes, $this->entries[$row]['objectClass']);
899 $category= $class= null;
900 if ($objectType) {
901 $category= $objectType['category'];
902 $class= $objectType['class'];
903 }
905 if ($action['type'] == "copypaste") {
906 $copy = !isset($action['copy']) || $action['copy'] == "true";
907 $cut = !isset($action['cut']) || $action['cut'] == "true";
908 $result.= $this->renderCopyPasteActions($row, $this->entries[$row]['dn'], $category, $class,$copy,$cut);
909 } else {
910 $result.= $this->renderSnapshotActions($row, $this->entries[$row]['dn'], $category, $class);
911 }
912 }
913 }
915 return $result;
916 }
919 function filterDepartmentLink($row, $dn, $description)
920 {
921 $attr= $this->departments[$row]['sort-attribute'];
922 $name= $this->departments[$row][$attr];
923 if (is_array($name)){
924 $name= $name[0];
925 }
926 $result= sprintf("%s [%s]", $name, $description[0]);
927 return("<a href='?plug=".$_GET['plug']."&PID=$this->pid&act=department_$row' title='$dn'>$result</a>");
928 }
931 function filterLink()
932 {
933 $result= " ";
935 $row= func_get_arg(0);
936 $pid= $this->pid;
937 $dn= LDAP::fix(func_get_arg(1));
938 $params= array(func_get_arg(2));
940 // Collect sprintf params
941 for ($i = 3;$i < func_num_args();$i++) {
942 $val= func_get_arg($i);
943 if (is_array($val)){
944 $params[]= $val[0];
945 continue;
946 }
947 $params[]= $val;
948 }
950 $result= " ";
951 $trans= call_user_func_array("sprintf", $params);
952 if ($trans != "") {
953 return("<a href='?plug=".$_GET['plug']."&PID=$pid&act=listing_edit_$row' title='$dn'>$trans</a>");
954 }
956 return $result;
957 }
960 function renderNavigation()
961 {
962 $result= array();
963 $enableBack = true;
964 $enableRoot = true;
965 $enableHome = true;
967 $ui = get_userinfo();
969 /* Check if base = first available base */
970 $deps = $ui->get_module_departments($this->categories);
972 if(!count($deps) || $deps[0] == $this->filter->base){
973 $enableBack = false;
974 $enableRoot = false;
975 }
977 $listhead ="";
979 /* Check if we are in users home department */
980 if(!count($deps) || $this->filter->base == $this->filter->getObjectBase($ui->dn)){
981 $enableHome = false;
982 }
984 /* Draw root button */
985 if($enableRoot){
986 $result["ROOT"]= "<input class='center' type='image' src='images/lists/root.png' align='middle' ".
987 "title='"._("Go to root department")."' name='ROOT' alt='"._("Root")."'>";
988 }else{
989 $result["ROOT"]= "<img src='images/lists/root_grey.png' class='center' alt='"._("Root")."'>";
990 }
992 /* Draw back button */
993 if($enableBack){
994 $result["BACK"]= "<input class='center' type='image' align='middle' src='images/lists/back.png' ".
995 "title='"._("Go up one department")."' alt='"._("Up")."' name='BACK'>";
996 }else{
997 $result["BACK"]= "<img src='images/lists/back_grey.png' class='center' alt='"._("Up")."'>";
998 }
1000 /* Draw home button */
1001 if($enableHome){
1002 $result["HOME"]= "<input class='center' type='image' align='middle' src='images/lists/home.png' ".
1003 "title='"._("Go to users department")."' alt='"._("Home")."' name='HOME'>";
1004 }else{
1005 $result["HOME"]= "<img src='images/lists/home_grey.png' class='center' alt='"._("Home")."'>";
1006 }
1008 /* Draw reload button, this button is enabled everytime */
1009 $result["RELOAD"]= "<input class='center' type='image' src='images/lists/reload.png' align='middle' ".
1010 "title='"._("Reload list")."' name='REFRESH' alt='"._("Submit")."'>";
1012 return ($result);
1013 }
1016 function getAction()
1017 {
1018 // Do not do anything if this is not our PID, or there's even no PID available...
1019 if(!isset($_REQUEST['PID']) || $_REQUEST['PID'] != $this->pid) {
1020 return;
1021 }
1023 // Save position if set
1024 if (isset($_POST['position_'.$this->pid]) && is_numeric($_POST['position_'.$this->pid])) {
1025 $this->scrollPosition= $_POST['position_'.$this->pid];
1026 }
1028 $result= array("targets" => array(), "action" => "");
1030 // Filter GET with "act" attributes
1031 if (isset($_GET['act'])) {
1032 $key= validate($_GET['act']);
1033 $target= preg_replace('/^listing_[a-zA-Z_]+_([0-9]+)$/', '$1', $key);
1034 if (isset($this->entries[$target]['dn'])) {
1035 $result['action']= preg_replace('/^listing_([a-zA-Z_]+)_[0-9]+$/', '$1', $key);
1036 $result['targets'][]= $this->entries[$target]['dn'];
1037 }
1039 // Drop targets if empty
1040 if (count($result['targets']) == 0) {
1041 unset($result['targets']);
1042 }
1043 return $result;
1044 }
1046 // Filter POST with "listing_" attributes
1047 foreach ($_POST as $key => $prop) {
1049 // Capture selections
1050 if (preg_match('/^listing_selected_[0-9]+$/', $key)) {
1051 $target= preg_replace('/^listing_selected_([0-9]+)$/', '$1', $key);
1052 if (isset($this->entries[$target]['dn'])) {
1053 $result['targets'][]= $this->entries[$target]['dn'];
1054 }
1055 continue;
1056 }
1058 // Capture action with target - this is a one shot
1059 if (preg_match('/^listing_[a-zA-Z_]+_[0-9]+(|_x)$/', $key)) {
1060 $target= preg_replace('/^listing_[a-zA-Z_]+_([0-9]+)(|_x)$/', '$1', $key);
1061 if (isset($this->entries[$target]['dn'])) {
1062 $result['action']= preg_replace('/^listing_([a-zA-Z_]+)_[0-9]+(|_x)$/', '$1', $key);
1063 $result['targets']= array($this->entries[$target]['dn']);
1064 }
1065 break;
1066 }
1068 // Capture action without target
1069 if (preg_match('/^listing_[a-zA-Z_]+(|_x)$/', $key)) {
1070 $result['action']= preg_replace('/^listing_([a-zA-Z_]+)(|_x)$/', '$1', $key);
1071 continue;
1072 }
1073 }
1075 // Filter POST with "act" attributes -> posted from action menu
1076 if (isset($_POST['act']) && $_POST['act'] != '') {
1077 if (!preg_match('/^export.*$/', $_POST['act'])){
1078 $result['action']= validate($_POST['act']);
1079 }
1080 }
1082 // Drop targets if empty
1083 if (count($result['targets']) == 0) {
1084 unset($result['targets']);
1085 }
1086 return $result;
1087 }
1090 function renderActionMenu()
1091 {
1092 // Don't send anything if the menu is not defined
1093 if (!isset($this->xmlData['actionmenu']['action'])){
1094 return "";
1095 }
1097 // Array?
1098 if (isset($this->xmlData['actionmenu']['action']['type'])){
1099 $this->xmlData['actionmenu']['action']= array($this->xmlData['actionmenu']['action']);
1100 }
1102 // Load shortcut
1103 $actions= &$this->xmlData['actionmenu']['action'];
1104 $result= "<input type='hidden' name='act' id='actionmenu' value=''><div style='display:none'><input type='submit' name='exec_act' id='exec_act' value=''></div>".
1105 "<ul class='level1' id='root'><li><a href='#'>"._("Actions")." <img ".
1106 "border=0 class='center' src='images/lists/sort-down.png'></a>";
1108 // Build ul/li list
1109 $result.= $this->recurseActions($actions);
1111 return "<div id='pulldown'>".$result."</li></ul><div>";
1112 }
1115 function recurseActions($actions)
1116 {
1117 global $class_mapping;
1118 static $level= 2;
1119 $result= "<ul class='level$level'>";
1120 $separator= "";
1122 foreach ($actions as $action) {
1124 // Skip the entry completely if there's no permission to execute it
1125 if (!$this->hasActionPermission($action, $this->filter->base)) {
1126 continue;
1127 }
1129 // Skip entry if there're missing dependencies
1130 if (isset($action['depends'])) {
1131 $deps= is_array($action['depends'])?$action['depends']:array($action['depends']);
1132 foreach($deps as $clazz) {
1133 if (!isset($class_mapping[$clazz])){
1134 continue 2;
1135 }
1136 }
1137 }
1139 // Fill image if set
1140 $img= "";
1141 if (isset($action['image'])){
1142 $img= "<img border='0' class='center' src='".$action['image']."'> ";
1143 }
1145 if ($action['type'] == "separator"){
1146 $separator= " style='border-top:1px solid #AAA' ";
1147 continue;
1148 }
1150 // Dive into subs
1151 if ($action['type'] == "sub" && isset($action['action'])) {
1152 $level++;
1153 if (isset($action['label'])){
1154 $result.= "<li$separator><a href='#'>$img"._($action['label'])." <img border='0' src='images/forward-arrow.png'></a>";
1155 }
1157 // Ensure we've an array of actions, this enables sub menus with only one action.
1158 if(isset($action['action']['type'])){
1159 $action['action'] = array($action['action']);
1160 }
1162 $result.= $this->recurseActions($action['action'])."</li>";
1163 $level--;
1164 $separator= "";
1165 continue;
1166 }
1168 // Render entry elseways
1169 if (isset($action['label'])){
1170 $result.= "<li$separator><a href='#' onClick='document.getElementById(\"actionmenu\").value= \"".$action['name']."\";mainform.submit();'>$img"._($action['label'])."</a></li>";
1171 }
1173 // Check for special types
1174 switch ($action['type']) {
1175 case 'copypaste':
1176 $cut = !isset($action['cut']) || $action['cut'] != "false";
1177 $copy = !isset($action['copy']) || $action['copy'] != "false";
1178 $result.= $this->renderCopyPasteMenu($separator, $copy , $cut);
1179 break;
1181 case 'snapshot':
1182 $result.= $this->renderSnapshotMenu($separator);
1183 break;
1185 case 'exporter':
1186 $result.= $this->renderExporterMenu($separator);
1187 break;
1189 case 'daemon':
1190 $result.= $this->renderDaemonMenu($separator);
1191 break;
1192 }
1194 $separator= "";
1195 }
1197 $result.= "</ul>";
1198 return $result;
1199 }
1202 function hasActionPermission($action, $dn, $classes= null)
1203 {
1204 $ui= get_userinfo();
1206 if (isset($action['acl'])) {
1207 $acls= $action['acl'];
1208 if (!is_array($acls)) {
1209 $acls= array($acls);
1210 }
1212 // Every ACL has to pass
1213 foreach ($acls as $acl) {
1214 $module= $this->categories;
1215 $aclList= array();
1217 // Replace %acl if available
1218 if ($classes) {
1219 $otype= $this->getObjectType($this->objectTypes, $classes);
1220 $acl= str_replace('%acl', $otype['category']."/".$otype['class'], $acl);
1221 }
1223 // Split for category and plugins if needed
1224 // match for "[rw]" style entries
1225 if (preg_match('/^\[([rwcdm]+)\]$/', $acl, $match)){
1226 $aclList= array($match[1]);
1227 }
1229 // match for "users[rw]" style entries
1230 if (preg_match('/^([a-zA-Z0-9]+)\[([rwcdm]+)\]$/', $acl, $match)){
1231 $module= $match[1];
1232 $aclList= array($match[2]);
1233 }
1235 // match for "users/user[rw]" style entries
1236 if (preg_match('/^([a-zA-Z0-9]+\/[a-zA-Z0-9]+)\[([rwcdm]+)\]$/', $acl, $match)){
1237 $module= $match[1];
1238 $aclList= array($match[2]);
1239 }
1241 // match "users/user[userPassword:rw(,...)*]" style entries
1242 if (preg_match('/^([a-zA-Z0-9]+\/[a-zA-Z0-9]+)\[([a-zA-Z0-9]+:[rwcdm]+(,[a-zA-Z0-9]+:[rwcdm]+)*)\]$/', $acl, $match)){
1243 $module= $match[1];
1244 $aclList= explode(',', $match[2]);
1245 }
1247 // Walk thru prepared ACL by using $module
1248 foreach($aclList as $sAcl) {
1249 $checkAcl= "";
1251 // Category or detailed permission?
1252 if (strpos('/', $module) === false) {
1253 if (preg_match('/([a-zA-Z0-9]+):([rwcdm]+)/', $sAcl, $m) ) {
1254 $checkAcl= $ui->get_permissions($dn, $module, $m[1]);
1255 $sAcl= $m[2];
1256 } else {
1257 $checkAcl= $ui->get_permissions($dn, $module, '0');
1258 }
1259 } else {
1260 $checkAcl= $ui->get_category_permissions($dn, $module);
1261 }
1263 // Split up remaining part of the acl and check if it we're
1264 // allowed to do something...
1265 $parts= str_split($sAcl);
1266 foreach ($parts as $part) {
1267 if (strpos($checkAcl, $part) === false){
1268 return false;
1269 }
1270 }
1272 }
1273 }
1274 }
1276 return true;
1277 }
1280 function refreshBasesList()
1281 {
1282 global $config;
1283 $ui= get_userinfo();
1285 // Do some array munching to get it user friendly
1286 $ids= $config->idepartments;
1287 $d= $ui->get_module_departments($this->categories);
1288 $k_ids= array_keys($ids);
1289 $deps= array_intersect($d,$k_ids);
1291 // Fill internal bases list
1292 $this->bases= array();
1293 foreach($k_ids as $department){
1294 $this->bases[$department] = $ids[$department];
1295 }
1297 // Populate base selector if already present
1298 if ($this->baseSelector && $this->baseMode) {
1299 $this->baseSelector->setBases($this->bases);
1300 }
1301 }
1304 function getDepartments()
1305 {
1306 $departments= array();
1307 $ui= get_userinfo();
1309 // Get list of supported department types
1310 $types = departmentManagement::get_support_departments();
1312 // Load departments allowed by ACL
1313 $validDepartments = $ui->get_module_departments($this->categories);
1315 // Build filter and look in the LDAP for possible sub departments
1316 // of current base
1317 $filter= "(&(objectClass=gosaDepartment)(|";
1318 $attrs= array("description", "objectClass");
1319 foreach($types as $name => $data){
1320 $filter.= "(objectClass=".$data['OC'].")";
1321 $attrs[]= $data['ATTR'];
1322 }
1323 $filter.= "))";
1324 $res= get_list($filter, $this->categories, $this->base, $attrs, GL_NONE);
1326 // Analyze list of departments
1327 foreach ($res as $department) {
1328 if (!in_array($department['dn'], $validDepartments)) {
1329 continue;
1330 }
1332 // Add the attribute where we use for sorting
1333 $oc= null;
1334 foreach(array_keys($types) as $type) {
1335 if (in_array($type, $department['objectClass'])) {
1336 $oc= $type;
1337 break;
1338 }
1339 }
1340 $department['sort-attribute']= $types[$oc]['ATTR'];
1342 // Move to the result list
1343 $departments[]= $department;
1344 }
1346 return $departments;
1347 }
1350 function renderCopyPasteMenu($separator, $copy= true, $cut= true)
1351 {
1352 // We can only provide information if we've got a copypaste handler
1353 // instance
1354 if(!(isset($this->copyPasteHandler) && is_object($this->copyPasteHandler))){
1355 return "";
1356 }
1358 // Presets
1359 $result= "";
1360 $read= $paste= false;
1361 $ui= get_userinfo();
1363 // Switch flags to on if there's at least one category which allows read/paste
1364 foreach($this->categories as $category){
1365 $read= $read || preg_match('/r/', $ui->get_category_permissions($this->base, $category));
1366 $paste= $paste || $ui->is_pasteable($this->base, $category) == 1;
1367 }
1370 // Draw entries that allow copy and cut
1371 if($read){
1373 // Copy entry
1374 if($copy){
1375 $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'> "._("Copy")."</a></li>";
1376 $separator= "";
1377 }
1379 // Cut entry
1380 if($cut){
1381 $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'> "._("Cut")."</a></li>";
1382 $separator= "";
1383 }
1384 }
1386 // Draw entries that allow pasting entries
1387 if($paste){
1388 if($this->copyPasteHandler->entries_queued()){
1389 $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'> "._("Paste")."</a></li>";
1390 }else{
1391 $result.= "<li$separator><a href='#'><img src='images/lists/paste-grey.png' alt='' border='0' class='center'> "._("Paste")."</a></li>";
1392 }
1393 }
1395 return($result);
1396 }
1399 function renderCopyPasteActions($row, $dn, $category, $class, $copy= true, $cut= true)
1400 {
1401 // We can only provide information if we've got a copypaste handler
1402 // instance
1403 if(!(isset($this->copyPasteHandler) && is_object($this->copyPasteHandler))){
1404 return "";
1405 }
1407 // Presets
1408 $ui = get_userinfo();
1409 $result = "";
1411 // Render cut entries
1412 if($cut){
1413 if($ui->is_cutable($dn, $category, $class)){
1414 $result .= "<input class='center' type='image'
1415 src='images/lists/cut.png' alt='"._("Cut")."' name='listing_cut_$row' title='"._("Cut this entry")."' style='padding:1px'>";
1416 }else{
1417 $result.="<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
1418 }
1419 }
1421 // Render copy entries
1422 if($copy){
1423 if($ui->is_copyable($dn, $category, $class)){
1424 $result.= "<input class='center' type='image'
1425 src='images/lists/copy.png' alt='"._("Copy")."' name='listing_copy_$row' title='"._("Copy this entry")."' style='padding:1px'>";
1426 }else{
1427 $result.="<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
1428 }
1429 }
1431 return($result);
1432 }
1435 function renderSnapshotMenu($separator)
1436 {
1437 // We can only provide information if we've got a snapshot handler
1438 // instance
1439 if(!(isset($this->snapshotHandler) && is_object($this->snapshotHandler))){
1440 return "";
1441 }
1443 // Presets
1444 $result = "";
1445 $ui = get_userinfo();
1447 if($this->snapshotHandler->enabled() && $ui->allow_snapshot_restore($this->base, $this->categories)){
1449 // Check if there is something to restore
1450 $restore= false;
1451 foreach($this->snapshotHandler->getSnapshotBases() as $base){
1452 $restore= $restore || count($this->snapshotHandler->getDeletedSnapshots($base)) > 0;
1453 }
1455 // Draw icons according to the restore flag
1456 if($restore){
1457 $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'> "._("Restore snapshots")."</a></li>";
1458 }else{
1459 $result.= "<li$separator><a href='#'><img src='images/lists/restore_grey.png' alt='' border='0' class='center'> "._("Restore snapshots")."</a></li>";
1460 }
1461 }
1463 return($result);
1464 }
1467 function renderExporterMenu($separator)
1468 {
1469 // Presets
1470 $result = "";
1472 // Draw entries
1473 $result.= "<li$separator><a href='#'><img border='0' class='center' src='images/lists/export.png'> "._("Export list")." <img border='0' src='images/forward-arrow.png'></a><ul class='level3'>";
1475 // Export CVS as build in exporter
1476 foreach ($this->exporter as $action => $exporter) {
1477 $result.= "<li><a href='#' onClick='document.getElementById(\"actionmenu\").value= \"$action\";document.getElementById(\"exec_act\").click();'><img border='0' class='center' src='".$exporter['image']."'> ".$exporter['label']."</a></li>";
1478 }
1480 // Finalize list
1481 $result.= "</ul></li>";
1483 return($result);
1484 }
1487 function renderSnapshotActions($row, $dn, $category, $class, $copy= true, $cut= true)
1488 {
1489 // We can only provide information if we've got a snapshot handler
1490 // instance
1491 if(!(isset($this->snapshotHandler) && is_object($this->snapshotHandler))){
1492 return "";
1493 }
1495 // Presets
1496 $result= "";
1497 $ui = get_userinfo();
1499 // Only act if enabled here
1500 if($this->snapshotHandler->enabled()){
1502 // Draw restore button
1503 if ($ui->allow_snapshot_restore($dn, $category)){
1505 // Do we have snapshots for this dn?
1506 if($this->snapshotHandler->hasSnapshots($dn)){
1507 $result.= "<input class='center' type='image' src='images/lists/restore.png' ".
1508 "alt='"._("Restore snapshot")."' name='listing_restore_$row' title='".
1509 _("Restore snapshot")."' style='padding:1px'>";
1510 } else {
1511 $result.= "<img src='images/lists/restore_grey.png' alt=' ' class='center' style='padding:1px'>";
1512 }
1513 }
1515 // Draw snapshot button
1516 if($ui->allow_snapshot_create($dn, $category)){
1517 $result.= "<input class='center' type='image' src='images/snapshot.png' ".
1518 "alt='"._("Create snapshot")."' name='listing_snapshot_$row' title='".
1519 _("Create a new snapshot from this object")."' style='padding:1px'>";
1520 }else{
1521 $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
1522 }
1523 }
1525 return($result);
1526 }
1529 function renderDaemonMenu($separator)
1530 {
1531 $result= "";
1533 // If there is a daemon registered, draw the menu entries
1534 if(class_available("DaemonEvent")){
1535 $events= DaemonEvent::get_event_types_by_category($this->categories);
1536 if(isset($events['BY_CLASS']) && count($events['BY_CLASS'])){
1537 foreach($events['BY_CLASS'] as $name => $event){
1538 $result.= "<li$separator><a href='#' onClick='document.getElementById(\"actionmenu\").value=\"$name\";document.getElementById(\"exec_act\").click();'>".$event['MenuImage']." ".$event['s_Menu_Name']."</a></li>";
1539 $separator= "";
1540 }
1541 }
1542 }
1544 return $result;
1545 }
1548 function getEntry($dn)
1549 {
1550 foreach ($this->entries as $entry) {
1551 if (isset($entry['dn']) && strcasecmp($dn, $entry['dn']) == 0){
1552 return $entry;
1553 }
1554 }
1555 return null;
1556 }
1559 function getEntries()
1560 {
1561 return $this->entries;
1562 }
1565 function getType($dn)
1566 {
1567 if (isset($this->objectDnMapping[$dn])) {
1568 return $this->objectDnMapping[$dn];
1569 }
1570 return null;
1571 }
1573 }
1575 ?>