Web Server Setup:
I needed 2 php file. The first controls the UI and the second handle the requests from Samba for the prices.
The file which handle Samba to access the DB is below, all it does is JSON the mysql db and send it back as a return statement.
I didnβt worry about authentication, as I really do not care if someone can access the price list.
[hide=
getprices.php
]
<?php
$input = file_get_contents('php://input');
$con = mysqli_connect('mysql9.000webhost.com','a1343640_daniel','test123','a1343640_test');
if (!$con) {
die('Could not connect: ' . mysqli_error($con));
}
if($input ==0){
$sql = "SELECT * from Prices";
$result = mysqli_query($con,$sql);
$rows = array();
while($r = mysqli_fetch_assoc($result)) {
$rows[] = $r;
}
$json = json_encode($rows);
echo $json;
} else if($input==1) {
$sql = "TRUNCATE TABLE `Prices`";
mysqli_query($con, $sql);
}
?>
[/hide]
The other php file handled the web interface, I made the decision to make it responsive by using bootstrap, as I see myself changing the prices from my phone if I need to.
Note I havent put any protection agianst sql injection. This file is hosted in an admin panel of my website which also includes custom reports.
The design also takes into account error and success statments.
[hide=
welcome.php
]
<?php $dbhost = 'mysql9.000webhost.com';
$dbuser = 'a1343640_daniel';
$dbpass = 'test123';
$dbname = 'a1343640_test';
$tablename = 'Prices';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
$price = $_POST["price"];
$name = $_POST["item"];
$suc = false;
if (!is_null($price)) {
if (is_numeric($price)) {
if (!$conn) {
die('Could not connect: ' . mysql_error());
}
$sql = "REPLACE INTO `".$dbname."`.`".$tablename."` VALUES ('".$name."', '".$price."');";
mysql_select_db('test_db');
$retval = mysql_query($sql, $conn);
if (!$retval) {
die('Could not enter data: ' . mysql_error());
}
mysql_close($conn);
$succ = true;
} else {
$succ = false;
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="../../favicon.ico">
<title>Samba Price Changer</title>
<!-- Bootstrap core CSS -->
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"
integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css"
integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous">
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"
integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS"
crossorigin="anonymous"></script>
<!-- Custom styles for this template -->
<link href="jumbotron-narrow.css" rel="stylesheet">
<!-- Just for debugging purposes. Don't actually copy these 2 lines! -->
<!--[if lt IE 9]>
<script src="../../assets/js/ie8-responsive-file-warning.js"></script><![endif]-->
<script src="../../assets/js/ie-emulation-modes-warning.js"></script>
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="#">Coffee Mange</a>
</div>
<ul class="nav navbar-nav">
<li><a href="#">Home</a></li>
<li><a href="#">Reports</a></li>
<li class="active"><a href="#">Prices</a></li>
<li><a href="#">Admin</a></li>
</ul>
</div>
</nav>
<div class="container">
<div class="jumbotron">
<h1>Change Samba Prices</h1>
<p class="lead">Change POS Prices from here.</p>
</div>
<div class="dropdown">
<form role="form" action="welcome.php" method="post">
<div class="form-group">
<label for="sel1">Select Item:</label>
<select class="form-control" id="item" name="item">
<option>Choclate Milkshake</option>
<option selected>Large Flat White</option>
<option selected>Small Hot Chocolate</option>
</select>
</div>
<div class="form-group">
<label for="price">Price:</label>
<input type="text" class="form-control" id="price" name="price">
</div>
<button type="submit" class="btn btn-default center-block">Change</button>
</form>
<?php
if (!is_null($price)) {
if (!$succ) {
echo '<div class="alert alert-warning pagination-centered" role="alert">
<strong>Error!</strong> Couldnt update ' . $name . ' to: $' . $price;
} else {
echo '<div class="alert alert-success pagination-centered" role="alert">
<strong>Success!</strong> Changed ' . $name . ' The new price is: $' . $price;
}
}
?>
</div>
<footer class="footer">
<p>by the133448.</p>
</footer>
</div> <!-- /container -->
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
</body>
</html>
[/hide]
Note that I only have 3 items in here, to add more create a new line and put in the name
For it to work it has to be the exact same name as in Samba
You replace the options here with your product name in Samba (its in welcome.php)
<option>Choclate Milkshake</option>
<option>Large Flat White</option>
<option selected>Small Hot Chocolate</option>
You could create some php to automatically create the product options, but I didnβt feel the need to add this.