function analyzeChoices()
{
    #----------------------------------------------------------------------
    global $chosenNameHtml, $chosenNameMysql, $chosenCountryIdHtml, $chosenCountryIdMysql;
    $chosenNameHtml = getHtmlParam('name');
    $chosenNameMysql = getMysqlParam('name');
    $chosenCountryIdHtml = getHtmlParam('countryId');
    $chosenCountryIdMysql = getMysqlParam('countryId');
}
function analyzeChoices()
{
    #----------------------------------------------------------------------
    global $chosenEventId, $chosenRegionId, $chosenPatternHtml, $chosenPatternMysql;
    $chosenEventId = getNormalParam('eventId');
    $chosenRegionId = getNormalParam('regionId');
    $chosenPatternHtml = getHtmlParam('pattern');
    $chosenPatternMysql = getMysqlParam('pattern');
}
function analyzeChoices () {
#----------------------------------------------------------------------
  global $chosenId, $chosenConfirm, $chosenName, $chosenNameHtml, $chosenCountryId, $chosenGender, $chosenDay, $chosenMonth, $chosenYear, $chosenUpdate, $chosenFix;

  $chosenConfirm     = getBooleanParam( 'confirm'   );
  $chosenUpdate      = getBooleanParam( 'update'    );
  $chosenFix         = getBooleanParam( 'fix'       );
  $chosenId          = getNormalParam ( 'id'        );
  $chosenName        = getMysqlParam  ( 'name'      );
  $chosenNameHtml    = getHtmlParam   ( 'name'      );
  $chosenCountryId   = getMysqlParam  ( 'countryId' );
  $chosenGender      = getNormalParam ( 'gender'    );
  $chosenDay         = getNormalParam ( 'day'       );
  $chosenMonth       = getNormalParam ( 'month'     );
  $chosenYear        = getNormalParam ( 'year'      );

}
function analyzeChoices()
{
    #----------------------------------------------------------------------
    global $chosenEventId, $chosenRegionId, $chosenYears, $chosenPatternHtml, $chosenPatternMysql, $chosenList, $chosenMap;
    $chosenEventId = getNormalParam('eventId');
    $chosenRegionId = getNormalParam('regionId');
    $chosenPatternHtml = getHtmlParam('pattern');
    $chosenPatternMysql = getMysqlParam('pattern');
    $chosenYears = getNormalParam('years');
    $chosenList = getBooleanParam('list');
    $chosenMap = getBooleanParam('map');
    if (!$chosenList && !$chosenMap) {
        $chosenYears = "current";
    }
    if (!$chosenMap) {
        $chosenList = true;
    }
}
function analyzeChoices()
{
    #----------------------------------------------------------------------
    global $chosenCompetitionId, $chosenType, $chosenText, $chosenUri;
    global $chosenSubmitterName, $chosenSubmitterEmail, $chosenSubmitterComment;
    global $chosenTextHtml, $chosenUriHtml, $chosenSubmitterNameHtml, $chosenSubmitterEmailHtml, $chosenSubmitterCommentHtml;
    global $chosenRecaptchaChallenge, $chosenRecaptchaResponse;
    $chosenCompetitionId = getNormalParam('competitionId');
    $chosenType = getNormalParam('type');
    $chosenText = getMysqlParam('text');
    $chosenUri = getMysqlParam('uri');
    $chosenSubmitterName = getMysqlParam('submitterName');
    $chosenSubmitterEmail = getMysqlParam('submitterEmail');
    $chosenSubmitterComment = getMysqlParam('submitterComment');
    $chosenTextHtml = getHtmlParam('text');
    $chosenUriHtml = getHtmlParam('uri');
    $chosenSubmitterNameHtml = getHtmlParam('submitterName');
    $chosenSubmitterEmailHtml = getHtmlParam('submitterEmail');
    $chosenSubmitterCommentHtml = getHtmlParam('submitterComment');
    $chosenRecaptchaChallenge = getRawParamThisShouldBeAnException('recaptcha_challenge_field');
    $chosenRecaptchaResponse = getRawParamThisShouldBeAnException('recaptcha_response_field');
}
function saveMedium()
{
    #----------------------------------------------------------------------
    global $mediumId;
    $type = getNormalParam('type');
    $competitionId = getNormalParam('competitionId');
    $text = getMysqlParam('text');
    $link = getMysqlParam('link');
    $submitterName = getMysqlParam('submitterName');
    $submitterEmail = getMysqlParam('submitterEmail');
    $submitterComment = getMysqlParam('submitterComment');
    $command = "\n  UPDATE CompetitionsMedia\n    SET type='{$type}',\n        competitionId='{$competitionId}',\n        text='{$text}',\n        uri='{$link}',\n        submitterName='{$submitterName}',\n        submitterEmail='{$submitterEmail}',\n        submitterComment='{$submitterComment}'\n    WHERE id={$mediumId}";
    dbCommand($command);
    echo "I just did this : \n";
    echo $command;
}
function savePreregForm()
{
    #----------------------------------------------------------------------
    global $chosenCompetitionId, $competition, $config;
    $personId = getMysqlParam('personId');
    $name = getMysqlParam('name');
    $countryId = getMysqlParam('countryId');
    $gender = getMysqlParam('gender');
    $birthYear = getMysqlParam('birthYear');
    $birthMonth = getMysqlParam('birthMonth');
    $birthDay = getMysqlParam('birthDay');
    $email = getMysqlParam('email');
    $guests = getMysqlParam('guests');
    $comments = getMysqlParam('comments');
    $ip = getMysqlParam('ip');
    if (!$name or !$email or !$gender) {
        noticeBox(false, "Fields 'name', 'gender' and 'email' are required.");
        return false;
    }
    if (!preg_match("/^[_0-9a-zA-Z-]+(\\.[_0-9a-zA-Z-]+)*@[0-9a-zA-Z-]+(\\.[0-9a-zA-Z-]+)*(\\.[a-zA-Z]{2,3})\$/", $email)) {
        noticeBox(false, "Incorrect email address.");
        return false;
    }
    if ($birthYear == date('Y')) {
        noticeBox(false, "Please enter your date of birth.");
        return false;
    }
    if (!$birthYear) {
        $chosenPerson = dbQuery("SELECT * FROM Persons WHERE id='{$personId}'");
        $chosenPerson = $chosenPerson[0];
        $birthYear = $chosenPerson['year'];
        $birthMonth = $chosenPerson['month'];
        $birthDay = $chosenPerson['day'];
    }
    $guests = str_replace(array("\r\n", "\n", "\r", ","), ";", $guests);
    #--- Building query
    $eventIds = '';
    foreach (getAllEventIds() as $eventId) {
        if (getBooleanParam("E{$eventId}")) {
            $eventIds .= "{$eventId} ";
        }
    }
    rtrim($eventIds);
    # Remove last space
    $into = "competitionId, name, personId, countryId, gender, birthYear, birthMonth, birthDay, email, guests, comments, ip, status, eventIds";
    $values = "'{$chosenCompetitionId}', '{$name}', '{$personId}', '{$countryId}', '{$gender}', '{$birthYear}', '{$birthMonth}', '{$birthDay}', '{$email}', '{$guests}', '{$comments}', '{$ip}', 'p', '{$eventIds}'";
    dbCommand("INSERT INTO Preregs ({$into}) VALUES ({$values})");
    $organizers = getCompetitionOrganizers($competition['id']);
    foreach ($organizers as $organizer) {
        $mailEmail = $organizer['email'];
        // load more competition data for a nicer email
        $result = dbQuery("SELECT * FROM Competitions WHERE id='{$chosenCompetitionId}'");
        $competition_data = $result[0];
        $mailBody = "A new competitor has registered for your competition - " . $competition['cellName'] . "! ";
        $mailBody .= "Their information is below.\n-------------------\n";
        if ($personId) {
            $mailBody .= "Name : {$name}";
            $mailBody .= "     {$personId} - https://www.worldcubeassociation.org/results/p.php?i={$personId}\n";
        } else {
            $mailBody .= "Name : {$name}\n";
        }
        $mailBody .= "Country : {$countryId}\n";
        $mailBody .= "Gender : {$gender}\n";
        $mailBody .= "Date of birth : {$birthYear}/{$birthMonth}/{$birthDay}\n";
        $mailBody .= "Email : {$email}\n";
        $mailBody .= "Events : {$eventIds}\n";
        $mailBody .= "Guests : {$guests}\n";
        $mailBody .= "Comments : {$comments}\n";
        $mailBody .= "Ip : {$ip}\n";
        $mailBody .= "-------------------\n";
        $mailBody .= "You may edit this registration (and others) at:\n";
        $mailBody .= "https://www.worldcubeassociation.org/competitions/{$chosenCompetitionId}/registrations";
        $mailSubject = $competition['cellName'] . " - New registration";
        $mail_config = $config->get('mail');
        // only send mails on the real website
        if (preg_match('/^www.worldcubeassociation.org$/', $_SERVER["SERVER_NAME"])) {
            if ($mail_config['pear']) {
                // send smtp mail
                $headers = array('From' => $mail_config['from'], 'To' => $mailEmail, 'Subject' => $mailSubject);
                $smtp = Mail::factory('smtp', array('host' => $mail_config['host'], 'port' => $mail_config['port'], 'auth' => true, 'username' => $mail_config['user'], 'password' => $mail_config['pass']));
                $mail = $smtp->send($mailEmail, $headers, $mailBody);
            } else {
                // normal php mail
                $mailHeaders = "From: \"WCA\" <" . $mail_config['from'] . ">\r\n";
                $mailHeaders .= "Reply-To: board@worldcubeassociation.org\r\n";
                $mailHeaders .= "MIME-Version: 1.0\r\n";
                $mailHeaders .= "Content-Type: text/plain; charset=UTF-8\r\n";
                mail($mailEmail, $mailSubject, $mailBody, $mailHeaders, "-f" . $mail_config['from']);
            }
        } else {
            // just print out message when testing
            noticeBox3(0, "Mail not sent (test website): " . $mailBody);
        }
    }
    noticeBox(true, "Registration complete.<br />Please note that all registrations must be approved by the organizer.<br/>Your registration will appear here within a few days.");
    return true;
}