f49960ad0775760071ec5bc0fd3488f9c471dbf4
1 <?php
2 /*
3 * This code is part of GOsa (http://www.gosa-project.org)
4 * Copyright (C) 2003-2008 GONICUS GmbH
5 *
6 * ID: $$Id$$
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
23 class listing {
25 var $xmlData;
26 var $entries;
27 var $departments= array();
28 var $departmentBrowser= false;
29 var $departmentRootVisible= false;
30 var $multiSelect= false;
31 var $template;
32 var $headline;
33 var $base;
34 var $sortDirection= null;
35 var $sortColumn= null;
36 var $sortAttribute;
37 var $sortType;
38 var $numColumns;
39 var $baseMode= false;
40 var $bases= array();
41 var $header= array();
42 var $colprops= array();
43 var $filters= array();
44 var $filter= null;
45 var $pid;
46 var $objectTypes= array();
47 var $objectTypeCount= array();
48 var $objectDnMapping= array();
49 var $copyPasteHandler= null;
50 var $snapshotHandler= null;
51 var $exporter= array();
52 var $exportColumns= array();
53 var $useSpan= false;
54 var $height= 0;
55 var $scrollPosition= 0;
56 var $baseSelector;
59 function listing($filename)
60 {
61 global $config;
62 global $class_mapping;
64 // Initialize pid
65 $this->pid= preg_replace("/[^0-9]/", "", microtime(TRUE));
67 if (!$this->load($filename)) {
68 die("Cannot parse $filename!");
69 }
71 // Set base for filter
72 if ($this->baseMode) {
73 $this->base= session::global_get("CurrentMainBase");
74 if ($this->base == null) {
75 $this->base= $config->current['BASE'];
76 }
77 $this->refreshBasesList();
78 } else {
79 $this->base= $config->current['BASE'];
80 }
82 // Move footer information
83 $this->showFooter= ($config->get_cfg_value("listSummary") == "true");
85 // Register build in filters
86 $this->registerElementFilter("objectType", "listing::filterObjectType");
87 $this->registerElementFilter("departmentLink", "listing::filterDepartmentLink");
88 $this->registerElementFilter("link", "listing::filterLink");
89 $this->registerElementFilter("actions", "listing::filterActions");
91 // Load exporters
92 foreach($class_mapping as $class => $dummy) {
93 if (preg_match('/Exporter$/', $class)) {
94 $info= call_user_func(array($class, "getInfo"));
95 if ($info != null) {
96 $this->exporter= array_merge($this->exporter, $info);
97 }
98 }
99 }
101 // Instanciate base selector
102 $this->baseSelector= new baseSelector($this->bases, $this->base);
103 }
106 function setCopyPasteHandler($handler)
107 {
108 $this->copyPasteHandler= &$handler;
109 }
112 function setHeight($height)
113 {
114 $this->height= $height;
115 }
118 function setSnapshotHandler($handler)
119 {
120 $this->snapshotHandler= &$handler;
121 }
124 function setFilter($filter)
125 {
126 $this->filter= &$filter;
127 $filter->headpage = &$this;
128 if ($this->departmentBrowser){
129 $this->departments= $this->getDepartments();
130 }
131 $this->filter->setBase($this->base);
132 }
135 function registerElementFilter($name, $call)
136 {
137 if (!isset($this->filters[$name])) {
138 $this->filters[$name]= $call;
139 return true;
140 }
142 return false;
143 }
146 function load($filename)
147 {
148 $contents = file_get_contents($filename);
149 $this->xmlData= xml::xml2array($contents, 1);
151 if (!isset($this->xmlData['list'])) {
152 return false;
153 }
155 $this->xmlData= $this->xmlData["list"];
157 // Load some definition values
158 foreach (array("departmentBrowser", "departmentRootVisible", "multiSelect", "baseMode") as $token) {
159 if (isset($this->xmlData['definition'][$token]) &&
160 $this->xmlData['definition'][$token] == "true"){
161 $this->$token= true;
162 }
163 }
165 // Fill objectTypes from departments and xml definition
166 $types = departmentManagement::get_support_departments();
167 foreach ($types as $class => $data) {
168 $this->objectTypes[$data['OC']]= array("label" => $data['TITLE'],
169 "objectClass" => $data['OC'],
170 "image" => $data['IMG']);
171 }
172 $this->categories= array();
173 if (isset($this->xmlData['definition']['objectType'])) {
174 if(isset($this->xmlData['definition']['objectType']['label'])) {
175 $this->xmlData['definition']['objectType']= array($this->xmlData['definition']['objectType']);
176 }
177 foreach ($this->xmlData['definition']['objectType'] as $index => $otype) {
178 $tmp = $this->xmlData['definition']['objectType'][$index];
179 $this->objectTypes[$tmp['objectClass']]= $tmp;
180 if (isset($this->xmlData['definition']['objectType'][$index]['category'])){
181 $this->categories[]= $otype['category'];
182 }
183 }
184 }
185 $this->objectTypes = array_values($this->objectTypes);
187 // Parse layout per column
188 $this->colprops= $this->parseLayout($this->xmlData['table']['layout']);
190 // Prepare table headers
191 $this->renderHeader();
193 // Assign headline/Categories
194 $this->headline= _($this->xmlData['definition']['label']);
195 if (!is_array($this->categories)){
196 $this->categories= array($this->categories);
197 }
199 // Evaluate columns to be exported
200 if (isset($this->xmlData['table']['column'])){
201 foreach ($this->xmlData['table']['column'] as $index => $config) {
202 if (isset($config['export']) && $config['export'] == "true"){
203 $this->exportColumns[]= $index;
204 }
205 }
206 }
208 return true;
209 }
212 function renderHeader()
213 {
214 $this->header= array();
215 $this->plainHeader= array();
217 // Initialize sort?
218 $sortInit= false;
219 if (!$this->sortDirection) {
220 $this->sortColumn= 0;
221 if (isset($this->xmlData['definition']['defaultSortColumn'])){
222 $this->sortColumn= $this->xmlData['definition']['defaultSortColumn'];
223 } else {
224 $this->sortAttribute= "";
225 }
226 $this->sortDirection= array();
227 $sortInit= true;
228 }
230 if (isset($this->xmlData['table']['column'])){
231 foreach ($this->xmlData['table']['column'] as $index => $config) {
232 // Initialize everything to one direction
233 if ($sortInit) {
234 $this->sortDirection[$index]= false;
235 }
237 $sorter= "";
238 if ($index == $this->sortColumn && isset($config['sortAttribute']) &&
239 isset($config['sortType'])) {
240 $this->sortAttribute= $config['sortAttribute'];
241 $this->sortType= $config['sortType'];
242 $sorter= " <img border='0' title='".($this->sortDirection[$index]?_("Up"):_("Down"))."' src='images/lists/sort-".($this->sortDirection[$index]?"up":"down").".png' align='top'>";
243 }
244 $sortable= (isset($config['sortAttribute']));
246 $link= "href='?plug=".$_GET['plug']."&PID=".$this->pid."&act=SORT_$index'";
247 if (isset($config['label'])) {
248 if ($sortable) {
249 $this->header[$index]= "<td class='listheader' ".$this->colprops[$index]."><a $link>"._($config['label'])."$sorter</a></td>";
250 } else {
251 $this->header[$index]= "<td class='listheader' ".$this->colprops[$index].">"._($config['label'])."</td>";
252 }
253 $this->plainHeader[]= _($config['label']);
254 } else {
255 if ($sortable) {
256 $this->header[$index]= "<td class='listheader' ".$this->colprops[$index]."><a $link> $sorter</a></td>";
257 } else {
258 $this->header[$index]= "<td class='listheader' ".$this->colprops[$index]."> </td>";
259 }
260 $this->plainHeader[]= "";
261 }
262 }
263 }
264 }
267 function render()
268 {
269 // Check for exeeded sizelimit
270 if (($message= check_sizelimit()) != ""){
271 return($message);
272 }
274 // Some browsers don't have the ability do do scrollable table bodies, filter them
275 // here.
276 $switch= false;
277 if (preg_match('/(Opera|Konqueror|Safari)/i', $_SERVER['HTTP_USER_AGENT'])){
278 $switch= true;
279 }
281 // Initialize list
282 $result= "<input type='hidden' value='$this->pid' name='PID'>\n";
283 $result.= "<input type='hidden' name='position_".$this->pid."' id='position_".$this->pid."'>\n";
284 $height= 450;
285 if ($this->height != 0) {
286 $result.= "<input type='hidden' value='$this->height' id='d_height'>\n";
287 $height= $this->height;
288 }
290 $result.= "<div class='listContainer' id='d_scrollbody' style='border-top:1px solid #B0B0B0;border-right:1px solid #B0B0B0;width:100%;min-height:".($height+25)."px;'>\n";
291 $result.= "<table summary='$this->headline' style='width:100%; table-layout:fixed' cellspacing='0' cellpadding='0' id='t_scrolltable'>\n";
292 $this->numColumns= count($this->colprops) + ($this->multiSelect?1:0);
294 // Build list header
295 $result.= "<thead class='fixedListHeader listHeaderFormat'><tr>\n";
296 if ($this->multiSelect) {
297 $width= "24px";
298 if (preg_match('/Konqueror/i', $_SERVER['HTTP_USER_AGENT'])){
299 $width= "28px";
300 }
301 $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";
302 }
303 foreach ($this->header as $header) {
304 $result.= $header;
305 }
306 $result.= "</tr></thead>\n";
308 // Build list body
309 $result.= "<tbody class='listScrollContent listBodyFormat' id='t_nscrollbody' style='height:".$height."px;'>\n";
311 // No results? Just take an empty colspanned row
312 if (count($this->entries) + count($this->departments) == 0) {
313 $result.= "<tr class='rowxp0'><td class='list1nohighlight' colspan='$this->numColumns' style='height:100%;border-right:0px;width:100%;'> </td></tr>";
314 }
316 // Line color alternation
317 $alt= 0;
318 $deps= 0;
320 // Draw department browser if configured and we're not in sub mode
321 $this->useSpan= false;
322 if ($this->departmentBrowser && $this->filter->scope != "sub") {
323 // Fill with department browser if configured this way
324 $departmentIterator= new departmentSortIterator($this->departments, $this->sortDirection[$this->sortColumn]);
325 foreach ($departmentIterator as $row => $entry){
326 $result.="<tr class='rowxp".($alt&1)."'>";
328 // Render multi select if needed
329 if ($this->multiSelect) {
330 $result.="<td style='text-align:center;padding:0;' class='list1'> </td>";
331 }
333 // Render defined department columns, fill the rest with some stuff
334 $rest= $this->numColumns - 1;
335 foreach ($this->xmlData['table']['department'] as $index => $config) {
336 $colspan= 1;
337 if (isset($config['span'])){
338 $colspan= $config['span'];
339 $this->useSpan= true;
340 }
341 $result.="<td colspan='$colspan' ".$this->colprops[$index]." class='list1'>".$this->renderCell($config['value'], $entry, $row)."</td>";
342 $rest-= $colspan;
343 }
345 // Fill remaining cols with nothing
346 $last= $this->numColumns - $rest;
347 for ($i= 0; $i<$rest; $i++){
348 $result.= "<td ".$this->colprops[$last+$i-1]." class='list1'> </td>";
349 }
350 $result.="</tr>";
352 $alt++;
353 }
354 $deps= $alt;
355 }
357 // Fill with contents, sort as configured
358 foreach ($this->entries as $row => $entry) {
359 $trow= "";
361 // Render multi select if needed
362 if ($this->multiSelect) {
363 $trow.="<td style='text-align:center;width:20px;' class='list0'><input type='checkbox' id='listing_selected_$row' name='listing_selected_$row'></td>\n";
364 }
366 foreach ($this->xmlData['table']['column'] as $index => $config) {
367 $renderedCell= $this->renderCell($config['value'], $entry, $row);
368 $trow.="<td ".$this->colprops[$index]." class='list0'>".$renderedCell."</td>\n";
370 // Save rendered column
371 $sort= preg_replace('/.*>([^<]+)<.*$/', '$1', $renderedCell);
372 $sort= preg_replace('/ /', '', $sort);
373 if (preg_match('/</', $sort)){
374 $sort= "";
375 }
376 $this->entries[$row]["_sort$index"]= $sort;
377 }
379 // Save rendered entry
380 $this->entries[$row]['_rendered']= $trow;
381 }
383 // Complete list by sorting entries for _sort$index and appending them to the output
384 $entryIterator= new listingSortIterator($this->entries, $this->sortDirection[$this->sortColumn], "_sort".$this->sortColumn, $this->sortType);
385 foreach ($entryIterator as $row => $entry){
386 $result.="<tr class='rowxp".($alt&1)."'>\n";
387 $result.= $entry['_rendered'];
388 $result.="</tr>\n";
389 $alt++;
390 }
392 // Need to fill the list if it's not full (nobody knows why this is 22 ;-))
393 $emptyListStyle= (count($this->entries) + (($this->useSpan && count($this->entries))?$deps:0) == 0)?"border:0;":"";
394 if ((count($this->entries) + $deps) < 22) {
395 $result.= "<tr>";
396 for ($i= 0; $i<$this->numColumns; $i++) {
397 if ($i == 0) {
398 $result.= "<td class='list1nohighlight' style='$emptyListStyle height:100%;'> </td>";
399 continue;
400 }
401 if ($i != $this->numColumns-1) {
402 $result.= "<td class='list1nohighlight' style='$emptyListStyle'> </td>";
403 } else {
404 $result.= "<td class='list1nohighlight' style='border-right:0;$emptyListStyle'> </td>";
405 }
406 }
407 $result.= "</tr>";
408 }
410 // Close list body
411 $result.= "</tbody></table></div>";
413 // Add the footer if requested
414 if ($this->showFooter) {
415 $result.= "<div class='nlistFooter'><div style='padding:3px'>";
417 foreach ($this->objectTypes as $objectType) {
418 if (isset($this->objectTypeCount[$objectType['label']])) {
419 $label= _($objectType['label']);
420 $result.= "<img class='center' src='".$objectType['image']."' title='$label' alt='$label'> ".$this->objectTypeCount[$objectType['label']]." ";
421 }
422 }
424 $result.= "</div></div>";
425 }
427 // Close list
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 // Take care of base selector
476 if ($this->baseMode) {
477 $this->baseSelector->update();
478 // Check if a wrong base was supplied
479 if(!$this->baseSelector->checkLastBaseUpdate()){
480 msg_dialog::display(_("Error"), msgPool::check_base(), ERROR_DIALOG);
481 }
482 }
484 // Save base
485 $refresh= false;
486 if ($this->baseMode) {
487 $this->base= $this->baseSelector->getBase();
488 session::global_set("CurrentMainBase", $this->base);
489 $refresh= true;
490 }
493 // Reset object counter / DN mapping
494 $this->objectTypeCount= array();
495 $this->objectDnMapping= array();
497 // Do not do anything if this is not our PID
498 if($refresh || !(isset($_REQUEST['PID']) && $_REQUEST['PID'] != $this->pid)) {
500 // Save position if set
501 if (isset($_POST['position_'.$this->pid]) && is_numeric($_POST['position_'.$this->pid])) {
502 $this->scrollPosition= $_POST['position_'.$this->pid];
503 }
505 // Override the base if we got a message from the browser navigation
506 if ($this->departmentBrowser && isset($_GET['act'])) {
507 if (preg_match('/^department_([0-9]+)$/', validate($_GET['act']), $match)){
508 if (isset($this->departments[$match[1]])){
509 $this->base= $this->departments[$match[1]]['dn'];
510 if ($this->baseMode) {
511 $this->baseSelector->setBase($this->base);
512 }
513 session::global_set("CurrentMainBase", $this->base);
514 }
515 }
516 }
518 // Filter POST with "act" attributes -> posted from action menu
519 if (isset($_POST['exec_act']) && $_POST['act'] != '') {
520 if (preg_match('/^export.*$/', $_POST['act']) && isset($this->exporter[$_POST['act']])) {
521 $exporter= $this->exporter[$_POST['act']];
522 $userinfo= ", "._("created by")." ".$ui->cn." - ".strftime('%A, %d. %B %Y, %H:%M:%S');
523 $entryIterator= new listingSortIterator($this->entries, $this->sortDirection[$this->sortColumn], "_sort".$this->sortColumn, $this->sortType);
524 $sortedEntries= array();
525 foreach ($entryIterator as $entry){
526 $sortedEntries[]= $entry;
527 }
528 $instance= new $exporter['class']($this->headline.$userinfo, $this->plainHeader, $sortedEntries, $this->exportColumns);
529 $type= call_user_func(array($exporter['class'], "getInfo"));
530 $type= $type[$_POST['act']];
531 send_binary_content($instance->query(), $type['filename'], $type= $type['mime']);
532 }
533 }
535 // Filter GET with "act" attributes
536 if (isset($_GET['act'])) {
537 $key= validate($_GET['act']);
538 if (preg_match('/^SORT_([0-9]+)$/', $key, $match)) {
539 // Switch to new column or invert search order?
540 $column= $match[1];
541 if ($this->sortColumn != $column) {
542 $this->sortColumn= $column;
543 } else {
544 $this->sortDirection[$column]= !$this->sortDirection[$column];
545 }
547 // Allow header to update itself according to the new sort settings
548 $this->renderHeader();
549 }
550 }
552 // Override base if we got signals from the navigation elements
553 $action= "";
554 foreach ($_POST as $key => $value) {
555 if (preg_match('/^(ROOT|BACK|HOME)_x$/', $key, $match)) {
556 $action= $match[1];
557 break;
558 }
559 }
561 // Navigation handling
562 if ($action == 'ROOT') {
563 $deps= $ui->get_module_departments($this->categories);
564 $this->base= $deps[0];
565 $this->baseSelector->setBase($this->base);
566 session::global_set("CurrentMainBase", $this->base);
567 }
568 if ($action == 'BACK') {
569 $deps= $ui->get_module_departments($this->categories);
570 $base= preg_replace("/^[^,]+,/", "", $this->base);
571 if(in_array_ics($base, $deps)){
572 $this->base= $base;
573 $this->baseSelector->setBase($this->base);
574 session::global_set("CurrentMainBase", $this->base);
575 }
576 }
577 if ($action == 'HOME') {
578 $ui= get_userinfo();
579 $this->base= get_base_from_people($ui->dn);
580 $this->baseSelector->setBase($this->base);
581 session::global_set("CurrentMainBase", $this->base);
582 }
583 }
585 // Reload departments
586 if ($this->departmentBrowser){
587 $this->departments= $this->getDepartments();
588 }
590 // Update filter and refresh entries
591 $this->filter->setBase($this->base);
592 $this->entries= $this->filter->query();
594 // Fix filter if querie returns NULL
595 if ($this->entries == null) {
596 $this->entries= array();
597 }
598 }
601 function setBase($base)
602 {
603 $this->base= $base;
604 if ($this->baseMode) {
605 $this->baseSelector->setBase($this->base);
606 }
607 }
610 function getBase()
611 {
612 return $this->base;
613 }
616 function parseLayout($layout)
617 {
618 $result= array();
619 $layout= preg_replace("/^\|/", "", $layout);
620 $layout= preg_replace("/\|$/", "", $layout);
621 $cols= explode("|", $layout);
623 foreach ($cols as $index => $config) {
624 if ($config != "") {
625 $res= "";
626 $components= explode(';', $config);
627 foreach ($components as $part) {
628 if (preg_match("/^r$/", $part)) {
629 $res.= "text-align:right;";
630 continue;
631 }
632 if (preg_match("/^l$/", $part)) {
633 $res.= "text-align:left;";
634 continue;
635 }
636 if (preg_match("/^c$/", $part)) {
637 $res.= "text-align:center;";
638 continue;
639 }
640 if (preg_match("/^[0-9]+(|px|%)$/", $part)) {
641 $res.= "width:$part;min-width:$part;";
642 continue;
643 }
644 }
646 // Add minimum width for scalable columns
647 if (!preg_match('/width:/', $res)){
648 $res.= "min-width:200px;";
649 }
651 $result[$index]= " style='$res'";
652 } else {
653 $result[$index]= " style='min-width:100px;'";
654 }
655 }
657 // Save number of columns for later use
658 $this->numColumns= count($cols);
660 // Add no border to the last column
661 $result[$this->numColumns-1]= preg_replace("/'$/", "border-right:0;'", $result[$this->numColumns-1]);
663 return $result;
664 }
667 function renderCell($data, $config, $row)
668 {
669 // Replace flat attributes in data string
670 for ($i= 0; $i<$config['count']; $i++) {
671 $attr= $config[$i];
672 $value= "";
673 if (is_array($config[$attr])) {
674 $value= $config[$attr][0];
675 } else {
676 $value= $config[$attr];
677 }
678 $data= preg_replace("/%\{$attr\}/", $value, $data);
679 }
681 // Watch out for filters and prepare to execute them
682 $data= $this->processElementFilter($data, $config, $row);
684 // Replace all non replaced %{...} instances because they
685 // are non resolved attributes or filters
686 $data= preg_replace('/%{[^}]+}/', ' ', $data);
688 return $data;
689 }
692 function renderBase()
693 {
694 if (!$this->baseMode) {
695 return;
696 }
698 return $this->baseSelector->render();
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)= explode('=', $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->categories);
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 == get_base_from_people($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->categories;
1219 $aclList= array();
1221 // Replace %acl if available
1222 if ($classes) {
1223 $otype= $this->getObjectType($this->objectTypes, $classes);
1224 $acl= str_replace('%acl', $otype['category']."/".$otype['class'], $acl);
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= explode(',', $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->categories);
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 }
1301 // Populate base selector if already present
1302 if ($this->baseSelector && $this->baseMode) {
1303 $this->baseSelector->setBases($this->bases);
1304 $this->baseSelector->update(TRUE);
1305 }
1306 }
1309 function getDepartments()
1310 {
1311 $departments= array();
1312 $ui= get_userinfo();
1314 // Get list of supported department types
1315 $types = departmentManagement::get_support_departments();
1317 // Load departments allowed by ACL
1318 $validDepartments = $ui->get_module_departments($this->categories);
1320 // Build filter and look in the LDAP for possible sub departments
1321 // of current base
1322 $filter= "(&(objectClass=gosaDepartment)(|";
1323 $attrs= array("description", "objectClass");
1324 foreach($types as $name => $data){
1325 $filter.= "(objectClass=".$data['OC'].")";
1326 $attrs[]= $data['ATTR'];
1327 }
1328 $filter.= "))";
1329 $res= get_list($filter, $this->categories, $this->base, $attrs, GL_NONE);
1331 // Analyze list of departments
1332 foreach ($res as $department) {
1333 if (!in_array($department['dn'], $validDepartments)) {
1334 continue;
1335 }
1337 // Add the attribute where we use for sorting
1338 $oc= null;
1339 foreach(array_keys($types) as $type) {
1340 if (in_array($type, $department['objectClass'])) {
1341 $oc= $type;
1342 break;
1343 }
1344 }
1345 $department['sort-attribute']= $types[$oc]['ATTR'];
1347 // Move to the result list
1348 $departments[]= $department;
1349 }
1351 return $departments;
1352 }
1355 function renderCopyPasteMenu($separator, $copy= true, $cut= true)
1356 {
1357 // We can only provide information if we've got a copypaste handler
1358 // instance
1359 if(!(isset($this->copyPasteHandler) && is_object($this->copyPasteHandler))){
1360 return "";
1361 }
1363 // Presets
1364 $result= "";
1365 $read= $paste= false;
1366 $ui= get_userinfo();
1368 // Switch flags to on if there's at least one category which allows read/paste
1369 foreach($this->categories as $category){
1370 $read= $read || preg_match('/r/', $ui->get_category_permissions($this->base, $category));
1371 $paste= $paste || $ui->is_pasteable($this->base, $category) == 1;
1372 }
1375 // Draw entries that allow copy and cut
1376 if($read){
1378 // Copy entry
1379 if($copy){
1380 $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>";
1381 $separator= "";
1382 }
1384 // Cut entry
1385 if($cut){
1386 $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>";
1387 $separator= "";
1388 }
1389 }
1391 // Draw entries that allow pasting entries
1392 if($paste){
1393 if($this->copyPasteHandler->entries_queued()){
1394 $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>";
1395 }else{
1396 $result.= "<li$separator><a href='#'><img src='images/lists/paste-grey.png' alt='' border='0' class='center'> "._("Paste")."</a></li>";
1397 }
1398 }
1400 return($result);
1401 }
1404 function renderCopyPasteActions($row, $dn, $category, $class, $copy= true, $cut= true)
1405 {
1406 // We can only provide information if we've got a copypaste handler
1407 // instance
1408 if(!(isset($this->copyPasteHandler) && is_object($this->copyPasteHandler))){
1409 return "";
1410 }
1412 // Presets
1413 $ui = get_userinfo();
1414 $result = "";
1416 // Render cut entries
1417 if($cut){
1418 if($ui->is_cutable($dn, $category, $class)){
1419 $result .= "<input class='center' type='image'
1420 src='images/lists/cut.png' alt='"._("Cut")."' name='listing_cut_$row' title='"._("Cut this entry")."' style='padding:1px'>";
1421 }else{
1422 $result.="<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
1423 }
1424 }
1426 // Render copy entries
1427 if($copy){
1428 if($ui->is_copyable($dn, $category, $class)){
1429 $result.= "<input class='center' type='image'
1430 src='images/lists/copy.png' alt='"._("Copy")."' name='listing_copy_$row' title='"._("Copy this entry")."' style='padding:1px'>";
1431 }else{
1432 $result.="<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
1433 }
1434 }
1436 return($result);
1437 }
1440 function renderSnapshotMenu($separator)
1441 {
1442 // We can only provide information if we've got a snapshot handler
1443 // instance
1444 if(!(isset($this->snapshotHandler) && is_object($this->snapshotHandler))){
1445 return "";
1446 }
1448 // Presets
1449 $result = "";
1450 $ui = get_userinfo();
1452 if($this->snapshotHandler->enabled() && $ui->allow_snapshot_restore($this->base, $this->categories)){
1454 // Check if there is something to restore
1455 $restore= false;
1456 foreach($this->snapshotHandler->getSnapshotBases() as $base){
1457 $restore= $restore || count($this->snapshotHandler->getDeletedSnapshots($base)) > 0;
1458 }
1460 // Draw icons according to the restore flag
1461 if($restore){
1462 $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>";
1463 }else{
1464 $result.= "<li$separator><a href='#'><img src='images/lists/restore_grey.png' alt='' border='0' class='center'> "._("Restore snapshots")."</a></li>";
1465 }
1466 }
1468 return($result);
1469 }
1472 function renderExporterMenu($separator)
1473 {
1474 // Presets
1475 $result = "";
1477 // Draw entries
1478 $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'>";
1480 // Export CVS as build in exporter
1481 foreach ($this->exporter as $action => $exporter) {
1482 $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>";
1483 }
1485 // Finalize list
1486 $result.= "</ul></li>";
1488 return($result);
1489 }
1492 function renderSnapshotActions($row, $dn, $category, $class, $copy= true, $cut= true)
1493 {
1494 // We can only provide information if we've got a snapshot handler
1495 // instance
1496 if(!(isset($this->snapshotHandler) && is_object($this->snapshotHandler))){
1497 return "";
1498 }
1500 // Presets
1501 $result= "";
1502 $ui = get_userinfo();
1504 // Only act if enabled here
1505 if($this->snapshotHandler->enabled()){
1507 // Draw restore button
1508 if ($ui->allow_snapshot_restore($dn, $category)){
1510 // Do we have snapshots for this dn?
1511 if($this->snapshotHandler->hasSnapshots($dn)){
1512 $result.= "<input class='center' type='image' src='images/lists/restore.png' ".
1513 "alt='"._("Restore snapshot")."' name='listing_restore_$row' title='".
1514 _("Restore snapshot")."' style='padding:1px'>";
1515 } else {
1516 $result.= "<img src='images/lists/restore_grey.png' alt=' ' class='center' style='padding:1px'>";
1517 }
1518 }
1520 // Draw snapshot button
1521 if($ui->allow_snapshot_create($dn, $category)){
1522 $result.= "<input class='center' type='image' src='images/snapshot.png' ".
1523 "alt='"._("Create snapshot")."' name='listing_snapshot_$row' title='".
1524 _("Create a new snapshot from this object")."' style='padding:1px'>";
1525 }else{
1526 $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
1527 }
1528 }
1530 return($result);
1531 }
1534 function renderDaemonMenu($separator)
1535 {
1536 $result= "";
1538 // If there is a daemon registered, draw the menu entries
1539 if(class_available("DaemonEvent")){
1540 $events= DaemonEvent::get_event_types_by_category($this->categories);
1541 if(isset($events['BY_CLASS']) && count($events['BY_CLASS'])){
1542 foreach($events['BY_CLASS'] as $name => $event){
1543 $result.= "<li$separator><a href='#' onClick='document.getElementById(\"actionmenu\").value=\"$name\";document.getElementById(\"exec_act\").click();'>".$event['MenuImage']." ".$event['s_Menu_Name']."</a></li>";
1544 $separator= "";
1545 }
1546 }
1547 }
1549 return $result;
1550 }
1553 function getEntry($dn)
1554 {
1555 foreach ($this->entries as $entry) {
1556 if (isset($entry['dn']) && strcasecmp($dn, $entry['dn']) == 0){
1557 return $entry;
1558 }
1559 }
1560 return null;
1561 }
1564 function getEntries()
1565 {
1566 return $this->entries;
1567 }
1570 function getType($dn)
1571 {
1572 if (isset($this->objectDnMapping[$dn])) {
1573 return $this->objectDnMapping[$dn];
1574 }
1575 return null;
1576 }
1578 }
1580 ?>