<?php require_once 'autoload.php'; /* New Sheep - adds a sheep to the flock. * FlockBuddy - the Android app to keep track of your flock. * HackMCR2015 - Tim Tyler, Steven Tomlinson, Mudit Pandya * 24/10/2015 - 25/10/2015 */ if (isset($_POST)) { $sheepTable = new SheepTable(); $flockTable = new FlockTable(); $flockID = $_POST['flockID']; $flock = $flockTable->getFlockUsingFlockID($flockID); $sheepMobile = '44' . substr($_POST['mobile'], 1); $sheepID = $flockID . $sheepMobile; // Composite Key $sheep = new Sheep($sheepID, $sheepMobile, $_POST['sheepName'], NULL, NULL, false, false, false, $flockID); // FlockID if ($sheepTable->addSheep($sheep)) { http_response_code(200); $messageForSheep = "You have been added to the '" . $flock->getFlockName() . "' Flock by " . $flock->getShepherd()->getSheepName() . ". To enable tracking permission, text \"FLOCKME\" to 84433 (Texts cost 10p). Confused? Find out more at www.flockbuddy.com"; try { // Create a Clockwork object using your API key $clockwork = new Clockwork('787b4673e0ac4b043aab8a4764f0205ab06dc309'); // Setup and send the message $message = array('to' => $sheepMobile, 'message' => $messageForSheep); $result = $clockwork->send($message); // Check if the send was successful if ($result['success']) { echo 'Message sent - ID: ' . $result['id']; } else {
<?php require_once 'autoload.php'; /* New flock - Adds a flock to the database. * FlockBuddy - the Android app to keep track of your flock. * HackMCR2015 - Tim Tyler, Steven Tomlinson, Mudit Pandya * 24/10/2015 - 25/10/2015 */ if (isset($_POST)) { $flockTable = new FlockTable(); $sheepTable = new SheepTable(); $flockID = $flockTable->getNextFlockID(); // TALK TO DB AND GET AUTOINCREMENT FOR FLOCK ID $sheepMobile = '44' . substr($_POST['mobile'], 1); $shepherdID = $flockID . $sheepMobile; $shepherd = new Sheep($shepherdID, $sheepMobile, $_POST['sheepName'], NULL, NULL, true, true, true, $flockID); // FlockID if ($sheepTable->addSheep($shepherd)) { $flock = new Flock($flockID, $_POST['flockName'], $shepherdID, $_POST['start'], $_POST['end'], $_POST['maxDistance']); if ($flockTable->addFlock($flock)) { http_response_code(200); } else { http_response_code(400); } } else { http_response_code(400); } var_dump(http_response_code()); }
<?php require_once 'autoload.php'; /* * FlockBuddy - the Android app to keep track of your flock. * HackMCR2015 - Tim Tyler, Steven Tomlinson, Mudit Pandya * 24/10/2015 - 25/10/2015 */ /** * Processes SMS messages sent by Sheep via Clockwork. * @author Tim Tyler */ if (isset($_POST)) { $sheepTable = new SheepTable(); $flockTable = new FlockTable(); $sheepMobile = $_POST['from']; $sheep = $sheepTable->getSheepUsingSheepMobile($sheepMobile); $flock = $flockTable->getFlockUsingFlockID($sheep->getFlockID()); $messageFromSheep = strtoupper($_POST['keyword']); $messageForSheep = "Sorry, something seems to have gone wrong. Please try again or contact support@flockbuddy.com"; switch ($messageFromSheep) { // Can come from SMS or Android HTTP call. case "FLOCKME": // Has sheep already accepted, and is returning? if ($sheepTable->checkSheepAcceptance($sheepID)) { if ($sheepTable->toggleSheepTracking($sheep->getSheepID(), 1)) { // TODO limit to 160 characters $messageForSheep = "Welcome back to the '" . $flock->getFlockName() . "' flock! To suspend tracking again, text 'SUSPEND' to 84433 (Texts cost 10p)." . "Confused? Find out more at www.flockbuddy.com"; } } elseif ($sheepTable->confirmSheepAcceptance($sheep->getSheepID())) { // TODO Set App play package name address.
<?php /* * FlockBuddy - the Android app to keep track of your flock. * HackMCR2015 - Tim Tyler, Steven Tomlinson, Mudit Pandya * 24/10/2015 - 25/10/2015 */ /** * Returns an XML object containing all sheep in given flock. * @author Tim Tyler */ require_once 'autoload.php'; if (isset($_POST)) { $sheepTable = new SheepTable(); $sheeps[] = $sheepTable->getAllSheeps($_POST['flockID']); echo $sheepTable->buildSheepsXML($sheeps); }
<?php require_once 'autoload.php'; /* * FlockBuddy - the Android app to keep track of your flock. * HackMCR2015 - Tim Tyler, Steven Tomlinson, Mudit Pandya * 24/10/2015 - 25/10/2015 */ /** * Updates tracking info for one sheep, then analyses distances from Shepherd * - can trigger lost sheep message if distance is > maxRadius. * @author Tim Tyler */ if (isset($_POST)) { $flockTable = new FlockTable(); $sheepTable = new SheepTable(); $geoDistance = new GeoDataSource(); $sheepMobile = '44' . substr($_POST['mobile'], 1); // Locate flock and sheep. $sheep = $sheepTable->getSheepUsingSheepMobile($sheepMobile); $flock = $flockTable->getFlockUsingFlockID($sheep->getFlockID()); $newX = $_POST['longtitude']; $newY = $_POST['latitude']; $sheepTable->updateSheepCoordinates($sheep->getSheepID(), $newX, $newY); $shepherd = $flock->getShepherd(); $shepherdX = $shepherd->getSheepLongtitude(); $shepherdY = $shepherd->getSheepLatitude(); $flockMaxRadius = $flock->getFlockRadius(); $distanceFromShepherd = $geoDistance->distance($newY, $newX, $shepherdY, $shepherdX, "M"); if ($distanceFromShepherd > $flockMaxRadius) { // SEND MESSAGE.
public function getShepherd() { $sheepTable = new SheepTable(); return $sheepTable->getSheepUsingSheepID($this->flockShepherdID); }