-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
50 lines (41 loc) · 1.03 KB
/
index.php
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
<?php
use SudokuResolver\SudokuResolver,
SudokuResolver\SudokuBoard;
require('/usr/local/lib/php/smarty/Smarty.class.php');
require_once 'app/models/SudokuBoard.php';
require_once 'app/models/SudokuResolver.php';
$smarty = new Smarty();
$smarty->setTemplateDir('./smarty/templates');
$smarty->setCompileDir('./smarty/templates_c');
$smarty->setCacheDir('./smarty/cache');
$smarty->setConfigDir('./smarty/configs');
function post_req(&$smarty)
{
$board = array();
for ($i=1; $i<10; $i++) {
$board[$i] = array();
for ($j=1; $j<10; $j++) {
if ($_POST["$i$j"]) {
$board[$i][] = (int) $_POST["$i$j"];
} else {
$board[$i][] = '';
}
}
}
$solved = SudokuResolver::resolve(SudokuBoard::fromArray($board));
$smarty->assign('solved', $solved->toArray());
$smarty->display('solved.tpl');
}
function get_req(&$smarty)
{
$smarty->display('index.tpl');
}
switch ($_SERVER['REQUEST_METHOD']) {
case 'POST':
post_req($smarty);
break;
case 'GET':
get_req($smarty);
break;
}
?>