function getCompetition($id)
{
    foreach (getAllCompetitions() as $competition) {
        if ($competition['id'] == $id) {
            return $competition;
        }
    }
}
function offerChoices()
{
    #----------------------------------------------------------------------
    global $chosenUri;
    global $chosenCompetitionId, $chosenType;
    global $chosenTextHtml, $chosenUriHtml, $chosenSubmitterNameHtml, $chosenSubmitterEmailHtml, $chosenSubmitterCommentHtml;
    if ($chosenUri != '') {
        $success = saveMedium();
        noticeBox2($success, 'Thanks for sending us a link to competition media', 'The reCAPTCHA was not entered correctly. Try it again.');
    }
    echo "<p>All media will be reviewed before listed on the Media page</p>";
    echo "<form method='POST'>\n";
    echo "<table border='0' cellspacing='0' cellpadding='2' width='100%'>\n";
    echo "<tr><td>Competition</td>";
    $optionsComp = "<td><select class='drop' id='competitionId' name='competitionId'>\n";
    foreach (getAllCompetitions() as $competition) {
        $optionId = $competition['id'];
        $optionName = $competition['cellName'];
        if ($optionId == $chosenCompetitionId) {
            $optionsComp .= "<option value='{$optionId}' selected='selected'>{$optionName}</option>\n";
        } else {
            $optionsComp .= "<option value='{$optionId}'>{$optionName}</option>\n";
        }
    }
    $optionsComp .= "</select></td></tr>";
    echo $optionsComp;
    echo "<tr><td>Type</td>";
    echo "<td><select class='drop' id='type' name='type'>\n";
    foreach (array('article', 'report', 'multimedia') as $typeString) {
        if ($typeString == $chosenType) {
            echo "<option value='{$typeString}' selected='selected'>{$typeString}</option>";
        } else {
            echo "<option value='{$typeString}'>{$typeString}</option>";
        }
    }
    $fieldList = array(array('Text', 'text', $chosenTextHtml), array('Link', 'uri', $chosenUriHtml ? "{$chosenUriHtml}" : 'http://'), array('Submitter Name', 'submitterName', $chosenSubmitterNameHtml), array('Submitter Email', 'submitterEmail', $chosenSubmitterEmailHtml), array('Submitter Comment', 'submitterComment', $chosenSubmitterCommentHtml));
    foreach ($fieldList as $field) {
        list($title, $name, $value) = $field;
        echo "<tr><td>{$title}</td><td><input type='text' name='{$name}' value='{$value}' /></td></tr>\n";
    }
    echo "</table>";
    global $config;
    $recaptcha = $config->get('recaptcha');
    echo recaptcha_get_html($recaptcha['publickey'], null, true);
    echo "<input type='submit' class='butt' value='Save' />";
    echo "</form>";
}
function editMedium()
{
    #----------------------------------------------------------------------
    global $mediumId;
    $infos = dbQuery("\n    SELECT *\n    FROM CompetitionsMedia\n    WHERE id = '{$mediumId}'\n  ");
    extract($infos[0]);
    echo "<form method='POST'>\n";
    echo "<table border='0' cellspacing='0' cellpadding='2' width='100%'>\n";
    echo "<tr><td>Competition</td>";
    $optionsComp = "<td><select class='drop' id='competitionId' name='competitionId'>\n";
    foreach (getAllCompetitions() as $competition) {
        $optionId = $competition['id'];
        $optionName = $competition['cellName'];
        if ($optionId == $competitionId) {
            $optionsComp .= "<option value='{$optionId}' selected='selected'>{$optionName}</option>\n";
        } else {
            $optionsComp .= "<option value='{$optionId}'>{$optionName}</option>\n";
        }
    }
    $optionsComp .= "</select></td></tr>";
    echo $optionsComp;
    echo "<tr><td>Type</td>";
    echo "<td><select class='drop' id='type' name='type'>\n";
    foreach (array('article', 'report', 'multimedia') as $typeString) {
        if ($type == $typeString) {
            echo "<option value='{$typeString}' selected='selected'>{$typeString}</option>";
        } else {
            echo "<option value='{$typeString}'>{$typeString}</option>";
        }
    }
    $fieldList = array(array('Text', 'text', htmlEscape($text)), array('Link', 'link', htmlEscape($uri)), array('Submitter Name', 'submitterName', htmlEscape($submitterName)), array('Submitter Email', 'submitterEmail', htmlEscape($submitterEmail)), array('Submitter Comment', 'submitterComment', htmlEscape($submitterComment)));
    foreach ($fieldList as $field) {
        list($title, $name, $value) = $field;
        echo "<tr><td>{$title}</td><td><input type='text' name='{$name}' value='{$value}' /></td></tr>\n";
    }
    echo "</table>";
    echo "<input type='submit' class='butt' value='Save' name='save{$id}' /> ";
    echo "<input type='submit' class='butt' value='Erase' name='refuse{$id}' />";
    echo "</form>";
}
<?php

/**
 * Created by PhpStorm.
 * User: petar
 * Date: 29.9.2016
 * Time: 14:14
 */
require join(DIRECTORY_SEPARATOR, array('includes', 'init.php'));
$leagueId = 1;
$leagueName = 'Engleska 1';
$tmpSeason = array(23 => '2016', 24 => '2016/2017');
$allCompetition = getAllCompetitions();
if (isset($_POST['countryId'])) {
    $leagueId = $_POST['countryId'];
    foreach ($allCompetition as $ac) {
        if ($ac->competition_id == $leagueId) {
            $leagueName = $ac->name;
        }
    }
}
$allStats = getAllCompetitionResults($leagueId);
$allStatsByRound = getAllCompetitionResultsByRound($leagueId);
echo "<br>";
$alldata = array();
$team = '';
$i = 0;
foreach ($allStats as $as) {
    $i++;
    $sum = $as->valueFor + $as->valueOposite;
    if ($as->teamId != $team) {
function getAllCompetitionIds              () { return getAllIDs( getAllCompetitions()              ); }