function listCompetitions()
{
    #----------------------------------------------------------------------
    global $chosenEventId, $chosenYears, $chosenRegionId, $chosenPatternHtml;
    global $chosenList, $chosenMap;
    global $chosenCompetitions;
    $chosenCompetitions = getCompetitions($chosenList);
    tableBegin('results', 5);
    tableCaption(false, spaced(array(eventName($chosenEventId), chosenRegionName(), $chosenYears, $chosenPatternHtml ? "\"{$chosenPatternHtml}\"" : '')));
    if ($chosenList) {
        tableHeader(explode('|', 'Year|Date|Name|Country, City|Venue'), array(4 => 'class="f"'));
        foreach ($chosenCompetitions as $competition) {
            extract($competition);
            if (isset($previousYear) && $year != $previousYear) {
                tableRowEmpty();
            }
            $previousYear = $year;
            $isPast = wcaDate('Ymd') > 10000 * $year + 100 * $month + $day;
            tableRow(array($year, competitionDate($competition), $isPast ? competitionLink($id, $cellName) : ($showPreregForm || $showPreregList ? competitionLinkClassed('rg', $id, $cellName) : competitionLinkClassed('fc', $id, $cellName)), "<b>{$countryName}</b>, {$cityName}", processLinks($venue)));
        }
    }
    tableEnd();
    if ($chosenMap) {
        // create map markers
        $markers = array();
        foreach ($chosenCompetitions as $comp) {
            $markers[$comp['id']] = array();
            $markers[$comp['id']]['latitude'] = $comp['latitude'];
            $markers[$comp['id']]['longitude'] = $comp['longitude'];
            $markers[$comp['id']]['info'] = "<a href='c.php?i=" . $comp['id'] . "'>" . o($comp['cellName']) . "</a><br />" . date("M j, Y", mktime(0, 0, 0, $comp['month'], $comp['day'], $comp['year'])) . " - " . o($comp['cityName']);
        }
        displayMap($markers);
    }
}
Exemplo n.º 2
0
function showMatchingPersons()
{
    #----------------------------------------------------------------------
    global $chosenPatternHtml, $chosenPatternMysql, $chosenEventId, $chosenRegionId;
    #--- If nothing chosen yet, display a help message.
    if (!$chosenPatternHtml && !$chosenEventId && !$chosenRegionId) {
        echo "<div style='width:85%; margin:auto; font-size:1.00em; font-weight:bold'><p>For the name field search, enter any name or name parts and don't worry about letter variations. For example, 'or joe' (enter without the quotes) will among others also find Jo&euml;l van Noort.</p></div>";
        return;
    }
    #--- The pattern should contain at least 2 non-whitespace characters.
    if (!preg_match('/\\S.*\\S/', $chosenPatternHtml)) {
        noticeBox3(-1, "Please Enter at least 2 characters.");
        echo "<div style='width:85%; margin:auto; font-size:1.00em; font-weight:bold'><p>For the name field search, enter any name or name parts and don't worry about letter variations. For example, 'or joe' (enter without the quotes) will among others also find Jo&euml;l van Noort.</p></div>";
        return;
    }
    #--- Otherwise, build up a query to search for people.
    global $wcadb_conn;
    $params = array(0 => '');
    $parts = array();
    $rawPattern = getRawParamThisShouldBeAnException('pattern');
    #--- Build the nameCondition (all searched parts must occur).
    $nameCondition = "";
    foreach (explode(' ', $rawPattern) as $namePart) {
        $parts[$namePart] = '%' . $namePart . '%';
        $params[0] .= 's';
        $params[] =& $parts[$namePart];
        $likeId = '';
        if (ctype_alnum($namePart)) {
            $params[0] .= 's';
            $params[] =& $parts[$namePart];
            $likeId = ' OR person.id LIKE ?';
        }
        $nameCondition .= ' AND (person.name LIKE ?' . $likeId . ')';
    }
    #--- Build the eventCondition (if any).
    if ($chosenEventId) {
        $eventConditionPart1 = ', (SELECT DISTINCT personId FROM ConciseSingleResults WHERE 1 ' . eventCondition() . ') result';
        $eventConditionPart2 = 'AND person.id = result.personId';
    } else {
        $eventConditionPart1 = '';
        $eventConditionPart2 = '';
    }
    #--- Do the query!
    $query = 'SELECT DISTINCT person.id AS personId, person.name AS personName, country.name AS countryName
            FROM Persons AS person, Countries AS country' . $eventConditionPart1 . ' WHERE ' . randomDebug() . $nameCondition . regionCondition('') . ' AND country.id = person.countryId' . $eventConditionPart2 . ' ORDER BY personName, countryName, personId';
    $persons = $wcadb_conn->boundQuery($query, $params);
    $count = count($persons);
    $ext = $count != 1 ? 's' : '';
    tableBegin('results', 3);
    tableCaption(false, spaced(array("{$count} person{$ext} matching:", eventName($chosenEventId), chosenRegionName($chosenRegionId), $chosenPatternHtml ? "\"{$chosenPatternHtml}\"" : '')));
    tableHeader(explode('|', 'Person|WCA id|Citizen of'), array(2 => 'class="f"'));
    foreach ($persons as $person) {
        extract($person);
        tableRow(array(personLink($personId, $personName), $personId, $countryName));
    }
    tableEnd();
}
function chosenEventName()
{
    global $chosenEventId;
    return $chosenEventId ? eventName($chosenEventId) : '';
}
    extract($result);
    $result['regionName'] = $continentName;
    if (isset($showContinent[$continentId]) && $value == $bestValueOfContinent[$continentId]) {
        $bestOfContinent[] = $result;
    }
    $result['regionName'] = 'World';
    if ($value == $bestValueOfWorld) {
        $bestOfWorld[] = $result;
    }
}
#----------------------------------------------------------------------
#   Print the table.
#----------------------------------------------------------------------
startTimer();
$regionName = preg_replace('/^_/', '', $chosenRegionId);
$eventName = eventName($chosenEventId);
$headerSources = $chosenAverage ? 'Result Details' : '';
tableBegin('results', 5);
tableCaption(true, spaced(array($eventName, $chosenShow, $regionName, $chosenYears)));
tableHeader(explode('|', "Region|Result|Person|Competition|{$headerSources}"), array(0 => 'class="L"', 1 => "class='R2'", 4 => 'class="f"'));
if (isset($bestOfCountry)) {
    $all = array_merge($bestOfWorld, array(0), $bestOfContinent, array(0), $bestOfCountry);
    foreach ($all as $row) {
        if (!$row) {
            tableRowEmpty();
            continue;
        }
        extract($row);
        $isNewRegion = !isset($previousRegionName) || $regionName != $previousRegionName;
        $previousRegionName = $regionName;
        tableRow(array($isNewRegion ? $regionName : '', $isNewRegion ? formatValue($value, $valueFormat) : '', personLink($personId, $personName), competitionLink($competitionId, $competitionName), formatAverageSources($chosenAverage, $row, $valueFormat)));
function showPsychSheet($eventId)
{
    #----------------------------------------------------------------------
    global $chosenCompetitionId;
    echo "<h1>Psych Sheet</h1><br />";
    #--- What's first, single or average?
    $order = count(dbQuery("SELECT * FROM Results WHERE eventId='{$eventId}' AND formatId in ('a','m') LIMIT 1")) ? array('Average', 'Single') : array('Single', 'Average');
    #--- Get singles, averages and preregs.
    $score1 = array();
    foreach (dbQuery("SELECT personId, best, worldRank FROM Ranks{$order[0]} WHERE eventId='{$eventId}'") as $row) {
        $score1[$row['personId']] = array($row['best'], $row['worldRank']);
    }
    $score2 = array();
    foreach (dbQuery("SELECT personId, best, worldRank FROM Ranks{$order[1]} WHERE eventId='{$eventId}'") as $row) {
        $score2[$row['personId']] = array($row['best'], $row['worldRank']);
    }
    $preregs = dbQuery("\n    SELECT personId, name, countryId\n    FROM   Preregs\n    WHERE  competitionId = '{$chosenCompetitionId}'\n      AND  status = 'a'\n      AND  eventIds rlike '[[:<:]]{$eventId}[[:>:]]'\n  ");
    #--- Add singles, averages and a comparison key to the preregs.
    foreach ($preregs as &$prereg) {
        extract($prereg);
        $prereg['score1'] = isset($score1[$personId]) ? $score1[$personId] : array(0, 0);
        # PHP suuuucks
        $prereg['score2'] = isset($score2[$personId]) ? $score2[$personId] : array(0, 0);
        $s1 = isset($score1[$personId]) ? $score1[$personId][1] : 999999999;
        $s2 = isset($score2[$personId]) ? $score2[$personId][1] : 999999999;
        $prereg['cmpKey'] = sprintf('%09d%09d', $s1, $s2);
    }
    unset($prereg);
    # Because otherwise PHP is a weirdo and messes up the table-foreach below.
    #--- Sort the preregs.
    usort($preregs, function ($a, $b) {
        return strcmp($a['cmpKey'], $b['cmpKey']);
    });
    #--- Show the preregs table.
    tableBegin('results', 8);
    tableCaption(false, eventName($eventId));
    tableHeader(explode('|', "Rank|Person|Citizen of|Best {$order[0]}|WR|Best {$order[1]}|WR|"), array(0 => 'class="r"', 3 => 'class="R"', 4 => 'class="R"', 5 => 'class="r"', 6 => 'class="r"', 7 => 'class="f"'));
    $ctr = 0;
    $lastCmpKey = '';
    foreach ($preregs as $prereg) {
        extract($prereg);
        $ctr++;
        $rank = $cmpKey > $lastCmpKey ? $ctr : '';
        $lastCmpKey = $cmpKey;
        tableRow(array($rank, $personId ? personLink($personId, $name) : $name, $countryId, formatValue($score1[0], valueFormat($eventId)), $score1[1], formatValue($score2[0], valueFormat($eventId)), $score2[1], ''));
    }
    tableEnd();
}
function buildGraph($eventName, $eventId, $divide)
{
    #----------------------------------------------------------------------
    #pretty("buildGraph( $eventName, $eventId, $divide ) ...");
    $series = array();
    $highestCurrent = 0;
    $yMax = 0;
    #--- Build the series of this event
    foreach (array('1 best green', '1 average green', '10 best blue', '10 average blue', '100 best red', '100 average red') as $lineData) {
        list($n, $valueId, $color) = explode(' ', $lineData);
        #--- Get this event's results
        $rows = dbQueryHandle("\n      SELECT personId, {$valueId} value, year + datediff(year*10000+month*100+day,year*10000+101)/365.25 date\n      FROM Results result, Competitions competition\n      WHERE competition.id = competitionId\n        AND eventId = '{$eventId}' AND {$valueId} > 0\n      ORDER BY year, month, day\n    ");
        // Gather the data
        $xdata = array();
        // x-coordinates for the line-points of the graph
        $ydata = array();
        // y-coordinates for the line-points of the graph
        $data = array();
        // coordinates for the line-points of the graph
        $records = array();
        // $records[$personId] = record of that person
        $nthPlaceRecord = false;
        // record of the n-th place person
        $direction = $eventId == '333mbf' ? -1 : 1;
        while ($row = mysql_fetch_row($rows)) {
            list($personId, $value, $date) = $row;
            if ($eventId == '333mbf') {
                $value = ($value - $value % 10000000) / 10000000 - 99;
            }
            if ($eventId == '333fm' && $valueId == 'average') {
                $value /= 100;
            }
            #      if ( $eventId == '333mbf' ) echo "$value ";
            //--- Skip values worse than n-th place
            if ($nthPlaceRecord && $value >= $nthPlaceRecord) {
                continue;
            }
            //--- Update this person's record
            $oldRecord = isset($records[$personId]) ? $records[$personId] : 1000000000;
            if ($value < $oldRecord) {
                $records[$personId] = $value;
            }
            //--- If we just reached n persons or this person just entered the top n...
            if (!$nthPlaceRecord && count($records) == $n || $oldRecord >= $nthPlaceRecord && $value < $nthPlaceRecord) {
                #echo "$nthPlaceRecord $oldRecord $value<br />";
                //--- Sort the records, determine the n-th place value, and just keep the top n
                asort($records);
                $keep = array();
                foreach ($records as $personId => $rec) {
                    $nthPlaceRecord = $keep[$personId] = $rec;
                    if (count($keep) == $n) {
                        break;
                    }
                }
                $records = $keep;
                //--- Remove previous line points for the same date
                while (end($xdata) == $date) {
                    array_pop($xdata);
                    array_pop($ydata);
                    array_pop($data);
                }
                if ($nthPlaceRecord * $direction == end($ydata)) {
                    continue;
                }
                //--- Add the line point
                $xdata[] = $date;
                $ydata[] = $nthPlaceRecord * $direction;
                $data[] = array(round($date, 2), $nthPlaceRecord * $direction);
                #printf( "<pre>%6.2f %6.2f</pre>", $date, $nthPlaceRecord );
                #echo "<pre>"; print_r( $records ); echo "</pre>";
            }
        }
        //--- Free the query handle
        mysql_free_result($rows);
        //--- Skip if we didn't even find n persons
        if (!$nthPlaceRecord) {
            continue;
        }
        //--- Remember the worst current shown record for later y-scale adjustment (worst will be at 1/3 height)
        $highestCurrent = max($highestCurrent, $nthPlaceRecord * $direction);
        #echo "<p>$eventName: $highestCurrent</p>";
        //--- Repeat the last height in the far future to finish with a straight line
        $xdata[] = 2222;
        $ydata[] = end($ydata);
        $data[] = array(2222, end($ydata));
        $yMax = max($yMax, max($ydata));
        $valueName = $valueId == 'best' ? 'Single' : 'Average';
        $series[] = "{ name: '#{$n} {$valueName}', color:'{$color}', data: " . json_encode($data) . '}';
    }
    #--- Build and return the javascript for this event's graph
    $chartJs = file_get_contents('charts_template.js');
    $chartJs = str_replace('$eventId', $eventId, $chartJs);
    $chartJs = str_replace('$xMax', 1970 + time() / 60 / 60 / 24 / 365.25, $chartJs);
    $chartJs = str_replace('$yMax', min($yMax, ($direction > 0 ? 3 : 1) * $highestCurrent), $chartJs);
    $chartJs = str_replace('$divide', $divide, $chartJs);
    $chartJs = str_replace('$eventName', json_encode(eventName($eventId)), $chartJs);
    $chartJs = str_replace('$series', implode(",\n    ", $series), $chartJs);
    return $chartJs;
}