Code

Removed second release selector from config management
[gosa.git] / gosa-plugins / goto-ng / admin / newConfigManagement / class_newConfigManagement.inc
1 <?php
3 /*! \brief  This class allows to manage backend config items and packages.
4  */
5 class newConfigManagement extends plugin
6 {
7     var $initTime;
8     var $plHeadline = "Config management";
9     var $plDescription = "Config management";
11     var $selectedContainer;
13     var $dataModel = NULL;
14     var $listing = NULL;
17     /*! \brief  Initialize the plugin and finally update the data model.
18      */
19     function __construct($config, $dn)
20     {
21         $this->config = &$config;
22         $this->listing = new ConfigManagementListing($this->config, get_userinfo(), $this);
24         // Request an update of the data model
25         $this->updateDataModel();
26     }
29     /*! \brief  Updates all distributions, releases, packages and items in the dataModel
30      *          Load information from the backend.
31      */
32     function updateDataModel()
33     {
34         // Recreate the data model, to have a clean and fresh instance.
35         $this->dataModel = new ConfigManagementDataModel();
37         // Load distributions 
38         $rpc = $this->config->getRpcHandle();
39         $res = $rpc->getDistributions();
40         if(!$rpc->success()){
41             msg_dialog::display(_("Error"), sprintf(_("Failed to load distributions: %s"), $rpc->get_error()),ERROR_DIALOG);
42             return(NULL);
43         }else{
44             foreach($res as $dist){
45                 $this->dataModel->addItem('Distribution','/root', $dist['name'], $dist);
46                 foreach($dist['releases'] as $release){
47                     $distPath = "/root/{$dist['name']}";
48                     $this->dataModel->addItem('Release',$distPath, $release['name'], $release);
50                     foreach($dist['components'] as $component){
51                         $comPath = "{$distPath}/{$release['name']}";
52                         $this->dataModel->addItem('Component',$comPath, $component['name'], $component);
53                     }
54                 }
55             }
56         }
57     }
60     /*! \brief  Keep track of posted values and populate those 
61      *           which are interesting for us.
62      *          Inspects the _POST and _GET values.
63      */
64     function save_object()
65     {
66         // Update the listing class, this is necessary to get post
67         //  actions from it.
68         $this->listing->save_object();
70         // Get the selected distribution and release from the listing widget.
71         $cont = $this->listing->getSelectedContainer();
72         $this->setCurrentContainer($cont);
73     }
76     /*! \brief  Load extended sub-objecte like 'config items' or 'packages'
77      *           for the given release path.
78      *  @param  String  The release path to load sub-objects for.
79      *  @return NULL 
80      */
81     function updateItemList($path)
82     {
83         // Fist get Item and check if it is an release 
84         if($this->dataModel->itemExistsByPath($path)){
85             $data = $this->dataModel->getItemByPath($path);
87             // Only releases can contain config-items.
88             if($data['type'] == 'Release' && $data['status'] != "fetched"){
90                 $rpc = $this->config->getRpcHandle();
91                 $res = $rpc->listConfigItems($data['name']);
92                 if(!$rpc->success()){
93                     msg_dialog::display(_("Error"), 
94                             sprintf(_("Failed to load distributions: %s"), 
95                                 $rpc->get_error()),ERROR_DIALOG);
96                 }else{
97                     $rpc = $this->config->getRpcHandle();
98                     $res = $rpc->getPackages($data['name']);
100                     return;
101                     foreach($res as $itemPath => $type){
103                         // Make names dataModel conform
104                         $itemPath = $path.'/'.preg_replace("/^\//","/root", $itemPath);
105                         $name = preg_replace("/^.*\//","",$itemPath);   
106                         $itemPath = preg_replace("/\/[^\/]*$/","", $itemPath);
107                         $this->dataModel->addItem($type, $itemPath, $name); 
108                     }
109                     $this->dataModel->setItemStatus($path, 'fetched');
110                 }
111             }
112         }
113     }
116     /*! \brief  Sets the currently selected container and item path. 
117      *  @param  String  The path of the container to set.
118      *  @param  String  The path of the item to set.
119      *  @return 
120      */
121     function setCurrentContainer($cont)
122     {
123         $this->selectedContainer = $cont;
125         // Get a list of all available container and items.
126         $releaseList = $this->getItemList();
128         // Update list of items within the selected container. 
129         $this->updateItemList($this->selectedContainer);
131         // Transfer checked values back to the listing class.
132         $this->listing->setContainers($this->getContainerList());
133     }
136     /*! \brief  Generate the HTML content for this plugin.
137      *          Actually renders the listing widget..
138      */
139     function execute()
140     {
141         // Get the selected release and store it in a session variable
142         //  to allow the configFilter to access it and display the
143         //  packages and items.
144         $res = $this->listing->execute();
145         $this->listing->setListingTypes($this->getListingTypes());
147         return($res);
148     }
151     /*! \brief      Returns a list of items which will then be displayed 
152      *               in the management-list. 
153      *              (The management class calls this method from its execute())
154      *  @return     Array   A list of items/objects for the listing. 
155      */
156     function getItemsToBeDisplayed()
157     {
159         $path = $this->selectedContainer;
160         $item = $this->dataModel->getItemByPath($path);
161         return($item);
162     }
165     /*! \brief  Returns a simply list of all releases of the CURRENT distribution.
166      *          This list will then be used to generate the entries of the 
167      *           ItemSelectors in the listing class.
168      */
169     function getItemList()
170     {
171         $data = $this->dataModel->getItemByPath($this->selectedContainer);
172         $res = array();
173         $res[""] = array("name" => "/", "desc" => "");
174         $res = array_merge($res,$this->__recurseItem($data, array('Component')));
175         return($res);
178         if($data['type'] != 'Release'){
179         }else{
180             $res = array_merge($res,$this->__recurseItem($data, array('Component'),$this->selectedContainer));
181         }
182         return($res);
183     }
186     /*! \brief  Returns a simply list of all distributions.
187      *          This list will then be used to generate the entries of the 
188      *           ItemSelectors in the listing class.
189      */
190     function getContainerList()
191     {
192         $data = $this->dataModel->getItemByPath('/root');
193         $res = array();
194         $res["/root"] = array("name" => "/", "desc" => "");
195         $res = array_merge($res,$this->__recurseItem($data, array('Distribution','Release')));
197         print_a($res);
198         return($res);
199     }
202     /*! \brief  Recursivly walks through an item and collects all path and name info.
203      *          The reult can then be used to fill the ItemSelector.
204      *  @param  Array   The Item to recurse. 
205      *  @param  Array   The type of of objects to collect. 
206      *  @param  String  The parent path prefix which should be removed.
207      *  @return Array   An array containing Array[path] = name
208      */
209     function __recurseItem($item, $types, $parent = "")
210     {
211         $res = array();
212         if(in_array($item['type'], $types)){
213             $path = preg_replace("/".preg_quote($parent,'/')."/","",$item['path']);
214             $res[$path] = array('name' => $item['name'],'desc'=>$item['type']);
215         }
216         if(count($item['children'])){
217             foreach($item['children'] as $child){
218                 $res = array_merge($res, $this->__recurseItem($child, $types, $parent));
219             }
220         }
221         return($res);
222     }
225     /*! \brief  Intializes this plugin
226      *          All available installation methods will be loaded
227      */
228     function loadInstallationMethods()
229     {
230         // Reset erros
231         $this->rpcError = $this->initFailed = FALSE;
233         // Load configuration via rpc.
234         $rpc = $this->config->getRpcHandle();
236         // Populate install methods on success.
237         $res = $rpc->getSupportedInstallMethods();
238         if(!$rpc->success()){
239             $this->rpcError = TRUE;
240             $this->errorMessage = $rpc->get_error();;
241             return;
242         }
243         $this->installationMethods = $res;
244         if(!count($this->installationMethods)){
245             $this->errorMessage = _("No selectable install methods returned!");
246             msg_dialog::display(_("Setup"), $this->errorMessage , ERROR_DIALOG);
247             $this->initFailed = TRUE;
248             return;
249         }
250     }
253     /*! \brief   Returns a info list about all items we can manage,
254      *            this used to fill the listings <objectType> settings.
255      *  @return Array   An array with item info.
256      */
257     function getListingTypes()
258     {
259         $types= array();
260         $types['Distribution']['objectClass'] = 'Distribution';
261         $types['Distribution']['label'] = _('Distribution');
262         $types['Distribution']['image'] = 'images/lists/edit.png';
263         $types['Distribution']['category'] = 'Device';
264         $types['Distribution']['class'] = 'Device';
266         $types['Release']['objectClass'] = 'Release';
267         $types['Release']['label'] = _('Release');
268         $types['Release']['image'] = 'images/lists/delete.png';
269         $types['Release']['category'] = 'Device';
270         $types['Release']['class'] = 'Device';
272         $types['Component']['objectClass'] = 'Component';
273         $types['Component']['label'] = _('Component');
274         $types['Component']['image'] = 'plugins/users/images/select_user.png';
275         $types['Component']['category'] = 'Device';
276         $types['Component']['class'] = 'Device';
277         return($types);
278     }
281     /*! \brief  Acts on edit requests and opens an edit dialog for the received item-id.
282      *          (This action is received from the ConfigManagementListing class.)
283      *  @param  Array   The items ids. (May contain multiple ids)
284      *  @return  
285      */
286     function editEntry($ids)
287     {
288         foreach($ids as $id){
289             echo "<br>Edit {$id}";
290         }
291     }
294     /*! \brief  Acts on remove requests.
295      *          (This action is received from the ConfigManagementListing class.)
296      *  @param  Array   The items ids. (May contain multiple ids)
297      *  @return  
298      */
299     function removeEntry($ids)
300     {
301         foreach($ids as $id){
302             echo "<br>Remove {$id}";
303         }
304     }
307     /*! \brief  Acts on open requests.
308      *          (This action is received from the ConfigManagementListing class.)
309      *  @param  Array   The items ids. (May contain multiple ids)
310      *  @return  
311      */
312     function openEntry($ids)
313     {
314         $id = $ids[0];
315         $item = $this->dataModel->getItemById($id);
316         if($item){
317             if(in_array($item['type'], array('Distribution', 'Release'))){
318                 $this->setCurrentContainer($item['path']);
319             }elseif(in_array($item['type'], array('Component'))){
320                 $next = preg_replace("/".preg_quote($this->selectedContainer,'/')."/","", $item['path']);
321                 $this->setCurrentContainer($this->selectedContainer, $next);
322             }else{
323                 $this->editEntry(array($id));
324             }
325         }
326     }
329     /*! \brief      The plugins ACL and plugin-property definition. 
330      *  @return 
331      */
332     public static function plInfo()
333     {
334         return (array(
335                     "plShortName"   => _("Config management"),
336                     "plDescription" => _("Config management"),
337                     "plSelfModify"  => FALSE,
338                     "plDepends"     => array(),
339                     "plPriority"    => 0,
340                     "plSection"     => array("administration"),
341                     "plCategory"    => array(
342                         "newConfigManagement" => array("description"  => _("Config management"),
343                             "objectClass"  => "FAKE_OC_newConfigManagement")),
344                     "plProvidedAcls"=> array()
345                     ));
346     }
349     /*! \brief   
350      *  @param  
351      *  @return 
352      */
353     function remove_lock()
354     {
355     }
359 ?>