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($source, $isString = FALSE)
61 {
62 global $config;
63 global $class_mapping;
65 // Initialize pid
66 $this->pid= preg_replace("/[^0-9]/", "", microtime(TRUE));
68 if($isString){
69 if(!$this->loadString($source)){
70 die("Cannot parse $source!");
71 }
72 }else{
73 if (!$this->loadFile($source)) {
74 die("Cannot parse $source!");
75 }
76 }
78 // Set base for filter
79 if ($this->baseMode) {
80 $this->base= session::global_get("CurrentMainBase");
81 if ($this->base == null) {
82 $this->base= $config->current['BASE'];
83 }
84 $this->refreshBasesList();
85 } else {
86 $this->base= $config->current['BASE'];
87 }
89 // Move footer information
90 $this->showFooter= ($config->get_cfg_value("core","listSummary") == "true");
92 // Register build in filters
93 $this->registerElementFilter("objectType", "listing::filterObjectType");
94 $this->registerElementFilter("departmentLink", "listing::filterDepartmentLink");
95 $this->registerElementFilter("link", "listing::filterLink");
96 $this->registerElementFilter("actions", "listing::filterActions");
98 // Load exporters
99 foreach($class_mapping as $class => $dummy) {
100 if (preg_match('/Exporter$/', $class)) {
101 $info= call_user_func(array($class, "getInfo"));
102 if ($info != null) {
103 $this->exporter= array_merge($this->exporter, $info);
104 }
105 }
106 }
108 // Instanciate base selector
109 $this->baseSelector= new baseSelector($this->bases, $this->base);
110 }
113 function setCopyPasteHandler($handler)
114 {
115 $this->copyPasteHandler= &$handler;
116 }
119 function setHeight($height)
120 {
121 $this->height= $height;
122 }
125 function setSnapshotHandler($handler)
126 {
127 $this->snapshotHandler= &$handler;
128 }
131 function getFilter()
132 {
133 return($this->filter);
134 }
137 function setFilter($filter)
138 {
139 $this->filter= &$filter;
140 if ($this->departmentBrowser){
141 $this->departments= $this->getDepartments();
142 }
143 $this->filter->setBase($this->base);
144 }
147 function registerElementFilter($name, $call)
148 {
149 if (!isset($this->filters[$name])) {
150 $this->filters[$name]= $call;
151 return true;
152 }
154 return false;
155 }
157 function loadFile($filename)
158 {
159 return($this->loadString(file_get_contents($filename)));
160 }
162 function loadString($contents)
163 {
164 $this->xmlData= xml::xml2array($contents, 1);
166 if (!isset($this->xmlData['list'])) {
167 return false;
168 }
170 $this->xmlData= $this->xmlData["list"];
172 // Load some definition values
173 foreach (array("departmentBrowser", "departmentRootVisible", "multiSelect","singleSelect", "baseMode") as $token) {
174 if (isset($this->xmlData['definition'][$token]) &&
175 $this->xmlData['definition'][$token] == "true"){
176 $this->$token= true;
177 }
178 }
180 // Fill objectTypes from departments and xml definition
181 $types = departmentManagement::get_support_departments();
182 foreach ($types as $class => $data) {
183 $this->objectTypes[$data['OC']]= array("label" => $data['TITLE'],
184 "objectClass" => $data['OC'],
185 "image" => $data['IMG']);
186 }
187 $this->categories= array();
188 if (isset($this->xmlData['definition']['objectType'])) {
189 if(isset($this->xmlData['definition']['objectType']['label'])) {
190 $this->xmlData['definition']['objectType']= array($this->xmlData['definition']['objectType']);
191 }
192 foreach ($this->xmlData['definition']['objectType'] as $index => $otype) {
193 $tmp = $this->xmlData['definition']['objectType'][$index];
194 $this->objectTypes[$tmp['objectClass']]= $tmp;
195 if (isset($this->xmlData['definition']['objectType'][$index]['category'])){
196 $this->categories[]= $otype['category'];
197 }
198 }
199 }
200 $this->objectTypes = array_values($this->objectTypes);
202 // Parse layout per column
203 $this->colprops= $this->parseLayout($this->xmlData['table']['layout']);
205 // Prepare table headers
206 $this->renderHeader();
208 // Assign headline/Categories
209 $this->headline= _($this->xmlData['definition']['label']);
210 if (!is_array($this->categories)){
211 $this->categories= array($this->categories);
212 }
214 // Evaluate columns to be exported
215 if (isset($this->xmlData['table']['column'])){
216 foreach ($this->xmlData['table']['column'] as $index => $config) {
217 if (isset($config['export']) && $config['export'] == "true"){
218 $this->exportColumns[]= $index;
219 }
220 }
221 }
223 return true;
224 }
227 function renderHeader()
228 {
229 $this->header= array();
230 $this->plainHeader= array();
232 // Initialize sort?
233 $sortInit= false;
234 if (!$this->sortDirection) {
235 $this->sortColumn= 0;
236 if (isset($this->xmlData['definition']['defaultSortColumn'])){
237 $this->sortColumn= $this->xmlData['definition']['defaultSortColumn'];
238 } else {
239 $this->sortAttribute= "";
240 }
241 $this->sortDirection= array();
242 $sortInit= true;
243 }
245 if (isset($this->xmlData['table']['column'])){
246 foreach ($this->xmlData['table']['column'] as $index => $config) {
247 // Initialize everything to one direction
248 if ($sortInit) {
249 $this->sortDirection[$index]= false;
250 }
252 $sorter= "";
253 if ($index == $this->sortColumn && isset($config['sortAttribute']) &&
254 isset($config['sortType'])) {
255 $this->sortAttribute= $config['sortAttribute'];
256 $this->sortType= $config['sortType'];
257 $sorter= " ".image("images/lists/sort-".($this->sortDirection[$index]?"up":"down").".png", null, $this->sortDirection[$index]?_("Sort ascending"):_("Sort descending"), "text-top");
258 }
259 $sortable= (isset($config['sortAttribute']));
261 $link= "href='?plug=".$_GET['plug']."&PID=".$this->pid."&act=SORT_$index'";
262 if (isset($config['label'])) {
263 if ($sortable) {
264 $this->header[$index]= "<td class='listheader' ".$this->colprops[$index]."><a $link>"._($config['label'])."</a>$sorter</td>";
265 } else {
266 $this->header[$index]= "<td class='listheader' ".$this->colprops[$index].">"._($config['label'])."</td>";
267 }
268 $this->plainHeader[]= _($config['label']);
269 } else {
270 if ($sortable) {
271 $this->header[$index]= "<td class='listheader' ".$this->colprops[$index]."><a $link> </a>$sorter</td>";
272 } else {
273 $this->header[$index]= "<td class='listheader' ".$this->colprops[$index]."> </td>";
274 }
275 $this->plainHeader[]= "";
276 }
277 }
278 }
279 }
282 function render()
283 {
284 // Check for exeeded sizelimit
285 if (($message= check_sizelimit()) != ""){
286 return($message);
287 }
289 // Some browsers don't have the ability do do scrollable table bodies, filter them
290 // here.
291 $switch= false;
292 if (preg_match('/(Opera|Konqueror|Safari)/i', $_SERVER['HTTP_USER_AGENT'])){
293 $switch= true;
294 }
296 // Initialize list
297 $result= "<input type='hidden' value='$this->pid' name='PID'>\n";
298 $result.= "<input type='hidden' name='position_".$this->pid."' id='position_".$this->pid."'>\n";
299 $height= 450;
300 if ($this->height != 0) {
301 $result.= "<input type='hidden' value='$this->height' id='d_height'>\n";
302 $height= $this->height;
303 }
305 $result.= "<div class='listContainer' id='d_scrollbody' style='min-height:".($height+25)."px;'>\n";
306 $result.= "<table summary='$this->headline' style='width:100%;table-layout:fixed' cellspacing='0' cellpadding='0' id='t_scrolltable'>\n";
307 $this->numColumns= count($this->colprops) + (($this->multiSelect|$this->singleSelect)?1:0);
309 // Build list header
310 $result.= "<thead class='fixedListHeader listHeaderFormat'><tr>\n";
311 if ($this->multiSelect || $this->singleSelect) {
312 $width= "24px";
313 if (preg_match('/Konqueror/i', $_SERVER['HTTP_USER_AGENT'])){
314 $width= "28px";
315 }
316 $result.= "<td class='listheader' style='text-align:center;padding:0;width:$width;'>";
317 if($this->multiSelect){
318 $result.= "<input type='checkbox' id='select_all' name='select_all'
319 title='"._("Select all")."' onClick='toggle_all_(\"listing_selected_[0-9]*$\",\"select_all\");' >";
320 }else{
321 $result.= " ";
322 }
323 $result.="</td>\n";
324 }
325 foreach ($this->header as $header) {
326 $result.= $header;
327 }
328 $result.= "</tr></thead>\n";
330 // Build list body
331 $result.= "<tbody class='listScrollContent listBodyFormat' id='t_nscrollbody' style='height:".$height."px;'>\n";
333 // No results? Just take an empty colspanned row
334 if (count($this->entries) + count($this->departments) == 0) {
335 $result.= "<tr><td class='list1nohighlight' colspan='$this->numColumns' style='height:100%;border-right:0px;width:100%;'> </td></tr>";
336 }
338 // Line color alternation
339 $alt= 0;
340 $deps= 0;
342 // Draw department browser if configured and we're not in sub mode
343 $this->useSpan= false;
344 if ($this->departmentBrowser && $this->filter->scope != "sub") {
345 // Fill with department browser if configured this way
346 $departmentIterator= new departmentSortIterator($this->departments, $this->sortDirection[$this->sortColumn]);
347 foreach ($departmentIterator as $row => $entry){
348 $rowResult= "<tr>";
350 // Render multi select if needed
351 if ($this->multiSelect || $this->singleSelect) {
352 $rowResult.="<td style='text-align:center;padding:0;' class='list1'> </td>";
353 }
355 // Render defined department columns, fill the rest with some stuff
356 $rest= $this->numColumns - 1;
357 foreach ($this->xmlData['table']['department'] as $index => $config) {
358 $colspan= 1;
359 if (isset($config['span'])){
360 $colspan= $config['span'];
361 $this->useSpan= true;
362 }
363 $rowResult.="<td colspan='$colspan' ".$this->colprops[$index]." class='list1'>".$this->renderCell($config['value'], $entry, $row)."</td>";
364 $rest-= $colspan;
365 }
367 // Fill remaining cols with nothing
368 $last= $this->numColumns - $rest;
369 for ($i= 0; $i<$rest; $i++){
370 $rowResult.= "<td ".$this->colprops[$last+$i-1]." class='list1'> </td>";
371 }
372 $rowResult.="</tr>";
374 // Apply label to objecttype icon?
375 if (preg_match("/<objectType:([^:]+):(.*)\/>/i", $rowResult, $matches)){
376 $objectType= image($matches[1], null, LDAP::fix(base64_decode($matches[2])));
377 $rowResult= preg_replace("/<objectType[^>]+>/", $objectType, $rowResult);
378 }
379 $result.= $rowResult;
380 $alt++;
381 }
384 $deps= $alt;
385 }
387 // Fill with contents, sort as configured
388 foreach ($this->entries as $row => $entry) {
389 $trow= "";
391 // Render multi select if needed
392 if ($this->multiSelect) {
393 $trow.="<td style='text-align:center;width:20px;' class='list0'><input type='checkbox' id='listing_selected_$row' name='listing_selected_$row'></td>\n";
394 }
396 if ($this->singleSelect) {
397 $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";
398 }
400 foreach ($this->xmlData['table']['column'] as $index => $config) {
401 $renderedCell= $this->renderCell($config['value'], $entry, $row);
402 $trow.="<td ".$this->colprops[$index]." class='list0'>".$renderedCell."</td>\n";
404 // Save rendered column
405 $sort= preg_replace('/.*>([^<]+)<.*$/', '$1', $renderedCell);
406 $sort= preg_replace('/ /', '', $sort);
407 if (preg_match('/</', $sort)){
408 $sort= "";
409 }
410 $this->entries[$row]["_sort$index"]= $sort;
411 }
413 // Save rendered entry
414 $this->entries[$row]['_rendered']= $trow;
415 }
417 // Complete list by sorting entries for _sort$index and appending them to the output
418 $entryIterator= new listingSortIterator($this->entries, $this->sortDirection[$this->sortColumn], "_sort".$this->sortColumn, $this->sortType);
419 foreach ($entryIterator as $row => $entry){
421 // Apply label to objecttype icon?
422 if (preg_match("/<objectType:([^:]+):(.*)\/>/i", $entry['_rendered'], $matches)){
423 if (preg_match("/<rowLabel:([a-z0-9_-]*)\/>/i", $entry['_rendered'], $m)) {
424 $objectType= image($matches[1]."[".$m[1]."]", null, LDAP::fix(base64_decode($matches[2])));
425 } else {
426 $objectType= image($matches[1], null, LDAP::fix(base64_decode($matches[2])));
427 }
428 $entry['_rendered']= preg_replace("/<objectType[^>]+>/", $objectType, $entry['_rendered']);
429 $entry['_rendered']= preg_replace("/<rowLabel[^>]+>/", '', $entry['_rendered']);
430 }
432 // Apply custom class to row?
433 if (preg_match("/<rowClass:([a-z0-9_-]*)\/>/i", $entry['_rendered'], $matches)) {
434 $result.="<tr class='".$matches[1]."'>\n";
435 $result.= preg_replace("/<rowClass[^>]+>/", '', $entry['_rendered']);
436 } else {
437 $result.="<tr>\n";
438 $result.= $entry['_rendered'];
439 }
441 $result.="</tr>\n";
442 $alt++;
443 }
445 // Need to fill the list if it's not full (nobody knows why this is 22 ;-))
446 $emptyListStyle= (count($this->entries) + (($this->useSpan && count($this->entries))?$deps:0) == 0)?"border:0;":"";
447 if ((count($this->entries) + $deps) < 22) {
448 $result.= "<tr>";
449 for ($i= 0; $i<$this->numColumns; $i++) {
450 if ($i == 0) {
451 $result.= "<td class='list1nohighlight' style='$emptyListStyle height:100%;'> </td>";
452 continue;
453 }
454 if ($i != $this->numColumns-1) {
455 $result.= "<td class='list1nohighlight' style='$emptyListStyle'> </td>";
456 } else {
457 $result.= "<td class='list1nohighlight' style='border-right:0;$emptyListStyle'> </td>";
458 }
459 }
461 $result.= "</tr>";
462 }
464 // Close list body
465 $result.= "</tbody></table></div>";
467 // Add the footer if requested
468 if ($this->showFooter) {
469 $result.= "<div class='nlistFooter'><div style='padding:3px'>";
471 foreach ($this->objectTypes as $objectType) {
472 if (isset($this->objectTypeCount[$objectType['label']])) {
473 $label= _($objectType['label']);
474 $result.= image($objectType['image'], null, $label)." ".$this->objectTypeCount[$objectType['label']]." ";
475 }
476 }
478 $result.= "</div></div>";
479 }
481 // Close list
482 $result.= $switch?"<input type='hidden' id='list_workaround'>":"";
484 // Add scroll positioner
485 $result.= '<script type="text/javascript" language="javascript">';
486 $result.= '$("t_nscrollbody").scrollTop= '.$this->scrollPosition.';';
487 $result.= 'var box = $("t_nscrollbody").onscroll= function() {$("position_'.$this->pid.'").value= this.scrollTop;}';
488 $result.= '</script>';
490 $smarty= get_smarty();
492 $smarty->assign("FILTER", $this->filter->render());
493 $smarty->assign("SIZELIMIT", print_sizelimit_warning());
494 $smarty->assign("LIST", $result);
496 // Assign navigation elements
497 $nav= $this->renderNavigation();
498 foreach ($nav as $key => $html) {
499 $smarty->assign($key, $html);
500 }
502 // Assign action menu / base
503 $smarty->assign("HEADLINE", $this->headline);
504 $smarty->assign("ACTIONS", $this->renderActionMenu());
505 $smarty->assign("BASE", $this->renderBase());
507 // Assign separator
508 $smarty->assign("SEPARATOR", "<img src='images/lists/seperator.png' alt='-' align='middle' height='16' width='1' class='center'>");
510 // Assign summary
511 $smarty->assign("HEADLINE", $this->headline);
513 // Try to load template from plugin the folder first...
514 $file = get_template_path($this->xmlData['definition']['template'], true);
516 // ... if this fails, try to load the file from the theme folder.
517 if(!file_exists($file)){
518 $file = get_template_path($this->xmlData['definition']['template']);
519 }
521 return ($smarty->fetch($file));
522 }
525 function update()
526 {
527 global $config;
528 $ui= get_userinfo();
530 // Take care of base selector
531 if ($this->baseMode) {
532 $this->baseSelector->update();
534 // Check if a wrong base was supplied
535 if(!$this->baseSelector->checkLastBaseUpdate()){
536 msg_dialog::display(_("Error"), msgPool::check_base(), ERROR_DIALOG);
537 }
538 }
540 // Save base
541 $refresh= false;
542 if ($this->baseMode) {
543 $this->base= $this->baseSelector->getBase();
544 session::global_set("CurrentMainBase", $this->base);
545 $refresh= true;
546 }
549 // Reset object counter / DN mapping
550 $this->objectTypeCount= array();
551 $this->objectDnMapping= array();
553 // Do not do anything if this is not our PID
554 if($refresh || !(isset($_REQUEST['PID']) && $_REQUEST['PID'] != $this->pid)) {
556 // Save position if set
557 if (isset($_POST['position_'.$this->pid]) && is_numeric($_POST['position_'.$this->pid])) {
558 $this->scrollPosition= $_POST['position_'.$this->pid];
559 }
561 // Override the base if we got a message from the browser navigation
562 if ($this->departmentBrowser && isset($_GET['act'])) {
563 if (preg_match('/^department_([0-9]+)$/', validate($_GET['act']), $match)){
564 if (isset($this->departments[$match[1]])){
565 $this->base= $this->departments[$match[1]]['dn'];
566 if ($this->baseMode) {
567 $this->baseSelector->setBase($this->base);
568 }
569 session::global_set("CurrentMainBase", $this->base);
570 }
571 }
572 }
574 // Filter POST with "act" attributes -> posted from action menu
575 if (isset($_POST['exec_act']) && $_POST['act'] != '') {
576 if (preg_match('/^export.*$/', $_POST['act']) && isset($this->exporter[$_POST['act']])) {
577 $exporter= $this->exporter[$_POST['act']];
578 $userinfo= ", "._("created by")." ".$ui->cn." - ".strftime('%A, %d. %B %Y, %H:%M:%S');
579 $entryIterator= new listingSortIterator($this->entries, $this->sortDirection[$this->sortColumn], "_sort".$this->sortColumn, $this->sortType);
580 $sortedEntries= array();
581 foreach ($entryIterator as $entry){
582 $sortedEntries[]= $entry;
583 }
584 $instance= new $exporter['class']($this->headline.$userinfo, $this->plainHeader, $sortedEntries, $this->exportColumns);
585 $type= call_user_func(array($exporter['class'], "getInfo"));
586 $type= $type[$_POST['act']];
587 send_binary_content($instance->query(), $type['filename'], $type= $type['mime']);
588 }
589 }
591 // Filter GET with "act" attributes
592 if (isset($_GET['act'])) {
593 $key= validate($_GET['act']);
594 if (preg_match('/^SORT_([0-9]+)$/', $key, $match)) {
595 // Switch to new column or invert search order?
596 $column= $match[1];
597 if ($this->sortColumn != $column) {
598 $this->sortColumn= $column;
599 } else {
600 $this->sortDirection[$column]= !$this->sortDirection[$column];
601 }
603 // Allow header to update itself according to the new sort settings
604 $this->renderHeader();
605 }
606 }
608 // Override base if we got signals from the navigation elements
609 $action= "";
610 foreach ($_POST as $key => $value) {
611 if (preg_match('/^(ROOT|BACK|HOME)(_x)?$/', $key, $match)) {
612 $action= $match[1];
613 break;
614 }
615 }
617 // Navigation handling
618 if ($action == 'ROOT') {
619 $deps= $ui->get_module_departments($this->categories);
620 $this->base= $deps[0];
621 $this->baseSelector->setBase($this->base);
622 session::global_set("CurrentMainBase", $this->base);
623 }
624 if ($action == 'BACK') {
625 $deps= $ui->get_module_departments($this->categories);
626 $base= preg_replace("/^[^,]+,/", "", $this->base);
627 if(in_array_ics($base, $deps)){
628 $this->base= $base;
629 $this->baseSelector->setBase($this->base);
630 session::global_set("CurrentMainBase", $this->base);
631 }
632 }
633 if ($action == 'HOME') {
634 $ui= get_userinfo();
635 $this->base= get_base_from_people($ui->dn);
636 $this->baseSelector->setBase($this->base);
637 session::global_set("CurrentMainBase", $this->base);
638 }
639 }
641 // Reload departments
642 if ($this->departmentBrowser){
643 $this->departments= $this->getDepartments();
644 }
646 // Update filter and refresh entries
647 $this->filter->setBase($this->base);
648 $this->entries= $this->filter->query();
650 // Fix filter if querie returns NULL
651 if ($this->entries == null) {
652 $this->entries= array();
653 }
654 }
657 function setBase($base)
658 {
659 $this->base= $base;
660 if ($this->baseMode) {
661 $this->baseSelector->setBase($this->base);
662 }
663 }
666 function getBase()
667 {
668 return $this->base;
669 }
672 function parseLayout($layout)
673 {
674 $result= array();
675 $layout= preg_replace("/^\|/", "", $layout);
676 $layout= preg_replace("/\|$/", "", $layout);
677 $cols= explode("|", $layout);
679 foreach ($cols as $index => $config) {
680 if ($config != "") {
681 $res= "";
682 $components= explode(';', $config);
683 foreach ($components as $part) {
684 if (preg_match("/^r$/", $part)) {
685 $res.= "text-align:right;";
686 continue;
687 }
688 if (preg_match("/^l$/", $part)) {
689 $res.= "text-align:left;";
690 continue;
691 }
692 if (preg_match("/^c$/", $part)) {
693 $res.= "text-align:center;";
694 continue;
695 }
696 if (preg_match("/^[0-9]+(|px|%)$/", $part)) {
697 $res.= "width:$part;min-width:$part;";
698 continue;
699 }
700 }
702 // Add minimum width for scalable columns
703 if (!preg_match('/width:/', $res)){
704 $res.= "min-width:200px;";
705 }
707 $result[$index]= " style='$res'";
708 } else {
709 $result[$index]= " style='min-width:100px;'";
710 }
711 }
713 // Save number of columns for later use
714 $this->numColumns= count($cols);
716 // Add no border to the last column
717 $result[$this->numColumns-1]= preg_replace("/'$/", "border-right:0;'", $result[$this->numColumns-1]);
719 return $result;
720 }
723 function renderCell($data, $config, $row)
724 {
725 // Replace flat attributes in data string
726 for ($i= 0; $i<$config['count']; $i++) {
727 $attr= $config[$i];
728 $value= "";
729 if (is_array($config[$attr])) {
730 $value= $config[$attr][0];
731 } else {
732 $value= $config[$attr];
733 }
734 $data= preg_replace("/%\{$attr\}/", $value, $data);
735 }
737 // Watch out for filters and prepare to execute them
738 $data= $this->processElementFilter($data, $config, $row);
740 // Replace all non replaced %{...} instances because they
741 // are non resolved attributes or filters
742 $data= preg_replace('/%{[^}]+}/', ' ', $data);
744 return $data;
745 }
748 function renderBase()
749 {
750 if (!$this->baseMode) {
751 return;
752 }
754 return $this->baseSelector->render();
755 }
758 function processElementFilter($data, $config, $row)
759 {
760 preg_match_all("/%\{filter:([^(]+)\((.*)\)\}/", $data, $matches, PREG_SET_ORDER);
762 foreach ($matches as $match) {
763 $cl= "";
764 $method= "";
765 if (preg_match('/::/', $match[1])) {
766 $cl= preg_replace('/::.*$/', '', $match[1]);
767 $method= preg_replace('/^.*::/', '', $match[1]);
768 } else {
769 if (!isset($this->filters[$match[1]])) {
770 continue;
771 }
772 $cl= preg_replace('/::.*$/', '', $this->filters[$match[1]]);
773 $method= preg_replace('/^.*::/', '', $this->filters[$match[1]]);
774 }
776 // Prepare params for function call
777 $params= array();
778 preg_match_all('/"[^"]+"|[^,]+/', $match[2], $parts);
779 foreach ($parts[0] as $param) {
781 // Row is replaced by the row number
782 if ($param == "row") {
783 $params[]= $row;
784 continue;
785 }
787 // pid is replaced by the current PID
788 if ($param == "pid") {
789 $params[]= $this->pid;
790 continue;
791 }
793 // base is replaced by the current base
794 if ($param == "base") {
795 $params[]= $this->getBase();
796 continue;
797 }
799 // Fixie with "" is passed directly
800 if (preg_match('/^".*"$/', $param)){
801 $params[]= preg_replace('/"/', '', $param);
802 continue;
803 }
805 // Move dn if needed
806 if ($param == "dn") {
807 $params[]= LDAP::fix($config["dn"]);
808 continue;
809 }
811 // LDAP variables get replaced by their objects
812 for ($i= 0; $i<$config['count']; $i++) {
813 if ($param == $config[$i]) {
814 $values= $config[$config[$i]];
815 if (is_array($values)){
816 unset($values['count']);
817 }
818 $params[]= $values;
819 break;
820 }
821 }
822 }
824 // Replace information
825 if ($cl == "listing") {
826 // Non static call - seems to result in errors
827 $data= @preg_replace('/'.preg_quote($match[0]).'/', call_user_func_array(array($this, "$method"), $params), $data);
828 } else {
829 // Static call
830 $data= preg_replace('/'.preg_quote($match[0]).'/', call_user_func_array(array($cl, $method), $params), $data);
831 }
832 }
834 return $data;
835 }
838 function getObjectType($types, $classes)
839 {
840 // Walk thru types and see if there's something matching
841 foreach ($types as $objectType) {
842 $ocs= $objectType['objectClass'];
843 if (!is_array($ocs)){
844 $ocs= array($ocs);
845 }
847 $found= true;
848 foreach ($ocs as $oc){
849 if (preg_match('/^!(.*)$/', $oc, $match)) {
850 $oc= $match[1];
851 if (in_array($oc, $classes)) {
852 $found= false;
853 }
854 } else {
855 if (!in_array($oc, $classes)) {
856 $found= false;
857 }
858 }
859 }
861 if ($found) {
862 return $objectType;
863 }
864 }
866 return null;
867 }
870 function filterObjectType($dn, $classes)
871 {
872 // Walk thru classes and return on first match
873 $result= " ";
875 $objectType= $this->getObjectType($this->objectTypes, $classes);
876 if ($objectType) {
877 $this->objectDnMapping[$dn]= $objectType["objectClass"];
878 $result= "<objectType:".$objectType["image"].":".base64_encode(LDAP::fix($dn))."/>";
879 if (!isset($this->objectTypeCount[$objectType['label']])) {
880 $this->objectTypeCount[$objectType['label']]= 0;
881 }
882 $this->objectTypeCount[$objectType['label']]++;
883 }
885 return $result;
886 }
889 function filterActions($dn, $row, $classes)
890 {
891 // Do nothing if there's no menu defined
892 if (!isset($this->xmlData['actiontriggers']['action'])) {
893 return " ";
894 }
896 // Go thru all actions
897 $result= "";
898 $actions= $this->xmlData['actiontriggers']['action'];
900 // Ensure we've a valid actions array, if there is only one action in the actiontriggers col
901 // then we've to create a valid array here.
902 if(isset($actions['name'])) $actions = array($actions);
904 foreach($actions as $action) {
905 // Skip the entry completely if there's no permission to execute it
906 if (!$this->hasActionPermission($action, $dn, $classes)) {
907 $result.= image('images/empty.png');
908 continue;
909 }
911 // Skip entry if the pseudo filter does not fit
912 if (isset($action['filter']) && preg_match('/^[a-z0-9_]+!?=[a-z0-9_]+$/i', $action['filter'])) {
913 list($fa, $fv)= explode('=', $action['filter']);
914 if (preg_match('/^(.*)!$/', $fa, $m)){
915 $fa= $m[1];
916 if (isset($this->entries[$row][$fa]) && $this->entries[$row][$fa][0] == $fv) {
917 $result.= image('images/empty.png');
918 continue;
919 }
920 } else {
921 if (!isset($this->entries[$row][$fa]) && !$this->entries[$row][$fa][0] == $fv) {
922 $result.= image('images/empty.png');
923 continue;
924 }
925 }
926 }
929 // If there's an objectclass definition and we don't have it
930 // add an empty picture here.
931 if (isset($action['objectclass'])){
932 $objectclass= $action['objectclass'];
933 if (preg_match('/^!(.*)$/', $objectclass, $m)){
934 $objectclass= $m[1];
935 if(in_array($objectclass, $classes)) {
936 $result.= image('images/empty.png');
937 continue;
938 }
939 } elseif (is_string($objectclass)) {
940 if(!in_array($objectclass, $classes)) {
941 $result.= image('images/empty.png');
942 continue;
943 }
944 } elseif (is_array($objectclass)) {
945 if(count(array_intersect($objectclass, $classes)) != count($objectclass)){
946 $result.= image('images/empty.png');
947 continue;
948 }
949 }
950 }
952 // Render normal entries as usual
953 if ($action['type'] == "entry") {
954 $label= $this->processElementFilter($action['label'], $this->entries[$row], $row);
955 $image= $this->processElementFilter($action['image'], $this->entries[$row], $row);
956 $result.= image($image, "listing_".$action['name']."_$row", $label);
957 }
959 // Handle special types
960 if ($action['type'] == "copypaste" || $action['type'] == "snapshot") {
962 $objectType= $this->getObjectType($this->objectTypes, $this->entries[$row]['objectClass']);
963 $category= $class= null;
964 if ($objectType) {
965 $category= $objectType['category'];
966 $class= $objectType['class'];
967 }
969 if ($action['type'] == "copypaste") {
970 $copy = !isset($action['copy']) || $action['copy'] == "true";
971 $cut = !isset($action['cut']) || $action['cut'] == "true";
972 $result.= $this->renderCopyPasteActions($row, $this->entries[$row]['dn'], $category, $class,$copy,$cut);
973 } else {
974 $result.= $this->renderSnapshotActions($row, $this->entries[$row]['dn'], $category, $class);
975 }
976 }
977 }
979 return $result;
980 }
983 function filterDepartmentLink($row, $dn, $description)
984 {
985 $attr= $this->departments[$row]['sort-attribute'];
986 $name= $this->departments[$row][$attr];
987 if (is_array($name)){
988 $name= $name[0];
989 }
990 $result= sprintf("%s [%s]", $name, $description[0]);
991 return("<a href='?plug=".$_GET['plug']."&PID=$this->pid&act=department_$row' title='$dn'>$result</a>");
992 }
995 function filterLink()
996 {
997 $result= " ";
999 $row= func_get_arg(0);
1000 $pid= $this->pid;
1001 $dn= LDAP::fix(func_get_arg(1));
1002 $params= array(func_get_arg(2));
1004 // Collect sprintf params
1005 for ($i = 3;$i < func_num_args();$i++) {
1006 $val= func_get_arg($i);
1007 if (is_array($val)){
1008 $params[]= $val[0];
1009 continue;
1010 }
1011 $params[]= $val;
1012 }
1014 $result= " ";
1015 $trans= call_user_func_array("sprintf", $params);
1016 if ($trans != "") {
1017 return("<a href='?plug=".$_GET['plug']."&PID=$pid&act=listing_edit_$row' title='$dn'>$trans</a>");
1018 }
1020 return $result;
1021 }
1024 function renderNavigation()
1025 {
1026 $result= array();
1027 $enableBack = true;
1028 $enableRoot = true;
1029 $enableHome = true;
1031 $ui = get_userinfo();
1033 /* Check if base = first available base */
1034 $deps = $ui->get_module_departments($this->categories);
1036 if(!count($deps) || $deps[0] == $this->filter->base){
1037 $enableBack = false;
1038 $enableRoot = false;
1039 }
1041 $listhead ="";
1043 /* Check if we are in users home department */
1044 if(!count($deps) || $this->filter->base == get_base_from_people($ui->dn)){
1045 $enableHome = false;
1046 }
1048 /* Draw root button */
1049 if($enableRoot){
1050 $result["ROOT"]= image('images/lists/root.png', 'ROOT', _("Root"));
1051 }else{
1052 $result["ROOT"]= image('images/lists/root-grey.png', null, _("Root"));
1053 }
1055 /* Draw back button */
1056 if($enableBack){
1057 $result["BACK"]= image('images/lists/back.png', 'BACK', _("Go to preceding level"));
1058 }else{
1059 $result["BACK"]= image('images/lists/back-grey.png', null, _("Go to preceding level"));
1060 }
1062 /* Draw home button */
1063 /* Draw home button */
1064 if($enableHome){
1065 $result["HOME"]= image('images/lists/home.png', 'HOME', _("Go to current users level"));
1066 }else{
1067 $result["HOME"]= image('images/lists/home-grey.png', null, _("Go to current users level"));
1068 }
1071 /* Draw reload button, this button is enabled everytime */
1072 $result["RELOAD"]= image('images/lists/reload.png', 'REFRESH', _("Reload list"));
1074 return ($result);
1075 }
1078 function getAction()
1079 {
1080 // Do not do anything if this is not our PID, or there's even no PID available...
1081 if(!isset($_REQUEST['PID']) || $_REQUEST['PID'] != $this->pid) {
1082 return;
1083 }
1085 // Save position if set
1086 if (isset($_POST['position_'.$this->pid]) && is_numeric($_POST['position_'.$this->pid])) {
1087 $this->scrollPosition= $_POST['position_'.$this->pid];
1088 }
1090 $result= array("targets" => array(), "action" => "");
1092 // Filter GET with "act" attributes
1093 if (isset($_GET['act'])) {
1094 $key= validate($_GET['act']);
1095 $target= preg_replace('/^listing_[a-zA-Z_]+_([0-9]+)$/', '$1', $key);
1096 if (isset($this->entries[$target]['dn'])) {
1097 $result['action']= preg_replace('/^listing_([a-zA-Z_]+)_[0-9]+$/', '$1', $key);
1098 $result['targets'][]= $this->entries[$target]['dn'];
1099 }
1101 // Drop targets if empty
1102 if (count($result['targets']) == 0) {
1103 unset($result['targets']);
1104 }
1105 return $result;
1106 }
1108 // Get single selection (radio box)
1109 if($this->singleSelect && isset($_POST['listing_radio_selected'])){
1110 $entry = $_POST['listing_radio_selected'];
1111 $result['targets']= array($this->entries[$entry]['dn']);
1112 }
1114 // Filter POST with "listing_" attributes
1115 foreach ($_POST as $key => $prop) {
1117 // Capture selections
1118 if (preg_match('/^listing_selected_[0-9]+$/', $key)) {
1119 $target= preg_replace('/^listing_selected_([0-9]+)$/', '$1', $key);
1120 if (isset($this->entries[$target]['dn'])) {
1121 $result['targets'][]= $this->entries[$target]['dn'];
1122 }
1123 continue;
1124 }
1126 // Capture action with target - this is a one shot
1127 if (preg_match('/^listing_[a-zA-Z_]+_[0-9]+(|_x)$/', $key)) {
1128 $target= preg_replace('/^listing_[a-zA-Z_]+_([0-9]+)(|_x)$/', '$1', $key);
1129 if (isset($this->entries[$target]['dn'])) {
1130 $result['action']= preg_replace('/^listing_([a-zA-Z_]+)_[0-9]+(|_x)$/', '$1', $key);
1131 $result['targets']= array($this->entries[$target]['dn']);
1132 }
1133 break;
1134 }
1136 // Capture action without target
1137 if (preg_match('/^listing_[a-zA-Z_]+(|_x)$/', $key)) {
1138 $result['action']= preg_replace('/^listing_([a-zA-Z_]+)(|_x)$/', '$1', $key);
1139 continue;
1140 }
1141 }
1143 // Filter POST with "act" attributes -> posted from action menu
1144 if (isset($_POST['act']) && $_POST['act'] != '') {
1145 if (!preg_match('/^export.*$/', $_POST['act'])){
1146 $result['action']= validate($_POST['act']);
1147 }
1148 }
1150 // Drop targets if empty
1151 if (count($result['targets']) == 0) {
1152 unset($result['targets']);
1153 }
1154 return $result;
1155 }
1158 function renderActionMenu()
1159 {
1160 $result= "<input type='hidden' name='act' id='act' value=''><div style='display:none'><input type='submit' name='exec_act' id='exec_act' value=''></div>";
1162 // Don't send anything if the menu is not defined
1163 if (!isset($this->xmlData['actionmenu']['action'])){
1164 return $result;
1165 }
1167 // Array?
1168 if (isset($this->xmlData['actionmenu']['action']['type'])){
1169 $this->xmlData['actionmenu']['action']= array($this->xmlData['actionmenu']['action']);
1170 }
1172 // Load shortcut
1173 $actions= &$this->xmlData['actionmenu']['action'];
1174 $result.= "<ul class='level1' id='root'><li><a href='#'>"._("Actions")." ".image("images/lists/sort-down.png")."</a>";
1176 // Build ul/li list
1177 $result.= $this->recurseActions($actions);
1179 return "<div id='pulldown'>".$result."</li></ul></div>";
1180 }
1183 function recurseActions($actions)
1184 {
1185 global $class_mapping;
1186 static $level= 2;
1187 $result= "<ul class='level$level'>";
1188 $separator= "";
1190 foreach ($actions as $action) {
1192 // Skip the entry completely if there's no permission to execute it
1193 if (!$this->hasActionPermission($action, $this->filter->base)) {
1194 continue;
1195 }
1197 // Skip entry if there're missing dependencies
1198 if (isset($action['depends'])) {
1199 $deps= is_array($action['depends'])?$action['depends']:array($action['depends']);
1200 foreach($deps as $clazz) {
1201 if (!isset($class_mapping[$clazz])){
1202 continue 2;
1203 }
1204 }
1205 }
1207 // Fill image if set
1208 $img= "";
1209 if (isset($action['image'])){
1210 $img= image($action['image'])." ";
1211 }
1213 if ($action['type'] == "separator"){
1214 $separator= " style='border-top:1px solid #AAA' ";
1215 continue;
1216 }
1218 // Dive into subs
1219 if ($action['type'] == "sub" && isset($action['action'])) {
1220 $level++;
1221 if (isset($action['label'])){
1222 $result.= "<li$separator><a href='#'>$img"._($action['label'])." ".image('images/forward-arrow.png')."</a>";
1223 }
1225 // Ensure we've an array of actions, this enables sub menus with only one action.
1226 if(isset($action['action']['type'])){
1227 $action['action'] = array($action['action']);
1228 }
1230 $result.= $this->recurseActions($action['action'])."</li>";
1231 $level--;
1232 $separator= "";
1233 continue;
1234 }
1236 // Render entry elseways
1237 if (isset($action['label'])){
1238 $result.= "<li$separator><a href='#' onClick='\$(\"act\").value= \"".$action['name']."\";\$(\"exec_act\").click();'>$img"._($action['label'])."</a></li>";
1239 }
1241 // Check for special types
1242 switch ($action['type']) {
1243 case 'copypaste':
1244 $cut = !isset($action['cut']) || $action['cut'] != "false";
1245 $copy = !isset($action['copy']) || $action['copy'] != "false";
1246 $result.= $this->renderCopyPasteMenu($separator, $copy , $cut);
1247 break;
1249 case 'snapshot':
1250 $result.= $this->renderSnapshotMenu($separator);
1251 break;
1253 case 'exporter':
1254 $result.= $this->renderExporterMenu($separator);
1255 break;
1257 case 'daemon':
1258 $result.= $this->renderDaemonMenu($separator);
1259 break;
1260 }
1262 $separator= "";
1263 }
1265 $result.= "</ul>";
1266 return $result;
1267 }
1270 function hasActionPermission($action, $dn, $classes= null)
1271 {
1272 $ui= get_userinfo();
1274 if (isset($action['acl'])) {
1275 $acls= $action['acl'];
1276 if (!is_array($acls)) {
1277 $acls= array($acls);
1278 }
1280 // Every ACL has to pass
1281 foreach ($acls as $acl) {
1282 $module= $this->categories;
1283 $aclList= array();
1285 // Replace %acl if available
1286 if ($classes) {
1287 $otype= $this->getObjectType($this->objectTypes, $classes);
1288 $acl= str_replace('%acl', $otype['category']."/".$otype['class'], $acl);
1289 }
1291 // Split for category and plugins if needed
1292 // match for "[rw]" style entries
1293 if (preg_match('/^\[([rwcdm]+)\]$/', $acl, $match)){
1294 $aclList= array($match[1]);
1295 }
1297 // match for "users[rw]" style entries
1298 if (preg_match('/^([a-zA-Z0-9]+)\[([rwcdm]+)\]$/', $acl, $match)){
1299 $module= $match[1];
1300 $aclList= array($match[2]);
1301 }
1303 // match for "users/user[rw]" style entries
1304 if (preg_match('/^([a-zA-Z0-9]+\/[a-zA-Z0-9]+)\[([rwcdm]+)\]$/', $acl, $match)){
1305 $module= $match[1];
1306 $aclList= array($match[2]);
1307 }
1309 // match "users/user[userPassword:rw(,...)*]" style entries
1310 if (preg_match('/^([a-zA-Z0-9]+\/[a-zA-Z0-9]+)\[([a-zA-Z0-9]+:[rwcdm]+(,[a-zA-Z0-9]+:[rwcdm]+)*)\]$/', $acl, $match)){
1311 $module= $match[1];
1312 $aclList= explode(',', $match[2]);
1313 }
1315 // Walk thru prepared ACL by using $module
1316 foreach($aclList as $sAcl) {
1317 $checkAcl= "";
1319 // Category or detailed permission?
1320 if (strpos($module, '/') !== false) {
1321 if (preg_match('/([a-zA-Z0-9]+):([rwcdm]+)/', $sAcl, $m) ) {
1322 $checkAcl= $ui->get_permissions($dn, $module, $m[1]);
1323 $sAcl= $m[2];
1324 } else {
1325 $checkAcl= $ui->get_permissions($dn, $module, '0');
1326 }
1327 } else {
1328 $checkAcl= $ui->get_category_permissions($dn, $module);
1329 }
1331 // Split up remaining part of the acl and check if it we're
1332 // allowed to do something...
1333 $parts= str_split($sAcl);
1334 foreach ($parts as $part) {
1335 if (strpos($checkAcl, $part) === false){
1336 return false;
1337 }
1338 }
1340 }
1341 }
1342 }
1344 return true;
1345 }
1348 function refreshBasesList()
1349 {
1350 global $config;
1351 $ui= get_userinfo();
1353 // Do some array munching to get it user friendly
1354 $ids= $config->idepartments;
1355 $d= $ui->get_module_departments($this->categories);
1356 $k_ids= array_keys($ids);
1357 $deps= array_intersect($d,$k_ids);
1359 // Fill internal bases list
1360 $this->bases= array();
1361 foreach($k_ids as $department){
1362 $this->bases[$department] = $ids[$department];
1363 }
1365 // Populate base selector if already present
1366 if ($this->baseSelector && $this->baseMode) {
1367 $this->baseSelector->setBases($this->bases);
1368 $this->baseSelector->update(TRUE);
1369 }
1370 }
1373 function getDepartments()
1374 {
1375 $departments= array();
1376 $ui= get_userinfo();
1378 // Get list of supported department types
1379 $types = departmentManagement::get_support_departments();
1381 // Load departments allowed by ACL
1382 $validDepartments = $ui->get_module_departments($this->categories);
1384 // Build filter and look in the LDAP for possible sub departments
1385 // of current base
1386 $filter= "(&(objectClass=gosaDepartment)(|";
1387 $attrs= array("description", "objectClass");
1388 foreach($types as $name => $data){
1389 $filter.= "(objectClass=".$data['OC'].")";
1390 $attrs[]= $data['ATTR'];
1391 }
1392 $filter.= "))";
1393 $res= get_list($filter, $this->categories, $this->base, $attrs, GL_NONE);
1395 // Analyze list of departments
1396 foreach ($res as $department) {
1397 if (!in_array($department['dn'], $validDepartments)) {
1398 continue;
1399 }
1401 // Add the attribute where we use for sorting
1402 $oc= null;
1403 foreach(array_keys($types) as $type) {
1404 if (in_array($type, $department['objectClass'])) {
1405 $oc= $type;
1406 break;
1407 }
1408 }
1409 $department['sort-attribute']= $types[$oc]['ATTR'];
1411 // Move to the result list
1412 $departments[]= $department;
1413 }
1415 return $departments;
1416 }
1419 function renderCopyPasteMenu($separator, $copy= true, $cut= true)
1420 {
1421 // We can only provide information if we've got a copypaste handler
1422 // instance
1423 if(!(isset($this->copyPasteHandler) && is_object($this->copyPasteHandler))){
1424 return "";
1425 }
1427 // Presets
1428 $result= "";
1429 $read= $paste= false;
1430 $ui= get_userinfo();
1432 // Switch flags to on if there's at least one category which allows read/paste
1433 foreach($this->categories as $category){
1434 $read= $read || preg_match('/r/', $ui->get_category_permissions($this->base, $category));
1435 $paste= $paste || $ui->is_pasteable($this->base, $category) == 1;
1436 }
1439 // Draw entries that allow copy and cut
1440 if($read){
1442 // Copy entry
1443 if($copy){
1444 $result.= "<li$separator><a href='#' onClick='\$(\"act\").value= \"copy\";\$(\"exec_act\").click();'>".image('images/lists/copy.png')." "._("Copy")."</a></li>";
1445 $separator= "";
1446 }
1448 // Cut entry
1449 if($cut){
1450 $result.= "<li$separator><a href='#' onClick='\$(\"act\").value= \"cut\";\$(\"exec_act\").click();'>".image("images/lists/cut.png")." "._("Cut")."</a></li>";
1451 $separator= "";
1452 }
1453 }
1455 // Draw entries that allow pasting entries
1456 if($paste){
1457 if($this->copyPasteHandler->entries_queued()){
1458 $result.= "<li$separator><a href='#' onClick='\$(\"act\").value= \"paste\";\$(\"exec_act\").click();'>".image("images/lists/paste.png")." "._("Paste")."</a></li>";
1459 }else{
1460 $result.= "<li$separator><a href='#'>".image('images/lists/paste-grey.png')." "._("Paste")."</a></li>";
1461 }
1462 }
1464 return($result);
1465 }
1468 function renderCopyPasteActions($row, $dn, $category, $class, $copy= true, $cut= true)
1469 {
1470 // We can only provide information if we've got a copypaste handler
1471 // instance
1472 if(!(isset($this->copyPasteHandler) && is_object($this->copyPasteHandler))){
1473 return "";
1474 }
1476 // Presets
1477 $ui = get_userinfo();
1478 $result = "";
1480 // Render cut entries
1481 if($cut){
1482 if($ui->is_cutable($dn, $category, $class)){
1483 $result.= image('images/lists/cut.png', "listing_cut_$row", _("Cut this entry"));
1484 }else{
1485 $result.= image('images/empty.png');
1486 }
1487 }
1489 // Render copy entries
1490 if($copy){
1491 if($ui->is_copyable($dn, $category, $class)){
1492 $result.= image('images/lists/copy.png', "listing_copy_$row", _("Copy this entry"));
1493 }else{
1494 $result.= image('images/empty.png');
1495 }
1496 }
1498 return($result);
1499 }
1502 function renderSnapshotMenu($separator)
1503 {
1504 // We can only provide information if we've got a snapshot handler
1505 // instance
1506 if(!(isset($this->snapshotHandler) && is_object($this->snapshotHandler))){
1507 return "";
1508 }
1510 // Presets
1511 $result = "";
1512 $ui = get_userinfo();
1514 if($this->snapshotHandler->enabled() && $ui->allow_snapshot_restore($this->base, $this->categories)){
1516 // Check if there is something to restore
1517 $restore= false;
1518 foreach($this->snapshotHandler->getSnapshotBases() as $base){
1519 $restore= $restore || count($this->snapshotHandler->getDeletedSnapshots($base)) > 0;
1520 }
1522 // Draw icons according to the restore flag
1523 if($restore){
1524 $result.= "<li$separator><a href='#' onClick='\$(\"act\").value= \"restore\";\$(\"exec_act\").click();'>".image('images/lists/restore.png')." "._("Restore snapshots")."</a></li>";
1525 }else{
1526 $result.= "<li$separator><a href='#'>".image('images/lists/restore-grey.png')." "._("Restore snapshots")."</a></li>";
1527 }
1528 }
1530 return($result);
1531 }
1534 function renderExporterMenu($separator)
1535 {
1536 // Presets
1537 $result = "";
1539 // Draw entries
1540 $result.= "<li$separator><a href='#'>".image('images/lists/export.png')." "._("Export list")." ".image("images/forward-arrow.png")."</a><ul class='level3'>";
1542 // Export CVS as build in exporter
1543 foreach ($this->exporter as $action => $exporter) {
1544 $result.= "<li><a href='#' onClick='\$(\"act\").value= \"$action\";\$(\"exec_act\").click();'>".image($exporter['image'])." ".$exporter['label']."</a></li>";
1545 }
1547 // Finalize list
1548 $result.= "</ul></li>";
1550 return($result);
1551 }
1554 function renderSnapshotActions($row, $dn, $category, $class, $copy= true, $cut= true)
1555 {
1556 // We can only provide information if we've got a snapshot handler
1557 // instance
1558 if(!(isset($this->snapshotHandler) && is_object($this->snapshotHandler))){
1559 return "";
1560 }
1562 // Presets
1563 $result= "";
1564 $ui = get_userinfo();
1566 // Only act if enabled here
1567 if($this->snapshotHandler->enabled()){
1569 // Draw restore button
1570 if ($ui->allow_snapshot_restore($dn, $category)){
1572 // Do we have snapshots for this dn?
1573 if($this->snapshotHandler->hasSnapshots($dn)){
1574 $result.= image('images/lists/restore.png', "listing_restore_$row", _("Restore snapshot"));
1575 } else {
1576 $result.= image('images/lists/restore-grey.png');
1577 }
1578 }
1580 // Draw snapshot button
1581 if($ui->allow_snapshot_create($dn, $category)){
1582 $result.= image('images/snapshot.png', "listing_snapshot_$row", _("Create new snapshot for this object"));
1583 }else{
1584 $result.= image('images/empty.png');
1585 }
1586 }
1588 return($result);
1589 }
1592 function renderDaemonMenu($separator)
1593 {
1594 $result= "";
1596 // If there is a daemon registered, draw the menu entries
1597 if(class_available("DaemonEvent")){
1598 $events= DaemonEvent::get_event_types_by_category($this->categories);
1599 if(isset($events['BY_CLASS']) && count($events['BY_CLASS'])){
1600 foreach($events['BY_CLASS'] as $name => $event){
1601 $result.= "<li$separator><a href='#' onClick='\$(\"act\").value=\"$name\";\$(\"exec_act\").click();'>".$event['MenuImage']." ".$event['s_Menu_Name']."</a></li>";
1602 $separator= "";
1603 }
1604 }
1605 }
1607 return $result;
1608 }
1611 function getEntry($dn)
1612 {
1613 foreach ($this->entries as $entry) {
1614 if (isset($entry['dn']) && strcasecmp($dn, $entry['dn']) == 0){
1615 return $entry;
1616 }
1617 }
1618 return null;
1619 }
1622 function getEntries()
1623 {
1624 return $this->entries;
1625 }
1628 function getType($dn)
1629 {
1630 $dn = LDAP::fix($dn);
1631 if (isset($this->objectDnMapping[$dn])) {
1632 return $this->objectDnMapping[$dn];
1633 }
1634 return null;
1635 }
1637 }
1639 ?>