global $sudokuGridSolutions
This commit is contained in:
parent
ed5795a6cc
commit
5feaa65955
16
index.php
16
index.php
@ -1,18 +1,19 @@
|
|||||||
<?php
|
<?php
|
||||||
require("classes.php");
|
require("classes.php");
|
||||||
session_start();
|
|
||||||
|
global $sudokuGridSolutions;
|
||||||
|
if (!isset($sudokuGridSolutions)) $sudokuGridSolutions = array();
|
||||||
|
|
||||||
$fullUrl = $_SERVER["REQUEST_SCHEME"]."://".$_SERVER["HTTP_HOST"].$_SERVER["DOCUMENT_URI"];
|
$fullUrl = $_SERVER["REQUEST_SCHEME"]."://".$_SERVER["HTTP_HOST"].$_SERVER["DOCUMENT_URI"];
|
||||||
$dirUrl = dirname($fullUrl);
|
$dirUrl = dirname($fullUrl);
|
||||||
$currentGrid = strip_tags($_SERVER['QUERY_STRING']);
|
$currentGrid = strip_tags($_SERVER['QUERY_STRING']);
|
||||||
|
|
||||||
if (preg_match("/^[1-9.]{81}$/", $currentGrid)) {
|
if (preg_match("/^[1-9.]{81}$/", $currentGrid)) {
|
||||||
if (!array_key_exists($currentGrid, $_SESSION)) {
|
if (!array_key_exists($currentGrid, $sudokuGridSolutions)) {
|
||||||
$grid = new Grid();
|
$grid = new Grid($currentGrid);
|
||||||
$grid->import($currentGrid);
|
$sudokuGridSolutions[$currentGrid] = $grid->containsDuplicates() ? -1 : $grid->countSolutions(2);
|
||||||
$_SESSION[$currentGrid] = $grid->containsDuplicates() ? -1 : $grid->countSolutions(2);
|
|
||||||
}
|
}
|
||||||
switch($_SESSION[$currentGrid]) {
|
switch($sudokuGridSolutions[$currentGrid]) {
|
||||||
case -1:
|
case -1:
|
||||||
$warning = "Cette grille contient des doublons.";
|
$warning = "Cette grille contient des doublons.";
|
||||||
break;
|
break;
|
||||||
@ -27,10 +28,9 @@
|
|||||||
require("sudoku.php");
|
require("sudoku.php");
|
||||||
} else {
|
} else {
|
||||||
$grid = new Grid();
|
$grid = new Grid();
|
||||||
$grid->generate();
|
|
||||||
$gridAsString = $grid->toString();
|
$gridAsString = $grid->toString();
|
||||||
$newGridUrl = "$dirUrl/?$gridAsString";
|
$newGridUrl = "$dirUrl/?$gridAsString";
|
||||||
$_SESSION[$gridAsString] = 1;
|
$sudokuGridSolutions[$gridAsString] = 1;
|
||||||
if ($currentGrid) {
|
if ($currentGrid) {
|
||||||
require("400.php");
|
require("400.php");
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user