|
@@ -13,6 +13,7 @@ class PostHandler
|
13
|
13
|
private $data;
|
14
|
14
|
private $dao;
|
15
|
15
|
private $uploadBaseDir = '../uploaded_images/';
|
|
16
|
+ private $stockFile = "../data/stock-v2.json";
|
16
|
17
|
|
17
|
18
|
private $responseArray = array(
|
18
|
19
|
"status" => 0,
|
|
@@ -59,16 +60,31 @@ class PostHandler
|
59
|
60
|
return $this->responseArray;
|
60
|
61
|
}
|
61
|
62
|
|
|
63
|
+ public function write_json()
|
|
64
|
+ {
|
|
65
|
+ $result = 0;
|
|
66
|
+ $fp = fopen($this->stockFile, "w");
|
|
67
|
+ $array = array(
|
|
68
|
+ "types" => $this->dao->get_categories(),
|
|
69
|
+ "articles" => $this->dao->get_articles(),
|
|
70
|
+ );
|
|
71
|
+ fwrite($fp, json_encode($array));
|
|
72
|
+ fclose($fp);
|
|
73
|
+
|
|
74
|
+ $this->responseArray["data"] = $result;
|
|
75
|
+ return $this->responseArray;
|
|
76
|
+ }
|
|
77
|
+
|
62
|
78
|
private function save_image()
|
63
|
79
|
{
|
64
|
80
|
$success = true;
|
65
|
81
|
if ($this->filesData["image"]["size"] > 0 && $this->data != null) {
|
66
|
|
- $uploadPath = $this->uploadBaseDir.$this->data.".jpg";
|
|
82
|
+ $uploadPath = $this->uploadBaseDir . $this->data . ".jpg";
|
67
|
83
|
|
68
|
84
|
if (move_uploaded_file($this->filesData["image"]["tmp_name"], $uploadPath)) {
|
69
|
85
|
$this->responseArray["message"] = "Image upload success";
|
70
|
86
|
} else {
|
71
|
|
- $this->responseArray["message"] = "Image upload failure: ". $uploadPath;
|
|
87
|
+ $this->responseArray["message"] = "Image upload failure: " . $uploadPath;
|
72
|
88
|
$this->responseArray["status"] = 1;
|
73
|
89
|
$success = false;
|
74
|
90
|
}
|
|
@@ -80,11 +96,12 @@ class PostHandler
|
80
|
96
|
if ($success)
|
81
|
97
|
return 0;
|
82
|
98
|
else
|
83
|
|
- return json_encode($this->filesData)."id: ".$this->data;
|
|
99
|
+ return json_encode($this->filesData) . "id: " . $this->data;
|
84
|
100
|
}
|
85
|
101
|
|
86
|
|
- private function remove_image() {
|
87
|
|
- $uploadPath = $this->uploadBaseDir.$this->data["id"].".jpg";
|
|
102
|
+ private function remove_image()
|
|
103
|
+ {
|
|
104
|
+ $uploadPath = $this->uploadBaseDir . $this->data["id"] . ".jpg";
|
88
|
105
|
if (file_exists($uploadPath) && unlink($uploadPath)) {
|
89
|
106
|
$this->responseArray["message"] = "Success: Deleted image";
|
90
|
107
|
} else if (!file_exists($uploadPath)) {
|
|
@@ -153,7 +170,8 @@ class PostHandler
|
153
|
170
|
return $result;
|
154
|
171
|
}
|
155
|
172
|
|
156
|
|
- function updateStock() {
|
|
173
|
+ function updateStock()
|
|
174
|
+ {
|
157
|
175
|
$result = 0;
|
158
|
176
|
foreach ($this->data as $row) {
|
159
|
177
|
$value = $row["value"];
|