code qr vehicule
This commit is contained in:
144
ms1_kc_set.php
144
ms1_kc_set.php
@ -62,11 +62,25 @@ if (empty($_SESSION['kc_edit_csrf'])) {
|
||||
}
|
||||
$strCsrf = $_SESSION['kc_edit_csrf'];
|
||||
$strBasePath = $_SERVER['PHP_SELF'];
|
||||
$strQueryK = ($strSecret !== '') ? ('?k=' . rawurlencode($strSecret)) : '';
|
||||
$strBaseUrlHtml = htmlspecialchars($strBasePath . $strQueryK, ENT_QUOTES, 'UTF-8');
|
||||
|
||||
if (!empty($_GET['reset'])) {
|
||||
unset($_SESSION['kc_edit_step_pk'], $_SESSION['kc_edit_step_vehicule']);
|
||||
function kc_set_page_url(array $params = [])
|
||||
{
|
||||
global $strBasePath;
|
||||
$query = $params;
|
||||
if (!empty($_SESSION['kc_edit_auth_key']) && !isset($query['k'])) {
|
||||
$query = array_merge(['k' => KEYCHAIN_HTTP_EDIT_SECRET], $query);
|
||||
}
|
||||
$qs = http_build_query($query);
|
||||
return $strBasePath . ($qs !== '' ? '?' . $qs : '');
|
||||
}
|
||||
|
||||
$strPageUrl = kc_set_page_url();
|
||||
$strBaseUrlHtml = htmlspecialchars($strPageUrl, ENT_QUOTES, 'UTF-8');
|
||||
$blnCanShareLink = !empty($_SESSION['kc_edit_auth_key']);
|
||||
$strShareUrl = '';
|
||||
if ($blnCanShareLink) {
|
||||
$scheme = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http';
|
||||
$strShareUrl = $scheme . '://' . $_SERVER['HTTP_HOST'] . kc_set_page_url(['k' => KEYCHAIN_HTTP_EDIT_SECRET]);
|
||||
}
|
||||
|
||||
$strUserName = '';
|
||||
@ -81,6 +95,12 @@ $strMessageClass = '';
|
||||
$intPk = 0;
|
||||
$strCurrentHttp = '';
|
||||
$blnShowUrlForm = false;
|
||||
$strVehiculeSaisi = '';
|
||||
|
||||
if (!empty($_GET['ok'])) {
|
||||
$strMessage = 'Le lien de votre code QR a été enregistré. Vous pouvez modifier un autre véhicule ci-dessous.';
|
||||
$strMessageClass = 'ok';
|
||||
}
|
||||
|
||||
function kc_set_parse_vehicule_no($input)
|
||||
{
|
||||
@ -120,8 +140,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$strAction = isset($_POST['action']) ? (string) $_POST['action'] : '';
|
||||
|
||||
if ($strAction === 'load') {
|
||||
$intVehiculeSaisi = isset($_POST['vehicule_no']) ? trim((string) $_POST['vehicule_no']) : '';
|
||||
$intPk = kc_set_parse_vehicule_no($intVehiculeSaisi);
|
||||
$strVehiculeSaisi = isset($_POST['vehicule_no']) ? trim((string) $_POST['vehicule_no']) : '';
|
||||
$intPk = kc_set_parse_vehicule_no($strVehiculeSaisi);
|
||||
if ($intPk <= 0) {
|
||||
$strMessage = 'Veuillez entrer un numéro de véhicule valide.';
|
||||
$strMessageClass = 'err';
|
||||
@ -134,14 +154,14 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
} else {
|
||||
$strCurrentHttp = $row['key_chain_http'];
|
||||
$blnShowUrlForm = true;
|
||||
$_SESSION['kc_edit_step_pk'] = $intPk;
|
||||
$_SESSION['kc_edit_step_vehicule'] = $intVehiculeSaisi;
|
||||
}
|
||||
}
|
||||
} elseif ($strAction === 'save') {
|
||||
$intPk = !empty($_SESSION['kc_edit_step_pk'])
|
||||
? (int) $_SESSION['kc_edit_step_pk']
|
||||
: intval(isset($_POST['pk']) ? $_POST['pk'] : 0);
|
||||
$intPk = intval(isset($_POST['pk']) ? $_POST['pk'] : 0);
|
||||
$strVehiculeSaisi = isset($_POST['vehicule_no']) ? trim((string) $_POST['vehicule_no']) : '';
|
||||
if ($strVehiculeSaisi !== '' && kc_set_parse_vehicule_no($strVehiculeSaisi) !== $intPk) {
|
||||
$intPk = 0;
|
||||
}
|
||||
$strLienPost = isset($_POST['lien_qr']) ? trim((string) $_POST['lien_qr']) : '';
|
||||
$strNewHttp = kc_set_validate_url($strLienPost);
|
||||
if ($intPk <= 0) {
|
||||
@ -167,10 +187,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$blnShowUrlForm = true;
|
||||
$strCurrentHttp = $strLienPost;
|
||||
} else {
|
||||
$strMessage = 'Le lien de votre code QR a été enregistré.';
|
||||
$strMessageClass = 'ok';
|
||||
$strCurrentHttp = $strNewHttp;
|
||||
$blnShowUrlForm = true;
|
||||
header('Location: ' . kc_set_page_url(['ok' => '1']));
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -178,25 +196,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
}
|
||||
}
|
||||
|
||||
// Nouvelle visite (GET) : toujours commencer par le numéro de véhicule
|
||||
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||||
unset($_SESSION['kc_edit_step_pk'], $_SESSION['kc_edit_step_vehicule']);
|
||||
$blnShowUrlForm = false;
|
||||
$intPk = 0;
|
||||
$strCurrentHttp = '';
|
||||
}
|
||||
|
||||
if ($blnShowUrlForm && !empty($_SESSION['kc_edit_step_pk'])) {
|
||||
$intPk = (int) $_SESSION['kc_edit_step_pk'];
|
||||
}
|
||||
|
||||
$strVehiculeSaisi = isset($_SESSION['kc_edit_step_vehicule']) ? (string) $_SESSION['kc_edit_step_vehicule'] : '';
|
||||
$strResetUrlHtml = htmlspecialchars(
|
||||
$strBasePath . ($strSecret !== '' ? ('?k=' . rawurlencode($strSecret) . '&reset=1') : '?reset=1'),
|
||||
ENT_QUOTES,
|
||||
'UTF-8'
|
||||
);
|
||||
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr">
|
||||
@ -488,6 +487,49 @@ $strResetUrlHtml = htmlspecialchars(
|
||||
background: rgba(255, 140, 0, 0.1);
|
||||
}
|
||||
|
||||
.share-box {
|
||||
background: #fff8ee;
|
||||
border: 1px dashed var(--ms1-orange);
|
||||
border-radius: 12px;
|
||||
padding: 1rem 1.15rem;
|
||||
margin-bottom: 1.25rem;
|
||||
}
|
||||
|
||||
.share-box strong {
|
||||
display: block;
|
||||
margin-bottom: 0.5rem;
|
||||
font-size: 0.95rem;
|
||||
}
|
||||
|
||||
.share-row {
|
||||
display: flex;
|
||||
gap: 0.5rem;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.share-url {
|
||||
flex: 1 1 12rem;
|
||||
min-width: 0;
|
||||
padding: 0.55rem 0.65rem;
|
||||
font-size: 0.82rem;
|
||||
border: 1px solid #e2e8f0;
|
||||
border-radius: 8px;
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
.btn-copy {
|
||||
padding: 0.55rem 1rem;
|
||||
font-weight: 600;
|
||||
font-size: 0.9rem;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
background: var(--ms1-ink);
|
||||
color: #fff;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.btn-copy:hover { background: #2d2d44; }
|
||||
|
||||
@media (max-width: 480px) {
|
||||
.actions { flex-direction: column; align-items: stretch; }
|
||||
.btn-enter { justify-content: center; }
|
||||
@ -510,6 +552,17 @@ $strResetUrlHtml = htmlspecialchars(
|
||||
|
||||
<p class="intro">Entrez votre numéro de véhicule. Vous pourrez ainsi changer le lien de votre code QR.</p>
|
||||
|
||||
<?php if ($blnCanShareLink && $strShareUrl !== '') { ?>
|
||||
<div class="share-box">
|
||||
<strong>Lien à envoyer aux autres</strong>
|
||||
<p class="hint" style="margin:0 0 0.65rem;">Chaque personne ouvre ce lien et entre <em>son</em> numéro de véhicule.</p>
|
||||
<div class="share-row">
|
||||
<input type="text" class="share-url" id="share_url" readonly value="<?php echo htmlspecialchars($strShareUrl, ENT_QUOTES, 'UTF-8'); ?>">
|
||||
<button type="button" class="btn-copy" id="btn_copy_link">Copier le lien</button>
|
||||
</div>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<div class="steps" aria-hidden="true">
|
||||
<span class="step <?php echo !$blnShowUrlForm ? 'active' : 'done'; ?>">1</span>
|
||||
<span class="step-line"></span>
|
||||
@ -547,6 +600,7 @@ $strResetUrlHtml = htmlspecialchars(
|
||||
<input type="hidden" name="csrf" value="<?php echo htmlspecialchars($strCsrf, ENT_QUOTES, 'UTF-8'); ?>">
|
||||
<input type="hidden" name="action" value="save">
|
||||
<input type="hidden" name="pk" value="<?php echo (int) $intPk; ?>">
|
||||
<input type="hidden" name="vehicule_no" value="<?php echo htmlspecialchars($strVehiculeSaisi, ENT_QUOTES, 'UTF-8'); ?>">
|
||||
<label class="field-label" for="lien_qr">Lien de votre code QR</label>
|
||||
<div class="field-wrap">
|
||||
<input type="url" class="input-lien" id="lien_qr" name="lien_qr" required autofocus placeholder="https://..." value="<?php echo htmlspecialchars($strCurrentHttp, ENT_QUOTES, 'UTF-8'); ?>">
|
||||
@ -563,8 +617,28 @@ $strResetUrlHtml = htmlspecialchars(
|
||||
</div>
|
||||
|
||||
<?php if ($blnShowUrlForm) { ?>
|
||||
<p class="back"><a href="<?php echo $strResetUrlHtml; ?>">← Autre numéro de véhicule</a></p>
|
||||
<p class="back"><a href="<?php echo $strBaseUrlHtml; ?>">← Autre numéro de véhicule</a></p>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<?php if ($blnCanShareLink && $strShareUrl !== '') { ?>
|
||||
<script>
|
||||
(function () {
|
||||
var btn = document.getElementById('btn_copy_link');
|
||||
var input = document.getElementById('share_url');
|
||||
if (!btn || !input) return;
|
||||
btn.addEventListener('click', function () {
|
||||
input.select();
|
||||
input.setSelectionRange(0, 99999);
|
||||
var ok = false;
|
||||
if (navigator.clipboard && navigator.clipboard.writeText) {
|
||||
navigator.clipboard.writeText(input.value).then(function () { ok = true; });
|
||||
}
|
||||
try { ok = document.execCommand('copy') || ok; } catch (e) {}
|
||||
btn.textContent = ok ? 'Copié !' : 'Sélectionné — Ctrl+C';
|
||||
setTimeout(function () { btn.textContent = 'Copier le lien'; }, 2000);
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
<?php } ?>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user