diff --git a/ms1_kc_set.php b/ms1_kc_set.php index 396beb9..6aba5ef 100644 --- a/ms1_kc_set.php +++ b/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' -); - ?> @@ -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(
Entrez votre numéro de véhicule. Vous pourrez ainsi changer le lien de votre code QR.
+ + + + + + +