function addTeams($con, $comp, $teams)
{
    $current = array();
    foreach ($comp->selectTeams($con) as $team) {
        array_push($current, $team->Number);
        // printf("%s %s %s %s %s\n",
        //        $team->Number, $team->Name, $team->City, $team->State, $team->Country);
    }
    foreach ($teams as $team) {
        if (!in_array($team->Number, $current)) {
            printf("Adding %s to %s\n", $team->Number, $comp->Name);
            $st = team::selectTeam($con, $team->Number);
            if (!$st) {
                printf("New team:  {$team->Number}, {$team->Name}, {$team->City}, {$team->State}, {$team->Country}\n");
                team::insertTeam($con, (array) $team);
            }
            $comp->insertTeam($con, $team->Number);
        } else {
            printf("Team %s to already added.\n", $team->Number);
        }
    }
}
<?php

set_include_path(__DIR__);
require_once 'lib/db.php';
require_once 'lib/team.php';
include 'header.php';
$con = DB::connect();
if ($_SERVER['REQUEST_METHOD'] == 'GET') {
    $team = null;
    $btn = "Create";
    if (isset($_GET["number"])) {
        // edit an existing team
        $number = $_GET["number"];
        $team = team::selectTeam($con, $number);
        $btn = "Update";
        // echo "number " . $team['Number'] . " name " . $team['Name'];
    } else {
        $team = new team();
        // make an empty
    }
    $form = "\n<form action='team-form.php' method='post'>\n<table>\n  <tr>\n    <td>Number</td>\n    <td><input type='text' name='Number' value='" . $team->Number . "'></td>\n  </tr>\n  <tr>\n    <td>Name</td>\n    <td><input type='text' name='Name' value='" . $team->Name . "'></td>\n  </tr>\n  <tr>\n    <td>City</td>\n    <td><input type='text' name='City' value='" . $team->City . "'></td>\n  </tr>\n  <tr>\n    <td>State</td>\n    <td><input type='text' name='State' value='" . $team->State . "'></td>\n  </tr>\n  <tr>\n    <td>Country</td>\n    <td><input type='text' name='Country'  value='" . $team->Country . "'></td>\n  </tr>\n</table>\n<br>";
    echo "<h2>" . $btn . " Team</h2>";
    echo $form;
    echo "<input value='" . $btn . "' type='Submit'>\n          </form>";
} else {
    // create a new team
    echo "POST";
}
include 'footer.php';
            break;
        case JSON_ERROR_STATE_MISMATCH:
            $error = 'Underflow or the modes mismatch';
            break;
        case JSON_ERROR_CTRL_CHAR:
            $error = 'Unexpected control character found';
            break;
        case JSON_ERROR_SYNTAX:
            $error = 'Syntax error, malformed JSON';
            break;
        case JSON_ERROR_UTF8:
            $error = 'Malformed UTF-8 characters, possibly incorrectly encoded';
            break;
    }
    throw new Exception($error);
}
$homepage = file_get_contents('teams.json');
$teams = json_decode($homepage, true, 5);
json_last_error_msg();
// var_dump($teams);
$con = DB::connect();
foreach ($teams as $team) {
    $st = team::selectTeam($con, $team['Number']);
    if (!$st) {
        printf("Missing: %s, %s, %s\n", $team['Number'], $team['Name'], $team['City']);
        team::insertTeam($con, $team);
    }
    // else {
    //    var_dump($st);
    //}
}
Beispiel #4
0
                }
                print "{$property} = {$value}";
                $first = false;
            }
        }
        print "\n";
    }
}
function reportMatch($match)
{
    $red = $match->RedAlliance;
    $blue = $match->BlueAlliance;
    printf("{$match->ID}, {$match->Time}, {$match->Number}, {$red->TeamOne}, {$red->TeamTwo}, {$red->TeamThree}, " . "{$blue->TeamOne}, {$blue->TeamTwo}, {$blue->TeamThree}, {$red->Points}, {$blue->Points}\n");
}
$match = match::select($con, 42);
$team = team::selectTeam($con, 1425);
// reportMatch($match);
if ($match == null) {
    die("match not found.");
}
if ($team == null) {
    die("team not found.");
}
// reportMatch($match);
printf("match = %s, team = %s\n", $match->ID, $match->Number);
/*
$game = new game();
$game->MatchID = $match->ID;
$game->MatchNumber = $match->Number;
$game->TeamNumber = $team->Number;
$game->Autonomous = 9;