75fe5cd42c941fb169a730cc5fa3b1cb19cffe89
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 getFilter()
125 {
126 return($this->filter);
127 }
130 function setFilter($filter)
131 {
132 $this->filter= &$filter;
133 if ($this->departmentBrowser){
134 $this->departments= $this->getDepartments();
135 }
136 $this->filter->setBase($this->base);
137 }
140 function registerElementFilter($name, $call)
141 {
142 if (!isset($this->filters[$name])) {
143 $this->filters[$name]= $call;
144 return true;
145 }
147 return false;
148 }
151 function load($filename)
152 {
153 $contents = file_get_contents($filename);
154 $this->xmlData= xml::xml2array($contents, 1);
156 if (!isset($this->xmlData['list'])) {
157 return false;
158 }
160 $this->xmlData= $this->xmlData["list"];
162 // Load some definition values
163 foreach (array("departmentBrowser", "departmentRootVisible", "multiSelect", "baseMode") as $token) {
164 if (isset($this->xmlData['definition'][$token]) &&
165 $this->xmlData['definition'][$token] == "true"){
166 $this->$token= true;
167 }
168 }
170 // Fill objectTypes from departments and xml definition
171 $types = departmentManagement::get_support_departments();
172 foreach ($types as $class => $data) {
173 $this->objectTypes[$data['OC']]= array("label" => $data['TITLE'],
174 "objectClass" => $data['OC'],
175 "image" => $data['IMG']);
176 }
177 $this->categories= array();
178 if (isset($this->xmlData['definition']['objectType'])) {
179 if(isset($this->xmlData['definition']['objectType']['label'])) {
180 $this->xmlData['definition']['objectType']= array($this->xmlData['definition']['objectType']);
181 }
182 foreach ($this->xmlData['definition']['objectType'] as $index => $otype) {
183 $tmp = $this->xmlData['definition']['objectType'][$index];
184 $this->objectTypes[$tmp['objectClass']]= $tmp;
185 if (isset($this->xmlData['definition']['objectType'][$index]['category'])){
186 $this->categories[]= $otype['category'];
187 }
188 }
189 }
190 $this->objectTypes = array_values($this->objectTypes);
192 // Parse layout per column
193 $this->colprops= $this->parseLayout($this->xmlData['table']['layout']);
195 // Prepare table headers
196 $this->renderHeader();
198 // Assign headline/Categories
199 $this->headline= _($this->xmlData['definition']['label']);
200 if (!is_array($this->categories)){
201 $this->categories= array($this->categories);
202 }
204 // Evaluate columns to be exported
205 if (isset($this->xmlData['table']['column'])){
206 foreach ($this->xmlData['table']['column'] as $index => $config) {
207 if (isset($config['export']) && $config['export'] == "true"){
208 $this->exportColumns[]= $index;
209 }
210 }
211 }
213 return true;
214 }
217 function renderHeader()
218 {
219 $this->header= array();
220 $this->plainHeader= array();
222 // Initialize sort?
223 $sortInit= false;
224 if (!$this->sortDirection) {
225 $this->sortColumn= 0;
226 if (isset($this->xmlData['definition']['defaultSortColumn'])){
227 $this->sortColumn= $this->xmlData['definition']['defaultSortColumn'];
228 } else {
229 $this->sortAttribute= "";
230 }
231 $this->sortDirection= array();
232 $sortInit= true;
233 }
235 if (isset($this->xmlData['table']['column'])){
236 foreach ($this->xmlData['table']['column'] as $index => $config) {
237 // Initialize everything to one direction
238 if ($sortInit) {
239 $this->sortDirection[$index]= false;
240 }
242 $sorter= "";
243 if ($index == $this->sortColumn && isset($config['sortAttribute']) &&
244 isset($config['sortType'])) {
245 $this->sortAttribute= $config['sortAttribute'];
246 $this->sortType= $config['sortType'];
247 $sorter= " ".image("images/lists/sort-".($this->sortDirection[$index]?"up":"down").".png", null, $this->sortDirection[$index]?_("Up"):_("Down"), "text-top");
248 }
249 $sortable= (isset($config['sortAttribute']));
251 $link= "href='?plug=".$_GET['plug']."&PID=".$this->pid."&act=SORT_$index'";
252 if (isset($config['label'])) {
253 if ($sortable) {
254 $this->header[$index]= "<td class='listheader' ".$this->colprops[$index]."><a $link>"._($config['label'])."</a>$sorter</td>";
255 } else {
256 $this->header[$index]= "<td class='listheader' ".$this->colprops[$index].">"._($config['label'])."</td>";
257 }
258 $this->plainHeader[]= _($config['label']);
259 } else {
260 if ($sortable) {
261 $this->header[$index]= "<td class='listheader' ".$this->colprops[$index]."><a $link> </a>$sorter</td>";
262 } else {
263 $this->header[$index]= "<td class='listheader' ".$this->colprops[$index]."> </td>";
264 }
265 $this->plainHeader[]= "";
266 }
267 }
268 }
269 }
272 function render()
273 {
274 // Check for exeeded sizelimit
275 if (($message= check_sizelimit()) != ""){
276 return($message);
277 }
279 // Some browsers don't have the ability do do scrollable table bodies, filter them
280 // here.
281 $switch= false;
282 if (preg_match('/(Opera|Konqueror|Safari)/i', $_SERVER['HTTP_USER_AGENT'])){
283 $switch= true;
284 }
286 // Initialize list
287 $result= "<input type='hidden' value='$this->pid' name='PID'>\n";
288 $result.= "<input type='hidden' name='position_".$this->pid."' id='position_".$this->pid."'>\n";
289 $height= 450;
290 if ($this->height != 0) {
291 $result.= "<input type='hidden' value='$this->height' id='d_height'>\n";
292 $height= $this->height;
293 }
295 $result.= "<div class='listContainer' id='d_scrollbody' style='min-height:".($height+25)."px;'>\n";
296 $result.= "<table summary='$this->headline' style='width:100%;table-layout:fixed' cellspacing='0' cellpadding='0' id='t_scrolltable'>\n";
297 $this->numColumns= count($this->colprops) + ($this->multiSelect?1:0);
299 // Build list header
300 $result.= "<thead class='fixedListHeader listHeaderFormat'><tr>\n";
301 if ($this->multiSelect) {
302 $width= "24px";
303 if (preg_match('/Konqueror/i', $_SERVER['HTTP_USER_AGENT'])){
304 $width= "28px";
305 }
306 $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";
307 }
308 foreach ($this->header as $header) {
309 $result.= $header;
310 }
311 $result.= "</tr></thead>\n";
313 // Build list body
314 $result.= "<tbody class='listScrollContent listBodyFormat' id='t_nscrollbody' style='height:".$height."px;'>\n";
316 // No results? Just take an empty colspanned row
317 if (count($this->entries) + count($this->departments) == 0) {
318 $result.= "<tr><td class='list1nohighlight' colspan='$this->numColumns' style='height:100%;border-right:0px;width:100%;'> </td></tr>";
319 }
321 // Line color alternation
322 $alt= 0;
323 $deps= 0;
325 // Draw department browser if configured and we're not in sub mode
326 $this->useSpan= false;
327 if ($this->departmentBrowser && $this->filter->scope != "sub") {
328 // Fill with department browser if configured this way
329 $departmentIterator= new departmentSortIterator($this->departments, $this->sortDirection[$this->sortColumn]);
330 foreach ($departmentIterator as $row => $entry){
331 $result.="<tr>";
333 // Render multi select if needed
334 if ($this->multiSelect) {
335 $result.="<td style='text-align:center;padding:0;' class='list1'> </td>";
336 }
338 // Render defined department columns, fill the rest with some stuff
339 $rest= $this->numColumns - 1;
340 foreach ($this->xmlData['table']['department'] as $index => $config) {
341 $colspan= 1;
342 if (isset($config['span'])){
343 $colspan= $config['span'];
344 $this->useSpan= true;
345 }
346 $result.="<td colspan='$colspan' ".$this->colprops[$index]." class='list1'>".$this->renderCell($config['value'], $entry, $row)."</td>";
347 $rest-= $colspan;
348 }
350 // Fill remaining cols with nothing
351 $last= $this->numColumns - $rest;
352 for ($i= 0; $i<$rest; $i++){
353 $result.= "<td ".$this->colprops[$last+$i-1]." class='list1'> </td>";
354 }
355 $result.="</tr>";
357 $alt++;
358 }
359 $deps= $alt;
360 }
362 // Fill with contents, sort as configured
363 foreach ($this->entries as $row => $entry) {
364 $trow= "";
366 // Render multi select if needed
367 if ($this->multiSelect) {
368 $trow.="<td style='text-align:center;width:20px;' class='list0'><input type='checkbox' id='listing_selected_$row' name='listing_selected_$row'></td>\n";
369 }
371 foreach ($this->xmlData['table']['column'] as $index => $config) {
372 $renderedCell= $this->renderCell($config['value'], $entry, $row);
373 $trow.="<td ".$this->colprops[$index]." class='list0'>".$renderedCell."</td>\n";
375 // Save rendered column
376 $sort= preg_replace('/.*>([^<]+)<.*$/', '$1', $renderedCell);
377 $sort= preg_replace('/ /', '', $sort);
378 if (preg_match('/</', $sort)){
379 $sort= "";
380 }
381 $this->entries[$row]["_sort$index"]= $sort;
382 }
384 // Save rendered entry
385 $this->entries[$row]['_rendered']= $trow;
386 }
388 // Complete list by sorting entries for _sort$index and appending them to the output
389 $entryIterator= new listingSortIterator($this->entries, $this->sortDirection[$this->sortColumn], "_sort".$this->sortColumn, $this->sortType);
390 foreach ($entryIterator as $row => $entry){
391 $result.="<tr>\n";
392 $result.= $entry['_rendered'];
393 $result.="</tr>\n";
394 $alt++;
395 }
397 // Need to fill the list if it's not full (nobody knows why this is 22 ;-))
398 $emptyListStyle= (count($this->entries) + (($this->useSpan && count($this->entries))?$deps:0) == 0)?"border:0;":"";
399 if ((count($this->entries) + $deps) < 22) {
400 $result.= "<tr>";
401 for ($i= 0; $i<$this->numColumns; $i++) {
402 if ($i == 0) {
403 $result.= "<td class='list1nohighlight' style='$emptyListStyle height:100%;'> </td>";
404 continue;
405 }
406 if ($i != $this->numColumns-1) {
407 $result.= "<td class='list1nohighlight' style='$emptyListStyle'> </td>";
408 } else {
409 $result.= "<td class='list1nohighlight' style='border-right:0;$emptyListStyle'> </td>";
410 }
411 }
412 $result.= "</tr>";
413 }
415 // Close list body
416 $result.= "</tbody></table></div>";
418 // Add the footer if requested
419 if ($this->showFooter) {
420 $result.= "<div class='nlistFooter'><div style='padding:3px'>";
422 foreach ($this->objectTypes as $objectType) {
423 if (isset($this->objectTypeCount[$objectType['label']])) {
424 $label= _($objectType['label']);
425 $result.= image($objectType['image'], null, $label)." ".$this->objectTypeCount[$objectType['label']]." ";
426 }
427 }
429 $result.= "</div></div>";
430 }
432 // Close list
433 $result.= $switch?"<input type='hidden' id='list_workaround'>":"";
435 // Add scroll positioner
436 $result.= '<script type="text/javascript" language="javascript">';
437 $result.= '$("t_nscrollbody").scrollTop= '.$this->scrollPosition.';';
438 $result.= 'var box = $("t_nscrollbody").onscroll= function() {$("position_'.$this->pid.'").value= this.scrollTop;}';
439 $result.= '</script>';
441 $smarty= get_smarty();
442 $smarty->assign("usePrototype", "true");
443 $smarty->assign("FILTER", $this->filter->render());
444 $smarty->assign("SIZELIMIT", print_sizelimit_warning());
445 $smarty->assign("LIST", $result);
447 // Assign navigation elements
448 $nav= $this->renderNavigation();
449 foreach ($nav as $key => $html) {
450 $smarty->assign($key, $html);
451 }
453 // Assign action menu / base
454 $smarty->assign("ACTIONS", $this->renderActionMenu());
455 $smarty->assign("BASE", $this->renderBase());
457 // Assign separator
458 $smarty->assign("SEPARATOR", "<img src='images/lists/seperator.png' alt='-' align='middle' height='16' width='1' class='center'>");
460 // Assign summary
461 $smarty->assign("HEADLINE", $this->headline);
463 // Try to load template from plugin the folder first...
464 $file = get_template_path($this->xmlData['definition']['template'], true);
466 // ... if this fails, try to load the file from the theme folder.
467 if(!file_exists($file)){
468 $file = get_template_path($this->xmlData['definition']['template']);
469 }
471 return ($smarty->fetch($file));
472 }
475 function update()
476 {
477 global $config;
478 $ui= get_userinfo();
480 // Take care of base selector
481 if ($this->baseMode) {
482 $this->baseSelector->update();
483 // Check if a wrong base was supplied
484 if(!$this->baseSelector->checkLastBaseUpdate()){
485 msg_dialog::display(_("Error"), msgPool::check_base(), ERROR_DIALOG);
486 }
487 }
489 // Save base
490 $refresh= false;
491 if ($this->baseMode) {
492 $this->base= $this->baseSelector->getBase();
493 session::global_set("CurrentMainBase", $this->base);
494 $refresh= true;
495 }
498 // Reset object counter / DN mapping
499 $this->objectTypeCount= array();
500 $this->objectDnMapping= array();
502 // Do not do anything if this is not our PID
503 if($refresh || !(isset($_REQUEST['PID']) && $_REQUEST['PID'] != $this->pid)) {
505 // Save position if set
506 if (isset($_POST['position_'.$this->pid]) && is_numeric($_POST['position_'.$this->pid])) {
507 $this->scrollPosition= $_POST['position_'.$this->pid];
508 }
510 // Override the base if we got a message from the browser navigation
511 if ($this->departmentBrowser && isset($_GET['act'])) {
512 if (preg_match('/^department_([0-9]+)$/', validate($_GET['act']), $match)){
513 if (isset($this->departments[$match[1]])){
514 $this->base= $this->departments[$match[1]]['dn'];
515 if ($this->baseMode) {
516 $this->baseSelector->setBase($this->base);
517 }
518 session::global_set("CurrentMainBase", $this->base);
519 }
520 }
521 }
523 // Filter POST with "act" attributes -> posted from action menu
524 if (isset($_POST['exec_act']) && $_POST['act'] != '') {
525 if (preg_match('/^export.*$/', $_POST['act']) && isset($this->exporter[$_POST['act']])) {
526 $exporter= $this->exporter[$_POST['act']];
527 $userinfo= ", "._("created by")." ".$ui->cn." - ".strftime('%A, %d. %B %Y, %H:%M:%S');
528 $entryIterator= new listingSortIterator($this->entries, $this->sortDirection[$this->sortColumn], "_sort".$this->sortColumn, $this->sortType);
529 $sortedEntries= array();
530 foreach ($entryIterator as $entry){
531 $sortedEntries[]= $entry;
532 }
533 $instance= new $exporter['class']($this->headline.$userinfo, $this->plainHeader, $sortedEntries, $this->exportColumns);
534 $type= call_user_func(array($exporter['class'], "getInfo"));
535 $type= $type[$_POST['act']];
536 send_binary_content($instance->query(), $type['filename'], $type= $type['mime']);
537 }
538 }
540 // Filter GET with "act" attributes
541 if (isset($_GET['act'])) {
542 $key= validate($_GET['act']);
543 if (preg_match('/^SORT_([0-9]+)$/', $key, $match)) {
544 // Switch to new column or invert search order?
545 $column= $match[1];
546 if ($this->sortColumn != $column) {
547 $this->sortColumn= $column;
548 } else {
549 $this->sortDirection[$column]= !$this->sortDirection[$column];
550 }
552 // Allow header to update itself according to the new sort settings
553 $this->renderHeader();
554 }
555 }
557 // Override base if we got signals from the navigation elements
558 $action= "";
559 foreach ($_POST as $key => $value) {
560 if (preg_match('/^(ROOT|BACK|HOME)(_x)?$/', $key, $match)) {
561 $action= $match[1];
562 break;
563 }
564 }
566 // Navigation handling
567 if ($action == 'ROOT') {
568 $deps= $ui->get_module_departments($this->categories);
569 $this->base= $deps[0];
570 $this->baseSelector->setBase($this->base);
571 session::global_set("CurrentMainBase", $this->base);
572 }
573 if ($action == 'BACK') {
574 $deps= $ui->get_module_departments($this->categories);
575 $base= preg_replace("/^[^,]+,/", "", $this->base);
576 if(in_array_ics($base, $deps)){
577 $this->base= $base;
578 $this->baseSelector->setBase($this->base);
579 session::global_set("CurrentMainBase", $this->base);
580 }
581 }
582 if ($action == 'HOME') {
583 $ui= get_userinfo();
584 $this->base= get_base_from_people($ui->dn);
585 $this->baseSelector->setBase($this->base);
586 session::global_set("CurrentMainBase", $this->base);
587 }
588 }
590 // Reload departments
591 if ($this->departmentBrowser){
592 $this->departments= $this->getDepartments();
593 }
595 // Update filter and refresh entries
596 $this->filter->setBase($this->base);
597 $this->entries= $this->filter->query();
599 // Fix filter if querie returns NULL
600 if ($this->entries == null) {
601 $this->entries= array();
602 }
603 }
606 function setBase($base)
607 {
608 $this->base= $base;
609 if ($this->baseMode) {
610 $this->baseSelector->setBase($this->base);
611 }
612 }
615 function getBase()
616 {
617 return $this->base;
618 }
621 function parseLayout($layout)
622 {
623 $result= array();
624 $layout= preg_replace("/^\|/", "", $layout);
625 $layout= preg_replace("/\|$/", "", $layout);
626 $cols= explode("|", $layout);
628 foreach ($cols as $index => $config) {
629 if ($config != "") {
630 $res= "";
631 $components= explode(';', $config);
632 foreach ($components as $part) {
633 if (preg_match("/^r$/", $part)) {
634 $res.= "text-align:right;";
635 continue;
636 }
637 if (preg_match("/^l$/", $part)) {
638 $res.= "text-align:left;";
639 continue;
640 }
641 if (preg_match("/^c$/", $part)) {
642 $res.= "text-align:center;";
643 continue;
644 }
645 if (preg_match("/^[0-9]+(|px|%)$/", $part)) {
646 $res.= "width:$part;min-width:$part;";
647 continue;
648 }
649 }
651 // Add minimum width for scalable columns
652 if (!preg_match('/width:/', $res)){
653 $res.= "min-width:200px;";
654 }
656 $result[$index]= " style='$res'";
657 } else {
658 $result[$index]= " style='min-width:100px;'";
659 }
660 }
662 // Save number of columns for later use
663 $this->numColumns= count($cols);
665 // Add no border to the last column
666 $result[$this->numColumns-1]= preg_replace("/'$/", "border-right:0;'", $result[$this->numColumns-1]);
668 return $result;
669 }
672 function renderCell($data, $config, $row)
673 {
674 // Replace flat attributes in data string
675 for ($i= 0; $i<$config['count']; $i++) {
676 $attr= $config[$i];
677 $value= "";
678 if (is_array($config[$attr])) {
679 $value= $config[$attr][0];
680 } else {
681 $value= $config[$attr];
682 }
683 $data= preg_replace("/%\{$attr\}/", $value, $data);
684 }
686 // Watch out for filters and prepare to execute them
687 $data= $this->processElementFilter($data, $config, $row);
689 // Replace all non replaced %{...} instances because they
690 // are non resolved attributes or filters
691 $data= preg_replace('/%{[^}]+}/', ' ', $data);
693 return $data;
694 }
697 function renderBase()
698 {
699 if (!$this->baseMode) {
700 return;
701 }
703 return $this->baseSelector->render();
704 }
707 function processElementFilter($data, $config, $row)
708 {
709 preg_match_all("/%\{filter:([^(]+)\((.*)\)\}/", $data, $matches, PREG_SET_ORDER);
711 foreach ($matches as $match) {
712 $cl= "";
713 $method= "";
714 if (preg_match('/::/', $match[1])) {
715 $cl= preg_replace('/::.*$/', '', $match[1]);
716 $method= preg_replace('/^.*::/', '', $match[1]);
717 } else {
718 if (!isset($this->filters[$match[1]])) {
719 continue;
720 }
721 $cl= preg_replace('/::.*$/', '', $this->filters[$match[1]]);
722 $method= preg_replace('/^.*::/', '', $this->filters[$match[1]]);
723 }
725 // Prepare params for function call
726 $params= array();
727 preg_match_all('/"[^"]+"|[^,]+/', $match[2], $parts);
728 foreach ($parts[0] as $param) {
730 // Row is replaced by the row number
731 if ($param == "row") {
732 $params[]= $row;
733 continue;
734 }
736 // pid is replaced by the current PID
737 if ($param == "pid") {
738 $params[]= $this->pid;
739 continue;
740 }
742 // base is replaced by the current base
743 if ($param == "base") {
744 $params[]= $this->getBase();
745 continue;
746 }
748 // Fixie with "" is passed directly
749 if (preg_match('/^".*"$/', $param)){
750 $params[]= preg_replace('/"/', '', $param);
751 continue;
752 }
754 // Move dn if needed
755 if ($param == "dn") {
756 $params[]= LDAP::fix($config["dn"]);
757 continue;
758 }
760 // LDAP variables get replaced by their objects
761 for ($i= 0; $i<$config['count']; $i++) {
762 if ($param == $config[$i]) {
763 $values= $config[$config[$i]];
764 if (is_array($values)){
765 unset($values['count']);
766 }
767 $params[]= $values;
768 break;
769 }
770 }
771 }
773 // Replace information
774 if ($cl == "listing") {
775 // Non static call - seems to result in errors
776 $data= @preg_replace('/'.preg_quote($match[0]).'/', call_user_func_array(array($this, "$method"), $params), $data);
777 } else {
778 // Static call
779 $data= preg_replace('/'.preg_quote($match[0]).'/', call_user_func_array(array($cl, $method), $params), $data);
780 }
781 }
783 return $data;
784 }
787 function getObjectType($types, $classes)
788 {
789 // Walk thru types and see if there's something matching
790 foreach ($types as $objectType) {
791 $ocs= $objectType['objectClass'];
792 if (!is_array($ocs)){
793 $ocs= array($ocs);
794 }
796 $found= true;
797 foreach ($ocs as $oc){
798 if (preg_match('/^!(.*)$/', $oc, $match)) {
799 $oc= $match[1];
800 if (in_array($oc, $classes)) {
801 $found= false;
802 }
803 } else {
804 if (!in_array($oc, $classes)) {
805 $found= false;
806 }
807 }
808 }
810 if ($found) {
811 return $objectType;
812 }
813 }
815 return null;
816 }
819 function filterObjectType($dn, $classes)
820 {
821 // Walk thru classes and return on first match
822 $result= " ";
824 $objectType= $this->getObjectType($this->objectTypes, $classes);
825 if ($objectType) {
826 $this->objectDnMapping[$dn]= $objectType["objectClass"];
827 $result= image($objectType["image"], null, LDAP::fix($dn));
828 if (!isset($this->objectTypeCount[$objectType['label']])) {
829 $this->objectTypeCount[$objectType['label']]= 0;
830 }
831 $this->objectTypeCount[$objectType['label']]++;
832 }
834 return $result;
835 }
838 function filterActions($dn, $row, $classes)
839 {
840 // Do nothing if there's no menu defined
841 if (!isset($this->xmlData['actiontriggers']['action'])) {
842 return " ";
843 }
845 // Go thru all actions
846 $result= "";
847 $actions= $this->xmlData['actiontriggers']['action'];
849 // Ensure we've a valid actions array, if there is only one action in the actiontriggers col
850 // then we've to create a valid array here.
851 if(isset($actions['name'])) $actions = array($actions);
853 foreach($actions as $action) {
854 // Skip the entry completely if there's no permission to execute it
855 if (!$this->hasActionPermission($action, $dn, $classes)) {
856 $result.= image('images/empty.png');
857 continue;
858 }
860 // Skip entry if the pseudo filter does not fit
861 if (isset($action['filter']) && preg_match('/^[a-z0-9_]+!?=[a-z0-9_]+$/i', $action['filter'])) {
862 list($fa, $fv)= explode('=', $action['filter']);
863 if (preg_match('/^(.*)!$/', $fa, $m)){
864 $fa= $m[1];
865 if (isset($this->entries[$row][$fa]) && $this->entries[$row][$fa][0] == $fv) {
866 $result.= image('images/empty.png');
867 continue;
868 }
869 } else {
870 if (!isset($this->entries[$row][$fa]) && !$this->entries[$row][$fa][0] == $fv) {
871 $result.= image('images/empty.png');
872 continue;
873 }
874 }
875 }
878 // If there's an objectclass definition and we don't have it
879 // add an empty picture here.
880 if (isset($action['objectclass'])){
881 $objectclass= $action['objectclass'];
882 if (preg_match('/^!(.*)$/', $objectclass, $m)){
883 $objectclass= $m[1];
884 if(in_array($objectclass, $classes)) {
885 $result.= image('images/empty.png');
886 continue;
887 }
888 } elseif (is_string($objectclass)) {
889 if(!in_array($objectclass, $classes)) {
890 $result.= image('images/empty.png');
891 continue;
892 }
893 } elseif (is_array($objectclass)) {
894 if(count(array_intersect($objectclass, $classes)) != count($objectclass)){
895 $result.= image('images/empty.png');
896 continue;
897 }
898 }
899 }
901 // Render normal entries as usual
902 if ($action['type'] == "entry") {
903 $label= $this->processElementFilter($action['label'], $this->entries[$row], $row);
904 $image= $this->processElementFilter($action['image'], $this->entries[$row], $row);
905 $result.= image($image, "listing_".$action['name']."_$row", $label);
906 }
908 // Handle special types
909 if ($action['type'] == "copypaste" || $action['type'] == "snapshot") {
911 $objectType= $this->getObjectType($this->objectTypes, $this->entries[$row]['objectClass']);
912 $category= $class= null;
913 if ($objectType) {
914 $category= $objectType['category'];
915 $class= $objectType['class'];
916 }
918 if ($action['type'] == "copypaste") {
919 $copy = !isset($action['copy']) || $action['copy'] == "true";
920 $cut = !isset($action['cut']) || $action['cut'] == "true";
921 $result.= $this->renderCopyPasteActions($row, $this->entries[$row]['dn'], $category, $class,$copy,$cut);
922 } else {
923 $result.= $this->renderSnapshotActions($row, $this->entries[$row]['dn'], $category, $class);
924 }
925 }
926 }
928 return $result;
929 }
932 function filterDepartmentLink($row, $dn, $description)
933 {
934 $attr= $this->departments[$row]['sort-attribute'];
935 $name= $this->departments[$row][$attr];
936 if (is_array($name)){
937 $name= $name[0];
938 }
939 $result= sprintf("%s [%s]", $name, $description[0]);
940 return("<a href='?plug=".$_GET['plug']."&PID=$this->pid&act=department_$row' title='$dn'>$result</a>");
941 }
944 function filterLink()
945 {
946 $result= " ";
948 $row= func_get_arg(0);
949 $pid= $this->pid;
950 $dn= LDAP::fix(func_get_arg(1));
951 $params= array(func_get_arg(2));
953 // Collect sprintf params
954 for ($i = 3;$i < func_num_args();$i++) {
955 $val= func_get_arg($i);
956 if (is_array($val)){
957 $params[]= $val[0];
958 continue;
959 }
960 $params[]= $val;
961 }
963 $result= " ";
964 $trans= call_user_func_array("sprintf", $params);
965 if ($trans != "") {
966 return("<a href='?plug=".$_GET['plug']."&PID=$pid&act=listing_edit_$row' title='$dn'>$trans</a>");
967 }
969 return $result;
970 }
973 function renderNavigation()
974 {
975 $result= array();
976 $enableBack = true;
977 $enableRoot = true;
978 $enableHome = true;
980 $ui = get_userinfo();
982 /* Check if base = first available base */
983 $deps = $ui->get_module_departments($this->categories);
985 if(!count($deps) || $deps[0] == $this->filter->base){
986 $enableBack = false;
987 $enableRoot = false;
988 }
990 $listhead ="";
992 /* Check if we are in users home department */
993 if(!count($deps) || $this->filter->base == get_base_from_people($ui->dn)){
994 $enableHome = false;
995 }
997 /* Draw root button */
998 if($enableRoot){
999 $result["ROOT"]= image('images/lists/root.png', 'ROOT', _("Root"));
1000 }else{
1001 $result["ROOT"]= image('images/lists/root-grey.png', null, _("Root"));
1002 }
1004 /* Draw back button */
1005 if($enableBack){
1006 $result["BACK"]= image('images/lists/back.png', 'BACK', _("Go up one department"));
1007 }else{
1008 $result["BACK"]= image('images/lists/back-grey.png', null, _("Go up one department"));
1009 }
1011 /* Draw home button */
1012 /* Draw home button */
1013 if($enableHome){
1014 $result["HOME"]= image('images/lists/home.png', 'HOME', _("Go to users department"));
1015 }else{
1016 $result["HOME"]= image('images/lists/home-grey.png', null, _("Go to users department"));
1017 }
1020 /* Draw reload button, this button is enabled everytime */
1021 $result["RELOAD"]= image('images/lists/reload.png', 'REFRESH', _("Reload list"));
1023 return ($result);
1024 }
1027 function getAction()
1028 {
1029 // Do not do anything if this is not our PID, or there's even no PID available...
1030 if(!isset($_REQUEST['PID']) || $_REQUEST['PID'] != $this->pid) {
1031 return;
1032 }
1034 // Save position if set
1035 if (isset($_POST['position_'.$this->pid]) && is_numeric($_POST['position_'.$this->pid])) {
1036 $this->scrollPosition= $_POST['position_'.$this->pid];
1037 }
1039 $result= array("targets" => array(), "action" => "");
1041 // Filter GET with "act" attributes
1042 if (isset($_GET['act'])) {
1043 $key= validate($_GET['act']);
1044 $target= preg_replace('/^listing_[a-zA-Z_]+_([0-9]+)$/', '$1', $key);
1045 if (isset($this->entries[$target]['dn'])) {
1046 $result['action']= preg_replace('/^listing_([a-zA-Z_]+)_[0-9]+$/', '$1', $key);
1047 $result['targets'][]= $this->entries[$target]['dn'];
1048 }
1050 // Drop targets if empty
1051 if (count($result['targets']) == 0) {
1052 unset($result['targets']);
1053 }
1054 return $result;
1055 }
1057 // Filter POST with "listing_" attributes
1058 foreach ($_POST as $key => $prop) {
1060 // Capture selections
1061 if (preg_match('/^listing_selected_[0-9]+$/', $key)) {
1062 $target= preg_replace('/^listing_selected_([0-9]+)$/', '$1', $key);
1063 if (isset($this->entries[$target]['dn'])) {
1064 $result['targets'][]= $this->entries[$target]['dn'];
1065 }
1066 continue;
1067 }
1069 // Capture action with target - this is a one shot
1070 if (preg_match('/^listing_[a-zA-Z_]+_[0-9]+(|_x)$/', $key)) {
1071 $target= preg_replace('/^listing_[a-zA-Z_]+_([0-9]+)(|_x)$/', '$1', $key);
1072 if (isset($this->entries[$target]['dn'])) {
1073 $result['action']= preg_replace('/^listing_([a-zA-Z_]+)_[0-9]+(|_x)$/', '$1', $key);
1074 $result['targets']= array($this->entries[$target]['dn']);
1075 }
1076 break;
1077 }
1079 // Capture action without target
1080 if (preg_match('/^listing_[a-zA-Z_]+(|_x)$/', $key)) {
1081 $result['action']= preg_replace('/^listing_([a-zA-Z_]+)(|_x)$/', '$1', $key);
1082 continue;
1083 }
1084 }
1086 // Filter POST with "act" attributes -> posted from action menu
1087 if (isset($_POST['act']) && $_POST['act'] != '') {
1088 if (!preg_match('/^export.*$/', $_POST['act'])){
1089 $result['action']= validate($_POST['act']);
1090 }
1091 }
1093 // Drop targets if empty
1094 if (count($result['targets']) == 0) {
1095 unset($result['targets']);
1096 }
1097 return $result;
1098 }
1101 function renderActionMenu()
1102 {
1103 $result= "<input type='hidden' name='act' id='act' value=''><div style='display:none'><input type='submit' name='exec_act' id='exec_act' value=''></div>";
1105 // Don't send anything if the menu is not defined
1106 if (!isset($this->xmlData['actionmenu']['action'])){
1107 return $result;
1108 }
1110 // Array?
1111 if (isset($this->xmlData['actionmenu']['action']['type'])){
1112 $this->xmlData['actionmenu']['action']= array($this->xmlData['actionmenu']['action']);
1113 }
1115 // Load shortcut
1116 $actions= &$this->xmlData['actionmenu']['action'];
1117 $result= "<ul class='level1' id='root'><li><a href='#'>"._("Actions")." ".image("images/lists/sort-down.png")."</a>";
1119 // Build ul/li list
1120 $result.= $this->recurseActions($actions);
1122 return "<div id='pulldown'>".$result."</li></ul><div>";
1123 }
1126 function recurseActions($actions)
1127 {
1128 global $class_mapping;
1129 static $level= 2;
1130 $result= "<ul class='level$level'>";
1131 $separator= "";
1133 foreach ($actions as $action) {
1135 // Skip the entry completely if there's no permission to execute it
1136 if (!$this->hasActionPermission($action, $this->filter->base)) {
1137 continue;
1138 }
1140 // Skip entry if there're missing dependencies
1141 if (isset($action['depends'])) {
1142 $deps= is_array($action['depends'])?$action['depends']:array($action['depends']);
1143 foreach($deps as $clazz) {
1144 if (!isset($class_mapping[$clazz])){
1145 continue 2;
1146 }
1147 }
1148 }
1150 // Fill image if set
1151 $img= "";
1152 if (isset($action['image'])){
1153 $img= image($action['image'])." ";
1154 }
1156 if ($action['type'] == "separator"){
1157 $separator= " style='border-top:1px solid #AAA' ";
1158 continue;
1159 }
1161 // Dive into subs
1162 if ($action['type'] == "sub" && isset($action['action'])) {
1163 $level++;
1164 if (isset($action['label'])){
1165 $result.= "<li$separator><a href='#'>$img"._($action['label'])." ".image('images/forward-arrow.png')."</a>";
1166 }
1168 // Ensure we've an array of actions, this enables sub menus with only one action.
1169 if(isset($action['action']['type'])){
1170 $action['action'] = array($action['action']);
1171 }
1173 $result.= $this->recurseActions($action['action'])."</li>";
1174 $level--;
1175 $separator= "";
1176 continue;
1177 }
1179 // Render entry elseways
1180 if (isset($action['label'])){
1181 $result.= "<li$separator><a href='#' onClick='\$(\"act\").value= \"".$action['name']."\";\$(\"exec_act\").click();'>$img"._($action['label'])."</a></li>";
1182 }
1184 // Check for special types
1185 switch ($action['type']) {
1186 case 'copypaste':
1187 $cut = !isset($action['cut']) || $action['cut'] != "false";
1188 $copy = !isset($action['copy']) || $action['copy'] != "false";
1189 $result.= $this->renderCopyPasteMenu($separator, $copy , $cut);
1190 break;
1192 case 'snapshot':
1193 $result.= $this->renderSnapshotMenu($separator);
1194 break;
1196 case 'exporter':
1197 $result.= $this->renderExporterMenu($separator);
1198 break;
1200 case 'daemon':
1201 $result.= $this->renderDaemonMenu($separator);
1202 break;
1203 }
1205 $separator= "";
1206 }
1208 $result.= "</ul>";
1209 return $result;
1210 }
1213 function hasActionPermission($action, $dn, $classes= null)
1214 {
1215 $ui= get_userinfo();
1217 if (isset($action['acl'])) {
1218 $acls= $action['acl'];
1219 if (!is_array($acls)) {
1220 $acls= array($acls);
1221 }
1223 // Every ACL has to pass
1224 foreach ($acls as $acl) {
1225 $module= $this->categories;
1226 $aclList= array();
1228 // Replace %acl if available
1229 if ($classes) {
1230 $otype= $this->getObjectType($this->objectTypes, $classes);
1231 $acl= str_replace('%acl', $otype['category']."/".$otype['class'], $acl);
1232 }
1234 // Split for category and plugins if needed
1235 // match for "[rw]" style entries
1236 if (preg_match('/^\[([rwcdm]+)\]$/', $acl, $match)){
1237 $aclList= array($match[1]);
1238 }
1240 // match for "users[rw]" style entries
1241 if (preg_match('/^([a-zA-Z0-9]+)\[([rwcdm]+)\]$/', $acl, $match)){
1242 $module= $match[1];
1243 $aclList= array($match[2]);
1244 }
1246 // match for "users/user[rw]" style entries
1247 if (preg_match('/^([a-zA-Z0-9]+\/[a-zA-Z0-9]+)\[([rwcdm]+)\]$/', $acl, $match)){
1248 $module= $match[1];
1249 $aclList= array($match[2]);
1250 }
1252 // match "users/user[userPassword:rw(,...)*]" style entries
1253 if (preg_match('/^([a-zA-Z0-9]+\/[a-zA-Z0-9]+)\[([a-zA-Z0-9]+:[rwcdm]+(,[a-zA-Z0-9]+:[rwcdm]+)*)\]$/', $acl, $match)){
1254 $module= $match[1];
1255 $aclList= explode(',', $match[2]);
1256 }
1258 // Walk thru prepared ACL by using $module
1259 foreach($aclList as $sAcl) {
1260 $checkAcl= "";
1262 // Category or detailed permission?
1263 if (strpos($module, '/') !== false) {
1264 if (preg_match('/([a-zA-Z0-9]+):([rwcdm]+)/', $sAcl, $m) ) {
1265 $checkAcl= $ui->get_permissions($dn, $module, $m[1]);
1266 $sAcl= $m[2];
1267 } else {
1268 $checkAcl= $ui->get_permissions($dn, $module, '0');
1269 }
1270 } else {
1271 $checkAcl= $ui->get_category_permissions($dn, $module);
1272 }
1274 // Split up remaining part of the acl and check if it we're
1275 // allowed to do something...
1276 $parts= str_split($sAcl);
1277 foreach ($parts as $part) {
1278 if (strpos($checkAcl, $part) === false){
1279 return false;
1280 }
1281 }
1283 }
1284 }
1285 }
1287 return true;
1288 }
1291 function refreshBasesList()
1292 {
1293 global $config;
1294 $ui= get_userinfo();
1296 // Do some array munching to get it user friendly
1297 $ids= $config->idepartments;
1298 $d= $ui->get_module_departments($this->categories);
1299 $k_ids= array_keys($ids);
1300 $deps= array_intersect($d,$k_ids);
1302 // Fill internal bases list
1303 $this->bases= array();
1304 foreach($k_ids as $department){
1305 $this->bases[$department] = $ids[$department];
1306 }
1308 // Populate base selector if already present
1309 if ($this->baseSelector && $this->baseMode) {
1310 $this->baseSelector->setBases($this->bases);
1311 $this->baseSelector->update(TRUE);
1312 }
1313 }
1316 function getDepartments()
1317 {
1318 $departments= array();
1319 $ui= get_userinfo();
1321 // Get list of supported department types
1322 $types = departmentManagement::get_support_departments();
1324 // Load departments allowed by ACL
1325 $validDepartments = $ui->get_module_departments($this->categories);
1327 // Build filter and look in the LDAP for possible sub departments
1328 // of current base
1329 $filter= "(&(objectClass=gosaDepartment)(|";
1330 $attrs= array("description", "objectClass");
1331 foreach($types as $name => $data){
1332 $filter.= "(objectClass=".$data['OC'].")";
1333 $attrs[]= $data['ATTR'];
1334 }
1335 $filter.= "))";
1336 $res= get_list($filter, $this->categories, $this->base, $attrs, GL_NONE);
1338 // Analyze list of departments
1339 foreach ($res as $department) {
1340 if (!in_array($department['dn'], $validDepartments)) {
1341 continue;
1342 }
1344 // Add the attribute where we use for sorting
1345 $oc= null;
1346 foreach(array_keys($types) as $type) {
1347 if (in_array($type, $department['objectClass'])) {
1348 $oc= $type;
1349 break;
1350 }
1351 }
1352 $department['sort-attribute']= $types[$oc]['ATTR'];
1354 // Move to the result list
1355 $departments[]= $department;
1356 }
1358 return $departments;
1359 }
1362 function renderCopyPasteMenu($separator, $copy= true, $cut= true)
1363 {
1364 // We can only provide information if we've got a copypaste handler
1365 // instance
1366 if(!(isset($this->copyPasteHandler) && is_object($this->copyPasteHandler))){
1367 return "";
1368 }
1370 // Presets
1371 $result= "";
1372 $read= $paste= false;
1373 $ui= get_userinfo();
1375 // Switch flags to on if there's at least one category which allows read/paste
1376 foreach($this->categories as $category){
1377 $read= $read || preg_match('/r/', $ui->get_category_permissions($this->base, $category));
1378 $paste= $paste || $ui->is_pasteable($this->base, $category) == 1;
1379 }
1382 // Draw entries that allow copy and cut
1383 if($read){
1385 // Copy entry
1386 if($copy){
1387 $result.= "<li$separator><a href='#' onClick='\$(\"act\").value= \"copy\";\$(\"exec_act\").click();'>".image('images/lists/copy.png')." "._("Copy")."</a></li>";
1388 $separator= "";
1389 }
1391 // Cut entry
1392 if($cut){
1393 $result.= "<li$separator><a href='#' onClick='\$(\"act\").value= \"cut\";\$(\"exec_act\").click();'>".image("images/lists/cut.png")." "._("Cut")."</a></li>";
1394 $separator= "";
1395 }
1396 }
1398 // Draw entries that allow pasting entries
1399 if($paste){
1400 if($this->copyPasteHandler->entries_queued()){
1401 $result.= "<li$separator><a href='#' onClick='\$(\"act\").value= \"paste\";\$(\"exec_act\").click();'>".image("images/lists/paste.png")." "._("Paste")."</a></li>";
1402 }else{
1403 $result.= "<li$separator><a href='#'>".image('images/lists/paste-grey.png')." "._("Paste")."</a></li>";
1404 }
1405 }
1407 return($result);
1408 }
1411 function renderCopyPasteActions($row, $dn, $category, $class, $copy= true, $cut= true)
1412 {
1413 // We can only provide information if we've got a copypaste handler
1414 // instance
1415 if(!(isset($this->copyPasteHandler) && is_object($this->copyPasteHandler))){
1416 return "";
1417 }
1419 // Presets
1420 $ui = get_userinfo();
1421 $result = "";
1423 // Render cut entries
1424 if($cut){
1425 if($ui->is_cutable($dn, $category, $class)){
1426 $result.= image('images/lists/cut.png', "listing_cut_$row", _("Cut this entry"));
1427 }else{
1428 $result.= image('images/empty.png');
1429 }
1430 }
1432 // Render copy entries
1433 if($copy){
1434 if($ui->is_copyable($dn, $category, $class)){
1435 $result.= image('images/lists/copy.png', "listing_copy_$row", _("Copy this entry"));
1436 }else{
1437 $result.= image('images/empty.png');
1438 }
1439 }
1441 return($result);
1442 }
1445 function renderSnapshotMenu($separator)
1446 {
1447 // We can only provide information if we've got a snapshot handler
1448 // instance
1449 if(!(isset($this->snapshotHandler) && is_object($this->snapshotHandler))){
1450 return "";
1451 }
1453 // Presets
1454 $result = "";
1455 $ui = get_userinfo();
1457 if($this->snapshotHandler->enabled() && $ui->allow_snapshot_restore($this->base, $this->categories)){
1459 // Check if there is something to restore
1460 $restore= false;
1461 foreach($this->snapshotHandler->getSnapshotBases() as $base){
1462 $restore= $restore || count($this->snapshotHandler->getDeletedSnapshots($base)) > 0;
1463 }
1465 // Draw icons according to the restore flag
1466 if($restore){
1467 $result.= "<li$separator><a href='#' onClick='\$(\"act\").value= \"restore\";\$(\"exec_act\").click();'>".image('images/lists/restore.png')." "._("Restore snapshots")."</a></li>";
1468 }else{
1469 $result.= "<li$separator><a href='#'>".image('images/lists/restore-grey.png')." "._("Restore snapshots")."</a></li>";
1470 }
1471 }
1473 return($result);
1474 }
1477 function renderExporterMenu($separator)
1478 {
1479 // Presets
1480 $result = "";
1482 // Draw entries
1483 $result.= "<li$separator><a href='#'>".image('images/lists/export.png')." "._("Export list")." ".image("images/forward-arrow.png")."</a><ul class='level3'>";
1485 // Export CVS as build in exporter
1486 foreach ($this->exporter as $action => $exporter) {
1487 $result.= "<li><a href='#' onClick='\$(\"act\").value= \"$action\";\$(\"exec_act\").click();'>".image($exporter['image'])." ".$exporter['label']."</a></li>";
1488 }
1490 // Finalize list
1491 $result.= "</ul></li>";
1493 return($result);
1494 }
1497 function renderSnapshotActions($row, $dn, $category, $class, $copy= true, $cut= true)
1498 {
1499 // We can only provide information if we've got a snapshot handler
1500 // instance
1501 if(!(isset($this->snapshotHandler) && is_object($this->snapshotHandler))){
1502 return "";
1503 }
1505 // Presets
1506 $result= "";
1507 $ui = get_userinfo();
1509 // Only act if enabled here
1510 if($this->snapshotHandler->enabled()){
1512 // Draw restore button
1513 if ($ui->allow_snapshot_restore($dn, $category)){
1515 // Do we have snapshots for this dn?
1516 if($this->snapshotHandler->hasSnapshots($dn)){
1517 $result.= image('images/lists/restore.png', "listing_restore_$row", _("Restore snapshot"));
1518 } else {
1519 $result.= image('images/lists/restore-grey.png');
1520 }
1521 }
1523 // Draw snapshot button
1524 if($ui->allow_snapshot_create($dn, $category)){
1525 $result.= image('images/snapshot.png', "listing_snapshot_$row", _("Create a new snapshot from this object"));
1526 }else{
1527 $result.= image('images/empty.png');
1528 }
1529 }
1531 return($result);
1532 }
1535 function renderDaemonMenu($separator)
1536 {
1537 $result= "";
1539 // If there is a daemon registered, draw the menu entries
1540 if(class_available("DaemonEvent")){
1541 $events= DaemonEvent::get_event_types_by_category($this->categories);
1542 if(isset($events['BY_CLASS']) && count($events['BY_CLASS'])){
1543 foreach($events['BY_CLASS'] as $name => $event){
1544 $result.= "<li$separator><a href='#' onClick='\$(\"act\").value=\"$name\";\$(\"exec_act\").click();'>".$event['MenuImage']." ".$event['s_Menu_Name']."</a></li>";
1545 $separator= "";
1546 }
1547 }
1548 }
1550 return $result;
1551 }
1554 function getEntry($dn)
1555 {
1556 foreach ($this->entries as $entry) {
1557 if (isset($entry['dn']) && strcasecmp($dn, $entry['dn']) == 0){
1558 return $entry;
1559 }
1560 }
1561 return null;
1562 }
1565 function getEntries()
1566 {
1567 return $this->entries;
1568 }
1571 function getType($dn)
1572 {
1573 if (isset($this->objectDnMapping[$dn])) {
1574 return $this->objectDnMapping[$dn];
1575 }
1576 return null;
1577 }
1579 }
1581 ?>