Example #1
0
<?php

// List teams route (api/team/)
global $dbh;
// Auth user
$user = Auth::authAPICall($dbh);
// Initialize scouting db
$sdb = new ScoutingDB($dbh, $user["organization_id"], 1, $user["id"]);
// Default team fields
$default_fields = array("id", "team_number", "team_name", "team_type", "summary", "strengths", "weaknesses", "use_markdown", "date_added");
$options = array_merge(array("sort_col" => "team_number", "sort_dir" => "up", "page" => 0, "limit" => 100, "fields" => $default_fields, "search" => ""), $get);
$safe_fields = $options["fields"] === $default_fields;
$options["search"] = urldecode($options["search"]);
$where = array();
// Output results
$output = array("data" => $sdb->getList("team", $options["sort_col"], $options["sort_dir"], $options["page"], $options["limit"], $options["fields"], $safe_fields, $where, $options["search"]), "numPages" => $sdb->getNumPages("team", $options["limit"], $where, $options["search"], $options["fields"]));
Example #2
0
<?php

// Add new feed route (api/feed/new)
global $dbh;
// Auth user
$user = Auth::authAPICall($dbh);
$sdb = new ScoutingDB($dbh, $user["organization_id"], 1, $user["id"]);
global $_POST;
$data = array_merge(array("entry" => "", "url" => ""), $_POST, array("organization_user_id" => $user["id"]));
if (strlen($data["entry"])) {
    global $_FILES;
    $id = $sdb->addFeedEntry($data);
    if ($id) {
        $entry = $sdb->getItem("feed_entry", array("id" => $id));
        $user = $sdb->getItem("organization_user", array("id" => $entry["organization_user_id"]), array("firstname", "lastname"));
        $entry["organization_user"] = $user["firstname"] . " " . $user["lastname"];
        if (strlen($entry["filename"])) {
            global $api_dir;
            rename("{$api_dir}/feed_files/files/last-{$entry["filename"]}", "{$api_dir}/feed_files/files/{$id}-{$entry["filename"]}");
        }
        $output = array("success" => true, "data" => $entry);
    } else {
        $output = array("success" => false, "error" => array("Server Error"));
    }
} else {
    $output = array("success" => false, "errors" => array("You must enter the entry text"));
}
Example #3
0
<?php

// List users route (api/user/)
global $dbh;
// Auth user
$user = Auth::authAPICall($dbh);
// Initialize scouting db
$sdb = new ScoutingDB($dbh, $user["organization_id"], 1, $user["id"]);
// Default user fields
$default_fields = array("id", "username", "firstname", "lastname", "active", "date_added");
$options = array_merge(array("sort_col" => "id", "sort_dir" => "up", "page" => 0, "limit" => 100, "fields" => $default_fields), $get);
$safe_fields = $options["fields"] === $default_fields;
// Output results
$output = array("data" => $sdb->getList("organization_user", $options["sort_col"], $options["sort_dir"], $options["page"], $options["limit"], $options["fields"], $safe_fields), "numPages" => $sdb->getNumPages("organization_user", $options["limit"]));
Example #4
0
     } else {
         $organization = array();
         $errors[] = "Invalid team number";
     }
 }
 if (strlen($username) && strlen($password) && count($organization)) {
     $users = new Auth($dbh, $organization["id"]);
     $user = $users->authUsernamePassword($username, $password);
     if (is_array($user)) {
         if (isset($user["error"])) {
             // Inactive user, etc.
             $errors[] = $user["error"];
         } else {
             $success = true;
             $token = Token::create($dbh, $user["id"]);
             $sdb = new ScoutingDB($dbh, $organization["id"], 1, $user["id"]);
             $organization["team_numbers"] = array_map(function ($team) {
                 return $team["team_number"];
             }, $sdb->getList("team", "team_number", "up", 1, 10000, $fields = array("team_number"), 1));
         }
     } else {
         $errors[] = "Invalid username/password";
     }
 } else {
     $errors[] = $required_fields_err;
 }
 $output = array();
 $output["success"] = $success;
 $output["error"] = $errors;
 if (strlen($token)) {
     $output["token"] = $token;
<?php

$api_dir = __DIR__;
require_once "{$api_dir}/helpers.php";
require_all("{$base_dir}/classes");
require "{$api_dir}/pages/team/default-fields.php";
$default_fields = $output["fields"];
$user = array("organization_id" => 1, "id" => 1);
$dbh = new DBHandler(json_decode(file_get_contents("{$api_dir}/dbconfig.json"), 1));
$sdb = new ScoutingDB($dbh, $user["organization_id"], 1, $user["id"]);
$tba = new TBA();
$file = $argv[1];
if (!file_exists($file)) {
    die("{$file} does not exist");
}
$file_contents = file_get_contents($file);
$data = array("stats" => array("defenses" => json_decode($file_contents, 1)));
$team_stats = array();
foreach ($data["stats"] as $stat => $teams) {
    if (is_string($teams)) {
        $teams = json_decode($teams, 1);
    }
    foreach ($teams as $team_number => $stats) {
        if (!isset($team_stats[$team_number])) {
            $team_stats[$team_number] = array();
        }
        $team_stats[$team_number][$stat] = $stats;
    }
}
$json_fields = array("questions", "stats");
foreach ($team_stats as $team_number => $stats) {
Example #6
0
<?php

// Get user route (api/user/:userID )
global $dbh;
// Auth user
$user = Auth::authAPICall($dbh);
// Initialize scouting db
$sdb = new ScoutingDB($dbh, $user["organization_id"], 1, $user["id"]);
function array_pluck($array = array(), $keys = array(), $default_values = array())
{
    $result = array();
    $array = array_merge($default_values, $array);
    foreach ($keys as $key) {
        $result[$key] = isset($array[$key]) ? $array[$key] : NULL;
    }
    return $result;
}
$default_fields = array("id", "firstname", "lastname", "username", "active");
$options = array_merge(array("fields" => $default_fields), $get);
$default_values = array("id" => 0, "firstname" => "", "lastname" => "", "username" => "");
$safe_fields = $options["fields"] === $default_fields;
$where = array();
if (is_numeric($data["userID"])) {
    $where["id"] = $data["userID"];
} else {
    $where["username"] = $data["userID"];
}
$output = array("data" => $sdb->getItem("organization_user", $where, $options["fields"], $safe_fields));
$output["data"] = array_pluck($output["data"], $options["fields"], $default_values);
if (!is_array($output["data"]) || !count($output["data"])) {
    $output["data"] = array();
Example #7
0
<?php

// Feed route (api/feed/)
global $dbh;
// Auth user
$user = Auth::authAPICall($dbh);
$sdb = new ScoutingDB($dbh, $user["organization_id"], 1, $user["id"]);
$options = array_merge(array("id" => 0, "down" => 0), $get);
$where = array("id" => $options["id"]);
$feed_entry = $sdb->getItem("feed_entry", array("id" => $options["id"]), array("id", "entry", "filename"), true);
if (is_array($feed_entry) && isset($feed_entry["id"]) && $feed_entry["id"] > 0 && isset($feed_entry["filename"]) && strlen($feed_entry["filename"])) {
    global $api_dir;
    $filepath = "{$api_dir}/feed_files/files/{$feed_entry["id"]}-{$feed_entry["filename"]}";
    if (file_exists($filepath)) {
        $file_info = new SplFileInfo($filepath);
        $extension = strtolower($file_info->getExtension());
        $image_extensions = array("jpg", "jpeg", "png", "gif");
        if (in_array($extension, $image_extensions)) {
            $type = "image/{$extension}";
            header("Content-Type: {$type}");
            header("Content-Length: " . filesize($filepath));
        } else {
            header('Content-Description: File Transfer');
            header('Content-Type: application/octet-stream');
            header('Content-Disposition: attachment; filename="' . basename($feed_entry["filename"]) . '"');
            header('Expires: 0');
            header('Cache-Control: must-revalidate');
            header('Pragma: public');
            header('Content-Length: ' . filesize($filepath));
        }
        readfile($filepath);
Example #8
0
<?php

// Add team route (api/team/new)
global $dbh;
// Auth user
$user = Auth::authAPICall($dbh);
// Initialize scouting db
$sdb = new ScoutingDB($dbh, $user["organization_id"], 1, $user["id"]);
$required_fields = array("team_name" => "Team Name");
$other_fields = array("weaknesses", "summary", "score", "strengths", "questions_json", "scores_json");
$errors = array();
$success = true;
if (isset($post) && count($post) && $_SERVER["REQUEST_METHOD"] == "POST") {
    $team_data = array();
    foreach ($required_fields as $field => $label) {
        if (isset($post[$field])) {
            if (strlen(trim($post[$field]))) {
                $team_data[$field] = trim($post[$field]);
            } else {
                $errors[] = array("field" => $field, "msg" => "{$label} can't be blank");
                $success = false;
            }
        }
    }
    foreach ($other_fields as $field) {
        if (isset($post[$field])) {
            $team_data[$field] = trim($post[$field]);
        }
    }
    if ($success) {
        $existing = $sdb->getItem("team", array("team_number" => $data["teamID"]));
Example #9
0
<?php

// Feed route (api/feed/)
global $dbh;
// Auth user
$user = Auth::authAPICall($dbh);
$sdb = new ScoutingDB($dbh, $user["organization_id"], 1, $user["id"]);
$default_fields = array("id", "organization_user_id", "name", "url", "entry", "filename", "use_markdown", "date_added");
$options = array_merge(array("sort_col" => "date_added", "sort_dir" => "down", "page" => 1, "limit" => 20, "fields" => $default_fields, "url" => ""), $get);
$safe_fields = $options["fields"] === $default_fields;
$where = array();
if (strlen($options["url"])) {
    $where["url"] = $options["url"];
}
// Output results
$output = array("data" => $sdb->getList("feed_entry", $options["sort_col"], $options["sort_dir"], $options["page"], $options["limit"], $options["fields"], $safe_fields, $where), "numPages" => $sdb->getNumPages("feed_entry", $options["limit"], $where));
foreach ($output["data"] as &$row) {
    $user = $sdb->getItem("organization_user", array("id" => $row["organization_user_id"]), array("firstname", "lastname"));
    $row["organization_user"] = $user["firstname"] . " " . $user["lastname"];
}
Example #10
0
<?php

// Import teams route (api/team/import)
// Import teams from a tba event code (e.g. "2016ncral")
global $dbh;
// Auth user
$user = Auth::authAPICall($dbh);
// Initialize scouting db
$sdb = new ScoutingDB($dbh, $user["organization_id"], 1, $user["id"]);
$tba = new TBA();
require __DIR__ . "/default-fields.php";
$default_fields = $output["fields"];
$required_fields = array("event_code" => "Event Code");
$other_fields = array();
$errors = array();
$success = true;
if (isset($post) && count($post) && $_SERVER["REQUEST_METHOD"] == "POST") {
    $team_data = array();
    foreach ($required_fields as $field => $label) {
        if (isset($post[$field]) && strlen(trim($post[$field]))) {
            $team_data[$field] = trim($post[$field]);
        } else {
            $errors[] = array("field" => $field, "msg" => "{$label} is required");
            $success = false;
        }
    }
    foreach ($other_fields as $field) {
        if (isset($post[$field]) && strlen(trim($post[$field]))) {
            $team_data[$field] = trim($post[$field]);
        }
    }
Example #11
0
<?php

// Add team route (api/team/new)
global $dbh;
// Auth user
$user = Auth::authAPICall($dbh);
// Initialize scouting db
$sdb = new ScoutingDB($dbh, $user["organization_id"], 1, $user["id"]);
$required_fields = array("team_number" => "Team Number", "team_name" => "Team Name");
$other_fields = array("weaknesses", "summary", "score", "strengths", "questions_json", "scores_json");
$errors = array();
$success = true;
if (isset($post) && count($post) && $_SERVER["REQUEST_METHOD"] == "POST") {
    $team_data = array();
    foreach ($required_fields as $field => $label) {
        if (isset($post[$field]) && strlen(trim($post[$field]))) {
            $team_data[$field] = trim($post[$field]);
        } else {
            $errors[] = array("field" => $field, "msg" => "{$label} is required");
            $success = false;
        }
    }
    foreach ($other_fields as $field) {
        if (isset($post[$field]) && strlen(trim($post[$field]))) {
            $team_data[$field] = trim($post[$field]);
        }
    }
    if ($success) {
        $existing = $sdb->getItem("team", array("team_number" => $team_data["team_number"]));
        if (count($existing)) {
            $success = false;
Example #12
0
<?php

// List teams route (api/team/)
global $dbh;
// Auth user
$user = Auth::authAPICall($dbh);
// Initialize scouting db
$sdb = new ScoutingDB($dbh, $user["organization_id"], 1, $user["id"]);
// Default team fields
$default_fields = array("id", "team_number", "team_name", "team_type", "summary", "score", "strengths", "weaknesses", "questions_json", "scores_json", "stats_json", "use_markdown", "date_added");
$options = array_merge(array("fields" => $default_fields, "query" => ""), $get);
$safe_fields = $options["fields"] === $default_fields;
// Output results
$output = array("data" => $sdb->getItem("team", array("team_number" => $data["teamID"]), $options["fields"], $safe_fields));