Code

Renamed plugin
[gosa.git] / gosa-plugins / goto-ng / admin / newConfigManagement / class_ConfigManagementListing.inc
1 <?php
3 class ConfigManagementListing extends management
4 {
6     private $base = "";
8     private $containerSelector = NULL;
9     private $itemSelector = NULL;
10     private $objectTypeStr = "";
12     function __construct($config, $ui, $parent)
13     {
14         // Set storage points - We do not have any - We just create a fake list which lists all items
15         $this->storagePoints = array("");
16         $this->rebuildListing();
18         $this->containerSelector = new ItemSelector(array(),'/root','/root');
19         $this->itemSelector = new ItemSelector(array(),'','');
21         $this->parent = &$parent;
22     }
24     function save_object()
25     {
26         $this->containerSelector->update();    
27         $this->itemSelector->update();    
28     }
30     function getSelectedContainer()
31     {
32         return($this->containerSelector->getBase());
33     }
35     function setContainer($dist)
36     {
37         return($this->containerSelector->setBase($dist));
38     }
40     function setItem($rel)
41     {
42         return($this->itemSelector->setBase($rel));
43     }
45     function getSelectedItem()
46     {
47         return($this->itemSelector->getBase());
48     }
51     function setContainers($containers) 
52     {
53         $this->containerSelector->setBases($containers);
54         $this->containerSelector->update(TRUE);
55     }
57     function setItems($items) 
58     {
59         $this->itemSelector->setBases($items);
60         $this->itemSelector->update(TRUE);
61     }
64     function renderList()
65     {
66         $headpage = $this->getHeadpage();
67         $headpage->update();
68         $smarty = get_smarty();
69         $smarty->assign("CONTAINER", $this->containerSelector->render());
70         $smarty->assign("ITEM", $this->itemSelector->render());
71         $display = $headpage->render();
72         return($this->getHeader().$display);
73     }
76     function setListingTypes($types)
77     {
78         $str = "";
79         foreach($types as $typeData){
80             $str.= "\n<objectType>";
81             foreach($typeData as $key => $value){
82                 $str .= "\n\t<{$key}>{$value}</{$key}>";
83             }
84             $str.= "\n</objectType>\n";
86         }
87         $this->objectTypeStr = $str;
88     }
91     function execute()
92     {
93         // Ensure that html posts and gets are kept even if we see a 'Entry islocked' dialog.
94         $vars = array('/^act$/','/^listing/','/^PID$/','/^FILTER_PID$/');
95         session::set('LOCK_VARS_TO_USE',$vars);
97         pathNavigator::registerPlugin($this);
99         /* Display the copy & paste dialog, if it is currently open */
100         $ret = $this->copyPasteHandler("",array());
101         if($ret){
102             return($this->getHeader().$ret);
103         }
105         // Update filter
106         if ($this->filter) {
107             $this->filter->update();
108             session::global_set(get_class($this)."_filter", $this->filter);
109             session::set('autocomplete', $this->filter);
110         }
112         // Handle actions (POSTs and GETs)
113         $str = $this->handleActions($this->detectPostActions());
114         if($str) return($this->getHeader().$str);
116         $items = $this->parent->getItemsToBeDisplayed();
117         session::set('CONFIG_ITEM', $items);
119         // Open single dialog objects
120         if(is_object($this->dialogObject)){
121             if(method_exists($this->dialogObject,'save_object')) $this->dialogObject->save_object();
122             if(method_exists($this->dialogObject,'execute')){
123                 $display = $this->dialogObject->execute();
124                 $display.= $this->_getTabFooter();
125                 return($this->getHeader().$display);
126             }
127         }
129         // Display tab object.
130         if($this->tabObject instanceOf tabs || $this->tabObject instanceOf multi_plug){
131 #      $this->tabObject->save_object();
132             $display = $this->tabObject->execute();
133             $display.= $this->_getTabFooter();
134             return($this->getHeader().$display);
135         }
136         // Set current restore base for snapshot handling.
137         if(is_object($this->snapHandler)){
138             $bases = array();
139             foreach($this->storagePoints as $sp){
140                 $bases[] = $sp.$this->headpage->getBase();
141             }
143             // No bases specified? Try base
144             if(!count($bases)) $bases[] = $this->headpage->getBase();
146             $this->snapHandler->setSnapshotBases($bases);
147         }
149         // Create statistic table entry
150         stats::log('management', $class = get_class($this), $this->getAclCategories(),  $action = 'view',
151                 $amount = 1, $duration = (microtime(TRUE) - $this->initTime));
153         // Display list
154         $this->rebuildListing();
155         $str = $this->renderList();
156         return($str);
157     }    
158     
160    
161     function rebuildListing()
162     {
163         // Build filter
164         if (session::global_is_set(get_class($this)."_filter")){
165             $filter= session::global_get(get_class($this)."_filter");
166         } else {
167             $filter = new filter(get_template_path("DeviceConfig-filter.xml", true));
168             $filter->setObjectStorage($this->storagePoints);
169         }
170         $this->setFilter($filter);
172         // Load service xml file and fill in placeholders
173         $contents = file_get_contents(get_template_path("DeviceConfig-list.xml", true));
174         $contents = preg_replace("/%TYPES%/", $this->objectTypeStr, $contents);
175         $contents = preg_replace("/%ITEMS%/", "", $contents);
177         $headpage = new listing($contents,TRUE);
178         $headpage->setBase($this->base);
179         $headpage->setFilter($filter);
181         parent::__construct($this->config, $this->ui, "services", $headpage);
183         // Register default actions
184         $this->registerAction("new",    "newEntry");
185         $this->registerAction("editEntry",  "editEntry");
186         $this->registerAction("edit",       "openEntry");
187         $this->registerAction("apply",  "applyChanges");
188         $this->registerAction("save",   "saveChanges");
189         $this->registerAction("cancel", "cancelEdit");
190         $this->registerAction("cancelDelete", "cancelEdit");
191         $this->registerAction("remove", "removeEntryRequested");
192         $this->registerAction("removeConfirmed", "removeEntryConfirmed");
194         $this->registerAction("config-filter","editFilter");
195         $this->registerAction("saveFilter","saveFilter");
196         $this->registerAction("cancelFilter","cancelFilter");
198     }
200     function removeEntryRequested($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="")
201     {
202         $this->parent->removeEntry($target);
203     }
205     function openEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="")
206     {
207         $this->parent->openEntry($target);
208     }
210     function editEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="")
211     {
212         $this->parent->editEntry($target);
213     }
228     
230
232 ?>