Code

Updated licenses
[gosa.git] / gosa-plugins / opsi / admin / opsiLicenses / class_opsiLicenseHandler.inc
1 <?php
3 class opsiLicenceHandler extends opsi  {
7   /*******************
8    * POOLs
9    *******************/
11   protected $use_alternative_xml_parse_method = TRUE;
14   /* @brief   Returns licensePoolId, description, productIds and windowsSoftwareIds 
15    *           for all found license pools.
16    */
17   function listPools()
18   {
19     $data= array();
20     $res = $this->send_data("gosa_opsi_getLicensePools_listOfHashes",$this->target,$data,TRUE);
21     
22     $items  = array();
23     if(isset($res['XML'][0]['RESULT'][0]['HIT'])){
24       $items = $res['XML'][0]['RESULT'][0]['HIT'];
25       $data =array();
26       foreach($items as $item){
27         $entry = array();
28         foreach(
29           array(
30             "DESCRIPTION"       => "description",
31             "LICENSEPOOLID"     => "cn",
32             "PRODUCTIDS"        => "productId",
33             "WINDOWSSOFTWAREIDS"=> "softwareId") as $source => $dest){
34         
35           if(isset($item[$source])){
36             $entry[$dest] = array('count' => 0);
37             foreach($item[$source] as $obj){
38               $entry[$dest][] = $obj['VALUE'];
39             }
40             $entry[$dest]['count'] = (count($entry[$dest]) -1 );
41           } 
42         }
43         $data[] =$entry;
44       }
45       return($data);
46     }
47     return(FALSE);
48   }
51   /* @brief Create a license pool at Opsi server.
52    * @param licensePoolId The name of the pool (optional).
53    * @param description The description of the pool (optional).
54    * @param productIds A list of assigned porducts of the pool (optional).
55    * @param windowsSoftwareIds A list of windows software Ids associated to the pool (optional).
56    */
57   function createPool($poolId,$desc = "",$products = array(),$softwareIds = array())
58   {
59     $data= array();
60     $data['licensePoolId']        = htmlentities($poolId);
61     if(!empty($desc)){
62       $data['description']        = htmlentities($desc);
63     }
64     if(count($products)){
65       $data['productIds']         = $products;
66     }
67     if(count($softwareIds)){
68       $data['windowsSoftwareIds'] = $softwareIds;
69     }
71     $res = $this->send_data("gosa_opsi_createLicensePool",$this->target,$data,TRUE);
72     if(isset($res['XML'][0]['ANSWER_OPSI_CREATELICENSEPOOL'])){
73       return(TRUE);
74     }
75     return(FALSE);
76   }
79   /* 
80    * @brief Return productIds, windowsSoftwareIds and description for a given licensePoolId
81    * @param licensePoolId The name of the pool.
82    */
83   function getPool($licensePoolId)
84   {
85     $data= array();
86     $data['licensePoolId'] = htmlentities($licensePoolId);
87     $res = $this->send_data("gosa_opsi_getLicensePool_hash",$this->target,$data,TRUE);
88     if(isset($res['XML'][0]['ANSWER_OPSI_GETLICENSEPOOL_HASH'])){
89       $item = array();
90       foreach(array("LICENSEPOOLID"       => "cn", 
91                     "DESCRIPTION"         => "description",
92                     "WINDOWSSOFTWAREIDS"  => "softwareId",
93                     "PRODUCTIDS"          => "productId") as $source => $target){
94         if(isset($res['XML'][0][$source])){
95           
96           $item[$target] = array('count' => 0);
97           foreach($res['XML'][0][$source] as $data){
98             $item[$target][] = $data['VALUE'];
99           }
100           $item[$target]['count'] = count($item[$target]) -1 ;
101         }
102       }
103       return($item);
104     }
105     return(FALSE);
106   }
109   /*
110    * @brief 
111    *    Delete licnese pool by license pool Id. 
112    *    A pool can only be deleted if there are no software licenses bound to the pool.
113    *    The fixed parameter deleteLicenses=True specifies that 
114    *      all software licenses bound to the pool are being deleted.
115    * @param licensePoolId The name of the pool.
116    */
117   function deletePool($poolId, $force = FALSE)
118   {
119     $data= array();
120     $data['licensePoolId']        = htmlentities($poolId);
121     if($force){
122       $data['deleteLicenses']     = 'TRUE';
123     }
124     $res = $this->send_data("gosa_opsi_deleteLicensePool",$this->target,$data,TRUE);
125     if(isset($res['XML'][0]['ANSWER_OPSI_DELETELICENSEPOOL'])){
126       return(TRUE);
127     }
128     return(FALSE);
129   }
132   /*******************
133    * LICENSES
134    *******************/
136   /*  
137    * @brief 
138    *     Create a license contract, create a software 
139    *       license and add the software license to the license pool
140    * @param licensePoolId The name of the pool the license should be assigned.
141    * @param licenseKey The license key.
142    * @param licenseTyp Typ of a licnese, either "OEM", "VOLUME" or "RETAIL" 
143    * @param partner Name of the license partner (optional).
144    * @param conclusionDate Date of conclusion of license contract (optional)
145    * @param notificationDate Date of notification that license is running out soon (optional).
146    * @param notes This is the place for some notes (optional)
147    * @param softwareLicenseId Identificator of a license (optional).
148    * @param maxInstallations The number of clients use this license (optional).
149    * @param boundToHost The name of the client the license is bound to (optional).
150    * @param expirationDate The date when the license is running down (optional).
151    */
152   function createLicense($poolId, $licenseKey,$licenseTyp = "",  
153         $partner = "",
154         $conclusionDate = "",
155         $notificationDate ="",
156         $notes = "", 
157         $softwareLicenseId = "",
158         $maxInstallations = "",
159         $boudToHost = "",
160         $expirationDate = "")
161   {
163     $data= array();
164     $data['licensePoolId']    = htmlentities($poolId);
165     $data['licenseKey']        = htmlentities($licenseKey);
167     // Append optional attributes 
168     foreach(array("partner","conclusionDate","notificationDate","notes","softwareLicenseId",
169           "licenseTyp","maxInstallations","boudToHost","expirationDate") as $attr){
170       if(!empty($$attr)){
171         $data[$attr] = $$attr;
172       }
173     }
175     $res = $this->send_data("gosa_opsi_createLicense",$this->target,$data,TRUE);
176     if(isset($res['XML'][0]['ANSWER_OPSI_GETSOFTWARELICENSE_HASH'])){
177       return(TRUE);
178     }
179     return(FALSE);
180   }
183   /* @brief     Returns expirationDate, boundToHost, maxInstallation, licenseTyp, 
184    *             licensePoolIds and licenseKeys for a given softwareLicense Id.
185    * @param softwareLicenseId Identificator of a license.
186    */
187   function getLicense($softwareLicenseId)
188   {
189     $data= array();
190     $data['softwareLicenseId'] = htmlentities($softwareLicenseId);
191     $res = $this->send_data("gosa_opsi_getSoftwareLicense_hash",$this->target,$data,TRUE);
192    
193     if(isset($res['XML'][0]['ANSWER_OPSI_GETSOFTWARELICENSE_HASH'])){
194       return($res);
195     }
196     return(FALSE);
197   }
200   /* 
201    * @brief Returns softwareLicenseId, notes, licenseKey, hostId and licensePoolId for optional given licensePoolId and hostId
202    * @param hostid Something like client_1.intranet.mydomain.de (optional).
203    * @param licensePoolId The name of the pool (optional).
204    */
205   function getLicenseUsage($hostId = "", $licensePoolId = "")
206   {
207     $data= array();
208     if(!empty($hostId)){
209       $data['hostId'] = htmlentities($hostId);
210     }
211     if(!empty($hostId)){
212       $data['licensePoolId'] = htmlentities($licensePoolId);
213     }
215     $res = $this->send_data("gosa_opsi_getSoftwareLicenseUsages_listOfHashes",$this->target,$data,TRUE);
216     if(isset($res['XML'][0]['ANSWER_OPSI_GETSOFTWARELICENSEUSAGES_LISTOFHASHES'])){
218       $items = array();
219       foreach($res['XML'][0]['RESULT'][0]['HIT'] as $entry){
220         $item = array();
221         foreach(array(
222               "HOSTID"              => "hostId",
223               "LICENSEKEY"          => "licenseKey",
224               "LICENSEPOOLID"       => "licensePoolId",
225               "NOTES"               => "notes",
226               "SOFTWARELICENSEID"   => "softwareLicenseId") as $source => $target){
227           if(isset($entry[$source])){
229             $item[$target] = array('count' => 0);
230             foreach($entry[$source] as $data){
231               $item[$target][] = $data['VALUE'];
232             }
233             $item[$target]['count'] = count($item[$target]) -1 ;
234           }
235         }
236         $items[]  = $item;
237       }
238       return($items);
239     }
240     return(FALSE);
241   }
244   /* @brief   Assigns a software license to a host
245    * @param   hostId Something like client_1.intranet.mydomain.de
246    * @param   licensePoolId The name of the pool.
247    */
248   function addLicenseToHost($licensePoolId,$hostId)
249   {
250     $data= array();
251     $data['licensePoolId'] = htmlentities($licensePoolId);
252     $data['hostId'] = htmlentities($hostId);
253     $res = $this->send_data("gosa_opsi_assignSoftwareLicenseToHost",$this->target,$data,TRUE);
254     if(isset($res['XML'][0]['ANSWER_OPSI_ASSIGNSOFTWARELICENSETOHOST'])){
255       return(TRUE);
256     }
257     return(FALSE);
258   }
261   /* 
262    * @brief   Unassign a software license from a host.
263    * @param   hostid Something like client_1.intranet.mydomain.de
264    * @param   licensePoolId The name of the pool.
265    */
266   function removeLicenseFromHost($licensePoolId,$hostId)
267   {
268     $data= array();
269     $data['licensePoolId'] = htmlentities($licensePoolId);
270     $data['hostId'] = htmlentities($hostid);
271     $res = $this->send_data("gosa_opsi_unassignSoftwareLicenseFromHost",$this->target,$data,TRUE);
272     if(isset($res['XML'][0]['ANSWER_OPSI_UNASSIGNSOFTWARELICENSEFROMHOST'])){
273       return(TRUE);
274     }
275     return(FALSE);
276   }
279   /* 
280    * @brief Unassign all software licenses from a host
281    * @param hostid Something like client_1.intranet.mydomain.de
282    */
283   function removeAllLicensesFromHost($hostId)
284   {
285     $data= array();
286     $data['hostId'] = htmlentities($hostid);
287     $res = $this->send_data("gosa_opsi_unassignAllSoftwareLicensesFromHost",$this->target,$data,TRUE);
288     if(isset($res['XML'][0]['ANSWER_OPSI_UNASSIGNALLSOFTWARELICENSESFROMHOST'])){
289       return(TRUE);
290     }
291     return(FALSE);
292   }
295   /* @brief 
296    *   Returns the assigned licensePoolId and licenses, 
297    *    how often the product is installed and at which host
298    *    and the number of max and remaining installations for a given OPSI product.
299    * @param productId Identificator of an OPSI product.
300    */
301   function getLicensesForProduct($productId)
302   {
303     $data= array();
304     $data['productId'] = htmlentities($productId);
305     $res = $this->send_data("gosa_opsi_getLicenseInformationForProduct",$this->target,$data,TRUE);
306     if(isset($res['XML'][0]['ANSWER_OPSI_UNASSIGNALLSOFTWARELICENSESFROMHOST'])){
307       return($res['XML'][0]);
308     }
309     return(FALSE);
310   }
313 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
314 ?>