1 <?php
3 class newConfigManagement extends plugin
4 {
5 var $initTime;
6 var $plHeadline = "Config management";
7 var $plDescription = "Config management";
9 var $installationMethods = array();
11 var $selectedDistribution;
13 function __construct($config, $dn)
14 {
15 $this->config = &$config;
16 $this->listing = new ConfigManagementListing($this->config, get_userinfo());
17 $this->dataModel = new ConfigManagementDataModel();
19 // Load distributions
20 $rpc = $this->config->getRpcHandle();
21 $res = $rpc->getDistributions();
22 if(!$rpc->success()){
23 msg_dialog::display(_("Error"), sprintf(_("Failed to load distributions, error was '%s'!"), $rpc->get_error()),ERROR_DIALOG);
24 return(NULL);
25 }
26 foreach($res as $dist){
27 $this->dataModel->addItem('Distribution','/root', $dist);
29 // Load the releases for the current distribution
30 $releases = $rpc->getReleases($dist);
31 if(!$rpc->success()){
32 msg_dialog::display(_("Error"), sprintf(_("Failed to load releases, error was '%s'!"), $rpc->get_error()),ERROR_DIALOG);
33 return(NULL);
34 }
35 foreach($releases as $release){
36 $this->dataModel->addItem('Release',"/root/{$dist}", $release);
38 // Load packages
39 $packages = $rpc->getPackages($release);
40 if(!$rpc->success()){
41 msg_dialog::display(_("Error"), sprintf(_("Failed to load packages, error was '%s'!"), $rpc->get_error()),ERROR_DIALOG);
42 return(NULL);
43 }
44 foreach($packages as $package){
45 $this->dataModel->addItem('Package',"/root/{$dist}/{$release}", $package['name'], $package);
46 }
47 }
48 }
50 }
52 function save_object()
53 {
54 $this->listing->save_object();
55 $this->selectedDistribution = $this->listing->getSelectedDistribution();
56 $this->selectedRelease = $this->listing->getSelectedRelease();
58 $distList = $this->getDistList();
59 $releaseList = $this->getReleaseList();
61 if(!isset($releaseList[$this->selectedRelease])){
62 if(count($releaseList)){
63 $this->selectedRelease = key($releaseList);
64 }else{
65 $this->selectedRelease = "";
66 }
67 }
68 $this->listing->setDistribution($this->selectedDistribution);
69 $this->listing->setRelease($this->selectedRelease);
70 $this->listing->setDistributions($this->getDistList());
71 $this->listing->setReleases($this->getReleaseList());
72 }
75 /*! \brief Intializes this plugin
76 * All available installation methods will be loaded
77 */
78 function loadInstallationMethods()
79 {
80 // Reset erros
81 $this->rpcError = $this->initFailed = FALSE;
83 // Load configuration via rpc.
84 $rpc = $this->config->getRpcHandle();
86 // Populate install methods on success.
87 $res = $rpc->getSupportedInstallMethods();
88 if(!$rpc->success()){
89 $this->rpcError = TRUE;
90 $this->errorMessage = $rpc->get_error();;
91 return;
92 }
93 $this->installationMethods = $res;
94 if(!count($this->installationMethods)){
95 $this->errorMessage = _("No selectable install methods returned!");
96 msg_dialog::display(_("Setup"), $this->errorMessage , ERROR_DIALOG);
97 $this->initFailed = TRUE;
98 return;
99 }
100 }
103 function execute()
104 {
105 $list = $this->dataModel->getItemsByType('Package');
106 $rel = $this->selectedRelease;
107 $displayEntries = array();
108 foreach($list as $entry){
109 if($entry['parentPath'] == $rel){
110 $displayEntries[] = $entry;
111 }
112 }
113 return($this->listing->renderList());
114 }
117 function getReleaseList()
118 {
119 $res = array();
120 $dist = $this->selectedDistribution;
121 $list = $this->dataModel->getItemsByType('Release');
122 foreach($list as $base => $entry){
123 if($entry['parentPath'] != $dist) continue;
124 $res[$entry['path']] = $entry['name'];
125 }
126 return($res);
127 }
130 function getDistList()
131 {
132 $list = $this->dataModel->getItemsByType('Distribution');
133 $res = array();
134 foreach($list as $base => $entry){
135 $res[$entry['path']] = $entry['name'];
136 }
137 return($res);
138 }
141 function remove_lock()
142 {
143 }
145 public static function plInfo()
146 {
147 return (array(
148 "plShortName" => _("Config management"),
149 "plDescription" => _("Config management"),
150 "plSelfModify" => FALSE,
151 "plDepends" => array(),
152 "plPriority" => 0,
153 "plSection" => array("administration"),
154 "plCategory" => array(
155 "newConfigManagement" => array("description" => _("Config management"),
156 "objectClass" => "FAKE_OC_newConfigManagement")),
157 "plProvidedAcls"=> array()
158 ));
159 }
160 }
161 ?>