mirror of
https://github.com/itflow-org/itflow
synced 2026-12-05 10:39:00 +00:00
102 lines
6.7 KiB
PHP
102 lines
6.7 KiB
PHP
<?php
|
|
|
|
/*
|
|
* Admin > Warranty Lookup - the manufacturers an asset's warranty can be looked up with
|
|
* (functions/warranty.php): Dell's and HP's keys, and whether Lenovo's support site is asked.
|
|
* Each has Save and test, with a serial number to try. Saved by edit_warranty_settings, tested by
|
|
* test_warranty_lookup (admin/post/settings_warranty.php).
|
|
*/
|
|
|
|
require_once "includes/inc_all_admin.php";
|
|
|
|
$warranty_ready = true;
|
|
try {
|
|
mysqli_query($mysqli, "SELECT config_warranty_lenovo FROM settings LIMIT 1");
|
|
} catch (\Throwable $e) {
|
|
$warranty_ready = false;
|
|
}
|
|
if (!$warranty_ready) { ?>
|
|
<div class="alert alert-warning"><i class="fas fa-fw fa-exclamation-triangle me-2"></i>Warranty lookup arrives with a database update - run it in <a href="update.php">Maintenance > Update</a> first.</div>
|
|
<?php
|
|
require_once "../includes/footer.php";
|
|
exit;
|
|
}
|
|
|
|
$warranty = settingsCurrent(['config_warranty_dell_client_id', 'config_warranty_dell_client_secret', 'config_warranty_hp_client_id', 'config_warranty_hp_client_secret', 'config_warranty_lenovo']);
|
|
$saved_secret = function ($stored) {
|
|
return trim((string) $stored) !== '' ? 'Saved - type a new one to replace it' : 'The secret\'s value';
|
|
};
|
|
$ready = warrantySettings()['ready'];
|
|
|
|
// Save and test, with a serial number to try - sent with the form, not saved with it
|
|
$test_field = function ($maker, $placeholder) {
|
|
return '<div class="input-group mt-3" style="max-width: 32rem;">'
|
|
. '<span class="input-group-text"><i class="fas fa-fw fa-barcode"></i></span>'
|
|
. '<input type="text" class="form-control" name="warranty_test_' . $maker . '" placeholder="' . escapeHtml($placeholder) . '" maxlength="40" data-settings-untracked aria-label="Serial number to try">'
|
|
. '<button type="submit" class="btn btn-outline-primary" name="test_warranty_lookup" value="' . $maker . '"><i class="fas fa-fw fa-vial me-1"></i>Save and test</button>'
|
|
. '</div>';
|
|
};
|
|
$state = function ($on, $off_text) {
|
|
return ($on ? '<span class="badge text-bg-success me-1">On</span>' : '<span class="badge text-bg-secondary me-1">' . escapeHtml($off_text) . '</span>') . ' ';
|
|
};
|
|
|
|
echo settingsPageStart('warranty');
|
|
|
|
?>
|
|
|
|
<form action="post.php" method="post" autocomplete="off" data-settings-form>
|
|
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
|
|
|
|
<div class="card itflow-settings-card">
|
|
<div class="card-body">
|
|
|
|
<?= settingsSectionStart('how', 'How it works', 'An asset is looked up by its make - Dell, HP or Lenovo - or, with no make, by its model: Latitude, ThinkPad, EliteBook. Only empty dates are filled in: a warranty or purchase date already on an asset is never changed.') ?>
|
|
<div class="small">
|
|
<p class="mb-2"><strong>On one asset</strong> - the <i class="fas fa-search"></i> button beside <strong>Warranty expires</strong> on its Purchase tab, before you save.</p>
|
|
<p class="mb-2"><strong>On many</strong> - select them on Assets, then <strong>Bulk Action > Look Up Warranty</strong>.</p>
|
|
<p class="mb-0 text-body-secondary">The warranty date is when the last of the manufacturer's coverage for it ends; the purchase date, when its warranty began - for Dell, the day it shipped.</p>
|
|
</div>
|
|
<?= settingsSectionEnd() ?>
|
|
|
|
<?= settingsSectionStart('dell', 'Dell', $state($ready['dell'], 'Not set up') . 'TechDirect\'s Warranty API, by service tag. Ask for a key at <a href="https://techdirect.dell.com" target="_blank" rel="noopener">techdirect.dell.com<i class="fas fa-external-link-alt small ms-1"></i></a> under Services > APIs - Dell approves it, usually within a few days.') ?>
|
|
<div class="row g-3">
|
|
<div class="col-lg-6">
|
|
<?= settingsInput('config_warranty_dell_client_id', $warranty['config_warranty_dell_client_id'], ['icon' => 'fa-id-badge', 'label' => 'Client ID', 'maxlength' => 200,
|
|
'help' => 'Empty switches Dell lookups off, and forgets its secret.']) ?>
|
|
</div>
|
|
<div class="col-lg-6">
|
|
<?= settingsInput('config_warranty_dell_client_secret', '', ['icon' => 'fa-key', 'type' => 'password', 'label' => 'Client secret', 'maxlength' => 500,
|
|
'autocomplete' => 'new-password', 'placeholder' => $saved_secret($warranty['config_warranty_dell_client_secret'])]) ?>
|
|
</div>
|
|
</div>
|
|
<?= $test_field('dell', 'A service tag to try') ?>
|
|
<?= settingsSectionEnd() ?>
|
|
|
|
<?= settingsSectionStart('lenovo', 'Lenovo', $state($ready['lenovo'], 'Off') . 'Lenovo\'s support site, asked the way its own pages ask it - no key needed. It isn\'t an API Lenovo offers, so it can stop working when Lenovo changes the site.') ?>
|
|
<?= settingsSwitch('config_warranty_lenovo', $warranty['config_warranty_lenovo'], ['label' => 'Look up Lenovo serial numbers on Lenovo\'s support site']) ?>
|
|
<?= $test_field('lenovo', 'A serial number to try') ?>
|
|
<?= settingsSectionEnd() ?>
|
|
|
|
<?= settingsSectionStart('hp', 'HP', $state($ready['hp'], 'Not set up') . 'HP Inc.\'s Warranty API, by serial number. Register at <a href="https://developers.hp.com" target="_blank" rel="noopener">developers.hp.com<i class="fas fa-external-link-alt small ms-1"></i></a>, then email warrantyapi.customers@hp.com for access - HP approves each by hand and doesn\'t give every IT company one. Not for HP Enterprise (HPE) servers, which have no such API.') ?>
|
|
<div class="row g-3">
|
|
<div class="col-lg-6">
|
|
<?= settingsInput('config_warranty_hp_client_id', $warranty['config_warranty_hp_client_id'], ['icon' => 'fa-id-badge', 'label' => 'API key', 'maxlength' => 200,
|
|
'help' => 'Empty switches HP lookups off, and forgets its secret.']) ?>
|
|
</div>
|
|
<div class="col-lg-6">
|
|
<?= settingsInput('config_warranty_hp_client_secret', '', ['icon' => 'fa-key', 'type' => 'password', 'label' => 'API secret', 'maxlength' => 500,
|
|
'autocomplete' => 'new-password', 'placeholder' => $saved_secret($warranty['config_warranty_hp_client_secret']),
|
|
'help' => 'HP works through each lookup as a job, so its answers can take a few minutes.']) ?>
|
|
</div>
|
|
</div>
|
|
<?= $test_field('hp', 'A serial number to try') ?>
|
|
<?= settingsSectionEnd() ?>
|
|
|
|
<?= settingsSaveBar('edit_warranty_settings') ?>
|
|
</div>
|
|
</div>
|
|
</form>
|
|
|
|
<?php
|
|
require_once "../includes/footer.php";
|