d4f972d3da2c5357fdb2f11ed6fe0c502125e3f3
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 $filter->setCategories($this->categories);
127 $this->filter= &$filter;
128 if ($this->departmentBrowser){
129 $this->departments= $this->getDepartments();
130 }
131 $this->filter->setBase($this->base);
132 }
135 function registerElementFilter($name, $call)
136 {
137 if (!isset($this->filters[$name])) {
138 $this->filters[$name]= $call;
139 return true;
140 }
142 return false;
143 }
146 function load($filename)
147 {
148 $contents = file_get_contents($filename);
149 $this->xmlData= xml::xml2array($contents, 1);
151 if (!isset($this->xmlData['list'])) {
152 return false;
153 }
155 $this->xmlData= $this->xmlData["list"];
157 // Load some definition values
158 foreach (array("departmentBrowser", "departmentRootVisible", "multiSelect", "baseMode") as $token) {
159 if (isset($this->xmlData['definition'][$token]) &&
160 $this->xmlData['definition'][$token] == "true"){
161 $this->$token= true;
162 }
163 }
165 // Fill objectTypes from departments and xml definition
166 $types = departmentManagement::get_support_departments();
167 foreach ($types as $class => $data) {
168 $this->objectTypes[$data['OC']]= array("label" => $data['TITLE'],
169 "objectClass" => $data['OC'],
170 "image" => $data['IMG']);
171 }
172 $this->categories= array();
173 if (isset($this->xmlData['definition']['objectType'])) {
174 if(isset($this->xmlData['definition']['objectType']['label'])) {
175 $this->xmlData['definition']['objectType']= array($this->xmlData['definition']['objectType']);
176 }
177 foreach ($this->xmlData['definition']['objectType'] as $index => $otype) {
178 $tmp = $this->xmlData['definition']['objectType'][$index];
179 $this->objectTypes[$tmp['objectClass']]= $tmp;
180 if (isset($this->xmlData['definition']['objectType'][$index]['category'])){
181 $this->categories[]= $otype['category'];
182 }
183 }
184 }
185 $this->objectTypes = array_values($this->objectTypes);
187 // Parse layout per column
188 $this->colprops= $this->parseLayout($this->xmlData['table']['layout']);
190 // Prepare table headers
191 $this->renderHeader();
193 // Assign headline/Categories
194 $this->headline= _($this->xmlData['definition']['label']);
195 if (!is_array($this->categories)){
196 $this->categories= array($this->categories);
197 }
199 // Evaluate columns to be exported
200 if (isset($this->xmlData['table']['column'])){
201 foreach ($this->xmlData['table']['column'] as $index => $config) {
202 if (isset($config['export']) && $config['export'] == "true"){
203 $this->exportColumns[]= $index;
204 }
205 }
206 }
208 return true;
209 }
212 function renderHeader()
213 {
214 $this->header= array();
215 $this->plainHeader= array();
217 // Initialize sort?
218 $sortInit= false;
219 if (!$this->sortDirection) {
220 $this->sortColumn= 0;
221 if (isset($this->xmlData['definition']['defaultSortColumn'])){
222 $this->sortColumn= $this->xmlData['definition']['defaultSortColumn'];
223 } else {
224 $this->sortAttribute= "";
225 }
226 $this->sortDirection= array();
227 $sortInit= true;
228 }
230 if (isset($this->xmlData['table']['column'])){
231 foreach ($this->xmlData['table']['column'] as $index => $config) {
232 // Initialize everything to one direction
233 if ($sortInit) {
234 $this->sortDirection[$index]= false;
235 }
237 $sorter= "";
238 if ($index == $this->sortColumn && isset($config['sortAttribute']) &&
239 isset($config['sortType'])) {
240 $this->sortAttribute= $config['sortAttribute'];
241 $this->sortType= $config['sortType'];
242 $sorter= " ".image("images/lists/sort-".($this->sortDirection[$index]?"up":"down").".png", null, $this->sortDirection[$index]?_("Up"):_("Down"), "text-top");
243 }
244 $sortable= (isset($config['sortAttribute']));
246 $link= "href='?plug=".$_GET['plug']."&PID=".$this->pid."&act=SORT_$index'";
247 if (isset($config['label'])) {
248 if ($sortable) {
249 $this->header[$index]= "<td class='listheader' ".$this->colprops[$index]."><a $link>"._($config['label'])."</a>$sorter</td>";
250 } else {
251 $this->header[$index]= "<td class='listheader' ".$this->colprops[$index].">"._($config['label'])."</td>";
252 }
253 $this->plainHeader[]= _($config['label']);
254 } else {
255 if ($sortable) {
256 $this->header[$index]= "<td class='listheader' ".$this->colprops[$index]."><a $link> </a>$sorter</td>";
257 } else {
258 $this->header[$index]= "<td class='listheader' ".$this->colprops[$index]."> </td>";
259 }
260 $this->plainHeader[]= "";
261 }
262 }
263 }
264 }
267 function render()
268 {
269 // Check for exeeded sizelimit
270 if (($message= check_sizelimit()) != ""){
271 return($message);
272 }
274 // Some browsers don't have the ability do do scrollable table bodies, filter them
275 // here.
276 $switch= false;
277 if (preg_match('/(Opera|Konqueror|Safari)/i', $_SERVER['HTTP_USER_AGENT'])){
278 $switch= true;
279 }
281 // Initialize list
282 $result= "<input type='hidden' value='$this->pid' name='PID'>\n";
283 $result.= "<input type='hidden' name='position_".$this->pid."' id='position_".$this->pid."'>\n";
284 $height= 450;
285 if ($this->height != 0) {
286 $result.= "<input type='hidden' value='$this->height' id='d_height'>\n";
287 $height= $this->height;
288 }
290 $result.= "<div class='listContainer' id='d_scrollbody' style='min-height:".($height+25)."px;'>\n";
291 $result.= "<table summary='$this->headline' style='width:100%;table-layout:fixed' cellspacing='0' cellpadding='0' id='t_scrolltable'>\n";
292 $this->numColumns= count($this->colprops) + ($this->multiSelect?1:0);
294 // Build list header
295 $result.= "<thead class='fixedListHeader listHeaderFormat'><tr>\n";
296 if ($this->multiSelect) {
297 $width= "24px";
298 if (preg_match('/Konqueror/i', $_SERVER['HTTP_USER_AGENT'])){
299 $width= "28px";
300 }
301 $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";
302 }
303 foreach ($this->header as $header) {
304 $result.= $header;
305 }
306 $result.= "</tr></thead>\n";
308 // Build list body
309 $result.= "<tbody class='listScrollContent listBodyFormat' id='t_nscrollbody' style='height:".$height."px;'>\n";
311 // No results? Just take an empty colspanned row
312 if (count($this->entries) + count($this->departments) == 0) {
313 $result.= "<tr><td class='list1nohighlight' colspan='$this->numColumns' style='height:100%;border-right:0px;width:100%;'> </td></tr>";
314 }
316 // Line color alternation
317 $alt= 0;
318 $deps= 0;
320 // Draw department browser if configured and we're not in sub mode
321 $this->useSpan= false;
322 if ($this->departmentBrowser && $this->filter->scope != "sub") {
323 // Fill with department browser if configured this way
324 $departmentIterator= new departmentSortIterator($this->departments, $this->sortDirection[$this->sortColumn]);
325 foreach ($departmentIterator as $row => $entry){
326 $result.="<tr>";
328 // Render multi select if needed
329 if ($this->multiSelect) {
330 $result.="<td style='text-align:center;padding:0;' class='list1'> </td>";
331 }
333 // Render defined department columns, fill the rest with some stuff
334 $rest= $this->numColumns - 1;
335 foreach ($this->xmlData['table']['department'] as $index => $config) {
336 $colspan= 1;
337 if (isset($config['span'])){
338 $colspan= $config['span'];
339 $this->useSpan= true;
340 }
341 $result.="<td colspan='$colspan' ".$this->colprops[$index]." class='list1'>".$this->renderCell($config['value'], $entry, $row)."</td>";
342 $rest-= $colspan;
343 }
345 // Fill remaining cols with nothing
346 $last= $this->numColumns - $rest;
347 for ($i= 0; $i<$rest; $i++){
348 $result.= "<td ".$this->colprops[$last+$i-1]." class='list1'> </td>";
349 }
350 $result.="</tr>";
352 $alt++;
353 }
354 $deps= $alt;
355 }
357 // Fill with contents, sort as configured
358 foreach ($this->entries as $row => $entry) {
359 $trow= "";
361 // Render multi select if needed
362 if ($this->multiSelect) {
363 $trow.="<td style='text-align:center;width:20px;' class='list0'><input type='checkbox' id='listing_selected_$row' name='listing_selected_$row'></td>\n";
364 }
366 foreach ($this->xmlData['table']['column'] as $index => $config) {
367 $renderedCell= $this->renderCell($config['value'], $entry, $row);
368 $trow.="<td ".$this->colprops[$index]." class='list0'>".$renderedCell."</td>\n";
370 // Save rendered column
371 $sort= preg_replace('/.*>([^<]+)<.*$/', '$1', $renderedCell);
372 $sort= preg_replace('/ /', '', $sort);
373 if (preg_match('/</', $sort)){
374 $sort= "";
375 }
376 $this->entries[$row]["_sort$index"]= $sort;
377 }
379 // Save rendered entry
380 $this->entries[$row]['_rendered']= $trow;
381 }
383 // Complete list by sorting entries for _sort$index and appending them to the output
384 $entryIterator= new listingSortIterator($this->entries, $this->sortDirection[$this->sortColumn], "_sort".$this->sortColumn, $this->sortType);
385 foreach ($entryIterator as $row => $entry){
386 $result.="<tr>\n";
387 $result.= $entry['_rendered'];
388 $result.="</tr>\n";
389 $alt++;
390 }
392 // Need to fill the list if it's not full (nobody knows why this is 22 ;-))
393 $emptyListStyle= (count($this->entries) + (($this->useSpan && count($this->entries))?$deps:0) == 0)?"border:0;":"";
394 if ((count($this->entries) + $deps) < 22) {
395 $result.= "<tr>";
396 for ($i= 0; $i<$this->numColumns; $i++) {
397 if ($i == 0) {
398 $result.= "<td class='list1nohighlight' style='$emptyListStyle height:100%;'> </td>";
399 continue;
400 }
401 if ($i != $this->numColumns-1) {
402 $result.= "<td class='list1nohighlight' style='$emptyListStyle'> </td>";
403 } else {
404 $result.= "<td class='list1nohighlight' style='border-right:0;$emptyListStyle'> </td>";
405 }
406 }
407 $result.= "</tr>";
408 }
410 // Close list body
411 $result.= "</tbody></table></div>";
413 // Add the footer if requested
414 if ($this->showFooter) {
415 $result.= "<div class='nlistFooter'><div style='padding:3px'>";
417 foreach ($this->objectTypes as $objectType) {
418 if (isset($this->objectTypeCount[$objectType['label']])) {
419 $label= _($objectType['label']);
420 $result.= image($objectType['image'], null, $label)." ".$this->objectTypeCount[$objectType['label']]." ";
421 }
422 }
424 $result.= "</div></div>";
425 }
427 // Close list
428 $result.= $switch?"<input type='hidden' id='list_workaround'>":"";
430 // Add scroll positioner
431 $result.= '<script type="text/javascript" language="javascript">';
432 $result.= '$("t_nscrollbody").scrollTop= '.$this->scrollPosition.';';
433 $result.= 'var box = $("t_nscrollbody").onscroll= function() {$("position_'.$this->pid.'").value= this.scrollTop;}';
434 $result.= '</script>';
436 $smarty= get_smarty();
437 $smarty->assign("usePrototype", "true");
438 $smarty->assign("FILTER", $this->filter->render());
439 $smarty->assign("SIZELIMIT", print_sizelimit_warning());
440 $smarty->assign("LIST", $result);
442 // Assign navigation elements
443 $nav= $this->renderNavigation();
444 foreach ($nav as $key => $html) {
445 $smarty->assign($key, $html);
446 }
448 // Assign action menu / base
449 $smarty->assign("ACTIONS", $this->renderActionMenu());
450 $smarty->assign("BASE", $this->renderBase());
452 // Assign separator
453 $smarty->assign("SEPARATOR", "<img src='images/lists/seperator.png' alt='-' align='middle' height='16' width='1' class='center'>");
455 // Assign summary
456 $smarty->assign("HEADLINE", $this->headline);
458 // Try to load template from plugin the folder first...
459 $file = get_template_path($this->xmlData['definition']['template'], true);
461 // ... if this fails, try to load the file from the theme folder.
462 if(!file_exists($file)){
463 $file = get_template_path($this->xmlData['definition']['template']);
464 }
466 return ($smarty->fetch($file));
467 }
470 function update()
471 {
472 global $config;
473 $ui= get_userinfo();
475 // Take care of base selector
476 if ($this->baseMode) {
477 $this->baseSelector->update();
478 // Check if a wrong base was supplied
479 if(!$this->baseSelector->checkLastBaseUpdate()){
480 msg_dialog::display(_("Error"), msgPool::check_base(), ERROR_DIALOG);
481 }
482 }
484 // Save base
485 $refresh= false;
486 if ($this->baseMode) {
487 $this->base= $this->baseSelector->getBase();
488 session::global_set("CurrentMainBase", $this->base);
489 $refresh= true;
490 }
493 // Reset object counter / DN mapping
494 $this->objectTypeCount= array();
495 $this->objectDnMapping= array();
497 // Do not do anything if this is not our PID
498 if($refresh || !(isset($_REQUEST['PID']) && $_REQUEST['PID'] != $this->pid)) {
500 // Save position if set
501 if (isset($_POST['position_'.$this->pid]) && is_numeric($_POST['position_'.$this->pid])) {
502 $this->scrollPosition= $_POST['position_'.$this->pid];
503 }
505 // Override the base if we got a message from the browser navigation
506 if ($this->departmentBrowser && isset($_GET['act'])) {
507 if (preg_match('/^department_([0-9]+)$/', validate($_GET['act']), $match)){
508 if (isset($this->departments[$match[1]])){
509 $this->base= $this->departments[$match[1]]['dn'];
510 if ($this->baseMode) {
511 $this->baseSelector->setBase($this->base);
512 }
513 session::global_set("CurrentMainBase", $this->base);
514 }
515 }
516 }
518 // Filter POST with "act" attributes -> posted from action menu
519 if (isset($_POST['exec_act']) && $_POST['act'] != '') {
520 if (preg_match('/^export.*$/', $_POST['act']) && isset($this->exporter[$_POST['act']])) {
521 $exporter= $this->exporter[$_POST['act']];
522 $userinfo= ", "._("created by")." ".$ui->cn." - ".strftime('%A, %d. %B %Y, %H:%M:%S');
523 $entryIterator= new listingSortIterator($this->entries, $this->sortDirection[$this->sortColumn], "_sort".$this->sortColumn, $this->sortType);
524 $sortedEntries= array();
525 foreach ($entryIterator as $entry){
526 $sortedEntries[]= $entry;
527 }
528 $instance= new $exporter['class']($this->headline.$userinfo, $this->plainHeader, $sortedEntries, $this->exportColumns);
529 $type= call_user_func(array($exporter['class'], "getInfo"));
530 $type= $type[$_POST['act']];
531 send_binary_content($instance->query(), $type['filename'], $type= $type['mime']);
532 }
533 }
535 // Filter GET with "act" attributes
536 if (isset($_GET['act'])) {
537 $key= validate($_GET['act']);
538 if (preg_match('/^SORT_([0-9]+)$/', $key, $match)) {
539 // Switch to new column or invert search order?
540 $column= $match[1];
541 if ($this->sortColumn != $column) {
542 $this->sortColumn= $column;
543 } else {
544 $this->sortDirection[$column]= !$this->sortDirection[$column];
545 }
547 // Allow header to update itself according to the new sort settings
548 $this->renderHeader();
549 }
550 }
552 // Override base if we got signals from the navigation elements
553 $action= "";
554 foreach ($_POST as $key => $value) {
555 if (preg_match('/^(ROOT|BACK|HOME)(_x)?$/', $key, $match)) {
556 $action= $match[1];
557 break;
558 }
559 }
561 // Navigation handling
562 if ($action == 'ROOT') {
563 $deps= $ui->get_module_departments($this->categories);
564 $this->base= $deps[0];
565 $this->baseSelector->setBase($this->base);
566 session::global_set("CurrentMainBase", $this->base);
567 }
568 if ($action == 'BACK') {
569 $deps= $ui->get_module_departments($this->categories);
570 $base= preg_replace("/^[^,]+,/", "", $this->base);
571 if(in_array_ics($base, $deps)){
572 $this->base= $base;
573 $this->baseSelector->setBase($this->base);
574 session::global_set("CurrentMainBase", $this->base);
575 }
576 }
577 if ($action == 'HOME') {
578 $ui= get_userinfo();
579 $this->base= get_base_from_people($ui->dn);
580 $this->baseSelector->setBase($this->base);
581 session::global_set("CurrentMainBase", $this->base);
582 }
583 }
585 // Reload departments
586 if ($this->departmentBrowser){
587 $this->departments= $this->getDepartments();
588 }
590 // Update filter and refresh entries
591 $this->filter->setBase($this->base);
592 $this->entries= $this->filter->query();
594 // Fix filter if querie returns NULL
595 if ($this->entries == null) {
596 $this->entries= array();
597 }
598 }
601 function setBase($base)
602 {
603 $this->base= $base;
604 if ($this->baseMode) {
605 $this->baseSelector->setBase($this->base);
606 }
607 }
610 function getBase()
611 {
612 return $this->base;
613 }
616 function parseLayout($layout)
617 {
618 $result= array();
619 $layout= preg_replace("/^\|/", "", $layout);
620 $layout= preg_replace("/\|$/", "", $layout);
621 $cols= explode("|", $layout);
623 foreach ($cols as $index => $config) {
624 if ($config != "") {
625 $res= "";
626 $components= explode(';', $config);
627 foreach ($components as $part) {
628 if (preg_match("/^r$/", $part)) {
629 $res.= "text-align:right;";
630 continue;
631 }
632 if (preg_match("/^l$/", $part)) {
633 $res.= "text-align:left;";
634 continue;
635 }
636 if (preg_match("/^c$/", $part)) {
637 $res.= "text-align:center;";
638 continue;
639 }
640 if (preg_match("/^[0-9]+(|px|%)$/", $part)) {
641 $res.= "width:$part;min-width:$part;";
642 continue;
643 }
644 }
646 // Add minimum width for scalable columns
647 if (!preg_match('/width:/', $res)){
648 $res.= "min-width:200px;";
649 }
651 $result[$index]= " style='$res'";
652 } else {
653 $result[$index]= " style='min-width:100px;'";
654 }
655 }
657 // Save number of columns for later use
658 $this->numColumns= count($cols);
660 // Add no border to the last column
661 $result[$this->numColumns-1]= preg_replace("/'$/", "border-right:0;'", $result[$this->numColumns-1]);
663 return $result;
664 }
667 function renderCell($data, $config, $row)
668 {
669 // Replace flat attributes in data string
670 for ($i= 0; $i<$config['count']; $i++) {
671 $attr= $config[$i];
672 $value= "";
673 if (is_array($config[$attr])) {
674 $value= $config[$attr][0];
675 } else {
676 $value= $config[$attr];
677 }
678 $data= preg_replace("/%\{$attr\}/", $value, $data);
679 }
681 // Watch out for filters and prepare to execute them
682 $data= $this->processElementFilter($data, $config, $row);
684 // Replace all non replaced %{...} instances because they
685 // are non resolved attributes or filters
686 $data= preg_replace('/%{[^}]+}/', ' ', $data);
688 return $data;
689 }
692 function renderBase()
693 {
694 if (!$this->baseMode) {
695 return;
696 }
698 return $this->baseSelector->render();
699 }
702 function processElementFilter($data, $config, $row)
703 {
704 preg_match_all("/%\{filter:([^(]+)\((.*)\)\}/", $data, $matches, PREG_SET_ORDER);
706 foreach ($matches as $match) {
707 $cl= "";
708 $method= "";
709 if (preg_match('/::/', $match[1])) {
710 $cl= preg_replace('/::.*$/', '', $match[1]);
711 $method= preg_replace('/^.*::/', '', $match[1]);
712 } else {
713 if (!isset($this->filters[$match[1]])) {
714 continue;
715 }
716 $cl= preg_replace('/::.*$/', '', $this->filters[$match[1]]);
717 $method= preg_replace('/^.*::/', '', $this->filters[$match[1]]);
718 }
720 // Prepare params for function call
721 $params= array();
722 preg_match_all('/"[^"]+"|[^,]+/', $match[2], $parts);
723 foreach ($parts[0] as $param) {
725 // Row is replaced by the row number
726 if ($param == "row") {
727 $params[]= $row;
728 continue;
729 }
731 // pid is replaced by the current PID
732 if ($param == "pid") {
733 $params[]= $this->pid;
734 continue;
735 }
737 // base is replaced by the current base
738 if ($param == "base") {
739 $params[]= $this->getBase();
740 continue;
741 }
743 // Fixie with "" is passed directly
744 if (preg_match('/^".*"$/', $param)){
745 $params[]= preg_replace('/"/', '', $param);
746 continue;
747 }
749 // Move dn if needed
750 if ($param == "dn") {
751 $params[]= LDAP::fix($config["dn"]);
752 continue;
753 }
755 // LDAP variables get replaced by their objects
756 for ($i= 0; $i<$config['count']; $i++) {
757 if ($param == $config[$i]) {
758 $values= $config[$config[$i]];
759 if (is_array($values)){
760 unset($values['count']);
761 }
762 $params[]= $values;
763 break;
764 }
765 }
766 }
768 // Replace information
769 if ($cl == "listing") {
770 // Non static call - seems to result in errors
771 $data= @preg_replace('/'.preg_quote($match[0]).'/', call_user_func_array(array($this, "$method"), $params), $data);
772 } else {
773 // Static call
774 $data= preg_replace('/'.preg_quote($match[0]).'/', call_user_func_array(array($cl, $method), $params), $data);
775 }
776 }
778 return $data;
779 }
782 function getObjectType($types, $classes)
783 {
784 // Walk thru types and see if there's something matching
785 foreach ($types as $objectType) {
786 $ocs= $objectType['objectClass'];
787 if (!is_array($ocs)){
788 $ocs= array($ocs);
789 }
791 $found= true;
792 foreach ($ocs as $oc){
793 if (preg_match('/^!(.*)$/', $oc, $match)) {
794 $oc= $match[1];
795 if (in_array($oc, $classes)) {
796 $found= false;
797 }
798 } else {
799 if (!in_array($oc, $classes)) {
800 $found= false;
801 }
802 }
803 }
805 if ($found) {
806 return $objectType;
807 }
808 }
810 return null;
811 }
814 function filterObjectType($dn, $classes)
815 {
816 // Walk thru classes and return on first match
817 $result= " ";
819 $objectType= $this->getObjectType($this->objectTypes, $classes);
820 if ($objectType) {
821 $this->objectDnMapping[$dn]= $objectType["objectClass"];
822 $result= image($objectType["image"], null, LDAP::fix($dn));
823 if (!isset($this->objectTypeCount[$objectType['label']])) {
824 $this->objectTypeCount[$objectType['label']]= 0;
825 }
826 $this->objectTypeCount[$objectType['label']]++;
827 }
829 return $result;
830 }
833 function filterActions($dn, $row, $classes)
834 {
835 // Do nothing if there's no menu defined
836 if (!isset($this->xmlData['actiontriggers']['action'])) {
837 return " ";
838 }
840 // Go thru all actions
841 $result= "";
842 $actions= $this->xmlData['actiontriggers']['action'];
844 // Ensure we've a valid actions array, if there is only one action in the actiontriggers col
845 // then we've to create a valid array here.
846 if(isset($actions['name'])) $actions = array($actions);
848 foreach($actions as $action) {
849 // Skip the entry completely if there's no permission to execute it
850 if (!$this->hasActionPermission($action, $dn, $classes)) {
851 $result.= image('images/empty.png');
852 continue;
853 }
855 // Skip entry if the pseudo filter does not fit
856 if (isset($action['filter']) && preg_match('/^[a-z0-9_]+!?=[a-z0-9_]+$/i', $action['filter'])) {
857 list($fa, $fv)= explode('=', $action['filter']);
858 if (preg_match('/^(.*)!$/', $fa, $m)){
859 $fa= $m[1];
860 if (isset($this->entries[$row][$fa]) && $this->entries[$row][$fa][0] == $fv) {
861 $result.= image('images/empty.png');
862 continue;
863 }
864 } else {
865 if (!isset($this->entries[$row][$fa]) && !$this->entries[$row][$fa][0] == $fv) {
866 $result.= image('images/empty.png');
867 continue;
868 }
869 }
870 }
873 // If there's an objectclass definition and we don't have it
874 // add an empty picture here.
875 if (isset($action['objectclass'])){
876 $objectclass= $action['objectclass'];
877 if (preg_match('/^!(.*)$/', $objectclass, $m)){
878 $objectclass= $m[1];
879 if(in_array($objectclass, $classes)) {
880 $result.= image('images/empty.png');
881 continue;
882 }
883 } elseif (is_string($objectclass)) {
884 if(!in_array($objectclass, $classes)) {
885 $result.= image('images/empty.png');
886 continue;
887 }
888 } elseif (is_array($objectclass)) {
889 if(count(array_intersect($objectclass, $classes)) != count($objectclass)){
890 $result.= image('images/empty.png');
891 continue;
892 }
893 }
894 }
896 // Render normal entries as usual
897 if ($action['type'] == "entry") {
898 $label= $this->processElementFilter($action['label'], $this->entries[$row], $row);
899 $image= $this->processElementFilter($action['image'], $this->entries[$row], $row);
900 $result.= image($image, "listing_".$action['name']."_$row", $label);
901 }
903 // Handle special types
904 if ($action['type'] == "copypaste" || $action['type'] == "snapshot") {
906 $objectType= $this->getObjectType($this->objectTypes, $this->entries[$row]['objectClass']);
907 $category= $class= null;
908 if ($objectType) {
909 $category= $objectType['category'];
910 $class= $objectType['class'];
911 }
913 if ($action['type'] == "copypaste") {
914 $copy = !isset($action['copy']) || $action['copy'] == "true";
915 $cut = !isset($action['cut']) || $action['cut'] == "true";
916 $result.= $this->renderCopyPasteActions($row, $this->entries[$row]['dn'], $category, $class,$copy,$cut);
917 } else {
918 $result.= $this->renderSnapshotActions($row, $this->entries[$row]['dn'], $category, $class);
919 }
920 }
921 }
923 return $result;
924 }
927 function filterDepartmentLink($row, $dn, $description)
928 {
929 $attr= $this->departments[$row]['sort-attribute'];
930 $name= $this->departments[$row][$attr];
931 if (is_array($name)){
932 $name= $name[0];
933 }
934 $result= sprintf("%s [%s]", $name, $description[0]);
935 return("<a href='?plug=".$_GET['plug']."&PID=$this->pid&act=department_$row' title='$dn'>$result</a>");
936 }
939 function filterLink()
940 {
941 $result= " ";
943 $row= func_get_arg(0);
944 $pid= $this->pid;
945 $dn= LDAP::fix(func_get_arg(1));
946 $params= array(func_get_arg(2));
948 // Collect sprintf params
949 for ($i = 3;$i < func_num_args();$i++) {
950 $val= func_get_arg($i);
951 if (is_array($val)){
952 $params[]= $val[0];
953 continue;
954 }
955 $params[]= $val;
956 }
958 $result= " ";
959 $trans= call_user_func_array("sprintf", $params);
960 if ($trans != "") {
961 return("<a href='?plug=".$_GET['plug']."&PID=$pid&act=listing_edit_$row' title='$dn'>$trans</a>");
962 }
964 return $result;
965 }
968 function renderNavigation()
969 {
970 $result= array();
971 $enableBack = true;
972 $enableRoot = true;
973 $enableHome = true;
975 $ui = get_userinfo();
977 /* Check if base = first available base */
978 $deps = $ui->get_module_departments($this->categories);
980 if(!count($deps) || $deps[0] == $this->filter->base){
981 $enableBack = false;
982 $enableRoot = false;
983 }
985 $listhead ="";
987 /* Check if we are in users home department */
988 if(!count($deps) || $this->filter->base == get_base_from_people($ui->dn)){
989 $enableHome = false;
990 }
992 /* Draw root button */
993 if($enableRoot){
994 $result["ROOT"]= image('images/lists/root.png', 'ROOT', _("Root"));
995 }else{
996 $result["ROOT"]= image('images/lists/root-grey.png', null, _("Root"));
997 }
999 /* Draw back button */
1000 if($enableBack){
1001 $result["BACK"]= image('images/lists/back.png', 'BACK', _("Go up one department"));
1002 }else{
1003 $result["BACK"]= image('images/lists/back-grey.png', null, _("Go up one department"));
1004 }
1006 /* Draw home button */
1007 /* Draw home button */
1008 if($enableHome){
1009 $result["HOME"]= image('images/lists/home.png', 'HOME', _("Go to users department"));
1010 }else{
1011 $result["HOME"]= image('images/lists/home-grey.png', null, _("Go to users department"));
1012 }
1015 /* Draw reload button, this button is enabled everytime */
1016 $result["RELOAD"]= image('images/lists/reload.png', 'REFRESH', _("Reload list"));
1018 return ($result);
1019 }
1022 function getAction()
1023 {
1024 // Do not do anything if this is not our PID, or there's even no PID available...
1025 if(!isset($_REQUEST['PID']) || $_REQUEST['PID'] != $this->pid) {
1026 return;
1027 }
1029 // Save position if set
1030 if (isset($_POST['position_'.$this->pid]) && is_numeric($_POST['position_'.$this->pid])) {
1031 $this->scrollPosition= $_POST['position_'.$this->pid];
1032 }
1034 $result= array("targets" => array(), "action" => "");
1036 // Filter GET with "act" attributes
1037 if (isset($_GET['act'])) {
1038 $key= validate($_GET['act']);
1039 $target= preg_replace('/^listing_[a-zA-Z_]+_([0-9]+)$/', '$1', $key);
1040 if (isset($this->entries[$target]['dn'])) {
1041 $result['action']= preg_replace('/^listing_([a-zA-Z_]+)_[0-9]+$/', '$1', $key);
1042 $result['targets'][]= $this->entries[$target]['dn'];
1043 }
1045 // Drop targets if empty
1046 if (count($result['targets']) == 0) {
1047 unset($result['targets']);
1048 }
1049 return $result;
1050 }
1052 // Filter POST with "listing_" attributes
1053 foreach ($_POST as $key => $prop) {
1055 // Capture selections
1056 if (preg_match('/^listing_selected_[0-9]+$/', $key)) {
1057 $target= preg_replace('/^listing_selected_([0-9]+)$/', '$1', $key);
1058 if (isset($this->entries[$target]['dn'])) {
1059 $result['targets'][]= $this->entries[$target]['dn'];
1060 }
1061 continue;
1062 }
1064 // Capture action with target - this is a one shot
1065 if (preg_match('/^listing_[a-zA-Z_]+_[0-9]+(|_x)$/', $key)) {
1066 $target= preg_replace('/^listing_[a-zA-Z_]+_([0-9]+)(|_x)$/', '$1', $key);
1067 if (isset($this->entries[$target]['dn'])) {
1068 $result['action']= preg_replace('/^listing_([a-zA-Z_]+)_[0-9]+(|_x)$/', '$1', $key);
1069 $result['targets']= array($this->entries[$target]['dn']);
1070 }
1071 break;
1072 }
1074 // Capture action without target
1075 if (preg_match('/^listing_[a-zA-Z_]+(|_x)$/', $key)) {
1076 $result['action']= preg_replace('/^listing_([a-zA-Z_]+)(|_x)$/', '$1', $key);
1077 continue;
1078 }
1079 }
1081 // Filter POST with "act" attributes -> posted from action menu
1082 if (isset($_POST['act']) && $_POST['act'] != '') {
1083 if (!preg_match('/^export.*$/', $_POST['act'])){
1084 $result['action']= validate($_POST['act']);
1085 }
1086 }
1088 // Drop targets if empty
1089 if (count($result['targets']) == 0) {
1090 unset($result['targets']);
1091 }
1092 return $result;
1093 }
1096 function renderActionMenu()
1097 {
1098 // Don't send anything if the menu is not defined
1099 if (!isset($this->xmlData['actionmenu']['action'])){
1100 return "";
1101 }
1103 // Array?
1104 if (isset($this->xmlData['actionmenu']['action']['type'])){
1105 $this->xmlData['actionmenu']['action']= array($this->xmlData['actionmenu']['action']);
1106 }
1108 // Load shortcut
1109 $actions= &$this->xmlData['actionmenu']['action'];
1110 $result= "<input type='hidden' name='act' id='actionmenu' value=''><div style='display:none'><input type='submit' name='exec_act' id='exec_act' value=''></div>".
1111 "<ul class='level1' id='root'><li><a href='#'>"._("Actions")." ".image("images/lists/sort-down.png")."</a>";
1113 // Build ul/li list
1114 $result.= $this->recurseActions($actions);
1116 return "<div id='pulldown'>".$result."</li></ul><div>";
1117 }
1120 function recurseActions($actions)
1121 {
1122 global $class_mapping;
1123 static $level= 2;
1124 $result= "<ul class='level$level'>";
1125 $separator= "";
1127 foreach ($actions as $action) {
1129 // Skip the entry completely if there's no permission to execute it
1130 if (!$this->hasActionPermission($action, $this->filter->base)) {
1131 continue;
1132 }
1134 // Skip entry if there're missing dependencies
1135 if (isset($action['depends'])) {
1136 $deps= is_array($action['depends'])?$action['depends']:array($action['depends']);
1137 foreach($deps as $clazz) {
1138 if (!isset($class_mapping[$clazz])){
1139 continue 2;
1140 }
1141 }
1142 }
1144 // Fill image if set
1145 $img= "";
1146 if (isset($action['image'])){
1147 $img= image($action['image'])." ";
1148 }
1150 if ($action['type'] == "separator"){
1151 $separator= " style='border-top:1px solid #AAA' ";
1152 continue;
1153 }
1155 // Dive into subs
1156 if ($action['type'] == "sub" && isset($action['action'])) {
1157 $level++;
1158 if (isset($action['label'])){
1159 $result.= "<li$separator><a href='#'>$img"._($action['label'])." ".image('images/forward-arrow.png')."</a>";
1160 }
1162 // Ensure we've an array of actions, this enables sub menus with only one action.
1163 if(isset($action['action']['type'])){
1164 $action['action'] = array($action['action']);
1165 }
1167 $result.= $this->recurseActions($action['action'])."</li>";
1168 $level--;
1169 $separator= "";
1170 continue;
1171 }
1173 // Render entry elseways
1174 if (isset($action['label'])){
1175 $result.= "<li$separator><a href='#' onClick='document.getElementById(\"actionmenu\").value= \"".$action['name']."\";mainform.submit();'>$img"._($action['label'])."</a></li>";
1176 }
1178 // Check for special types
1179 switch ($action['type']) {
1180 case 'copypaste':
1181 $cut = !isset($action['cut']) || $action['cut'] != "false";
1182 $copy = !isset($action['copy']) || $action['copy'] != "false";
1183 $result.= $this->renderCopyPasteMenu($separator, $copy , $cut);
1184 break;
1186 case 'snapshot':
1187 $result.= $this->renderSnapshotMenu($separator);
1188 break;
1190 case 'exporter':
1191 $result.= $this->renderExporterMenu($separator);
1192 break;
1194 case 'daemon':
1195 $result.= $this->renderDaemonMenu($separator);
1196 break;
1197 }
1199 $separator= "";
1200 }
1202 $result.= "</ul>";
1203 return $result;
1204 }
1207 function hasActionPermission($action, $dn, $classes= null)
1208 {
1209 $ui= get_userinfo();
1211 if (isset($action['acl'])) {
1212 $acls= $action['acl'];
1213 if (!is_array($acls)) {
1214 $acls= array($acls);
1215 }
1217 // Every ACL has to pass
1218 foreach ($acls as $acl) {
1219 $module= $this->categories;
1220 $aclList= array();
1222 // Replace %acl if available
1223 if ($classes) {
1224 $otype= $this->getObjectType($this->objectTypes, $classes);
1225 $acl= str_replace('%acl', $otype['category']."/".$otype['class'], $acl);
1226 }
1228 // Split for category and plugins if needed
1229 // match for "[rw]" style entries
1230 if (preg_match('/^\[([rwcdm]+)\]$/', $acl, $match)){
1231 $aclList= array($match[1]);
1232 }
1234 // match for "users[rw]" style entries
1235 if (preg_match('/^([a-zA-Z0-9]+)\[([rwcdm]+)\]$/', $acl, $match)){
1236 $module= $match[1];
1237 $aclList= array($match[2]);
1238 }
1240 // match for "users/user[rw]" style entries
1241 if (preg_match('/^([a-zA-Z0-9]+\/[a-zA-Z0-9]+)\[([rwcdm]+)\]$/', $acl, $match)){
1242 $module= $match[1];
1243 $aclList= array($match[2]);
1244 }
1246 // match "users/user[userPassword:rw(,...)*]" style entries
1247 if (preg_match('/^([a-zA-Z0-9]+\/[a-zA-Z0-9]+)\[([a-zA-Z0-9]+:[rwcdm]+(,[a-zA-Z0-9]+:[rwcdm]+)*)\]$/', $acl, $match)){
1248 $module= $match[1];
1249 $aclList= explode(',', $match[2]);
1250 }
1252 // Walk thru prepared ACL by using $module
1253 foreach($aclList as $sAcl) {
1254 $checkAcl= "";
1256 // Category or detailed permission?
1257 if (strpos($module, '/') !== false) {
1258 if (preg_match('/([a-zA-Z0-9]+):([rwcdm]+)/', $sAcl, $m) ) {
1259 $checkAcl= $ui->get_permissions($dn, $module, $m[1]);
1260 $sAcl= $m[2];
1261 } else {
1262 $checkAcl= $ui->get_permissions($dn, $module, '0');
1263 }
1264 } else {
1265 $checkAcl= $ui->get_category_permissions($dn, $module);
1266 }
1268 // Split up remaining part of the acl and check if it we're
1269 // allowed to do something...
1270 $parts= str_split($sAcl);
1271 foreach ($parts as $part) {
1272 if (strpos($checkAcl, $part) === false){
1273 return false;
1274 }
1275 }
1277 }
1278 }
1279 }
1281 return true;
1282 }
1285 function refreshBasesList()
1286 {
1287 global $config;
1288 $ui= get_userinfo();
1290 // Do some array munching to get it user friendly
1291 $ids= $config->idepartments;
1292 $d= $ui->get_module_departments($this->categories);
1293 $k_ids= array_keys($ids);
1294 $deps= array_intersect($d,$k_ids);
1296 // Fill internal bases list
1297 $this->bases= array();
1298 foreach($k_ids as $department){
1299 $this->bases[$department] = $ids[$department];
1300 }
1302 // Populate base selector if already present
1303 if ($this->baseSelector && $this->baseMode) {
1304 $this->baseSelector->setBases($this->bases);
1305 $this->baseSelector->update(TRUE);
1306 }
1307 }
1310 function getDepartments()
1311 {
1312 $departments= array();
1313 $ui= get_userinfo();
1315 // Get list of supported department types
1316 $types = departmentManagement::get_support_departments();
1318 // Load departments allowed by ACL
1319 $validDepartments = $ui->get_module_departments($this->categories);
1321 // Build filter and look in the LDAP for possible sub departments
1322 // of current base
1323 $filter= "(&(objectClass=gosaDepartment)(|";
1324 $attrs= array("description", "objectClass");
1325 foreach($types as $name => $data){
1326 $filter.= "(objectClass=".$data['OC'].")";
1327 $attrs[]= $data['ATTR'];
1328 }
1329 $filter.= "))";
1330 $res= get_list($filter, $this->categories, $this->base, $attrs, GL_NONE);
1332 // Analyze list of departments
1333 foreach ($res as $department) {
1334 if (!in_array($department['dn'], $validDepartments)) {
1335 continue;
1336 }
1338 // Add the attribute where we use for sorting
1339 $oc= null;
1340 foreach(array_keys($types) as $type) {
1341 if (in_array($type, $department['objectClass'])) {
1342 $oc= $type;
1343 break;
1344 }
1345 }
1346 $department['sort-attribute']= $types[$oc]['ATTR'];
1348 // Move to the result list
1349 $departments[]= $department;
1350 }
1352 return $departments;
1353 }
1356 function renderCopyPasteMenu($separator, $copy= true, $cut= true)
1357 {
1358 // We can only provide information if we've got a copypaste handler
1359 // instance
1360 if(!(isset($this->copyPasteHandler) && is_object($this->copyPasteHandler))){
1361 return "";
1362 }
1364 // Presets
1365 $result= "";
1366 $read= $paste= false;
1367 $ui= get_userinfo();
1369 // Switch flags to on if there's at least one category which allows read/paste
1370 foreach($this->categories as $category){
1371 $read= $read || preg_match('/r/', $ui->get_category_permissions($this->base, $category));
1372 $paste= $paste || $ui->is_pasteable($this->base, $category) == 1;
1373 }
1376 // Draw entries that allow copy and cut
1377 if($read){
1379 // Copy entry
1380 if($copy){
1381 $result.= "<li$separator><a href='#' onClick='document.getElementById(\"actionmenu\").value= \"copy\";document.getElementById(\"exec_act\").click();'>".image('images/lists/copy.png')." "._("Copy")."</a></li>";
1382 $separator= "";
1383 }
1385 // Cut entry
1386 if($cut){
1387 $result.= "<li$separator><a href='#' onClick='document.getElementById(\"actionmenu\").value= \"cut\";document.getElementById(\"exec_act\").click();'>".image("images/lists/cut.png")." "._("Cut")."</a></li>";
1388 $separator= "";
1389 }
1390 }
1392 // Draw entries that allow pasting entries
1393 if($paste){
1394 if($this->copyPasteHandler->entries_queued()){
1395 $result.= "<li$separator><a href='#' onClick='document.getElementById(\"actionmenu\").value= \"paste\";document.getElementById(\"exec_act\").click();'>".image("images/lists/paste.png")." "._("Paste")."</a></li>";
1396 }else{
1397 $result.= "<li$separator><a href='#'>".image('images/lists/paste-grey.png')." "._("Paste")."</a></li>";
1398 }
1399 }
1401 return($result);
1402 }
1405 function renderCopyPasteActions($row, $dn, $category, $class, $copy= true, $cut= true)
1406 {
1407 // We can only provide information if we've got a copypaste handler
1408 // instance
1409 if(!(isset($this->copyPasteHandler) && is_object($this->copyPasteHandler))){
1410 return "";
1411 }
1413 // Presets
1414 $ui = get_userinfo();
1415 $result = "";
1417 // Render cut entries
1418 if($cut){
1419 if($ui->is_cutable($dn, $category, $class)){
1420 $result.= image('images/lists/cut.png', "listing_cut_$row", _("Cut this entry"));
1421 }else{
1422 $result.= image('images/empty.png');
1423 }
1424 }
1426 // Render copy entries
1427 if($copy){
1428 if($ui->is_copyable($dn, $category, $class)){
1429 $result.= image('images/lists/copy.png', "listing_copy_$row", _("Copy this entry"));
1430 }else{
1431 $result.= image('images/empty.png');
1432 }
1433 }
1435 return($result);
1436 }
1439 function renderSnapshotMenu($separator)
1440 {
1441 // We can only provide information if we've got a snapshot handler
1442 // instance
1443 if(!(isset($this->snapshotHandler) && is_object($this->snapshotHandler))){
1444 return "";
1445 }
1447 // Presets
1448 $result = "";
1449 $ui = get_userinfo();
1451 if($this->snapshotHandler->enabled() && $ui->allow_snapshot_restore($this->base, $this->categories)){
1453 // Check if there is something to restore
1454 $restore= false;
1455 foreach($this->snapshotHandler->getSnapshotBases() as $base){
1456 $restore= $restore || count($this->snapshotHandler->getDeletedSnapshots($base)) > 0;
1457 }
1459 // Draw icons according to the restore flag
1460 if($restore){
1461 $result.= "<li$separator><a href='#' onClick='document.getElementById(\"actionmenu\").value= \"restore\";document.getElementById(\"exec_act\").click();'>".image('images/lists/restore.png')." "._("Restore snapshots")."</a></li>";
1462 }else{
1463 $result.= "<li$separator><a href='#'>".image('images/lists/restore-grey.png')." "._("Restore snapshots")."</a></li>";
1464 }
1465 }
1467 return($result);
1468 }
1471 function renderExporterMenu($separator)
1472 {
1473 // Presets
1474 $result = "";
1476 // Draw entries
1477 $result.= "<li$separator><a href='#'>".image('images/lists/export.png')." "._("Export list")." ".image("images/forward-arrow.png")."</a><ul class='level3'>";
1479 // Export CVS as build in exporter
1480 foreach ($this->exporter as $action => $exporter) {
1481 $result.= "<li><a href='#' onClick='document.getElementById(\"actionmenu\").value= \"$action\";document.getElementById(\"exec_act\").click();'>".image($exporter['image'])." ".$exporter['label']."</a></li>";
1482 }
1484 // Finalize list
1485 $result.= "</ul></li>";
1487 return($result);
1488 }
1491 function renderSnapshotActions($row, $dn, $category, $class, $copy= true, $cut= true)
1492 {
1493 // We can only provide information if we've got a snapshot handler
1494 // instance
1495 if(!(isset($this->snapshotHandler) && is_object($this->snapshotHandler))){
1496 return "";
1497 }
1499 // Presets
1500 $result= "";
1501 $ui = get_userinfo();
1503 // Only act if enabled here
1504 if($this->snapshotHandler->enabled()){
1506 // Draw restore button
1507 if ($ui->allow_snapshot_restore($dn, $category)){
1509 // Do we have snapshots for this dn?
1510 if($this->snapshotHandler->hasSnapshots($dn)){
1511 $result.= image('images/lists/restore.png', "listing_restore_$row", _("Restore snapshot"));
1512 } else {
1513 $result.= image('images/lists/restore-grey.png');
1514 }
1515 }
1517 // Draw snapshot button
1518 if($ui->allow_snapshot_create($dn, $category)){
1519 $result.= image('images/snapshot.png', "listing_snapshot_$row", _("Create a new snapshot from this object"));
1520 }else{
1521 $result.= image('images/empty.png');
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 ?>