.
* ---------------------------------------------------------------------
*/
if (!defined('GLPI_ROOT')) {
die("Sorry. You can't access this file directly");
}
/**
* Computer class
**/
class Computer extends CommonDBTM {
use Glpi\Features\DCBreadcrumb;
use Glpi\Features\Clonable;
// From CommonDBTM
public $dohistory = true;
static protected $forward_entity_to = ['Item_Disk','ComputerVirtualMachine',
'Item_SoftwareVersion', 'Infocom',
'NetworkPort', 'ReservationItem',
'Item_OperatingSystem'];
// Specific ones
///Device container - format $device = array(ID,"device type","ID in device table","specificity value")
public $devices = [];
static $rightname = 'computer';
protected $usenotepad = true;
public function getCloneRelations() :array {
return [
Item_OperatingSystem::class,
Item_Devices::class,
Infocom::class,
Item_Disk::class,
Item_SoftwareVersion::class,
Item_SoftwareLicense::class,
Contract_Item::class,
Document_Item::class,
NetworkPort::class,
Computer_Item::class,
Notepad::class,
KnowbaseItem_Item::class
];
}
static function getTypeName($nb = 0) {
return _n('Computer', 'Computers', $nb);
}
function useDeletedToLockIfDynamic() {
return false;
}
static function getMenuShorcut() {
return 'o';
}
function defineTabs($options = []) {
$ong = [];
$this->addDefaultFormTab($ong)
->addImpactTab($ong, $options)
->addStandardTab('Item_OperatingSystem', $ong, $options)
->addStandardTab('Item_Devices', $ong, $options)
->addStandardTab('Item_Disk', $ong, $options)
->addStandardTab('Item_SoftwareVersion', $ong, $options)
->addStandardTab('Computer_Item', $ong, $options)
->addStandardTab('NetworkPort', $ong, $options)
->addStandardTab('Infocom', $ong, $options)
->addStandardTab('Contract_Item', $ong, $options)
->addStandardTab('Document_Item', $ong, $options)
->addStandardTab('ComputerVirtualMachine', $ong, $options)
->addStandardTab('ComputerAntivirus', $ong, $options)
->addStandardTab('KnowbaseItem_Item', $ong, $options)
->addStandardTab('Ticket', $ong, $options)
->addStandardTab('Item_Problem', $ong, $options)
->addStandardTab('Change_Item', $ong, $options)
->addStandardTab('Link', $ong, $options)
->addStandardTab('Certificate_Item', $ong, $options)
->addStandardTab('Lock', $ong, $options)
->addStandardTab('Notepad', $ong, $options)
->addStandardTab('Reservation', $ong, $options)
->addStandardTab('Domain_Item', $ong, $options)
->addStandardTab('Appliance_Item', $ong, $options)
->addStandardTab('Log', $ong, $options);
return $ong;
}
function post_restoreItem() {
$comp_softvers = new Item_SoftwareVersion();
$comp_softvers->updateDatasForItem('Computer', $this->fields['id']);
}
function post_deleteItem() {
$comp_softvers = new Item_SoftwareVersion();
$comp_softvers->updateDatasForItem('Computer', $this->fields['id']);
}
function post_updateItem($history = 1) {
global $DB, $CFG_GLPI;
$changes = [];
$update_count = count($this->updates ?? []);
for ($i=0; $i < $update_count; $i++) {
// Update contact of attached items
if ($this->updates[$i] == 'contact_num' && $CFG_GLPI['is_contact_autoupdate']) {
$changes['contact_num'] = $this->fields['contact_num'];
}
if ($this->updates[$i] == 'contact' && $CFG_GLPI['is_contact_autoupdate']) {
$changes['contact'] = $this->fields['contact'];
}
// Update users and groups of attached items
if ($this->updates[$i] == 'users_id'
&& $CFG_GLPI['is_user_autoupdate']) {
$changes['users_id'] = $this->fields['users_id'];
}
if ($this->updates[$i] == 'groups_id'
&& $CFG_GLPI['is_group_autoupdate']) {
$changes['groups_id'] = $this->fields['groups_id'];
}
// Update state of attached items
if (($this->updates[$i] == 'states_id')
&& ($CFG_GLPI['state_autoupdate_mode'] < 0)) {
$changes['states_id'] = $this->fields['states_id'];
}
// Update loction of attached items
if ($this->updates[$i] == 'locations_id'
&& $CFG_GLPI['is_location_autoupdate']) {
$changes['locations_id'] = $this->fields['locations_id'];
}
}
if (count($changes)) {
$update_done = false;
// Propagates the changes to linked items
foreach ($CFG_GLPI['directconnect_types'] as $type) {
$items_result = $DB->request(
[
'SELECT' => ['items_id'],
'FROM' => Computer_Item::getTable(),
'WHERE' => [
'itemtype' => $type,
'computers_id' => $this->fields["id"],
'is_deleted' => 0
]
]
);
$item = new $type();
foreach ($items_result as $data) {
$tID = $data['items_id'];
$item->getFromDB($tID);
if (!$item->getField('is_global')) {
$changes['id'] = $item->getField('id');
if ($item->update($changes)) {
$update_done = true;
}
}
}
}
//fields that are not present for devices
unset($changes['groups_id']);
unset($changes['users_id']);
unset($changes['contact_num']);
unset($changes['contact']);
if (count($changes) > 0) {
// Propagates the changes to linked devices
foreach ($CFG_GLPI['itemdevices'] as $device) {
$item = new $device();
$devices_result = $DB->request(
[
'SELECT' => ['id'],
'FROM' => $item::getTable(),
'WHERE' => [
'itemtype' => self::getType(),
'items_id' => $this->fields["id"],
'is_deleted' => 0
]
]
);
foreach ($devices_result as $data) {
$tID = $data['id'];
$item->getFromDB($tID);
$changes['id'] = $item->getField('id');
if ($item->update($changes)) {
$update_done = true;
}
}
}
}
if ($update_done) {
if (isset($changes['contact']) || isset($changes['contact_num'])) {
Session::addMessageAfterRedirect(
__('Alternate username updated. The connected items have been updated using this alternate username.'),
true);
}
if (isset($changes['groups_id']) || isset($changes['users_id'])) {
Session::addMessageAfterRedirect(
__('User or group updated. The connected items have been moved in the same values.'),
true);
}
if (isset($changes['states_id'])) {
Session::addMessageAfterRedirect(
__('Status updated. The connected items have been updated using this status.'),
true);
}
if (isset($changes['locations_id'])) {
Session::addMessageAfterRedirect(
__('Location updated. The connected items have been moved in the same location.'),
true);
}
}
}
}
function prepareInputForAdd($input) {
if (isset($input["id"]) && ($input["id"] > 0)) {
$input["_oldID"] = $input["id"];
}
unset($input['id']);
unset($input['withtemplate']);
return $input;
}
function cleanDBonPurge() {
$this->deleteChildrenAndRelationsFromDb(
[
Certificate_Item::class,
Computer_Item::class,
Item_SoftwareLicense::class,
Item_SoftwareVersion::class,
ComputerAntivirus::class,
ComputerVirtualMachine::class,
Item_Disk::class,
Item_Project::class,
]
);
Item_Devices::cleanItemDeviceDBOnItemDelete($this->getType(), $this->fields['id'],
(!empty($this->input['keep_devices'])));
}
/**
* Print the computer form
*
* @param $ID integer ID of the item
* @param $options array
* - target for the Form
* - withtemplate template or basic computer
*
* @return boolean
**/
function showForm($ID, $options = []) {
$this->initForm($ID, $options);
$this->showFormHeader($options);
echo "
";
$rand = mt_rand();
$tplmark = $this->getAutofillMark('name', $options);
//TRANS: %1$s is a string, %2$s a second one without spaces between them : to change for RTL
echo "