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 } elseif (is_string($objectclass)) {
858 if(!in_array($objectclass, $classes)) {
859 $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
860 continue;
861 }
862 } elseif (is_array($objectclass)) {
863 if(count(array_intersect($objectclass, $classes)) != count($objectclass)){
864 $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
865 continue;
866 }
867 }
868 }
870 // Render normal entries as usual
871 if ($action['type'] == "entry") {
872 $label= $this->processElementFilter($action['label'], $this->entries[$row], $row);
873 $image= $this->processElementFilter($action['image'], $this->entries[$row], $row);
874 $result.="<input class='center' type='image' src='$image' title='$label' ".
875 "name='listing_".$action['name']."_$row' style='padding:1px'>";
876 }
878 // Handle special types
879 if ($action['type'] == "copypaste" || $action['type'] == "snapshot") {
881 $objectType= $this->getObjectType($this->objectTypes, $this->entries[$row]['objectClass']);
882 $category= $class= null;
883 if ($objectType) {
884 $category= $objectType['category'];
885 $class= $objectType['class'];
886 }
888 if ($action['type'] == "copypaste") {
889 $copy = !isset($action['copy']) || $action['copy'] == "true";
890 $cut = !isset($action['cut']) || $action['cut'] == "true";
891 $result.= $this->renderCopyPasteActions($row, $this->entries[$row]['dn'], $category, $class,$copy,$cut);
892 } else {
893 $result.= $this->renderSnapshotActions($row, $this->entries[$row]['dn'], $category, $class);
894 }
895 }
896 }
898 return $result;
899 }
902 function filterDepartmentLink($row, $dn, $description)
903 {
904 $attr= $this->departments[$row]['sort-attribute'];
905 $name= $this->departments[$row][$attr];
906 if (is_array($name)){
907 $name= $name[0];
908 }
909 $result= sprintf("%s [%s]", $name, $description[0]);
910 return("<a href='?plug=".$_GET['plug']."&PID=$this->pid&act=department_$row' title='$dn'>$result</a>");
911 }
914 function filterLink()
915 {
916 $result= " ";
918 $row= func_get_arg(0);
919 $pid= $this->pid;
920 $dn= LDAP::fix(func_get_arg(1));
921 $params= array(func_get_arg(2));
923 // Collect sprintf params
924 for ($i = 3;$i < func_num_args();$i++) {
925 $val= func_get_arg($i);
926 if (is_array($val)){
927 $params[]= $val[0];
928 continue;
929 }
930 $params[]= $val;
931 }
933 $result= " ";
934 $trans= call_user_func_array("sprintf", $params);
935 if ($trans != "") {
936 return("<a href='?plug=".$_GET['plug']."&PID=$pid&act=listing_edit_$row' title='$dn'>$trans</a>");
937 }
939 return $result;
940 }
943 function renderNavigation()
944 {
945 $result= array();
946 $enableBack = true;
947 $enableRoot = true;
948 $enableHome = true;
950 $ui = get_userinfo();
952 /* Check if base = first available base */
953 $deps = $ui->get_module_departments($this->module);
955 if(!count($deps) || $deps[0] == $this->filter->base){
956 $enableBack = false;
957 $enableRoot = false;
958 }
960 $listhead ="";
962 /* Check if we are in users home department */
963 if(!count($deps) || $this->filter->base == $this->filter->getObjectBase($ui->dn)){
964 $enableHome = false;
965 }
967 /* Draw root button */
968 if($enableRoot){
969 $result["ROOT"]= "<input class='center' type='image' src='images/lists/root.png' align='middle' ".
970 "title='"._("Go to root department")."' name='ROOT' alt='"._("Root")."'>";
971 }else{
972 $result["ROOT"]= "<img src='images/lists/root_grey.png' class='center' alt='"._("Root")."'>";
973 }
975 /* Draw back button */
976 if($enableBack){
977 $result["BACK"]= "<input class='center' type='image' align='middle' src='images/lists/back.png' ".
978 "title='"._("Go up one department")."' alt='"._("Up")."' name='BACK'>";
979 }else{
980 $result["BACK"]= "<img src='images/lists/back_grey.png' class='center' alt='"._("Up")."'>";
981 }
983 /* Draw home button */
984 if($enableHome){
985 $result["HOME"]= "<input class='center' type='image' align='middle' src='images/lists/home.png' ".
986 "title='"._("Go to users department")."' alt='"._("Home")."' name='HOME'>";
987 }else{
988 $result["HOME"]= "<img src='images/lists/home_grey.png' class='center' alt='"._("Home")."'>";
989 }
991 /* Draw reload button, this button is enabled everytime */
992 $result["RELOAD"]= "<input class='center' type='image' src='images/lists/reload.png' align='middle' ".
993 "title='"._("Reload list")."' name='REFRESH' alt='"._("Submit")."'>";
995 return ($result);
996 }
999 function getAction()
1000 {
1001 // Do not do anything if this is not our PID, or there's even no PID available...
1002 if(!isset($_REQUEST['PID']) || $_REQUEST['PID'] != $this->pid) {
1003 return;
1004 }
1006 $result= array("targets" => array(), "action" => "");
1008 // Filter GET with "act" attributes
1009 if (isset($_GET['act'])) {
1010 $key= validate($_GET['act']);
1011 $target= preg_replace('/^listing_[a-zA-Z_]+_([0-9]+)$/', '$1', $key);
1012 if (isset($this->entries[$target]['dn'])) {
1013 $result['action']= preg_replace('/^listing_([a-zA-Z_]+)_[0-9]+$/', '$1', $key);
1014 $result['targets'][]= $this->entries[$target]['dn'];
1015 }
1017 // Drop targets if empty
1018 if (count($result['targets']) == 0) {
1019 unset($result['targets']);
1020 }
1021 return $result;
1022 }
1024 // Filter POST with "listing_" attributes
1025 foreach ($_POST as $key => $prop) {
1027 // Capture selections
1028 if (preg_match('/^listing_selected_[0-9]+$/', $key)) {
1029 $target= preg_replace('/^listing_selected_([0-9]+)$/', '$1', $key);
1030 if (isset($this->entries[$target]['dn'])) {
1031 $result['targets'][]= $this->entries[$target]['dn'];
1032 }
1033 continue;
1034 }
1036 // Capture action with target - this is a one shot
1037 if (preg_match('/^listing_[a-zA-Z_]+_[0-9]+(|_x)$/', $key)) {
1038 $target= preg_replace('/^listing_[a-zA-Z_]+_([0-9]+)(|_x)$/', '$1', $key);
1039 if (isset($this->entries[$target]['dn'])) {
1040 $result['action']= preg_replace('/^listing_([a-zA-Z_]+)_[0-9]+(|_x)$/', '$1', $key);
1041 $result['targets']= array($this->entries[$target]['dn']);
1042 }
1043 break;
1044 }
1046 // Capture action without target
1047 if (preg_match('/^listing_[a-zA-Z_]+(|_x)$/', $key)) {
1048 $result['action']= preg_replace('/^listing_([a-zA-Z_]+)(|_x)$/', '$1', $key);
1049 continue;
1050 }
1051 }
1053 // Filter POST with "act" attributes -> posted from action menu
1054 if (isset($_POST['act']) && $_POST['act'] != '') {
1055 if (!preg_match('/^export.*$/', $_POST['act'])){
1056 $result['action']= validate($_POST['act']);
1057 }
1058 }
1060 // Drop targets if empty
1061 if (count($result['targets']) == 0) {
1062 unset($result['targets']);
1063 }
1064 return $result;
1065 }
1068 function renderActionMenu()
1069 {
1070 // Don't send anything if the menu is not defined
1071 if (!isset($this->xmlData['actionmenu']['action'])){
1072 return "";
1073 }
1075 // Array?
1076 if (isset($this->xmlData['actionmenu']['action']['type'])){
1077 $this->xmlData['actionmenu']['action']= array($this->xmlData['actionmenu']['action']);
1078 }
1080 // Load shortcut
1081 $actions= &$this->xmlData['actionmenu']['action'];
1082 $result= "<input type='hidden' name='act' id='actionmenu' value=''><div style='display:none'><input type='submit' name='exec_act' id='exec_act' value=''></div>".
1083 "<ul class='level1' id='root'><li><a href='#'>"._("Actions")." <img ".
1084 "border=0 class='center' src='images/lists/sort-down.png'></a>";
1086 // Build ul/li list
1087 $result.= $this->recurseActions($actions);
1089 return "<div id='pulldown'>".$result."</li></ul><div>";
1090 }
1093 function recurseActions($actions)
1094 {
1095 global $class_mapping;
1096 static $level= 2;
1097 $result= "<ul class='level$level'>";
1098 $separator= "";
1100 foreach ($actions as $action) {
1102 // Skip the entry completely if there's no permission to execute it
1103 if (!$this->hasActionPermission($action, $this->filter->base)) {
1104 continue;
1105 }
1107 // Skip entry if there're missing dependencies
1108 if (isset($action['depends'])) {
1109 $deps= is_array($action['depends'])?$action['depends']:array($action['depends']);
1110 foreach($deps as $clazz) {
1111 if (!isset($class_mapping[$clazz])){
1112 continue 2;
1113 }
1114 }
1115 }
1117 // Fill image if set
1118 $img= "";
1119 if (isset($action['image'])){
1120 $img= "<img border='0' class='center' src='".$action['image']."'> ";
1121 }
1123 if ($action['type'] == "separator"){
1124 $separator= " style='border-top:1px solid #AAA' ";
1125 continue;
1126 }
1128 // Dive into subs
1129 if ($action['type'] == "sub" && isset($action['action'])) {
1130 $level++;
1131 if (isset($action['label'])){
1132 $result.= "<li$separator><a href='#'>$img"._($action['label'])." <img border='0' src='images/forward-arrow.png'></a>";
1133 }
1135 // Ensure we've an array of actions, this enables sub menus with only one action.
1136 if(isset($action['action']['type'])){
1137 $action['action'] = array($action['action']);
1138 }
1140 $result.= $this->recurseActions($action['action'])."</li>";
1141 $level--;
1142 $separator= "";
1143 continue;
1144 }
1146 // Render entry elseways
1147 if (isset($action['label'])){
1148 $result.= "<li$separator><a href='#' onClick='document.getElementById(\"actionmenu\").value= \"".$action['name']."\";mainform.submit();'>$img"._($action['label'])."</a></li>";
1149 }
1151 // Check for special types
1152 switch ($action['type']) {
1153 case 'copypaste':
1154 $cut = !isset($action['cut']) || $action['cut'] != "false";
1155 $copy = !isset($action['copy']) || $action['copy'] != "false";
1156 $result.= $this->renderCopyPasteMenu($separator, $copy , $cut);
1157 break;
1159 case 'snapshot':
1160 $result.= $this->renderSnapshotMenu($separator);
1161 break;
1163 case 'exporter':
1164 $result.= $this->renderExporterMenu($separator);
1165 break;
1167 case 'daemon':
1168 $result.= $this->renderDaemonMenu($separator);
1169 break;
1170 }
1172 $separator= "";
1173 }
1175 $result.= "</ul>";
1176 return $result;
1177 }
1180 function hasActionPermission($action, $dn)
1181 {
1182 $ui= get_userinfo();
1184 if (isset($action['acl'])) {
1185 $acls= $action['acl'];
1186 if (!is_array($acls)) {
1187 $acls= array($acls);
1188 }
1190 // Every ACL has to pass
1191 foreach ($acls as $acl) {
1192 $module= $this->module;
1193 $aclList= array();
1195 // Split for category and plugins if needed
1196 // match for "[rw]" style entries
1197 if (preg_match('/^\[([rwcdm]+)\]$/', $acl, $match)){
1198 $aclList= array($match[1]);
1199 }
1201 // match for "users[rw]" style entries
1202 if (preg_match('/^([a-zA-Z0-9]+)\[([rwcdm]+)\]$/', $acl, $match)){
1203 $module= $match[1];
1204 $aclList= array($match[2]);
1205 }
1207 // match for "users/user[rw]" style entries
1208 if (preg_match('/^([a-zA-Z0-9]+\/[a-zA-Z0-9]+)\[([rwcdm]+)\]$/', $acl, $match)){
1209 $module= $match[1];
1210 $aclList= array($match[2]);
1211 }
1213 // match "users/user[userPassword:rw(,...)*]" style entries
1214 if (preg_match('/^([a-zA-Z0-9]+\/[a-zA-Z0-9]+)\[([a-zA-Z0-9]+:[rwcdm]+(,[a-zA-Z0-9]+:[rwcdm]+)*)\]$/', $acl, $match)){
1215 $module= $match[1];
1216 $aclList= split(',', $match[2]);
1217 }
1219 // Walk thru prepared ACL by using $module
1220 foreach($aclList as $sAcl) {
1221 $checkAcl= "";
1223 // Category or detailed permission?
1224 if (strpos('/', $module) === false) {
1225 if (preg_match('/([a-zA-Z0-9]+):([rwcdm]+)/', $sAcl, $m) ) {
1226 $checkAcl= $ui->get_permissions($dn, $module, $m[1]);
1227 $sAcl= $m[2];
1228 } else {
1229 $checkAcl= $ui->get_permissions($dn, $module, '0');
1230 }
1231 } else {
1232 $checkAcl= $ui->get_category_permissions($dn, $module);
1233 }
1235 // Split up remaining part of the acl and check if it we're
1236 // allowed to do something...
1237 $parts= str_split($sAcl);
1238 foreach ($parts as $part) {
1239 if (strpos($checkAcl, $part) === false){
1240 return false;
1241 }
1242 }
1244 }
1245 }
1246 }
1248 return true;
1249 }
1252 function refreshBasesList()
1253 {
1254 global $config;
1255 $ui= get_userinfo();
1257 // Do some array munching to get it user friendly
1258 $ids= $config->idepartments;
1259 $d= $ui->get_module_departments($this->module);
1260 $k_ids= array_keys($ids);
1261 $deps= array_intersect($d,$k_ids);
1263 // Fill internal bases list
1264 $this->bases= array();
1265 foreach($k_ids as $department){
1266 $this->bases[$department] = $ids[$department];
1267 }
1268 }
1271 function getDepartments()
1272 {
1273 $departments= array();
1274 $ui= get_userinfo();
1276 // Get list of supported department types
1277 $types = departmentManagement::get_support_departments();
1279 // Load departments allowed by ACL
1280 $validDepartments = $ui->get_module_departments($this->module);
1282 // Build filter and look in the LDAP for possible sub departments
1283 // of current base
1284 $filter= "(&(objectClass=gosaDepartment)(|";
1285 $attrs= array("description", "objectClass");
1286 foreach($types as $name => $data){
1287 $filter.= "(objectClass=".$data['OC'].")";
1288 $attrs[]= $data['ATTR'];
1289 }
1290 $filter.= "))";
1291 $res= get_list($filter, $this->module, $this->base, $attrs, GL_NONE);
1293 // Analyze list of departments
1294 foreach ($res as $department) {
1295 if (!in_array($department['dn'], $validDepartments)) {
1296 continue;
1297 }
1299 // Add the attribute where we use for sorting
1300 $oc= null;
1301 foreach(array_keys($types) as $type) {
1302 if (in_array($type, $department['objectClass'])) {
1303 $oc= $type;
1304 break;
1305 }
1306 }
1307 $department['sort-attribute']= $types[$oc]['ATTR'];
1309 // Move to the result list
1310 $departments[]= $department;
1311 }
1313 return $departments;
1314 }
1317 function renderCopyPasteMenu($separator, $copy= true, $cut= true)
1318 {
1319 // We can only provide information if we've got a copypaste handler
1320 // instance
1321 if(!(isset($this->copyPasteHandler) && is_object($this->copyPasteHandler))){
1322 return "";
1323 }
1325 // Presets
1326 $result= "";
1327 $read= $paste= false;
1328 $ui= get_userinfo();
1330 // Switch flags to on if there's at least one category which allows read/paste
1331 foreach($this->categories as $category){
1332 $read= $read || preg_match('/r/', $ui->get_category_permissions($this->base, $category));
1333 $paste= $paste || $ui->is_pasteable($this->base, $category) == 1;
1334 }
1337 // Draw entries that allow copy and cut
1338 if($read){
1340 // Copy entry
1341 if($copy){
1342 $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>";
1343 $separator= "";
1344 }
1346 // Cut entry
1347 if($cut){
1348 $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>";
1349 $separator= "";
1350 }
1351 }
1353 // Draw entries that allow pasting entries
1354 if($paste){
1355 if($this->copyPasteHandler->entries_queued()){
1356 $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>";
1357 }else{
1358 $result.= "<li$separator><a href='#'><img src='images/lists/paste-grey.png' alt='' border='0' class='center'> "._("Paste")."</a></li>";
1359 }
1360 }
1362 return($result);
1363 }
1366 function renderCopyPasteActions($row, $dn, $category, $class, $copy= true, $cut= true)
1367 {
1368 // We can only provide information if we've got a copypaste handler
1369 // instance
1370 if(!(isset($this->copyPasteHandler) && is_object($this->copyPasteHandler))){
1371 return "";
1372 }
1374 // Presets
1375 $ui = get_userinfo();
1376 $result = "";
1378 // Render cut entries
1379 if($cut){
1380 if($ui->is_cutable($dn, $category, $class)){
1381 $result .= "<input class='center' type='image'
1382 src='images/lists/cut.png' alt='"._("Cut")."' name='listing_cut_$row' title='"._("Cut this entry")."' style='padding:1px'>";
1383 }else{
1384 $result.="<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
1385 }
1386 }
1388 // Render copy entries
1389 if($copy){
1390 if($ui->is_copyable($dn, $category, $class)){
1391 $result.= "<input class='center' type='image'
1392 src='images/lists/copy.png' alt='"._("Copy")."' name='listing_copy_$row' title='"._("Copy this entry")."' style='padding:1px'>";
1393 }else{
1394 $result.="<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
1395 }
1396 }
1398 return($result);
1399 }
1402 function renderSnapshotMenu($separator)
1403 {
1404 // We can only provide information if we've got a snapshot handler
1405 // instance
1406 if(!(isset($this->snapshotHandler) && is_object($this->snapshotHandler))){
1407 return "";
1408 }
1410 // Presets
1411 $result = "";
1412 $ui = get_userinfo();
1414 if($this->snapshotHandler->enabled() && $ui->allow_snapshot_restore($this->base, $this->module)){
1416 // Check if there is something to restore
1417 $restore= false;
1418 foreach($this->snapshotHandler->getSnapshotBases() as $base){
1419 $restore= $restore || count($this->snapshotHandler->getDeletedSnapshots($base)) > 0;
1420 }
1422 // Draw icons according to the restore flag
1423 if($restore){
1424 $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>";
1425 }else{
1426 $result.= "<li$separator><a href='#'><img src='images/lists/restore_grey.png' alt='' border='0' class='center'> "._("Restore snapshots")."</a></li>";
1427 }
1428 }
1430 return($result);
1431 }
1434 function renderExporterMenu($separator)
1435 {
1436 // Presets
1437 $result = "";
1439 // Draw entries
1440 $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'>";
1442 // Export CVS as build in exporter
1443 foreach ($this->exporter as $action => $exporter) {
1444 $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>";
1445 }
1447 // Finalize list
1448 $result.= "</ul></li>";
1450 return($result);
1451 }
1454 function renderSnapshotActions($row, $dn, $category, $class, $copy= true, $cut= true)
1455 {
1456 // We can only provide information if we've got a snapshot handler
1457 // instance
1458 if(!(isset($this->snapshotHandler) && is_object($this->snapshotHandler))){
1459 return "";
1460 }
1462 // Presets
1463 $result= "";
1464 $ui = get_userinfo();
1466 // Only act if enabled here
1467 if($this->snapshotHandler->enabled()){
1469 // Draw restore button
1470 if ($ui->allow_snapshot_restore($dn, $category)){
1472 // Do we have snapshots for this dn?
1473 if($this->snapshotHandler->hasSnapshots($dn)){
1474 $result.= "<input class='center' type='image' src='images/lists/restore.png' ".
1475 "alt='"._("Restore snapshot")."' name='listing_restore_$row' title='".
1476 _("Restore snapshot")."' style='padding:1px'>";
1477 } else {
1478 $result.= "<img src='images/lists/restore_grey.png' alt=' ' class='center' style='padding:1px'>";
1479 }
1480 }
1482 // Draw snapshot button
1483 if($ui->allow_snapshot_create($dn, $category)){
1484 $result.= "<input class='center' type='image' src='images/snapshot.png' ".
1485 "alt='"._("Create snapshot")."' name='listing_snapshot_$row' title='".
1486 _("Create a new snapshot from this object")."' style='padding:1px'>";
1487 }else{
1488 $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
1489 }
1490 }
1492 return($result);
1493 }
1496 function renderDaemonMenu($separator)
1497 {
1498 $result= "";
1500 // If there is a daemon registered, draw the menu entries
1501 if(class_available("DaemonEvent")){
1502 $events= DaemonEvent::get_event_types_by_category($this->categories);
1503 if(isset($events['BY_CLASS']) && count($events['BY_CLASS'])){
1504 foreach($events['BY_CLASS'] as $name => $event){
1505 $result.= "<li$separator><a href='#' onClick='document.getElementById(\"actionmenu\").value=\"$name\";document.getElementById(\"exec_act\").click();'>".$event['MenuImage']." ".$event['s_Menu_Name']."</a></li>";
1506 $separator= "";
1507 }
1508 }
1509 }
1511 return $result;
1512 }
1515 function getEntry($dn)
1516 {
1517 foreach ($this->entries as $entry) {
1518 if (isset($entry['dn']) && strcasecmp($dn, $entry['dn']) == 0){
1519 return $entry;
1520 }
1521 }
1522 return null;
1523 }
1526 function getType($dn)
1527 {
1528 if (isset($this->objectDnMapping[$dn])) {
1529 return $this->objectDnMapping[$dn];
1530 }
1531 return null;
1532 }
1534 }
1536 ?>