-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
79 lines (63 loc) · 1.97 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
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
<?php
error_reporting(E_ALL);
require_once('lib/ProductManager.php');
$pdct = new ProductManager('lib/Product.csv');
require_once('lib/Smarty/libs/Smarty.class.php');
$smarty = new Smarty();
$smarty->default_modifiers = array('escape:html','nl2br');
$obj = array();
if(!empty($_POST)){
if(isset($_POST['delete'])){
try{
$buf = $pdct->getProduct($_POST['ProductId']);
$pdct->DeleteProduct($_POST['ProductId']);
$pdct->Commit();
$pdct->Reload();
$obj['msg'] = sprintf('商品ID: %sの商品(%s)を削除しました。',$buf['ProductId'],$buf['Name']);
} catch(Exception $e) {
$obj['msg'] = sprintf('その商品ID(%s)は存在してないです…。',$_POST['ProductId']);
}
}elseif(isset($_POST['append'])){
try{
$pdct->AddProduct([
'ProductId' => $_POST['ProductId'],
'Price' => $_POST['Price'],
'Name' => $_POST['Name'],
'Stock' => $_POST['Stock']
]);
$pdct->Commit();
$obj['msg'] = sprintf('商品ID: %sの商品(%s)を追加しました',$_POST['ProductId'],$_POST['Name']);
} catch(Exception $e) {
$obj['msg'] = sprintf('既にその商品ID(%s)は存在してます。',$_POST['ProductId']);
}
} elseif(isset($_POST['update'])){
try{
$pdct->updateProduct([
'ProductId' => $_POST['ProductId'],
'Price' => $_POST['Price'],
'Name' => $_POST['Name'],
'Stock' => $_POST['Stock']
]);
$pdct->Commit();
$pdct->Reload();
$obj['msg'] = sprintf('商品ID: %sの商品(%s)を更新しました',$_POST['ProductId'],$_POST['Name']);
} catch(Exception $e) {
$obj['msg'] = sprintf('その商品ID(%s)は多分存在してません。',$_POST['ProductId']);
}
}
}elseif(isset($_GET['id'])){
try{
$p = $pdct->getProduct($_GET['id']);
if($p){
$obj['current'] = $p;
} else {
throw new ErrorException('Invalid ProductId');
}
} catch(Excecption $e){
}
}
$pdct->reload();
$obj['products'] = $pdct->getProducts();
$smarty->assign($obj);
$smarty->display('template/index.tpl');
?>