. * --------------------------------------------------------------------- */ if (!defined('GLPI_ROOT')) { die("Sorry. You can't access this file directly"); } /** * Class to link a certificate to an item */ class Certificate_Item extends CommonDBRelation { // From CommonDBRelation static public $itemtype_1 = "Certificate"; static public $items_id_1 = 'certificates_id'; static public $take_entity_1 = false; static public $itemtype_2 = 'itemtype'; static public $items_id_2 = 'items_id'; static public $take_entity_2 = true; /** * @since 9.2 * **/ function getForbiddenStandardMassiveAction() { $forbidden = parent::getForbiddenStandardMassiveAction(); $forbidden[] = 'update'; return $forbidden; } /** * @param CommonDBTM $item */ static function cleanForItem(CommonDBTM $item) { $temp = new self(); $temp->deleteByCriteria(['itemtype' => $item->getType(), 'items_id' => $item->getField('id')]); } /** * @param CommonGLPI $item * @param int $withtemplate * @return string */ function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { if (!$withtemplate) { if ($item->getType() == 'Certificate' && count(Certificate::getTypes(false))) { if ($_SESSION['glpishow_count_on_tabs']) { return self::createTabEntry(_n('Associated item', 'Associated items', Session::getPluralNumber()), self::countForMainItem($item)); } return _n('Associated item', 'Associated items', Session::getPluralNumber()); } else if (in_array($item->getType(), Certificate::getTypes(true)) && Certificate::canView()) { if ($_SESSION['glpishow_count_on_tabs']) { return self::createTabEntry(Certificate::getTypeName(2), self::countForItem($item)); } return Certificate::getTypeName(2); } } return ''; } /** * @param CommonGLPI $item * @param int $tabnum * @param int $withtemplate * @return bool */ static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) { if ($item->getType() == 'Certificate') { self::showForCertificate($item); } else if (in_array($item->getType(), Certificate::getTypes(true))) { self::showForItem($item); } return true; } /** * @param $certificates_id * @param $items_id * @param $itemtype * @return bool */ function getFromDBbyCertificatesAndItem($certificates_id, $items_id, $itemtype) { $certificate = new self(); $certificates = $certificate->find([ 'certificates_id' => $certificates_id, 'itemtype' => $itemtype, 'items_id' => $items_id ]); if (count($certificates) != 1) { return false; } $cert = current($certificates); $this->fields = $cert; return true; } /** * Link a certificate to an item * * @since 9.2 * @param $values */ function addItem($values) { $this->add(['certificates_id' => $values["certificates_id"], 'items_id' => $values["items_id"], 'itemtype' => $values["itemtype"]]); } /** * Delete a certificate link to an item * * @since 9.2 * * @param integer $certificates_id the certificate ID * @param integer $items_id the item's id * @param string $itemtype the itemtype */ function deleteItemByCertificatesAndItem($certificates_id, $items_id, $itemtype) { if ($this->getFromDBbyCertificatesAndItem($certificates_id, $items_id, $itemtype)) { $this->delete(['id' => $this->fields["id"]]); } } /** * Show items linked to a certificate * * @since 9.2 * * @param $certificate Certificate object * * @return void (HTML display) **/ public static function showForCertificate(Certificate $certificate) { $instID = $certificate->fields['id']; if (!$certificate->can($instID, READ)) { return false; } $canedit = $certificate->can($instID, UPDATE); $rand = mt_rand(); $types_iterator = self::getDistinctTypes($instID, ['itemtype' => Certificate::getTypes(true)]); $number = count($types_iterator); if (Session::isMultiEntitiesMode()) { $colsup = 1; } else { $colsup = 0; } if ($canedit) { echo "
| " . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . " | "; } echo "" . _n('Type', 'Types', 1) . " | "; echo "" . __('Name') . " | "; if (Session::isMultiEntitiesMode()) { echo "" . Entity::getTypeName(1) . " | "; } echo "" . __('Serial number') . " | "; echo "" . __('Inventory number') . " | "; echo "
|---|---|---|---|---|---|
| "; Html::showMassiveActionCheckBox(__CLASS__, $data["linkid"]); echo " | "; } echo "" . $item->getTypeName(1) . " | "; echo "" . $name . " | "; if (Session::isMultiEntitiesMode()) { $entity = ($item->isEntityAssign() ? Dropdown::getDropdownName("glpi_entities", $data['entity']) : '-'); echo "" . $entity . " | "; } echo "" . (isset($data["serial"]) ? "" . $data["serial"] . "" : "-") . " | "; echo "" . (isset($data["otherserial"]) ? "" . $data["otherserial"] . "" : "-") . " | "; echo "
| "; echo Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand); echo " | "; } echo "" . __('Name') . " | "; if (Session::isMultiEntitiesMode()) { echo "" . Entity::getTypeName(1) . " | "; } echo "" . _n('Type', 'Types', 1) . " | "; echo "" . __('DNS name') . " | "; echo "" . __('DNS suffix') . " | "; echo "" . __('Creation date') . " | "; echo "" . __('Expiration date') . " | "; echo "" . __('Status') . " | "; echo "||
|---|---|---|---|---|---|---|---|---|---|---|
| "; Html::showMassiveActionCheckBox(__CLASS__, $data["linkid"]); echo " | "; } echo "$link | "; if (Session::isMultiEntitiesMode()) { echo "" . Dropdown::getDropdownName("glpi_entities", $data['entities_id']) . " | "; } echo ""; echo Dropdown::getDropdownName("glpi_certificatetypes", $data["certificatetypes_id"]); echo " | "; echo "" . $data["dns_name"] . " | "; echo "" . $data["dns_suffix"] . " | "; echo "" . Html::convDate($data["date_creation"]) . " | "; if ($data["date_expiration"] <= date('Y-m-d') && !empty($data["date_expiration"]) ) { echo "";
echo " " . Html::convDate($data["date_expiration"]) . " ";
echo " | ";
} else if (empty($data["date_expiration"])) {
echo "" . __('Does not expire') . " | "; } else { echo "" . Html::convDate($data["date_expiration"]) . " | "; } echo ""; echo Dropdown::getDropdownName("glpi_states", $data["states_id"]); echo " | "; echo "