Created
November 30, 2016 06:34
-
-
Save sedflix/25c191951de27c62e977a66d05a2f9b5 to your computer and use it in GitHub Desktop.
firstStageOfTheMessThingBackend
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<component name="CopyrightManager"> | |
<settings default="" /> | |
</component> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<project version="4"> | |
<component name="PublishConfigData"> | |
<serverData> | |
<paths name="Hackathon"> | |
<serverdata> | |
<mappings> | |
<mapping local="$PROJECT_DIR$" web="/" /> | |
</mappings> | |
</serverdata> | |
</paths> | |
</serverData> | |
</component> | |
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<project version="4"> | |
<component name="ProjectLevelVcsManager" settingsEditedManually="false"> | |
<OptionsSetting value="true" id="Add" /> | |
<OptionsSetting value="true" id="Remove" /> | |
<OptionsSetting value="true" id="Checkout" /> | |
<OptionsSetting value="true" id="Update" /> | |
<OptionsSetting value="true" id="Status" /> | |
<OptionsSetting value="true" id="Edit" /> | |
<ConfirmationsSetting value="0" id="Add" /> | |
<ConfirmationsSetting value="0" id="Remove" /> | |
</component> | |
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<project version="4"> | |
<component name="ProjectModuleManager"> | |
<modules> | |
<module fileurl="file://$PROJECT_DIR$/.idea/theMessThing.iml" filepath="$PROJECT_DIR$/.idea/theMessThing.iml" /> | |
</modules> | |
</component> | |
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<module type="WEB_MODULE" version="4"> | |
<component name="NewModuleRootManager"> | |
<content url="file://$MODULE_DIR$" /> | |
<orderEntry type="inheritedJdk" /> | |
<orderEntry type="sourceFolder" forTests="false" /> | |
</component> | |
</module> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function getTypeOfMeal($time) | |
{ | |
$breakfastStart = "7:00:00"; | |
$breakfastEnd = "10:00:00"; | |
$lunchStart = "11:30:00"; | |
$lunchEnd = "15:00:00"; | |
$eveningStart = "17:30:00"; | |
$eveningEnd = "18:30:30"; | |
$dinnerStart = "19:30:30"; | |
$dinnerEnd = "22:00:00"; | |
if ($time > $breakfastStart && $time < $breakfastEnd) { | |
return "b"; | |
} elseif ($time > $lunchStart && $time < $lunchEnd) { | |
return "l"; | |
} elseif ($time > $eveningStart && $time < $eveningEnd) { | |
return "e"; | |
} elseif ($time > $dinnerStart && $time < $dinnerEnd) { | |
return "d"; | |
} else { | |
return false; | |
} | |
} | |
function isRFIDValid($rfid, $pdo) | |
{ | |
$userstmt = $pdo->prepare("SELECT * FROM user WHERE rfid=?"); | |
$userstmt->execute([$rfid]); | |
if ($userstmt->rowCount() > 0) { | |
return $userstmt->fetch(PDO::FETCH_ASSOC); | |
} else { | |
echo "WRONG RFID"; | |
return false; | |
} | |
} | |
$host = '127.0.0.1'; | |
$db = 'messthing'; | |
$user = 'root'; | |
$pass = ''; | |
$charset = 'utf8'; | |
$dsn = "mysql:host=$host;dbname=$db;charset=$charset"; | |
$opt = [ | |
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, | |
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, | |
PDO::ATTR_EMULATE_PREPARES => false, | |
]; | |
try { | |
$pdo = new PDO($dsn, $user, $pass, $opt); | |
} catch (PDOException $e) { | |
print_r($e); | |
} | |
//Dededuct Coupons | |
date_default_timezone_set("Asia/Bangkok"); | |
$k = ["b" => "breakfat", "l" => "lunch", "e" => "evening", "d" => "dinner"]; | |
$rfid = $_GET['id']; | |
$user = isRFIDValid($rfid, $pdo); | |
if ($user) { | |
$time = time(); | |
$type = getTypeOfMeal($time); | |
echo "$type"; | |
if ($type != false) { | |
if ($user[$k[$type]] > 0) { | |
try { | |
$pdo->beginTransaction(); | |
$stmtUpdateUser = $pdo->prepare("UPDATE user SET " . $k[$type] . " = " . $k[$type] . "-1 WHERE rfid = ?"); | |
$stmtUpdateUser->execute([$rfid]); | |
$redemptionHistoryInsert = $pdo->prepare("INSERT INTO `redemption_history` (`user_id`, `time`, `coupon_type`) VALUES (?, NOW(), ?); "); | |
$redemptionHistoryInsert->execute([$user['user_id'], $type]); | |
$pdo->commit(); | |
echo "DONE"; | |
} | |
catch (PDOException $e) | |
{ | |
$pdo->rollBack(); | |
echo $e->getMessage(); | |
} | |
} else { | |
echo "No coupons left"; | |
} | |
} else { | |
echo "You entered the mess at the wrong time"; | |
} | |
} else { | |
echo "Sorry, that rfid is not registerd"; | |
} | |
//$stmtR = $pdo->prepare(''); | |
//$stmtR->execute(''); | |
//$e = $stmtR->fetch(PDO::FETCH_ASSOC); | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$host = '127.0.0.1'; | |
$db = 'messthing'; | |
$user = 'root'; | |
$pass = ''; | |
$charset = 'utf8'; | |
$dsn = "mysql:host=$host;dbname=$db;charset=$charset"; | |
$opt = [ | |
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, | |
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, | |
PDO::ATTR_EMULATE_PREPARES => false, | |
]; | |
try { | |
$pdo = new PDO($dsn, $user, $pass, $opt); | |
} catch (PDOException $e) { | |
print_r($e); | |
} | |
$rfid = $_GET['id']; | |
$stmtPaymentHistory = $pdo->prepare('SELECT user_id as id, breakfast, lunch, evening, dinner FROM user WHERE rfid = ?'); | |
$stmtPaymentHistory->execute([$rfid]); | |
$history = $stmtPaymentHistory->fetch(PDO::FETCH_ASSOC); | |
print_r( $history); | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$host = '127.0.0.1'; | |
$db = 'messthing'; | |
$user = 'root'; | |
$pass = ''; | |
$charset = 'utf8'; | |
$dsn = "mysql:host=$host;dbname=$db;charset=$charset"; | |
$opt = [ | |
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, | |
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, | |
PDO::ATTR_EMULATE_PREPARES => false, | |
]; | |
try { | |
$pdo = new PDO($dsn, $user, $pass, $opt); | |
} catch (PDOException $e) { | |
print_r($e); | |
} | |
$rfid = $_GET['id']; | |
$stmtPaymentHistory = $pdo->prepare('SELECT * FROM redemption_history WHERE user_id = ?'); | |
$stmtPaymentHistory->execute([$rfid]); | |
$history = $stmtPaymentHistory->fetch(PDO::FETCH_ASSOC); | |
print_r($history); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment