. * --------------------------------------------------------------------- */ /** * @since 9.1 */ if (!defined('GLPI_ROOT')) { die("Sorry. You can't access directly to this file"); } class ComputerAntivirus extends CommonDBChild { // From CommonDBChild static public $itemtype = 'Computer'; static public $items_id = 'computers_id'; public $dohistory = true; static function getTypeName($nb = 0) { return _n('Antivirus', 'Antiviruses', $nb); } function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { // can exists for template if (($item->getType() == 'Computer') && Computer::canView()) { $nb = 0; if ($_SESSION['glpishow_count_on_tabs']) { $nb = countElementsInTable('glpi_computerantiviruses', ["computers_id" => $item->getID(), 'is_deleted' => 0 ]); } return self::createTabEntry(self::getTypeName(Session::getPluralNumber()), $nb); } return ''; } static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) { self::showForComputer($item, $withtemplate); return true; } function defineTabs($options = []) { $ong = []; $this->addDefaultFormTab($ong); $this->addStandardTab('Log', $ong, $options); return $ong; } /** * Duplicate all antirivuses from a computer template to his clone * * @deprecated 9.5 * * @param $oldid * @param $newid **/ static function cloneComputer($oldid, $newid) { global $DB; Toolbox::deprecated('Use clone'); $result = $DB->request( [ 'FROM' => ComputerAntivirus::getTable(), 'WHERE' => ['computers_id' => $oldid], ] ); foreach ($result as $data) { $antirivus = new self(); unset($data['id']); $data['computers_id'] = $newid; $data = Toolbox::addslashes_deep($data); $antirivus->add($data); } } function rawSearchOptions() { $tab = []; $tab[] = [ 'id' => 'common', 'name' => __('Characteristics') ]; $tab[] = [ 'id' => '1', 'table' => $this->getTable(), 'field' => 'name', 'name' => __('Name'), 'datatype' => 'itemlink', 'massiveaction' => false, 'autocomplete' => true, ]; $tab[] = [ 'id' => '2', 'table' => $this->getTable(), 'field' => 'antivirus_version', 'name' => _n('Version', 'Versions', 1), 'datatype' => 'string', 'massiveaction' => false, 'autocomplete' => true, ]; $tab[] = [ 'id' => '3', 'table' => $this->getTable(), 'field' => 'signature_version', 'name' => __('Signature database version'), 'datatype' => 'string', 'massiveaction' => false, 'autocomplete' => true, ]; return $tab; } static public function rawSearchOptionsToAdd() { $tab = []; $name = _n('Antivirus', 'Antiviruses', Session::getPluralNumber()); $tab[] = [ 'id' => 'antivirus', 'name' => $name ]; $tab[] = [ 'id' => '167', 'table' => 'glpi_computerantiviruses', 'field' => 'name', 'name' => __('Name'), 'forcegroupby' => true, 'massiveaction' => false, 'datatype' => 'dropdown', 'joinparams' => [ 'jointype' => 'child' ] ]; $tab[] = [ 'id' => '168', 'table' => 'glpi_computerantiviruses', 'field' => 'antivirus_version', 'name' => _n('Version', 'Versions', 1), 'forcegroupby' => true, 'massiveaction' => false, 'datatype' => 'text', 'joinparams' => [ 'jointype' => 'child' ] ]; $tab[] = [ 'id' => '169', 'table' => 'glpi_computerantiviruses', 'field' => 'is_active', 'linkfield' => '', 'name' => __('Active'), 'datatype' => 'bool', 'joinparams' => [ 'jointype' => 'child' ], 'massiveaction' => false, 'forcegroupby' => true, 'searchtype' => ['equals'] ]; $tab[] = [ 'id' => '170', 'table' => 'glpi_computerantiviruses', 'field' => 'is_uptodate', 'linkfield' => '', 'name' => __('Is up to date'), 'datatype' => 'bool', 'joinparams' => [ 'jointype' => 'child' ], 'massiveaction' => false, 'forcegroupby' => true, 'searchtype' => ['equals'] ]; $tab[] = [ 'id' => '171', 'table' => 'glpi_computerantiviruses', 'field' => 'signature_version', 'name' => __('Signature database version'), 'forcegroupby' => true, 'massiveaction' => false, 'datatype' => 'text', 'joinparams' => [ 'jointype' => 'child' ] ]; $tab[] = [ 'id' => '172', 'table' => 'glpi_computerantiviruses', 'field' => 'date_expiration', 'name' => __('Expiration date'), 'forcegroupby' => true, 'massiveaction' => false, 'datatype' => 'date', 'joinparams' => [ 'jointype' => 'child' ] ]; return $tab; } /** * Display form for antivirus * * @param integer $ID id of the antivirus * @param array $options * * @return boolean TRUE if form is ok **/ function showForm($ID, $options = []) { if (!Session::haveRight("computer", READ)) { return false; } $comp = new Computer(); if ($ID > 0) { $this->check($ID, READ); $comp->getFromDB($this->fields['computers_id']); } else { $this->check(-1, CREATE, $options); $comp->getFromDB($options['computers_id']); } $this->showFormHeader($options); if ($this->isNewID($ID)) { echo ""; } echo ""; echo "".Computer::getTypeName(1).""; echo "".$comp->getLink().""; if (Plugin::haveImport()) { echo "".__('Automatic inventory').""; echo ""; if ($ID && $this->fields['is_dynamic']) { Plugin::doHook("autoinventory_information", $this); } else { echo __('No'); } echo ""; } else { echo ""; } echo "\n"; echo ""; echo "".__('Name').""; echo ""; Html::autocompletionTextField($this, "name"); echo ""; echo "".__('Active').""; echo ""; Dropdown::showYesNo('is_active', $this->fields['is_active']); echo ""; echo ""; echo "".Manufacturer::getTypeName(1).""; echo ""; Dropdown::show('Manufacturer', ['value' => $this->fields["manufacturers_id"]]); echo ""; echo "".__('Up to date').""; echo ""; Dropdown::showYesNo('is_uptodate', $this->fields['is_uptodate']); echo ""; echo ""; echo "". __('Antivirus version').""; echo ""; Html::autocompletionTextField($this, "antivirus_version"); echo ""; echo "".__('Signature database version').""; echo ""; Html::autocompletionTextField($this, "signature_version"); echo ""; echo ""; echo "".__('Expiration date').""; echo ""; Html::showDateField("date_expiration", ['value' => $this->fields['date_expiration']]); echo ""; echo ""; echo ""; $options['canedit'] = Session::haveRight("computer", UPDATE); $this->showFormButtons($options); return true; } /** * Print the computers antiviruses * * @param $comp Computer object * @param $withtemplate boolean Template or basic item (default 0) * * @return void **/ static function showForComputer(Computer $comp, $withtemplate = 0) { global $DB; $ID = $comp->fields['id']; if (!$comp->getFromDB($ID) || !$comp->can($ID, READ)) { return; } $canedit = $comp->canEdit($ID); if ($canedit && !(!empty($withtemplate) && ($withtemplate == 2))) { echo "
". ""; echo __('Add an antivirus'); echo "
\n"; } echo "
"; $result = $DB->request( [ 'FROM' => ComputerAntivirus::getTable(), 'WHERE' => [ 'computers_id' => $ID, 'is_deleted' => 0, ], ] ); echo ""; $colspan = 7; if (Plugin::haveImport()) { $colspan++; } echo ""; if ($result->numrows() != 0) { $header = ""; if (Plugin::haveImport()) { $header .= ""; } $header .= ""; $header .= ""; $header .= ""; $header .= ""; $header .= ""; $header .= ""; $header .= ""; echo $header; Session::initNavigateListItems(__CLASS__, //TRANS : %1$s is the itemtype name, // %2$s is the name of the item (used for headings of a list) sprintf(__('%1$s = %2$s'), Computer::getTypeName(1), $comp->getName())); $antivirus = new self(); foreach ($result as $data) { $antivirus->getFromDB($data['id']); echo ""; echo ""; if (Plugin::haveImport()) { echo ""; } echo ""; } else { echo ""; } echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; Session::addToNavigateListItems(__CLASS__, $data['id']); } echo $header; } else { echo ""; } echo "
".self::getTypeName($result->numrows()). "
".__('Name')."".__('Automatic inventory')."".Manufacturer::getTypeName(1)."".__('Antivirus version')."".__('Signature database version')."".__('Active')."".__('Up to date')."".__('Expiration date')."
".$antivirus->getLink()."".Dropdown::getYesNo($data['is_dynamic']).""; if ($data['manufacturers_id']) { echo Dropdown::getDropdownName('glpi_manufacturers', $data['manufacturers_id'])."".$data['antivirus_version']."".$data['signature_version']."".Dropdown::getYesNo($data['is_active'])."".Dropdown::getYesNo($data['is_uptodate'])."".Html::convDate($data['date_expiration'])."
".__('No item found')."
"; echo "
"; } }