Commit 15e5a682 authored by Sam's avatar Sam

Merge remote-tracking branch 'world_museums/master'

parents d923146b a95ac93e
<?php
if(isset($_POST['bookingID'])){
$bookingID = htmlspecialchars($_POST['bookingID']);
while(true){
require_once "connect_db.php";
$sql = 'SELECT * FROM receipt_museum WHERE bookingID= ?;';
$stmt = mysqli_stmt_init($connect);
if (!mysqli_stmt_prepare($stmt, $sql)) {
echo 'failure';
} else {
mysqli_stmt_bind_param($stmt, "i", $bookingID);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
if (mysqli_fetch_assoc($result)) {
$bookingID = mt_rand(100000,999999);
}
else {
break;
}
}
}
mysqli_stmt_close($stmt);
echo $bookingID;
} else{
echo 'no submit';
}
\ No newline at end of file
<?php
//connecting to the database
$dbServername = "cs2s.yorkdc.net";
$username = "sam.markey";
$passwordConnect = "ENTER PASSWORD HERE";
$dbname = "sammarkey";
$connect = mysqli_connect($dbServername, $username, $passwordConnect, $dbname);
if (!$connect) {
die("Connection Failed: " . mysqli_connect_error());
}
\ No newline at end of file
<?php
require_once 'connect_db.php';
if (isset($_POST['username']) && isset($_POST['firstname']) && isset($_POST['lastname']) && isset($_POST['password'])) {
$key = 'fu4823yfu03$&u3Sy(48%$>gh)83*hf201*&fg3"!fh9HFG8';
require_once 'encode_decode.php';
$username = htmlspecialchars($_POST['username']);
$firstname = encrypt(htmlspecialchars($_POST['firstname']),$key);
$lastname = encrypt(htmlspecialchars($_POST['lastname']),$key);
$password = htmlspecialchars(password_hash($_POST['password'], PASSWORD_DEFAULT));
//init the connection and sql
$stmt = mysqli_stmt_init($connect);
if (AccountCheck($username, $connect)) {
echo "username_taken";
exit();
} else {
$sql = "INSERT INTO user_museum VALUES (?,?,?,?);";
if (!mysqli_stmt_prepare($stmt, $sql)) {
echo "failure";
} else {
mysqli_stmt_bind_param($stmt, "ssss", $username, $firstname,$lastname, $password);
mysqli_stmt_execute($stmt);
echo "success";
}
mysqli_stmt_close($stmt);
exit();
}
}
function AccountCheck($username, $connect)
{
$sql2 = 'SELECT * FROM user_museum WHERE username= ?;';
$stmt2 = mysqli_stmt_init($connect);
if (!mysqli_stmt_prepare($stmt2, $sql2)) {
echo "sql_error";
} else {
mysqli_stmt_bind_param($stmt2, 's', $username);
mysqli_stmt_execute($stmt2);
$result = mysqli_stmt_get_result($stmt2);
if (mysqli_fetch_assoc($result)) {
mysqli_stmt_close($stmt2);
return true;
} else {
mysqli_stmt_close($stmt2);
return false;
}
}
};
\ No newline at end of file
<?php
if(isset($_POST['bookingID']) &&isset($_POST['museumID']) && isset($_POST['numberOfItems']) && isset($_POST['bookedDate']) && isset($_POST['bookedTime']) && isset($_POST['totalCost']) && isset($_POST['userEntered']) && isset($_POST['userChange'])){
require_once 'connect_db.php';
$bookingID = (int)htmlspecialchars($_POST['bookingID']);
$numberOfItems = htmlspecialchars($_POST['numberOfItems']);
$museumID = htmlspecialchars($_POST['museumID']);
$bookedDate = htmlspecialchars($_POST['bookedDate']);
$bookedTime = htmlspecialchars($_POST['bookedTime']);
$totalCost = htmlspecialchars($_POST['totalCost']);
$userEntered = htmlspecialchars($_POST['userEntered']);
$userChange = htmlspecialchars($_POST['userChange']);
$stmt = mysqli_stmt_init($connect);
$sql = 'INSERT INTO `receipt_museum` VALUES (?,?,?,?,?,?,?,?);';
if(!mysqli_stmt_prepare($stmt,$sql)){
echo 'failure';
}
else{
mysqli_stmt_bind_param($stmt,"iiisssss",$bookingID,$museumID,$numberOfItems,$bookedDate,$bookedTime,$totalCost,$userEntered,$userChange);
mysqli_stmt_execute($stmt);
echo "success";
}
mysqli_stmt_close($stmt);
}
else{
echo "check isset";
}
\ No newline at end of file
<?php
//encrypts data using PHP openssl
function encrypt($data, $key)
{
$encryption_key = base64_decode($key);
$iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length('aes-256-cbc'));
$encrypted = openssl_encrypt($data, 'aes-256-cbc', $encryption_key, 0, $iv);
return base64_encode($encrypted . '::' . $iv);
}
//decrypts data using the same key as the encrpyt function
function decrypt($data, $key)
{
$encryption_key = base64_decode($key);
list($encrypted_data, $iv) = array_pad(explode('::', base64_decode($data), 2), 2, null);
return openssl_decrypt($encrypted_data, 'aes-256-cbc', $encryption_key, 0, $iv);
}
\ No newline at end of file
<?php
if (isset($_GET['table'])) {
$table = trim(htmlspecialchars($_GET['table']));
if(strcmp($table,'museum') == 0 || strcmp($table,'item_museum') == 0){
$language = $_GET['language'];
getTable($table,$language);
}else{
getTable($table,"");
}
}
else{
echo 'check_isset';
}
function getTable($tablename,$languageType)
{
require_once 'connect_db.php';
$stmt = mysqli_stmt_init($connect);
if(strcmp($tablename,'museum') == 0 || strcmp($tablename,'item_museum') == 0){
$sql = 'SELECT * FROM ' . $tablename ." WHERE language='".$languageType."';";
} else{
$sql = 'SELECT * FROM ' . $tablename . ";";
}
if (!mysqli_stmt_prepare($stmt, $sql)) {
echo "ERROR: ".$sql;
} else {
mysqli_stmt_execute($stmt);
$dataArray = array();
if ($resultData = mysqli_stmt_get_result($stmt)) {
while ($row = mysqli_fetch_assoc($resultData)) {
$rows[] = $row;
}
echo json_encode(JsonVerify($rows));
}
}
mysqli_stmt_close($stmt);
}
function JsonVerify($var)
{
if (is_array($var)) {
foreach ($var as $key => $value) {
$var[$key] = JsonVerify($value);
}
} elseif (is_string($var)) {
return mb_convert_encoding($var, "UTF-8", "UTF-8");
}
return $var;
}
\ No newline at end of file
<?php
if(isset($_POST['bookingID']) && isset($_POST['itemName'])&& isset($_POST['itemQuantity'])){
require_once 'connect_db.php';
$itemQuantity = htmlspecialchars($_POST['itemQuantity']);
$itemName = htmlspecialchars($_POST['itemName']);
$bookingID = htmlspecialchars($_POST['bookingID']);
$stmt = mysqli_stmt_init($connect);
$sql = 'INSERT INTO `items_on_receipt_museum`(receipt_bookingID,item_name,item_quantity) VALUES (?,?,?)';
if(!mysqli_stmt_prepare($stmt,$sql)){
echo 'failure';
}
else{
mysqli_stmt_bind_param($stmt,'isi',$bookingID,$itemName,$itemQuantity);
mysqli_stmt_execute($stmt);
echo 'success';
}
mysqli_stmt_close($stmt);
}
else{
echo 'check_isset';
}
\ No newline at end of file
<?php
if (isset($_POST['username']) && isset($_POST['password'])) {
require_once "connect_db.php";
$sql = 'SELECT * FROM user_museum WHERE username= ?;';
$username = htmlspecialchars($_POST['username']);
$password = htmlspecialchars($_POST['password']);
$stmt = mysqli_stmt_init($connect);
if (!mysqli_stmt_prepare($stmt, $sql)) {
echo "sql_error";
} else {
mysqli_stmt_bind_param($stmt, "s", $username);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
if ($row = mysqli_fetch_assoc($result)) {
require_once 'encode_decode.php';
$passwordmatch = password_verify($password, $row["password"]);
$key = 'fu4823yfu03$&u3Sy(48%$>gh)83*hf201*&fg3"!fh9HFG8';
$decryptedFirstName = decrypt($row["Firstname"],$key);
$decryptedLastName = decrypt($row["Lastname"],$key);
if ($passwordmatch) {
echo "success,".$decryptedFirstName.','.$decryptedLastName;
} else {
echo "password_nomatch";
}
} else {
echo "username_nomatch";
}
}
mysqli_stmt_close($stmt);
exit();
}
\ No newline at end of file
<?php
use PHPMailer\PHPMailer\PHPMailer;
if(isset($_POST['details']) && isset($_POST['emailAddress']) ){
$allDetails = json_decode($_POST['details']);
$allItemData = json_decode($_POST['itemData']);
//checks is valid email
$email = filter_var($_POST['emailAddress'],FILTER_SANITIZE_EMAIL);
if(!filter_var($_POST['emailAddress'],FILTER_SANITIZE_EMAIL)){
echo 'invalidEmail';
}
//Email Address
// DETAILS
$museumName = $allDetails->museumName;
$dateSelected = $allDetails->dateSelected;
$timeSelected = $allDetails->timeSelected;
$totalCost = $allDetails->totalCost;
$amountEntered = $allDetails->amountEntered;
$change = $allDetails->change;
$bookingID = $allDetails->bookingID;
$userName = $allDetails->firstname;
$lastname = $allDetails->lastname;
$body = "Dear ".$userName."<br><br>
Here is Your Receipt.<br>Thank you for booking with World Museums! <br>
";
//ITEM DATA
$itemNames = $allItemData->ItemNames;
$itemQuantity = $allItemData->ItemQuantity;
$ItemPrices = $allItemData->ItemPrices;
//checking to see if user has bought items
$body .='<body>
<h3>----------------------ITEMS----------------------</h3><br>
<table>';
for($i = 0; $i < count($itemNames);$i++){
$body .='<tr><td style="text-align: center;">'.$itemNames[$i].
'</td><td style="text-align: center;">'
.$itemQuantity[$i].'</td><td style="text-align: center;">&amp;pound;'.$ItemPrices[$i].".00</td></tr>";
}
$body.='</table>';
$body .= '<h3>----------------------Details----------------------</h3>';
$body .= '<table><tr><td>Customer Name:</td><td>'.$userName." ".$lastname."</td></tr>"."<tr><td>MuseumName:</td><td>".$museumName.'</td></tr>'."<tr><td>Date:</td><td>".$dateSelected.'</td></tr>'
."<tr><td>Time Start:</td><td>".$timeSelected.'</td></tr>'."<tr><td>Total Cost:</td><td>".$totalCost."</td></tr>"."<tr><td>Amount Entered:</td><td>".$amountEntered.'</td></tr>'."<tr><td>Change
Given:</td><td>".$change."</td></tr>
</table>
<h2 style='color: #A40C01;'><b>BOOKING CODE: ".$bookingID."</b></h2>
<br> Thank you,<br> World Museums</body>";
PostEmail($body,$email,$userName,$bookingID);
}
else{
echo 'check Isset ';
}
function PostEmail($body,$usersEmail,$username,$bookingID){
require 'vendor/autoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->Host = 'smtp.hostinger.co.uk';
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->Username = 'worldmuseums@sammarkey.com';
$mail->Password = 'ENTER PASSWORD HERE';
$mail->setFrom('worldmuseums@sammarkey.com', 'World Museums');
$mail->addAddress($usersEmail, $userName);
$mail->Subject = $username.' Your BOOKING CODE IS: '.$bookingID;
$mail->Body = html_entity_decode($body);
$mail->IsHTML(true);
if (!$mail->send()) {
echo 'failure';
}
else{
echo 'success';
}
}
?>
\ No newline at end of file
<?php
if(isset($_POST['bookingID']) && isset($_POST['username'])){
require_once 'connect_db.php';
$bookingID = htmlspecialchars($_POST['bookingID']);
$username = htmlspecialchars($_POST['username']);
$stmt = mysqli_stmt_init($connect);
$sql = 'INSERT INTO `receipt_has_user_museum` VALUES (?,?);';
if(!mysqli_stmt_prepare($stmt,$sql)){
echo 'failure';
}
else{
mysqli_stmt_bind_param($stmt,'is',$bookingID,$username);
mysqli_stmt_execute($stmt);
echo 'success';
}
mysqli_stmt_close($stmt);
}
else {
echo "checkisset";
}
\ No newline at end of file
......@@ -14,6 +14,7 @@ import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.TextView;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.core.content.res.ResourcesCompat;
......@@ -21,11 +22,13 @@ import androidx.fragment.app.DialogFragment;
import com.example.museumworld.R;
import com.example.museumworld.cafe_shop.cafe_activity;
import com.example.museumworld.checkout.Receipt;
import com.example.museumworld.details.MuseumDetails;
import com.google.android.material.snackbar.Snackbar;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
......@@ -88,29 +91,8 @@ public class booking extends AppCompatActivity implements View.OnClickListener,
snackbarAlert("Please Select a date", true);
Log.d("TEStB", "TEST");
} else {
//select the spinner item
switch (spinner.getSelectedItem().toString()) {
case "9-11am":
timeSelected = "09:00";
break;
case "11-1pm":
timeSelected = "11:00";
break;
case "1-3pm":
timeSelected = "13:00";
break;
case "3-5pm":
timeSelected = "15:00";
break;
}
OpenDialogBox(getString(R.string.bookingTitle));
//start the cafe activity
Intent cafe = new Intent(this, cafe_activity.class);
//put the URL image in the cafe activity
cafe.putExtra("topURL", topImgURL);
startActivity(cafe);
}
break;
}
......@@ -193,4 +175,39 @@ public class booking extends AppCompatActivity implements View.OnClickListener,
}
alert.show();
}
public void OpenDialogBox(String title) {
AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.AlertDialogTheme);
builder.setTitle(title)
.setMessage(getString(R.string.bookingConfirm) +" " +MuseumDetails.MuseumName +"\n"+ getString(R.string.bookingConfirm2)+" " + dateSelected + "\n" + getString(R.string.bookingConfirm3) +" "+ spinner.getSelectedItem().toString())
.setPositiveButton(getResources().getString(R.string.yes), (dialog, which) -> {
switch (spinner.getSelectedItem().toString()) {
case "9-11am":
timeSelected = "09:00";
break;
case "11-1pm":
timeSelected = "11:00";
break;
case "1-3pm":
timeSelected = "13:00";
break;
case "3-5pm":
timeSelected = "15:00";
break;
}
//start the cafe activity
Intent cafe = new Intent(this, cafe_activity.class);
//put the URL image in the cafe activity
cafe.putExtra("topURL", topImgURL);
startActivity(cafe);
}).setNegativeButton(getResources().getString(R.string.no), (dialog, which) -> {
});
builder.show();
}
}
\ No newline at end of file
......@@ -138,11 +138,10 @@ public class cafe_activity extends AppCompatActivity implements View.OnClickList
case R.id.next_btn:
Intent shop = new Intent(this, shop_activity.class);
shop.putExtra("topURL", topImgURL);
//if the itemData array is not null add the cafe items to the shop activity which will be passed down to the checkout and receipt
if (getItemData() != null) {
shop.putExtra("cafeItems", getItemData().get(0));
shop.putExtra("topURL", topImgURL);
shop.putExtra("cafeQuantity", getItemData().get(1));
shop.putExtra("cafePrice", getItemData().get(2));
}
......
......@@ -58,6 +58,7 @@ public class shop_activity extends AppCompatActivity implements View.OnClickList
MuseumDetails md = new MuseumDetails();
top_img = findViewById(R.id.top_img);
topImgURL= getIntent().getStringExtra("topURL");
Log.d("topImgURLShop", topImgURL);
md.setImagesByURL(getApplicationContext(), top_img, getIntent().getStringExtra("topURL"));
next_btn = findViewById(R.id.next_btn);
......
......@@ -82,4 +82,8 @@
<string name="select_time">Sélectionnez l\'heure</string>
<string name="too_much_input">Vous êtes trop entré</string>
<string name="world_museums">Musées du monde</string>
<string name="bookingConfirm">Êtes-vous sûr de vouloir réserver:</string>
<string name="bookingConfirm2">Daté:</string>
<string name="bookingConfirm3">Temps:</string>
<string name="bookingTitle">Confirmer la réservation</string>
</resources>
\ No newline at end of file
......@@ -73,6 +73,10 @@
<string name="email_invalid">Please Enter a Valid Email</string>
<string name="email_sent">The Receipt Was sent to the email</string>
<string name="email_error">Something went wrong please try again</string>
<string name="bookingConfirm">Are you sure you want to book:</string>
<string name="bookingConfirm2"> Date:</string>
<string name="bookingConfirm3"> Time:</string>
<string name="bookingTitle"> Confirm Booking</string>
<!-- LOGIN / REGISTER-->
<string name="login_usernameError">*Name has to be 5 characters long</string>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment