1 <?php
2 /*
3 * This code is part of GOsa (http://www.gosa-project.org)
4 * Copyright (C) 2003-2008 GONICUS GmbH
5 *
6 * ID: $$Id$$
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
23 class listing {
25 var $xmlData;
26 var $entries;
27 var $departments= array();
28 var $departmentBrowser= false;
29 var $departmentRootVisible= false;
30 var $multiSelect= false;
31 var $template;
32 var $headline;
33 var $base;
34 var $sortDirection= null;
35 var $sortColumn= null;
36 var $sortAttribute;
37 var $sortType;
38 var $numColumns;
39 var $baseMode= false;
40 var $bases= array();
41 var $header= array();
42 var $colprops= array();
43 var $filters= array();
44 var $filter= null;
45 var $pid;
46 var $objectTypes= array();
47 var $objectTypeCount= array();
48 var $objectDnMapping= array();
49 var $copyPasteHandler= null;
50 var $snapshotHandler= null;
51 var $exporter= array();
52 var $exportColumns= array();
53 var $useSpan= false;
54 var $height= 0;
55 var $scrollPosition= 0;
56 var $baseSelector;
59 function listing($filename)
60 {
61 global $config;
62 global $class_mapping;
64 // Initialize pid
65 $this->pid= preg_replace("/[^0-9]/", "", microtime(TRUE));
67 if (!$this->load($filename)) {
68 die("Cannot parse $filename!");
69 }
71 // Set base for filter
72 if ($this->baseMode) {
73 $this->base= session::global_get("CurrentMainBase");
74 if ($this->base == null) {
75 $this->base= $config->current['BASE'];
76 }
77 $this->refreshBasesList();
78 } else {
79 $this->base= $config->current['BASE'];
80 }
82 // Move footer information
83 $this->showFooter= ($config->get_cfg_value("listSummary") == "true");
85 // Register build in filters
86 $this->registerElementFilter("objectType", "listing::filterObjectType");
87 $this->registerElementFilter("departmentLink", "listing::filterDepartmentLink");
88 $this->registerElementFilter("link", "listing::filterLink");
89 $this->registerElementFilter("actions", "listing::filterActions");
91 // Load exporters
92 foreach($class_mapping as $class => $dummy) {
93 if (preg_match('/Exporter$/', $class)) {
94 $info= call_user_func(array($class, "getInfo"));
95 if ($info != null) {
96 $this->exporter= array_merge($this->exporter, $info);
97 }
98 }
99 }
101 // Instanciate base selector
102 $this->baseSelector= new baseSelector($this->bases, $this->base);
103 }
106 function setCopyPasteHandler($handler)
107 {
108 $this->copyPasteHandler= &$handler;
109 }
112 function setHeight($height)
113 {
114 $this->height= $height;
115 }
118 function setSnapshotHandler($handler)
119 {
120 $this->snapshotHandler= &$handler;
121 }
124 function setFilter($filter)
125 {
126 $this->filter= &$filter;
127 if ($this->departmentBrowser){
128 $this->departments= $this->getDepartments();
129 }
130 $this->filter->setBase($this->base);
131 }
134 function registerElementFilter($name, $call)
135 {
136 if (!isset($this->filters[$name])) {
137 $this->filters[$name]= $call;
138 return true;
139 }
141 return false;
142 }
145 function load($filename)
146 {
147 $contents = file_get_contents($filename);
148 $this->xmlData= xml::xml2array($contents, 1);
150 if (!isset($this->xmlData['list'])) {
151 return false;
152 }
154 $this->xmlData= $this->xmlData["list"];
156 // Load some definition values
157 foreach (array("departmentBrowser", "departmentRootVisible", "multiSelect", "baseMode") as $token) {
158 if (isset($this->xmlData['definition'][$token]) &&
159 $this->xmlData['definition'][$token] == "true"){
160 $this->$token= true;
161 }
162 }
164 // Fill objectTypes from departments and xml definition
165 $types = departmentManagement::get_support_departments();
166 foreach ($types as $class => $data) {
167 $this->objectTypes[$data['OC']]= array("label" => $data['TITLE'],
168 "objectClass" => $data['OC'],
169 "image" => $data['IMG']);
170 }
171 $this->categories= array();
172 if (isset($this->xmlData['definition']['objectType'])) {
173 if(isset($this->xmlData['definition']['objectType']['label'])) {
174 $this->xmlData['definition']['objectType']= array($this->xmlData['definition']['objectType']);
175 }
176 foreach ($this->xmlData['definition']['objectType'] as $index => $otype) {
177 $tmp = $this->xmlData['definition']['objectType'][$index];
178 $this->objectTypes[$tmp['objectClass']]= $tmp;
179 if (isset($this->xmlData['definition']['objectType'][$index]['category'])){
180 $this->categories[]= $otype['category'];
181 }
182 }
183 }
184 $this->objectTypes = array_values($this->objectTypes);
186 // Parse layout per column
187 $this->colprops= $this->parseLayout($this->xmlData['table']['layout']);
189 // Prepare table headers
190 $this->renderHeader();
192 // Assign headline/Categories
193 $this->headline= _($this->xmlData['definition']['label']);
194 if (!is_array($this->categories)){
195 $this->categories= array($this->categories);
196 }
198 // Evaluate columns to be exported
199 if (isset($this->xmlData['table']['column'])){
200 foreach ($this->xmlData['table']['column'] as $index => $config) {
201 if (isset($config['export']) && $config['export'] == "true"){
202 $this->exportColumns[]= $index;
203 }
204 }
205 }
207 return true;
208 }
211 function renderHeader()
212 {
213 $this->header= array();
214 $this->plainHeader= array();
216 // Initialize sort?
217 $sortInit= false;
218 if (!$this->sortDirection) {
219 $this->sortColumn= 0;
220 if (isset($this->xmlData['definition']['defaultSortColumn'])){
221 $this->sortColumn= $this->xmlData['definition']['defaultSortColumn'];
222 } else {
223 $this->sortAttribute= "";
224 }
225 $this->sortDirection= array();
226 $sortInit= true;
227 }
229 if (isset($this->xmlData['table']['column'])){
230 foreach ($this->xmlData['table']['column'] as $index => $config) {
231 // Initialize everything to one direction
232 if ($sortInit) {
233 $this->sortDirection[$index]= false;
234 }
236 $sorter= "";
237 if ($index == $this->sortColumn && isset($config['sortAttribute']) &&
238 isset($config['sortType'])) {
239 $this->sortAttribute= $config['sortAttribute'];
240 $this->sortType= $config['sortType'];
241 $sorter= " ".image("images/lists/sort-".($this->sortDirection[$index]?"up":"down").".png", null, null, $this->sortDirection[$index]?_("Up"):_("Down"), "text-top");
242 }
243 $sortable= (isset($config['sortAttribute']));
245 $link= "href='?plug=".$_GET['plug']."&PID=".$this->pid."&act=SORT_$index'";
246 if (isset($config['label'])) {
247 if ($sortable) {
248 $this->header[$index]= "<td class='listheader' ".$this->colprops[$index]."><a $link>"._($config['label'])."$sorter</a></td>";
249 } else {
250 $this->header[$index]= "<td class='listheader' ".$this->colprops[$index].">"._($config['label'])."</td>";
251 }
252 $this->plainHeader[]= _($config['label']);
253 } else {
254 if ($sortable) {
255 $this->header[$index]= "<td class='listheader' ".$this->colprops[$index]."><a $link> $sorter</a></td>";
256 } else {
257 $this->header[$index]= "<td class='listheader' ".$this->colprops[$index]."> </td>";
258 }
259 $this->plainHeader[]= "";
260 }
261 }
262 }
263 }
266 function render()
267 {
268 // Check for exeeded sizelimit
269 if (($message= check_sizelimit()) != ""){
270 return($message);
271 }
273 // Some browsers don't have the ability do do scrollable table bodies, filter them
274 // here.
275 $switch= false;
276 if (preg_match('/(Opera|Konqueror|Safari)/i', $_SERVER['HTTP_USER_AGENT'])){
277 $switch= true;
278 }
280 // Initialize list
281 $result= "<input type='hidden' value='$this->pid' name='PID'>\n";
282 $result.= "<input type='hidden' name='position_".$this->pid."' id='position_".$this->pid."'>\n";
283 $height= 450;
284 if ($this->height != 0) {
285 $result.= "<input type='hidden' value='$this->height' id='d_height'>\n";
286 $height= $this->height;
287 }
289 $result.= "<div class='listContainer' id='d_scrollbody' style='min-height:".($height+25)."px;'>\n";
290 $result.= "<table summary='$this->headline' style='width:100%;table-layout:fixed' cellspacing='0' cellpadding='0' id='t_scrolltable'>\n";
291 $this->numColumns= count($this->colprops) + ($this->multiSelect?1:0);
293 // Build list header
294 $result.= "<thead class='fixedListHeader listHeaderFormat'><tr>\n";
295 if ($this->multiSelect) {
296 $width= "24px";
297 if (preg_match('/Konqueror/i', $_SERVER['HTTP_USER_AGENT'])){
298 $width= "28px";
299 }
300 $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";
301 }
302 foreach ($this->header as $header) {
303 $result.= $header;
304 }
305 $result.= "</tr></thead>\n";
307 // Build list body
308 $result.= "<tbody class='listScrollContent listBodyFormat' id='t_nscrollbody' style='height:".$height."px;'>\n";
310 // No results? Just take an empty colspanned row
311 if (count($this->entries) + count($this->departments) == 0) {
312 $result.= "<tr><td class='list1nohighlight' colspan='$this->numColumns' style='height:100%;border-right:0px;width:100%;'> </td></tr>";
313 }
315 // Line color alternation
316 $alt= 0;
317 $deps= 0;
319 // Draw department browser if configured and we're not in sub mode
320 $this->useSpan= false;
321 if ($this->departmentBrowser && $this->filter->scope != "sub") {
322 // Fill with department browser if configured this way
323 $departmentIterator= new departmentSortIterator($this->departments, $this->sortDirection[$this->sortColumn]);
324 foreach ($departmentIterator as $row => $entry){
325 $result.="<tr>";
327 // Render multi select if needed
328 if ($this->multiSelect) {
329 $result.="<td style='text-align:center;padding:0;' class='list1'> </td>";
330 }
332 // Render defined department columns, fill the rest with some stuff
333 $rest= $this->numColumns - 1;
334 foreach ($this->xmlData['table']['department'] as $index => $config) {
335 $colspan= 1;
336 if (isset($config['span'])){
337 $colspan= $config['span'];
338 $this->useSpan= true;
339 }
340 $result.="<td colspan='$colspan' ".$this->colprops[$index]." class='list1'>".$this->renderCell($config['value'], $entry, $row)."</td>";
341 $rest-= $colspan;
342 }
344 // Fill remaining cols with nothing
345 $last= $this->numColumns - $rest;
346 for ($i= 0; $i<$rest; $i++){
347 $result.= "<td ".$this->colprops[$last+$i-1]." class='list1'> </td>";
348 }
349 $result.="</tr>";
351 $alt++;
352 }
353 $deps= $alt;
354 }
356 // Fill with contents, sort as configured
357 foreach ($this->entries as $row => $entry) {
358 $trow= "";
360 // Render multi select if needed
361 if ($this->multiSelect) {
362 $trow.="<td style='text-align:center;width:20px;' class='list0'><input type='checkbox' id='listing_selected_$row' name='listing_selected_$row'></td>\n";
363 }
365 foreach ($this->xmlData['table']['column'] as $index => $config) {
366 $renderedCell= $this->renderCell($config['value'], $entry, $row);
367 $trow.="<td ".$this->colprops[$index]." class='list0'>".$renderedCell."</td>\n";
369 // Save rendered column
370 $sort= preg_replace('/.*>([^<]+)<.*$/', '$1', $renderedCell);
371 $sort= preg_replace('/ /', '', $sort);
372 if (preg_match('/</', $sort)){
373 $sort= "";
374 }
375 $this->entries[$row]["_sort$index"]= $sort;
376 }
378 // Save rendered entry
379 $this->entries[$row]['_rendered']= $trow;
380 }
382 // Complete list by sorting entries for _sort$index and appending them to the output
383 $entryIterator= new listingSortIterator($this->entries, $this->sortDirection[$this->sortColumn], "_sort".$this->sortColumn, $this->sortType);
384 foreach ($entryIterator as $row => $entry){
385 $result.="<tr>\n";
386 $result.= $entry['_rendered'];
387 $result.="</tr>\n";
388 $alt++;
389 }
391 // Need to fill the list if it's not full (nobody knows why this is 22 ;-))
392 $emptyListStyle= (count($this->entries) + (($this->useSpan && count($this->entries))?$deps:0) == 0)?"border:0;":"";
393 if ((count($this->entries) + $deps) < 22) {
394 $result.= "<tr>";
395 for ($i= 0; $i<$this->numColumns; $i++) {
396 if ($i == 0) {
397 $result.= "<td class='list1nohighlight' style='$emptyListStyle height:100%;'> </td>";
398 continue;
399 }
400 if ($i != $this->numColumns-1) {
401 $result.= "<td class='list1nohighlight' style='$emptyListStyle'> </td>";
402 } else {
403 $result.= "<td class='list1nohighlight' style='border-right:0;$emptyListStyle'> </td>";
404 }
405 }
406 $result.= "</tr>";
407 }
409 // Close list body
410 $result.= "</tbody></table></div>";
412 // Add the footer if requested
413 if ($this->showFooter) {
414 $result.= "<div class='nlistFooter'><div style='padding:3px'>";
416 foreach ($this->objectTypes as $objectType) {
417 if (isset($this->objectTypeCount[$objectType['label']])) {
418 $label= _($objectType['label']);
419 $result.= image($objectType['image'], null, null, $label)." ".$this->objectTypeCount[$objectType['label']]." ";
420 }
421 }
423 $result.= "</div></div>";
424 }
426 // Close list
427 $result.= $switch?"<input type='hidden' id='list_workaround'>":"";
429 // Add scroll positioner
430 $result.= '<script type="text/javascript" language="javascript">';
431 $result.= '$("t_nscrollbody").scrollTop= '.$this->scrollPosition.';';
432 $result.= 'var box = $("t_nscrollbody").onscroll= function() {$("position_'.$this->pid.'").value= this.scrollTop;}';
433 $result.= '</script>';
435 $smarty= get_smarty();
436 $smarty->assign("usePrototype", "true");
437 $smarty->assign("FILTER", $this->filter->render());
438 $smarty->assign("SIZELIMIT", print_sizelimit_warning());
439 $smarty->assign("LIST", $result);
441 // Assign navigation elements
442 $nav= $this->renderNavigation();
443 foreach ($nav as $key => $html) {
444 $smarty->assign($key, $html);
445 }
447 // Assign action menu / base
448 $smarty->assign("ACTIONS", $this->renderActionMenu());
449 $smarty->assign("BASE", $this->renderBase());
451 // Assign separator
452 $smarty->assign("SEPARATOR", "<img src='images/lists/seperator.png' alt='-' align='middle' height='16' width='1' class='center'>");
454 // Assign summary
455 $smarty->assign("HEADLINE", $this->headline);
457 // Try to load template from plugin the folder first...
458 $file = get_template_path($this->xmlData['definition']['template'], true);
460 // ... if this fails, try to load the file from the theme folder.
461 if(!file_exists($file)){
462 $file = get_template_path($this->xmlData['definition']['template']);
463 }
465 return ($smarty->fetch($file));
466 }
469 function update()
470 {
471 global $config;
472 $ui= get_userinfo();
474 // Take care of base selector
475 if ($this->baseMode) {
476 $this->baseSelector->update();
477 // Check if a wrong base was supplied
478 if(!$this->baseSelector->checkLastBaseUpdate()){
479 msg_dialog::display(_("Error"), msgPool::check_base(), ERROR_DIALOG);
480 }
481 }
483 // Save base
484 $refresh= false;
485 if ($this->baseMode) {
486 $this->base= $this->baseSelector->getBase();
487 session::global_set("CurrentMainBase", $this->base);
488 $refresh= true;
489 }
492 // Reset object counter / DN mapping
493 $this->objectTypeCount= array();
494 $this->objectDnMapping= array();
496 // Do not do anything if this is not our PID
497 if($refresh || !(isset($_REQUEST['PID']) && $_REQUEST['PID'] != $this->pid)) {
499 // Save position if set
500 if (isset($_POST['position_'.$this->pid]) && is_numeric($_POST['position_'.$this->pid])) {
501 $this->scrollPosition= $_POST['position_'.$this->pid];
502 }
504 // Override the base if we got a message from the browser navigation
505 if ($this->departmentBrowser && isset($_GET['act'])) {
506 if (preg_match('/^department_([0-9]+)$/', validate($_GET['act']), $match)){
507 if (isset($this->departments[$match[1]])){
508 $this->base= $this->departments[$match[1]]['dn'];
509 if ($this->baseMode) {
510 $this->baseSelector->setBase($this->base);
511 }
512 session::global_set("CurrentMainBase", $this->base);
513 }
514 }
515 }
517 // Filter POST with "act" attributes -> posted from action menu
518 if (isset($_POST['exec_act']) && $_POST['act'] != '') {
519 if (preg_match('/^export.*$/', $_POST['act']) && isset($this->exporter[$_POST['act']])) {
520 $exporter= $this->exporter[$_POST['act']];
521 $userinfo= ", "._("created by")." ".$ui->cn." - ".strftime('%A, %d. %B %Y, %H:%M:%S');
522 $entryIterator= new listingSortIterator($this->entries, $this->sortDirection[$this->sortColumn], "_sort".$this->sortColumn, $this->sortType);
523 $sortedEntries= array();
524 foreach ($entryIterator as $entry){
525 $sortedEntries[]= $entry;
526 }
527 $instance= new $exporter['class']($this->headline.$userinfo, $this->plainHeader, $sortedEntries, $this->exportColumns);
528 $type= call_user_func(array($exporter['class'], "getInfo"));
529 $type= $type[$_POST['act']];
530 send_binary_content($instance->query(), $type['filename'], $type= $type['mime']);
531 }
532 }
534 // Filter GET with "act" attributes
535 if (isset($_GET['act'])) {
536 $key= validate($_GET['act']);
537 if (preg_match('/^SORT_([0-9]+)$/', $key, $match)) {
538 // Switch to new column or invert search order?
539 $column= $match[1];
540 if ($this->sortColumn != $column) {
541 $this->sortColumn= $column;
542 } else {
543 $this->sortDirection[$column]= !$this->sortDirection[$column];
544 }
546 // Allow header to update itself according to the new sort settings
547 $this->renderHeader();
548 }
549 }
551 // Override base if we got signals from the navigation elements
552 $action= "";
553 foreach ($_POST as $key => $value) {
554 if (preg_match('/^(ROOT|BACK|HOME)(_x)?$/', $key, $match)) {
555 $action= $match[1];
556 break;
557 }
558 }
560 // Navigation handling
561 if ($action == 'ROOT') {
562 $deps= $ui->get_module_departments($this->categories);
563 $this->base= $deps[0];
564 $this->baseSelector->setBase($this->base);
565 session::global_set("CurrentMainBase", $this->base);
566 }
567 if ($action == 'BACK') {
568 $deps= $ui->get_module_departments($this->categories);
569 $base= preg_replace("/^[^,]+,/", "", $this->base);
570 if(in_array_ics($base, $deps)){
571 $this->base= $base;
572 $this->baseSelector->setBase($this->base);
573 session::global_set("CurrentMainBase", $this->base);
574 }
575 }
576 if ($action == 'HOME') {
577 $ui= get_userinfo();
578 $this->base= get_base_from_people($ui->dn);
579 $this->baseSelector->setBase($this->base);
580 session::global_set("CurrentMainBase", $this->base);
581 }
582 }
584 // Reload departments
585 if ($this->departmentBrowser){
586 $this->departments= $this->getDepartments();
587 }
589 // Update filter and refresh entries
590 $this->filter->setBase($this->base);
591 $this->entries= $this->filter->query();
593 // Fix filter if querie returns NULL
594 if ($this->entries == null) {
595 $this->entries= array();
596 }
597 }
600 function setBase($base)
601 {
602 $this->base= $base;
603 if ($this->baseMode) {
604 $this->baseSelector->setBase($this->base);
605 }
606 }
609 function getBase()
610 {
611 return $this->base;
612 }
615 function parseLayout($layout)
616 {
617 $result= array();
618 $layout= preg_replace("/^\|/", "", $layout);
619 $layout= preg_replace("/\|$/", "", $layout);
620 $cols= explode("|", $layout);
622 foreach ($cols as $index => $config) {
623 if ($config != "") {
624 $res= "";
625 $components= explode(';', $config);
626 foreach ($components as $part) {
627 if (preg_match("/^r$/", $part)) {
628 $res.= "text-align:right;";
629 continue;
630 }
631 if (preg_match("/^l$/", $part)) {
632 $res.= "text-align:left;";
633 continue;
634 }
635 if (preg_match("/^c$/", $part)) {
636 $res.= "text-align:center;";
637 continue;
638 }
639 if (preg_match("/^[0-9]+(|px|%)$/", $part)) {
640 $res.= "width:$part;min-width:$part;";
641 continue;
642 }
643 }
645 // Add minimum width for scalable columns
646 if (!preg_match('/width:/', $res)){
647 $res.= "min-width:200px;";
648 }
650 $result[$index]= " style='$res'";
651 } else {
652 $result[$index]= " style='min-width:100px;'";
653 }
654 }
656 // Save number of columns for later use
657 $this->numColumns= count($cols);
659 // Add no border to the last column
660 $result[$this->numColumns-1]= preg_replace("/'$/", "border-right:0;'", $result[$this->numColumns-1]);
662 return $result;
663 }
666 function renderCell($data, $config, $row)
667 {
668 // Replace flat attributes in data string
669 for ($i= 0; $i<$config['count']; $i++) {
670 $attr= $config[$i];
671 $value= "";
672 if (is_array($config[$attr])) {
673 $value= $config[$attr][0];
674 } else {
675 $value= $config[$attr];
676 }
677 $data= preg_replace("/%\{$attr\}/", $value, $data);
678 }
680 // Watch out for filters and prepare to execute them
681 $data= $this->processElementFilter($data, $config, $row);
683 // Replace all non replaced %{...} instances because they
684 // are non resolved attributes or filters
685 $data= preg_replace('/%{[^}]+}/', ' ', $data);
687 return $data;
688 }
691 function renderBase()
692 {
693 if (!$this->baseMode) {
694 return;
695 }
697 return $this->baseSelector->render();
698 }
701 function processElementFilter($data, $config, $row)
702 {
703 preg_match_all("/%\{filter:([^(]+)\((.*)\)\}/", $data, $matches, PREG_SET_ORDER);
705 foreach ($matches as $match) {
706 $cl= "";
707 $method= "";
708 if (preg_match('/::/', $match[1])) {
709 $cl= preg_replace('/::.*$/', '', $match[1]);
710 $method= preg_replace('/^.*::/', '', $match[1]);
711 } else {
712 if (!isset($this->filters[$match[1]])) {
713 continue;
714 }
715 $cl= preg_replace('/::.*$/', '', $this->filters[$match[1]]);
716 $method= preg_replace('/^.*::/', '', $this->filters[$match[1]]);
717 }
719 // Prepare params for function call
720 $params= array();
721 preg_match_all('/"[^"]+"|[^,]+/', $match[2], $parts);
722 foreach ($parts[0] as $param) {
724 // Row is replaced by the row number
725 if ($param == "row") {
726 $params[]= $row;
727 continue;
728 }
730 // pid is replaced by the current PID
731 if ($param == "pid") {
732 $params[]= $this->pid;
733 continue;
734 }
736 // base is replaced by the current base
737 if ($param == "base") {
738 $params[]= $this->getBase();
739 continue;
740 }
742 // Fixie with "" is passed directly
743 if (preg_match('/^".*"$/', $param)){
744 $params[]= preg_replace('/"/', '', $param);
745 continue;
746 }
748 // Move dn if needed
749 if ($param == "dn") {
750 $params[]= LDAP::fix($config["dn"]);
751 continue;
752 }
754 // LDAP variables get replaced by their objects
755 for ($i= 0; $i<$config['count']; $i++) {
756 if ($param == $config[$i]) {
757 $values= $config[$config[$i]];
758 if (is_array($values)){
759 unset($values['count']);
760 }
761 $params[]= $values;
762 break;
763 }
764 }
765 }
767 // Replace information
768 if ($cl == "listing") {
769 // Non static call - seems to result in errors
770 $data= @preg_replace('/'.preg_quote($match[0]).'/', call_user_func_array(array($this, "$method"), $params), $data);
771 } else {
772 // Static call
773 $data= preg_replace('/'.preg_quote($match[0]).'/', call_user_func_array(array($cl, $method), $params), $data);
774 }
775 }
777 return $data;
778 }
781 function getObjectType($types, $classes)
782 {
783 // Walk thru types and see if there's something matching
784 foreach ($types as $objectType) {
785 $ocs= $objectType['objectClass'];
786 if (!is_array($ocs)){
787 $ocs= array($ocs);
788 }
790 $found= true;
791 foreach ($ocs as $oc){
792 if (preg_match('/^!(.*)$/', $oc, $match)) {
793 $oc= $match[1];
794 if (in_array($oc, $classes)) {
795 $found= false;
796 }
797 } else {
798 if (!in_array($oc, $classes)) {
799 $found= false;
800 }
801 }
802 }
804 if ($found) {
805 return $objectType;
806 }
807 }
809 return null;
810 }
813 function filterObjectType($dn, $classes)
814 {
815 // Walk thru classes and return on first match
816 $result= " ";
818 $objectType= $this->getObjectType($this->objectTypes, $classes);
819 if ($objectType) {
820 $this->objectDnMapping[$dn]= $objectType["objectClass"];
821 $result= image($objectType["image"], null, null, LDAP::fix($dn));
822 if (!isset($this->objectTypeCount[$objectType['label']])) {
823 $this->objectTypeCount[$objectType['label']]= 0;
824 }
825 $this->objectTypeCount[$objectType['label']]++;
826 }
828 return $result;
829 }
832 function filterActions($dn, $row, $classes)
833 {
834 // Do nothing if there's no menu defined
835 if (!isset($this->xmlData['actiontriggers']['action'])) {
836 return " ";
837 }
839 // Go thru all actions
840 $result= "";
841 $actions= $this->xmlData['actiontriggers']['action'];
842 foreach($actions as $action) {
843 // Skip the entry completely if there's no permission to execute it
844 if (!$this->hasActionPermission($action, $dn, $classes)) {
845 $result.= image('images/empty.png');
846 continue;
847 }
849 // Skip entry if the pseudo filter does not fit
850 if (isset($action['filter']) && preg_match('/^[a-z0-9_]+!?=[a-z0-9_]+$/i', $action['filter'])) {
851 list($fa, $fv)= explode('=', $action['filter']);
852 if (preg_match('/^(.*)!$/', $fa, $m)){
853 $fa= $m[1];
854 if (isset($this->entries[$row][$fa]) && $this->entries[$row][$fa][0] == $fv) {
855 $result.= image('images/empty.png');
856 continue;
857 }
858 } else {
859 if (!isset($this->entries[$row][$fa]) && !$this->entries[$row][$fa][0] == $fv) {
860 $result.= image('images/empty.png');
861 continue;
862 }
863 }
864 }
867 // If there's an objectclass definition and we don't have it
868 // add an empty picture here.
869 if (isset($action['objectclass'])){
870 $objectclass= $action['objectclass'];
871 if (preg_match('/^!(.*)$/', $objectclass, $m)){
872 $objectclass= $m[1];
873 if(in_array($objectclass, $classes)) {
874 $result.= image('images/empty.png');
875 continue;
876 }
877 } elseif (is_string($objectclass)) {
878 if(!in_array($objectclass, $classes)) {
879 $result.= image('images/empty.png');
880 continue;
881 }
882 } elseif (is_array($objectclass)) {
883 if(count(array_intersect($objectclass, $classes)) != count($objectclass)){
884 $result.= image('images/empty.png');
885 continue;
886 }
887 }
888 }
890 // Render normal entries as usual
891 if ($action['type'] == "entry") {
892 $label= $this->processElementFilter($action['label'], $this->entries[$row], $row);
893 $image= $this->processElementFilter($action['image'], $this->entries[$row], $row);
894 $result.= image($image, null, "listing_".$action['name']."_$row", $label);
895 }
897 // Handle special types
898 if ($action['type'] == "copypaste" || $action['type'] == "snapshot") {
900 $objectType= $this->getObjectType($this->objectTypes, $this->entries[$row]['objectClass']);
901 $category= $class= null;
902 if ($objectType) {
903 $category= $objectType['category'];
904 $class= $objectType['class'];
905 }
907 if ($action['type'] == "copypaste") {
908 $copy = !isset($action['copy']) || $action['copy'] == "true";
909 $cut = !isset($action['cut']) || $action['cut'] == "true";
910 $result.= $this->renderCopyPasteActions($row, $this->entries[$row]['dn'], $category, $class,$copy,$cut);
911 } else {
912 $result.= $this->renderSnapshotActions($row, $this->entries[$row]['dn'], $category, $class);
913 }
914 }
915 }
917 return $result;
918 }
921 function filterDepartmentLink($row, $dn, $description)
922 {
923 $attr= $this->departments[$row]['sort-attribute'];
924 $name= $this->departments[$row][$attr];
925 if (is_array($name)){
926 $name= $name[0];
927 }
928 $result= sprintf("%s [%s]", $name, $description[0]);
929 return("<a href='?plug=".$_GET['plug']."&PID=$this->pid&act=department_$row' title='$dn'>$result</a>");
930 }
933 function filterLink()
934 {
935 $result= " ";
937 $row= func_get_arg(0);
938 $pid= $this->pid;
939 $dn= LDAP::fix(func_get_arg(1));
940 $params= array(func_get_arg(2));
942 // Collect sprintf params
943 for ($i = 3;$i < func_num_args();$i++) {
944 $val= func_get_arg($i);
945 if (is_array($val)){
946 $params[]= $val[0];
947 continue;
948 }
949 $params[]= $val;
950 }
952 $result= " ";
953 $trans= call_user_func_array("sprintf", $params);
954 if ($trans != "") {
955 return("<a href='?plug=".$_GET['plug']."&PID=$pid&act=listing_edit_$row' title='$dn'>$trans</a>");
956 }
958 return $result;
959 }
962 function renderNavigation()
963 {
964 $result= array();
965 $enableBack = true;
966 $enableRoot = true;
967 $enableHome = true;
969 $ui = get_userinfo();
971 /* Check if base = first available base */
972 $deps = $ui->get_module_departments($this->categories);
974 if(!count($deps) || $deps[0] == $this->filter->base){
975 $enableBack = false;
976 $enableRoot = false;
977 }
979 $listhead ="";
981 /* Check if we are in users home department */
982 if(!count($deps) || $this->filter->base == get_base_from_people($ui->dn)){
983 $enableHome = false;
984 }
986 /* Draw root button */
987 if($enableRoot){
988 $result["ROOT"]= image('images/lists/root.png', null, 'ROOT', _("Root"));
989 }else{
990 $result["ROOT"]= image('images/lists/root-grey.png', null, null, _("Root"));
991 }
993 /* Draw back button */
994 if($enableBack){
995 $result["BACK"]= image('images/lists/back.png', null, 'BACK', _("Go up one department"));
996 }else{
997 $result["BACK"]= image('images/lists/back-grey.png', null, null, _("Go up one department"));
998 }
1000 /* Draw home button */
1001 /* Draw home button */
1002 if($enableHome){
1003 $result["HOME"]= image('images/lists/home.png', null, 'HOME', _("Go to users department"));
1004 }else{
1005 $result["HOME"]= image('images/lists/home-grey.png', null, null, _("Go to users department"));
1006 }
1009 /* Draw reload button, this button is enabled everytime */
1010 $result["RELOAD"]= image('images/lists/reload.png', null, 'REFRESH', _("Reload list"));
1012 return ($result);
1013 }
1016 function getAction()
1017 {
1018 // Do not do anything if this is not our PID, or there's even no PID available...
1019 if(!isset($_REQUEST['PID']) || $_REQUEST['PID'] != $this->pid) {
1020 return;
1021 }
1023 // Save position if set
1024 if (isset($_POST['position_'.$this->pid]) && is_numeric($_POST['position_'.$this->pid])) {
1025 $this->scrollPosition= $_POST['position_'.$this->pid];
1026 }
1028 $result= array("targets" => array(), "action" => "");
1030 // Filter GET with "act" attributes
1031 if (isset($_GET['act'])) {
1032 $key= validate($_GET['act']);
1033 $target= preg_replace('/^listing_[a-zA-Z_]+_([0-9]+)$/', '$1', $key);
1034 if (isset($this->entries[$target]['dn'])) {
1035 $result['action']= preg_replace('/^listing_([a-zA-Z_]+)_[0-9]+$/', '$1', $key);
1036 $result['targets'][]= $this->entries[$target]['dn'];
1037 }
1039 // Drop targets if empty
1040 if (count($result['targets']) == 0) {
1041 unset($result['targets']);
1042 }
1043 return $result;
1044 }
1046 // Filter POST with "listing_" attributes
1047 foreach ($_POST as $key => $prop) {
1049 // Capture selections
1050 if (preg_match('/^listing_selected_[0-9]+$/', $key)) {
1051 $target= preg_replace('/^listing_selected_([0-9]+)$/', '$1', $key);
1052 if (isset($this->entries[$target]['dn'])) {
1053 $result['targets'][]= $this->entries[$target]['dn'];
1054 }
1055 continue;
1056 }
1058 // Capture action with target - this is a one shot
1059 if (preg_match('/^listing_[a-zA-Z_]+_[0-9]+(|_x)$/', $key)) {
1060 $target= preg_replace('/^listing_[a-zA-Z_]+_([0-9]+)(|_x)$/', '$1', $key);
1061 if (isset($this->entries[$target]['dn'])) {
1062 $result['action']= preg_replace('/^listing_([a-zA-Z_]+)_[0-9]+(|_x)$/', '$1', $key);
1063 $result['targets']= array($this->entries[$target]['dn']);
1064 }
1065 break;
1066 }
1068 // Capture action without target
1069 if (preg_match('/^listing_[a-zA-Z_]+(|_x)$/', $key)) {
1070 $result['action']= preg_replace('/^listing_([a-zA-Z_]+)(|_x)$/', '$1', $key);
1071 continue;
1072 }
1073 }
1075 // Filter POST with "act" attributes -> posted from action menu
1076 if (isset($_POST['act']) && $_POST['act'] != '') {
1077 if (!preg_match('/^export.*$/', $_POST['act'])){
1078 $result['action']= validate($_POST['act']);
1079 }
1080 }
1082 // Drop targets if empty
1083 if (count($result['targets']) == 0) {
1084 unset($result['targets']);
1085 }
1086 return $result;
1087 }
1090 function renderActionMenu()
1091 {
1092 // Don't send anything if the menu is not defined
1093 if (!isset($this->xmlData['actionmenu']['action'])){
1094 return "";
1095 }
1097 // Array?
1098 if (isset($this->xmlData['actionmenu']['action']['type'])){
1099 $this->xmlData['actionmenu']['action']= array($this->xmlData['actionmenu']['action']);
1100 }
1102 // Load shortcut
1103 $actions= &$this->xmlData['actionmenu']['action'];
1104 $result= "<input type='hidden' name='act' id='actionmenu' value=''><div style='display:none'><input type='submit' name='exec_act' id='exec_act' value=''></div>".
1105 "<ul class='level1' id='root'><li><a href='#'>"._("Actions")." ".image("images/lists/sort-down.png")."</a>";
1107 // Build ul/li list
1108 $result.= $this->recurseActions($actions);
1110 return "<div id='pulldown'>".$result."</li></ul><div>";
1111 }
1114 function recurseActions($actions)
1115 {
1116 global $class_mapping;
1117 static $level= 2;
1118 $result= "<ul class='level$level'>";
1119 $separator= "";
1121 foreach ($actions as $action) {
1123 // Skip the entry completely if there's no permission to execute it
1124 if (!$this->hasActionPermission($action, $this->filter->base)) {
1125 continue;
1126 }
1128 // Skip entry if there're missing dependencies
1129 if (isset($action['depends'])) {
1130 $deps= is_array($action['depends'])?$action['depends']:array($action['depends']);
1131 foreach($deps as $clazz) {
1132 if (!isset($class_mapping[$clazz])){
1133 continue 2;
1134 }
1135 }
1136 }
1138 // Fill image if set
1139 $img= "";
1140 if (isset($action['image'])){
1141 $img= image($action['image'])." ";
1142 }
1144 if ($action['type'] == "separator"){
1145 $separator= " style='border-top:1px solid #AAA' ";
1146 continue;
1147 }
1149 // Dive into subs
1150 if ($action['type'] == "sub" && isset($action['action'])) {
1151 $level++;
1152 if (isset($action['label'])){
1153 $result.= "<li$separator><a href='#'>$img"._($action['label'])." ".image('images/forward-arrow.png')."</a>";
1154 }
1156 // Ensure we've an array of actions, this enables sub menus with only one action.
1157 if(isset($action['action']['type'])){
1158 $action['action'] = array($action['action']);
1159 }
1161 $result.= $this->recurseActions($action['action'])."</li>";
1162 $level--;
1163 $separator= "";
1164 continue;
1165 }
1167 // Render entry elseways
1168 if (isset($action['label'])){
1169 $result.= "<li$separator><a href='#' onClick='document.getElementById(\"actionmenu\").value= \"".$action['name']."\";mainform.submit();'>$img"._($action['label'])."</a></li>";
1170 }
1172 // Check for special types
1173 switch ($action['type']) {
1174 case 'copypaste':
1175 $cut = !isset($action['cut']) || $action['cut'] != "false";
1176 $copy = !isset($action['copy']) || $action['copy'] != "false";
1177 $result.= $this->renderCopyPasteMenu($separator, $copy , $cut);
1178 break;
1180 case 'snapshot':
1181 $result.= $this->renderSnapshotMenu($separator);
1182 break;
1184 case 'exporter':
1185 $result.= $this->renderExporterMenu($separator);
1186 break;
1188 case 'daemon':
1189 $result.= $this->renderDaemonMenu($separator);
1190 break;
1191 }
1193 $separator= "";
1194 }
1196 $result.= "</ul>";
1197 return $result;
1198 }
1201 function hasActionPermission($action, $dn, $classes= null)
1202 {
1203 $ui= get_userinfo();
1205 if (isset($action['acl'])) {
1206 $acls= $action['acl'];
1207 if (!is_array($acls)) {
1208 $acls= array($acls);
1209 }
1211 // Every ACL has to pass
1212 foreach ($acls as $acl) {
1213 $module= $this->categories;
1214 $aclList= array();
1216 // Replace %acl if available
1217 if ($classes) {
1218 $otype= $this->getObjectType($this->objectTypes, $classes);
1219 $acl= str_replace('%acl', $otype['category']."/".$otype['class'], $acl);
1220 }
1222 // Split for category and plugins if needed
1223 // match for "[rw]" style entries
1224 if (preg_match('/^\[([rwcdm]+)\]$/', $acl, $match)){
1225 $aclList= array($match[1]);
1226 }
1228 // match for "users[rw]" style entries
1229 if (preg_match('/^([a-zA-Z0-9]+)\[([rwcdm]+)\]$/', $acl, $match)){
1230 $module= $match[1];
1231 $aclList= array($match[2]);
1232 }
1234 // match for "users/user[rw]" style entries
1235 if (preg_match('/^([a-zA-Z0-9]+\/[a-zA-Z0-9]+)\[([rwcdm]+)\]$/', $acl, $match)){
1236 $module= $match[1];
1237 $aclList= array($match[2]);
1238 }
1240 // match "users/user[userPassword:rw(,...)*]" style entries
1241 if (preg_match('/^([a-zA-Z0-9]+\/[a-zA-Z0-9]+)\[([a-zA-Z0-9]+:[rwcdm]+(,[a-zA-Z0-9]+:[rwcdm]+)*)\]$/', $acl, $match)){
1242 $module= $match[1];
1243 $aclList= explode(',', $match[2]);
1244 }
1246 // Walk thru prepared ACL by using $module
1247 foreach($aclList as $sAcl) {
1248 $checkAcl= "";
1250 // Category or detailed permission?
1251 if (strpos($module, '/') !== false) {
1252 if (preg_match('/([a-zA-Z0-9]+):([rwcdm]+)/', $sAcl, $m) ) {
1253 $checkAcl= $ui->get_permissions($dn, $module, $m[1]);
1254 $sAcl= $m[2];
1255 } else {
1256 $checkAcl= $ui->get_permissions($dn, $module, '0');
1257 }
1258 } else {
1259 $checkAcl= $ui->get_category_permissions($dn, $module);
1260 }
1262 // Split up remaining part of the acl and check if it we're
1263 // allowed to do something...
1264 $parts= str_split($sAcl);
1265 foreach ($parts as $part) {
1266 if (strpos($checkAcl, $part) === false){
1267 return false;
1268 }
1269 }
1271 }
1272 }
1273 }
1275 return true;
1276 }
1279 function refreshBasesList()
1280 {
1281 global $config;
1282 $ui= get_userinfo();
1284 // Do some array munching to get it user friendly
1285 $ids= $config->idepartments;
1286 $d= $ui->get_module_departments($this->categories);
1287 $k_ids= array_keys($ids);
1288 $deps= array_intersect($d,$k_ids);
1290 // Fill internal bases list
1291 $this->bases= array();
1292 foreach($k_ids as $department){
1293 $this->bases[$department] = $ids[$department];
1294 }
1296 // Populate base selector if already present
1297 if ($this->baseSelector && $this->baseMode) {
1298 $this->baseSelector->setBases($this->bases);
1299 $this->baseSelector->update(TRUE);
1300 }
1301 }
1304 function getDepartments()
1305 {
1306 $departments= array();
1307 $ui= get_userinfo();
1309 // Get list of supported department types
1310 $types = departmentManagement::get_support_departments();
1312 // Load departments allowed by ACL
1313 $validDepartments = $ui->get_module_departments($this->categories);
1315 // Build filter and look in the LDAP for possible sub departments
1316 // of current base
1317 $filter= "(&(objectClass=gosaDepartment)(|";
1318 $attrs= array("description", "objectClass");
1319 foreach($types as $name => $data){
1320 $filter.= "(objectClass=".$data['OC'].")";
1321 $attrs[]= $data['ATTR'];
1322 }
1323 $filter.= "))";
1324 $res= get_list($filter, $this->categories, $this->base, $attrs, GL_NONE);
1326 // Analyze list of departments
1327 foreach ($res as $department) {
1328 if (!in_array($department['dn'], $validDepartments)) {
1329 continue;
1330 }
1332 // Add the attribute where we use for sorting
1333 $oc= null;
1334 foreach(array_keys($types) as $type) {
1335 if (in_array($type, $department['objectClass'])) {
1336 $oc= $type;
1337 break;
1338 }
1339 }
1340 $department['sort-attribute']= $types[$oc]['ATTR'];
1342 // Move to the result list
1343 $departments[]= $department;
1344 }
1346 return $departments;
1347 }
1350 function renderCopyPasteMenu($separator, $copy= true, $cut= true)
1351 {
1352 // We can only provide information if we've got a copypaste handler
1353 // instance
1354 if(!(isset($this->copyPasteHandler) && is_object($this->copyPasteHandler))){
1355 return "";
1356 }
1358 // Presets
1359 $result= "";
1360 $read= $paste= false;
1361 $ui= get_userinfo();
1363 // Switch flags to on if there's at least one category which allows read/paste
1364 foreach($this->categories as $category){
1365 $read= $read || preg_match('/r/', $ui->get_category_permissions($this->base, $category));
1366 $paste= $paste || $ui->is_pasteable($this->base, $category) == 1;
1367 }
1370 // Draw entries that allow copy and cut
1371 if($read){
1373 // Copy entry
1374 if($copy){
1375 $result.= "<li$separator><a href='#' onClick='document.getElementById(\"actionmenu\").value= \"copy\";document.getElementById(\"exec_act\").click();'>".image('images/lists/copy.png')." "._("Copy")."</a></li>";
1376 $separator= "";
1377 }
1379 // Cut entry
1380 if($cut){
1381 $result.= "<li$separator><a href='#' onClick='document.getElementById(\"actionmenu\").value= \"cut\";document.getElementById(\"exec_act\").click();'>".image("images/lists/cut.png")." "._("Cut")."</a></li>";
1382 $separator= "";
1383 }
1384 }
1386 // Draw entries that allow pasting entries
1387 if($paste){
1388 if($this->copyPasteHandler->entries_queued()){
1389 $result.= "<li$separator><a href='#' onClick='document.getElementById(\"actionmenu\").value= \"paste\";document.getElementById(\"exec_act\").click();'>".image("images/lists/paste.png")." "._("Paste")."</a></li>";
1390 }else{
1391 $result.= "<li$separator><a href='#'>".image('images/lists/paste-grey.png')." "._("Paste")."</a></li>";
1392 }
1393 }
1395 return($result);
1396 }
1399 function renderCopyPasteActions($row, $dn, $category, $class, $copy= true, $cut= true)
1400 {
1401 // We can only provide information if we've got a copypaste handler
1402 // instance
1403 if(!(isset($this->copyPasteHandler) && is_object($this->copyPasteHandler))){
1404 return "";
1405 }
1407 // Presets
1408 $ui = get_userinfo();
1409 $result = "";
1411 // Render cut entries
1412 if($cut){
1413 if($ui->is_cutable($dn, $category, $class)){
1414 $result.= image('images/lists/cut.png', null, "listing_cut_$row", _("Cut this entry"));
1415 }else{
1416 $result.= image('images/empty.png');
1417 }
1418 }
1420 // Render copy entries
1421 if($copy){
1422 if($ui->is_copyable($dn, $category, $class)){
1423 $result.= image('images/lists/copy.png', null, "listing_copy_$row", _("Copy this entry"));
1424 }else{
1425 $result.= image('images/empty.png');
1426 }
1427 }
1429 return($result);
1430 }
1433 function renderSnapshotMenu($separator)
1434 {
1435 // We can only provide information if we've got a snapshot handler
1436 // instance
1437 if(!(isset($this->snapshotHandler) && is_object($this->snapshotHandler))){
1438 return "";
1439 }
1441 // Presets
1442 $result = "";
1443 $ui = get_userinfo();
1445 if($this->snapshotHandler->enabled() && $ui->allow_snapshot_restore($this->base, $this->categories)){
1447 // Check if there is something to restore
1448 $restore= false;
1449 foreach($this->snapshotHandler->getSnapshotBases() as $base){
1450 $restore= $restore || count($this->snapshotHandler->getDeletedSnapshots($base)) > 0;
1451 }
1453 // Draw icons according to the restore flag
1454 if($restore){
1455 $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>";
1456 }else{
1457 $result.= "<li$separator><a href='#'>".image('images/lists/restore_grey.png')." "._("Restore snapshots")."</a></li>";
1458 }
1459 }
1461 return($result);
1462 }
1465 function renderExporterMenu($separator)
1466 {
1467 // Presets
1468 $result = "";
1470 // Draw entries
1471 $result.= "<li$separator><a href='#'>".image('images/lists/export.png')." "._("Export list")." ".image("images/forward-arrow.png")."</a><ul class='level3'>";
1473 // Export CVS as build in exporter
1474 foreach ($this->exporter as $action => $exporter) {
1475 $result.= "<li><a href='#' onClick='document.getElementById(\"actionmenu\").value= \"$action\";document.getElementById(\"exec_act\").click();'>".image($exporter['image'])." ".$exporter['label']."</a></li>";
1476 }
1478 // Finalize list
1479 $result.= "</ul></li>";
1481 return($result);
1482 }
1485 function renderSnapshotActions($row, $dn, $category, $class, $copy= true, $cut= true)
1486 {
1487 // We can only provide information if we've got a snapshot handler
1488 // instance
1489 if(!(isset($this->snapshotHandler) && is_object($this->snapshotHandler))){
1490 return "";
1491 }
1493 // Presets
1494 $result= "";
1495 $ui = get_userinfo();
1497 // Only act if enabled here
1498 if($this->snapshotHandler->enabled()){
1500 // Draw restore button
1501 if ($ui->allow_snapshot_restore($dn, $category)){
1503 // Do we have snapshots for this dn?
1504 if($this->snapshotHandler->hasSnapshots($dn)){
1505 $result.= image('images/lists/restore.png', null, "listing_restore_$row", _("Restore snapshot"));
1506 } else {
1507 $result.= image('images/lists/restore_grey.png');
1508 }
1509 }
1511 // Draw snapshot button
1512 if($ui->allow_snapshot_create($dn, $category)){
1513 $result.= image('images/snapshot.png', null, "listing_snapshot_$row", _("Create a new snapshot from this object"));
1514 }else{
1515 $result.= image('images/empty.png');
1516 }
1517 }
1519 return($result);
1520 }
1523 function renderDaemonMenu($separator)
1524 {
1525 $result= "";
1527 // If there is a daemon registered, draw the menu entries
1528 if(class_available("DaemonEvent")){
1529 $events= DaemonEvent::get_event_types_by_category($this->categories);
1530 if(isset($events['BY_CLASS']) && count($events['BY_CLASS'])){
1531 foreach($events['BY_CLASS'] as $name => $event){
1532 $result.= "<li$separator><a href='#' onClick='document.getElementById(\"actionmenu\").value=\"$name\";document.getElementById(\"exec_act\").click();'>".$event['MenuImage']." ".$event['s_Menu_Name']."</a></li>";
1533 $separator= "";
1534 }
1535 }
1536 }
1538 return $result;
1539 }
1542 function getEntry($dn)
1543 {
1544 foreach ($this->entries as $entry) {
1545 if (isset($entry['dn']) && strcasecmp($dn, $entry['dn']) == 0){
1546 return $entry;
1547 }
1548 }
1549 return null;
1550 }
1553 function getEntries()
1554 {
1555 return $this->entries;
1556 }
1559 function getType($dn)
1560 {
1561 if (isset($this->objectDnMapping[$dn])) {
1562 return $this->objectDnMapping[$dn];
1563 }
1564 return null;
1565 }
1567 }
1569 ?>