Code

Updated handler name
[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     $items  = array();
22     if(isset($res['XML'][0]['RESULT'][0]['HIT'])){
23       $items = $res['XML'][0]['RESULT'][0]['HIT'];
24     }
25     return($items);
26   }
29   /* @brief Create a license pool at Opsi server.
30    * @param licensePoolId The name of the pool (optional).
31    * @param description The description of the pool (optional).
32    * @param productIds A list of assigned porducts of the pool (optional).
33    * @param windowsSoftwareIds A list of windows software Ids associated to the pool (optional).
34    */
35   function createPool($poolId,$desc = "",$products = array(),$softwareIds = array())
36   {
37     $data= array();
38     $data['licensePoolId']        = htmlentities($poolId);
39     if(!empty($desc)){
40       $data['description']        = htmlentities($desc);
41     }
42     if(count($products)){
43       $data['productIds']         = $products;
44     }
45     if(count($softwareIds)){
46       $data['windowsSoftwareIds'] = $softwareIds;
47     }
49     $res = $this->send_data("gosa_opsi_createLicensePool",$this->target,$data,TRUE);
50     if(isset($res['XML'][0]['ANSWER_OPSI_CREATELICENSEPOOL'])){
51       return(TRUE);
52     }
53     return(FALSE);
54   }
57   /* 
58    * @brief Return productIds, windowsSoftwareIds and description for a given licensePoolId
59    * @param licensePoolId The name of the pool.
60    */
61   function getPool($licensePoolId)
62   {
63     $data= array();
64     $data['licensePoolId'] = htmlentities($licensePoolId);
65     $res = $this->send_data("gosa_opsi_getLicensePool_hash",$this->target,$data,TRUE);
66     
67     print_a($res);
69     if(isset($res['XML'][0]['ANSWER_OPSI_GETLICENSEPOOL_HASH'])){
70       $item = array();
71       foreach(array("LICENSEPOOLID"       => "licensePoolId", 
72                     "DESCRIPTION"         => "description",
73                     "WINDOWSSOFTWAREIDS"  => "windowsSoftwareIds",
74                     "PRODUCTIDS"          => "productIds") as $source => $target){
75         if(isset($res['XML'][0][$source])){
76           foreach($res['XML'][0][$source] as $data){
77             $item[$target][] = $res['XML'][0][$source][0]['VALUE'];
78           }
79         }
80       }
81       return($item);
82     }
83     return(FALSE);
84   }
87   /*
88    * @brief 
89    *    Delete licnese pool by license pool Id. 
90    *    A pool can only be deleted if there are no software licenses bound to the pool.
91    *    The fixed parameter deleteLicenses=True specifies that 
92    *      all software licenses bound to the pool are being deleted.
93    * @param licensePoolId The name of the pool.
94    */
95   function deletePool($poolId, $force = FALSE)
96   {
97     $data= array();
98     $data['licensePoolId']        = htmlentities($poolId);
99     if($force){
100       $data['deleteLicenses']     = 'TRUE';
101     }
102     $res = $this->send_data("gosa_opsi_deleteLicensePool",$this->target,$data,TRUE);
103     if(isset($res['XML'][0]['ANSWER_OPSI_DELETELICENSEPOOL'])){
104       return(TRUE);
105     }
106     return(FALSE);
107   }
110   /*******************
111    * LICENSES
112    *******************/
114   /*  
115    * @brief 
116    *     Create a license contract, create a software 
117    *       license and add the software license to the license pool
118    * @param licensePoolId The name of the pool the license should be assigned.
119    * @param licenseKey The license key.
120    * @param licenseTyp Typ of a licnese, either "OEM", "VOLUME" or "RETAIL" 
121    * @param partner Name of the license partner (optional).
122    * @param conclusionDate Date of conclusion of license contract (optional)
123    * @param notificationDate Date of notification that license is running out soon (optional).
124    * @param notes This is the place for some notes (optional)
125    * @param softwareLicenseId Identificator of a license (optional).
126    * @param maxInstallations The number of clients use this license (optional).
127    * @param boundToHost The name of the client the license is bound to (optional).
128    * @param expirationDate The date when the license is running down (optional).
129    */
130   function createLicense($poolId, $licenseKey,$licenseTyp = "",  
131         $partner = "",
132         $conclusionDate = "",
133         $notificationDate ="",
134         $notes = "", 
135         $softwareLicenseId = "",
136         $maxInstallations = "",
137         $boudToHost = "",
138         $expirationDate = "")
139   {
141     $data= array();
142     $data['licensePoolId']    = htmlentities($poolId);
143     $data['licenseKey']        = htmlentities($licenseKey);
145     // Append optional attributes 
146     foreach(array("partner","conclusionDate","notificationDate","notes","softwareLicenseId",
147           "licenseTyp","maxInstallations","boudToHost","expirationDate") as $attr){
148       if(!empty($$attr)){
149         $data[$attr] = $$attr;
150       }
151     }
153     $res = $this->send_data("gosa_opsi_createLicense",$this->target,$data,TRUE);
154     if(isset($res['XML'][0]['ANSWER_OPSI_GETSOFTWARELICENSE_HASH'])){
155       return(TRUE);
156     }
157     return(FALSE);
158   }
161   /* @brief     Returns expirationDate, boundToHost, maxInstallation, licenseTyp, 
162    *             licensePoolIds and licenseKeys for a given softwareLicense Id.
163    * @param softwareLicenseId Identificator of a license.
164    */
165   function getLicense($softwareLicenseId)
166   {
167     $data= array();
168     $data['softwareLicenseId'] = htmlentities($softwareLicenseId);
169     $res = $this->send_data("gosa_opsi_getSoftwareLicense_hash",$this->target,$data,TRUE);
170    
171     if(isset($res['XML'][0]['ANSWER_OPSI_GETSOFTWARELICENSE_HASH'])){
172       return($res);
173     }
174     return(FALSE);
175   }
178   /* 
179    * @brief Returns softwareLicenseId, notes, licenseKey, hostId and licensePoolId for optional given licensePoolId and hostId
180    * @param hostid Something like client_1.intranet.mydomain.de (optional).
181    * @param licensePoolId The name of the pool (optional).
182    */
183   function getLicenseUsage($hostId = "", $licensePoolId = "")
184   {
185     $data= array();
186     if(!empty($hostId)){
187       $data['hostId'] = htmlentities($hostId);
188     }
189     if(!empty($hostId)){
190       $data['licensePoolId'] = htmlentities($licensePoolId);
191     }
193     $res = $this->send_data("gosa_opsi_getSoftwareLicenseUsages_listOfHashes",$this->target,$data,TRUE);
194     if(isset($res['XML'][0]['ANSWER_OPSI_GETSOFTWARELICENSEUSAGES_LISTOFHASHES'])){
195       return($res['XML'][0]['RESULT']);
196     }
197     return(FALSE);
198   }
201   /* @brief   Assigns a software license to a host
202    * @param   hostId Something like client_1.intranet.mydomain.de
203    * @param   licensePoolId The name of the pool.
204    */
205   function addLicenseToHost($licensePoolId,$hostId)
206   {
207     $data= array();
208     $data['licensePoolId'] = htmlentities($licensePoolId);
209     $data['hostId'] = htmlentities($hostId);
210     $res = $this->send_data("gosa_opsi_assignSoftwareLicenseToHost",$this->target,$data,TRUE);
211     if(isset($res['XML'][0]['ANSWER_OPSI_ASSIGNSOFTWARELICENSETOHOST'])){
212       return(TRUE);
213     }
214     return(FALSE);
215   }
218   /* 
219    * @brief   Unassign a software license from a host.
220    * @param   hostid Something like client_1.intranet.mydomain.de
221    * @param   licensePoolId The name of the pool.
222    */
223   function removeLicenseFromHost($licensePoolId,$hostId)
224   {
225     $data= array();
226     $data['licensePoolId'] = htmlentities($licensePoolId);
227     $data['hostId'] = htmlentities($hostid);
228     $res = $this->send_data("gosa_opsi_unassignSoftwareLicenseFromHost",$this->target,$data,TRUE);
229     if(isset($res['XML'][0]['ANSWER_OPSI_UNASSIGNSOFTWARELICENSEFROMHOST'])){
230       return(TRUE);
231     }
232     return(FALSE);
233   }
236   /* 
237    * @brief Unassign all software licenses from a host
238    * @param hostid Something like client_1.intranet.mydomain.de
239    */
240   function removeAllLicensesFromHost($hostId)
241   {
242     $data= array();
243     $data['hostId'] = htmlentities($hostid);
244     $res = $this->send_data("gosa_opsi_unassignAllSoftwareLicensesFromHost",$this->target,$data,TRUE);
245     if(isset($res['XML'][0]['ANSWER_OPSI_UNASSIGNALLSOFTWARELICENSESFROMHOST'])){
246       return(TRUE);
247     }
248     return(FALSE);
249   }
252   /* @brief 
253    *   Returns the assigned licensePoolId and licenses, 
254    *    how often the product is installed and at which host
255    *    and the number of max and remaining installations for a given OPSI product.
256    * @param productId Identificator of an OPSI product.
257    */
258   function getLicensesForProduct($productId)
259   {
260     $data= array();
261     $data['productId'] = htmlentities($productId);
262     $res = $this->send_data("gosa_opsi_getLicenseInformationForProduct",$this->target,$data,TRUE);
263     if(isset($res['XML'][0]['ANSWER_OPSI_UNASSIGNALLSOFTWARELICENSESFROMHOST'])){
264       return(TRUE);
265     }
266     return(FALSE);
267   }
270 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
271 ?>