9d09f550b34a611f3fb38156424bdf93356929d1
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;
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/Categories
187 $this->headline= _($this->xmlData['definition']['label']);
188 if (!is_array($this->categories)){
189 $this->categories= array($this->categories);
190 }
192 // Evaluate columns to be exported
193 if (isset($this->xmlData['table']['column'])){
194 foreach ($this->xmlData['table']['column'] as $index => $config) {
195 if (isset($config['export']) && $config['export'] == "true"){
196 $this->exportColumns[]= $index;
197 }
198 }
199 }
201 return true;
202 }
205 function renderHeader()
206 {
207 $this->header= array();
208 $this->plainHeader= array();
210 // Initialize sort?
211 $sortInit= false;
212 if (!$this->sortDirection) {
213 $this->sortColumn= 0;
214 if (isset($this->xmlData['definition']['defaultSortColumn'])){
215 $this->sortColumn= $this->xmlData['definition']['defaultSortColumn'];
216 } else {
217 $this->sortAttribute= "";
218 }
219 $this->sortDirection= array();
220 $sortInit= true;
221 }
223 if (isset($this->xmlData['table']['column'])){
224 foreach ($this->xmlData['table']['column'] as $index => $config) {
225 // Initialize everything to one direction
226 if ($sortInit) {
227 $this->sortDirection[$index]= false;
228 }
230 $sorter= "";
231 if ($index == $this->sortColumn && isset($config['sortAttribute']) &&
232 isset($config['sortType'])) {
233 $this->sortAttribute= $config['sortAttribute'];
234 $this->sortType= $config['sortType'];
235 $sorter= " <img border='0' title='".($this->sortDirection[$index]?_("Up"):_("Down"))."' src='images/lists/sort-".($this->sortDirection[$index]?"up":"down").".png' align='top'>";
236 }
237 $sortable= (isset($config['sortAttribute']));
239 $link= "href='?plug=".$_GET['plug']."&PID=".$this->pid."&act=SORT_$index'";
240 if (isset($config['label'])) {
241 if ($sortable) {
242 $this->header[$index]= "<td class='listheader' ".$this->colprops[$index]."><a $link>"._($config['label'])."$sorter</a></td>";
243 } else {
244 $this->header[$index]= "<td class='listheader' ".$this->colprops[$index].">"._($config['label'])."</td>";
245 }
246 $this->plainHeader[]= _($config['label']);
247 } else {
248 if ($sortable) {
249 $this->header[$index]= "<td class='listheader' ".$this->colprops[$index]."><a $link> $sorter</a></td>";
250 } else {
251 $this->header[$index]= "<td class='listheader' ".$this->colprops[$index]."> </td>";
252 }
253 $this->plainHeader[]= "";
254 }
255 }
256 }
257 }
260 function render()
261 {
262 // Check for exeeded sizelimit
263 if (($message= check_sizelimit()) != ""){
264 return($message);
265 }
267 // Some browsers don't have the ability do do scrollable table bodies, filter them
268 // here.
269 $switch= false;
270 if (preg_match('/(Opera|Konqueror|Safari|msie)/i', $_SERVER['HTTP_USER_AGENT'])){
271 $switch= true;
272 }
274 // Initialize list
275 $result= "<input type='hidden' value='$this->pid' name='PID'>\n";
276 $result.= "<input type='hidden' name='position_".$this->pid."' id='position_".$this->pid."'>\n";
277 $height= 450;
278 if ($this->height != 0) {
279 $result.= "<input type='hidden' value='$this->height' id='d_height'>\n";
280 $height= $this->height;
281 }
283 $result.= "<table cellpadding='0' cellspacing='0' border='0'><tr><td><div class='listContainer' id='d_scrollbody' style='border-top:1px solid #B0B0B0;border-right:1px solid #B0B0B0;width:700px;min-height:".($height+25)."px;'>\n";
285 $height= "";
286 if ($switch){
287 $height= "height:100%;";
288 }
289 $result.= "<table summary='$this->headline' style='${height}width:100%; table-layout:fixed;' cellspacing='0' cellpadding='0' id='t_scrolltable'>\n";
290 $this->numColumns= count($this->colprops) + ($this->multiSelect?1:0);
292 // Build list header
293 $result.= "<thead class='fixedListHeader listHeaderFormat'><tr>\n";
294 if ($this->multiSelect) {
295 $width= "24px";
296 if (preg_match('/Konqueror/i', $_SERVER['HTTP_USER_AGENT'])){
297 $width= "28px";
298 }
299 $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";
300 }
301 foreach ($this->header as $header) {
302 $result.= $header;
303 }
304 $result.= "</tr></thead>\n";
306 // Build list body
307 $result.= "<tbody class='listScrollContent listBodyFormat' id='t_nscrollbody' style='height:".$height."px;'>\n";
309 // No results? Just take an empty colspanned row
310 if (count($this->entries) + count($this->departments) == 0) {
311 $result.= "<tr class='rowxp0'><td class='list1nohighlight' colspan='$this->numColumns' style='height:100%;border-right:0px;width:100%;'> </td></tr>";
312 }
314 // Line color alternation
315 $alt= 0;
316 $deps= 0;
318 // Draw department browser if configured and we're not in sub mode
319 $this->useSpan= false;
320 if ($this->departmentBrowser && $this->filter->scope != "sub") {
321 // Fill with department browser if configured this way
322 $departmentIterator= new departmentSortIterator($this->departments, $this->sortDirection[$this->sortColumn]);
323 foreach ($departmentIterator as $row => $entry){
324 $result.="<tr class='rowxp".($alt&1)."'>";
326 // Render multi select if needed
327 if ($this->multiSelect) {
328 $result.="<td style='text-align:center;padding:0;' class='list1'> </td>";
329 }
331 // Render defined department columns, fill the rest with some stuff
332 $rest= $this->numColumns - 1;
333 foreach ($this->xmlData['table']['department'] as $index => $config) {
334 $colspan= 1;
335 if (isset($config['span'])){
336 $colspan= $config['span'];
337 $this->useSpan= true;
338 }
339 $result.="<td colspan='$colspan' ".$this->colprops[$index]." class='list1'>".$this->renderCell($config['value'], $entry, $row)."</td>";
340 $rest-= $colspan;
341 }
343 // Fill remaining cols with nothing
344 $last= $this->numColumns - $rest;
345 for ($i= 0; $i<$rest; $i++){
346 $result.= "<td ".$this->colprops[$last+$i-1]." class='list1'> </td>";
347 }
348 $result.="</tr>";
350 $alt++;
351 }
352 $deps= $alt;
353 }
355 // Fill with contents, sort as configured
356 foreach ($this->entries as $row => $entry) {
357 $trow= "";
359 // Render multi select if needed
360 if ($this->multiSelect) {
361 $trow.="<td style='text-align:center;width:20px;' class='list0'><input type='checkbox' id='listing_selected_$row' name='listing_selected_$row'></td>\n";
362 }
364 foreach ($this->xmlData['table']['column'] as $index => $config) {
365 $renderedCell= $this->renderCell($config['value'], $entry, $row);
366 $trow.="<td ".$this->colprops[$index]." class='list0'>".$renderedCell."</td>\n";
368 // Save rendered column
369 $sort= preg_replace('/.*>([^<]+)<.*$/', '$1', $renderedCell);
370 $sort= preg_replace('/ /', '', $sort);
371 if (preg_match('/</', $sort)){
372 $sort= "";
373 }
374 $this->entries[$row]["_sort$index"]= $sort;
375 }
377 // Save rendered entry
378 $this->entries[$row]['_rendered']= $trow;
379 }
381 // Complete list by sorting entries for _sort$index and appending them to the output
382 $entryIterator= new listingSortIterator($this->entries, $this->sortDirection[$this->sortColumn], "_sort".$this->sortColumn, $this->sortType);
383 foreach ($entryIterator as $row => $entry){
384 $alt++;
385 $result.="<tr class='rowxp".($alt&1)."'>\n";
386 $result.= $entry['_rendered'];
387 $result.="</tr>\n";
388 }
390 // Need to fill the list if it's not full (nobody knows why this is 22 ;-))
391 $emptyListStyle= (count($this->entries) + (($this->useSpan && count($this->entries))?$deps:0) == 0)?"border:0;":"";
392 if ((count($this->entries) + $deps) < 22) {
393 $result.= "<tr>";
394 for ($i= 0; $i<$this->numColumns; $i++) {
395 if ($i == 0) {
396 $result.= "<td class='list1nohighlight' style='$emptyListStyle height:100%;'> </td>";
397 continue;
398 }
399 if ($i != $this->numColumns-1) {
400 $result.= "<td class='list1nohighlight' style='$emptyListStyle'> </td>";
401 } else {
402 $result.= "<td class='list1nohighlight' style='border-right:0;$emptyListStyle'> </td>";
403 }
404 }
405 $result.= "</tr>";
406 }
408 // Close list body
409 $result.= "</tbody></table></div></td></tr>";
411 // Add the footer if requested
412 if ($this->showFooter) {
413 $result.= "<tr><td class='nlistFooter'>";
415 foreach ($this->objectTypes as $objectType) {
416 if (isset($this->objectTypeCount[$objectType['label']])) {
417 $label= _($objectType['label']);
418 $result.= "<img class='center' src='".$objectType['image']."' title='$label' alt='$label'> ".$this->objectTypeCount[$objectType['label']]." ";
419 }
420 }
422 $result.= "</td></tr>";
423 }
425 // Close list
426 $result.= "</table>";
427 $result.= $switch?"<input type='hidden' id='list_workaround'>":"";
429 // Add scroll positioner
430 $result.= '<script type="text/javascript" language="javascript">';
431 $result.= '$("t_nscrollbody").scrollTop= '.$this->scrollPosition.';';
432 $result.= 'var box = $("t_nscrollbody").onscroll= function() {$("position_'.$this->pid.'").value= this.scrollTop;}';
433 $result.= '</script>';
435 $smarty= get_smarty();
436 $smarty->assign("usePrototype", "true");
437 $smarty->assign("FILTER", $this->filter->render());
438 $smarty->assign("SIZELIMIT", print_sizelimit_warning());
439 $smarty->assign("LIST", $result);
441 // Assign navigation elements
442 $nav= $this->renderNavigation();
443 foreach ($nav as $key => $html) {
444 $smarty->assign($key, $html);
445 }
447 // Assign action menu / base
448 $smarty->assign("ACTIONS", $this->renderActionMenu());
449 $smarty->assign("BASE", $this->renderBase());
451 // Assign separator
452 $smarty->assign("SEPARATOR", "<img src='images/lists/seperator.png' alt='-' align='middle' height='16' width='1' class='center'>");
454 // Assign summary
455 $smarty->assign("HEADLINE", $this->headline);
457 // Try to load template from plugin the folder first...
458 $file = get_template_path($this->xmlData['definition']['template'], true);
460 // ... if this fails, try to load the file from the theme folder.
461 if(!file_exists($file)){
462 $file = get_template_path($this->xmlData['definition']['template']);
463 }
465 return ($smarty->fetch($file));
466 }
469 function update()
470 {
471 global $config;
472 $ui= get_userinfo();
474 // Reset object counter / DN mapping
475 $this->objectTypeCount= array();
476 $this->objectDnMapping= array();
478 // Do not do anything if this is not our PID
479 if(!(isset($_REQUEST['PID']) && $_REQUEST['PID'] != $this->pid)) {
481 // Save position if set
482 if (isset($_POST['position_'.$this->pid]) && is_numeric($_POST['position_'.$this->pid])) {
483 $this->scrollPosition= $_POST['position_'.$this->pid];
484 }
486 // Save base
487 if (isset($_POST['BASE']) && $this->baseMode) {
488 $base= base64_decode(get_post('BASE'));
489 if (isset($this->bases[$base])) {
490 $this->base= $base;
491 session::global_set("CurrentMainBase", $this->base);
492 }
493 }
495 // Override the base if we got a message from the browser navigation
496 if ($this->departmentBrowser && isset($_GET['act'])) {
497 if (preg_match('/^department_([0-9]+)$/', validate($_GET['act']), $match)){
498 if (isset($this->departments[$match[1]])){
499 $this->base= $this->departments[$match[1]]['dn'];
500 session::global_set("CurrentMainBase", $this->base);
501 }
502 }
503 }
505 // Filter POST with "act" attributes -> posted from action menu
506 if (isset($_POST['exec_act']) && $_POST['act'] != '') {
507 if (preg_match('/^export.*$/', $_POST['act']) && isset($this->exporter[$_POST['act']])) {
508 $exporter= $this->exporter[$_POST['act']];
509 $userinfo= ", "._("created by")." ".$ui->cn." - ".strftime('%A, %d. %B %Y, %H:%M:%S');
510 $entryIterator= new listingSortIterator($this->entries, $this->sortDirection[$this->sortColumn], "_sort".$this->sortColumn, $this->sortType);
511 $sortedEntries= array();
512 foreach ($entryIterator as $entry){
513 $sortedEntries[]= $entry;
514 }
515 $instance= new $exporter['class']($this->headline.$userinfo, $this->plainHeader, $sortedEntries, $this->exportColumns);
516 $type= call_user_func(array($exporter['class'], "getInfo"));
517 $type= $type[$_POST['act']];
518 send_binary_content($instance->query(), $type['filename'], $type= $type['mime']);
519 }
520 }
522 // Filter GET with "act" attributes
523 if (isset($_GET['act'])) {
524 $key= validate($_GET['act']);
525 if (preg_match('/^SORT_([0-9]+)$/', $key, $match)) {
526 // Switch to new column or invert search order?
527 $column= $match[1];
528 if ($this->sortColumn != $column) {
529 $this->sortColumn= $column;
530 } else {
531 $this->sortDirection[$column]= !$this->sortDirection[$column];
532 }
534 // Allow header to update itself according to the new sort settings
535 $this->renderHeader();
536 }
537 }
539 // Override base if we got signals from the navigation elements
540 $action= "";
541 foreach ($_POST as $key => $value) {
542 if (preg_match('/^(ROOT|BACK|HOME)_x$/', $key, $match)) {
543 $action= $match[1];
544 break;
545 }
546 }
548 // Navigation handling
549 if ($action == 'ROOT') {
550 $deps= $ui->get_module_departments($this->categories);
551 $this->base= $deps[0];
552 }
553 if ($action == 'BACK') {
554 $deps= $ui->get_module_departments($this->categories);
555 $base= preg_replace("/^[^,]+,/", "", $this->base);
556 if(in_array_ics($base, $deps)){
557 $this->base= $base;
558 }
559 }
560 if ($action == 'HOME') {
561 $ui= get_userinfo();
562 $this->base= $this->filter->getObjectBase($ui->dn);
563 }
564 }
566 // Reload departments
567 if ($this->departmentBrowser){
568 $this->departments= $this->getDepartments();
569 }
571 // Update filter and refresh entries
572 $this->filter->setBase($this->base);
573 $this->entries= $this->filter->query();
575 // Fix filter if querie returns NULL
576 if ($this->entries == null) {
577 $this->entries= array();
578 }
579 }
582 function setBase($base)
583 {
584 $this->base= $base;
585 }
588 function getBase()
589 {
590 return $this->base;
591 }
594 function parseLayout($layout)
595 {
596 $result= array();
597 $layout= preg_replace("/^\|/", "", $layout);
598 $layout= preg_replace("/\|$/", "", $layout);
599 $cols= split("\|", $layout);
601 foreach ($cols as $index => $config) {
602 if ($config != "") {
603 $res= "";
604 $components= split(';', $config);
605 foreach ($components as $part) {
606 if (preg_match("/^r$/", $part)) {
607 $res.= "text-align:right;";
608 continue;
609 }
610 if (preg_match("/^l$/", $part)) {
611 $res.= "text-align:left;";
612 continue;
613 }
614 if (preg_match("/^c$/", $part)) {
615 $res.= "text-align:center;";
616 continue;
617 }
618 if (preg_match("/^[0-9]+(|px|%)$/", $part)) {
619 $res.= "width:$part;min-width:$part;";
620 continue;
621 }
622 }
624 // Add minimum width for scalable columns
625 if (!preg_match('/width:/', $res)){
626 $res.= "min-width:200px;";
627 }
629 $result[$index]= " style='$res'";
630 } else {
631 $result[$index]= " style='min-width:100px;'";
632 }
633 }
635 // Save number of columns for later use
636 $this->numColumns= count($cols);
638 // Add no border to the last column
639 $result[$this->numColumns-1]= preg_replace("/'$/", "border-right:0;'", $result[$this->numColumns-1]);
641 return $result;
642 }
645 function renderCell($data, $config, $row)
646 {
647 // Replace flat attributes in data string
648 for ($i= 0; $i<$config['count']; $i++) {
649 $attr= $config[$i];
650 $value= "";
651 if (is_array($config[$attr])) {
652 $value= $config[$attr][0];
653 } else {
654 $value= $config[$attr];
655 }
656 $data= preg_replace("/%\{$attr\}/", $value, $data);
657 }
659 // Watch out for filters and prepare to execute them
660 $data= $this->processElementFilter($data, $config, $row);
662 // Replace all non replaced %{...} instances because they
663 // are non resolved attributes or filters
664 $data= preg_replace('/%{[^}]+}/', ' ', $data);
666 return $data;
667 }
670 function renderBase()
671 {
672 if (!$this->baseMode) {
673 return;
674 }
676 $result= "<select name='BASE' onChange='mainform.submit()' size='1'>";
677 $firstDN= null;
678 $found= false;
679 foreach ($this->bases as $key=>$value) {
680 // Keep first entry to fall back eventually
681 if(!$firstDN) {
682 $firstDN= $key;
683 }
685 // Prepare to render entry
686 $selected= "";
687 if ($key == $this->base) {
688 $selected= " selected";
689 $found= true;
690 }
691 // Encode key in b64 to avoid strange characters
692 $result.= "\n<option value=\"".base64_encode($key)."\"$selected>".$value."</option>";
693 }
695 $result.= "</select>";
697 // Reset the currently used base to the first DN we found if there
698 // was no match.
699 if(!$found){
700 $this->base = $firstDN;
701 }
703 return $result;
704 }
707 function processElementFilter($data, $config, $row)
708 {
709 preg_match_all("/%\{filter:([^(]+)\((.*)\)\}/", $data, $matches, PREG_SET_ORDER);
711 foreach ($matches as $match) {
712 $cl= "";
713 $method= "";
714 if (preg_match('/::/', $match[1])) {
715 $cl= preg_replace('/::.*$/', '', $match[1]);
716 $method= preg_replace('/^.*::/', '', $match[1]);
717 } else {
718 if (!isset($this->filters[$match[1]])) {
719 continue;
720 }
721 $cl= preg_replace('/::.*$/', '', $this->filters[$match[1]]);
722 $method= preg_replace('/^.*::/', '', $this->filters[$match[1]]);
723 }
725 // Prepare params for function call
726 $params= array();
727 preg_match_all('/"[^"]+"|[^,]+/', $match[2], $parts);
728 foreach ($parts[0] as $param) {
730 // Row is replaced by the row number
731 if ($param == "row") {
732 $params[]= $row;
733 continue;
734 }
736 // pid is replaced by the current PID
737 if ($param == "pid") {
738 $params[]= $this->pid;
739 continue;
740 }
742 // base is replaced by the current base
743 if ($param == "base") {
744 $params[]= $this->getBase();
745 continue;
746 }
748 // Fixie with "" is passed directly
749 if (preg_match('/^".*"$/', $param)){
750 $params[]= preg_replace('/"/', '', $param);
751 continue;
752 }
754 // Move dn if needed
755 if ($param == "dn") {
756 $params[]= LDAP::fix($config["dn"]);
757 continue;
758 }
760 // LDAP variables get replaced by their objects
761 for ($i= 0; $i<$config['count']; $i++) {
762 if ($param == $config[$i]) {
763 $values= $config[$config[$i]];
764 if (is_array($values)){
765 unset($values['count']);
766 }
767 $params[]= $values;
768 break;
769 }
770 }
771 }
773 // Replace information
774 if ($cl == "listing") {
775 // Non static call - seems to result in errors
776 $data= @preg_replace('/'.preg_quote($match[0]).'/', call_user_func_array(array($this, "$method"), $params), $data);
777 } else {
778 // Static call
779 $data= preg_replace('/'.preg_quote($match[0]).'/', call_user_func_array(array($cl, $method), $params), $data);
780 }
781 }
783 return $data;
784 }
787 function getObjectType($types, $classes)
788 {
789 // Walk thru types and see if there's something matching
790 foreach ($types as $objectType) {
791 $ocs= $objectType['objectClass'];
792 if (!is_array($ocs)){
793 $ocs= array($ocs);
794 }
796 $found= true;
797 foreach ($ocs as $oc){
798 if (preg_match('/^!(.*)$/', $oc, $match)) {
799 $oc= $match[1];
800 if (in_array($oc, $classes)) {
801 $found= false;
802 }
803 } else {
804 if (!in_array($oc, $classes)) {
805 $found= false;
806 }
807 }
808 }
810 if ($found) {
811 return $objectType;
812 }
813 }
815 return null;
816 }
819 function filterObjectType($dn, $classes)
820 {
821 // Walk thru classes and return on first match
822 $result= " ";
824 $objectType= $this->getObjectType($this->objectTypes, $classes);
825 if ($objectType) {
826 $this->objectDnMapping[$dn]= $objectType["objectClass"];
827 $result= "<img class='center' title='".LDAP::fix($dn)."' src='".$objectType["image"]."'>";
828 if (!isset($this->objectTypeCount[$objectType['label']])) {
829 $this->objectTypeCount[$objectType['label']]= 0;
830 }
831 $this->objectTypeCount[$objectType['label']]++;
832 }
834 return $result;
835 }
838 function filterActions($dn, $row, $classes)
839 {
840 // Do nothing if there's no menu defined
841 if (!isset($this->xmlData['actiontriggers']['action'])) {
842 return " ";
843 }
845 // Go thru all actions
846 $result= "";
847 $actions= $this->xmlData['actiontriggers']['action'];
848 foreach($actions as $action) {
849 // Skip the entry completely if there's no permission to execute it
850 if (!$this->hasActionPermission($action, $dn, $classes)) {
851 $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
852 continue;
853 }
855 // Skip entry if the pseudo filter does not fit
856 if (isset($action['filter']) && preg_match('/^[a-z0-9_]+!?=[a-z0-9_]+$/i', $action['filter'])) {
857 list($fa, $fv)= split('=', $action['filter']);
858 if (preg_match('/^(.*)!$/', $fa, $m)){
859 $fa= $m[1];
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 } else {
865 if (!isset($this->entries[$row][$fa]) && !$this->entries[$row][$fa][0] == $fv) {
866 $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
867 continue;
868 }
869 }
870 }
873 // If there's an objectclass definition and we don't have it
874 // add an empty picture here.
875 if (isset($action['objectclass'])){
876 $objectclass= $action['objectclass'];
877 if (preg_match('/^!(.*)$/', $objectclass, $m)){
878 $objectclass= $m[1];
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_string($objectclass)) {
884 if(!in_array($objectclass, $classes)) {
885 $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
886 continue;
887 }
888 } elseif (is_array($objectclass)) {
889 if(count(array_intersect($objectclass, $classes)) != count($objectclass)){
890 $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
891 continue;
892 }
893 }
894 }
896 // Render normal entries as usual
897 if ($action['type'] == "entry") {
898 $label= $this->processElementFilter($action['label'], $this->entries[$row], $row);
899 $image= $this->processElementFilter($action['image'], $this->entries[$row], $row);
900 $result.="<input class='center' type='image' src='$image' title='$label' ".
901 "name='listing_".$action['name']."_$row' style='padding:1px'>";
902 }
904 // Handle special types
905 if ($action['type'] == "copypaste" || $action['type'] == "snapshot") {
907 $objectType= $this->getObjectType($this->objectTypes, $this->entries[$row]['objectClass']);
908 $category= $class= null;
909 if ($objectType) {
910 $category= $objectType['category'];
911 $class= $objectType['class'];
912 }
914 if ($action['type'] == "copypaste") {
915 $copy = !isset($action['copy']) || $action['copy'] == "true";
916 $cut = !isset($action['cut']) || $action['cut'] == "true";
917 $result.= $this->renderCopyPasteActions($row, $this->entries[$row]['dn'], $category, $class,$copy,$cut);
918 } else {
919 $result.= $this->renderSnapshotActions($row, $this->entries[$row]['dn'], $category, $class);
920 }
921 }
922 }
924 return $result;
925 }
928 function filterDepartmentLink($row, $dn, $description)
929 {
930 $attr= $this->departments[$row]['sort-attribute'];
931 $name= $this->departments[$row][$attr];
932 if (is_array($name)){
933 $name= $name[0];
934 }
935 $result= sprintf("%s [%s]", $name, $description[0]);
936 return("<a href='?plug=".$_GET['plug']."&PID=$this->pid&act=department_$row' title='$dn'>$result</a>");
937 }
940 function filterLink()
941 {
942 $result= " ";
944 $row= func_get_arg(0);
945 $pid= $this->pid;
946 $dn= LDAP::fix(func_get_arg(1));
947 $params= array(func_get_arg(2));
949 // Collect sprintf params
950 for ($i = 3;$i < func_num_args();$i++) {
951 $val= func_get_arg($i);
952 if (is_array($val)){
953 $params[]= $val[0];
954 continue;
955 }
956 $params[]= $val;
957 }
959 $result= " ";
960 $trans= call_user_func_array("sprintf", $params);
961 if ($trans != "") {
962 return("<a href='?plug=".$_GET['plug']."&PID=$pid&act=listing_edit_$row' title='$dn'>$trans</a>");
963 }
965 return $result;
966 }
969 function renderNavigation()
970 {
971 $result= array();
972 $enableBack = true;
973 $enableRoot = true;
974 $enableHome = true;
976 $ui = get_userinfo();
978 /* Check if base = first available base */
979 $deps = $ui->get_module_departments($this->categories);
981 if(!count($deps) || $deps[0] == $this->filter->base){
982 $enableBack = false;
983 $enableRoot = false;
984 }
986 $listhead ="";
988 /* Check if we are in users home department */
989 if(!count($deps) || $this->filter->base == $this->filter->getObjectBase($ui->dn)){
990 $enableHome = false;
991 }
993 /* Draw root button */
994 if($enableRoot){
995 $result["ROOT"]= "<input class='center' type='image' src='images/lists/root.png' align='middle' ".
996 "title='"._("Go to root department")."' name='ROOT' alt='"._("Root")."'>";
997 }else{
998 $result["ROOT"]= "<img src='images/lists/root_grey.png' class='center' alt='"._("Root")."'>";
999 }
1001 /* Draw back button */
1002 if($enableBack){
1003 $result["BACK"]= "<input class='center' type='image' align='middle' src='images/lists/back.png' ".
1004 "title='"._("Go up one department")."' alt='"._("Up")."' name='BACK'>";
1005 }else{
1006 $result["BACK"]= "<img src='images/lists/back_grey.png' class='center' alt='"._("Up")."'>";
1007 }
1009 /* Draw home button */
1010 if($enableHome){
1011 $result["HOME"]= "<input class='center' type='image' align='middle' src='images/lists/home.png' ".
1012 "title='"._("Go to users department")."' alt='"._("Home")."' name='HOME'>";
1013 }else{
1014 $result["HOME"]= "<img src='images/lists/home_grey.png' class='center' alt='"._("Home")."'>";
1015 }
1017 /* Draw reload button, this button is enabled everytime */
1018 $result["RELOAD"]= "<input class='center' type='image' src='images/lists/reload.png' align='middle' ".
1019 "title='"._("Reload list")."' name='REFRESH' alt='"._("Submit")."'>";
1021 return ($result);
1022 }
1025 function getAction()
1026 {
1027 // Do not do anything if this is not our PID, or there's even no PID available...
1028 if(!isset($_REQUEST['PID']) || $_REQUEST['PID'] != $this->pid) {
1029 return;
1030 }
1032 // Save position if set
1033 if (isset($_POST['position_'.$this->pid]) && is_numeric($_POST['position_'.$this->pid])) {
1034 $this->scrollPosition= $_POST['position_'.$this->pid];
1035 }
1037 $result= array("targets" => array(), "action" => "");
1039 // Filter GET with "act" attributes
1040 if (isset($_GET['act'])) {
1041 $key= validate($_GET['act']);
1042 $target= preg_replace('/^listing_[a-zA-Z_]+_([0-9]+)$/', '$1', $key);
1043 if (isset($this->entries[$target]['dn'])) {
1044 $result['action']= preg_replace('/^listing_([a-zA-Z_]+)_[0-9]+$/', '$1', $key);
1045 $result['targets'][]= $this->entries[$target]['dn'];
1046 }
1048 // Drop targets if empty
1049 if (count($result['targets']) == 0) {
1050 unset($result['targets']);
1051 }
1052 return $result;
1053 }
1055 // Filter POST with "listing_" attributes
1056 foreach ($_POST as $key => $prop) {
1058 // Capture selections
1059 if (preg_match('/^listing_selected_[0-9]+$/', $key)) {
1060 $target= preg_replace('/^listing_selected_([0-9]+)$/', '$1', $key);
1061 if (isset($this->entries[$target]['dn'])) {
1062 $result['targets'][]= $this->entries[$target]['dn'];
1063 }
1064 continue;
1065 }
1067 // Capture action with target - this is a one shot
1068 if (preg_match('/^listing_[a-zA-Z_]+_[0-9]+(|_x)$/', $key)) {
1069 $target= preg_replace('/^listing_[a-zA-Z_]+_([0-9]+)(|_x)$/', '$1', $key);
1070 if (isset($this->entries[$target]['dn'])) {
1071 $result['action']= preg_replace('/^listing_([a-zA-Z_]+)_[0-9]+(|_x)$/', '$1', $key);
1072 $result['targets']= array($this->entries[$target]['dn']);
1073 }
1074 break;
1075 }
1077 // Capture action without target
1078 if (preg_match('/^listing_[a-zA-Z_]+(|_x)$/', $key)) {
1079 $result['action']= preg_replace('/^listing_([a-zA-Z_]+)(|_x)$/', '$1', $key);
1080 continue;
1081 }
1082 }
1084 // Filter POST with "act" attributes -> posted from action menu
1085 if (isset($_POST['act']) && $_POST['act'] != '') {
1086 if (!preg_match('/^export.*$/', $_POST['act'])){
1087 $result['action']= validate($_POST['act']);
1088 }
1089 }
1091 // Drop targets if empty
1092 if (count($result['targets']) == 0) {
1093 unset($result['targets']);
1094 }
1095 return $result;
1096 }
1099 function renderActionMenu()
1100 {
1101 // Don't send anything if the menu is not defined
1102 if (!isset($this->xmlData['actionmenu']['action'])){
1103 return "";
1104 }
1106 // Array?
1107 if (isset($this->xmlData['actionmenu']['action']['type'])){
1108 $this->xmlData['actionmenu']['action']= array($this->xmlData['actionmenu']['action']);
1109 }
1111 // Load shortcut
1112 $actions= &$this->xmlData['actionmenu']['action'];
1113 $result= "<input type='hidden' name='act' id='actionmenu' value=''><div style='display:none'><input type='submit' name='exec_act' id='exec_act' value=''></div>".
1114 "<ul class='level1' id='root'><li><a href='#'>"._("Actions")." <img ".
1115 "border=0 class='center' src='images/lists/sort-down.png'></a>";
1117 // Build ul/li list
1118 $result.= $this->recurseActions($actions);
1120 return "<div id='pulldown'>".$result."</li></ul><div>";
1121 }
1124 function recurseActions($actions)
1125 {
1126 global $class_mapping;
1127 static $level= 2;
1128 $result= "<ul class='level$level'>";
1129 $separator= "";
1131 foreach ($actions as $action) {
1133 // Skip the entry completely if there's no permission to execute it
1134 if (!$this->hasActionPermission($action, $this->filter->base)) {
1135 continue;
1136 }
1138 // Skip entry if there're missing dependencies
1139 if (isset($action['depends'])) {
1140 $deps= is_array($action['depends'])?$action['depends']:array($action['depends']);
1141 foreach($deps as $clazz) {
1142 if (!isset($class_mapping[$clazz])){
1143 continue 2;
1144 }
1145 }
1146 }
1148 // Fill image if set
1149 $img= "";
1150 if (isset($action['image'])){
1151 $img= "<img border='0' class='center' src='".$action['image']."'> ";
1152 }
1154 if ($action['type'] == "separator"){
1155 $separator= " style='border-top:1px solid #AAA' ";
1156 continue;
1157 }
1159 // Dive into subs
1160 if ($action['type'] == "sub" && isset($action['action'])) {
1161 $level++;
1162 if (isset($action['label'])){
1163 $result.= "<li$separator><a href='#'>$img"._($action['label'])." <img border='0' src='images/forward-arrow.png'></a>";
1164 }
1166 // Ensure we've an array of actions, this enables sub menus with only one action.
1167 if(isset($action['action']['type'])){
1168 $action['action'] = array($action['action']);
1169 }
1171 $result.= $this->recurseActions($action['action'])."</li>";
1172 $level--;
1173 $separator= "";
1174 continue;
1175 }
1177 // Render entry elseways
1178 if (isset($action['label'])){
1179 $result.= "<li$separator><a href='#' onClick='document.getElementById(\"actionmenu\").value= \"".$action['name']."\";mainform.submit();'>$img"._($action['label'])."</a></li>";
1180 }
1182 // Check for special types
1183 switch ($action['type']) {
1184 case 'copypaste':
1185 $cut = !isset($action['cut']) || $action['cut'] != "false";
1186 $copy = !isset($action['copy']) || $action['copy'] != "false";
1187 $result.= $this->renderCopyPasteMenu($separator, $copy , $cut);
1188 break;
1190 case 'snapshot':
1191 $result.= $this->renderSnapshotMenu($separator);
1192 break;
1194 case 'exporter':
1195 $result.= $this->renderExporterMenu($separator);
1196 break;
1198 case 'daemon':
1199 $result.= $this->renderDaemonMenu($separator);
1200 break;
1201 }
1203 $separator= "";
1204 }
1206 $result.= "</ul>";
1207 return $result;
1208 }
1211 function hasActionPermission($action, $dn, $classes= null)
1212 {
1213 $ui= get_userinfo();
1215 if (isset($action['acl'])) {
1216 $acls= $action['acl'];
1217 if (!is_array($acls)) {
1218 $acls= array($acls);
1219 }
1221 // Every ACL has to pass
1222 foreach ($acls as $acl) {
1223 $module= $this->categories;
1224 $aclList= array();
1226 // Replace %acl if available
1227 if ($classes) {
1228 $otype= $this->getObjectType($this->objectTypes, $classes);
1229 $acl= str_replace('%acl', $otype['category']."/".$otype['class'], $acl);
1230 }
1232 // Split for category and plugins if needed
1233 // match for "[rw]" style entries
1234 if (preg_match('/^\[([rwcdm]+)\]$/', $acl, $match)){
1235 $aclList= array($match[1]);
1236 }
1238 // match for "users[rw]" style entries
1239 if (preg_match('/^([a-zA-Z0-9]+)\[([rwcdm]+)\]$/', $acl, $match)){
1240 $module= $match[1];
1241 $aclList= array($match[2]);
1242 }
1244 // match for "users/user[rw]" style entries
1245 if (preg_match('/^([a-zA-Z0-9]+\/[a-zA-Z0-9]+)\[([rwcdm]+)\]$/', $acl, $match)){
1246 $module= $match[1];
1247 $aclList= array($match[2]);
1248 }
1250 // match "users/user[userPassword:rw(,...)*]" style entries
1251 if (preg_match('/^([a-zA-Z0-9]+\/[a-zA-Z0-9]+)\[([a-zA-Z0-9]+:[rwcdm]+(,[a-zA-Z0-9]+:[rwcdm]+)*)\]$/', $acl, $match)){
1252 $module= $match[1];
1253 $aclList= split(',', $match[2]);
1254 }
1256 // Walk thru prepared ACL by using $module
1257 foreach($aclList as $sAcl) {
1258 $checkAcl= "";
1260 // Category or detailed permission?
1261 if (strpos('/', $module) === false) {
1262 if (preg_match('/([a-zA-Z0-9]+):([rwcdm]+)/', $sAcl, $m) ) {
1263 $checkAcl= $ui->get_permissions($dn, $module, $m[1]);
1264 $sAcl= $m[2];
1265 } else {
1266 $checkAcl= $ui->get_permissions($dn, $module, '0');
1267 }
1268 } else {
1269 $checkAcl= $ui->get_category_permissions($dn, $module);
1270 }
1272 // Split up remaining part of the acl and check if it we're
1273 // allowed to do something...
1274 $parts= str_split($sAcl);
1275 foreach ($parts as $part) {
1276 if (strpos($checkAcl, $part) === false){
1277 return false;
1278 }
1279 }
1281 }
1282 }
1283 }
1285 return true;
1286 }
1289 function refreshBasesList()
1290 {
1291 global $config;
1292 $ui= get_userinfo();
1294 // Do some array munching to get it user friendly
1295 $ids= $config->idepartments;
1296 $d= $ui->get_module_departments($this->categories);
1297 $k_ids= array_keys($ids);
1298 $deps= array_intersect($d,$k_ids);
1300 // Fill internal bases list
1301 $this->bases= array();
1302 foreach($k_ids as $department){
1303 $this->bases[$department] = $ids[$department];
1304 }
1305 }
1308 function getDepartments()
1309 {
1310 $departments= array();
1311 $ui= get_userinfo();
1313 // Get list of supported department types
1314 $types = departmentManagement::get_support_departments();
1316 // Load departments allowed by ACL
1317 $validDepartments = $ui->get_module_departments($this->categories);
1319 // Build filter and look in the LDAP for possible sub departments
1320 // of current base
1321 $filter= "(&(objectClass=gosaDepartment)(|";
1322 $attrs= array("description", "objectClass");
1323 foreach($types as $name => $data){
1324 $filter.= "(objectClass=".$data['OC'].")";
1325 $attrs[]= $data['ATTR'];
1326 }
1327 $filter.= "))";
1328 $res= get_list($filter, $this->categories, $this->base, $attrs, GL_NONE);
1330 // Analyze list of departments
1331 foreach ($res as $department) {
1332 if (!in_array($department['dn'], $validDepartments)) {
1333 continue;
1334 }
1336 // Add the attribute where we use for sorting
1337 $oc= null;
1338 foreach(array_keys($types) as $type) {
1339 if (in_array($type, $department['objectClass'])) {
1340 $oc= $type;
1341 break;
1342 }
1343 }
1344 $department['sort-attribute']= $types[$oc]['ATTR'];
1346 // Move to the result list
1347 $departments[]= $department;
1348 }
1350 return $departments;
1351 }
1354 function renderCopyPasteMenu($separator, $copy= true, $cut= true)
1355 {
1356 // We can only provide information if we've got a copypaste handler
1357 // instance
1358 if(!(isset($this->copyPasteHandler) && is_object($this->copyPasteHandler))){
1359 return "";
1360 }
1362 // Presets
1363 $result= "";
1364 $read= $paste= false;
1365 $ui= get_userinfo();
1367 // Switch flags to on if there's at least one category which allows read/paste
1368 foreach($this->categories as $category){
1369 $read= $read || preg_match('/r/', $ui->get_category_permissions($this->base, $category));
1370 $paste= $paste || $ui->is_pasteable($this->base, $category) == 1;
1371 }
1374 // Draw entries that allow copy and cut
1375 if($read){
1377 // Copy entry
1378 if($copy){
1379 $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>";
1380 $separator= "";
1381 }
1383 // Cut entry
1384 if($cut){
1385 $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>";
1386 $separator= "";
1387 }
1388 }
1390 // Draw entries that allow pasting entries
1391 if($paste){
1392 if($this->copyPasteHandler->entries_queued()){
1393 $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>";
1394 }else{
1395 $result.= "<li$separator><a href='#'><img src='images/lists/paste-grey.png' alt='' border='0' class='center'> "._("Paste")."</a></li>";
1396 }
1397 }
1399 return($result);
1400 }
1403 function renderCopyPasteActions($row, $dn, $category, $class, $copy= true, $cut= true)
1404 {
1405 // We can only provide information if we've got a copypaste handler
1406 // instance
1407 if(!(isset($this->copyPasteHandler) && is_object($this->copyPasteHandler))){
1408 return "";
1409 }
1411 // Presets
1412 $ui = get_userinfo();
1413 $result = "";
1415 // Render cut entries
1416 if($cut){
1417 if($ui->is_cutable($dn, $category, $class)){
1418 $result .= "<input class='center' type='image'
1419 src='images/lists/cut.png' alt='"._("Cut")."' name='listing_cut_$row' title='"._("Cut this entry")."' style='padding:1px'>";
1420 }else{
1421 $result.="<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
1422 }
1423 }
1425 // Render copy entries
1426 if($copy){
1427 if($ui->is_copyable($dn, $category, $class)){
1428 $result.= "<input class='center' type='image'
1429 src='images/lists/copy.png' alt='"._("Copy")."' name='listing_copy_$row' title='"._("Copy this entry")."' style='padding:1px'>";
1430 }else{
1431 $result.="<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
1432 }
1433 }
1435 return($result);
1436 }
1439 function renderSnapshotMenu($separator)
1440 {
1441 // We can only provide information if we've got a snapshot handler
1442 // instance
1443 if(!(isset($this->snapshotHandler) && is_object($this->snapshotHandler))){
1444 return "";
1445 }
1447 // Presets
1448 $result = "";
1449 $ui = get_userinfo();
1451 if($this->snapshotHandler->enabled() && $ui->allow_snapshot_restore($this->base, $this->categories)){
1453 // Check if there is something to restore
1454 $restore= false;
1455 foreach($this->snapshotHandler->getSnapshotBases() as $base){
1456 $restore= $restore || count($this->snapshotHandler->getDeletedSnapshots($base)) > 0;
1457 }
1459 // Draw icons according to the restore flag
1460 if($restore){
1461 $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>";
1462 }else{
1463 $result.= "<li$separator><a href='#'><img src='images/lists/restore_grey.png' alt='' border='0' class='center'> "._("Restore snapshots")."</a></li>";
1464 }
1465 }
1467 return($result);
1468 }
1471 function renderExporterMenu($separator)
1472 {
1473 // Presets
1474 $result = "";
1476 // Draw entries
1477 $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'>";
1479 // Export CVS as build in exporter
1480 foreach ($this->exporter as $action => $exporter) {
1481 $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>";
1482 }
1484 // Finalize list
1485 $result.= "</ul></li>";
1487 return($result);
1488 }
1491 function renderSnapshotActions($row, $dn, $category, $class, $copy= true, $cut= true)
1492 {
1493 // We can only provide information if we've got a snapshot handler
1494 // instance
1495 if(!(isset($this->snapshotHandler) && is_object($this->snapshotHandler))){
1496 return "";
1497 }
1499 // Presets
1500 $result= "";
1501 $ui = get_userinfo();
1503 // Only act if enabled here
1504 if($this->snapshotHandler->enabled()){
1506 // Draw restore button
1507 if ($ui->allow_snapshot_restore($dn, $category)){
1509 // Do we have snapshots for this dn?
1510 if($this->snapshotHandler->hasSnapshots($dn)){
1511 $result.= "<input class='center' type='image' src='images/lists/restore.png' ".
1512 "alt='"._("Restore snapshot")."' name='listing_restore_$row' title='".
1513 _("Restore snapshot")."' style='padding:1px'>";
1514 } else {
1515 $result.= "<img src='images/lists/restore_grey.png' alt=' ' class='center' style='padding:1px'>";
1516 }
1517 }
1519 // Draw snapshot button
1520 if($ui->allow_snapshot_create($dn, $category)){
1521 $result.= "<input class='center' type='image' src='images/snapshot.png' ".
1522 "alt='"._("Create snapshot")."' name='listing_snapshot_$row' title='".
1523 _("Create a new snapshot from this object")."' style='padding:1px'>";
1524 }else{
1525 $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
1526 }
1527 }
1529 return($result);
1530 }
1533 function renderDaemonMenu($separator)
1534 {
1535 $result= "";
1537 // If there is a daemon registered, draw the menu entries
1538 if(class_available("DaemonEvent")){
1539 $events= DaemonEvent::get_event_types_by_category($this->categories);
1540 if(isset($events['BY_CLASS']) && count($events['BY_CLASS'])){
1541 foreach($events['BY_CLASS'] as $name => $event){
1542 $result.= "<li$separator><a href='#' onClick='document.getElementById(\"actionmenu\").value=\"$name\";document.getElementById(\"exec_act\").click();'>".$event['MenuImage']." ".$event['s_Menu_Name']."</a></li>";
1543 $separator= "";
1544 }
1545 }
1546 }
1548 return $result;
1549 }
1552 function getEntry($dn)
1553 {
1554 foreach ($this->entries as $entry) {
1555 if (isset($entry['dn']) && strcasecmp($dn, $entry['dn']) == 0){
1556 return $entry;
1557 }
1558 }
1559 return null;
1560 }
1563 function getType($dn)
1564 {
1565 if (isset($this->objectDnMapping[$dn])) {
1566 return $this->objectDnMapping[$dn];
1567 }
1568 return null;
1569 }
1571 }
1573 ?>