ryxeo-glpi-git / htdocs / inc / software.class.php @ 1c14bcc4
Historique | Voir | Annoter | Télécharger (15,1 ko)
1 |
<?php
|
---|---|
2 |
|
3 |
|
4 |
/*
|
5 |
* @version $Id: software.class.php 7875 2009-01-23 15:16:47Z moyo $
|
6 |
-------------------------------------------------------------------------
|
7 |
GLPI - Gestionnaire Libre de Parc Informatique
|
8 |
Copyright (C) 2003-2009 by the INDEPNET Development Team.
|
9 |
|
10 |
http://indepnet.net/ http://glpi-project.org
|
11 |
-------------------------------------------------------------------------
|
12 |
|
13 |
LICENSE
|
14 |
|
15 |
This file is part of GLPI.
|
16 |
|
17 |
GLPI is free software; you can redistribute it and/or modify
|
18 |
it under the terms of the GNU General Public License as published by
|
19 |
the Free Software Foundation; either version 2 of the License, or
|
20 |
(at your option) any later version.
|
21 |
|
22 |
GLPI is distributed in the hope that it will be useful,
|
23 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
24 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
25 |
GNU General Public License for more details.
|
26 |
|
27 |
You should have received a copy of the GNU General Public License
|
28 |
along with GLPI; if not, write to the Free Software
|
29 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
30 |
--------------------------------------------------------------------------
|
31 |
*/
|
32 |
|
33 |
// ----------------------------------------------------------------------
|
34 |
// Original Author of file:
|
35 |
// Purpose of file:
|
36 |
// ----------------------------------------------------------------------
|
37 |
|
38 |
if (!defined('GLPI_ROOT')) { |
39 |
die("Sorry. You can't access directly to this file"); |
40 |
} |
41 |
|
42 |
/// Software class
|
43 |
class Software extends CommonDBTM { |
44 |
|
45 |
/**
|
46 |
* Constructor
|
47 |
**/
|
48 |
function Software() { |
49 |
$this->table = "glpi_software"; |
50 |
$this->type = SOFTWARE_TYPE; |
51 |
$this->dohistory = true; |
52 |
} |
53 |
|
54 |
function defineOnglets($withtemplate) { |
55 |
global $LANG, $CFG_GLPI; |
56 |
$ong[1] = $LANG["title"][26]; |
57 |
if (empty ($withtemplate)) { |
58 |
$ong[2] = $LANG["software"][19]; |
59 |
} |
60 |
if (haveRight("contract_infocom","r")){ |
61 |
$ong[4] = $LANG["Menu"][26]; |
62 |
} |
63 |
if (haveRight("document","r")){ |
64 |
$ong[5] = $LANG["Menu"][27]; |
65 |
} |
66 |
|
67 |
if (empty ($withtemplate)) { |
68 |
if (haveRight("show_all_ticket","1")){ |
69 |
$ong[6] = $LANG["title"][28]; |
70 |
} |
71 |
if (haveRight("link","r")){ |
72 |
$ong[7] = $LANG["title"][34]; |
73 |
} |
74 |
if (haveRight("notes","r")){ |
75 |
$ong[10] = $LANG["title"][37]; |
76 |
} |
77 |
if (haveRight("reservation_central", "r")){ |
78 |
$ong[11] = $LANG["Menu"][17]; |
79 |
} |
80 |
|
81 |
$ong[12] = $LANG["title"][38]; |
82 |
} |
83 |
return $ong; |
84 |
} |
85 |
|
86 |
function prepareInputForUpdate($input) { |
87 |
|
88 |
if (isset ($input['is_update']) && ! $input['is_update']) |
89 |
$input['update_software'] = -1; |
90 |
|
91 |
return $input; |
92 |
} |
93 |
|
94 |
function prepareInputForAdd($input) { |
95 |
|
96 |
if (isset ($input['is_update']) && !$input['is_update']) |
97 |
$input['update_software'] = -1; |
98 |
|
99 |
if (isset($input["ID"])&&$input["ID"]>0){ |
100 |
$input["_oldID"]=$input["ID"]; |
101 |
} |
102 |
unset($input['ID']); |
103 |
unset($input['withtemplate']); |
104 |
|
105 |
//If category was not set by user (when manually adding a user)
|
106 |
if (!isset($input["category"])||!$input["category"]) |
107 |
{ |
108 |
$softcatrule = new SoftwareCategoriesRuleCollection; |
109 |
$result = $softcatrule->processAllRules(null,null,$input); |
110 |
if (!empty($result) && isset($result["category"])){ |
111 |
$input["category"]=$result["category"]; |
112 |
} else {
|
113 |
$input["category"]=0; |
114 |
} |
115 |
} |
116 |
|
117 |
return $input; |
118 |
} |
119 |
function post_addItem($newID, $input) { |
120 |
global $DB; |
121 |
|
122 |
|
123 |
// Manage add from template
|
124 |
if (isset($input["_oldID"])){ |
125 |
// ADD Infocoms
|
126 |
$ic = new Infocom(); |
127 |
if ($ic->getFromDBforDevice(SOFTWARE_TYPE, $input["_oldID"])) { |
128 |
$ic->fields["FK_device"] = $newID; |
129 |
unset ($ic->fields["ID"]); |
130 |
$ic->addToDB();
|
131 |
} |
132 |
|
133 |
// ADD Contract
|
134 |
$query = "SELECT FK_contract from glpi_contract_device WHERE FK_device='" . $input["_oldID"] . "' AND device_type='" . SOFTWARE_TYPE . "';"; |
135 |
$result = $DB->query($query); |
136 |
if ($DB->numrows($result) > 0) { |
137 |
|
138 |
while ($data = $DB->fetch_array($result)) |
139 |
addDeviceContract($data["FK_contract"], SOFTWARE_TYPE, $newID); |
140 |
} |
141 |
|
142 |
// ADD Documents
|
143 |
$query = "SELECT FK_doc from glpi_doc_device WHERE FK_device='" . $input["_oldID"] . "' AND device_type='" . SOFTWARE_TYPE . "';"; |
144 |
$result = $DB->query($query); |
145 |
if ($DB->numrows($result) > 0) { |
146 |
|
147 |
while ($data = $DB->fetch_array($result)) |
148 |
addDeviceDocument($data["FK_doc"], SOFTWARE_TYPE, $newID); |
149 |
} |
150 |
} |
151 |
|
152 |
} |
153 |
|
154 |
function cleanDBonPurge($ID) { |
155 |
|
156 |
global $DB, $CFG_GLPI; |
157 |
|
158 |
$job = new Job(); |
159 |
$query = "SELECT * FROM glpi_tracking WHERE (computer = '$ID' AND device_type='" . SOFTWARE_TYPE . "')"; |
160 |
$result = $DB->query($query); |
161 |
|
162 |
if ($DB->numrows($result)) |
163 |
while ($data = $DB->fetch_array($result)) { |
164 |
if ($CFG_GLPI["keep_tracking_on_delete"] == 1) { |
165 |
$query = "UPDATE glpi_tracking SET computer = '0', device_type='0' WHERE ID='" . $data["ID"] . "';"; |
166 |
$DB->query($query); |
167 |
} else
|
168 |
$job->delete(array ( |
169 |
"ID" => $data["ID"] |
170 |
)); |
171 |
} |
172 |
|
173 |
$query = "DELETE FROM glpi_infocoms WHERE (FK_device = '$ID' AND device_type='" . SOFTWARE_TYPE . "')"; |
174 |
$result = $DB->query($query); |
175 |
|
176 |
$query = "DELETE FROM glpi_contract_device WHERE (FK_device = '$ID' AND device_type='" . SOFTWARE_TYPE . "')"; |
177 |
$result = $DB->query($query); |
178 |
|
179 |
$query = "select * from glpi_reservation_item where (device_type='" . SOFTWARE_TYPE . "' and id_device='$ID')"; |
180 |
if ($result = $DB->query($query)) { |
181 |
if ($DB->numrows($result) > 0) { |
182 |
$rr = new ReservationItem(); |
183 |
$rr->delete(array ( |
184 |
"ID" => $DB->result($result, |
185 |
0,
|
186 |
"ID"
|
187 |
))); |
188 |
} |
189 |
} |
190 |
|
191 |
// Delete all Licenses
|
192 |
$query2 = "SELECT ID FROM glpi_licenses WHERE (sID = '$ID')"; |
193 |
|
194 |
if ($result2 = $DB->query($query2)) { |
195 |
if ($DB->numrows($result2)) { |
196 |
$lic = new License; |
197 |
|
198 |
while ($data = $DB->fetch_array($result2)) { |
199 |
$lic->delete(array ( |
200 |
"ID" => $data["ID"] |
201 |
)); |
202 |
} |
203 |
} |
204 |
} |
205 |
} |
206 |
|
207 |
/**
|
208 |
* Print the printer form
|
209 |
*
|
210 |
*@param $target filename : where to go when done.
|
211 |
*@param $ID Integer : Id of the item to print
|
212 |
*@param $withtemplate integer template or basic item
|
213 |
*
|
214 |
*@return boolean item found
|
215 |
**/
|
216 |
function showForm($target, $ID, $withtemplate = '') { |
217 |
// Show Software or blank form
|
218 |
|
219 |
global $CFG_GLPI, $LANG; |
220 |
|
221 |
if (!haveRight("software", "r")) |
222 |
return false; |
223 |
|
224 |
$sw_spotted = false; |
225 |
$use_cache=true; |
226 |
if ((empty ($ID) && $withtemplate == 1) || $ID == -1) { |
227 |
$use_cache=false; |
228 |
if ($this->getEmpty()){ |
229 |
$sw_spotted = true; |
230 |
} |
231 |
} else {
|
232 |
if ($this->getFromDB($ID) && haveAccessToEntity($this->fields["FK_entities"])){ |
233 |
$sw_spotted = true; |
234 |
} |
235 |
} |
236 |
|
237 |
if ($sw_spotted) { |
238 |
$this->showOnglets($ID, $withtemplate, $_SESSION['glpi_onglet']); |
239 |
if (!empty ($withtemplate) && $withtemplate == 2) { |
240 |
$template = "newcomp"; |
241 |
$datestring = $LANG["computers"][14] . ": "; |
242 |
$date = convDateTime($_SESSION["glpi_currenttime"]); |
243 |
} |
244 |
elseif (!empty ($withtemplate) && $withtemplate == 1) { |
245 |
$template = "newtemplate"; |
246 |
$datestring = $LANG["computers"][14] . ": "; |
247 |
$date = convDateTime($_SESSION["glpi_currenttime"]); |
248 |
} else {
|
249 |
$datestring = $LANG["common"][26] . " : "; |
250 |
$date = convDateTime($this->fields["date_mod"]); |
251 |
$template = false; |
252 |
} |
253 |
|
254 |
echo "<div class='center'><form method='post' action=\"$target\">"; |
255 |
if (strcmp($template, "newtemplate") === 0) { |
256 |
echo "<input type=\"hidden\" name=\"is_template\" value=\"1\" />"; |
257 |
} |
258 |
|
259 |
echo "<input type='hidden' name='FK_entities' value='".$this->fields["FK_entities"]."'>"; |
260 |
|
261 |
echo "<table class='tab_cadre_fixe'>"; |
262 |
|
263 |
echo "<tr><th align='center' colspan='2' >"; |
264 |
if (!$template) { |
265 |
echo $LANG["common"][2]." ".$this->fields["ID"]; |
266 |
} elseif (strcmp($template, "newcomp") === 0) { |
267 |
echo $LANG["software"][42] . ": " . $this->fields["tplname"]; |
268 |
echo "<input type='hidden' name='tplname' value='" . $this->fields["tplname"] . "'>"; |
269 |
} elseif (strcmp($template, "newtemplate") === 0) { |
270 |
echo $LANG["common"][6] . " : "; |
271 |
autocompletionTextField("tplname", "glpi_software", "tplname", $this->fields["tplname"], 20,$this->fields["FK_entities"]); |
272 |
} |
273 |
if (isMultiEntitiesMode()){
|
274 |
echo " (".getDropdownName("glpi_entities",$this->fields["FK_entities"]).")"; |
275 |
} |
276 |
|
277 |
echo "</th><th colspan='2' align='center'>" . $datestring . $date; |
278 |
if (!$template && !empty ($this->fields['tplname'])) |
279 |
echo " (" . $LANG["common"][13] . ": " . $this->fields['tplname'] . ")"; |
280 |
echo "</th></tr>"; |
281 |
|
282 |
if (!$use_cache||!($CFG_GLPI["cache"]->start($ID . "_" . $_SESSION["glpilanguage"], "GLPI_" . $this->type))) { |
283 |
echo "<tr class='tab_bg_1'><td>" . $LANG["common"][16] . ": </td>"; |
284 |
echo "<td>"; |
285 |
autocompletionTextField("name", "glpi_software", "name", $this->fields["name"], 25,$this->fields["FK_entities"]); |
286 |
echo "</td>"; |
287 |
|
288 |
|
289 |
echo "<td>" . $LANG["common"][36] . ": </td><td>"; |
290 |
dropdownValue("glpi_dropdown_software_category", "category", $this->fields["category"]); |
291 |
echo "</td>"; |
292 |
|
293 |
echo "<tr class='tab_bg_1'><td>" . $LANG["software"][3] . ": </td><td>"; |
294 |
dropdownValue("glpi_dropdown_os", "platform", $this->fields["platform"]); |
295 |
echo "</td>"; |
296 |
|
297 |
echo "<td>" . $LANG["common"][5] . ": </td><td>"; |
298 |
dropdownValue("glpi_dropdown_manufacturer", "FK_glpi_enterprise", $this->fields["FK_glpi_enterprise"]); |
299 |
echo "</td></tr>"; |
300 |
|
301 |
echo "<tr class='tab_bg_1'>"; |
302 |
echo "<td >" . $LANG["common"][34] . ": </td>"; |
303 |
echo "<td >"; |
304 |
dropdownAllUsers("FK_users", $this->fields["FK_users"], 1, $this->fields["FK_entities"]); |
305 |
echo "</td>"; |
306 |
|
307 |
echo "<td>" . $LANG["common"][35] . ":</td><td>"; |
308 |
dropdownValue("glpi_groups", "FK_groups", $this->fields["FK_groups"], 1, $this->fields["FK_entities"]); |
309 |
echo "</td></tr>"; |
310 |
|
311 |
echo "<tr class='tab_bg_1'><td>" . $LANG["common"][10] . ": </td><td>"; |
312 |
dropdownUsersID("tech_num", $this->fields["tech_num"], "interface", 1, $this->fields["FK_entities"]); |
313 |
echo "</td>"; |
314 |
|
315 |
echo "<td>" . $LANG["common"][15] . ": </td><td>"; |
316 |
dropdownValue("glpi_dropdown_locations", "location", $this->fields["location"], 1, $this->fields["FK_entities"]); |
317 |
echo "</td></tr>"; |
318 |
|
319 |
// UPDATE
|
320 |
echo "<tr class='tab_bg_1'><td>" . $LANG["software"][29] . ":</td><td>"; |
321 |
dropdownYesNo("is_update",$this->fields['is_update']); |
322 |
echo " " . $LANG["pager"][2] . " "; |
323 |
dropdownValue("glpi_software", "update_software", $this->fields["update_software"]); |
324 |
echo "</td>"; |
325 |
|
326 |
echo "<td>" . $LANG["state"][0] . ":</td><td>"; |
327 |
dropdownValue("glpi_dropdown_state", "state", $this->fields["state"]); |
328 |
echo "</td></tr>"; |
329 |
|
330 |
echo "<tr class='tab_bg_1'><td>" . $LANG["software"][46] . ":</td><td>"; |
331 |
dropdownYesNo('helpdesk_visible',$this->fields['helpdesk_visible']); |
332 |
echo "</td>"; |
333 |
echo "<td colspan='2'></td></tr>"; |
334 |
|
335 |
echo "<tr class='tab_bg_1'><td valign='top'>"; |
336 |
echo $LANG["common"][25] . ": </td>"; |
337 |
echo "<td align='center' colspan='3'><textarea cols='50' rows='4' name='comments' >" . $this->fields["comments"] . "</textarea>"; |
338 |
echo "</td></tr>"; |
339 |
if ($use_cache){ |
340 |
$CFG_GLPI["cache"]->end(); |
341 |
} |
342 |
} |
343 |
|
344 |
if (haveRight("software", "w")) { |
345 |
echo "<tr>"; |
346 |
|
347 |
if ($template) { |
348 |
|
349 |
if (empty ($ID) || $withtemplate == 2) { |
350 |
echo "<td class='tab_bg_2' align='center' colspan='4'>\n"; |
351 |
echo "<input type='hidden' name='ID' value=$ID>"; |
352 |
echo "<input type='submit' name='add' value=\"" . $LANG["buttons"][8] . "\" class='submit'>"; |
353 |
echo "</td>\n"; |
354 |
} else {
|
355 |
echo "<td class='tab_bg_2' align='center' colspan='4'>\n"; |
356 |
echo "<input type='hidden' name='ID' value=$ID>"; |
357 |
echo "<input type='submit' name='update' value=\"" . $LANG["buttons"][7] . "\" class='submit'>"; |
358 |
echo "</td>\n"; |
359 |
} |
360 |
} else {
|
361 |
|
362 |
echo "<td class='tab_bg_2'> </td>"; |
363 |
echo "<td class='tab_bg_2' valign='top'>"; |
364 |
echo "<input type='hidden' name='ID' value=\"$ID\">\n"; |
365 |
echo "<div class='center'><input type='submit' name='update' value=\"" . $LANG["buttons"][7] . "\" class='submit'></div>"; |
366 |
echo "</td>"; |
367 |
echo "<td class='tab_bg_2' valign='top' colspan='2'>\n"; |
368 |
echo "<div class='center'>"; |
369 |
if (!$this->fields["deleted"]) |
370 |
echo "<input type='submit' name='delete' value=\"" . $LANG["buttons"][6] . "\" class='submit'>"; |
371 |
else {
|
372 |
echo "<input type='submit' name='restore' value=\"" . $LANG["buttons"][21] . "\" class='submit'>"; |
373 |
echo " <input type='submit' name='purge' value=\"" . $LANG["buttons"][22] . "\" class='submit'>"; |
374 |
} |
375 |
echo "</div>"; |
376 |
echo "</td>"; |
377 |
|
378 |
} |
379 |
echo "</tr>"; |
380 |
} |
381 |
echo "</table></form></div>"; |
382 |
|
383 |
return true; |
384 |
} else {
|
385 |
echo "<div class='center'><strong>".$LANG["common"][54]."</strong></div>"; |
386 |
return false; |
387 |
} |
388 |
|
389 |
} |
390 |
|
391 |
// SPECIFIC FUNCTIONS
|
392 |
/**
|
393 |
* Count Installations of a software
|
394 |
*
|
395 |
* @return integer installation number
|
396 |
*/
|
397 |
function countInstallations() { |
398 |
global $DB; |
399 |
$query = "SELECT * FROM glpi_inst_software WHERE (sID = '" . $this->fields["ID"] . "')"; |
400 |
if ($result = $DB->query($query)) { |
401 |
$number = $DB->numrows($result); |
402 |
return $number; |
403 |
} else {
|
404 |
return false; |
405 |
} |
406 |
} |
407 |
} |
408 |
/// License class
|
409 |
class License extends CommonDBTM { |
410 |
|
411 |
/**
|
412 |
* Constructor
|
413 |
**/
|
414 |
function License() { |
415 |
$this->table = "glpi_licenses"; |
416 |
} |
417 |
|
418 |
function prepareInputForUpdate($input) { |
419 |
if (empty ($input['expire'])) |
420 |
unset ($input['expire']); |
421 |
if (!isset ($input['expire']) || $input['expire'] == "0000-00-00"){ |
422 |
$input['expire'] = "NULL"; |
423 |
} |
424 |
if (isset ($input['oem']) && !$input['oem']) |
425 |
$input['oem_computer'] = -1; |
426 |
// Backup initial values
|
427 |
if (isset($input['expire'])){ |
428 |
$this->getFromDB($input['ID']); |
429 |
$input['_expire']=$this->fields['expire']; |
430 |
} |
431 |
|
432 |
return $input; |
433 |
} |
434 |
|
435 |
|
436 |
function post_updateItem($input,$updates,$history=1) { |
437 |
// Clean end alert if expire is after old one
|
438 |
if ((in_array('expire',$updates) |
439 |
&& ($input['_expire'] < $this->fields['expire'] )) |
440 |
){ |
441 |
$alert=new Alert(); |
442 |
$alert->clear($this->type,$this->fields['ID'],ALERT_END); |
443 |
} |
444 |
} |
445 |
|
446 |
function prepareInputForAdd($input) { |
447 |
if (empty ($input['expire']) || $input['expire'] == "0000-00-00" || $input['expire'] == "NULL") |
448 |
unset ($input['expire']); |
449 |
if (isset($input['oem']) && !$input['oem']){ |
450 |
$input['oem_computer'] = -1; |
451 |
} |
452 |
if (!isset($input['oem_computer']) || $input['oem_computer'] == 0){ |
453 |
$input['oem_computer'] = -1; |
454 |
} |
455 |
if (!isset($input['version'])){ |
456 |
$input['version'] = ''; |
457 |
} |
458 |
unset ($input["form"]); |
459 |
unset ($input["withtemplate"]); |
460 |
unset ($input["lID"]); |
461 |
return $input; |
462 |
} |
463 |
|
464 |
function post_addItem($newID, $input) { |
465 |
// Add license but not for unglobalize system
|
466 |
if (!isset ($input["_duplicate_license"]) && isset($input['oem']) && isset($input['oem_computer']) && $input['oem'] && $input['oem_computer'] > 0){ |
467 |
installSoftware($input['oem_computer'], $newID); |
468 |
} |
469 |
|
470 |
$type = SOFTWARE_TYPE; |
471 |
$dupid = $this->fields["sID"]; |
472 |
if (isset ($input["_duplicate_license"])) { |
473 |
$type = LICENSE_TYPE; |
474 |
$dupid = $input["_duplicate_license"]; |
475 |
} |
476 |
|
477 |
// Add infocoms if exists for the licence
|
478 |
$ic = new Infocom(); |
479 |
if ($ic->getFromDBforDevice($type, $dupid)) { |
480 |
unset ($ic->fields["ID"]); |
481 |
$ic->fields["FK_device"] = $newID; |
482 |
$ic->fields["device_type"] = LICENSE_TYPE; |
483 |
$ic->addToDB();
|
484 |
} |
485 |
} |
486 |
|
487 |
function cleanDBonPurge($ID) { |
488 |
|
489 |
global $DB; |
490 |
|
491 |
$query = "DELETE FROM glpi_infocoms WHERE (FK_device = '$ID' AND device_type='" . LICENSE_TYPE . "')"; |
492 |
$result = $DB->query($query); |
493 |
|
494 |
// Delete Installations
|
495 |
$query2 = "DELETE FROM glpi_inst_software WHERE (license = '$ID')"; |
496 |
$DB->query($query2); |
497 |
} |
498 |
|
499 |
} |
500 |
?>
|