147 lines
6.2 KiB
PHP
147 lines
6.2 KiB
PHP
<?php
|
||
/**
|
||
* Outil superadmin — générer un QR depuis un lien libre (avec / sans logo MS1).
|
||
* Pas d’enregistrement BD : génération à la volée + téléchargement PNG.
|
||
*/
|
||
|
||
$strLangue = 'fr';
|
||
$strPage = 'qr_lien.php';
|
||
|
||
require_once('php/inc_start_time.php');
|
||
require_once('php/inc_functions.php');
|
||
require_once dirname(__FILE__) . '/../php/inc_fx_kc_qr.php';
|
||
|
||
if (empty($_SESSION['usa_id'])) {
|
||
header('Location: login.php');
|
||
exit;
|
||
}
|
||
|
||
$strUrl = '';
|
||
$strError = '';
|
||
$strQrWithLogo = '';
|
||
$strQrPlain = '';
|
||
$blnReady = false;
|
||
|
||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||
$strUrl = isset($_POST['lien']) ? trim((string) $_POST['lien']) : '';
|
||
|
||
if ($strUrl === '') {
|
||
$strError = 'Entrez un lien (http:// ou https://).';
|
||
} elseif (!filter_var($strUrl, FILTER_VALIDATE_URL)) {
|
||
$strError = 'Adresse Web invalide.';
|
||
} else {
|
||
$tabParts = parse_url($strUrl);
|
||
$strScheme = isset($tabParts['scheme']) ? strtolower((string) $tabParts['scheme']) : '';
|
||
if (!in_array($strScheme, array('http', 'https'), true)) {
|
||
$strError = 'Le lien doit commencer par http:// ou https://.';
|
||
} else {
|
||
$binWith = fxKcQrGeneratePngBinary($strUrl, 12, true);
|
||
$binPlain = fxKcQrGeneratePngBinary($strUrl, 12, false);
|
||
if ($binWith === false || $binPlain === false) {
|
||
$strError = 'Impossible de générer les QR (GD / phpqrcode).';
|
||
} else {
|
||
$strQrWithLogo = 'data:image/png;base64,' . base64_encode($binWith);
|
||
$strQrPlain = 'data:image/png;base64,' . base64_encode($binPlain);
|
||
$blnReady = true;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
$strSafeSlug = '';
|
||
if ($blnReady) {
|
||
$strHost = parse_url($strUrl, PHP_URL_HOST);
|
||
$strSafeSlug = preg_replace('/[^a-zA-Z0-9_-]+/', '-', (string) $strHost);
|
||
$strSafeSlug = trim((string) $strSafeSlug, '-');
|
||
if ($strSafeSlug === '') {
|
||
$strSafeSlug = 'lien';
|
||
}
|
||
}
|
||
|
||
include('inc_header.php');
|
||
?>
|
||
<div class="container-fluid" id="main">
|
||
<div class="row">
|
||
<div class="col-md-9 col-lg-10 order-first order-md-last py-3">
|
||
<?php
|
||
require_once dirname(__FILE__) . '/../php/inc_fx_superadm_v2_ui.php';
|
||
fxSuperadmV2PanelOpen('Liens pratiques — Créer un code QR', array(
|
||
'zone_class' => 'superadm-content-v2-zone superadm-content-v2-zone--flush',
|
||
));
|
||
?>
|
||
|
||
<p class="text-muted mb-3">
|
||
Collez un lien, générez deux PNG (avec logo MS1 / sans logo), téléchargez-les.
|
||
Rien n’est enregistré en base.
|
||
</p>
|
||
|
||
<?php if ($strError !== '') { ?>
|
||
<div class="alert alert-danger"><?php echo htmlspecialchars($strError, ENT_QUOTES, 'UTF-8'); ?></div>
|
||
<?php } ?>
|
||
|
||
<form method="post" action="qr_lien.php" class="mb-4">
|
||
<div class="form-group">
|
||
<label for="lien" class="font-weight-bold">Lien à encoder</label>
|
||
<input type="url"
|
||
class="form-control form-control-lg"
|
||
id="lien"
|
||
name="lien"
|
||
required
|
||
autofocus
|
||
placeholder="https://…"
|
||
value="<?php echo htmlspecialchars($strUrl, ENT_QUOTES, 'UTF-8'); ?>">
|
||
</div>
|
||
<button type="submit" class="btn btn-primary rounded-0">
|
||
<i class="fa fa-qrcode" aria-hidden="true"></i> Générer les 2 QR
|
||
</button>
|
||
</form>
|
||
|
||
<?php if ($blnReady) { ?>
|
||
<div class="row">
|
||
<div class="col-md-6 mb-4">
|
||
<div class="border p-3 h-100 bg-white">
|
||
<h5 class="mb-3">Avec logo MS1</h5>
|
||
<div class="mb-3 text-center">
|
||
<img src="<?php echo htmlspecialchars($strQrWithLogo, ENT_QUOTES, 'UTF-8'); ?>"
|
||
alt="QR avec logo"
|
||
width="260" height="260"
|
||
class="border bg-white p-1">
|
||
</div>
|
||
<a class="btn btn-outline-secondary btn-sm rounded-0 btn-block"
|
||
href="<?php echo htmlspecialchars($strQrWithLogo, ENT_QUOTES, 'UTF-8'); ?>"
|
||
download="qr-<?php echo htmlspecialchars($strSafeSlug, ENT_QUOTES, 'UTF-8'); ?>-logo.png">
|
||
<i class="fa fa-download" aria-hidden="true"></i> Télécharger (avec logo)
|
||
</a>
|
||
</div>
|
||
</div>
|
||
<div class="col-md-6 mb-4">
|
||
<div class="border p-3 h-100 bg-white">
|
||
<h5 class="mb-3">Sans logo</h5>
|
||
<div class="mb-3 text-center">
|
||
<img src="<?php echo htmlspecialchars($strQrPlain, ENT_QUOTES, 'UTF-8'); ?>"
|
||
alt="QR sans logo"
|
||
width="260" height="260"
|
||
class="border bg-white p-1">
|
||
</div>
|
||
<a class="btn btn-outline-secondary btn-sm rounded-0 btn-block"
|
||
href="<?php echo htmlspecialchars($strQrPlain, ENT_QUOTES, 'UTF-8'); ?>"
|
||
download="qr-<?php echo htmlspecialchars($strSafeSlug, ENT_QUOTES, 'UTF-8'); ?>-plain.png">
|
||
<i class="fa fa-download" aria-hidden="true"></i> Télécharger (sans logo)
|
||
</a>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<p class="small text-muted mb-0">
|
||
Lien encodé :
|
||
<code><?php echo htmlspecialchars($strUrl, ENT_QUOTES, 'UTF-8'); ?></code>
|
||
</p>
|
||
<?php } ?>
|
||
|
||
<?php fxSuperadmV2PanelClose(); ?>
|
||
<p> </p>
|
||
</div>
|
||
<?php require_once('inc_droite.php'); ?>
|
||
</div>
|
||
</div>
|
||
<?php require_once('inc_footer.php'); ?>
|