Exemplo n.º 1
0
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.
                // http://developer.android.com/distribute/tools/promote/linking.html#OpeningDetails