Code

Updated config manamgenet
[gosa.git] / gosa-core / plugins / admin / newConfigManagement / class_newConfigManagement.inc
1 <?php
3 class newConfigManagement extends plugin
4 {
5     var $initTime;
6     var $plHeadline = "Config management";
7     var $plDescription = "Config management";
9     var $selectedContainer;
10     var $selectedItem;
12     var $dataModel = NULL;
13     var $listing = NULL;
16     /*! \brief  Initialize the plugin and finally update the data model.
17      */
18     function __construct($config, $dn)
19     {
20         $this->config = &$config;
21         $this->listing = new ConfigManagementListing($this->config, get_userinfo());
23         // Request an update of the data model
24         $this->updateDataModel();
25     }
28     /*! \brief  Updates all distributions, releases, packages and items in the dataModel
29      *          Load information from the backend.
30      */
31     function updateDataModel()
32     {
33         // Recreate the data model, to have a clean and fresh instance.
34         $this->dataModel = new ConfigManagementDataModel();
36         // Load distributions 
37         $rpc = $this->config->getRpcHandle();
38         $res = $rpc->getDistributions();
39         if(!$rpc->success()){
40             msg_dialog::display(_("Error"), sprintf(_("Failed to load distributions, error was '%s'!"), $rpc->get_error()),ERROR_DIALOG);
41             return(NULL);
42         }
43         foreach($res as $dist){
44             $this->dataModel->addItem('Distribution','/root', $dist['name'], $dist);
45             foreach($dist['releases'] as $release){
46                 $distPath = "/root/{$dist['name']}";
47                 $this->dataModel->addItem('Release',$distPath, $release['name'], $release);
49                 foreach($dist['components'] as $component){
50                     $comPath = "{$distPath}/{$release['name']}";
51                     $this->dataModel->addItem('Component',$comPath, $component['name'], $component);
52                 }
53             }
54         }
55     }
58     /*! \brief  Keep track of posted values and populate those 
59      *           which are interesting for us.
60      *          Inspects the _POST and _GET values.
61      */
62     function save_object()
63     {
64         // Update the listing class, this is necessary to get post
65         //  actions from it.
66         $this->listing->save_object();
68         // Get the selected distribution and release from the listing widget.
69         $this->selectedContainer = $this->listing->getSelectedContainer();
70         $this->selectedItem = $this->listing->getSelectedItem();
71   
72         // Get a list of all available distributions and releases.
73         $distList = $this->getDistList();
74         $releaseList = $this->getItemList();
76         // Ensure that we've valid values selected.
77         if(!isset($releaseList[$this->selectedItem])){
78             if(count($releaseList)){
79                 $this->selectedItem = key($releaseList);
80             }else{
81                 $this->selectedItem = "";
82             }
83         }
85         // Update list of items within the selected container. 
86         $this->updateItemList($this->selectedContainer);
88         // Transfer checked values back to the listing class.
89         $this->listing->setContainer($this->selectedContainer);
90         $this->listing->setItem($this->selectedItem);
91         $this->listing->setContainers($this->getDistList());
92         $this->listing->setItems($this->getItemList());
93     }
96     function updateItemList($path)
97     {
98         // Fist get Item and check if it is an release 
99         if($this->dataModel->itemExistsByPath($path)){
100             $data = $this->dataModel->getItemByPath($path);
102             // Only releases can contain config-items.
103             if($data['type'] == 'Release' && $data['status'] != "fetched"){
105                 $rpc = $this->config->getRpcHandle();
106                 $res = $rpc->listConfigItems($data['name']);
107                 if(!$rpc->success()){
108                     msg_dialog::display(_("Error"), 
109                             sprintf(_("Failed to load distributions, error was '%s'!"), 
110                                 $rpc->get_error()),ERROR_DIALOG);
111                 }else{
112                     $this->dataModel->setItemStatus($path, 'käse');
113                     $rpc = $this->config->getRpcHandle();
114                     $res = $rpc->getPackages($data['name']);
116                     return;
117                     foreach($res as $itemPath => $type){
118                 
119                         // Make names dataModel conform
120                         $itemPath = $path.'/'.preg_replace("/^\//","/root", $itemPath);
121                         $name = preg_replace("/^.*\//","",$itemPath);   
122                         $itemPath = preg_replace("/\/[^\/]*$/","", $itemPath);
123                         $this->dataModel->addItem($type, $itemPath, $name); 
124                     }
125                 }
126             }
127         }
128     }
131     /*! \brief  Generate the HTML content for this plugin.
132      *          Actually renders the listing widget..
133      */
134     function execute()
135     {
136         // Get the selected release and store it in a session variable
137         //  to allow the configFilter to access it and display the
138         //  packages and items.
139         $path = $this->selectedContainer.$this->selectedItem;
140         $item = $this->dataModel->getItemByPath($path);
141         session::set('CONFIG_ITEM', $item);
143         return($this->listing->renderList());
144     }
147     /*! \brief  Returns a simply list of all releases of the CURRENT distribution.
148      *          This list will then be used to generate the entries of the 
149      *           ItemSelectors in the listing class.
150      */
151     function getItemList()
152     {
153         $data = $this->dataModel->getItemByPath($this->selectedContainer);
154         $res = array(""=>"/");
155         if($data['type'] != 'Release'){
156         }else{
157             $res = array_merge($res,$this->__recurseItem($data, array('Component'),$this->selectedContainer));
158         }
159         return($res);
160     }
161     
162     
163     /*! \brief  Returns a simply list of all distributions.
164      *          This list will then be used to generate the entries of the 
165      *           ItemSelectors in the listing class.
166      */
167     function getDistList()
168     {
169         $data = $this->dataModel->getItemByPath('/root');
170         $res["/root"] = "/";
171         $res = array_merge($res,$this->__recurseItem($data, array('Distribution','Release')));
172         return($res);
173     }
174     
176     function __recurseItem($item, $types, $parent = "")
177     {
178         $res = array();
179         if(in_array($item['type'], $types)){
180             $path = preg_replace("/".preg_quote($parent,'/')."/","",$item['path']);
181             $res[$path] = $item['name'];
182         }
183         if(count($item['children'])){
184             foreach($item['children'] as $child){
185                 $res = array_merge($res, $this->__recurseItem($child, $types, $parent));
186             }
187         }
188         return($res);
189     }
193     function remove_lock()
194     {
195     }
197     
198     /*! \brief  Intializes this plugin
199      *          All available installation methods will be loaded
200      */
201     function loadInstallationMethods()
202     {
203         // Reset erros
204         $this->rpcError = $this->initFailed = FALSE;
206         // Load configuration via rpc.
207         $rpc = $this->config->getRpcHandle();
209         // Populate install methods on success.
210         $res = $rpc->getSupportedInstallMethods();
211         if(!$rpc->success()){
212             $this->rpcError = TRUE;
213             $this->errorMessage = $rpc->get_error();;
214             return;
215         }
216         $this->installationMethods = $res;
217         if(!count($this->installationMethods)){
218             $this->errorMessage = _("No selectable install methods returned!");
219             msg_dialog::display(_("Setup"), $this->errorMessage , ERROR_DIALOG);
220             $this->initFailed = TRUE;
221             return;
222         }
223     }
226     public static function plInfo()
227     {
228         return (array(
229                     "plShortName"   => _("Config management"),
230                     "plDescription" => _("Config management"),
231                     "plSelfModify"  => FALSE,
232                     "plDepends"     => array(),
233                     "plPriority"    => 0,
234                     "plSection"     => array("administration"),
235                     "plCategory"    => array(
236                         "newConfigManagement" => array("description"  => _("Config management"),
237                             "objectClass"  => "FAKE_OC_newConfigManagement")),
238                     "plProvidedAcls"=> array()
239                     ));
240     }
242 ?>