37efe409d57c98598959e78a68e7a572df0c69ee
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 if ($this->departmentBrowser){
128 $this->departments= $this->getDepartments();
129 }
130 $this->filter->setBase($this->base);
131 }
134 function registerElementFilter($name, $call)
135 {
136 if (!isset($this->filters[$name])) {
137 $this->filters[$name]= $call;
138 return true;
139 }
141 return false;
142 }
145 function load($filename)
146 {
147 $contents = file_get_contents($filename);
148 $this->xmlData= xml::xml2array($contents, 1);
150 if (!isset($this->xmlData['list'])) {
151 return false;
152 }
154 $this->xmlData= $this->xmlData["list"];
156 // Load some definition values
157 foreach (array("departmentBrowser", "departmentRootVisible", "multiSelect", "baseMode") as $token) {
158 if (isset($this->xmlData['definition'][$token]) &&
159 $this->xmlData['definition'][$token] == "true"){
160 $this->$token= true;
161 }
162 }
164 // Fill objectTypes from departments and xml definition
165 $types = departmentManagement::get_support_departments();
166 foreach ($types as $class => $data) {
167 $this->objectTypes[$data['OC']]= array("label" => $data['TITLE'],
168 "objectClass" => $data['OC'],
169 "image" => $data['IMG']);
170 }
171 $this->categories= array();
172 if (isset($this->xmlData['definition']['objectType'])) {
173 if(isset($this->xmlData['definition']['objectType']['label'])) {
174 $this->xmlData['definition']['objectType']= array($this->xmlData['definition']['objectType']);
175 }
176 foreach ($this->xmlData['definition']['objectType'] as $index => $otype) {
177 $tmp = $this->xmlData['definition']['objectType'][$index];
178 $this->objectTypes[$tmp['objectClass']]= $tmp;
179 if (isset($this->xmlData['definition']['objectType'][$index]['category'])){
180 $this->categories[]= $otype['category'];
181 }
182 }
183 }
184 $this->objectTypes = array_values($this->objectTypes);
186 // Parse layout per column
187 $this->colprops= $this->parseLayout($this->xmlData['table']['layout']);
189 // Prepare table headers
190 $this->renderHeader();
192 // Assign headline/Categories
193 $this->headline= _($this->xmlData['definition']['label']);
194 if (!is_array($this->categories)){
195 $this->categories= array($this->categories);
196 }
198 // Evaluate columns to be exported
199 if (isset($this->xmlData['table']['column'])){
200 foreach ($this->xmlData['table']['column'] as $index => $config) {
201 if (isset($config['export']) && $config['export'] == "true"){
202 $this->exportColumns[]= $index;
203 }
204 }
205 }
207 return true;
208 }
211 function renderHeader()
212 {
213 $this->header= array();
214 $this->plainHeader= array();
216 // Initialize sort?
217 $sortInit= false;
218 if (!$this->sortDirection) {
219 $this->sortColumn= 0;
220 if (isset($this->xmlData['definition']['defaultSortColumn'])){
221 $this->sortColumn= $this->xmlData['definition']['defaultSortColumn'];
222 } else {
223 $this->sortAttribute= "";
224 }
225 $this->sortDirection= array();
226 $sortInit= true;
227 }
229 if (isset($this->xmlData['table']['column'])){
230 foreach ($this->xmlData['table']['column'] as $index => $config) {
231 // Initialize everything to one direction
232 if ($sortInit) {
233 $this->sortDirection[$index]= false;
234 }
236 $sorter= "";
237 if ($index == $this->sortColumn && isset($config['sortAttribute']) &&
238 isset($config['sortType'])) {
239 $this->sortAttribute= $config['sortAttribute'];
240 $this->sortType= $config['sortType'];
241 $sorter= " <img border='0' title='".($this->sortDirection[$index]?_("Up"):_("Down"))."' src='images/lists/sort-".($this->sortDirection[$index]?"up":"down").".png' align='top'>";
242 }
243 $sortable= (isset($config['sortAttribute']));
245 $link= "href='?plug=".$_GET['plug']."&PID=".$this->pid."&act=SORT_$index'";
246 if (isset($config['label'])) {
247 if ($sortable) {
248 $this->header[$index]= "<td class='listheader' ".$this->colprops[$index]."><a $link>"._($config['label'])."$sorter</a></td>";
249 } else {
250 $this->header[$index]= "<td class='listheader' ".$this->colprops[$index].">"._($config['label'])."</td>";
251 }
252 $this->plainHeader[]= _($config['label']);
253 } else {
254 if ($sortable) {
255 $this->header[$index]= "<td class='listheader' ".$this->colprops[$index]."><a $link> $sorter</a></td>";
256 } else {
257 $this->header[$index]= "<td class='listheader' ".$this->colprops[$index]."> </td>";
258 }
259 $this->plainHeader[]= "";
260 }
261 }
262 }
263 }
266 function render()
267 {
268 // Check for exeeded sizelimit
269 if (($message= check_sizelimit()) != ""){
270 return($message);
271 }
273 // Some browsers don't have the ability do do scrollable table bodies, filter them
274 // here.
275 $switch= false;
276 if (preg_match('/(Opera|Konqueror|Safari)/i', $_SERVER['HTTP_USER_AGENT'])){
277 $switch= true;
278 }
280 // Initialize list
281 $result= "<input type='hidden' value='$this->pid' name='PID'>\n";
282 $result.= "<input type='hidden' name='position_".$this->pid."' id='position_".$this->pid."'>\n";
283 $height= 450;
284 if ($this->height != 0) {
285 $result.= "<input type='hidden' value='$this->height' id='d_height'>\n";
286 $height= $this->height;
287 }
289 $result.= "<div class='listContainer' id='d_scrollbody' style='min-height:".($height+25)."px;'>\n";
290 $result.= "<table summary='$this->headline' style='width:100%;table-layout:fixed' cellspacing='0' cellpadding='0' id='t_scrolltable'>\n";
291 $this->numColumns= count($this->colprops) + ($this->multiSelect?1:0);
293 // Build list header
294 $result.= "<thead class='fixedListHeader listHeaderFormat'><tr>\n";
295 if ($this->multiSelect) {
296 $width= "24px";
297 if (preg_match('/Konqueror/i', $_SERVER['HTTP_USER_AGENT'])){
298 $width= "28px";
299 }
300 $result.= "<td class='listheader' style='text-align:center;padding:0;width:$width;'><input type='checkbox' id='select_all' name='select_all' title='"._("Select all")."' onClick='toggle_all_(\"listing_selected_[0-9]*$\",\"select_all\");' ></td>\n";
301 }
302 foreach ($this->header as $header) {
303 $result.= $header;
304 }
305 $result.= "</tr></thead>\n";
307 // Build list body
308 $result.= "<tbody class='listScrollContent listBodyFormat' id='t_nscrollbody' style='height:".$height."px;'>\n";
310 // No results? Just take an empty colspanned row
311 if (count($this->entries) + count($this->departments) == 0) {
312 $result.= "<tr><td class='list1nohighlight' colspan='$this->numColumns' style='height:100%;border-right:0px;width:100%;'> </td></tr>";
313 }
315 // Line color alternation
316 $alt= 0;
317 $deps= 0;
319 // Draw department browser if configured and we're not in sub mode
320 $this->useSpan= false;
321 if ($this->departmentBrowser && $this->filter->scope != "sub") {
322 // Fill with department browser if configured this way
323 $departmentIterator= new departmentSortIterator($this->departments, $this->sortDirection[$this->sortColumn]);
324 foreach ($departmentIterator as $row => $entry){
325 $result.="<tr>";
327 // Render multi select if needed
328 if ($this->multiSelect) {
329 $result.="<td style='text-align:center;padding:0;' class='list1'> </td>";
330 }
332 // Render defined department columns, fill the rest with some stuff
333 $rest= $this->numColumns - 1;
334 foreach ($this->xmlData['table']['department'] as $index => $config) {
335 $colspan= 1;
336 if (isset($config['span'])){
337 $colspan= $config['span'];
338 $this->useSpan= true;
339 }
340 $result.="<td colspan='$colspan' ".$this->colprops[$index]." class='list1'>".$this->renderCell($config['value'], $entry, $row)."</td>";
341 $rest-= $colspan;
342 }
344 // Fill remaining cols with nothing
345 $last= $this->numColumns - $rest;
346 for ($i= 0; $i<$rest; $i++){
347 $result.= "<td ".$this->colprops[$last+$i-1]." class='list1'> </td>";
348 }
349 $result.="</tr>";
351 $alt++;
352 }
353 $deps= $alt;
354 }
356 // Fill with contents, sort as configured
357 foreach ($this->entries as $row => $entry) {
358 $trow= "";
360 // Render multi select if needed
361 if ($this->multiSelect) {
362 $trow.="<td style='text-align:center;width:20px;' class='list0'><input type='checkbox' id='listing_selected_$row' name='listing_selected_$row'></td>\n";
363 }
365 foreach ($this->xmlData['table']['column'] as $index => $config) {
366 $renderedCell= $this->renderCell($config['value'], $entry, $row);
367 $trow.="<td ".$this->colprops[$index]." class='list0'>".$renderedCell."</td>\n";
369 // Save rendered column
370 $sort= preg_replace('/.*>([^<]+)<.*$/', '$1', $renderedCell);
371 $sort= preg_replace('/ /', '', $sort);
372 if (preg_match('/</', $sort)){
373 $sort= "";
374 }
375 $this->entries[$row]["_sort$index"]= $sort;
376 }
378 // Save rendered entry
379 $this->entries[$row]['_rendered']= $trow;
380 }
382 // Complete list by sorting entries for _sort$index and appending them to the output
383 $entryIterator= new listingSortIterator($this->entries, $this->sortDirection[$this->sortColumn], "_sort".$this->sortColumn, $this->sortType);
384 foreach ($entryIterator as $row => $entry){
385 $result.="<tr>\n";
386 $result.= $entry['_rendered'];
387 $result.="</tr>\n";
388 $alt++;
389 }
391 // Need to fill the list if it's not full (nobody knows why this is 22 ;-))
392 $emptyListStyle= (count($this->entries) + (($this->useSpan && count($this->entries))?$deps:0) == 0)?"border:0;":"";
393 if ((count($this->entries) + $deps) < 22) {
394 $result.= "<tr>";
395 for ($i= 0; $i<$this->numColumns; $i++) {
396 if ($i == 0) {
397 $result.= "<td class='list1nohighlight' style='$emptyListStyle height:100%;'> </td>";
398 continue;
399 }
400 if ($i != $this->numColumns-1) {
401 $result.= "<td class='list1nohighlight' style='$emptyListStyle'> </td>";
402 } else {
403 $result.= "<td class='list1nohighlight' style='border-right:0;$emptyListStyle'> </td>";
404 }
405 }
406 $result.= "</tr>";
407 }
409 // Close list body
410 $result.= "</tbody></table></div>";
412 // Add the footer if requested
413 if ($this->showFooter) {
414 $result.= "<div class='nlistFooter'><div style='padding:3px'>";
416 foreach ($this->objectTypes as $objectType) {
417 if (isset($this->objectTypeCount[$objectType['label']])) {
418 $label= _($objectType['label']);
419 $result.= "<img class='center' src='".$objectType['image']."' title='$label' alt='$label'> ".$this->objectTypeCount[$objectType['label']]." ";
420 }
421 }
423 $result.= "</div></div>";
424 }
426 // Close list
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 // Take care of base selector
475 if ($this->baseMode) {
476 $this->baseSelector->update();
477 // Check if a wrong base was supplied
478 if(!$this->baseSelector->checkLastBaseUpdate()){
479 msg_dialog::display(_("Error"), msgPool::check_base(), ERROR_DIALOG);
480 }
481 }
483 // Save base
484 $refresh= false;
485 if ($this->baseMode) {
486 $this->base= $this->baseSelector->getBase();
487 session::global_set("CurrentMainBase", $this->base);
488 $refresh= true;
489 }
492 // Reset object counter / DN mapping
493 $this->objectTypeCount= array();
494 $this->objectDnMapping= array();
496 // Do not do anything if this is not our PID
497 if($refresh || !(isset($_REQUEST['PID']) && $_REQUEST['PID'] != $this->pid)) {
499 // Save position if set
500 if (isset($_POST['position_'.$this->pid]) && is_numeric($_POST['position_'.$this->pid])) {
501 $this->scrollPosition= $_POST['position_'.$this->pid];
502 }
504 // Override the base if we got a message from the browser navigation
505 if ($this->departmentBrowser && isset($_GET['act'])) {
506 if (preg_match('/^department_([0-9]+)$/', validate($_GET['act']), $match)){
507 if (isset($this->departments[$match[1]])){
508 $this->base= $this->departments[$match[1]]['dn'];
509 if ($this->baseMode) {
510 $this->baseSelector->setBase($this->base);
511 }
512 session::global_set("CurrentMainBase", $this->base);
513 }
514 }
515 }
517 // Filter POST with "act" attributes -> posted from action menu
518 if (isset($_POST['exec_act']) && $_POST['act'] != '') {
519 if (preg_match('/^export.*$/', $_POST['act']) && isset($this->exporter[$_POST['act']])) {
520 $exporter= $this->exporter[$_POST['act']];
521 $userinfo= ", "._("created by")." ".$ui->cn." - ".strftime('%A, %d. %B %Y, %H:%M:%S');
522 $entryIterator= new listingSortIterator($this->entries, $this->sortDirection[$this->sortColumn], "_sort".$this->sortColumn, $this->sortType);
523 $sortedEntries= array();
524 foreach ($entryIterator as $entry){
525 $sortedEntries[]= $entry;
526 }
527 $instance= new $exporter['class']($this->headline.$userinfo, $this->plainHeader, $sortedEntries, $this->exportColumns);
528 $type= call_user_func(array($exporter['class'], "getInfo"));
529 $type= $type[$_POST['act']];
530 send_binary_content($instance->query(), $type['filename'], $type= $type['mime']);
531 }
532 }
534 // Filter GET with "act" attributes
535 if (isset($_GET['act'])) {
536 $key= validate($_GET['act']);
537 if (preg_match('/^SORT_([0-9]+)$/', $key, $match)) {
538 // Switch to new column or invert search order?
539 $column= $match[1];
540 if ($this->sortColumn != $column) {
541 $this->sortColumn= $column;
542 } else {
543 $this->sortDirection[$column]= !$this->sortDirection[$column];
544 }
546 // Allow header to update itself according to the new sort settings
547 $this->renderHeader();
548 }
549 }
551 // Override base if we got signals from the navigation elements
552 $action= "";
553 foreach ($_POST as $key => $value) {
554 if (preg_match('/^(ROOT|BACK|HOME)_x$/', $key, $match)) {
555 $action= $match[1];
556 break;
557 }
558 }
560 // Navigation handling
561 if ($action == 'ROOT') {
562 $deps= $ui->get_module_departments($this->categories);
563 $this->base= $deps[0];
564 $this->baseSelector->setBase($this->base);
565 session::global_set("CurrentMainBase", $this->base);
566 }
567 if ($action == 'BACK') {
568 $deps= $ui->get_module_departments($this->categories);
569 $base= preg_replace("/^[^,]+,/", "", $this->base);
570 if(in_array_ics($base, $deps)){
571 $this->base= $base;
572 $this->baseSelector->setBase($this->base);
573 session::global_set("CurrentMainBase", $this->base);
574 }
575 }
576 if ($action == 'HOME') {
577 $ui= get_userinfo();
578 $this->base= get_base_from_people($ui->dn);
579 $this->baseSelector->setBase($this->base);
580 session::global_set("CurrentMainBase", $this->base);
581 }
582 }
584 // Reload departments
585 if ($this->departmentBrowser){
586 $this->departments= $this->getDepartments();
587 }
589 // Update filter and refresh entries
590 $this->filter->setBase($this->base);
591 $this->entries= $this->filter->query();
593 // Fix filter if querie returns NULL
594 if ($this->entries == null) {
595 $this->entries= array();
596 }
597 }
600 function setBase($base)
601 {
602 $this->base= $base;
603 if ($this->baseMode) {
604 $this->baseSelector->setBase($this->base);
605 }
606 }
609 function getBase()
610 {
611 return $this->base;
612 }
615 function parseLayout($layout)
616 {
617 $result= array();
618 $layout= preg_replace("/^\|/", "", $layout);
619 $layout= preg_replace("/\|$/", "", $layout);
620 $cols= explode("|", $layout);
622 foreach ($cols as $index => $config) {
623 if ($config != "") {
624 $res= "";
625 $components= explode(';', $config);
626 foreach ($components as $part) {
627 if (preg_match("/^r$/", $part)) {
628 $res.= "text-align:right;";
629 continue;
630 }
631 if (preg_match("/^l$/", $part)) {
632 $res.= "text-align:left;";
633 continue;
634 }
635 if (preg_match("/^c$/", $part)) {
636 $res.= "text-align:center;";
637 continue;
638 }
639 if (preg_match("/^[0-9]+(|px|%)$/", $part)) {
640 $res.= "width:$part;min-width:$part;";
641 continue;
642 }
643 }
645 // Add minimum width for scalable columns
646 if (!preg_match('/width:/', $res)){
647 $res.= "min-width:200px;";
648 }
650 $result[$index]= " style='$res'";
651 } else {
652 $result[$index]= " style='min-width:100px;'";
653 }
654 }
656 // Save number of columns for later use
657 $this->numColumns= count($cols);
659 // Add no border to the last column
660 $result[$this->numColumns-1]= preg_replace("/'$/", "border-right:0;'", $result[$this->numColumns-1]);
662 return $result;
663 }
666 function renderCell($data, $config, $row)
667 {
668 // Replace flat attributes in data string
669 for ($i= 0; $i<$config['count']; $i++) {
670 $attr= $config[$i];
671 $value= "";
672 if (is_array($config[$attr])) {
673 $value= $config[$attr][0];
674 } else {
675 $value= $config[$attr];
676 }
677 $data= preg_replace("/%\{$attr\}/", $value, $data);
678 }
680 // Watch out for filters and prepare to execute them
681 $data= $this->processElementFilter($data, $config, $row);
683 // Replace all non replaced %{...} instances because they
684 // are non resolved attributes or filters
685 $data= preg_replace('/%{[^}]+}/', ' ', $data);
687 return $data;
688 }
691 function renderBase()
692 {
693 if (!$this->baseMode) {
694 return;
695 }
697 return $this->baseSelector->render();
698 }
701 function processElementFilter($data, $config, $row)
702 {
703 preg_match_all("/%\{filter:([^(]+)\((.*)\)\}/", $data, $matches, PREG_SET_ORDER);
705 foreach ($matches as $match) {
706 $cl= "";
707 $method= "";
708 if (preg_match('/::/', $match[1])) {
709 $cl= preg_replace('/::.*$/', '', $match[1]);
710 $method= preg_replace('/^.*::/', '', $match[1]);
711 } else {
712 if (!isset($this->filters[$match[1]])) {
713 continue;
714 }
715 $cl= preg_replace('/::.*$/', '', $this->filters[$match[1]]);
716 $method= preg_replace('/^.*::/', '', $this->filters[$match[1]]);
717 }
719 // Prepare params for function call
720 $params= array();
721 preg_match_all('/"[^"]+"|[^,]+/', $match[2], $parts);
722 foreach ($parts[0] as $param) {
724 // Row is replaced by the row number
725 if ($param == "row") {
726 $params[]= $row;
727 continue;
728 }
730 // pid is replaced by the current PID
731 if ($param == "pid") {
732 $params[]= $this->pid;
733 continue;
734 }
736 // base is replaced by the current base
737 if ($param == "base") {
738 $params[]= $this->getBase();
739 continue;
740 }
742 // Fixie with "" is passed directly
743 if (preg_match('/^".*"$/', $param)){
744 $params[]= preg_replace('/"/', '', $param);
745 continue;
746 }
748 // Move dn if needed
749 if ($param == "dn") {
750 $params[]= LDAP::fix($config["dn"]);
751 continue;
752 }
754 // LDAP variables get replaced by their objects
755 for ($i= 0; $i<$config['count']; $i++) {
756 if ($param == $config[$i]) {
757 $values= $config[$config[$i]];
758 if (is_array($values)){
759 unset($values['count']);
760 }
761 $params[]= $values;
762 break;
763 }
764 }
765 }
767 // Replace information
768 if ($cl == "listing") {
769 // Non static call - seems to result in errors
770 $data= @preg_replace('/'.preg_quote($match[0]).'/', call_user_func_array(array($this, "$method"), $params), $data);
771 } else {
772 // Static call
773 $data= preg_replace('/'.preg_quote($match[0]).'/', call_user_func_array(array($cl, $method), $params), $data);
774 }
775 }
777 return $data;
778 }
781 function getObjectType($types, $classes)
782 {
783 // Walk thru types and see if there's something matching
784 foreach ($types as $objectType) {
785 $ocs= $objectType['objectClass'];
786 if (!is_array($ocs)){
787 $ocs= array($ocs);
788 }
790 $found= true;
791 foreach ($ocs as $oc){
792 if (preg_match('/^!(.*)$/', $oc, $match)) {
793 $oc= $match[1];
794 if (in_array($oc, $classes)) {
795 $found= false;
796 }
797 } else {
798 if (!in_array($oc, $classes)) {
799 $found= false;
800 }
801 }
802 }
804 if ($found) {
805 return $objectType;
806 }
807 }
809 return null;
810 }
813 function filterObjectType($dn, $classes)
814 {
815 // Walk thru classes and return on first match
816 $result= " ";
818 $objectType= $this->getObjectType($this->objectTypes, $classes);
819 if ($objectType) {
820 $this->objectDnMapping[$dn]= $objectType["objectClass"];
821 $result= "<img class='center' title='".LDAP::fix($dn)."' src='".$objectType["image"]."'>";
822 if (!isset($this->objectTypeCount[$objectType['label']])) {
823 $this->objectTypeCount[$objectType['label']]= 0;
824 }
825 $this->objectTypeCount[$objectType['label']]++;
826 }
828 return $result;
829 }
832 function filterActions($dn, $row, $classes)
833 {
834 // Do nothing if there's no menu defined
835 if (!isset($this->xmlData['actiontriggers']['action'])) {
836 return " ";
837 }
839 // Go thru all actions
840 $result= "";
841 $actions= $this->xmlData['actiontriggers']['action'];
842 foreach($actions as $action) {
843 // Skip the entry completely if there's no permission to execute it
844 if (!$this->hasActionPermission($action, $dn, $classes)) {
845 $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
846 continue;
847 }
849 // Skip entry if the pseudo filter does not fit
850 if (isset($action['filter']) && preg_match('/^[a-z0-9_]+!?=[a-z0-9_]+$/i', $action['filter'])) {
851 list($fa, $fv)= explode('=', $action['filter']);
852 if (preg_match('/^(.*)!$/', $fa, $m)){
853 $fa= $m[1];
854 if (isset($this->entries[$row][$fa]) && $this->entries[$row][$fa][0] == $fv) {
855 $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
856 continue;
857 }
858 } else {
859 if (!isset($this->entries[$row][$fa]) && !$this->entries[$row][$fa][0] == $fv) {
860 $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
861 continue;
862 }
863 }
864 }
867 // If there's an objectclass definition and we don't have it
868 // add an empty picture here.
869 if (isset($action['objectclass'])){
870 $objectclass= $action['objectclass'];
871 if (preg_match('/^!(.*)$/', $objectclass, $m)){
872 $objectclass= $m[1];
873 if(in_array($objectclass, $classes)) {
874 $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
875 continue;
876 }
877 } elseif (is_string($objectclass)) {
878 if(!in_array($objectclass, $classes)) {
879 $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
880 continue;
881 }
882 } elseif (is_array($objectclass)) {
883 if(count(array_intersect($objectclass, $classes)) != count($objectclass)){
884 $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
885 continue;
886 }
887 }
888 }
890 // Render normal entries as usual
891 if ($action['type'] == "entry") {
892 $label= $this->processElementFilter($action['label'], $this->entries[$row], $row);
893 $image= $this->processElementFilter($action['image'], $this->entries[$row], $row);
894 $result.="<input class='center' type='image' src='$image' title='$label' ".
895 "name='listing_".$action['name']."_$row' style='padding:1px'>";
896 }
898 // Handle special types
899 if ($action['type'] == "copypaste" || $action['type'] == "snapshot") {
901 $objectType= $this->getObjectType($this->objectTypes, $this->entries[$row]['objectClass']);
902 $category= $class= null;
903 if ($objectType) {
904 $category= $objectType['category'];
905 $class= $objectType['class'];
906 }
908 if ($action['type'] == "copypaste") {
909 $copy = !isset($action['copy']) || $action['copy'] == "true";
910 $cut = !isset($action['cut']) || $action['cut'] == "true";
911 $result.= $this->renderCopyPasteActions($row, $this->entries[$row]['dn'], $category, $class,$copy,$cut);
912 } else {
913 $result.= $this->renderSnapshotActions($row, $this->entries[$row]['dn'], $category, $class);
914 }
915 }
916 }
918 return $result;
919 }
922 function filterDepartmentLink($row, $dn, $description)
923 {
924 $attr= $this->departments[$row]['sort-attribute'];
925 $name= $this->departments[$row][$attr];
926 if (is_array($name)){
927 $name= $name[0];
928 }
929 $result= sprintf("%s [%s]", $name, $description[0]);
930 return("<a href='?plug=".$_GET['plug']."&PID=$this->pid&act=department_$row' title='$dn'>$result</a>");
931 }
934 function filterLink()
935 {
936 $result= " ";
938 $row= func_get_arg(0);
939 $pid= $this->pid;
940 $dn= LDAP::fix(func_get_arg(1));
941 $params= array(func_get_arg(2));
943 // Collect sprintf params
944 for ($i = 3;$i < func_num_args();$i++) {
945 $val= func_get_arg($i);
946 if (is_array($val)){
947 $params[]= $val[0];
948 continue;
949 }
950 $params[]= $val;
951 }
953 $result= " ";
954 $trans= call_user_func_array("sprintf", $params);
955 if ($trans != "") {
956 return("<a href='?plug=".$_GET['plug']."&PID=$pid&act=listing_edit_$row' title='$dn'>$trans</a>");
957 }
959 return $result;
960 }
963 function renderNavigation()
964 {
965 $result= array();
966 $enableBack = true;
967 $enableRoot = true;
968 $enableHome = true;
970 $ui = get_userinfo();
972 /* Check if base = first available base */
973 $deps = $ui->get_module_departments($this->categories);
975 if(!count($deps) || $deps[0] == $this->filter->base){
976 $enableBack = false;
977 $enableRoot = false;
978 }
980 $listhead ="";
982 /* Check if we are in users home department */
983 if(!count($deps) || $this->filter->base == get_base_from_people($ui->dn)){
984 $enableHome = false;
985 }
987 /* Draw root button */
988 if($enableRoot){
989 $result["ROOT"]= "<input class='center' type='image' src='images/lists/root.png' align='middle' ".
990 "title='"._("Go to root department")."' name='ROOT' alt='"._("Root")."'>";
991 }else{
992 $result["ROOT"]= "<img src='images/lists/root_grey.png' class='center' alt='"._("Root")."'>";
993 }
995 /* Draw back button */
996 if($enableBack){
997 $result["BACK"]= "<input class='center' type='image' align='middle' src='images/lists/back.png' ".
998 "title='"._("Go up one department")."' alt='"._("Up")."' name='BACK'>";
999 }else{
1000 $result["BACK"]= "<img src='images/lists/back_grey.png' class='center' alt='"._("Up")."'>";
1001 }
1003 /* Draw home button */
1004 if($enableHome){
1005 $result["HOME"]= "<input class='center' type='image' align='middle' src='images/lists/home.png' ".
1006 "title='"._("Go to users department")."' alt='"._("Home")."' name='HOME'>";
1007 }else{
1008 $result["HOME"]= "<img src='images/lists/home_grey.png' class='center' alt='"._("Home")."'>";
1009 }
1011 /* Draw reload button, this button is enabled everytime */
1012 $result["RELOAD"]= "<input class='center' type='image' src='images/lists/reload.png' align='middle' ".
1013 "title='"._("Reload list")."' name='REFRESH' alt='"._("Submit")."'>";
1015 return ($result);
1016 }
1019 function getAction()
1020 {
1021 // Do not do anything if this is not our PID, or there's even no PID available...
1022 if(!isset($_REQUEST['PID']) || $_REQUEST['PID'] != $this->pid) {
1023 return;
1024 }
1026 // Save position if set
1027 if (isset($_POST['position_'.$this->pid]) && is_numeric($_POST['position_'.$this->pid])) {
1028 $this->scrollPosition= $_POST['position_'.$this->pid];
1029 }
1031 $result= array("targets" => array(), "action" => "");
1033 // Filter GET with "act" attributes
1034 if (isset($_GET['act'])) {
1035 $key= validate($_GET['act']);
1036 $target= preg_replace('/^listing_[a-zA-Z_]+_([0-9]+)$/', '$1', $key);
1037 if (isset($this->entries[$target]['dn'])) {
1038 $result['action']= preg_replace('/^listing_([a-zA-Z_]+)_[0-9]+$/', '$1', $key);
1039 $result['targets'][]= $this->entries[$target]['dn'];
1040 }
1042 // Drop targets if empty
1043 if (count($result['targets']) == 0) {
1044 unset($result['targets']);
1045 }
1046 return $result;
1047 }
1049 // Filter POST with "listing_" attributes
1050 foreach ($_POST as $key => $prop) {
1052 // Capture selections
1053 if (preg_match('/^listing_selected_[0-9]+$/', $key)) {
1054 $target= preg_replace('/^listing_selected_([0-9]+)$/', '$1', $key);
1055 if (isset($this->entries[$target]['dn'])) {
1056 $result['targets'][]= $this->entries[$target]['dn'];
1057 }
1058 continue;
1059 }
1061 // Capture action with target - this is a one shot
1062 if (preg_match('/^listing_[a-zA-Z_]+_[0-9]+(|_x)$/', $key)) {
1063 $target= preg_replace('/^listing_[a-zA-Z_]+_([0-9]+)(|_x)$/', '$1', $key);
1064 if (isset($this->entries[$target]['dn'])) {
1065 $result['action']= preg_replace('/^listing_([a-zA-Z_]+)_[0-9]+(|_x)$/', '$1', $key);
1066 $result['targets']= array($this->entries[$target]['dn']);
1067 }
1068 break;
1069 }
1071 // Capture action without target
1072 if (preg_match('/^listing_[a-zA-Z_]+(|_x)$/', $key)) {
1073 $result['action']= preg_replace('/^listing_([a-zA-Z_]+)(|_x)$/', '$1', $key);
1074 continue;
1075 }
1076 }
1078 // Filter POST with "act" attributes -> posted from action menu
1079 if (isset($_POST['act']) && $_POST['act'] != '') {
1080 if (!preg_match('/^export.*$/', $_POST['act'])){
1081 $result['action']= validate($_POST['act']);
1082 }
1083 }
1085 // Drop targets if empty
1086 if (count($result['targets']) == 0) {
1087 unset($result['targets']);
1088 }
1089 return $result;
1090 }
1093 function renderActionMenu()
1094 {
1095 // Don't send anything if the menu is not defined
1096 if (!isset($this->xmlData['actionmenu']['action'])){
1097 return "";
1098 }
1100 // Array?
1101 if (isset($this->xmlData['actionmenu']['action']['type'])){
1102 $this->xmlData['actionmenu']['action']= array($this->xmlData['actionmenu']['action']);
1103 }
1105 // Load shortcut
1106 $actions= &$this->xmlData['actionmenu']['action'];
1107 $result= "<input type='hidden' name='act' id='actionmenu' value=''><div style='display:none'><input type='submit' name='exec_act' id='exec_act' value=''></div>".
1108 "<ul class='level1' id='root'><li><a href='#'>"._("Actions")." <img ".
1109 "border=0 class='center' src='images/lists/sort-down.png'></a>";
1111 // Build ul/li list
1112 $result.= $this->recurseActions($actions);
1114 return "<div id='pulldown'>".$result."</li></ul><div>";
1115 }
1118 function recurseActions($actions)
1119 {
1120 global $class_mapping;
1121 static $level= 2;
1122 $result= "<ul class='level$level'>";
1123 $separator= "";
1125 foreach ($actions as $action) {
1127 // Skip the entry completely if there's no permission to execute it
1128 if (!$this->hasActionPermission($action, $this->filter->base)) {
1129 continue;
1130 }
1132 // Skip entry if there're missing dependencies
1133 if (isset($action['depends'])) {
1134 $deps= is_array($action['depends'])?$action['depends']:array($action['depends']);
1135 foreach($deps as $clazz) {
1136 if (!isset($class_mapping[$clazz])){
1137 continue 2;
1138 }
1139 }
1140 }
1142 // Fill image if set
1143 $img= "";
1144 if (isset($action['image'])){
1145 $img= "<img border='0' class='center' src='".$action['image']."'> ";
1146 }
1148 if ($action['type'] == "separator"){
1149 $separator= " style='border-top:1px solid #AAA' ";
1150 continue;
1151 }
1153 // Dive into subs
1154 if ($action['type'] == "sub" && isset($action['action'])) {
1155 $level++;
1156 if (isset($action['label'])){
1157 $result.= "<li$separator><a href='#'>$img"._($action['label'])." <img border='0' src='images/forward-arrow.png'></a>";
1158 }
1160 // Ensure we've an array of actions, this enables sub menus with only one action.
1161 if(isset($action['action']['type'])){
1162 $action['action'] = array($action['action']);
1163 }
1165 $result.= $this->recurseActions($action['action'])."</li>";
1166 $level--;
1167 $separator= "";
1168 continue;
1169 }
1171 // Render entry elseways
1172 if (isset($action['label'])){
1173 $result.= "<li$separator><a href='#' onClick='document.getElementById(\"actionmenu\").value= \"".$action['name']."\";mainform.submit();'>$img"._($action['label'])."</a></li>";
1174 }
1176 // Check for special types
1177 switch ($action['type']) {
1178 case 'copypaste':
1179 $cut = !isset($action['cut']) || $action['cut'] != "false";
1180 $copy = !isset($action['copy']) || $action['copy'] != "false";
1181 $result.= $this->renderCopyPasteMenu($separator, $copy , $cut);
1182 break;
1184 case 'snapshot':
1185 $result.= $this->renderSnapshotMenu($separator);
1186 break;
1188 case 'exporter':
1189 $result.= $this->renderExporterMenu($separator);
1190 break;
1192 case 'daemon':
1193 $result.= $this->renderDaemonMenu($separator);
1194 break;
1195 }
1197 $separator= "";
1198 }
1200 $result.= "</ul>";
1201 return $result;
1202 }
1205 function hasActionPermission($action, $dn, $classes= null)
1206 {
1207 $ui= get_userinfo();
1209 if (isset($action['acl'])) {
1210 $acls= $action['acl'];
1211 if (!is_array($acls)) {
1212 $acls= array($acls);
1213 }
1215 // Every ACL has to pass
1216 foreach ($acls as $acl) {
1217 $module= $this->categories;
1218 $aclList= array();
1220 // Replace %acl if available
1221 if ($classes) {
1222 $otype= $this->getObjectType($this->objectTypes, $classes);
1223 $acl= str_replace('%acl', $otype['category']."/".$otype['class'], $acl);
1224 }
1226 // Split for category and plugins if needed
1227 // match for "[rw]" style entries
1228 if (preg_match('/^\[([rwcdm]+)\]$/', $acl, $match)){
1229 $aclList= array($match[1]);
1230 }
1232 // match for "users[rw]" style entries
1233 if (preg_match('/^([a-zA-Z0-9]+)\[([rwcdm]+)\]$/', $acl, $match)){
1234 $module= $match[1];
1235 $aclList= array($match[2]);
1236 }
1238 // match for "users/user[rw]" style entries
1239 if (preg_match('/^([a-zA-Z0-9]+\/[a-zA-Z0-9]+)\[([rwcdm]+)\]$/', $acl, $match)){
1240 $module= $match[1];
1241 $aclList= array($match[2]);
1242 }
1244 // match "users/user[userPassword:rw(,...)*]" style entries
1245 if (preg_match('/^([a-zA-Z0-9]+\/[a-zA-Z0-9]+)\[([a-zA-Z0-9]+:[rwcdm]+(,[a-zA-Z0-9]+:[rwcdm]+)*)\]$/', $acl, $match)){
1246 $module= $match[1];
1247 $aclList= explode(',', $match[2]);
1248 }
1250 // Walk thru prepared ACL by using $module
1251 foreach($aclList as $sAcl) {
1252 $checkAcl= "";
1254 // Category or detailed permission?
1255 if (strpos($module, '/') !== false) {
1256 if (preg_match('/([a-zA-Z0-9]+):([rwcdm]+)/', $sAcl, $m) ) {
1257 $checkAcl= $ui->get_permissions($dn, $module, $m[1]);
1258 $sAcl= $m[2];
1259 } else {
1260 $checkAcl= $ui->get_permissions($dn, $module, '0');
1261 }
1262 } else {
1263 $checkAcl= $ui->get_category_permissions($dn, $module);
1264 }
1266 // Split up remaining part of the acl and check if it we're
1267 // allowed to do something...
1268 $parts= str_split($sAcl);
1269 foreach ($parts as $part) {
1270 if (strpos($checkAcl, $part) === false){
1271 return false;
1272 }
1273 }
1275 }
1276 }
1277 }
1279 return true;
1280 }
1283 function refreshBasesList()
1284 {
1285 global $config;
1286 $ui= get_userinfo();
1288 // Do some array munching to get it user friendly
1289 $ids= $config->idepartments;
1290 $d= $ui->get_module_departments($this->categories);
1291 $k_ids= array_keys($ids);
1292 $deps= array_intersect($d,$k_ids);
1294 // Fill internal bases list
1295 $this->bases= array();
1296 foreach($k_ids as $department){
1297 $this->bases[$department] = $ids[$department];
1298 }
1300 // Populate base selector if already present
1301 if ($this->baseSelector && $this->baseMode) {
1302 $this->baseSelector->setBases($this->bases);
1303 $this->baseSelector->update(TRUE);
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 getEntries()
1564 {
1565 return $this->entries;
1566 }
1569 function getType($dn)
1570 {
1571 if (isset($this->objectDnMapping[$dn])) {
1572 return $this->objectDnMapping[$dn];
1573 }
1574 return null;
1575 }
1577 }
1579 ?>