651e37f9eb6ed6e8be97afadb15222258dd3c9e7
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 $pid;
45 var $objectTypes= array();
46 var $objectTypeCount= array();
47 var $objectDnMapping= array();
48 var $copyPasteHandler= null;
49 var $snapshotHandler= null;
50 var $exporter= array();
51 var $exportColumns= array();
52 var $useSpan= false;
53 var $height= 0;
54 var $scrollPosition= 0;
57 function listing($filename)
58 {
59 global $config;
60 global $class_mapping;
62 // Initialize pid
63 $this->pid= preg_replace("/[^0-9]/", "", microtime(TRUE));
65 if (!$this->load($filename)) {
66 die("Cannot parse $filename!");
67 }
69 // Set base for filter
70 if ($this->baseMode) {
71 $this->base= session::global_get("CurrentMainBase");
72 if ($this->base == null) {
73 $this->base= $config->current['BASE'];
74 }
75 $this->refreshBasesList();
76 } else {
77 $this->base= $config->current['BASE'];
78 }
80 // Move footer information
81 $this->showFooter= ($config->get_cfg_value("listSummary") == "true");
83 // Register build in filters
84 $this->registerElementFilter("objectType", "listing::filterObjectType");
85 $this->registerElementFilter("departmentLink", "listing::filterDepartmentLink");
86 $this->registerElementFilter("link", "listing::filterLink");
87 $this->registerElementFilter("actions", "listing::filterActions");
89 // Load exporters
90 foreach($class_mapping as $class => $dummy) {
91 if (preg_match('/Exporter$/', $class)) {
92 $info= call_user_func(array($class, "getInfo"));
93 if ($info != null) {
94 $this->exporter= array_merge($this->exporter, $info);
95 }
96 }
97 }
98 }
101 function setCopyPasteHandler($handler)
102 {
103 $this->copyPasteHandler= &$handler;
104 }
107 function setHeight($height)
108 {
109 $this->height= $height;
110 }
113 function setSnapshotHandler($handler)
114 {
115 $this->snapshotHandler= &$handler;
116 }
119 function setFilter($filter)
120 {
121 $this->filter= &$filter;
122 if ($this->departmentBrowser){
123 $this->departments= $this->getDepartments();
124 }
125 $this->filter->setBase($this->base);
126 }
129 function registerElementFilter($name, $call)
130 {
131 if (!isset($this->filters[$name])) {
132 $this->filters[$name]= $call;
133 return true;
134 }
136 return false;
137 }
140 function load($filename)
141 {
142 $contents = file_get_contents($filename);
143 $this->xmlData= xml::xml2array($contents, 1);
145 if (!isset($this->xmlData['list'])) {
146 return false;
147 }
149 $this->xmlData= $this->xmlData["list"];
151 // Load some definition values
152 foreach (array("departmentBrowser", "departmentRootVisible", "multiSelect", "baseMode") as $token) {
153 if (isset($this->xmlData['definition'][$token]) &&
154 $this->xmlData['definition'][$token] == "true"){
155 $this->$token= true;
156 }
157 }
159 // Fill objectTypes from departments and xml definition
160 $types = departmentManagement::get_support_departments();
161 foreach ($types as $class => $data) {
162 $this->objectTypes[]= array("label" => $data['TITLE'],
163 "objectClass" => $data['OC'],
164 "image" => $data['IMG']);
165 }
166 $this->categories= array();
167 if (isset($this->xmlData['definition']['objectType'])) {
168 if(isset($this->xmlData['definition']['objectType']['label'])) {
169 $this->xmlData['definition']['objectType']= array($this->xmlData['definition']['objectType']);
170 }
171 foreach ($this->xmlData['definition']['objectType'] as $index => $otype) {
172 $this->objectTypes[]= $this->xmlData['definition']['objectType'][$index];
173 if (isset($this->xmlData['definition']['objectType'][$index]['category'])){
174 $this->categories[]= $otype['category'];
175 }
176 }
177 }
179 // Parse layout per column
180 $this->colprops= $this->parseLayout($this->xmlData['table']['layout']);
182 // Prepare table headers
183 $this->renderHeader();
185 // Assign headline/Categories
186 $this->headline= _($this->xmlData['definition']['label']);
187 if (!is_array($this->categories)){
188 $this->categories= array($this->categories);
189 }
191 // Evaluate columns to be exported
192 if (isset($this->xmlData['table']['column'])){
193 foreach ($this->xmlData['table']['column'] as $index => $config) {
194 if (isset($config['export']) && $config['export'] == "true"){
195 $this->exportColumns[]= $index;
196 }
197 }
198 }
200 return true;
201 }
204 function renderHeader()
205 {
206 $this->header= array();
207 $this->plainHeader= array();
209 // Initialize sort?
210 $sortInit= false;
211 if (!$this->sortDirection) {
212 $this->sortColumn= 0;
213 if (isset($this->xmlData['definition']['defaultSortColumn'])){
214 $this->sortColumn= $this->xmlData['definition']['defaultSortColumn'];
215 } else {
216 $this->sortAttribute= "";
217 }
218 $this->sortDirection= array();
219 $sortInit= true;
220 }
222 if (isset($this->xmlData['table']['column'])){
223 foreach ($this->xmlData['table']['column'] as $index => $config) {
224 // Initialize everything to one direction
225 if ($sortInit) {
226 $this->sortDirection[$index]= false;
227 }
229 $sorter= "";
230 if ($index == $this->sortColumn && isset($config['sortAttribute']) &&
231 isset($config['sortType'])) {
232 $this->sortAttribute= $config['sortAttribute'];
233 $this->sortType= $config['sortType'];
234 $sorter= " <img border='0' title='".($this->sortDirection[$index]?_("Up"):_("Down"))."' src='images/lists/sort-".($this->sortDirection[$index]?"up":"down").".png' align='top'>";
235 }
236 $sortable= (isset($config['sortAttribute']));
238 $link= "href='?plug=".$_GET['plug']."&PID=".$this->pid."&act=SORT_$index'";
239 if (isset($config['label'])) {
240 if ($sortable) {
241 $this->header[$index]= "<td class='listheader' ".$this->colprops[$index]."><a $link>"._($config['label'])."$sorter</a></td>";
242 } else {
243 $this->header[$index]= "<td class='listheader' ".$this->colprops[$index].">"._($config['label'])."</td>";
244 }
245 $this->plainHeader[]= _($config['label']);
246 } else {
247 if ($sortable) {
248 $this->header[$index]= "<td class='listheader' ".$this->colprops[$index]."><a $link> $sorter</a></td>";
249 } else {
250 $this->header[$index]= "<td class='listheader' ".$this->colprops[$index]."> </td>";
251 }
252 $this->plainHeader[]= "";
253 }
254 }
255 }
256 }
259 function render()
260 {
261 // Check for exeeded sizelimit
262 if (($message= check_sizelimit()) != ""){
263 return($message);
264 }
266 // Some browsers don't have the ability do do scrollable table bodies, filter them
267 // here.
268 $switch= false;
269 if (preg_match('/(Opera|Konqueror|Safari|msie)/i', $_SERVER['HTTP_USER_AGENT'])){
270 $switch= true;
271 }
273 // Initialize list
274 $result= "<input type='hidden' value='$this->pid' name='PID'>\n";
275 $result.= "<input type='hidden' name='position_".$this->pid."' id='position_".$this->pid."'>\n";
276 $height= 450;
277 if ($this->height != 0) {
278 $result.= "<input type='hidden' value='$this->height' id='d_height'>\n";
279 $height= $this->height;
280 }
282 $result.= "<table cellpadding='0' cellspacing='0' border='0'><tr><td><div class='listContainer' id='d_scrollbody' style='border-top:1px solid #B0B0B0;width:700px;min-height:".($height+25)."px;'>\n";
284 $height= "";
285 if ($switch){
286 $height= "height:100%;";
287 }
288 $result.= "<table summary='$this->headline' style='${height}width:100%; table-layout:fixed;' cellspacing='0' cellpadding='0' id='t_scrolltable'>\n";
289 $this->numColumns= count($this->colprops) + ($this->multiSelect?1:0);
291 // Build list header
292 $result.= "<thead class='fixedListHeader listHeaderFormat'><tr>\n";
293 if ($this->multiSelect) {
294 $width= "24px";
295 if (preg_match('/Konqueror/i', $_SERVER['HTTP_USER_AGENT'])){
296 $width= "28px";
297 }
298 $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";
299 }
300 foreach ($this->header as $header) {
301 $result.= $header;
302 }
303 $result.= "</tr></thead>\n";
305 // Build list body
306 $result.= "<tbody class='listScrollContent listBodyFormat' id='t_nscrollbody' style='height:".$height."px;'>\n";
308 // No results? Just take an empty colspanned row
309 if (count($this->entries) + count($this->departments) == 0) {
310 $result.= "<tr class='rowxp0'><td class='list1nohighlight' colspan='$this->numColumns' style='height:100%;border-right:0px;width:100%;'> </td></tr>";
311 }
313 // Line color alternation
314 $alt= 0;
315 $deps= 0;
317 // Draw department browser if configured and we're not in sub mode
318 $this->useSpan= false;
319 if ($this->departmentBrowser && $this->filter->scope != "sub") {
320 // Fill with department browser if configured this way
321 $departmentIterator= new departmentSortIterator($this->departments, $this->sortDirection[$this->sortColumn]);
322 foreach ($departmentIterator as $row => $entry){
323 $result.="<tr class='rowxp".($alt&1)."'>";
325 // Render multi select if needed
326 if ($this->multiSelect) {
327 $result.="<td style='text-align:center;padding:0;' class='list1'> </td>";
328 }
330 // Render defined department columns, fill the rest with some stuff
331 $rest= $this->numColumns - 1;
332 foreach ($this->xmlData['table']['department'] as $index => $config) {
333 $colspan= 1;
334 if (isset($config['span'])){
335 $colspan= $config['span'];
336 $this->useSpan= true;
337 }
338 $result.="<td colspan='$colspan' ".$this->colprops[$index]." class='list1'>".$this->renderCell($config['value'], $entry, $row)."</td>";
339 $rest-= $colspan;
340 }
342 // Fill remaining cols with nothing
343 $last= $this->numColumns - $rest;
344 for ($i= 0; $i<$rest; $i++){
345 $result.= "<td ".$this->colprops[$last+$i-1]." class='list1'> </td>";
346 }
347 $result.="</tr>";
349 $alt++;
350 }
351 $deps= $alt;
352 }
354 // Fill with contents, sort as configured
355 foreach ($this->entries as $row => $entry) {
356 $trow= "";
358 // Render multi select if needed
359 if ($this->multiSelect) {
360 $trow.="<td style='text-align:center;width:20px;' class='list0'><input type='checkbox' id='listing_selected_$row' name='listing_selected_$row'></td>\n";
361 }
363 foreach ($this->xmlData['table']['column'] as $index => $config) {
364 $renderedCell= $this->renderCell($config['value'], $entry, $row);
365 $trow.="<td ".$this->colprops[$index]." class='list0'>".$renderedCell."</td>\n";
367 // Save rendered column
368 $sort= preg_replace('/.*>([^<]+)<.*$/', '$1', $renderedCell);
369 $sort= preg_replace('/ /', '', $sort);
370 if (preg_match('/</', $sort)){
371 $sort= "";
372 }
373 $this->entries[$row]["_sort$index"]= $sort;
374 }
376 // Save rendered entry
377 $this->entries[$row]['_rendered']= $trow;
378 }
380 // Complete list by sorting entries for _sort$index and appending them to the output
381 $entryIterator= new listingSortIterator($this->entries, $this->sortDirection[$this->sortColumn], "_sort".$this->sortColumn, $this->sortType);
382 foreach ($entryIterator as $row => $entry){
383 $alt++;
384 $result.="<tr class='rowxp".($alt&1)."'>\n";
385 $result.= $entry['_rendered'];
386 $result.="</tr>\n";
387 }
389 // Need to fill the list if it's not full (nobody knows why this is 22 ;-))
390 $emptyListStyle= (count($this->entries) + (($this->useSpan && count($this->entries))?$deps:0) == 0)?"border:0;":"";
391 if ((count($this->entries) + $deps) < 22) {
392 $result.= "<tr>";
393 for ($i= 0; $i<$this->numColumns; $i++) {
394 if ($i == 0) {
395 $result.= "<td class='list1nohighlight' style='$emptyListStyle height:100%;'> </td>";
396 continue;
397 }
398 if ($i != $this->numColumns-1) {
399 $result.= "<td class='list1nohighlight' style='$emptyListStyle'> </td>";
400 } else {
401 $result.= "<td class='list1nohighlight' style='border-right:1px solid #AAA;$emptyListStyle'> </td>";
402 }
403 }
404 $result.= "</tr>";
405 }
407 // Close list body
408 $result.= "</tbody></table></div></td></tr>";
410 // Add the footer if requested
411 if ($this->showFooter) {
412 $result.= "<tr><td class='nlistFooter'>";
414 foreach ($this->objectTypes as $objectType) {
415 if (isset($this->objectTypeCount[$objectType['label']])) {
416 $label= _($objectType['label']);
417 $result.= "<img class='center' src='".$objectType['image']."' title='$label' alt='$label'> ".$this->objectTypeCount[$objectType['label']]." ";
418 }
419 }
421 $result.= "</td></tr>";
422 }
424 // Close list
425 $result.= "</table>";
426 $result.= $switch?"<input type='hidden' id='list_workaround'>":"";
428 // Add scroll positioner
429 $result.= '<script type="text/javascript" language="javascript">';
430 $result.= '$("t_nscrollbody").scrollTop= '.$this->scrollPosition.';';
431 $result.= 'var box = $("t_nscrollbody").onscroll= function() {$("position_'.$this->pid.'").value= this.scrollTop;}';
432 $result.= '</script>';
434 $smarty= get_smarty();
435 $smarty->assign("usePrototype", "true");
436 $smarty->assign("FILTER", $this->filter->render());
437 $smarty->assign("SIZELIMIT", print_sizelimit_warning());
438 $smarty->assign("LIST", $result);
440 // Assign navigation elements
441 $nav= $this->renderNavigation();
442 foreach ($nav as $key => $html) {
443 $smarty->assign($key, $html);
444 }
446 // Assign action menu / base
447 $smarty->assign("ACTIONS", $this->renderActionMenu());
448 $smarty->assign("BASE", $this->renderBase());
450 // Assign separator
451 $smarty->assign("SEPARATOR", "<img src='images/lists/seperator.png' alt='-' align='middle' height='16' width='1' class='center'>");
453 // Assign summary
454 $smarty->assign("HEADLINE", $this->headline);
456 // Try to load template from plugin the folder first...
457 $file = get_template_path($this->xmlData['definition']['template'], true);
459 // ... if this fails, try to load the file from the theme folder.
460 if(!file_exists($file)){
461 $file = get_template_path($this->xmlData['definition']['template']);
462 }
464 return ($smarty->fetch($file));
465 }
468 function update()
469 {
470 global $config;
471 $ui= get_userinfo();
473 // Reset object counter / DN mapping
474 $this->objectTypeCount= array();
475 $this->objectDnMapping= array();
477 // Do not do anything if this is not our PID
478 if(isset($_REQUEST['PID']) && $_REQUEST['PID'] != $this->pid) {
479 return;
480 }
482 // Save position if set
483 if (isset($_POST['position_'.$this->pid]) && is_numeric($_POST['position_'.$this->pid])) {
484 $this->scrollPosition= $_POST['position_'.$this->pid];
485 }
487 // Save base
488 if (isset($_POST['BASE']) && $this->baseMode) {
489 $base= base64_decode(get_post('BASE'));
490 if (isset($this->bases[$base])) {
491 $this->base= $base;
492 session::global_set("CurrentMainBase", $this->base);
493 }
494 }
496 // Override the base if we got a message from the browser navigation
497 if ($this->departmentBrowser && isset($_GET['act'])) {
498 if (preg_match('/^department_([0-9]+)$/', validate($_GET['act']), $match)){
499 if (isset($this->departments[$match[1]])){
500 $this->base= $this->departments[$match[1]]['dn'];
501 session::global_set("CurrentMainBase", $this->base);
502 }
503 }
504 }
506 // Filter POST with "act" attributes -> posted from action menu
507 if (isset($_POST['exec_act']) && $_POST['act'] != '') {
508 if (preg_match('/^export.*$/', $_POST['act']) && isset($this->exporter[$_POST['act']])) {
509 $exporter= $this->exporter[$_POST['act']];
510 $userinfo= ", "._("created by")." ".$ui->cn." - ".strftime('%A, %d. %B %Y, %H:%M:%S');
511 $entryIterator= new listingSortIterator($this->entries, $this->sortDirection[$this->sortColumn], "_sort".$this->sortColumn, $this->sortType);
512 $sortedEntries= array();
513 foreach ($entryIterator as $entry){
514 $sortedEntries[]= $entry;
515 }
516 $instance= new $exporter['class']($this->headline.$userinfo, $this->plainHeader, $sortedEntries, $this->exportColumns);
517 $type= call_user_func(array($exporter['class'], "getInfo"));
518 $type= $type[$_POST['act']];
519 send_binary_content($instance->query(), $type['filename'], $type= $type['mime']);
520 }
521 }
523 // Filter GET with "act" attributes
524 if (isset($_GET['act'])) {
525 $key= validate($_GET['act']);
526 if (preg_match('/^SORT_([0-9]+)$/', $key, $match)) {
527 // Switch to new column or invert search order?
528 $column= $match[1];
529 if ($this->sortColumn != $column) {
530 $this->sortColumn= $column;
531 } else {
532 $this->sortDirection[$column]= !$this->sortDirection[$column];
533 }
535 // Allow header to update itself according to the new sort settings
536 $this->renderHeader();
537 }
538 }
540 // Override base if we got signals from the navigation elements
541 $action= "";
542 foreach ($_POST as $key => $value) {
543 if (preg_match('/^(ROOT|BACK|HOME)_x$/', $key, $match)) {
544 $action= $match[1];
545 break;
546 }
547 }
549 // Navigation handling
550 if ($action == 'ROOT') {
551 $deps= $ui->get_module_departments($this->categories);
552 $this->base= $deps[0];
553 }
554 if ($action == 'BACK') {
555 $deps= $ui->get_module_departments($this->categories);
556 $base= preg_replace("/^[^,]+,/", "", $this->base);
557 if(in_array_ics($base, $deps)){
558 $this->base= $base;
559 }
560 }
561 if ($action == 'HOME') {
562 $ui= get_userinfo();
563 $this->base= $this->filter->getObjectBase($ui->dn);
564 }
566 // Reload departments
567 if ($this->departmentBrowser){
568 $this->departments= $this->getDepartments();
569 }
571 // Update filter and refresh entries
572 $this->filter->setBase($this->base);
573 $this->entries= $this->filter->query();
574 }
577 function setBase($base)
578 {
579 $this->base= $base;
580 }
583 function getBase()
584 {
585 return $this->base;
586 }
589 function parseLayout($layout)
590 {
591 $result= array();
592 $layout= preg_replace("/^\|/", "", $layout);
593 $layout= preg_replace("/\|$/", "", $layout);
594 $cols= split("\|", $layout);
596 foreach ($cols as $index => $config) {
597 if ($config != "") {
598 $res= "";
599 $components= split(';', $config);
600 foreach ($components as $part) {
601 if (preg_match("/^r$/", $part)) {
602 $res.= "text-align:right;";
603 continue;
604 }
605 if (preg_match("/^l$/", $part)) {
606 $res.= "text-align:left;";
607 continue;
608 }
609 if (preg_match("/^c$/", $part)) {
610 $res.= "text-align:center;";
611 continue;
612 }
613 if (preg_match("/^[0-9]+(|px|%)$/", $part)) {
614 $res.= "width:$part;min-width:$part;";
615 continue;
616 }
617 }
619 // Add minimum width for scalable columns
620 if (!preg_match('/width:/', $res)){
621 $res.= "min-width:200px;";
622 }
624 $result[$index]= " style='$res' ";
625 } else {
626 $result[$index]= " style='min-width:100px'";
627 }
628 }
630 // Save number of columns for later use
631 $this->numColumns= count($cols);
633 return $result;
634 }
637 function renderCell($data, $config, $row)
638 {
639 // Replace flat attributes in data string
640 for ($i= 0; $i<$config['count']; $i++) {
641 $attr= $config[$i];
642 $value= "";
643 if (is_array($config[$attr])) {
644 $value= $config[$attr][0];
645 } else {
646 $value= $config[$attr];
647 }
648 $data= preg_replace("/%\{$attr\}/", $value, $data);
649 }
651 // Watch out for filters and prepare to execute them
652 $data= $this->processElementFilter($data, $config, $row);
654 // Replace all non replaced %{...} instances because they
655 // are non resolved attributes or filters
656 $data= preg_replace('/%{[^}]+}/', ' ', $data);
658 return $data;
659 }
662 function renderBase()
663 {
664 if (!$this->baseMode) {
665 return;
666 }
668 $result= "<select name='BASE' onChange='mainform.submit()' size='1'>";
669 $firstDN= null;
670 $found= false;
671 foreach ($this->bases as $key=>$value) {
672 // Keep first entry to fall back eventually
673 if(!$firstDN) {
674 $firstDN= $key;
675 }
677 // Prepare to render entry
678 $selected= "";
679 if ($key == $this->base) {
680 $selected= " selected";
681 $found= true;
682 }
683 // Encode key in b64 to avoid strange characters
684 $result.= "\n<option value=\"".base64_encode($key)."\"$selected>".$value."</option>";
685 }
687 $result.= "</select>";
689 // Reset the currently used base to the first DN we found if there
690 // was no match.
691 if(!$found){
692 $this->base = $firstDN;
693 }
695 return $result;
696 }
699 function processElementFilter($data, $config, $row)
700 {
701 preg_match_all("/%\{filter:([^(]+)\((.*)\)\}/", $data, $matches, PREG_SET_ORDER);
703 foreach ($matches as $match) {
704 $cl= "";
705 $method= "";
706 if (preg_match('/::/', $match[1])) {
707 $cl= preg_replace('/::.*$/', '', $match[1]);
708 $method= preg_replace('/^.*::/', '', $match[1]);
709 } else {
710 if (!isset($this->filters[$match[1]])) {
711 continue;
712 }
713 $cl= preg_replace('/::.*$/', '', $this->filters[$match[1]]);
714 $method= preg_replace('/^.*::/', '', $this->filters[$match[1]]);
715 }
717 // Prepare params for function call
718 $params= array();
719 preg_match_all('/"[^"]+"|[^,]+/', $match[2], $parts);
720 foreach ($parts[0] as $param) {
722 // Row is replaced by the row number
723 if ($param == "row") {
724 $params[]= $row;
725 continue;
726 }
728 // pid is replaced by the current PID
729 if ($param == "pid") {
730 $params[]= $this->pid;
731 continue;
732 }
734 // base is replaced by the current base
735 if ($param == "base") {
736 $params[]= $this->getBase();
737 continue;
738 }
740 // Fixie with "" is passed directly
741 if (preg_match('/^".*"$/', $param)){
742 $params[]= preg_replace('/"/', '', $param);
743 continue;
744 }
746 // Move dn if needed
747 if ($param == "dn") {
748 $params[]= LDAP::fix($config["dn"]);
749 continue;
750 }
752 // LDAP variables get replaced by their objects
753 for ($i= 0; $i<$config['count']; $i++) {
754 if ($param == $config[$i]) {
755 $values= $config[$config[$i]];
756 if (is_array($values)){
757 unset($values['count']);
758 }
759 $params[]= $values;
760 break;
761 }
762 }
763 }
765 // Replace information
766 if ($cl == "listing") {
767 // Non static call - seems to result in errors
768 $data= @preg_replace('/'.preg_quote($match[0]).'/', call_user_func_array(array($this, "$method"), $params), $data);
769 } else {
770 // Static call
771 $data= preg_replace('/'.preg_quote($match[0]).'/', call_user_func_array(array($cl, $method), $params), $data);
772 }
773 }
775 return $data;
776 }
779 function getObjectType($types, $classes)
780 {
781 // Walk thru types and see if there's something matching
782 foreach ($types as $objectType) {
783 $ocs= $objectType['objectClass'];
784 if (!is_array($ocs)){
785 $ocs= array($ocs);
786 }
788 $found= true;
789 foreach ($ocs as $oc){
790 if (preg_match('/^!(.*)$/', $oc, $match)) {
791 $oc= $match[1];
792 if (in_array($oc, $classes)) {
793 $found= false;
794 }
795 } else {
796 if (!in_array($oc, $classes)) {
797 $found= false;
798 }
799 }
800 }
802 if ($found) {
803 return $objectType;
804 }
805 }
807 return null;
808 }
811 function filterObjectType($dn, $classes)
812 {
813 // Walk thru classes and return on first match
814 $result= " ";
816 $objectType= $this->getObjectType($this->objectTypes, $classes);
817 if ($objectType) {
818 $this->objectDnMapping[$dn]= $objectType["objectClass"];
819 $result= "<img class='center' title='".LDAP::fix($dn)."' src='".$objectType["image"]."'>";
820 if (!isset($this->objectTypeCount[$objectType['label']])) {
821 $this->objectTypeCount[$objectType['label']]= 0;
822 }
823 $this->objectTypeCount[$objectType['label']]++;
824 }
826 return $result;
827 }
830 function filterActions($dn, $row, $classes)
831 {
832 // Do nothing if there's no menu defined
833 if (!isset($this->xmlData['actiontriggers']['action'])) {
834 return " ";
835 }
837 // Go thru all actions
838 $result= "";
839 $actions= $this->xmlData['actiontriggers']['action'];
840 foreach($actions as $action) {
841 // Skip the entry completely if there's no permission to execute it
842 if (!$this->hasActionPermission($action, $dn, $classes)) {
843 $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
844 continue;
845 }
847 // Skip entry if the pseudo filter does not fit
848 if (isset($action['filter']) && preg_match('/^[a-z0-9_]+!?=[a-z0-9_]+$/i', $action['filter'])) {
849 list($fa, $fv)= split('=', $action['filter']);
850 if (preg_match('/^(.*)!$/', $fa, $m)){
851 $fa= $m[1];
852 if (isset($this->entries[$row][$fa]) && $this->entries[$row][$fa][0] == $fv) {
853 $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
854 continue;
855 }
856 } else {
857 if (!isset($this->entries[$row][$fa]) && !$this->entries[$row][$fa][0] == $fv) {
858 $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
859 continue;
860 }
861 }
862 }
865 // If there's an objectclass definition and we don't have it
866 // add an empty picture here.
867 if (isset($action['objectclass'])){
868 $objectclass= $action['objectclass'];
869 if (preg_match('/^!(.*)$/', $objectclass, $m)){
870 $objectclass= $m[1];
871 if(in_array($objectclass, $classes)) {
872 $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
873 continue;
874 }
875 } elseif (is_string($objectclass)) {
876 if(!in_array($objectclass, $classes)) {
877 $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
878 continue;
879 }
880 } elseif (is_array($objectclass)) {
881 if(count(array_intersect($objectclass, $classes)) != count($objectclass)){
882 $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
883 continue;
884 }
885 }
886 }
888 // Render normal entries as usual
889 if ($action['type'] == "entry") {
890 $label= $this->processElementFilter($action['label'], $this->entries[$row], $row);
891 $image= $this->processElementFilter($action['image'], $this->entries[$row], $row);
892 $result.="<input class='center' type='image' src='$image' title='$label' ".
893 "name='listing_".$action['name']."_$row' style='padding:1px'>";
894 }
896 // Handle special types
897 if ($action['type'] == "copypaste" || $action['type'] == "snapshot") {
899 $objectType= $this->getObjectType($this->objectTypes, $this->entries[$row]['objectClass']);
900 $category= $class= null;
901 if ($objectType) {
902 $category= $objectType['category'];
903 $class= $objectType['class'];
904 }
906 if ($action['type'] == "copypaste") {
907 $copy = !isset($action['copy']) || $action['copy'] == "true";
908 $cut = !isset($action['cut']) || $action['cut'] == "true";
909 $result.= $this->renderCopyPasteActions($row, $this->entries[$row]['dn'], $category, $class,$copy,$cut);
910 } else {
911 $result.= $this->renderSnapshotActions($row, $this->entries[$row]['dn'], $category, $class);
912 }
913 }
914 }
916 return $result;
917 }
920 function filterDepartmentLink($row, $dn, $description)
921 {
922 $attr= $this->departments[$row]['sort-attribute'];
923 $name= $this->departments[$row][$attr];
924 if (is_array($name)){
925 $name= $name[0];
926 }
927 $result= sprintf("%s [%s]", $name, $description[0]);
928 return("<a href='?plug=".$_GET['plug']."&PID=$this->pid&act=department_$row' title='$dn'>$result</a>");
929 }
932 function filterLink()
933 {
934 $result= " ";
936 $row= func_get_arg(0);
937 $pid= $this->pid;
938 $dn= LDAP::fix(func_get_arg(1));
939 $params= array(func_get_arg(2));
941 // Collect sprintf params
942 for ($i = 3;$i < func_num_args();$i++) {
943 $val= func_get_arg($i);
944 if (is_array($val)){
945 $params[]= $val[0];
946 continue;
947 }
948 $params[]= $val;
949 }
951 $result= " ";
952 $trans= call_user_func_array("sprintf", $params);
953 if ($trans != "") {
954 return("<a href='?plug=".$_GET['plug']."&PID=$pid&act=listing_edit_$row' title='$dn'>$trans</a>");
955 }
957 return $result;
958 }
961 function renderNavigation()
962 {
963 $result= array();
964 $enableBack = true;
965 $enableRoot = true;
966 $enableHome = true;
968 $ui = get_userinfo();
970 /* Check if base = first available base */
971 $deps = $ui->get_module_departments($this->categories);
973 if(!count($deps) || $deps[0] == $this->filter->base){
974 $enableBack = false;
975 $enableRoot = false;
976 }
978 $listhead ="";
980 /* Check if we are in users home department */
981 if(!count($deps) || $this->filter->base == $this->filter->getObjectBase($ui->dn)){
982 $enableHome = false;
983 }
985 /* Draw root button */
986 if($enableRoot){
987 $result["ROOT"]= "<input class='center' type='image' src='images/lists/root.png' align='middle' ".
988 "title='"._("Go to root department")."' name='ROOT' alt='"._("Root")."'>";
989 }else{
990 $result["ROOT"]= "<img src='images/lists/root_grey.png' class='center' alt='"._("Root")."'>";
991 }
993 /* Draw back button */
994 if($enableBack){
995 $result["BACK"]= "<input class='center' type='image' align='middle' src='images/lists/back.png' ".
996 "title='"._("Go up one department")."' alt='"._("Up")."' name='BACK'>";
997 }else{
998 $result["BACK"]= "<img src='images/lists/back_grey.png' class='center' alt='"._("Up")."'>";
999 }
1001 /* Draw home button */
1002 if($enableHome){
1003 $result["HOME"]= "<input class='center' type='image' align='middle' src='images/lists/home.png' ".
1004 "title='"._("Go to users department")."' alt='"._("Home")."' name='HOME'>";
1005 }else{
1006 $result["HOME"]= "<img src='images/lists/home_grey.png' class='center' alt='"._("Home")."'>";
1007 }
1009 /* Draw reload button, this button is enabled everytime */
1010 $result["RELOAD"]= "<input class='center' type='image' src='images/lists/reload.png' align='middle' ".
1011 "title='"._("Reload list")."' name='REFRESH' alt='"._("Submit")."'>";
1013 return ($result);
1014 }
1017 function getAction()
1018 {
1019 // Do not do anything if this is not our PID, or there's even no PID available...
1020 if(!isset($_REQUEST['PID']) || $_REQUEST['PID'] != $this->pid) {
1021 return;
1022 }
1024 // Save position if set
1025 if (isset($_POST['position_'.$this->pid]) && is_numeric($_POST['position_'.$this->pid])) {
1026 $this->scrollPosition= $_POST['position_'.$this->pid];
1027 }
1029 $result= array("targets" => array(), "action" => "");
1031 // Filter GET with "act" attributes
1032 if (isset($_GET['act'])) {
1033 $key= validate($_GET['act']);
1034 $target= preg_replace('/^listing_[a-zA-Z_]+_([0-9]+)$/', '$1', $key);
1035 if (isset($this->entries[$target]['dn'])) {
1036 $result['action']= preg_replace('/^listing_([a-zA-Z_]+)_[0-9]+$/', '$1', $key);
1037 $result['targets'][]= $this->entries[$target]['dn'];
1038 }
1040 // Drop targets if empty
1041 if (count($result['targets']) == 0) {
1042 unset($result['targets']);
1043 }
1044 return $result;
1045 }
1047 // Filter POST with "listing_" attributes
1048 foreach ($_POST as $key => $prop) {
1050 // Capture selections
1051 if (preg_match('/^listing_selected_[0-9]+$/', $key)) {
1052 $target= preg_replace('/^listing_selected_([0-9]+)$/', '$1', $key);
1053 if (isset($this->entries[$target]['dn'])) {
1054 $result['targets'][]= $this->entries[$target]['dn'];
1055 }
1056 continue;
1057 }
1059 // Capture action with target - this is a one shot
1060 if (preg_match('/^listing_[a-zA-Z_]+_[0-9]+(|_x)$/', $key)) {
1061 $target= preg_replace('/^listing_[a-zA-Z_]+_([0-9]+)(|_x)$/', '$1', $key);
1062 if (isset($this->entries[$target]['dn'])) {
1063 $result['action']= preg_replace('/^listing_([a-zA-Z_]+)_[0-9]+(|_x)$/', '$1', $key);
1064 $result['targets']= array($this->entries[$target]['dn']);
1065 }
1066 break;
1067 }
1069 // Capture action without target
1070 if (preg_match('/^listing_[a-zA-Z_]+(|_x)$/', $key)) {
1071 $result['action']= preg_replace('/^listing_([a-zA-Z_]+)(|_x)$/', '$1', $key);
1072 continue;
1073 }
1074 }
1076 // Filter POST with "act" attributes -> posted from action menu
1077 if (isset($_POST['act']) && $_POST['act'] != '') {
1078 if (!preg_match('/^export.*$/', $_POST['act'])){
1079 $result['action']= validate($_POST['act']);
1080 }
1081 }
1083 // Drop targets if empty
1084 if (count($result['targets']) == 0) {
1085 unset($result['targets']);
1086 }
1087 return $result;
1088 }
1091 function renderActionMenu()
1092 {
1093 // Don't send anything if the menu is not defined
1094 if (!isset($this->xmlData['actionmenu']['action'])){
1095 return "";
1096 }
1098 // Array?
1099 if (isset($this->xmlData['actionmenu']['action']['type'])){
1100 $this->xmlData['actionmenu']['action']= array($this->xmlData['actionmenu']['action']);
1101 }
1103 // Load shortcut
1104 $actions= &$this->xmlData['actionmenu']['action'];
1105 $result= "<input type='hidden' name='act' id='actionmenu' value=''><div style='display:none'><input type='submit' name='exec_act' id='exec_act' value=''></div>".
1106 "<ul class='level1' id='root'><li><a href='#'>"._("Actions")." <img ".
1107 "border=0 class='center' src='images/lists/sort-down.png'></a>";
1109 // Build ul/li list
1110 $result.= $this->recurseActions($actions);
1112 return "<div id='pulldown'>".$result."</li></ul><div>";
1113 }
1116 function recurseActions($actions)
1117 {
1118 global $class_mapping;
1119 static $level= 2;
1120 $result= "<ul class='level$level'>";
1121 $separator= "";
1123 foreach ($actions as $action) {
1125 // Skip the entry completely if there's no permission to execute it
1126 if (!$this->hasActionPermission($action, $this->filter->base)) {
1127 continue;
1128 }
1130 // Skip entry if there're missing dependencies
1131 if (isset($action['depends'])) {
1132 $deps= is_array($action['depends'])?$action['depends']:array($action['depends']);
1133 foreach($deps as $clazz) {
1134 if (!isset($class_mapping[$clazz])){
1135 continue 2;
1136 }
1137 }
1138 }
1140 // Fill image if set
1141 $img= "";
1142 if (isset($action['image'])){
1143 $img= "<img border='0' class='center' src='".$action['image']."'> ";
1144 }
1146 if ($action['type'] == "separator"){
1147 $separator= " style='border-top:1px solid #AAA' ";
1148 continue;
1149 }
1151 // Dive into subs
1152 if ($action['type'] == "sub" && isset($action['action'])) {
1153 $level++;
1154 if (isset($action['label'])){
1155 $result.= "<li$separator><a href='#'>$img"._($action['label'])." <img border='0' src='images/forward-arrow.png'></a>";
1156 }
1158 // Ensure we've an array of actions, this enables sub menus with only one action.
1159 if(isset($action['action']['type'])){
1160 $action['action'] = array($action['action']);
1161 }
1163 $result.= $this->recurseActions($action['action'])."</li>";
1164 $level--;
1165 $separator= "";
1166 continue;
1167 }
1169 // Render entry elseways
1170 if (isset($action['label'])){
1171 $result.= "<li$separator><a href='#' onClick='document.getElementById(\"actionmenu\").value= \"".$action['name']."\";mainform.submit();'>$img"._($action['label'])."</a></li>";
1172 }
1174 // Check for special types
1175 switch ($action['type']) {
1176 case 'copypaste':
1177 $cut = !isset($action['cut']) || $action['cut'] != "false";
1178 $copy = !isset($action['copy']) || $action['copy'] != "false";
1179 $result.= $this->renderCopyPasteMenu($separator, $copy , $cut);
1180 break;
1182 case 'snapshot':
1183 $result.= $this->renderSnapshotMenu($separator);
1184 break;
1186 case 'exporter':
1187 $result.= $this->renderExporterMenu($separator);
1188 break;
1190 case 'daemon':
1191 $result.= $this->renderDaemonMenu($separator);
1192 break;
1193 }
1195 $separator= "";
1196 }
1198 $result.= "</ul>";
1199 return $result;
1200 }
1203 function hasActionPermission($action, $dn, $classes= null)
1204 {
1205 $ui= get_userinfo();
1207 if (isset($action['acl'])) {
1208 $acls= $action['acl'];
1209 if (!is_array($acls)) {
1210 $acls= array($acls);
1211 }
1213 // Every ACL has to pass
1214 foreach ($acls as $acl) {
1215 $module= $this->categories;
1216 $aclList= array();
1218 // Replace %acl if available
1219 if ($classes) {
1220 $otype= $this->getObjectType($this->objectTypes, $classes);
1221 $acl= str_replace('%acl', $otype['category']."/".$otype['class'], $acl);
1222 }
1224 // Split for category and plugins if needed
1225 // match for "[rw]" style entries
1226 if (preg_match('/^\[([rwcdm]+)\]$/', $acl, $match)){
1227 $aclList= array($match[1]);
1228 }
1230 // match for "users[rw]" style entries
1231 if (preg_match('/^([a-zA-Z0-9]+)\[([rwcdm]+)\]$/', $acl, $match)){
1232 $module= $match[1];
1233 $aclList= array($match[2]);
1234 }
1236 // match for "users/user[rw]" style entries
1237 if (preg_match('/^([a-zA-Z0-9]+\/[a-zA-Z0-9]+)\[([rwcdm]+)\]$/', $acl, $match)){
1238 $module= $match[1];
1239 $aclList= array($match[2]);
1240 }
1242 // match "users/user[userPassword:rw(,...)*]" style entries
1243 if (preg_match('/^([a-zA-Z0-9]+\/[a-zA-Z0-9]+)\[([a-zA-Z0-9]+:[rwcdm]+(,[a-zA-Z0-9]+:[rwcdm]+)*)\]$/', $acl, $match)){
1244 $module= $match[1];
1245 $aclList= split(',', $match[2]);
1246 }
1248 // Walk thru prepared ACL by using $module
1249 foreach($aclList as $sAcl) {
1250 $checkAcl= "";
1252 // Category or detailed permission?
1253 if (strpos('/', $module) === false) {
1254 if (preg_match('/([a-zA-Z0-9]+):([rwcdm]+)/', $sAcl, $m) ) {
1255 $checkAcl= $ui->get_permissions($dn, $module, $m[1]);
1256 $sAcl= $m[2];
1257 } else {
1258 $checkAcl= $ui->get_permissions($dn, $module, '0');
1259 }
1260 } else {
1261 $checkAcl= $ui->get_category_permissions($dn, $module);
1262 }
1264 // Split up remaining part of the acl and check if it we're
1265 // allowed to do something...
1266 $parts= str_split($sAcl);
1267 foreach ($parts as $part) {
1268 if (strpos($checkAcl, $part) === false){
1269 return false;
1270 }
1271 }
1273 }
1274 }
1275 }
1277 return true;
1278 }
1281 function refreshBasesList()
1282 {
1283 global $config;
1284 $ui= get_userinfo();
1286 // Do some array munching to get it user friendly
1287 $ids= $config->idepartments;
1288 $d= $ui->get_module_departments($this->categories);
1289 $k_ids= array_keys($ids);
1290 $deps= array_intersect($d,$k_ids);
1292 // Fill internal bases list
1293 $this->bases= array();
1294 foreach($k_ids as $department){
1295 $this->bases[$department] = $ids[$department];
1296 }
1297 }
1300 function getDepartments()
1301 {
1302 $departments= array();
1303 $ui= get_userinfo();
1305 // Get list of supported department types
1306 $types = departmentManagement::get_support_departments();
1308 // Load departments allowed by ACL
1309 $validDepartments = $ui->get_module_departments($this->categories);
1311 // Build filter and look in the LDAP for possible sub departments
1312 // of current base
1313 $filter= "(&(objectClass=gosaDepartment)(|";
1314 $attrs= array("description", "objectClass");
1315 foreach($types as $name => $data){
1316 $filter.= "(objectClass=".$data['OC'].")";
1317 $attrs[]= $data['ATTR'];
1318 }
1319 $filter.= "))";
1320 $res= get_list($filter, $this->categories, $this->base, $attrs, GL_NONE);
1322 // Analyze list of departments
1323 foreach ($res as $department) {
1324 if (!in_array($department['dn'], $validDepartments)) {
1325 continue;
1326 }
1328 // Add the attribute where we use for sorting
1329 $oc= null;
1330 foreach(array_keys($types) as $type) {
1331 if (in_array($type, $department['objectClass'])) {
1332 $oc= $type;
1333 break;
1334 }
1335 }
1336 $department['sort-attribute']= $types[$oc]['ATTR'];
1338 // Move to the result list
1339 $departments[]= $department;
1340 }
1342 return $departments;
1343 }
1346 function renderCopyPasteMenu($separator, $copy= true, $cut= true)
1347 {
1348 // We can only provide information if we've got a copypaste handler
1349 // instance
1350 if(!(isset($this->copyPasteHandler) && is_object($this->copyPasteHandler))){
1351 return "";
1352 }
1354 // Presets
1355 $result= "";
1356 $read= $paste= false;
1357 $ui= get_userinfo();
1359 // Switch flags to on if there's at least one category which allows read/paste
1360 foreach($this->categories as $category){
1361 $read= $read || preg_match('/r/', $ui->get_category_permissions($this->base, $category));
1362 $paste= $paste || $ui->is_pasteable($this->base, $category) == 1;
1363 }
1366 // Draw entries that allow copy and cut
1367 if($read){
1369 // Copy entry
1370 if($copy){
1371 $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>";
1372 $separator= "";
1373 }
1375 // Cut entry
1376 if($cut){
1377 $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>";
1378 $separator= "";
1379 }
1380 }
1382 // Draw entries that allow pasting entries
1383 if($paste){
1384 if($this->copyPasteHandler->entries_queued()){
1385 $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>";
1386 }else{
1387 $result.= "<li$separator><a href='#'><img src='images/lists/paste-grey.png' alt='' border='0' class='center'> "._("Paste")."</a></li>";
1388 }
1389 }
1391 return($result);
1392 }
1395 function renderCopyPasteActions($row, $dn, $category, $class, $copy= true, $cut= true)
1396 {
1397 // We can only provide information if we've got a copypaste handler
1398 // instance
1399 if(!(isset($this->copyPasteHandler) && is_object($this->copyPasteHandler))){
1400 return "";
1401 }
1403 // Presets
1404 $ui = get_userinfo();
1405 $result = "";
1407 // Render cut entries
1408 if($cut){
1409 if($ui->is_cutable($dn, $category, $class)){
1410 $result .= "<input class='center' type='image'
1411 src='images/lists/cut.png' alt='"._("Cut")."' name='listing_cut_$row' title='"._("Cut this entry")."' style='padding:1px'>";
1412 }else{
1413 $result.="<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
1414 }
1415 }
1417 // Render copy entries
1418 if($copy){
1419 if($ui->is_copyable($dn, $category, $class)){
1420 $result.= "<input class='center' type='image'
1421 src='images/lists/copy.png' alt='"._("Copy")."' name='listing_copy_$row' title='"._("Copy this entry")."' style='padding:1px'>";
1422 }else{
1423 $result.="<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
1424 }
1425 }
1427 return($result);
1428 }
1431 function renderSnapshotMenu($separator)
1432 {
1433 // We can only provide information if we've got a snapshot handler
1434 // instance
1435 if(!(isset($this->snapshotHandler) && is_object($this->snapshotHandler))){
1436 return "";
1437 }
1439 // Presets
1440 $result = "";
1441 $ui = get_userinfo();
1443 if($this->snapshotHandler->enabled() && $ui->allow_snapshot_restore($this->base, $this->categories)){
1445 // Check if there is something to restore
1446 $restore= false;
1447 foreach($this->snapshotHandler->getSnapshotBases() as $base){
1448 $restore= $restore || count($this->snapshotHandler->getDeletedSnapshots($base)) > 0;
1449 }
1451 // Draw icons according to the restore flag
1452 if($restore){
1453 $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>";
1454 }else{
1455 $result.= "<li$separator><a href='#'><img src='images/lists/restore_grey.png' alt='' border='0' class='center'> "._("Restore snapshots")."</a></li>";
1456 }
1457 }
1459 return($result);
1460 }
1463 function renderExporterMenu($separator)
1464 {
1465 // Presets
1466 $result = "";
1468 // Draw entries
1469 $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'>";
1471 // Export CVS as build in exporter
1472 foreach ($this->exporter as $action => $exporter) {
1473 $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>";
1474 }
1476 // Finalize list
1477 $result.= "</ul></li>";
1479 return($result);
1480 }
1483 function renderSnapshotActions($row, $dn, $category, $class, $copy= true, $cut= true)
1484 {
1485 // We can only provide information if we've got a snapshot handler
1486 // instance
1487 if(!(isset($this->snapshotHandler) && is_object($this->snapshotHandler))){
1488 return "";
1489 }
1491 // Presets
1492 $result= "";
1493 $ui = get_userinfo();
1495 // Only act if enabled here
1496 if($this->snapshotHandler->enabled()){
1498 // Draw restore button
1499 if ($ui->allow_snapshot_restore($dn, $category)){
1501 // Do we have snapshots for this dn?
1502 if($this->snapshotHandler->hasSnapshots($dn)){
1503 $result.= "<input class='center' type='image' src='images/lists/restore.png' ".
1504 "alt='"._("Restore snapshot")."' name='listing_restore_$row' title='".
1505 _("Restore snapshot")."' style='padding:1px'>";
1506 } else {
1507 $result.= "<img src='images/lists/restore_grey.png' alt=' ' class='center' style='padding:1px'>";
1508 }
1509 }
1511 // Draw snapshot button
1512 if($ui->allow_snapshot_create($dn, $category)){
1513 $result.= "<input class='center' type='image' src='images/snapshot.png' ".
1514 "alt='"._("Create snapshot")."' name='listing_snapshot_$row' title='".
1515 _("Create a new snapshot from this object")."' style='padding:1px'>";
1516 }else{
1517 $result.= "<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
1518 }
1519 }
1521 return($result);
1522 }
1525 function renderDaemonMenu($separator)
1526 {
1527 $result= "";
1529 // If there is a daemon registered, draw the menu entries
1530 if(class_available("DaemonEvent")){
1531 $events= DaemonEvent::get_event_types_by_category($this->categories);
1532 if(isset($events['BY_CLASS']) && count($events['BY_CLASS'])){
1533 foreach($events['BY_CLASS'] as $name => $event){
1534 $result.= "<li$separator><a href='#' onClick='document.getElementById(\"actionmenu\").value=\"$name\";document.getElementById(\"exec_act\").click();'>".$event['MenuImage']." ".$event['s_Menu_Name']."</a></li>";
1535 $separator= "";
1536 }
1537 }
1538 }
1540 return $result;
1541 }
1544 function getEntry($dn)
1545 {
1546 foreach ($this->entries as $entry) {
1547 if (isset($entry['dn']) && strcasecmp($dn, $entry['dn']) == 0){
1548 return $entry;
1549 }
1550 }
1551 return null;
1552 }
1555 function getType($dn)
1556 {
1557 if (isset($this->objectDnMapping[$dn])) {
1558 return $this->objectDnMapping[$dn];
1559 }
1560 return null;
1561 }
1563 }
1565 ?>