Code

Updated edit handling
[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(), $this);
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         $cont = $this->listing->getSelectedContainer();
70         $item = $this->listing->getSelectedItem();
71         $this->setCurrentContainer($cont, $item);
72     }
75     function updateItemList($path)
76     {
77         // Fist get Item and check if it is an release 
78         if($this->dataModel->itemExistsByPath($path)){
79             $data = $this->dataModel->getItemByPath($path);
81             // Only releases can contain config-items.
82             if($data['type'] == 'Release' && $data['status'] != "fetched"){
84                 $rpc = $this->config->getRpcHandle();
85                 $res = $rpc->listConfigItems($data['name']);
86                 if(!$rpc->success()){
87                     msg_dialog::display(_("Error"), 
88                             sprintf(_("Failed to load distributions, error was '%s'!"), 
89                                 $rpc->get_error()),ERROR_DIALOG);
90                 }else{
91                     $this->dataModel->setItemStatus($path, 'käse');
92                     $rpc = $this->config->getRpcHandle();
93                     $res = $rpc->getPackages($data['name']);
95                     return;
96                     foreach($res as $itemPath => $type){
97                 
98                         // Make names dataModel conform
99                         $itemPath = $path.'/'.preg_replace("/^\//","/root", $itemPath);
100                         $name = preg_replace("/^.*\//","",$itemPath);   
101                         $itemPath = preg_replace("/\/[^\/]*$/","", $itemPath);
102                         $this->dataModel->addItem($type, $itemPath, $name); 
103                     }
104                 }
105             }
106         }
107     }
111     function setCurrentContainer($cont, $item)
112     {
113         $this->selectedContainer = $cont;
114         $this->selectedItem = $item;
116         // Get a list of all available distributions and releases.
117         $distList = $this->getDistList();
118         $releaseList = $this->getItemList();
120         // Ensure that we've valid values selected.
121         if(!isset($releaseList[$this->selectedItem])){
122             if(count($releaseList)){
123                 $this->selectedItem = key($releaseList);
124             }else{
125                 $this->selectedItem = "";
126             }
127         }
129         // Update list of items within the selected container. 
130         $this->updateItemList($this->selectedContainer);
132         // Transfer checked values back to the listing class.
133         $this->listing->setContainer($this->selectedContainer);
134         $this->listing->setItem($this->selectedItem);
135         $this->listing->setContainers($this->getDistList());
136         $this->listing->setItems($this->getItemList());
137     }
140     /*! \brief  Generate the HTML content for this plugin.
141      *          Actually renders the listing widget..
142      */
143     function execute()
144     {
145         // Get the selected release and store it in a session variable
146         //  to allow the configFilter to access it and display the
147         //  packages and items.
148         $res = $this->listing->execute();
149         $this->listing->setListingTypes($this->getListingTypes());
151         return($res);
152     }
154     
155     function getItemsToBeDisplayed()
156     {
158         $path = $this->selectedContainer.$this->selectedItem;
159         $item = $this->dataModel->getItemByPath($path);
160         return($item);
161     }
164     /*! \brief  Returns a simply list of all releases of the CURRENT distribution.
165      *          This list will then be used to generate the entries of the 
166      *           ItemSelectors in the listing class.
167      */
168     function getItemList()
169     {
170         $data = $this->dataModel->getItemByPath($this->selectedContainer);
171         $res = array(""=>"/");
172         if($data['type'] != 'Release'){
173         }else{
174             $res = array_merge($res,$this->__recurseItem($data, array('Component'),$this->selectedContainer));
175         }
176         return($res);
177     }
178     
179     
180     /*! \brief  Returns a simply list of all distributions.
181      *          This list will then be used to generate the entries of the 
182      *           ItemSelectors in the listing class.
183      */
184     function getDistList()
185     {
186         $data = $this->dataModel->getItemByPath('/root');
187         $res["/root"] = "/";
188         $res = array_merge($res,$this->__recurseItem($data, array('Distribution','Release')));
189         return($res);
190     }
191     
193     function __recurseItem($item, $types, $parent = "")
194     {
195         $res = array();
196         if(in_array($item['type'], $types)){
197             $path = preg_replace("/".preg_quote($parent,'/')."/","",$item['path']);
198             $res[$path] = $item['name'];
199         }
200         if(count($item['children'])){
201             foreach($item['children'] as $child){
202                 $res = array_merge($res, $this->__recurseItem($child, $types, $parent));
203             }
204         }
205         return($res);
206     }
210     function remove_lock()
211     {
212     }
214     
215     /*! \brief  Intializes this plugin
216      *          All available installation methods will be loaded
217      */
218     function loadInstallationMethods()
219     {
220         // Reset erros
221         $this->rpcError = $this->initFailed = FALSE;
223         // Load configuration via rpc.
224         $rpc = $this->config->getRpcHandle();
226         // Populate install methods on success.
227         $res = $rpc->getSupportedInstallMethods();
228         if(!$rpc->success()){
229             $this->rpcError = TRUE;
230             $this->errorMessage = $rpc->get_error();;
231             return;
232         }
233         $this->installationMethods = $res;
234         if(!count($this->installationMethods)){
235             $this->errorMessage = _("No selectable install methods returned!");
236             msg_dialog::display(_("Setup"), $this->errorMessage , ERROR_DIALOG);
237             $this->initFailed = TRUE;
238             return;
239         }
240     }
243     function getListingTypes()
244     {
245         $types= array();
246         $types['Distribution']['objectClass'] = 'Distribution';
247         $types['Distribution']['label'] = _('Distribution');
248         $types['Distribution']['image'] = 'images/lists/edit.png';
249         $types['Distribution']['category'] = 'Device';
250         $types['Distribution']['class'] = 'Device';
252         $types['Release']['objectClass'] = 'Release';
253         $types['Release']['label'] = _('Release');
254         $types['Release']['image'] = 'images/lists/delete.png';
255         $types['Release']['category'] = 'Device';
256         $types['Release']['class'] = 'Device';
258         $types['Component']['objectClass'] = 'Component';
259         $types['Component']['label'] = _('Component');
260         $types['Component']['image'] = 'plugins/users/images/select_user.png';
261         $types['Component']['category'] = 'Device';
262         $types['Component']['class'] = 'Device';
263         return($types);
264     }
267     function editEntry($ids)
268     {
269         foreach($ids as $id){
270             echo "<br>Edit {$id}";
271         }
272     }
275     function removeEntry($ids)
276     {
277         foreach($ids as $id){
278             echo "<br>Remove {$id}";
279         }
280     }
283     function openEntry($ids)
284     {
285         $id = $ids[0];
286         $item = $this->dataModel->getItemById($id);
287         if($item){
288             if(in_array($item['type'], array('Distribution', 'Release'))){
289                 $this->setCurrentContainer($item['path'], $this->selectedContainer);
290             }else{
291                 $this->editEntry(array($id));
292             }
293         }
294     }
297     public static function plInfo()
298     {
299         return (array(
300                     "plShortName"   => _("Config management"),
301                     "plDescription" => _("Config management"),
302                     "plSelfModify"  => FALSE,
303                     "plDepends"     => array(),
304                     "plPriority"    => 0,
305                     "plSection"     => array("administration"),
306                     "plCategory"    => array(
307                         "newConfigManagement" => array("description"  => _("Config management"),
308                             "objectClass"  => "FAKE_OC_newConfigManagement")),
309                     "plProvidedAcls"=> array()
310                     ));
311     }
313 ?>