6ca5c31ae9db4990472894146897bbc2fa60b7d7
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 $singleSelect= false;
32 var $template;
33 var $headline;
34 var $base;
35 var $sortDirection= null;
36 var $sortColumn= null;
37 var $sortAttribute;
38 var $sortType;
39 var $numColumns;
40 var $baseMode= false;
41 var $bases= array();
42 var $header= array();
43 var $colprops= array();
44 var $filters= array();
45 var $filter= null;
46 var $pid;
47 var $objectTypes= array();
48 var $objectTypeCount= array();
49 var $objectDnMapping= array();
50 var $copyPasteHandler= null;
51 var $snapshotHandler= null;
52 var $exporter= array();
53 var $exportColumns= array();
54 var $useSpan= false;
55 var $height= 0;
56 var $scrollPosition= 0;
57 var $baseSelector;
60 function listing($filename)
61 {
62 global $config;
63 global $class_mapping;
65 // Initialize pid
66 $this->pid= preg_replace("/[^0-9]/", "", microtime(TRUE));
68 if (!$this->load($filename)) {
69 die("Cannot parse $filename!");
70 }
72 // Set base for filter
73 if ($this->baseMode) {
74 $this->base= session::global_get("CurrentMainBase");
75 if ($this->base == null) {
76 $this->base= $config->current['BASE'];
77 }
78 $this->refreshBasesList();
79 } else {
80 $this->base= $config->current['BASE'];
81 }
83 // Move footer information
84 $this->showFooter= ($config->get_cfg_value("listSummary") == "true");
86 // Register build in filters
87 $this->registerElementFilter("objectType", "listing::filterObjectType");
88 $this->registerElementFilter("departmentLink", "listing::filterDepartmentLink");
89 $this->registerElementFilter("link", "listing::filterLink");
90 $this->registerElementFilter("actions", "listing::filterActions");
92 // Load exporters
93 foreach($class_mapping as $class => $dummy) {
94 if (preg_match('/Exporter$/', $class)) {
95 $info= call_user_func(array($class, "getInfo"));
96 if ($info != null) {
97 $this->exporter= array_merge($this->exporter, $info);
98 }
99 }
100 }
102 // Instanciate base selector
103 $this->baseSelector= new baseSelector($this->bases, $this->base);
104 }
107 function setCopyPasteHandler($handler)
108 {
109 $this->copyPasteHandler= &$handler;
110 }
113 function setHeight($height)
114 {
115 $this->height= $height;
116 }
119 function setSnapshotHandler($handler)
120 {
121 $this->snapshotHandler= &$handler;
122 }
125 function getFilter()
126 {
127 return($this->filter);
128 }
131 function setFilter($filter)
132 {
133 $this->filter= &$filter;
134 if ($this->departmentBrowser){
135 $this->departments= $this->getDepartments();
136 }
137 $this->filter->setBase($this->base);
138 }
141 function registerElementFilter($name, $call)
142 {
143 if (!isset($this->filters[$name])) {
144 $this->filters[$name]= $call;
145 return true;
146 }
148 return false;
149 }
152 function load($filename)
153 {
154 $contents = file_get_contents($filename);
155 $this->xmlData= xml::xml2array($contents, 1);
157 if (!isset($this->xmlData['list'])) {
158 return false;
159 }
161 $this->xmlData= $this->xmlData["list"];
163 // Load some definition values
164 foreach (array("departmentBrowser", "departmentRootVisible", "multiSelect","singleSelect", "baseMode") as $token) {
165 if (isset($this->xmlData['definition'][$token]) &&
166 $this->xmlData['definition'][$token] == "true"){
167 $this->$token= true;
168 }
169 }
171 // Fill objectTypes from departments and xml definition
172 $types = departmentManagement::get_support_departments();
173 foreach ($types as $class => $data) {
174 $this->objectTypes[$data['OC']]= array("label" => $data['TITLE'],
175 "objectClass" => $data['OC'],
176 "image" => $data['IMG']);
177 }
178 $this->categories= array();
179 if (isset($this->xmlData['definition']['objectType'])) {
180 if(isset($this->xmlData['definition']['objectType']['label'])) {
181 $this->xmlData['definition']['objectType']= array($this->xmlData['definition']['objectType']);
182 }
183 foreach ($this->xmlData['definition']['objectType'] as $index => $otype) {
184 $tmp = $this->xmlData['definition']['objectType'][$index];
185 $this->objectTypes[$tmp['objectClass']]= $tmp;
186 if (isset($this->xmlData['definition']['objectType'][$index]['category'])){
187 $this->categories[]= $otype['category'];
188 }
189 }
190 }
191 $this->objectTypes = array_values($this->objectTypes);
193 // Parse layout per column
194 $this->colprops= $this->parseLayout($this->xmlData['table']['layout']);
196 // Prepare table headers
197 $this->renderHeader();
199 // Assign headline/Categories
200 $this->headline= _($this->xmlData['definition']['label']);
201 if (!is_array($this->categories)){
202 $this->categories= array($this->categories);
203 }
205 // Evaluate columns to be exported
206 if (isset($this->xmlData['table']['column'])){
207 foreach ($this->xmlData['table']['column'] as $index => $config) {
208 if (isset($config['export']) && $config['export'] == "true"){
209 $this->exportColumns[]= $index;
210 }
211 }
212 }
214 return true;
215 }
218 function renderHeader()
219 {
220 $this->header= array();
221 $this->plainHeader= array();
223 // Initialize sort?
224 $sortInit= false;
225 if (!$this->sortDirection) {
226 $this->sortColumn= 0;
227 if (isset($this->xmlData['definition']['defaultSortColumn'])){
228 $this->sortColumn= $this->xmlData['definition']['defaultSortColumn'];
229 } else {
230 $this->sortAttribute= "";
231 }
232 $this->sortDirection= array();
233 $sortInit= true;
234 }
236 if (isset($this->xmlData['table']['column'])){
237 foreach ($this->xmlData['table']['column'] as $index => $config) {
238 // Initialize everything to one direction
239 if ($sortInit) {
240 $this->sortDirection[$index]= false;
241 }
243 $sorter= "";
244 if ($index == $this->sortColumn && isset($config['sortAttribute']) &&
245 isset($config['sortType'])) {
246 $this->sortAttribute= $config['sortAttribute'];
247 $this->sortType= $config['sortType'];
248 $sorter= " ".image("images/lists/sort-".($this->sortDirection[$index]?"up":"down").".png", null, $this->sortDirection[$index]?_("Up"):_("Down"), "text-top");
249 }
250 $sortable= (isset($config['sortAttribute']));
252 $link= "href='?plug=".$_GET['plug']."&PID=".$this->pid."&act=SORT_$index'";
253 if (isset($config['label'])) {
254 if ($sortable) {
255 $this->header[$index]= "<td class='listheader' ".$this->colprops[$index]."><a $link>"._($config['label'])."</a>$sorter</td>";
256 } else {
257 $this->header[$index]= "<td class='listheader' ".$this->colprops[$index].">"._($config['label'])."</td>";
258 }
259 $this->plainHeader[]= _($config['label']);
260 } else {
261 if ($sortable) {
262 $this->header[$index]= "<td class='listheader' ".$this->colprops[$index]."><a $link> </a>$sorter</td>";
263 } else {
264 $this->header[$index]= "<td class='listheader' ".$this->colprops[$index]."> </td>";
265 }
266 $this->plainHeader[]= "";
267 }
268 }
269 }
270 }
273 function render()
274 {
275 // Check for exeeded sizelimit
276 if (($message= check_sizelimit()) != ""){
277 return($message);
278 }
280 // Some browsers don't have the ability do do scrollable table bodies, filter them
281 // here.
282 $switch= false;
283 if (preg_match('/(Opera|Konqueror|Safari)/i', $_SERVER['HTTP_USER_AGENT'])){
284 $switch= true;
285 }
287 // Initialize list
288 $result= "<input type='hidden' value='$this->pid' name='PID'>\n";
289 $result.= "<input type='hidden' name='position_".$this->pid."' id='position_".$this->pid."'>\n";
290 $height= 450;
291 if ($this->height != 0) {
292 $result.= "<input type='hidden' value='$this->height' id='d_height'>\n";
293 $height= $this->height;
294 }
296 $result.= "<div class='listContainer' id='d_scrollbody' style='min-height:".($height+25)."px;'>\n";
297 $result.= "<table summary='$this->headline' style='width:100%;table-layout:fixed' cellspacing='0' cellpadding='0' id='t_scrolltable'>\n";
298 $this->numColumns= count($this->colprops) + (($this->multiSelect|$this->singleSelect)?1:0);
300 // Build list header
301 $result.= "<thead class='fixedListHeader listHeaderFormat'><tr>\n";
302 if ($this->multiSelect || $this->singleSelect) {
303 $width= "24px";
304 if (preg_match('/Konqueror/i', $_SERVER['HTTP_USER_AGENT'])){
305 $width= "28px";
306 }
307 $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";
308 }
309 foreach ($this->header as $header) {
310 $result.= $header;
311 }
312 $result.= "</tr></thead>\n";
314 // Build list body
315 $result.= "<tbody class='listScrollContent listBodyFormat' id='t_nscrollbody' style='height:".$height."px;'>\n";
317 // No results? Just take an empty colspanned row
318 if (count($this->entries) + count($this->departments) == 0) {
319 $result.= "<tr><td class='list1nohighlight' colspan='$this->numColumns' style='height:100%;border-right:0px;width:100%;'> </td></tr>";
320 }
322 // Line color alternation
323 $alt= 0;
324 $deps= 0;
326 // Draw department browser if configured and we're not in sub mode
327 $this->useSpan= false;
328 if ($this->departmentBrowser && $this->filter->scope != "sub") {
329 // Fill with department browser if configured this way
330 $departmentIterator= new departmentSortIterator($this->departments, $this->sortDirection[$this->sortColumn]);
331 foreach ($departmentIterator as $row => $entry){
332 $result.="<tr>";
334 // Render multi select if needed
335 if ($this->multiSelect || $this->singleSelect) {
336 $result.="<td style='text-align:center;padding:0;' class='list1'> </td>";
337 }
339 // Render defined department columns, fill the rest with some stuff
340 $rest= $this->numColumns - 1;
341 foreach ($this->xmlData['table']['department'] as $index => $config) {
342 $colspan= 1;
343 if (isset($config['span'])){
344 $colspan= $config['span'];
345 $this->useSpan= true;
346 }
347 $result.="<td colspan='$colspan' ".$this->colprops[$index]." class='list1'>".$this->renderCell($config['value'], $entry, $row)."</td>";
348 $rest-= $colspan;
349 }
351 // Fill remaining cols with nothing
352 $last= $this->numColumns - $rest;
353 for ($i= 0; $i<$rest; $i++){
354 $result.= "<td ".$this->colprops[$last+$i-1]." class='list1'> </td>";
355 }
356 $result.="</tr>";
358 $alt++;
359 }
360 $deps= $alt;
361 }
363 // Fill with contents, sort as configured
364 foreach ($this->entries as $row => $entry) {
365 $trow= "";
367 // Render multi select if needed
368 if ($this->multiSelect) {
369 $trow.="<td style='text-align:center;width:20px;' class='list0'><input type='checkbox' id='listing_selected_$row' name='listing_selected_$row'></td>\n";
370 }
372 if ($this->singleSelect) {
373 $trow.="<td style='text-align:center;width:20px;' class='list0'><input type='radio' id='listing_radio_selected_$row' name='listing_radio_selected' value='{$row}'></td>\n";
374 }
376 foreach ($this->xmlData['table']['column'] as $index => $config) {
377 $renderedCell= $this->renderCell($config['value'], $entry, $row);
378 $trow.="<td ".$this->colprops[$index]." class='list0'>".$renderedCell."</td>\n";
380 // Save rendered column
381 $sort= preg_replace('/.*>([^<]+)<.*$/', '$1', $renderedCell);
382 $sort= preg_replace('/ /', '', $sort);
383 if (preg_match('/</', $sort)){
384 $sort= "";
385 }
386 $this->entries[$row]["_sort$index"]= $sort;
387 }
389 // Save rendered entry
390 $this->entries[$row]['_rendered']= $trow;
391 }
393 // Complete list by sorting entries for _sort$index and appending them to the output
394 $entryIterator= new listingSortIterator($this->entries, $this->sortDirection[$this->sortColumn], "_sort".$this->sortColumn, $this->sortType);
395 foreach ($entryIterator as $row => $entry){
397 // Apply custom class to row?
398 if (preg_match("/<rowClass:([a-z0-9_-]*)\/>/i", $entry['_rendered'], $matches)) {
399 $result.="<tr class='".$matches[1]."'>\n";
400 $result.= preg_replace("/<rowClass[^>]+>/", '', $entry['_rendered']);
401 } else {
402 $result.="<tr>\n";
403 $result.= $entry['_rendered'];
404 }
406 $result.="</tr>\n";
407 $alt++;
408 }
410 // Need to fill the list if it's not full (nobody knows why this is 22 ;-))
411 $emptyListStyle= (count($this->entries) + (($this->useSpan && count($this->entries))?$deps:0) == 0)?"border:0;":"";
412 if ((count($this->entries) + $deps) < 22) {
413 $result.= "<tr>";
414 for ($i= 0; $i<$this->numColumns; $i++) {
415 if ($i == 0) {
416 $result.= "<td class='list1nohighlight' style='$emptyListStyle height:100%;'> </td>";
417 continue;
418 }
419 if ($i != $this->numColumns-1) {
420 $result.= "<td class='list1nohighlight' style='$emptyListStyle'> </td>";
421 } else {
422 $result.= "<td class='list1nohighlight' style='border-right:0;$emptyListStyle'> </td>";
423 }
424 }
426 $result.= "</tr>";
427 }
429 // Close list body
430 $result.= "</tbody></table></div>";
432 // Add the footer if requested
433 if ($this->showFooter) {
434 $result.= "<div class='nlistFooter'><div style='padding:3px'>";
436 foreach ($this->objectTypes as $objectType) {
437 if (isset($this->objectTypeCount[$objectType['label']])) {
438 $label= _($objectType['label']);
439 $result.= image($objectType['image'], null, $label)." ".$this->objectTypeCount[$objectType['label']]." ";
440 }
441 }
443 $result.= "</div></div>";
444 }
446 // Close list
447 $result.= $switch?"<input type='hidden' id='list_workaround'>":"";
449 // Add scroll positioner
450 $result.= '<script type="text/javascript" language="javascript">';
451 $result.= '$("t_nscrollbody").scrollTop= '.$this->scrollPosition.';';
452 $result.= 'var box = $("t_nscrollbody").onscroll= function() {$("position_'.$this->pid.'").value= this.scrollTop;}';
453 $result.= '</script>';
455 $smarty= get_smarty();
456 $smarty->assign("usePrototype", "true");
457 $smarty->assign("FILTER", $this->filter->render());
458 $smarty->assign("SIZELIMIT", print_sizelimit_warning());
459 $smarty->assign("LIST", $result);
461 // Assign navigation elements
462 $nav= $this->renderNavigation();
463 foreach ($nav as $key => $html) {
464 $smarty->assign($key, $html);
465 }
467 // Assign action menu / base
468 $smarty->assign("HEADLINE", $this->headline);
469 $smarty->assign("ACTIONS", $this->renderActionMenu());
470 $smarty->assign("BASE", $this->renderBase());
472 // Assign separator
473 $smarty->assign("SEPARATOR", "<img src='images/lists/seperator.png' alt='-' align='middle' height='16' width='1' class='center'>");
475 // Assign summary
476 $smarty->assign("HEADLINE", $this->headline);
478 // Try to load template from plugin the folder first...
479 $file = get_template_path($this->xmlData['definition']['template'], true);
481 // ... if this fails, try to load the file from the theme folder.
482 if(!file_exists($file)){
483 $file = get_template_path($this->xmlData['definition']['template']);
484 }
486 return ($smarty->fetch($file));
487 }
490 function update()
491 {
492 global $config;
493 $ui= get_userinfo();
495 // Take care of base selector
496 if ($this->baseMode) {
497 $this->baseSelector->update();
498 // Check if a wrong base was supplied
499 if(!$this->baseSelector->checkLastBaseUpdate()){
500 msg_dialog::display(_("Error"), msgPool::check_base(), ERROR_DIALOG);
501 }
502 }
504 // Save base
505 $refresh= false;
506 if ($this->baseMode) {
507 $this->base= $this->baseSelector->getBase();
508 session::global_set("CurrentMainBase", $this->base);
509 $refresh= true;
510 }
513 // Reset object counter / DN mapping
514 $this->objectTypeCount= array();
515 $this->objectDnMapping= array();
517 // Do not do anything if this is not our PID
518 if($refresh || !(isset($_REQUEST['PID']) && $_REQUEST['PID'] != $this->pid)) {
520 // Save position if set
521 if (isset($_POST['position_'.$this->pid]) && is_numeric($_POST['position_'.$this->pid])) {
522 $this->scrollPosition= $_POST['position_'.$this->pid];
523 }
525 // Override the base if we got a message from the browser navigation
526 if ($this->departmentBrowser && isset($_GET['act'])) {
527 if (preg_match('/^department_([0-9]+)$/', validate($_GET['act']), $match)){
528 if (isset($this->departments[$match[1]])){
529 $this->base= $this->departments[$match[1]]['dn'];
530 if ($this->baseMode) {
531 $this->baseSelector->setBase($this->base);
532 }
533 session::global_set("CurrentMainBase", $this->base);
534 }
535 }
536 }
538 // Filter POST with "act" attributes -> posted from action menu
539 if (isset($_POST['exec_act']) && $_POST['act'] != '') {
540 if (preg_match('/^export.*$/', $_POST['act']) && isset($this->exporter[$_POST['act']])) {
541 $exporter= $this->exporter[$_POST['act']];
542 $userinfo= ", "._("created by")." ".$ui->cn." - ".strftime('%A, %d. %B %Y, %H:%M:%S');
543 $entryIterator= new listingSortIterator($this->entries, $this->sortDirection[$this->sortColumn], "_sort".$this->sortColumn, $this->sortType);
544 $sortedEntries= array();
545 foreach ($entryIterator as $entry){
546 $sortedEntries[]= $entry;
547 }
548 $instance= new $exporter['class']($this->headline.$userinfo, $this->plainHeader, $sortedEntries, $this->exportColumns);
549 $type= call_user_func(array($exporter['class'], "getInfo"));
550 $type= $type[$_POST['act']];
551 send_binary_content($instance->query(), $type['filename'], $type= $type['mime']);
552 }
553 }
555 // Filter GET with "act" attributes
556 if (isset($_GET['act'])) {
557 $key= validate($_GET['act']);
558 if (preg_match('/^SORT_([0-9]+)$/', $key, $match)) {
559 // Switch to new column or invert search order?
560 $column= $match[1];
561 if ($this->sortColumn != $column) {
562 $this->sortColumn= $column;
563 } else {
564 $this->sortDirection[$column]= !$this->sortDirection[$column];
565 }
567 // Allow header to update itself according to the new sort settings
568 $this->renderHeader();
569 }
570 }
572 // Override base if we got signals from the navigation elements
573 $action= "";
574 foreach ($_POST as $key => $value) {
575 if (preg_match('/^(ROOT|BACK|HOME)(_x)?$/', $key, $match)) {
576 $action= $match[1];
577 break;
578 }
579 }
581 // Navigation handling
582 if ($action == 'ROOT') {
583 $deps= $ui->get_module_departments($this->categories);
584 $this->base= $deps[0];
585 $this->baseSelector->setBase($this->base);
586 session::global_set("CurrentMainBase", $this->base);
587 }
588 if ($action == 'BACK') {
589 $deps= $ui->get_module_departments($this->categories);
590 $base= preg_replace("/^[^,]+,/", "", $this->base);
591 if(in_array_ics($base, $deps)){
592 $this->base= $base;
593 $this->baseSelector->setBase($this->base);
594 session::global_set("CurrentMainBase", $this->base);
595 }
596 }
597 if ($action == 'HOME') {
598 $ui= get_userinfo();
599 $this->base= get_base_from_people($ui->dn);
600 $this->baseSelector->setBase($this->base);
601 session::global_set("CurrentMainBase", $this->base);
602 }
603 }
605 // Reload departments
606 if ($this->departmentBrowser){
607 $this->departments= $this->getDepartments();
608 }
610 // Update filter and refresh entries
611 $this->filter->setBase($this->base);
612 $this->entries= $this->filter->query();
614 // Fix filter if querie returns NULL
615 if ($this->entries == null) {
616 $this->entries= array();
617 }
618 }
621 function setBase($base)
622 {
623 $this->base= $base;
624 if ($this->baseMode) {
625 $this->baseSelector->setBase($this->base);
626 }
627 }
630 function getBase()
631 {
632 return $this->base;
633 }
636 function parseLayout($layout)
637 {
638 $result= array();
639 $layout= preg_replace("/^\|/", "", $layout);
640 $layout= preg_replace("/\|$/", "", $layout);
641 $cols= explode("|", $layout);
643 foreach ($cols as $index => $config) {
644 if ($config != "") {
645 $res= "";
646 $components= explode(';', $config);
647 foreach ($components as $part) {
648 if (preg_match("/^r$/", $part)) {
649 $res.= "text-align:right;";
650 continue;
651 }
652 if (preg_match("/^l$/", $part)) {
653 $res.= "text-align:left;";
654 continue;
655 }
656 if (preg_match("/^c$/", $part)) {
657 $res.= "text-align:center;";
658 continue;
659 }
660 if (preg_match("/^[0-9]+(|px|%)$/", $part)) {
661 $res.= "width:$part;min-width:$part;";
662 continue;
663 }
664 }
666 // Add minimum width for scalable columns
667 if (!preg_match('/width:/', $res)){
668 $res.= "min-width:200px;";
669 }
671 $result[$index]= " style='$res'";
672 } else {
673 $result[$index]= " style='min-width:100px;'";
674 }
675 }
677 // Save number of columns for later use
678 $this->numColumns= count($cols);
680 // Add no border to the last column
681 $result[$this->numColumns-1]= preg_replace("/'$/", "border-right:0;'", $result[$this->numColumns-1]);
683 return $result;
684 }
687 function renderCell($data, $config, $row)
688 {
689 // Replace flat attributes in data string
690 for ($i= 0; $i<$config['count']; $i++) {
691 $attr= $config[$i];
692 $value= "";
693 if (is_array($config[$attr])) {
694 $value= $config[$attr][0];
695 } else {
696 $value= $config[$attr];
697 }
698 $data= preg_replace("/%\{$attr\}/", $value, $data);
699 }
701 // Watch out for filters and prepare to execute them
702 $data= $this->processElementFilter($data, $config, $row);
704 // Replace all non replaced %{...} instances because they
705 // are non resolved attributes or filters
706 $data= preg_replace('/%{[^}]+}/', ' ', $data);
708 return $data;
709 }
712 function renderBase()
713 {
714 if (!$this->baseMode) {
715 return;
716 }
718 return $this->baseSelector->render();
719 }
722 function processElementFilter($data, $config, $row)
723 {
724 preg_match_all("/%\{filter:([^(]+)\((.*)\)\}/", $data, $matches, PREG_SET_ORDER);
726 foreach ($matches as $match) {
727 $cl= "";
728 $method= "";
729 if (preg_match('/::/', $match[1])) {
730 $cl= preg_replace('/::.*$/', '', $match[1]);
731 $method= preg_replace('/^.*::/', '', $match[1]);
732 } else {
733 if (!isset($this->filters[$match[1]])) {
734 continue;
735 }
736 $cl= preg_replace('/::.*$/', '', $this->filters[$match[1]]);
737 $method= preg_replace('/^.*::/', '', $this->filters[$match[1]]);
738 }
740 // Prepare params for function call
741 $params= array();
742 preg_match_all('/"[^"]+"|[^,]+/', $match[2], $parts);
743 foreach ($parts[0] as $param) {
745 // Row is replaced by the row number
746 if ($param == "row") {
747 $params[]= $row;
748 continue;
749 }
751 // pid is replaced by the current PID
752 if ($param == "pid") {
753 $params[]= $this->pid;
754 continue;
755 }
757 // base is replaced by the current base
758 if ($param == "base") {
759 $params[]= $this->getBase();
760 continue;
761 }
763 // Fixie with "" is passed directly
764 if (preg_match('/^".*"$/', $param)){
765 $params[]= preg_replace('/"/', '', $param);
766 continue;
767 }
769 // Move dn if needed
770 if ($param == "dn") {
771 $params[]= LDAP::fix($config["dn"]);
772 continue;
773 }
775 // LDAP variables get replaced by their objects
776 for ($i= 0; $i<$config['count']; $i++) {
777 if ($param == $config[$i]) {
778 $values= $config[$config[$i]];
779 if (is_array($values)){
780 unset($values['count']);
781 }
782 $params[]= $values;
783 break;
784 }
785 }
786 }
788 // Replace information
789 if ($cl == "listing") {
790 // Non static call - seems to result in errors
791 $data= @preg_replace('/'.preg_quote($match[0]).'/', call_user_func_array(array($this, "$method"), $params), $data);
792 } else {
793 // Static call
794 $data= preg_replace('/'.preg_quote($match[0]).'/', call_user_func_array(array($cl, $method), $params), $data);
795 }
796 }
798 return $data;
799 }
802 function getObjectType($types, $classes)
803 {
804 // Walk thru types and see if there's something matching
805 foreach ($types as $objectType) {
806 $ocs= $objectType['objectClass'];
807 if (!is_array($ocs)){
808 $ocs= array($ocs);
809 }
811 $found= true;
812 foreach ($ocs as $oc){
813 if (preg_match('/^!(.*)$/', $oc, $match)) {
814 $oc= $match[1];
815 if (in_array($oc, $classes)) {
816 $found= false;
817 }
818 } else {
819 if (!in_array($oc, $classes)) {
820 $found= false;
821 }
822 }
823 }
825 if ($found) {
826 return $objectType;
827 }
828 }
830 return null;
831 }
834 function filterObjectType($dn, $classes)
835 {
836 // Walk thru classes and return on first match
837 $result= " ";
839 $objectType= $this->getObjectType($this->objectTypes, $classes);
840 if ($objectType) {
841 $this->objectDnMapping[$dn]= $objectType["objectClass"];
842 $result= image($objectType["image"], null, LDAP::fix($dn));
843 if (!isset($this->objectTypeCount[$objectType['label']])) {
844 $this->objectTypeCount[$objectType['label']]= 0;
845 }
846 $this->objectTypeCount[$objectType['label']]++;
847 }
849 return $result;
850 }
853 function filterActions($dn, $row, $classes)
854 {
855 // Do nothing if there's no menu defined
856 if (!isset($this->xmlData['actiontriggers']['action'])) {
857 return " ";
858 }
860 // Go thru all actions
861 $result= "";
862 $actions= $this->xmlData['actiontriggers']['action'];
864 // Ensure we've a valid actions array, if there is only one action in the actiontriggers col
865 // then we've to create a valid array here.
866 if(isset($actions['name'])) $actions = array($actions);
868 foreach($actions as $action) {
869 // Skip the entry completely if there's no permission to execute it
870 if (!$this->hasActionPermission($action, $dn, $classes)) {
871 $result.= image('images/empty.png');
872 continue;
873 }
875 // Skip entry if the pseudo filter does not fit
876 if (isset($action['filter']) && preg_match('/^[a-z0-9_]+!?=[a-z0-9_]+$/i', $action['filter'])) {
877 list($fa, $fv)= explode('=', $action['filter']);
878 if (preg_match('/^(.*)!$/', $fa, $m)){
879 $fa= $m[1];
880 if (isset($this->entries[$row][$fa]) && $this->entries[$row][$fa][0] == $fv) {
881 $result.= image('images/empty.png');
882 continue;
883 }
884 } else {
885 if (!isset($this->entries[$row][$fa]) && !$this->entries[$row][$fa][0] == $fv) {
886 $result.= image('images/empty.png');
887 continue;
888 }
889 }
890 }
893 // If there's an objectclass definition and we don't have it
894 // add an empty picture here.
895 if (isset($action['objectclass'])){
896 $objectclass= $action['objectclass'];
897 if (preg_match('/^!(.*)$/', $objectclass, $m)){
898 $objectclass= $m[1];
899 if(in_array($objectclass, $classes)) {
900 $result.= image('images/empty.png');
901 continue;
902 }
903 } elseif (is_string($objectclass)) {
904 if(!in_array($objectclass, $classes)) {
905 $result.= image('images/empty.png');
906 continue;
907 }
908 } elseif (is_array($objectclass)) {
909 if(count(array_intersect($objectclass, $classes)) != count($objectclass)){
910 $result.= image('images/empty.png');
911 continue;
912 }
913 }
914 }
916 // Render normal entries as usual
917 if ($action['type'] == "entry") {
918 $label= $this->processElementFilter($action['label'], $this->entries[$row], $row);
919 $image= $this->processElementFilter($action['image'], $this->entries[$row], $row);
920 $result.= image($image, "listing_".$action['name']."_$row", $label);
921 }
923 // Handle special types
924 if ($action['type'] == "copypaste" || $action['type'] == "snapshot") {
926 $objectType= $this->getObjectType($this->objectTypes, $this->entries[$row]['objectClass']);
927 $category= $class= null;
928 if ($objectType) {
929 $category= $objectType['category'];
930 $class= $objectType['class'];
931 }
933 if ($action['type'] == "copypaste") {
934 $copy = !isset($action['copy']) || $action['copy'] == "true";
935 $cut = !isset($action['cut']) || $action['cut'] == "true";
936 $result.= $this->renderCopyPasteActions($row, $this->entries[$row]['dn'], $category, $class,$copy,$cut);
937 } else {
938 $result.= $this->renderSnapshotActions($row, $this->entries[$row]['dn'], $category, $class);
939 }
940 }
941 }
943 return $result;
944 }
947 function filterDepartmentLink($row, $dn, $description)
948 {
949 $attr= $this->departments[$row]['sort-attribute'];
950 $name= $this->departments[$row][$attr];
951 if (is_array($name)){
952 $name= $name[0];
953 }
954 $result= sprintf("%s [%s]", $name, $description[0]);
955 return("<a href='?plug=".$_GET['plug']."&PID=$this->pid&act=department_$row' title='$dn'>$result</a>");
956 }
959 function filterLink()
960 {
961 $result= " ";
963 $row= func_get_arg(0);
964 $pid= $this->pid;
965 $dn= LDAP::fix(func_get_arg(1));
966 $params= array(func_get_arg(2));
968 // Collect sprintf params
969 for ($i = 3;$i < func_num_args();$i++) {
970 $val= func_get_arg($i);
971 if (is_array($val)){
972 $params[]= $val[0];
973 continue;
974 }
975 $params[]= $val;
976 }
978 $result= " ";
979 $trans= call_user_func_array("sprintf", $params);
980 if ($trans != "") {
981 return("<a href='?plug=".$_GET['plug']."&PID=$pid&act=listing_edit_$row' title='$dn'>$trans</a>");
982 }
984 return $result;
985 }
988 function renderNavigation()
989 {
990 $result= array();
991 $enableBack = true;
992 $enableRoot = true;
993 $enableHome = true;
995 $ui = get_userinfo();
997 /* Check if base = first available base */
998 $deps = $ui->get_module_departments($this->categories);
1000 if(!count($deps) || $deps[0] == $this->filter->base){
1001 $enableBack = false;
1002 $enableRoot = false;
1003 }
1005 $listhead ="";
1007 /* Check if we are in users home department */
1008 if(!count($deps) || $this->filter->base == get_base_from_people($ui->dn)){
1009 $enableHome = false;
1010 }
1012 /* Draw root button */
1013 if($enableRoot){
1014 $result["ROOT"]= image('images/lists/root.png', 'ROOT', _("Root"));
1015 }else{
1016 $result["ROOT"]= image('images/lists/root-grey.png', null, _("Root"));
1017 }
1019 /* Draw back button */
1020 if($enableBack){
1021 $result["BACK"]= image('images/lists/back.png', 'BACK', _("Go up one department"));
1022 }else{
1023 $result["BACK"]= image('images/lists/back-grey.png', null, _("Go up one department"));
1024 }
1026 /* Draw home button */
1027 /* Draw home button */
1028 if($enableHome){
1029 $result["HOME"]= image('images/lists/home.png', 'HOME', _("Go to users department"));
1030 }else{
1031 $result["HOME"]= image('images/lists/home-grey.png', null, _("Go to users department"));
1032 }
1035 /* Draw reload button, this button is enabled everytime */
1036 $result["RELOAD"]= image('images/lists/reload.png', 'REFRESH', _("Reload list"));
1038 return ($result);
1039 }
1042 function getAction()
1043 {
1044 // Do not do anything if this is not our PID, or there's even no PID available...
1045 if(!isset($_REQUEST['PID']) || $_REQUEST['PID'] != $this->pid) {
1046 return;
1047 }
1049 // Save position if set
1050 if (isset($_POST['position_'.$this->pid]) && is_numeric($_POST['position_'.$this->pid])) {
1051 $this->scrollPosition= $_POST['position_'.$this->pid];
1052 }
1054 $result= array("targets" => array(), "action" => "");
1056 // Filter GET with "act" attributes
1057 if (isset($_GET['act'])) {
1058 $key= validate($_GET['act']);
1059 $target= preg_replace('/^listing_[a-zA-Z_]+_([0-9]+)$/', '$1', $key);
1060 if (isset($this->entries[$target]['dn'])) {
1061 $result['action']= preg_replace('/^listing_([a-zA-Z_]+)_[0-9]+$/', '$1', $key);
1062 $result['targets'][]= $this->entries[$target]['dn'];
1063 }
1065 // Drop targets if empty
1066 if (count($result['targets']) == 0) {
1067 unset($result['targets']);
1068 }
1069 return $result;
1070 }
1072 // Get single selection (radio box)
1073 if($this->singleSelect && isset($_POST['listing_radio_selected'])){
1074 $entry = $_POST['listing_radio_selected'];
1075 $result['targets']= array($this->entries[$entry]['dn']);
1076 }
1078 // Filter POST with "listing_" attributes
1079 foreach ($_POST as $key => $prop) {
1081 // Capture selections
1082 if (preg_match('/^listing_selected_[0-9]+$/', $key)) {
1083 $target= preg_replace('/^listing_selected_([0-9]+)$/', '$1', $key);
1084 if (isset($this->entries[$target]['dn'])) {
1085 $result['targets'][]= $this->entries[$target]['dn'];
1086 }
1087 continue;
1088 }
1090 // Capture action with target - this is a one shot
1091 if (preg_match('/^listing_[a-zA-Z_]+_[0-9]+(|_x)$/', $key)) {
1092 $target= preg_replace('/^listing_[a-zA-Z_]+_([0-9]+)(|_x)$/', '$1', $key);
1093 if (isset($this->entries[$target]['dn'])) {
1094 $result['action']= preg_replace('/^listing_([a-zA-Z_]+)_[0-9]+(|_x)$/', '$1', $key);
1095 $result['targets']= array($this->entries[$target]['dn']);
1096 }
1097 break;
1098 }
1100 // Capture action without target
1101 if (preg_match('/^listing_[a-zA-Z_]+(|_x)$/', $key)) {
1102 $result['action']= preg_replace('/^listing_([a-zA-Z_]+)(|_x)$/', '$1', $key);
1103 continue;
1104 }
1105 }
1107 // Filter POST with "act" attributes -> posted from action menu
1108 if (isset($_POST['act']) && $_POST['act'] != '') {
1109 if (!preg_match('/^export.*$/', $_POST['act'])){
1110 $result['action']= validate($_POST['act']);
1111 }
1112 }
1114 // Drop targets if empty
1115 if (count($result['targets']) == 0) {
1116 unset($result['targets']);
1117 }
1118 return $result;
1119 }
1122 function renderActionMenu()
1123 {
1124 $result= "<input type='hidden' name='act' id='act' value=''><div style='display:none'><input type='submit' name='exec_act' id='exec_act' value=''></div>";
1126 // Don't send anything if the menu is not defined
1127 if (!isset($this->xmlData['actionmenu']['action'])){
1128 return $result;
1129 }
1131 // Array?
1132 if (isset($this->xmlData['actionmenu']['action']['type'])){
1133 $this->xmlData['actionmenu']['action']= array($this->xmlData['actionmenu']['action']);
1134 }
1136 // Load shortcut
1137 $actions= &$this->xmlData['actionmenu']['action'];
1138 $result.= "<ul class='level1' id='root'><li><a href='#'>"._("Actions")." ".image("images/lists/sort-down.png")."</a>";
1140 // Build ul/li list
1141 $result.= $this->recurseActions($actions);
1143 return "<div id='pulldown'>".$result."</li></ul></div>";
1144 }
1147 function recurseActions($actions)
1148 {
1149 global $class_mapping;
1150 static $level= 2;
1151 $result= "<ul class='level$level'>";
1152 $separator= "";
1154 foreach ($actions as $action) {
1156 // Skip the entry completely if there's no permission to execute it
1157 if (!$this->hasActionPermission($action, $this->filter->base)) {
1158 continue;
1159 }
1161 // Skip entry if there're missing dependencies
1162 if (isset($action['depends'])) {
1163 $deps= is_array($action['depends'])?$action['depends']:array($action['depends']);
1164 foreach($deps as $clazz) {
1165 if (!isset($class_mapping[$clazz])){
1166 continue 2;
1167 }
1168 }
1169 }
1171 // Fill image if set
1172 $img= "";
1173 if (isset($action['image'])){
1174 $img= image($action['image'])." ";
1175 }
1177 if ($action['type'] == "separator"){
1178 $separator= " style='border-top:1px solid #AAA' ";
1179 continue;
1180 }
1182 // Dive into subs
1183 if ($action['type'] == "sub" && isset($action['action'])) {
1184 $level++;
1185 if (isset($action['label'])){
1186 $result.= "<li$separator><a href='#'>$img"._($action['label'])." ".image('images/forward-arrow.png')."</a>";
1187 }
1189 // Ensure we've an array of actions, this enables sub menus with only one action.
1190 if(isset($action['action']['type'])){
1191 $action['action'] = array($action['action']);
1192 }
1194 $result.= $this->recurseActions($action['action'])."</li>";
1195 $level--;
1196 $separator= "";
1197 continue;
1198 }
1200 // Render entry elseways
1201 if (isset($action['label'])){
1202 $result.= "<li$separator><a href='#' onClick='\$(\"act\").value= \"".$action['name']."\";\$(\"exec_act\").click();'>$img"._($action['label'])."</a></li>";
1203 }
1205 // Check for special types
1206 switch ($action['type']) {
1207 case 'copypaste':
1208 $cut = !isset($action['cut']) || $action['cut'] != "false";
1209 $copy = !isset($action['copy']) || $action['copy'] != "false";
1210 $result.= $this->renderCopyPasteMenu($separator, $copy , $cut);
1211 break;
1213 case 'snapshot':
1214 $result.= $this->renderSnapshotMenu($separator);
1215 break;
1217 case 'exporter':
1218 $result.= $this->renderExporterMenu($separator);
1219 break;
1221 case 'daemon':
1222 $result.= $this->renderDaemonMenu($separator);
1223 break;
1224 }
1226 $separator= "";
1227 }
1229 $result.= "</ul>";
1230 return $result;
1231 }
1234 function hasActionPermission($action, $dn, $classes= null)
1235 {
1236 $ui= get_userinfo();
1238 if (isset($action['acl'])) {
1239 $acls= $action['acl'];
1240 if (!is_array($acls)) {
1241 $acls= array($acls);
1242 }
1244 // Every ACL has to pass
1245 foreach ($acls as $acl) {
1246 $module= $this->categories;
1247 $aclList= array();
1249 // Replace %acl if available
1250 if ($classes) {
1251 $otype= $this->getObjectType($this->objectTypes, $classes);
1252 $acl= str_replace('%acl', $otype['category']."/".$otype['class'], $acl);
1253 }
1255 // Split for category and plugins if needed
1256 // match for "[rw]" style entries
1257 if (preg_match('/^\[([rwcdm]+)\]$/', $acl, $match)){
1258 $aclList= array($match[1]);
1259 }
1261 // match for "users[rw]" style entries
1262 if (preg_match('/^([a-zA-Z0-9]+)\[([rwcdm]+)\]$/', $acl, $match)){
1263 $module= $match[1];
1264 $aclList= array($match[2]);
1265 }
1267 // match for "users/user[rw]" style entries
1268 if (preg_match('/^([a-zA-Z0-9]+\/[a-zA-Z0-9]+)\[([rwcdm]+)\]$/', $acl, $match)){
1269 $module= $match[1];
1270 $aclList= array($match[2]);
1271 }
1273 // match "users/user[userPassword:rw(,...)*]" style entries
1274 if (preg_match('/^([a-zA-Z0-9]+\/[a-zA-Z0-9]+)\[([a-zA-Z0-9]+:[rwcdm]+(,[a-zA-Z0-9]+:[rwcdm]+)*)\]$/', $acl, $match)){
1275 $module= $match[1];
1276 $aclList= explode(',', $match[2]);
1277 }
1279 // Walk thru prepared ACL by using $module
1280 foreach($aclList as $sAcl) {
1281 $checkAcl= "";
1283 // Category or detailed permission?
1284 if (strpos($module, '/') !== false) {
1285 if (preg_match('/([a-zA-Z0-9]+):([rwcdm]+)/', $sAcl, $m) ) {
1286 $checkAcl= $ui->get_permissions($dn, $module, $m[1]);
1287 $sAcl= $m[2];
1288 } else {
1289 $checkAcl= $ui->get_permissions($dn, $module, '0');
1290 }
1291 } else {
1292 $checkAcl= $ui->get_category_permissions($dn, $module);
1293 }
1295 // Split up remaining part of the acl and check if it we're
1296 // allowed to do something...
1297 $parts= str_split($sAcl);
1298 foreach ($parts as $part) {
1299 if (strpos($checkAcl, $part) === false){
1300 return false;
1301 }
1302 }
1304 }
1305 }
1306 }
1308 return true;
1309 }
1312 function refreshBasesList()
1313 {
1314 global $config;
1315 $ui= get_userinfo();
1317 // Do some array munching to get it user friendly
1318 $ids= $config->idepartments;
1319 $d= $ui->get_module_departments($this->categories);
1320 $k_ids= array_keys($ids);
1321 $deps= array_intersect($d,$k_ids);
1323 // Fill internal bases list
1324 $this->bases= array();
1325 foreach($k_ids as $department){
1326 $this->bases[$department] = $ids[$department];
1327 }
1329 // Populate base selector if already present
1330 if ($this->baseSelector && $this->baseMode) {
1331 $this->baseSelector->setBases($this->bases);
1332 $this->baseSelector->update(TRUE);
1333 }
1334 }
1337 function getDepartments()
1338 {
1339 $departments= array();
1340 $ui= get_userinfo();
1342 // Get list of supported department types
1343 $types = departmentManagement::get_support_departments();
1345 // Load departments allowed by ACL
1346 $validDepartments = $ui->get_module_departments($this->categories);
1348 // Build filter and look in the LDAP for possible sub departments
1349 // of current base
1350 $filter= "(&(objectClass=gosaDepartment)(|";
1351 $attrs= array("description", "objectClass");
1352 foreach($types as $name => $data){
1353 $filter.= "(objectClass=".$data['OC'].")";
1354 $attrs[]= $data['ATTR'];
1355 }
1356 $filter.= "))";
1357 $res= get_list($filter, $this->categories, $this->base, $attrs, GL_NONE);
1359 // Analyze list of departments
1360 foreach ($res as $department) {
1361 if (!in_array($department['dn'], $validDepartments)) {
1362 continue;
1363 }
1365 // Add the attribute where we use for sorting
1366 $oc= null;
1367 foreach(array_keys($types) as $type) {
1368 if (in_array($type, $department['objectClass'])) {
1369 $oc= $type;
1370 break;
1371 }
1372 }
1373 $department['sort-attribute']= $types[$oc]['ATTR'];
1375 // Move to the result list
1376 $departments[]= $department;
1377 }
1379 return $departments;
1380 }
1383 function renderCopyPasteMenu($separator, $copy= true, $cut= true)
1384 {
1385 // We can only provide information if we've got a copypaste handler
1386 // instance
1387 if(!(isset($this->copyPasteHandler) && is_object($this->copyPasteHandler))){
1388 return "";
1389 }
1391 // Presets
1392 $result= "";
1393 $read= $paste= false;
1394 $ui= get_userinfo();
1396 // Switch flags to on if there's at least one category which allows read/paste
1397 foreach($this->categories as $category){
1398 $read= $read || preg_match('/r/', $ui->get_category_permissions($this->base, $category));
1399 $paste= $paste || $ui->is_pasteable($this->base, $category) == 1;
1400 }
1403 // Draw entries that allow copy and cut
1404 if($read){
1406 // Copy entry
1407 if($copy){
1408 $result.= "<li$separator><a href='#' onClick='\$(\"act\").value= \"copy\";\$(\"exec_act\").click();'>".image('images/lists/copy.png')." "._("Copy")."</a></li>";
1409 $separator= "";
1410 }
1412 // Cut entry
1413 if($cut){
1414 $result.= "<li$separator><a href='#' onClick='\$(\"act\").value= \"cut\";\$(\"exec_act\").click();'>".image("images/lists/cut.png")." "._("Cut")."</a></li>";
1415 $separator= "";
1416 }
1417 }
1419 // Draw entries that allow pasting entries
1420 if($paste){
1421 if($this->copyPasteHandler->entries_queued()){
1422 $result.= "<li$separator><a href='#' onClick='\$(\"act\").value= \"paste\";\$(\"exec_act\").click();'>".image("images/lists/paste.png")." "._("Paste")."</a></li>";
1423 }else{
1424 $result.= "<li$separator><a href='#'>".image('images/lists/paste-grey.png')." "._("Paste")."</a></li>";
1425 }
1426 }
1428 return($result);
1429 }
1432 function renderCopyPasteActions($row, $dn, $category, $class, $copy= true, $cut= true)
1433 {
1434 // We can only provide information if we've got a copypaste handler
1435 // instance
1436 if(!(isset($this->copyPasteHandler) && is_object($this->copyPasteHandler))){
1437 return "";
1438 }
1440 // Presets
1441 $ui = get_userinfo();
1442 $result = "";
1444 // Render cut entries
1445 if($cut){
1446 if($ui->is_cutable($dn, $category, $class)){
1447 $result.= image('images/lists/cut.png', "listing_cut_$row", _("Cut this entry"));
1448 }else{
1449 $result.= image('images/empty.png');
1450 }
1451 }
1453 // Render copy entries
1454 if($copy){
1455 if($ui->is_copyable($dn, $category, $class)){
1456 $result.= image('images/lists/copy.png', "listing_copy_$row", _("Copy this entry"));
1457 }else{
1458 $result.= image('images/empty.png');
1459 }
1460 }
1462 return($result);
1463 }
1466 function renderSnapshotMenu($separator)
1467 {
1468 // We can only provide information if we've got a snapshot handler
1469 // instance
1470 if(!(isset($this->snapshotHandler) && is_object($this->snapshotHandler))){
1471 return "";
1472 }
1474 // Presets
1475 $result = "";
1476 $ui = get_userinfo();
1478 if($this->snapshotHandler->enabled() && $ui->allow_snapshot_restore($this->base, $this->categories)){
1480 // Check if there is something to restore
1481 $restore= false;
1482 foreach($this->snapshotHandler->getSnapshotBases() as $base){
1483 $restore= $restore || count($this->snapshotHandler->getDeletedSnapshots($base)) > 0;
1484 }
1486 // Draw icons according to the restore flag
1487 if($restore){
1488 $result.= "<li$separator><a href='#' onClick='\$(\"act\").value= \"restore\";\$(\"exec_act\").click();'>".image('images/lists/restore.png')." "._("Restore snapshots")."</a></li>";
1489 }else{
1490 $result.= "<li$separator><a href='#'>".image('images/lists/restore-grey.png')." "._("Restore snapshots")."</a></li>";
1491 }
1492 }
1494 return($result);
1495 }
1498 function renderExporterMenu($separator)
1499 {
1500 // Presets
1501 $result = "";
1503 // Draw entries
1504 $result.= "<li$separator><a href='#'>".image('images/lists/export.png')." "._("Export list")." ".image("images/forward-arrow.png")."</a><ul class='level3'>";
1506 // Export CVS as build in exporter
1507 foreach ($this->exporter as $action => $exporter) {
1508 $result.= "<li><a href='#' onClick='\$(\"act\").value= \"$action\";\$(\"exec_act\").click();'>".image($exporter['image'])." ".$exporter['label']."</a></li>";
1509 }
1511 // Finalize list
1512 $result.= "</ul></li>";
1514 return($result);
1515 }
1518 function renderSnapshotActions($row, $dn, $category, $class, $copy= true, $cut= true)
1519 {
1520 // We can only provide information if we've got a snapshot handler
1521 // instance
1522 if(!(isset($this->snapshotHandler) && is_object($this->snapshotHandler))){
1523 return "";
1524 }
1526 // Presets
1527 $result= "";
1528 $ui = get_userinfo();
1530 // Only act if enabled here
1531 if($this->snapshotHandler->enabled()){
1533 // Draw restore button
1534 if ($ui->allow_snapshot_restore($dn, $category)){
1536 // Do we have snapshots for this dn?
1537 if($this->snapshotHandler->hasSnapshots($dn)){
1538 $result.= image('images/lists/restore.png', "listing_restore_$row", _("Restore snapshot"));
1539 } else {
1540 $result.= image('images/lists/restore-grey.png');
1541 }
1542 }
1544 // Draw snapshot button
1545 if($ui->allow_snapshot_create($dn, $category)){
1546 $result.= image('images/snapshot.png', "listing_snapshot_$row", _("Create a new snapshot from this object"));
1547 }else{
1548 $result.= image('images/empty.png');
1549 }
1550 }
1552 return($result);
1553 }
1556 function renderDaemonMenu($separator)
1557 {
1558 $result= "";
1560 // If there is a daemon registered, draw the menu entries
1561 if(class_available("DaemonEvent")){
1562 $events= DaemonEvent::get_event_types_by_category($this->categories);
1563 if(isset($events['BY_CLASS']) && count($events['BY_CLASS'])){
1564 foreach($events['BY_CLASS'] as $name => $event){
1565 $result.= "<li$separator><a href='#' onClick='\$(\"act\").value=\"$name\";\$(\"exec_act\").click();'>".$event['MenuImage']." ".$event['s_Menu_Name']."</a></li>";
1566 $separator= "";
1567 }
1568 }
1569 }
1571 return $result;
1572 }
1575 function getEntry($dn)
1576 {
1577 foreach ($this->entries as $entry) {
1578 if (isset($entry['dn']) && strcasecmp($dn, $entry['dn']) == 0){
1579 return $entry;
1580 }
1581 }
1582 return null;
1583 }
1586 function getEntries()
1587 {
1588 return $this->entries;
1589 }
1592 function getType($dn)
1593 {
1594 if (isset($this->objectDnMapping[$dn])) {
1595 return $this->objectDnMapping[$dn];
1596 }
1597 return null;
1598 }
1600 }
1602 ?>