1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
| <?php
session_start();
$iduser = $_SESSION["id_user"];
include("../mysqlcon.php");
$ans = ["operation" => false,"name" => ""];
$num = (isset($_POST["numero"]) && !empty($_POST["numero"]) && is_numeric($_POST["numero"]))?$_POST["numero"]:false;
$q = "Select COUNT(*) as carteok from commande where numerocarte='$num'";
$q = $conn->query($q);
$f = mysqli_fetch_array($q);
$numok = $f["carteok"];
//set it to writable location, a place for temp generated PNG files
$PNG_TEMP_DIR = dirname(__FILE__).DIRECTORY_SEPARATOR.'temp'.DIRECTORY_SEPARATOR;
//html PNG location prefix
$PNG_WEB_DIR = 'temp/';
include "phpqrcode/qrlib.php";
//ofcourse we need rights to create temp dir
if (!file_exists($PNG_TEMP_DIR))
mkdir($PNG_TEMP_DIR);
$filename = $PNG_TEMP_DIR.'test.png';
//processing form input
//remember to sanitize user input in real-life solution !!!
$errorCorrectionLevel = 'L';
if (isset($_REQUEST['level']) && in_array($_REQUEST['level'], array('L','M','Q','H')))
$errorCorrectionLevel = $_REQUEST['level'];
$matrixPointSize = 4;
if (isset($_REQUEST['size']))
$matrixPointSize = min(max((int)$_REQUEST['size'], 1), 10);
$lien = "https://www.tesdemuret.fr/join.php=$id_user";
//it's very important!
if (trim(lien) == '')
die('data cannot be empty! <a href="?">back</a>');
// user data
$lien = "https://www.....fr/join.php=800";
$filename = $PNG_TEMP_DIR.'test'.md5($lien.'|'.$errorCorrectionLevel.'|'.$matrixPointSize).'.png';
QRcode::png($lien, $filename, $errorCorrectionLevel, $matrixPointSize, 2);
$liens = "<img src='$PNG_WEB_DIR.basename($filename)'>";
if($numok == 1){
$ans["operation"] = true;
$ans["name"] = createCarte("source.png",$num,"allCarte/",$liens);
$qu = "UPDATE commande SET carteok = 'ok', choix='duo' WHERE numerocarte='$num'";
$qu = $conn->query($qu);
}
echo json_encode($ans);
function createCarte($pathSoucre,$number,$cheminSave,$url)
{
$carte = Imagecreatefrompng($pathSoucre);
$textcolor = imagecolorallocate($carte, 225, 29, 72);
$name = "carte_".$number."_.png";
$sizeCenter = (330 - (strlen($number)*10))/2;
$sizeCenterli = (330 - (strlen($url)*10))/2;
imagestring($carte, 5, 700+$sizeCenter, 210, $number, $textcolor);
imagestring($carte, 5, 720+$sizeCenterli, 110, $url, $textcolor);
imagepng($carte,$cheminSave.$name);
return $name;
}
?> |
Partager