Ejemplo n.º 1
0
function sql_error_report($sql, $file)
{
    $date = getDateNow();
    $sqlError = mysql_error();
    mysql_query(sprintf("INSERT INTO errors (type, error, extra, date) VALUES ('SQL', '%s', '%s:%s', '%s');", addslashes($sqlError), $file, addslashes($sql), $date));
    $ret = array("status" => "SQL_ERROR", "error" => $sqlError, "sql" => $sql);
    die(json_encode($ret));
}
Ejemplo n.º 2
0
// to improve with mutual likes
if ($fbcmdCommand == 'FLIKES') {
    ValidateParamCount(1, 2);
    $count = 1;
    if ($fbcmdParams[2] != null) {
        $count = $fbcmdParams[2];
    }
    $fql = "select name, page_id from page where page_id in ( SELECT page_id FROM page_fan WHERE uid IN ( {$fbcmdParams[1]} ) ) LIMIT 1,{$count}";
    try {
        $fbReturn = $fbObject->api_client->fql_query($fql);
        TraceReturn($fbReturn);
    } catch (Exception $e) {
        FbcmdException($e);
    }
    if (!empty($fbReturn)) {
        $date_now = getDateNow();
        $fileName = "output.json";
        file_put_contents($fileName, '{"likes":' . json_encode($fbReturn) . "}\n");
        file_put_contents("query.fql", '{"query":{"date":"' . $date_now . '","fql":"' . $fql . '"}}');
        print "(writing on {$fileName})";
    } else {
        print "error for {$fbUser}";
    }
}
if ($fbcmdCommand == 'OINFO') {
    //     ValidateParamCount(1,2);
    //     SetDefaultParam(1,$fbcmdPrefs['default_finfo_fields']);
    //     SetDefaultParam(2,$fbcmdPrefs['default_finfo_flist']);
    //     GetFlistIds($fbcmdParams[2]);
    $info_fields = "uid,name,friend_count,mutual_friend_count,pic_small,profile_url,sex,significant_other_id";
    $uid_list = $fbcmdParams[1];
Ejemplo n.º 3
0
function startGame($gameId, $gameName, $players)
{
    $playerNumber = count($players);
    if ($playerNumber < 3) {
        return;
    }
    $date = getDateNow();
    $dateLimit = getDateLimit();
    // Start the game
    $sql = "UPDATE games SET state='ACTIVE' WHERE gameId='{$gameId}' LIMIT 1;";
    mysql_query($sql) or sql_error_report($sql, $_SERVER["SCRIPT_NAME"]);
    // Randomize the players
    shuffle($players);
    $assassinationList = '';
    for ($i = 0; $i < $playerNumber; $i++) {
        $playerId = $players[$i];
        $victimId = $players[($i + 1) % $playerNumber];
        trace("Starting: {$playerId} -> {$victimId}");
        if ($assassinationList != '') {
            $assassinationList .= ', ';
        }
        $assassinationList .= "('{$gameId}', '{$playerId}', '{$victimId}', 'PENDING', '{$date}', '{$dateLimit}')";
    }
    $sql = "INSERT INTO assassinations (gameId, assassinId, victimId, state, startDate, endDate) VALUES {$assassinationList};";
    mysql_query($sql) or sql_error_report($sql, $_SERVER["SCRIPT_NAME"]);
    require_once 'handler.php';
    handleGameStart($gameId);
}
Ejemplo n.º 4
0
function joinGame($playerId, $alias, $tokens)
{
    // check to see that the player's state is NOTHING
    $sql = "SELECT state FROM players WHERE playerId='{$playerId}' LIMIT 1;";
    $result = mysql_query($sql) or sql_error_report($sql, $_SERVER["SCRIPT_NAME"]);
    if ($row = mysql_fetch_assoc($result)) {
        $state = $row['state'];
        if ($state != 'NOTHING') {
            $ret = array("status" => "BAD_STATE", "state" => $state);
            print json_encode($ret);
            return;
        }
    } else {
        $ret = array("status" => "IMPOSSIBLE7");
        die(json_encode($ret));
    }
    // check that the game with the correct token exists
    $tokenList = "'" . implode("','", explode(";\n", $tokens)) . "'";
    $sql = "SELECT gameId FROM games WHERE state = 'PENDING' AND token IN ({$tokenList}) LIMIT 1;";
    $result = mysql_query($sql) or sql_error_report($sql, $_SERVER["SCRIPT_NAME"]);
    if ($row = mysql_fetch_assoc($result)) {
        $gameId = $row['gameId'];
        // check to see if alias exists
        $sql = "SELECT * FROM participations WHERE alias='{$alias}' AND gameId = '{$gameId}' LIMIT 1;";
        $result = mysql_query($sql) or sql_error_report($sql, $_SERVER["SCRIPT_NAME"]);
        if (mysql_num_rows($result) == 1) {
            $ret = array("status" => "ALIAS_TAKEN");
            print json_encode($ret);
            return;
        }
        // get the code word
        $codewords = codewords();
        shuffle($codewords);
        do {
            $codeword = array_pop($codewords);
            $sql = "SELECT * FROM participations WHERE codeword = '{$codeword}' AND gameId = '{$gameId}' LIMIT 1;";
            $result = mysql_query($sql) or sql_error_report($sql, $_SERVER["SCRIPT_NAME"]);
        } while (mysql_num_rows($result) > 0);
        $sql = "INSERT INTO participations (gameId, playerId, state, alias, codeword) VALUES ('{$gameId}', '{$playerId}', 'ACTIVE', '{$alias}', '{$codeword}');";
        mysql_query($sql) or sql_error_report($sql, $_SERVER["SCRIPT_NAME"]);
        $sql = "UPDATE players SET state='PLAYING', waitingAlias='', waitingStart='0000-00-00 00:00:00', tokens='{$tokens}' WHERE playerId = '{$playerId}' LIMIT 1;";
        mysql_query($sql) or sql_error_report($sql, $_SERVER["SCRIPT_NAME"]);
        if (mysql_affected_rows() == 1) {
            $player = getPlayerObject($playerId);
            $news = getNews($playerId);
            $game = getGameObject($playerId, $gameId);
            $ret = array("status" => "OK", "player" => $player, "news" => $news, "game" => $game);
            print json_encode($ret);
            return;
        } else {
            $ret = array("status" => "IMPOSSIBLE8a");
            print json_encode($ret);
            return;
        }
    } else {
        // check to see if alias exists
        $sql = "SELECT * FROM players WHERE waitingAlias='{$alias}' LIMIT 1;";
        $result = mysql_query($sql) or sql_error_report($sql, $_SERVER["SCRIPT_NAME"]);
        if (mysql_num_rows($result) == 1) {
            $ret = array("status" => "ALIAS_TAKEN");
            print json_encode($ret);
            return;
        }
        $date = getDateNow();
        $sql = "UPDATE players SET waitingAlias='{$alias}', state='WAITING', waitingStart='{$date}', tokens='{$tokens}' WHERE playerId='{$playerId}' LIMIT 1;";
        mysql_query($sql) or sql_error_report($sql, $_SERVER["SCRIPT_NAME"]);
        if (mysql_affected_rows() == 1) {
            $player = getPlayerObject($playerId);
            $ret = array("status" => "OK", "player" => $player);
            print json_encode($ret);
            return;
        } else {
            $ret = array("status" => "IMPOSSIBLE8b");
            print json_encode($ret);
            return;
        }
    }
}
Ejemplo n.º 5
0
    }
}
// Check email
if ($fail === false) {
    $name = $part[0];
    $email = $part[1];
    $rule = $part[2];
    if (strstr($email, 'stanford.edu') === false) {
        $fail = 'bad email';
    }
}
// authenticate player
if ($fail === false) {
    require_once 'common.php';
    require_once 'db_login.php';
    $date = getDateNow();
    $sql = "SELECT playerId FROM players WHERE email='{$email}' LIMIT 1;";
    $result = mysql_query($sql) or $fail = mysql_error();
    if ($fail === false) {
        if ($row = mysql_fetch_assoc($result)) {
            // player exists get the playerId
            $playerId = $row['playerId'];
            // update the last time logged in
            $sql = "UPDATE players SET lastLogin='******' WHERE playerId='{$playerId}' LIMIT 1;";
            mysql_query($sql) or $fail = mysql_error();
        } else {
            // first time player, create him
            $sql = "INSERT INTO players (email, name, rule, dateCreated, lastLogin) VALUES ('{$email}', '{$name}', '{$rule}', '{$date}', '{$date}');";
            mysql_query($sql) or $fail = mysql_error();
            if ($fail === false) {
                $sql = "SELECT playerId FROM players WHERE email='{$email}' LIMIT 1;";
Ejemplo n.º 6
0
function emailOnShiftSwapUnFilled($connection, $request_id)
{
    $request_id = mysql_real_escape_string($request_id);
    $query = 'select requests.created as request_created,shifts.user_id as owner_id, shifts.name as shift_name,shifts.time_begin as shift_begin,shifts.time_end as shift_end ' . ' from requests left outer join shifts on requests.shift_id=shifts.id where requests.id="' . $request_id . '";';
    $result = mysql_query($query);
    if ($result && mysql_num_rows($result) == 1) {
        $row = mysql_fetch_assoc($result);
        $owner_id = $row["owner_id"];
        $shift_name = $row["shift_name"];
        $request_created = dateFromString($row["request_created"]);
        $shift_begin = dateFromString($row["shift_begin"]);
        $shift_end = dateFromString($row["shift_end"]);
        $subject = 'BSFTH Swap Request';
        $body = 'The following Shift Swap has been un-filled (at ' . getHumanFullDateFromDate(getDateNow()) . '):  ' . $shift_name . ' : ' . getHumanDayFromDate($shift_begin) . ', ' . getHumanTimeOfDayFromDate($shift_begin) . ' - ' . getHumanTimeOfDayFromDate($shift_end);
        mysql_free_result($result);
        $query = 'select id,username,email from users where (id="' . $owner_id . '" and preference_email_shift_self="1") or preference_email_shift_other="1";';
        $result = mysql_query($query);
        if ($result) {
            while ($row = mysql_fetch_assoc($result)) {
                $email = $row["email"];
                if (isValidEmail($email)) {
                    sendEmailBSFTH($email, $subject, $body);
                }
            }
            mysql_free_result($result);
        } else {
            //error_log("could not send users data");
        }
        mysql_free_result($result);
    }
}
Ejemplo n.º 7
0
 public function bogies_put()
 {
     $id = (int) $this->get('id');
     if ($id <= 0) {
         $message = ['status' => false, 'message' => 'incorrect id'];
         $this->response($message, REST_Controller::HTTP_BAD_REQUEST);
         // BAD_REQUEST (400)
     }
     $entity = $this->_put_args;
     $entity['UPDATE_DATE'] = getDateNow();
     $entity['UPDATE_USER'] = GetCurr_UserLoginID();
     $this->Bogie_Model->Update($entity, $id);
     $message = ['status' => true, 'message' => 'data was updated', 'result' => $entity];
     $this->set_response($message, REST_Controller::HTTP_OK);
     // OK (200)
 }
Ejemplo n.º 8
0
<?php

// index.php
//error_reporting(E_WARNING);
error_reporting(E_ERROR);
// mysql warnings
require "functions.php";
require "config.php";
// 22:30 -> 01:30 = ahead by 3 hours
$TIME_ZONE_OFFSET = -3 * 60;
// in minutes
$TIME_NOW = ' adddate(now(),interval ' . $TIME_ZONE_OFFSET . ' minute) ';
$DATE_NOW = getDateNow();
/*
// headers
$headers = apache_request_headers();
foreach($headers as $header => $value){
	//echo ": ".$header." = ".$value."<br/>";
	if($header=="Authorization"){
		//
	}else if($header=="Host"){
		// 
	}else if($header=="Cache-Control"){
		// 
	}else if($header=="User-Agent"){
		// 
	}else if($header=="Content-type"){
		// 
	}else if($header=="Accept"){
		// 
	}else if($header=="Referer"){