Code

Applied in_array strict patches from trunk
[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_strict($oc, $classes)) {
852                     $found= false;
853                 }
854             } else {
855                 if (!in_array_strict($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_strict($objectclass, $classes)) {
936                     $result.= image('images/empty.png');
937                     continue;
938                 }
939             } elseif (is_string($objectclass)) {
940                 if(!in_array_strict($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;
1002     // Prepare title attribute
1003     $titleAttr = func_get_arg(1);
1004     if(is_array($titleAttr) && isset($titleAttr[0])){
1005         $titleAttr = $titleAttr[0];
1006     }
1007     $titleAttr = LDAP::fix($titleAttr);
1009     $params= array(func_get_arg(2));
1011     // Collect sprintf params
1012     for ($i = 3;$i < func_num_args();$i++) {
1013         $val= func_get_arg($i);
1014         if (is_array($val)){
1015             $params[]= $val[0];
1016             continue;
1017         }
1018         $params[]= $val;
1019     }
1021     $result= "&nbsp;";
1022     $trans= call_user_func_array("sprintf", $params);
1023     if ($trans != "") {
1024         return("<a href='?plug=".$_GET['plug']."&amp;PID=$pid&amp;act=listing_edit_$row' title='{$titleAttr}'>".set_post($trans)."</a>");
1025     }
1027     return $result;
1031 function renderNavigation()
1033     $result= array();
1034     $enableBack = true;
1035     $enableRoot = true;
1036     $enableHome = true;
1038     $ui = get_userinfo();
1040     /* Check if base = first available base */
1041     $deps = $ui->get_module_departments($this->categories);
1043     if(!count($deps) || $deps[0] == $this->filter->base){
1044         $enableBack = false;
1045         $enableRoot = false;
1046     }
1048     $listhead ="";
1050     /* Check if we are in users home  department */
1051     if(!count($deps) || $this->filter->base == get_base_from_people($ui->dn)){
1052         $enableHome = false;
1053     }
1055     /* Draw root button */
1056     if($enableRoot){
1057         $result["ROOT"]= image('images/lists/root.png', 'ROOT', _("Root"));
1058     }else{
1059         $result["ROOT"]= image('images/lists/root-grey.png', null, _("Root"));
1060     }
1062     /* Draw back button */
1063     if($enableBack){
1064         $result["BACK"]= image('images/lists/back.png', 'BACK', _("Go to preceding level"));
1065     }else{
1066         $result["BACK"]= image('images/lists/back-grey.png', null, _("Go to preceding level"));
1067     }
1069     /* Draw home button */
1070     /* Draw home button */
1071     if($enableHome){
1072         $result["HOME"]= image('images/lists/home.png', 'HOME', _("Go to current users level"));
1073     }else{
1074         $result["HOME"]= image('images/lists/home-grey.png', null, _("Go to current users level"));
1075     }
1078     /* Draw reload button, this button is enabled everytime */
1079     $result["RELOAD"]= image('images/lists/reload.png', 'REFRESH', _("Reload list"));
1081     return ($result);
1085 function getAction()
1087     // Do not do anything if this is not our PID, or there's even no PID available...
1088     if(!isset($_REQUEST['PID']) || $_REQUEST['PID'] != $this->pid) {
1089         return;
1090     }
1092     // Save position if set
1093     if (isset($_POST['position_'.$this->pid]) && is_numeric($_POST['position_'.$this->pid])) {
1094         $this->scrollPosition= get_post('position_'.$this->pid);
1095     }
1097     $result= array("targets" => array(), "action" => "");
1099     // Filter GET with "act" attributes
1100     if (isset($_GET['act'])) {
1101         $key= validate($_GET['act']);
1102         $target= preg_replace('/^listing_[a-zA-Z_]+_([0-9]+)$/', '$1', $key);
1103         if (isset($this->entries[$target]['dn'])) {
1104             $result['action']= preg_replace('/^listing_([a-zA-Z_]+)_[0-9]+$/', '$1', $key);
1105             $result['targets'][]= $this->entries[$target]['dn'];
1106         }
1108         // Drop targets if empty
1109         if (count($result['targets']) == 0) {
1110             unset($result['targets']);
1111         }
1112         return $result;
1113     }
1115     // Get single selection (radio box)
1116     if($this->singleSelect && isset($_POST['listing_radio_selected'])){
1117         $entry = get_post('listing_radio_selected');
1118         $result['targets']= array($this->entries[$entry]['dn']);
1119     }
1121     // Filter POST with "listing_" attributes
1122     foreach ($_POST as $key => $prop) {
1124         $prop = get_post($key);
1126         // Capture selections
1127         if (preg_match('/^listing_selected_[0-9]+$/', $key)) {
1128             $target= preg_replace('/^listing_selected_([0-9]+)$/', '$1', $key);
1129             if (isset($this->entries[$target]['dn'])) {
1130                 $result['targets'][]= $this->entries[$target]['dn'];
1131             }
1132             continue;
1133         }
1135         // Capture action with target - this is a one shot
1136         if (preg_match('/^listing_[a-zA-Z_]+_[0-9]+(|_x)$/', $key)) {
1137             $target= preg_replace('/^listing_[a-zA-Z_]+_([0-9]+)(|_x)$/', '$1', $key);
1138             if (isset($this->entries[$target]['dn'])) {
1139                 $result['action']= preg_replace('/^listing_([a-zA-Z_]+)_[0-9]+(|_x)$/', '$1', $key);
1140                 $result['targets']= array($this->entries[$target]['dn']);
1141             }
1142             break;
1143         }
1145         // Capture action without target
1146         if (preg_match('/^listing_[a-zA-Z_]+(|_x)$/', $key)) {
1147             $result['action']= preg_replace('/^listing_([a-zA-Z_]+)(|_x)$/', '$1', $key);
1148             continue;
1149         }
1150     }
1152     // Filter POST with "act" attributes -> posted from action menu
1153     if (isset($_POST['act']) && $_POST['act'] != '') {
1154         if (!preg_match('/^export.*$/', $_POST['act'])){
1155             $result['action']= get_post('act');
1156         }
1157     }
1159     // Drop targets if empty
1160     if (count($result['targets']) == 0) {
1161         unset($result['targets']);
1162     }
1163     return $result;
1167 function renderActionMenu()
1169     $result= "<input type='hidden' name='act' id='act' value=''><div style='display:none'><input type='submit' name='exec_act' id='exec_act' value=''></div>";
1171     // Don't send anything if the menu is not defined
1172     if (!isset($this->xmlData['actionmenu']['action'])){
1173         return $result;
1174     }
1176     // Array?
1177     if (isset($this->xmlData['actionmenu']['action']['type'])){
1178         $this->xmlData['actionmenu']['action']= array($this->xmlData['actionmenu']['action']);
1179     }
1181     // Load shortcut
1182     $actions= &$this->xmlData['actionmenu']['action'];
1183     $result.= "<ul class='level1' id='root'><li><a href='#'>"._("Actions")."&nbsp;".image("images/lists/sort-down.png")."</a>";
1185     // Build ul/li list
1186     $result.= $this->recurseActions($actions);
1188     return "<div id='pulldown'>".$result."</li></ul></div>";
1192 function recurseActions($actions)
1194     global $class_mapping;
1195     static $level= 2;
1196     $result= "<ul class='level$level'>";
1197     $separator= "";
1199     foreach ($actions as $action) {
1201         // Skip the entry completely if there's no permission to execute it
1202         if (!$this->hasActionPermission($action, $this->filter->base)) {
1203             continue;
1204         }
1206         // Skip entry if there're missing dependencies
1207         if (isset($action['depends'])) {
1208             $deps= is_array($action['depends'])?$action['depends']:array($action['depends']);
1209             foreach($deps as $clazz) {
1210                 if (!isset($class_mapping[$clazz])){
1211                     continue 2;
1212                 }
1213             }
1214         }
1216         // Fill image if set
1217         $img= "";
1218         if (isset($action['image'])){
1219             $img= image($action['image'])."&nbsp;";
1220         }
1222         if ($action['type'] == "separator"){
1223             $separator= " style='border-top:1px solid #AAA' ";
1224             continue;
1225         }
1227         // Dive into subs
1228         if ($action['type'] == "sub" && isset($action['action'])) {
1229             $level++;
1230             if (isset($action['label'])){
1231                 $result.= "<li$separator><a href='#'>$img"._($action['label'])."&nbsp;".image('images/forward-arrow.png')."</a>";
1232             }
1234             // Ensure we've an array of actions, this enables sub menus with only one action.
1235             if(isset($action['action']['type'])){
1236                 $action['action'] = array($action['action']);
1237             }
1239             $result.= $this->recurseActions($action['action'])."</li>";
1240             $level--;
1241             $separator= "";
1242             continue;
1243         }
1245         // Render entry elseways
1246         if (isset($action['label'])){
1247             $result.= "<li$separator><a href='#' onClick='\$(\"act\").value= \"".$action['name']."\";\$(\"exec_act\").click();'>$img"._($action['label'])."</a></li>";
1248         }
1250         // Check for special types
1251         switch ($action['type']) {
1252             case 'copypaste':
1253                 $cut = !isset($action['cut']) || $action['cut'] != "false";
1254                 $copy = !isset($action['copy']) || $action['copy'] != "false";
1255                 $result.= $this->renderCopyPasteMenu($separator, $copy , $cut);
1256                 break;
1258             case 'snapshot':
1259                 $result.= $this->renderSnapshotMenu($separator);
1260                 break;
1262             case 'exporter':
1263                 $result.= $this->renderExporterMenu($separator);
1264                 break;
1266             case 'daemon':
1267                 $result.= $this->renderDaemonMenu($separator);
1268                 break;
1269         }
1271         $separator= "";
1272     }
1274     $result.= "</ul>";
1275     return $result;
1279 function hasActionPermission($action, $dn, $classes= null)
1281     $ui= get_userinfo();
1283     if (isset($action['acl'])) {
1284         $acls= $action['acl'];
1285         if (!is_array($acls)) {
1286             $acls= array($acls);
1287         }
1289         // Every ACL has to pass
1290         foreach ($acls as $acl) {
1291             $module= $this->categories;
1292             $aclList= array();
1294             // Replace %acl if available
1295             if ($classes) {
1296                 $otype= $this->getObjectType($this->objectTypes, $classes);
1297                 $acl= str_replace('%acl', $otype['category']."/".$otype['class'], $acl);
1298             }
1300             // Split for category and plugins if needed
1301             // match for "[rw]" style entries
1302             if (preg_match('/^\[([rwcdm]+)\]$/', $acl, $match)){
1303                 $aclList= array($match[1]);
1304             }
1306             // match for "users[rw]" style entries
1307             if (preg_match('/^([a-zA-Z0-9]+)\[([rwcdm]+)\]$/', $acl, $match)){
1308                 $module= $match[1];
1309                 $aclList= array($match[2]);
1310             }
1312             // match for "users/user[rw]" style entries
1313             if (preg_match('/^([a-zA-Z0-9]+\/[a-zA-Z0-9]+)\[([rwcdm]+)\]$/', $acl, $match)){
1314                 $module= $match[1];
1315                 $aclList= array($match[2]);
1316             }
1318             // match "users/user[userPassword:rw(,...)*]" style entries
1319             if (preg_match('/^([a-zA-Z0-9]+\/[a-zA-Z0-9]+)\[([a-zA-Z0-9]+:[rwcdm]+(,[a-zA-Z0-9]+:[rwcdm]+)*)\]$/', $acl, $match)){
1320                 $module= $match[1];
1321                 $aclList= explode(',', $match[2]);
1322             }
1324             // Walk thru prepared ACL by using $module
1325             foreach($aclList as $sAcl) {
1326                 $checkAcl= "";
1328                 // Category or detailed permission?
1329                 if (strpos($module, '/') !== false) {
1330                     if (preg_match('/([a-zA-Z0-9]+):([rwcdm]+)/', $sAcl, $m) ) {
1331                         $checkAcl= $ui->get_permissions($dn, $module, $m[1]);
1332                         $sAcl= $m[2];
1333                     } else {
1334                         $checkAcl= $ui->get_permissions($dn, $module, '0');
1335                     }
1336                 } else {
1337                     $checkAcl= $ui->get_category_permissions($dn, $module);
1338                 }
1340                 // Split up remaining part of the acl and check if it we're
1341                 // allowed to do something...
1342                 $parts= str_split($sAcl);
1343                 foreach ($parts as $part) {
1344                     if (strpos($checkAcl, $part) === false){
1345                         return false;
1346                     }
1347                 }
1349             }
1350         }
1351     }
1353     return true;
1357 function refreshBasesList()
1359     global $config;
1360     $ui= get_userinfo();
1362     // Do some array munching to get it user friendly
1363     $ids= $config->idepartments;
1364     $d= $ui->get_module_departments($this->categories);
1365     $k_ids= array_keys($ids);
1366     $deps= array_intersect($d,$k_ids);
1368     // Fill internal bases list
1369     $this->bases= array();
1370     foreach($k_ids as $department){
1371         $this->bases[$department] = $ids[$department];
1372     }
1374     // Populate base selector if already present
1375     if ($this->baseSelector && $this->baseMode) {
1376         $this->baseSelector->setBases($this->bases);
1377         $this->baseSelector->update(TRUE);
1378     }
1382 function getDepartments()
1384     $departments= array();
1385     $ui= get_userinfo();
1387     // Get list of supported department types
1388     $types = departmentManagement::get_support_departments();
1390     // Load departments allowed by ACL
1391     $validDepartments = $ui->get_module_departments($this->categories);
1393     // Build filter and look in the LDAP for possible sub departments
1394     // of current base
1395     $filter= "(&(objectClass=gosaDepartment)(|";
1396     $attrs= array("description", "objectClass");
1397     foreach($types as $name => $data){
1398         $filter.= "(objectClass=".$data['OC'].")";
1399         $attrs[]= $data['ATTR'];
1400     }
1401     $filter.= "))";
1402     $res= get_list($filter, $this->categories, $this->base, $attrs, GL_NONE);
1404     // Analyze list of departments
1405     foreach ($res as $department) {
1406         if (!in_array_strict($department['dn'], $validDepartments)) {
1407             continue;
1408         }
1410         // Add the attribute where we use for sorting
1411         $oc= null;
1412         foreach(array_keys($types) as $type) {
1413             if (in_array_strict($type, $department['objectClass'])) {
1414                 $oc= $type;
1415                 break;
1416             }
1417         }
1418         $department['sort-attribute']= $types[$oc]['ATTR'];
1420         // Move to the result list
1421         $departments[]= $department;
1422     }
1424     return $departments;
1428 function renderCopyPasteMenu($separator, $copy= true, $cut= true)
1430     // We can only provide information if we've got a copypaste handler
1431     // instance
1432     if(!(isset($this->copyPasteHandler) && is_object($this->copyPasteHandler))){
1433         return "";
1434     }
1436     // Presets
1437     $result= "";
1438     $read= $paste= false;
1439     $ui= get_userinfo();
1441     // Switch flags to on if there's at least one category which allows read/paste
1442     foreach($this->categories as $category){
1443         $read= $read || preg_match('/r/', $ui->get_category_permissions($this->base, $category));
1444         $paste= $paste || $ui->is_pasteable($this->base, $category) == 1;
1445     }
1448     // Draw entries that allow copy and cut
1449     if($read){
1451         // Copy entry
1452         if($copy){
1453             $result.= "<li$separator><a href='#' onClick='\$(\"act\").value= \"copy\";\$(\"exec_act\").click();'>".image('images/lists/copy.png')."&nbsp;"._("Copy")."</a></li>";
1454             $separator= "";
1455         }
1457         // Cut entry
1458         if($cut){
1459             $result.= "<li$separator><a href='#' onClick='\$(\"act\").value= \"cut\";\$(\"exec_act\").click();'>".image("images/lists/cut.png")."&nbsp;"._("Cut")."</a></li>";
1460             $separator= "";
1461         }
1462     }
1464     // Draw entries that allow pasting entries
1465     if($paste){
1466         if($this->copyPasteHandler->entries_queued()){
1467             $result.= "<li$separator><a href='#' onClick='\$(\"act\").value= \"paste\";\$(\"exec_act\").click();'>".image("images/lists/paste.png")."&nbsp;"._("Paste")."</a></li>";
1468         }else{
1469             $result.= "<li$separator><a href='#'>".image('images/lists/paste-grey.png')."&nbsp;"._("Paste")."</a></li>";
1470         }
1471     }
1473     return($result);
1477 function renderCopyPasteActions($row, $dn, $category, $class, $copy= true, $cut= true)
1479     // We can only provide information if we've got a copypaste handler
1480     // instance
1481     if(!(isset($this->copyPasteHandler) && is_object($this->copyPasteHandler))){
1482         return "";
1483     }
1485     // Presets
1486     $ui = get_userinfo();
1487     $result = "";
1489     // Render cut entries
1490     if($cut){
1491         if($ui->is_cutable($dn, $category, $class)){
1492             $result.= image('images/lists/cut.png', "listing_cut_$row", _("Cut this entry"));
1493         }else{
1494             $result.= image('images/empty.png');
1495         }
1496     }
1498     // Render copy entries
1499     if($copy){
1500         if($ui->is_copyable($dn, $category, $class)){
1501             $result.= image('images/lists/copy.png', "listing_copy_$row", _("Copy this entry"));
1502         }else{
1503             $result.= image('images/empty.png');
1504         }
1505     }
1507     return($result);
1511 function renderSnapshotMenu($separator)
1513     // We can only provide information if we've got a snapshot handler
1514     // instance
1515     if(!(isset($this->snapshotHandler) && is_object($this->snapshotHandler))){
1516         return "";
1517     }
1519     // Presets
1520     $result = "";
1521     $ui = get_userinfo();
1523     if($this->snapshotHandler->enabled() && $ui->allow_snapshot_restore($this->base, $this->categories)){
1525         // Check if there is something to restore
1526         $restore= false;
1527         foreach($this->snapshotHandler->getSnapshotBases() as $base){
1528             $restore= $restore || count($this->snapshotHandler->getDeletedSnapshots($base)) > 0;
1529         }
1531         // Draw icons according to the restore flag
1532         if($restore){
1533             $result.= "<li$separator><a href='#' onClick='\$(\"act\").value= \"restore\";\$(\"exec_act\").click();'>".image('images/lists/restore.png')."&nbsp;"._("Restore snapshots")."</a></li>";
1534         }else{
1535             $result.= "<li$separator><a href='#'>".image('images/lists/restore-grey.png')."&nbsp;"._("Restore snapshots")."</a></li>";
1536         }
1537     }
1539     return($result);
1543 function renderExporterMenu($separator)
1545     // Presets
1546     $result = "";
1548     // Draw entries
1549     $result.= "<li$separator><a href='#'>".image('images/lists/export.png')."&nbsp;"._("Export list")."&nbsp;".image("images/forward-arrow.png")."</a><ul class='level3'>";
1551     // Export CVS as build in exporter
1552     foreach ($this->exporter as $action => $exporter) {
1553         $result.= "<li><a href='#' onClick='\$(\"act\").value= \"$action\";\$(\"exec_act\").click();'>".image($exporter['image'])."&nbsp;".$exporter['label']."</a></li>";
1554     }
1556     // Finalize list
1557     $result.= "</ul></li>";
1559     return($result);
1563 function renderSnapshotActions($row, $dn, $category, $class, $copy= true, $cut= true)
1565     // We can only provide information if we've got a snapshot handler
1566     // instance
1567     if(!(isset($this->snapshotHandler) && is_object($this->snapshotHandler))){
1568         return "";
1569     }
1571     // Presets
1572     $result= "";
1573     $ui = get_userinfo();
1575     // Only act if enabled here
1576     if($this->snapshotHandler->enabled()){
1578         // Draw restore button
1579         if ($ui->allow_snapshot_restore($dn, $category)){
1581             // Do we have snapshots for this dn?
1582             if($this->snapshotHandler->hasSnapshots($dn)){
1583                 $result.= image('images/lists/restore.png', "listing_restore_$row", _("Restore snapshot"));
1584             } else {
1585                 $result.= image('images/lists/restore-grey.png');
1586             }
1587         }
1589         // Draw snapshot button
1590         if($ui->allow_snapshot_create($dn, $category)){
1591             $result.= image('images/snapshot.png', "listing_snapshot_$row", _("Create new snapshot for this object"));
1592         }else{
1593             $result.= image('images/empty.png');
1594         }
1595     }
1597     return($result);
1601 function renderDaemonMenu($separator)
1603     $result= "";
1605     // If there is a daemon registered, draw the menu entries
1606     if(class_available("DaemonEvent")){
1607         $events= DaemonEvent::get_event_types_by_category($this->categories);
1608         if(isset($events['BY_CLASS']) && count($events['BY_CLASS'])){
1609             foreach($events['BY_CLASS'] as $name => $event){
1610                 $result.= "<li$separator><a href='#' onClick='\$(\"act\").value=\"$name\";\$(\"exec_act\").click();'>".$event['MenuImage']."&nbsp;".$event['s_Menu_Name']."</a></li>";
1611                 $separator= "";
1612             }
1613         }
1614     }
1616     return $result;
1620 function getEntry($dn)
1622     foreach ($this->entries as $entry) {
1623         if (isset($entry['dn']) && strcasecmp($dn, $entry['dn']) == 0){
1624             return $entry;
1625         }
1626     }
1627     return null;
1631 function getEntries()
1633     return $this->entries;
1637 function getType($dn)
1639     $dn = LDAP::fix($dn);
1640     if (isset($this->objectDnMapping[$dn])) {
1641         return $this->objectDnMapping[$dn];
1642     }
1643     return null;
1648 ?>