Example #1
0
<?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());
}
Example #2
0
<?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 {
Example #3
0
<?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.