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 $module;
34 var $base;
35 var $sortDirection= null;
36 var $sortColumn= null;
37 var $sortAttribute;
38 var $sortType;
39 var $numColumns;
40 var $baseMode= false;
41 var $bases= array();
42 var $header= array();
43 var $colprops= array();
44 var $filters= array();
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;
57 function listing($filename)
58 {
59 global $config;
60 global $class_mapping;
62 // Initialize pid
63 $this->pid= preg_replace("/[^0-9]/", "", microtime(TRUE));
65 if (!$this->load($filename)) {
66 die("Cannot parse $filename!");
67 }
69 // Set base for filter
70 if ($this->baseMode) {
71 $this->base= session::global_get("CurrentMainBase");
72 if ($this->base == null) {
73 $this->base= $config->current['BASE'];
74 }
75 $this->refreshBasesList();
76 } else {
77 $this->base= $config->current['BASE'];
78 }
80 // Move footer information
81 $this->showFooter= ($config->get_cfg_value("listSummary") == "true");
83 // Register build in filters
84 $this->registerElementFilter("objectType", "listing::filterObjectType");
85 $this->registerElementFilter("departmentLink", "listing::filterDepartmentLink");
86 $this->registerElementFilter("link", "listing::filterLink");
87 $this->registerElementFilter("actions", "listing::filterActions");
89 // Load exporters
90 foreach($class_mapping as $class => $dummy) {
91 if (preg_match('/Exporter$/', $class)) {
92 $info= call_user_func(array($class, "getInfo"));
93 if ($info != null) {
94 $this->exporter= array_merge($this->exporter, $info);
95 }
96 }
97 }
98 }
101 function setCopyPasteHandler($handler)
102 {
103 $this->copyPasteHandler= &$handler;
104 }
107 function setHeight($height)
108 {
109 $this->height= $height;
110 }
113 function setSnapshotHandler($handler)
114 {
115 $this->snapshotHandler= &$handler;
116 }
119 function setFilter($filter)
120 {
121 $this->filter= &$filter;
122 if ($this->departmentBrowser){
123 $this->departments= $this->getDepartments();
124 }
125 $this->filter->setBase($this->base);
126 }
129 function registerElementFilter($name, $call)
130 {
131 if (!isset($this->filters[$name])) {
132 $this->filters[$name]= $call;
133 return true;
134 }
136 return false;
137 }
140 function load($filename)
141 {
142 $contents = file_get_contents($filename);
143 $this->xmlData= xml::xml2array($contents, 1);
145 if (!isset($this->xmlData['list'])) {
146 return false;
147 }
149 $this->xmlData= $this->xmlData["list"];
151 // Load some definition values
152 foreach (array("departmentBrowser", "departmentRootVisible", "multiSelect", "baseMode") as $token) {
153 if (isset($this->xmlData['definition'][$token]) &&
154 $this->xmlData['definition'][$token] == "true"){
155 $this->$token= true;
156 }
157 }
159 // Fill objectTypes from departments and xml definition
160 $types = departmentManagement::get_support_departments();
161 foreach ($types as $class => $data) {
162 $this->objectTypes[]= array("label" => $data['TITLE'],
163 "objectClass" => $data['OC'],
164 "image" => $data['IMG']);
165 }
166 $this->categories= array();
167 if (isset($this->xmlData['definition']['objectType'])) {
168 if(isset($this->xmlData['definition']['objectType']['label'])) {
169 $this->xmlData['definition']['objectType']= array($this->xmlData['definition']['objectType']);
170 }
171 foreach ($this->xmlData['definition']['objectType'] as $index => $otype) {
172 $this->objectTypes[]= $this->xmlData['definition']['objectType'][$index];
173 if (isset($this->xmlData['definition']['objectType'][$index]['category'])){
174 $this->categories[]= $this->xmlData['definition']['objectType'][$index]['category'];
175 }
176 }
177 }
179 // Parse layout per column
180 $this->colprops= $this->parseLayout($this->xmlData['table']['layout']);
182 // Prepare table headers
183 $this->renderHeader();
185 // Assign headline/module
186 $this->headline= _($this->xmlData['definition']['label']);
187 $this->module= $this->xmlData['definition']['module'];
188 if (!is_array($this->categories)){
189 $this->categories= array($this->categories);
190 }
192 // Evaluate columns to be exported
193 if (isset($this->xmlData['table']['column'])){
194 foreach ($this->xmlData['table']['column'] as $index => $config) {
195 if (isset($config['export']) && $config['export'] == "true"){
196 $this->exportColumns[]= $index;
197 }
198 }
199 }
201 return true;
202 }
205 function renderHeader()
206 {
207 $this->header= array();
208 $this->plainHeader= array();
210 // Initialize sort?
211 $sortInit= false;
212 if (!$this->sortDirection) {
213 $this->sortColumn= 0;
214 if (isset($this->xmlData['definition']['defaultSortColumn'])){
215 $this->sortColumn= $this->xmlData['definition']['defaultSortColumn'];
216 } else {
217 $this->sortAttribute= "";
218 }
219 $this->sortDirection= array();
220 $sortInit= true;
221 }
223 if (isset($this->xmlData['table']['column'])){
224 foreach ($this->xmlData['table']['column'] as $index => $config) {
225 // Initialize everything to one direction
226 if ($sortInit) {
227 $this->sortDirection[$index]= false;
228 }
230 $sorter= "";
231 if ($index == $this->sortColumn && isset($config['sortAttribute']) &&
232 isset($config['sortType'])) {
233 $this->sortAttribute= $config['sortAttribute'];
234 $this->sortType= $config['sortType'];
235 $sorter= " <img border='0' title='".($this->sortDirection[$index]?_("Up"):_("Down"))."' src='images/lists/sort-".($this->sortDirection[$index]?"up":"down").".png' align='top'>";
236 }
237 $sortable= (isset($config['sortAttribute']));
239 $link= "href='?plug=".$_GET['plug']."&PID=".$this->pid."&act=SORT_$index'";
240 if (isset($config['label'])) {
241 if ($sortable) {
242 $this->header[$index]= "<td class='listheader' ".$this->colprops[$index]."><a $link>"._($config['label'])."$sorter</a></td>";
243 } else {
244 $this->header[$index]= "<td class='listheader' ".$this->colprops[$index].">"._($config['label'])."</td>";
245 }
246 $this->plainHeader[]= _($config['label']);
247 } else {
248 if ($sortable) {
249 $this->header[$index]= "<td class='listheader' ".$this->colprops[$index]."><a $link> $sorter</a></td>";
250 } else {
251 $this->header[$index]= "<td class='listheader' ".$this->colprops[$index]."> </td>";
252 }
253 $this->plainHeader[]= "";
254 }
255 }
256 }
257 }
260 function render()
261 {
262 // Check for exeeded sizelimit
263 if (($message= check_sizelimit()) != ""){
264 return($message);
265 }
267 // Some browsers don't have the ability do do scrollable table bodies, filter them
268 // here.
269 $switch= false;
270 if (preg_match('/(Opera|Konqueror|Safari|msie)/i', $_SERVER['HTTP_USER_AGENT'])){
271 $switch= true;
272 }
274 // Initialize list
275 $result= "<input type='hidden' value='$this->pid' name='PID'>\n";
276 $height= 450;
277 if ($this->height != 0) {
278 $result.= "<input type='hidden' value='$this->height' id='d_height'>\n";
279 $height= $this->height;
280 }
282 $result.= "<table cellpadding='0' cellspacing='0' border='0'><tr><td><div class='listContainer' id='d_scrollbody' style='border-top:1px solid #B0B0B0;width:700px;min-height:".($height+25)."px;'>\n";
284 $height= "";
285 if ($switch){
286 $height= "height:100%;";
287 }
288 $result.= "<table summary='$this->headline' style='${height}width:100%; table-layout:fixed;' cellspacing='0' cellpadding='0' id='t_scrolltable'>\n";
289 $this->numColumns= count($this->colprops) + ($this->multiSelect?1:0);
291 // Build list header
292 $result.= "<thead class='fixedListHeader listHeaderFormat'><tr>\n";
293 if ($this->multiSelect) {
294 $width= "24px";
295 if (preg_match('/Konqueror/i', $_SERVER['HTTP_USER_AGENT'])){
296 $width= "28px";
297 }
298 $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";
299 }
300 foreach ($this->header as $header) {
301 $result.= $header;
302 }
303 $result.= "</tr></thead>\n";
305 // Build list body
306 $result.= "<tbody class='listScrollContent listBodyFormat' id='t_nscrollbody' style='height:".$height."px;'>\n";
308 // No results? Just take an empty colspanned row
309 if (count($this->entries) + count($this->departments) == 0) {
310 $result.= "<tr class='rowxp0'><td class='list1nohighlight' colspan='$this->numColumns' style='height:100%;border-right:0px;width:100%;'> </td></tr>";
311 }
313 // Line color alternation
314 $alt= 0;
315 $deps= 0;
317 // Draw department browser if configured and we're not in sub mode
318 $this->useSpan= false;
319 if ($this->departmentBrowser && $this->filter->scope != "sub") {
320 // Fill with department browser if configured this way
321 $departmentIterator= new departmentSortIterator($this->departments, $this->sortDirection[$this->sortColumn]);
322 foreach ($departmentIterator as $row => $entry){
323 $result.="<tr class='rowxp".($alt&1)."'>";
325 // Render multi select if needed
326 if ($this->multiSelect) {
327 $result.="<td style='text-align:center;padding:0;' class='list1'> </td>";
328 }
330 // Render defined department columns, fill the rest with some stuff
331 $rest= $this->numColumns - 1;
332 foreach ($this->xmlData['table']['department'] as $index => $config) {
333 $colspan= 1;
334 if (isset($config['span'])){
335 $colspan= $config['span'];
336 $this->useSpan= true;
337 }
338 $result.="<td colspan='$colspan' ".$this->colprops[$index]." class='list1'>".$this->renderCell($config['value'], $entry, $row)."</td>";
339 $rest-= $colspan;
340 }
342 // Fill remaining cols with nothing
343 $last= $this->numColumns - $rest;
344 for ($i= 0; $i<$rest; $i++){
345 $result.= "<td ".$this->colprops[$last+$i-1]." class='list1'> </td>";
346 }
347 $result.="</tr>";
349 $alt++;
350 }
351 $deps= $alt;
352 }
354 // Fill with contents, sort as configured
355 foreach ($this->entries as $row => $entry) {
356 $trow= "";
358 // Render multi select if needed
359 if ($this->multiSelect) {
360 $trow.="<td style='text-align:center;width:20px;' class='list0'><input type='checkbox' id='listing_selected_$row' name='listing_selected_$row'></td>\n";
361 }
363 foreach ($this->xmlData['table']['column'] as $index => $config) {
364 $renderedCell= $this->renderCell($config['value'], $entry, $row);
365 $trow.="<td ".$this->colprops[$index]." class='list0'>".$renderedCell."</td>\n";
367 // Save rendered column
368 $sort= preg_replace('/.*>([^<]+)<.*$/', '$1', $renderedCell);
369 $sort= preg_replace('/ /', '', $sort);
370 if (preg_match('/</', $sort)){
371 $sort= "";
372 }
373 $this->entries[$row]["_sort$index"]= $sort;
374 }
376 // Save rendered entry
377 $this->entries[$row]['_rendered']= $trow;
378 }
380 // Complete list by sorting entries for _sort$index and appending them to the output
381 $entryIterator= new listingSortIterator($this->entries, $this->sortDirection[$this->sortColumn], "_sort".$this->sortColumn, $this->sortType);
382 foreach ($entryIterator as $row => $entry){
383 $alt++;
384 $result.="<tr class='rowxp".($alt&1)."'>\n";
385 $result.= $entry['_rendered'];
386 $result.="</tr>\n";
387 }
389 // Need to fill the list if it's not full (nobody knows why this is 22 ;-))
390 $emptyListStyle= (count($this->entries) + (($this->useSpan && count($this->entries))?$deps:0) == 0)?"border:0;":"";
391 if ((count($this->entries) + $deps) < 22) {
392 $result.= "<tr>";
393 for ($i= 0; $i<$this->numColumns; $i++) {
394 if ($i == 0) {
395 $result.= "<td class='list1nohighlight' style='$emptyListStyle height:100%;'> </td>";
396 continue;
397 }
398 if ($i != $this->numColumns-1) {
399 $result.= "<td class='list1nohighlight' style='$emptyListStyle'> </td>";
400 } else {
401 $result.= "<td class='list1nohighlight' style='border-right:1px solid #AAA;$emptyListStyle'> </td>";
402 }
403 }
404 $result.= "</tr>";
405 }
407 // Close list body
408 $result.= "</tbody></table></div></td></tr>";
410 // Add the footer if requested
411 if ($this->showFooter) {
412 $result.= "<tr><td class='nlistFooter'>";
414 foreach ($this->objectTypes as $objectType) {
415 if (isset($this->objectTypeCount[$objectType['label']])) {
416 $label= _($objectType['label']);
417 $result.= "<img class='center' src='".$objectType['image']."' title='$label' alt='$label'> ".$this->objectTypeCount[$objectType['label']]." ";
418 }
419 }
421 $result.= "</td></tr>";
422 }
424 // Close list
425 $result.= "</table>";
426 $result.= $switch?"<input type='hidden' id='list_workaround'>":"";
428 $smarty= get_smarty();
429 $smarty->assign("usePrototype", "true");
430 $smarty->assign("FILTER", $this->filter->render());
431 $smarty->assign("SIZELIMIT", print_sizelimit_warning());
432 $smarty->assign("LIST", $result);
434 // Assign navigation elements
435 $nav= $this->renderNavigation();
436 foreach ($nav as $key => $html) {
437 $smarty->assign($key, $html);
438 }
440 // Assign action menu / base
441 $smarty->assign("ACTIONS", $this->renderActionMenu());
442 $smarty->assign("BASE", $this->renderBase());
444 // Assign separator
445 $smarty->assign("SEPARATOR", "<img src='images/lists/seperator.png' alt='-' align='middle' height='16' width='1' class='center'>");
447 // Assign summary
448 $smarty->assign("HEADLINE", $this->headline);
450 // Try to load template from plugin the folder first...
451 $file = get_template_path($this->xmlData['definition']['template'], true);
453 // ... if this fails, try to load the file from the theme folder.
454 if(!file_exists($file)){
455 $file = get_template_path($this->xmlData['definition']['template']);
456 }
458 return ($smarty->fetch($file));
459 }
462 function update()
463 {
464 global $config;
465 $ui= get_userinfo();
467 // Reset object counter / DN mapping
468 $this->objectTypeCount= array();
469 $this->objectDnMapping= array();
471 // Do not do anything if this is not our PID
472 if(isset($_REQUEST['PID']) && $_REQUEST['PID'] != $this->pid) {
473 return;
474 }
476 // Save base
477 if (isset($_POST['BASE']) && $this->baseMode) {
478 $base= get_post('BASE');
479 if (isset($this->bases[$base])) {
480 $this->base= $base;
481 session::global_set("CurrentMainBase", $this->base);
482 }
483 }
485 // Override the base if we got a message from the browser navigation
486 if ($this->departmentBrowser && isset($_GET['act'])) {
487 if (preg_match('/^department_([0-9]+)$/', validate($_GET['act']), $match)){
488 if (isset($this->departments[$match[1]])){
489 $this->base= $this->departments[$match[1]]['dn'];
490 session::global_set("CurrentMainBase", $this->base);
491 }
492 }
493 }
495 // Filter POST with "act" attributes -> posted from action menu
496 if (isset($_POST['exec_act']) && $_POST['act'] != '') {
497 if (preg_match('/^export.*$/', $_POST['act']) && isset($this->exporter[$_POST['act']])) {
498 $exporter= $this->exporter[$_POST['act']];
499 $userinfo= ", "._("created by")." ".$ui->cn." - ".strftime('%A, %d. %B %Y, %H:%M:%S');
500 $entryIterator= new listingSortIterator($this->entries, $this->sortDirection[$this->sortColumn], "_sort".$this->sortColumn, $this->sortType);
501 $sortedEntries= array();
502 foreach ($entryIterator as $entry){
503 $sortedEntries[]= $entry;
504 }
505 $instance= new $exporter['class']($this->headline.$userinfo, $this->plainHeader, $sortedEntries, $this->exportColumns);
506 $type= call_user_func(array($exporter['class'], "getInfo"));
507 $type= $type[$_POST['act']];
508 send_binary_content($instance->query(), $type['filename'], $type= $type['mime']);
509 }
510 }
512 // Filter GET with "act" attributes
513 if (isset($_GET['act'])) {
514 $key= validate($_GET['act']);
515 if (preg_match('/^SORT_([0-9]+)$/', $key, $match)) {
516 // Switch to new column or invert search order?
517 $column= $match[1];
518 if ($this->sortColumn != $column) {
519 $this->sortColumn= $column;
520 } else {
521 $this->sortDirection[$column]= !$this->sortDirection[$column];
522 }
524 // Allow header to update itself according to the new sort settings
525 $this->renderHeader();
526 }
527 }
529 // Override base if we got signals from the navigation elements
530 $action= "";
531 foreach ($_POST as $key => $value) {
532 if (preg_match('/^(ROOT|BACK|HOME)_x$/', $key, $match)) {
533 $action= $match[1];
534 break;
535 }
536 }
538 // Navigation handling
539 if ($action == 'ROOT') {
540 $deps= $ui->get_module_departments($this->module);
541 $this->base= $deps[0];
542 }
543 if ($action == 'BACK') {
544 $deps= $ui->get_module_departments($this->module);
545 $base= preg_replace("/^[^,]+,/", "", $this->base);
546 if(in_array_ics($base, $deps)){
547 $this->base= $base;
548 }
549 }
550 if ($action == 'HOME') {
551 $ui= get_userinfo();
552 $this->base= $this->filter->getObjectBase($ui->dn);
553 }
555 // Reload departments
556 if ($this->departmentBrowser){
557 $this->departments= $this->getDepartments();
558 }
560 // Update filter and refresh entries
561 $this->filter->setBase($this->base);
562 $this->entries= $this->filter->query();
563 }
566 function setBase($base)
567 {
568 $this->base= $base;
569 }
572 function getBase()
573 {
574 return $this->base;
575 }
578 function parseLayout($layout)
579 {
580 $result= array();
581 $layout= preg_replace("/^\|/", "", $layout);
582 $layout= preg_replace("/\|$/", "", $layout);
583 $cols= split("\|", $layout);
585 foreach ($cols as $index => $config) {
586 if ($config != "") {
587 $res= "";
588 $components= split(';', $config);
589 foreach ($components as $part) {
590 if (preg_match("/^r$/", $part)) {
591 $res.= "text-align:right;";
592 continue;
593 }
594 if (preg_match("/^l$/", $part)) {
595 $res.= "text-align:left;";
596 continue;
597 }
598 if (preg_match("/^c$/", $part)) {
599 $res.= "text-align:center;";
600 continue;
601 }
602 if (preg_match("/^[0-9]+(|px|%)$/", $part)) {
603 $res.= "width:$part;min-width:$part;";
604 continue;
605 }
606 }
608 // Add minimum width for scalable columns
609 if (!preg_match('/width:/', $res)){
610 $res.= "min-width:200px;";
611 }
613 $result[$index]= " style='$res' ";
614 } else {
615 $result[$index]= " style='min-width:100px'";
616 }
617 }
619 // Save number of columns for later use
620 $this->numColumns= count($cols);
622 return $result;
623 }
626 function renderCell($data, $config, $row)
627 {
628 // Replace flat attributes in data string
629 for ($i= 0; $i<$config['count']; $i++) {
630 $attr= $config[$i];
631 $value= "";
632 if (is_array($config[$attr])) {
633 $value= $config[$attr][0];
634 } else {
635 $value= $config[$attr];
636 }
637 $data= preg_replace("/%\{$attr\}/", $value, $data);
638 }
640 // Watch out for filters and prepare to execute them
641 $data= $this->processElementFilter($data, $config, $row);
643 // Replace all non replaced %{...} instances because they
644 // are non resolved attributes or filters
645 $data= preg_replace('/%{[^}]+}/', ' ', $data);
647 return $data;
648 }
651 function renderBase()
652 {
653 if (!$this->baseMode) {
654 return;
655 }
657 $result= "<select name='BASE' onChange='mainform.submit()' size='1'>";
658 $firstDN= null;
659 $found= false;
661 foreach ($this->bases as $key=>$value) {
662 // Keep first entry to fall back eventually
663 if(!$firstDN) {
664 $firstDN= $key;
665 }
667 // Prepare to render entry
668 $selected= "";
669 if ($key == $this->base) {
670 $selected= " selected";
671 $found= true;
672 }
673 $key = htmlentities($key,ENT_QUOTES);
674 $result.= "\n<option value=\"".$key."\"$selected>".$value."</option>";
675 }
677 $result.= "</select>";
679 // Reset the currently used base to the first DN we found if there
680 // was no match.
681 if(!$found){
682 $this->base = $firstDN;
683 }
685 return $result;
686 }
689 function processElementFilter($data, $config, $row)
690 {
691 preg_match_all("/%\{filter:([^(]+)\((.*)\)\}/", $data, $matches, PREG_SET_ORDER);
693 foreach ($matches as $match) {
694 $cl= "";
695 $method= "";
696 if (preg_match('/::/', $match[1])) {
697 $cl= preg_replace('/::.*$/', '', $match[1]);
698 $method= preg_replace('/^.*::/', '', $match[1]);
699 } else {
700 if (!isset($this->filters[$match[1]])) {
701 continue;
702 }
703 $cl= preg_replace('/::.*$/', '', $this->filters[$match[1]]);
704 $method= preg_replace('/^.*::/', '', $this->filters[$match[1]]);
705 }
707 // Prepare params for function call
708 $params= array();
709 preg_match_all('/"[^"]+"|[^,]+/', $match[2], $parts);
710 foreach ($parts[0] as $param) {
712 // Row is replaced by the row number
713 if ($param == "row") {
714 $params[]= $row;
715 continue;
716 }
718 // pid is replaced by the current PID
719 if ($param == "pid") {
720 $params[]= $this->pid;
721 continue;
722 }
724 // base is replaced by the current base
725 if ($param == "base") {
726 $params[]= $this->getBase();
727 continue;
728 }
730 // Fixie with "" is passed directly
731 if (preg_match('/^".*"$/', $param)){
732 $params[]= preg_replace('/"/', '', $param);
733 continue;
734 }
736 // Move dn if needed
737 if ($param == "dn") {
738 $params[]= LDAP::fix($config["dn"]);
739 continue;
740 }
742 // LDAP variables get replaced by their objects
743 for ($i= 0; $i<$config['count']; $i++) {
744 if ($param == $config[$i]) {
745 $values= $config[$config[$i]];
746 if (is_array($values)){
747 unset($values['count']);
748 }
749 $params[]= $values;
750 break;
751 }
752 }
753 }
755 // Replace information
756 if ($cl == "listing") {
757 // Non static call - seems to result in errors
758 $data= @preg_replace('/'.preg_quote($match[0]).'/', call_user_func_array(array($this, "$method"), $params), $data);
759 } else {
760 // Static call
761 $data= preg_replace('/'.preg_quote($match[0]).'/', call_user_func_array(array($cl, $method), $params), $data);
762 }
763 }
765 return $data;
766 }
769 function getObjectType($types, $classes)
770 {
771 // Walk thru types and see if there's something matching
772 foreach ($types as $objectType) {
773 $ocs= $objectType['objectClass'];
774 if (!is_array($ocs)){
775 $ocs= array($ocs);
776 }
778 $found= true;
779 foreach ($ocs as $oc){
780 if (preg_match('/^!(.*)$/', $oc, $match)) {
781 $oc= $match[1];
782 if (in_array($oc, $classes)) {
783 $found= false;
784 }
785 } else {
786 if (!in_array($oc, $classes)) {
787 $found= false;
788 }
789 }
790 }
792 if ($found) {
793 return $objectType;
794 }
795 }
797 return null;
798 }
801 function filterObjectType($dn, $classes)
802 {
803 // Walk thru classes and return on first match
804 $result= " ";
806 $objectType= $this->getObjectType($this->objectTypes, $classes);
807 if ($objectType) {
808 $this->objectDnMapping[$dn]= $objectType["objectClass"];
809 $result= "<img class='center' title='".LDAP::fix($dn)."' src='".$objectType["image"]."'>";
810 if (!isset($this->objectTypeCount[$objectType['label']])) {
811 $this->objectTypeCount[$objectType['label']]= 0;
812 }
813 $this->objectTypeCount[$objectType['label']]++;
814 }
816 return $result;
817 }
820 function filterActions($dn, $row, $classes)
821 {
822 // Do nothing if there's no menu defined
823 if (!isset($this->xmlData['actiontriggers']['action'])) {
824 return " ";
825 }
827 // Go thru all actions
828 $result= "";
829 $actions= $this->xmlData['actiontriggers']['action'];
830 foreach($actions as $action) {
831 // Skip the entry completely if there's no permission to execute it
832 if (!$this->hasActionPermission($action, $dn)) {
833 $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
834 continue;
835 }
837 // Skip entry if the pseudo filter does not fit
838 if (isset($action['filter']) && preg_match('/^[a-z0-9_]+!?=[a-z0-9_]+$/i', $action['filter'])) {
839 list($fa, $fv)= split('=', $action['filter']);
840 if (preg_match('/^(.*)!$/', $fa, $m)){
841 $fa= $m[1];
842 if (isset($this->entries[$row][$fa]) && $this->entries[$row][$fa][0] == $fv) {
843 $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
844 continue;
845 }
846 } else {
847 if (!isset($this->entries[$row][$fa]) && !$this->entries[$row][$fa][0] == $fv) {
848 $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
849 continue;
850 }
851 }
852 }
855 // If there's an objectclass definition and we don't have it
856 // add an empty picture here.
857 if (isset($action['objectclass'])){
858 $objectclass= $action['objectclass'];
859 if (preg_match('/^!(.*)$/', $objectclass, $m)){
860 $objectclass= $m[1];
861 if(in_array($objectclass, $classes)) {
862 $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
863 continue;
864 }
865 } elseif (is_string($objectclass)) {
866 if(!in_array($objectclass, $classes)) {
867 $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
868 continue;
869 }
870 } elseif (is_array($objectclass)) {
871 if(count(array_intersect($objectclass, $classes)) != count($objectclass)){
872 $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
873 continue;
874 }
875 }
876 }
878 // Render normal entries as usual
879 if ($action['type'] == "entry") {
880 $label= $this->processElementFilter($action['label'], $this->entries[$row], $row);
881 $image= $this->processElementFilter($action['image'], $this->entries[$row], $row);
882 $result.="<input class='center' type='image' src='$image' title='$label' ".
883 "name='listing_".$action['name']."_$row' style='padding:1px'>";
884 }
886 // Handle special types
887 if ($action['type'] == "copypaste" || $action['type'] == "snapshot") {
889 $objectType= $this->getObjectType($this->objectTypes, $this->entries[$row]['objectClass']);
890 $category= $class= null;
891 if ($objectType) {
892 $category= $objectType['category'];
893 $class= $objectType['class'];
894 }
896 if ($action['type'] == "copypaste") {
897 $copy = !isset($action['copy']) || $action['copy'] == "true";
898 $cut = !isset($action['cut']) || $action['cut'] == "true";
899 $result.= $this->renderCopyPasteActions($row, $this->entries[$row]['dn'], $category, $class,$copy,$cut);
900 } else {
901 $result.= $this->renderSnapshotActions($row, $this->entries[$row]['dn'], $category, $class);
902 }
903 }
904 }
906 return $result;
907 }
910 function filterDepartmentLink($row, $dn, $description)
911 {
912 $attr= $this->departments[$row]['sort-attribute'];
913 $name= $this->departments[$row][$attr];
914 if (is_array($name)){
915 $name= $name[0];
916 }
917 $result= sprintf("%s [%s]", $name, $description[0]);
918 return("<a href='?plug=".$_GET['plug']."&PID=$this->pid&act=department_$row' title='$dn'>$result</a>");
919 }
922 function filterLink()
923 {
924 $result= " ";
926 $row= func_get_arg(0);
927 $pid= $this->pid;
928 $dn= LDAP::fix(func_get_arg(1));
929 $params= array(func_get_arg(2));
931 // Collect sprintf params
932 for ($i = 3;$i < func_num_args();$i++) {
933 $val= func_get_arg($i);
934 if (is_array($val)){
935 $params[]= $val[0];
936 continue;
937 }
938 $params[]= $val;
939 }
941 $result= " ";
942 $trans= call_user_func_array("sprintf", $params);
943 if ($trans != "") {
944 return("<a href='?plug=".$_GET['plug']."&PID=$pid&act=listing_edit_$row' title='$dn'>$trans</a>");
945 }
947 return $result;
948 }
951 function renderNavigation()
952 {
953 $result= array();
954 $enableBack = true;
955 $enableRoot = true;
956 $enableHome = true;
958 $ui = get_userinfo();
960 /* Check if base = first available base */
961 $deps = $ui->get_module_departments($this->module);
963 if(!count($deps) || $deps[0] == $this->filter->base){
964 $enableBack = false;
965 $enableRoot = false;
966 }
968 $listhead ="";
970 /* Check if we are in users home department */
971 if(!count($deps) || $this->filter->base == $this->filter->getObjectBase($ui->dn)){
972 $enableHome = false;
973 }
975 /* Draw root button */
976 if($enableRoot){
977 $result["ROOT"]= "<input class='center' type='image' src='images/lists/root.png' align='middle' ".
978 "title='"._("Go to root department")."' name='ROOT' alt='"._("Root")."'>";
979 }else{
980 $result["ROOT"]= "<img src='images/lists/root_grey.png' class='center' alt='"._("Root")."'>";
981 }
983 /* Draw back button */
984 if($enableBack){
985 $result["BACK"]= "<input class='center' type='image' align='middle' src='images/lists/back.png' ".
986 "title='"._("Go up one department")."' alt='"._("Up")."' name='BACK'>";
987 }else{
988 $result["BACK"]= "<img src='images/lists/back_grey.png' class='center' alt='"._("Up")."'>";
989 }
991 /* Draw home button */
992 if($enableHome){
993 $result["HOME"]= "<input class='center' type='image' align='middle' src='images/lists/home.png' ".
994 "title='"._("Go to users department")."' alt='"._("Home")."' name='HOME'>";
995 }else{
996 $result["HOME"]= "<img src='images/lists/home_grey.png' class='center' alt='"._("Home")."'>";
997 }
999 /* Draw reload button, this button is enabled everytime */
1000 $result["RELOAD"]= "<input class='center' type='image' src='images/lists/reload.png' align='middle' ".
1001 "title='"._("Reload list")."' name='REFRESH' alt='"._("Submit")."'>";
1003 return ($result);
1004 }
1007 function getAction()
1008 {
1009 // Do not do anything if this is not our PID, or there's even no PID available...
1010 if(!isset($_REQUEST['PID']) || $_REQUEST['PID'] != $this->pid) {
1011 return;
1012 }
1014 $result= array("targets" => array(), "action" => "");
1016 // Filter GET with "act" attributes
1017 if (isset($_GET['act'])) {
1018 $key= validate($_GET['act']);
1019 $target= preg_replace('/^listing_[a-zA-Z_]+_([0-9]+)$/', '$1', $key);
1020 if (isset($this->entries[$target]['dn'])) {
1021 $result['action']= preg_replace('/^listing_([a-zA-Z_]+)_[0-9]+$/', '$1', $key);
1022 $result['targets'][]= $this->entries[$target]['dn'];
1023 }
1025 // Drop targets if empty
1026 if (count($result['targets']) == 0) {
1027 unset($result['targets']);
1028 }
1029 return $result;
1030 }
1032 // Filter POST with "listing_" attributes
1033 foreach ($_POST as $key => $prop) {
1035 // Capture selections
1036 if (preg_match('/^listing_selected_[0-9]+$/', $key)) {
1037 $target= preg_replace('/^listing_selected_([0-9]+)$/', '$1', $key);
1038 if (isset($this->entries[$target]['dn'])) {
1039 $result['targets'][]= $this->entries[$target]['dn'];
1040 }
1041 continue;
1042 }
1044 // Capture action with target - this is a one shot
1045 if (preg_match('/^listing_[a-zA-Z_]+_[0-9]+(|_x)$/', $key)) {
1046 $target= preg_replace('/^listing_[a-zA-Z_]+_([0-9]+)(|_x)$/', '$1', $key);
1047 if (isset($this->entries[$target]['dn'])) {
1048 $result['action']= preg_replace('/^listing_([a-zA-Z_]+)_[0-9]+(|_x)$/', '$1', $key);
1049 $result['targets']= array($this->entries[$target]['dn']);
1050 }
1051 break;
1052 }
1054 // Capture action without target
1055 if (preg_match('/^listing_[a-zA-Z_]+(|_x)$/', $key)) {
1056 $result['action']= preg_replace('/^listing_([a-zA-Z_]+)(|_x)$/', '$1', $key);
1057 continue;
1058 }
1059 }
1061 // Filter POST with "act" attributes -> posted from action menu
1062 if (isset($_POST['act']) && $_POST['act'] != '') {
1063 if (!preg_match('/^export.*$/', $_POST['act'])){
1064 $result['action']= validate($_POST['act']);
1065 }
1066 }
1068 // Drop targets if empty
1069 if (count($result['targets']) == 0) {
1070 unset($result['targets']);
1071 }
1072 return $result;
1073 }
1076 function renderActionMenu()
1077 {
1078 // Don't send anything if the menu is not defined
1079 if (!isset($this->xmlData['actionmenu']['action'])){
1080 return "";
1081 }
1083 // Array?
1084 if (isset($this->xmlData['actionmenu']['action']['type'])){
1085 $this->xmlData['actionmenu']['action']= array($this->xmlData['actionmenu']['action']);
1086 }
1088 // Load shortcut
1089 $actions= &$this->xmlData['actionmenu']['action'];
1090 $result= "<input type='hidden' name='act' id='actionmenu' value=''><div style='display:none'><input type='submit' name='exec_act' id='exec_act' value=''></div>".
1091 "<ul class='level1' id='root'><li><a href='#'>"._("Actions")." <img ".
1092 "border=0 class='center' src='images/lists/sort-down.png'></a>";
1094 // Build ul/li list
1095 $result.= $this->recurseActions($actions);
1097 return "<div id='pulldown'>".$result."</li></ul><div>";
1098 }
1101 function recurseActions($actions)
1102 {
1103 global $class_mapping;
1104 static $level= 2;
1105 $result= "<ul class='level$level'>";
1106 $separator= "";
1108 foreach ($actions as $action) {
1110 // Skip the entry completely if there's no permission to execute it
1111 if (!$this->hasActionPermission($action, $this->filter->base)) {
1112 continue;
1113 }
1115 // Skip entry if there're missing dependencies
1116 if (isset($action['depends'])) {
1117 $deps= is_array($action['depends'])?$action['depends']:array($action['depends']);
1118 foreach($deps as $clazz) {
1119 if (!isset($class_mapping[$clazz])){
1120 continue 2;
1121 }
1122 }
1123 }
1125 // Fill image if set
1126 $img= "";
1127 if (isset($action['image'])){
1128 $img= "<img border='0' class='center' src='".$action['image']."'> ";
1129 }
1131 if ($action['type'] == "separator"){
1132 $separator= " style='border-top:1px solid #AAA' ";
1133 continue;
1134 }
1136 // Dive into subs
1137 if ($action['type'] == "sub" && isset($action['action'])) {
1138 $level++;
1139 if (isset($action['label'])){
1140 $result.= "<li$separator><a href='#'>$img"._($action['label'])." <img border='0' src='images/forward-arrow.png'></a>";
1141 }
1143 // Ensure we've an array of actions, this enables sub menus with only one action.
1144 if(isset($action['action']['type'])){
1145 $action['action'] = array($action['action']);
1146 }
1148 $result.= $this->recurseActions($action['action'])."</li>";
1149 $level--;
1150 $separator= "";
1151 continue;
1152 }
1154 // Render entry elseways
1155 if (isset($action['label'])){
1156 $result.= "<li$separator><a href='#' onClick='document.getElementById(\"actionmenu\").value= \"".$action['name']."\";mainform.submit();'>$img"._($action['label'])."</a></li>";
1157 }
1159 // Check for special types
1160 switch ($action['type']) {
1161 case 'copypaste':
1162 $cut = !isset($action['cut']) || $action['cut'] != "false";
1163 $copy = !isset($action['copy']) || $action['copy'] != "false";
1164 $result.= $this->renderCopyPasteMenu($separator, $copy , $cut);
1165 break;
1167 case 'snapshot':
1168 $result.= $this->renderSnapshotMenu($separator);
1169 break;
1171 case 'exporter':
1172 $result.= $this->renderExporterMenu($separator);
1173 break;
1175 case 'daemon':
1176 $result.= $this->renderDaemonMenu($separator);
1177 break;
1178 }
1180 $separator= "";
1181 }
1183 $result.= "</ul>";
1184 return $result;
1185 }
1188 function hasActionPermission($action, $dn)
1189 {
1190 $ui= get_userinfo();
1192 if (isset($action['acl'])) {
1193 $acls= $action['acl'];
1194 if (!is_array($acls)) {
1195 $acls= array($acls);
1196 }
1198 // Every ACL has to pass
1199 foreach ($acls as $acl) {
1200 $module= $this->module;
1201 $aclList= array();
1203 // Split for category and plugins if needed
1204 // match for "[rw]" style entries
1205 if (preg_match('/^\[([rwcdm]+)\]$/', $acl, $match)){
1206 $aclList= array($match[1]);
1207 }
1209 // match for "users[rw]" style entries
1210 if (preg_match('/^([a-zA-Z0-9]+)\[([rwcdm]+)\]$/', $acl, $match)){
1211 $module= $match[1];
1212 $aclList= array($match[2]);
1213 }
1215 // match for "users/user[rw]" style entries
1216 if (preg_match('/^([a-zA-Z0-9]+\/[a-zA-Z0-9]+)\[([rwcdm]+)\]$/', $acl, $match)){
1217 $module= $match[1];
1218 $aclList= array($match[2]);
1219 }
1221 // match "users/user[userPassword:rw(,...)*]" style entries
1222 if (preg_match('/^([a-zA-Z0-9]+\/[a-zA-Z0-9]+)\[([a-zA-Z0-9]+:[rwcdm]+(,[a-zA-Z0-9]+:[rwcdm]+)*)\]$/', $acl, $match)){
1223 $module= $match[1];
1224 $aclList= split(',', $match[2]);
1225 }
1227 // Walk thru prepared ACL by using $module
1228 foreach($aclList as $sAcl) {
1229 $checkAcl= "";
1231 // Category or detailed permission?
1232 if (strpos('/', $module) === false) {
1233 if (preg_match('/([a-zA-Z0-9]+):([rwcdm]+)/', $sAcl, $m) ) {
1234 $checkAcl= $ui->get_permissions($dn, $module, $m[1]);
1235 $sAcl= $m[2];
1236 } else {
1237 $checkAcl= $ui->get_permissions($dn, $module, '0');
1238 }
1239 } else {
1240 $checkAcl= $ui->get_category_permissions($dn, $module);
1241 }
1243 // Split up remaining part of the acl and check if it we're
1244 // allowed to do something...
1245 $parts= str_split($sAcl);
1246 foreach ($parts as $part) {
1247 if (strpos($checkAcl, $part) === false){
1248 return false;
1249 }
1250 }
1252 }
1253 }
1254 }
1256 return true;
1257 }
1260 function refreshBasesList()
1261 {
1262 global $config;
1263 $ui= get_userinfo();
1265 // Do some array munching to get it user friendly
1266 $ids= $config->idepartments;
1267 $d= $ui->get_module_departments($this->module);
1268 $k_ids= array_keys($ids);
1269 $deps= array_intersect($d,$k_ids);
1271 // Fill internal bases list
1272 $this->bases= array();
1273 foreach($k_ids as $department){
1274 $this->bases[$department] = $ids[$department];
1275 }
1276 }
1279 function getDepartments()
1280 {
1281 $departments= array();
1282 $ui= get_userinfo();
1284 // Get list of supported department types
1285 $types = departmentManagement::get_support_departments();
1287 // Load departments allowed by ACL
1288 $validDepartments = $ui->get_module_departments($this->module);
1290 // Build filter and look in the LDAP for possible sub departments
1291 // of current base
1292 $filter= "(&(objectClass=gosaDepartment)(|";
1293 $attrs= array("description", "objectClass");
1294 foreach($types as $name => $data){
1295 $filter.= "(objectClass=".$data['OC'].")";
1296 $attrs[]= $data['ATTR'];
1297 }
1298 $filter.= "))";
1299 $res= get_list($filter, $this->module, $this->base, $attrs, GL_NONE);
1301 // Analyze list of departments
1302 foreach ($res as $department) {
1303 if (!in_array($department['dn'], $validDepartments)) {
1304 continue;
1305 }
1307 // Add the attribute where we use for sorting
1308 $oc= null;
1309 foreach(array_keys($types) as $type) {
1310 if (in_array($type, $department['objectClass'])) {
1311 $oc= $type;
1312 break;
1313 }
1314 }
1315 $department['sort-attribute']= $types[$oc]['ATTR'];
1317 // Move to the result list
1318 $departments[]= $department;
1319 }
1321 return $departments;
1322 }
1325 function renderCopyPasteMenu($separator, $copy= true, $cut= true)
1326 {
1327 // We can only provide information if we've got a copypaste handler
1328 // instance
1329 if(!(isset($this->copyPasteHandler) && is_object($this->copyPasteHandler))){
1330 return "";
1331 }
1333 // Presets
1334 $result= "";
1335 $read= $paste= false;
1336 $ui= get_userinfo();
1338 // Switch flags to on if there's at least one category which allows read/paste
1339 foreach($this->categories as $category){
1340 $read= $read || preg_match('/r/', $ui->get_category_permissions($this->base, $category));
1341 $paste= $paste || $ui->is_pasteable($this->base, $category) == 1;
1342 }
1345 // Draw entries that allow copy and cut
1346 if($read){
1348 // Copy entry
1349 if($copy){
1350 $result.= "<li$separator><a href='#' onClick='document.getElementById(\"actionmenu\").value= \"copy\";document.getElementById(\"exec_act\").click();'><img src='images/lists/copy.png' alt='' border='0' class='center'> "._("Copy")."</a></li>";
1351 $separator= "";
1352 }
1354 // Cut entry
1355 if($cut){
1356 $result.= "<li$separator><a href='#' onClick='document.getElementById(\"actionmenu\").value= \"cut\";document.getElementById(\"exec_act\").click();'><img src='images/lists/cut.png' alt='' border='0' class='center'> "._("Cut")."</a></li>";
1357 $separator= "";
1358 }
1359 }
1361 // Draw entries that allow pasting entries
1362 if($paste){
1363 if($this->copyPasteHandler->entries_queued()){
1364 $result.= "<li$separator><a href='#' onClick='document.getElementById(\"actionmenu\").value= \"paste\";document.getElementById(\"exec_act\").click();'><img src='images/lists/paste.png' alt='' border='0' class='center'> "._("Paste")."</a></li>";
1365 }else{
1366 $result.= "<li$separator><a href='#'><img src='images/lists/paste-grey.png' alt='' border='0' class='center'> "._("Paste")."</a></li>";
1367 }
1368 }
1370 return($result);
1371 }
1374 function renderCopyPasteActions($row, $dn, $category, $class, $copy= true, $cut= true)
1375 {
1376 // We can only provide information if we've got a copypaste handler
1377 // instance
1378 if(!(isset($this->copyPasteHandler) && is_object($this->copyPasteHandler))){
1379 return "";
1380 }
1382 // Presets
1383 $ui = get_userinfo();
1384 $result = "";
1386 // Render cut entries
1387 if($cut){
1388 if($ui->is_cutable($dn, $category, $class)){
1389 $result .= "<input class='center' type='image'
1390 src='images/lists/cut.png' alt='"._("Cut")."' name='listing_cut_$row' title='"._("Cut this entry")."' style='padding:1px'>";
1391 }else{
1392 $result.="<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
1393 }
1394 }
1396 // Render copy entries
1397 if($copy){
1398 if($ui->is_copyable($dn, $category, $class)){
1399 $result.= "<input class='center' type='image'
1400 src='images/lists/copy.png' alt='"._("Copy")."' name='listing_copy_$row' title='"._("Copy this entry")."' style='padding:1px'>";
1401 }else{
1402 $result.="<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
1403 }
1404 }
1406 return($result);
1407 }
1410 function renderSnapshotMenu($separator)
1411 {
1412 // We can only provide information if we've got a snapshot handler
1413 // instance
1414 if(!(isset($this->snapshotHandler) && is_object($this->snapshotHandler))){
1415 return "";
1416 }
1418 // Presets
1419 $result = "";
1420 $ui = get_userinfo();
1422 if($this->snapshotHandler->enabled() && $ui->allow_snapshot_restore($this->base, $this->module)){
1424 // Check if there is something to restore
1425 $restore= false;
1426 foreach($this->snapshotHandler->getSnapshotBases() as $base){
1427 $restore= $restore || count($this->snapshotHandler->getDeletedSnapshots($base)) > 0;
1428 }
1430 // Draw icons according to the restore flag
1431 if($restore){
1432 $result.= "<li$separator><a href='#' onClick='document.getElementById(\"actionmenu\").value= \"restore\";document.getElementById(\"exec_act\").click();'><img src='images/lists/restore.png' alt='' border='0' class='center'> "._("Restore snapshots")."</a></li>";
1433 }else{
1434 $result.= "<li$separator><a href='#'><img src='images/lists/restore_grey.png' alt='' border='0' class='center'> "._("Restore snapshots")."</a></li>";
1435 }
1436 }
1438 return($result);
1439 }
1442 function renderExporterMenu($separator)
1443 {
1444 // Presets
1445 $result = "";
1447 // Draw entries
1448 $result.= "<li$separator><a href='#'><img border='0' class='center' src='images/lists/export.png'> "._("Export list")." <img border='0' src='images/forward-arrow.png'></a><ul class='level3'>";
1450 // Export CVS as build in exporter
1451 foreach ($this->exporter as $action => $exporter) {
1452 $result.= "<li><a href='#' onClick='document.getElementById(\"actionmenu\").value= \"$action\";document.getElementById(\"exec_act\").click();'><img border='0' class='center' src='".$exporter['image']."'> ".$exporter['label']."</a></li>";
1453 }
1455 // Finalize list
1456 $result.= "</ul></li>";
1458 return($result);
1459 }
1462 function renderSnapshotActions($row, $dn, $category, $class, $copy= true, $cut= true)
1463 {
1464 // We can only provide information if we've got a snapshot handler
1465 // instance
1466 if(!(isset($this->snapshotHandler) && is_object($this->snapshotHandler))){
1467 return "";
1468 }
1470 // Presets
1471 $result= "";
1472 $ui = get_userinfo();
1474 // Only act if enabled here
1475 if($this->snapshotHandler->enabled()){
1477 // Draw restore button
1478 if ($ui->allow_snapshot_restore($dn, $category)){
1480 // Do we have snapshots for this dn?
1481 if($this->snapshotHandler->hasSnapshots($dn)){
1482 $result.= "<input class='center' type='image' src='images/lists/restore.png' ".
1483 "alt='"._("Restore snapshot")."' name='listing_restore_$row' title='".
1484 _("Restore snapshot")."' style='padding:1px'>";
1485 } else {
1486 $result.= "<img src='images/lists/restore_grey.png' alt=' ' class='center' style='padding:1px'>";
1487 }
1488 }
1490 // Draw snapshot button
1491 if($ui->allow_snapshot_create($dn, $category)){
1492 $result.= "<input class='center' type='image' src='images/snapshot.png' ".
1493 "alt='"._("Create snapshot")."' name='listing_snapshot_$row' title='".
1494 _("Create a new snapshot from this object")."' style='padding:1px'>";
1495 }else{
1496 $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
1497 }
1498 }
1500 return($result);
1501 }
1504 function renderDaemonMenu($separator)
1505 {
1506 $result= "";
1508 // If there is a daemon registered, draw the menu entries
1509 if(class_available("DaemonEvent")){
1510 $events= DaemonEvent::get_event_types_by_category($this->categories);
1511 if(isset($events['BY_CLASS']) && count($events['BY_CLASS'])){
1512 foreach($events['BY_CLASS'] as $name => $event){
1513 $result.= "<li$separator><a href='#' onClick='document.getElementById(\"actionmenu\").value=\"$name\";document.getElementById(\"exec_act\").click();'>".$event['MenuImage']." ".$event['s_Menu_Name']."</a></li>";
1514 $separator= "";
1515 }
1516 }
1517 }
1519 return $result;
1520 }
1523 function getEntry($dn)
1524 {
1525 foreach ($this->entries as $entry) {
1526 if (isset($entry['dn']) && strcasecmp($dn, $entry['dn']) == 0){
1527 return $entry;
1528 }
1529 }
1530 return null;
1531 }
1534 function getType($dn)
1535 {
1536 if (isset($this->objectDnMapping[$dn])) {
1537 return $this->objectDnMapping[$dn];
1538 }
1539 return null;
1540 }
1542 }
1544 ?>