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("HEADLINE", $this->headline);
455 $smarty->assign("ACTIONS", $this->renderActionMenu());
456 $smarty->assign("BASE", $this->renderBase());
458 // Assign separator
459 $smarty->assign("SEPARATOR", "<img src='images/lists/seperator.png' alt='-' align='middle' height='16' width='1' class='center'>");
461 // Assign summary
462 $smarty->assign("HEADLINE", $this->headline);
464 // Try to load template from plugin the folder first...
465 $file = get_template_path($this->xmlData['definition']['template'], true);
467 // ... if this fails, try to load the file from the theme folder.
468 if(!file_exists($file)){
469 $file = get_template_path($this->xmlData['definition']['template']);
470 }
472 return ($smarty->fetch($file));
473 }
476 function update()
477 {
478 global $config;
479 $ui= get_userinfo();
481 // Take care of base selector
482 if ($this->baseMode) {
483 $this->baseSelector->update();
484 // Check if a wrong base was supplied
485 if(!$this->baseSelector->checkLastBaseUpdate()){
486 msg_dialog::display(_("Error"), msgPool::check_base(), ERROR_DIALOG);
487 }
488 }
490 // Save base
491 $refresh= false;
492 if ($this->baseMode) {
493 $this->base= $this->baseSelector->getBase();
494 session::global_set("CurrentMainBase", $this->base);
495 $refresh= true;
496 }
499 // Reset object counter / DN mapping
500 $this->objectTypeCount= array();
501 $this->objectDnMapping= array();
503 // Do not do anything if this is not our PID
504 if($refresh || !(isset($_REQUEST['PID']) && $_REQUEST['PID'] != $this->pid)) {
506 // Save position if set
507 if (isset($_POST['position_'.$this->pid]) && is_numeric($_POST['position_'.$this->pid])) {
508 $this->scrollPosition= $_POST['position_'.$this->pid];
509 }
511 // Override the base if we got a message from the browser navigation
512 if ($this->departmentBrowser && isset($_GET['act'])) {
513 if (preg_match('/^department_([0-9]+)$/', validate($_GET['act']), $match)){
514 if (isset($this->departments[$match[1]])){
515 $this->base= $this->departments[$match[1]]['dn'];
516 if ($this->baseMode) {
517 $this->baseSelector->setBase($this->base);
518 }
519 session::global_set("CurrentMainBase", $this->base);
520 }
521 }
522 }
524 // Filter POST with "act" attributes -> posted from action menu
525 if (isset($_POST['exec_act']) && $_POST['act'] != '') {
526 if (preg_match('/^export.*$/', $_POST['act']) && isset($this->exporter[$_POST['act']])) {
527 $exporter= $this->exporter[$_POST['act']];
528 $userinfo= ", "._("created by")." ".$ui->cn." - ".strftime('%A, %d. %B %Y, %H:%M:%S');
529 $entryIterator= new listingSortIterator($this->entries, $this->sortDirection[$this->sortColumn], "_sort".$this->sortColumn, $this->sortType);
530 $sortedEntries= array();
531 foreach ($entryIterator as $entry){
532 $sortedEntries[]= $entry;
533 }
534 $instance= new $exporter['class']($this->headline.$userinfo, $this->plainHeader, $sortedEntries, $this->exportColumns);
535 $type= call_user_func(array($exporter['class'], "getInfo"));
536 $type= $type[$_POST['act']];
537 send_binary_content($instance->query(), $type['filename'], $type= $type['mime']);
538 }
539 }
541 // Filter GET with "act" attributes
542 if (isset($_GET['act'])) {
543 $key= validate($_GET['act']);
544 if (preg_match('/^SORT_([0-9]+)$/', $key, $match)) {
545 // Switch to new column or invert search order?
546 $column= $match[1];
547 if ($this->sortColumn != $column) {
548 $this->sortColumn= $column;
549 } else {
550 $this->sortDirection[$column]= !$this->sortDirection[$column];
551 }
553 // Allow header to update itself according to the new sort settings
554 $this->renderHeader();
555 }
556 }
558 // Override base if we got signals from the navigation elements
559 $action= "";
560 foreach ($_POST as $key => $value) {
561 if (preg_match('/^(ROOT|BACK|HOME)(_x)?$/', $key, $match)) {
562 $action= $match[1];
563 break;
564 }
565 }
567 // Navigation handling
568 if ($action == 'ROOT') {
569 $deps= $ui->get_module_departments($this->categories);
570 $this->base= $deps[0];
571 $this->baseSelector->setBase($this->base);
572 session::global_set("CurrentMainBase", $this->base);
573 }
574 if ($action == 'BACK') {
575 $deps= $ui->get_module_departments($this->categories);
576 $base= preg_replace("/^[^,]+,/", "", $this->base);
577 if(in_array_ics($base, $deps)){
578 $this->base= $base;
579 $this->baseSelector->setBase($this->base);
580 session::global_set("CurrentMainBase", $this->base);
581 }
582 }
583 if ($action == 'HOME') {
584 $ui= get_userinfo();
585 $this->base= get_base_from_people($ui->dn);
586 $this->baseSelector->setBase($this->base);
587 session::global_set("CurrentMainBase", $this->base);
588 }
589 }
591 // Reload departments
592 if ($this->departmentBrowser){
593 $this->departments= $this->getDepartments();
594 }
596 // Update filter and refresh entries
597 $this->filter->setBase($this->base);
598 $this->entries= $this->filter->query();
600 // Fix filter if querie returns NULL
601 if ($this->entries == null) {
602 $this->entries= array();
603 }
604 }
607 function setBase($base)
608 {
609 $this->base= $base;
610 if ($this->baseMode) {
611 $this->baseSelector->setBase($this->base);
612 }
613 }
616 function getBase()
617 {
618 return $this->base;
619 }
622 function parseLayout($layout)
623 {
624 $result= array();
625 $layout= preg_replace("/^\|/", "", $layout);
626 $layout= preg_replace("/\|$/", "", $layout);
627 $cols= explode("|", $layout);
629 foreach ($cols as $index => $config) {
630 if ($config != "") {
631 $res= "";
632 $components= explode(';', $config);
633 foreach ($components as $part) {
634 if (preg_match("/^r$/", $part)) {
635 $res.= "text-align:right;";
636 continue;
637 }
638 if (preg_match("/^l$/", $part)) {
639 $res.= "text-align:left;";
640 continue;
641 }
642 if (preg_match("/^c$/", $part)) {
643 $res.= "text-align:center;";
644 continue;
645 }
646 if (preg_match("/^[0-9]+(|px|%)$/", $part)) {
647 $res.= "width:$part;min-width:$part;";
648 continue;
649 }
650 }
652 // Add minimum width for scalable columns
653 if (!preg_match('/width:/', $res)){
654 $res.= "min-width:200px;";
655 }
657 $result[$index]= " style='$res'";
658 } else {
659 $result[$index]= " style='min-width:100px;'";
660 }
661 }
663 // Save number of columns for later use
664 $this->numColumns= count($cols);
666 // Add no border to the last column
667 $result[$this->numColumns-1]= preg_replace("/'$/", "border-right:0;'", $result[$this->numColumns-1]);
669 return $result;
670 }
673 function renderCell($data, $config, $row)
674 {
675 // Replace flat attributes in data string
676 for ($i= 0; $i<$config['count']; $i++) {
677 $attr= $config[$i];
678 $value= "";
679 if (is_array($config[$attr])) {
680 $value= $config[$attr][0];
681 } else {
682 $value= $config[$attr];
683 }
684 $data= preg_replace("/%\{$attr\}/", $value, $data);
685 }
687 // Watch out for filters and prepare to execute them
688 $data= $this->processElementFilter($data, $config, $row);
690 // Replace all non replaced %{...} instances because they
691 // are non resolved attributes or filters
692 $data= preg_replace('/%{[^}]+}/', ' ', $data);
694 return $data;
695 }
698 function renderBase()
699 {
700 if (!$this->baseMode) {
701 return;
702 }
704 return $this->baseSelector->render();
705 }
708 function processElementFilter($data, $config, $row)
709 {
710 preg_match_all("/%\{filter:([^(]+)\((.*)\)\}/", $data, $matches, PREG_SET_ORDER);
712 foreach ($matches as $match) {
713 $cl= "";
714 $method= "";
715 if (preg_match('/::/', $match[1])) {
716 $cl= preg_replace('/::.*$/', '', $match[1]);
717 $method= preg_replace('/^.*::/', '', $match[1]);
718 } else {
719 if (!isset($this->filters[$match[1]])) {
720 continue;
721 }
722 $cl= preg_replace('/::.*$/', '', $this->filters[$match[1]]);
723 $method= preg_replace('/^.*::/', '', $this->filters[$match[1]]);
724 }
726 // Prepare params for function call
727 $params= array();
728 preg_match_all('/"[^"]+"|[^,]+/', $match[2], $parts);
729 foreach ($parts[0] as $param) {
731 // Row is replaced by the row number
732 if ($param == "row") {
733 $params[]= $row;
734 continue;
735 }
737 // pid is replaced by the current PID
738 if ($param == "pid") {
739 $params[]= $this->pid;
740 continue;
741 }
743 // base is replaced by the current base
744 if ($param == "base") {
745 $params[]= $this->getBase();
746 continue;
747 }
749 // Fixie with "" is passed directly
750 if (preg_match('/^".*"$/', $param)){
751 $params[]= preg_replace('/"/', '', $param);
752 continue;
753 }
755 // Move dn if needed
756 if ($param == "dn") {
757 $params[]= LDAP::fix($config["dn"]);
758 continue;
759 }
761 // LDAP variables get replaced by their objects
762 for ($i= 0; $i<$config['count']; $i++) {
763 if ($param == $config[$i]) {
764 $values= $config[$config[$i]];
765 if (is_array($values)){
766 unset($values['count']);
767 }
768 $params[]= $values;
769 break;
770 }
771 }
772 }
774 // Replace information
775 if ($cl == "listing") {
776 // Non static call - seems to result in errors
777 $data= @preg_replace('/'.preg_quote($match[0]).'/', call_user_func_array(array($this, "$method"), $params), $data);
778 } else {
779 // Static call
780 $data= preg_replace('/'.preg_quote($match[0]).'/', call_user_func_array(array($cl, $method), $params), $data);
781 }
782 }
784 return $data;
785 }
788 function getObjectType($types, $classes)
789 {
790 // Walk thru types and see if there's something matching
791 foreach ($types as $objectType) {
792 $ocs= $objectType['objectClass'];
793 if (!is_array($ocs)){
794 $ocs= array($ocs);
795 }
797 $found= true;
798 foreach ($ocs as $oc){
799 if (preg_match('/^!(.*)$/', $oc, $match)) {
800 $oc= $match[1];
801 if (in_array($oc, $classes)) {
802 $found= false;
803 }
804 } else {
805 if (!in_array($oc, $classes)) {
806 $found= false;
807 }
808 }
809 }
811 if ($found) {
812 return $objectType;
813 }
814 }
816 return null;
817 }
820 function filterObjectType($dn, $classes)
821 {
822 // Walk thru classes and return on first match
823 $result= " ";
825 $objectType= $this->getObjectType($this->objectTypes, $classes);
826 if ($objectType) {
827 $this->objectDnMapping[$dn]= $objectType["objectClass"];
828 $result= image($objectType["image"], null, LDAP::fix($dn));
829 if (!isset($this->objectTypeCount[$objectType['label']])) {
830 $this->objectTypeCount[$objectType['label']]= 0;
831 }
832 $this->objectTypeCount[$objectType['label']]++;
833 }
835 return $result;
836 }
839 function filterActions($dn, $row, $classes)
840 {
841 // Do nothing if there's no menu defined
842 if (!isset($this->xmlData['actiontriggers']['action'])) {
843 return " ";
844 }
846 // Go thru all actions
847 $result= "";
848 $actions= $this->xmlData['actiontriggers']['action'];
850 // Ensure we've a valid actions array, if there is only one action in the actiontriggers col
851 // then we've to create a valid array here.
852 if(isset($actions['name'])) $actions = array($actions);
854 foreach($actions as $action) {
855 // Skip the entry completely if there's no permission to execute it
856 if (!$this->hasActionPermission($action, $dn, $classes)) {
857 $result.= image('images/empty.png');
858 continue;
859 }
861 // Skip entry if the pseudo filter does not fit
862 if (isset($action['filter']) && preg_match('/^[a-z0-9_]+!?=[a-z0-9_]+$/i', $action['filter'])) {
863 list($fa, $fv)= explode('=', $action['filter']);
864 if (preg_match('/^(.*)!$/', $fa, $m)){
865 $fa= $m[1];
866 if (isset($this->entries[$row][$fa]) && $this->entries[$row][$fa][0] == $fv) {
867 $result.= image('images/empty.png');
868 continue;
869 }
870 } else {
871 if (!isset($this->entries[$row][$fa]) && !$this->entries[$row][$fa][0] == $fv) {
872 $result.= image('images/empty.png');
873 continue;
874 }
875 }
876 }
879 // If there's an objectclass definition and we don't have it
880 // add an empty picture here.
881 if (isset($action['objectclass'])){
882 $objectclass= $action['objectclass'];
883 if (preg_match('/^!(.*)$/', $objectclass, $m)){
884 $objectclass= $m[1];
885 if(in_array($objectclass, $classes)) {
886 $result.= image('images/empty.png');
887 continue;
888 }
889 } elseif (is_string($objectclass)) {
890 if(!in_array($objectclass, $classes)) {
891 $result.= image('images/empty.png');
892 continue;
893 }
894 } elseif (is_array($objectclass)) {
895 if(count(array_intersect($objectclass, $classes)) != count($objectclass)){
896 $result.= image('images/empty.png');
897 continue;
898 }
899 }
900 }
902 // Render normal entries as usual
903 if ($action['type'] == "entry") {
904 $label= $this->processElementFilter($action['label'], $this->entries[$row], $row);
905 $image= $this->processElementFilter($action['image'], $this->entries[$row], $row);
906 $result.= image($image, "listing_".$action['name']."_$row", $label);
907 }
909 // Handle special types
910 if ($action['type'] == "copypaste" || $action['type'] == "snapshot") {
912 $objectType= $this->getObjectType($this->objectTypes, $this->entries[$row]['objectClass']);
913 $category= $class= null;
914 if ($objectType) {
915 $category= $objectType['category'];
916 $class= $objectType['class'];
917 }
919 if ($action['type'] == "copypaste") {
920 $copy = !isset($action['copy']) || $action['copy'] == "true";
921 $cut = !isset($action['cut']) || $action['cut'] == "true";
922 $result.= $this->renderCopyPasteActions($row, $this->entries[$row]['dn'], $category, $class,$copy,$cut);
923 } else {
924 $result.= $this->renderSnapshotActions($row, $this->entries[$row]['dn'], $category, $class);
925 }
926 }
927 }
929 return $result;
930 }
933 function filterDepartmentLink($row, $dn, $description)
934 {
935 $attr= $this->departments[$row]['sort-attribute'];
936 $name= $this->departments[$row][$attr];
937 if (is_array($name)){
938 $name= $name[0];
939 }
940 $result= sprintf("%s [%s]", $name, $description[0]);
941 return("<a href='?plug=".$_GET['plug']."&PID=$this->pid&act=department_$row' title='$dn'>$result</a>");
942 }
945 function filterLink()
946 {
947 $result= " ";
949 $row= func_get_arg(0);
950 $pid= $this->pid;
951 $dn= LDAP::fix(func_get_arg(1));
952 $params= array(func_get_arg(2));
954 // Collect sprintf params
955 for ($i = 3;$i < func_num_args();$i++) {
956 $val= func_get_arg($i);
957 if (is_array($val)){
958 $params[]= $val[0];
959 continue;
960 }
961 $params[]= $val;
962 }
964 $result= " ";
965 $trans= call_user_func_array("sprintf", $params);
966 if ($trans != "") {
967 return("<a href='?plug=".$_GET['plug']."&PID=$pid&act=listing_edit_$row' title='$dn'>$trans</a>");
968 }
970 return $result;
971 }
974 function renderNavigation()
975 {
976 $result= array();
977 $enableBack = true;
978 $enableRoot = true;
979 $enableHome = true;
981 $ui = get_userinfo();
983 /* Check if base = first available base */
984 $deps = $ui->get_module_departments($this->categories);
986 if(!count($deps) || $deps[0] == $this->filter->base){
987 $enableBack = false;
988 $enableRoot = false;
989 }
991 $listhead ="";
993 /* Check if we are in users home department */
994 if(!count($deps) || $this->filter->base == get_base_from_people($ui->dn)){
995 $enableHome = false;
996 }
998 /* Draw root button */
999 if($enableRoot){
1000 $result["ROOT"]= image('images/lists/root.png', 'ROOT', _("Root"));
1001 }else{
1002 $result["ROOT"]= image('images/lists/root-grey.png', null, _("Root"));
1003 }
1005 /* Draw back button */
1006 if($enableBack){
1007 $result["BACK"]= image('images/lists/back.png', 'BACK', _("Go up one department"));
1008 }else{
1009 $result["BACK"]= image('images/lists/back-grey.png', null, _("Go up one department"));
1010 }
1012 /* Draw home button */
1013 /* Draw home button */
1014 if($enableHome){
1015 $result["HOME"]= image('images/lists/home.png', 'HOME', _("Go to users department"));
1016 }else{
1017 $result["HOME"]= image('images/lists/home-grey.png', null, _("Go to users department"));
1018 }
1021 /* Draw reload button, this button is enabled everytime */
1022 $result["RELOAD"]= image('images/lists/reload.png', 'REFRESH', _("Reload list"));
1024 return ($result);
1025 }
1028 function getAction()
1029 {
1030 // Do not do anything if this is not our PID, or there's even no PID available...
1031 if(!isset($_REQUEST['PID']) || $_REQUEST['PID'] != $this->pid) {
1032 return;
1033 }
1035 // Save position if set
1036 if (isset($_POST['position_'.$this->pid]) && is_numeric($_POST['position_'.$this->pid])) {
1037 $this->scrollPosition= $_POST['position_'.$this->pid];
1038 }
1040 $result= array("targets" => array(), "action" => "");
1042 // Filter GET with "act" attributes
1043 if (isset($_GET['act'])) {
1044 $key= validate($_GET['act']);
1045 $target= preg_replace('/^listing_[a-zA-Z_]+_([0-9]+)$/', '$1', $key);
1046 if (isset($this->entries[$target]['dn'])) {
1047 $result['action']= preg_replace('/^listing_([a-zA-Z_]+)_[0-9]+$/', '$1', $key);
1048 $result['targets'][]= $this->entries[$target]['dn'];
1049 }
1051 // Drop targets if empty
1052 if (count($result['targets']) == 0) {
1053 unset($result['targets']);
1054 }
1055 return $result;
1056 }
1058 // Filter POST with "listing_" attributes
1059 foreach ($_POST as $key => $prop) {
1061 // Capture selections
1062 if (preg_match('/^listing_selected_[0-9]+$/', $key)) {
1063 $target= preg_replace('/^listing_selected_([0-9]+)$/', '$1', $key);
1064 if (isset($this->entries[$target]['dn'])) {
1065 $result['targets'][]= $this->entries[$target]['dn'];
1066 }
1067 continue;
1068 }
1070 // Capture action with target - this is a one shot
1071 if (preg_match('/^listing_[a-zA-Z_]+_[0-9]+(|_x)$/', $key)) {
1072 $target= preg_replace('/^listing_[a-zA-Z_]+_([0-9]+)(|_x)$/', '$1', $key);
1073 if (isset($this->entries[$target]['dn'])) {
1074 $result['action']= preg_replace('/^listing_([a-zA-Z_]+)_[0-9]+(|_x)$/', '$1', $key);
1075 $result['targets']= array($this->entries[$target]['dn']);
1076 }
1077 break;
1078 }
1080 // Capture action without target
1081 if (preg_match('/^listing_[a-zA-Z_]+(|_x)$/', $key)) {
1082 $result['action']= preg_replace('/^listing_([a-zA-Z_]+)(|_x)$/', '$1', $key);
1083 continue;
1084 }
1085 }
1087 // Filter POST with "act" attributes -> posted from action menu
1088 if (isset($_POST['act']) && $_POST['act'] != '') {
1089 if (!preg_match('/^export.*$/', $_POST['act'])){
1090 $result['action']= validate($_POST['act']);
1091 }
1092 }
1094 // Drop targets if empty
1095 if (count($result['targets']) == 0) {
1096 unset($result['targets']);
1097 }
1098 return $result;
1099 }
1102 function renderActionMenu()
1103 {
1104 $result= "<input type='hidden' name='act' id='act' value=''><div style='display:none'><input type='submit' name='exec_act' id='exec_act' value=''></div>";
1106 // Don't send anything if the menu is not defined
1107 if (!isset($this->xmlData['actionmenu']['action'])){
1108 return $result;
1109 }
1111 // Array?
1112 if (isset($this->xmlData['actionmenu']['action']['type'])){
1113 $this->xmlData['actionmenu']['action']= array($this->xmlData['actionmenu']['action']);
1114 }
1116 // Load shortcut
1117 $actions= &$this->xmlData['actionmenu']['action'];
1118 $result.= "<ul class='level1' id='root'><li><a href='#'>"._("Actions")." ".image("images/lists/sort-down.png")."</a>";
1120 // Build ul/li list
1121 $result.= $this->recurseActions($actions);
1123 return "<div id='pulldown'>".$result."</li></ul><div>";
1124 }
1127 function recurseActions($actions)
1128 {
1129 global $class_mapping;
1130 static $level= 2;
1131 $result= "<ul class='level$level'>";
1132 $separator= "";
1134 foreach ($actions as $action) {
1136 // Skip the entry completely if there's no permission to execute it
1137 if (!$this->hasActionPermission($action, $this->filter->base)) {
1138 continue;
1139 }
1141 // Skip entry if there're missing dependencies
1142 if (isset($action['depends'])) {
1143 $deps= is_array($action['depends'])?$action['depends']:array($action['depends']);
1144 foreach($deps as $clazz) {
1145 if (!isset($class_mapping[$clazz])){
1146 continue 2;
1147 }
1148 }
1149 }
1151 // Fill image if set
1152 $img= "";
1153 if (isset($action['image'])){
1154 $img= image($action['image'])." ";
1155 }
1157 if ($action['type'] == "separator"){
1158 $separator= " style='border-top:1px solid #AAA' ";
1159 continue;
1160 }
1162 // Dive into subs
1163 if ($action['type'] == "sub" && isset($action['action'])) {
1164 $level++;
1165 if (isset($action['label'])){
1166 $result.= "<li$separator><a href='#'>$img"._($action['label'])." ".image('images/forward-arrow.png')."</a>";
1167 }
1169 // Ensure we've an array of actions, this enables sub menus with only one action.
1170 if(isset($action['action']['type'])){
1171 $action['action'] = array($action['action']);
1172 }
1174 $result.= $this->recurseActions($action['action'])."</li>";
1175 $level--;
1176 $separator= "";
1177 continue;
1178 }
1180 // Render entry elseways
1181 if (isset($action['label'])){
1182 $result.= "<li$separator><a href='#' onClick='\$(\"act\").value= \"".$action['name']."\";\$(\"exec_act\").click();'>$img"._($action['label'])."</a></li>";
1183 }
1185 // Check for special types
1186 switch ($action['type']) {
1187 case 'copypaste':
1188 $cut = !isset($action['cut']) || $action['cut'] != "false";
1189 $copy = !isset($action['copy']) || $action['copy'] != "false";
1190 $result.= $this->renderCopyPasteMenu($separator, $copy , $cut);
1191 break;
1193 case 'snapshot':
1194 $result.= $this->renderSnapshotMenu($separator);
1195 break;
1197 case 'exporter':
1198 $result.= $this->renderExporterMenu($separator);
1199 break;
1201 case 'daemon':
1202 $result.= $this->renderDaemonMenu($separator);
1203 break;
1204 }
1206 $separator= "";
1207 }
1209 $result.= "</ul>";
1210 return $result;
1211 }
1214 function hasActionPermission($action, $dn, $classes= null)
1215 {
1216 $ui= get_userinfo();
1218 if (isset($action['acl'])) {
1219 $acls= $action['acl'];
1220 if (!is_array($acls)) {
1221 $acls= array($acls);
1222 }
1224 // Every ACL has to pass
1225 foreach ($acls as $acl) {
1226 $module= $this->categories;
1227 $aclList= array();
1229 // Replace %acl if available
1230 if ($classes) {
1231 $otype= $this->getObjectType($this->objectTypes, $classes);
1232 $acl= str_replace('%acl', $otype['category']."/".$otype['class'], $acl);
1233 }
1235 // Split for category and plugins if needed
1236 // match for "[rw]" style entries
1237 if (preg_match('/^\[([rwcdm]+)\]$/', $acl, $match)){
1238 $aclList= array($match[1]);
1239 }
1241 // match for "users[rw]" style entries
1242 if (preg_match('/^([a-zA-Z0-9]+)\[([rwcdm]+)\]$/', $acl, $match)){
1243 $module= $match[1];
1244 $aclList= array($match[2]);
1245 }
1247 // match for "users/user[rw]" style entries
1248 if (preg_match('/^([a-zA-Z0-9]+\/[a-zA-Z0-9]+)\[([rwcdm]+)\]$/', $acl, $match)){
1249 $module= $match[1];
1250 $aclList= array($match[2]);
1251 }
1253 // match "users/user[userPassword:rw(,...)*]" style entries
1254 if (preg_match('/^([a-zA-Z0-9]+\/[a-zA-Z0-9]+)\[([a-zA-Z0-9]+:[rwcdm]+(,[a-zA-Z0-9]+:[rwcdm]+)*)\]$/', $acl, $match)){
1255 $module= $match[1];
1256 $aclList= explode(',', $match[2]);
1257 }
1259 // Walk thru prepared ACL by using $module
1260 foreach($aclList as $sAcl) {
1261 $checkAcl= "";
1263 // Category or detailed permission?
1264 if (strpos($module, '/') !== false) {
1265 if (preg_match('/([a-zA-Z0-9]+):([rwcdm]+)/', $sAcl, $m) ) {
1266 $checkAcl= $ui->get_permissions($dn, $module, $m[1]);
1267 $sAcl= $m[2];
1268 } else {
1269 $checkAcl= $ui->get_permissions($dn, $module, '0');
1270 }
1271 } else {
1272 $checkAcl= $ui->get_category_permissions($dn, $module);
1273 }
1275 // Split up remaining part of the acl and check if it we're
1276 // allowed to do something...
1277 $parts= str_split($sAcl);
1278 foreach ($parts as $part) {
1279 if (strpos($checkAcl, $part) === false){
1280 return false;
1281 }
1282 }
1284 }
1285 }
1286 }
1288 return true;
1289 }
1292 function refreshBasesList()
1293 {
1294 global $config;
1295 $ui= get_userinfo();
1297 // Do some array munching to get it user friendly
1298 $ids= $config->idepartments;
1299 $d= $ui->get_module_departments($this->categories);
1300 $k_ids= array_keys($ids);
1301 $deps= array_intersect($d,$k_ids);
1303 // Fill internal bases list
1304 $this->bases= array();
1305 foreach($k_ids as $department){
1306 $this->bases[$department] = $ids[$department];
1307 }
1309 // Populate base selector if already present
1310 if ($this->baseSelector && $this->baseMode) {
1311 $this->baseSelector->setBases($this->bases);
1312 $this->baseSelector->update(TRUE);
1313 }
1314 }
1317 function getDepartments()
1318 {
1319 $departments= array();
1320 $ui= get_userinfo();
1322 // Get list of supported department types
1323 $types = departmentManagement::get_support_departments();
1325 // Load departments allowed by ACL
1326 $validDepartments = $ui->get_module_departments($this->categories);
1328 // Build filter and look in the LDAP for possible sub departments
1329 // of current base
1330 $filter= "(&(objectClass=gosaDepartment)(|";
1331 $attrs= array("description", "objectClass");
1332 foreach($types as $name => $data){
1333 $filter.= "(objectClass=".$data['OC'].")";
1334 $attrs[]= $data['ATTR'];
1335 }
1336 $filter.= "))";
1337 $res= get_list($filter, $this->categories, $this->base, $attrs, GL_NONE);
1339 // Analyze list of departments
1340 foreach ($res as $department) {
1341 if (!in_array($department['dn'], $validDepartments)) {
1342 continue;
1343 }
1345 // Add the attribute where we use for sorting
1346 $oc= null;
1347 foreach(array_keys($types) as $type) {
1348 if (in_array($type, $department['objectClass'])) {
1349 $oc= $type;
1350 break;
1351 }
1352 }
1353 $department['sort-attribute']= $types[$oc]['ATTR'];
1355 // Move to the result list
1356 $departments[]= $department;
1357 }
1359 return $departments;
1360 }
1363 function renderCopyPasteMenu($separator, $copy= true, $cut= true)
1364 {
1365 // We can only provide information if we've got a copypaste handler
1366 // instance
1367 if(!(isset($this->copyPasteHandler) && is_object($this->copyPasteHandler))){
1368 return "";
1369 }
1371 // Presets
1372 $result= "";
1373 $read= $paste= false;
1374 $ui= get_userinfo();
1376 // Switch flags to on if there's at least one category which allows read/paste
1377 foreach($this->categories as $category){
1378 $read= $read || preg_match('/r/', $ui->get_category_permissions($this->base, $category));
1379 $paste= $paste || $ui->is_pasteable($this->base, $category) == 1;
1380 }
1383 // Draw entries that allow copy and cut
1384 if($read){
1386 // Copy entry
1387 if($copy){
1388 $result.= "<li$separator><a href='#' onClick='\$(\"act\").value= \"copy\";\$(\"exec_act\").click();'>".image('images/lists/copy.png')." "._("Copy")."</a></li>";
1389 $separator= "";
1390 }
1392 // Cut entry
1393 if($cut){
1394 $result.= "<li$separator><a href='#' onClick='\$(\"act\").value= \"cut\";\$(\"exec_act\").click();'>".image("images/lists/cut.png")." "._("Cut")."</a></li>";
1395 $separator= "";
1396 }
1397 }
1399 // Draw entries that allow pasting entries
1400 if($paste){
1401 if($this->copyPasteHandler->entries_queued()){
1402 $result.= "<li$separator><a href='#' onClick='\$(\"act\").value= \"paste\";\$(\"exec_act\").click();'>".image("images/lists/paste.png")." "._("Paste")."</a></li>";
1403 }else{
1404 $result.= "<li$separator><a href='#'>".image('images/lists/paste-grey.png')." "._("Paste")."</a></li>";
1405 }
1406 }
1408 return($result);
1409 }
1412 function renderCopyPasteActions($row, $dn, $category, $class, $copy= true, $cut= true)
1413 {
1414 // We can only provide information if we've got a copypaste handler
1415 // instance
1416 if(!(isset($this->copyPasteHandler) && is_object($this->copyPasteHandler))){
1417 return "";
1418 }
1420 // Presets
1421 $ui = get_userinfo();
1422 $result = "";
1424 // Render cut entries
1425 if($cut){
1426 if($ui->is_cutable($dn, $category, $class)){
1427 $result.= image('images/lists/cut.png', "listing_cut_$row", _("Cut this entry"));
1428 }else{
1429 $result.= image('images/empty.png');
1430 }
1431 }
1433 // Render copy entries
1434 if($copy){
1435 if($ui->is_copyable($dn, $category, $class)){
1436 $result.= image('images/lists/copy.png', "listing_copy_$row", _("Copy this entry"));
1437 }else{
1438 $result.= image('images/empty.png');
1439 }
1440 }
1442 return($result);
1443 }
1446 function renderSnapshotMenu($separator)
1447 {
1448 // We can only provide information if we've got a snapshot handler
1449 // instance
1450 if(!(isset($this->snapshotHandler) && is_object($this->snapshotHandler))){
1451 return "";
1452 }
1454 // Presets
1455 $result = "";
1456 $ui = get_userinfo();
1458 if($this->snapshotHandler->enabled() && $ui->allow_snapshot_restore($this->base, $this->categories)){
1460 // Check if there is something to restore
1461 $restore= false;
1462 foreach($this->snapshotHandler->getSnapshotBases() as $base){
1463 $restore= $restore || count($this->snapshotHandler->getDeletedSnapshots($base)) > 0;
1464 }
1466 // Draw icons according to the restore flag
1467 if($restore){
1468 $result.= "<li$separator><a href='#' onClick='\$(\"act\").value= \"restore\";\$(\"exec_act\").click();'>".image('images/lists/restore.png')." "._("Restore snapshots")."</a></li>";
1469 }else{
1470 $result.= "<li$separator><a href='#'>".image('images/lists/restore-grey.png')." "._("Restore snapshots")."</a></li>";
1471 }
1472 }
1474 return($result);
1475 }
1478 function renderExporterMenu($separator)
1479 {
1480 // Presets
1481 $result = "";
1483 // Draw entries
1484 $result.= "<li$separator><a href='#'>".image('images/lists/export.png')." "._("Export list")." ".image("images/forward-arrow.png")."</a><ul class='level3'>";
1486 // Export CVS as build in exporter
1487 foreach ($this->exporter as $action => $exporter) {
1488 $result.= "<li><a href='#' onClick='\$(\"act\").value= \"$action\";\$(\"exec_act\").click();'>".image($exporter['image'])." ".$exporter['label']."</a></li>";
1489 }
1491 // Finalize list
1492 $result.= "</ul></li>";
1494 return($result);
1495 }
1498 function renderSnapshotActions($row, $dn, $category, $class, $copy= true, $cut= true)
1499 {
1500 // We can only provide information if we've got a snapshot handler
1501 // instance
1502 if(!(isset($this->snapshotHandler) && is_object($this->snapshotHandler))){
1503 return "";
1504 }
1506 // Presets
1507 $result= "";
1508 $ui = get_userinfo();
1510 // Only act if enabled here
1511 if($this->snapshotHandler->enabled()){
1513 // Draw restore button
1514 if ($ui->allow_snapshot_restore($dn, $category)){
1516 // Do we have snapshots for this dn?
1517 if($this->snapshotHandler->hasSnapshots($dn)){
1518 $result.= image('images/lists/restore.png', "listing_restore_$row", _("Restore snapshot"));
1519 } else {
1520 $result.= image('images/lists/restore-grey.png');
1521 }
1522 }
1524 // Draw snapshot button
1525 if($ui->allow_snapshot_create($dn, $category)){
1526 $result.= image('images/snapshot.png', "listing_snapshot_$row", _("Create a new snapshot from this object"));
1527 }else{
1528 $result.= image('images/empty.png');
1529 }
1530 }
1532 return($result);
1533 }
1536 function renderDaemonMenu($separator)
1537 {
1538 $result= "";
1540 // If there is a daemon registered, draw the menu entries
1541 if(class_available("DaemonEvent")){
1542 $events= DaemonEvent::get_event_types_by_category($this->categories);
1543 if(isset($events['BY_CLASS']) && count($events['BY_CLASS'])){
1544 foreach($events['BY_CLASS'] as $name => $event){
1545 $result.= "<li$separator><a href='#' onClick='\$(\"act\").value=\"$name\";\$(\"exec_act\").click();'>".$event['MenuImage']." ".$event['s_Menu_Name']."</a></li>";
1546 $separator= "";
1547 }
1548 }
1549 }
1551 return $result;
1552 }
1555 function getEntry($dn)
1556 {
1557 foreach ($this->entries as $entry) {
1558 if (isset($entry['dn']) && strcasecmp($dn, $entry['dn']) == 0){
1559 return $entry;
1560 }
1561 }
1562 return null;
1563 }
1566 function getEntries()
1567 {
1568 return $this->entries;
1569 }
1572 function getType($dn)
1573 {
1574 if (isset($this->objectDnMapping[$dn])) {
1575 return $this->objectDnMapping[$dn];
1576 }
1577 return null;
1578 }
1580 }
1582 ?>