3b83e0811adcc73b06f1a2e398003d61833b6611
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 return ($smarty->fetch(get_template_path($this->xmlData['definition']['template'], true)));
451 }
454 function update()
455 {
456 global $config;
457 $ui= get_userinfo();
459 // Reset object counter / DN mapping
460 $this->objectTypeCount= array();
461 $this->objectDnMapping= array();
463 // Do not do anything if this is not our PID
464 if(isset($_REQUEST['PID']) && $_REQUEST['PID'] != $this->pid) {
465 return;
466 }
468 // Save base
469 if (isset($_POST['BASE']) && $this->baseMode) {
470 $base= get_post('BASE');
471 if (isset($this->bases[$base])) {
472 $this->base= $base;
473 session::global_set("CurrentMainBase", $this->base);
474 }
475 }
477 // Override the base if we got a message from the browser navigation
478 if ($this->departmentBrowser && isset($_GET['act'])) {
479 if (preg_match('/^department_([0-9]+)$/', validate($_GET['act']), $match)){
480 if (isset($this->departments[$match[1]])){
481 $this->base= $this->departments[$match[1]]['dn'];
482 session::global_set("CurrentMainBase", $this->base);
483 }
484 }
485 }
487 // Filter POST with "act" attributes -> posted from action menu
488 if (isset($_POST['exec_act']) && $_POST['act'] != '') {
489 if (preg_match('/^export.*$/', $_POST['act']) && isset($this->exporter[$_POST['act']])) {
490 $exporter= $this->exporter[$_POST['act']];
491 $userinfo= ", "._("created by")." ".$ui->cn." - ".strftime('%A, %d. %B %Y, %H:%M:%S');
492 $entryIterator= new listingSortIterator($this->entries, $this->sortDirection[$this->sortColumn], "_sort".$this->sortColumn, $this->sortType);
493 $sortedEntries= array();
494 foreach ($entryIterator as $entry){
495 $sortedEntries[]= $entry;
496 }
497 $instance= new $exporter['class']($this->headline.$userinfo, $this->plainHeader, $sortedEntries, $this->exportColumns);
498 $type= call_user_func(array($exporter['class'], "getInfo"));
499 $type= $type[$_POST['act']];
500 send_binary_content($instance->query(), $type['filename'], $type= $type['mime']);
501 }
502 }
504 // Filter GET with "act" attributes
505 if (isset($_GET['act'])) {
506 $key= validate($_GET['act']);
507 if (preg_match('/^SORT_([0-9]+)$/', $key, $match)) {
508 // Switch to new column or invert search order?
509 $column= $match[1];
510 if ($this->sortColumn != $column) {
511 $this->sortColumn= $column;
512 } else {
513 $this->sortDirection[$column]= !$this->sortDirection[$column];
514 }
516 // Allow header to update itself according to the new sort settings
517 $this->renderHeader();
518 }
519 }
521 // Override base if we got signals from the navigation elements
522 $action= "";
523 foreach ($_POST as $key => $value) {
524 if (preg_match('/^(ROOT|BACK|HOME)_x$/', $key, $match)) {
525 $action= $match[1];
526 break;
527 }
528 }
530 // Navigation handling
531 if ($action == 'ROOT') {
532 $deps= $ui->get_module_departments($this->module);
533 $this->base= $deps[0];
534 }
535 if ($action == 'BACK') {
536 $deps= $ui->get_module_departments($this->module);
537 $base= preg_replace("/^[^,]+,/", "", $this->base);
538 if(in_array_ics($base, $deps)){
539 $this->base= $base;
540 }
541 }
542 if ($action == 'HOME') {
543 $ui= get_userinfo();
544 $this->base= $this->filter->getObjectBase($ui->dn);
545 }
547 // Reload departments
548 if ($this->departmentBrowser){
549 $this->departments= $this->getDepartments();
550 }
552 // Update filter and refresh entries
553 $this->filter->setBase($this->base);
554 $this->entries= $this->filter->query();
555 }
558 function setBase($base)
559 {
560 $this->base= $base;
561 }
564 function getBase()
565 {
566 return $this->base;
567 }
570 function parseLayout($layout)
571 {
572 $result= array();
573 $layout= preg_replace("/^\|/", "", $layout);
574 $layout= preg_replace("/\|$/", "", $layout);
575 $cols= split("\|", $layout);
577 foreach ($cols as $index => $config) {
578 if ($config != "") {
579 $res= "";
580 $components= split(';', $config);
581 foreach ($components as $part) {
582 if (preg_match("/^r$/", $part)) {
583 $res.= "text-align:right;";
584 continue;
585 }
586 if (preg_match("/^l$/", $part)) {
587 $res.= "text-align:left;";
588 continue;
589 }
590 if (preg_match("/^c$/", $part)) {
591 $res.= "text-align:center;";
592 continue;
593 }
594 if (preg_match("/^[0-9]+(|px|%)$/", $part)) {
595 $res.= "width:$part;min-width:$part;";
596 continue;
597 }
598 }
600 // Add minimum width for scalable columns
601 if (!preg_match('/width:/', $res)){
602 $res.= "min-width:200px;";
603 }
605 $result[$index]= " style='$res' ";
606 } else {
607 $result[$index]= " style='min-width:100px'";
608 }
609 }
611 // Save number of columns for later use
612 $this->numColumns= count($cols);
614 return $result;
615 }
618 function renderCell($data, $config, $row)
619 {
620 // Replace flat attributes in data string
621 for ($i= 0; $i<$config['count']; $i++) {
622 $attr= $config[$i];
623 $value= "";
624 if (is_array($config[$attr])) {
625 $value= $config[$attr][0];
626 } else {
627 $value= $config[$attr];
628 }
629 $data= preg_replace("/%\{$attr\}/", $value, $data);
630 }
632 // Watch out for filters and prepare to execute them
633 $data= $this->processElementFilter($data, $config, $row);
635 // Replace all non replaced %{...} instances because they
636 // are non resolved attributes or filters
637 $data= preg_replace('/%{[^}]+}/', ' ', $data);
639 return $data;
640 }
643 function renderBase()
644 {
645 if (!$this->baseMode) {
646 return;
647 }
649 $result= "<select name='BASE' onChange='mainform.submit()' size='1'>";
650 $firstDN= null;
651 $found= false;
653 foreach ($this->bases as $key=>$value) {
654 // Keep first entry to fall back eventually
655 if(!$firstDN) {
656 $firstDN= $key;
657 }
659 // Prepare to render entry
660 $selected= "";
661 if ($key == $this->base) {
662 $selected= " selected";
663 $found= true;
664 }
665 $key = htmlentities($key,ENT_QUOTES);
666 $result.= "\n<option value=\"".$key."\"$selected>".$value."</option>";
667 }
669 $result.= "</select>";
671 // Reset the currently used base to the first DN we found if there
672 // was no match.
673 if(!$found){
674 $this->base = $firstDN;
675 }
677 return $result;
678 }
681 function processElementFilter($data, $config, $row)
682 {
683 preg_match_all("/%\{filter:([^(]+)\((.*)\)\}/", $data, $matches, PREG_SET_ORDER);
685 foreach ($matches as $match) {
686 $cl= "";
687 $method= "";
688 if (preg_match('/::/', $match[1])) {
689 $cl= preg_replace('/::.*$/', '', $match[1]);
690 $method= preg_replace('/^.*::/', '', $match[1]);
691 } else {
692 if (!isset($this->filters[$match[1]])) {
693 continue;
694 }
695 $cl= preg_replace('/::.*$/', '', $this->filters[$match[1]]);
696 $method= preg_replace('/^.*::/', '', $this->filters[$match[1]]);
697 }
699 // Prepare params for function call
700 $params= array();
701 preg_match_all('/"[^"]+"|[^,]+/', $match[2], $parts);
702 foreach ($parts[0] as $param) {
704 // Row is replaced by the row number
705 if ($param == "row") {
706 $params[]= $row;
707 continue;
708 }
710 // pid is replaced by the current PID
711 if ($param == "pid") {
712 $params[]= $this->pid;
713 continue;
714 }
716 // base is replaced by the current base
717 if ($param == "base") {
718 $params[]= $this->getBase();
719 continue;
720 }
722 // Fixie with "" is passed directly
723 if (preg_match('/^".*"$/', $param)){
724 $params[]= preg_replace('/"/', '', $param);
725 continue;
726 }
728 // Move dn if needed
729 if ($param == "dn") {
730 $params[]= LDAP::fix($config["dn"]);
731 continue;
732 }
734 // LDAP variables get replaced by their objects
735 for ($i= 0; $i<$config['count']; $i++) {
736 if ($param == $config[$i]) {
737 $values= $config[$config[$i]];
738 if (is_array($values)){
739 unset($values['count']);
740 }
741 $params[]= $values;
742 break;
743 }
744 }
745 }
747 // Replace information
748 if ($cl == "listing") {
749 // Non static call - seems to result in errors
750 $data= @preg_replace('/'.preg_quote($match[0]).'/', call_user_func_array(array($this, "$method"), $params), $data);
751 } else {
752 // Static call
753 $data= preg_replace('/'.preg_quote($match[0]).'/', call_user_func_array(array($cl, $method), $params), $data);
754 }
755 }
757 return $data;
758 }
761 function getObjectType($types, $classes)
762 {
763 // Walk thru types and see if there's something matching
764 foreach ($types as $objectType) {
765 $ocs= $objectType['objectClass'];
766 if (!is_array($ocs)){
767 $ocs= array($ocs);
768 }
770 $found= true;
771 foreach ($ocs as $oc){
772 if (preg_match('/^!(.*)$/', $oc, $match)) {
773 $oc= $match[1];
774 if (in_array($oc, $classes)) {
775 $found= false;
776 }
777 } else {
778 if (!in_array($oc, $classes)) {
779 $found= false;
780 }
781 }
782 }
784 if ($found) {
785 return $objectType;
786 }
787 }
789 return null;
790 }
793 function filterObjectType($dn, $classes)
794 {
795 // Walk thru classes and return on first match
796 $result= " ";
798 $objectType= $this->getObjectType($this->objectTypes, $classes);
799 if ($objectType) {
800 $this->objectDnMapping[$dn]= $objectType["objectClass"];
801 $result= "<img class='center' title='".LDAP::fix($dn)."' src='".$objectType["image"]."'>";
802 if (!isset($this->objectTypeCount[$objectType['label']])) {
803 $this->objectTypeCount[$objectType['label']]= 0;
804 }
805 $this->objectTypeCount[$objectType['label']]++;
806 }
808 return $result;
809 }
812 function filterActions($dn, $row, $classes)
813 {
814 // Do nothing if there's no menu defined
815 if (!isset($this->xmlData['actiontriggers']['action'])) {
816 return " ";
817 }
819 // Go thru all actions
820 $result= "";
821 $actions= $this->xmlData['actiontriggers']['action'];
822 foreach($actions as $action) {
823 // Skip the entry completely if there's no permission to execute it
824 if (!$this->hasActionPermission($action, $dn)) {
825 $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
826 continue;
827 }
829 // Skip entry if the pseudo filter does not fit
830 if (isset($action['filter']) && preg_match('/^[a-z0-9_]+!?=[a-z0-9_]+$/i', $action['filter'])) {
831 list($fa, $fv)= split('=', $action['filter']);
832 if (preg_match('/^(.*)!$/', $fa, $m)){
833 $fa= $m[1];
834 if (isset($this->entries[$row][$fa]) && $this->entries[$row][$fa][0] == $fv) {
835 $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
836 continue;
837 }
838 } else {
839 if (!isset($this->entries[$row][$fa]) && !$this->entries[$row][$fa][0] == $fv) {
840 $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
841 continue;
842 }
843 }
844 }
847 // If there's an objectclass definition and we don't have it
848 // add an empty picture here.
849 if (isset($action['objectclass'])){
850 $objectclass= $action['objectclass'];
851 if (preg_match('/^!(.*)$/', $objectclass, $m)){
852 $objectclass= $m[1];
853 if(in_array($objectclass, $classes)) {
854 $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
855 continue;
856 }
857 } else {
858 if(!in_array($objectclass, $classes)) {
859 $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
860 continue;
861 }
862 }
863 }
865 // Render normal entries as usual
866 if ($action['type'] == "entry") {
867 $label= $this->processElementFilter($action['label'], $this->entries[$row], $row);
868 $image= $this->processElementFilter($action['image'], $this->entries[$row], $row);
869 $result.="<input class='center' type='image' src='$image' title='$label' ".
870 "name='listing_".$action['name']."_$row' style='padding:1px'>";
871 }
873 // Handle special types
874 if ($action['type'] == "copypaste" || $action['type'] == "snapshot") {
876 $objectType= $this->getObjectType($this->objectTypes, $this->entries[$row]['objectClass']);
877 $category= $class= null;
878 if ($objectType) {
879 $category= $objectType['category'];
880 $class= $objectType['class'];
881 }
883 if ($action['type'] == "copypaste") {
884 $copy = !isset($action['copy']) || $action['copy'] == "true";
885 $cut = !isset($action['cut']) || $action['cut'] == "true";
886 $result.= $this->renderCopyPasteActions($row, $this->entries[$row]['dn'], $category, $class,$copy,$cut);
887 } else {
888 $result.= $this->renderSnapshotActions($row, $this->entries[$row]['dn'], $category, $class);
889 }
890 }
891 }
893 return $result;
894 }
897 function filterDepartmentLink($row, $dn, $description)
898 {
899 $attr= $this->departments[$row]['sort-attribute'];
900 $name= $this->departments[$row][$attr];
901 if (is_array($name)){
902 $name= $name[0];
903 }
904 $result= sprintf("%s [%s]", $name, $description[0]);
905 return("<a href='?plug=".$_GET['plug']."&PID=$this->pid&act=department_$row' title='$dn'>$result</a>");
906 }
909 function filterLink()
910 {
911 $result= " ";
913 $row= func_get_arg(0);
914 $pid= $this->pid;
915 $dn= LDAP::fix(func_get_arg(1));
916 $params= array(func_get_arg(2));
918 // Collect sprintf params
919 for ($i = 3;$i < func_num_args();$i++) {
920 $val= func_get_arg($i);
921 if (is_array($val)){
922 $params[]= $val[0];
923 continue;
924 }
925 $params[]= $val;
926 }
928 $result= " ";
929 $trans= call_user_func_array("sprintf", $params);
930 if ($trans != "") {
931 return("<a href='?plug=".$_GET['plug']."&PID=$pid&act=listing_edit_$row' title='$dn'>$trans</a>");
932 }
934 return $result;
935 }
938 function renderNavigation()
939 {
940 $result= array();
941 $enableBack = true;
942 $enableRoot = true;
943 $enableHome = true;
945 $ui = get_userinfo();
947 /* Check if base = first available base */
948 $deps = $ui->get_module_departments($this->module);
950 if(!count($deps) || $deps[0] == $this->filter->base){
951 $enableBack = false;
952 $enableRoot = false;
953 }
955 $listhead ="";
957 /* Check if we are in users home department */
958 if(!count($deps) || $this->filter->base == $this->filter->getObjectBase($ui->dn)){
959 $enableHome = false;
960 }
962 /* Draw root button */
963 if($enableRoot){
964 $result["ROOT"]= "<input class='center' type='image' src='images/lists/root.png' align='middle' ".
965 "title='"._("Go to root department")."' name='ROOT' alt='"._("Root")."'>";
966 }else{
967 $result["ROOT"]= "<img src='images/lists/root_grey.png' class='center' alt='"._("Root")."'>";
968 }
970 /* Draw back button */
971 if($enableBack){
972 $result["BACK"]= "<input class='center' type='image' align='middle' src='images/lists/back.png' ".
973 "title='"._("Go up one department")."' alt='"._("Up")."' name='BACK'>";
974 }else{
975 $result["BACK"]= "<img src='images/lists/back_grey.png' class='center' alt='"._("Up")."'>";
976 }
978 /* Draw home button */
979 if($enableHome){
980 $result["HOME"]= "<input class='center' type='image' align='middle' src='images/lists/home.png' ".
981 "title='"._("Go to users department")."' alt='"._("Home")."' name='HOME'>";
982 }else{
983 $result["HOME"]= "<img src='images/lists/home_grey.png' class='center' alt='"._("Home")."'>";
984 }
986 /* Draw reload button, this button is enabled everytime */
987 $result["RELOAD"]= "<input class='center' type='image' src='images/lists/reload.png' align='middle' ".
988 "title='"._("Reload list")."' name='REFRESH' alt='"._("Submit")."'>";
990 return ($result);
991 }
994 function getAction()
995 {
996 // Do not do anything if this is not our PID, or there's even no PID available...
997 if(!isset($_REQUEST['PID']) || $_REQUEST['PID'] != $this->pid) {
998 return;
999 }
1001 $result= array("targets" => array(), "action" => "");
1003 // Filter GET with "act" attributes
1004 if (isset($_GET['act'])) {
1005 $key= validate($_GET['act']);
1006 $target= preg_replace('/^listing_[a-zA-Z_]+_([0-9]+)$/', '$1', $key);
1007 if (isset($this->entries[$target]['dn'])) {
1008 $result['action']= preg_replace('/^listing_([a-zA-Z_]+)_[0-9]+$/', '$1', $key);
1009 $result['targets'][]= $this->entries[$target]['dn'];
1010 }
1012 // Drop targets if empty
1013 if (count($result['targets']) == 0) {
1014 unset($result['targets']);
1015 }
1016 return $result;
1017 }
1019 // Filter POST with "listing_" attributes
1020 foreach ($_POST as $key => $prop) {
1022 // Capture selections
1023 if (preg_match('/^listing_selected_[0-9]+$/', $key)) {
1024 $target= preg_replace('/^listing_selected_([0-9]+)$/', '$1', $key);
1025 if (isset($this->entries[$target]['dn'])) {
1026 $result['targets'][]= $this->entries[$target]['dn'];
1027 }
1028 continue;
1029 }
1031 // Capture action with target - this is a one shot
1032 if (preg_match('/^listing_[a-zA-Z_]+_[0-9]+(|_x)$/', $key)) {
1033 $target= preg_replace('/^listing_[a-zA-Z_]+_([0-9]+)(|_x)$/', '$1', $key);
1034 if (isset($this->entries[$target]['dn'])) {
1035 $result['action']= preg_replace('/^listing_([a-zA-Z_]+)_[0-9]+(|_x)$/', '$1', $key);
1036 $result['targets']= array($this->entries[$target]['dn']);
1037 }
1038 break;
1039 }
1041 // Capture action without target
1042 if (preg_match('/^listing_[a-zA-Z_]+(|_x)$/', $key)) {
1043 $result['action']= preg_replace('/^listing_([a-zA-Z_]+)(|_x)$/', '$1', $key);
1044 continue;
1045 }
1046 }
1048 // Filter POST with "act" attributes -> posted from action menu
1049 if (isset($_POST['act']) && $_POST['act'] != '') {
1050 if (!preg_match('/^export.*$/', $_POST['act'])){
1051 $result['action']= validate($_POST['act']);
1052 }
1053 }
1055 // Drop targets if empty
1056 if (count($result['targets']) == 0) {
1057 unset($result['targets']);
1058 }
1059 return $result;
1060 }
1063 function renderActionMenu()
1064 {
1065 // Don't send anything if the menu is not defined
1066 if (!isset($this->xmlData['actionmenu']['action'])){
1067 return "";
1068 }
1070 // Array?
1071 if (isset($this->xmlData['actionmenu']['action']['type'])){
1072 $this->xmlData['actionmenu']['action']= array($this->xmlData['actionmenu']['action']);
1073 }
1075 // Load shortcut
1076 $actions= &$this->xmlData['actionmenu']['action'];
1077 $result= "<input type='hidden' name='act' id='actionmenu' value=''><div style='display:none'><input type='submit' name='exec_act' id='exec_act' value=''></div>".
1078 "<ul class='level1' id='root'><li><a href='#'>"._("Actions")." <img ".
1079 "border=0 class='center' src='images/lists/sort-down.png'></a>";
1081 // Build ul/li list
1082 $result.= $this->recurseActions($actions);
1084 return "<div id='pulldown'>".$result."</li></ul><div>";
1085 }
1088 function recurseActions($actions)
1089 {
1090 global $class_mapping;
1091 static $level= 2;
1092 $result= "<ul class='level$level'>";
1093 $separator= "";
1095 foreach ($actions as $action) {
1097 // Skip the entry completely if there's no permission to execute it
1098 if (!$this->hasActionPermission($action, $this->filter->base)) {
1099 continue;
1100 }
1102 // Skip entry if there're missing dependencies
1103 if (isset($action['depends'])) {
1104 $deps= is_array($action['depends'])?$action['depends']:array($action['depends']);
1105 foreach($deps as $clazz) {
1106 if (!isset($class_mapping[$clazz])){
1107 continue 2;
1108 }
1109 }
1110 }
1112 // Fill image if set
1113 $img= "";
1114 if (isset($action['image'])){
1115 $img= "<img border='0' class='center' src='".$action['image']."'> ";
1116 }
1118 if ($action['type'] == "separator"){
1119 $separator= " style='border-top:1px solid #AAA' ";
1120 continue;
1121 }
1123 // Dive into subs
1124 if ($action['type'] == "sub" && isset($action['action'])) {
1125 $level++;
1126 if (isset($action['label'])){
1127 $result.= "<li$separator><a href='#'>$img"._($action['label'])." <img border='0' src='images/forward-arrow.png'></a>";
1128 }
1130 // Ensure we've an array of actions, this enables sub menus with only one action.
1131 if(isset($action['action']['type'])){
1132 $action['action'] = array($action['action']);
1133 }
1135 $result.= $this->recurseActions($action['action'])."</li>";
1136 $level--;
1137 $separator= "";
1138 continue;
1139 }
1141 // Render entry elseways
1142 if (isset($action['label'])){
1143 $result.= "<li$separator><a href='#' onClick='document.getElementById(\"actionmenu\").value= \"".$action['name']."\";mainform.submit();'>$img"._($action['label'])."</a></li>";
1144 }
1146 // Check for special types
1147 switch ($action['type']) {
1148 case 'copypaste':
1149 $cut = !isset($action['cut']) || $action['cut'] != "false";
1150 $copy = !isset($action['copy']) || $action['copy'] != "false";
1151 $result.= $this->renderCopyPasteMenu($separator, $copy , $cut);
1152 break;
1154 case 'snapshot':
1155 $result.= $this->renderSnapshotMenu($separator);
1156 break;
1158 case 'exporter':
1159 $result.= $this->renderExporterMenu($separator);
1160 break;
1162 case 'daemon':
1163 $result.= $this->renderDaemonMenu($separator);
1164 break;
1165 }
1167 $separator= "";
1168 }
1170 $result.= "</ul>";
1171 return $result;
1172 }
1175 function hasActionPermission($action, $dn)
1176 {
1177 $ui= get_userinfo();
1179 if (isset($action['acl'])) {
1180 $acls= $action['acl'];
1181 if (!is_array($acls)) {
1182 $acls= array($acls);
1183 }
1185 // Every ACL has to pass
1186 foreach ($acls as $acl) {
1187 $module= $this->module;
1188 $aclList= array();
1190 // Split for category and plugins if needed
1191 // match for "[rw]" style entries
1192 if (preg_match('/^\[([rwcdm]+)\]$/', $acl, $match)){
1193 $aclList= array($match[1]);
1194 }
1196 // match for "users[rw]" style entries
1197 if (preg_match('/^([a-zA-Z0-9]+)\[([rwcdm]+)\]$/', $acl, $match)){
1198 $module= $match[1];
1199 $aclList= array($match[2]);
1200 }
1202 // match for "users/user[rw]" style entries
1203 if (preg_match('/^([a-zA-Z0-9]+\/[a-zA-Z0-9]+)\[([rwcdm]+)\]$/', $acl, $match)){
1204 $module= $match[1];
1205 $aclList= array($match[2]);
1206 }
1208 // match "users/user[userPassword:rw(,...)*]" style entries
1209 if (preg_match('/^([a-zA-Z0-9]+\/[a-zA-Z0-9]+)\[([a-zA-Z0-9]+:[rwcdm]+(,[a-zA-Z0-9]+:[rwcdm]+)*)\]$/', $acl, $match)){
1210 $module= $match[1];
1211 $aclList= split(',', $match[2]);
1212 }
1214 // Walk thru prepared ACL by using $module
1215 foreach($aclList as $sAcl) {
1216 $checkAcl= "";
1218 // Category or detailed permission?
1219 if (strpos('/', $module) === false) {
1220 if (preg_match('/([a-zA-Z0-9]+):([rwcdm]+)/', $sAcl, $m) ) {
1221 $checkAcl= $ui->get_permissions($dn, $module, $m[1]);
1222 $sAcl= $m[2];
1223 } else {
1224 $checkAcl= $ui->get_permissions($dn, $module, '0');
1225 }
1226 } else {
1227 $checkAcl= $ui->get_category_permissions($dn, $module);
1228 }
1230 // Split up remaining part of the acl and check if it we're
1231 // allowed to do something...
1232 $parts= str_split($sAcl);
1233 foreach ($parts as $part) {
1234 if (strpos($checkAcl, $part) === false){
1235 return false;
1236 }
1237 }
1239 }
1240 }
1241 }
1243 return true;
1244 }
1247 function refreshBasesList()
1248 {
1249 global $config;
1250 $ui= get_userinfo();
1252 // Do some array munching to get it user friendly
1253 $ids= $config->idepartments;
1254 $d= $ui->get_module_departments($this->module);
1255 $k_ids= array_keys($ids);
1256 $deps= array_intersect($d,$k_ids);
1258 // Fill internal bases list
1259 $this->bases= array();
1260 foreach($k_ids as $department){
1261 $this->bases[$department] = $ids[$department];
1262 }
1263 }
1266 function getDepartments()
1267 {
1268 $departments= array();
1269 $ui= get_userinfo();
1271 // Get list of supported department types
1272 $types = departmentManagement::get_support_departments();
1274 // Load departments allowed by ACL
1275 $validDepartments = $ui->get_module_departments($this->module);
1277 // Build filter and look in the LDAP for possible sub departments
1278 // of current base
1279 $filter= "(&(objectClass=gosaDepartment)(|";
1280 $attrs= array("description", "objectClass");
1281 foreach($types as $name => $data){
1282 $filter.= "(objectClass=".$data['OC'].")";
1283 $attrs[]= $data['ATTR'];
1284 }
1285 $filter.= "))";
1286 $res= get_list($filter, $this->module, $this->base, $attrs, GL_NONE);
1288 // Analyze list of departments
1289 foreach ($res as $department) {
1290 if (!in_array($department['dn'], $validDepartments)) {
1291 continue;
1292 }
1294 // Add the attribute where we use for sorting
1295 $oc= null;
1296 foreach(array_keys($types) as $type) {
1297 if (in_array($type, $department['objectClass'])) {
1298 $oc= $type;
1299 break;
1300 }
1301 }
1302 $department['sort-attribute']= $types[$oc]['ATTR'];
1304 // Move to the result list
1305 $departments[]= $department;
1306 }
1308 return $departments;
1309 }
1312 function renderCopyPasteMenu($separator, $copy= true, $cut= true)
1313 {
1314 // We can only provide information if we've got a copypaste handler
1315 // instance
1316 if(!(isset($this->copyPasteHandler) && is_object($this->copyPasteHandler))){
1317 return "";
1318 }
1320 // Presets
1321 $result= "";
1322 $read= $paste= false;
1323 $ui= get_userinfo();
1325 // Switch flags to on if there's at least one category which allows read/paste
1326 foreach($this->categories as $category){
1327 $read= $read || preg_match('/r/', $ui->get_category_permissions($this->base, $category));
1328 $paste= $paste || $ui->is_pasteable($this->base, $category) == 1;
1329 }
1332 // Draw entries that allow copy and cut
1333 if($read){
1335 // Copy entry
1336 if($copy){
1337 $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>";
1338 $separator= "";
1339 }
1341 // Cut entry
1342 if($cut){
1343 $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>";
1344 $separator= "";
1345 }
1346 }
1348 // Draw entries that allow pasting entries
1349 if($paste){
1350 if($this->copyPasteHandler->entries_queued()){
1351 $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>";
1352 }else{
1353 $result.= "<li$separator><a href='#'><img src='images/lists/paste-grey.png' alt='' border='0' class='center'> "._("Paste")."</a></li>";
1354 }
1355 }
1357 return($result);
1358 }
1361 function renderCopyPasteActions($row, $dn, $category, $class, $copy= true, $cut= true)
1362 {
1363 // We can only provide information if we've got a copypaste handler
1364 // instance
1365 if(!(isset($this->copyPasteHandler) && is_object($this->copyPasteHandler))){
1366 return "";
1367 }
1369 // Presets
1370 $ui = get_userinfo();
1371 $result = "";
1373 // Render cut entries
1374 if($cut){
1375 if($ui->is_cutable($dn, $category, $class)){
1376 $result .= "<input class='center' type='image'
1377 src='images/lists/cut.png' alt='"._("Cut")."' name='listing_cut_$row' title='"._("Cut this entry")."' style='padding:1px'>";
1378 }else{
1379 $result.="<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
1380 }
1381 }
1383 // Render copy entries
1384 if($copy){
1385 if($ui->is_copyable($dn, $category, $class)){
1386 $result.= "<input class='center' type='image'
1387 src='images/lists/copy.png' alt='"._("Copy")."' name='listing_copy_$row' title='"._("Copy this entry")."' style='padding:1px'>";
1388 }else{
1389 $result.="<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
1390 }
1391 }
1393 return($result);
1394 }
1397 function renderSnapshotMenu($separator)
1398 {
1399 // We can only provide information if we've got a snapshot handler
1400 // instance
1401 if(!(isset($this->snapshotHandler) && is_object($this->snapshotHandler))){
1402 return "";
1403 }
1405 // Presets
1406 $result = "";
1407 $ui = get_userinfo();
1409 if($this->snapshotHandler->enabled() && $ui->allow_snapshot_restore($this->base, $this->module)){
1411 // Check if there is something to restore
1412 $restore= false;
1413 foreach($this->snapshotHandler->getSnapshotBases() as $base){
1414 $restore= $restore || count($this->snapshotHandler->getDeletedSnapshots($base)) > 0;
1415 }
1417 // Draw icons according to the restore flag
1418 if($restore){
1419 $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>";
1420 }else{
1421 $result.= "<li$separator><a href='#'><img src='images/lists/restore_grey.png' alt='' border='0' class='center'> "._("Restore snapshots")."</a></li>";
1422 }
1423 }
1425 return($result);
1426 }
1429 function renderExporterMenu($separator)
1430 {
1431 // Presets
1432 $result = "";
1434 // Draw entries
1435 $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'>";
1437 // Export CVS as build in exporter
1438 foreach ($this->exporter as $action => $exporter) {
1439 $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>";
1440 }
1442 // Finalize list
1443 $result.= "</ul></li>";
1445 return($result);
1446 }
1449 function renderSnapshotActions($row, $dn, $category, $class, $copy= true, $cut= true)
1450 {
1451 // We can only provide information if we've got a snapshot handler
1452 // instance
1453 if(!(isset($this->snapshotHandler) && is_object($this->snapshotHandler))){
1454 return "";
1455 }
1457 // Presets
1458 $result= "";
1459 $ui = get_userinfo();
1461 // Only act if enabled here
1462 if($this->snapshotHandler->enabled()){
1464 // Draw restore button
1465 if ($ui->allow_snapshot_restore($dn, $category)){
1467 // Do we have snapshots for this dn?
1468 if($this->snapshotHandler->hasSnapshots($dn)){
1469 $result.= "<input class='center' type='image' src='images/lists/restore.png' ".
1470 "alt='"._("Restore snapshot")."' name='listing_restore_$row' title='".
1471 _("Restore snapshot")."' style='padding:1px'>";
1472 } else {
1473 $result.= "<img src='images/lists/restore_grey.png' alt=' ' class='center' style='padding:1px'>";
1474 }
1475 }
1477 // Draw snapshot button
1478 if($ui->allow_snapshot_create($dn, $category)){
1479 $result.= "<input class='center' type='image' src='images/snapshot.png' ".
1480 "alt='"._("Create snapshot")."' name='listing_snapshot_$row' title='".
1481 _("Create a new snapshot from this object")."' style='padding:1px'>";
1482 }else{
1483 $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
1484 }
1485 }
1487 return($result);
1488 }
1491 function renderDaemonMenu($separator)
1492 {
1493 $result= "";
1495 // If there is a daemon registered, draw the menu entries
1496 if(class_available("DaemonEvent")){
1497 $events= DaemonEvent::get_event_types_by_category($this->categories);
1498 if(isset($events['BY_CLASS']) && count($events['BY_CLASS'])){
1499 foreach($events['BY_CLASS'] as $name => $event){
1500 $result.= "<li$separator><a href='#' onClick='document.getElementById(\"actionmenu\").value=\"$name\";document.getElementById(\"exec_act\").click();'>".$event['MenuImage']." ".$event['s_Menu_Name']."</a></li>";
1501 $separator= "";
1502 }
1503 }
1504 }
1506 return $result;
1507 }
1510 function getEntry($dn)
1511 {
1512 foreach ($this->entries as $entry) {
1513 if (isset($entry['dn']) && strcasecmp($dn, $entry['dn']) == 0){
1514 return $entry;
1515 }
1516 }
1517 return null;
1518 }
1521 function getType($dn)
1522 {
1523 if (isset($this->objectDnMapping[$dn])) {
1524 return $this->objectDnMapping[$dn];
1525 }
1526 return null;
1527 }
1529 }
1531 ?>