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("core","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]?_("Sort ascending"):_("Sort descending"), "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;'>";
308 if($this->multiSelect){
309 $result.= "<input type='checkbox' id='select_all' name='select_all'
310 title='"._("Select all")."' onClick='toggle_all_(\"listing_selected_[0-9]*$\",\"select_all\");' >";
311 }else{
312 $result.= " ";
313 }
314 $result.="</td>\n";
315 }
316 foreach ($this->header as $header) {
317 $result.= $header;
318 }
319 $result.= "</tr></thead>\n";
321 // Build list body
322 $result.= "<tbody class='listScrollContent listBodyFormat' id='t_nscrollbody' style='height:".$height."px;'>\n";
324 // No results? Just take an empty colspanned row
325 if (count($this->entries) + count($this->departments) == 0) {
326 $result.= "<tr><td class='list1nohighlight' colspan='$this->numColumns' style='height:100%;border-right:0px;width:100%;'> </td></tr>";
327 }
329 // Line color alternation
330 $alt= 0;
331 $deps= 0;
333 // Draw department browser if configured and we're not in sub mode
334 $this->useSpan= false;
335 if ($this->departmentBrowser && $this->filter->scope != "sub") {
336 // Fill with department browser if configured this way
337 $departmentIterator= new departmentSortIterator($this->departments, $this->sortDirection[$this->sortColumn]);
338 foreach ($departmentIterator as $row => $entry){
339 $rowResult= "<tr>";
341 // Render multi select if needed
342 if ($this->multiSelect || $this->singleSelect) {
343 $rowResult.="<td style='text-align:center;padding:0;' class='list1'> </td>";
344 }
346 // Render defined department columns, fill the rest with some stuff
347 $rest= $this->numColumns - 1;
348 foreach ($this->xmlData['table']['department'] as $index => $config) {
349 $colspan= 1;
350 if (isset($config['span'])){
351 $colspan= $config['span'];
352 $this->useSpan= true;
353 }
354 $rowResult.="<td colspan='$colspan' ".$this->colprops[$index]." class='list1'>".$this->renderCell($config['value'], $entry, $row)."</td>";
355 $rest-= $colspan;
356 }
358 // Fill remaining cols with nothing
359 $last= $this->numColumns - $rest;
360 for ($i= 0; $i<$rest; $i++){
361 $rowResult.= "<td ".$this->colprops[$last+$i-1]." class='list1'> </td>";
362 }
363 $rowResult.="</tr>";
365 // Apply label to objecttype icon?
366 if (preg_match("/<objectType:([^:]+):(.*)\/>/i", $rowResult, $matches)){
367 $objectType= image($matches[1], null, LDAP::fix(base64_decode($matches[2])));
368 $rowResult= preg_replace("/<objectType[^>]+>/", $objectType, $rowResult);
369 }
370 $result.= $rowResult;
371 $alt++;
372 }
375 $deps= $alt;
376 }
378 // Fill with contents, sort as configured
379 foreach ($this->entries as $row => $entry) {
380 $trow= "";
382 // Render multi select if needed
383 if ($this->multiSelect) {
384 $trow.="<td style='text-align:center;width:20px;' class='list0'><input type='checkbox' id='listing_selected_$row' name='listing_selected_$row'></td>\n";
385 }
387 if ($this->singleSelect) {
388 $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";
389 }
391 foreach ($this->xmlData['table']['column'] as $index => $config) {
392 $renderedCell= $this->renderCell($config['value'], $entry, $row);
393 $trow.="<td ".$this->colprops[$index]." class='list0'>".$renderedCell."</td>\n";
395 // Save rendered column
396 $sort= preg_replace('/.*>([^<]+)<.*$/', '$1', $renderedCell);
397 $sort= preg_replace('/ /', '', $sort);
398 if (preg_match('/</', $sort)){
399 $sort= "";
400 }
401 $this->entries[$row]["_sort$index"]= $sort;
402 }
404 // Save rendered entry
405 $this->entries[$row]['_rendered']= $trow;
406 }
408 // Complete list by sorting entries for _sort$index and appending them to the output
409 $entryIterator= new listingSortIterator($this->entries, $this->sortDirection[$this->sortColumn], "_sort".$this->sortColumn, $this->sortType);
410 foreach ($entryIterator as $row => $entry){
412 // Apply label to objecttype icon?
413 if (preg_match("/<objectType:([^:]+):(.*)\/>/i", $entry['_rendered'], $matches)){
414 if (preg_match("/<rowLabel:([a-z0-9_-]*)\/>/i", $entry['_rendered'], $m)) {
415 $objectType= image($matches[1]."[".$m[1]."]", null, LDAP::fix(base64_decode($matches[2])));
416 } else {
417 $objectType= image($matches[1], null, LDAP::fix(base64_decode($matches[2])));
418 }
419 $entry['_rendered']= preg_replace("/<objectType[^>]+>/", $objectType, $entry['_rendered']);
420 $entry['_rendered']= preg_replace("/<rowLabel[^>]+>/", '', $entry['_rendered']);
421 }
423 // Apply custom class to row?
424 if (preg_match("/<rowClass:([a-z0-9_-]*)\/>/i", $entry['_rendered'], $matches)) {
425 $result.="<tr class='".$matches[1]."'>\n";
426 $result.= preg_replace("/<rowClass[^>]+>/", '', $entry['_rendered']);
427 } else {
428 $result.="<tr>\n";
429 $result.= $entry['_rendered'];
430 }
432 $result.="</tr>\n";
433 $alt++;
434 }
436 // Need to fill the list if it's not full (nobody knows why this is 22 ;-))
437 $emptyListStyle= (count($this->entries) + (($this->useSpan && count($this->entries))?$deps:0) == 0)?"border:0;":"";
438 if ((count($this->entries) + $deps) < 22) {
439 $result.= "<tr>";
440 for ($i= 0; $i<$this->numColumns; $i++) {
441 if ($i == 0) {
442 $result.= "<td class='list1nohighlight' style='$emptyListStyle height:100%;'> </td>";
443 continue;
444 }
445 if ($i != $this->numColumns-1) {
446 $result.= "<td class='list1nohighlight' style='$emptyListStyle'> </td>";
447 } else {
448 $result.= "<td class='list1nohighlight' style='border-right:0;$emptyListStyle'> </td>";
449 }
450 }
452 $result.= "</tr>";
453 }
455 // Close list body
456 $result.= "</tbody></table></div>";
458 // Add the footer if requested
459 if ($this->showFooter) {
460 $result.= "<div class='nlistFooter'><div style='padding:3px'>";
462 foreach ($this->objectTypes as $objectType) {
463 if (isset($this->objectTypeCount[$objectType['label']])) {
464 $label= _($objectType['label']);
465 $result.= image($objectType['image'], null, $label)." ".$this->objectTypeCount[$objectType['label']]." ";
466 }
467 }
469 $result.= "</div></div>";
470 }
472 // Close list
473 $result.= $switch?"<input type='hidden' id='list_workaround'>":"";
475 // Add scroll positioner
476 $result.= '<script type="text/javascript" language="javascript">';
477 $result.= '$("t_nscrollbody").scrollTop= '.$this->scrollPosition.';';
478 $result.= 'var box = $("t_nscrollbody").onscroll= function() {$("position_'.$this->pid.'").value= this.scrollTop;}';
479 $result.= '</script>';
481 $smarty= get_smarty();
483 $smarty->assign("FILTER", $this->filter->render());
484 $smarty->assign("SIZELIMIT", print_sizelimit_warning());
485 $smarty->assign("LIST", $result);
487 // Assign navigation elements
488 $nav= $this->renderNavigation();
489 foreach ($nav as $key => $html) {
490 $smarty->assign($key, $html);
491 }
493 // Assign action menu / base
494 $smarty->assign("HEADLINE", $this->headline);
495 $smarty->assign("ACTIONS", $this->renderActionMenu());
496 $smarty->assign("BASE", $this->renderBase());
498 // Assign separator
499 $smarty->assign("SEPARATOR", "<img src='images/lists/seperator.png' alt='-' align='middle' height='16' width='1' class='center'>");
501 // Assign summary
502 $smarty->assign("HEADLINE", $this->headline);
504 // Try to load template from plugin the folder first...
505 $file = get_template_path($this->xmlData['definition']['template'], true);
507 // ... if this fails, try to load the file from the theme folder.
508 if(!file_exists($file)){
509 $file = get_template_path($this->xmlData['definition']['template']);
510 }
512 return ($smarty->fetch($file));
513 }
516 function update()
517 {
518 global $config;
519 $ui= get_userinfo();
521 // Take care of base selector
522 if ($this->baseMode) {
523 $this->baseSelector->update();
525 // Check if a wrong base was supplied
526 if(!$this->baseSelector->checkLastBaseUpdate()){
527 msg_dialog::display(_("Error"), msgPool::check_base(), ERROR_DIALOG);
528 }
529 }
531 // Save base
532 $refresh= false;
533 if ($this->baseMode) {
534 $this->base= $this->baseSelector->getBase();
535 session::global_set("CurrentMainBase", $this->base);
536 $refresh= true;
537 }
540 // Reset object counter / DN mapping
541 $this->objectTypeCount= array();
542 $this->objectDnMapping= array();
544 // Do not do anything if this is not our PID
545 if($refresh || !(isset($_REQUEST['PID']) && $_REQUEST['PID'] != $this->pid)) {
547 // Save position if set
548 if (isset($_POST['position_'.$this->pid]) && is_numeric($_POST['position_'.$this->pid])) {
549 $this->scrollPosition= $_POST['position_'.$this->pid];
550 }
552 // Override the base if we got a message from the browser navigation
553 if ($this->departmentBrowser && isset($_GET['act'])) {
554 if (preg_match('/^department_([0-9]+)$/', validate($_GET['act']), $match)){
555 if (isset($this->departments[$match[1]])){
556 $this->base= $this->departments[$match[1]]['dn'];
557 if ($this->baseMode) {
558 $this->baseSelector->setBase($this->base);
559 }
560 session::global_set("CurrentMainBase", $this->base);
561 }
562 }
563 }
565 // Filter POST with "act" attributes -> posted from action menu
566 if (isset($_POST['exec_act']) && $_POST['act'] != '') {
567 if (preg_match('/^export.*$/', $_POST['act']) && isset($this->exporter[$_POST['act']])) {
568 $exporter= $this->exporter[$_POST['act']];
569 $userinfo= ", "._("created by")." ".$ui->cn." - ".strftime('%A, %d. %B %Y, %H:%M:%S');
570 $entryIterator= new listingSortIterator($this->entries, $this->sortDirection[$this->sortColumn], "_sort".$this->sortColumn, $this->sortType);
571 $sortedEntries= array();
572 foreach ($entryIterator as $entry){
573 $sortedEntries[]= $entry;
574 }
575 $instance= new $exporter['class']($this->headline.$userinfo, $this->plainHeader, $sortedEntries, $this->exportColumns);
576 $type= call_user_func(array($exporter['class'], "getInfo"));
577 $type= $type[$_POST['act']];
578 send_binary_content($instance->query(), $type['filename'], $type= $type['mime']);
579 }
580 }
582 // Filter GET with "act" attributes
583 if (isset($_GET['act'])) {
584 $key= validate($_GET['act']);
585 if (preg_match('/^SORT_([0-9]+)$/', $key, $match)) {
586 // Switch to new column or invert search order?
587 $column= $match[1];
588 if ($this->sortColumn != $column) {
589 $this->sortColumn= $column;
590 } else {
591 $this->sortDirection[$column]= !$this->sortDirection[$column];
592 }
594 // Allow header to update itself according to the new sort settings
595 $this->renderHeader();
596 }
597 }
599 // Override base if we got signals from the navigation elements
600 $action= "";
601 foreach ($_POST as $key => $value) {
602 if (preg_match('/^(ROOT|BACK|HOME)(_x)?$/', $key, $match)) {
603 $action= $match[1];
604 break;
605 }
606 }
608 // Navigation handling
609 if ($action == 'ROOT') {
610 $deps= $ui->get_module_departments($this->categories);
611 $this->base= $deps[0];
612 $this->baseSelector->setBase($this->base);
613 session::global_set("CurrentMainBase", $this->base);
614 }
615 if ($action == 'BACK') {
616 $deps= $ui->get_module_departments($this->categories);
617 $base= preg_replace("/^[^,]+,/", "", $this->base);
618 if(in_array_ics($base, $deps)){
619 $this->base= $base;
620 $this->baseSelector->setBase($this->base);
621 session::global_set("CurrentMainBase", $this->base);
622 }
623 }
624 if ($action == 'HOME') {
625 $ui= get_userinfo();
626 $this->base= get_base_from_people($ui->dn);
627 $this->baseSelector->setBase($this->base);
628 session::global_set("CurrentMainBase", $this->base);
629 }
630 }
632 // Reload departments
633 if ($this->departmentBrowser){
634 $this->departments= $this->getDepartments();
635 }
637 // Update filter and refresh entries
638 $this->filter->setBase($this->base);
639 $this->entries= $this->filter->query();
641 // Fix filter if querie returns NULL
642 if ($this->entries == null) {
643 $this->entries= array();
644 }
645 }
648 function setBase($base)
649 {
650 $this->base= $base;
651 if ($this->baseMode) {
652 $this->baseSelector->setBase($this->base);
653 }
654 }
657 function getBase()
658 {
659 return $this->base;
660 }
663 function parseLayout($layout)
664 {
665 $result= array();
666 $layout= preg_replace("/^\|/", "", $layout);
667 $layout= preg_replace("/\|$/", "", $layout);
668 $cols= explode("|", $layout);
670 foreach ($cols as $index => $config) {
671 if ($config != "") {
672 $res= "";
673 $components= explode(';', $config);
674 foreach ($components as $part) {
675 if (preg_match("/^r$/", $part)) {
676 $res.= "text-align:right;";
677 continue;
678 }
679 if (preg_match("/^l$/", $part)) {
680 $res.= "text-align:left;";
681 continue;
682 }
683 if (preg_match("/^c$/", $part)) {
684 $res.= "text-align:center;";
685 continue;
686 }
687 if (preg_match("/^[0-9]+(|px|%)$/", $part)) {
688 $res.= "width:$part;min-width:$part;";
689 continue;
690 }
691 }
693 // Add minimum width for scalable columns
694 if (!preg_match('/width:/', $res)){
695 $res.= "min-width:200px;";
696 }
698 $result[$index]= " style='$res'";
699 } else {
700 $result[$index]= " style='min-width:100px;'";
701 }
702 }
704 // Save number of columns for later use
705 $this->numColumns= count($cols);
707 // Add no border to the last column
708 $result[$this->numColumns-1]= preg_replace("/'$/", "border-right:0;'", $result[$this->numColumns-1]);
710 return $result;
711 }
714 function renderCell($data, $config, $row)
715 {
716 // Replace flat attributes in data string
717 for ($i= 0; $i<$config['count']; $i++) {
718 $attr= $config[$i];
719 $value= "";
720 if (is_array($config[$attr])) {
721 $value= $config[$attr][0];
722 } else {
723 $value= $config[$attr];
724 }
725 $data= preg_replace("/%\{$attr\}/", $value, $data);
726 }
728 // Watch out for filters and prepare to execute them
729 $data= $this->processElementFilter($data, $config, $row);
731 // Replace all non replaced %{...} instances because they
732 // are non resolved attributes or filters
733 $data= preg_replace('/%{[^}]+}/', ' ', $data);
735 return $data;
736 }
739 function renderBase()
740 {
741 if (!$this->baseMode) {
742 return;
743 }
745 return $this->baseSelector->render();
746 }
749 function processElementFilter($data, $config, $row)
750 {
751 preg_match_all("/%\{filter:([^(]+)\((.*)\)\}/", $data, $matches, PREG_SET_ORDER);
753 foreach ($matches as $match) {
754 $cl= "";
755 $method= "";
756 if (preg_match('/::/', $match[1])) {
757 $cl= preg_replace('/::.*$/', '', $match[1]);
758 $method= preg_replace('/^.*::/', '', $match[1]);
759 } else {
760 if (!isset($this->filters[$match[1]])) {
761 continue;
762 }
763 $cl= preg_replace('/::.*$/', '', $this->filters[$match[1]]);
764 $method= preg_replace('/^.*::/', '', $this->filters[$match[1]]);
765 }
767 // Prepare params for function call
768 $params= array();
769 preg_match_all('/"[^"]+"|[^,]+/', $match[2], $parts);
770 foreach ($parts[0] as $param) {
772 // Row is replaced by the row number
773 if ($param == "row") {
774 $params[]= $row;
775 continue;
776 }
778 // pid is replaced by the current PID
779 if ($param == "pid") {
780 $params[]= $this->pid;
781 continue;
782 }
784 // base is replaced by the current base
785 if ($param == "base") {
786 $params[]= $this->getBase();
787 continue;
788 }
790 // Fixie with "" is passed directly
791 if (preg_match('/^".*"$/', $param)){
792 $params[]= preg_replace('/"/', '', $param);
793 continue;
794 }
796 // Move dn if needed
797 if ($param == "dn") {
798 $params[]= LDAP::fix($config["dn"]);
799 continue;
800 }
802 // LDAP variables get replaced by their objects
803 for ($i= 0; $i<$config['count']; $i++) {
804 if ($param == $config[$i]) {
805 $values= $config[$config[$i]];
806 if (is_array($values)){
807 unset($values['count']);
808 }
809 $params[]= $values;
810 break;
811 }
812 }
813 }
815 // Replace information
816 if ($cl == "listing") {
817 // Non static call - seems to result in errors
818 $data= @preg_replace('/'.preg_quote($match[0]).'/', call_user_func_array(array($this, "$method"), $params), $data);
819 } else {
820 // Static call
821 $data= preg_replace('/'.preg_quote($match[0]).'/', call_user_func_array(array($cl, $method), $params), $data);
822 }
823 }
825 return $data;
826 }
829 function getObjectType($types, $classes)
830 {
831 // Walk thru types and see if there's something matching
832 foreach ($types as $objectType) {
833 $ocs= $objectType['objectClass'];
834 if (!is_array($ocs)){
835 $ocs= array($ocs);
836 }
838 $found= true;
839 foreach ($ocs as $oc){
840 if (preg_match('/^!(.*)$/', $oc, $match)) {
841 $oc= $match[1];
842 if (in_array($oc, $classes)) {
843 $found= false;
844 }
845 } else {
846 if (!in_array($oc, $classes)) {
847 $found= false;
848 }
849 }
850 }
852 if ($found) {
853 return $objectType;
854 }
855 }
857 return null;
858 }
861 function filterObjectType($dn, $classes)
862 {
863 // Walk thru classes and return on first match
864 $result= " ";
866 $objectType= $this->getObjectType($this->objectTypes, $classes);
867 if ($objectType) {
868 $this->objectDnMapping[$dn]= $objectType["objectClass"];
869 $result= "<objectType:".$objectType["image"].":".base64_encode(LDAP::fix($dn))."/>";
870 if (!isset($this->objectTypeCount[$objectType['label']])) {
871 $this->objectTypeCount[$objectType['label']]= 0;
872 }
873 $this->objectTypeCount[$objectType['label']]++;
874 }
876 return $result;
877 }
880 function filterActions($dn, $row, $classes)
881 {
882 // Do nothing if there's no menu defined
883 if (!isset($this->xmlData['actiontriggers']['action'])) {
884 return " ";
885 }
887 // Go thru all actions
888 $result= "";
889 $actions= $this->xmlData['actiontriggers']['action'];
891 // Ensure we've a valid actions array, if there is only one action in the actiontriggers col
892 // then we've to create a valid array here.
893 if(isset($actions['name'])) $actions = array($actions);
895 foreach($actions as $action) {
896 // Skip the entry completely if there's no permission to execute it
897 if (!$this->hasActionPermission($action, $dn, $classes)) {
898 $result.= image('images/empty.png');
899 continue;
900 }
902 // Skip entry if the pseudo filter does not fit
903 if (isset($action['filter']) && preg_match('/^[a-z0-9_]+!?=[a-z0-9_]+$/i', $action['filter'])) {
904 list($fa, $fv)= explode('=', $action['filter']);
905 if (preg_match('/^(.*)!$/', $fa, $m)){
906 $fa= $m[1];
907 if (isset($this->entries[$row][$fa]) && $this->entries[$row][$fa][0] == $fv) {
908 $result.= image('images/empty.png');
909 continue;
910 }
911 } else {
912 if (!isset($this->entries[$row][$fa]) && !$this->entries[$row][$fa][0] == $fv) {
913 $result.= image('images/empty.png');
914 continue;
915 }
916 }
917 }
920 // If there's an objectclass definition and we don't have it
921 // add an empty picture here.
922 if (isset($action['objectclass'])){
923 $objectclass= $action['objectclass'];
924 if (preg_match('/^!(.*)$/', $objectclass, $m)){
925 $objectclass= $m[1];
926 if(in_array($objectclass, $classes)) {
927 $result.= image('images/empty.png');
928 continue;
929 }
930 } elseif (is_string($objectclass)) {
931 if(!in_array($objectclass, $classes)) {
932 $result.= image('images/empty.png');
933 continue;
934 }
935 } elseif (is_array($objectclass)) {
936 if(count(array_intersect($objectclass, $classes)) != count($objectclass)){
937 $result.= image('images/empty.png');
938 continue;
939 }
940 }
941 }
943 // Render normal entries as usual
944 if ($action['type'] == "entry") {
945 $label= $this->processElementFilter($action['label'], $this->entries[$row], $row);
946 $image= $this->processElementFilter($action['image'], $this->entries[$row], $row);
947 $result.= image($image, "listing_".$action['name']."_$row", $label);
948 }
950 // Handle special types
951 if ($action['type'] == "copypaste" || $action['type'] == "snapshot") {
953 $objectType= $this->getObjectType($this->objectTypes, $this->entries[$row]['objectClass']);
954 $category= $class= null;
955 if ($objectType) {
956 $category= $objectType['category'];
957 $class= $objectType['class'];
958 }
960 if ($action['type'] == "copypaste") {
961 $copy = !isset($action['copy']) || $action['copy'] == "true";
962 $cut = !isset($action['cut']) || $action['cut'] == "true";
963 $result.= $this->renderCopyPasteActions($row, $this->entries[$row]['dn'], $category, $class,$copy,$cut);
964 } else {
965 $result.= $this->renderSnapshotActions($row, $this->entries[$row]['dn'], $category, $class);
966 }
967 }
968 }
970 return $result;
971 }
974 function filterDepartmentLink($row, $dn, $description)
975 {
976 $attr= $this->departments[$row]['sort-attribute'];
977 $name= $this->departments[$row][$attr];
978 if (is_array($name)){
979 $name= $name[0];
980 }
981 $result= sprintf("%s [%s]", $name, $description[0]);
982 return("<a href='?plug=".$_GET['plug']."&PID=$this->pid&act=department_$row' title='$dn'>$result</a>");
983 }
986 function filterLink()
987 {
988 $result= " ";
990 $row= func_get_arg(0);
991 $pid= $this->pid;
992 $dn= LDAP::fix(func_get_arg(1));
993 $params= array(func_get_arg(2));
995 // Collect sprintf params
996 for ($i = 3;$i < func_num_args();$i++) {
997 $val= func_get_arg($i);
998 if (is_array($val)){
999 $params[]= $val[0];
1000 continue;
1001 }
1002 $params[]= $val;
1003 }
1005 $result= " ";
1006 $trans= call_user_func_array("sprintf", $params);
1007 if ($trans != "") {
1008 return("<a href='?plug=".$_GET['plug']."&PID=$pid&act=listing_edit_$row' title='$dn'>$trans</a>");
1009 }
1011 return $result;
1012 }
1015 function renderNavigation()
1016 {
1017 $result= array();
1018 $enableBack = true;
1019 $enableRoot = true;
1020 $enableHome = true;
1022 $ui = get_userinfo();
1024 /* Check if base = first available base */
1025 $deps = $ui->get_module_departments($this->categories);
1027 if(!count($deps) || $deps[0] == $this->filter->base){
1028 $enableBack = false;
1029 $enableRoot = false;
1030 }
1032 $listhead ="";
1034 /* Check if we are in users home department */
1035 if(!count($deps) || $this->filter->base == get_base_from_people($ui->dn)){
1036 $enableHome = false;
1037 }
1039 /* Draw root button */
1040 if($enableRoot){
1041 $result["ROOT"]= image('images/lists/root.png', 'ROOT', _("Root"));
1042 }else{
1043 $result["ROOT"]= image('images/lists/root-grey.png', null, _("Root"));
1044 }
1046 /* Draw back button */
1047 if($enableBack){
1048 $result["BACK"]= image('images/lists/back.png', 'BACK', _("Go to preceding level"));
1049 }else{
1050 $result["BACK"]= image('images/lists/back-grey.png', null, _("Go to preceding level"));
1051 }
1053 /* Draw home button */
1054 /* Draw home button */
1055 if($enableHome){
1056 $result["HOME"]= image('images/lists/home.png', 'HOME', _("Go to current users level"));
1057 }else{
1058 $result["HOME"]= image('images/lists/home-grey.png', null, _("Go to current users level"));
1059 }
1062 /* Draw reload button, this button is enabled everytime */
1063 $result["RELOAD"]= image('images/lists/reload.png', 'REFRESH', _("Reload list"));
1065 return ($result);
1066 }
1069 function getAction()
1070 {
1071 // Do not do anything if this is not our PID, or there's even no PID available...
1072 if(!isset($_REQUEST['PID']) || $_REQUEST['PID'] != $this->pid) {
1073 return;
1074 }
1076 // Save position if set
1077 if (isset($_POST['position_'.$this->pid]) && is_numeric($_POST['position_'.$this->pid])) {
1078 $this->scrollPosition= $_POST['position_'.$this->pid];
1079 }
1081 $result= array("targets" => array(), "action" => "");
1083 // Filter GET with "act" attributes
1084 if (isset($_GET['act'])) {
1085 $key= validate($_GET['act']);
1086 $target= preg_replace('/^listing_[a-zA-Z_]+_([0-9]+)$/', '$1', $key);
1087 if (isset($this->entries[$target]['dn'])) {
1088 $result['action']= preg_replace('/^listing_([a-zA-Z_]+)_[0-9]+$/', '$1', $key);
1089 $result['targets'][]= $this->entries[$target]['dn'];
1090 }
1092 // Drop targets if empty
1093 if (count($result['targets']) == 0) {
1094 unset($result['targets']);
1095 }
1096 return $result;
1097 }
1099 // Get single selection (radio box)
1100 if($this->singleSelect && isset($_POST['listing_radio_selected'])){
1101 $entry = $_POST['listing_radio_selected'];
1102 $result['targets']= array($this->entries[$entry]['dn']);
1103 }
1105 // Filter POST with "listing_" attributes
1106 foreach ($_POST as $key => $prop) {
1108 // Capture selections
1109 if (preg_match('/^listing_selected_[0-9]+$/', $key)) {
1110 $target= preg_replace('/^listing_selected_([0-9]+)$/', '$1', $key);
1111 if (isset($this->entries[$target]['dn'])) {
1112 $result['targets'][]= $this->entries[$target]['dn'];
1113 }
1114 continue;
1115 }
1117 // Capture action with target - this is a one shot
1118 if (preg_match('/^listing_[a-zA-Z_]+_[0-9]+(|_x)$/', $key)) {
1119 $target= preg_replace('/^listing_[a-zA-Z_]+_([0-9]+)(|_x)$/', '$1', $key);
1120 if (isset($this->entries[$target]['dn'])) {
1121 $result['action']= preg_replace('/^listing_([a-zA-Z_]+)_[0-9]+(|_x)$/', '$1', $key);
1122 $result['targets']= array($this->entries[$target]['dn']);
1123 }
1124 break;
1125 }
1127 // Capture action without target
1128 if (preg_match('/^listing_[a-zA-Z_]+(|_x)$/', $key)) {
1129 $result['action']= preg_replace('/^listing_([a-zA-Z_]+)(|_x)$/', '$1', $key);
1130 continue;
1131 }
1132 }
1134 // Filter POST with "act" attributes -> posted from action menu
1135 if (isset($_POST['act']) && $_POST['act'] != '') {
1136 if (!preg_match('/^export.*$/', $_POST['act'])){
1137 $result['action']= validate($_POST['act']);
1138 }
1139 }
1141 // Drop targets if empty
1142 if (count($result['targets']) == 0) {
1143 unset($result['targets']);
1144 }
1145 return $result;
1146 }
1149 function renderActionMenu()
1150 {
1151 $result= "<input type='hidden' name='act' id='act' value=''><div style='display:none'><input type='submit' name='exec_act' id='exec_act' value=''></div>";
1153 // Don't send anything if the menu is not defined
1154 if (!isset($this->xmlData['actionmenu']['action'])){
1155 return $result;
1156 }
1158 // Array?
1159 if (isset($this->xmlData['actionmenu']['action']['type'])){
1160 $this->xmlData['actionmenu']['action']= array($this->xmlData['actionmenu']['action']);
1161 }
1163 // Load shortcut
1164 $actions= &$this->xmlData['actionmenu']['action'];
1165 $result.= "<ul class='level1' id='root'><li><a href='#'>"._("Actions")." ".image("images/lists/sort-down.png")."</a>";
1167 // Build ul/li list
1168 $result.= $this->recurseActions($actions);
1170 return "<div id='pulldown'>".$result."</li></ul></div>";
1171 }
1174 function recurseActions($actions)
1175 {
1176 global $class_mapping;
1177 static $level= 2;
1178 $result= "<ul class='level$level'>";
1179 $separator= "";
1181 foreach ($actions as $action) {
1183 // Skip the entry completely if there's no permission to execute it
1184 if (!$this->hasActionPermission($action, $this->filter->base)) {
1185 continue;
1186 }
1188 // Skip entry if there're missing dependencies
1189 if (isset($action['depends'])) {
1190 $deps= is_array($action['depends'])?$action['depends']:array($action['depends']);
1191 foreach($deps as $clazz) {
1192 if (!isset($class_mapping[$clazz])){
1193 continue 2;
1194 }
1195 }
1196 }
1198 // Fill image if set
1199 $img= "";
1200 if (isset($action['image'])){
1201 $img= image($action['image'])." ";
1202 }
1204 if ($action['type'] == "separator"){
1205 $separator= " style='border-top:1px solid #AAA' ";
1206 continue;
1207 }
1209 // Dive into subs
1210 if ($action['type'] == "sub" && isset($action['action'])) {
1211 $level++;
1212 if (isset($action['label'])){
1213 $result.= "<li$separator><a href='#'>$img"._($action['label'])." ".image('images/forward-arrow.png')."</a>";
1214 }
1216 // Ensure we've an array of actions, this enables sub menus with only one action.
1217 if(isset($action['action']['type'])){
1218 $action['action'] = array($action['action']);
1219 }
1221 $result.= $this->recurseActions($action['action'])."</li>";
1222 $level--;
1223 $separator= "";
1224 continue;
1225 }
1227 // Render entry elseways
1228 if (isset($action['label'])){
1229 $result.= "<li$separator><a href='#' onClick='\$(\"act\").value= \"".$action['name']."\";\$(\"exec_act\").click();'>$img"._($action['label'])."</a></li>";
1230 }
1232 // Check for special types
1233 switch ($action['type']) {
1234 case 'copypaste':
1235 $cut = !isset($action['cut']) || $action['cut'] != "false";
1236 $copy = !isset($action['copy']) || $action['copy'] != "false";
1237 $result.= $this->renderCopyPasteMenu($separator, $copy , $cut);
1238 break;
1240 case 'snapshot':
1241 $result.= $this->renderSnapshotMenu($separator);
1242 break;
1244 case 'exporter':
1245 $result.= $this->renderExporterMenu($separator);
1246 break;
1248 case 'daemon':
1249 $result.= $this->renderDaemonMenu($separator);
1250 break;
1251 }
1253 $separator= "";
1254 }
1256 $result.= "</ul>";
1257 return $result;
1258 }
1261 function hasActionPermission($action, $dn, $classes= null)
1262 {
1263 $ui= get_userinfo();
1265 if (isset($action['acl'])) {
1266 $acls= $action['acl'];
1267 if (!is_array($acls)) {
1268 $acls= array($acls);
1269 }
1271 // Every ACL has to pass
1272 foreach ($acls as $acl) {
1273 $module= $this->categories;
1274 $aclList= array();
1276 // Replace %acl if available
1277 if ($classes) {
1278 $otype= $this->getObjectType($this->objectTypes, $classes);
1279 $acl= str_replace('%acl', $otype['category']."/".$otype['class'], $acl);
1280 }
1282 // Split for category and plugins if needed
1283 // match for "[rw]" style entries
1284 if (preg_match('/^\[([rwcdm]+)\]$/', $acl, $match)){
1285 $aclList= array($match[1]);
1286 }
1288 // match for "users[rw]" style entries
1289 if (preg_match('/^([a-zA-Z0-9]+)\[([rwcdm]+)\]$/', $acl, $match)){
1290 $module= $match[1];
1291 $aclList= array($match[2]);
1292 }
1294 // match for "users/user[rw]" style entries
1295 if (preg_match('/^([a-zA-Z0-9]+\/[a-zA-Z0-9]+)\[([rwcdm]+)\]$/', $acl, $match)){
1296 $module= $match[1];
1297 $aclList= array($match[2]);
1298 }
1300 // match "users/user[userPassword:rw(,...)*]" style entries
1301 if (preg_match('/^([a-zA-Z0-9]+\/[a-zA-Z0-9]+)\[([a-zA-Z0-9]+:[rwcdm]+(,[a-zA-Z0-9]+:[rwcdm]+)*)\]$/', $acl, $match)){
1302 $module= $match[1];
1303 $aclList= explode(',', $match[2]);
1304 }
1306 // Walk thru prepared ACL by using $module
1307 foreach($aclList as $sAcl) {
1308 $checkAcl= "";
1310 // Category or detailed permission?
1311 if (strpos($module, '/') !== false) {
1312 if (preg_match('/([a-zA-Z0-9]+):([rwcdm]+)/', $sAcl, $m) ) {
1313 $checkAcl= $ui->get_permissions($dn, $module, $m[1]);
1314 $sAcl= $m[2];
1315 } else {
1316 $checkAcl= $ui->get_permissions($dn, $module, '0');
1317 }
1318 } else {
1319 $checkAcl= $ui->get_category_permissions($dn, $module);
1320 }
1322 // Split up remaining part of the acl and check if it we're
1323 // allowed to do something...
1324 $parts= str_split($sAcl);
1325 foreach ($parts as $part) {
1326 if (strpos($checkAcl, $part) === false){
1327 return false;
1328 }
1329 }
1331 }
1332 }
1333 }
1335 return true;
1336 }
1339 function refreshBasesList()
1340 {
1341 global $config;
1342 $ui= get_userinfo();
1344 // Do some array munching to get it user friendly
1345 $ids= $config->idepartments;
1346 $d= $ui->get_module_departments($this->categories);
1347 $k_ids= array_keys($ids);
1348 $deps= array_intersect($d,$k_ids);
1350 // Fill internal bases list
1351 $this->bases= array();
1352 foreach($k_ids as $department){
1353 $this->bases[$department] = $ids[$department];
1354 }
1356 // Populate base selector if already present
1357 if ($this->baseSelector && $this->baseMode) {
1358 $this->baseSelector->setBases($this->bases);
1359 $this->baseSelector->update(TRUE);
1360 }
1361 }
1364 function getDepartments()
1365 {
1366 $departments= array();
1367 $ui= get_userinfo();
1369 // Get list of supported department types
1370 $types = departmentManagement::get_support_departments();
1372 // Load departments allowed by ACL
1373 $validDepartments = $ui->get_module_departments($this->categories);
1375 // Build filter and look in the LDAP for possible sub departments
1376 // of current base
1377 $filter= "(&(objectClass=gosaDepartment)(|";
1378 $attrs= array("description", "objectClass");
1379 foreach($types as $name => $data){
1380 $filter.= "(objectClass=".$data['OC'].")";
1381 $attrs[]= $data['ATTR'];
1382 }
1383 $filter.= "))";
1384 $res= get_list($filter, $this->categories, $this->base, $attrs, GL_NONE);
1386 // Analyze list of departments
1387 foreach ($res as $department) {
1388 if (!in_array($department['dn'], $validDepartments)) {
1389 continue;
1390 }
1392 // Add the attribute where we use for sorting
1393 $oc= null;
1394 foreach(array_keys($types) as $type) {
1395 if (in_array($type, $department['objectClass'])) {
1396 $oc= $type;
1397 break;
1398 }
1399 }
1400 $department['sort-attribute']= $types[$oc]['ATTR'];
1402 // Move to the result list
1403 $departments[]= $department;
1404 }
1406 return $departments;
1407 }
1410 function renderCopyPasteMenu($separator, $copy= true, $cut= true)
1411 {
1412 // We can only provide information if we've got a copypaste handler
1413 // instance
1414 if(!(isset($this->copyPasteHandler) && is_object($this->copyPasteHandler))){
1415 return "";
1416 }
1418 // Presets
1419 $result= "";
1420 $read= $paste= false;
1421 $ui= get_userinfo();
1423 // Switch flags to on if there's at least one category which allows read/paste
1424 foreach($this->categories as $category){
1425 $read= $read || preg_match('/r/', $ui->get_category_permissions($this->base, $category));
1426 $paste= $paste || $ui->is_pasteable($this->base, $category) == 1;
1427 }
1430 // Draw entries that allow copy and cut
1431 if($read){
1433 // Copy entry
1434 if($copy){
1435 $result.= "<li$separator><a href='#' onClick='\$(\"act\").value= \"copy\";\$(\"exec_act\").click();'>".image('images/lists/copy.png')." "._("Copy")."</a></li>";
1436 $separator= "";
1437 }
1439 // Cut entry
1440 if($cut){
1441 $result.= "<li$separator><a href='#' onClick='\$(\"act\").value= \"cut\";\$(\"exec_act\").click();'>".image("images/lists/cut.png")." "._("Cut")."</a></li>";
1442 $separator= "";
1443 }
1444 }
1446 // Draw entries that allow pasting entries
1447 if($paste){
1448 if($this->copyPasteHandler->entries_queued()){
1449 $result.= "<li$separator><a href='#' onClick='\$(\"act\").value= \"paste\";\$(\"exec_act\").click();'>".image("images/lists/paste.png")." "._("Paste")."</a></li>";
1450 }else{
1451 $result.= "<li$separator><a href='#'>".image('images/lists/paste-grey.png')." "._("Paste")."</a></li>";
1452 }
1453 }
1455 return($result);
1456 }
1459 function renderCopyPasteActions($row, $dn, $category, $class, $copy= true, $cut= true)
1460 {
1461 // We can only provide information if we've got a copypaste handler
1462 // instance
1463 if(!(isset($this->copyPasteHandler) && is_object($this->copyPasteHandler))){
1464 return "";
1465 }
1467 // Presets
1468 $ui = get_userinfo();
1469 $result = "";
1471 // Render cut entries
1472 if($cut){
1473 if($ui->is_cutable($dn, $category, $class)){
1474 $result.= image('images/lists/cut.png', "listing_cut_$row", _("Cut this entry"));
1475 }else{
1476 $result.= image('images/empty.png');
1477 }
1478 }
1480 // Render copy entries
1481 if($copy){
1482 if($ui->is_copyable($dn, $category, $class)){
1483 $result.= image('images/lists/copy.png', "listing_copy_$row", _("Copy this entry"));
1484 }else{
1485 $result.= image('images/empty.png');
1486 }
1487 }
1489 return($result);
1490 }
1493 function renderSnapshotMenu($separator)
1494 {
1495 // We can only provide information if we've got a snapshot handler
1496 // instance
1497 if(!(isset($this->snapshotHandler) && is_object($this->snapshotHandler))){
1498 return "";
1499 }
1501 // Presets
1502 $result = "";
1503 $ui = get_userinfo();
1505 if($this->snapshotHandler->enabled() && $ui->allow_snapshot_restore($this->base, $this->categories)){
1507 // Check if there is something to restore
1508 $restore= false;
1509 foreach($this->snapshotHandler->getSnapshotBases() as $base){
1510 $restore= $restore || count($this->snapshotHandler->getDeletedSnapshots($base)) > 0;
1511 }
1513 // Draw icons according to the restore flag
1514 if($restore){
1515 $result.= "<li$separator><a href='#' onClick='\$(\"act\").value= \"restore\";\$(\"exec_act\").click();'>".image('images/lists/restore.png')." "._("Restore snapshots")."</a></li>";
1516 }else{
1517 $result.= "<li$separator><a href='#'>".image('images/lists/restore-grey.png')." "._("Restore snapshots")."</a></li>";
1518 }
1519 }
1521 return($result);
1522 }
1525 function renderExporterMenu($separator)
1526 {
1527 // Presets
1528 $result = "";
1530 // Draw entries
1531 $result.= "<li$separator><a href='#'>".image('images/lists/export.png')." "._("Export list")." ".image("images/forward-arrow.png")."</a><ul class='level3'>";
1533 // Export CVS as build in exporter
1534 foreach ($this->exporter as $action => $exporter) {
1535 $result.= "<li><a href='#' onClick='\$(\"act\").value= \"$action\";\$(\"exec_act\").click();'>".image($exporter['image'])." ".$exporter['label']."</a></li>";
1536 }
1538 // Finalize list
1539 $result.= "</ul></li>";
1541 return($result);
1542 }
1545 function renderSnapshotActions($row, $dn, $category, $class, $copy= true, $cut= true)
1546 {
1547 // We can only provide information if we've got a snapshot handler
1548 // instance
1549 if(!(isset($this->snapshotHandler) && is_object($this->snapshotHandler))){
1550 return "";
1551 }
1553 // Presets
1554 $result= "";
1555 $ui = get_userinfo();
1557 // Only act if enabled here
1558 if($this->snapshotHandler->enabled()){
1560 // Draw restore button
1561 if ($ui->allow_snapshot_restore($dn, $category)){
1563 // Do we have snapshots for this dn?
1564 if($this->snapshotHandler->hasSnapshots($dn)){
1565 $result.= image('images/lists/restore.png', "listing_restore_$row", _("Restore snapshot"));
1566 } else {
1567 $result.= image('images/lists/restore-grey.png');
1568 }
1569 }
1571 // Draw snapshot button
1572 if($ui->allow_snapshot_create($dn, $category)){
1573 $result.= image('images/snapshot.png', "listing_snapshot_$row", _("Create new snapshot for this object"));
1574 }else{
1575 $result.= image('images/empty.png');
1576 }
1577 }
1579 return($result);
1580 }
1583 function renderDaemonMenu($separator)
1584 {
1585 $result= "";
1587 // If there is a daemon registered, draw the menu entries
1588 if(class_available("DaemonEvent")){
1589 $events= DaemonEvent::get_event_types_by_category($this->categories);
1590 if(isset($events['BY_CLASS']) && count($events['BY_CLASS'])){
1591 foreach($events['BY_CLASS'] as $name => $event){
1592 $result.= "<li$separator><a href='#' onClick='\$(\"act\").value=\"$name\";\$(\"exec_act\").click();'>".$event['MenuImage']." ".$event['s_Menu_Name']."</a></li>";
1593 $separator= "";
1594 }
1595 }
1596 }
1598 return $result;
1599 }
1602 function getEntry($dn)
1603 {
1604 foreach ($this->entries as $entry) {
1605 if (isset($entry['dn']) && strcasecmp($dn, $entry['dn']) == 0){
1606 return $entry;
1607 }
1608 }
1609 return null;
1610 }
1613 function getEntries()
1614 {
1615 return $this->entries;
1616 }
1619 function getType($dn)
1620 {
1621 $dn = LDAP::fix($dn);
1622 if (isset($this->objectDnMapping[$dn])) {
1623 return $this->objectDnMapping[$dn];
1624 }
1625 return null;
1626 }
1628 }
1630 ?>