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