Example #1
0
 * @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
                // TODO limit to 160 characters
                $messageForSheep = "Great, you have joined the '" . $flock->getFlockName() . "' flock! Tracking will begin at " . $flock->getFlockStart() . " To suspend tracking, text 'SUSPEND' to 84433 (Texts cost 10p). " . "Now install http://play.google.com/store/apps/details?id=<package_name>. " . "Confused? Find out more at www.flockbuddy.com";
            }
            break;
        case "FLOCKMENOT":
            // User rejection message, remove sheep from database.
            $shepherd = $flock->getShepherd();
            // Check if sheep cancelling is the shepherd.
            if ($sheep->getSheepID() === $shepherd->getSheepID()) {