Complete deposit(). Add updated requirement function.
This commit is contained in:
parent
269e45b653
commit
a1fcc9dea9
32
webhook.php
32
webhook.php
|
@ -71,21 +71,39 @@ function add_requirement() {
|
||||||
function deposit(){
|
function deposit(){
|
||||||
global $command_list;
|
global $command_list;
|
||||||
$item_id = $command_list[1];
|
$item_id = $command_list[1];
|
||||||
for ($i = 2; $i < count($command_list) - 1; $i++){
|
$quantity = $command_list[2];
|
||||||
$item_name .= $command_list[$i];
|
|
||||||
if ($i != count($command_list) - 2){
|
|
||||||
$item_name .= " ";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$quantity = $command_list[count(command_list) - 1];
|
|
||||||
|
|
||||||
$mysql = require('mysql_credentials.php');
|
$mysql = require('mysql_credentials.php');
|
||||||
$conn = new mysqli($mysql['servername'], $mysql['username'], $mysql['password'], $mysql['database']);
|
$conn = new mysqli($mysql['servername'], $mysql['username'], $mysql['password'], $mysql['database']);
|
||||||
if ($conn->connect_error) {
|
if ($conn->connect_error) {
|
||||||
die("Connection failed: " . $conn->connect_error);
|
die("Connection failed: " . $conn->connect_error);
|
||||||
}
|
}
|
||||||
|
$stmt = $conn->prepare("UPDATE req set quantity = quantity - ? where id = ?;");
|
||||||
|
$stmt->bind('is', $item_id, $quantity);
|
||||||
|
$stmt->execute();
|
||||||
|
$conn->close();
|
||||||
|
send_html("Deposited!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function get_updated_req() {
|
||||||
|
$mysql = require('mysql_credentials.php');
|
||||||
|
$conn = new mysqli($mysql['servername'], $mysql['username'], $mysql['password'], $mysql['database']);
|
||||||
|
if ($conn->connect_error) {
|
||||||
|
die("Connection failed: " . $conn->connect_error);
|
||||||
|
}
|
||||||
|
$sql = "SELECT name, quantity FROM req WHERE quantity > 0;";
|
||||||
|
$result = $conn->query($sql);
|
||||||
|
|
||||||
|
if ($result->num_rows > 0) {
|
||||||
|
$text = "";
|
||||||
|
while($row = $result->fetch_assoc()) {
|
||||||
|
$text .= $row["id"] . " " . $row["quantity"] . "\n";
|
||||||
|
}
|
||||||
|
return $text;
|
||||||
|
} else {
|
||||||
|
return "Everything is complete";
|
||||||
|
}
|
||||||
|
}
|
||||||
// Get JSON from post, store it and decode it.
|
// Get JSON from post, store it and decode it.
|
||||||
$var = file_get_contents('php://input');
|
$var = file_get_contents('php://input');
|
||||||
$decoded = json_decode($var);
|
$decoded = json_decode($var);
|
||||||
|
|
Loading…
Reference in New Issue