Example #1
0
<?php

/**
 * Created by PhpStorm.
 * User: davidkryzaniak
 * Date: 24/10/15
 * Time: 16:10
 */
require_once __DIR__ . '/../classes/MonsterMonday.php';
$mm = new MonsterMonday();
$timeIs = time() - strtotime("today");
//seconds since midnight
$dayOfWeekIs = date('N');
// 7 == Sunday
$TIME_NOON = 43200;
//NOON
$TIME_LAST_CALL = 64875;
//6:15pm
// are we in the correct time slot (Sunday)
if (7 == $dayOfWeekIs && $timeIs > 43000 && $timeIs < 64875) {
    // is this the buyer?
    $theBuyer = $mm->getWeekBuyer();
    $mm->setSendMessage($theBuyer['number'], 'MONSTER MONDAY REMINDER: Ohh Snap! It\'s your turn to buy! Please reply YES or NO to confirm.');
    exit;
}
if (7 == $dayOfWeekIs && $timeIs > 64975 && $mm->getIsWeekStatusSet() === NULL) {
    // is this the buyer?
    $theBuyer = $mm->getWeekBuyer();
    $mm->setSendMessageToAll("MONSTER MONDAY has been cancelled. {$theBuyer['name']} never replied to the reminder");
    exit;
}
$messageBody = '' . trim($_REQUEST['Body']);
$receivedFrom = '' . trim($_REQUEST['From']);
$timeIs = time() - strtotime("today");
//seconds since midnight
$dayOfWeekIs = date('N');
// 7 == Sunday
$TIME_NOON = 43200;
//NOON
$TIME_LAST_CALL = 64875;
//6:15pm
$mm->logMessage($receivedFrom, $messageBody);
// ================================ Do stuff with the message  ================================ //
// are we in the correct time slot (Sunday)
if (7 == $dayOfWeekIs && $timeIs > 43200 && $timeIs < 64875) {
    // is this the buyer?
    $theBuyer = $mm->getWeekBuyer();
    if ($theBuyer['number'] == $receivedFrom) {
        // check to make sure they have not verified already
        if (NULL !== $mm->getIsWeekStatusSet()) {
            $mm->setSendMessage($receivedFrom, 'Sorry, you\'ve already replied a status for this week!');
            header($_SERVER['SERVER_PROTOCOL'] . ' OK', true, 200);
            exit;
        }
        // is this a confirmation from the buyer?
        if ('yes' == strtolower(substr($messageBody, 0, 4))) {
            $mm->setSendMessageToAll("Kudos to {$theBuyer['name']}! Monster Monday is a go.");
            $mm->setWeekStatus(TRUE);
            // mark this week as a success
            $mm->logMessage('localhost', "Kudos to {$theBuyer['name']}! Monster Monday is a go.");
            header($_SERVER['SERVER_PROTOCOL'] . ' OK', true, 200);
            exit;