153c0380f994aa532fe527216411b9644fddb698
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;
55 var $scrollPosition= 0;
58 function listing($filename)
59 {
60 global $config;
61 global $class_mapping;
63 // Initialize pid
64 $this->pid= preg_replace("/[^0-9]/", "", microtime(TRUE));
66 if (!$this->load($filename)) {
67 die("Cannot parse $filename!");
68 }
70 // Set base for filter
71 if ($this->baseMode) {
72 $this->base= session::global_get("CurrentMainBase");
73 if ($this->base == null) {
74 $this->base= $config->current['BASE'];
75 }
76 $this->refreshBasesList();
77 } else {
78 $this->base= $config->current['BASE'];
79 }
81 // Move footer information
82 $this->showFooter= ($config->get_cfg_value("listSummary") == "true");
84 // Register build in filters
85 $this->registerElementFilter("objectType", "listing::filterObjectType");
86 $this->registerElementFilter("departmentLink", "listing::filterDepartmentLink");
87 $this->registerElementFilter("link", "listing::filterLink");
88 $this->registerElementFilter("actions", "listing::filterActions");
90 // Load exporters
91 foreach($class_mapping as $class => $dummy) {
92 if (preg_match('/Exporter$/', $class)) {
93 $info= call_user_func(array($class, "getInfo"));
94 if ($info != null) {
95 $this->exporter= array_merge($this->exporter, $info);
96 }
97 }
98 }
99 }
102 function setCopyPasteHandler($handler)
103 {
104 $this->copyPasteHandler= &$handler;
105 }
108 function setHeight($height)
109 {
110 $this->height= $height;
111 }
114 function setSnapshotHandler($handler)
115 {
116 $this->snapshotHandler= &$handler;
117 }
120 function setFilter($filter)
121 {
122 $this->filter= &$filter;
123 if ($this->departmentBrowser){
124 $this->departments= $this->getDepartments();
125 }
126 $this->filter->setBase($this->base);
127 }
130 function registerElementFilter($name, $call)
131 {
132 if (!isset($this->filters[$name])) {
133 $this->filters[$name]= $call;
134 return true;
135 }
137 return false;
138 }
141 function load($filename)
142 {
143 $contents = file_get_contents($filename);
144 $this->xmlData= xml::xml2array($contents, 1);
146 if (!isset($this->xmlData['list'])) {
147 return false;
148 }
150 $this->xmlData= $this->xmlData["list"];
152 // Load some definition values
153 foreach (array("departmentBrowser", "departmentRootVisible", "multiSelect", "baseMode") as $token) {
154 if (isset($this->xmlData['definition'][$token]) &&
155 $this->xmlData['definition'][$token] == "true"){
156 $this->$token= true;
157 }
158 }
160 // Fill objectTypes from departments and xml definition
161 $types = departmentManagement::get_support_departments();
162 foreach ($types as $class => $data) {
163 $this->objectTypes[]= array("label" => $data['TITLE'],
164 "objectClass" => $data['OC'],
165 "image" => $data['IMG']);
166 }
167 $this->categories= array();
168 if (isset($this->xmlData['definition']['objectType'])) {
169 if(isset($this->xmlData['definition']['objectType']['label'])) {
170 $this->xmlData['definition']['objectType']= array($this->xmlData['definition']['objectType']);
171 }
172 foreach ($this->xmlData['definition']['objectType'] as $index => $otype) {
173 $this->objectTypes[]= $this->xmlData['definition']['objectType'][$index];
174 if (isset($this->xmlData['definition']['objectType'][$index]['category'])){
175 $this->categories[]= $otype['category'];
176 }
177 }
178 }
180 // Parse layout per column
181 $this->colprops= $this->parseLayout($this->xmlData['table']['layout']);
183 // Prepare table headers
184 $this->renderHeader();
186 // Assign headline/module
187 $this->headline= _($this->xmlData['definition']['label']);
188 $this->module= $this->xmlData['definition']['module'];
189 if (!is_array($this->categories)){
190 $this->categories= array($this->categories);
191 }
193 // Evaluate columns to be exported
194 if (isset($this->xmlData['table']['column'])){
195 foreach ($this->xmlData['table']['column'] as $index => $config) {
196 if (isset($config['export']) && $config['export'] == "true"){
197 $this->exportColumns[]= $index;
198 }
199 }
200 }
202 return true;
203 }
206 function renderHeader()
207 {
208 $this->header= array();
209 $this->plainHeader= array();
211 // Initialize sort?
212 $sortInit= false;
213 if (!$this->sortDirection) {
214 $this->sortColumn= 0;
215 if (isset($this->xmlData['definition']['defaultSortColumn'])){
216 $this->sortColumn= $this->xmlData['definition']['defaultSortColumn'];
217 } else {
218 $this->sortAttribute= "";
219 }
220 $this->sortDirection= array();
221 $sortInit= true;
222 }
224 if (isset($this->xmlData['table']['column'])){
225 foreach ($this->xmlData['table']['column'] as $index => $config) {
226 // Initialize everything to one direction
227 if ($sortInit) {
228 $this->sortDirection[$index]= false;
229 }
231 $sorter= "";
232 if ($index == $this->sortColumn && isset($config['sortAttribute']) &&
233 isset($config['sortType'])) {
234 $this->sortAttribute= $config['sortAttribute'];
235 $this->sortType= $config['sortType'];
236 $sorter= " <img border='0' title='".($this->sortDirection[$index]?_("Up"):_("Down"))."' src='images/lists/sort-".($this->sortDirection[$index]?"up":"down").".png' align='top'>";
237 }
238 $sortable= (isset($config['sortAttribute']));
240 $link= "href='?plug=".$_GET['plug']."&PID=".$this->pid."&act=SORT_$index'";
241 if (isset($config['label'])) {
242 if ($sortable) {
243 $this->header[$index]= "<td class='listheader' ".$this->colprops[$index]."><a $link>"._($config['label'])."$sorter</a></td>";
244 } else {
245 $this->header[$index]= "<td class='listheader' ".$this->colprops[$index].">"._($config['label'])."</td>";
246 }
247 $this->plainHeader[]= _($config['label']);
248 } else {
249 if ($sortable) {
250 $this->header[$index]= "<td class='listheader' ".$this->colprops[$index]."><a $link> $sorter</a></td>";
251 } else {
252 $this->header[$index]= "<td class='listheader' ".$this->colprops[$index]."> </td>";
253 }
254 $this->plainHeader[]= "";
255 }
256 }
257 }
258 }
261 function render()
262 {
263 // Check for exeeded sizelimit
264 if (($message= check_sizelimit()) != ""){
265 return($message);
266 }
268 // Some browsers don't have the ability do do scrollable table bodies, filter them
269 // here.
270 $switch= false;
271 if (preg_match('/(Opera|Konqueror|Safari|msie)/i', $_SERVER['HTTP_USER_AGENT'])){
272 $switch= true;
273 }
275 // Initialize list
276 $result= "<input type='hidden' value='$this->pid' name='PID'>\n";
277 $result.= "<input type='hidden' name='position_".$this->pid."' id='position_".$this->pid."'>\n";
278 $height= 450;
279 if ($this->height != 0) {
280 $result.= "<input type='hidden' value='$this->height' id='d_height'>\n";
281 $height= $this->height;
282 }
284 $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";
286 $height= "";
287 if ($switch){
288 $height= "height:100%;";
289 }
290 $result.= "<table summary='$this->headline' style='${height}width:100%; table-layout:fixed;' cellspacing='0' cellpadding='0' id='t_scrolltable'>\n";
291 $this->numColumns= count($this->colprops) + ($this->multiSelect?1:0);
293 // Build list header
294 $result.= "<thead class='fixedListHeader listHeaderFormat'><tr>\n";
295 if ($this->multiSelect) {
296 $width= "24px";
297 if (preg_match('/Konqueror/i', $_SERVER['HTTP_USER_AGENT'])){
298 $width= "28px";
299 }
300 $result.= "<td class='listheader' style='text-align:center;padding:0;width:$width;'><input type='checkbox' id='select_all' name='select_all' title='"._("Select all")."' onClick='toggle_all_(\"listing_selected_[0-9]*$\",\"select_all\");' ></td>\n";
301 }
302 foreach ($this->header as $header) {
303 $result.= $header;
304 }
305 $result.= "</tr></thead>\n";
307 // Build list body
308 $result.= "<tbody class='listScrollContent listBodyFormat' id='t_nscrollbody' style='height:".$height."px;'>\n";
310 // No results? Just take an empty colspanned row
311 if (count($this->entries) + count($this->departments) == 0) {
312 $result.= "<tr class='rowxp0'><td class='list1nohighlight' colspan='$this->numColumns' style='height:100%;border-right:0px;width:100%;'> </td></tr>";
313 }
315 // Line color alternation
316 $alt= 0;
317 $deps= 0;
319 // Draw department browser if configured and we're not in sub mode
320 $this->useSpan= false;
321 if ($this->departmentBrowser && $this->filter->scope != "sub") {
322 // Fill with department browser if configured this way
323 $departmentIterator= new departmentSortIterator($this->departments, $this->sortDirection[$this->sortColumn]);
324 foreach ($departmentIterator as $row => $entry){
325 $result.="<tr class='rowxp".($alt&1)."'>";
327 // Render multi select if needed
328 if ($this->multiSelect) {
329 $result.="<td style='text-align:center;padding:0;' class='list1'> </td>";
330 }
332 // Render defined department columns, fill the rest with some stuff
333 $rest= $this->numColumns - 1;
334 foreach ($this->xmlData['table']['department'] as $index => $config) {
335 $colspan= 1;
336 if (isset($config['span'])){
337 $colspan= $config['span'];
338 $this->useSpan= true;
339 }
340 $result.="<td colspan='$colspan' ".$this->colprops[$index]." class='list1'>".$this->renderCell($config['value'], $entry, $row)."</td>";
341 $rest-= $colspan;
342 }
344 // Fill remaining cols with nothing
345 $last= $this->numColumns - $rest;
346 for ($i= 0; $i<$rest; $i++){
347 $result.= "<td ".$this->colprops[$last+$i-1]." class='list1'> </td>";
348 }
349 $result.="</tr>";
351 $alt++;
352 }
353 $deps= $alt;
354 }
356 // Fill with contents, sort as configured
357 foreach ($this->entries as $row => $entry) {
358 $trow= "";
360 // Render multi select if needed
361 if ($this->multiSelect) {
362 $trow.="<td style='text-align:center;width:20px;' class='list0'><input type='checkbox' id='listing_selected_$row' name='listing_selected_$row'></td>\n";
363 }
365 foreach ($this->xmlData['table']['column'] as $index => $config) {
366 $renderedCell= $this->renderCell($config['value'], $entry, $row);
367 $trow.="<td ".$this->colprops[$index]." class='list0'>".$renderedCell."</td>\n";
369 // Save rendered column
370 $sort= preg_replace('/.*>([^<]+)<.*$/', '$1', $renderedCell);
371 $sort= preg_replace('/ /', '', $sort);
372 if (preg_match('/</', $sort)){
373 $sort= "";
374 }
375 $this->entries[$row]["_sort$index"]= $sort;
376 }
378 // Save rendered entry
379 $this->entries[$row]['_rendered']= $trow;
380 }
382 // Complete list by sorting entries for _sort$index and appending them to the output
383 $entryIterator= new listingSortIterator($this->entries, $this->sortDirection[$this->sortColumn], "_sort".$this->sortColumn, $this->sortType);
384 foreach ($entryIterator as $row => $entry){
385 $alt++;
386 $result.="<tr class='rowxp".($alt&1)."'>\n";
387 $result.= $entry['_rendered'];
388 $result.="</tr>\n";
389 }
391 // Need to fill the list if it's not full (nobody knows why this is 22 ;-))
392 $emptyListStyle= (count($this->entries) + (($this->useSpan && count($this->entries))?$deps:0) == 0)?"border:0;":"";
393 if ((count($this->entries) + $deps) < 22) {
394 $result.= "<tr>";
395 for ($i= 0; $i<$this->numColumns; $i++) {
396 if ($i == 0) {
397 $result.= "<td class='list1nohighlight' style='$emptyListStyle height:100%;'> </td>";
398 continue;
399 }
400 if ($i != $this->numColumns-1) {
401 $result.= "<td class='list1nohighlight' style='$emptyListStyle'> </td>";
402 } else {
403 $result.= "<td class='list1nohighlight' style='border-right:1px solid #AAA;$emptyListStyle'> </td>";
404 }
405 }
406 $result.= "</tr>";
407 }
409 // Close list body
410 $result.= "</tbody></table></div></td></tr>";
412 // Add the footer if requested
413 if ($this->showFooter) {
414 $result.= "<tr><td class='nlistFooter'>";
416 foreach ($this->objectTypes as $objectType) {
417 if (isset($this->objectTypeCount[$objectType['label']])) {
418 $label= _($objectType['label']);
419 $result.= "<img class='center' src='".$objectType['image']."' title='$label' alt='$label'> ".$this->objectTypeCount[$objectType['label']]." ";
420 }
421 }
423 $result.= "</td></tr>";
424 }
426 // Close list
427 $result.= "</table>";
428 $result.= $switch?"<input type='hidden' id='list_workaround'>":"";
430 // Add scroll positioner
431 $result.= '<script type="text/javascript" language="javascript">';
432 $result.= '$("t_nscrollbody").scrollTop= '.$this->scrollPosition.';';
433 $result.= 'var box = $("t_nscrollbody").onscroll= function() {$("position_'.$this->pid.'").value= this.scrollTop;}';
434 $result.= '</script>';
436 $smarty= get_smarty();
437 $smarty->assign("usePrototype", "true");
438 $smarty->assign("FILTER", $this->filter->render());
439 $smarty->assign("SIZELIMIT", print_sizelimit_warning());
440 $smarty->assign("LIST", $result);
442 // Assign navigation elements
443 $nav= $this->renderNavigation();
444 foreach ($nav as $key => $html) {
445 $smarty->assign($key, $html);
446 }
448 // Assign action menu / base
449 $smarty->assign("ACTIONS", $this->renderActionMenu());
450 $smarty->assign("BASE", $this->renderBase());
452 // Assign separator
453 $smarty->assign("SEPARATOR", "<img src='images/lists/seperator.png' alt='-' align='middle' height='16' width='1' class='center'>");
455 // Assign summary
456 $smarty->assign("HEADLINE", $this->headline);
458 // Try to load template from plugin the folder first...
459 $file = get_template_path($this->xmlData['definition']['template'], true);
461 // ... if this fails, try to load the file from the theme folder.
462 if(!file_exists($file)){
463 $file = get_template_path($this->xmlData['definition']['template']);
464 }
466 return ($smarty->fetch($file));
467 }
470 function update()
471 {
472 global $config;
473 $ui= get_userinfo();
475 // Reset object counter / DN mapping
476 $this->objectTypeCount= array();
477 $this->objectDnMapping= array();
479 // Do not do anything if this is not our PID
480 if(isset($_REQUEST['PID']) && $_REQUEST['PID'] != $this->pid) {
481 return;
482 }
484 // Save position if set
485 if (isset($_POST['position_'.$this->pid]) && is_numeric($_POST['position_'.$this->pid])) {
486 $this->scrollPosition= $_POST['position_'.$this->pid];
487 }
489 // Save base
490 if (isset($_POST['BASE']) && $this->baseMode) {
491 $base= get_post('BASE');
492 if (isset($this->bases[$base])) {
493 $this->base= $base;
494 session::global_set("CurrentMainBase", $this->base);
495 }
496 }
498 // Override the base if we got a message from the browser navigation
499 if ($this->departmentBrowser && isset($_GET['act'])) {
500 if (preg_match('/^department_([0-9]+)$/', validate($_GET['act']), $match)){
501 if (isset($this->departments[$match[1]])){
502 $this->base= $this->departments[$match[1]]['dn'];
503 session::global_set("CurrentMainBase", $this->base);
504 }
505 }
506 }
508 // Filter POST with "act" attributes -> posted from action menu
509 if (isset($_POST['exec_act']) && $_POST['act'] != '') {
510 if (preg_match('/^export.*$/', $_POST['act']) && isset($this->exporter[$_POST['act']])) {
511 $exporter= $this->exporter[$_POST['act']];
512 $userinfo= ", "._("created by")." ".$ui->cn." - ".strftime('%A, %d. %B %Y, %H:%M:%S');
513 $entryIterator= new listingSortIterator($this->entries, $this->sortDirection[$this->sortColumn], "_sort".$this->sortColumn, $this->sortType);
514 $sortedEntries= array();
515 foreach ($entryIterator as $entry){
516 $sortedEntries[]= $entry;
517 }
518 $instance= new $exporter['class']($this->headline.$userinfo, $this->plainHeader, $sortedEntries, $this->exportColumns);
519 $type= call_user_func(array($exporter['class'], "getInfo"));
520 $type= $type[$_POST['act']];
521 send_binary_content($instance->query(), $type['filename'], $type= $type['mime']);
522 }
523 }
525 // Filter GET with "act" attributes
526 if (isset($_GET['act'])) {
527 $key= validate($_GET['act']);
528 if (preg_match('/^SORT_([0-9]+)$/', $key, $match)) {
529 // Switch to new column or invert search order?
530 $column= $match[1];
531 if ($this->sortColumn != $column) {
532 $this->sortColumn= $column;
533 } else {
534 $this->sortDirection[$column]= !$this->sortDirection[$column];
535 }
537 // Allow header to update itself according to the new sort settings
538 $this->renderHeader();
539 }
540 }
542 // Override base if we got signals from the navigation elements
543 $action= "";
544 foreach ($_POST as $key => $value) {
545 if (preg_match('/^(ROOT|BACK|HOME)_x$/', $key, $match)) {
546 $action= $match[1];
547 break;
548 }
549 }
551 // Navigation handling
552 if ($action == 'ROOT') {
553 $deps= $ui->get_module_departments($this->module);
554 $this->base= $deps[0];
555 }
556 if ($action == 'BACK') {
557 $deps= $ui->get_module_departments($this->module);
558 $base= preg_replace("/^[^,]+,/", "", $this->base);
559 if(in_array_ics($base, $deps)){
560 $this->base= $base;
561 }
562 }
563 if ($action == 'HOME') {
564 $ui= get_userinfo();
565 $this->base= $this->filter->getObjectBase($ui->dn);
566 }
568 // Reload departments
569 if ($this->departmentBrowser){
570 $this->departments= $this->getDepartments();
571 }
573 // Update filter and refresh entries
574 $this->filter->setBase($this->base);
575 $this->entries= $this->filter->query();
576 }
579 function setBase($base)
580 {
581 $this->base= $base;
582 }
585 function getBase()
586 {
587 return $this->base;
588 }
591 function parseLayout($layout)
592 {
593 $result= array();
594 $layout= preg_replace("/^\|/", "", $layout);
595 $layout= preg_replace("/\|$/", "", $layout);
596 $cols= split("\|", $layout);
598 foreach ($cols as $index => $config) {
599 if ($config != "") {
600 $res= "";
601 $components= split(';', $config);
602 foreach ($components as $part) {
603 if (preg_match("/^r$/", $part)) {
604 $res.= "text-align:right;";
605 continue;
606 }
607 if (preg_match("/^l$/", $part)) {
608 $res.= "text-align:left;";
609 continue;
610 }
611 if (preg_match("/^c$/", $part)) {
612 $res.= "text-align:center;";
613 continue;
614 }
615 if (preg_match("/^[0-9]+(|px|%)$/", $part)) {
616 $res.= "width:$part;min-width:$part;";
617 continue;
618 }
619 }
621 // Add minimum width for scalable columns
622 if (!preg_match('/width:/', $res)){
623 $res.= "min-width:200px;";
624 }
626 $result[$index]= " style='$res' ";
627 } else {
628 $result[$index]= " style='min-width:100px'";
629 }
630 }
632 // Save number of columns for later use
633 $this->numColumns= count($cols);
635 return $result;
636 }
639 function renderCell($data, $config, $row)
640 {
641 // Replace flat attributes in data string
642 for ($i= 0; $i<$config['count']; $i++) {
643 $attr= $config[$i];
644 $value= "";
645 if (is_array($config[$attr])) {
646 $value= $config[$attr][0];
647 } else {
648 $value= $config[$attr];
649 }
650 $data= preg_replace("/%\{$attr\}/", $value, $data);
651 }
653 // Watch out for filters and prepare to execute them
654 $data= $this->processElementFilter($data, $config, $row);
656 // Replace all non replaced %{...} instances because they
657 // are non resolved attributes or filters
658 $data= preg_replace('/%{[^}]+}/', ' ', $data);
660 return $data;
661 }
664 function renderBase()
665 {
666 if (!$this->baseMode) {
667 return;
668 }
670 $result= "<select name='BASE' onChange='mainform.submit()' size='1'>";
671 $firstDN= null;
672 $found= false;
674 foreach ($this->bases as $key=>$value) {
675 // Keep first entry to fall back eventually
676 if(!$firstDN) {
677 $firstDN= $key;
678 }
680 // Prepare to render entry
681 $selected= "";
682 if ($key == $this->base) {
683 $selected= " selected";
684 $found= true;
685 }
686 $key = htmlentities($key,ENT_QUOTES);
687 $result.= "\n<option value=\"".$key."\"$selected>".$value."</option>";
688 }
690 $result.= "</select>";
692 // Reset the currently used base to the first DN we found if there
693 // was no match.
694 if(!$found){
695 $this->base = $firstDN;
696 }
698 return $result;
699 }
702 function processElementFilter($data, $config, $row)
703 {
704 preg_match_all("/%\{filter:([^(]+)\((.*)\)\}/", $data, $matches, PREG_SET_ORDER);
706 foreach ($matches as $match) {
707 $cl= "";
708 $method= "";
709 if (preg_match('/::/', $match[1])) {
710 $cl= preg_replace('/::.*$/', '', $match[1]);
711 $method= preg_replace('/^.*::/', '', $match[1]);
712 } else {
713 if (!isset($this->filters[$match[1]])) {
714 continue;
715 }
716 $cl= preg_replace('/::.*$/', '', $this->filters[$match[1]]);
717 $method= preg_replace('/^.*::/', '', $this->filters[$match[1]]);
718 }
720 // Prepare params for function call
721 $params= array();
722 preg_match_all('/"[^"]+"|[^,]+/', $match[2], $parts);
723 foreach ($parts[0] as $param) {
725 // Row is replaced by the row number
726 if ($param == "row") {
727 $params[]= $row;
728 continue;
729 }
731 // pid is replaced by the current PID
732 if ($param == "pid") {
733 $params[]= $this->pid;
734 continue;
735 }
737 // base is replaced by the current base
738 if ($param == "base") {
739 $params[]= $this->getBase();
740 continue;
741 }
743 // Fixie with "" is passed directly
744 if (preg_match('/^".*"$/', $param)){
745 $params[]= preg_replace('/"/', '', $param);
746 continue;
747 }
749 // Move dn if needed
750 if ($param == "dn") {
751 $params[]= LDAP::fix($config["dn"]);
752 continue;
753 }
755 // LDAP variables get replaced by their objects
756 for ($i= 0; $i<$config['count']; $i++) {
757 if ($param == $config[$i]) {
758 $values= $config[$config[$i]];
759 if (is_array($values)){
760 unset($values['count']);
761 }
762 $params[]= $values;
763 break;
764 }
765 }
766 }
768 // Replace information
769 if ($cl == "listing") {
770 // Non static call - seems to result in errors
771 $data= @preg_replace('/'.preg_quote($match[0]).'/', call_user_func_array(array($this, "$method"), $params), $data);
772 } else {
773 // Static call
774 $data= preg_replace('/'.preg_quote($match[0]).'/', call_user_func_array(array($cl, $method), $params), $data);
775 }
776 }
778 return $data;
779 }
782 function getObjectType($types, $classes)
783 {
784 // Walk thru types and see if there's something matching
785 foreach ($types as $objectType) {
786 $ocs= $objectType['objectClass'];
787 if (!is_array($ocs)){
788 $ocs= array($ocs);
789 }
791 $found= true;
792 foreach ($ocs as $oc){
793 if (preg_match('/^!(.*)$/', $oc, $match)) {
794 $oc= $match[1];
795 if (in_array($oc, $classes)) {
796 $found= false;
797 }
798 } else {
799 if (!in_array($oc, $classes)) {
800 $found= false;
801 }
802 }
803 }
805 if ($found) {
806 return $objectType;
807 }
808 }
810 return null;
811 }
814 function filterObjectType($dn, $classes)
815 {
816 // Walk thru classes and return on first match
817 $result= " ";
819 $objectType= $this->getObjectType($this->objectTypes, $classes);
820 if ($objectType) {
821 $this->objectDnMapping[$dn]= $objectType["objectClass"];
822 $result= "<img class='center' title='".LDAP::fix($dn)."' src='".$objectType["image"]."'>";
823 if (!isset($this->objectTypeCount[$objectType['label']])) {
824 $this->objectTypeCount[$objectType['label']]= 0;
825 }
826 $this->objectTypeCount[$objectType['label']]++;
827 }
829 return $result;
830 }
833 function filterActions($dn, $row, $classes)
834 {
835 // Do nothing if there's no menu defined
836 if (!isset($this->xmlData['actiontriggers']['action'])) {
837 return " ";
838 }
840 // Go thru all actions
841 $result= "";
842 $actions= $this->xmlData['actiontriggers']['action'];
843 foreach($actions as $action) {
844 // Skip the entry completely if there's no permission to execute it
845 if (!$this->hasActionPermission($action, $dn, $classes)) {
846 $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
847 continue;
848 }
850 // Skip entry if the pseudo filter does not fit
851 if (isset($action['filter']) && preg_match('/^[a-z0-9_]+!?=[a-z0-9_]+$/i', $action['filter'])) {
852 list($fa, $fv)= split('=', $action['filter']);
853 if (preg_match('/^(.*)!$/', $fa, $m)){
854 $fa= $m[1];
855 if (isset($this->entries[$row][$fa]) && $this->entries[$row][$fa][0] == $fv) {
856 $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
857 continue;
858 }
859 } else {
860 if (!isset($this->entries[$row][$fa]) && !$this->entries[$row][$fa][0] == $fv) {
861 $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
862 continue;
863 }
864 }
865 }
868 // If there's an objectclass definition and we don't have it
869 // add an empty picture here.
870 if (isset($action['objectclass'])){
871 $objectclass= $action['objectclass'];
872 if (preg_match('/^!(.*)$/', $objectclass, $m)){
873 $objectclass= $m[1];
874 if(in_array($objectclass, $classes)) {
875 $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
876 continue;
877 }
878 } elseif (is_string($objectclass)) {
879 if(!in_array($objectclass, $classes)) {
880 $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
881 continue;
882 }
883 } elseif (is_array($objectclass)) {
884 if(count(array_intersect($objectclass, $classes)) != count($objectclass)){
885 $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
886 continue;
887 }
888 }
889 }
891 // Render normal entries as usual
892 if ($action['type'] == "entry") {
893 $label= $this->processElementFilter($action['label'], $this->entries[$row], $row);
894 $image= $this->processElementFilter($action['image'], $this->entries[$row], $row);
895 $result.="<input class='center' type='image' src='$image' title='$label' ".
896 "name='listing_".$action['name']."_$row' style='padding:1px'>";
897 }
899 // Handle special types
900 if ($action['type'] == "copypaste" || $action['type'] == "snapshot") {
902 $objectType= $this->getObjectType($this->objectTypes, $this->entries[$row]['objectClass']);
903 $category= $class= null;
904 if ($objectType) {
905 $category= $objectType['category'];
906 $class= $objectType['class'];
907 }
909 if ($action['type'] == "copypaste") {
910 $copy = !isset($action['copy']) || $action['copy'] == "true";
911 $cut = !isset($action['cut']) || $action['cut'] == "true";
912 $result.= $this->renderCopyPasteActions($row, $this->entries[$row]['dn'], $category, $class,$copy,$cut);
913 } else {
914 $result.= $this->renderSnapshotActions($row, $this->entries[$row]['dn'], $category, $class);
915 }
916 }
917 }
919 return $result;
920 }
923 function filterDepartmentLink($row, $dn, $description)
924 {
925 $attr= $this->departments[$row]['sort-attribute'];
926 $name= $this->departments[$row][$attr];
927 if (is_array($name)){
928 $name= $name[0];
929 }
930 $result= sprintf("%s [%s]", $name, $description[0]);
931 return("<a href='?plug=".$_GET['plug']."&PID=$this->pid&act=department_$row' title='$dn'>$result</a>");
932 }
935 function filterLink()
936 {
937 $result= " ";
939 $row= func_get_arg(0);
940 $pid= $this->pid;
941 $dn= LDAP::fix(func_get_arg(1));
942 $params= array(func_get_arg(2));
944 // Collect sprintf params
945 for ($i = 3;$i < func_num_args();$i++) {
946 $val= func_get_arg($i);
947 if (is_array($val)){
948 $params[]= $val[0];
949 continue;
950 }
951 $params[]= $val;
952 }
954 $result= " ";
955 $trans= call_user_func_array("sprintf", $params);
956 if ($trans != "") {
957 return("<a href='?plug=".$_GET['plug']."&PID=$pid&act=listing_edit_$row' title='$dn'>$trans</a>");
958 }
960 return $result;
961 }
964 function renderNavigation()
965 {
966 $result= array();
967 $enableBack = true;
968 $enableRoot = true;
969 $enableHome = true;
971 $ui = get_userinfo();
973 /* Check if base = first available base */
974 $deps = $ui->get_module_departments($this->module);
976 if(!count($deps) || $deps[0] == $this->filter->base){
977 $enableBack = false;
978 $enableRoot = false;
979 }
981 $listhead ="";
983 /* Check if we are in users home department */
984 if(!count($deps) || $this->filter->base == $this->filter->getObjectBase($ui->dn)){
985 $enableHome = false;
986 }
988 /* Draw root button */
989 if($enableRoot){
990 $result["ROOT"]= "<input class='center' type='image' src='images/lists/root.png' align='middle' ".
991 "title='"._("Go to root department")."' name='ROOT' alt='"._("Root")."'>";
992 }else{
993 $result["ROOT"]= "<img src='images/lists/root_grey.png' class='center' alt='"._("Root")."'>";
994 }
996 /* Draw back button */
997 if($enableBack){
998 $result["BACK"]= "<input class='center' type='image' align='middle' src='images/lists/back.png' ".
999 "title='"._("Go up one department")."' alt='"._("Up")."' name='BACK'>";
1000 }else{
1001 $result["BACK"]= "<img src='images/lists/back_grey.png' class='center' alt='"._("Up")."'>";
1002 }
1004 /* Draw home button */
1005 if($enableHome){
1006 $result["HOME"]= "<input class='center' type='image' align='middle' src='images/lists/home.png' ".
1007 "title='"._("Go to users department")."' alt='"._("Home")."' name='HOME'>";
1008 }else{
1009 $result["HOME"]= "<img src='images/lists/home_grey.png' class='center' alt='"._("Home")."'>";
1010 }
1012 /* Draw reload button, this button is enabled everytime */
1013 $result["RELOAD"]= "<input class='center' type='image' src='images/lists/reload.png' align='middle' ".
1014 "title='"._("Reload list")."' name='REFRESH' alt='"._("Submit")."'>";
1016 return ($result);
1017 }
1020 function getAction()
1021 {
1022 // Do not do anything if this is not our PID, or there's even no PID available...
1023 if(!isset($_REQUEST['PID']) || $_REQUEST['PID'] != $this->pid) {
1024 return;
1025 }
1027 // Save position if set
1028 if (isset($_POST['position_'.$this->pid]) && is_numeric($_POST['position_'.$this->pid])) {
1029 $this->scrollPosition= $_POST['position_'.$this->pid];
1030 }
1032 $result= array("targets" => array(), "action" => "");
1034 // Filter GET with "act" attributes
1035 if (isset($_GET['act'])) {
1036 $key= validate($_GET['act']);
1037 $target= preg_replace('/^listing_[a-zA-Z_]+_([0-9]+)$/', '$1', $key);
1038 if (isset($this->entries[$target]['dn'])) {
1039 $result['action']= preg_replace('/^listing_([a-zA-Z_]+)_[0-9]+$/', '$1', $key);
1040 $result['targets'][]= $this->entries[$target]['dn'];
1041 }
1043 // Drop targets if empty
1044 if (count($result['targets']) == 0) {
1045 unset($result['targets']);
1046 }
1047 return $result;
1048 }
1050 // Filter POST with "listing_" attributes
1051 foreach ($_POST as $key => $prop) {
1053 // Capture selections
1054 if (preg_match('/^listing_selected_[0-9]+$/', $key)) {
1055 $target= preg_replace('/^listing_selected_([0-9]+)$/', '$1', $key);
1056 if (isset($this->entries[$target]['dn'])) {
1057 $result['targets'][]= $this->entries[$target]['dn'];
1058 }
1059 continue;
1060 }
1062 // Capture action with target - this is a one shot
1063 if (preg_match('/^listing_[a-zA-Z_]+_[0-9]+(|_x)$/', $key)) {
1064 $target= preg_replace('/^listing_[a-zA-Z_]+_([0-9]+)(|_x)$/', '$1', $key);
1065 if (isset($this->entries[$target]['dn'])) {
1066 $result['action']= preg_replace('/^listing_([a-zA-Z_]+)_[0-9]+(|_x)$/', '$1', $key);
1067 $result['targets']= array($this->entries[$target]['dn']);
1068 }
1069 break;
1070 }
1072 // Capture action without target
1073 if (preg_match('/^listing_[a-zA-Z_]+(|_x)$/', $key)) {
1074 $result['action']= preg_replace('/^listing_([a-zA-Z_]+)(|_x)$/', '$1', $key);
1075 continue;
1076 }
1077 }
1079 // Filter POST with "act" attributes -> posted from action menu
1080 if (isset($_POST['act']) && $_POST['act'] != '') {
1081 if (!preg_match('/^export.*$/', $_POST['act'])){
1082 $result['action']= validate($_POST['act']);
1083 }
1084 }
1086 // Drop targets if empty
1087 if (count($result['targets']) == 0) {
1088 unset($result['targets']);
1089 }
1090 return $result;
1091 }
1094 function renderActionMenu()
1095 {
1096 // Don't send anything if the menu is not defined
1097 if (!isset($this->xmlData['actionmenu']['action'])){
1098 return "";
1099 }
1101 // Array?
1102 if (isset($this->xmlData['actionmenu']['action']['type'])){
1103 $this->xmlData['actionmenu']['action']= array($this->xmlData['actionmenu']['action']);
1104 }
1106 // Load shortcut
1107 $actions= &$this->xmlData['actionmenu']['action'];
1108 $result= "<input type='hidden' name='act' id='actionmenu' value=''><div style='display:none'><input type='submit' name='exec_act' id='exec_act' value=''></div>".
1109 "<ul class='level1' id='root'><li><a href='#'>"._("Actions")." <img ".
1110 "border=0 class='center' src='images/lists/sort-down.png'></a>";
1112 // Build ul/li list
1113 $result.= $this->recurseActions($actions);
1115 return "<div id='pulldown'>".$result."</li></ul><div>";
1116 }
1119 function recurseActions($actions)
1120 {
1121 global $class_mapping;
1122 static $level= 2;
1123 $result= "<ul class='level$level'>";
1124 $separator= "";
1126 foreach ($actions as $action) {
1128 // Skip the entry completely if there's no permission to execute it
1129 if (!$this->hasActionPermission($action, $this->filter->base)) {
1130 continue;
1131 }
1133 // Skip entry if there're missing dependencies
1134 if (isset($action['depends'])) {
1135 $deps= is_array($action['depends'])?$action['depends']:array($action['depends']);
1136 foreach($deps as $clazz) {
1137 if (!isset($class_mapping[$clazz])){
1138 continue 2;
1139 }
1140 }
1141 }
1143 // Fill image if set
1144 $img= "";
1145 if (isset($action['image'])){
1146 $img= "<img border='0' class='center' src='".$action['image']."'> ";
1147 }
1149 if ($action['type'] == "separator"){
1150 $separator= " style='border-top:1px solid #AAA' ";
1151 continue;
1152 }
1154 // Dive into subs
1155 if ($action['type'] == "sub" && isset($action['action'])) {
1156 $level++;
1157 if (isset($action['label'])){
1158 $result.= "<li$separator><a href='#'>$img"._($action['label'])." <img border='0' src='images/forward-arrow.png'></a>";
1159 }
1161 // Ensure we've an array of actions, this enables sub menus with only one action.
1162 if(isset($action['action']['type'])){
1163 $action['action'] = array($action['action']);
1164 }
1166 $result.= $this->recurseActions($action['action'])."</li>";
1167 $level--;
1168 $separator= "";
1169 continue;
1170 }
1172 // Render entry elseways
1173 if (isset($action['label'])){
1174 $result.= "<li$separator><a href='#' onClick='document.getElementById(\"actionmenu\").value= \"".$action['name']."\";mainform.submit();'>$img"._($action['label'])."</a></li>";
1175 }
1177 // Check for special types
1178 switch ($action['type']) {
1179 case 'copypaste':
1180 $cut = !isset($action['cut']) || $action['cut'] != "false";
1181 $copy = !isset($action['copy']) || $action['copy'] != "false";
1182 $result.= $this->renderCopyPasteMenu($separator, $copy , $cut);
1183 break;
1185 case 'snapshot':
1186 $result.= $this->renderSnapshotMenu($separator);
1187 break;
1189 case 'exporter':
1190 $result.= $this->renderExporterMenu($separator);
1191 break;
1193 case 'daemon':
1194 $result.= $this->renderDaemonMenu($separator);
1195 break;
1196 }
1198 $separator= "";
1199 }
1201 $result.= "</ul>";
1202 return $result;
1203 }
1206 function hasActionPermission($action, $dn, $classes= null)
1207 {
1208 $ui= get_userinfo();
1210 if (isset($action['acl'])) {
1211 $acls= $action['acl'];
1212 if (!is_array($acls)) {
1213 $acls= array($acls);
1214 }
1216 // Every ACL has to pass
1217 foreach ($acls as $acl) {
1218 $module= $this->module;
1219 $aclList= array();
1221 // Replace %acl if available
1222 if ($classes) {
1223 $otype= $this->getObjectType($this->objectTypes, $classes);
1224 $acl= str_replace('%acl', $module."/".$otype['category']);
1225 }
1227 // Split for category and plugins if needed
1228 // match for "[rw]" style entries
1229 if (preg_match('/^\[([rwcdm]+)\]$/', $acl, $match)){
1230 $aclList= array($match[1]);
1231 }
1233 // match for "users[rw]" style entries
1234 if (preg_match('/^([a-zA-Z0-9]+)\[([rwcdm]+)\]$/', $acl, $match)){
1235 $module= $match[1];
1236 $aclList= array($match[2]);
1237 }
1239 // match for "users/user[rw]" style entries
1240 if (preg_match('/^([a-zA-Z0-9]+\/[a-zA-Z0-9]+)\[([rwcdm]+)\]$/', $acl, $match)){
1241 $module= $match[1];
1242 $aclList= array($match[2]);
1243 }
1245 // match "users/user[userPassword:rw(,...)*]" style entries
1246 if (preg_match('/^([a-zA-Z0-9]+\/[a-zA-Z0-9]+)\[([a-zA-Z0-9]+:[rwcdm]+(,[a-zA-Z0-9]+:[rwcdm]+)*)\]$/', $acl, $match)){
1247 $module= $match[1];
1248 $aclList= split(',', $match[2]);
1249 }
1251 // Walk thru prepared ACL by using $module
1252 foreach($aclList as $sAcl) {
1253 $checkAcl= "";
1255 // Category or detailed permission?
1256 if (strpos('/', $module) === false) {
1257 if (preg_match('/([a-zA-Z0-9]+):([rwcdm]+)/', $sAcl, $m) ) {
1258 $checkAcl= $ui->get_permissions($dn, $module, $m[1]);
1259 $sAcl= $m[2];
1260 } else {
1261 $checkAcl= $ui->get_permissions($dn, $module, '0');
1262 }
1263 } else {
1264 $checkAcl= $ui->get_category_permissions($dn, $module);
1265 }
1267 // Split up remaining part of the acl and check if it we're
1268 // allowed to do something...
1269 $parts= str_split($sAcl);
1270 foreach ($parts as $part) {
1271 if (strpos($checkAcl, $part) === false){
1272 return false;
1273 }
1274 }
1276 }
1277 }
1278 }
1280 return true;
1281 }
1284 function refreshBasesList()
1285 {
1286 global $config;
1287 $ui= get_userinfo();
1289 // Do some array munching to get it user friendly
1290 $ids= $config->idepartments;
1291 $d= $ui->get_module_departments($this->module);
1292 $k_ids= array_keys($ids);
1293 $deps= array_intersect($d,$k_ids);
1295 // Fill internal bases list
1296 $this->bases= array();
1297 foreach($k_ids as $department){
1298 $this->bases[$department] = $ids[$department];
1299 }
1300 }
1303 function getDepartments()
1304 {
1305 $departments= array();
1306 $ui= get_userinfo();
1308 // Get list of supported department types
1309 $types = departmentManagement::get_support_departments();
1311 // Load departments allowed by ACL
1312 $validDepartments = $ui->get_module_departments($this->module);
1314 // Build filter and look in the LDAP for possible sub departments
1315 // of current base
1316 $filter= "(&(objectClass=gosaDepartment)(|";
1317 $attrs= array("description", "objectClass");
1318 foreach($types as $name => $data){
1319 $filter.= "(objectClass=".$data['OC'].")";
1320 $attrs[]= $data['ATTR'];
1321 }
1322 $filter.= "))";
1323 $res= get_list($filter, $this->module, $this->base, $attrs, GL_NONE);
1325 // Analyze list of departments
1326 foreach ($res as $department) {
1327 if (!in_array($department['dn'], $validDepartments)) {
1328 continue;
1329 }
1331 // Add the attribute where we use for sorting
1332 $oc= null;
1333 foreach(array_keys($types) as $type) {
1334 if (in_array($type, $department['objectClass'])) {
1335 $oc= $type;
1336 break;
1337 }
1338 }
1339 $department['sort-attribute']= $types[$oc]['ATTR'];
1341 // Move to the result list
1342 $departments[]= $department;
1343 }
1345 return $departments;
1346 }
1349 function renderCopyPasteMenu($separator, $copy= true, $cut= true)
1350 {
1351 // We can only provide information if we've got a copypaste handler
1352 // instance
1353 if(!(isset($this->copyPasteHandler) && is_object($this->copyPasteHandler))){
1354 return "";
1355 }
1357 // Presets
1358 $result= "";
1359 $read= $paste= false;
1360 $ui= get_userinfo();
1362 // Switch flags to on if there's at least one category which allows read/paste
1363 foreach($this->categories as $category){
1364 $read= $read || preg_match('/r/', $ui->get_category_permissions($this->base, $category));
1365 $paste= $paste || $ui->is_pasteable($this->base, $category) == 1;
1366 }
1369 // Draw entries that allow copy and cut
1370 if($read){
1372 // Copy entry
1373 if($copy){
1374 $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>";
1375 $separator= "";
1376 }
1378 // Cut entry
1379 if($cut){
1380 $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>";
1381 $separator= "";
1382 }
1383 }
1385 // Draw entries that allow pasting entries
1386 if($paste){
1387 if($this->copyPasteHandler->entries_queued()){
1388 $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>";
1389 }else{
1390 $result.= "<li$separator><a href='#'><img src='images/lists/paste-grey.png' alt='' border='0' class='center'> "._("Paste")."</a></li>";
1391 }
1392 }
1394 return($result);
1395 }
1398 function renderCopyPasteActions($row, $dn, $category, $class, $copy= true, $cut= true)
1399 {
1400 // We can only provide information if we've got a copypaste handler
1401 // instance
1402 if(!(isset($this->copyPasteHandler) && is_object($this->copyPasteHandler))){
1403 return "";
1404 }
1406 // Presets
1407 $ui = get_userinfo();
1408 $result = "";
1410 // Render cut entries
1411 if($cut){
1412 if($ui->is_cutable($dn, $category, $class)){
1413 $result .= "<input class='center' type='image'
1414 src='images/lists/cut.png' alt='"._("Cut")."' name='listing_cut_$row' title='"._("Cut this entry")."' style='padding:1px'>";
1415 }else{
1416 $result.="<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
1417 }
1418 }
1420 // Render copy entries
1421 if($copy){
1422 if($ui->is_copyable($dn, $category, $class)){
1423 $result.= "<input class='center' type='image'
1424 src='images/lists/copy.png' alt='"._("Copy")."' name='listing_copy_$row' title='"._("Copy this entry")."' style='padding:1px'>";
1425 }else{
1426 $result.="<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
1427 }
1428 }
1430 return($result);
1431 }
1434 function renderSnapshotMenu($separator)
1435 {
1436 // We can only provide information if we've got a snapshot handler
1437 // instance
1438 if(!(isset($this->snapshotHandler) && is_object($this->snapshotHandler))){
1439 return "";
1440 }
1442 // Presets
1443 $result = "";
1444 $ui = get_userinfo();
1446 if($this->snapshotHandler->enabled() && $ui->allow_snapshot_restore($this->base, $this->module)){
1448 // Check if there is something to restore
1449 $restore= false;
1450 foreach($this->snapshotHandler->getSnapshotBases() as $base){
1451 $restore= $restore || count($this->snapshotHandler->getDeletedSnapshots($base)) > 0;
1452 }
1454 // Draw icons according to the restore flag
1455 if($restore){
1456 $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>";
1457 }else{
1458 $result.= "<li$separator><a href='#'><img src='images/lists/restore_grey.png' alt='' border='0' class='center'> "._("Restore snapshots")."</a></li>";
1459 }
1460 }
1462 return($result);
1463 }
1466 function renderExporterMenu($separator)
1467 {
1468 // Presets
1469 $result = "";
1471 // Draw entries
1472 $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'>";
1474 // Export CVS as build in exporter
1475 foreach ($this->exporter as $action => $exporter) {
1476 $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>";
1477 }
1479 // Finalize list
1480 $result.= "</ul></li>";
1482 return($result);
1483 }
1486 function renderSnapshotActions($row, $dn, $category, $class, $copy= true, $cut= true)
1487 {
1488 // We can only provide information if we've got a snapshot handler
1489 // instance
1490 if(!(isset($this->snapshotHandler) && is_object($this->snapshotHandler))){
1491 return "";
1492 }
1494 // Presets
1495 $result= "";
1496 $ui = get_userinfo();
1498 // Only act if enabled here
1499 if($this->snapshotHandler->enabled()){
1501 // Draw restore button
1502 if ($ui->allow_snapshot_restore($dn, $category)){
1504 // Do we have snapshots for this dn?
1505 if($this->snapshotHandler->hasSnapshots($dn)){
1506 $result.= "<input class='center' type='image' src='images/lists/restore.png' ".
1507 "alt='"._("Restore snapshot")."' name='listing_restore_$row' title='".
1508 _("Restore snapshot")."' style='padding:1px'>";
1509 } else {
1510 $result.= "<img src='images/lists/restore_grey.png' alt=' ' class='center' style='padding:1px'>";
1511 }
1512 }
1514 // Draw snapshot button
1515 if($ui->allow_snapshot_create($dn, $category)){
1516 $result.= "<input class='center' type='image' src='images/snapshot.png' ".
1517 "alt='"._("Create snapshot")."' name='listing_snapshot_$row' title='".
1518 _("Create a new snapshot from this object")."' style='padding:1px'>";
1519 }else{
1520 $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
1521 }
1522 }
1524 return($result);
1525 }
1528 function renderDaemonMenu($separator)
1529 {
1530 $result= "";
1532 // If there is a daemon registered, draw the menu entries
1533 if(class_available("DaemonEvent")){
1534 $events= DaemonEvent::get_event_types_by_category($this->categories);
1535 if(isset($events['BY_CLASS']) && count($events['BY_CLASS'])){
1536 foreach($events['BY_CLASS'] as $name => $event){
1537 $result.= "<li$separator><a href='#' onClick='document.getElementById(\"actionmenu\").value=\"$name\";document.getElementById(\"exec_act\").click();'>".$event['MenuImage']." ".$event['s_Menu_Name']."</a></li>";
1538 $separator= "";
1539 }
1540 }
1541 }
1543 return $result;
1544 }
1547 function getEntry($dn)
1548 {
1549 foreach ($this->entries as $entry) {
1550 if (isset($entry['dn']) && strcasecmp($dn, $entry['dn']) == 0){
1551 return $entry;
1552 }
1553 }
1554 return null;
1555 }
1558 function getType($dn)
1559 {
1560 if (isset($this->objectDnMapping[$dn])) {
1561 return $this->objectDnMapping[$dn];
1562 }
1563 return null;
1564 }
1566 }
1568 ?>