Code

Removed jpgraph | qpl license doesn't match our needs
[gosa.git] / gosa-core / include / class_listing.inc
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= "&nbsp;".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']."&amp;PID=".$this->pid."&amp;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>&nbsp;</a>$sorter</td>";
272                     } else {
273                         $this->header[$index]= "<td class='listheader' ".$this->colprops[$index].">&nbsp;</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.= "&nbsp;";
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%;'>&nbsp;</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'>&nbsp;</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'>&nbsp;</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('/&nbsp;/', '', $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%;'>&nbsp;</td>";
452                     continue;
453                 }
454                 if ($i != $this->numColumns-1) {
455                     $result.= "<td class='list1nohighlight' style='$emptyListStyle'>&nbsp;</td>";
456                 } else {
457                     $result.= "<td class='list1nohighlight' style='border-right:0;$emptyListStyle'>&nbsp;</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)."&nbsp;".$this->objectTypeCount[$objectType['label']]."&nbsp;&nbsp;";
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= get_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[get_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[get_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('/%{[^}]+}/', '&nbsp;', $data);
744         return $data;
748 function renderBase()
750     if (!$this->baseMode) {
751         return;
752     }
754     return $this->baseSelector->render();
758 function processElementFilter($data, $config, $row)
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;
838 function getObjectType($types, $classes)
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;
870 function filterObjectType($dn, $classes)
872     // Walk thru classes and return on first match
873     $result= "&nbsp;";
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;
889 function filterActions($dn, $row, $classes)
891     // Do nothing if there's no menu defined
892     if (!isset($this->xmlData['actiontriggers']['action'])) {
893         return "&nbsp;";
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;
983 function filterDepartmentLink($row, $dn, $description)
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']."&amp;PID=$this->pid&amp;act=department_$row' title='$dn'>".set_post($result)."</a>");
995 function filterLink()
997     $result= "&nbsp;";
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= "&nbsp;";
1015     $trans= call_user_func_array("sprintf", $params);
1016     if ($trans != "") {
1017         return("<a href='?plug=".$_GET['plug']."&amp;PID=$pid&amp;act=listing_edit_$row' title='$dn'>".set_post($trans)."</a>");
1018     }
1020     return $result;
1024 function renderNavigation()
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);
1078 function getAction()
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= get_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 = get_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         $prop = get_post($key);
1119         // Capture selections
1120         if (preg_match('/^listing_selected_[0-9]+$/', $key)) {
1121             $target= preg_replace('/^listing_selected_([0-9]+)$/', '$1', $key);
1122             if (isset($this->entries[$target]['dn'])) {
1123                 $result['targets'][]= $this->entries[$target]['dn'];
1124             }
1125             continue;
1126         }
1128         // Capture action with target - this is a one shot
1129         if (preg_match('/^listing_[a-zA-Z_]+_[0-9]+(|_x)$/', $key)) {
1130             $target= preg_replace('/^listing_[a-zA-Z_]+_([0-9]+)(|_x)$/', '$1', $key);
1131             if (isset($this->entries[$target]['dn'])) {
1132                 $result['action']= preg_replace('/^listing_([a-zA-Z_]+)_[0-9]+(|_x)$/', '$1', $key);
1133                 $result['targets']= array($this->entries[$target]['dn']);
1134             }
1135             break;
1136         }
1138         // Capture action without target
1139         if (preg_match('/^listing_[a-zA-Z_]+(|_x)$/', $key)) {
1140             $result['action']= preg_replace('/^listing_([a-zA-Z_]+)(|_x)$/', '$1', $key);
1141             continue;
1142         }
1143     }
1145     // Filter POST with "act" attributes -> posted from action menu
1146     if (isset($_POST['act']) && $_POST['act'] != '') {
1147         if (!preg_match('/^export.*$/', $_POST['act'])){
1148             $result['action']= get_post('act');
1149         }
1150     }
1152     // Drop targets if empty
1153     if (count($result['targets']) == 0) {
1154         unset($result['targets']);
1155     }
1156     return $result;
1160 function renderActionMenu()
1162     $result= "<input type='hidden' name='act' id='act' value=''><div style='display:none'><input type='submit' name='exec_act' id='exec_act' value=''></div>";
1164     // Don't send anything if the menu is not defined
1165     if (!isset($this->xmlData['actionmenu']['action'])){
1166         return $result;
1167     }
1169     // Array?
1170     if (isset($this->xmlData['actionmenu']['action']['type'])){
1171         $this->xmlData['actionmenu']['action']= array($this->xmlData['actionmenu']['action']);
1172     }
1174     // Load shortcut
1175     $actions= &$this->xmlData['actionmenu']['action'];
1176     $result.= "<ul class='level1' id='root'><li><a href='#'>"._("Actions")."&nbsp;".image("images/lists/sort-down.png")."</a>";
1178     // Build ul/li list
1179     $result.= $this->recurseActions($actions);
1181     return "<div id='pulldown'>".$result."</li></ul></div>";
1185 function recurseActions($actions)
1187     global $class_mapping;
1188     static $level= 2;
1189     $result= "<ul class='level$level'>";
1190     $separator= "";
1192     foreach ($actions as $action) {
1194         // Skip the entry completely if there's no permission to execute it
1195         if (!$this->hasActionPermission($action, $this->filter->base)) {
1196             continue;
1197         }
1199         // Skip entry if there're missing dependencies
1200         if (isset($action['depends'])) {
1201             $deps= is_array($action['depends'])?$action['depends']:array($action['depends']);
1202             foreach($deps as $clazz) {
1203                 if (!isset($class_mapping[$clazz])){
1204                     continue 2;
1205                 }
1206             }
1207         }
1209         // Fill image if set
1210         $img= "";
1211         if (isset($action['image'])){
1212             $img= image($action['image'])."&nbsp;";
1213         }
1215         if ($action['type'] == "separator"){
1216             $separator= " style='border-top:1px solid #AAA' ";
1217             continue;
1218         }
1220         // Dive into subs
1221         if ($action['type'] == "sub" && isset($action['action'])) {
1222             $level++;
1223             if (isset($action['label'])){
1224                 $result.= "<li$separator><a href='#'>$img"._($action['label'])."&nbsp;".image('images/forward-arrow.png')."</a>";
1225             }
1227             // Ensure we've an array of actions, this enables sub menus with only one action.
1228             if(isset($action['action']['type'])){
1229                 $action['action'] = array($action['action']);
1230             }
1232             $result.= $this->recurseActions($action['action'])."</li>";
1233             $level--;
1234             $separator= "";
1235             continue;
1236         }
1238         // Render entry elseways
1239         if (isset($action['label'])){
1240             $result.= "<li$separator><a href='#' onClick='\$(\"act\").value= \"".$action['name']."\";\$(\"exec_act\").click();'>$img"._($action['label'])."</a></li>";
1241         }
1243         // Check for special types
1244         switch ($action['type']) {
1245             case 'copypaste':
1246                 $cut = !isset($action['cut']) || $action['cut'] != "false";
1247                 $copy = !isset($action['copy']) || $action['copy'] != "false";
1248                 $result.= $this->renderCopyPasteMenu($separator, $copy , $cut);
1249                 break;
1251             case 'snapshot':
1252                 $result.= $this->renderSnapshotMenu($separator);
1253                 break;
1255             case 'exporter':
1256                 $result.= $this->renderExporterMenu($separator);
1257                 break;
1259             case 'daemon':
1260                 $result.= $this->renderDaemonMenu($separator);
1261                 break;
1262         }
1264         $separator= "";
1265     }
1267     $result.= "</ul>";
1268     return $result;
1272 function hasActionPermission($action, $dn, $classes= null)
1274     $ui= get_userinfo();
1276     if (isset($action['acl'])) {
1277         $acls= $action['acl'];
1278         if (!is_array($acls)) {
1279             $acls= array($acls);
1280         }
1282         // Every ACL has to pass
1283         foreach ($acls as $acl) {
1284             $module= $this->categories;
1285             $aclList= array();
1287             // Replace %acl if available
1288             if ($classes) {
1289                 $otype= $this->getObjectType($this->objectTypes, $classes);
1290                 $acl= str_replace('%acl', $otype['category']."/".$otype['class'], $acl);
1291             }
1293             // Split for category and plugins if needed
1294             // match for "[rw]" style entries
1295             if (preg_match('/^\[([rwcdm]+)\]$/', $acl, $match)){
1296                 $aclList= array($match[1]);
1297             }
1299             // match for "users[rw]" style entries
1300             if (preg_match('/^([a-zA-Z0-9]+)\[([rwcdm]+)\]$/', $acl, $match)){
1301                 $module= $match[1];
1302                 $aclList= array($match[2]);
1303             }
1305             // match for "users/user[rw]" style entries
1306             if (preg_match('/^([a-zA-Z0-9]+\/[a-zA-Z0-9]+)\[([rwcdm]+)\]$/', $acl, $match)){
1307                 $module= $match[1];
1308                 $aclList= array($match[2]);
1309             }
1311             // match "users/user[userPassword:rw(,...)*]" style entries
1312             if (preg_match('/^([a-zA-Z0-9]+\/[a-zA-Z0-9]+)\[([a-zA-Z0-9]+:[rwcdm]+(,[a-zA-Z0-9]+:[rwcdm]+)*)\]$/', $acl, $match)){
1313                 $module= $match[1];
1314                 $aclList= explode(',', $match[2]);
1315             }
1317             // Walk thru prepared ACL by using $module
1318             foreach($aclList as $sAcl) {
1319                 $checkAcl= "";
1321                 // Category or detailed permission?
1322                 if (strpos($module, '/') !== false) {
1323                     if (preg_match('/([a-zA-Z0-9]+):([rwcdm]+)/', $sAcl, $m) ) {
1324                         $checkAcl= $ui->get_permissions($dn, $module, $m[1]);
1325                         $sAcl= $m[2];
1326                     } else {
1327                         $checkAcl= $ui->get_permissions($dn, $module, '0');
1328                     }
1329                 } else {
1330                     $checkAcl= $ui->get_category_permissions($dn, $module);
1331                 }
1333                 // Split up remaining part of the acl and check if it we're
1334                 // allowed to do something...
1335                 $parts= str_split($sAcl);
1336                 foreach ($parts as $part) {
1337                     if (strpos($checkAcl, $part) === false){
1338                         return false;
1339                     }
1340                 }
1342             }
1343         }
1344     }
1346     return true;
1350 function refreshBasesList()
1352     global $config;
1353     $ui= get_userinfo();
1355     // Do some array munching to get it user friendly
1356     $ids= $config->idepartments;
1357     $d= $ui->get_module_departments($this->categories);
1358     $k_ids= array_keys($ids);
1359     $deps= array_intersect($d,$k_ids);
1361     // Fill internal bases list
1362     $this->bases= array();
1363     foreach($k_ids as $department){
1364         $this->bases[$department] = $ids[$department];
1365     }
1367     // Populate base selector if already present
1368     if ($this->baseSelector && $this->baseMode) {
1369         $this->baseSelector->setBases($this->bases);
1370         $this->baseSelector->update(TRUE);
1371     }
1375 function getDepartments()
1377     $departments= array();
1378     $ui= get_userinfo();
1380     // Get list of supported department types
1381     $types = departmentManagement::get_support_departments();
1383     // Load departments allowed by ACL
1384     $validDepartments = $ui->get_module_departments($this->categories);
1386     // Build filter and look in the LDAP for possible sub departments
1387     // of current base
1388     $filter= "(&(objectClass=gosaDepartment)(|";
1389     $attrs= array("description", "objectClass");
1390     foreach($types as $name => $data){
1391         $filter.= "(objectClass=".$data['OC'].")";
1392         $attrs[]= $data['ATTR'];
1393     }
1394     $filter.= "))";
1395     $res= get_list($filter, $this->categories, $this->base, $attrs, GL_NONE);
1397     // Analyze list of departments
1398     foreach ($res as $department) {
1399         if (!in_array($department['dn'], $validDepartments)) {
1400             continue;
1401         }
1403         // Add the attribute where we use for sorting
1404         $oc= null;
1405         foreach(array_keys($types) as $type) {
1406             if (in_array($type, $department['objectClass'])) {
1407                 $oc= $type;
1408                 break;
1409             }
1410         }
1411         $department['sort-attribute']= $types[$oc]['ATTR'];
1413         // Move to the result list
1414         $departments[]= $department;
1415     }
1417     return $departments;
1421 function renderCopyPasteMenu($separator, $copy= true, $cut= true)
1423     // We can only provide information if we've got a copypaste handler
1424     // instance
1425     if(!(isset($this->copyPasteHandler) && is_object($this->copyPasteHandler))){
1426         return "";
1427     }
1429     // Presets
1430     $result= "";
1431     $read= $paste= false;
1432     $ui= get_userinfo();
1434     // Switch flags to on if there's at least one category which allows read/paste
1435     foreach($this->categories as $category){
1436         $read= $read || preg_match('/r/', $ui->get_category_permissions($this->base, $category));
1437         $paste= $paste || $ui->is_pasteable($this->base, $category) == 1;
1438     }
1441     // Draw entries that allow copy and cut
1442     if($read){
1444         // Copy entry
1445         if($copy){
1446             $result.= "<li$separator><a href='#' onClick='\$(\"act\").value= \"copy\";\$(\"exec_act\").click();'>".image('images/lists/copy.png')."&nbsp;"._("Copy")."</a></li>";
1447             $separator= "";
1448         }
1450         // Cut entry
1451         if($cut){
1452             $result.= "<li$separator><a href='#' onClick='\$(\"act\").value= \"cut\";\$(\"exec_act\").click();'>".image("images/lists/cut.png")."&nbsp;"._("Cut")."</a></li>";
1453             $separator= "";
1454         }
1455     }
1457     // Draw entries that allow pasting entries
1458     if($paste){
1459         if($this->copyPasteHandler->entries_queued()){
1460             $result.= "<li$separator><a href='#' onClick='\$(\"act\").value= \"paste\";\$(\"exec_act\").click();'>".image("images/lists/paste.png")."&nbsp;"._("Paste")."</a></li>";
1461         }else{
1462             $result.= "<li$separator><a href='#'>".image('images/lists/paste-grey.png')."&nbsp;"._("Paste")."</a></li>";
1463         }
1464     }
1466     return($result);
1470 function renderCopyPasteActions($row, $dn, $category, $class, $copy= true, $cut= true)
1472     // We can only provide information if we've got a copypaste handler
1473     // instance
1474     if(!(isset($this->copyPasteHandler) && is_object($this->copyPasteHandler))){
1475         return "";
1476     }
1478     // Presets
1479     $ui = get_userinfo();
1480     $result = "";
1482     // Render cut entries
1483     if($cut){
1484         if($ui->is_cutable($dn, $category, $class)){
1485             $result.= image('images/lists/cut.png', "listing_cut_$row", _("Cut this entry"));
1486         }else{
1487             $result.= image('images/empty.png');
1488         }
1489     }
1491     // Render copy entries
1492     if($copy){
1493         if($ui->is_copyable($dn, $category, $class)){
1494             $result.= image('images/lists/copy.png', "listing_copy_$row", _("Copy this entry"));
1495         }else{
1496             $result.= image('images/empty.png');
1497         }
1498     }
1500     return($result);
1504 function renderSnapshotMenu($separator)
1506     // We can only provide information if we've got a snapshot handler
1507     // instance
1508     if(!(isset($this->snapshotHandler) && is_object($this->snapshotHandler))){
1509         return "";
1510     }
1512     // Presets
1513     $result = "";
1514     $ui = get_userinfo();
1516     if($this->snapshotHandler->enabled() && $ui->allow_snapshot_restore($this->base, $this->categories)){
1518         // Check if there is something to restore
1519         $restore= false;
1520         foreach($this->snapshotHandler->getSnapshotBases() as $base){
1521             $restore= $restore || count($this->snapshotHandler->getDeletedSnapshots($base)) > 0;
1522         }
1524         // Draw icons according to the restore flag
1525         if($restore){
1526             $result.= "<li$separator><a href='#' onClick='\$(\"act\").value= \"restore\";\$(\"exec_act\").click();'>".image('images/lists/restore.png')."&nbsp;"._("Restore snapshots")."</a></li>";
1527         }else{
1528             $result.= "<li$separator><a href='#'>".image('images/lists/restore-grey.png')."&nbsp;"._("Restore snapshots")."</a></li>";
1529         }
1530     }
1532     return($result);
1536 function renderExporterMenu($separator)
1538     // Presets
1539     $result = "";
1541     // Draw entries
1542     $result.= "<li$separator><a href='#'>".image('images/lists/export.png')."&nbsp;"._("Export list")."&nbsp;".image("images/forward-arrow.png")."</a><ul class='level3'>";
1544     // Export CVS as build in exporter
1545     foreach ($this->exporter as $action => $exporter) {
1546         $result.= "<li><a href='#' onClick='\$(\"act\").value= \"$action\";\$(\"exec_act\").click();'>".image($exporter['image'])."&nbsp;".$exporter['label']."</a></li>";
1547     }
1549     // Finalize list
1550     $result.= "</ul></li>";
1552     return($result);
1556 function renderSnapshotActions($row, $dn, $category, $class, $copy= true, $cut= true)
1558     // We can only provide information if we've got a snapshot handler
1559     // instance
1560     if(!(isset($this->snapshotHandler) && is_object($this->snapshotHandler))){
1561         return "";
1562     }
1564     // Presets
1565     $result= "";
1566     $ui = get_userinfo();
1568     // Only act if enabled here
1569     if($this->snapshotHandler->enabled()){
1571         // Draw restore button
1572         if ($ui->allow_snapshot_restore($dn, $category)){
1574             // Do we have snapshots for this dn?
1575             if($this->snapshotHandler->hasSnapshots($dn)){
1576                 $result.= image('images/lists/restore.png', "listing_restore_$row", _("Restore snapshot"));
1577             } else {
1578                 $result.= image('images/lists/restore-grey.png');
1579             }
1580         }
1582         // Draw snapshot button
1583         if($ui->allow_snapshot_create($dn, $category)){
1584             $result.= image('images/snapshot.png', "listing_snapshot_$row", _("Create new snapshot for this object"));
1585         }else{
1586             $result.= image('images/empty.png');
1587         }
1588     }
1590     return($result);
1594 function renderDaemonMenu($separator)
1596     $result= "";
1598     // If there is a daemon registered, draw the menu entries
1599     if(class_available("DaemonEvent")){
1600         $events= DaemonEvent::get_event_types_by_category($this->categories);
1601         if(isset($events['BY_CLASS']) && count($events['BY_CLASS'])){
1602             foreach($events['BY_CLASS'] as $name => $event){
1603                 $result.= "<li$separator><a href='#' onClick='\$(\"act\").value=\"$name\";\$(\"exec_act\").click();'>".$event['MenuImage']."&nbsp;".$event['s_Menu_Name']."</a></li>";
1604                 $separator= "";
1605             }
1606         }
1607     }
1609     return $result;
1613 function getEntry($dn)
1615     foreach ($this->entries as $entry) {
1616         if (isset($entry['dn']) && strcasecmp($dn, $entry['dn']) == 0){
1617             return $entry;
1618         }
1619     }
1620     return null;
1624 function getEntries()
1626     return $this->entries;
1630 function getType($dn)
1632     $dn = LDAP::fix($dn);
1633     if (isset($this->objectDnMapping[$dn])) {
1634         return $this->objectDnMapping[$dn];
1635     }
1636     return null;
1641 ?>